| 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 | { |
|---|
| 29 | this->entities = new ListTemplate<StoryEntity>(); |
|---|
| 30 | this->isInit = false; |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | Campaign::~Campaign () {} |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | ErrorMessage Campaign::init() |
|---|
| 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 | */ |
|---|
| 50 | void Campaign::addEntity(StoryEntity* se, int storyID) |
|---|
| 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 | |
|---|
| 62 | void Campaign::removeEntity(int storyID) |
|---|
| 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 | |
|---|
| 75 | ErrorMessage Campaign::start() |
|---|
| 76 | { |
|---|
| 77 | this->start(0); |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | ErrorMessage Campaign::start(int storyID = 0) |
|---|
| 81 | { |
|---|
| 82 | printf("World::start() - starting new StoryEntity Nr:%i\n", storyID); |
|---|
| 83 | ErrorMessage errorCode; |
|---|
| 84 | if( !this->isInit) return errorCode; |
|---|
| 85 | if( storyID == WORLD_ID_GAMEEND) return errorCode; |
|---|
| 86 | this->running = true; |
|---|
| 87 | StoryEntity* se = this->getStoryEntity(storyID); |
|---|
| 88 | this->currentEntity = se; |
|---|
| 89 | while( se != NULL && this->running) |
|---|
| 90 | { |
|---|
| 91 | se->displayLoadScreen(); |
|---|
| 92 | se->load(); |
|---|
| 93 | se->init(); |
|---|
| 94 | se->releaseLoadScreen(); |
|---|
| 95 | se->start(); |
|---|
| 96 | se->destroy(); |
|---|
| 97 | |
|---|
| 98 | delete se; |
|---|
| 99 | |
|---|
| 100 | int nextWorldID = se->getNextStoryID(); |
|---|
| 101 | //printf("Campaing::start() - got nextWorldID = %i\n", nextWorldID); |
|---|
| 102 | se = this->getStoryEntity(nextWorldID); |
|---|
| 103 | this->currentEntity = se; |
|---|
| 104 | if( ( nextWorldID == WORLD_ID_GAMEEND) ||( se == NULL) ) |
|---|
| 105 | { |
|---|
| 106 | printf("Campaign::start() - quitting campaing story loop\n"); |
|---|
| 107 | if(se != NULL) |
|---|
| 108 | delete se; |
|---|
| 109 | return errorCode; |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | } |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | ErrorMessage Campaign::stop() |
|---|
| 116 | { |
|---|
| 117 | this->running = false; |
|---|
| 118 | if(this->currentEntity != NULL) |
|---|
| 119 | { |
|---|
| 120 | this->currentEntity->stop(); |
|---|
| 121 | //delete this->currentEntity; |
|---|
| 122 | //this->currentEntity = NULL; |
|---|
| 123 | } |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | ErrorMessage Campaign::pause() |
|---|
| 127 | { |
|---|
| 128 | if(this->currentEntity != NULL) |
|---|
| 129 | this->isPaused = true; |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | |
|---|
| 133 | ErrorMessage Campaign::resume() |
|---|
| 134 | { |
|---|
| 135 | if(this->currentEntity != NULL) |
|---|
| 136 | this->isPaused = false; |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | |
|---|
| 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 | |
|---|
| 150 | /* |
|---|
| 151 | \brief this changes to the next level |
|---|
| 152 | */ |
|---|
| 153 | void Campaign::nextLevel() |
|---|
| 154 | { |
|---|
| 155 | printf("Campaign:nextLevel()\n"); |
|---|
| 156 | //int nextID = this->currentEntity->getNextStoryID(); |
|---|
| 157 | //this->stop(); |
|---|
| 158 | //this->start(nextID); |
|---|
| 159 | this->currentEntity->stop(); |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | /* |
|---|
| 163 | \brief change to the previous level - not implemented |
|---|
| 164 | |
|---|
| 165 | this propably useless |
|---|
| 166 | */ |
|---|
| 167 | void Campaign::previousLevel() |
|---|
| 168 | {} |
|---|
| 169 | |
|---|
| 170 | |
|---|
| 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 | */ |
|---|
| 176 | StoryEntity* Campaign::getStoryEntity(int storyID) |
|---|
| 177 | { |
|---|
| 178 | //printf("Campaing::getStoryEntity(%i) - getting next Entity\n", storyID); |
|---|
| 179 | if( storyID == WORLD_ID_GAMEEND) |
|---|
| 180 | return NULL; |
|---|
| 181 | ListTemplate<StoryEntity>* l; |
|---|
| 182 | StoryEntity* entity = NULL; |
|---|
| 183 | l = this->entities->getNext(); |
|---|
| 184 | while( l != NULL) |
|---|
| 185 | { |
|---|
| 186 | entity = l->getObject(); |
|---|
| 187 | l = l->getNext(); |
|---|
| 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 | } |
|---|
| 195 | } |
|---|
| 196 | return NULL; |
|---|
| 197 | } |
|---|