本文整理匯總了C++中ObjectManager::getObjectsByPos方法的典型用法代碼示例。如果您正苦於以下問題:C++ ObjectManager::getObjectsByPos方法的具體用法?C++ ObjectManager::getObjectsByPos怎麽用?C++ ObjectManager::getObjectsByPos使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ObjectManager
的用法示例。
在下文中一共展示了ObjectManager::getObjectsByPos方法的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:
std::map<uint32_t, std::pair<std::string, uint32_t> > LoadArmament::generateListOptions(){
Logger::getLogger()->debug("Entering LoadArmament::generateListOptions");
std::map<uint32_t, std::pair<std::string, uint32_t> > options;
Game* game = Game::getGame();
IGObject::Ptr selectedObj = game->getObjectManager()->getObject(
game->getOrderManager()->getOrderQueue(orderqueueid)->getObjectId());
Fleet* fleet = dynamic_cast<Fleet*>(selectedObj->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);
for (std::set<uint32_t>::iterator itcurr = objs.begin(); itcurr != objs.end(); ++itcurr) {
if (obman->getObject(*itcurr)->getType() == otman->getObjectTypeByName("Planet")) {
IGObject::Ptr planetObj = obman->getObject(*itcurr);
Planet* planet = dynamic_cast<Planet*>(planetObj->getObjectBehaviour());
Logger::getLogger()->debug("Found Planet %s for Load Armaments Order", planetObj->getName().c_str());
std::map<uint32_t, std::pair<uint32_t, uint32_t> > reslist = planet->getResources();
for (std::map<uint32_t, std::pair<uint32_t, uint32_t> >::iterator it = reslist.begin(); it != reslist.end(); ++it) {
if (resman->getResourceDescription(it->first)->getUnitSingular() == "weapon") {
options[it->first] = std::pair<std::string, uint32_t>(resman->getResourceDescription(it->first)->getNamePlural(),
planet->getResourceSurfaceValue(it->first));
}
}
}
}
Logger::getLogger()->debug("Exiting LoadArmament::generateListOptions");
return options;
}
示例3: rebuildRegion
//Recurrsively rebuilds regions given a system.
//If the system already has a region or is not occupied or
//colonized, then this function returns. Otherwise it
//sets the region based on its neighbors.
void TaeTurn::rebuildRegion(uint32_t system) {
Game* game = Game::getGame();
ObjectManager* obm = game->getObjectManager();
ObjectTypeManager* obtm = game->getObjectTypeManager();
set<uint32_t>::iterator itcurr;
IGObject::Ptr sys = obm->getObject(system);
StarSystem* sysData = (StarSystem*) sys->getObjectBehaviour();
//Check to make sure the system doesnt already have a region
if(sysData->getRegion() != 0) {
return;
}
//Check to make sure it is colonized or occupied
set<uint32_t> children = sys->getContainedObjects();
for(itcurr = children.begin(); itcurr != children.end(); itcurr++) {
IGObject::Ptr ob = obm->getObject(*itcurr);
bool resource = true;
bool occupied = false;
if(ob->getType() == obtm->getObjectTypeByName("Planet")) {
Planet* p = (Planet*) ob->getObjectBehaviour();
if(p->getResource(4) == 0 && p->getResource(5) == 0 && p->getResource(6) == 0 && p->getResource(7) == 0) {
resource = false;
}
} else if(ob->getType() == obtm->getObjectTypeByName("Fleet")) {
if(!Move::isBorderingScienceColony(sysData)) {
sendHome(*itcurr);
occupied = false;
} else {
occupied = true;
}
}
if(!(resource || occupied)) {
return;
}
}
//Check to make sure this isnt a home system
if(sys->getName().find("'s System") != string::npos) {
return;
}
//Get neighbors
set<uint32_t> regions;
set<uint32_t> emptyNeighbors;
Vector3d pos = sysData->getPosition();
//east-west neighbors
for(int i = -1; i < 2; i+=2) {
set<uint32_t> ids = obm->getObjectsByPos(pos+Vector3d(80000*i,0,0), 1);
for(set<uint32_t>::iterator j=ids.begin(); j != ids.end(); j++) {
IGObject::Ptr tempObj = obm->getObject(*j);
if(tempObj->getType() == obtm->getObjectTypeByName("Star System")) {
uint32_t r = ((StarSystem*)(tempObj->getObjectBehaviour()))->getRegion();
if(r == 0) {
emptyNeighbors.insert(*j);
} else if (regions.count(r) == 0) {
regions.insert(r);
}
}
}
}
//north-south neighbors
for(int i = -1; i < 2; i+=2) {
set<uint32_t> ids = obm->getObjectsByPos(pos+Vector3d(0,80000*i,0), 1);
for(set<uint32_t>::iterator j=ids.begin(); j != ids.end(); j++) {
IGObject::Ptr tempObj = obm->getObject(*j);
if(tempObj->getType() == obtm->getObjectTypeByName("Star System")) {
uint32_t r = ((StarSystem*)(tempObj->getObjectBehaviour()))->getRegion();
if(r == 0) {
emptyNeighbors.insert(*j);
} else if (regions.count(r) == 0) {
regions.insert(r);
}
}
}
}
//Set Region
if(regions.size() == 0) {
//If neighbors have no region, then create a new region
sysData->setRegion(sys->getID());
stringstream out;
out << sysData->getRegion();
Logger::getLogger()->debug(string("System " + sys->getName() + " added to region " + out.str()).c_str());
} else if(regions.size() == 1) {
//If it neighbors 1 region, then set as that region
sysData->setRegion(*(regions.begin()));
stringstream out;
out << sysData->getRegion();
Logger::getLogger()->debug(string("System " + sys->getName() + " added to region " + out.str()).c_str());
} else {
//It should never border more than one region. If it reaches this point, then there is an error somewhere
Logger::getLogger()->debug(string("** Unable to rebuild region! System, " + sys->getName() + " is bordering more than one region! ***").c_str());
}
//.........這裏部分代碼省略.........
示例4: initCombat
//Setup the next turn to be ready for combat
void TaeTurn::initCombat() {
std::set<uint32_t>::iterator itcurr;
Game* game = Game::getGame();
ObjectManager* objectmanager = game->getObjectManager();
PlayerManager::Ptr playermanager = game->getPlayerManager();
ObjectTypeManager* obtm = game->getObjectTypeManager();
DesignStore::Ptr ds = game->getDesignStore();
//Pop the combat queue and set the combatants
pair<bool, map<uint32_t, uint32_t> > temp;
temp = combatQueue.front();
combatQueue.pop();
isInternal = temp.first;
combatants = temp.second;
strength.clear();
for(map<uint32_t, uint32_t>::iterator i = combatants.begin(); i != combatants.end(); ++i) {
IGObject::Ptr ob = Game::getGame()->getObjectManager()->getObject(i->first);
Fleet* f = (Fleet*) ob->getObjectBehaviour();
strength[f->getOwner()] = 0;
}
set<uint32_t> owners;
set<uint32_t> regions;
string shipType;
for(map<uint32_t, uint32_t>::iterator i = combatants.begin(); i != combatants.end(); ++i) {
IGObject::Ptr ob = objectmanager->getObject(i->first);
Fleet* leader = (Fleet*) (ob)->getObjectBehaviour();
//look for the shiptype which this combat is associated with
if(shipType.empty()) {
if(isInternal) {
shipType = "ScientistShip";
} else {
//Set shiptype to the type corresponding to the leader
uint32_t ship = leader->getShips().begin()->first;
shipType = ds->getDesign(ship)->getName();
size_t pos = shipType.find("Leader");
if(pos != shipType.npos) {
shipType.erase(pos, 6);
}
}
}
owners.insert(leader->getOwner());
//Set which regions are involved in combat
if(regions.count(i->second) <= 0) {
regions.insert(i->second);
}
//Set initial internal combat strength
if(isInternal) {
IGObject::Ptr starSys = objectmanager->getObject(ob->getParent());
StarSystem* starSysData = (StarSystem*)(starSys->getObjectBehaviour());
Vector3d pos = starSysData->getPosition();
//Search for bordering science colonies
//east-west neighbors
for(int i = -1; i < 2; i+=2) {
set<uint32_t> ids = objectmanager->getObjectsByPos(pos+Vector3d(80000*i,0,0), 1);
for(set<uint32_t>::iterator j=ids.begin(); j != ids.end(); j++) {
IGObject::Ptr tempObj = objectmanager->getObject(*j);
if(tempObj->getType() == obtm->getObjectTypeByName("Planet")) {
Planet* p = (Planet*)(tempObj->getObjectBehaviour());
if(p->getResource(5) > 0) {
addReinforcement(leader->getOwner());
}
}
}
}
//north-south neighbors
for(int i = -1; i < 2; i+=2) {
set<uint32_t> ids = objectmanager->getObjectsByPos(pos+Vector3d(0,80000*i,0), 1);
for(set<uint32_t>::iterator j=ids.begin(); j != ids.end(); j++) {
IGObject::Ptr tempObj = objectmanager->getObject(*j);
if(tempObj->getType() == obtm->getObjectTypeByName("Planet")) {
Planet* p = (Planet*)(tempObj->getObjectBehaviour());
if(p->getResource(5) > 0) {
addReinforcement(leader->getOwner());
}
}
}
}
}
}
//Set which resource will be awarded
int resourceType;
if(shipType.compare("MerchantShip") == 0) {
resourceType = 4;
} else if(shipType.compare("ScientistShip") == 0) {
resourceType = 5;
} else if(shipType.compare("SettlerShip") == 0) {
resourceType = 6;
} else {
resourceType = 7;
}
//Set all fleets to combat mode. Flag the fleets whose owners are
//directly involved in combat.
std::set<uint32_t> views;
//.........這裏部分代碼省略.........