[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 "game_loader.h" |
---|
| 20 | #include "campaign.h" |
---|
| 21 | #include "world.h" |
---|
| 22 | #include "player.h" |
---|
| 23 | #include "orxonox.h" |
---|
| 24 | #include "camera.h" |
---|
| 25 | #include "command_node.h" |
---|
| 26 | #include "vector.h" |
---|
| 27 | |
---|
| 28 | #include <string.h> |
---|
| 29 | |
---|
| 30 | |
---|
| 31 | using namespace std; |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | GameLoader* GameLoader::singletonRef = 0; |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | GameLoader::GameLoader () {} |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | GameLoader::~GameLoader () {} |
---|
| 41 | |
---|
| 42 | |
---|
[3225] | 43 | /** |
---|
| 44 | \brief this class is a singleton class |
---|
| 45 | \returns an instance of itself |
---|
| 46 | |
---|
| 47 | if you are unsure about singleton classes, check the theory out on the internet :) |
---|
| 48 | */ |
---|
[2636] | 49 | GameLoader* GameLoader::getInstance() |
---|
| 50 | { |
---|
| 51 | if(singletonRef == NULL) |
---|
| 52 | singletonRef = new GameLoader(); |
---|
| 53 | return singletonRef; |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | |
---|
[3222] | 57 | ErrorMessage GameLoader::init() |
---|
[2636] | 58 | { |
---|
| 59 | if(this->currentCampaign != NULL) |
---|
| 60 | this->currentCampaign->init(); |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | |
---|
[3225] | 64 | /** |
---|
| 65 | \brief reads a campaign definition file into a campaign class |
---|
| 66 | \param filename to be loaded |
---|
| 67 | \returns the loaded campaign |
---|
| 68 | |
---|
| 69 | this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns |
---|
| 70 | */ |
---|
[3222] | 71 | ErrorMessage GameLoader::loadCampaign(char* name) |
---|
[2636] | 72 | { |
---|
[3222] | 73 | ErrorMessage errorCode; |
---|
[2636] | 74 | |
---|
| 75 | this->currentCampaign = this->fileToCampaign(name); |
---|
| 76 | } |
---|
| 77 | |
---|
[3225] | 78 | |
---|
| 79 | /** |
---|
| 80 | \brief loads a debug campaign for test purposes only. |
---|
| 81 | \param the identifier of the campaign. |
---|
| 82 | \returns error message if not able to do so. |
---|
| 83 | */ |
---|
[3222] | 84 | ErrorMessage GameLoader::loadDebugCampaign(Uint32 campaignID) |
---|
[2636] | 85 | { |
---|
| 86 | switch(campaignID) |
---|
| 87 | { |
---|
[3629] | 88 | /* |
---|
| 89 | Debug Level 0: Debug level used to test the base frame work. |
---|
| 90 | As you can see, all storyentity data is allocated before game |
---|
| 91 | start. the storyentity will load themselfs shortly before start |
---|
| 92 | through the StoryEntity::init() funtion. |
---|
| 93 | */ |
---|
[2636] | 94 | case DEBUG_CAMPAIGN_0: |
---|
| 95 | { |
---|
| 96 | Campaign* debugCampaign = new Campaign(); |
---|
[3220] | 97 | |
---|
[2636] | 98 | World* world0 = new World(DEBUG_WORLD_0); |
---|
[3220] | 99 | world0->setNextStoryID(WORLD_ID_1); |
---|
[2636] | 100 | debugCampaign->addEntity(world0, WORLD_ID_0); |
---|
[3220] | 101 | |
---|
[2636] | 102 | World* world1 = new World(DEBUG_WORLD_1); |
---|
[3727] | 103 | world1->setNextStoryID(WORLD_ID_2); |
---|
[2636] | 104 | debugCampaign->addEntity(world1, WORLD_ID_1); |
---|
| 105 | |
---|
[3727] | 106 | World* world2 = new World(DEBUG_WORLD_2); |
---|
| 107 | world2->setNextStoryID(WORLD_ID_GAMEEND); |
---|
| 108 | debugCampaign->addEntity(world2, WORLD_ID_2); |
---|
| 109 | |
---|
[2636] | 110 | this->currentCampaign = debugCampaign; |
---|
| 111 | break; |
---|
| 112 | } |
---|
| 113 | } |
---|
| 114 | } |
---|
| 115 | |
---|
[3222] | 116 | ErrorMessage GameLoader::start() |
---|
[2636] | 117 | { |
---|
| 118 | if(this->currentCampaign != NULL) |
---|
| 119 | this->currentCampaign->start(); |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | |
---|
[3222] | 123 | ErrorMessage GameLoader::stop() |
---|
[2636] | 124 | { |
---|
| 125 | if(this->currentCampaign != NULL) |
---|
| 126 | this->currentCampaign->stop(); |
---|
| 127 | this->currentCampaign = NULL; |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | |
---|
[3222] | 131 | ErrorMessage GameLoader::pause() |
---|
[2636] | 132 | { |
---|
| 133 | this->isPaused = true; |
---|
| 134 | if(this->currentCampaign != NULL) |
---|
| 135 | this->currentCampaign->pause(); |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | |
---|
[3222] | 139 | ErrorMessage GameLoader::resume() |
---|
[2636] | 140 | { |
---|
| 141 | this->isPaused = false; |
---|
| 142 | if(this->currentCampaign != NULL) |
---|
| 143 | this->currentCampaign->resume(); |
---|
| 144 | } |
---|
| 145 | |
---|
[3225] | 146 | /** |
---|
| 147 | \brief release the mem |
---|
| 148 | */ |
---|
| 149 | ErrorMessage GameLoader::destroy() |
---|
[2636] | 150 | {} |
---|
| 151 | |
---|
| 152 | |
---|
[3225] | 153 | /** |
---|
| 154 | \brief reads a campaign definition file into a campaign class |
---|
| 155 | \param filename to be loaded |
---|
| 156 | \returns the loaded campaign |
---|
| 157 | |
---|
| 158 | this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns |
---|
| 159 | */ |
---|
[2636] | 160 | Campaign* GameLoader::fileToCampaign(char *name) |
---|
| 161 | { |
---|
| 162 | /* do not entirely load the campaign. just the current world |
---|
| 163 | before start of each world, it has to be initialized so it |
---|
| 164 | can load everything it needs into memory then. |
---|
| 165 | */ |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | |
---|
| 169 | /** |
---|
| 170 | \brief handle keyboard commands |
---|
| 171 | \param cmd: the command to handle |
---|
[3225] | 172 | \returns true if the command was handled by the system |
---|
[2636] | 173 | */ |
---|
| 174 | bool GameLoader::worldCommand (Command* cmd) |
---|
| 175 | { |
---|
| 176 | if( !strcmp( cmd->cmd, "up_world")) |
---|
| 177 | { |
---|
| 178 | if( !cmd->bUp) |
---|
| 179 | { |
---|
| 180 | this->nextLevel(); |
---|
| 181 | } |
---|
| 182 | return true; |
---|
| 183 | } |
---|
| 184 | else if( !strcmp( cmd->cmd, "down_world")) |
---|
| 185 | { |
---|
| 186 | if( !cmd->bUp) |
---|
| 187 | { |
---|
| 188 | this->previousLevel(); |
---|
| 189 | } |
---|
| 190 | return true; |
---|
| 191 | } |
---|
| 192 | else if( !strcmp( cmd->cmd, "pause")) |
---|
| 193 | { |
---|
| 194 | if( !cmd->bUp) |
---|
| 195 | { |
---|
| 196 | if(this->isPaused) |
---|
| 197 | this->resume(); |
---|
| 198 | else |
---|
| 199 | this->pause(); |
---|
| 200 | } |
---|
| 201 | return true; |
---|
| 202 | } |
---|
[3220] | 203 | else if( !strcmp( cmd->cmd, "quit")) |
---|
| 204 | { |
---|
| 205 | if( !cmd->bUp) this->stop(); |
---|
| 206 | return true; |
---|
| 207 | } |
---|
[2636] | 208 | return false; |
---|
| 209 | } |
---|
| 210 | |
---|
[3225] | 211 | |
---|
| 212 | /* |
---|
| 213 | \brief this changes to the next level |
---|
| 214 | */ |
---|
[2636] | 215 | void GameLoader::nextLevel() |
---|
| 216 | { |
---|
| 217 | if(this->currentCampaign != NULL) |
---|
| 218 | this->currentCampaign->nextLevel(); |
---|
| 219 | } |
---|
| 220 | |
---|
[3225] | 221 | |
---|
| 222 | /* |
---|
| 223 | \brief change to the previous level - not implemented |
---|
| 224 | |
---|
| 225 | this propably useless |
---|
| 226 | */ |
---|
[2636] | 227 | void GameLoader::previousLevel() |
---|
| 228 | { |
---|
| 229 | if(this->currentCampaign != NULL) |
---|
| 230 | this->currentCampaign->previousLevel(); |
---|
| 231 | } |
---|