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