Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4324 was 4324, checked in by patrick, 19 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
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 "campaign.h"
[3629]20
[4010]21#include "game_loader.h"
[3629]22#include "story_entity.h"
23
[2636]24#include "world.h"
25#include "camera.h"
[3629]26
[3608]27#include "list.h"
[2636]28
[4261]29#include "load_param.h"
30
[2636]31using namespace std;
32
33
34Campaign::Campaign () 
35{
[3608]36  this->entities = new tList<StoryEntity>();
[2636]37  this->isInit = false;
38}
[4261]39
[4010]40Campaign::Campaign ( TiXmlElement* root) 
41{
42  TiXmlElement* element;
43  const char* string;
44  int id;
45 
[4114]46  PRINTF(3)("Loading Campaign...\n");
[4010]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    {
[4114]58      PRINTF(2)("Campaign is missing a proper 'identifier'\n");
[4010]59      this->setStoryID( -1);
60    }
61  else this->setStoryID( id);
62 
63  // find WorldList
64  element = root->FirstChildElement( "WorldList");
65  if( element == NULL)
66    {
[4114]67      PRINTF(2)("Campaign is missing a proper 'WorldList'\n");
[4010]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}
[2636]94
95Campaign::~Campaign () {}
96
97
[3222]98ErrorMessage Campaign::init()
[2636]99{
100  this->isInit = true;
101}
102
103
[3222]104ErrorMessage Campaign::start()
[2636]105{
106  this->start(0);
107}
108
[3459]109
[3222]110ErrorMessage Campaign::start(int storyID = 0)
[2636]111{
[3222]112  ErrorMessage errorCode;
[3221]113  if( !this->isInit) return errorCode; 
114  if( storyID == WORLD_ID_GAMEEND) return errorCode;
[2636]115  this->running = true;
116  StoryEntity* se = this->getStoryEntity(storyID);
[3220]117  this->currentEntity = se;
[3221]118  while( se != NULL && this->running)
[2636]119    {
[4324]120      PRINTF(0)("Starting new StoryEntity Nr:%i\n", se->getStoryID());
[3220]121      se->displayLoadScreen();
[3629]122      se->preLoad();
[2636]123      se->load();
124      se->init();
[3220]125      se->releaseLoadScreen();
[2636]126      se->start();
[3221]127      se->destroy();
128     
[3220]129      delete se;
130
[2636]131      int nextWorldID = se->getNextStoryID();
[3220]132      //printf("Campaing::start() - got nextWorldID = %i\n", nextWorldID);
[2636]133      se = this->getStoryEntity(nextWorldID);
[3220]134      this->currentEntity = se;
135      if( ( nextWorldID == WORLD_ID_GAMEEND) ||( se == NULL) ) 
136        {
[4324]137          PRINTF(0)("Quitting campaing story loop\n");
[3220]138          if(se != NULL)
139            delete se;
140          return errorCode;
141        }
142     
[2636]143    }
144}
145
146
[3222]147ErrorMessage Campaign::pause()
[2636]148{
149  if(this->currentEntity != NULL)
150    this->isPaused = true;
151}
152
153
[3222]154ErrorMessage Campaign::resume()
[2636]155{
156  if(this->currentEntity != NULL)
157    this->isPaused = false;
158}
159
160
[3459]161ErrorMessage Campaign::stop()
[3220]162{
[3459]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{
[3220]175  if(this->currentEntity != NULL)
176    {
177      this->currentEntity->destroy();
178      delete this->currentEntity;
179      this->currentEntity = NULL;
180    }
181}
182
[3459]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
[3225]218/*
219  \brief this changes to the next level
220*/
[2636]221void Campaign::nextLevel()
222{
[3220]223  printf("Campaign:nextLevel()\n");
224  //int nextID = this->currentEntity->getNextStoryID();
225  //this->stop();
226  //this->start(nextID);
227  this->currentEntity->stop();
[2636]228}
229
[3225]230/*
231  \brief change to the previous level - not implemented
232
233  this propably useless
234*/
[2636]235void Campaign::previousLevel()
236{}
237
238
[3225]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*/
[3220]244StoryEntity* Campaign::getStoryEntity(int storyID)
[2636]245{
[3220]246  //printf("Campaing::getStoryEntity(%i) - getting next Entity\n", storyID);
247  if( storyID == WORLD_ID_GAMEEND)
248    return NULL;
[3608]249
250  /*
251  tList<StoryEntity>* l;
[3220]252  StoryEntity* entity = NULL;
[3231]253  l = this->entities->getNext(); 
[2636]254  while( l != NULL)
255    {
[3231]256      entity = l->getObject();
257      l = l->getNext();
[3608]258
[3220]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        }
[3608]266
[2636]267    }
[3608]268  */
269
270
[3832]271  tIterator<StoryEntity>* iterator = this->entities->getIterator();
272  StoryEntity* entity = iterator->nextElement();
[3608]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        }
[3832]282      entity = iterator->nextElement();
[3608]283    }
[3832]284  delete iterator;
[3608]285
286
[2636]287  return NULL;
288}
Note: See TracBrowser for help on using the repository browser.