Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/levelloader/src/story_entities/campaign.cc @ 3525

Last change on this file since 3525 was 3525, checked in by chris, 19 years ago

orxonox/branches/levelloader: removed excess class usage adn messed with makefile definitions

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