Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6874 was 6874, checked in by patrick, 18 years ago

trunk: the menu control better implemented

File size: 3.0 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
[6874]42  this->bReturnToMenu = false;
43
[6424]44  this->campaignData = new CampaignData(root);
[4598]45  this->loadParams(root);
[4597]46
[4010]47}
[2636]48
[6424]49
50/**
51 * the campaign destructor
52 */
[4816]53Campaign::~Campaign ()
[2636]54{
[6424]55  if( this->campaignData)
56    delete this->campaignData;
[2636]57}
58
[6424]59
[4598]60/**
[6424]61 *  loads the Parameters of a Campaign
62 * @param root: The XML-element to load from
[4598]63 */
64void Campaign::loadParams(const TiXmlElement* root)
65{
[6512]66  StoryEntity::loadParams(root);
[2636]67
[6424]68  PRINTF(4)("Loaded Campaign specific stuff\n");
[4598]69}
70
[6424]71
[4598]72/**
[6424]73 *  starts the campaing with a specific ID
74 * @param storyID the id of the StoryEntity
[4598]75 */
[6424]76bool Campaign::start()
[4598]77{
[6424]78  PRINTF(2)("Starting Campaign nr. %i\n", this->getStoryID());
[5651]79
[6424]80  this->isRunning = true;
[6874]81  this->bReturnToMenu = false;
[6424]82  this->run();
[4598]83}
84
[2636]85
[6424]86/**
87 *  pauses the campaign
88 */
89bool Campaign::pause()
[2636]90{
[6424]91  this->isPaused = true;
[2636]92}
93
94
[6424]95/**
96 *  resumes the campaign after a pause
97 */
98bool Campaign::resume()
[2636]99{
[6424]100  PRINTF(4)("Resuming the current Campaign\n");
101  this->isPaused = false;
[2636]102}
103
104
[6424]105/**
106 *  stops the campaign
107 */
108bool Campaign::stop()
[2636]109{
[6424]110  PRINTF(4)("Stopping the current Campaign\n");
[6874]111  this->bReturnToMenu = true;
[6424]112  if( this->currentEntity != NULL)
113  {
114    this->currentEntity->stop();
115  }
[2636]116}
117
118
[4597]119/**
[6424]120 *  runs the campaign
121 */
122void Campaign::run()
[3459]123{
[6424]124  ErrorMessage       errorCode;
125  int                storyID = WORLD_ID_0;
[3459]126
[6424]127  for( this->currentEntity = this->campaignData->getFirstLevel(), this->isRunning = true;
128       this->currentEntity != NULL && this->isRunning;
129       this->currentEntity = this->campaignData->getNextLevel())
130  {
131    PRINTF(0)("Campaign is starting StoryEntity nr:%i\n", this->currentEntity->getStoryID());
[3459]132
[6874]133    // check if return to menu
134    if( this->bReturnToMenu)
135    {
136      this->currentEntity = this->campaignData->getLevel(WORLD_ID_MENU);
137      this->bReturnToMenu = false;
138    }
139
140    this->campaignData->setCurrentEntity(this->currentEntity);
141
[6424]142    this->currentEntity->init();
143    this->currentEntity->loadData();
144    this->currentEntity->start();
145    this->currentEntity->unloadData();
146  }
[6874]147  PRINTF(2)("There is no StoryEnity left to play, quitting game\n");
[3459]148}
149
150
[6424]151/**
152 *  this changes to the next level
153 */
154void Campaign::switchToNextLevel()
[3459]155{
[6424]156  PRINTF(4)("Switching to the next StoryEntity\n");
[3220]157  this->currentEntity->stop();
[2636]158}
159
[3225]160
Note: See TracBrowser for help on using the repository browser.