00001
00002
00003
00004
00005
00006
00007 #include <assert.h>
00008
00009 #include <const.h>
00010 #include <utils.h>
00011 #include <engine.h>
00012 #include <ent.h>
00013 #include <aspect.h>
00014 #include <ai/gather.h>
00015 #include <commandHelp.h>
00016 #include <unitAI.h>
00017
00018 #include <groupAI.h>
00019 #include <flock.h>
00020
00021 #include <gameMgr.h>
00022
00023 #include <OgreVector3.h>
00024 #include <cfloat>
00025 #include "DEBUG.h"
00026
00027
00028
00029
00030
00031
00032 FastEcslent::GameMgr::GameMgr(Engine* engine, Options opts): Mgr(engine) {
00033
00034 options = opts;
00035
00036 }
00037
00038 void FastEcslent::GameMgr::init() {
00039 switch (options.gameNumber) {
00040 case 0:
00041 game0();
00042 break;
00043 case 1:
00044 WaterCraft();
00045 break;
00046 case 2:
00047 tester();
00048 break;
00049 default:
00050 tester();
00051 }
00052
00053 }
00054
00055 bool FastEcslent::GameMgr::notExceedPopCap(Identity entId) {
00056 Entity *ent = this->engine->entityMgr->ents[entId.id];
00057 return (this->pop[ent->entityId.player] + this->entTypeData[ent->entityType].supply <= this->currentPopCap[ent->entityId.player]);
00058
00059 }
00060
00061 bool FastEcslent::GameMgr::preReqExists(EntityType entType) {
00062 return true;
00063 }
00064
00065 void FastEcslent::GameMgr::setupEntityBuildTimes(){
00066 this->entTypeData[SCV].buildTime = 17;
00067 this->entTypeData[MARINE].buildTime = 25;
00068 this->entTypeData[REAPER].buildTime = 45;
00069 this->entTypeData[TANK].buildTime = 45;
00070 this->entTypeData[THOR].buildTime = 60;
00071 this->entTypeData[MARAUDER].buildTime = 30;
00072 this->entTypeData[HELLION].buildTime = 30;
00073
00074 this->entTypeData[COMMANDCENTER].buildTime = 100;
00075 this->entTypeData[BARRACKS].buildTime = 65;
00076 this->entTypeData[FACTORY].buildTime = 60;
00077 this->entTypeData[ARMORY].buildTime = 65;
00078 this->entTypeData[ENGINEERINGBAY].buildTime = 35;
00079
00080 this->entTypeData[REFINERY].buildTime = 30;
00081 this->entTypeData[SUPPLYDEPOT].buildTime = 30;
00082
00083 this->entTypeData[MINERALS].buildTime = 0;
00084 this->entTypeData[GAS].buildTime = 0;
00085 }
00086
00087 void FastEcslent::GameMgr::setupEntitySupply(){
00088 for (int i = 0; i < NENTITYTYPES; i++){
00089 this->entTypeData[i].supply = 0;
00090 }
00091 this->entTypeData[SCV].supply = 1;
00092 this->entTypeData[MARINE].supply = 1;
00093 this->entTypeData[REAPER].supply = 1;
00094 this->entTypeData[TANK].supply = 3;
00095 this->entTypeData[THOR].supply = 5;
00096 this->entTypeData[MARAUDER].supply = 2;
00097 this->entTypeData[HELLION].supply = 2;
00098 }
00099
00100 void FastEcslent::GameMgr::game0(){
00101 for(int i = 0; i < NPLAYERS; i++){
00102 this->popCap[i] = 200;
00103 this->currentPopCap[i] = 10;
00104 this->pop[i] = 0;
00105 }
00106 setupEntityBuildTimes();
00107
00108 tester();
00109 }
00110
00111 void FastEcslent::GameMgr::WaterCraft(){
00112 for(int i = 0; i < NPLAYERS; i++){
00113 this->popCap[i] = 200;
00114 this->pop[i] = 0;
00115 this->currentPopCap[i] = 10;
00116 this->resources[i].gas = 0;
00117 this->resources[i].minerals = 50;
00118 this->playerNEnts[i] = 0;
00119 }
00120 setupEntityBuildTimes();
00121 setupEntitySupply();
00122 float offset = 3500.0f;
00123 makeBaseForSidePlayer(RED, ONE, Ogre::Vector3(-offset, 0, -offset), 550.0f, 0.06f);
00124
00125
00126
00127 startMining(RED, ONE);
00128 }
00129
00130 void FastEcslent::GameMgr::makeBaseForSidePlayer(Side side, Player player, Ogre::Vector3 location, float offset, float yawOffset){
00131
00132 Entity *ent;
00133 ent = engine->entityMgr->createEntityForPlayerAndSide(COMMANDCENTER, location, 0.0f, side, player);
00134 ent->pos = location;
00135 DEBUG(std::cout << "Game Manager: " << ent->uiname << std::endl;)
00136 ent->init();
00137 this->currentEntityCounts[player][ent->entityType]++;
00138 this->playerEnts[player][this->playerNEnts[player]++] = ent;
00139 ent->entityState = ALIVE;
00140
00141
00142 createMineralPatch(8, side, player, location, offset, yawOffset);
00143
00144
00145 createNEntitiesRadial(GAS, 2, side, player, location, offset, yawOffset * 5, 2.0f);
00146
00147 createNEntitiesRadial(SCV, 5, side, player, location, offset/3.0f, yawOffset/2.0f);
00148
00149 }
00150
00151 std::vector<FastEcslent::Entity*> FastEcslent::GameMgr::createNEntitiesRadial(EntityType entType, int nEntities, Side side, Player player, Ogre::Vector3 location, float offset, float yawOffset, int yawOffsetMultiplier){
00152 std::vector<Entity*> ents;
00153 Entity *ent;
00154 Ogre::Vector3 entityLocation(location.x, 0, location.z);
00155 float radius = entityLocation.length();
00156 radius = radius + fabs(offset);
00157 float yaw = atan2(location.z, location.x);
00158 yaw = yaw - yawOffset*nEntities/2.0f;
00159
00160 entityLocation.x = cos(yaw) * radius;
00161 entityLocation.z = sin(yaw) * radius;
00162 for (int i = 0; i < nEntities; i++) {
00163 ent = engine->entityMgr->createEntityForPlayerAndSide(entType, entityLocation, yaw, side, player );
00164 ent->init();
00165
00166 this->pop[player] += this->entTypeData[ent->entityType].supply;
00167 this->currentEntityCounts[player][ent->entityType]++;
00168 this->playerEnts[player][this->playerNEnts[player]++] = ent;
00169 ent->entityState = ALIVE;
00170
00171 ents.push_back(ent);
00172
00173 yaw += yawOffset * yawOffsetMultiplier;
00174 entityLocation.x = cos(yaw) * radius;
00175 entityLocation.z = sin(yaw) * radius;
00176 }
00177
00178 return ents;
00179 }
00180
00181 void FastEcslent::GameMgr::createMineralPatch(int nEntities, Side side, Player player, Ogre::Vector3 location, float offset, float yawOffset, int yawOffsetMultiplier){
00182 MineralPatch *mp = new MineralPatch();
00183 mineralPatches.push_back(mp);
00184 std::vector<Entity*> ents = createNEntitiesRadial(MINERALS, nEntities, side, player, location, offset, yawOffset);
00185 for(std::vector<Entity*>::iterator i= ents.begin(); i!= ents.end();i++){
00186 Minerals *m = dynamic_cast<Minerals*>(*i);
00187 mp->addMineral(m);
00188 m->patch = mp;
00189 }
00190 }
00191
00192 FastEcslent::Entity *FastEcslent::GameMgr::findClosestEntityOfTypeWithinDistance(EntityType entityType, Ogre::Vector3 pos, float maxDistance, Side side, Player player){
00193 float minDistance = FLT_MAX;
00194 float distance;
00195 Entity *minEnt = 0;
00196 Entity *ent = 0;
00197 for (int i = 0; i < this->playerNEnts[player]; i++){
00198 ent = this->playerEnts[player][i];
00199
00200 if (ent->entityType == entityType && ent->entityState == ALIVE){
00201 DEBUG(std::cout << "Found: " << ent->uiname << ": " << ent->entityState << std::endl;)
00202 distance = pos.distance(ent->pos);
00203 if (distance < maxDistance) {
00204 DEBUG(std::cout << ent->uiname << ", distance: " << distance << std::endl;)
00205 if (distance < minDistance) {
00206 minDistance = distance;
00207 minEnt = ent;
00208 }
00209 }
00210 }
00211 }
00212 return minEnt;
00213 }
00214
00215 void FastEcslent::GameMgr::startMining(Side side, Player player){
00216 Entity *ent;
00217 for (int i = 0; i < this->playerNEnts[player]; i++){
00218 ent = this->playerEnts[player][i];
00219 if (ent->entityType == SCV ){
00220 SCVehicle *scv = dynamic_cast<SCVehicle *>(ent);
00221 Entity *mineral = findClosestEntityOfTypeWithinDistance(MINERALS, scv->pos, FLT_MAX, side, player);
00222 assert(mineral != 0);
00223 Gather *g = createGatherForEntAndMineral(scv, dynamic_cast<Minerals *>(mineral));
00224 UnitAI *ai = dynamic_cast<UnitAI *> (scv->getAspect(UNITAI));
00225 ai->setCommand(g);
00226 }
00227 }
00228 }
00229
00230
00231 void FastEcslent::GameMgr::tester(){
00232 int x = 0;
00233 int z = 0;
00234
00235 int rangex = 2000;
00236 int rangez = rangex;
00237 int nEnts = 50;
00238 DEBUG(std::cout << "Game2...nEnts: " << nEnts << std::endl;)
00239 engine->selectionMgr->resetAll();
00240
00241
00242 Entity *ent;
00243 ent = engine->entityMgr->createEntityAfterTime(BARRACKS, Ogre::Vector3(0, 0, 0), 0.0f);
00244 ent->pos = Ogre::Vector3(x, 0.0f, z);
00245 x += 500;
00246 DEBUG(std::cout << "Game Manager: " << ent->uiname << std::endl;)
00247 ent->init();
00248
00249 ent = engine->entityMgr->createEntityAfterTime(COMMANDCENTER, Ogre::Vector3(0, 0, 0), 0.0f);
00250 ent->pos = Ogre::Vector3(x, 0.0f, z);
00251 x += 500;
00252 DEBUG(std::cout << "Game Manager: " << ent->uiname << std::endl;)
00253 ent->init();
00254
00255 ent = engine->entityMgr->createEntityAfterTime(FACTORY, Ogre::Vector3(0, 0, 0), 0.0f);
00256 ent->pos = Ogre::Vector3(x, 0.0f, z);
00257 x += 500;
00258 DEBUG(std::cout << "Game Manager: " << ent->uiname << std::endl;)
00259 ent->init();
00260
00261 ent = engine->entityMgr->createEntityAfterTime(REFINERY, Ogre::Vector3(0, 0, 0), 0.0f);
00262 ent->pos = Ogre::Vector3(x, 0.0f, z);
00263 x += 500;
00264 DEBUG(std::cout << "Game Manager: " << ent->uiname << std::endl;)
00265 ent->init();
00266
00267 ent = engine->entityMgr->createEntityAfterTime(SUPPLYDEPOT, Ogre::Vector3(0, 0, 0), 0.0f);
00268 ent->pos = Ogre::Vector3(x, 0.0f, z);
00269 x += 500;
00270 DEBUG(std::cout << "Game Manager: " << ent->uiname << std::endl;)
00271 ent->init();
00272
00273 ent = engine->entityMgr->createEntityAfterTime(ENGINEERINGBAY, Ogre::Vector3(0, 0, 0), 0.0f);
00274 ent->pos = Ogre::Vector3(x, 0.0f, z);
00275 x += 500;
00276 DEBUG(std::cout << "Game Manager: " << ent->uiname << std::endl;)
00277 ent->init();
00278
00279 ent = engine->entityMgr->createEntityAfterTime(ARMORY, Ogre::Vector3(0, 0, 0), 0.0f);
00280 ent->pos = Ogre::Vector3(x, 0.0f, z);
00281 x += 500;
00282 DEBUG(std::cout << "Game Manager: " << ent->uiname << std::endl;)
00283 ent->init();
00284
00285 x = 0;
00286 z = 0;
00287 for(int i = 0; i < nEnts; i++){
00288 ent = engine->entityMgr->createEntityAfterTime(static_cast<EntityType>(i%7), Ogre::Vector3(0, 0, 0), 0.0f);
00289 DEBUG(std::cout << "Game Manager: " << ent->uiname << std::endl;)
00290 ent->init();
00291 ent->pos = Ogre::Vector3(x, 0.0f, z);
00292 z = rangez - random() % (2 * rangez);
00293 x = rangex - random() % (2 * rangex);
00294 ent->heading = (random()%180) * 0.0174532925;
00295 ent->yaw = ent->heading;
00296 ent->desiredHeading = ent->heading;
00297 ent->desiredSpeed = 0.0f;
00298 }
00299
00300 }
00301
00302
00303
00304 void FastEcslent::GameMgr::tick(double dtime){
00305 return;
00306 }
00307
00308
00309
00310