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"); }
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()); } }
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++; } }