Debian Codegraph @

prboom2/src/dsda/skill_info.c

raw
1 //
2 // Copyright(C) 2023 by Ryan Krafnick
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // DESCRIPTION:
15 // DSDA Skill Info
16 //
17
18 #include "doomstat.h"
19
20 #include "dsda/args.h"
21 #include "dsda/configuration.h"
22 #include "dsda/mapinfo/doom/parser.h"
23 #include "dsda/text_color.h"
24 #include "dsda/utility.h"
25
26 #include "skill_info.h"
27
28 skill_info_t skill_info;
29
30 const skill_info_t doom_skill_infos[5] = {
31 {
32 .ammo_factor = FRACUNIT * 2,
33 .damage_factor = FRACUNIT / 2,
34 .spawn_filter = 1,
35 .key = 'i',
36 .name = "I'm too young to die.",
37 .pic_name = "M_JKILL",
38 .flags = SI_EASY_BOSS_BRAIN
39 },
40 {
41 .spawn_filter = 2,
42 .key = 'h',
43 .name = "Hey, not too rough.",
44 .pic_name = "M_ROUGH",
45 .flags = SI_EASY_BOSS_BRAIN
46 },
47 {
48 .spawn_filter = 3,
49 .key = 'h',
50 .name = "Hurt me plenty.",
51 .pic_name = "M_HURT",
52 .flags = 0
53 },
54 {
55 .spawn_filter = 4,
56 .key = 'u',
57 .name = "Ultra-Violence.",
58 .pic_name = "M_ULTRA",
59 .flags = 0
60 },
61 {
62 .ammo_factor = FRACUNIT * 2,
63 .spawn_filter = 5,
64 .key = 'n',
65 .name = "Nightmare!",
66 .pic_name = "M_NMARE",
67 .respawn_time = 12,
68 .flags = SI_FAST_MONSTERS | SI_INSTANT_REACTION | SI_MUST_CONFIRM
69 },
70 };
71
72 const skill_info_t heretic_skill_infos[5] = {
73 {
74 .ammo_factor = FRACUNIT * 3 / 2,
75 .damage_factor = FRACUNIT / 2,
76 .spawn_filter = 1,
77 .name = "THOU NEEDETH A WET-NURSE",
78 .flags = SI_AUTO_USE_HEALTH
79 },
80 {
81 .spawn_filter = 2,
82 .name = "YELLOWBELLIES-R-US",
83 .flags = 0
84 },
85 {
86 .spawn_filter = 3,
87 .name = "BRINGEST THEM ONETH",
88 .flags = 0
89 },
90 {
91 .spawn_filter = 4,
92 .name = "THOU ART A SMITE-MEISTER",
93 .flags = 0
94 },
95 {
96 .ammo_factor = FRACUNIT * 3 / 2,
97 .spawn_filter = 5,
98 .name = "BLACK PLAGUE POSSESSES THEE",
99 .flags = SI_FAST_MONSTERS | SI_INSTANT_REACTION
100 },
101 };
102
103 const skill_info_t hexen_skill_infos[5] = {
104 {
105 .ammo_factor = FRACUNIT * 3 / 2,
106 .damage_factor = FRACUNIT / 2,
107 .spawn_filter = 1,
108 .flags = SI_AUTO_USE_HEALTH
109 },
110 {
111 .spawn_filter = 2,
112 .flags = 0
113 },
114 {
115 .spawn_filter = 3,
116 .flags = 0
117 },
118 {
119 .spawn_filter = 4,
120 .flags = 0
121 },
122 {
123 .ammo_factor = FRACUNIT * 3 / 2,
124 .spawn_filter = 5,
125 .flags = SI_FAST_MONSTERS | SI_INSTANT_REACTION
126 },
127 };
128
129 int num_skills;
130 skill_info_t* skill_infos;
131
132 static void dsda_CopyFactor(fixed_t* dest, const char* source) {
133 // We will compute integers with these,
134 // and common human values (i.e., not powers of 2) are rounded down.
135 // Add 1 (= 1/2^16) to yield expected results.
136 // Otherwise, 0.2 * 15 would be 2 instead of 3.
137
138 if (source)
139 *dest = dsda_StringToFixed(source) + 1;
140 }
141
142 void dsda_CopySkillInfo(int i, const doom_mapinfo_skill_t* info) {
143 memset(&skill_infos[i], 0, sizeof(skill_infos[i]));
144
145 dsda_CopyFactor(&skill_infos[i].ammo_factor, info->ammo_factor);
146 dsda_CopyFactor(&skill_infos[i].damage_factor, info->damage_factor);
147 dsda_CopyFactor(&skill_infos[i].armor_factor, info->armor_factor);
148 dsda_CopyFactor(&skill_infos[i].health_factor, info->health_factor);
149 dsda_CopyFactor(&skill_infos[i].monster_health_factor, info->monster_health_factor);
150 dsda_CopyFactor(&skill_infos[i].friend_health_factor, info->friend_health_factor);
151
152 skill_infos[i].respawn_time = info->respawn_time;
153 skill_infos[i].spawn_filter = info->spawn_filter;
154 skill_infos[i].key = info->key;
155
156 if (info->must_confirm)
157 skill_infos[i].must_confirm = Z_Strdup(info->must_confirm);
158
159 if (info->name)
160 skill_infos[i].name = Z_Strdup(info->name);
161
162 if (info->pic_name)
163 skill_infos[i].pic_name = Z_Strdup(info->pic_name);
164
165 if (info->text_color)
166 skill_infos[i].text_color = dsda_ColorNameToIndex(info->text_color);
167
168 skill_infos[i].flags = info->flags;
169 }
170
171 void dsda_InitSkills(void) {
172 int i = 0;
173 int j;
174 dboolean clear_skills;
175
176 clear_skills = (doom_mapinfo.num_skills && doom_mapinfo.skills_cleared);
177
178 num_skills = (clear_skills ? 0 : 5) + doom_mapinfo.num_skills;
179
180 skill_infos = Z_Calloc(num_skills, sizeof(*skill_infos));
181
182 if (!clear_skills) {
183 const skill_info_t* original_skill_infos;
184
185 original_skill_infos = hexen ? hexen_skill_infos :
186 heretic ? heretic_skill_infos :
187 doom_skill_infos;
188
189 for (i = 0; i < 5; ++i)
190 skill_infos[i] = original_skill_infos[i];
191 }
192
193 for (j = 0; j < doom_mapinfo.num_skills; ++j) {
194 if (!stricmp(doom_mapinfo.skills[j].unique_id, "baby")) {
195 dsda_CopySkillInfo(0, &doom_mapinfo.skills[j]);
196 --i;
197 --num_skills;
198 }
199 else if (!stricmp(doom_mapinfo.skills[j].unique_id, "easy")) {
200 dsda_CopySkillInfo(1, &doom_mapinfo.skills[j]);
201 --i;
202 --num_skills;
203 }
204 else if (!stricmp(doom_mapinfo.skills[j].unique_id, "normal")) {
205 dsda_CopySkillInfo(2, &doom_mapinfo.skills[j]);
206 --i;
207 --num_skills;
208 }
209 else if (!stricmp(doom_mapinfo.skills[j].unique_id, "hard")) {
210 dsda_CopySkillInfo(3, &doom_mapinfo.skills[j]);
211 --i;
212 --num_skills;
213 }
214 else if (!stricmp(doom_mapinfo.skills[j].unique_id, "nightmare")) {
215 dsda_CopySkillInfo(4, &doom_mapinfo.skills[j]);
216 --i;
217 --num_skills;
218 }
219 else
220 dsda_CopySkillInfo(i + j, &doom_mapinfo.skills[j]);
221 }
222 }
223
224 // At startup, set-up temp game modifier configs based off args / persistent cfgs
225 // Only set once, as modifiers can break away from args
226 //
227 // "Always Pistol Start" is the only persistent cfg (saved in cfg file)
228 //
229
230 void dsda_InitGameModifiers(void)
231 {
232 if (dsda_Flag(dsda_arg_pistol_start) || dsda_IntConfig(dsda_config_always_pistol_start))
233 dsda_UpdateIntConfig(dsda_config_pistol_start, true, true);
234 if (dsda_Flag(dsda_arg_respawn))
235 dsda_UpdateIntConfig(dsda_config_respawn_monsters, true, true);
236 if (dsda_Flag(dsda_arg_fast))
237 dsda_UpdateIntConfig(dsda_config_fast_monsters, true, true);
238 if (dsda_Flag(dsda_arg_nomonsters))
239 dsda_UpdateIntConfig(dsda_config_no_monsters, true, true);
240 if (dsda_Flag(dsda_arg_coop_spawns))
241 dsda_UpdateIntConfig(dsda_config_coop_spawns, true, true);
242 }
243
244 // if "Pistol Start" is disabled, disable "Always Pistol Start" (avoid impossible condition)
245 void dsda_RefreshPistolStart(void)
246 {
247 dboolean pistol_start_conflict = dsda_IntConfig(dsda_config_always_pistol_start) && !dsda_IntConfig(dsda_config_pistol_start);
248
249 // Fix pistolstart option "conflict"
250 if (allow_incompatibility || in_game)
251 if (pistol_start_conflict)
252 dsda_UpdateIntConfig(dsda_config_always_pistol_start, false, true);
253
254 // Refresh pistolstart status
255 dsda_ResetGameModifiers();
256 }
257
258 // if "Always Pistol Start" is enabled, enable "Pistol Start" (avoid impossible condition)
259 void dsda_RefreshAlwaysPistolStart(void)
260 {
261 dboolean pistol_start_conflict = dsda_IntConfig(dsda_config_always_pistol_start) && !dsda_IntConfig(dsda_config_pistol_start);
262
263 // Fix pistolstart option "conflict"
264 if (allow_incompatibility || in_game)
265 if (pistol_start_conflict)
266 dsda_UpdateIntConfig(dsda_config_pistol_start, true, true);
267
268 // Refresh pistolstart status
269 dsda_ResetGameModifiers();
270 }
271
272 // During demo recording/playback only use args, else use cfgs
273 void dsda_ResetGameModifiers(void)
274 {
275 pistolstart = (allow_incompatibility ? dsda_IntConfig(dsda_config_pistol_start) : false); // pistolstart not allowed in demos
276 respawnparm = (allow_incompatibility ? dsda_IntConfig(dsda_config_respawn_monsters) : dsda_Flag(dsda_arg_respawn));
277 fastparm = (allow_incompatibility ? dsda_IntConfig(dsda_config_fast_monsters) : dsda_Flag(dsda_arg_fast));
278 nomonsters = (allow_incompatibility ? dsda_IntConfig(dsda_config_no_monsters) : dsda_Flag(dsda_arg_nomonsters));
279 coop_spawns = (allow_incompatibility ? dsda_IntConfig(dsda_config_coop_spawns) : dsda_Flag(dsda_arg_coop_spawns));
280 }
281
282 void dsda_RefreshGameSkill(void) {
283 void G_RefreshFastMonsters(void);
284
285 if (allow_incompatibility)
286 dsda_ResetGameModifiers();
287
288 skill_info = skill_infos[gameskill];
289
290 if (respawnparm && !skill_info.respawn_time)
291 skill_info.respawn_time = 12;
292
293 if (fastparm)
294 skill_info.flags |= SI_FAST_MONSTERS;
295
296 if (coop_spawns)
297 skill_info.flags |= SI_SPAWN_MULTI;
298
299 G_RefreshFastMonsters();
300 }
301
302 void dsda_UpdateGameSkill(int skill) {
303 if (skill > num_skills - 1)
304 skill = num_skills - 1;
305
306 gameskill = skill;
307 dsda_RefreshGameSkill();
308 }
309
310 void dsda_AlterGameFlags(void)
311 {
312 if (!allow_incompatibility || !in_game)
313 return;
314
315 dsda_RefreshGameSkill();
316 }