| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
#include "config.h" |
| 30 |
|
| 31 |
#include <limits.h> |
| 32 |
#include <stdio.h> |
| 33 |
|
| 34 |
#include "blit.h" |
| 35 |
#include "config_json.h" |
| 36 |
#include "config_old.h" |
| 37 |
#include "keyboard.h" |
| 38 |
#include "music.h" |
| 39 |
#include "sounds.h" |
| 40 |
#include "utils.h" |
| 41 |
|
| 42 |
#define NET_DEFAULT_LISTEN_PORT 34219 |
| 43 |
|
| 44 |
const char *DifficultyStr(int d) |
| 45 |
{ |
| 46 |
switch (d) |
| 47 |
{ |
| 48 |
T2S(DIFFICULTY_VERYEASY, "Easiest"); |
| 49 |
T2S(DIFFICULTY_EASY, "Easy"); |
| 50 |
T2S(DIFFICULTY_NORMAL, "Normal"); |
| 51 |
T2S(DIFFICULTY_HARD, "Hard"); |
| 52 |
T2S(DIFFICULTY_VERYHARD, "Very hard"); |
| 53 |
default: |
| 54 |
return ""; |
| 55 |
} |
| 56 |
} |
| 57 |
int StrDifficulty(const char *s) |
| 58 |
{ |
| 59 |
S2T(DIFFICULTY_VERYEASY, "Easiest"); |
| 60 |
S2T(DIFFICULTY_EASY, "Easy"); |
| 61 |
S2T(DIFFICULTY_NORMAL, "Normal"); |
| 62 |
S2T(DIFFICULTY_HARD, "Hard"); |
| 63 |
S2T(DIFFICULTY_VERYHARD, "Very hard"); |
| 64 |
return DIFFICULTY_NORMAL; |
| 65 |
} |
| 66 |
const char *FireMoveStyleStr(int s) |
| 67 |
{ |
| 68 |
switch (s) |
| 69 |
{ |
| 70 |
T2S(FIREMOVE_STOP, "Stop"); |
| 71 |
T2S(FIREMOVE_NORMAL, "Normal"); |
| 72 |
T2S(FIREMOVE_STRAFE, "Strafe"); |
| 73 |
default: |
| 74 |
return ""; |
| 75 |
} |
| 76 |
} |
| 77 |
int StrFireMoveStyle(const char *s) |
| 78 |
{ |
| 79 |
S2T(FIREMOVE_STOP, "Stop"); |
| 80 |
S2T(FIREMOVE_NORMAL, "Normal"); |
| 81 |
S2T(FIREMOVE_STRAFE, "Strafe"); |
| 82 |
return FIREMOVE_STOP; |
| 83 |
} |
| 84 |
const char *SwitchMoveStyleStr(int s) |
| 85 |
{ |
| 86 |
switch (s) |
| 87 |
{ |
| 88 |
T2S(SWITCHMOVE_SLIDE, "Slide"); |
| 89 |
T2S(SWITCHMOVE_STRAFE, "Strafe"); |
| 90 |
T2S(SWITCHMOVE_NONE, "None"); |
| 91 |
default: |
| 92 |
return ""; |
| 93 |
} |
| 94 |
} |
| 95 |
int StrSwitchMoveStyle(const char *s) |
| 96 |
{ |
| 97 |
S2T(SWITCHMOVE_SLIDE, "Slide"); |
| 98 |
S2T(SWITCHMOVE_STRAFE, "Strafe"); |
| 99 |
S2T(SWITCHMOVE_NONE, "None"); |
| 100 |
return SWITCHMOVE_SLIDE; |
| 101 |
} |
| 102 |
const char *ScaleModeStr(int s) |
| 103 |
{ |
| 104 |
switch (s) |
| 105 |
{ |
| 106 |
T2S(SCALE_MODE_NN, "Nearest neighbor"); |
| 107 |
T2S(SCALE_MODE_BILINEAR, "Bilinear"); |
| 108 |
default: |
| 109 |
return ""; |
| 110 |
} |
| 111 |
} |
| 112 |
int StrScaleMode(const char *s) |
| 113 |
{ |
| 114 |
S2T(SCALE_MODE_NN, "Nearest neighbor"); |
| 115 |
S2T(SCALE_MODE_BILINEAR, "Bilinear"); |
| 116 |
return SCALE_MODE_NN; |
| 117 |
} |
| 118 |
const char *GoreAmountStr(int g) |
| 119 |
{ |
| 120 |
switch (g) |
| 121 |
{ |
| 122 |
T2S(GORE_NONE, "None"); |
| 123 |
T2S(GORE_LOW, "Trickle"); |
| 124 |
T2S(GORE_MEDIUM, "Buckets"); |
| 125 |
T2S(GORE_HIGH, "Torrents"); |
| 126 |
default: |
| 127 |
return ""; |
| 128 |
} |
| 129 |
} |
| 130 |
int StrGoreAmount(const char *s) |
| 131 |
{ |
| 132 |
S2T(GORE_NONE, "None"); |
| 133 |
S2T(GORE_LOW, "Trickle"); |
| 134 |
S2T(GORE_MEDIUM, "Buckets"); |
| 135 |
S2T(GORE_HIGH, "Torrents"); |
| 136 |
return GORE_NONE; |
| 137 |
} |
| 138 |
const char *LaserSightStr(int l) |
| 139 |
{ |
| 140 |
switch (l) |
| 141 |
{ |
| 142 |
T2S(LASER_SIGHT_NONE, "None"); |
| 143 |
T2S(LASER_SIGHT_PLAYERS, "Players only"); |
| 144 |
T2S(LASER_SIGHT_ALL, "All"); |
| 145 |
default: |
| 146 |
return ""; |
| 147 |
} |
| 148 |
} |
| 149 |
int StrLaserSight(const char *s) |
| 150 |
{ |
| 151 |
S2T(LASER_SIGHT_NONE, "None"); |
| 152 |
S2T(LASER_SIGHT_PLAYERS, "Players only"); |
| 153 |
S2T(LASER_SIGHT_ALL, "All"); |
| 154 |
return LASER_SIGHT_NONE; |
| 155 |
} |
| 156 |
const char *SplitscreenStyleStr(int s) |
| 157 |
{ |
| 158 |
switch (s) |
| 159 |
{ |
| 160 |
T2S(SPLITSCREEN_NORMAL, "Normal"); |
| 161 |
T2S(SPLITSCREEN_ALWAYS, "Always"); |
| 162 |
T2S(SPLITSCREEN_NEVER, "Never"); |
| 163 |
default: |
| 164 |
return ""; |
| 165 |
} |
| 166 |
} |
| 167 |
int StrSplitscreenStyle(const char *s) |
| 168 |
{ |
| 169 |
S2T(SPLITSCREEN_NORMAL, "Normal"); |
| 170 |
S2T(SPLITSCREEN_ALWAYS, "Always"); |
| 171 |
S2T(SPLITSCREEN_NEVER, "Never"); |
| 172 |
return SPLITSCREEN_NORMAL; |
| 173 |
} |
| 174 |
const char *AIChatterStr(int c) |
| 175 |
{ |
| 176 |
switch (c) |
| 177 |
{ |
| 178 |
T2S(AICHATTER_NONE, "None"); |
| 179 |
T2S(AICHATTER_SELDOM, "Seldom"); |
| 180 |
T2S(AICHATTER_OFTEN, "Often"); |
| 181 |
T2S(AICHATTER_ALWAYS, "Always"); |
| 182 |
default: |
| 183 |
return ""; |
| 184 |
} |
| 185 |
} |
| 186 |
int StrAIChatter(const char *s) |
| 187 |
{ |
| 188 |
S2T(AICHATTER_NONE, "None"); |
| 189 |
S2T(AICHATTER_SELDOM, "Seldom"); |
| 190 |
S2T(AICHATTER_OFTEN, "Often"); |
| 191 |
S2T(AICHATTER_ALWAYS, "Always"); |
| 192 |
return AICHATTER_NONE; |
| 193 |
} |
| 194 |
const char *QuickPlayQuantityStr(int q) |
| 195 |
{ |
| 196 |
switch (q) |
| 197 |
{ |
| 198 |
T2S(QUICKPLAY_QUANTITY_ANY, "Any"); |
| 199 |
T2S(QUICKPLAY_QUANTITY_SMALL, "Small"); |
| 200 |
T2S(QUICKPLAY_QUANTITY_MEDIUM, "Medium"); |
| 201 |
T2S(QUICKPLAY_QUANTITY_LARGE, "Large"); |
| 202 |
default: |
| 203 |
return ""; |
| 204 |
} |
| 205 |
} |
| 206 |
int StrQuickPlayQuantity(const char *s) |
| 207 |
{ |
| 208 |
S2T(QUICKPLAY_QUANTITY_ANY, "Any"); |
| 209 |
S2T(QUICKPLAY_QUANTITY_SMALL, "Small"); |
| 210 |
S2T(QUICKPLAY_QUANTITY_MEDIUM, "Medium"); |
| 211 |
S2T(QUICKPLAY_QUANTITY_LARGE, "Large"); |
| 212 |
return QUICKPLAY_QUANTITY_ANY; |
| 213 |
} |
| 214 |
|
| 215 |
Config gConfig; |
| 216 |
|
| 217 |
static Config ConfigNew(const char *name, const ConfigType type); |
| 218 |
Config ConfigNewString(const char *name, const char *defaultValue) |
| 219 |
{ |
| 220 |
Config c = ConfigNew(name, CONFIG_TYPE_STRING); |
| 221 |
UNUSED(defaultValue); |
| 222 |
CASSERT(false, "unimplemented"); |
| 223 |
return c; |
| 224 |
} |
| 225 |
Config ConfigNewInt( |
| 226 |
const char *name, const int defaultValue, const int minValue, |
| 227 |
const int maxValue, const int increment, int (*strToInt)(const char *), |
| 228 |
char *(*intToStr)(int)) |
| 229 |
{ |
| 230 |
Config c = ConfigNew(name, CONFIG_TYPE_INT); |
| 231 |
c.u.Int.Default = c.u.Int.Value = c.u.Int.Last = defaultValue; |
| 232 |
c.u.Int.Min = minValue; |
| 233 |
c.u.Int.Max = maxValue; |
| 234 |
c.u.Int.Increment = increment; |
| 235 |
c.u.Int.StrToInt = strToInt ? strToInt : atoi; |
| 236 |
c.u.Int.IntToStr = intToStr ? intToStr : IntStr; |
| 237 |
return c; |
| 238 |
} |
| 239 |
Config ConfigNewFloat( |
| 240 |
const char *name, const double defaultValue, const double minValue, |
| 241 |
const double maxValue, const double increment) |
| 242 |
{ |
| 243 |
Config c = ConfigNew(name, CONFIG_TYPE_FLOAT); |
| 244 |
c.u.Float.Default = c.u.Float.Value = c.u.Float.Last = defaultValue; |
| 245 |
c.u.Float.Min = minValue; |
| 246 |
c.u.Float.Max = maxValue; |
| 247 |
c.u.Float.Increment = increment; |
| 248 |
return c; |
| 249 |
} |
| 250 |
Config ConfigNewBool(const char *name, const bool defaultValue) |
| 251 |
{ |
| 252 |
Config c = ConfigNew(name, CONFIG_TYPE_BOOL); |
| 253 |
c.u.Bool.Default = c.u.Bool.Value = c.u.Bool.Last = defaultValue; |
| 254 |
return c; |
| 255 |
} |
| 256 |
Config ConfigNewEnum( |
| 257 |
const char *name, const int defaultValue, const int minValue, |
| 258 |
const int maxValue, int (*strToEnum)(const char *), |
| 259 |
const char *(*enumToStr)(int)) |
| 260 |
{ |
| 261 |
Config c = ConfigNew(name, CONFIG_TYPE_ENUM); |
| 262 |
c.u.Enum.Default = c.u.Enum.Value = c.u.Enum.Last = defaultValue; |
| 263 |
c.u.Enum.Min = minValue; |
| 264 |
c.u.Enum.Max = maxValue; |
| 265 |
c.u.Enum.StrToEnum = strToEnum; |
| 266 |
c.u.Enum.EnumToStr = enumToStr; |
| 267 |
return c; |
| 268 |
} |
| 269 |
Config ConfigNewGroup(const char *name) |
| 270 |
{ |
| 271 |
Config c = ConfigNew(name, CONFIG_TYPE_GROUP); |
| 272 |
CArrayInit(&c.u.Group, sizeof(Config)); |
| 273 |
return c; |
| 274 |
} |
| 275 |
static Config ConfigNew(const char *name, const ConfigType type) |
| 276 |
{ |
| 277 |
Config c; |
| 278 |
memset(&c, 0, sizeof c); |
| 279 |
if (name != NULL) |
| 280 |
{ |
| 281 |
CSTRDUP(c.Name, name); |
| 282 |
} |
| 283 |
c.Type = type; |
| 284 |
return c; |
| 285 |
} |
| 286 |
|
| 287 |
void ConfigDestroy(Config *c) |
| 288 |
{ |
| 289 |
CFREE(c->Name); |
| 290 |
if (c->Type == CONFIG_TYPE_GROUP) |
| 291 |
{ |
| 292 |
CA_FOREACH(Config, child, c->u.Group) |
| 293 |
ConfigDestroy(child); |
| 294 |
CA_FOREACH_END() |
| 295 |
CArrayTerminate(&c->u.Group); |
| 296 |
} |
| 297 |
} |
| 298 |
|
| 299 |
void ConfigGroupAdd(Config *group, Config child) |
| 300 |
{ |
| 301 |
CASSERT(group->Type == CONFIG_TYPE_GROUP, "Invalid config type"); |
| 302 |
CArrayPushBack(&group->u.Group, &child); |
| 303 |
} |
| 304 |
|
| 305 |
int ConfigGetVersion(FILE *f) |
| 306 |
{ |
| 307 |
if (ConfigIsOld(f)) |
| 308 |
{ |
| 309 |
return 0; |
| 310 |
} |
| 311 |
rewind(f); |
| 312 |
return ConfigGetJSONVersion(f); |
| 313 |
} |
| 314 |
|
| 315 |
Config *ConfigGet(Config *c, const char *name) |
| 316 |
{ |
| 317 |
char *nameCopy; |
| 318 |
CSTRDUP(nameCopy, name); |
| 319 |
char *pch = strtok(nameCopy, "."); |
| 320 |
while (pch != NULL) |
| 321 |
{ |
| 322 |
if (c->Type != CONFIG_TYPE_GROUP) |
| 323 |
{ |
| 324 |
CASSERT(false, "Invalid config type"); |
| 325 |
goto bail; |
| 326 |
} |
| 327 |
bool found = false; |
| 328 |
CA_FOREACH(Config, child, c->u.Group) |
| 329 |
if (strcmp(child->Name, pch) == 0) |
| 330 |
{ |
| 331 |
c = child; |
| 332 |
found = true; |
| 333 |
break; |
| 334 |
} |
| 335 |
CA_FOREACH_END() |
| 336 |
if (!found) |
| 337 |
{ |
| 338 |
CASSERT(false, "Config not found"); |
| 339 |
goto bail; |
| 340 |
} |
| 341 |
pch = strtok(NULL, "."); |
| 342 |
} |
| 343 |
bail: |
| 344 |
CFREE(nameCopy); |
| 345 |
return c; |
| 346 |
} |
| 347 |
|
| 348 |
bool ConfigChanged(const Config *c) |
| 349 |
{ |
| 350 |
switch (c->Type) |
| 351 |
{ |
| 352 |
case CONFIG_TYPE_STRING: |
| 353 |
return strcmp(c->u.String.Value, c->u.String.Last) != 0; |
| 354 |
case CONFIG_TYPE_INT: |
| 355 |
return c->u.Int.Value != c->u.Int.Last; |
| 356 |
case CONFIG_TYPE_FLOAT: |
| 357 |
return c->u.Float.Value != c->u.Float.Last; |
| 358 |
case CONFIG_TYPE_BOOL: |
| 359 |
return c->u.Bool.Value != c->u.Bool.Last; |
| 360 |
case CONFIG_TYPE_ENUM: |
| 361 |
return c->u.Enum.Value != c->u.Enum.Last; |
| 362 |
case CONFIG_TYPE_GROUP: |
| 363 |
CA_FOREACH(Config, child, c->u.Group) |
| 364 |
if (ConfigChanged(child)) |
| 365 |
{ |
| 366 |
return true; |
| 367 |
} |
| 368 |
CA_FOREACH_END() |
| 369 |
return false; |
| 370 |
default: |
| 371 |
CASSERT(false, "Unknown config type"); |
| 372 |
return false; |
| 373 |
} |
| 374 |
} |
| 375 |
|
| 376 |
void ConfigResetChanged(Config *c) |
| 377 |
{ |
| 378 |
switch (c->Type) |
| 379 |
{ |
| 380 |
case CONFIG_TYPE_STRING: |
| 381 |
CFREE(c->u.String.Value); |
| 382 |
if (c->u.String.Last != NULL) |
| 383 |
{ |
| 384 |
CSTRDUP(c->u.String.Value, c->u.String.Last); |
| 385 |
} |
| 386 |
break; |
| 387 |
case CONFIG_TYPE_INT: |
| 388 |
c->u.Int.Value = c->u.Int.Last; |
| 389 |
break; |
| 390 |
case CONFIG_TYPE_FLOAT: |
| 391 |
c->u.Float.Value = c->u.Float.Last; |
| 392 |
break; |
| 393 |
case CONFIG_TYPE_BOOL: |
| 394 |
c->u.Bool.Value = c->u.Bool.Last; |
| 395 |
break; |
| 396 |
case CONFIG_TYPE_ENUM: |
| 397 |
c->u.Enum.Value = c->u.Enum.Last; |
| 398 |
break; |
| 399 |
case CONFIG_TYPE_GROUP: |
| 400 |
CA_FOREACH(Config, child, c->u.Group) |
| 401 |
ConfigResetChanged(child); |
| 402 |
CA_FOREACH_END() |
| 403 |
break; |
| 404 |
default: |
| 405 |
CASSERT(false, "Unknown config type"); |
| 406 |
break; |
| 407 |
} |
| 408 |
} |
| 409 |
|
| 410 |
void ConfigSetChanged(Config *c) |
| 411 |
{ |
| 412 |
switch (c->Type) |
| 413 |
{ |
| 414 |
case CONFIG_TYPE_STRING: |
| 415 |
CFREE(c->u.String.Last); |
| 416 |
if (c->u.String.Value != NULL) |
| 417 |
{ |
| 418 |
CSTRDUP(c->u.String.Last, c->u.String.Value); |
| 419 |
} |
| 420 |
break; |
| 421 |
case CONFIG_TYPE_INT: |
| 422 |
c->u.Int.Last = c->u.Int.Value; |
| 423 |
break; |
| 424 |
case CONFIG_TYPE_FLOAT: |
| 425 |
c->u.Float.Last = c->u.Float.Value; |
| 426 |
break; |
| 427 |
case CONFIG_TYPE_BOOL: |
| 428 |
c->u.Bool.Last = c->u.Bool.Value; |
| 429 |
break; |
| 430 |
case CONFIG_TYPE_ENUM: |
| 431 |
c->u.Enum.Last = c->u.Enum.Value; |
| 432 |
break; |
| 433 |
case CONFIG_TYPE_GROUP: |
| 434 |
CA_FOREACH(Config, child, c->u.Group) |
| 435 |
ConfigSetChanged(child); |
| 436 |
CA_FOREACH_END() |
| 437 |
break; |
| 438 |
default: |
| 439 |
CASSERT(false, "Unknown config type"); |
| 440 |
break; |
| 441 |
} |
| 442 |
} |
| 443 |
|
| 444 |
void ConfigResetDefault(Config *c) |
| 445 |
{ |
| 446 |
switch (c->Type) |
| 447 |
{ |
| 448 |
case CONFIG_TYPE_STRING: |
| 449 |
CFREE(c->u.String.Value); |
| 450 |
if (c->u.String.Default != NULL) |
| 451 |
{ |
| 452 |
CSTRDUP(c->u.String.Value, c->u.String.Default); |
| 453 |
} |
| 454 |
break; |
| 455 |
case CONFIG_TYPE_INT: |
| 456 |
c->u.Int.Value = c->u.Int.Default; |
| 457 |
break; |
| 458 |
case CONFIG_TYPE_FLOAT: |
| 459 |
c->u.Float.Value = c->u.Float.Default; |
| 460 |
break; |
| 461 |
case CONFIG_TYPE_BOOL: |
| 462 |
c->u.Bool.Value = c->u.Bool.Default; |
| 463 |
break; |
| 464 |
case CONFIG_TYPE_ENUM: |
| 465 |
c->u.Enum.Value = c->u.Enum.Default; |
| 466 |
break; |
| 467 |
case CONFIG_TYPE_GROUP: |
| 468 |
CA_FOREACH(Config, child, c->u.Group) |
| 469 |
ConfigResetDefault(child); |
| 470 |
CA_FOREACH_END() |
| 471 |
break; |
| 472 |
default: |
| 473 |
CASSERT(false, "Unknown config type"); |
| 474 |
break; |
| 475 |
} |
| 476 |
} |
| 477 |
|
| 478 |
const char *ConfigGetString(Config *c, const char *name) |
| 479 |
{ |
| 480 |
c = ConfigGet(c, name); |
| 481 |
CASSERT(c->Type == CONFIG_TYPE_STRING, "wrong config type"); |
| 482 |
return c->u.String.Value; |
| 483 |
} |
| 484 |
int ConfigGetInt(Config *c, const char *name) |
| 485 |
{ |
| 486 |
c = ConfigGet(c, name); |
| 487 |
CASSERT(c->Type == CONFIG_TYPE_INT, "wrong config type"); |
| 488 |
return c->u.Int.Value; |
| 489 |
} |
| 490 |
double ConfigGetFloat(Config *c, const char *name) |
| 491 |
{ |
| 492 |
c = ConfigGet(c, name); |
| 493 |
CASSERT(c->Type == CONFIG_TYPE_FLOAT, "wrong config type"); |
| 494 |
return c->u.Float.Value; |
| 495 |
} |
| 496 |
bool ConfigGetBool(Config *c, const char *name) |
| 497 |
{ |
| 498 |
c = ConfigGet(c, name); |
| 499 |
CASSERT(c->Type == CONFIG_TYPE_BOOL, "wrong config type"); |
| 500 |
return c->u.Bool.Value; |
| 501 |
} |
| 502 |
int ConfigGetEnum(Config *c, const char *name) |
| 503 |
{ |
| 504 |
c = ConfigGet(c, name); |
| 505 |
CASSERT(c->Type == CONFIG_TYPE_ENUM, "wrong config type"); |
| 506 |
return c->u.Enum.Value; |
| 507 |
} |
| 508 |
CArray *ConfigGetGroup(Config *c, const char *name) |
| 509 |
{ |
| 510 |
c = ConfigGet(c, name); |
| 511 |
CASSERT(c->Type == CONFIG_TYPE_GROUP, "wrong config type"); |
| 512 |
return &c->u.Group; |
| 513 |
} |
| 514 |
|
| 515 |
void ConfigSetInt(Config *c, const char *name, const int value) |
| 516 |
{ |
| 517 |
c = ConfigGet(c, name); |
| 518 |
CASSERT(c->Type == CONFIG_TYPE_INT, "wrong config type"); |
| 519 |
c->u.Int.Value = CLAMP(value, c->u.Int.Min, c->u.Int.Max); |
| 520 |
} |
| 521 |
|
| 522 |
void ConfigSetFloat(Config *c, const char *name, const double value) |
| 523 |
{ |
| 524 |
c = ConfigGet(c, name); |
| 525 |
CASSERT(c->Type == CONFIG_TYPE_FLOAT, "wrong config type"); |
| 526 |
c->u.Float.Value = CLAMP(value, c->u.Float.Min, c->u.Float.Max); |
| 527 |
} |
| 528 |
|
| 529 |
bool ConfigTrySetFromString(Config *c, const char *name, const char *value) |
| 530 |
{ |
| 531 |
Config *child = ConfigGet(c, name); |
| 532 |
switch (child->Type) |
| 533 |
{ |
| 534 |
case CONFIG_TYPE_STRING: |
| 535 |
CASSERT(false, "unimplemented"); |
| 536 |
return false; |
| 537 |
case CONFIG_TYPE_INT: |
| 538 |
ConfigSetInt(c, name, atoi(value)); |
| 539 |
return true; |
| 540 |
case CONFIG_TYPE_FLOAT: |
| 541 |
ConfigSetFloat(c, name, atof(value)); |
| 542 |
return true; |
| 543 |
case CONFIG_TYPE_BOOL: |
| 544 |
child->u.Bool.Value = strcmp(value, "true") == 0; |
| 545 |
return false; |
| 546 |
case CONFIG_TYPE_ENUM: |
| 547 |
CASSERT(false, "unimplemented"); |
| 548 |
return false; |
| 549 |
case CONFIG_TYPE_GROUP: |
| 550 |
CASSERT(false, "Cannot set group config"); |
| 551 |
return false; |
| 552 |
default: |
| 553 |
CASSERT(false, "Unknown config type"); |
| 554 |
return false; |
| 555 |
} |
| 556 |
} |
| 557 |
|
| 558 |
Config ConfigDefault(void) |
| 559 |
{ |
| 560 |
Config root = ConfigNewGroup(NULL); |
| 561 |
|
| 562 |
Config game = ConfigNewGroup("Game"); |
| 563 |
ConfigGroupAdd(&game, ConfigNewBool("FriendlyFire", false)); |
| 564 |
ConfigGroupAdd( |
| 565 |
&game, ConfigNewInt("RandomSeed", 0, 0, INT_MAX, 1, NULL, NULL)); |
| 566 |
ConfigGroupAdd( |
| 567 |
&game, ConfigNewEnum( |
| 568 |
"Difficulty", DIFFICULTY_NORMAL, DIFFICULTY_VERYEASY, |
| 569 |
DIFFICULTY_VERYHARD, StrDifficulty, DifficultyStr)); |
| 570 |
ConfigGroupAdd(&game, ConfigNewInt("FPS", 70, 10, 120, 10, NULL, NULL)); |
| 571 |
ConfigGroupAdd(&game, ConfigNewBool("Superhot(tm)Mode", false)); |
| 572 |
ConfigGroupAdd( |
| 573 |
&game, |
| 574 |
ConfigNewInt("EnemyDensity", 100, 25, 200, 25, NULL, PercentStr)); |
| 575 |
ConfigGroupAdd( |
| 576 |
&game, |
| 577 |
ConfigNewInt("NonPlayerHP", 100, 25, 200, 25, NULL, PercentStr)); |
| 578 |
ConfigGroupAdd( |
| 579 |
&game, ConfigNewInt("PlayerHP", 75, 25, 200, 25, NULL, PercentStr)); |
| 580 |
ConfigGroupAdd(&game, ConfigNewInt("Lives", 2, 1, 5, 1, NULL, NULL)); |
| 581 |
ConfigGroupAdd(&game, ConfigNewBool("HealthPickups", true)); |
| 582 |
ConfigGroupAdd(&game, ConfigNewBool("Fog", true)); |
| 583 |
ConfigGroupAdd( |
| 584 |
&game, ConfigNewInt("SightRange", 15, 8, 40, 1, NULL, NULL)); |
| 585 |
ConfigGroupAdd( |
| 586 |
&game, ConfigNewEnum( |
| 587 |
"FireMoveStyle", FIREMOVE_STOP, FIREMOVE_STOP, |
| 588 |
FIREMOVE_STRAFE, StrFireMoveStyle, FireMoveStyleStr)); |
| 589 |
ConfigGroupAdd( |
| 590 |
&game, ConfigNewEnum( |
| 591 |
"SwitchMoveStyle", SWITCHMOVE_SLIDE, SWITCHMOVE_SLIDE, |
| 592 |
SWITCHMOVE_NONE, StrSwitchMoveStyle, SwitchMoveStyleStr)); |
| 593 |
ConfigGroupAdd( |
| 594 |
&game, ConfigNewEnum( |
| 595 |
"AllyCollision", ALLYCOLLISION_REPEL, ALLYCOLLISION_NORMAL, |
| 596 |
ALLYCOLLISION_NONE, StrAllyCollision, AllyCollisionStr)); |
| 597 |
ConfigGroupAdd( |
| 598 |
&game, ConfigNewEnum( |
| 599 |
"LaserSight", LASER_SIGHT_NONE, LASER_SIGHT_NONE, |
| 600 |
LASER_SIGHT_ALL, StrLaserSight, LaserSightStr)); |
| 601 |
ConfigGroupAdd(&game, ConfigNewBool("NoFestiveHats", false)); |
| 602 |
ConfigGroupAdd(&root, game); |
| 603 |
|
| 604 |
Config dm = ConfigNewGroup("Deathmatch"); |
| 605 |
ConfigGroupAdd(&dm, ConfigNewInt("Lives", 10, 1, 20, 1, NULL, NULL)); |
| 606 |
ConfigGroupAdd(&root, dm); |
| 607 |
|
| 608 |
Config df = ConfigNewGroup("Dogfight"); |
| 609 |
ConfigGroupAdd( |
| 610 |
&df, ConfigNewInt("PlayerHP", 100, 25, 200, 25, NULL, PercentStr)); |
| 611 |
ConfigGroupAdd(&df, ConfigNewInt("FirstTo", 5, 1, 10, 1, NULL, NULL)); |
| 612 |
ConfigGroupAdd(&root, df); |
| 613 |
|
| 614 |
Config gfx = ConfigNewGroup("Graphics"); |
| 615 |
ConfigGroupAdd( |
| 616 |
&gfx, ConfigNewInt( |
| 617 |
"Brightness", 0, BLIT_BRIGHTNESS_MIN, BLIT_BRIGHTNESS_MAX, 1, |
| 618 |
NULL, NULL)); |
| 619 |
|
| 620 |
ConfigGroupAdd( |
| 621 |
&gfx, ConfigNewBool( |
| 622 |
"Fullscreen", |
| 623 |
#ifdef __GCWZERO__ |
| 624 |
true |
| 625 |
#else |
| 626 |
false |
| 627 |
#endif |
| 628 |
)); |
| 629 |
|
| 630 |
ConfigGroupAdd( |
| 631 |
&gfx, ConfigNewInt("WindowWidth", 640, 320, 4096, 0, NULL, NULL)); |
| 632 |
ConfigGroupAdd( |
| 633 |
&gfx, ConfigNewInt("WindowHeight", 480, 200, 2160, 0, NULL, NULL)); |
| 634 |
ConfigGroupAdd( |
| 635 |
&gfx, ConfigNewInt( |
| 636 |
"ScaleFactor", |
| 637 |
#ifdef __GCWZERO__ |
| 638 |
1 |
| 639 |
#else |
| 640 |
2 |
| 641 |
#endif |
| 642 |
, |
| 643 |
1, 16, 1, NULL, NULL)); |
| 644 |
ConfigGroupAdd( |
| 645 |
&gfx, ConfigNewInt("ShakeMultiplier", 1, 0, 10, 1, NULL, NULL)); |
| 646 |
ConfigGroupAdd(&gfx, ConfigNewBool("ShowHUD", true)); |
| 647 |
ConfigGroupAdd( |
| 648 |
&gfx, ConfigNewEnum( |
| 649 |
"ScaleMode", SCALE_MODE_NN, SCALE_MODE_NN, |
| 650 |
SCALE_MODE_BILINEAR, StrScaleMode, ScaleModeStr)); |
| 651 |
ConfigGroupAdd(&gfx, ConfigNewBool("Shadows", true)); |
| 652 |
ConfigGroupAdd( |
| 653 |
&gfx, ConfigNewEnum( |
| 654 |
"Gore", GORE_LOW, GORE_NONE, GORE_HIGH, StrGoreAmount, |
| 655 |
GoreAmountStr)); |
| 656 |
ConfigGroupAdd(&gfx, ConfigNewBool("Brass", true)); |
| 657 |
ConfigGroupAdd(&gfx, ConfigNewBool("SecondWindow", false)); |
| 658 |
ConfigGroupAdd(&root, gfx); |
| 659 |
|
| 660 |
Config input = ConfigNewGroup("Input"); |
| 661 |
Config pk0 = ConfigNewGroup("PlayerCodes0"); |
| 662 |
ConfigGroupAdd( |
| 663 |
&pk0, ConfigNewInt("left", SDL_SCANCODE_LEFT, 0, 0, 0, NULL, NULL)); |
| 664 |
ConfigGroupAdd( |
| 665 |
&pk0, ConfigNewInt("right", SDL_SCANCODE_RIGHT, 0, 0, 0, NULL, NULL)); |
| 666 |
ConfigGroupAdd( |
| 667 |
&pk0, ConfigNewInt("up", SDL_SCANCODE_UP, 0, 0, 0, NULL, NULL)); |
| 668 |
ConfigGroupAdd( |
| 669 |
&pk0, ConfigNewInt("down", SDL_SCANCODE_DOWN, 0, 0, 0, NULL, NULL)); |
| 670 |
#ifdef __GCWZERO__ |
| 671 |
ConfigGroupAdd( |
| 672 |
&pk0, |
| 673 |
ConfigNewInt("button1", SDL_SCANCODE_LCTRL, 0, 0, 0, NULL, NULL)); |
| 674 |
ConfigGroupAdd( |
| 675 |
&pk0, ConfigNewInt("button2", SDL_SCANCODE_LALT, 0, 0, 0, NULL, NULL)); |
| 676 |
ConfigGroupAdd( |
| 677 |
&pk0, |
| 678 |
ConfigNewInt("grenade", SDL_SCANCODE_BACKSPACE, 0, 0, 0, NULL, NULL)); |
| 679 |
ConfigGroupAdd( |
| 680 |
&pk0, ConfigNewInt("map", SDL_SCANCODE_TAB, 0, 0, 0, NULL, NULL)); |
| 681 |
#else |
| 682 |
ConfigGroupAdd( |
| 683 |
&pk0, ConfigNewInt("button1", SDL_SCANCODE_X, 0, 0, 0, NULL, NULL)); |
| 684 |
ConfigGroupAdd( |
| 685 |
&pk0, ConfigNewInt("button2", SDL_SCANCODE_Z, 0, 0, 0, NULL, NULL)); |
| 686 |
ConfigGroupAdd( |
| 687 |
&pk0, ConfigNewInt("grenade", SDL_SCANCODE_S, 0, 0, 0, NULL, NULL)); |
| 688 |
ConfigGroupAdd( |
| 689 |
&pk0, ConfigNewInt("map", SDL_SCANCODE_A, 0, 0, 0, NULL, NULL)); |
| 690 |
#endif |
| 691 |
ConfigGroupAdd(&input, pk0); |
| 692 |
Config pk1 = ConfigNewGroup("PlayerCodes1"); |
| 693 |
ConfigGroupAdd( |
| 694 |
&pk1, ConfigNewInt("left", SDL_SCANCODE_KP_4, 0, 0, 0, NULL, NULL)); |
| 695 |
ConfigGroupAdd( |
| 696 |
&pk1, ConfigNewInt("right", SDL_SCANCODE_KP_6, 0, 0, 0, NULL, NULL)); |
| 697 |
ConfigGroupAdd( |
| 698 |
&pk1, ConfigNewInt("up", SDL_SCANCODE_KP_8, 0, 0, 0, NULL, NULL)); |
| 699 |
ConfigGroupAdd( |
| 700 |
&pk1, ConfigNewInt("down", SDL_SCANCODE_KP_2, 0, 0, 0, NULL, NULL)); |
| 701 |
ConfigGroupAdd( |
| 702 |
&pk1, |
| 703 |
ConfigNewInt("button1", SDL_SCANCODE_KP_ENTER, 0, 0, 0, NULL, NULL)); |
| 704 |
ConfigGroupAdd( |
| 705 |
&pk1, |
| 706 |
ConfigNewInt("button2", SDL_SCANCODE_KP_PERIOD, 0, 0, 0, NULL, NULL)); |
| 707 |
ConfigGroupAdd( |
| 708 |
&pk1, ConfigNewInt("grenade", SDL_SCANCODE_KP_3, 0, 0, 0, NULL, NULL)); |
| 709 |
ConfigGroupAdd( |
| 710 |
&pk1, ConfigNewInt("map", SDL_SCANCODE_KP_0, 0, 0, 0, NULL, NULL)); |
| 711 |
ConfigGroupAdd(&input, pk1); |
| 712 |
ConfigGroupAdd(&root, input); |
| 713 |
|
| 714 |
Config itf = ConfigNewGroup("Interface"); |
| 715 |
ConfigGroupAdd(&itf, ConfigNewBool("ShowFPS", false)); |
| 716 |
ConfigGroupAdd(&itf, ConfigNewBool("ShowTime", false)); |
| 717 |
ConfigGroupAdd(&itf, ConfigNewBool("ShowHUDMap", true)); |
| 718 |
ConfigGroupAdd( |
| 719 |
&itf, ConfigNewEnum( |
| 720 |
"AIChatter", AICHATTER_SELDOM, AICHATTER_NONE, |
| 721 |
AICHATTER_ALWAYS, StrAIChatter, AIChatterStr)); |
| 722 |
ConfigGroupAdd( |
| 723 |
&itf, |
| 724 |
ConfigNewEnum( |
| 725 |
"Splitscreen", SPLITSCREEN_NEVER, SPLITSCREEN_NORMAL, |
| 726 |
SPLITSCREEN_NEVER, StrSplitscreenStyle, SplitscreenStyleStr)); |
| 727 |
ConfigGroupAdd(&itf, ConfigNewBool("SplitscreenAI", false)); |
| 728 |
ConfigGroupAdd(&root, itf); |
| 729 |
|
| 730 |
Config snd = ConfigNewGroup("Sound"); |
| 731 |
ConfigGroupAdd( |
| 732 |
&snd, ConfigNewInt("MusicVolume", 32, 0, 64, 8, NULL, Div8Str)); |
| 733 |
ConfigGroupAdd( |
| 734 |
&snd, ConfigNewInt("SoundVolume", 64, 0, 64, 8, NULL, Div8Str)); |
| 735 |
ConfigGroupAdd(&snd, ConfigNewBool("Footsteps", true)); |
| 736 |
ConfigGroupAdd(&snd, ConfigNewBool("Reloads", true)); |
| 737 |
ConfigGroupAdd(&root, snd); |
| 738 |
|
| 739 |
Config qp = ConfigNewGroup("QuickPlay"); |
| 740 |
ConfigGroupAdd( |
| 741 |
&qp, ConfigNewEnum( |
| 742 |
"MapSize", QUICKPLAY_QUANTITY_ANY, QUICKPLAY_QUANTITY_ANY, |
| 743 |
QUICKPLAY_QUANTITY_LARGE, StrQuickPlayQuantity, |
| 744 |
QuickPlayQuantityStr)); |
| 745 |
ConfigGroupAdd( |
| 746 |
&qp, ConfigNewEnum( |
| 747 |
"WallCount", QUICKPLAY_QUANTITY_ANY, QUICKPLAY_QUANTITY_ANY, |
| 748 |
QUICKPLAY_QUANTITY_LARGE, StrQuickPlayQuantity, |
| 749 |
QuickPlayQuantityStr)); |
| 750 |
ConfigGroupAdd( |
| 751 |
&qp, ConfigNewEnum( |
| 752 |
"WallLength", QUICKPLAY_QUANTITY_ANY, QUICKPLAY_QUANTITY_ANY, |
| 753 |
QUICKPLAY_QUANTITY_LARGE, StrQuickPlayQuantity, |
| 754 |
QuickPlayQuantityStr)); |
| 755 |
ConfigGroupAdd( |
| 756 |
&qp, ConfigNewEnum( |
| 757 |
"RoomCount", QUICKPLAY_QUANTITY_ANY, QUICKPLAY_QUANTITY_ANY, |
| 758 |
QUICKPLAY_QUANTITY_LARGE, StrQuickPlayQuantity, |
| 759 |
QuickPlayQuantityStr)); |
| 760 |
ConfigGroupAdd( |
| 761 |
&qp, ConfigNewEnum( |
| 762 |
"SquareCount", QUICKPLAY_QUANTITY_ANY, QUICKPLAY_QUANTITY_ANY, |
| 763 |
QUICKPLAY_QUANTITY_LARGE, StrQuickPlayQuantity, |
| 764 |
QuickPlayQuantityStr)); |
| 765 |
ConfigGroupAdd( |
| 766 |
&qp, ConfigNewEnum( |
| 767 |
"EnemyCount", QUICKPLAY_QUANTITY_ANY, QUICKPLAY_QUANTITY_ANY, |
| 768 |
QUICKPLAY_QUANTITY_LARGE, StrQuickPlayQuantity, |
| 769 |
QuickPlayQuantityStr)); |
| 770 |
ConfigGroupAdd( |
| 771 |
&qp, ConfigNewEnum( |
| 772 |
"EnemySpeed", QUICKPLAY_QUANTITY_ANY, QUICKPLAY_QUANTITY_ANY, |
| 773 |
QUICKPLAY_QUANTITY_LARGE, StrQuickPlayQuantity, |
| 774 |
QuickPlayQuantityStr)); |
| 775 |
ConfigGroupAdd( |
| 776 |
&qp, ConfigNewEnum( |
| 777 |
"EnemyHealth", QUICKPLAY_QUANTITY_ANY, QUICKPLAY_QUANTITY_ANY, |
| 778 |
QUICKPLAY_QUANTITY_LARGE, StrQuickPlayQuantity, |
| 779 |
QuickPlayQuantityStr)); |
| 780 |
ConfigGroupAdd(&qp, ConfigNewBool("EnemiesWithExplosives", true)); |
| 781 |
ConfigGroupAdd( |
| 782 |
&qp, ConfigNewEnum( |
| 783 |
"ItemCount", QUICKPLAY_QUANTITY_ANY, QUICKPLAY_QUANTITY_ANY, |
| 784 |
QUICKPLAY_QUANTITY_LARGE, StrQuickPlayQuantity, |
| 785 |
QuickPlayQuantityStr)); |
| 786 |
ConfigGroupAdd(&root, qp); |
| 787 |
|
| 788 |
ConfigGroupAdd(&root, ConfigNewBool("StartServer", false)); |
| 789 |
ConfigGroupAdd( |
| 790 |
&root, |
| 791 |
ConfigNewInt( |
| 792 |
"ListenPort", NET_DEFAULT_LISTEN_PORT, 0, 65535, 1, NULL, NULL)); |
| 793 |
|
| 794 |
return root; |
| 795 |
} |