本文整理汇总了C++中Planet::addResource方法的典型用法代码示例。如果您正苦于以下问题:C++ Planet::addResource方法的具体用法?C++ Planet::addResource怎么用?C++ Planet::addResource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Planet
的用法示例。
在下文中一共展示了Planet::addResource方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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());
//.........这里部分代码省略.........
示例3: 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;
}
示例4: createBoard
void taeRuleset::createBoard(string path, uint32_t galaxy) {
Game* game = Game::getGame();
ObjectManager* obm = game->getObjectManager();
ObjectTypeManager* obtm = game->getObjectTypeManager();
stack<string> lines;
string line;
int row = 0;
ifstream file (path.c_str());
//Attempt to read in a custom map
if (file.is_open())
{
while(!file.eof()) {
getline (file,line);
lines.push(line);
}
if(lines.top().compare("") == 0) {
lines.pop();
}
file.close();
} else {
//Build default map
lines.push(string("....MMMMM.A.M..."));
lines.push(string(".A..M.......M..A"));
lines.push(string("...MMA......MM.."));
lines.push(string("MMMM.........MMM"));
lines.push(string(".............AMM"));
lines.push(string("..............M."));
lines.push(string("MMMM....A...MMM."));
lines.push(string(".A.MMMM.....M..."));
lines.push(string("......MMMMMMM.A."));
lines.push(string(".....A.........."));
lines.push(string("..........A....."));
}
while(!lines.empty()) {
line = lines.top();
lines.pop();
for(int i = 0; i < line.length(); i++) {
//Create a star system
IGObject* sys1 = obm->createNewObject();
obtm->setupObject(sys1, obtm->getObjectTypeByName("Star System"));
StarSystem* sys1ob = (StarSystem*)(sys1->getObjectBehaviour());
sys1ob->setSize(60000ll);
char* name = new char[8];
sprintf(name, "%d, %d", i, row);
sys1->setName(name);
sys1ob->setPosition(Vector3d(1ll + 80000ll*i, 1ll+80000ll*(row+1), 0ll));
sys1ob->setDestroyed(false);
sys1->addToParent(galaxy);
obm->addObject(sys1);
//Create a planet
IGObject *p = obm->createNewObject();
obtm->setupObject(p, obtm->getObjectTypeByName("Planet"));
Planet * pob = (Planet*)(p->getObjectBehaviour());
pob->setSize(2);
char* planetName = new char[20];
sprintf(planetName, "Planet %d, %d", i, row);
p->setName(planetName);
pob->setPosition(sys1ob->getPosition());
OrderQueue *planetoq = new OrderQueue();
planetoq->setObjectId(p->getID());
planetoq->addOwner(0);
game->getOrderManager()->addOrderQueue(planetoq);
OrderQueueObjectParam* oqop = static_cast<OrderQueueObjectParam*>(p->getParameterByType(obpT_Order_Queue));
oqop->setQueueId(planetoq->getQueueId());
pob->setDefaultOrderTypes();
p->addToParent(sys1->getID());
obm->addObject(p);
if(line[i] == '.') {
sys1ob->setInhabitable(true);
} else if (line[i] == 'M') {
sys1ob->setInhabitable(false);
pob->addResource(1,1);
} else if (line[i] == 'A') {
sys1ob->setInhabitable(true);
sys1ob->setRegion(sys1->getID());
pob->addResource(3,1);
pob->addResource(5,1);
}
}
row++;
}
}