Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 3536 was 3530, checked in by chris, 20 years ago

orxonox/branches/levelloader: Got the system to compile, the basic backbone now runs. What remains to be done is implementing all necessary functions to load all vital classes into a world

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