Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/campaign.cc @ 3220

Last change on this file since 3220 was 3220, checked in by patrick, 19 years ago

orxonox/trunk: fixed a lot of bugs with StoryEntity management, also cleared up some old unused code

File size: 3.8 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
24using namespace std;
25
26
27Campaign::Campaign () 
28{
29  this->entities = new ListTemplate<StoryEntity>();
30  this->isInit = false;
31}
32
33Campaign::~Campaign () {}
34
35
36Error Campaign::init()
37{
38  this->isInit = true;
39}
40
41/**
42    \brief adds an game stroy entity to the campaign
43
44    \param se: The entity
45    \param storyID: The number that identifies the entity in the campaign. Each ID only used once in a Campaign
46
47    An entity can be a world (playable), a cinematic, a shop, sounds, whatever you
48    want to queue up in the campaign.
49*/
50void Campaign::addEntity(StoryEntity* se, int storyID)
51{
52  se->setStoryID(storyID);
53  this->addEntity(se);
54}
55
56void Campaign::addEntity(StoryEntity* se)
57{
58  this->entities->add(se);
59}
60
61
62void Campaign::removeEntity(int storyID)
63{
64  this->removeEntity(this->getStoryEntity(storyID));
65 
66}
67
68
69void Campaign::removeEntity(StoryEntity* se)
70{
71  this->entities->remove(se);
72}
73
74
75Error Campaign::start()
76{
77  this->start(0);
78}
79
80Error Campaign::start(int storyID = 0)
81{
82  printf("World::start() - starting new StoryEntity Nr:%i\n", storyID);
83  Error errorCode;
84  if(!this->isInit) return errorCode; 
85  if(storyID == WORLD_ID_GAMEEND) return errorCode;
86  this->running = true;
87  StoryEntity* se = this->getStoryEntity(storyID);
88  this->currentEntity = se;
89  while(se != NULL && this->running)
90    {
91      //se = this->getStoryEntity(storyID);
92     
93     
94      se->displayLoadScreen();
95      se->load();
96      se->init();
97      se->releaseLoadScreen();
98      se->start();
99
100      delete se;
101
102      int nextWorldID = se->getNextStoryID();
103      //printf("Campaing::start() - got nextWorldID = %i\n", nextWorldID);
104      se = this->getStoryEntity(nextWorldID);
105      this->currentEntity = se;
106      if( ( nextWorldID == WORLD_ID_GAMEEND) ||( se == NULL) ) 
107        {
108          printf("Campaign::start() - quiting campaing story loop\n");
109          if(se != NULL)
110            delete se;
111          return errorCode;
112        }
113     
114    }
115}
116
117Error Campaign::stop()
118{
119  this->running = false;
120  if(this->currentEntity != NULL) 
121    {
122      this->currentEntity->stop();
123      //delete this->currentEntity;
124      //this->currentEntity = NULL;
125    }
126}
127
128Error Campaign::pause()
129{
130  if(this->currentEntity != NULL)
131    this->isPaused = true;
132}
133
134
135Error Campaign::resume()
136{
137  if(this->currentEntity != NULL)
138    this->isPaused = false;
139}
140
141
142void Campaign::destroy()
143{
144  if(this->currentEntity != NULL)
145    {
146      this->currentEntity->destroy();
147      delete this->currentEntity;
148      this->currentEntity = NULL;
149    }
150}
151
152void Campaign::nextLevel()
153{
154  printf("Campaign:nextLevel()\n");
155  //int nextID = this->currentEntity->getNextStoryID();
156  //this->stop();
157  //this->start(nextID);
158  this->currentEntity->stop();
159}
160
161void Campaign::previousLevel()
162{}
163
164
165StoryEntity* Campaign::getStoryEntity(int storyID)
166{
167  //printf("Campaing::getStoryEntity(%i) - getting next Entity\n", storyID);
168  if( storyID == WORLD_ID_GAMEEND)
169    return NULL;
170  ListTemplate<StoryEntity>* l;
171  StoryEntity* entity = NULL;
172  l = this->entities->get_next(); 
173  while( l != NULL) 
174    { 
175      entity = l->get_object();
176      l = l->get_next();
177      int id = entity->getStoryID();
178      //printf("Campaing::getStoryEntity() - now looping, found entity nr=%i\n", id);
179      if(id == storyID)
180        {
181          //printf("Campaing::getStoryEntity() - yea, this is what we where looking for: %id\n");
182          return entity;
183        }
184    }
185  return NULL;
186}
Note: See TracBrowser for help on using the repository browser.