Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10678 was 9869, checked in by bensch, 18 years ago

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

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