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 | co-programmer: |
---|
16 | */ |
---|
17 | |
---|
18 | |
---|
19 | #include "campaign.h" |
---|
20 | |
---|
21 | #include "story_entity.h" |
---|
22 | |
---|
23 | #include "world.h" |
---|
24 | #include "camera.h" |
---|
25 | |
---|
26 | #include "list.h" |
---|
27 | |
---|
28 | using namespace std; |
---|
29 | |
---|
30 | |
---|
31 | Campaign::Campaign () |
---|
32 | { |
---|
33 | this->entities = new tList<StoryEntity>(); |
---|
34 | this->isInit = false; |
---|
35 | } |
---|
36 | |
---|
37 | |
---|
38 | Campaign::~Campaign () {} |
---|
39 | |
---|
40 | |
---|
41 | ErrorMessage Campaign::init() |
---|
42 | { |
---|
43 | this->isInit = true; |
---|
44 | } |
---|
45 | |
---|
46 | |
---|
47 | ErrorMessage Campaign::start() |
---|
48 | { |
---|
49 | this->start(0); |
---|
50 | } |
---|
51 | |
---|
52 | |
---|
53 | ErrorMessage Campaign::start(int storyID = 0) |
---|
54 | { |
---|
55 | printf("World::start() - starting new StoryEntity Nr:%i\n", storyID); |
---|
56 | ErrorMessage errorCode; |
---|
57 | if( !this->isInit) return errorCode; |
---|
58 | if( storyID == WORLD_ID_GAMEEND) return errorCode; |
---|
59 | this->running = true; |
---|
60 | StoryEntity* se = this->getStoryEntity(storyID); |
---|
61 | this->currentEntity = se; |
---|
62 | while( se != NULL && this->running) |
---|
63 | { |
---|
64 | se->displayLoadScreen(); |
---|
65 | se->preLoad(); |
---|
66 | se->load(); |
---|
67 | se->init(); |
---|
68 | se->releaseLoadScreen(); |
---|
69 | se->start(); |
---|
70 | se->destroy(); |
---|
71 | |
---|
72 | delete se; |
---|
73 | |
---|
74 | int nextWorldID = se->getNextStoryID(); |
---|
75 | //printf("Campaing::start() - got nextWorldID = %i\n", nextWorldID); |
---|
76 | se = this->getStoryEntity(nextWorldID); |
---|
77 | this->currentEntity = se; |
---|
78 | if( ( nextWorldID == WORLD_ID_GAMEEND) ||( se == NULL) ) |
---|
79 | { |
---|
80 | printf("Campaign::start() - quitting campaing story loop\n"); |
---|
81 | if(se != NULL) |
---|
82 | delete se; |
---|
83 | return errorCode; |
---|
84 | } |
---|
85 | |
---|
86 | } |
---|
87 | } |
---|
88 | |
---|
89 | |
---|
90 | ErrorMessage Campaign::pause() |
---|
91 | { |
---|
92 | if(this->currentEntity != NULL) |
---|
93 | this->isPaused = true; |
---|
94 | } |
---|
95 | |
---|
96 | |
---|
97 | ErrorMessage Campaign::resume() |
---|
98 | { |
---|
99 | if(this->currentEntity != NULL) |
---|
100 | this->isPaused = false; |
---|
101 | } |
---|
102 | |
---|
103 | |
---|
104 | ErrorMessage Campaign::stop() |
---|
105 | { |
---|
106 | this->running = false; |
---|
107 | if(this->currentEntity != NULL) |
---|
108 | { |
---|
109 | this->currentEntity->stop(); |
---|
110 | //delete this->currentEntity; |
---|
111 | //this->currentEntity = NULL; |
---|
112 | } |
---|
113 | } |
---|
114 | |
---|
115 | |
---|
116 | ErrorMessage Campaign::destroy() |
---|
117 | { |
---|
118 | if(this->currentEntity != NULL) |
---|
119 | { |
---|
120 | this->currentEntity->destroy(); |
---|
121 | delete this->currentEntity; |
---|
122 | this->currentEntity = NULL; |
---|
123 | } |
---|
124 | } |
---|
125 | |
---|
126 | |
---|
127 | /** |
---|
128 | \brief adds an game stroy entity to the campaign |
---|
129 | |
---|
130 | \param se: The entity |
---|
131 | \param storyID: The number that identifies the entity in the campaign. Each ID only used once in a Campaign |
---|
132 | |
---|
133 | An entity can be a world (playable), a cinematic, a shop, sounds, whatever you |
---|
134 | want to queue up in the campaign. |
---|
135 | */ |
---|
136 | void Campaign::addEntity(StoryEntity* se, int storyID) |
---|
137 | { |
---|
138 | se->setStoryID(storyID); |
---|
139 | this->addEntity(se); |
---|
140 | } |
---|
141 | |
---|
142 | void Campaign::addEntity(StoryEntity* se) |
---|
143 | { |
---|
144 | this->entities->add(se); |
---|
145 | } |
---|
146 | |
---|
147 | |
---|
148 | void Campaign::removeEntity(int storyID) |
---|
149 | { |
---|
150 | this->removeEntity(this->getStoryEntity(storyID)); |
---|
151 | |
---|
152 | } |
---|
153 | |
---|
154 | |
---|
155 | void Campaign::removeEntity(StoryEntity* se) |
---|
156 | { |
---|
157 | this->entities->remove(se); |
---|
158 | } |
---|
159 | |
---|
160 | |
---|
161 | /* |
---|
162 | \brief this changes to the next level |
---|
163 | */ |
---|
164 | void Campaign::nextLevel() |
---|
165 | { |
---|
166 | printf("Campaign:nextLevel()\n"); |
---|
167 | //int nextID = this->currentEntity->getNextStoryID(); |
---|
168 | //this->stop(); |
---|
169 | //this->start(nextID); |
---|
170 | this->currentEntity->stop(); |
---|
171 | } |
---|
172 | |
---|
173 | /* |
---|
174 | \brief change to the previous level - not implemented |
---|
175 | |
---|
176 | this propably useless |
---|
177 | */ |
---|
178 | void Campaign::previousLevel() |
---|
179 | {} |
---|
180 | |
---|
181 | |
---|
182 | /* |
---|
183 | \brief lookup a entity with a given id |
---|
184 | \param story id to be lookuped |
---|
185 | \returns the entity found or NULL if search ended without match |
---|
186 | */ |
---|
187 | StoryEntity* Campaign::getStoryEntity(int storyID) |
---|
188 | { |
---|
189 | //printf("Campaing::getStoryEntity(%i) - getting next Entity\n", storyID); |
---|
190 | if( storyID == WORLD_ID_GAMEEND) |
---|
191 | return NULL; |
---|
192 | |
---|
193 | /* |
---|
194 | tList<StoryEntity>* l; |
---|
195 | StoryEntity* entity = NULL; |
---|
196 | l = this->entities->getNext(); |
---|
197 | while( l != NULL) |
---|
198 | { |
---|
199 | entity = l->getObject(); |
---|
200 | l = l->getNext(); |
---|
201 | |
---|
202 | int id = entity->getStoryID(); |
---|
203 | //printf("Campaing::getStoryEntity() - now looping, found entity nr=%i\n", id); |
---|
204 | if(id == storyID) |
---|
205 | { |
---|
206 | //printf("Campaing::getStoryEntity() - yea, this is what we where looking for: %id\n"); |
---|
207 | return entity; |
---|
208 | } |
---|
209 | |
---|
210 | } |
---|
211 | */ |
---|
212 | |
---|
213 | |
---|
214 | tIterator<StoryEntity>* iterator = this->entities->getIterator(); |
---|
215 | StoryEntity* entity = iterator->nextElement(); |
---|
216 | while( entity != NULL) |
---|
217 | { |
---|
218 | int id = entity->getStoryID(); |
---|
219 | //printf("Campaing::getStoryEntity() - now looping, found entity nr=%i\n", id); |
---|
220 | if(id == storyID) |
---|
221 | { |
---|
222 | //printf("Campaing::getStoryEntity() - yea, this is what we where looking for: %id\n"); |
---|
223 | return entity; |
---|
224 | } |
---|
225 | entity = iterator->nextElement(); |
---|
226 | } |
---|
227 | delete iterator; |
---|
228 | |
---|
229 | |
---|
230 | return NULL; |
---|
231 | } |
---|