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