Debian Codegraph @

src/cdogs/files.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-2016, 2018 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 <SDL_endian.h>
52
53 #include "sys_config.h"
54 #include "gamedata.h"
55 #include "sys_specifics.h"
56
57 /*
58 C-Dogs (classic) file format:
59 Sizes in bytes unless otherwise stated
60
61 Priviledged types (types that are used directly in the file format)
62 Changing these types will break the game!
63 - CampaignSettingOld
64 - struct MissionOld
65 - TBadGuy
66 - struct MissionObjectiveOld
67
68 Campaign:
69 - CAMPAIGN_MAGIC (4)
70 - CAMPAIGN_VERSION (4)
71 - Title (40, char *)
72 - Author (40, char *)
73 - Description (200, char *)
74 - MissionCount (4)
75 - <Missions> (MissionCount * sizeof(struct MissionOld))
76 - CharacterCount (4)
77 - <Characters> (CharacterCount * sizeof(TBadGuy))
78 */
79 #ifdef _MSC_VER
80 #pragma pack(push, 1)
81 #endif
82 typedef struct
83 {
84 int32_t armedBodyPic;
85 int32_t unarmedBodyPic;
86 int32_t facePic;
87 int32_t speed;
88 int32_t probabilityToMove;
89 int32_t probabilityToTrack;
90 int32_t probabilityToShoot;
91 int32_t actionDelay;
92 int32_t gun;
93 int32_t skinColor;
94 int32_t armColor;
95 int32_t bodyColor;
96 int32_t legColor;
97 int32_t hairColor;
98 int32_t health;
99 int32_t flags;
100 }
101 #ifndef _MSC_VER
102 __attribute__((packed))
103 #endif
104 TBadGuy;
105 #ifdef _MSC_VER
106 #pragma pack(pop)
107 #endif
108
109 // WARNING: data type used in C format (builtin campaigns)
110 typedef struct
111 {
112 char title[40];
113 char author[40];
114 char description[200];
115 int missionCount;
116 struct MissionOld *missions;
117 int characterCount;
118 TBadGuy *characters;
119 } CampaignSettingOld;
120
121 // WARNING: written as-is to file
122 #ifdef _MSC_VER
123 #pragma pack(push, 1)
124 #endif
125 struct MissionObjectiveOld
126 {
127 char description[60];
128 int32_t type;
129 int32_t index;
130 int32_t count;
131 int32_t required;
132 int32_t flags;
133 }
134 #ifndef _MSC_VER
135 __attribute__((packed))
136 #endif
137 ;
138 #ifdef _MSC_VER
139 #pragma pack(pop)
140 #endif
141
142
143 // WARNING: affects file format
144 #define BADDIE_MAX 12
145 #define SPECIAL_MAX 6
146 #define ITEMS_MAX 16
147
148 #define WEAPON_MAX 11
149
150
151 // WARNING: written as-is to file
152 #ifdef _MSC_VER
153 #pragma pack(push, 1)
154 #endif
155 struct MissionOld
156 {
157 char title[60];
158 char description[400];
159 int32_t wallStyle;
160 int32_t floorStyle;
161 int32_t roomStyle;
162 int32_t exitStyle;
163 int32_t keyStyle;
164 int32_t doorStyle;
165
166 int32_t mapWidth, mapHeight;
167 int32_t wallCount, wallLength;
168 int32_t roomCount;
169 int32_t squareCount;
170
171 int32_t exitLeft, exitTop, exitRight, exitBottom;
172
173 int32_t objectiveCount;
174 struct MissionObjectiveOld objectives[OBJECTIVE_MAX_OLD];
175
176 int32_t baddieCount;
177 int32_t baddies[BADDIE_MAX];
178 int32_t specialCount;
179 int32_t specials[SPECIAL_MAX];
180 int32_t itemCount;
181 int32_t items[ITEMS_MAX];
182 int32_t itemDensity[ITEMS_MAX];
183
184 int32_t baddieDensity;
185 int32_t weaponSelection;
186
187 char song[80];
188 char map[80];
189
190 int32_t wallRange;
191 int32_t floorRange;
192 int32_t roomRange;
193 int32_t altRange;
194 }
195 #ifndef _MSC_VER
196 __attribute__((packed))
197 #endif
198 ;
199 #ifdef _MSC_VER
200 #pragma pack(pop)
201 #endif
202
203 void ConvertCampaignSetting(CampaignSetting *dest, CampaignSettingOld *src);
204 void ConvertCharacterColors(
205 const int skin, const int arm, const int body, const int leg,
206 const int hair, CharColors *c);
207 void ConvertHairColors(Character *ch, const char *face);
208
209 int ScanCampaignOld(const char *filename, char **title, int *missions);
210 int IsCampaignOldFile(const char *filename);
211 int LoadCampaignOld(const char *filename, CampaignSettingOld *setting);
212
213 const char *GetHomeDirectory(void);
214 const char *GetConfigFilePath(const char *name);
215
216 void SetupConfigDir(void);
217
218 size_t f_read(FILE *f, void *buf, size_t size);
219 size_t f_read16(FILE *f, void *buf, size_t size);
220
221 void swap16 (void *d);
222
223 // Convert classic colour range indices to color_t
224 color_t RangeToColor(const int range);
225 #define COLORRANGE_COUNT 27
226
227 bool mkdir_deep(const char *path);