本文整理汇总了C++中IdMap::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ IdMap::begin方法的具体用法?C++ IdMap::begin怎么用?C++ IdMap::begin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IdMap
的用法示例。
在下文中一共展示了IdMap::begin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addDesign
bool DesignStore::addDesign(Design::Ptr d){
d->setDesignId(next_designid++);
//check components all come from this category
IdMap cl = d->getComponents();
Player::Ptr player = Game::getGame()->getPlayerManager()->getPlayer(d->getOwner());
PlayerView::Ptr playerview = player->getPlayerView();
for(IdMap::iterator itcurr = cl.begin();
itcurr != cl.end(); ++itcurr){
if(!(playerview->isUsableComponent(itcurr->first)))
return false;
std::map<uint32_t, Component::Ptr>::iterator itcomp = components.find(itcurr->first);
if(itcomp == components.end())
return false;
getComponent(itcurr->first)->setInUse();
}
d->eval();
designs[d->getId()] = d;
getCategory(d->getCategoryId())->doAddDesign(d);
if(d->isValid()){
playerview->addUsableDesign(d->getId());
}else{
playerview->addVisibleDesign( DesignView::Ptr( new DesignView( d->getId(), true )) );
}
Game::getGame()->getPlayerManager()->updatePlayer(player->getID());
Game::getGame()->getPersistence()->saveDesign(d);
return true;
}
示例2: 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;
}
示例3: valmap_bind
ValueMap valmap_bind(IdMap &id, unsigned int code) {
ValueMap valmap;
unsigned int mask = 1;
for (auto it = id.begin(); it != id.end(); ++it, mask <<= 1) {
valmap[it->first] = (code & mask) == mask;
}
return valmap;
}
示例4: modifyDesign
bool DesignStore::modifyDesign(Design::Ptr d){
Design::Ptr current = designs[d->getId()];
if(!current || current->getOwner() != d->getOwner() || current->getNumExist() != 0 || current->getInUse() != 0)
return false;
Player::Ptr player = Game::getGame()->getPlayerManager()->getPlayer(d->getOwner());
PlayerView::Ptr playerview = player->getPlayerView();
playerview->removeUsableDesign(d->getId());
IdMap cl = current->getComponents();
for(IdMap::iterator itcurr = cl.begin(); itcurr != cl.end(); ++itcurr){
components[itcurr->first]->setInUse(false);
}
for(IdMap::iterator itcurr = cl.begin(); itcurr != cl.end(); ++itcurr){
if(!(playerview->isUsableComponent(itcurr->first)))
return false;
std::map<uint32_t, Component::Ptr>::iterator itcomp = components.find(itcurr->first);
if(itcomp == components.end())
return false;
itcomp->second->setInUse();
}
d->eval();
bool rtv;
if(getCategory(d->getCategoryId())->doModifyDesign(d)){
designs[d->getId()] = d;
rtv = true;
}else{
d = current;
rtv = false;
}
if(d->isValid()){
playerview->addUsableDesign(d->getId());
}
Game::getGame()->getPlayerManager()->updatePlayer(player->getID());
Game::getGame()->getPersistence()->updateDesign(d);
return rtv;
}
示例5:
bool
ExtModelReferenceCycles::alreadyExistsInMap(IdMap map,
pair<const std::string, std::string> dependency)
{
bool exists = false;
IdIter it;
for (it = map.begin(); it != map.end(); it++)
{
if (((*it).first == dependency.first)
&& ((*it).second == dependency.second))
exists = true;
}
return exists;
}
示例6:
bool
FunctionDefinitionRecursion::alreadyExistsInMap(IdMap map,
pair<const std::string, std::string> dependency)
{
bool exists = false;
IdIter it;
for (it = map.begin(); it != map.end(); it++)
{
if (((*it).first == dependency.first)
&& ((*it).second == dependency.second))
exists = true;
}
return exists;
}
示例7: main
int main(int argc, char **argv)
{
IdMap idmap;
ValueMap valmap;
int permutations_size = 0;
// Call the parser
yyparse();
if (root == NULL) {
return 1;
}
// Find and print some information about identifiers
std::cout << root->prettyPrint() << std::endl;
find_identifiers(*root, idmap);
std::cout << "Found " << idmap.size() << " unique identifiers" << std::endl;
for (auto it = idmap.begin(); it != idmap.end(); ++it) {
std::cout << it->first << ": " << it->second.size() << " occurrences" << std::endl;
}
// Check how many boolean permutations we need to generate
if (idmap.size() <= 2) {
permutations_size = 2;
} else if (idmap.size() <= 4) {
permutations_size = 4;
} else {
std::cout << "More than 4 identifiers not supported yet." << std::endl;
return 2;
}
std::cout << "Generating a lut" << permutations_size << "." << std::endl;
// Bind each possible permutation and evaluate the function
std::cout << "0";
for(unsigned int i = 0; i < permutations_size * permutations_size; ++i) {
valmap = valmap_bind(idmap, i);
std::cout << evaluate(*root, valmap);
}
std::cout << std::endl;
return 0;
}
示例8: inputFrame
void Build::inputFrame(InputFrame::Ptr f, uint32_t playerid)
{
Order::inputFrame(f, playerid);
Player::Ptr player = Game::getGame()->getPlayerManager()->getPlayer(playerid);
DesignStore::Ptr ds = Game::getGame()->getDesignStore();
uint32_t bldTmPropID = ds->getPropertyByName( "BuildTime");
IdMap fleettype = fleetlist->getList();
uint32_t usedshipres = 0;
for(IdMap::iterator itcurr = fleettype.begin();
itcurr != fleettype.end(); ++itcurr) {
uint32_t type = itcurr->first;
uint32_t number = itcurr->second; // number to build
if(player->getPlayerView()->isUsableDesign(type) && number >= 0){
Design::Ptr design = ds->getDesign(type);
usedshipres += (int)(ceil(number * design->getPropertyValue(bldTmPropID)));
design->addUnderConstruction(number);
ds->designCountsUpdated(design);
}else{
throw FrameException( fec_FrameError, "The requested design was not valid.");
}
}
if(usedshipres == 0 && !fleettype.empty()){
throw FrameException( fec_FrameError, "To build was empty...");
}
resources[1] = usedshipres;
if(fleetname->getString().length() == 0){
fleetname->setString("A Fleet");
}
}
示例9: doOrder
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;
}
示例10: evalDesign
void TpMzScheme::evalDesign(Design::Ptr d){
DesignStore::Ptr ds = Game::getGame()->getDesignStore();
if (scheme_setjmp(scheme_error_buf)) {
Logger::getLogger()->warning("MzScheme Error");
} else {
Scheme_Object* temp;
std::ostringstream formater;
formater.str("");
formater << "(define-values (struct:designType make-designType designType? designType-ref designType-set!)(make-design-type "
<< ds->getMaxPropertyId() << "))";
temp = scheme_eval_string(formater.str().c_str(), env);
temp = scheme_eval_string("(define property-designType-set! (lambda (design id val) (designType-set! design (- id 1) val)))", env);
std::set<uint32_t> propids = ds->getPropertyIds();
for(std::set<uint32_t>::iterator propit = propids.begin();
propit != propids.end(); ++propit){
// for each property type
Property::Ptr p = ds->getProperty(*propit);
if(p){
formater.str("");
formater << "(define designType." << p->getName()
<< " (make-property-accessor designType-ref "
<< p->getPropertyId() << " \"" << p->getName()
<< "\" ))";
temp = scheme_eval_string(formater.str().c_str(), env);
}
}
propids.clear();
IdMap complist = d->getComponents();
temp = scheme_eval_string("(define design (make-designType))", env);
for(std::set<uint32_t>::iterator propit = propids.begin();
propit != propids.end(); ++propit){
formater.str("");
formater << "(property-designType-set! design "
<< *propit << " 0.0)";
temp = scheme_eval_string(formater.str().c_str(), env);
}
std::map<uint32_t, std::map<uint32_t, std::list<std::string> > > propranking;
for(IdMap::iterator compit = complist.begin();
compit != complist.end(); ++compit){
Component::Ptr c = ds->getComponent(compit->first);
std::map<uint32_t, std::string> pilist = c->getPropertyList();
for(std::map<uint32_t, std::string>::iterator piit = pilist.begin();
piit != pilist.end(); ++piit){
Property::Ptr p = ds->getProperty(piit->first);
for(uint32_t i = 0; i < compit->second; i++){
propranking[p->getRank()][p->getPropertyId()].push_back(piit->second);
}
}
}
std::map<uint32_t, PropertyValue> propertyvalues;
for(std::map<uint32_t, std::map<uint32_t, std::list<std::string> > >::iterator rpiit = propranking.begin();
rpiit != propranking.end(); ++rpiit){
std::map<uint32_t, std::list<std::string> > pilist = rpiit->second;
std::set<PropertyValue> localvalues;
for(std::map<uint32_t, std::list<std::string> >::iterator piit = pilist.begin();
piit != pilist.end(); ++piit){
PropertyValue propval(piit->first,0.0);
std::list<double> listvals;
std::list<std::string> lambdas = piit->second;
for(std::list<std::string>::iterator itlamb = lambdas.begin();
itlamb != lambdas.end(); ++itlamb){
temp = scheme_eval_string((std::string("(") + (*itlamb) + " design)").c_str(), env);
if(!SCHEME_NUMBERP(temp)){
Logger::getLogger()->warning("MzScheme: Return not a number");
}else{
listvals.push_back(scheme_real_to_double(temp));
}
}
Property::Ptr p = ds->getProperty(piit->first);
formater.str("");
formater << "(" << p->getTpclDisplayFunction() << " design '(";
for(std::list<double>::iterator itvals = listvals.begin();
itvals != listvals.end(); ++itvals){
formater << *itvals << " ";
}
formater << "))";
temp = scheme_eval_string(formater.str().c_str(), env);
#ifdef HAVE_MZSCHEME20X
if(!SCHEME_PAIRP(temp) || !SCHEME_NUMBERP(SCHEME_CAR(temp)) || !SCHEME_STRINGP(SCHEME_CDR(temp))){
#else
if(!SCHEME_PAIRP(temp) || !SCHEME_NUMBERP(SCHEME_CAR(temp)) || !SCHEME_CHAR_STRINGP(SCHEME_CDR(temp))){
#endif
Logger::getLogger()->warning("MzScheme: Return not a pair, or the wrong time in the pair");
}else{
propval.setValue(scheme_real_to_double(SCHEME_CAR(temp)));
#ifdef HAVE_MZSCHEME20X
//.........这里部分代码省略.........
示例11: debug
//This function gets the top bid for the given object
pair<IGObject::Ptr ,uint32_t> Colonize::getTopPlayerAndBid(IGObject::Ptr obj) {
pair<IGObject::Ptr ,uint32_t> result;
result.second = 0;
Planet* origin = dynamic_cast<Planet*>(obj->getObjectBehaviour());
assert(origin);
Logger::getLogger()->debug("\tCollecting all bids on object %s",origin->getName().c_str());
Game* game = Game::getGame();
OrderManager* ordM = game->getOrderManager();
ObjectManager* objM = game->getObjectManager();
//Construct the map to be used, the identifier is the planet, the value is the bid
map<IGObject::Ptr ,uint32_t> bids;
//Get all objects from object manager
set<uint32_t> objectsIds = objM->getAllIds();
//Iterate over every object
for(set<uint32_t>::iterator i = objectsIds.begin(); i != objectsIds.end(); ++i)
{
//Get current object
IGObject::Ptr currObj = objM->getObject(*i);
//Print out current planet
Planet* bidder = dynamic_cast<Planet*>(currObj->getObjectBehaviour());
if (bidder != NULL) {
Logger::getLogger()->debug("\t\tLooking at orders on object %s",bidder->getName().c_str());
}
//Get order queue from object
OrderQueueObjectParam* oqop = dynamic_cast<OrderQueueObjectParam*>(currObj->getParameterByType(obpT_Order_Queue));
OrderQueue::Ptr oq;
//Validate that the oq exists
if(oqop != NULL && (oq = ordM->getOrderQueue(oqop->getQueueId())) != NULL)
{
//Iterate over all orders
for (uint32_t j = 0; j < oq->getNumberOrders(); j++)
{
OwnedObject *orderedObj = dynamic_cast<OwnedObject*>(currObj->getObjectBehaviour());
Order* order = NULL;
if ( orderedObj != NULL ) {
order = oq->getOrder(j, orderedObj->getOwner());
}
Logger::getLogger()->debug("\t\tThere exists a %s order on %s", order->getName().c_str(), bidder->getName().c_str());
//if order is a colonize order
if( order != NULL && order->getName() == "Colonize")
{
Colonize* colonize = dynamic_cast<Colonize*>(order);
assert(colonize);
//Get the list of planetIDs and the # of units to move
IdMap list = colonize->getTargetList()->getList();
//Iterate over all suborders
for(IdMap::iterator i = list.begin(); i != list.end(); ++i) {
uint32_t planetID = i->first;
uint32_t numUnits = i->second;
format debug("\t\t\tEncountered suborder to Colonize %1% with %2% units");
debug % planetID; debug % numUnits;
Logger::getLogger()->debug(debug.str().c_str());
IGObject::Ptr target = Game::getGame()->getObjectManager()->getObject(planetID);
if ( target == obj ) {
bids[currObj] += numUnits;
}
}
}
else if ( order->getName() != "Colonize")
{
j = oq->getNumberOrders() + 1; //force the loop to exit, we have "left" the frontal Colonize orders
}
}
currObj->touchModTime();
}
objM->doneWithObject(currObj->getID());
}
//Iterate over all bids and restrict them to the maximum armies availible on that planet
for(map<IGObject::Ptr ,uint32_t>::iterator i = bids.begin(); i != bids.end(); ++i) {
Logger::getLogger()->debug("Iterating over all bids to pick the highest legal bid.");
//FIXME: Somewhere in this "for" the server crashes when a single bid is created for 1 unit when planet only has 1 unit left
//Restrict players bid to 1 less than their current reinforcements
Planet* planet = dynamic_cast<Planet*>(i->first->getObjectBehaviour());
assert(planet);
result.first = i->first;
uint32_t numUnits = i->second;
uint32_t maxUnits = planet->getResource("Army").first;
//If there is overflow of numUnits, check for maxUnits over 0 insures we don't set unsigned to < 0
if ( numUnits >= maxUnits && maxUnits > 0) {
if ( maxUnits > 0)
//.........这里部分代码省略.........
示例12: doOrder
bool Colonize::doOrder(IGObject::Ptr obj) {
bool result = true;
--turns;
Planet* origin = dynamic_cast<Planet*>(obj->getObjectBehaviour());
assert(origin);
Logger::getLogger()->debug("Starting a Colonize::doOrder on %s.",origin->getName().c_str());
//Get the list of objects and the # of units to colonize
IdMap list = targetPlanet->getList();
//Collect all of the players bids and restrain them to 1 less than the current units
map<IGObject::Ptr ,uint32_t> bids;
for(IdMap::iterator i = list.begin(); i != list.end(); ++i) {
uint32_t planetID = i->first;
uint32_t numUnits = i->second;
IGObject::Ptr target = Game::getGame()->getObjectManager()->getObject(planetID);
//Restrain the number of units moved off of origin
uint32_t maxUnits = origin->getResource("Army").first;
numUnits = numUnits + bids[target]; //Add current bid on target to requests units (no tricksy bidding!)
if ( numUnits >= maxUnits && maxUnits > 0) {
if ( maxUnits > 0)
numUnits = maxUnits - 1;
else
numUnits = 0;
}
bids[target] = numUnits;
}
//for each seperate planet bid on run the bid routine
for(map<IGObject::Ptr ,uint32_t>::iterator i = bids.begin(); i != bids.end(); ++i) {
Logger::getLogger()->debug("\tStarting to iterate over all players bids");
Planet* biddedPlanet = dynamic_cast<Planet*>(i->first->getObjectBehaviour());
assert(biddedPlanet);
//Ensure the object IS a planet and the object is unowned
//The object MAY be owned if a bid has occured and a winner was chosen
//then all other bids on that planet will simply be ignored
if ( biddedPlanet != NULL && biddedPlanet->getOwner() == 0) {
Logger::getLogger()->debug("\tGetting the top player and bid for planet %s",biddedPlanet->getName().c_str());
//Get pair <owner's planet,bid> of top bidder
pair<IGObject::Ptr ,uint32_t> topBidder = getTopPlayerAndBid(i->first);
//Check if players bid is bigger than top bidder elsewhere - only did this because I wasn't sure
//BUG: this code would force the reset of bid restriction
// if ( i->second > topBidder.second ) {
// topBidder.second = i->second;
// topBidder.first = obj;
// }
Planet* ownerPlanet = dynamic_cast<Planet*>(topBidder.first->getObjectBehaviour());
assert(ownerPlanet);
uint32_t player = ownerPlanet->getOwner();
biddedPlanet->setOwner(player);
biddedPlanet->addResource("Army",topBidder.second);
ownerPlanet->removeResource("Army",topBidder.second);
//Inform colonize winner, and obj owner
}
else //Bidded planet is now owned
{
Logger::getLogger()->debug("\tNot getting top bidders, planet is already owned");
//inform player bid failed, obj is now owned by _person_, won bid with _#units_
}
}
return result;
}
示例13: doOrder
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;
}
示例14: 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;
}
示例15: 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;
}