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