| [2636] | 1 |  | 
|---|
 | 2 |  | 
|---|
| [4597] | 3 | /* | 
|---|
| [2636] | 4 |    orxonox - the future of 3D-vertical-scrollers | 
|---|
 | 5 |  | 
|---|
 | 6 |    Copyright (C) 2004 orx | 
|---|
 | 7 |  | 
|---|
 | 8 |    This program is free software; you can redistribute it and/or modify | 
|---|
 | 9 |    it under the terms of the GNU General Public License as published by | 
|---|
 | 10 |    the Free Software Foundation; either version 2, or (at your option) | 
|---|
 | 11 |    any later version. | 
|---|
 | 12 |  | 
|---|
 | 13 |    ### File Specific: | 
|---|
 | 14 |    main-programmer: Patrick Boenzli | 
|---|
| [4597] | 15 |    co-programmer: | 
|---|
| [2636] | 16 | */ | 
|---|
 | 17 |  | 
|---|
 | 18 |  | 
|---|
 | 19 | #include "campaign.h" | 
|---|
| [3629] | 20 |  | 
|---|
| [5982] | 21 | #include "factory.h" | 
|---|
| [4010] | 22 | #include "game_loader.h" | 
|---|
| [3629] | 23 | #include "story_entity.h" | 
|---|
 | 24 |  | 
|---|
| [2636] | 25 | #include "world.h" | 
|---|
 | 26 | #include "camera.h" | 
|---|
| [3629] | 27 |  | 
|---|
| [4261] | 28 | #include "load_param.h" | 
|---|
 | 29 |  | 
|---|
| [5651] | 30 |  | 
|---|
| [2636] | 31 | using namespace std; | 
|---|
 | 32 |  | 
|---|
 | 33 |  | 
|---|
| [4597] | 34 | Campaign::Campaign () | 
|---|
| [2636] | 35 | { | 
|---|
| [4597] | 36 |   this->setClassID(CL_CAMPAIGN, "Campaign"); | 
|---|
| [2636] | 37 |   this->isInit = false; | 
|---|
 | 38 | } | 
|---|
| [4261] | 39 |  | 
|---|
| [4597] | 40 | Campaign::Campaign ( TiXmlElement* root) | 
|---|
| [4010] | 41 | { | 
|---|
| [4597] | 42 |   this->setClassID(CL_CAMPAIGN, "Campaign"); | 
|---|
 | 43 |  | 
|---|
| [5300] | 44 |   PRINTF(4)("Loading Campaign...\n"); | 
|---|
| [4597] | 45 |  | 
|---|
| [4010] | 46 |   assert( root != NULL); | 
|---|
| [4597] | 47 |  | 
|---|
| [4010] | 48 |   this->isInit = false; | 
|---|
| [4597] | 49 |  | 
|---|
| [4598] | 50 |   this->loadParams(root); | 
|---|
| [4597] | 51 |  | 
|---|
 | 52 |  | 
|---|
 | 53 |   //if( lastCreated != NULL) | 
|---|
| [4010] | 54 |   //lastCreated->setStoryID( WORLD_ID_GAMEEND); | 
|---|
 | 55 | } | 
|---|
| [2636] | 56 |  | 
|---|
| [4816] | 57 | Campaign::~Campaign () | 
|---|
 | 58 | {} | 
|---|
| [2636] | 59 |  | 
|---|
 | 60 |  | 
|---|
| [3222] | 61 | ErrorMessage Campaign::init() | 
|---|
| [2636] | 62 | { | 
|---|
 | 63 |   this->isInit = true; | 
|---|
 | 64 | } | 
|---|
 | 65 |  | 
|---|
| [4598] | 66 | /** | 
|---|
 | 67 |   \brief loads the Parameters of a Campaign | 
|---|
| [4836] | 68 | * @param root: The XML-element to load from | 
|---|
| [4598] | 69 |  */ | 
|---|
 | 70 | void Campaign::loadParams(const TiXmlElement* root) | 
|---|
 | 71 | { | 
|---|
| [4600] | 72 |   static_cast<BaseObject*>(this)->loadParams(root); | 
|---|
| [2636] | 73 |  | 
|---|
| [5671] | 74 |   LoadParam(root, "identifier", this, Campaign, setStoryID) | 
|---|
| [5651] | 75 |      .describe("A Unique Identifier for this Campaign"); | 
|---|
| [4598] | 76 |  | 
|---|
| [5651] | 77 |    LoadParamXML(root, "WorldList", this, Campaign, loadWorldListParams) | 
|---|
| [4600] | 78 |       .describe("A List of Worlds to be loaded in this Campaign"); | 
|---|
| [4598] | 79 | } | 
|---|
 | 80 |  | 
|---|
 | 81 | /** | 
|---|
 | 82 |   \brief loads a WorldList | 
|---|
| [4836] | 83 | * @param root: the XML-element to load from | 
|---|
| [4598] | 84 |  */ | 
|---|
 | 85 | void Campaign::loadWorldListParams(const TiXmlElement* root) | 
|---|
 | 86 | { | 
|---|
| [5651] | 87 |   if (root == NULL) | 
|---|
 | 88 |     return; | 
|---|
 | 89 |  | 
|---|
| [5751] | 90 |   LOAD_PARAM_START_CYCLE(root, element); | 
|---|
| [4598] | 91 |   { | 
|---|
| [5300] | 92 |     PRINTF(5)("Campaign: Constructor: adding a world\n"); | 
|---|
| [5982] | 93 |     StoryEntity* created = (StoryEntity*) Factory::fabricate(element); | 
|---|
| [4598] | 94 |     if( created != NULL) | 
|---|
 | 95 |     { | 
|---|
 | 96 |       this->addEntity( created); | 
|---|
 | 97 |     } | 
|---|
 | 98 |   } | 
|---|
| [5751] | 99 |   LOAD_PARAM_END_CYCLE(element); | 
|---|
| [4598] | 100 | } | 
|---|
 | 101 |  | 
|---|
| [3222] | 102 | ErrorMessage Campaign::start() | 
|---|
| [2636] | 103 | { | 
|---|
 | 104 |   this->start(0); | 
|---|
 | 105 | } | 
|---|
 | 106 |  | 
|---|
| [5292] | 107 | //! @todo boky -> fix it | 
|---|
| [3222] | 108 | ErrorMessage Campaign::start(int storyID = 0) | 
|---|
| [2636] | 109 | { | 
|---|
| [3222] | 110 |   ErrorMessage errorCode; | 
|---|
| [4597] | 111 |   if( !this->isInit) return errorCode; | 
|---|
| [3221] | 112 |   if( storyID == WORLD_ID_GAMEEND) return errorCode; | 
|---|
| [2636] | 113 |   this->running = true; | 
|---|
 | 114 |   StoryEntity* se = this->getStoryEntity(storyID); | 
|---|
| [3220] | 115 |   this->currentEntity = se; | 
|---|
| [3221] | 116 |   while( se != NULL && this->running) | 
|---|
| [2636] | 117 |     { | 
|---|
| [4324] | 118 |       PRINTF(0)("Starting new StoryEntity Nr:%i\n", se->getStoryID()); | 
|---|
| [3220] | 119 |       se->displayLoadScreen(); | 
|---|
| [3629] | 120 |       se->preLoad(); | 
|---|
| [2636] | 121 |       se->load(); | 
|---|
 | 122 |       se->init(); | 
|---|
| [3220] | 123 |       se->releaseLoadScreen(); | 
|---|
| [2636] | 124 |       se->start(); | 
|---|
| [3221] | 125 |       se->destroy(); | 
|---|
| [4597] | 126 |  | 
|---|
| [5215] | 127 |       int nextWorldID = se->getNextStoryID(); | 
|---|
 | 128 |  | 
|---|
| [5773] | 129 |       this->entities.remove(se); | 
|---|
| [3220] | 130 |       delete se; | 
|---|
 | 131 |  | 
|---|
 | 132 |       //printf("Campaing::start() - got nextWorldID = %i\n", nextWorldID); | 
|---|
| [2636] | 133 |       se = this->getStoryEntity(nextWorldID); | 
|---|
| [3220] | 134 |       this->currentEntity = se; | 
|---|
| [4597] | 135 |       if( ( nextWorldID == WORLD_ID_GAMEEND) ||( se == NULL) ) | 
|---|
 | 136 |         { | 
|---|
| [5305] | 137 |           PRINTF(4)("Quitting campaing story loop\n"); | 
|---|
| [4597] | 138 |           if(se != NULL) | 
|---|
 | 139 |             delete se; | 
|---|
 | 140 |           return errorCode; | 
|---|
 | 141 |         } | 
|---|
| [4816] | 142 |     } | 
|---|
| [4597] | 143 |  | 
|---|
| [4816] | 144 |     /* clean up all world that have not been loaded and therefore are still in the world list  - | 
|---|
 | 145 |        this probably does not belong into the start function. remove this later | 
|---|
 | 146 |     */ | 
|---|
| [5773] | 147 |     list<StoryEntity*>::iterator it; | 
|---|
 | 148 |     for(it = this->entities.begin(); it != entities.end(); it++) | 
|---|
| [4816] | 149 |     { | 
|---|
| [5773] | 150 |       delete (*it); | 
|---|
| [2636] | 151 |     } | 
|---|
 | 152 | } | 
|---|
 | 153 |  | 
|---|
 | 154 |  | 
|---|
| [3222] | 155 | ErrorMessage Campaign::pause() | 
|---|
| [2636] | 156 | { | 
|---|
 | 157 |   if(this->currentEntity != NULL) | 
|---|
 | 158 |     this->isPaused = true; | 
|---|
 | 159 | } | 
|---|
 | 160 |  | 
|---|
 | 161 |  | 
|---|
| [3222] | 162 | ErrorMessage Campaign::resume() | 
|---|
| [2636] | 163 | { | 
|---|
 | 164 |   if(this->currentEntity != NULL) | 
|---|
 | 165 |     this->isPaused = false; | 
|---|
 | 166 | } | 
|---|
 | 167 |  | 
|---|
 | 168 |  | 
|---|
| [3459] | 169 | ErrorMessage Campaign::stop() | 
|---|
| [3220] | 170 | { | 
|---|
| [3459] | 171 |   this->running = false; | 
|---|
| [4597] | 172 |   if(this->currentEntity != NULL) | 
|---|
| [3459] | 173 |     { | 
|---|
 | 174 |       this->currentEntity->stop(); | 
|---|
 | 175 |     } | 
|---|
 | 176 | } | 
|---|
 | 177 |  | 
|---|
 | 178 |  | 
|---|
 | 179 | ErrorMessage Campaign::destroy() | 
|---|
 | 180 | { | 
|---|
| [3220] | 181 |   if(this->currentEntity != NULL) | 
|---|
 | 182 |     { | 
|---|
 | 183 |       this->currentEntity->destroy(); | 
|---|
 | 184 |       delete this->currentEntity; | 
|---|
 | 185 |       this->currentEntity = NULL; | 
|---|
 | 186 |     } | 
|---|
 | 187 | } | 
|---|
 | 188 |  | 
|---|
| [3459] | 189 |  | 
|---|
| [4597] | 190 | /** | 
|---|
| [4836] | 191 |   *  adds an game stroy entity to the campaign | 
|---|
| [3459] | 192 |  | 
|---|
| [4836] | 193 |   * @param se: The entity | 
|---|
 | 194 |   * @param storyID: The number that identifies the entity in the campaign. Each ID only used once in a Campaign | 
|---|
| [3459] | 195 |  | 
|---|
 | 196 |     An entity can be a world (playable), a cinematic, a shop, sounds, whatever you | 
|---|
 | 197 |     want to queue up in the campaign. | 
|---|
 | 198 | */ | 
|---|
 | 199 | void Campaign::addEntity(StoryEntity* se, int storyID) | 
|---|
 | 200 | { | 
|---|
 | 201 |   se->setStoryID(storyID); | 
|---|
 | 202 |   this->addEntity(se); | 
|---|
 | 203 | } | 
|---|
 | 204 |  | 
|---|
 | 205 | void Campaign::addEntity(StoryEntity* se) | 
|---|
 | 206 | { | 
|---|
| [5773] | 207 |   this->entities.push_back(se); | 
|---|
| [3459] | 208 | } | 
|---|
 | 209 |  | 
|---|
 | 210 |  | 
|---|
 | 211 | void Campaign::removeEntity(int storyID) | 
|---|
 | 212 | { | 
|---|
 | 213 |   this->removeEntity(this->getStoryEntity(storyID)); | 
|---|
| [4597] | 214 |  | 
|---|
| [3459] | 215 | } | 
|---|
 | 216 |  | 
|---|
 | 217 |  | 
|---|
 | 218 | void Campaign::removeEntity(StoryEntity* se) | 
|---|
 | 219 | { | 
|---|
| [5773] | 220 |   this->entities.remove(se); | 
|---|
| [3459] | 221 | } | 
|---|
 | 222 |  | 
|---|
 | 223 |  | 
|---|
| [3225] | 224 | /* | 
|---|
 | 225 |   \brief this changes to the next level | 
|---|
 | 226 | */ | 
|---|
| [2636] | 227 | void Campaign::nextLevel() | 
|---|
 | 228 | { | 
|---|
| [5324] | 229 |   PRINTF(4)("Campaign:nextLevel()\n"); | 
|---|
| [3220] | 230 |   this->currentEntity->stop(); | 
|---|
| [2636] | 231 | } | 
|---|
 | 232 |  | 
|---|
| [3225] | 233 | /* | 
|---|
 | 234 |   \brief change to the previous level - not implemented | 
|---|
 | 235 |  | 
|---|
 | 236 |   this propably useless | 
|---|
 | 237 | */ | 
|---|
| [2636] | 238 | void Campaign::previousLevel() | 
|---|
 | 239 | {} | 
|---|
 | 240 |  | 
|---|
 | 241 |  | 
|---|
| [3225] | 242 | /* | 
|---|
 | 243 |   \brief lookup a entity with a given id | 
|---|
| [4836] | 244 | * @param story id to be lookuped | 
|---|
 | 245 |   @returns the entity found or NULL if search ended without match | 
|---|
| [3225] | 246 | */ | 
|---|
| [3220] | 247 | StoryEntity* Campaign::getStoryEntity(int storyID) | 
|---|
| [2636] | 248 | { | 
|---|
| [3220] | 249 |   //printf("Campaing::getStoryEntity(%i) - getting next Entity\n", storyID); | 
|---|
 | 250 |   if( storyID == WORLD_ID_GAMEEND) | 
|---|
 | 251 |     return NULL; | 
|---|
| [3608] | 252 |  | 
|---|
 | 253 |   /* | 
|---|
 | 254 |   tList<StoryEntity>* l; | 
|---|
| [3220] | 255 |   StoryEntity* entity = NULL; | 
|---|
| [4597] | 256 |   l = this->entities->getNext(); | 
|---|
 | 257 |   while( l != NULL) | 
|---|
 | 258 |     { | 
|---|
| [3231] | 259 |       entity = l->getObject(); | 
|---|
 | 260 |       l = l->getNext(); | 
|---|
| [3608] | 261 |  | 
|---|
| [3220] | 262 |       int id = entity->getStoryID(); | 
|---|
 | 263 |       //printf("Campaing::getStoryEntity() - now looping, found entity nr=%i\n", id); | 
|---|
 | 264 |       if(id == storyID) | 
|---|
| [4597] | 265 |         { | 
|---|
 | 266 |           //printf("Campaing::getStoryEntity() - yea, this is what we where looking for: %id\n"); | 
|---|
 | 267 |           return entity; | 
|---|
 | 268 |         } | 
|---|
| [3608] | 269 |  | 
|---|
| [2636] | 270 |     } | 
|---|
| [3608] | 271 |   */ | 
|---|
 | 272 |  | 
|---|
 | 273 |  | 
|---|
| [5773] | 274 |   list<StoryEntity*>::iterator it; | 
|---|
 | 275 |   for (it = this->entities.begin(); it != this->entities.end(); it++) | 
|---|
 | 276 |   { | 
|---|
 | 277 |       int id = (*it)->getStoryID(); | 
|---|
| [3608] | 278 |       //printf("Campaing::getStoryEntity() - now looping, found entity nr=%i\n", id); | 
|---|
 | 279 |       if(id == storyID) | 
|---|
| [4597] | 280 |         { | 
|---|
 | 281 |           //printf("Campaing::getStoryEntity() - yea, this is what we where looking for: %id\n"); | 
|---|
| [5773] | 282 |           return (*it); | 
|---|
| [4597] | 283 |         } | 
|---|
| [3608] | 284 |     } | 
|---|
 | 285 |  | 
|---|
 | 286 |  | 
|---|
| [5773] | 287 |  | 
|---|
| [2636] | 288 |   return NULL; | 
|---|
 | 289 | } | 
|---|