void RSPCombat::resolveCombatantsToObjects(std::vector<Combatant*> combatants) { std::map<objectid_t, bool> colonydead; std::map<objectid_t, uint32_t> damagemap; for(std::vector<Combatant*>::iterator itcombat = combatants.begin(); itcombat != combatants.end(); ++itcombat) { Combatant* combatant = *itcombat; if(combatant->getShipType() == 0) { //special for planets std::map<objectid_t, bool>::iterator itplanet = colonydead.find(combatant->getObject()); if(itplanet == colonydead.end()) { colonydead[combatant->getObject()] = combatant->isDead(); } else { itplanet->second &= combatant->isDead(); } } else if(combatant->isDead()) { IGObject::Ptr obj = objectcache[combatant->getObject()]; Fleet* fleet = dynamic_cast<Fleet*>(obj->getObjectBehaviour()); if(fleet != NULL) { fleet->removeShips(combatant->getShipType(), 1); if(fleet->totalShips() == 0) { //the fleet dead //message player msgstrings[combatant->getOwner()] += str(boost::format("Your fleet %1% was destroyed. ") % obj->getName()); //remove object uint32_t queueid = static_cast<OrderQueueObjectParam*>(obj->getParameterByType(obpT_Order_Queue))->getQueueId(); OrderQueue::Ptr queue = Game::getGame()->getOrderManager()->getOrderQueue(queueid); queue->removeOwner(combatant->getOwner()); queue->removeAllOrders(); Game::getGame()->getObjectManager()->scheduleRemoveObject(obj->getID()); Game::getGame()->getPlayerManager()->getPlayer(fleet->getOwner())->getPlayerView()->removeOwnedObject(obj->getID()); } } } else { if(damagemap.find(combatant->getObject()) == damagemap.end()) { damagemap[combatant->getObject()] = combatant->getDamage(); } else { damagemap[combatant->getObject()] += combatant->getDamage(); } } } for(std::map<objectid_t, uint32_t>::iterator itobj = damagemap.begin(); itobj != damagemap.end(); ++itobj) { IGObject::Ptr obj = objectcache[itobj->first]; Fleet* fleet = dynamic_cast<Fleet*>(obj->getObjectBehaviour()); if(fleet == NULL) { warningLog("Fleet was not a fleet"); continue; } fleet->setDamage(itobj->second); } for(std::map<objectid_t, bool>::iterator itplanet = colonydead.begin(); itplanet != colonydead.end(); ++itplanet) { if(itplanet->second) { IGObject::Ptr obj = objectcache[itplanet->first]; Planet* planet = dynamic_cast<Planet*>(obj->getObjectBehaviour()); if(planet == NULL) { warningLog("Planet was not a planet"); continue; } resourcetypeid_t homeplanetres = Game::getGame()->getResourceManager()->getResourceDescription("Home Planet")->getResourceType(); bool ishomeplanet = (planet->getResource(homeplanetres) == 1); //planet has fallen if(ishomeplanet) { planet->removeResource(homeplanetres, 1); } uint32_t oldowner = planet->getOwner(); planet->setOwner(0); uint32_t queueid = static_cast<OrderQueueObjectParam*>(obj->getParameterByType(obpT_Order_Queue))->getQueueId(); OrderQueue::Ptr queue = Game::getGame()->getOrderManager()->getOrderQueue(queueid); queue->removeOwner(oldowner); queue->removeAllOrders(); Game::getGame()->getPlayerManager()->getPlayer(oldowner)->getPlayerView()->removeOwnedObject(obj->getID()); } } }
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; }