Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/heightMap/src/game_loader.cc @ 4080

Last change on this file since 4080 was 4021, checked in by nico, 20 years ago

branches/heightmap/: created new empty files for the heightmap class.

File size: 4.7 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
28#include <string.h>
29
30
31using namespace std;
32
33
34GameLoader* GameLoader::singletonRef = 0;
35
36
37GameLoader::GameLoader () {}
38
39
40GameLoader::~GameLoader () {}
41
42
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*/
49GameLoader* GameLoader::getInstance()
50{
51  if(singletonRef == NULL)
52    singletonRef = new GameLoader();
53  return singletonRef;
54}
55
56
57ErrorMessage GameLoader::init()
58{
59  if(this->currentCampaign != NULL)
60    this->currentCampaign->init();
61}
62
63
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*/
71ErrorMessage GameLoader::loadCampaign(char* name)
72{
73  ErrorMessage errorCode;
74 
75  this->currentCampaign = this->fileToCampaign(name);
76}
77
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*/
84ErrorMessage GameLoader::loadDebugCampaign(Uint32 campaignID)
85{
86  switch(campaignID)
87    {
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      */
94    case DEBUG_CAMPAIGN_0:
95      {
96        Campaign* debugCampaign = new Campaign();
97
98/*
99        World* world0 = new World(DEBUG_WORLD_0);
100        world0->setNextStoryID(WORLD_ID_1);
101        debugCampaign->addEntity(world0, WORLD_ID_0);
102
103        World* world1 = new World(DEBUG_WORLD_1);
104        world1->setNextStoryID(WORLD_ID_2);
105        debugCampaign->addEntity(world1, WORLD_ID_1);
106
107        World* world2 = new World(DEBUG_WORLD_2);
108        world2->setNextStoryID(WORLD_ID_3);
109        debugCampaign->addEntity(world2, WORLD_ID_2);
110*/
111        World* world3 = new World(DEBUG_WORLD_3);
112        world3->setNextStoryID(WORLD_ID_GAMEEND);
113        debugCampaign->addEntity(world3, WORLD_ID_0);
114
115        this->currentCampaign = debugCampaign;
116        break;
117      }
118    }
119}
120
121ErrorMessage GameLoader::start()
122{
123  if(this->currentCampaign != NULL)
124    this->currentCampaign->start();
125}
126
127
128ErrorMessage GameLoader::stop()
129{
130  if(this->currentCampaign != NULL)
131    this->currentCampaign->stop();
132  this->currentCampaign = NULL;
133}
134
135
136ErrorMessage GameLoader::pause()
137{
138  this->isPaused = true;
139  if(this->currentCampaign != NULL)
140    this->currentCampaign->pause();
141}
142
143
144ErrorMessage GameLoader::resume()
145{
146  this->isPaused = false;
147  if(this->currentCampaign != NULL)
148    this->currentCampaign->resume();
149}
150
151/**
152   \brief release the mem
153 */
154ErrorMessage GameLoader::destroy()
155{}
156
157
158/**
159   \brief reads a campaign definition file into a campaign class
160   \param filename to be loaded
161   \returns the loaded campaign
162
163   this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns
164*/
165Campaign* GameLoader::fileToCampaign(char *name)
166{
167  /* do not entirely load the campaign. just the current world
168     before start of each world, it has to be initialized so it
169     can load everything it needs into memory then.
170  */
171}
172
173
174/**
175   \brief handle keyboard commands
176   \param cmd: the command to handle
177   \returns true if the command was handled by the system
178*/
179bool GameLoader::worldCommand (Command* cmd)
180{
181  if( !strcmp( cmd->cmd, "up_world"))
182    {
183      if( !cmd->bUp) 
184        {
185          this->nextLevel();
186        }
187      return true;
188    }
189  else if( !strcmp( cmd->cmd, "down_world"))
190    {
191      if( !cmd->bUp)
192        {
193          this->previousLevel();
194        }
195      return true;
196    }
197  else if( !strcmp( cmd->cmd, "pause"))
198    {
199      if( !cmd->bUp)
200        {
201          if(this->isPaused)
202            this->resume();
203          else
204            this->pause();
205        }
206      return true;
207    }
208  else if( !strcmp( cmd->cmd, "quit"))
209    {
210      if( !cmd->bUp) this->stop();
211      return true;
212    }
213  return false;
214}
215
216
217/*
218  \brief this changes to the next level
219*/
220void GameLoader::nextLevel()
221{
222  if(this->currentCampaign != NULL)
223    this->currentCampaign->nextLevel();
224}
225
226
227/*
228  \brief change to the previous level - not implemented
229
230  this propably useless
231*/
232void GameLoader::previousLevel()
233{
234  if(this->currentCampaign != NULL)
235    this->currentCampaign->previousLevel();
236}
Note: See TracBrowser for help on using the repository browser.