Ejemplo n.º 1
0
void PathFinder::calculateShotestPath() {
	// 如果目标无效,则不寻路
	if(_target.equals(INVALID_POINT)) {
		//stopAllActions();
		return;
	}
	CCPoint targetTilePos = _map->realPosToTilePos(getTarget());
	 // 如果目标在地图外或是墙,则不寻路
	if(int(targetTilePos.x + targetTilePos.y) == -2 || _map->getTileType(targetTilePos) == emWall) {
		//stopAllActions();
		setTarget(INVALID_POINT);
		return;
	}
    
	SearchDijkstra<NaviGraph<NaviNode, NaviEdge> > search(
		_map->getNaviGraph(), _map->tilePosToNodeId(getTilePos()), _map->realPosToNodeId(getTarget()));
	_shortestPath = search.getPathToTarget();
	
    _currPathNode = 0;
	_target = _map->getNaviGraph().getNode(_shortestPath[_currPathNode]).getCenterPos();
    /*
    CCParticleSystem* _jet = CCParticleSystemQuad::create("particle/jet.plist");
    _jet->retain();
    //this->addChild(_jet);
    _jet->setSourcePosition(ccp(0, 0));
    _jet->setPosition(getPosition());
    _jet->setAngle(0);
    _jet->setVisible(true);
    _jet->resetSystem();
    */
}
Ejemplo n.º 2
0
/***********************************************************************
     * Map
     * renderLight

***********************************************************************/
void Map::renderLight() {
	sf::Vector2i from(0, 0);
	sf::Vector2i to(MAP_SIZE_X, MAP_SIZE_Y);

	for (int i = from.x - 1; i < to.x; i++)
		for (int j = from.y - 1; j < to.y; j++) {
			lightMask[0].position = getTilePos(i  , j  );
			lightMask[1].position = getTilePos(i+1, j  );
			lightMask[2].position = getTilePos(i+1, j+1);
			lightMask[3].position = getTilePos(i  , j+1);

			lightMask[0].color = getTileLight(i  , j  );
			lightMask[1].color = getTileLight(i+1, j  );
			lightMask[2].color = getTileLight(i+1, j+1);
			lightMask[3].color = getTileLight(i  , j+1);

			app->draw(lightMask, 4, sf::Quads, sf::BlendMultiply);
		}
}
Ejemplo n.º 3
0
void Garden::build( CityPtr city, const TilePos& pos )
{
  // this is the same arrangement of garden tiles as existed in C3
  int theGrid[2][2] = {{113, 110}, {112, 111}};

  Construction::build( city, pos );
  setPicture( ResourceGroup::entertaiment, theGrid[pos.getI() % 2][pos.getJ() % 2] );

  if( getSize().getArea() == 1 )
  {
    TilemapTiles tilesAround = city->getTilemap().getRectangle( getTilePos() - TilePos( 1, 1),
                                                                getTilePos() + TilePos( 1, 1 ) );
    foreach( Tile* tile, tilesAround )
    {
      GardenPtr garden = tile->getOverlay().as<Garden>();
      if( garden.isValid() )
      {
        garden->update();
      }
    }
Ejemplo n.º 4
0
bool CompleteIsoView::eventMouseClick(const AGEvent *m)
{
  const AGSDLEvent *e=reinterpret_cast<const AGSDLEvent*>(m);
  if(e)
    {
      if(e->getButton()==SDL_BUTTON_RIGHT)
        mSelected.clear();
      else if(getScreenRect().contains(e->getMousePosition()))
        {
          //clicked
          AGPoint p(e->getMousePosition());
          cdebug("clicked on "<<p.x<<","<<p.y);

          std::vector<AntEntity *> es=getEntity(p);
	  if(es.size())
	    clickEntities(toEntVector(es));
	  else
	    {
              IVTile t=getTile(p);
              cdebug(t.x<<","<<t.y);
	      Pos2D p2=getTilePos(t);
	      clickMap(p2);
	    }
	  /*
          if(es.size())
            {
              if(mSelected.size())
                {
                  // already something selected - so fight
                  for(std::set
                        <AVItem*>::iterator k=mSelected.begin();k!=mSelected.end();k++) // loop selected
                      {
                        AVItem *i=*k;

                        AntHero *h=dynamic_cast<AntHero*>(mEntities[i]);
                        if(isMyHero(h))
                          {
                            AntHero *otherHero=getHero(es);
                            if(otherHero)
                              h->fightHero(otherHero);
                            //h->setJob(new FightJob(*es.begin())); // FIXME: currently fighting first
                          }
                      }

                }
              else
                {
                  std::vector<AntEntity*>::iterator i=es.begin();
                  for(;i!=es.end();i++)
                    mSelected.insert(mEntitiesInv[*i]);
                }

            }
          else
            {

              IVTile t=getTile(p);
              cdebug(t.x<<","<<t.y);
	      Pos2D p2=getTilePos(t);

	      clickMap(p2);

              if(mSelected.size() && es.size()==0)
                {
                  for(std::set
                        <AVItem*>::iterator k=mSelected.begin();k!=mSelected.end();k++)
                      {
                        AVItem *i=*k;

                        AntEntity *h=mEntities[i];
                        if(isMyHero(h))
                          {
			    //                            h->goTo(1,getTilePos(t));
                            h->setJob(new MoveJob(0,getTilePos(t),0));
                          }
                      }
                }
		}*/
        }
    }
  return false;

}
Ejemplo n.º 5
0
void BurningRuins::destroy()
{
  ServiceBuilding::destroy();

  Scenario::instance().getCity().build( B_BURNED_RUINS, getTilePos());
}