Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/game_loader.cc @ 3390

Last change on this file since 3390 was 3225, checked in by patrick, 20 years ago

/orxonox/trunk: unstable - added many comments and now redefinit all function/variable names with underline

File size: 4.3 KB
Line 
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
32using namespace std;
33
34
35GameLoader* GameLoader::singletonRef = 0;
36
37
38GameLoader::GameLoader () {}
39
40
41GameLoader::~GameLoader () {}
42
43
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*/
50GameLoader* GameLoader::getInstance()
51{
52  if(singletonRef == NULL)
53    singletonRef = new GameLoader();
54  return singletonRef;
55}
56
57
58ErrorMessage GameLoader::init()
59{
60  if(this->currentCampaign != NULL)
61    this->currentCampaign->init();
62}
63
64
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*/
72ErrorMessage GameLoader::loadCampaign(char* name)
73{
74  ErrorMessage errorCode;
75 
76  this->currentCampaign = this->fileToCampaign(name);
77}
78
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*/
85ErrorMessage GameLoader::loadDebugCampaign(Uint32 campaignID)
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();
93
94        World* world0 = new World(DEBUG_WORLD_0);
95        world0->setNextStoryID(WORLD_ID_1);
96        debugCampaign->addEntity(world0, WORLD_ID_0);
97
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
108ErrorMessage GameLoader::start()
109{
110  if(this->currentCampaign != NULL)
111    this->currentCampaign->start();
112}
113
114
115ErrorMessage GameLoader::stop()
116{
117  if(this->currentCampaign != NULL)
118    this->currentCampaign->stop();
119  this->currentCampaign = NULL;
120}
121
122
123ErrorMessage GameLoader::pause()
124{
125  this->isPaused = true;
126  if(this->currentCampaign != NULL)
127    this->currentCampaign->pause();
128}
129
130
131ErrorMessage GameLoader::resume()
132{
133  this->isPaused = false;
134  if(this->currentCampaign != NULL)
135    this->currentCampaign->resume();
136}
137
138/**
139   \brief release the mem
140 */
141ErrorMessage GameLoader::destroy()
142{}
143
144
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*/
152Campaign* 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
164   \returns true if the command was handled by the system
165*/
166bool 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    }
195  else if( !strcmp( cmd->cmd, "quit"))
196    {
197      if( !cmd->bUp) this->stop();
198      return true;
199    }
200  return false;
201}
202
203
204/*
205  \brief this changes to the next level
206*/
207void GameLoader::nextLevel()
208{
209  if(this->currentCampaign != NULL)
210    this->currentCampaign->nextLevel();
211}
212
213
214/*
215  \brief change to the previous level - not implemented
216
217  this propably useless
218*/
219void GameLoader::previousLevel()
220{
221  if(this->currentCampaign != NULL)
222    this->currentCampaign->previousLevel();
223}
Note: See TracBrowser for help on using the repository browser.