Debian Codegraph @

src/cdogs/mission.h

raw symbols SCIP
1 /*
2 C-Dogs SDL
3 A port of the legendary (and fun) action/arcade cdogs.
4 Copyright (C) 1995 Ronny Wester
5 Copyright (C) 2003 Jeremy Chin
6 Copyright (C) 2003-2007 Lucas Martin-King
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 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
22 This file incorporates work covered by the following copyright and
23 permission notice:
24
25 Copyright (c) 2013-2017, 2019-2023 Cong Xu
26 All rights reserved.
27
28 Redistribution and use in source and binary forms, with or without
29 modification, are permitted provided that the following conditions are met:
30
31 Redistributions of source code must retain the above copyright notice, this
32 list of conditions and the following disclaimer.
33 Redistributions in binary form must reproduce the above copyright notice,
34 this list of conditions and the following disclaimer in the documentation
35 and/or other materials provided with the distribution.
36
37 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
38 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
40 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
41 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
42 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
43 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
44 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
45 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
47 POSSIBILITY OF SUCH DAMAGE.
48 */
49 #pragma once
50
51 #include <stdbool.h>
52
53 #include "config.h"
54 #include "map_object.h"
55 #include "mission_static.h"
56 #include "objective.h"
57 #include "proto/msg.pb.h"
58 #include "sys_config.h"
59
60 #define ObjectiveFromThing(f) ((((f)&THING_OBJECTIVE) >> OBJECTIVE_SHIFT) - 1)
61 #define ObjectiveToThing(o) (((o) + 1) << OBJECTIVE_SHIFT)
62
63 #define KEY_COUNT 4
64
65 typedef enum
66 {
67 MAPTYPE_CLASSIC,
68 MAPTYPE_STATIC,
69 MAPTYPE_CAVE,
70 MAPTYPE_INTERIOR,
71 MAPTYPE_COUNT
72 } MapType;
73 const char *MapTypeStr(MapType t);
74 MapType StrMapType(const char *s);
75
76 // Keys that have been collected in this level
77 // Applies to all players
78 #define FLAGS_KEYCARD_YELLOW 0x1
79 #define FLAGS_KEYCARD_GREEN 0x2
80 #define FLAGS_KEYCARD_BLUE 0x4
81 #define FLAGS_KEYCARD_RED 0x8
82 int StrKeycard(const char *s);
83 const char *KeycardStr(const int d);
84 color_t KeyColor(const int flags);
85
86 typedef struct
87 {
88 TileClass Wall;
89 TileClass Floor;
90 TileClass Room;
91 TileClass Door;
92 } MissionTileClasses;
93 typedef struct
94 {
95 const MapObject *M;
96 int Density;
97 } MapObjectDensity;
98 typedef struct
99 {
100 const PickupClass *P;
101 int Count;
102 } PickupCount;
103 typedef struct
104 {
105 int Count;
106 int Min;
107 int Max;
108 bool Edge;
109 bool Overlap;
110 int Walls;
111 int WallLength;
112 int WallPad;
113 } RoomParams;
114 typedef struct
115 {
116 bool Enabled;
117 int Min;
118 int Max;
119 bool RandomPos;
120 } DoorParams;
121 typedef struct
122 {
123 int Count;
124 int Min;
125 int Max;
126 } PillarParams;
127 typedef struct
128 {
129 char *Title;
130 char *Description;
131 MapType Type;
132 struct vec2i Size;
133
134 // styles
135 char ExitStyle[CDOGS_FILENAME_MAX];
136 char KeyStyle[CDOGS_FILENAME_MAX];
137
138 CArray Objectives; // of Objective
139 CArray Enemies; // of int (character index)
140 CArray SpecialChars; // of int
141 CArray MapObjectDensities; // of MapObjectDensity
142 CArray PickupCounts; // of PickupCount
143
144 int EnemyDensity;
145 CArray Weapons; // of WeaponClass *
146
147 struct
148 {
149 MusicSourceType Type;
150 union {
151 char *Filename;
152 MusicChunk Chunk;
153 } Data;
154 } Music;
155
156 bool WeaponPersist;
157 bool SkipDebrief;
158
159 union {
160 // Classic
161 struct
162 {
163 // TODO: multiple tile classes
164 MissionTileClasses TileClasses;
165 int Walls;
166 int WallLength;
167 int CorridorWidth;
168 RoomParams Rooms;
169 int Squares;
170 bool ExitEnabled;
171 DoorParams Doors;
172 PillarParams Pillars;
173 } Classic;
174 MissionStatic Static;
175 // Cave
176 struct
177 {
178 // TODO: multiple tile classes
179 MissionTileClasses TileClasses;
180 int FillPercent;
181 int Repeat;
182 int R1;
183 int R2;
184 int CorridorWidth;
185 RoomParams Rooms;
186 int Squares;
187 bool ExitEnabled;
188 bool DoorsEnabled;
189 } Cave;
190 struct
191 {
192 // TODO: multiple tile classes
193 MissionTileClasses TileClasses;
194 int CorridorWidth;
195 RoomParams Rooms;
196 bool ExitEnabled;
197 DoorParams Doors;
198 PillarParams Pillars;
199 } Interior;
200 } u;
201 } Mission;
202
203 typedef enum
204 {
205 MISSION_STATE_WAITING,
206 MISSION_STATE_PLAY,
207 MISSION_STATE_PICKUP
208 } MissionState;
209
210 struct MissionOptions
211 {
212 int index;
213 int KeyFlags;
214
215 Mission *missionData;
216 CArray Weapons; // of WeaponClass *
217 int time;
218 // Time when players first entered pickup area
219 int pickupTime;
220 MissionState state;
221 // Whether the mission has loaded
222 bool HasStarted;
223 // Whether the mission has begun (can complete objectives etc.)
224 bool HasBegun;
225 bool isDone;
226 int DoneCounter;
227 int NextMission;
228 bool MissionCompleted;
229 };
230
231 void MissionInit(Mission *m);
232 void MissionCopy(Mission *dst, const Mission *src);
233 void MissionTerminate(Mission *m);
234
235 MissionTileClasses *MissionGetTileClasses(Mission *m);
236
237 void SetupMission(Mission *m, struct MissionOptions *mo, int missionIndex);
238 void MissionSetupTileClasses(
239 Map *m, PicManager *pm, const MissionTileClasses *mtc);
240 void MissionTileClassesInitDefault(MissionTileClasses *mtc);
241 void MissionTileClassesCopy(
242 MissionTileClasses *dst, const MissionTileClasses *src);
243 void MissionTileClassesTerminate(MissionTileClasses *mtc);
244
245 void MissionSetMessageIfComplete(struct MissionOptions *options);
246 // If object is a mission objective, send an update event
247 void UpdateMissionObjective(
248 const struct MissionOptions *options, const int flags,
249 const ObjectiveType type, const int count);
250 bool MissionCanBegin(void);
251 void MissionBegin(struct MissionOptions *m, const NGameBegin gb);
252 bool CanCompleteMission(const struct MissionOptions *options);
253 bool MissionAllObjectivesComplete(const struct MissionOptions *mo);
254 bool IsMissionComplete(const struct MissionOptions *mo);
255 // Returns exit index or -1 if not all players in same exit
256 int AllSurvivingPlayersInSameExit(void);
257 bool MissionNeedsMoreRescuesInExit(const struct MissionOptions *mo);
258 bool MissionHasRequiredObjectives(const struct MissionOptions *mo);
259 void MissionDone(struct MissionOptions *mo, const NMissionEnd end);
260
261 // Count the number of keys in the flags
262 int KeycardCount(int flags);
263
264 void MissionStaticAddObjective(
265 Mission *m, MissionStatic *ms, const int idx, const int idx2,
266 const struct vec2i pos, const bool force);
267 bool MissionStaticTryRemoveObjective(
268 Mission *m, MissionStatic *ms, const struct vec2i pos);