Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9337 was 8717, checked in by bensch, 18 years ago

merged the gui back

File size: 3.2 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();
[8717]84
85  return true;
[4598]86}
87
[2636]88
[6424]89/**
90 *  pauses the campaign
91 */
92bool Campaign::pause()
[2636]93{
[8717]94  return (this->bPaused = true);
[2636]95}
96
97
[6424]98/**
99 *  resumes the campaign after a pause
100 */
101bool Campaign::resume()
[2636]102{
[6424]103  PRINTF(4)("Resuming the current Campaign\n");
[8717]104  return (this->bPaused = false);
[2636]105}
106
107
[6424]108/**
109 *  stops the campaign
110 */
111bool Campaign::stop()
[2636]112{
[6424]113  PRINTF(4)("Stopping the current Campaign\n");
[7032]114  if( State::getMenuID() != -1)
[6875]115    this->bReturnToMenu = true;
116  else
[7283]117    this->bRunning = false;  // fast exit
[6424]118  if( this->currentEntity != NULL)
119  {
120    this->currentEntity->stop();
121  }
[8717]122
123  return true;
[2636]124}
125
126
[4597]127/**
[6424]128 *  runs the campaign
129 */
130void Campaign::run()
[3459]131{
[6424]132  ErrorMessage       errorCode;
[8717]133//  int                storyID = WORLD_ID_0;
[3459]134
[7283]135  for( this->currentEntity = this->campaignData->getFirstLevel(), this->bRunning = true;
136       this->currentEntity != NULL && this->bRunning;
[6424]137       this->currentEntity = this->campaignData->getNextLevel())
138  {
139    PRINTF(0)("Campaign is starting StoryEntity nr:%i\n", this->currentEntity->getStoryID());
[3459]140
[6874]141    // check if return to menu
142    if( this->bReturnToMenu)
143    {
144      this->currentEntity = this->campaignData->getLevel(WORLD_ID_MENU);
145      this->bReturnToMenu = false;
146    }
147
148    this->campaignData->setCurrentEntity(this->currentEntity);
149
[6424]150    this->currentEntity->init();
151    this->currentEntity->loadData();
152    this->currentEntity->start();
153    this->currentEntity->unloadData();
154  }
[6874]155  PRINTF(2)("There is no StoryEnity left to play, quitting game\n");
[3459]156}
157
158
[6424]159/**
160 *  this changes to the next level
161 */
162void Campaign::switchToNextLevel()
[3459]163{
[6424]164  PRINTF(4)("Switching to the next StoryEntity\n");
[3220]165  this->currentEntity->stop();
[2636]166}
167
[3225]168
Note: See TracBrowser for help on using the repository browser.