本文整理汇总了C++中ObjectTypeManager类的典型用法代码示例。如果您正苦于以下问题:C++ ObjectTypeManager类的具体用法?C++ ObjectTypeManager怎么用?C++ ObjectTypeManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ObjectTypeManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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());
}
}
}
示例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:
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;
}
示例4: 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;
}
示例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: createGame
void taeRuleset::createGame() {
Game* game = Game::getGame();
ObjectManager* obm = game->getObjectManager();
ObjectTypeManager* obtm = game->getObjectTypeManager();
//Create ship design category
Category* cat = new Category();
cat->setName("Ships");
cat->setDescription("Ship components");
game->getDesignStore()->addCategory(cat);
//Create properties
createProperties();
//Create components
createComponents();
//Create resources
setupResources();
uint32_t obT_Universe = obtm->getObjectTypeByName("Universe");
uint32_t obT_Galaxy = obtm->getObjectTypeByName("Galaxy");
//Create the universe
IGObject* universe = obm->createNewObject();
obtm->setupObject(universe, obT_Universe);
Universe* theUniverse = (Universe*)(universe->getObjectBehaviour());
theUniverse->setSize(1000000000000ll);
universe->setName("The Universe");
theUniverse->setPosition(Vector3d(0ll,0ll,0ll));
obm->addObject(universe);
//Create the galaxy
IGObject* gal = obm->createNewObject();
obtm->setupObject(gal, obT_Galaxy);
EmptyObject* galob = (EmptyObject*)(gal->getObjectBehaviour());
galob->setSize(100000000000ll);
gal->setName("The Fertile Galaxy");
galob->setPosition(Vector3d(0ll, -6000ll, 0ll));
gal->addToParent(universe->getID());
obm->addObject(gal);
string path = string(Settings::getSettings()->get("board_path"));
Logger::getLogger()->debug(path.c_str());
createBoard(path, gal->getID());
Logger::getLogger()->info("TaE created");
}
示例7: 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.");
}
}
示例8: MTSecTurn
void MTSec::initGame() {
Game* game = Game::getGame();
MTSecTurn* turn = new MTSecTurn();
game->setTurnProcess(turn);
ObjectTypeManager* obdm = game->getObjectTypeManager();
obdm->addNewObjectType( new UniverseType());
obdm->addNewObjectType( new EmptyObjectType( "Galaxy", "The Galaxy Object type") );
obdm->addNewObjectType( new EmptyObjectType( "Star System","The Star System Object type") );
uint32_t pt = obdm->addNewObjectType( new PlanetType());
uint32_t ft = obdm->addNewObjectType( new FleetType());
turn->setPlanetType(pt);
turn->setFleetType(ft);
OrderManager* ordm = game->getOrderManager();
ordm->addOrderType(new Nop());
ordm->addOrderType(new Move());
ordm->addOrderType(new BuildFleet());
ordm->addOrderType(new BuildWeapon());
ordm->addOrderType(new Colonise());
ordm->addOrderType(new SplitFleet());
ordm->addOrderType(new MergeFleet());
ordm->addOrderType(new Enhance());
ordm->addOrderType(new SendPoints());
ordm->addOrderType(new LoadArmament());
ordm->addOrderType(new UnloadArmament());
}
示例9: FleetBuilder
void taeRuleset::initGame() {
Game* game = Game::getGame();
fleetBuilder = new FleetBuilder();
//Setup turns
TaeTurn* turn = new TaeTurn(fleetBuilder);
game->setTurnProcess(turn);
//Add universe object type
ObjectTypeManager* obtm = game->getObjectTypeManager();
obtm->addNewObjectType(new UniverseType());
//Add Galaxy object type
EmptyObjectType * eo = new EmptyObjectType();
eo->setTypeName("Galaxy");
eo->setTypeDescription("The Galaxy Object type");
obtm->addNewObjectType(eo);
//Add Solar system object type
obtm->addNewObjectType(new StarSystemType());
//Add Planet object type
uint32_t pt = obtm->addNewObjectType(new PlanetType());
turn->setPlanetType(pt);
//Add Fleet object type
uint32_t ft = obtm->addNewObjectType(new FleetType());
turn->setFleetType(ft);
//Set Order types
OrderManager* orm = game->getOrderManager();
orm->addOrderType(new Colonize(true));
orm->addOrderType(new Colonize(false));
orm->addOrderType(new Move());
orm->addOrderType(new Attack());
orm->addOrderType(new Reinforce());
Logger::getLogger()->info("TaE initialised");
}
示例10: 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;
//.........这里部分代码省略.........
示例11: 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());
//.........这里部分代码省略.........
示例12: 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++;
}
}
示例13: 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());
}
//.........这里部分代码省略.........
示例14: onPlayerAdded
void taeRuleset::onPlayerAdded(Player* player) {
Logger::getLogger()->debug("TaE onPlayerAdded");
Game *game = Game::getGame();
PlayerView* playerview = player->getPlayerView();
ObjectTypeManager* obtm = game->getObjectTypeManager();
//Set Player's score to 0
player->setScore(1,0);
player->setScore(2,0);
player->setScore(3,0);
player->setScore(4,0);
player->setScore(5,0);
//Set visibility of current designs
std::set<uint32_t> allotherdesigns = Game::getGame()->getDesignStore()->getDesignIds();
for(std::set<uint32_t>::const_iterator desid = allotherdesigns.begin(); desid != allotherdesigns.end(); ++desid){
DesignView* dv = new DesignView();
dv->setDesignId(*desid);
playerview->addVisibleDesign(dv);
}
for(uint32_t i = 1; i <= game->getDesignStore()->getMaxComponentId(); ++i){
playerview->addUsableComponent(i);
}
std::set<uint32_t> mydesignids;
//Add system and planet to hold player's fleets
IGObject* sys1 = game->getObjectManager()->createNewObject();
obtm->setupObject(sys1, obtm->getObjectTypeByName("Star System"));
StarSystem* sys1ob = (StarSystem*)(sys1->getObjectBehaviour());
sys1ob->setSize(60000ll);
sys1->setName(player->getName() + "'s System");
sys1ob->setPosition(Vector3d(1ll+80000*player->getID(), 1ll, 0ll));
sys1ob->setInhabitable(true);
sys1ob->setDestroyed(true);
sys1->addToParent(1);
game->getObjectManager()->addObject(sys1);
IGObject *p = game->getObjectManager()->createNewObject();
obtm->setupObject(p, obtm->getObjectTypeByName("Planet"));
Planet * pob = (Planet*)(p->getObjectBehaviour());
pob->setSize(2);
p->setName(player->getName() + "'s Home Planet");
pob->setPosition(sys1ob->getPosition());
OrderQueue *planetoq = new OrderQueue();
planetoq->setObjectId(p->getID());
planetoq->addOwner(player->getID());
game->getOrderManager()->addOrderQueue(planetoq);
OrderQueueObjectParam* oqop = static_cast<OrderQueueObjectParam*>(p->getParameterByType(obpT_Order_Queue));
oqop->setQueueId(planetoq->getQueueId());
pob->setDefaultOrderTypes();
p->addToParent(sys1->getID());
game->getObjectManager()->addObject(p);
//Setup starting fleets
IGObject* fleet;
//Colonist fleets
for(int i = 0; i < 6; i++) {
fleet = fleetBuilder->createFleet(FleetBuilder::PASSENGER_FLEET, FleetBuilder::RANDOM_SHIP, player, p, "Colonist Fleet");
game->getObjectManager()->addObject(fleet);
}
//Leader fleets
fleet = fleetBuilder->createFleet(FleetBuilder::VIP_FLEET, FleetBuilder::MERCHANT_SHIP, player, p, "Merchant Leader");
game->getObjectManager()->addObject(fleet);
fleet = fleetBuilder->createFleet(FleetBuilder::VIP_FLEET, FleetBuilder::SCIENTIST_SHIP, player, p, "Scientist Leader");
game->getObjectManager()->addObject(fleet);
fleet = fleetBuilder->createFleet(FleetBuilder::VIP_FLEET, FleetBuilder::SETTLER_SHIP, player, p, "Settler Leader");
game->getObjectManager()->addObject(fleet);
fleet = fleetBuilder->createFleet(FleetBuilder::VIP_FLEET, FleetBuilder::MINING_SHIP, player, p, "Mining Leader");
game->getObjectManager()->addObject(fleet);
//Bomber fleets
for(int i = 0; i < 2; i++) {
fleet = fleetBuilder->createFleet(FleetBuilder::BOMBER_FLEET, NULL, player, p, "Bomber");
game->getObjectManager()->addObject(fleet);
}
//Set visibility of new designs and objects
std::set<uint32_t> objids = game->getObjectManager()->getAllIds();
for(std::set<uint32_t>::iterator itcurr = objids.begin(); itcurr != objids.end(); ++itcurr){
ObjectView* obv = new ObjectView();
obv->setObjectId(*itcurr);
obv->setCompletelyVisible(true);
playerview->addVisibleObject(obv);
}
std::set<uint32_t> playerids = game->getPlayerManager()->getAllIds();
for(std::set<uint32_t>::iterator playerit = playerids.begin(); playerit != playerids.end(); ++playerit){
Player* oplayer = game->getPlayerManager()->getPlayer(*playerit);
game->getPlayerManager()->updatePlayer(oplayer->getID());
}
//.........这里部分代码省略.........
示例15: awardArtifacts
//Award artifacts to any players who have a merchant leader
//in a region with two artifacts
void TaeTurn::awardArtifacts() {
Game* game = Game::getGame();
ObjectTypeManager* obtm = game->getObjectTypeManager();
ObjectManager* objectmanager = game->getObjectManager();
std::set<uint32_t> artifacts;
std::set<uint32_t> regions;
std::set<uint32_t> objects = objectmanager->getAllIds();
std::set<uint32_t>::iterator itcurr;
//Find any regions with 2 or more alien artifacts
for(itcurr = objects.begin(); itcurr != objects.end(); ++itcurr) {
IGObject::Ptr ob = objectmanager->getObject(*itcurr);
if(ob->getType() == obtm->getObjectTypeByName("Planet")) {
Planet* p = (Planet*) ob->getObjectBehaviour();
if(p->getResource(3) > 0) {
StarSystem* sys = (StarSystem*)(objectmanager->getObject(ob->getParent())->getObjectBehaviour());
if(sys->getRegion() != 0) {
if(regions.count(sys->getRegion()) > 0) {
artifacts.insert(*itcurr);
} else {
regions.insert(sys->getRegion());
}
}
}
}
}
if(!artifacts.empty()) {
uint32_t type;
DesignStore::Ptr ds = game->getDesignStore();
PlayerManager::Ptr pm = game->getPlayerManager();
std::set<uint32_t> designs = ds->getDesignIds();
//get leader ID
for(itcurr = designs.begin(); itcurr != designs.end(); ++itcurr) {
if(ds->getDesign(*itcurr)->getName().compare("MerchantLeaderShip")) {
type = *itcurr;
}
}
//Search the objects for a merchant leader
for(itcurr = objects.begin(); itcurr != objects.end(); ++itcurr) {
IGObject::Ptr ob = objectmanager->getObject(*itcurr);
if(ob->getType() == obtm->getObjectTypeByName("Fleet")) {
Fleet* f = (Fleet*) (ob->getObjectBehaviour());
if(f->getShips().count(type) > 0) {
IGObject::Ptr parent = objectmanager->getObject(ob->getParent());
if(parent->getType() == obtm->getObjectTypeByName("Star System")) {
StarSystem* parentData = (StarSystem*) (parent->getObjectBehaviour());
//See if this leader is in a region with
//2 or more alien artifacts
for(std::set<uint32_t>::iterator i = artifacts.begin(); i != artifacts.end(); ++i) {
IGObject::Ptr obj = objectmanager->getObject(*i);
Planet* p = (Planet*) obj->getObjectBehaviour();
StarSystem* sys = (StarSystem*)(objectmanager->getObject(obj->getParent())->getObjectBehaviour());
if(sys->getRegion() == parentData->getRegion()) {
//+1 to leader's owner's artifact score
Player::Ptr owner = pm->getPlayer(f->getOwner());
owner->setScore(5, owner->getScore(5) + 1);
p->removeResource(3, 1);
artifacts.erase(*i);
}
}
}
}
}
}
}
}