Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7994 was 7283, checked in by bensch, 19 years ago

orxonox/trunk: thread for audio, and 'is' to 'b'

File size: 3.1 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
15*/
16
[6834]17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_STORY_ENTITY
[2636]18
19#include "campaign.h"
[3629]20
[7193]21#include "util/loading/factory.h"
22#include "util/loading/load_param.h"
[6875]23#include "state.h"
[4261]24
[6424]25#include "campaign_data.h"
[5651]26
[2636]27using namespace std;
28
29
[6424]30/**
31 *  the constructor
32 * @param root the XML root element
33 *
34 * this constructor is always called in a XML context (loading procedure)
35 */
[4597]36Campaign::Campaign ( TiXmlElement* root)
[4010]37{
[4597]38  this->setClassID(CL_CAMPAIGN, "Campaign");
39
[5300]40  PRINTF(4)("Loading Campaign...\n");
[4010]41  assert( root != NULL);
[4597]42
[6874]43  this->bReturnToMenu = false;
44
[6424]45  this->campaignData = new CampaignData(root);
[4598]46  this->loadParams(root);
[4597]47
[4010]48}
[2636]49
[6424]50
51/**
52 * the campaign destructor
53 */
[4816]54Campaign::~Campaign ()
[2636]55{
[6424]56  if( this->campaignData)
57    delete this->campaignData;
[2636]58}
59
[6424]60
[4598]61/**
[6424]62 *  loads the Parameters of a Campaign
63 * @param root: The XML-element to load from
[4598]64 */
65void Campaign::loadParams(const TiXmlElement* root)
66{
[6512]67  StoryEntity::loadParams(root);
[2636]68
[6424]69  PRINTF(4)("Loaded Campaign specific stuff\n");
[4598]70}
71
[6424]72
[4598]73/**
[6424]74 *  starts the campaing with a specific ID
75 * @param storyID the id of the StoryEntity
[4598]76 */
[6424]77bool Campaign::start()
[4598]78{
[6424]79  PRINTF(2)("Starting Campaign nr. %i\n", this->getStoryID());
[5651]80
[7283]81  this->bRunning = true;
[6874]82  this->bReturnToMenu = false;
[6424]83  this->run();
[4598]84}
85
[2636]86
[6424]87/**
88 *  pauses the campaign
89 */
90bool Campaign::pause()
[2636]91{
[7283]92  this->bPaused = true;
[2636]93}
94
95
[6424]96/**
97 *  resumes the campaign after a pause
98 */
99bool Campaign::resume()
[2636]100{
[6424]101  PRINTF(4)("Resuming the current Campaign\n");
[7283]102  this->bPaused = false;
[2636]103}
104
105
[6424]106/**
107 *  stops the campaign
108 */
109bool Campaign::stop()
[2636]110{
[6424]111  PRINTF(4)("Stopping the current Campaign\n");
[7032]112  if( State::getMenuID() != -1)
[6875]113    this->bReturnToMenu = true;
114  else
[7283]115    this->bRunning = false;  // fast exit
[6424]116  if( this->currentEntity != NULL)
117  {
118    this->currentEntity->stop();
119  }
[2636]120}
121
122
[4597]123/**
[6424]124 *  runs the campaign
125 */
126void Campaign::run()
[3459]127{
[6424]128  ErrorMessage       errorCode;
129  int                storyID = WORLD_ID_0;
[3459]130
[7283]131  for( this->currentEntity = this->campaignData->getFirstLevel(), this->bRunning = true;
132       this->currentEntity != NULL && this->bRunning;
[6424]133       this->currentEntity = this->campaignData->getNextLevel())
134  {
135    PRINTF(0)("Campaign is starting StoryEntity nr:%i\n", this->currentEntity->getStoryID());
[3459]136
[6874]137    // check if return to menu
138    if( this->bReturnToMenu)
139    {
140      this->currentEntity = this->campaignData->getLevel(WORLD_ID_MENU);
141      this->bReturnToMenu = false;
142    }
143
144    this->campaignData->setCurrentEntity(this->currentEntity);
145
[6424]146    this->currentEntity->init();
147    this->currentEntity->loadData();
148    this->currentEntity->start();
149    this->currentEntity->unloadData();
150  }
[6874]151  PRINTF(2)("There is no StoryEnity left to play, quitting game\n");
[3459]152}
153
154
[6424]155/**
156 *  this changes to the next level
157 */
158void Campaign::switchToNextLevel()
[3459]159{
[6424]160  PRINTF(4)("Switching to the next StoryEntity\n");
[3220]161  this->currentEntity->stop();
[2636]162}
163
[3225]164
Note: See TracBrowser for help on using the repository browser.