void AVACombat::resolveCombat(Fleet* fleet){ Logger::getLogger()->debug("AVACombat::resolveCombat : Entering"); Game* game = Game::getGame(); DesignStore::Ptr ds = game->getDesignStore(); typedef std::map<uint32_t, uint32_t> shipList; shipList ships = fleet->getShips(); uint32_t damage = fleet->getDamage(); uint32_t hpPropID = ds->getPropertyByName("HitPoints"); for (shipList::reverse_iterator itcurr = ships.rbegin(); itcurr != ships.rend(); ++itcurr){ uint32_t shipNumber = itcurr->first; uint32_t shipQuantity = itcurr->second; Logger::getLogger()->debug("Working on ship %s", ds->getDesign(shipNumber)->getName().c_str()); uint32_t damageNeeded = static_cast<uint32_t>(ds->getDesign(shipNumber)->getPropertyValue(hpPropID)); Logger::getLogger()->debug("Damage needed to destroy this ship: %d Damage available: %d", damageNeeded, damage); if (damage >= damageNeeded) { uint32_t factor = damage % damageNeeded; if (factor > shipQuantity) { factor = shipQuantity; } fleet->removeShips(shipNumber, factor); fleet->setDamage(damage - (damageNeeded*factor)); Logger::getLogger()->debug("Damage is greater than a ship can take, Total(%d), Delivering(%d), factor (%d), new setDamage(%d)", damage, damageNeeded*factor, factor, fleet->getDamage()); } } Logger::getLogger()->debug("AVACombat::resolveCombat : Exiting"); }
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"); } }
bool xmlImport::importComps() { TiXmlDocument doc(xmlFile.c_str()); if(!doc.LoadFile()){ Logger::getLogger()->debug("Error: could not load components XML file"); return false; } TiXmlElement* pElem; TiXmlElement* pChild; TiXmlHandle hDoc(&doc); TiXmlHandle hRoot(0); DesignStore::Ptr ds = Game::getGame()->getDesignStore(); int count=0; // item count pElem = hDoc.FirstChildElement("components").Element(); if(!pElem) return false; hRoot = TiXmlHandle(pElem); for(pElem=hRoot.FirstChild("comp").Element(); pElem != NULL; pElem = pElem->NextSiblingElement()) { TiXmlElement* pCur = 0; std::string compName, compDescription, compTpcl, compIDName; std::map<uint32_t, std::string> propertylist; pChild = hRoot.Child("comp",count).Element(); //debug: cout << "count: " << count << endl; if(pChild) { //read and set the name of the component pCur = pChild->FirstChildElement("name"); if (pCur) { compName = pCur->GetText(); if (compName.empty()) return false; } else { return false; } //read and set the ID of the component pCur = pChild->FirstChildElement("ComponentIDName"); if (pCur) { compIDName = pCur->GetText(); if (compIDName.empty()) return false; } else { return false; } //read and set the description of the component pCur = pChild->FirstChildElement("description"); if (pCur) { compDescription = pCur->GetText(); if (compDescription.empty()) return false; } else { return false; } //read and set the tpclRequirementsFunction of the component pCur = pChild->FirstChildElement("tpclRequirementsFunction"); if (pCur) { compTpcl = pCur->GetText(); if (compTpcl.empty()) return false; } else { return false; } //read and set the tpclRequirementsFunction of the component pCur = pChild->FirstChildElement("propertylist"); if (pCur) { TiXmlElement* pElem; for(pElem=pCur->FirstChildElement(); pElem != NULL; pElem=pElem->NextSiblingElement()) { std::string pKey=pElem->Value(); std::string pText=pElem->GetText(); if (!pKey.empty() && !pText.empty()) { propertylist[ds->getPropertyByName(pKey)] = pText; } else { return false; } } } else { return false; } //do the component Component::Ptr comp( new Component() ); comp->addCategoryId(ds->getCategoryByName(compIDName)); comp->setName(compName); comp->setDescription(compDescription); comp->setTpclRequirementsFunction(compTpcl); comp->setPropertyList(propertylist); ds->addComponent(comp); } else { return false; } count++; } return true; }
// This routine handles one combat round. // fleets[2] are the combatants. // msgs[0] is sent to the owner of fleet1, // msgs[1] is sent to the owner of fleet2. // // Assume that 'number of missiles/torpedoes a ship can carry' // really means 'number of missiles/torpedoes a ship can fire in one round'. // Ships have an infinite amount of ammunition. // // Further assume that everyone fires his/her full load, // then all the damage is done. No 'this ship was destroyed // in this round, so it can't fire any missiles'. // // I keep (for now) the policy of always targetting the largest // ship. // // Likelihood of (correct) impact is 100% for missiles, and // (1-dodge likelihood) for torpedoes. // // How about armor as a recurring damage absorber? Like // 20HP of damage hitting a ship that has 5HP of armor // results in only 15HP of damage to that ship. The next // round, another 15HP of damage hits the ship, resulting // in another 10HP of damage. The armor itself is not // damaged until the ship is destroyed. // // Keep the same damage effects? Ships are at full // capacity until they are destroyed? // // All that being said, I decreased the damage the two sides // do to each other by a random 0-39% because I wanted some // randomness involved. bool AVACombat::doCombatRound( Fleet* fleet1, Message::Ptr msg1, Fleet* fleet2, Message::Ptr msg2) { Logger::getLogger()->debug("doCombatRound Entering"); Game* game = Game::getGame(); DesignStore::Ptr ds = game->getDesignStore(); ResourceManager::Ptr resman = game->getResourceManager(); typedef std::map<uint32_t, std::pair<uint32_t, uint32_t> > weaponList; // ID/TYPE AMOUNT typedef std::map<uint32_t, uint32_t> shipList; std::map<uint32_t, std::string> tubes; tubes[ds->getPropertyByName("AlphaMissileTube")] = "AlphaMissileTube"; tubes[ds->getPropertyByName("BetaMissileTube")] = "BetaMissileTube"; tubes[ds->getPropertyByName("GammaMissileTube")] = "GammaMissileTube"; tubes[ds->getPropertyByName("DeltaMissileTube")] = "DeltaMissileTube"; tubes[ds->getPropertyByName("EpsilonMissileTube")] = "EpsilonMissileTube"; tubes[ds->getPropertyByName("OmegaTorpedoeTube")] = "OmegaTorpedoeTube"; tubes[ds->getPropertyByName("UpsilonTorpedoeTube")] = "UpsilonTorpedoeTube"; tubes[ds->getPropertyByName("TauTorpedoeTube")] = "TauTorpedoeTube"; tubes[ds->getPropertyByName("SigmaTorpedoeTube")] = "SigmaTorpedoeTube"; tubes[ds->getPropertyByName("RhoTorpedoeTube")] = "RhoTorpedoeTube"; tubes[ds->getPropertyByName("XiTorpedoeTube")] = "XiTorpedoeTube"; std::map<uint32_t, uint32_t> tubeList; std::set<Design::Ptr> designList; weaponList fleetweaponry[2]; shipList fleetships[2]; Fleet* fleets[2]; std::map<uint32_t, std::pair<std::string, uint32_t> > fleettubes[2]; std::map<uint32_t, uint32_t> fleetusable[2]; // resourceid, designid fleetweaponry[0] = fleet1->getResources(); fleetweaponry[1] = fleet2->getResources(); fleetships[0] = fleet1->getShips(); fleetships[1] = fleet2->getShips(); fleets[0] = fleet1; fleets[1] = fleet2; uint32_t damage[2] = {0}; for (int i=0; i < 2; i++) { for (shipList::iterator itcurr = fleetships[i].begin(); itcurr != fleetships[i].end(); ++itcurr) { for (std::map<uint32_t, std::string>::iterator tubeit = tubes.begin(); tubeit != tubes.end(); ++tubeit) { if (ds->getDesign(itcurr->first)->getPropertyValue(tubeit->first) > 0.0) { Logger::getLogger()->debug("Found usable Tube %s, inserting into Fleet %d", tubeit->second.c_str(), i); //size of weapon uint32_t weapSizePropID = ds->getPropertyByName(tubeit->second); uint32_t weapNumPropID = ds->getPropertyByName("num-" + tubeit->second); uint32_t weapSizePropValue = static_cast<uint32_t>(ds->getDesign(itcurr->first)->getPropertyValue(weapSizePropID)); uint32_t weapNumPropValue = static_cast<uint32_t>(ds->getDesign(itcurr->first)->getPropertyValue(weapNumPropID)); if (fleettubes[i].find(weapSizePropValue) != fleettubes[i].end()) { std::pair<std::string, uint32_t>fleetpair = fleettubes[i][weapSizePropValue]; fleetpair.second += weapNumPropValue; fleettubes[i][weapSizePropValue] = fleetpair; Logger::getLogger()->debug("Adding %d into Tube List", weapSizePropValue); } else { fleettubes[i][weapSizePropValue] = std::pair<std::string, uint32_t> (tubeit->second, weapNumPropValue); } } } for (weaponList::iterator weapit = fleetweaponry[i].begin(); weapit != fleetweaponry[i].end(); ++weapit) { Design::Ptr weapDesign; std::string weapName = resman->getResourceDescription(weapit->first)->getNameSingular(); std::set<uint32_t>dIDs = ds->getDesignIds(); for (std::set<uint32_t>::iterator dit = dIDs.begin(); dit != dIDs.end(); ++dit) { if (weapName == ds->getDesign(*dit)->getName()) { weapDesign = ds->getDesign(*dit); Logger::getLogger()->debug("Found design %s", weapDesign->getName().c_str()); for (std::map<uint32_t, std::pair<std::string, uint32_t> >::iterator tubeit = fleettubes[i].begin(); tubeit != fleettubes[i].end(); ++tubeit) { //property ID, name of the TUBE uint32_t propID = ds->getPropertyByName("MissileSize"); //Logger::getLogger()->debug("Checking fleettubes list for propID %s", ds->getProperty(propID)->getName().c_str()); uint32_t weapPropVal = static_cast<uint32_t>(weapDesign->getPropertyValue(propID)); if (fleettubes[i].find(weapPropVal) != fleettubes[i].end()) { Logger::getLogger()->debug("Found it, trying to remove resource %d from fleet", weapit->first); fleetusable[i][weapit->first] = weapDesign->getDesignId(); if (fleets[i]->removeResource(weapit->first, 1)) { uint32_t explPropID = ds->getPropertyByName("AmmoExplosiveness"); //damage to be deliveredt damage[!i] += static_cast<uint32_t>(weapDesign->getPropertyValue(explPropID)); Logger::getLogger()->debug("Adding Damage (%d) Total (%d)", static_cast<uint32_t>(weapDesign->getPropertyValue(explPropID)), damage[!i]); } else { Logger::getLogger()->debug("No available Weapon for this tube!"); } } } } } } } } fleet1->setDamage(damage[0]); fleet2->setDamage(damage[1]); resolveCombat(fleet1); resolveCombat(fleet2); //Tube format: std::map<double, std::pair<std::string, uint32_t> > // tube size name number bool tte = false; std::string body[2]; if (fleet1->totalShips() == 0) { body[0] += "Your fleet was destroyed. "; body[1] += "You destroyed their fleet. "; c1.reset(); tte = true; }; if (fleet2->totalShips() == 0) { body[0] += "Your fleet was destroyed."; body[1] += "You destroyed their fleet."; c2.reset(); tte = true; } if ( tte) { msg1->setBody( body[0]); msg2->setBody( body[1]); } Logger::getLogger()->debug("doCombatRound Exiting"); return false; }
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; }