Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6152 was 6152, checked in by bensch, 18 years ago

orxonox/trunk: some work in the loading process of worlds

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