bool Build::doOrder(IGObject::Ptr ob) { Planet* planet = static_cast<Planet*>(ob->getObjectBehaviour()); uint32_t usedshipres = resources[1]; if(usedshipres == 0) return true; int ownerid = planet->getOwner(); if(ownerid == 0){ //currently not owned by anyone, just forget about it return true; } planet->addResource(1, 1); if(planet->removeResource(1, usedshipres)){ //create fleet Game* game = Game::getGame(); IGObject::Ptr fleet = game->getObjectManager()->createNewObject(); game->getObjectTypeManager()->setupObject(fleet, game->getObjectTypeManager()->getObjectTypeByName("Fleet")); //add fleet to container fleet->addToParent(ob->getID()); fleet->setName(fleetname->getString().c_str()); Fleet * thefleet = ((Fleet*)(fleet->getObjectBehaviour())); thefleet->setSize(2); thefleet->setOwner(ownerid); // set ownerid thefleet->setPosition(planet->getPosition()); thefleet->setVelocity(Vector3d(0LL, 0ll, 0ll)); uint32_t queueid = Game::getGame()->getOrderManager()->addOrderQueue(fleet->getID(), ownerid); OrderQueueObjectParam* oqop = static_cast<OrderQueueObjectParam*>(fleet->getParameterByType(obpT_Order_Queue)); oqop->setQueueId(queueid); thefleet->setDefaultOrderTypes(); thefleet->setIcon("common/object-icons/ship"); thefleet->setMedia("common-2d/foreign/vegastrike/ship-small/" + ((MiniSec*)(game->getRuleset()))->getFleetMediaNames()->getName()); //set ship type IdMap fleettype = fleetlist->getList(); for(IdMap::iterator itcurr = fleettype.begin(); itcurr != fleettype.end(); ++itcurr){ thefleet->addShips(itcurr->first, itcurr->second); Design::Ptr design = Game::getGame()->getDesignStore()->getDesign(itcurr->first); design->addComplete(itcurr->second); Game::getGame()->getDesignStore()->designCountsUpdated(design); } //add fleet to universe Game::getGame()->getObjectManager()->addObject(fleet); Game::getGame()->getPlayerManager()->getPlayer(ownerid)->getPlayerView()->addOwnedObject(fleet->getID()); Message::Ptr msg( new Message() ); msg->setSubject("Build Fleet order complete"); msg->setBody(std::string("The construction of your new fleet \"") + fleetname->getString() + "\" is complete."); msg->addReference(rst_Action_Order, rsorav_Completion); msg->addReference(rst_Object, fleet->getID()); msg->addReference(rst_Object, ob->getID()); Game::getGame()->getPlayerManager()->getPlayer(ownerid)->postToBoard(msg); return true; } return false; }
bool BuildFleet::doOrder(IGObject::Ptr ob) { Logger::getLogger()->debug("Entering BuildFleet::doOrder"); Planet* planet = static_cast<Planet*>(ob->getObjectBehaviour()); Game* game = Game::getGame(); ResourceManager::Ptr resman = game->getResourceManager(); const uint32_t resType = resman->getResourceDescription("Factories")->getResourceType(); const uint32_t resValue = planet->getResourceSurfaceValue(resType); int ownerid = planet->getOwner(); if(ownerid == 0){ Logger::getLogger()->debug("Exiting BuildFleet::doOrder ownerid == 0"); //currently not owned by anyone, just forget about it return true; } uint32_t runningTotal = resources[1]; if (resValue == 0) { Message::Ptr msg(new Message()); msg->setSubject("Build Fleet order error"); msg->setBody(std::string("The construction of your new fleet \"") + fleetname->getString() + "\" has been delayed, you do not have any production points this turn."); Game::getGame()->getPlayerManager()->getPlayer(ownerid)->postToBoard(msg); return false; } else if(runningTotal > resValue) { if (planet->removeResource(resType, resValue)) { removeResource(1, resValue); runningTotal = resources[1]; uint32_t planetFactories = planet->getFactoriesPerTurn(); turns = static_cast<uint32_t>(ceil(runningTotal / planetFactories)); Message::Ptr msg(new Message()); msg->setSubject("Build Fleet order slowed"); msg->setBody(std::string("The construction of your new fleet \"") + fleetname->getString() + "\" has been delayed."); Game::getGame()->getPlayerManager()->getPlayer(ownerid)->postToBoard(msg); return false; } } else if(runningTotal <= resValue && planet->removeResource(resType, runningTotal)){ //create fleet //this is probably unnecessary resources[1] = 0; Game* game = Game::getGame(); IGObject::Ptr fleet = game->getObjectManager()->createNewObject(); game->getObjectTypeManager()->setupObject(fleet, game->getObjectTypeManager()->getObjectTypeByName("Fleet")); //add fleet to container fleet->addToParent(ob->getID()); fleet->setName(fleetname->getString().c_str()); Fleet * thefleet = dynamic_cast<Fleet*>(fleet->getObjectBehaviour()); thefleet->setSize(2); thefleet->setOwner(ownerid); // set ownerid thefleet->setPosition(planet->getPosition()); thefleet->setVelocity(Vector3d(0LL, 0ll, 0ll)); uint32_t queueid = Game::getGame()->getOrderManager()->addOrderQueue(fleet->getID(), ownerid); OrderQueueObjectParam* oqop = static_cast<OrderQueueObjectParam*>(fleet->getParameterByType(obpT_Order_Queue)); oqop->setQueueId(queueid); thefleet->setDefaultOrderTypes(); //set ship type IdMap fleettype = fleetlist->getList(); for(IdMap::iterator itcurr = fleettype.begin(); itcurr != fleettype.end(); ++itcurr){ thefleet->addShips(itcurr->first, itcurr->second); Design::Ptr design = Game::getGame()->getDesignStore()->getDesign(itcurr->first); design->addComplete(itcurr->second); Game::getGame()->getDesignStore()->designCountsUpdated(design); } //add fleet to universe Game::getGame()->getObjectManager()->addObject(fleet); Game::getGame()->getPlayerManager()->getPlayer(ownerid)->getPlayerView()->addOwnedObject(fleet->getID()); Message::Ptr msg( new Message() ); msg->setSubject("Build Fleet order complete"); msg->setBody(std::string("The construction of your new fleet \"") + fleetname->getString() + "\" is complete."); msg->addReference(rst_Action_Order, rsorav_Completion); msg->addReference(rst_Object, fleet->getID()); msg->addReference(rst_Object, ob->getID()); Game::getGame()->getPlayerManager()->getPlayer(ownerid)->postToBoard(msg); Logger::getLogger()->debug("Exiting BuildFleet::doOrder on Success"); return true; } Logger::getLogger()->debug("Exiting BuildFleet::doOrder on failure"); return false; }