Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/story_entities/campaign.cc @ 4657

Last change on this file since 4657 was 4600, checked in by bensch, 19 years ago

orxonox/trunk: better output

File size: 6.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 "campaign.h"
20
21#include "game_loader.h"
22#include "story_entity.h"
23
24#include "world.h"
25#include "camera.h"
26
27#include "list.h"
28
29#include "load_param.h"
30
31using namespace std;
32
33
34Campaign::Campaign ()
35{
36  this->setClassID(CL_CAMPAIGN, "Campaign");
37  this->entities = new tList<StoryEntity>();
38  this->isInit = false;
39}
40
41Campaign::Campaign ( TiXmlElement* root)
42{
43  this->setClassID(CL_CAMPAIGN, "Campaign");
44
45  PRINTF(3)("Loading Campaign...\n");
46
47  assert( root != NULL);
48
49  this->entities = new tList<StoryEntity>();
50  this->isInit = false;
51
52  this->loadParams(root);
53
54
55  //if( lastCreated != NULL)
56  //lastCreated->setStoryID( WORLD_ID_GAMEEND);
57}
58
59Campaign::~Campaign () {}
60
61
62ErrorMessage Campaign::init()
63{
64  this->isInit = true;
65}
66
67/**
68  \brief loads the Parameters of a Campaign
69  \param root: The XML-element to load from
70 */
71void Campaign::loadParams(const TiXmlElement* root)
72{
73  static_cast<BaseObject*>(this)->loadParams(root);
74
75  LoadParam<Campaign>(root, "identifier", this, &Campaign::setStoryID)
76      .describe("A Unique Identifier for this Campaign");
77
78  LoadParam<Campaign>(root, "WorldList", this, &Campaign::loadWorldListParams)
79      .describe("A List of Worlds to be loaded in this Campaign");
80}
81
82/**
83  \brief loads a WorldList
84  \param root: the XML-element to load from
85 */
86void Campaign::loadWorldListParams(const TiXmlElement* root)
87{
88  const TiXmlElement* element = root->FirstChildElement();
89  // load Worlds/Subcampaigns/Whatever
90  StoryEntity* lastCreated = NULL;
91  while( element != NULL)
92  {
93    printf("Campaign: Constructor: adding a world\n");
94    StoryEntity* created = (StoryEntity*) GameLoader::getInstance()->fabricate(element);
95      /*
96    if( lastCreated != NULL)
97    created->setNextStoryID( lastCreated->getStoryID());
98    else
99    created->setNextStoryID( WORLD_ID_GAMEEND);
100      */
101    if( created != NULL)
102    {
103      this->addEntity( created);
104      lastCreated = created;
105    }
106    element = element->NextSiblingElement();
107  }
108}
109
110ErrorMessage Campaign::start()
111{
112  this->start(0);
113}
114
115
116ErrorMessage Campaign::start(int storyID = 0)
117{
118  ErrorMessage errorCode;
119  if( !this->isInit) return errorCode;
120  if( storyID == WORLD_ID_GAMEEND) return errorCode;
121  this->running = true;
122  StoryEntity* se = this->getStoryEntity(storyID);
123  this->currentEntity = se;
124  while( se != NULL && this->running)
125    {
126      PRINTF(0)("Starting new StoryEntity Nr:%i\n", se->getStoryID());
127      se->displayLoadScreen();
128      se->preLoad();
129      se->load();
130      se->init();
131      se->releaseLoadScreen();
132      se->start();
133      se->destroy();
134
135      delete se;
136
137      int nextWorldID = se->getNextStoryID();
138      //printf("Campaing::start() - got nextWorldID = %i\n", nextWorldID);
139      se = this->getStoryEntity(nextWorldID);
140      this->currentEntity = se;
141      if( ( nextWorldID == WORLD_ID_GAMEEND) ||( se == NULL) )
142        {
143          PRINTF(0)("Quitting campaing story loop\n");
144          if(se != NULL)
145            delete se;
146          return errorCode;
147        }
148
149    }
150}
151
152
153ErrorMessage Campaign::pause()
154{
155  if(this->currentEntity != NULL)
156    this->isPaused = true;
157}
158
159
160ErrorMessage Campaign::resume()
161{
162  if(this->currentEntity != NULL)
163    this->isPaused = false;
164}
165
166
167ErrorMessage Campaign::stop()
168{
169  this->running = false;
170  if(this->currentEntity != NULL)
171    {
172      this->currentEntity->stop();
173      //delete this->currentEntity;
174      //this->currentEntity = NULL;
175    }
176}
177
178
179ErrorMessage Campaign::destroy()
180{
181  if(this->currentEntity != NULL)
182    {
183      this->currentEntity->destroy();
184      delete this->currentEntity;
185      this->currentEntity = NULL;
186    }
187}
188
189
190/**
191    \brief adds an game stroy entity to the campaign
192
193    \param se: The entity
194    \param storyID: The number that identifies the entity in the campaign. Each ID only used once in a Campaign
195
196    An entity can be a world (playable), a cinematic, a shop, sounds, whatever you
197    want to queue up in the campaign.
198*/
199void Campaign::addEntity(StoryEntity* se, int storyID)
200{
201  se->setStoryID(storyID);
202  this->addEntity(se);
203}
204
205void Campaign::addEntity(StoryEntity* se)
206{
207  this->entities->add(se);
208}
209
210
211void Campaign::removeEntity(int storyID)
212{
213  this->removeEntity(this->getStoryEntity(storyID));
214
215}
216
217
218void Campaign::removeEntity(StoryEntity* se)
219{
220  this->entities->remove(se);
221}
222
223
224/*
225  \brief this changes to the next level
226*/
227void Campaign::nextLevel()
228{
229  printf("Campaign:nextLevel()\n");
230  //int nextID = this->currentEntity->getNextStoryID();
231  //this->stop();
232  //this->start(nextID);
233  this->currentEntity->stop();
234}
235
236/*
237  \brief change to the previous level - not implemented
238
239  this propably useless
240*/
241void Campaign::previousLevel()
242{}
243
244
245/*
246  \brief lookup a entity with a given id
247  \param story id to be lookuped
248  \returns the entity found or NULL if search ended without match
249*/
250StoryEntity* Campaign::getStoryEntity(int storyID)
251{
252  //printf("Campaing::getStoryEntity(%i) - getting next Entity\n", storyID);
253  if( storyID == WORLD_ID_GAMEEND)
254    return NULL;
255
256  /*
257  tList<StoryEntity>* l;
258  StoryEntity* entity = NULL;
259  l = this->entities->getNext();
260  while( l != NULL)
261    {
262      entity = l->getObject();
263      l = l->getNext();
264
265      int id = entity->getStoryID();
266      //printf("Campaing::getStoryEntity() - now looping, found entity nr=%i\n", id);
267      if(id == storyID)
268        {
269          //printf("Campaing::getStoryEntity() - yea, this is what we where looking for: %id\n");
270          return entity;
271        }
272
273    }
274  */
275
276
277  tIterator<StoryEntity>* iterator = this->entities->getIterator();
278  StoryEntity* entity = iterator->nextElement();
279  while( entity != NULL)
280    {
281      int id = entity->getStoryID();
282      //printf("Campaing::getStoryEntity() - now looping, found entity nr=%i\n", id);
283      if(id == storyID)
284        {
285          //printf("Campaing::getStoryEntity() - yea, this is what we where looking for: %id\n");
286          return entity;
287        }
288      entity = iterator->nextElement();
289    }
290  delete iterator;
291
292
293  return NULL;
294}
Note: See TracBrowser for help on using the repository browser.