当前位置: 首页>>代码示例>>C++>>正文


C++ Fleet类代码示例

本文整理汇总了C++中Fleet的典型用法代码示例。如果您正苦于以下问题:C++ Fleet类的具体用法?C++ Fleet怎么用?C++ Fleet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Fleet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: doOrder

bool UnloadArmament::doOrder(IGObject::Ptr ob){
  Fleet* fleet = dynamic_cast<Fleet*>(ob->getObjectBehaviour());
  ObjectManager* obman = Game::getGame()->getObjectManager();
  ObjectTypeManager* otman = Game::getGame()->getObjectTypeManager();
  ResourceManager::Ptr resman = Game::getGame()->getResourceManager();
  std::set<uint32_t>objs = obman->getObjectsByPos(fleet->getPosition(), 10000);
  IGObject::Ptr planetObj;
  Planet* planet;

  for (std::set<uint32_t>::const_iterator itcurr = objs.begin(); itcurr != objs.end(); ++itcurr) {
    if (obman->getObject(*itcurr)->getType() == otman->getObjectTypeByName("Planet")) {

      planetObj = obman->getObject(*itcurr);
      planet = dynamic_cast<Planet*>(planetObj->getObjectBehaviour());
      Logger::getLogger()->debug("UnloadArmaments::doOrder Found Planet %s for Unload Armaments Order", planetObj->getName().c_str());
      const uint32_t factoryType = resman->getResourceDescription("Factories")->getResourceType();

    IdMap weapontype = weaponlist->getList();
    for(IdMap::iterator weaponit = weapontype.begin(); weaponit != weapontype.end(); ++weaponit) {
      if (planet->removeResource(factoryType, 1)) {
        if (fleet->removeResource(weaponit->first, weaponit->second)) {
          Logger::getLogger()->debug("UnloadArmaments::doOrder success, adding to resource %d: #:%d", weaponit->first, weaponit->second);
          planet->addResource(weaponit->first, weaponit->second);
          planetObj->touchModTime();
          return true;
          }
        } else {
          turns = 1;
          return true;
        }
      }
    }
  }
  return false;
}
开发者ID:epyon,项目名称:tpserver-cpp,代码行数:35,代码来源:unloadarm.cpp

示例2: DumpWorldToSyncLog

void DumpWorldToSyncLog( char *_filename )
{
    FILE *file = fopen( _filename, "a" );
    if( !file ) return;

    fprintf( file, "\n\nBegin Final Object Positions\n" );

    for( int i = 0; i < g_app->GetWorld()->m_teams.Size(); ++i )
    {
        Team *team = g_app->GetWorld()->m_teams[i];
        for( int j = 0; j < team->m_fleets.Size(); ++j )
        {
            Fleet *fleet = team->m_fleets[j];
            char *state = fleet->LogState();
            fprintf( file, "%s\n", state );
        }
    }

    for( int i = 0; i < g_app->GetWorld()->m_objects.Size(); ++i )
    {
        if( g_app->GetWorld()->m_objects.ValidIndex(i) )
        {
            WorldObject *obj = g_app->GetWorld()->m_objects[i];
            char *state = obj->LogState();
            fprintf( file, "%s\n", state );
        }
    }

    fclose(file);
}
开发者ID:cahocachi,项目名称:DEFCON,代码行数:30,代码来源:defcon.cpp

示例3: sendHome

//Sends a fleet back to it's home planet
void TaeTurn::sendHome(uint32_t fleet) {
    Game* game = Game::getGame();
    ObjectManager* obm = game->getObjectManager();
    ObjectTypeManager* obtm = game->getObjectTypeManager();
    PlayerManager::Ptr pm = game->getPlayerManager();

    IGObject::Ptr fleetobj = obm->getObject(fleet);
    //Check to make sure it is really a fleet
    if(fleetobj->getType() != obtm->getObjectTypeByName("Fleet")) {
        return;
    }

    //Get all the required objects
    Fleet* f = (Fleet*) fleetobj->getObjectBehaviour();
    Player::Ptr p = pm->getPlayer(f->getOwner());
    IGObject::Ptr sys = obm->getObject(fleetobj->getParent());
    StarSystem* sysData = (StarSystem*) sys->getObjectBehaviour();

    //Remove fleet from system
    sysData->setRegion(0);
    fleetobj->removeFromParent();

    //Find it's home planet
    std::set<uint32_t> objects = obm->getAllIds();
    std::set<uint32_t>::iterator itcurr;
    for(itcurr = objects.begin(); itcurr != objects.end(); ++itcurr) {
        IGObject::Ptr ob = obm->getObject(*itcurr);
        if(ob->getName().compare(string(p->getName() + "'s Home Planet")) == 0) {
            Planet* p = (Planet*) ob->getObjectBehaviour();
            f->setPosition(p->getPosition());
            fleetobj->addToParent(ob->getID());
        }
    }
}
开发者ID:epyon,项目名称:tpserver-cpp,代码行数:35,代码来源:taeturn.cpp

示例4:

std::map<uint32_t, std::pair<std::string, uint32_t> > LoadArmament::generateListOptions(){
  Logger::getLogger()->debug("Entering LoadArmament::generateListOptions");
  std::map<uint32_t, std::pair<std::string, uint32_t> > options;

  Game* game = Game::getGame();
  IGObject::Ptr selectedObj = game->getObjectManager()->getObject(
            game->getOrderManager()->getOrderQueue(orderqueueid)->getObjectId());

  Fleet* fleet = dynamic_cast<Fleet*>(selectedObj->getObjectBehaviour());

  ObjectManager* obman = Game::getGame()->getObjectManager();
  ObjectTypeManager* otman = Game::getGame()->getObjectTypeManager();
  ResourceManager::Ptr resman = Game::getGame()->getResourceManager();
  std::set<uint32_t>objs = obman->getObjectsByPos(fleet->getPosition(), 10000);

  for (std::set<uint32_t>::iterator itcurr = objs.begin(); itcurr != objs.end(); ++itcurr) {
    if (obman->getObject(*itcurr)->getType() == otman->getObjectTypeByName("Planet")) {
      IGObject::Ptr planetObj = obman->getObject(*itcurr);
      Planet* planet = dynamic_cast<Planet*>(planetObj->getObjectBehaviour());
      Logger::getLogger()->debug("Found Planet %s for Load Armaments Order", planetObj->getName().c_str());
      std::map<uint32_t, std::pair<uint32_t, uint32_t> > reslist = planet->getResources();
      for (std::map<uint32_t, std::pair<uint32_t, uint32_t> >::iterator it = reslist.begin(); it != reslist.end(); ++it) {
        if (resman->getResourceDescription(it->first)->getUnitSingular() == "weapon") {
          options[it->first] = std::pair<std::string, uint32_t>(resman->getResourceDescription(it->first)->getNamePlural(),
            planet->getResourceSurfaceValue(it->first));
        }
      }

    }
  }

  Logger::getLogger()->debug("Exiting LoadArmament::generateListOptions");
  return options;
}
开发者ID:epyon,项目名称:tpserver-cpp,代码行数:34,代码来源:loadarm.cpp

示例5: return

bool Fleet::operator == (const Fleet& fleet) const{
    return (_ownerID==fleet.OwnerID() &&
		   _source_planet_id==fleet.SourcePlanetID() &&
		   _destination_planet_id==fleet.DestinationPlanetID() &&
		   _num_ships==fleet.NumShips() &&
			_turns_remaining==fleet.TurnsRemaining() );
}
开发者ID:9thbit,项目名称:Planet-Wars,代码行数:7,代码来源:Fleet.cpp

示例6: while

void PlanetWarsGame::advanceGame() {
    //Make planets grow ships.
    const int numPlanets = static_cast<int>(m_planets.size());

    for (int i = 0; i < numPlanets; ++i) {
        m_planets[i]->growFleets();
    }

    //Advance fleets.
    for (FleetList::iterator it = m_fleets.begin(); it != m_fleets.end(); ++it) {
        (*it)->advance();
    }

    //Welcome (or fight) the arrived fleets.
    for (int i = 0; i < numPlanets; ++i) {
        m_planets[i]->welcomeArrivedFleets();
    }

    //Clean up arrived fleets.
    FleetList::iterator itFleet = m_fleets.begin();

    while (itFleet != m_fleets.end()) {
        FleetList::iterator itCurrent = itFleet;
        ++itFleet;

        Fleet* fleet = (*itCurrent);

        if (fleet->getTurnsRemaining() <= 0) {
            delete fleet;
            m_fleets.erase(itCurrent);

        }
    }
}
开发者ID:kerzum,项目名称:PlanetWarrior,代码行数:34,代码来源:game.cpp

示例7: getETA

int Move::getETA(IGObject *ob) const{
  Fleet* fleet = ((Fleet*)(ob->getObjectBehaviour()));
  unsigned long long distance = coords->getPosition().getDistance(fleet->getPosition());
  unsigned long max_speed = 3000000;
  
  if(distance == 0) 
    return 1;
  return (int)((distance - 1) / max_speed) + 1;
}
开发者ID:AfrazHussain,项目名称:tpserver-cpp,代码行数:9,代码来源:move.cpp

示例8: panel_clicked_fleet

void panel_clicked_fleet(int mx, int my, int mb) {
    Fleet *flt = (Fleet*)cur_object;
    if(mx >= 800 && mb == 4) {
        --panel_offset;
        panel_draw_fleet();
        SDL_Rect screenrec = {800, 12+24*SKIP, 224, 24*23};
        screenrec.h = min(int(screenrec.h), 24*(flt->NumShips()));
        update(&screenrec);
        return;
    }
    if(mx >= 800 && mb == 5) {
        ++panel_offset;
        panel_draw_fleet();
        SDL_Rect screenrec = {800, 12+24*SKIP, 224, 24*23};
        screenrec.h = min(int(screenrec.h), 24*(flt->NumShips()));
        update(&screenrec);
        return;
    }

    int line = my;
    line -= 12+24*SKIP;
    if(line >= 0) line /= 24;
    if(line < 0 || line > 22
            || line >= int(flt->NumShips()) - panel_offset) {
        if(selection >= 0) {
            update(800, 12+24*(SKIP+selection-panel_offset), 224, 24);
            selection = -1;
            panel_draw_fleet();
        }
        return;
    }

    line += panel_offset;

    if(mb == 3) {
    }
    else if(mb == 1) {
        SDL_Rect screenrec = {800, 12+24*SKIP, 224, 24};
        if(selection >= 0) {
            screenrec.y = 12+24*(SKIP+selection);
            update(&screenrec);
        }
        if(selection != line) {
            selection = line;
            screenrec.y = 12+24*(SKIP+selection);
            update(&screenrec);
            panel_draw_fleet();
        }
        else {
            cur_ship = line;
            panel = PANEL_SHIP;
            panel_init();
        }
        audio_play(click2, 8, 8);
    }
}
开发者ID:steaphangreene,项目名称:cosmos,代码行数:56,代码来源:gui_panel_fleet.cpp

示例9: GetUniverse

Fleet* Fleet::Clone(int empire_id) const {
    Visibility vis = GetUniverse().GetObjectVisibilityByEmpire(this->ID(), empire_id);

    if (!(vis >= VIS_BASIC_VISIBILITY && vis <= VIS_FULL_VISIBILITY))
        return 0;

    Fleet* retval = new Fleet();
    retval->Copy(this, empire_id);
    return retval;
}
开发者ID:adesst,项目名称:freeorion,代码行数:10,代码来源:Fleet.cpp

示例10: Message

bool Bombard::doOrder(IGObject *fleet) {

   Game *game = Game::getGame();
   ObjectManager *om = game->getObjectManager();
   ObjectTypeManager *odm = game->getObjectTypeManager();
   Random *rand = game->getRandom();

   IGObject *planetObj = om->getObject(planet->getObjectId());

   if(planetObj->getType() != odm->getObjectTypeByName("Planet"))
   {
      Logger::getLogger()->debug("Player tried to bombard something illogical");
      return true;
   }

   Fleet *fleetData = dynamic_cast<Fleet*>(fleet->getObjectBehaviour());
   Planet *planetData = dynamic_cast<Planet*>(planetObj->getObjectBehaviour());
   char planetShipTech = PlayerInfo::getPlayerInfo(planetData->getOwner()).getShipTechLevel();
   double attack = fleetData->getAttack();
   
   planetData->removeResource("Industry", 
                  static_cast<uint32_t>(attack * INDUSTRY_DMG * (1+rand->getInRange(-2,2)/100.) ));

   planetData->removeResource("Social Environment", 
                  static_cast<uint32_t>(attack * SOCIAL_DMG * (1+rand->getInRange(-2,2)/100.) ));

   planetData->removeResource("Planetary Environment", 
                  static_cast<uint32_t>(attack * PLANETARY_DMG * (1+rand->getInRange(-2,2)/100.) ));

   planetData->removeResource(string("PDB") + planetShipTech,
                  static_cast<uint32_t>(attack * PDB_DMG / 10. * (1+rand->getInRange(-2,2)/100.) ));

   PlayerInfo::getPlayerInfo(fleetData->getOwner()).addVictoryPoints(VICTORY_POINTS);


   // PDBs counter-attack at: PDB level * 6 * numPDBs
   fleetData->takeDamage( (planetShipTech - '0') *
                         6 * planetData->getResource(string("PDB") + planetShipTech).first);

   Message *msg = new Message();
   msg->setSubject("Bombard complete");
   string body = "Fleet \"" + fleet->getName() + "\" bombarded " + planetObj->getName();
   msg->setBody(PlayerInfo::appAllVictoryPoints(body));
   msg->addReference(rst_Action_Order, rsorav_Completion);
   msg->addReference(rst_Object, fleet->getID());
   msg->addReference(rst_Object, planetObj->getID());

   game->getPlayerManager()->getPlayer(fleetData->getOwner())->postToBoard(msg);
   game->getPlayerManager()->getPlayer(planetData->getOwner())->postToBoard(msg);

   return true;
}
开发者ID:AfrazHussain,项目名称:tpserver-cpp,代码行数:52,代码来源:bombard.cpp

示例11: welcomeArrivedFleets

void Planet::welcomeArrivedFleets() {
    const int ownerId = m_owner->getId();

    //Tally up the ships for each force.
    const int numArrivedFleets = static_cast<int>(m_landedFleets.size());

    if (numArrivedFleets == 0) {
        return;
    }

    int playerShips[3];
    playerShips[0] = (ownerId == 0) ? m_numShips : 0;
    playerShips[1] = (ownerId == 1) ? m_numShips : 0;
    playerShips[2] = (ownerId == 2) ? m_numShips : 0;

    for (int i = 0; i < numArrivedFleets; ++i) {
        Fleet* fleet = m_landedFleets[i];
        playerShips[fleet->getOwner()->getId()] += fleet->getNumShips();
    }

    m_landedFleets.clear();

    //Check who won.
    //Check whether the owner stays the same.
    if (playerShips[ownerId] >= std::max(playerShips[(ownerId+1)%3], playerShips[(ownerId+2)%3])) {
        this->setNumShips(playerShips[ownerId]
                          - std::max(playerShips[(ownerId+1)%3], playerShips[(ownerId+2)%3]));
        return;
    }

    //Otherwise, find the new owner.
    if (playerShips[1] > playerShips[2]) {
        this->setOwner(m_game->getFirstPlayer());
        const int remainingShips = playerShips[1] - std::max(playerShips[2], playerShips[0]);
        this->setNumShips(remainingShips);

    } else if (playerShips[2] > playerShips[1]) {
        this->setOwner(m_game->getSecondPlayer());
        const int remainingShips = playerShips[2] - std::max(playerShips[1], playerShips[0]);
        this->setNumShips(remainingShips);

    } else if (ownerId == 0 && playerShips[2] == playerShips[1]) {
        //The invading fleets are larger than the neutral planet, but equal in size.
        //Planet stays neutral.
        this->setNumShips(0);
    }

    //There should be no other cases.
}
开发者ID:kerzum,项目名称:PlanetWarrior,代码行数:49,代码来源:game.cpp

示例12: addFleet

void StarSystem::addFleet(Fleet& input_fleet)
{
  fleets.insert(std::pair<int,Fleet>(input_fleet.getID(),input_fleet) );


//  cout << "added fleet with id " << input_fleet.getID() << endl;
}
开发者ID:unfixed,项目名称:Nebula,代码行数:7,代码来源:starsystem.cpp

示例13: pause

void NormalGame::display_stats()
{
	STACKTRACE;
	pause();
	int i;
	for (i = 0; i < num_players; i += 1) {
		Fleet *fleet = player_fleet[i];
		switch (log->type) {
			case Log::log_net1client:
			case Log::log_net1server:
			{
				//				if (log->get_direction(player_control[i]->channel) & Log::direction_write)
				message.print(6000, 15, "%s status: : %d / ?? Ships, %d / ??? points", player_name[i], fleet->getSize(), fleet->getCost());
				//				else
				//					message.print(6000, 15, "%s status: : %d / %d points", buffy, fleet->cost, player_total_fleet[i]);
			}
			break;
			default:
			{
				message.print(6000, 15, "%s status: : %d / ?? Ships, %d / ??? points", player_name[i], fleet->getSize(), fleet->getCost());
			}
			break;
		}
	}
	unpause();
	return;
}
开发者ID:Yurand,项目名称:tw-light,代码行数:27,代码来源:mmain.cpp

示例14: toString

std::string PlanetWarsGame::toString(Player* pov) const {
    std::stringstream gameState;
    const int numPlanets = static_cast<int>(m_planets.size());

    //Write the planets.
    for (int i = 0; i < numPlanets; ++i) {
        Planet* planet = m_planets[i];
        gameState << "P " << planet->getX()
                << " " << planet->getY()
                << " " << pov->povId(planet->getOwner())
                << " " << planet->getNumShips()
                << " " << planet->getGrowthRate()
                << std::endl;
    }

    //Write the fleets.
    for (FleetList::const_iterator it = m_fleets.begin(); it != m_fleets.end(); ++it) {
        Fleet* fleet = (*it);
        gameState << "F " << pov->povId(fleet->getOwner())
                << " " << fleet->getNumShips()
                << " " << fleet->getSource()->getId()
                << " " << fleet->getDestination()->getId()
                << " " << fleet->getTotalTripLength()
                << " " << fleet->getTurnsRemaining()
                << std::endl;
    }

    gameState << "go" << std::endl;

    return gameState.str();

}
开发者ID:kerzum,项目名称:PlanetWarrior,代码行数:32,代码来源:game.cpp

示例15: if

void CargoHolder::AdjustAmounts(CargoType ct, long amount)
{
	if (amount == 0)
		return;

	if (ct >= 0) {
		mContains[ct] += amount;
	} else if (ct == POPULATION) {
		mPopulation += amount;
	} else if (ct == FUEL) {
		Fleet * f = dynamic_cast<Fleet *>(this);
		if (f == NULL) {
			assert(false);
		} else
			f->AdjustFuel(amount);
	} else {
		assert(false);
	}
}
开发者ID:vkholodkov,项目名称:freestars,代码行数:19,代码来源:CargoHolder.cpp


注:本文中的Fleet类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。