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