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