Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

merged the gui back

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