Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4178 was 4114, checked in by bensch, 20 years ago

orxonox/trunk: minor cleanup/windowsTest

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