Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4336 was 4324, checked in by patrick, 20 years ago

orxonox/trunk: added a debug level at the end to be able to experiment a little with new load modules and game ideas

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