Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/sound/src/campaign.cc @ 3291

Last change on this file since 3291 was 3238, checked in by bensch, 20 years ago

orxonox/branches: updated branches: buerli, nico, sound. And moved bezierTrack to old.bezierTrack. Conflicts resolved in a usefull order.
Conflics mostly resolved in favor of trunk
merge.

File size: 4.1 KB
RevLine 
[2636]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{
[3238]29  this->entities = new ListTemplate<StoryEntity>();
[2636]30  this->isInit = false;
31}
32
33Campaign::~Campaign () {}
34
35
[3238]36ErrorMessage Campaign::init()
[2636]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*/
[3238]50void Campaign::addEntity(StoryEntity* se, int storyID)
[2636]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
[3238]62void Campaign::removeEntity(int storyID)
[2636]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
[3238]75ErrorMessage Campaign::start()
[2636]76{
77  this->start(0);
78}
79
[3238]80ErrorMessage Campaign::start(int storyID = 0)
[2636]81{
82  printf("World::start() - starting new StoryEntity Nr:%i\n", storyID);
[3238]83  ErrorMessage errorCode;
84  if( !this->isInit) return errorCode; 
85  if( storyID == WORLD_ID_GAMEEND) return errorCode;
[2636]86  this->running = true;
87  StoryEntity* se = this->getStoryEntity(storyID);
[3238]88  this->currentEntity = se;
89  while( se != NULL && this->running)
[2636]90    {
[3238]91      se->displayLoadScreen();
[2636]92      se->load();
93      se->init();
[3238]94      se->releaseLoadScreen();
[2636]95      se->start();
[3238]96      se->destroy();
97     
98      delete se;
[2636]99
100      int nextWorldID = se->getNextStoryID();
[3238]101      //printf("Campaing::start() - got nextWorldID = %i\n", nextWorldID);
[2636]102      se = this->getStoryEntity(nextWorldID);
[3238]103      this->currentEntity = se;
104      if( ( nextWorldID == WORLD_ID_GAMEEND) ||( se == NULL) ) 
105        {
106          printf("Campaign::start() - quitting campaing story loop\n");
107          if(se != NULL)
108            delete se;
109          return errorCode;
110        }
111     
[2636]112    }
113}
114
[3238]115ErrorMessage Campaign::stop()
[2636]116{
117  this->running = false;
118  if(this->currentEntity != NULL) 
119    {
120      this->currentEntity->stop();
[3238]121      //delete this->currentEntity;
122      //this->currentEntity = NULL;
[2636]123    }
124}
125
[3238]126ErrorMessage Campaign::pause()
[2636]127{
128  if(this->currentEntity != NULL)
129    this->isPaused = true;
130}
131
132
[3238]133ErrorMessage Campaign::resume()
[2636]134{
135  if(this->currentEntity != NULL)
136    this->isPaused = false;
137}
138
139
[3238]140void Campaign::destroy()
141{
142  if(this->currentEntity != NULL)
143    {
144      this->currentEntity->destroy();
145      delete this->currentEntity;
146      this->currentEntity = NULL;
147    }
148}
149
150/*
151  \brief this changes to the next level
152*/
[2636]153void Campaign::nextLevel()
154{
[3238]155  printf("Campaign:nextLevel()\n");
156  //int nextID = this->currentEntity->getNextStoryID();
157  //this->stop();
158  //this->start(nextID);
159  this->currentEntity->stop();
[2636]160}
161
[3238]162/*
163  \brief change to the previous level - not implemented
164
165  this propably useless
166*/
[2636]167void Campaign::previousLevel()
168{}
169
170
[3238]171/*
172  \brief lookup a entity with a given id
173  \param story id to be lookuped
174  \returns the entity found or NULL if search ended without match
175*/
176StoryEntity* Campaign::getStoryEntity(int storyID)
[2636]177{
[3238]178  //printf("Campaing::getStoryEntity(%i) - getting next Entity\n", storyID);
179  if( storyID == WORLD_ID_GAMEEND)
180    return NULL;
181  ListTemplate<StoryEntity>* l;
182  StoryEntity* entity = NULL;
183  l = this->entities->getNext(); 
[2636]184  while( l != NULL) 
185    { 
[3238]186      entity = l->getObject();
187      l = l->getNext();
188      int id = entity->getStoryID();
189      //printf("Campaing::getStoryEntity() - now looping, found entity nr=%i\n", id);
190      if(id == storyID)
191        {
192          //printf("Campaing::getStoryEntity() - yea, this is what we where looking for: %id\n");
193          return entity;
194        }
[2636]195    }
196  return NULL;
197}
Note: See TracBrowser for help on using the repository browser.