Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: better algorithm for loading the Shader through the ResourceManager
if a fragment-Shader was supplied, but the file did not exist, the Shader gets rejected

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