Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: setClassID implemented in all files

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