本文整理汇总了C++中ObjectManager::getObject方法的典型用法代码示例。如果您正苦于以下问题:C++ ObjectManager::getObject方法的具体用法?C++ ObjectManager::getObject怎么用?C++ ObjectManager::getObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObjectManager
的用法示例。
在下文中一共展示了ObjectManager::getObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: setVisibleObjects
void setVisibleObjects(Player::Ptr player) {
ObjectManager *om = Game::getGame()->getObjectManager();
IGObject::Ptr universe = om->getObject(0);
PlayerView::Ptr pv = player->getPlayerView();
set<uint32_t> ownedObjects = pv->getOwnedObjects();
// add universe and star systems
ObjectView::Ptr obv = pv->getObjectView(universe->getID());
if(!obv){
pv->addVisibleObject( universe->getID(), true );
}
uint32_t fleettype = Game::getGame()->getObjectTypeManager()->getObjectTypeByName("Fleet");
set<uint32_t> containedObjects = universe->getContainedObjects();
for(set<uint32_t>::const_iterator i = containedObjects.begin(); i != containedObjects.end(); ++i){
IGObject::Ptr object = om->getObject(*i);
obv = pv->getObjectView(*i);
if(object->getType() != fleettype){
if(!obv){
pv->addVisibleObject(*i, true );
}
}else{
if(obv && !obv->isGone()){
obv->setGone(true);
pv->updateObjectView(*i);
}
}
om->doneWithObject(*i);
}
for(set<uint32_t>::const_iterator i = ownedObjects.begin(); i != ownedObjects.end(); ++i)
{
IGObject::Ptr obj = om->getObject(*i);
if(obj->getType() != fleettype || obj->getParent() != 0){
exploreStarSys(obj);
}
om->doneWithObject(*i);
}
set<uint32_t> visobjects = pv->getVisibleObjects();
for(set<uint32_t>::const_iterator i = visobjects.begin(); i != visobjects.end(); ++i)
{
IGObject::Ptr obj = om->getObject(*i);
obv = pv->getObjectView(*i);
if(!obj){
if(!obv->isGone()){
obv->setGone(true);
pv->updateObjectView(*i);
}
}else if((!obv->isGone()) && obv->isCompletelyVisible() && obj->getModTime() > obv->getModTime()){
obv->setModTime(obj->getModTime());
pv->updateObjectView(*i);
}
if(obj != NULL){
om->doneWithObject(*i);
}
}
}
示例3: sendHome
//Sends a fleet back to it's home planet
void TaeTurn::sendHome(uint32_t fleet) {
Game* game = Game::getGame();
ObjectManager* obm = game->getObjectManager();
ObjectTypeManager* obtm = game->getObjectTypeManager();
PlayerManager::Ptr pm = game->getPlayerManager();
IGObject::Ptr fleetobj = obm->getObject(fleet);
//Check to make sure it is really a fleet
if(fleetobj->getType() != obtm->getObjectTypeByName("Fleet")) {
return;
}
//Get all the required objects
Fleet* f = (Fleet*) fleetobj->getObjectBehaviour();
Player::Ptr p = pm->getPlayer(f->getOwner());
IGObject::Ptr sys = obm->getObject(fleetobj->getParent());
StarSystem* sysData = (StarSystem*) sys->getObjectBehaviour();
//Remove fleet from system
sysData->setRegion(0);
fleetobj->removeFromParent();
//Find it's home planet
std::set<uint32_t> objects = obm->getAllIds();
std::set<uint32_t>::iterator itcurr;
for(itcurr = objects.begin(); itcurr != objects.end(); ++itcurr) {
IGObject::Ptr ob = obm->getObject(*itcurr);
if(ob->getName().compare(string(p->getName() + "'s Home Planet")) == 0) {
Planet* p = (Planet*) ob->getObjectBehaviour();
f->setPosition(p->getPosition());
fleetobj->addToParent(ob->getID());
}
}
}
示例4:
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;
}
示例5: canBeColonized
//System cannot be destroyed, occupied, or colonized in order to be able to be colonized.
//It also must be inhabitable for the colony type.
bool StarSystem::canBeColonized(bool mining) {
ObjectManager* obm = Game::getGame()->getObjectManager();
ObjectTypeManager* obtm = Game::getGame()->getObjectTypeManager();
if(isDestroyed()) {
Logger::getLogger()->debug("StarSystem->canBeColonized: System is destroyed");
return false;
}
//Grab the children and see if the system is occupied
set<uint32_t> children = obj->getContainedObjects();
uint32_t pid;
bool isOccupied = false;
for(set<uint32_t>::iterator i = children.begin(); i != children.end(); i++) {
if(obm->getObject(*i)->getType() == obtm->getObjectTypeByName("Planet")) {
pid = *i;
} else if (obm->getObject(*i)->getType() == obtm->getObjectTypeByName("Fleet")) {
isOccupied = true;
}
}
if(isOccupied) {
Logger::getLogger()->debug("StarSystem->canBeColonized: System is occupied");
return false;
}
//Check to see if the system has already been colonized
Planet* planet = (Planet*)(obm->getObject(pid)->getObjectBehaviour());
if(planet->getResource(4) > 0) {
Logger::getLogger()->debug("StarSystem->canBeColonized: System has been colonized by merchants.");
return false;
} else if(planet->getResource(5) > 0) {
Logger::getLogger()->debug("StarSystem->canBeColonized: System has been colonized by scientists.");
return false;
} else if(planet->getResource(6) > 0) {
Logger::getLogger()->debug("StarSystem->canBeColonized: System has been colonized by settlers.");
return false;
} else if(planet->getResource(7) > 0) {
Logger::getLogger()->debug("StarSystem->canBeColonized: System has been colonized by mining robots.");
return false;
}
//Check to make sure the system is inhabitable by the fleet
if(mining && planet->getResource(1) < 1) {
Logger::getLogger()->debug("StarSystem->canBeColonized: System is inhabitable and cannot be colonized by mining robots");
return false;
} else if(!mining && planet->getResource(1) > 0) {
Logger::getLogger()->debug("StarSystem->canBeColonized: System is Uninhabitable and can ONLY be colonized by mining robots");
return false;
}
return true;
}
示例6: assert
map<uint32_t, pair<string, uint32_t> > Colonize::generateListOptions() {
map<uint32_t, pair<string,uint32_t> > options;
Game* game = Game::getGame();
ObjectManager* om = game->getObjectManager();
IGObject::Ptr selectedObj = game->getObjectManager()->getObject(
game->getOrderManager()->getOrderQueue(orderqueueid)->getObjectId());
Planet* planet = dynamic_cast<Planet*>(selectedObj->getObjectBehaviour());
assert(planet);
om->doneWithObject(selectedObj->getID());
set<uint32_t> allObjs = om->getAllIds();
uint32_t availibleUnits = planet->getResource("Army").first + planet->getResource("Army").second - 1;
/* This for loop will iterate over every adjacent planet.
This is where the majority of the work occurs, and we populate our list.
You see here we select an item of the map, in my case (*i)->getID(), and
for that item we create a pair.
If its a little hard to read, here is what I am doing:
options[#] = pair<string,uint32_t>( "title", max# );
For my pair I set the title as the adjacent planet to move to, and set the
max to availible units. */
for(set<uint32_t>::iterator i = allObjs.begin(); i != allObjs.end(); i++) {
IGObject::Ptr currObj = om->getObject((*i));
Planet* owned = dynamic_cast<Planet*>(currObj->getObjectBehaviour());
if ( owned != NULL && owned->getOwner() == 0) {
options[owned->getID()] = pair<string,uint32_t>(
owned->getName(), availibleUnits );
}
}
return options;
}
示例7: ConCmd_objectInfo
void ObjectManager::ConCmd_objectInfo(const Console::ArgvType& argv)
{
if (argv.size() != 2) {
pout << "usage: objectInfo <objectnum>" << std::endl;
return;
}
ObjectManager* objman = ObjectManager::get_instance();
ObjId objid = static_cast<ObjId>(strtol(argv[1].c_str(), 0, 0));
Object* obj = objman->getObject(objid);
if (obj == 0) {
bool reserved = false;
if (objid >= 256) // CONSTANT!
reserved = objman->objIDs->isIDUsed(objid);
else
reserved = objman->actorIDs->isIDUsed(objid);
if (reserved)
pout << "Reserved objid: " << objid << std::endl;
else
pout << "No such object: " << objid << std::endl;
} else {
obj->dumpInfo();
}
}
示例8:
set<Planet*> Planet::getAdjacent() {
set<Planet*> result;
Risk* risk = dynamic_cast<Risk*>(Game::getGame()->getRuleset());
ObjectManager* om = Game::getGame()->getObjectManager();
set<uint32_t> adjacent = risk->getGraph()->getAdjacent(this->obj->getID());
for(set<uint32_t>::iterator i = adjacent.begin(); i != adjacent.end(); ++i) {
result.insert(dynamic_cast<Planet*>(om->getObject(*i)->getObjectBehaviour()));
}
return result;
}
示例9: doOrder
bool Bombard::doOrder(IGObject *fleet) {
Game *game = Game::getGame();
ObjectManager *om = game->getObjectManager();
ObjectTypeManager *odm = game->getObjectTypeManager();
Random *rand = game->getRandom();
IGObject *planetObj = om->getObject(planet->getObjectId());
if(planetObj->getType() != odm->getObjectTypeByName("Planet"))
{
Logger::getLogger()->debug("Player tried to bombard something illogical");
return true;
}
Fleet *fleetData = dynamic_cast<Fleet*>(fleet->getObjectBehaviour());
Planet *planetData = dynamic_cast<Planet*>(planetObj->getObjectBehaviour());
char planetShipTech = PlayerInfo::getPlayerInfo(planetData->getOwner()).getShipTechLevel();
double attack = fleetData->getAttack();
planetData->removeResource("Industry",
static_cast<uint32_t>(attack * INDUSTRY_DMG * (1+rand->getInRange(-2,2)/100.) ));
planetData->removeResource("Social Environment",
static_cast<uint32_t>(attack * SOCIAL_DMG * (1+rand->getInRange(-2,2)/100.) ));
planetData->removeResource("Planetary Environment",
static_cast<uint32_t>(attack * PLANETARY_DMG * (1+rand->getInRange(-2,2)/100.) ));
planetData->removeResource(string("PDB") + planetShipTech,
static_cast<uint32_t>(attack * PDB_DMG / 10. * (1+rand->getInRange(-2,2)/100.) ));
PlayerInfo::getPlayerInfo(fleetData->getOwner()).addVictoryPoints(VICTORY_POINTS);
// PDBs counter-attack at: PDB level * 6 * numPDBs
fleetData->takeDamage( (planetShipTech - '0') *
6 * planetData->getResource(string("PDB") + planetShipTech).first);
Message *msg = new Message();
msg->setSubject("Bombard complete");
string body = "Fleet \"" + fleet->getName() + "\" bombarded " + planetObj->getName();
msg->setBody(PlayerInfo::appAllVictoryPoints(body));
msg->addReference(rst_Action_Order, rsorav_Completion);
msg->addReference(rst_Object, fleet->getID());
msg->addReference(rst_Object, planetObj->getID());
game->getPlayerManager()->getPlayer(fleetData->getOwner())->postToBoard(msg);
game->getPlayerManager()->getPlayer(planetData->getOwner())->postToBoard(msg);
return true;
}
示例10: inputFrame
Result Bombard::inputFrame(Frame * f, unsigned int playerid) {
Result r = Order::inputFrame(f, playerid);
if(!r) return r;
ObjectManager *om = Game::getGame()->getObjectManager();
IGObject *planetObj = om->getObject(planet->getObjectId());
Planet *planetData = dynamic_cast<Planet*>(planetObj->getObjectBehaviour());
if(!planetData)
planet->setObjectId(0);
else if(planetData->getOwner() == playerid)
planet->setObjectId(0);
return Success();
}
示例11: inputFrame
void Colonize::inputFrame(InputFrame::Ptr f, uint32_t playerid) {
FleetOrder::inputFrame(f, playerid);
Game *game = Game::getGame();
ObjectManager *obm = game->getObjectManager();
ObjectTypeManager *obtm = game->getObjectTypeManager();
IGObject::Ptr starSysObj = obm->getObject(starSys->getObjectId());
StarSystem* starSysData = (StarSystem*) starSysObj->getObjectBehaviour();
// Check to see if it is a legal system to colonize
if(starSysObj->getType() == obtm->getObjectTypeByName("Star System") && !starSysData->canBeColonized(isMining)) {
starSys->setObjectId(0);
Logger::getLogger()->debug("Player tried to colonize a system which cannot be colonized.");
}
}
示例12: exploreStarSys
void exploreStarSys(IGObject* obj) {
// set the planets in this star sys to visible for my owner
OwnedObject *objData = dynamic_cast<OwnedObject*>(obj->getObjectBehaviour());
Game *game = Game::getGame();
ObjectManager *om = game->getObjectManager();
IGObject *starSys = om->getObject(obj->getParent());
PlayerView *pview = game->getPlayerManager()->getPlayer(objData->getOwner())->getPlayerView();
ObjectView* obv = pview->getObjectView(obj->getID());
if(obv != NULL){
if(!obv->isCompletelyVisible()){
obv->setCompletelyVisible(true);
pview->updateObjectView(obj->getID());
}
if(obv->isGone()){
obv->setGone(false);
pview->updateObjectView(obj->getID());
}
}else{
obv = new ObjectView();
obv->setObjectId(obj->getID());
obv->setCompletelyVisible(true);
pview->addVisibleObject(obv);
}
if(starSys->getID() == 0) return; // don't explore the universe
set<uint32_t> planets = starSys->getContainedObjects();
for(set<uint32_t>::const_iterator i = planets.begin(); i != planets.end(); ++i){
obv = pview->getObjectView(*i);
if(obv != NULL){
if(!obv->isCompletelyVisible()){
obv->setCompletelyVisible(true);
pview->updateObjectView(*i);
}
}else{
obv = new ObjectView();
obv->setObjectId(*i);
obv->setCompletelyVisible(true);
pview->addVisibleObject(obv);
}
}
}
示例13: doTurn
void MinisecTurn::doTurn(){
std::set<uint32_t>::iterator itcurr;
Game* game = Game::getGame();
OrderManager* ordermanager = game->getOrderManager();
ObjectManager* objectmanager = game->getObjectManager();
RSPCombat* combatstrategy = new RSPCombat();
PlayerManager::Ptr playermanager = game->getPlayerManager();
//sort by order type
std::set<uint32_t> movers;
std::set<uint32_t> otherorders;
std::set<uint32_t> interceptors;
containerids.clear();
std::set<uint32_t> possiblecombatants;
std::set<uint32_t> objects = objectmanager->getAllIds();
for(itcurr = objects.begin(); itcurr != objects.end(); ++itcurr) {
IGObject::Ptr ob = objectmanager->getObject(*itcurr);
if(ob->getType() == planettype || ob->getType() == fleettype){
possiblecombatants.insert(ob->getID());
OrderQueueObjectParam* oqop = dynamic_cast<OrderQueueObjectParam*>(ob->getParameterByType(obpT_Order_Queue));
if(oqop != NULL){
OrderQueue::Ptr orderqueue = ordermanager->getOrderQueue(oqop->getQueueId());
if(orderqueue != NULL){
Order * currOrder = orderqueue->getFirstOrder();
if(currOrder != NULL){
if(currOrder->getType() == ordermanager->getOrderTypeByName("Move")){
movers.insert(ob->getID());
} else if (currOrder->getType() == ordermanager->getOrderTypeByName("Intercept")){
interceptors.insert(ob->getID());
}else{
otherorders.insert(ob->getID());
}
}
}
}
}
if(ob->getContainerType() >= 1){
containerids.insert(ob->getID());
}
objectmanager->doneWithObject(ob->getID());
}
// do move
for(itcurr = movers.begin(); itcurr != movers.end(); ++itcurr) {
IGObject::Ptr ob = objectmanager->getObject(*itcurr);
OrderQueueObjectParam* oqop = dynamic_cast<OrderQueueObjectParam*>(ob->getParameterByType(obpT_Order_Queue));
OrderQueue::Ptr orderqueue = ordermanager->getOrderQueue(oqop->getQueueId());
Order * currOrder = orderqueue->getFirstOrder();
if(currOrder->doOrder(ob)){
orderqueue->removeFirstOrder();
}else{
orderqueue->updateFirstOrder();
}
objectmanager->doneWithObject(ob->getID());
}
// do interceptions
for(itcurr = interceptors.begin(); itcurr != interceptors.end(); ++itcurr) {
IGObject::Ptr ob = objectmanager->getObject(*itcurr);
OrderQueueObjectParam* oqop = dynamic_cast<OrderQueueObjectParam*>(ob->getParameterByType(obpT_Order_Queue));
OrderQueue::Ptr orderqueue = ordermanager->getOrderQueue(oqop->getQueueId());
Order * currOrder = orderqueue->getFirstOrder();
if(currOrder->doOrder(ob)){
orderqueue->removeFirstOrder();
}else{
orderqueue->updateFirstOrder();
}
objectmanager->doneWithObject(ob->getID());
}
// do combat
std::list<std::map<uint32_t, std::set<uint32_t> > > combats;
for(itcurr = possiblecombatants.begin(); itcurr != possiblecombatants.end(); ++itcurr) {
IGObject::Ptr ob = objectmanager->getObject(*itcurr);
uint32_t playerid1;
Vector3d pos1;
uint32_t size1;
if(ob->getType() == planettype){
Planet* planet = (Planet*)(ob->getObjectBehaviour());
playerid1 = planet->getOwner();
pos1 = planet->getPosition();
size1 = planet->getSize();
}else{
Fleet* fleet = (Fleet*)(ob->getObjectBehaviour());
playerid1 = fleet->getOwner();
pos1 = fleet->getPosition();
size1 = fleet->getSize();
}
if(playerid1 == 0){
//.........这里部分代码省略.........
示例14: doCombat
void RSPCombat::doCombat(std::map<uint32_t, IdSet> sides) {
Game* game = Game::getGame();
PlayerManager::Ptr playermanager = game->getPlayerManager();
ObjectManager* objectmanager = game->getObjectManager();
DesignStore::Ptr ds = game->getDesignStore();
const char * const rsp[] = {"rock", "scissors", "paper"};
IdSet listallobids;
IdSet listallplayerids;
std::map<uint32_t, std::vector<Combatant*> > fleetcache;
battlelogger.reset(new BattleXML::BattleLogger());
msgstrings.clear();
for(std::map<uint32_t, IdSet>::iterator itmap = sides.begin(); itmap != sides.end(); ++itmap) {
std::vector<Combatant*> pcombatant;
Player::Ptr player = playermanager->getPlayer(itmap->first);
battlelogger->startSide(player->getName());
IdSet theset = itmap->second;
for(IdSet::iterator itset = theset.begin(); itset != theset.end(); ++itset) {
listallobids.insert(*itset);
IGObject::Ptr obj = objectmanager->getObject (*itset);
objectcache[*itset] = obj;
if(obj->getType() == obT_Fleet) {
Fleet* f2 = (Fleet*)(obj->getObjectBehaviour());
IdMap shiplist = f2->getShips();
uint32_t damage = f2->getDamage();
for(IdMap::reverse_iterator itship = shiplist.rbegin(); itship != shiplist.rend(); ++itship) {
for(uint32_t i = 0; i < itship->second; i++) {
Combatant* f1 = new Combatant();
f1->setOwner(itmap->first);
f1->setObject(obj->getID());
f1->setShipType(itship->first);
uint32_t mydamage = damage / std::max(1U, (unsigned int)(shiplist.size() - i));
f1->setDamage(mydamage);
damage -= mydamage;
std::string type = ds->getDesign(itship->first)->getName();
f1->setBattleXmlType(type);
f1->setBattleXmlId(str(boost::format("%1%-%2%-%3%") % type % obj->getID() % i));
f1->setBattleXmlName(str(boost::format("%1%'s %2%, %3% %4%") % player->getName() % obj->getName() % type % i));
battlelogger->addCombatant(f1);
pcombatant.push_back(f1);
}
}
} else {
int shipcount = 2;
int homeplanetid = game->getResourceManager()->getResourceDescription("Home Planet")->getResourceType();
if(((Planet*)(obj->getObjectBehaviour()))->getResource(homeplanetid) == 1) {
//three more for home planets
shipcount += 3;
}
for(int i = 0; i < shipcount; i++) {
Combatant* f1 = new Combatant();
f1->setOwner(itmap->first);
f1->setObject(obj->getID());
f1->setShipType(0);
f1->setBattleXmlType("planet");
f1->setBattleXmlId(str(boost::format("planet-%1%-%2%") % obj->getID() % i));
f1->setBattleXmlName(str(boost::format("%1%'s colony on %2%, Defense battery %3%") % player->getName() % obj->getName() % i));
battlelogger->addCombatant(f1);
pcombatant.push_back(f1);
}
}
}
listallplayerids.insert(itmap->first);
battlelogger->endSide();
//sort combatant list by ship type, descending
sort(pcombatant.begin(), pcombatant.end(), CombatantSorter());
fleetcache[itmap->first] = pcombatant;
}
for(std::set<uint32_t>::iterator itplayer = listallplayerids.begin(); itplayer != listallplayerids.end(); ++itplayer) {
msgstrings[*itplayer] = "";
}
Random* random = Game::getGame()->getRandom();
Logger::getLogger()->debug("Combat start");
while(fleetcache.size() >= 2) {
battlelogger->startRound();
uint32_t pos1, pos2;
if(fleetcache.size() == 2) {
pos1 = 0;
pos2 = 1;
} else {
pos1 = pos2 = random->getInRange(0U, ((uint32_t)(fleetcache.size() - 1)));
while(pos2 == pos1) {
pos2 = random->getInRange(0U, ((uint32_t)(fleetcache.size() - 1)));
}
}
std::map<uint32_t, std::vector<Combatant*> >::iterator itpa = fleetcache.begin();
advance(itpa, pos1);
std::map<uint32_t, std::vector<Combatant*> >::iterator itpb = fleetcache.begin();
advance(itpb, pos2);
//.........这里部分代码省略.........
示例15: 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());
//.........这里部分代码省略.........