本文整理汇总了C++中Fleet::getShips方法的典型用法代码示例。如果您正苦于以下问题:C++ Fleet::getShips方法的具体用法?C++ Fleet::getShips怎么用?C++ Fleet::getShips使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Fleet
的用法示例。
在下文中一共展示了Fleet::getShips方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: doOrder
//The colonize order checks to make sure the system is valid, then adds a resource to the planet, checks for
//external combat, and awards one point to the player with the leader in the region of the new colony.
bool Colonize::doOrder(IGObject::Ptr obj) {
ObjectManager* obm = Game::getGame()->getObjectManager();
ObjectTypeManager* obtm = Game::getGame()->getObjectTypeManager();
Fleet* fleetData = (Fleet*)(obj->getObjectBehaviour());
Player::Ptr player = Game::getGame()->getPlayerManager()->getPlayer(fleetData->getOwner());
IGObject::Ptr newStarSys = obm->getObject(starSys->getObjectId());
//Perform last minute checks to make sure the system can be colonized
if(newStarSys->getType() != obtm->getObjectTypeByName("Star System")) {
//Not a star system
Logger::getLogger()->debug("Trying to colonize to an object which is not a star system");
Message::Ptr msg( new Message() );
msg->setSubject("Colonize order failed");
msg->setBody(string("You're fleet, \"" + obj->getName() + "\" tried to colonize an object which is not a star system!"));
msg->addReference(rst_Object, obj->getID());
player->postToBoard(msg);
return false;
}
if(!((StarSystem*)(newStarSys->getObjectBehaviour()))->canBeColonized(isMining)) {
//Not colonizable
Logger::getLogger()->debug("Player tried to colonize a system which cannot be colonized.");
Message::Ptr msg( new Message() );
msg->setSubject("Colonize order failed");
msg->setBody(string("You're fleet, \"" + obj->getName() + "\" tried to colonize a fleet which cannot be colonized!"));
msg->addReference(rst_Object, obj->getID());
player->postToBoard(msg);
return false;
}
//Find the star system's planet
set<uint32_t> children = newStarSys->getContainedObjects();
uint32_t pid;
bool planetFound = false;
for(set<uint32_t>::iterator i=children.begin(); i != children.end(); i++) {
if(obm->getObject(*i)->getType() == obtm->getObjectTypeByName("Planet")) {
pid = *i;
planetFound = true;
}
}
if(!planetFound) {
Logger::getLogger()->debug("Colonize Order: No planet found in target star system");
return false;
}
//Add resource to planet
Planet* planet = (Planet*)(obm->getObject(pid)->getObjectBehaviour());
Design::Ptr ship = Game::getGame()->getDesignStore()->getDesign(fleetData->getShips().begin()->first);
uint32_t scoreType = 0;
string leaderName;
if(ship->getName().compare("MerchantShip") == 0) {
planet->addResource(4, 1);
scoreType = 1;
leaderName = "MerchantLeaderShip";
} else if(ship->getName().compare("ScientistShip") == 0) {
planet->addResource(5, 1);
scoreType = 2;
leaderName = "ScientistLeaderShip";
} else if(ship->getName().compare("SettlerShip") == 0) {
planet->addResource(6, 1);
scoreType = 3;
leaderName = "SettlerLeaderShip";
} else if(ship->getName().compare("MiningShip") == 0) {
planet->addResource(7, 1);
scoreType = 4;
leaderName = "MiningLeaderShip";
}
//Get bordering star systems' regions
StarSystem* starSysData = (StarSystem*)(newStarSys->getObjectBehaviour());
set<uint32_t> regions = getBorderingRegions();
//Put the newly colonized ship into the proper region
//If it does not border any regions, then set it to a new one with a unique id
if(regions.size() == 0) {
starSysData->setRegion(starSys->getObjectId());
stringstream out;
out << starSysData->getRegion();
Logger::getLogger()->debug(string("System " + newStarSys->getName() + " added to region " + out.str()).c_str());
} else if(regions.size() == 1) {
// Add +1 to the resource score of the player with the correct leader
// in this region
int leaderID = getLeaderInRegion(*(regions.begin()), leaderName);
if(leaderID < 0 && leaderName.compare("SettlerLeaderShip") != 0) {
leaderID = getLeaderInRegion(*(regions.begin()), "SettlerLeaderShip");
}
if(leaderID >= 0) {
Fleet* leader = (Fleet*) ((obm->getObject((uint32_t) leaderID))->getObjectBehaviour());
Player::Ptr owner = Game::getGame()->getPlayerManager()->getPlayer(leader->getOwner());
owner->setScore(scoreType, owner->getScore(scoreType) + 1);
}
//Add the newly colonized system to the region
starSysData->setRegion(*(regions.begin()));
stringstream out;
out << starSysData->getRegion();
Logger::getLogger()->debug(string("System " + newStarSys->getName() + " added to region " + out.str()).c_str());
//.........这里部分代码省略.........
示例2: awardArtifacts
//Award artifacts to any players who have a merchant leader
//in a region with two artifacts
void TaeTurn::awardArtifacts() {
Game* game = Game::getGame();
ObjectTypeManager* obtm = game->getObjectTypeManager();
ObjectManager* objectmanager = game->getObjectManager();
std::set<uint32_t> artifacts;
std::set<uint32_t> regions;
std::set<uint32_t> objects = objectmanager->getAllIds();
std::set<uint32_t>::iterator itcurr;
//Find any regions with 2 or more alien artifacts
for(itcurr = objects.begin(); itcurr != objects.end(); ++itcurr) {
IGObject::Ptr ob = objectmanager->getObject(*itcurr);
if(ob->getType() == obtm->getObjectTypeByName("Planet")) {
Planet* p = (Planet*) ob->getObjectBehaviour();
if(p->getResource(3) > 0) {
StarSystem* sys = (StarSystem*)(objectmanager->getObject(ob->getParent())->getObjectBehaviour());
if(sys->getRegion() != 0) {
if(regions.count(sys->getRegion()) > 0) {
artifacts.insert(*itcurr);
} else {
regions.insert(sys->getRegion());
}
}
}
}
}
if(!artifacts.empty()) {
uint32_t type;
DesignStore::Ptr ds = game->getDesignStore();
PlayerManager::Ptr pm = game->getPlayerManager();
std::set<uint32_t> designs = ds->getDesignIds();
//get leader ID
for(itcurr = designs.begin(); itcurr != designs.end(); ++itcurr) {
if(ds->getDesign(*itcurr)->getName().compare("MerchantLeaderShip")) {
type = *itcurr;
}
}
//Search the objects for a merchant leader
for(itcurr = objects.begin(); itcurr != objects.end(); ++itcurr) {
IGObject::Ptr ob = objectmanager->getObject(*itcurr);
if(ob->getType() == obtm->getObjectTypeByName("Fleet")) {
Fleet* f = (Fleet*) (ob->getObjectBehaviour());
if(f->getShips().count(type) > 0) {
IGObject::Ptr parent = objectmanager->getObject(ob->getParent());
if(parent->getType() == obtm->getObjectTypeByName("Star System")) {
StarSystem* parentData = (StarSystem*) (parent->getObjectBehaviour());
//See if this leader is in a region with
//2 or more alien artifacts
for(std::set<uint32_t>::iterator i = artifacts.begin(); i != artifacts.end(); ++i) {
IGObject::Ptr obj = objectmanager->getObject(*i);
Planet* p = (Planet*) obj->getObjectBehaviour();
StarSystem* sys = (StarSystem*)(objectmanager->getObject(obj->getParent())->getObjectBehaviour());
if(sys->getRegion() == parentData->getRegion()) {
//+1 to leader's owner's artifact score
Player::Ptr owner = pm->getPlayer(f->getOwner());
owner->setScore(5, owner->getScore(5) + 1);
p->removeResource(3, 1);
artifacts.erase(*i);
}
}
}
}
}
}
}
}
示例3: doOrder
bool MergeFleet::doOrder(IGObject::Ptr ob){
IGObject::Ptr parent = Game::getGame()->getObjectManager()->getObject(ob->getParent());
Fleet *myfleet = (Fleet*)(ob->getObjectBehaviour());
//find fleet to merge with
uint32_t targetid = 0;
std::set<uint32_t> oblist = parent->getContainedObjects();
for(std::set<uint32_t>::iterator itcurr = oblist.begin(); itcurr != oblist.end(); ++itcurr){
if(*itcurr == ob->getID())
continue;
IGObject::Ptr ptarget = Game::getGame()->getObjectManager()->getObject(*itcurr);
if(ptarget->getType() == ob->getType()){
Fleet* pfleet = (Fleet*)(ptarget->getObjectBehaviour());
if(pfleet->getOwner() == myfleet->getOwner()){
if(pfleet->getSize() + myfleet->getSize() > pfleet->getPosition().getDistance(myfleet->getPosition())){
targetid = *itcurr;
Game::getGame()->getObjectManager()->doneWithObject(*itcurr);
break;
}
}
}
Game::getGame()->getObjectManager()->doneWithObject(*itcurr);
}
if(targetid == 0){
Message::Ptr msg( new Message() );
msg->setSubject("Merge Fleet order canceled");
msg->setBody("No target fleet at this location");
msg->addReference(rst_Action_Order, rsorav_Canceled);
msg->addReference(rst_Object, ob->getID());
Game::getGame()->getPlayerManager()->getPlayer(((Fleet*)(ob->getObjectBehaviour()))->getOwner())->postToBoard(msg);
}else{
IGObject::Ptr target = Game::getGame()->getObjectManager()->getObject(targetid);
Message::Ptr msg( new Message() );
msg->setSubject("Merge Fleet order complete");
msg->setBody("The two fleets have been merged");
msg->addReference(rst_Action_Order, rsorav_Completion);
msg->addReference(rst_Object, ob->getID());
msg->addReference(rst_Object, target->getID());
Fleet *tfleet = (Fleet*)(target->getObjectBehaviour());
IdMap ships = myfleet->getShips();
for(IdMap::iterator itcurr = ships.begin();
itcurr != ships.end(); ++itcurr){
tfleet->addShips(itcurr->first, itcurr->second);
}
//remove the fleet from the physical universe
ob->removeFromParent();
Game::getGame()->getObjectManager()->scheduleRemoveObject(ob->getID());
Game::getGame()->getPlayerManager()->getPlayer(myfleet->getOwner())->getPlayerView()->removeOwnedObject(ob->getID());
Game::getGame()->getObjectManager()->doneWithObject(target->getID());
Game::getGame()->getPlayerManager()->getPlayer(myfleet->getOwner())->postToBoard(msg);
}
return true;
}
示例4: initCombat
//Setup the next turn to be ready for combat
void TaeTurn::initCombat() {
std::set<uint32_t>::iterator itcurr;
Game* game = Game::getGame();
ObjectManager* objectmanager = game->getObjectManager();
PlayerManager::Ptr playermanager = game->getPlayerManager();
ObjectTypeManager* obtm = game->getObjectTypeManager();
DesignStore::Ptr ds = game->getDesignStore();
//Pop the combat queue and set the combatants
pair<bool, map<uint32_t, uint32_t> > temp;
temp = combatQueue.front();
combatQueue.pop();
isInternal = temp.first;
combatants = temp.second;
strength.clear();
for(map<uint32_t, uint32_t>::iterator i = combatants.begin(); i != combatants.end(); ++i) {
IGObject::Ptr ob = Game::getGame()->getObjectManager()->getObject(i->first);
Fleet* f = (Fleet*) ob->getObjectBehaviour();
strength[f->getOwner()] = 0;
}
set<uint32_t> owners;
set<uint32_t> regions;
string shipType;
for(map<uint32_t, uint32_t>::iterator i = combatants.begin(); i != combatants.end(); ++i) {
IGObject::Ptr ob = objectmanager->getObject(i->first);
Fleet* leader = (Fleet*) (ob)->getObjectBehaviour();
//look for the shiptype which this combat is associated with
if(shipType.empty()) {
if(isInternal) {
shipType = "ScientistShip";
} else {
//Set shiptype to the type corresponding to the leader
uint32_t ship = leader->getShips().begin()->first;
shipType = ds->getDesign(ship)->getName();
size_t pos = shipType.find("Leader");
if(pos != shipType.npos) {
shipType.erase(pos, 6);
}
}
}
owners.insert(leader->getOwner());
//Set which regions are involved in combat
if(regions.count(i->second) <= 0) {
regions.insert(i->second);
}
//Set initial internal combat strength
if(isInternal) {
IGObject::Ptr starSys = objectmanager->getObject(ob->getParent());
StarSystem* starSysData = (StarSystem*)(starSys->getObjectBehaviour());
Vector3d pos = starSysData->getPosition();
//Search for bordering science colonies
//east-west neighbors
for(int i = -1; i < 2; i+=2) {
set<uint32_t> ids = objectmanager->getObjectsByPos(pos+Vector3d(80000*i,0,0), 1);
for(set<uint32_t>::iterator j=ids.begin(); j != ids.end(); j++) {
IGObject::Ptr tempObj = objectmanager->getObject(*j);
if(tempObj->getType() == obtm->getObjectTypeByName("Planet")) {
Planet* p = (Planet*)(tempObj->getObjectBehaviour());
if(p->getResource(5) > 0) {
addReinforcement(leader->getOwner());
}
}
}
}
//north-south neighbors
for(int i = -1; i < 2; i+=2) {
set<uint32_t> ids = objectmanager->getObjectsByPos(pos+Vector3d(0,80000*i,0), 1);
for(set<uint32_t>::iterator j=ids.begin(); j != ids.end(); j++) {
IGObject::Ptr tempObj = objectmanager->getObject(*j);
if(tempObj->getType() == obtm->getObjectTypeByName("Planet")) {
Planet* p = (Planet*)(tempObj->getObjectBehaviour());
if(p->getResource(5) > 0) {
addReinforcement(leader->getOwner());
}
}
}
}
}
}
//Set which resource will be awarded
int resourceType;
if(shipType.compare("MerchantShip") == 0) {
resourceType = 4;
} else if(shipType.compare("ScientistShip") == 0) {
resourceType = 5;
} else if(shipType.compare("SettlerShip") == 0) {
resourceType = 6;
} else {
resourceType = 7;
}
//Set all fleets to combat mode. Flag the fleets whose owners are
//directly involved in combat.
std::set<uint32_t> views;
//.........这里部分代码省略.........
示例5: doOrder
bool Colonise::doOrder(IGObject::Ptr ob){
//if not close, move
IGObject::Ptr target = Game::getGame()->getObjectManager()->getObject(ob->getParent());
if(target == NULL || target->getType() != Game::getGame()->getObjectTypeManager()->getObjectTypeByName("Planet")){
Logger::getLogger()->debug("Object(%d)->Colonise->doOrder(): Target was not valid.", ob->getID());
Game::getGame()->getObjectManager()->doneWithObject(ob->getParent());
Message::Ptr msg( new Message() );
msg->setSubject("Colonise order canceled");
msg->setBody("Not at a planet, colonisation canceled");
msg->addReference(rst_Action_Order, rsorav_Canceled);
msg->addReference(rst_Object, ob->getID());
Game::getGame()->getPlayerManager()->getPlayer(((Fleet*)(ob->getObjectBehaviour()))->getOwner())->postToBoard(msg);
return true;
}
Fleet* fleet = (Fleet*)(ob->getObjectBehaviour());
Planet* planet = (Planet*)(target->getObjectBehaviour());
Message::Ptr msg( new Message() );
msg->addReference(rst_Object, ob->getID());
msg->addReference(rst_Object, target->getID());
if(planet->getOwner() != fleet->getOwner()){
if(planet->getOwner() != 0){
Logger::getLogger()->debug("Object(%d)->Colonise->doOrder(): Planet already owned.",
ob->getID());
msg->setSubject("Colonisation failed");
msg->setBody("The planet you tried to colonise, is already owned by someone else.");
msg->addReference(rst_Action_Order, rsorav_Canceled);
}else{
DesignStore::Ptr ds = Game::getGame()->getDesignStore();
int shiptype = 0;
int shiphp = 2000000;
IdMap ships = fleet->getShips();
uint32_t colonisePropID = ds->getPropertyByName( "Colonise");
uint32_t armorPropID = ds->getPropertyByName( "Armour");
for(IdMap::iterator itcurr = ships.begin();
itcurr != ships.end(); ++itcurr){
Design::Ptr design = ds->getDesign(itcurr->first);
if(design->getPropertyValue(colonisePropID) != 0.0 && shiphp > (int)design->getPropertyValue(armorPropID)){
shiptype = itcurr->first;
shiphp = (int)design->getPropertyValue(armorPropID);
}
}
Logger::getLogger()->debug("Object(%d)->Colonise->doOrder(): shiptype %d",
ob->getID(), shiptype);
if(shiptype != 0){
uint32_t oldowner = planet->getOwner();
planet->setOwner(fleet->getOwner());
Game::getGame()->getPlayerManager()->getPlayer(fleet->getOwner())->getPlayerView()->addOwnedObject(target->getID());
uint32_t queueid = static_cast<OrderQueueObjectParam*>(target->getParameterByType(obpT_Order_Queue))->getQueueId();
OrderQueue::Ptr queue = Game::getGame()->getOrderManager()->getOrderQueue(queueid);
queue->removeOwner(oldowner);
queue->addOwner(fleet->getOwner());
fleet->removeShips(shiptype, 1);
msg->setSubject("Colonised planet");
msg->setBody("You have colonised a planet!");
msg->addReference(rst_Action_Order, rsorav_Completion);
}else{
msg->setSubject("Colonisation failed");
msg->setBody("Your fleet did not have a frigate to colonise the planet");
msg->addReference(rst_Action_Order, rsorav_Invalid);
}
if(fleet->totalShips() == 0){
Game::getGame()->getObjectManager()->scheduleRemoveObject(ob->getID());
Game::getGame()->getPlayerManager()->getPlayer(fleet->getOwner())->getPlayerView()->removeOwnedObject(ob->getID());
}
}
}else{
Logger::getLogger()->debug("Object(%d)->Colonise->doOrder(): Was already owned by the player!",
ob->getID());
msg->setSubject("Colonisation failed");
msg->setBody("You already own the planet you tried to colonise");
msg->addReference(rst_Action_Order, rsorav_Canceled);
}
Game::getGame()->getPlayerManager()->getPlayer(fleet->getOwner())->postToBoard(msg);
Game::getGame()->getObjectManager()->doneWithObject(target->getID());
return true;
}