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