Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

trunk: the game now always jumps back to the menu

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