Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/levelloader/src/story_entities/campaign.cc @ 3501

Last change on this file since 3501 was 3501, checked in by chris, 19 years ago

orxonox/branches/levelloader: Feeble attempt to load anything… neither finished nor useful

File size: 4.6 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 "campaign.h"
20#include "world.h"
21#include "camera.h"
22#include "story_entity.h"
23
24using namespace std;
25
26
27Campaign::Campaign () 
28{
29  this->entities = new ListTemplate<StoryEntity>();
30  this->isInit = false;
31}
32
33Campaign::~Campaign () {}
34
35Campaign::Campaign ( TiXMLElement* root) 
36{
37        TiXMLElement* element;
38       
39        assert( root != NULL);
40        GameLoader* loader = GameLoader::getInstance();
41       
42  this->entities = new ListTemplate<StoryEntity>();
43  this->isInit = false;
44 
45  // grab all the necessary parameters
46 
47  // find WorldList
48  element = root->FirstChildElement( "WorldList");
49 
50  // load Worlds
51        while( element != NULL)
52        {
53                StoryEntity created = loader->fabricate( element);
54                if( created != NULL) addEntity( created);
55                element = element->nextSiblingElement();
56        }
57}
58
59ErrorMessage Campaign::init()
60{
61  this->isInit = true;
62}
63
64
65ErrorMessage Campaign::start()
66{
67  this->start(0);
68}
69
70
71ErrorMessage Campaign::start(int storyID = 0)
72{
73  printf("World::start() - starting new StoryEntity Nr:%i\n", storyID);
74  ErrorMessage errorCode;
75  if( !this->isInit) return errorCode; 
76  if( storyID == WORLD_ID_GAMEEND) return errorCode;
77  this->running = true;
78  StoryEntity* se = this->getStoryEntity(storyID);
79  this->currentEntity = se;
80  while( se != NULL && this->running)
81    {
82      se->displayLoadScreen();
83      se->load();
84      se->init();
85      se->releaseLoadScreen();
86      se->start();
87      se->destroy();
88     
89      delete se;
90
91      int nextWorldID = se->getNextStoryID();
92      //printf("Campaing::start() - got nextWorldID = %i\n", nextWorldID);
93      se = this->getStoryEntity(nextWorldID);
94      this->currentEntity = se;
95      if( ( nextWorldID == WORLD_ID_GAMEEND) ||( se == NULL) ) 
96        {
97          printf("Campaign::start() - quitting campaing story loop\n");
98          if(se != NULL)
99            delete se;
100          return errorCode;
101        }
102     
103    }
104}
105
106
107ErrorMessage Campaign::pause()
108{
109  if(this->currentEntity != NULL)
110    this->isPaused = true;
111}
112
113
114ErrorMessage Campaign::resume()
115{
116  if(this->currentEntity != NULL)
117    this->isPaused = false;
118}
119
120
121ErrorMessage Campaign::stop()
122{
123  this->running = false;
124  if(this->currentEntity != NULL) 
125    {
126      this->currentEntity->stop();
127      //delete this->currentEntity;
128      //this->currentEntity = NULL;
129    }
130}
131
132
133ErrorMessage Campaign::destroy()
134{
135  if(this->currentEntity != NULL)
136    {
137      this->currentEntity->destroy();
138      delete this->currentEntity;
139      this->currentEntity = NULL;
140    }
141}
142
143
144/**
145    \brief adds an game stroy entity to the campaign
146
147    \param se: The entity
148    \param storyID: The number that identifies the entity in the campaign. Each ID only used once in a Campaign
149
150    An entity can be a world (playable), a cinematic, a shop, sounds, whatever you
151    want to queue up in the campaign.
152*/
153void Campaign::addEntity(StoryEntity* se, int storyID)
154{
155  se->setStoryID(storyID);
156  this->addEntity(se);
157}
158
159void Campaign::addEntity(StoryEntity* se)
160{
161  this->entities->add(se);
162}
163
164
165void Campaign::removeEntity(int storyID)
166{
167  this->removeEntity(this->getStoryEntity(storyID));
168 
169}
170
171
172void Campaign::removeEntity(StoryEntity* se)
173{
174  this->entities->remove(se);
175}
176
177
178/*
179  \brief this changes to the next level
180*/
181void Campaign::nextLevel()
182{
183  printf("Campaign:nextLevel()\n");
184  //int nextID = this->currentEntity->getNextStoryID();
185  //this->stop();
186  //this->start(nextID);
187  this->currentEntity->stop();
188}
189
190/*
191  \brief change to the previous level - not implemented
192
193  this propably useless
194*/
195void Campaign::previousLevel()
196{}
197
198
199/*
200  \brief lookup a entity with a given id
201  \param story id to be lookuped
202  \returns the entity found or NULL if search ended without match
203*/
204StoryEntity* Campaign::getStoryEntity(int storyID)
205{
206  //printf("Campaing::getStoryEntity(%i) - getting next Entity\n", storyID);
207  if( storyID == WORLD_ID_GAMEEND)
208    return NULL;
209  ListTemplate<StoryEntity>* l;
210  StoryEntity* entity = NULL;
211  l = this->entities->getNext(); 
212  while( l != NULL) 
213    { 
214      entity = l->getObject();
215      l = l->getNext();
216      int id = entity->getStoryID();
217      //printf("Campaing::getStoryEntity() - now looping, found entity nr=%i\n", id);
218      if(id == storyID)
219        {
220          //printf("Campaing::getStoryEntity() - yea, this is what we where looking for: %id\n");
221          return entity;
222        }
223    }
224  return NULL;
225}
Note: See TracBrowser for help on using the repository browser.