| 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 <setjmp.h> |
| 28 |
#include <stdio.h> |
| 29 |
#include <stdlib.h> |
| 30 |
#include <string.h> |
| 31 |
|
| 32 |
#include "scare.h" |
| 33 |
#include "scprotos.h" |
| 34 |
#include "scgamest.h" |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
enum { LINE_BUFFER_SIZE = 256 }; |
| 39 |
static const sc_char NUL = '\0'; |
| 40 |
static const sc_char SPECIAL_PATTERN = '#'; |
| 41 |
static const sc_char WILDCARD_PATTERN = '*'; |
| 42 |
static const sc_char *const WHITESPACE = "\t\n\v\f\r "; |
| 43 |
static const sc_char *const SEPARATORS = ".,"; |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
static sc_bool |
| 55 |
run_is_task_function (const sc_char *pattern, sc_gameref_t game) |
| 56 |
{ |
| 57 |
const sc_prop_setref_t bundle = gs_get_bundle (game); |
| 58 |
const sc_var_setref_t vars = gs_get_vars (game); |
| 59 |
sc_vartype_t vt_key[3]; |
| 60 |
sc_int room, object; |
| 61 |
sc_char *argument; |
| 62 |
|
| 63 |
|
| 64 |
argument = sc_malloc (strlen (pattern) + 1); |
| 65 |
if (sscanf (pattern, " # %%object%% = getdynfromroom (%[^)])", argument) == 0) |
| 66 |
{ |
| 67 |
sc_free (argument); |
| 68 |
return FALSE; |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
vt_key[0].string = "Rooms"; |
| 77 |
for (room = 0; room < gs_room_count (game); room++) |
| 78 |
{ |
| 79 |
const sc_char *name; |
| 80 |
|
| 81 |
vt_key[1].integer = room; |
| 82 |
vt_key[2].string = "Short"; |
| 83 |
name = prop_get_string (bundle, "S<-sis", vt_key); |
| 84 |
if (sc_strcasecmp (name, argument) == 0) |
| 85 |
break; |
| 86 |
} |
| 87 |
sc_free (argument); |
| 88 |
if (room == gs_room_count (game)) |
| 89 |
return FALSE; |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
vt_key[0].string = "Objects"; |
| 98 |
for (object = 0; object < gs_object_count (game); object++) |
| 99 |
{ |
| 100 |
sc_bool bstatic; |
| 101 |
|
| 102 |
vt_key[1].integer = object; |
| 103 |
vt_key[2].string = "Static"; |
| 104 |
bstatic = prop_get_boolean (bundle, "B<-sis", vt_key); |
| 105 |
if (!bstatic && obj_directly_in_room (game, object, room)) |
| 106 |
break; |
| 107 |
} |
| 108 |
if (object == gs_object_count (game)) |
| 109 |
return FALSE; |
| 110 |
|
| 111 |
|
| 112 |
gs_clear_object_references (game); |
| 113 |
game->object_references[object] = TRUE; |
| 114 |
var_set_ref_object (vars, object); |
| 115 |
|
| 116 |
return TRUE; |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
typedef struct sc_commands_s |
| 122 |
{ |
| 123 |
const sc_char *const command; |
| 124 |
sc_bool (*const handler) (sc_gameref_t game); |
| 125 |
} sc_commands_t; |
| 126 |
typedef sc_commands_t *sc_commandsref_t; |
| 127 |
|
| 128 |
|
| 129 |
static sc_commands_t MOVE_COMMANDS_4[] = { |
| 130 |
{"{go {to {the}}} [north/n]", lib_cmd_go_north}, |
| 131 |
{"{go {to {the}}} [east/e]", lib_cmd_go_east}, |
| 132 |
{"{go {to {the}}} [south/s]", lib_cmd_go_south}, |
| 133 |
{"{go {to {the}}} [west/w]", lib_cmd_go_west}, |
| 134 |
{"{go {to {the}}} [up/u]", lib_cmd_go_up}, |
| 135 |
{"{go {to {the}}} [down/d]", lib_cmd_go_down}, |
| 136 |
{"{go {to {the}}} [in]", lib_cmd_go_in}, |
| 137 |
{"{go {to {the}}} [out/o]", lib_cmd_go_out}, |
| 138 |
{NULL, NULL} |
| 139 |
}; |
| 140 |
|
| 141 |
|
| 142 |
static sc_commands_t MOVE_COMMANDS_8[] = { |
| 143 |
{"{go {to {the}}} [north/n]", lib_cmd_go_north}, |
| 144 |
{"{go {to {the}}} [east/e]", lib_cmd_go_east}, |
| 145 |
{"{go {to {the}}} [south/s]", lib_cmd_go_south}, |
| 146 |
{"{go {to {the}}} [west/w]", lib_cmd_go_west}, |
| 147 |
{"{go {to {the}}} [up/u]", lib_cmd_go_up}, |
| 148 |
{"{go {to {the}}} [down/d]", lib_cmd_go_down}, |
| 149 |
{"{go {to {the}}} [in]", lib_cmd_go_in}, |
| 150 |
{"{go {to {the}}} [out/o]", lib_cmd_go_out}, |
| 151 |
{"{go {to {the}}} [northeast/north-east/ne]", lib_cmd_go_northeast}, |
| 152 |
{"{go {to {the}}} [southeast/south-east/se]", lib_cmd_go_southeast}, |
| 153 |
{"{go {to {the}}} [northwest/north-west/nw]", lib_cmd_go_northwest}, |
| 154 |
{"{go {to {the}}} [southwest/south-west/sw]", lib_cmd_go_southwest}, |
| 155 |
{NULL, NULL} |
| 156 |
}; |
| 157 |
|
| 158 |
|
| 159 |
static sc_commands_t PRIORITY_COMMANDS[] = { |
| 160 |
|
| 161 |
|
| 162 |
{"[[get/take/remove/extract] [all/everything] from/empty] %object%", |
| 163 |
lib_cmd_take_all_from}, |
| 164 |
{"[[get/take/remove/extract] [all/everything] from/empty] %object%" |
| 165 |
" [[except/but] {for}/apart from] %text%", |
| 166 |
lib_cmd_take_from_except_multiple}, |
| 167 |
{"[get/take/remove/extract] [all/everything]" |
| 168 |
" [[except/but] {for}/apart from] %text% from %object%", |
| 169 |
lib_cmd_take_from_except_multiple}, |
| 170 |
{"[get/take/remove/extract] %text% from %object%", |
| 171 |
lib_cmd_take_from_multiple}, |
| 172 |
{"[get/take] [all/everything] from %character%", lib_cmd_take_all_from_npc}, |
| 173 |
{"[get/take] [all/everything] from %character%" |
| 174 |
" [[except/but] {for}/apart from] %text%", |
| 175 |
lib_cmd_take_from_npc_except_multiple}, |
| 176 |
{"[get/take] [all/everything]" |
| 177 |
" [[except/but] {for}/apart from] %text% from %character%", |
| 178 |
lib_cmd_take_from_npc_except_multiple}, |
| 179 |
{"[get/take] %text% from %character%", lib_cmd_take_from_npc_multiple}, |
| 180 |
{"[[get/take/pick up] [all/everything]/pick [all/everything] up]", |
| 181 |
lib_cmd_take_all}, |
| 182 |
{"[get/take/pick up] [all/everything] [[except/but] {for}/apart from] %text%", |
| 183 |
lib_cmd_take_except_multiple}, |
| 184 |
{"[get/take/pick up] %text%", lib_cmd_take_multiple}, |
| 185 |
{"pick %text% up", lib_cmd_take_multiple}, |
| 186 |
{"[[drop/put down] [all/everything]/put [all/everything] down]", |
| 187 |
lib_cmd_drop_all}, |
| 188 |
{"[drop/put down] [all/everything] [[except/but] {for}/apart from] %text%", |
| 189 |
lib_cmd_drop_except_multiple}, |
| 190 |
{"[drop/put down] %text%", lib_cmd_drop_multiple}, |
| 191 |
{"put %text% down", lib_cmd_drop_multiple}, |
| 192 |
{NULL, NULL} |
| 193 |
}; |
| 194 |
|
| 195 |
|
| 196 |
static sc_commands_t STANDARD_COMMANDS[] = { |
| 197 |
|
| 198 |
|
| 199 |
#ifdef SCARE_NO_ABBREVIATIONS |
| 200 |
{"[inventory/inv]", lib_cmd_inventory}, |
| 201 |
{"[ex/exam/examine/look {at}] {{the} [room/location]}", lib_cmd_look}, |
| 202 |
{"[ex/exam/examine/look {at/in}] %object%", lib_cmd_examine_object}, |
| 203 |
{"[ex/exam/examine/look {at}] %character%", lib_cmd_examine_npc}, |
| 204 |
{"[ex/exam/examine/look {at}] [me/self/myself]", lib_cmd_examine_self}, |
| 205 |
{"[ex/exam/examine/look {at}] all", lib_cmd_examine_all}, |
| 206 |
#else |
| 207 |
{"[inventory/inv/i]", lib_cmd_inventory}, |
| 208 |
{"[x/ex/exam/examine/l/look {at}] {{the} [room/location]}", lib_cmd_look}, |
| 209 |
{"[x/ex/exam/examine/look {at/in}] %object%", lib_cmd_examine_object}, |
| 210 |
{"[x/ex/exam/examine/look {at}] %character%", lib_cmd_examine_npc}, |
| 211 |
{"[x/ex/exam/examine/look {at}] [me/self/myself]", lib_cmd_examine_self}, |
| 212 |
{"[x/ex/exam/examine/look {at}] all", lib_cmd_examine_all}, |
| 213 |
#endif |
| 214 |
|
| 215 |
|
| 216 |
{"[get/take/pick up] %character%", lib_cmd_take_npc}, |
| 217 |
{"pick %character% up", lib_cmd_take_npc}, |
| 218 |
|
| 219 |
|
| 220 |
{"put [all/everything] [in/into/inside {of}] %object%", lib_cmd_put_all_in}, |
| 221 |
{"put [all/everything] [[except/but] {for}/apart from] %text%" |
| 222 |
" [in/into/inside {of}] %object%", lib_cmd_put_in_except_multiple}, |
| 223 |
{"put %text% [in/into/inside {of}] %object%", lib_cmd_put_in_multiple}, |
| 224 |
{"put [all/everything] [on/onto/on top of] %object%", lib_cmd_put_all_on}, |
| 225 |
{"put [all/everything] [[except/but] {for}/apart from] %text%" |
| 226 |
" [on/onto/on top of] %object%", lib_cmd_put_on_except_multiple}, |
| 227 |
{"put %text% [on/onto/on top of] %object%", lib_cmd_put_on_multiple}, |
| 228 |
{"open %object%", lib_cmd_open_object}, |
| 229 |
{"close %object%", lib_cmd_close_object}, |
| 230 |
{"unlock %object% with %text%", lib_cmd_unlock_object_with}, |
| 231 |
{"lock %object% with %text%", lib_cmd_lock_object_with}, |
| 232 |
{"unlock %object%", lib_cmd_unlock_object}, |
| 233 |
{"lock %object%", lib_cmd_lock_object}, |
| 234 |
{"read %object%", lib_cmd_read_object}, |
| 235 |
{"read *", lib_cmd_read_other}, |
| 236 |
{"give %object% to %character%", lib_cmd_give_object_npc}, |
| 237 |
{"sit {down/up} [on/in] %object%", lib_cmd_sit_on_object}, |
| 238 |
{"stand {up/down} [on/in] %object%", lib_cmd_stand_on_object}, |
| 239 |
{"[lie/lay] on %object%", lib_cmd_lie_on_object}, |
| 240 |
{"get {down/up} off %object%", lib_cmd_get_off_object}, |
| 241 |
{"get off", lib_cmd_get_off}, |
| 242 |
{"sit {down/up} {[on/in] {the} [ground/floor]}", lib_cmd_sit_on_floor}, |
| 243 |
{"stand {up/down} {[on/in] {the} [ground/floor]}", lib_cmd_stand_on_floor}, |
| 244 |
{"[lie/lay] {down/up} {[on/in] {the} [ground/floor]}", lib_cmd_lie_on_floor}, |
| 245 |
{"eat %object%", lib_cmd_eat_object}, |
| 246 |
|
| 247 |
|
| 248 |
{"[[wear/put on/don] [all/everything]/put [all/everything] on]", |
| 249 |
lib_cmd_wear_all}, |
| 250 |
{"[wear/put on/don] [all/everything] [[except/but] {for}/apart from] %text%", |
| 251 |
lib_cmd_wear_except_multiple}, |
| 252 |
{"[wear/put on/don] %text%", lib_cmd_wear_multiple}, |
| 253 |
{"put %text% on", lib_cmd_wear_multiple}, |
| 254 |
{"[[remove/take off/doff] [all/everything]/take [all/everything] off/strip]", |
| 255 |
lib_cmd_remove_all}, |
| 256 |
{"[remove/take off/doff] [all/everything]" |
| 257 |
" [[except/but] {for}/apart from] %text%", |
| 258 |
lib_cmd_remove_except_multiple}, |
| 259 |
{"[remove/take off/doff] %text%", lib_cmd_remove_multiple}, |
| 260 |
{"take %text% off", lib_cmd_remove_multiple}, |
| 261 |
|
| 262 |
|
| 263 |
{"ask %character% about %text%", lib_cmd_ask_npc_about}, |
| 264 |
{"[attack/hit/kick/slap/shoot/stab] %character% with %object%", |
| 265 |
lib_cmd_attack_npc_with}, |
| 266 |
{"[attack/shoot] %character%", lib_cmd_attack_npc}, |
| 267 |
|
| 268 |
|
| 269 |
{"[goto/go {to}] %text%", lib_cmd_go_room}, |
| 270 |
{"[goto/go {to}] *", lib_cmd_print_room_exits}, |
| 271 |
{"[exit/exits/directions/where]", lib_cmd_print_room_exits}, |
| 272 |
#ifdef SCARE_NO_ABBREVIATIONS |
| 273 |
{"[wait] %number%", lib_cmd_wait_number}, |
| 274 |
{"[wait]", lib_cmd_wait}, |
| 275 |
#else |
| 276 |
{"[wait/z] %number%", lib_cmd_wait_number}, |
| 277 |
{"[wait/z]", lib_cmd_wait}, |
| 278 |
#endif |
| 279 |
{"save", lib_cmd_save}, |
| 280 |
{"[restore/load]", lib_cmd_restore}, |
| 281 |
{"restart", lib_cmd_restart}, |
| 282 |
#ifdef SCARE_NO_ABBREVIATIONS |
| 283 |
{"[again]", lib_cmd_again}, |
| 284 |
#else |
| 285 |
{"[again/g]", lib_cmd_again}, |
| 286 |
#endif |
| 287 |
{"[redo /!]%number%", lib_cmd_redo_number}, |
| 288 |
{"[redo /!]%text%", lib_cmd_redo_text}, |
| 289 |
{"[redo/!]", lib_cmd_redo_last}, |
| 290 |
#ifdef SCARE_NO_ABBREVIATIONS |
| 291 |
{"[quit]", lib_cmd_quit}, |
| 292 |
#else |
| 293 |
{"[quit/q]", lib_cmd_quit}, |
| 294 |
#endif |
| 295 |
{"turns", lib_cmd_turns}, |
| 296 |
{"score", lib_cmd_score}, |
| 297 |
{"undo", lib_cmd_undo}, |
| 298 |
{"[hist/history] %number%", lib_cmd_history_number}, |
| 299 |
{"[hist/history]", lib_cmd_history}, |
| 300 |
{"[hint/hints]", lib_cmd_hints}, |
| 301 |
{"verbose", lib_cmd_verbose}, |
| 302 |
{"brief", lib_cmd_brief}, |
| 303 |
{"[notify/notification] %text%", lib_cmd_notify_on_off}, |
| 304 |
{"[notify/notification]", lib_cmd_notify}, |
| 305 |
{"time", lib_cmd_time}, |
| 306 |
{"date", lib_cmd_date}, |
| 307 |
{"[help/commands]", lib_cmd_help}, |
| 308 |
{"[gpl/license]", lib_cmd_license}, |
| 309 |
{"[about/info/information/author]", lib_cmd_information}, |
| 310 |
{"[clear/cls/clr]", lib_cmd_clear}, |
| 311 |
{"status{line}", lib_cmd_statusline}, |
| 312 |
{"version", lib_cmd_version}, |
| 313 |
|
| 314 |
{"[locate/where {is/are}/find] %object%", lib_cmd_locate_object}, |
| 315 |
{"[locate/where {is}/find] %character%", lib_cmd_locate_npc}, |
| 316 |
|
| 317 |
{"[count/num]", lib_cmd_count}, |
| 318 |
|
| 319 |
|
| 320 |
{"[get/take/pick up] *", lib_cmd_get_what}, |
| 321 |
{"open *", lib_cmd_open_what}, |
| 322 |
{"close *", lib_cmd_close_other}, |
| 323 |
{"give %object% *", lib_cmd_give_object}, |
| 324 |
{"give *", lib_cmd_give_what}, |
| 325 |
{"lock %text%", lib_cmd_lock_other}, |
| 326 |
{"lock", lib_cmd_lock_what}, |
| 327 |
{"unlock %text%", lib_cmd_unlock_other}, |
| 328 |
{"unlock", lib_cmd_unlock_what}, |
| 329 |
{"sit {down/up} [on/in] *", lib_cmd_sit_other}, |
| 330 |
{"stand {up/down} [on/in] *", lib_cmd_stand_other}, |
| 331 |
{"[lie/lay] {down/up} [on/in] *", lib_cmd_lie_other}, |
| 332 |
{"[remove/take off/doff] *", lib_cmd_remove_what}, |
| 333 |
{"[drop/put down] *", lib_cmd_drop_what}, |
| 334 |
{"[wear/put on/don] *", lib_cmd_wear_what}, |
| 335 |
{"[shit/fuck/bastard/cunt/crap/hell/shag/bollocks/bollox/bugger] *", |
| 336 |
lib_cmd_profanity}, |
| 337 |
{"[x/examine/look {at}] *", lib_cmd_examine_other}, |
| 338 |
{"[locate/where {is/are}/find] *", lib_cmd_locate_other}, |
| 339 |
{"[cp/mv/ln/ls] *", lib_cmd_unix_like}, |
| 340 |
{"dir *", lib_cmd_dos_like}, |
| 341 |
{"ask %character% *", lib_cmd_ask_npc}, |
| 342 |
{"ask %object% *", lib_cmd_ask_object}, |
| 343 |
{"ask *", lib_cmd_ask_other}, |
| 344 |
{"block %object% *", lib_cmd_block_object}, |
| 345 |
{"block %text%", lib_cmd_block_other}, |
| 346 |
{"block", lib_cmd_block_what}, |
| 347 |
{"[break/destroy/smash] %object% *", lib_cmd_break_object}, |
| 348 |
{"[break/destroy/smash] %text%", lib_cmd_break_other}, |
| 349 |
{"break", lib_cmd_break_what}, |
| 350 |
{"destroy", lib_cmd_destroy_what}, |
| 351 |
{"smash", lib_cmd_smash_what}, |
| 352 |
{"buy %object% *", lib_cmd_buy_object}, |
| 353 |
{"buy %text%", lib_cmd_buy_other}, |
| 354 |
{"buy", lib_cmd_buy_what}, |
| 355 |
{"clean %object% *", lib_cmd_clean_object}, |
| 356 |
{"clean %text%", lib_cmd_clean_other}, |
| 357 |
{"clean", lib_cmd_clean_what}, |
| 358 |
{"climb %object% *", lib_cmd_climb_object}, |
| 359 |
{"climb %text%", lib_cmd_climb_other}, |
| 360 |
{"climb", lib_cmd_climb_what}, |
| 361 |
{"cry *", lib_cmd_cry}, |
| 362 |
{"cut %object% *", lib_cmd_cut_object}, |
| 363 |
{"cut %text%", lib_cmd_cut_other}, |
| 364 |
{"cut", lib_cmd_cut_what}, |
| 365 |
{"dance *", lib_cmd_dance}, |
| 366 |
{"drink %object% *", lib_cmd_drink_object}, |
| 367 |
{"drink %text%", lib_cmd_drink_other}, |
| 368 |
{"drink", lib_cmd_drink_what}, |
| 369 |
{"eat *", lib_cmd_eat_other}, |
| 370 |
{"feed *", lib_cmd_feed}, |
| 371 |
{"feel *", lib_cmd_feel}, |
| 372 |
{"fight *", lib_cmd_fight}, |
| 373 |
{"fix %object% *", lib_cmd_fix_object}, |
| 374 |
{"fix %text%", lib_cmd_fix_other}, |
| 375 |
{"fix", lib_cmd_fix_what}, |
| 376 |
{"fly *", lib_cmd_fly}, |
| 377 |
{"hint *", lib_cmd_hint}, |
| 378 |
{"hit %character%", lib_cmd_attack_npc}, |
| 379 |
{"hit %object% *", lib_cmd_hit_object}, |
| 380 |
{"hit %text%", lib_cmd_hit_other}, |
| 381 |
{"hit", lib_cmd_hit_what}, |
| 382 |
{"hum *", lib_cmd_hum}, |
| 383 |
{"jump *", lib_cmd_jump}, |
| 384 |
{"kick %character%", lib_cmd_attack_npc}, |
| 385 |
{"kick %object% *", lib_cmd_kick_object}, |
| 386 |
{"kick %text%", lib_cmd_kick_other}, |
| 387 |
{"kick", lib_cmd_kick_what}, |
| 388 |
{"kiss %character% *", lib_cmd_kiss_npc}, |
| 389 |
{"kiss %object% *", lib_cmd_kiss_object}, |
| 390 |
{"kiss *", lib_cmd_kiss_other}, |
| 391 |
{"kill *", lib_cmd_kill_other}, |
| 392 |
{"lift %object% *", lib_cmd_lift_object}, |
| 393 |
{"lift %text%", lib_cmd_lift_other}, |
| 394 |
{"lift", lib_cmd_lift_what}, |
| 395 |
{"light %object% *", lib_cmd_light_object}, |
| 396 |
{"light %text%", lib_cmd_light_other}, |
| 397 |
{"light", lib_cmd_light_what}, |
| 398 |
{"listen *", lib_cmd_listen}, |
| 399 |
{"mend %object% *", lib_cmd_mend_object}, |
| 400 |
{"mend %text%", lib_cmd_mend_other}, |
| 401 |
{"mend", lib_cmd_mend_what}, |
| 402 |
{"move %object% *", lib_cmd_move_object}, |
| 403 |
{"move %text%", lib_cmd_move_other}, |
| 404 |
{"move", lib_cmd_move_what}, |
| 405 |
{"please *", lib_cmd_please}, |
| 406 |
{"press %object% *", lib_cmd_press_object}, |
| 407 |
{"press %text%", lib_cmd_press_other}, |
| 408 |
{"press", lib_cmd_press_what}, |
| 409 |
{"pull %object% *", lib_cmd_pull_object}, |
| 410 |
{"pull %text%", lib_cmd_pull_other}, |
| 411 |
{"pull", lib_cmd_pull_what}, |
| 412 |
{"punch *", lib_cmd_punch}, |
| 413 |
{"push %object% *", lib_cmd_push_object}, |
| 414 |
{"push %text%", lib_cmd_push_other}, |
| 415 |
{"push", lib_cmd_push_what}, |
| 416 |
{"repair %object% *", lib_cmd_repair_object}, |
| 417 |
{"repair %text%", lib_cmd_repair_other}, |
| 418 |
{"repair", lib_cmd_repair_what}, |
| 419 |
{"rub %object% *", lib_cmd_rub_object}, |
| 420 |
{"rub %text%", lib_cmd_rub_other}, |
| 421 |
{"rub", lib_cmd_rub_what}, |
| 422 |
{"run *", lib_cmd_run}, |
| 423 |
{"say *", lib_cmd_say}, |
| 424 |
{"sell %object% *", lib_cmd_sell_object}, |
| 425 |
{"sell %text%", lib_cmd_sell_other}, |
| 426 |
{"sell", lib_cmd_sell_what}, |
| 427 |
{"shake %object% *", lib_cmd_shake_object}, |
| 428 |
{"shake %text%", lib_cmd_shake_other}, |
| 429 |
{"shake", lib_cmd_shake_what}, |
| 430 |
{"shout *", lib_cmd_shout}, |
| 431 |
{"sing *", lib_cmd_sing}, |
| 432 |
{"sleep *", lib_cmd_sleep}, |
| 433 |
{"smell %object% *", lib_cmd_smell_object}, |
| 434 |
{"smell *", lib_cmd_smell_other}, |
| 435 |
{"stop %object% *", lib_cmd_stop_object}, |
| 436 |
{"stop %text%", lib_cmd_stop_other}, |
| 437 |
{"stop", lib_cmd_stop_what}, |
| 438 |
{"suck %object% *", lib_cmd_suck_object}, |
| 439 |
{"suck %text%", lib_cmd_suck_other}, |
| 440 |
{"suck", lib_cmd_suck_what}, |
| 441 |
{"talk *", lib_cmd_talk}, |
| 442 |
{"thank *", lib_cmd_thank}, |
| 443 |
{"turn %object% *", lib_cmd_turn_object}, |
| 444 |
{"turn %text%", lib_cmd_turn_other}, |
| 445 |
{"turn", lib_cmd_turn_what}, |
| 446 |
{"touch %object% *", lib_cmd_touch_object}, |
| 447 |
{"touch %text%", lib_cmd_touch_other}, |
| 448 |
{"touch", lib_cmd_touch_what}, |
| 449 |
{"unblock %object% *", lib_cmd_unblock_object}, |
| 450 |
{"unblock %text%", lib_cmd_unblock_other}, |
| 451 |
{"unblock", lib_cmd_unblock_what}, |
| 452 |
{"wash %object% *", lib_cmd_wash_object}, |
| 453 |
{"wash %text%", lib_cmd_wash_other}, |
| 454 |
{"wash", lib_cmd_wash_what}, |
| 455 |
{"whistle *", lib_cmd_whistle}, |
| 456 |
{"[why/when/what/can/how] *", lib_cmd_interrogation}, |
| 457 |
{"xyzzy *", lib_cmd_xyzzy}, |
| 458 |
{"campbell", lib_cmd_egotistic}, |
| 459 |
{"[yes/no] *", lib_cmd_yes_or_no}, |
| 460 |
{"* %object% *", lib_cmd_verb_object}, |
| 461 |
{"* %character% *", lib_cmd_verb_npc}, |
| 462 |
|
| 463 |
|
| 464 |
{"{#}debug{ger}", debug_cmd_debugger}, |
| 465 |
|
| 466 |
{NULL, NULL} |
| 467 |
}; |
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
static sc_bool |
| 489 |
run_priority_commands (sc_gameref_t game, const sc_char *string) |
| 490 |
{ |
| 491 |
sc_commandsref_t command; |
| 492 |
|
| 493 |
for (command = PRIORITY_COMMANDS; command->command; command++) |
| 494 |
{ |
| 495 |
if (uip_match (command->command, string, game)) |
| 496 |
{ |
| 497 |
if (command->handler (game)) |
| 498 |
return TRUE; |
| 499 |
} |
| 500 |
} |
| 501 |
|
| 502 |
|
| 503 |
return FALSE; |
| 504 |
} |
| 505 |
|
| 506 |
static sc_bool |
| 507 |
run_standard_commands (sc_gameref_t game, const sc_char *string) |
| 508 |
{ |
| 509 |
const sc_prop_setref_t bundle = gs_get_bundle (game); |
| 510 |
sc_vartype_t vt_key[2]; |
| 511 |
sc_bool eightpointcompass; |
| 512 |
sc_commandsref_t command; |
| 513 |
|
| 514 |
|
| 515 |
vt_key[0].string = "Globals"; |
| 516 |
vt_key[1].string = "EightPointCompass"; |
| 517 |
eightpointcompass = prop_get_boolean (bundle, "B<-ss", vt_key); |
| 518 |
command = eightpointcompass ? MOVE_COMMANDS_8 : MOVE_COMMANDS_4; |
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
for (; command->command; command++) |
| 525 |
{ |
| 526 |
if (uip_match (command->command, string, game)) |
| 527 |
{ |
| 528 |
if (command->handler (game)) |
| 529 |
return TRUE; |
| 530 |
} |
| 531 |
} |
| 532 |
|
| 533 |
for (command = STANDARD_COMMANDS; command->command; command++) |
| 534 |
{ |
| 535 |
if (uip_match (command->command, string, game)) |
| 536 |
{ |
| 537 |
if (command->handler (game)) |
| 538 |
return TRUE; |
| 539 |
} |
| 540 |
} |
| 541 |
|
| 542 |
|
| 543 |
return FALSE; |
| 544 |
} |
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
static void |
| 553 |
run_update_status (sc_gameref_t game) |
| 554 |
{ |
| 555 |
const sc_prop_setref_t bundle = gs_get_bundle (game); |
| 556 |
const sc_var_setref_t vars = gs_get_vars (game); |
| 557 |
sc_vartype_t vt_key[2]; |
| 558 |
const sc_char *name, *status; |
| 559 |
sc_char *filtered; |
| 560 |
sc_bool statusbox; |
| 561 |
|
| 562 |
|
| 563 |
name = lib_get_room_name (game, gs_playerroom (game)); |
| 564 |
filtered = pf_filter (name, vars, bundle); |
| 565 |
pf_strip_tags (filtered); |
| 566 |
|
| 567 |
|
| 568 |
sc_free (game->current_room_name); |
| 569 |
game->current_room_name = filtered; |
| 570 |
|
| 571 |
|
| 572 |
vt_key[0].string = "Globals"; |
| 573 |
vt_key[1].string = "StatusBox"; |
| 574 |
statusbox = prop_get_boolean (bundle, "B<-ss", vt_key); |
| 575 |
if (statusbox) |
| 576 |
{ |
| 577 |
|
| 578 |
vt_key[1].string = "StatusBoxText"; |
| 579 |
status = prop_get_string (bundle, "S<-ss", vt_key); |
| 580 |
filtered = pf_filter (status, vars, bundle); |
| 581 |
pf_strip_tags (filtered); |
| 582 |
} |
| 583 |
else |
| 584 |
|
| 585 |
filtered = NULL; |
| 586 |
|
| 587 |
|
| 588 |
sc_free (game->status_line); |
| 589 |
game->status_line = filtered; |
| 590 |
} |
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
static void |
| 602 |
run_notify_score_change (sc_gameref_t game) |
| 603 |
{ |
| 604 |
const sc_gameref_t undo = game->undo; |
| 605 |
sc_char buffer[32]; |
| 606 |
assert (gs_is_game_valid (undo)); |
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
if (!game->undo_available |
| 613 |
|| !game->notify_score_change || game->has_notified) |
| 614 |
return; |
| 615 |
|
| 616 |
|
| 617 |
if (game->score > undo->score) |
| 618 |
{ |
| 619 |
if_print_string ("(Your score has increased by "); |
| 620 |
sprintf (buffer, "%ld", game->score - undo->score); |
| 621 |
if_print_string (buffer); |
| 622 |
if_print_string (")\n"); |
| 623 |
} |
| 624 |
else if (game->score < undo->score) |
| 625 |
{ |
| 626 |
if_print_string ("(Your score has decreased by "); |
| 627 |
sprintf (buffer, "%ld", undo->score - game->score); |
| 628 |
if_print_string (buffer); |
| 629 |
if_print_string (")\n"); |
| 630 |
} |
| 631 |
game->has_notified = TRUE; |
| 632 |
} |
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
static sc_bool |
| 647 |
run_match_task_common (sc_gameref_t game, |
| 648 |
sc_int task, const sc_char *string, sc_bool forwards, |
| 649 |
sc_bool is_library, sc_bool is_normal) |
| 650 |
{ |
| 651 |
const sc_prop_setref_t bundle = gs_get_bundle (game); |
| 652 |
sc_vartype_t vt_key[4]; |
| 653 |
sc_int command_count, command; |
| 654 |
sc_bool is_matched; |
| 655 |
|
| 656 |
|
| 657 |
vt_key[0].string = "Tasks"; |
| 658 |
vt_key[1].integer = task; |
| 659 |
vt_key[2].string = forwards ? "Command" : "ReverseCommand"; |
| 660 |
command_count = prop_get_child_count (bundle, "I<-sis", vt_key); |
| 661 |
|
| 662 |
|
| 663 |
is_matched = FALSE; |
| 664 |
for (command = 0; command < command_count; command++) |
| 665 |
{ |
| 666 |
const sc_char *pattern; |
| 667 |
sc_int first; |
| 668 |
|
| 669 |
|
| 670 |
vt_key[3].integer = command; |
| 671 |
pattern = prop_get_string (bundle, "S<-sisi", vt_key); |
| 672 |
first = strspn (pattern, WHITESPACE); |
| 673 |
|
| 674 |
|
| 675 |
if (is_normal) |
| 676 |
{ |
| 677 |
if (pattern[first] != SPECIAL_PATTERN) |
| 678 |
{ |
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
if (is_library && pattern[first] == WILDCARD_PATTERN) |
| 684 |
is_matched = FALSE; |
| 685 |
else |
| 686 |
is_matched = uip_match (pattern, string, game); |
| 687 |
} |
| 688 |
} |
| 689 |
else |
| 690 |
{ |
| 691 |
if (pattern[first] == SPECIAL_PATTERN) |
| 692 |
is_matched = run_is_task_function (pattern, game); |
| 693 |
} |
| 694 |
|
| 695 |
|
| 696 |
if (is_matched) |
| 697 |
break; |
| 698 |
} |
| 699 |
|
| 700 |
|
| 701 |
return is_matched; |
| 702 |
} |
| 703 |
|
| 704 |
static sc_bool |
| 705 |
run_match_task_commands (sc_gameref_t game, |
| 706 |
sc_int task, const sc_char *string, |
| 707 |
sc_bool forwards, sc_bool is_library) |
| 708 |
{ |
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
return run_match_task_common (game, task, string, forwards, is_library, TRUE); |
| 714 |
} |
| 715 |
|
| 716 |
static sc_bool |
| 717 |
run_match_task_functions (sc_gameref_t game, |
| 718 |
sc_int task, const sc_char *string, sc_bool forwards) |
| 719 |
{ |
| 720 |
|
| 721 |
return run_match_task_common (game, task, string, forwards, FALSE, FALSE); |
| 722 |
} |
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
static sc_bool |
| 738 |
run_task_is_unrestricted (sc_gameref_t game, sc_int task) |
| 739 |
{ |
| 740 |
sc_bool restrictions_passed; |
| 741 |
const sc_char *fail_message; |
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
if (!restr_eval_task_restrictions (game, task, |
| 748 |
&restrictions_passed, &fail_message)) |
| 749 |
{ |
| 750 |
sc_error ("run_task_is_unrestricted: restrictions error, %ld\n", task); |
| 751 |
return FALSE; |
| 752 |
} |
| 753 |
|
| 754 |
|
| 755 |
return restrictions_passed; |
| 756 |
} |
| 757 |
|
| 758 |
static sc_bool |
| 759 |
run_task_is_loudly_restricted (sc_gameref_t game, sc_int task) |
| 760 |
{ |
| 761 |
sc_bool restrictions_passed; |
| 762 |
const sc_char *fail_message; |
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
if (!restr_eval_task_restrictions (game, task, |
| 769 |
&restrictions_passed, &fail_message)) |
| 770 |
{ |
| 771 |
sc_error ("run_task_is_loudly_restricted:" |
| 772 |
" restrictions error, %ld\n", task); |
| 773 |
return TRUE; |
| 774 |
} |
| 775 |
|
| 776 |
|
| 777 |
return !restrictions_passed && (fail_message != NULL); |
| 778 |
} |
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
static sc_bool |
| 817 |
run_game_commands_common (sc_gameref_t game, const sc_char *string, |
| 818 |
sc_bool include_restrictions, sc_bool is_library) |
| 819 |
{ |
| 820 |
sc_bool is_matched = FALSE, is_handled = FALSE; |
| 821 |
sc_bool *is_matching; |
| 822 |
sc_int task_count, task, direction; |
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
task_count = gs_task_count (game); |
| 829 |
if (include_restrictions) |
| 830 |
{ |
| 831 |
is_matching = sc_malloc (task_count * sizeof (*is_matching)); |
| 832 |
memset (is_matching, FALSE, task_count * sizeof (*is_matching)); |
| 833 |
} |
| 834 |
else |
| 835 |
is_matching = NULL; |
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
for (task = 0; task < task_count; task++) |
| 843 |
{ |
| 844 |
if (!task_can_run_task (game, task)) |
| 845 |
continue; |
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
for (direction = 0; direction < 2; direction++) |
| 854 |
{ |
| 855 |
const sc_bool is_forwards = !direction; |
| 856 |
|
| 857 |
if (task_can_run_task_directional (game, task, is_forwards) |
| 858 |
&& run_match_task_commands (game, task, string, |
| 859 |
is_forwards, is_library)) |
| 860 |
{ |
| 861 |
if (run_task_is_unrestricted (game, task)) |
| 862 |
{ |
| 863 |
if (task_run_task (game, task, is_forwards)) |
| 864 |
is_handled = TRUE; |
| 865 |
is_matched = TRUE; |
| 866 |
break; |
| 867 |
} |
| 868 |
|
| 869 |
if (is_matching) |
| 870 |
is_matching[task] = TRUE; |
| 871 |
} |
| 872 |
} |
| 873 |
if (is_matched) |
| 874 |
break; |
| 875 |
} |
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
if (!is_handled && !is_matched && include_restrictions) |
| 884 |
{ |
| 885 |
for (task = 0; task < task_count; task++) |
| 886 |
{ |
| 887 |
if (!is_matching[task] || !task_can_run_task (game, task)) |
| 888 |
continue; |
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
for (direction = 0; direction < 2; direction++) |
| 897 |
{ |
| 898 |
const sc_bool is_forwards = !direction; |
| 899 |
|
| 900 |
if (task_can_run_task_directional (game, task, is_forwards) |
| 901 |
&& run_match_task_commands (game, task, string, |
| 902 |
is_forwards, is_library)) |
| 903 |
{ |
| 904 |
if (run_task_is_loudly_restricted (game, task)) |
| 905 |
{ |
| 906 |
if (task_run_task (game, task, is_forwards)) |
| 907 |
{ |
| 908 |
is_handled = TRUE; |
| 909 |
break; |
| 910 |
} |
| 911 |
} |
| 912 |
} |
| 913 |
} |
| 914 |
if (is_handled) |
| 915 |
break; |
| 916 |
} |
| 917 |
} |
| 918 |
|
| 919 |
|
| 920 |
sc_free (is_matching); |
| 921 |
return is_handled; |
| 922 |
} |
| 923 |
|
| 924 |
static sc_bool |
| 925 |
run_game_commands_in_parser_context (sc_gameref_t game, const sc_char *string, |
| 926 |
sc_bool include_restrictions) |
| 927 |
{ |
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
return run_game_commands_common (game, string, include_restrictions, FALSE); |
| 934 |
} |
| 935 |
|
| 936 |
static sc_bool |
| 937 |
run_game_commands_in_library_context (sc_gameref_t game, const sc_char *string) |
| 938 |
{ |
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
return run_game_commands_common (game, string, TRUE, TRUE); |
| 945 |
} |
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
static void |
| 956 |
run_game_functions (sc_gameref_t game, const sc_char *string) |
| 957 |
{ |
| 958 |
sc_int task_count, task, direction; |
| 959 |
|
| 960 |
|
| 961 |
task_count = gs_task_count (game); |
| 962 |
for (task = 0; task < task_count; task++) |
| 963 |
{ |
| 964 |
if (!task_can_run_task (game, task)) |
| 965 |
continue; |
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
for (direction = 0; direction < 2; direction++) |
| 972 |
{ |
| 973 |
const sc_bool is_forwards = !direction; |
| 974 |
|
| 975 |
if (task_can_run_task_directional (game, task, is_forwards) |
| 976 |
&& run_match_task_functions (game, task, string, is_forwards)) |
| 977 |
{ |
| 978 |
if (run_task_is_unrestricted (game, task)) |
| 979 |
task_run_task (game, task, is_forwards); |
| 980 |
} |
| 981 |
} |
| 982 |
} |
| 983 |
} |
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
static sc_bool |
| 995 |
run_all_commands (sc_gameref_t game, const sc_char *string) |
| 996 |
{ |
| 997 |
const sc_prop_setref_t bundle = gs_get_bundle (game); |
| 998 |
sc_bool status; |
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
status = run_game_commands_in_parser_context (game, string, FALSE); |
| 1031 |
if (!status) |
| 1032 |
status = run_priority_commands (game, string); |
| 1033 |
if (!status) |
| 1034 |
status = run_game_commands_in_parser_context (game, string, TRUE); |
| 1035 |
if (!status) |
| 1036 |
status = run_standard_commands (game, string); |
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
if (status && !game->is_admin) |
| 1044 |
{ |
| 1045 |
sc_vartype_t vt_key; |
| 1046 |
sc_int version; |
| 1047 |
|
| 1048 |
|
| 1049 |
vt_key.string = "Version"; |
| 1050 |
version = prop_get_integer (bundle, "I<-s", &vt_key); |
| 1051 |
if (version == TAF_VERSION_400) |
| 1052 |
run_game_functions (game, string); |
| 1053 |
} |
| 1054 |
|
| 1055 |
return status; |
| 1056 |
} |
| 1057 |
|
| 1058 |
sc_bool |
| 1059 |
run_game_task_commands (sc_gameref_t game, const sc_char *string) |
| 1060 |
{ |
| 1061 |
return run_game_commands_in_library_context (game, string); |
| 1062 |
} |
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
static sc_bool |
| 1083 |
run_player_input (sc_gameref_t game) |
| 1084 |
{ |
| 1085 |
static sc_char line_buffer[LINE_BUFFER_SIZE]; |
| 1086 |
static sc_char prior_element[LINE_BUFFER_SIZE]; |
| 1087 |
static sc_char line_element[LINE_BUFFER_SIZE]; |
| 1088 |
|
| 1089 |
const sc_filterref_t filter = gs_get_filter (game); |
| 1090 |
const sc_prop_setref_t bundle = gs_get_bundle (game); |
| 1091 |
const sc_var_setref_t vars = gs_get_vars (game); |
| 1092 |
const sc_memo_setref_t memento = gs_get_memento (game); |
| 1093 |
sc_bool is_rerunning, was_undo_available, status; |
| 1094 |
sc_char *filtered, *replaced; |
| 1095 |
const sc_char *command; |
| 1096 |
|
| 1097 |
|
| 1098 |
if (!game->is_running) |
| 1099 |
{ |
| 1100 |
memset (line_buffer, NUL, sizeof (line_buffer)); |
| 1101 |
memset (prior_element, NUL, sizeof (prior_element)); |
| 1102 |
memset (line_element, NUL, sizeof (line_element)); |
| 1103 |
return TRUE; |
| 1104 |
} |
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
is_rerunning = game->do_again; |
| 1111 |
was_undo_available = game->undo_available; |
| 1112 |
|
| 1113 |
|
| 1114 |
if (game->do_again) |
| 1115 |
{ |
| 1116 |
game->do_again = FALSE; |
| 1117 |
|
| 1118 |
|
| 1119 |
if (prior_element[0] == NUL) |
| 1120 |
{ |
| 1121 |
pf_buffer_string (filter, "You can hardly repeat that.\n"); |
| 1122 |
return FALSE; |
| 1123 |
} |
| 1124 |
|
| 1125 |
|
| 1126 |
strcpy (line_element, prior_element); |
| 1127 |
} |
| 1128 |
else |
| 1129 |
{ |
| 1130 |
sc_int length, extent; |
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
if (line_buffer[0] == NUL) |
| 1137 |
if_read_line (line_buffer, sizeof (line_buffer)); |
| 1138 |
else |
| 1139 |
if_print_character ('\n'); |
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
length = (line_buffer[0] == NUL) ? 0 : 1; |
| 1150 |
while (line_buffer[length] != NUL |
| 1151 |
&& strchr (SEPARATORS, line_buffer[length]) == NULL) |
| 1152 |
length++; |
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
|
| 1158 |
|
| 1159 |
|
| 1160 |
memcpy (line_element, line_buffer, length); |
| 1161 |
line_element[length] = NUL; |
| 1162 |
|
| 1163 |
extent = length; |
| 1164 |
extent += (line_buffer[length] == NUL |
| 1165 |
|| strchr (SEPARATORS, line_buffer[length]) == NULL) ? 0 : 1; |
| 1166 |
extent += strspn (line_buffer + extent, WHITESPACE); |
| 1167 |
memmove (line_buffer, |
| 1168 |
line_buffer + extent, strlen (line_buffer) - extent + 1); |
| 1169 |
} |
| 1170 |
|
| 1171 |
|
| 1172 |
gs_copy (game->temporary, game); |
| 1173 |
|
| 1174 |
|
| 1175 |
filtered = pf_filter_input (line_element, bundle); |
| 1176 |
replaced = uip_replace_pronouns (game, filtered ? filtered : line_element); |
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
|
| 1181 |
|
| 1182 |
command = replaced ? sc_normalize_string (replaced) |
| 1183 |
: (filtered ? sc_normalize_string (filtered) : line_element); |
| 1184 |
if (command != line_element) |
| 1185 |
{ |
| 1186 |
if_print_tag (SC_TAG_ITALICS, ""); |
| 1187 |
if_print_character ('['); |
| 1188 |
if_print_string (command); |
| 1189 |
if_print_character (']'); |
| 1190 |
if_print_tag (SC_TAG_ENDITALICS, ""); |
| 1191 |
if_print_character ('\n'); |
| 1192 |
} |
| 1193 |
|
| 1194 |
|
| 1195 |
status = run_all_commands (game, command); |
| 1196 |
if (!status) |
| 1197 |
{ |
| 1198 |
|
| 1199 |
if (!sc_strempty (command)) |
| 1200 |
{ |
| 1201 |
sc_vartype_t vt_key[2]; |
| 1202 |
sc_char *escaped; |
| 1203 |
const sc_char *message; |
| 1204 |
|
| 1205 |
|
| 1206 |
escaped = pf_escape (sc_normalize_string (line_element)); |
| 1207 |
var_set_ref_text (vars, escaped); |
| 1208 |
sc_free (escaped); |
| 1209 |
vt_key[0].string = "Globals"; |
| 1210 |
vt_key[1].string = "DontUnderstand"; |
| 1211 |
message = prop_get_string (bundle, "S<-ss", vt_key); |
| 1212 |
pf_buffer_string (filter, message); |
| 1213 |
pf_buffer_character (filter, '\n'); |
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
line_buffer[0] = NUL; |
| 1220 |
sc_free (filtered); |
| 1221 |
sc_free (replaced); |
| 1222 |
return status; |
| 1223 |
} |
| 1224 |
} |
| 1225 |
else |
| 1226 |
{ |
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
|
| 1231 |
|
| 1232 |
if (!game->is_admin) |
| 1233 |
{ |
| 1234 |
if (game->undo_available) |
| 1235 |
memo_save_game (memento, game->undo); |
| 1236 |
|
| 1237 |
gs_copy (game->undo, game->temporary); |
| 1238 |
game->undo_available = TRUE; |
| 1239 |
|
| 1240 |
uip_assign_pronouns (game, command); |
| 1241 |
} |
| 1242 |
} |
| 1243 |
sc_free (filtered); |
| 1244 |
sc_free (replaced); |
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
if (!sc_strempty (line_element) && !game->do_again) |
| 1252 |
{ |
| 1253 |
|
| 1254 |
|
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
if (game->redo_sequence == 0) |
| 1260 |
{ |
| 1261 |
sc_int timestamp; |
| 1262 |
|
| 1263 |
timestamp = var_get_elapsed_seconds (vars); |
| 1264 |
memo_save_command (memento, line_element, timestamp, game->turns); |
| 1265 |
} |
| 1266 |
else |
| 1267 |
game->redo_sequence = 0; |
| 1268 |
} |
| 1269 |
|
| 1270 |
|
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
if (game->do_restart || game->do_restore |
| 1276 |
|| (was_undo_available && !game->undo_available)) |
| 1277 |
{ |
| 1278 |
line_buffer[0] = NUL; |
| 1279 |
return status; |
| 1280 |
} |
| 1281 |
|
| 1282 |
|
| 1283 |
if (!sc_strempty (line_element)) |
| 1284 |
{ |
| 1285 |
|
| 1286 |
|
| 1287 |
|
| 1288 |
|
| 1289 |
if (!game->do_again && !is_rerunning) |
| 1290 |
strcpy (prior_element, line_element); |
| 1291 |
|
| 1292 |
|
| 1293 |
|
| 1294 |
|
| 1295 |
|
| 1296 |
|
| 1297 |
|
| 1298 |
if (game->do_again && game->redo_sequence != 0) |
| 1299 |
{ |
| 1300 |
const sc_char *redo_command; |
| 1301 |
|
| 1302 |
redo_command = memo_find_command (memento, game->redo_sequence); |
| 1303 |
if (redo_command) |
| 1304 |
strcpy (prior_element, redo_command); |
| 1305 |
else |
| 1306 |
{ |
| 1307 |
sc_error ("run_player_input: invalid redo sequence request\n"); |
| 1308 |
game->do_again = FALSE; |
| 1309 |
} |
| 1310 |
game->redo_sequence = 0; |
| 1311 |
} |
| 1312 |
} |
| 1313 |
|
| 1314 |
return status; |
| 1315 |
} |
| 1316 |
|
| 1317 |
|
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
static void |
| 1324 |
run_main_loop (sc_gameref_t game) |
| 1325 |
{ |
| 1326 |
const sc_filterref_t filter = gs_get_filter (game); |
| 1327 |
const sc_var_setref_t vars = gs_get_vars (game); |
| 1328 |
const sc_prop_setref_t bundle = gs_get_bundle (game); |
| 1329 |
|
| 1330 |
|
| 1331 |
|
| 1332 |
|
| 1333 |
|
| 1334 |
|
| 1335 |
if (!gs_room_seen (game, gs_playerroom (game))) |
| 1336 |
{ |
| 1337 |
sc_vartype_t vt_key[2]; |
| 1338 |
const sc_char *gamename, *startuptext; |
| 1339 |
sc_bool disp_first_room, battle_system; |
| 1340 |
|
| 1341 |
|
| 1342 |
vt_key[0].string = "Globals"; |
| 1343 |
vt_key[1].string = "BattleSystem"; |
| 1344 |
battle_system = prop_get_boolean (bundle, "B<-ss", vt_key); |
| 1345 |
if (battle_system && !debug_get_enabled (game)) |
| 1346 |
{ |
| 1347 |
if_print_tag (SC_TAG_CLS, ""); |
| 1348 |
lib_warn_battle_system (); |
| 1349 |
} |
| 1350 |
|
| 1351 |
|
| 1352 |
pf_buffer_tag (filter, SC_TAG_CLS); |
| 1353 |
|
| 1354 |
|
| 1355 |
vt_key[0].string = "Globals"; |
| 1356 |
vt_key[1].string = "GameName"; |
| 1357 |
gamename = prop_get_string (bundle, "S<-ss", vt_key); |
| 1358 |
pf_buffer_string (filter, gamename); |
| 1359 |
pf_buffer_character (filter, '\n'); |
| 1360 |
|
| 1361 |
|
| 1362 |
vt_key[0].string = "Header"; |
| 1363 |
vt_key[1].string = "StartupText"; |
| 1364 |
startuptext = prop_get_string (bundle, "S<-ss", vt_key); |
| 1365 |
pf_buffer_string (filter, startuptext); |
| 1366 |
pf_buffer_character (filter, '\n'); |
| 1367 |
|
| 1368 |
|
| 1369 |
vt_key[0].string = "Globals"; |
| 1370 |
vt_key[1].string = "DispFirstRoom"; |
| 1371 |
disp_first_room = prop_get_boolean (bundle, "B<-ss", vt_key); |
| 1372 |
if (disp_first_room) |
| 1373 |
lib_cmd_look (game); |
| 1374 |
|
| 1375 |
|
| 1376 |
vt_key[0].string = "Globals"; |
| 1377 |
vt_key[1].string = "IntroRes"; |
| 1378 |
res_handle_resource (game, "ss", vt_key); |
| 1379 |
|
| 1380 |
|
| 1381 |
npc_setup_initial (game); |
| 1382 |
obj_setup_initial (game); |
| 1383 |
|
| 1384 |
|
| 1385 |
evt_tick_events (game); |
| 1386 |
npc_tick_npcs (game); |
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
debug_game_started (game); |
| 1395 |
|
| 1396 |
|
| 1397 |
gs_set_room_seen (game, gs_playerroom (game), TRUE); |
| 1398 |
} |
| 1399 |
else |
| 1400 |
{ |
| 1401 |
|
| 1402 |
debug_game_started (game); |
| 1403 |
} |
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
|
| 1408 |
|
| 1409 |
while (game->is_running) |
| 1410 |
{ |
| 1411 |
sc_bool status; |
| 1412 |
|
| 1413 |
|
| 1414 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
|
| 1418 |
|
| 1419 |
res_sync_resources (game); |
| 1420 |
run_notify_score_change (game); |
| 1421 |
|
| 1422 |
|
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 1426 |
pf_flush (filter, vars, bundle); |
| 1427 |
game->is_admin = FALSE; |
| 1428 |
|
| 1429 |
|
| 1430 |
if (game->waitcounter == 0) |
| 1431 |
{ |
| 1432 |
|
| 1433 |
run_update_status (game); |
| 1434 |
status = run_player_input (game); |
| 1435 |
|
| 1436 |
|
| 1437 |
|
| 1438 |
|
| 1439 |
|
| 1440 |
if (game->waitcounter > 0) |
| 1441 |
game->waitcounter--; |
| 1442 |
} |
| 1443 |
else |
| 1444 |
{ |
| 1445 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
|
| 1449 |
game->waitcounter--; |
| 1450 |
status = TRUE; |
| 1451 |
} |
| 1452 |
|
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
|
| 1457 |
|
| 1458 |
if (status && !game->is_admin) |
| 1459 |
{ |
| 1460 |
|
| 1461 |
game->turns++; |
| 1462 |
game->has_notified = FALSE; |
| 1463 |
|
| 1464 |
if (game->is_running) |
| 1465 |
{ |
| 1466 |
|
| 1467 |
evt_tick_events (game); |
| 1468 |
npc_tick_npcs (game); |
| 1469 |
|
| 1470 |
|
| 1471 |
npc_turn_update (game); |
| 1472 |
obj_turn_update (game); |
| 1473 |
|
| 1474 |
|
| 1475 |
gs_set_room_seen (game, gs_playerroom (game), TRUE); |
| 1476 |
|
| 1477 |
|
| 1478 |
debug_turn_update (game); |
| 1479 |
} |
| 1480 |
} |
| 1481 |
} |
| 1482 |
|
| 1483 |
|
| 1484 |
|
| 1485 |
|
| 1486 |
|
| 1487 |
|
| 1488 |
run_update_status (game); |
| 1489 |
debug_game_ended (game); |
| 1490 |
|
| 1491 |
|
| 1492 |
|
| 1493 |
|
| 1494 |
|
| 1495 |
res_sync_resources (game); |
| 1496 |
run_notify_score_change (game); |
| 1497 |
pf_flush (filter, vars, bundle); |
| 1498 |
|
| 1499 |
|
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
assert (!game->is_running); |
| 1504 |
run_player_input (game); |
| 1505 |
} |
| 1506 |
|
| 1507 |
|
| 1508 |
|
| 1509 |
|
| 1510 |
|
| 1511 |
|
| 1512 |
|
| 1513 |
sc_gameref_t |
| 1514 |
run_create (sc_read_callbackref_t callback, void *opaque) |
| 1515 |
{ |
| 1516 |
sc_tafref_t taf; |
| 1517 |
sc_prop_setref_t bundle; |
| 1518 |
sc_var_setref_t vars, temporary_vars, undo_vars; |
| 1519 |
sc_filterref_t filter; |
| 1520 |
sc_gameref_t game, temporary_game, undo_game; |
| 1521 |
assert (callback); |
| 1522 |
|
| 1523 |
|
| 1524 |
taf = taf_create (callback, opaque); |
| 1525 |
if (!taf) |
| 1526 |
return NULL; |
| 1527 |
else if (if_get_trace_flag (SC_DUMP_TAF)) |
| 1528 |
taf_debug_dump (taf); |
| 1529 |
|
| 1530 |
|
| 1531 |
bundle = prop_create (taf); |
| 1532 |
if (!bundle) |
| 1533 |
{ |
| 1534 |
sc_error ("run_create: error parsing game data\n"); |
| 1535 |
taf_destroy (taf); |
| 1536 |
return NULL; |
| 1537 |
} |
| 1538 |
else if (if_get_trace_flag (SC_DUMP_PROPERTIES)) |
| 1539 |
prop_debug_dump (bundle); |
| 1540 |
|
| 1541 |
|
| 1542 |
loc_detect_game_locale (bundle); |
| 1543 |
if (if_get_trace_flag (SC_DUMP_LOCALE_TABLES)) |
| 1544 |
loc_debug_dump (); |
| 1545 |
|
| 1546 |
|
| 1547 |
vars = var_create (bundle); |
| 1548 |
if (if_get_trace_flag (SC_DUMP_VARIABLES)) |
| 1549 |
var_debug_dump (vars); |
| 1550 |
|
| 1551 |
|
| 1552 |
filter = pf_create (); |
| 1553 |
|
| 1554 |
|
| 1555 |
|
| 1556 |
|
| 1557 |
|
| 1558 |
game = gs_create (vars, bundle, filter); |
| 1559 |
var_register_game (vars, game); |
| 1560 |
|
| 1561 |
temporary_vars = var_create (bundle); |
| 1562 |
temporary_game = gs_create (temporary_vars, bundle, filter); |
| 1563 |
var_register_game (temporary_vars, temporary_game); |
| 1564 |
|
| 1565 |
undo_vars = var_create (bundle); |
| 1566 |
undo_game = gs_create (undo_vars, bundle, filter); |
| 1567 |
var_register_game (undo_vars, undo_game); |
| 1568 |
|
| 1569 |
|
| 1570 |
game->temporary = temporary_game; |
| 1571 |
game->undo = undo_game; |
| 1572 |
game->memento = memo_create (); |
| 1573 |
return game; |
| 1574 |
} |
| 1575 |
|
| 1576 |
|
| 1577 |
|
| 1578 |
|
| 1579 |
|
| 1580 |
|
| 1581 |
|
| 1582 |
static void |
| 1583 |
run_restart_handler (sc_gameref_t game) |
| 1584 |
{ |
| 1585 |
const sc_filterref_t filter = gs_get_filter (game); |
| 1586 |
const sc_prop_setref_t bundle = gs_get_bundle (game); |
| 1587 |
sc_gameref_t new_game; |
| 1588 |
sc_var_setref_t new_vars; |
| 1589 |
|
| 1590 |
|
| 1591 |
|
| 1592 |
|
| 1593 |
|
| 1594 |
|
| 1595 |
new_vars = var_create (bundle); |
| 1596 |
new_game = gs_create (new_vars, bundle, filter); |
| 1597 |
var_register_game (new_vars, new_game); |
| 1598 |
|
| 1599 |
|
| 1600 |
|
| 1601 |
|
| 1602 |
new_game->temporary = game->temporary; |
| 1603 |
new_game->undo = game->undo; |
| 1604 |
gs_copy (game, new_game); |
| 1605 |
|
| 1606 |
|
| 1607 |
sc_free (game->current_room_name); |
| 1608 |
game->current_room_name = NULL; |
| 1609 |
sc_free (game->status_line); |
| 1610 |
game->status_line = NULL; |
| 1611 |
|
| 1612 |
|
| 1613 |
|
| 1614 |
|
| 1615 |
|
| 1616 |
gs_destroy (new_game); |
| 1617 |
var_destroy (new_vars); |
| 1618 |
|
| 1619 |
|
| 1620 |
res_cancel_resources (game); |
| 1621 |
} |
| 1622 |
|
| 1623 |
|
| 1624 |
|
| 1625 |
|
| 1626 |
|
| 1627 |
|
| 1628 |
|
| 1629 |
static void |
| 1630 |
run_restore_handler (sc_gameref_t game) |
| 1631 |
{ |
| 1632 |
|
| 1633 |
game->undo_available = FALSE; |
| 1634 |
|
| 1635 |
|
| 1636 |
|
| 1637 |
|
| 1638 |
|
| 1639 |
|
| 1640 |
|
| 1641 |
|
| 1642 |
|
| 1643 |
game->stop_sound = TRUE; |
| 1644 |
} |
| 1645 |
|
| 1646 |
|
| 1647 |
|
| 1648 |
|
| 1649 |
|
| 1650 |
|
| 1651 |
|
| 1652 |
static void |
| 1653 |
run_quit_handler (sc_gameref_t game) |
| 1654 |
{ |
| 1655 |
const sc_filterref_t filter = gs_get_filter (game); |
| 1656 |
const sc_var_setref_t vars = gs_get_vars (game); |
| 1657 |
const sc_prop_setref_t bundle = gs_get_bundle (game); |
| 1658 |
|
| 1659 |
|
| 1660 |
run_notify_score_change (game); |
| 1661 |
pf_flush (filter, vars, bundle); |
| 1662 |
|
| 1663 |
|
| 1664 |
res_cancel_resources (game); |
| 1665 |
|
| 1666 |
|
| 1667 |
|
| 1668 |
|
| 1669 |
|
| 1670 |
assert (!game->is_running); |
| 1671 |
run_player_input (game); |
| 1672 |
} |
| 1673 |
|
| 1674 |
|
| 1675 |
|
| 1676 |
|
| 1677 |
|
| 1678 |
|
| 1679 |
|
| 1680 |
void |
| 1681 |
run_interpret (sc_gameref_t game) |
| 1682 |
{ |
| 1683 |
assert (gs_is_game_valid (game)); |
| 1684 |
|
| 1685 |
|
| 1686 |
if (game->is_running) |
| 1687 |
{ |
| 1688 |
sc_error ("run_interpret: game is already running\n"); |
| 1689 |
return; |
| 1690 |
} |
| 1691 |
if (game->has_completed) |
| 1692 |
{ |
| 1693 |
sc_error ("run_interpret: game has already completed\n"); |
| 1694 |
return; |
| 1695 |
} |
| 1696 |
|
| 1697 |
|
| 1698 |
if (gs_room_count (game) == 0) |
| 1699 |
{ |
| 1700 |
sc_error ("run_interpret: game contains no rooms\n"); |
| 1701 |
return; |
| 1702 |
} |
| 1703 |
|
| 1704 |
|
| 1705 |
game->is_running = TRUE; |
| 1706 |
do |
| 1707 |
{ |
| 1708 |
|
| 1709 |
if (setjmp (game->quitter) == 0) |
| 1710 |
run_main_loop (game); |
| 1711 |
|
| 1712 |
|
| 1713 |
|
| 1714 |
|
| 1715 |
|
| 1716 |
|
| 1717 |
if (game->do_restart) |
| 1718 |
{ |
| 1719 |
game->do_restart = FALSE; |
| 1720 |
run_restart_handler (game); |
| 1721 |
game->is_running = TRUE; |
| 1722 |
} |
| 1723 |
|
| 1724 |
if (game->do_restore) |
| 1725 |
{ |
| 1726 |
game->do_restore = FALSE; |
| 1727 |
run_restore_handler (game); |
| 1728 |
game->is_running = TRUE; |
| 1729 |
} |
| 1730 |
} |
| 1731 |
while (game->is_running); |
| 1732 |
|
| 1733 |
|
| 1734 |
run_quit_handler (game); |
| 1735 |
} |
| 1736 |
|
| 1737 |
|
| 1738 |
|
| 1739 |
|
| 1740 |
|
| 1741 |
|
| 1742 |
|
| 1743 |
void |
| 1744 |
run_destroy (sc_gameref_t game) |
| 1745 |
{ |
| 1746 |
assert (gs_is_game_valid (game)); |
| 1747 |
|
| 1748 |
|
| 1749 |
if (game->is_running) |
| 1750 |
{ |
| 1751 |
sc_error ("run_destroy: game is running, stop it first\n"); |
| 1752 |
return; |
| 1753 |
} |
| 1754 |
|
| 1755 |
|
| 1756 |
|
| 1757 |
|
| 1758 |
|
| 1759 |
debug_set_enabled (game, FALSE); |
| 1760 |
assert (!debug_get_enabled (game->temporary)); |
| 1761 |
assert (!debug_get_enabled (game->undo)); |
| 1762 |
|
| 1763 |
|
| 1764 |
|
| 1765 |
|
| 1766 |
|
| 1767 |
|
| 1768 |
|
| 1769 |
|
| 1770 |
assert (gs_get_bundle (game->temporary) == gs_get_bundle (game)); |
| 1771 |
assert (gs_get_filter (game->temporary) == gs_get_filter (game)); |
| 1772 |
assert (gs_get_vars (game->temporary) != gs_get_vars (game)); |
| 1773 |
assert (!gs_get_memento (game->temporary)); |
| 1774 |
var_destroy (gs_get_vars (game->temporary)); |
| 1775 |
gs_destroy (game->temporary); |
| 1776 |
|
| 1777 |
assert (gs_get_bundle (game->undo) == gs_get_bundle (game)); |
| 1778 |
assert (gs_get_filter (game->undo) == gs_get_filter (game)); |
| 1779 |
assert (gs_get_vars (game->undo) != gs_get_vars (game)); |
| 1780 |
assert (!gs_get_memento (game->undo)); |
| 1781 |
var_destroy (gs_get_vars (game->undo)); |
| 1782 |
gs_destroy (game->undo); |
| 1783 |
|
| 1784 |
prop_destroy (gs_get_bundle (game)); |
| 1785 |
pf_destroy (gs_get_filter (game)); |
| 1786 |
var_destroy (gs_get_vars (game)); |
| 1787 |
memo_destroy (gs_get_memento (game)); |
| 1788 |
|
| 1789 |
gs_destroy (game); |
| 1790 |
} |
| 1791 |
|
| 1792 |
|
| 1793 |
|
| 1794 |
|
| 1795 |
|
| 1796 |
|
| 1797 |
|
| 1798 |
|
| 1799 |
void |
| 1800 |
run_quit (sc_gameref_t game) |
| 1801 |
{ |
| 1802 |
assert (gs_is_game_valid (game)); |
| 1803 |
|
| 1804 |
|
| 1805 |
if (!game->is_running) |
| 1806 |
{ |
| 1807 |
sc_error ("run_quit: game is not running\n"); |
| 1808 |
return; |
| 1809 |
} |
| 1810 |
|
| 1811 |
|
| 1812 |
game->is_running = FALSE; |
| 1813 |
longjmp (game->quitter, 1); |
| 1814 |
sc_fatal ("run_quit: unable to quit cleanly\n"); |
| 1815 |
} |
| 1816 |
|
| 1817 |
|
| 1818 |
|
| 1819 |
|
| 1820 |
|
| 1821 |
|
| 1822 |
|
| 1823 |
|
| 1824 |
|
| 1825 |
void |
| 1826 |
run_restart (sc_gameref_t game) |
| 1827 |
{ |
| 1828 |
assert (gs_is_game_valid (game)); |
| 1829 |
|
| 1830 |
|
| 1831 |
|
| 1832 |
|
| 1833 |
|
| 1834 |
if (game->is_running) |
| 1835 |
{ |
| 1836 |
game->is_running = FALSE; |
| 1837 |
game->do_restart = TRUE; |
| 1838 |
longjmp (game->quitter, 1); |
| 1839 |
sc_fatal ("run_restart: unable to restart cleanly\n"); |
| 1840 |
} |
| 1841 |
|
| 1842 |
|
| 1843 |
run_restart_handler (game); |
| 1844 |
game->is_running = FALSE; |
| 1845 |
} |
| 1846 |
|
| 1847 |
|
| 1848 |
|
| 1849 |
|
| 1850 |
|
| 1851 |
|
| 1852 |
|
| 1853 |
|
| 1854 |
void |
| 1855 |
run_save (sc_gameref_t game, sc_write_callbackref_t callback, void *opaque) |
| 1856 |
{ |
| 1857 |
assert (gs_is_game_valid (game)); |
| 1858 |
assert (callback); |
| 1859 |
|
| 1860 |
ser_save_game (game, callback, opaque); |
| 1861 |
} |
| 1862 |
|
| 1863 |
sc_bool |
| 1864 |
run_save_prompted (sc_gameref_t game) |
| 1865 |
{ |
| 1866 |
assert (gs_is_game_valid (game)); |
| 1867 |
|
| 1868 |
return ser_save_game_prompted (game); |
| 1869 |
} |
| 1870 |
|
| 1871 |
|
| 1872 |
|
| 1873 |
|
| 1874 |
|
| 1875 |
|
| 1876 |
|
| 1877 |
|
| 1878 |
|
| 1879 |
|
| 1880 |
|
| 1881 |
|
| 1882 |
|
| 1883 |
static sc_bool |
| 1884 |
run_restore_common (sc_gameref_t game, |
| 1885 |
sc_read_callbackref_t callback, void *opaque) |
| 1886 |
{ |
| 1887 |
sc_bool is_running, status; |
| 1888 |
|
| 1889 |
|
| 1890 |
|
| 1891 |
|
| 1892 |
|
| 1893 |
|
| 1894 |
is_running = game->is_running; |
| 1895 |
status = callback ? ser_load_game (game, callback, opaque) |
| 1896 |
: ser_load_game_prompted (game); |
| 1897 |
if (status) |
| 1898 |
{ |
| 1899 |
|
| 1900 |
game->is_running = is_running; |
| 1901 |
|
| 1902 |
|
| 1903 |
|
| 1904 |
|
| 1905 |
|
| 1906 |
if (game->is_running) |
| 1907 |
{ |
| 1908 |
game->is_running = FALSE; |
| 1909 |
game->do_restore = TRUE; |
| 1910 |
longjmp (game->quitter, 1); |
| 1911 |
sc_fatal ("run_restore_common: unable to restart cleanly\n"); |
| 1912 |
} |
| 1913 |
} |
| 1914 |
|
| 1915 |
|
| 1916 |
return status; |
| 1917 |
} |
| 1918 |
|
| 1919 |
sc_bool |
| 1920 |
run_restore (sc_gameref_t game, sc_read_callbackref_t callback, void *opaque) |
| 1921 |
{ |
| 1922 |
assert (gs_is_game_valid (game)); |
| 1923 |
assert (callback); |
| 1924 |
|
| 1925 |
return run_restore_common (game, callback, opaque); |
| 1926 |
} |
| 1927 |
|
| 1928 |
sc_bool |
| 1929 |
run_restore_prompted (sc_gameref_t game) |
| 1930 |
{ |
| 1931 |
assert (gs_is_game_valid (game)); |
| 1932 |
|
| 1933 |
return run_restore_common (game, NULL, NULL); |
| 1934 |
} |
| 1935 |
|
| 1936 |
|
| 1937 |
|
| 1938 |
|
| 1939 |
|
| 1940 |
|
| 1941 |
|
| 1942 |
|
| 1943 |
sc_bool |
| 1944 |
run_undo (sc_gameref_t game) |
| 1945 |
{ |
| 1946 |
const sc_memo_setref_t memento = gs_get_memento (game); |
| 1947 |
sc_bool is_running; |
| 1948 |
assert (gs_is_game_valid (game)); |
| 1949 |
|
| 1950 |
|
| 1951 |
is_running = game->is_running; |
| 1952 |
|
| 1953 |
|
| 1954 |
if (game->undo_available) |
| 1955 |
{ |
| 1956 |
|
| 1957 |
gs_copy (game, game->undo); |
| 1958 |
game->undo_available = FALSE; |
| 1959 |
game->is_running = is_running; |
| 1960 |
|
| 1961 |
|
| 1962 |
run_update_status (game); |
| 1963 |
|
| 1964 |
|
| 1965 |
res_sync_resources (game); |
| 1966 |
return TRUE; |
| 1967 |
} |
| 1968 |
|
| 1969 |
|
| 1970 |
|
| 1971 |
|
| 1972 |
|
| 1973 |
if (memo_load_game (memento, game)) |
| 1974 |
{ |
| 1975 |
|
| 1976 |
game->is_running = is_running; |
| 1977 |
|
| 1978 |
|
| 1979 |
|
| 1980 |
|
| 1981 |
|
| 1982 |
if (game->is_running) |
| 1983 |
{ |
| 1984 |
game->is_running = FALSE; |
| 1985 |
game->do_restore = TRUE; |
| 1986 |
longjmp (game->quitter, 1); |
| 1987 |
sc_fatal ("run_undo: unable to restart cleanly\n"); |
| 1988 |
} |
| 1989 |
|
| 1990 |
|
| 1991 |
return TRUE; |
| 1992 |
} |
| 1993 |
|
| 1994 |
|
| 1995 |
return FALSE; |
| 1996 |
} |
| 1997 |
|
| 1998 |
|
| 1999 |
|
| 2000 |
|
| 2001 |
|
| 2002 |
|
| 2003 |
|
| 2004 |
sc_bool |
| 2005 |
run_is_running (sc_gameref_t game) |
| 2006 |
{ |
| 2007 |
assert (gs_is_game_valid (game)); |
| 2008 |
|
| 2009 |
return game->is_running; |
| 2010 |
} |
| 2011 |
|
| 2012 |
|
| 2013 |
|
| 2014 |
|
| 2015 |
|
| 2016 |
|
| 2017 |
|
| 2018 |
|
| 2019 |
sc_bool |
| 2020 |
run_has_completed (sc_gameref_t game) |
| 2021 |
{ |
| 2022 |
assert (gs_is_game_valid (game)); |
| 2023 |
|
| 2024 |
return game->has_completed; |
| 2025 |
} |
| 2026 |
|
| 2027 |
|
| 2028 |
|
| 2029 |
|
| 2030 |
|
| 2031 |
|
| 2032 |
|
| 2033 |
sc_bool |
| 2034 |
run_is_undo_available (sc_gameref_t game) |
| 2035 |
{ |
| 2036 |
const sc_memo_setref_t memento = gs_get_memento (game); |
| 2037 |
assert (gs_is_game_valid (game)); |
| 2038 |
|
| 2039 |
return game->undo_available || memo_is_load_available (memento); |
| 2040 |
} |
| 2041 |
|
| 2042 |
|
| 2043 |
|
| 2044 |
|
| 2045 |
|
| 2046 |
|
| 2047 |
|
| 2048 |
|
| 2049 |
void |
| 2050 |
run_get_attributes (sc_gameref_t game, |
| 2051 |
const sc_char **game_name, const sc_char **game_author, |
| 2052 |
const sc_char **game_compile_date, |
| 2053 |
sc_int *turns, sc_int *score, sc_int *max_score, |
| 2054 |
const sc_char **current_room_name, |
| 2055 |
const sc_char **status_line, const sc_char **preferred_font, |
| 2056 |
sc_bool *bold_room_names, sc_bool *verbose, |
| 2057 |
sc_bool *notify_score_change) |
| 2058 |
{ |
| 2059 |
const sc_prop_setref_t bundle = gs_get_bundle (game); |
| 2060 |
const sc_var_setref_t vars = gs_get_vars (game); |
| 2061 |
sc_vartype_t vt_key[2]; |
| 2062 |
assert (gs_is_game_valid (game)); |
| 2063 |
|
| 2064 |
|
| 2065 |
if (game_name) |
| 2066 |
{ |
| 2067 |
if (!game->title) |
| 2068 |
{ |
| 2069 |
const sc_char *gamename; |
| 2070 |
sc_char *filtered; |
| 2071 |
|
| 2072 |
vt_key[0].string = "Globals"; |
| 2073 |
vt_key[1].string = "GameName"; |
| 2074 |
gamename = prop_get_string (bundle, "S<-ss", vt_key); |
| 2075 |
|
| 2076 |
filtered = pf_filter_for_info (gamename, vars); |
| 2077 |
pf_strip_tags (filtered); |
| 2078 |
game->title = filtered; |
| 2079 |
} |
| 2080 |
*game_name = game->title; |
| 2081 |
} |
| 2082 |
if (game_author) |
| 2083 |
{ |
| 2084 |
if (!game->author) |
| 2085 |
{ |
| 2086 |
const sc_char *gameauthor; |
| 2087 |
sc_char *filtered; |
| 2088 |
|
| 2089 |
vt_key[0].string = "Globals"; |
| 2090 |
vt_key[1].string = "GameAuthor"; |
| 2091 |
gameauthor = prop_get_string (bundle, "S<-ss", vt_key); |
| 2092 |
|
| 2093 |
filtered = pf_filter_for_info (gameauthor, vars); |
| 2094 |
pf_strip_tags (filtered); |
| 2095 |
game->author = filtered; |
| 2096 |
} |
| 2097 |
*game_author = game->author; |
| 2098 |
} |
| 2099 |
if (game_compile_date) |
| 2100 |
{ |
| 2101 |
vt_key[0].string = "CompileDate"; |
| 2102 |
*game_compile_date = prop_get_string (bundle, "S<-s", vt_key); |
| 2103 |
} |
| 2104 |
|
| 2105 |
|
| 2106 |
if (current_room_name) |
| 2107 |
*current_room_name = game->current_room_name; |
| 2108 |
if (status_line) |
| 2109 |
*status_line = game->status_line; |
| 2110 |
|
| 2111 |
|
| 2112 |
if (preferred_font) |
| 2113 |
{ |
| 2114 |
vt_key[0].string = "CustomFont"; |
| 2115 |
if (prop_get_boolean (bundle, "B<-s", vt_key)) |
| 2116 |
{ |
| 2117 |
vt_key[0].string = "FontNameSize"; |
| 2118 |
*preferred_font = prop_get_string (bundle, "S<-s", vt_key); |
| 2119 |
} |
| 2120 |
else |
| 2121 |
*preferred_font = NULL; |
| 2122 |
} |
| 2123 |
|
| 2124 |
|
| 2125 |
if (turns) |
| 2126 |
*turns = game->turns; |
| 2127 |
if (score) |
| 2128 |
*score = game->score; |
| 2129 |
if (max_score) |
| 2130 |
{ |
| 2131 |
vt_key[0].string = "Globals"; |
| 2132 |
vt_key[1].string = "MaxScore"; |
| 2133 |
*max_score = prop_get_integer (bundle, "I<-ss", vt_key); |
| 2134 |
} |
| 2135 |
if (bold_room_names) |
| 2136 |
*bold_room_names = game->bold_room_names; |
| 2137 |
if (verbose) |
| 2138 |
*verbose = game->verbose; |
| 2139 |
if (notify_score_change) |
| 2140 |
*notify_score_change = game->notify_score_change; |
| 2141 |
} |
| 2142 |
|
| 2143 |
void |
| 2144 |
run_set_attributes (sc_gameref_t game, |
| 2145 |
sc_bool bold_room_names, sc_bool verbose, |
| 2146 |
sc_bool notify_score_change) |
| 2147 |
{ |
| 2148 |
assert (gs_is_game_valid (game)); |
| 2149 |
|
| 2150 |
|
| 2151 |
game->bold_room_names = bold_room_names; |
| 2152 |
game->verbose = verbose; |
| 2153 |
game->notify_score_change = notify_score_change; |
| 2154 |
} |
| 2155 |
|
| 2156 |
|
| 2157 |
|
| 2158 |
|
| 2159 |
|
| 2160 |
|
| 2161 |
|
| 2162 |
|
| 2163 |
|
| 2164 |
|
| 2165 |
|
| 2166 |
sc_hintref_t |
| 2167 |
run_hint_iterate (sc_gameref_t game, sc_hintref_t hint) |
| 2168 |
{ |
| 2169 |
sc_int task; |
| 2170 |
assert (gs_is_game_valid (game)); |
| 2171 |
|
| 2172 |
|
| 2173 |
|
| 2174 |
|
| 2175 |
|
| 2176 |
if (!hint) |
| 2177 |
task = 0; |
| 2178 |
else |
| 2179 |
{ |
| 2180 |
|
| 2181 |
task = hint - game->tasks; |
| 2182 |
if (task < 0 || task >= gs_task_count (game)) |
| 2183 |
{ |
| 2184 |
sc_error ("run_hint_iterate: invalid iteration hint\n"); |
| 2185 |
return NULL; |
| 2186 |
} |
| 2187 |
|
| 2188 |
|
| 2189 |
task++; |
| 2190 |
} |
| 2191 |
|
| 2192 |
|
| 2193 |
for (; task < gs_task_count (game); task++) |
| 2194 |
{ |
| 2195 |
if (task_can_run_task (game, task) && task_has_hints (game, task)) |
| 2196 |
break; |
| 2197 |
} |
| 2198 |
|
| 2199 |
|
| 2200 |
return task < gs_task_count (game) ? game->tasks + task : NULL; |
| 2201 |
} |
| 2202 |
|
| 2203 |
|
| 2204 |
|
| 2205 |
|
| 2206 |
|
| 2207 |
|
| 2208 |
|
| 2209 |
|
| 2210 |
|
| 2211 |
|
| 2212 |
|
| 2213 |
|
| 2214 |
|
| 2215 |
|
| 2216 |
|
| 2217 |
static const sc_char * |
| 2218 |
run_get_hint_common (sc_gameref_t game, sc_hintref_t hint, |
| 2219 |
const sc_char *(*handler) (sc_gameref_t, sc_int)) |
| 2220 |
{ |
| 2221 |
const sc_prop_setref_t bundle = gs_get_bundle (game); |
| 2222 |
const sc_var_setref_t vars = gs_get_vars (game); |
| 2223 |
sc_int task; |
| 2224 |
const sc_char *string; |
| 2225 |
assert (gs_is_game_valid (game)); |
| 2226 |
|
| 2227 |
|
| 2228 |
task = hint - game->tasks; |
| 2229 |
if (task < 0 || task >= gs_task_count (game)) |
| 2230 |
{ |
| 2231 |
sc_error ("run_get_hint_common: invalid iteration hint\n"); |
| 2232 |
return NULL; |
| 2233 |
} |
| 2234 |
else if (!task_has_hints (game, task)) |
| 2235 |
{ |
| 2236 |
sc_error ("run_get_hint_common: task has no hint\n"); |
| 2237 |
return NULL; |
| 2238 |
} |
| 2239 |
|
| 2240 |
|
| 2241 |
string = handler (game, task); |
| 2242 |
if (!sc_strempty (string)) |
| 2243 |
{ |
| 2244 |
sc_char *filtered; |
| 2245 |
|
| 2246 |
|
| 2247 |
filtered = pf_filter (string, vars, bundle); |
| 2248 |
pf_strip_tags_for_hints (filtered); |
| 2249 |
sc_free (game->hint_text); |
| 2250 |
game->hint_text = filtered; |
| 2251 |
} |
| 2252 |
else |
| 2253 |
{ |
| 2254 |
|
| 2255 |
sc_free (game->hint_text); |
| 2256 |
game->hint_text = NULL; |
| 2257 |
} |
| 2258 |
|
| 2259 |
return game->hint_text; |
| 2260 |
} |
| 2261 |
|
| 2262 |
const sc_char * |
| 2263 |
run_get_hint_question (sc_gameref_t game, sc_hintref_t hint) |
| 2264 |
{ |
| 2265 |
return run_get_hint_common (game, hint, task_get_hint_question); |
| 2266 |
} |
| 2267 |
|
| 2268 |
const sc_char * |
| 2269 |
run_get_subtle_hint (sc_gameref_t game, sc_hintref_t hint) |
| 2270 |
{ |
| 2271 |
return run_get_hint_common (game, hint, task_get_hint_subtle); |
| 2272 |
} |
| 2273 |
|
| 2274 |
const sc_char * |
| 2275 |
run_get_unsubtle_hint (sc_gameref_t game, sc_hintref_t hint) |
| 2276 |
{ |
| 2277 |
return run_get_hint_common (game, hint, task_get_hint_unsubtle); |
| 2278 |
} |