Example #1
7
//RETURNS: 0 on success, -1 o/w
int
shMapLevel::pushCreature (shCreature *c, shDirection dir)
{
    shDirection dirlist[3];
    int r = RNG (1, 2);
    int i;

    dirlist[0] = dir;
    dirlist[r] = (shDirection) ((dir + 1) % 8);
    dirlist[3-r] = (shDirection) ((dir + 7) % 8);

    for (i = 0; i < 3; i++) {
        int x = c->mX;
        int y = c->mY;
        shDirection dir = dirlist[i];

        moveForward (dir, &x, &y);

        if (isObstacle (x, y) or isOccupied (x, y))
            continue;

        return moveCreature (c, x, y);
    }

    if (c->isHero ()) {
        I->p ("You are crushed between the walls!");
    } else if (Hero.canSee (c)) {
        I->p ("%s is crushed!", THE (c));
    }
    c->die (kMisc, "Crushed by a garbage compactor");
    return -1;
}
Example #2
0
void AbstractGame::paintAllPositions(CDC &dc, PositionSet markedPositions) {
  CPen *oldPen = dc.SelectObject(&m_positionPen);

  const size_t n = m_brickPositions.size();
  CBrush *oldBrush = dc.SelectObject(&m_occupiedBrush);
  setTextColor(dc, false);
  for(UINT pos = 0; pos < n; pos++) {
    if(isOccupied(pos) && !SET_CONTAINS(markedPositions, pos)) {
      paintPosition(dc, pos);
    }
  }

  dc.SelectObject(&m_emptyBrush);
  for(UINT pos = 0; pos < n; pos++) {
    if(!isOccupied(pos)) {
      paintPosition(dc, pos);
    }
  }

  if(!SET_ISEMPTY(markedPositions)) {
    dc.SelectObject(&m_markedBrush);
    setTextColor(dc, true);
    for(UINT pos = 0; pos < n; pos++) {
      if(SET_CONTAINS(markedPositions, pos)) {
        paintPosition(dc, pos);
      }
    }
  }
  dc.SelectObject(oldBrush);
  dc.SelectObject(oldPen);
}
Example #3
0
bool Field::tryToEnter(FightingCharacter* a){
	if(!enoughActionPoints(a)) return false;
	a->useActionPoints(points_to_enter);
	if(isOccupied()) { 
		occupied_by->meet(a);
		buryDead();
	}
	return !isOccupied();
}
Example #4
0
bool Commander::isEdgeChokepoint(Chokepoint* choke)
{
	pair<BWTA::Region*,BWTA::Region*> regions = choke->getRegions();
	//If both is occupied it is not an edge chokepoint
	if (isOccupied(regions.first) && isOccupied(regions.second))
	{
		return false;
	}
	//...but one of them must be occupied
	if (isOccupied(regions.first) || isOccupied(regions.second))
	{
		return true;
	}
	return false;
}
void TimelineButton::mouseDrag(){


   float timeLineWidth= timeSize * secondMark;

    //now zoom in ( timeline gets wider the more we're zoomed in
    //timeLineWidth = timeLineWidth / zoomTime;

    float startPos = timePos * timeLineWidth;

    if(input->pressedLeft && startPressedLeft==0){

        draggedKey=NULL;
        float mouseX=input->mouseX;

        for (uint i=0;i<keyFrames.size();i++){
            float myTime = keyFrames[i]->timeKey/10.0;
            float keyX= location.x + myTime/zoomTime - startPos;
            if (mouseX > keyX && mouseX< keyX+10)
                draggedKey=keyFrames[i];
        }
    }

    if(input->pressedLeft && draggedKey){
        if (!isOccupied() ){
            draggedKey->timeKey  = (input->mouseX-location.x)*zoomTime  + startPos * zoomTime;
            draggedKey->timeKey  *= 10.0;
        }

        startPressedLeft = input->startPressLeftBtn;
    }


}
Example #6
0
TilePosition Commander::findUnfortifiedChokePoint()
{
	double bestDist = 0;
	Chokepoint* bestChoke = NULL;

	for(set<BWTA::Region*>::const_iterator i=getRegions().begin();i!=getRegions().end();i++)
	{
		if (isOccupied((*i)))
		{
			for(set<Chokepoint*>::const_iterator c=(*i)->getChokepoints().begin();c!=(*i)->getChokepoints().end();c++)
			{
				if (isEdgeChokepoint((*c)))
				{
					if (!chokePointFortified(TilePosition((*c)->getCenter())))
				{
						double cDist = Broodwar->self()->getStartLocation().getDistance(TilePosition((*c)->getCenter()));
						if (cDist > bestDist)
				{
							bestDist = cDist;
							bestChoke = (*c);
						}
					}
				}
			}
		}
	}

	TilePosition buildPos = TilePosition(-1, -1);
	if (bestChoke != NULL)
	{
		buildPos = TilePosition(bestChoke->getCenter());
	}
	return buildPos;
}
Example #7
0
gboolean
isCrossingNode(PlannerPertchartNode *pertchartnode)
{
	g_printf("-----------in isCrossingNode function\n");
	GList *l = NULL;
	GList *ancestors = getPertNodeAncestor(pertchartnode);
	gint ancol = 0;
	gint nodecol = 0;
	gint noderow = 0;
	gint col = 0;
	nodecol = planner_pertchart_node_get_col(pertchartnode);
	noderow = planner_pertchart_node_get_row(pertchartnode);
	for(l = ancestors;l;l=l->next)
	{
		PlannerPertchartNode *ancestor = l->data;
		ancol = planner_pertchart_node_get_col(ancestor);
		if(ancol < nodecol-1)
			for(col=nodecol-1;col>ancol;col--)
			{
				if(isOccupied(noderow,col))
					return TRUE;
			}
	}
	g_printf("-----------out isCrossingNode function\n");
	return FALSE;
}
Example #8
0
int
shMapLevel::makeNest (int sx, int sy, int ex, int ey)
{
    int x, y;
    int roomid = mSquares[sx][sy].mRoomId;

    if (mDLevel > 12) {
        shMonster *queen = new shMonster (kMonAlienQueen);
        queen->mStrategy = shMonster::kLurk;
        putCreature (queen, RNG (sx + 1, ex - 1), RNG (sy + 1, ey -1));
    }

    debug.log ("made nest on level %d", mDLevel);

    for (x = sx + 1; x < ex ; x++) {
        for (y = sy + 1; y < ey; y++) {
            if (!isOccupied (x, y)) {
                shMonster *alien = NULL;
                if (x%4 and y%3) {
                    alien = new shMonster (kMonAlienEgg);
                } else if (!RNG (8) and mDLevel >= 8) {
                    alien = new shMonster (kMonAlienWarrior);
                    alien->mStrategy = shMonster::kLurk;
                }
                if (alien) {
                    putCreature (alien, x, y);
                }
            } /* No stairs in a nest! */
            //mSquares[x][y].mFlags &= ~shSquare::kStairsOK;
        }
    }

    mRooms[roomid].mType = shRoom::kNest;
    return 1;
}
Example #9
0
char Field::getSymbolToShow() {
	if(isOccupied()){
		return occupied_by->getSymbol();
	} else {
		return getSymbol();
	}
}
Example #10
0
bool game::isGlobe(int index){
    if(index < 52){     //check only the indexes on the board, not in the home streak
        if(index % 13 == 0 || (index - 8) % 13 == 0 || isOccupied(index) > 1){  //if more people of the same team stand on the same spot it counts as globe
            return true;
        }
    }
    return false;
}
Example #11
0
void
moveDown(PlannerPertchartNode *pertchartnode)
{
	gint row = planner_pertchart_node_get_row(pertchartnode);
	gint col = planner_pertchart_node_get_col(pertchartnode);
	while(isOccupied(++row,col));
	g_object_set(pertchartnode,"row",row,NULL);
}
Example #12
0
void AbstractGame::paintPosition(CDC &dc, int pos) {
  const Point2D &p = m_brickPositions[pos];
  dc.Ellipse((int)(p.x-POSSIZE),(int)(p.y-POSSIZE),(int)(p.x+POSSIZE),(int)(p.y+POSSIZE));

  if(m_showNumbers && isOccupied(pos)) {
    textOut(dc, (int)(p.x - ((pos>9)?8:4)), (int)(p.y-8), format(_T("%d"), pos));
  }
}
void DynamicVoronoi::setObstacle(int x, int y) {
    dataCell c = data[x][y];
    if(isOccupied(x,y,c)) return;

    addList.push_back(INTPOINT(x,y));
    c.obstX = x;
    c.obstY = y;
    data[x][y] = c;
}
Example #14
0
Parameter* KernelFunction::getIndexOperationValue() {
	Parameter* parameter = indexOperation;

	if (indexOperation != NULL && indexOperation->isOccupied()) {
		indexOperation = NULL;
	}

	return parameter;
}
Example #15
0
void DynamicEDT3D::setObstacle(int x, int y, int z) {
	dataCell c = data[x][y][z];
	if(isOccupied(x,y,z,c)) return;

	addList.push_back(INTPOINT3D(x,y,z));
	c.obstX = x;
	c.obstY = y;
	c.obstZ = z;
	data[x][y][z] = c;
}
void DynamicVoronoi::removeObstacle(int x, int y) {
    dataCell c = data[x][y];
    if(isOccupied(x,y,c) == false) return;

    removeList.push_back(INTPOINT(x,y));
    c.obstX = invalidObstData;
    c.obstY  = invalidObstData;
    c.queueing = bwQueued;
    data[x][y] = c;
}
Example #17
0
void DynamicEDT3D::removeObstacle(int x, int y, int z) {
	dataCell c = data[x][y][z];
	if(isOccupied(x,y,z,c) == false) return;

	removeList.push_back(INTPOINT3D(x,y,z));
	c.obstX = invalidObstData;
	c.obstY  = invalidObstData;
	c.obstZ  = invalidObstData;
	c.queueing = bwQueued;
	data[x][y][z] = c;
}
Example #18
0
int AbstractGame::findPosition(const CPoint &p) const {
  for(int pos = 0; pos < m_positionCount; pos++) {
    if(distance(Point2DP(p), m_brickPositions[pos]) <= POSSIZE) {
      if(isOccupied(pos)) {
        return pos;
      }
      break;
    }
  }
  return -1;
}
Example #19
0
bool CGBBattleGrid::canMove(CGBBattleActor *actor, U32 targetX, U32 targetY)
{
    if (!mConstructed)
        return false;
    
    // More elaborate check later. Now just see if target cell is occupied
    if (isOccupied(targetX, targetY))
        return false;
    
    if (targetX >= mSizeX || targetY >= mSizeY)
        return false;
    return true;
}
Example #20
0
/*
Location::&operator =(Location other)
{
	if (this != &other)
	{
		(*this)->myCoordinates.getRow()=other->myCoordinates.getRow();
		(*this)->myCoordinates.getColumn()=other->myCoordinates.getColumn();
}
*/
void Location::printContents()
{
	
    if(isOccupied())
        cout <<"*";
		//cout<<myCoordinates->getRow()<<myCoordinates->getColumn()<<" is ocupied."<<endl;
    else if(itHasFood())
		//cout<<myCoordinates->getRow()<<myCoordinates->getColumn()<<" is stocked."<<endl;
        cout <<"-";
    else 
		//cout<<" is vacant."<<endl;
        cout <<"_";
}
Example #21
0
///
// Does the current piece collide at the specified coordinates/rotation.
///
static bool isCollision(const FSEngine *f, int x, int y, int theta)
{
    i8x2 blocks[FS_NBP];

    fsGetBlocks(f, blocks, f->piece, x, y, theta);

    for (int i = 0; i < FS_NBP; ++i) {
        if (isOccupied(f, blocks[i].x, blocks[i].y)) {
            return true;
        }
    }
    return false;
}
Example #22
0
	bool ServerChair::updateBotGift( float t )
	{
		if(isOccupied() || m_giftDat.giftID < 0)
			return false;

		m_botGiftTimeout += t;

		if(m_botGiftTimeout >= m_botGiftInterval)
		{
			m_botGiftTimeout = 0;
			return true;
		}

		return false;
	}
Example #23
0
TilePosition Commander::findChokePoint()
{
	//First, check the DefenseLocator
	//for a stored defense position.
	DefenseLocator* df = DefenseLocator::getInstance();
	TilePosition storedPos = df->getBaseDefensePos(Broodwar->mapHash());
	if (storedPos.x() != -1) return storedPos;

	double bestPrio = -1;
	Chokepoint* bestChoke = NULL;
	
	for(set<BWTA::Region*>::const_iterator i=getRegions().begin();i!=getRegions().end();i++)
	{
		if (isOccupied((*i)))
		{
			for(set<Chokepoint*>::const_iterator c=(*i)->getChokepoints().begin();c!=(*i)->getChokepoints().end();c++)
			{
				if (isEdgeChokepoint((*c)))
				{
					double cPrio = getChokepointPrio(TilePosition((*c)->getCenter()));
					if (cPrio > bestPrio)
					{
						bestPrio = cPrio;
						bestChoke = (*c);
					}
				}
			}
		}
	}

	TilePosition guardPos = Broodwar->self()->getStartLocation();
	if (bestChoke != NULL)
	{
		guardPos = findDefensePos(bestChoke);
		//guardPos = TilePosition(bestChoke->getCenter());

		//Pre-calculate path
		TilePosition b = ExplorationManager::getInstance()->getClosestSpottedBuilding(guardPos);
		if (b.x() >= 0)
		{
			Pathfinder::getInstance()->requestPath(guardPos, b);
		}
	}

	return guardPos;
}
Example #24
0
void KeyPointFilter::filterByRadius(int radius,
		const std::vector<cv::KeyPoint>& input,
		std::vector<cv::KeyPoint>& filtered) {
	// clear the old bitmap
	reset();
	filtered.clear();

	// sort points by response

	// eliminating by covering
	for (auto it = input.begin(); it != input.end(); it++) {
		if (!isOccupied(it->pt)) {
			coverAround(it->pt, radius);
			filtered.push_back(*it);
		}
	}
}
Example #25
0
bool GameBoard::insertPiece(int col, int occupiedByColor){
	for (int i = BOARD_HEIGHT - 1; i >= 0; i--){
		if (isOccupied(i, col) != true){
			int position = i * BOARD_WIDTH + col;
			squares[position].color = occupiedByColor;
			squares[position].occupied = true;
			squares[position].row = i;
			squares[position].col = col;
			
			return true;
		}
		else if (i == 0){
			return false;
		}
	}
	return false;
}
Example #26
0
void DynamicEDT3D::initializeMap(int _sizeX, int _sizeY, int _sizeZ, bool*** _gridMap) {
	gridMap = _gridMap;
	initializeEmpty(_sizeX, _sizeY, _sizeZ, false);

	for (int x=0; x<sizeX; x++) {
		for (int y=0; y<sizeY; y++) {
			for (int z=0; z<sizeZ; z++) {
				if (gridMap[x][y][z]) {
					dataCell c = data[x][y][z];
					if (!isOccupied(x,y,z,c)) {

						bool isSurrounded = true;
						for (int dx=-1; dx<=1; dx++) {
							int nx = x+dx;
							if (nx<0 || nx>sizeX-1) continue;
							for (int dy=-1; dy<=1; dy++) {
								int ny = y+dy;
								if (ny<0 || ny>sizeY-1) continue;
								for (int dz=-1; dz<=1; dz++) {
									if (dx==0 && dy==0 && dz==0) continue;
									int nz = z+dz;
									if (nz<0 || nz>sizeZ-1) continue;

									if (!gridMap[nx][ny][nz]) {
										isSurrounded = false;
										break;
									}
								}
							}
						}
						if (isSurrounded) {
							c.obstX = x;
							c.obstY = y;
							c.obstZ = z;
							c.sqdist = 0;
							c.dist = 0;
							c.queueing = fwProcessed;
							data[x][y][z] = c;
						} else setObstacle(x,y,z);
					}
				}
			}
		}
	}
}
Enemies GetAdjacentEnemyData(Unit unit) {
    Enemies enemies;
    enemies.count = 0;

    char color = GetUnitColor(unit);
    
    Grids adjacentGrids = GetAdjacentGrids(*GetGrid(GetLocation(unit)));
    for (unsigned int i = 0; i < adjacentGrids.count; i++) {
        Grid grid = *adjacentGrids.grids[i];
        if (isOccupied(grid) && !isOccupiedByAlly(grid, color)) {
            Unit *enemy = GetUnit(grid);
            enemies.enemy[enemies.count].unit = enemy;
            enemies.enemy[enemies.count].canRetaliate = Retaliates(unit, *enemy);
            ++enemies.count;
        }
    }

    return enemies;
}
//LC: Modified function for kinect localization
void MapModel::getHeightlist(double x, double y, double minHeight, double maxHeight, std::vector<double>& heights){
  double minX, minY, minZ, maxX, maxY, maxZ;
  m_map->getMetricMin(minX, minY, minZ);
  m_map->getMetricMax(maxX, maxY, maxZ);

  if(minHeight > 0.0)
      minZ = minHeight;

  double res = m_map->getResolution();

  double z =  minZ;

  while (z <= maxHeight && z <= maxZ){
    if (!isOccupied(octomap::point3d(x, y, z))){
        heights.push_back(z);
    }
    z += res;
  }
}
void TimelineButton::clickedRight(){

    cout << "creating new keyframe!" << endl;


    float timeLineWidth= timeSize * secondMark;

    //now zoom in ( timeline gets wider the more we're zoomed in
    float startPos = timePos * timeLineWidth; // in Pixels

    //check if we already have a key in this location
    bool bOccupied=isOccupied();


    if (!bOccupied){
        createKey((input->mouseX-location.x)*zoomTime + startPos  * zoomTime);
    }


}
Example #30
0
void MapModel::getHeightlist(double x, double y, double totalHeight, std::vector<double>& heights){
  double minX, minY, minZ, maxX, maxY, maxZ;
  m_map->getMetricMin(minX, minY, minZ);
  m_map->getMetricMax(maxX, maxY, maxZ);
  double res = m_map->getResolution();

  double z =  maxZ-res/2.0;
  double lastZ = z + res;

  while (z >= minZ){
    if (isOccupied(octomap::point3d(x, y, z))){
      if (lastZ - z >= totalHeight + res){
        heights.push_back(z+ res/2.0);
      }
      lastZ = z;
    }

    z -= res;
  }
}