| 1 |
// |
| 2 |
// Copyright(C) 2020 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 Options Lump |
| 16 |
// |
| 17 |
|
| 18 |
#include "doomstat.h" |
| 19 |
#include "w_wad.h" |
| 20 |
#include "g_game.h" |
| 21 |
#include "m_random.h" |
| 22 |
#include "lprintf.h" |
| 23 |
|
| 24 |
#include "dsda/configuration.h" |
| 25 |
|
| 26 |
#include "options.h" |
| 27 |
|
| 28 |
static const dsda_options_t default_vanilla_options = { |
| 29 |
.weapon_recoil = 0, |
| 30 |
.monsters_remember = 0, |
| 31 |
.monster_infighting = 1, |
| 32 |
.monster_backing = 0, |
| 33 |
.monster_avoid_hazards = 0, |
| 34 |
.monkeys = 0, |
| 35 |
.monster_friction = 0, |
| 36 |
.help_friends = 0, |
| 37 |
.player_helpers = 0, |
| 38 |
.friend_distance = 0, |
| 39 |
.dog_jumping = 0 |
| 40 |
}; |
| 41 |
|
| 42 |
static const dsda_options_t default_boom_options = { |
| 43 |
.weapon_recoil = 0, |
| 44 |
.monsters_remember = 1, |
| 45 |
.monster_infighting = 1, |
| 46 |
.monster_backing = 0, |
| 47 |
.monster_avoid_hazards = 0, |
| 48 |
.monkeys = 0, |
| 49 |
.monster_friction = 0, |
| 50 |
.help_friends = 0, |
| 51 |
.player_helpers = 0, |
| 52 |
.friend_distance = 0, |
| 53 |
.dog_jumping = 0 |
| 54 |
}; |
| 55 |
|
| 56 |
static const dsda_options_t default_mbf_options = { |
| 57 |
.weapon_recoil = 0, |
| 58 |
.monsters_remember = 1, |
| 59 |
.monster_infighting = 1, |
| 60 |
.monster_backing = 0, |
| 61 |
.monster_avoid_hazards = 1, |
| 62 |
.monkeys = 0, |
| 63 |
.monster_friction = 1, |
| 64 |
.help_friends = 0, |
| 65 |
.player_helpers = 0, |
| 66 |
.friend_distance = 128, |
| 67 |
.dog_jumping = 1, |
| 68 |
|
| 69 |
.comp_telefrag = 0, |
| 70 |
.comp_dropoff = 0, |
| 71 |
.comp_vile = 0, |
| 72 |
.comp_pain = 0, |
| 73 |
.comp_skull = 0, |
| 74 |
.comp_blazing = 0, |
| 75 |
.comp_doorlight = 0, |
| 76 |
.comp_model = 0, |
| 77 |
.comp_god = 0, |
| 78 |
.comp_falloff = 0, |
| 79 |
.comp_floors = 0, |
| 80 |
.comp_skymap = 0, |
| 81 |
.comp_pursuit = 0, |
| 82 |
.comp_doorstuck = 0, |
| 83 |
.comp_staylift = 0, |
| 84 |
.comp_zombie = 1, |
| 85 |
.comp_stairs = 0, |
| 86 |
.comp_infcheat = 0, |
| 87 |
.comp_zerotags = 0 |
| 88 |
|
| 89 |
// These are not configurable: |
| 90 |
// .comp_moveblock = 0, |
| 91 |
// .comp_respawn = 1, |
| 92 |
// .comp_sound = 0, |
| 93 |
// .comp_666 = 0, |
| 94 |
// .comp_soul = 1, |
| 95 |
// .comp_maskedanim = 0, |
| 96 |
// .comp_ouchface = 1, |
| 97 |
// .comp_maxhealth = 0, |
| 98 |
// .comp_translucency = 0, |
| 99 |
// .comp_ledgeblock = 0, |
| 100 |
// .comp_friendlyspawn = 1, |
| 101 |
// .comp_voodooscroller = 1, |
| 102 |
// .comp_reservedlineflag = 1, |
| 103 |
}; |
| 104 |
|
| 105 |
static const dsda_options_t default_latest_options = { |
| 106 |
.weapon_recoil = 0, |
| 107 |
.monsters_remember = 1, |
| 108 |
.monster_infighting = 1, |
| 109 |
.monster_backing = 0, |
| 110 |
.monster_avoid_hazards = 1, |
| 111 |
.monkeys = 0, |
| 112 |
.monster_friction = 1, |
| 113 |
.help_friends = 0, |
| 114 |
.player_helpers = 0, |
| 115 |
.friend_distance = 128, |
| 116 |
.dog_jumping = 1, |
| 117 |
|
| 118 |
.comp_telefrag = 0, |
| 119 |
.comp_dropoff = 0, |
| 120 |
.comp_vile = 0, |
| 121 |
.comp_pain = 0, |
| 122 |
.comp_skull = 0, |
| 123 |
.comp_blazing = 0, |
| 124 |
.comp_doorlight = 0, |
| 125 |
.comp_model = 0, |
| 126 |
.comp_god = 0, |
| 127 |
.comp_falloff = 0, |
| 128 |
.comp_floors = 0, |
| 129 |
.comp_skymap = 0, |
| 130 |
.comp_pursuit = 1, |
| 131 |
.comp_doorstuck = 0, |
| 132 |
.comp_staylift = 0, |
| 133 |
.comp_zombie = 1, |
| 134 |
.comp_stairs = 0, |
| 135 |
.comp_infcheat = 0, |
| 136 |
.comp_zerotags = 0, |
| 137 |
|
| 138 |
.comp_moveblock = 0, |
| 139 |
.comp_respawn = 0, |
| 140 |
.comp_sound = 0, |
| 141 |
.comp_666 = 0, |
| 142 |
.comp_soul = 0, |
| 143 |
.comp_maskedanim = 0, |
| 144 |
.comp_ouchface = 0, |
| 145 |
.comp_maxhealth = 0, |
| 146 |
.comp_translucency = 0, |
| 147 |
.comp_ledgeblock = 1, |
| 148 |
.comp_friendlyspawn = 1, |
| 149 |
.comp_voodooscroller = 0, |
| 150 |
.comp_reservedlineflag = 1, |
| 151 |
}; |
| 152 |
|
| 153 |
static dsda_options_t mbf_options; |
| 154 |
|
| 155 |
typedef struct { |
| 156 |
const char* key; |
| 157 |
int* value; |
| 158 |
int min; |
| 159 |
int max; |
| 160 |
int config_key; |
| 161 |
} dsda_option_t; |
| 162 |
|
| 163 |
static dsda_option_t option_list[] = { |
| 164 |
{ "weapon_recoil", &mbf_options.weapon_recoil, 0, 1 }, |
| 165 |
{ "monsters_remember", &mbf_options.monsters_remember, 0, 1 }, |
| 166 |
{ "monster_infighting", &mbf_options.monster_infighting, 0, 1 }, |
| 167 |
{ "monster_backing", &mbf_options.monster_backing, 0, 1 }, |
| 168 |
{ "monster_avoid_hazards", &mbf_options.monster_avoid_hazards, 0, 1 }, |
| 169 |
{ "monkeys", &mbf_options.monkeys, 0, 1 }, |
| 170 |
{ "monster_friction", &mbf_options.monster_friction, 0, 1 }, |
| 171 |
{ "help_friends", &mbf_options.help_friends, 0, 1 }, |
| 172 |
{ "player_helpers", &mbf_options.player_helpers, 0, 3 }, |
| 173 |
{ "friend_distance", &mbf_options.friend_distance, 0, 999 }, |
| 174 |
{ "dog_jumping", &mbf_options.dog_jumping, 0, 1 }, |
| 175 |
{ "comp_telefrag", &mbf_options.comp_telefrag, 0, 1 }, |
| 176 |
{ "comp_dropoff", &mbf_options.comp_dropoff, 0, 1 }, |
| 177 |
{ "comp_vile", &mbf_options.comp_vile, 0, 1 }, |
| 178 |
{ "comp_pain", &mbf_options.comp_pain, 0, 1 }, |
| 179 |
{ "comp_skull", &mbf_options.comp_skull, 0, 1 }, |
| 180 |
{ "comp_blazing", &mbf_options.comp_blazing, 0, 1 }, |
| 181 |
{ "comp_doorlight", &mbf_options.comp_doorlight, 0, 1 }, |
| 182 |
{ "comp_model", &mbf_options.comp_model, 0, 1 }, |
| 183 |
{ "comp_god", &mbf_options.comp_god, 0, 1 }, |
| 184 |
{ "comp_falloff", &mbf_options.comp_falloff, 0, 1 }, |
| 185 |
{ "comp_floors", &mbf_options.comp_floors, 0, 1 }, |
| 186 |
{ "comp_skymap", &mbf_options.comp_skymap, 0, 1 }, |
| 187 |
{ "comp_pursuit", &mbf_options.comp_pursuit, 0, 1 }, |
| 188 |
{ "comp_doorstuck", &mbf_options.comp_doorstuck, 0, 1 }, |
| 189 |
{ "comp_staylift", &mbf_options.comp_staylift, 0, 1 }, |
| 190 |
{ "comp_zombie", &mbf_options.comp_zombie, 0, 1 }, |
| 191 |
{ "comp_stairs", &mbf_options.comp_stairs, 0, 1 }, |
| 192 |
{ "comp_infcheat", &mbf_options.comp_infcheat, 0, 1 }, |
| 193 |
{ "comp_zerotags", &mbf_options.comp_zerotags, 0, 1 }, |
| 194 |
{ "comp_respawn", &mbf_options.comp_respawn, 0, 1 }, |
| 195 |
{ "comp_respawnfix", &mbf_options.comp_respawn, 0, 1 }, |
| 196 |
{ "comp_soul", &mbf_options.comp_soul, 0, 1 }, |
| 197 |
{ "comp_ledgeblock", &mbf_options.comp_ledgeblock, 0, 1 }, |
| 198 |
{ "comp_friendlyspawn", &mbf_options.comp_friendlyspawn, 0, 1 }, |
| 199 |
{ "comp_voodooscroller", &mbf_options.comp_voodooscroller, 0, 1 }, |
| 200 |
{ "comp_reservedlineflag", &mbf_options.comp_reservedlineflag, 0, 1 }, |
| 201 |
|
| 202 |
{ "mapcolor_back", NULL, 0, 255, dsda_config_mapcolor_back }, |
| 203 |
{ "mapcolor_grid", NULL, 0, 255, dsda_config_mapcolor_grid }, |
| 204 |
{ "mapcolor_wall", NULL, 0, 255, dsda_config_mapcolor_wall }, |
| 205 |
{ "mapcolor_fchg", NULL, 0, 255, dsda_config_mapcolor_fchg }, |
| 206 |
{ "mapcolor_cchg", NULL, 0, 255, dsda_config_mapcolor_cchg }, |
| 207 |
{ "mapcolor_clsd", NULL, 0, 255, dsda_config_mapcolor_clsd }, |
| 208 |
{ "mapcolor_rkey", NULL, 0, 255, dsda_config_mapcolor_rkey }, |
| 209 |
{ "mapcolor_bkey", NULL, 0, 255, dsda_config_mapcolor_bkey }, |
| 210 |
{ "mapcolor_ykey", NULL, 0, 255, dsda_config_mapcolor_ykey }, |
| 211 |
{ "mapcolor_rdor", NULL, 0, 255, dsda_config_mapcolor_rdor }, |
| 212 |
{ "mapcolor_bdor", NULL, 0, 255, dsda_config_mapcolor_bdor }, |
| 213 |
{ "mapcolor_ydor", NULL, 0, 255, dsda_config_mapcolor_ydor }, |
| 214 |
{ "mapcolor_tele", NULL, 0, 255, dsda_config_mapcolor_tele }, |
| 215 |
{ "mapcolor_secr", NULL, 0, 255, dsda_config_mapcolor_secr }, |
| 216 |
{ "mapcolor_revsecr", NULL, 0, 255, dsda_config_mapcolor_revsecr }, |
| 217 |
{ "mapcolor_tagfinder", NULL, 0, 255, dsda_config_mapcolor_tagfinder }, |
| 218 |
{ "mapcolor_exit", NULL, 0, 255, dsda_config_mapcolor_exit }, |
| 219 |
{ "mapcolor_exitsecr", NULL, 0, 255, dsda_config_mapcolor_exitsecr }, |
| 220 |
{ "mapcolor_unsn", NULL, 0, 255, dsda_config_mapcolor_unsn }, |
| 221 |
{ "mapcolor_flat", NULL, 0, 255, dsda_config_mapcolor_flat }, |
| 222 |
{ "mapcolor_sprt", NULL, 0, 255, dsda_config_mapcolor_sprt }, |
| 223 |
{ "mapcolor_item", NULL, 0, 255, dsda_config_mapcolor_item }, |
| 224 |
{ "mapcolor_enemy", NULL, 0, 255, dsda_config_mapcolor_enemy }, |
| 225 |
{ "mapcolor_frnd", NULL, 0, 255, dsda_config_mapcolor_frnd }, |
| 226 |
{ "mapcolor_hair", NULL, 0, 255, dsda_config_mapcolor_hair }, |
| 227 |
{ "mapcolor_sngl", NULL, 0, 255, dsda_config_mapcolor_sngl }, |
| 228 |
{ "mapcolor_me", NULL, 0, 255, dsda_config_mapcolor_me }, |
| 229 |
{ "mapcolor_pickup", NULL, 0, 255, dsda_config_mapcolor_pickup }, |
| 230 |
{ 0 } |
| 231 |
}; |
| 232 |
|
| 233 |
typedef struct { |
| 234 |
dboolean found; |
| 235 |
int value; |
| 236 |
} dsda_parsed_option_t; |
| 237 |
|
| 238 |
static dsda_parsed_option_t parsed_option_list[arrlen(option_list)]; |
| 239 |
|
| 240 |
#define OPTIONS_LINE_LENGTH 80 |
| 241 |
|
| 242 |
typedef struct { |
| 243 |
const char* data; |
| 244 |
int length; |
| 245 |
} options_lump_t; |
| 246 |
|
| 247 |
static const char* dsda_ReadOption(char* buf, size_t size, options_lump_t* lump) { |
| 248 |
if (lump->length <= 0) |
| 249 |
return NULL; |
| 250 |
|
| 251 |
while (size > 1 && *lump->data && lump->length) { |
| 252 |
size--; |
| 253 |
lump->length--; |
| 254 |
if ((*buf++ = *lump->data++) == '\n') |
| 255 |
break; |
| 256 |
} |
| 257 |
|
| 258 |
*buf = '\0'; |
| 259 |
|
| 260 |
return lump->data; |
| 261 |
} |
| 262 |
|
| 263 |
void dsda_ParseOptionsLump(void) { |
| 264 |
options_lump_t lump; |
| 265 |
char buf[OPTIONS_LINE_LENGTH]; |
| 266 |
char key[OPTIONS_LINE_LENGTH]; |
| 267 |
char* scan; |
| 268 |
int lumpnum; |
| 269 |
int i, value, count; |
| 270 |
|
| 271 |
lumpnum = W_CheckNumForName("OPTIONS"); |
| 272 |
|
| 273 |
if (lumpnum == LUMP_NOT_FOUND) |
| 274 |
return; |
| 275 |
|
| 276 |
lump.length = W_LumpLength(lumpnum); |
| 277 |
lump.data = W_LumpByNum(lumpnum); |
| 278 |
|
| 279 |
while (dsda_ReadOption(buf, OPTIONS_LINE_LENGTH, &lump)) { |
| 280 |
if (buf[0] == '#') |
| 281 |
continue; |
| 282 |
|
| 283 |
scan = buf; |
| 284 |
count = sscanf(scan, "%79s %d", key, &value); |
| 285 |
|
| 286 |
if (count != 2) |
| 287 |
continue; |
| 288 |
|
| 289 |
for (i = 0; option_list[i].key; ++i) { |
| 290 |
if (!strncmp(key, option_list[i].key, OPTIONS_LINE_LENGTH)) { |
| 291 |
if (option_list[i].value) { |
| 292 |
parsed_option_list[i].found = true; |
| 293 |
parsed_option_list[i].value = BETWEEN(option_list[i].min, option_list[i].max, value); |
| 294 |
} |
| 295 |
else |
| 296 |
dsda_UpdateIntConfig(option_list[i].config_key, value, false); |
| 297 |
|
| 298 |
lprintf(LO_INFO, "dsda_LumpOptions: %s = %d\n", key, value); |
| 299 |
|
| 300 |
break; |
| 301 |
} |
| 302 |
} |
| 303 |
} |
| 304 |
|
| 305 |
return; |
| 306 |
} |
| 307 |
|
| 308 |
static const dsda_options_t* dsda_MBFOptions(void) { |
| 309 |
int i; |
| 310 |
|
| 311 |
if (compatibility_level == mbf_compatibility) |
| 312 |
mbf_options = default_mbf_options; |
| 313 |
else |
| 314 |
mbf_options = default_latest_options; |
| 315 |
|
| 316 |
for (i = 0; option_list[i].value; ++i) |
| 317 |
if (parsed_option_list[i].found) |
| 318 |
*option_list[i].value = parsed_option_list[i].value; |
| 319 |
|
| 320 |
return &mbf_options; |
| 321 |
} |
| 322 |
|
| 323 |
const dsda_options_t* dsda_Options(void) { |
| 324 |
if (demo_compatibility) |
| 325 |
return &default_vanilla_options; |
| 326 |
|
| 327 |
if (!mbf_features) |
| 328 |
return &default_boom_options; |
| 329 |
|
| 330 |
return dsda_MBFOptions(); |
| 331 |
} |
| 332 |
|
| 333 |
#define MBF21_COMP_TOTAL 25 |
| 334 |
|
| 335 |
static int mbf21_comp_translation[MBF21_COMP_TOTAL] = { |
| 336 |
comp_telefrag, |
| 337 |
comp_dropoff, |
| 338 |
comp_vile, |
| 339 |
comp_pain, |
| 340 |
comp_skull, |
| 341 |
comp_blazing, |
| 342 |
comp_doorlight, |
| 343 |
comp_model, |
| 344 |
comp_god, |
| 345 |
comp_falloff, |
| 346 |
comp_floors, |
| 347 |
comp_skymap, |
| 348 |
comp_pursuit, |
| 349 |
comp_doorstuck, |
| 350 |
comp_staylift, |
| 351 |
comp_zombie, |
| 352 |
comp_stairs, |
| 353 |
comp_infcheat, |
| 354 |
comp_zerotags, |
| 355 |
comp_respawn, |
| 356 |
comp_soul, |
| 357 |
comp_ledgeblock, |
| 358 |
comp_friendlyspawn, |
| 359 |
comp_voodooscroller, |
| 360 |
comp_reservedlineflag, |
| 361 |
}; |
| 362 |
|
| 363 |
// killough 5/2/98: number of bytes reserved for saving options |
| 364 |
#define MBF_GAME_OPTION_SIZE 64 |
| 365 |
#define MBF21_GAME_OPTION_SIZE (21 + MBF21_COMP_TOTAL) |
| 366 |
|
| 367 |
int dsda_GameOptionSize(void) { |
| 368 |
return mbf21 ? MBF21_GAME_OPTION_SIZE : MBF_GAME_OPTION_SIZE; |
| 369 |
} |
| 370 |
|
| 371 |
byte* dsda_WriteOptions21(byte* demo_p) { |
| 372 |
int i; |
| 373 |
byte *target = demo_p + dsda_GameOptionSize(); |
| 374 |
|
| 375 |
*demo_p++ = monsters_remember; |
| 376 |
*demo_p++ = weapon_recoil; |
| 377 |
*demo_p++ = player_bobbing; |
| 378 |
|
| 379 |
*demo_p++ = respawnparm; |
| 380 |
*demo_p++ = fastparm; |
| 381 |
*demo_p++ = nomonsters; |
| 382 |
|
| 383 |
*demo_p++ = (byte)((rngseed >> 24) & 0xff); |
| 384 |
*demo_p++ = (byte)((rngseed >> 16) & 0xff); |
| 385 |
*demo_p++ = (byte)((rngseed >> 8) & 0xff); |
| 386 |
*demo_p++ = (byte)( rngseed & 0xff); |
| 387 |
|
| 388 |
*demo_p++ = monster_infighting; |
| 389 |
*demo_p++ = dogs; |
| 390 |
|
| 391 |
*demo_p++ = (distfriend >> 8) & 0xff; |
| 392 |
*demo_p++ = distfriend & 0xff; |
| 393 |
|
| 394 |
*demo_p++ = monster_backing; |
| 395 |
*demo_p++ = monster_avoid_hazards; |
| 396 |
*demo_p++ = monster_friction; |
| 397 |
*demo_p++ = help_friends; |
| 398 |
*demo_p++ = dog_jumping; |
| 399 |
*demo_p++ = monkeys; |
| 400 |
|
| 401 |
*demo_p++ = MBF21_COMP_TOTAL; |
| 402 |
for (i = 0; i < MBF21_COMP_TOTAL; i++) |
| 403 |
*demo_p++ = comp[mbf21_comp_translation[i]] != 0; |
| 404 |
|
| 405 |
if (demo_p != target) |
| 406 |
I_Error("dsda_WriteOptions21: dsda_GameOptionSize is too small"); |
| 407 |
|
| 408 |
return demo_p; |
| 409 |
} |
| 410 |
|
| 411 |
const byte *dsda_ReadOptions21(const byte *demo_p) { |
| 412 |
int i, count; |
| 413 |
|
| 414 |
// not configurable in mbf21 |
| 415 |
variable_friction = 1; |
| 416 |
allow_pushers = 1; |
| 417 |
demo_insurance = 0; |
| 418 |
|
| 419 |
monsters_remember = *demo_p++; |
| 420 |
weapon_recoil = *demo_p++; |
| 421 |
player_bobbing = *demo_p++; |
| 422 |
|
| 423 |
respawnparm = *demo_p++; |
| 424 |
fastparm = *demo_p++; |
| 425 |
nomonsters = *demo_p++; |
| 426 |
|
| 427 |
rngseed = *demo_p++ & 0xff; |
| 428 |
rngseed <<= 8; |
| 429 |
rngseed += *demo_p++ & 0xff; |
| 430 |
rngseed <<= 8; |
| 431 |
rngseed += *demo_p++ & 0xff; |
| 432 |
rngseed <<= 8; |
| 433 |
rngseed += *demo_p++ & 0xff; |
| 434 |
|
| 435 |
monster_infighting = *demo_p++; |
| 436 |
dogs = *demo_p++; |
| 437 |
|
| 438 |
distfriend = *demo_p++ << 8; |
| 439 |
distfriend += *demo_p++; |
| 440 |
|
| 441 |
monster_backing = *demo_p++; |
| 442 |
monster_avoid_hazards = *demo_p++; |
| 443 |
monster_friction = *demo_p++; |
| 444 |
help_friends = *demo_p++; |
| 445 |
dog_jumping = *demo_p++; |
| 446 |
monkeys = *demo_p++; |
| 447 |
|
| 448 |
count = *demo_p++; |
| 449 |
|
| 450 |
if (count > MBF21_COMP_TOTAL) |
| 451 |
I_Error("Encountered unknown mbf21 compatibility options!"); |
| 452 |
|
| 453 |
for (i = 0; i < count; i++) |
| 454 |
comp[mbf21_comp_translation[i]] = *demo_p++; |
| 455 |
|
| 456 |
// comp_voodooscroller |
| 457 |
if (count < 24) |
| 458 |
comp[mbf21_comp_translation[23]] = 1; |
| 459 |
|
| 460 |
// comp_reservedlineflag |
| 461 |
if (count < 25) |
| 462 |
comp[mbf21_comp_translation[24]] = 0; |
| 463 |
|
| 464 |
G_Compatibility(); |
| 465 |
|
| 466 |
return demo_p; |
| 467 |
} |