[2636] | 1 | |
---|
| 2 | |
---|
| 3 | /* |
---|
| 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 |
---|
| 15 | co-programmer: |
---|
| 16 | */ |
---|
| 17 | |
---|
| 18 | |
---|
| 19 | #include "campaign.h" |
---|
[3629] | 20 | |
---|
[4010] | 21 | #include "game_loader.h" |
---|
[3629] | 22 | #include "story_entity.h" |
---|
| 23 | |
---|
[2636] | 24 | #include "world.h" |
---|
| 25 | #include "camera.h" |
---|
[3629] | 26 | |
---|
[3608] | 27 | #include "list.h" |
---|
[2636] | 28 | |
---|
| 29 | using namespace std; |
---|
| 30 | |
---|
| 31 | |
---|
| 32 | Campaign::Campaign () |
---|
| 33 | { |
---|
[3608] | 34 | this->entities = new tList<StoryEntity>(); |
---|
[2636] | 35 | this->isInit = false; |
---|
| 36 | } |
---|
[4010] | 37 | Campaign::Campaign ( TiXmlElement* root) |
---|
| 38 | { |
---|
| 39 | TiXmlElement* element; |
---|
| 40 | const char* string; |
---|
| 41 | int id; |
---|
| 42 | |
---|
[4114] | 43 | PRINTF(3)("Loading Campaign...\n"); |
---|
[4010] | 44 | |
---|
| 45 | assert( root != NULL); |
---|
| 46 | GameLoader* loader = GameLoader::getInstance(); |
---|
| 47 | |
---|
| 48 | this->entities = new tList<StoryEntity>(); |
---|
| 49 | this->isInit = false; |
---|
| 50 | |
---|
| 51 | // grab all the necessary parameters |
---|
| 52 | string = grabParameter( root, "identifier"); |
---|
| 53 | if( string == NULL || sscanf(string, "%d", &id) != 1) |
---|
| 54 | { |
---|
[4114] | 55 | PRINTF(2)("Campaign is missing a proper 'identifier'\n"); |
---|
[4010] | 56 | this->setStoryID( -1); |
---|
| 57 | } |
---|
| 58 | else this->setStoryID( id); |
---|
| 59 | |
---|
| 60 | // find WorldList |
---|
| 61 | element = root->FirstChildElement( "WorldList"); |
---|
| 62 | if( element == NULL) |
---|
| 63 | { |
---|
[4114] | 64 | PRINTF(2)("Campaign is missing a proper 'WorldList'\n"); |
---|
[4010] | 65 | } |
---|
| 66 | else |
---|
| 67 | element = element->FirstChildElement(); |
---|
| 68 | |
---|
| 69 | // load Worlds/Subcampaigns/Whatever |
---|
| 70 | StoryEntity* lastCreated = NULL; |
---|
| 71 | while( element != NULL) |
---|
| 72 | { |
---|
| 73 | printf("Campaign: Constructor: adding a world\n"); |
---|
| 74 | StoryEntity* created = (StoryEntity*) loader->fabricate( element); |
---|
| 75 | /* |
---|
| 76 | if( lastCreated != NULL) |
---|
| 77 | created->setNextStoryID( lastCreated->getStoryID()); |
---|
| 78 | else |
---|
| 79 | created->setNextStoryID( WORLD_ID_GAMEEND); |
---|
| 80 | */ |
---|
| 81 | if( created != NULL) |
---|
| 82 | { |
---|
| 83 | this->addEntity( created); |
---|
| 84 | lastCreated = created; |
---|
| 85 | } |
---|
| 86 | element = element->NextSiblingElement(); |
---|
| 87 | } |
---|
| 88 | //if( lastCreated != NULL) |
---|
| 89 | //lastCreated->setStoryID( WORLD_ID_GAMEEND); |
---|
| 90 | } |
---|
[2636] | 91 | |
---|
| 92 | Campaign::~Campaign () {} |
---|
| 93 | |
---|
| 94 | |
---|
[3222] | 95 | ErrorMessage Campaign::init() |
---|
[2636] | 96 | { |
---|
| 97 | this->isInit = true; |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | |
---|
[3222] | 101 | ErrorMessage Campaign::start() |
---|
[2636] | 102 | { |
---|
| 103 | this->start(0); |
---|
| 104 | } |
---|
| 105 | |
---|
[3459] | 106 | |
---|
[3222] | 107 | ErrorMessage Campaign::start(int storyID = 0) |
---|
[2636] | 108 | { |
---|
| 109 | printf("World::start() - starting new StoryEntity Nr:%i\n", storyID); |
---|
[3222] | 110 | ErrorMessage errorCode; |
---|
[3221] | 111 | if( !this->isInit) return errorCode; |
---|
| 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 | { |
---|
[3220] | 118 | se->displayLoadScreen(); |
---|
[3629] | 119 | se->preLoad(); |
---|
[2636] | 120 | se->load(); |
---|
| 121 | se->init(); |
---|
[3220] | 122 | se->releaseLoadScreen(); |
---|
[2636] | 123 | se->start(); |
---|
[3221] | 124 | se->destroy(); |
---|
| 125 | |
---|
[3220] | 126 | delete se; |
---|
| 127 | |
---|
[2636] | 128 | int nextWorldID = se->getNextStoryID(); |
---|
[3220] | 129 | //printf("Campaing::start() - got nextWorldID = %i\n", nextWorldID); |
---|
[2636] | 130 | se = this->getStoryEntity(nextWorldID); |
---|
[3220] | 131 | this->currentEntity = se; |
---|
| 132 | if( ( nextWorldID == WORLD_ID_GAMEEND) ||( se == NULL) ) |
---|
| 133 | { |
---|
[3225] | 134 | printf("Campaign::start() - quitting campaing story loop\n"); |
---|
[3220] | 135 | if(se != NULL) |
---|
| 136 | delete se; |
---|
| 137 | return errorCode; |
---|
| 138 | } |
---|
| 139 | |
---|
[2636] | 140 | } |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | |
---|
[3222] | 144 | ErrorMessage Campaign::pause() |
---|
[2636] | 145 | { |
---|
| 146 | if(this->currentEntity != NULL) |
---|
| 147 | this->isPaused = true; |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | |
---|
[3222] | 151 | ErrorMessage Campaign::resume() |
---|
[2636] | 152 | { |
---|
| 153 | if(this->currentEntity != NULL) |
---|
| 154 | this->isPaused = false; |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | |
---|
[3459] | 158 | ErrorMessage Campaign::stop() |
---|
[3220] | 159 | { |
---|
[3459] | 160 | this->running = false; |
---|
| 161 | if(this->currentEntity != NULL) |
---|
| 162 | { |
---|
| 163 | this->currentEntity->stop(); |
---|
| 164 | //delete this->currentEntity; |
---|
| 165 | //this->currentEntity = NULL; |
---|
| 166 | } |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | |
---|
| 170 | ErrorMessage Campaign::destroy() |
---|
| 171 | { |
---|
[3220] | 172 | if(this->currentEntity != NULL) |
---|
| 173 | { |
---|
| 174 | this->currentEntity->destroy(); |
---|
| 175 | delete this->currentEntity; |
---|
| 176 | this->currentEntity = NULL; |
---|
| 177 | } |
---|
| 178 | } |
---|
| 179 | |
---|
[3459] | 180 | |
---|
| 181 | /** |
---|
| 182 | \brief adds an game stroy entity to the campaign |
---|
| 183 | |
---|
| 184 | \param se: The entity |
---|
| 185 | \param storyID: The number that identifies the entity in the campaign. Each ID only used once in a Campaign |
---|
| 186 | |
---|
| 187 | An entity can be a world (playable), a cinematic, a shop, sounds, whatever you |
---|
| 188 | want to queue up in the campaign. |
---|
| 189 | */ |
---|
| 190 | void Campaign::addEntity(StoryEntity* se, int storyID) |
---|
| 191 | { |
---|
| 192 | se->setStoryID(storyID); |
---|
| 193 | this->addEntity(se); |
---|
| 194 | } |
---|
| 195 | |
---|
| 196 | void Campaign::addEntity(StoryEntity* se) |
---|
| 197 | { |
---|
| 198 | this->entities->add(se); |
---|
| 199 | } |
---|
| 200 | |
---|
| 201 | |
---|
| 202 | void Campaign::removeEntity(int storyID) |
---|
| 203 | { |
---|
| 204 | this->removeEntity(this->getStoryEntity(storyID)); |
---|
| 205 | |
---|
| 206 | } |
---|
| 207 | |
---|
| 208 | |
---|
| 209 | void Campaign::removeEntity(StoryEntity* se) |
---|
| 210 | { |
---|
| 211 | this->entities->remove(se); |
---|
| 212 | } |
---|
| 213 | |
---|
| 214 | |
---|
[3225] | 215 | /* |
---|
| 216 | \brief this changes to the next level |
---|
| 217 | */ |
---|
[2636] | 218 | void Campaign::nextLevel() |
---|
| 219 | { |
---|
[3220] | 220 | printf("Campaign:nextLevel()\n"); |
---|
| 221 | //int nextID = this->currentEntity->getNextStoryID(); |
---|
| 222 | //this->stop(); |
---|
| 223 | //this->start(nextID); |
---|
| 224 | this->currentEntity->stop(); |
---|
[2636] | 225 | } |
---|
| 226 | |
---|
[3225] | 227 | /* |
---|
| 228 | \brief change to the previous level - not implemented |
---|
| 229 | |
---|
| 230 | this propably useless |
---|
| 231 | */ |
---|
[2636] | 232 | void Campaign::previousLevel() |
---|
| 233 | {} |
---|
| 234 | |
---|
| 235 | |
---|
[3225] | 236 | /* |
---|
| 237 | \brief lookup a entity with a given id |
---|
| 238 | \param story id to be lookuped |
---|
| 239 | \returns the entity found or NULL if search ended without match |
---|
| 240 | */ |
---|
[3220] | 241 | StoryEntity* Campaign::getStoryEntity(int storyID) |
---|
[2636] | 242 | { |
---|
[3220] | 243 | //printf("Campaing::getStoryEntity(%i) - getting next Entity\n", storyID); |
---|
| 244 | if( storyID == WORLD_ID_GAMEEND) |
---|
| 245 | return NULL; |
---|
[3608] | 246 | |
---|
| 247 | /* |
---|
| 248 | tList<StoryEntity>* l; |
---|
[3220] | 249 | StoryEntity* entity = NULL; |
---|
[3231] | 250 | l = this->entities->getNext(); |
---|
[2636] | 251 | while( l != NULL) |
---|
| 252 | { |
---|
[3231] | 253 | entity = l->getObject(); |
---|
| 254 | l = l->getNext(); |
---|
[3608] | 255 | |
---|
[3220] | 256 | int id = entity->getStoryID(); |
---|
| 257 | //printf("Campaing::getStoryEntity() - now looping, found entity nr=%i\n", id); |
---|
| 258 | if(id == storyID) |
---|
| 259 | { |
---|
| 260 | //printf("Campaing::getStoryEntity() - yea, this is what we where looking for: %id\n"); |
---|
| 261 | return entity; |
---|
| 262 | } |
---|
[3608] | 263 | |
---|
[2636] | 264 | } |
---|
[3608] | 265 | */ |
---|
| 266 | |
---|
| 267 | |
---|
[3832] | 268 | tIterator<StoryEntity>* iterator = this->entities->getIterator(); |
---|
| 269 | StoryEntity* entity = iterator->nextElement(); |
---|
[3608] | 270 | while( entity != NULL) |
---|
| 271 | { |
---|
| 272 | int id = entity->getStoryID(); |
---|
| 273 | //printf("Campaing::getStoryEntity() - now looping, found entity nr=%i\n", id); |
---|
| 274 | if(id == storyID) |
---|
| 275 | { |
---|
| 276 | //printf("Campaing::getStoryEntity() - yea, this is what we where looking for: %id\n"); |
---|
| 277 | return entity; |
---|
| 278 | } |
---|
[3832] | 279 | entity = iterator->nextElement(); |
---|
[3608] | 280 | } |
---|
[3832] | 281 | delete iterator; |
---|
[3608] | 282 | |
---|
| 283 | |
---|
[2636] | 284 | return NULL; |
---|
| 285 | } |
---|