| 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 |
#include <assert.h> |
| 27 |
#include <stdio.h> |
| 28 |
#include <stdlib.h> |
| 29 |
#include <string.h> |
| 30 |
|
| 31 |
#include "scare.h" |
| 32 |
#include "scprotos.h" |
| 33 |
#include "scgamest.h" |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
static const sc_char NEWLINE = '\n'; |
| 38 |
static const sc_char CARRIAGE_RETURN = '\r'; |
| 39 |
static const sc_char NUL = '\0'; |
| 40 |
|
| 41 |
|
| 42 |
static sc_uint if_trace_flags = 0; |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
static void |
| 52 |
if_initialize (void) |
| 53 |
{ |
| 54 |
static sc_bool initialized = FALSE; |
| 55 |
|
| 56 |
|
| 57 |
if (!initialized) |
| 58 |
{ |
| 59 |
|
| 60 |
if (sizeof (sc_byte) != 1 || sizeof (sc_char) != 1) |
| 61 |
{ |
| 62 |
sc_error ("if_initialize: sizeof sc_byte or sc_char" |
| 63 |
" is not 1, check compile options\n"); |
| 64 |
} |
| 65 |
else if (sizeof (sc_uint) < 4 || sizeof (sc_int) < 4) |
| 66 |
{ |
| 67 |
sc_error ("if_initialize: sizeof sc_uint or sc_int" |
| 68 |
" is not at least 4, check compile options\n"); |
| 69 |
} |
| 70 |
else if (sizeof (sc_uint) > 8 || sizeof (sc_int) > 8) |
| 71 |
{ |
| 72 |
sc_error ("if_initialize: sizeof sc_uint or sc_int" |
| 73 |
" is more than 8, check compile options\n"); |
| 74 |
} |
| 75 |
else if (!((sc_uint) -1 > 0)) |
| 76 |
{ |
| 77 |
sc_error ("if_initialize: sc_uint appears not to be unsigned," |
| 78 |
" check compile options\n"); |
| 79 |
} |
| 80 |
|
| 81 |
initialized = TRUE; |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
static sc_bool |
| 95 |
if_bool (sc_uint flag) |
| 96 |
{ |
| 97 |
return flag ? TRUE : FALSE; |
| 98 |
} |
| 99 |
|
| 100 |
void |
| 101 |
sc_set_trace_flags (sc_uint trace_flags) |
| 102 |
{ |
| 103 |
if_initialize (); |
| 104 |
|
| 105 |
|
| 106 |
if_trace_flags = trace_flags; |
| 107 |
|
| 108 |
|
| 109 |
parse_debug_trace (if_bool (trace_flags & SC_TRACE_PARSE)); |
| 110 |
prop_debug_trace (if_bool (trace_flags & SC_TRACE_PROPERTIES)); |
| 111 |
var_debug_trace (if_bool (trace_flags & SC_TRACE_VARIABLES)); |
| 112 |
uip_debug_trace (if_bool (trace_flags & SC_TRACE_PARSER)); |
| 113 |
lib_debug_trace (if_bool (trace_flags & SC_TRACE_LIBRARY)); |
| 114 |
evt_debug_trace (if_bool (trace_flags & SC_TRACE_EVENTS)); |
| 115 |
npc_debug_trace (if_bool (trace_flags & SC_TRACE_NPCS)); |
| 116 |
obj_debug_trace (if_bool (trace_flags & SC_TRACE_OBJECTS)); |
| 117 |
task_debug_trace (if_bool (trace_flags & SC_TRACE_TASKS)); |
| 118 |
restr_debug_trace (if_bool (trace_flags & SC_TRACE_TASKS)); |
| 119 |
pf_debug_trace (if_bool (trace_flags & SC_TRACE_PRINTFILTER)); |
| 120 |
} |
| 121 |
|
| 122 |
sc_bool |
| 123 |
if_get_trace_flag (sc_uint bitmask) |
| 124 |
{ |
| 125 |
return if_bool (if_trace_flags & bitmask); |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
static void |
| 141 |
if_print_string_common (const sc_char *string, |
| 142 |
void (*print_string_function) (const sc_char *)) |
| 143 |
{ |
| 144 |
assert (string); |
| 145 |
|
| 146 |
if (string[0] != NUL) |
| 147 |
print_string_function (string); |
| 148 |
} |
| 149 |
|
| 150 |
void |
| 151 |
if_print_string (const sc_char *string) |
| 152 |
{ |
| 153 |
if_print_string_common (string, os_print_string); |
| 154 |
} |
| 155 |
|
| 156 |
void |
| 157 |
if_print_debug (const sc_char *string) |
| 158 |
{ |
| 159 |
if_print_string_common (string, os_print_string_debug); |
| 160 |
} |
| 161 |
|
| 162 |
static void |
| 163 |
if_print_character_common (sc_char character, |
| 164 |
void (*print_string_function) (const sc_char *)) |
| 165 |
{ |
| 166 |
if (character != NUL) |
| 167 |
{ |
| 168 |
sc_char buffer[2]; |
| 169 |
|
| 170 |
buffer[0] = character; |
| 171 |
buffer[1] = NUL; |
| 172 |
print_string_function (buffer); |
| 173 |
} |
| 174 |
} |
| 175 |
|
| 176 |
void |
| 177 |
if_print_character (sc_char character) |
| 178 |
{ |
| 179 |
if_print_character_common (character, os_print_string); |
| 180 |
} |
| 181 |
|
| 182 |
void |
| 183 |
if_print_debug_character (sc_char character) |
| 184 |
{ |
| 185 |
if_print_character_common (character, os_print_string_debug); |
| 186 |
} |
| 187 |
|
| 188 |
void |
| 189 |
if_print_tag (sc_int tag, const sc_char *arg) |
| 190 |
{ |
| 191 |
assert (arg); |
| 192 |
|
| 193 |
os_print_tag (tag, arg); |
| 194 |
} |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
static void |
| 206 |
if_read_line_common (sc_char *buffer, sc_int length, |
| 207 |
sc_bool (*read_line_function) (sc_char *, sc_int)) |
| 208 |
{ |
| 209 |
sc_bool is_line_available; |
| 210 |
sc_int last; |
| 211 |
assert (buffer && length > 0); |
| 212 |
|
| 213 |
|
| 214 |
do |
| 215 |
{ |
| 216 |
|
| 217 |
if_print_character ('\n'); |
| 218 |
memset (buffer, NUL, length); |
| 219 |
|
| 220 |
is_line_available = read_line_function (buffer, length); |
| 221 |
} |
| 222 |
while (!is_line_available); |
| 223 |
|
| 224 |
|
| 225 |
last = strlen (buffer) - 1; |
| 226 |
while (last >= 0 |
| 227 |
&& (buffer[last] == CARRIAGE_RETURN || buffer[last] == NEWLINE)) |
| 228 |
buffer[last--] = NUL; |
| 229 |
} |
| 230 |
|
| 231 |
void |
| 232 |
if_read_line (sc_char *buffer, sc_int length) |
| 233 |
{ |
| 234 |
if_read_line_common (buffer, length, os_read_line); |
| 235 |
} |
| 236 |
|
| 237 |
void |
| 238 |
if_read_debug (sc_char *buffer, sc_int length) |
| 239 |
{ |
| 240 |
if_read_line_common (buffer, length, os_read_line_debug); |
| 241 |
} |
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
sc_bool |
| 250 |
if_confirm (sc_int type) |
| 251 |
{ |
| 252 |
return os_confirm (type); |
| 253 |
} |
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
void * |
| 265 |
if_open_saved_game (sc_bool is_save) |
| 266 |
{ |
| 267 |
return os_open_file (is_save); |
| 268 |
} |
| 269 |
|
| 270 |
void |
| 271 |
if_write_saved_game (void *opaque, const sc_byte *buffer, sc_int length) |
| 272 |
{ |
| 273 |
assert (buffer); |
| 274 |
|
| 275 |
os_write_file (opaque, buffer, length); |
| 276 |
} |
| 277 |
|
| 278 |
sc_int |
| 279 |
if_read_saved_game (void *opaque, sc_byte *buffer, sc_int length) |
| 280 |
{ |
| 281 |
assert (buffer); |
| 282 |
|
| 283 |
return os_read_file (opaque, buffer, length); |
| 284 |
} |
| 285 |
|
| 286 |
void |
| 287 |
if_close_saved_game (void *opaque) |
| 288 |
{ |
| 289 |
os_close_file (opaque); |
| 290 |
} |
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
void |
| 299 |
if_display_hints (sc_gameref_t game) |
| 300 |
{ |
| 301 |
assert (gs_is_game_valid (game)); |
| 302 |
|
| 303 |
os_display_hints ((sc_game) game); |
| 304 |
} |
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
void |
| 314 |
if_update_sound (const sc_char *filename, |
| 315 |
sc_int sound_offset, sc_int sound_length, |
| 316 |
sc_bool is_looping) |
| 317 |
{ |
| 318 |
if (strlen (filename) > 0) |
| 319 |
os_play_sound (filename, sound_offset, sound_length, is_looping); |
| 320 |
else |
| 321 |
os_stop_sound (); |
| 322 |
} |
| 323 |
|
| 324 |
void |
| 325 |
if_update_graphic (const sc_char *filename, |
| 326 |
sc_int graphic_offset, sc_int graphic_length) |
| 327 |
{ |
| 328 |
os_show_graphic (filename, graphic_offset, graphic_length); |
| 329 |
} |
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
const sc_char * |
| 339 |
sc_scare_version (void) |
| 340 |
{ |
| 341 |
if_initialize (); |
| 342 |
return "SCARE " SCARE_VERSION SCARE_PATCH_LEVEL; |
| 343 |
} |
| 344 |
|
| 345 |
sc_int |
| 346 |
sc_scare_emulation (void) |
| 347 |
{ |
| 348 |
if_initialize (); |
| 349 |
return SCARE_EMULATION; |
| 350 |
} |
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
static sc_int |
| 361 |
if_file_read_callback (void *opaque, sc_byte *buffer, sc_int length) |
| 362 |
{ |
| 363 |
FILE *stream = (FILE *) opaque; |
| 364 |
sc_int bytes; |
| 365 |
|
| 366 |
bytes = fread (buffer, 1, length, stream); |
| 367 |
if (ferror (stream)) |
| 368 |
sc_error ("if_file_read_callback: warning: read error\n"); |
| 369 |
|
| 370 |
return bytes; |
| 371 |
} |
| 372 |
|
| 373 |
static void |
| 374 |
if_file_write_callback (void *opaque, const sc_byte *buffer, sc_int length) |
| 375 |
{ |
| 376 |
FILE *stream = (FILE *) opaque; |
| 377 |
|
| 378 |
fwrite (buffer, 1, length, stream); |
| 379 |
if (ferror (stream)) |
| 380 |
sc_error ("if_file_write_callback: warning: write error\n"); |
| 381 |
} |
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
sc_game |
| 393 |
sc_game_from_filename (const sc_char *filename) |
| 394 |
{ |
| 395 |
FILE *stream; |
| 396 |
sc_game game; |
| 397 |
|
| 398 |
if_initialize (); |
| 399 |
if (!filename) |
| 400 |
{ |
| 401 |
sc_error ("sc_game_from_filename: NULL filename\n"); |
| 402 |
return NULL; |
| 403 |
} |
| 404 |
|
| 405 |
stream = fopen (filename, "rb"); |
| 406 |
if (!stream) |
| 407 |
{ |
| 408 |
sc_error ("sc_game_from_filename: fopen error\n"); |
| 409 |
return NULL; |
| 410 |
} |
| 411 |
|
| 412 |
game = run_create (if_file_read_callback, stream); |
| 413 |
fclose (stream); |
| 414 |
|
| 415 |
return game; |
| 416 |
} |
| 417 |
|
| 418 |
sc_game |
| 419 |
sc_game_from_stream (FILE *stream) |
| 420 |
{ |
| 421 |
if_initialize (); |
| 422 |
if (!stream) |
| 423 |
{ |
| 424 |
sc_error ("sc_game_from_stream: NULL stream\n"); |
| 425 |
return NULL; |
| 426 |
} |
| 427 |
|
| 428 |
return run_create (if_file_read_callback, stream); |
| 429 |
} |
| 430 |
|
| 431 |
sc_game |
| 432 |
sc_game_from_callback (sc_int (*callback) (void *, sc_byte *, sc_int), |
| 433 |
void *opaque) |
| 434 |
{ |
| 435 |
if_initialize (); |
| 436 |
if (!callback) |
| 437 |
{ |
| 438 |
sc_error ("sc_game_from_callback: NULL callback\n"); |
| 439 |
return NULL; |
| 440 |
} |
| 441 |
|
| 442 |
return run_create (callback, opaque); |
| 443 |
} |
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
static sc_bool |
| 453 |
if_game_error (sc_gameref_t game, const sc_char *function_name) |
| 454 |
{ |
| 455 |
|
| 456 |
if (!gs_is_game_valid (game)) |
| 457 |
{ |
| 458 |
if (game) |
| 459 |
sc_error ("%s: invalid game\n", function_name); |
| 460 |
else |
| 461 |
sc_error ("%s: NULL game\n", function_name); |
| 462 |
return TRUE; |
| 463 |
} |
| 464 |
|
| 465 |
|
| 466 |
return FALSE; |
| 467 |
} |
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
void |
| 487 |
sc_interpret_game (sc_game game) |
| 488 |
{ |
| 489 |
const sc_gameref_t game_ = game; |
| 490 |
|
| 491 |
if (if_game_error (game_, "sc_interpret_game")) |
| 492 |
return; |
| 493 |
|
| 494 |
run_interpret (game_); |
| 495 |
} |
| 496 |
|
| 497 |
void |
| 498 |
sc_restart_game (sc_game game) |
| 499 |
{ |
| 500 |
const sc_gameref_t game_ = game; |
| 501 |
|
| 502 |
if (if_game_error (game_, "sc_restart_game")) |
| 503 |
return; |
| 504 |
|
| 505 |
run_restart (game_); |
| 506 |
} |
| 507 |
|
| 508 |
sc_bool |
| 509 |
sc_save_game (sc_game game) |
| 510 |
{ |
| 511 |
const sc_gameref_t game_ = game; |
| 512 |
|
| 513 |
if (if_game_error (game_, "sc_save_game")) |
| 514 |
return FALSE; |
| 515 |
|
| 516 |
return run_save_prompted (game_); |
| 517 |
} |
| 518 |
|
| 519 |
sc_bool |
| 520 |
sc_load_game (sc_game game) |
| 521 |
{ |
| 522 |
const sc_gameref_t game_ = game; |
| 523 |
|
| 524 |
if (if_game_error (game_, "sc_load_game")) |
| 525 |
return FALSE; |
| 526 |
|
| 527 |
return run_restore_prompted (game_); |
| 528 |
} |
| 529 |
|
| 530 |
sc_bool |
| 531 |
sc_undo_game_turn (sc_game game) |
| 532 |
{ |
| 533 |
const sc_gameref_t game_ = game; |
| 534 |
|
| 535 |
if (if_game_error (game_, "sc_undo_game_turn")) |
| 536 |
return FALSE; |
| 537 |
|
| 538 |
return run_undo (game_); |
| 539 |
} |
| 540 |
|
| 541 |
void |
| 542 |
sc_quit_game (sc_game game) |
| 543 |
{ |
| 544 |
const sc_gameref_t game_ = game; |
| 545 |
|
| 546 |
if (if_game_error (game_, "sc_quit_game")) |
| 547 |
return; |
| 548 |
|
| 549 |
run_quit (game_); |
| 550 |
} |
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
sc_bool |
| 568 |
sc_save_game_to_filename (sc_game game, const sc_char *filename) |
| 569 |
{ |
| 570 |
const sc_gameref_t game_ = game; |
| 571 |
FILE *stream; |
| 572 |
|
| 573 |
if (if_game_error (game_, "sc_save_game_to_filename")) |
| 574 |
return FALSE; |
| 575 |
|
| 576 |
if (!filename) |
| 577 |
{ |
| 578 |
sc_error ("sc_save_game_to_filename: NULL filename\n"); |
| 579 |
return FALSE; |
| 580 |
} |
| 581 |
|
| 582 |
stream = fopen (filename, "wb"); |
| 583 |
if (!stream) |
| 584 |
{ |
| 585 |
sc_error ("sc_save_game_to_filename: fopen error\n"); |
| 586 |
return FALSE; |
| 587 |
} |
| 588 |
|
| 589 |
run_save (game_, if_file_write_callback, stream); |
| 590 |
fclose (stream); |
| 591 |
|
| 592 |
return TRUE; |
| 593 |
} |
| 594 |
|
| 595 |
void |
| 596 |
sc_save_game_to_stream (sc_game game, FILE *stream) |
| 597 |
{ |
| 598 |
const sc_gameref_t game_ = game; |
| 599 |
|
| 600 |
if (if_game_error (game_, "sc_save_game_to_stream")) |
| 601 |
return; |
| 602 |
|
| 603 |
if (!stream) |
| 604 |
{ |
| 605 |
sc_error ("sc_save_game_to_stream: NULL stream\n"); |
| 606 |
return; |
| 607 |
} |
| 608 |
|
| 609 |
run_save (game_, if_file_write_callback, stream); |
| 610 |
} |
| 611 |
|
| 612 |
void |
| 613 |
sc_save_game_to_callback (sc_game game, |
| 614 |
void (*callback) (void *, const sc_byte *, sc_int), |
| 615 |
void *opaque) |
| 616 |
{ |
| 617 |
const sc_gameref_t game_ = game; |
| 618 |
|
| 619 |
if (if_game_error (game_, "sc_save_game_to_callback")) |
| 620 |
return; |
| 621 |
|
| 622 |
if (!callback) |
| 623 |
{ |
| 624 |
sc_error ("sc_save_game_to_callback: NULL callback\n"); |
| 625 |
return; |
| 626 |
} |
| 627 |
|
| 628 |
run_save (game_, callback, opaque); |
| 629 |
} |
| 630 |
|
| 631 |
sc_bool |
| 632 |
sc_load_game_from_filename (sc_game game, const sc_char *filename) |
| 633 |
{ |
| 634 |
const sc_gameref_t game_ = game; |
| 635 |
FILE *stream; |
| 636 |
sc_bool status; |
| 637 |
|
| 638 |
if (if_game_error (game_, "sc_load_game_from_filename")) |
| 639 |
return FALSE; |
| 640 |
|
| 641 |
if (!filename) |
| 642 |
{ |
| 643 |
sc_error ("sc_load_game_from_filename: NULL filename\n"); |
| 644 |
return FALSE; |
| 645 |
} |
| 646 |
|
| 647 |
stream = fopen (filename, "rb"); |
| 648 |
if (!stream) |
| 649 |
{ |
| 650 |
sc_error ("sc_load_game_from_filename: fopen error\n"); |
| 651 |
return FALSE; |
| 652 |
} |
| 653 |
|
| 654 |
status = run_restore (game_, if_file_read_callback, stream); |
| 655 |
fclose (stream); |
| 656 |
|
| 657 |
return status; |
| 658 |
} |
| 659 |
|
| 660 |
sc_bool |
| 661 |
sc_load_game_from_stream (sc_game game, FILE *stream) |
| 662 |
{ |
| 663 |
const sc_gameref_t game_ = game; |
| 664 |
|
| 665 |
if (if_game_error (game_, "sc_load_game_from_stream")) |
| 666 |
return FALSE; |
| 667 |
|
| 668 |
if (!stream) |
| 669 |
{ |
| 670 |
sc_error ("sc_load_game_from_stream: NULL stream\n"); |
| 671 |
return FALSE; |
| 672 |
} |
| 673 |
|
| 674 |
return run_restore (game_, if_file_read_callback, stream); |
| 675 |
} |
| 676 |
|
| 677 |
sc_bool |
| 678 |
sc_load_game_from_callback (sc_game game, |
| 679 |
sc_int (*callback) (void *, sc_byte *, sc_int), |
| 680 |
void *opaque) |
| 681 |
{ |
| 682 |
const sc_gameref_t game_ = game; |
| 683 |
|
| 684 |
if (if_game_error (game_, "sc_load_game_from_callback")) |
| 685 |
return FALSE; |
| 686 |
|
| 687 |
if (!callback) |
| 688 |
{ |
| 689 |
sc_error ("sc_load_game_from_callback: NULL callback\n"); |
| 690 |
return FALSE; |
| 691 |
} |
| 692 |
|
| 693 |
return run_restore (game_, callback, opaque); |
| 694 |
} |
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
void |
| 703 |
sc_free_game (sc_game game) |
| 704 |
{ |
| 705 |
const sc_gameref_t game_ = game; |
| 706 |
|
| 707 |
if (if_game_error (game_, "sc_free_game")) |
| 708 |
return; |
| 709 |
|
| 710 |
run_destroy (game_); |
| 711 |
} |
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
sc_bool |
| 734 |
sc_is_game_running (sc_game game) |
| 735 |
{ |
| 736 |
const sc_gameref_t game_ = game; |
| 737 |
|
| 738 |
if (if_game_error (game_, "sc_is_game_running")) |
| 739 |
return FALSE; |
| 740 |
|
| 741 |
return run_is_running (game_); |
| 742 |
} |
| 743 |
|
| 744 |
const sc_char * |
| 745 |
sc_get_game_name (sc_game game) |
| 746 |
{ |
| 747 |
const sc_gameref_t game_ = game; |
| 748 |
const sc_char *retval; |
| 749 |
|
| 750 |
if (if_game_error (game_, "sc_get_game_name")) |
| 751 |
return "[invalid game]"; |
| 752 |
|
| 753 |
run_get_attributes (game_, &retval, |
| 754 |
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
| 755 |
NULL, NULL); |
| 756 |
return retval; |
| 757 |
} |
| 758 |
|
| 759 |
const sc_char * |
| 760 |
sc_get_game_author (sc_game game) |
| 761 |
{ |
| 762 |
const sc_gameref_t game_ = game; |
| 763 |
const sc_char *retval; |
| 764 |
|
| 765 |
if (if_game_error (game_, "sc_get_game_author")) |
| 766 |
return "[invalid game]"; |
| 767 |
|
| 768 |
run_get_attributes (game_, NULL, &retval, |
| 769 |
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
| 770 |
NULL); |
| 771 |
return retval; |
| 772 |
} |
| 773 |
|
| 774 |
const sc_char * |
| 775 |
sc_get_game_compile_date (sc_game game) |
| 776 |
{ |
| 777 |
const sc_gameref_t game_ = game; |
| 778 |
const sc_char *retval; |
| 779 |
|
| 780 |
if (if_game_error (game_, "sc_get_game_compile_date")) |
| 781 |
return "[invalid game]"; |
| 782 |
|
| 783 |
run_get_attributes (game_, NULL, NULL, &retval, |
| 784 |
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); |
| 785 |
return retval; |
| 786 |
} |
| 787 |
|
| 788 |
sc_int |
| 789 |
sc_get_game_turns (sc_game game) |
| 790 |
{ |
| 791 |
const sc_gameref_t game_ = game; |
| 792 |
sc_int retval; |
| 793 |
|
| 794 |
if (if_game_error (game_, "sc_get_game_turns")) |
| 795 |
return 0; |
| 796 |
|
| 797 |
run_get_attributes (game_, NULL, NULL, NULL, &retval, |
| 798 |
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); |
| 799 |
return retval; |
| 800 |
} |
| 801 |
|
| 802 |
sc_int |
| 803 |
sc_get_game_score (sc_game game) |
| 804 |
{ |
| 805 |
const sc_gameref_t game_ = game; |
| 806 |
sc_int retval; |
| 807 |
|
| 808 |
if (if_game_error (game_, "sc_get_game_score")) |
| 809 |
return 0; |
| 810 |
|
| 811 |
run_get_attributes (game_, NULL, NULL, NULL, NULL, &retval, |
| 812 |
NULL, NULL, NULL, NULL, NULL, NULL, NULL); |
| 813 |
return retval; |
| 814 |
} |
| 815 |
|
| 816 |
sc_int |
| 817 |
sc_get_game_max_score (sc_game game) |
| 818 |
{ |
| 819 |
const sc_gameref_t game_ = game; |
| 820 |
sc_int retval; |
| 821 |
|
| 822 |
if (if_game_error (game_, "sc_get_game_max_score")) |
| 823 |
return 0; |
| 824 |
|
| 825 |
run_get_attributes (game_, NULL, NULL, NULL, NULL, NULL, &retval, |
| 826 |
NULL, NULL, NULL, NULL, NULL, NULL); |
| 827 |
return retval; |
| 828 |
} |
| 829 |
|
| 830 |
const sc_char * |
| 831 |
sc_get_game_room (sc_game game) |
| 832 |
{ |
| 833 |
const sc_gameref_t game_ = game; |
| 834 |
const sc_char *retval; |
| 835 |
|
| 836 |
if (if_game_error (game_, "sc_get_game_room")) |
| 837 |
return "[invalid game]"; |
| 838 |
|
| 839 |
run_get_attributes (game_, NULL, NULL, NULL, NULL, NULL, NULL, &retval, |
| 840 |
NULL, NULL, NULL, NULL, NULL); |
| 841 |
return retval; |
| 842 |
} |
| 843 |
|
| 844 |
const sc_char * |
| 845 |
sc_get_game_status_line (sc_game game) |
| 846 |
{ |
| 847 |
const sc_gameref_t game_ = game; |
| 848 |
const sc_char *retval; |
| 849 |
|
| 850 |
if (if_game_error (game_, "sc_get_game_status_line")) |
| 851 |
return "[invalid game]"; |
| 852 |
|
| 853 |
run_get_attributes (game_, NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
| 854 |
&retval, NULL, NULL, NULL, NULL); |
| 855 |
return retval; |
| 856 |
} |
| 857 |
|
| 858 |
const sc_char * |
| 859 |
sc_get_game_preferred_font (sc_game game) |
| 860 |
{ |
| 861 |
const sc_gameref_t game_ = game; |
| 862 |
const sc_char *retval; |
| 863 |
|
| 864 |
if (if_game_error (game_, "sc_get_game_preferred_font")) |
| 865 |
return "[invalid game]"; |
| 866 |
|
| 867 |
run_get_attributes (game_, NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
| 868 |
NULL, &retval, NULL, NULL, NULL); |
| 869 |
return retval; |
| 870 |
} |
| 871 |
|
| 872 |
sc_bool |
| 873 |
sc_get_game_bold_room_names (sc_game game) |
| 874 |
{ |
| 875 |
const sc_gameref_t game_ = game; |
| 876 |
sc_bool retval; |
| 877 |
|
| 878 |
if (if_game_error (game_, "sc_get_game_bold_room_names")) |
| 879 |
return FALSE; |
| 880 |
|
| 881 |
run_get_attributes (game_, NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
| 882 |
NULL, NULL, &retval, NULL, NULL); |
| 883 |
return retval; |
| 884 |
} |
| 885 |
|
| 886 |
sc_bool |
| 887 |
sc_get_game_verbose (sc_game game) |
| 888 |
{ |
| 889 |
const sc_gameref_t game_ = game; |
| 890 |
sc_bool retval; |
| 891 |
|
| 892 |
if (if_game_error (game_, "sc_get_game_verbose")) |
| 893 |
return FALSE; |
| 894 |
|
| 895 |
run_get_attributes (game_, NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
| 896 |
NULL, NULL, NULL, &retval, NULL); |
| 897 |
return retval; |
| 898 |
} |
| 899 |
|
| 900 |
sc_bool |
| 901 |
sc_get_game_notify_score_change (sc_game game) |
| 902 |
{ |
| 903 |
const sc_gameref_t game_ = game; |
| 904 |
sc_bool retval; |
| 905 |
|
| 906 |
if (if_game_error (game_, "sc_get_game_notify_score_change")) |
| 907 |
return FALSE; |
| 908 |
|
| 909 |
run_get_attributes (game_, NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
| 910 |
NULL, NULL, NULL, NULL, &retval); |
| 911 |
return retval; |
| 912 |
} |
| 913 |
|
| 914 |
sc_bool |
| 915 |
sc_has_game_completed (sc_game game) |
| 916 |
{ |
| 917 |
const sc_gameref_t game_ = game; |
| 918 |
|
| 919 |
if (if_game_error (game_, "sc_has_game_completed")) |
| 920 |
return FALSE; |
| 921 |
|
| 922 |
return run_has_completed (game_); |
| 923 |
} |
| 924 |
|
| 925 |
sc_bool |
| 926 |
sc_is_game_undo_available (sc_game game) |
| 927 |
{ |
| 928 |
const sc_gameref_t game_ = game; |
| 929 |
|
| 930 |
if (if_game_error (game_, "sc_is_game_undo_available")) |
| 931 |
return FALSE; |
| 932 |
|
| 933 |
return run_is_undo_available (game_); |
| 934 |
} |
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
void |
| 945 |
sc_set_game_bold_room_names (sc_game game, sc_bool flag) |
| 946 |
{ |
| 947 |
const sc_gameref_t game_ = game; |
| 948 |
sc_bool bold, verbose, notify; |
| 949 |
|
| 950 |
if (if_game_error (game_, "sc_set_game_bold_room_names")) |
| 951 |
return; |
| 952 |
|
| 953 |
run_get_attributes (game_, NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
| 954 |
NULL, NULL, &bold, &verbose, ¬ify); |
| 955 |
run_set_attributes (game_, flag, verbose, notify); |
| 956 |
} |
| 957 |
|
| 958 |
void |
| 959 |
sc_set_game_verbose (sc_game game, sc_bool flag) |
| 960 |
{ |
| 961 |
const sc_gameref_t game_ = game; |
| 962 |
sc_bool bold, verbose, notify; |
| 963 |
|
| 964 |
if (if_game_error (game_, "sc_set_game_verbose")) |
| 965 |
return; |
| 966 |
|
| 967 |
run_get_attributes (game_, NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
| 968 |
NULL, NULL, &bold, &verbose, ¬ify); |
| 969 |
run_set_attributes (game_, bold, flag, notify); |
| 970 |
} |
| 971 |
|
| 972 |
void |
| 973 |
sc_set_game_notify_score_change (sc_game game, sc_bool flag) |
| 974 |
{ |
| 975 |
const sc_gameref_t game_ = game; |
| 976 |
sc_bool bold, verbose, notify; |
| 977 |
|
| 978 |
if (if_game_error (game_, "sc_set_game_notify_score_change")) |
| 979 |
return; |
| 980 |
|
| 981 |
run_get_attributes (game_, NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
| 982 |
NULL, NULL, &bold, &verbose, ¬ify); |
| 983 |
run_set_attributes (game_, bold, verbose, flag); |
| 984 |
} |
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
sc_bool |
| 994 |
sc_does_game_use_sounds (sc_game game) |
| 995 |
{ |
| 996 |
const sc_gameref_t game_ = game; |
| 997 |
|
| 998 |
if (if_game_error (game_, "sc_does_game_use_sounds")) |
| 999 |
return FALSE; |
| 1000 |
|
| 1001 |
return res_has_sound (game_); |
| 1002 |
} |
| 1003 |
|
| 1004 |
sc_bool |
| 1005 |
sc_does_game_use_graphics (sc_game game) |
| 1006 |
{ |
| 1007 |
const sc_gameref_t game_ = game; |
| 1008 |
|
| 1009 |
if (if_game_error (game_, "sc_does_game_use_graphics")) |
| 1010 |
return FALSE; |
| 1011 |
|
| 1012 |
return res_has_graphics (game_); |
| 1013 |
} |
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
sc_game_hint |
| 1026 |
sc_get_first_game_hint (sc_game game) |
| 1027 |
{ |
| 1028 |
const sc_gameref_t game_ = game; |
| 1029 |
|
| 1030 |
if (if_game_error (game_, "sc_get_first_game_hint")) |
| 1031 |
return NULL; |
| 1032 |
|
| 1033 |
return run_hint_iterate (game_, NULL); |
| 1034 |
} |
| 1035 |
|
| 1036 |
sc_game_hint |
| 1037 |
sc_get_next_game_hint (sc_game game, sc_game_hint hint) |
| 1038 |
{ |
| 1039 |
const sc_gameref_t game_ = game; |
| 1040 |
const sc_hintref_t hint_ = hint; |
| 1041 |
|
| 1042 |
if (if_game_error (game_, "sc_get_next_game_hint")) |
| 1043 |
return NULL; |
| 1044 |
if (!hint_) |
| 1045 |
{ |
| 1046 |
sc_error ("sc_get_next_game_hint: NULL hint\n"); |
| 1047 |
return NULL; |
| 1048 |
} |
| 1049 |
|
| 1050 |
return run_hint_iterate (game_, hint_); |
| 1051 |
} |
| 1052 |
|
| 1053 |
const sc_char * |
| 1054 |
sc_get_game_hint_question (sc_game game, sc_game_hint hint) |
| 1055 |
{ |
| 1056 |
const sc_gameref_t game_ = game; |
| 1057 |
const sc_hintref_t hint_ = hint; |
| 1058 |
|
| 1059 |
if (if_game_error (game_, "sc_get_game_hint_question")) |
| 1060 |
return NULL; |
| 1061 |
if (!hint_) |
| 1062 |
{ |
| 1063 |
sc_error ("sc_get_game_hint_question: NULL hint\n"); |
| 1064 |
return NULL; |
| 1065 |
} |
| 1066 |
|
| 1067 |
return run_get_hint_question (game_, hint_); |
| 1068 |
} |
| 1069 |
|
| 1070 |
const sc_char * |
| 1071 |
sc_get_game_subtle_hint (sc_game game, sc_game_hint hint) |
| 1072 |
{ |
| 1073 |
const sc_gameref_t game_ = game; |
| 1074 |
const sc_hintref_t hint_ = hint; |
| 1075 |
|
| 1076 |
if (if_game_error (game_, "sc_get_game_subtle_hint")) |
| 1077 |
return NULL; |
| 1078 |
if (!hint_) |
| 1079 |
{ |
| 1080 |
sc_error ("sc_get_game_subtle_hint: NULL hint\n"); |
| 1081 |
return NULL; |
| 1082 |
} |
| 1083 |
|
| 1084 |
return run_get_subtle_hint (game_, hint_); |
| 1085 |
} |
| 1086 |
|
| 1087 |
const sc_char * |
| 1088 |
sc_get_game_unsubtle_hint (sc_game game, sc_game_hint hint) |
| 1089 |
{ |
| 1090 |
const sc_gameref_t game_ = game; |
| 1091 |
const sc_hintref_t hint_ = hint; |
| 1092 |
|
| 1093 |
if (if_game_error (game_, "sc_get_game_unsubtle_hint")) |
| 1094 |
return NULL; |
| 1095 |
if (!hint_) |
| 1096 |
{ |
| 1097 |
sc_error ("sc_get_game_unsubtle_hint: NULL hint\n"); |
| 1098 |
return NULL; |
| 1099 |
} |
| 1100 |
|
| 1101 |
return run_get_unsubtle_hint (game_, hint_); |
| 1102 |
} |
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
void |
| 1113 |
sc_set_game_debugger_enabled (sc_game game, sc_bool flag) |
| 1114 |
{ |
| 1115 |
const sc_gameref_t game_ = game; |
| 1116 |
|
| 1117 |
if (if_game_error (game_, "sc_set_game_debugger_enabled")) |
| 1118 |
return; |
| 1119 |
|
| 1120 |
debug_set_enabled (game_, flag); |
| 1121 |
} |
| 1122 |
|
| 1123 |
sc_bool |
| 1124 |
sc_get_game_debugger_enabled (sc_game game) |
| 1125 |
{ |
| 1126 |
const sc_gameref_t game_ = game; |
| 1127 |
|
| 1128 |
if (if_game_error (game_, "sc_get_game_debugger_enabled")) |
| 1129 |
return FALSE; |
| 1130 |
|
| 1131 |
return debug_get_enabled (game_); |
| 1132 |
} |
| 1133 |
|
| 1134 |
sc_bool |
| 1135 |
sc_run_game_debugger_command (sc_game game, const sc_char *debug_command) |
| 1136 |
{ |
| 1137 |
const sc_gameref_t game_ = game; |
| 1138 |
|
| 1139 |
if (if_game_error (game_, "sc_run_game_debugger_command")) |
| 1140 |
return FALSE; |
| 1141 |
|
| 1142 |
return debug_run_command (game_, debug_command); |
| 1143 |
} |
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
sc_bool |
| 1153 |
sc_set_locale (const sc_char *name) |
| 1154 |
{ |
| 1155 |
if (!name) |
| 1156 |
{ |
| 1157 |
sc_error ("sc_set_locale: NULL name\n"); |
| 1158 |
return FALSE; |
| 1159 |
} |
| 1160 |
|
| 1161 |
return loc_set_locale (name); |
| 1162 |
} |
| 1163 |
|
| 1164 |
const sc_char * |
| 1165 |
sc_get_locale (void) |
| 1166 |
{ |
| 1167 |
return loc_get_locale (); |
| 1168 |
} |
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
|
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
void |
| 1179 |
sc_set_portable_random (sc_bool flag) |
| 1180 |
{ |
| 1181 |
if (flag) |
| 1182 |
sc_set_congruential_random (); |
| 1183 |
else |
| 1184 |
sc_set_platform_random (); |
| 1185 |
} |
| 1186 |
|
| 1187 |
void |
| 1188 |
sc_reseed_random_sequence (sc_uint new_seed) |
| 1189 |
{ |
| 1190 |
if (new_seed == 0) |
| 1191 |
{ |
| 1192 |
sc_error ("sc_reseed_random_sequence: new_seed may not be 0\n"); |
| 1193 |
return; |
| 1194 |
} |
| 1195 |
|
| 1196 |
sc_seed_random (new_seed); |
| 1197 |
} |