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