Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/trackManager/src/game_loader.cc @ 3500

Last change on this file since 3500 was 3374, checked in by bensch, 20 years ago

orxonox/branches/trackManager: deleted old track-system

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