| 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 <stdlib.h> |
| 28 |
#include <string.h> |
| 29 |
|
| 30 |
#include "scare.h" |
| 31 |
#include "scprotos.h" |
| 32 |
#include "scgamest.h" |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
static const sc_char NUL = '\0'; |
| 37 |
|
| 38 |
|
| 39 |
static sc_bool obj_trace = FALSE; |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
sc_bool |
| 50 |
obj_is_static (sc_gameref_t game, sc_int object) |
| 51 |
{ |
| 52 |
const sc_prop_setref_t bundle = gs_get_bundle (game); |
| 53 |
sc_vartype_t vt_key[3]; |
| 54 |
sc_bool bstatic; |
| 55 |
|
| 56 |
vt_key[0].string = "Objects"; |
| 57 |
vt_key[1].integer = object; |
| 58 |
vt_key[2].string = "Static"; |
| 59 |
bstatic = prop_get_boolean (bundle, "B<-sis", vt_key); |
| 60 |
return bstatic; |
| 61 |
} |
| 62 |
|
| 63 |
sc_bool |
| 64 |
obj_is_container (sc_gameref_t game, sc_int object) |
| 65 |
{ |
| 66 |
const sc_prop_setref_t bundle = gs_get_bundle (game); |
| 67 |
sc_vartype_t vt_key[3]; |
| 68 |
sc_bool is_container; |
| 69 |
|
| 70 |
vt_key[0].string = "Objects"; |
| 71 |
vt_key[1].integer = object; |
| 72 |
vt_key[2].string = "Container"; |
| 73 |
is_container = prop_get_boolean (bundle, "B<-sis", vt_key); |
| 74 |
return is_container; |
| 75 |
} |
| 76 |
|
| 77 |
sc_bool |
| 78 |
obj_is_surface (sc_gameref_t game, sc_int object) |
| 79 |
{ |
| 80 |
const sc_prop_setref_t bundle = gs_get_bundle (game); |
| 81 |
sc_vartype_t vt_key[3]; |
| 82 |
sc_bool is_surface; |
| 83 |
|
| 84 |
vt_key[0].string = "Objects"; |
| 85 |
vt_key[1].integer = object; |
| 86 |
vt_key[2].string = "Surface"; |
| 87 |
is_surface = prop_get_boolean (bundle, "B<-sis", vt_key); |
| 88 |
return is_surface; |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
sc_int |
| 98 |
obj_container_object (sc_gameref_t game, sc_int n) |
| 99 |
{ |
| 100 |
sc_int object, count; |
| 101 |
|
| 102 |
|
| 103 |
count = n; |
| 104 |
for (object = 0; object < gs_object_count (game) && count >= 0; object++) |
| 105 |
{ |
| 106 |
if (obj_is_container (game, object)) |
| 107 |
count--; |
| 108 |
} |
| 109 |
return object - 1; |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
sc_int |
| 119 |
obj_container_index (sc_gameref_t game, sc_int objnum) |
| 120 |
{ |
| 121 |
sc_int object, count; |
| 122 |
|
| 123 |
|
| 124 |
count = 0; |
| 125 |
for (object = 0; object < objnum; object++) |
| 126 |
{ |
| 127 |
if (obj_is_container (game, object)) |
| 128 |
count++; |
| 129 |
} |
| 130 |
return count; |
| 131 |
} |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
sc_int |
| 140 |
obj_surface_object (sc_gameref_t game, sc_int n) |
| 141 |
{ |
| 142 |
sc_int object, count; |
| 143 |
|
| 144 |
|
| 145 |
count = n; |
| 146 |
for (object = 0; object < gs_object_count (game) && count >= 0; object++) |
| 147 |
{ |
| 148 |
if (obj_is_surface (game, object)) |
| 149 |
count--; |
| 150 |
} |
| 151 |
return object - 1; |
| 152 |
} |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
sc_int |
| 161 |
obj_surface_index (sc_gameref_t game, sc_int objnum) |
| 162 |
{ |
| 163 |
sc_int object, count; |
| 164 |
|
| 165 |
|
| 166 |
count = 0; |
| 167 |
for (object = 0; object < objnum; object++) |
| 168 |
{ |
| 169 |
if (obj_is_surface (game, object)) |
| 170 |
count++; |
| 171 |
} |
| 172 |
return count; |
| 173 |
} |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
sc_int |
| 182 |
obj_stateful_object (sc_gameref_t game, sc_int n) |
| 183 |
{ |
| 184 |
const sc_prop_setref_t bundle = gs_get_bundle (game); |
| 185 |
sc_int object, count; |
| 186 |
|
| 187 |
|
| 188 |
count = n; |
| 189 |
for (object = 0; object < gs_object_count (game) && count >= 0; object++) |
| 190 |
{ |
| 191 |
sc_vartype_t vt_key[3]; |
| 192 |
sc_bool is_openable, is_statussed; |
| 193 |
|
| 194 |
vt_key[0].string = "Objects"; |
| 195 |
vt_key[1].integer = object; |
| 196 |
vt_key[2].string = "Openable"; |
| 197 |
is_openable = prop_get_integer (bundle, "I<-sis", vt_key) != 0; |
| 198 |
vt_key[2].string = "CurrentState"; |
| 199 |
is_statussed = prop_get_integer (bundle, "I<-sis", vt_key) != 0; |
| 200 |
if (is_openable || is_statussed) |
| 201 |
count--; |
| 202 |
} |
| 203 |
return object - 1; |
| 204 |
} |
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
sc_int |
| 213 |
obj_stateful_index (sc_gameref_t game, sc_int objnum) |
| 214 |
{ |
| 215 |
const sc_prop_setref_t bundle = gs_get_bundle (game); |
| 216 |
sc_int object, count; |
| 217 |
|
| 218 |
|
| 219 |
count = 0; |
| 220 |
for (object = 0; object < objnum; object++) |
| 221 |
{ |
| 222 |
sc_vartype_t vt_key[3]; |
| 223 |
sc_bool is_openable, is_statussed; |
| 224 |
|
| 225 |
vt_key[0].string = "Objects"; |
| 226 |
vt_key[1].integer = object; |
| 227 |
vt_key[2].string = "Openable"; |
| 228 |
is_openable = prop_get_integer (bundle, "I<-sis", vt_key) != 0; |
| 229 |
vt_key[2].string = "CurrentState"; |
| 230 |
is_statussed = prop_get_integer (bundle, "I<-sis", vt_key) != 0; |
| 231 |
if (is_openable || is_statussed) |
| 232 |
count++; |
| 233 |
} |
| 234 |
return count; |
| 235 |
} |
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
sc_char * |
| 246 |
obj_state_name (sc_gameref_t game, sc_int objnum) |
| 247 |
{ |
| 248 |
const sc_prop_setref_t bundle = gs_get_bundle (game); |
| 249 |
sc_vartype_t vt_key[3]; |
| 250 |
const sc_char *states; |
| 251 |
sc_int length, state, count, first, last; |
| 252 |
sc_char *string; |
| 253 |
|
| 254 |
|
| 255 |
vt_key[0].string = "Objects"; |
| 256 |
vt_key[1].integer = objnum; |
| 257 |
vt_key[2].string = "States"; |
| 258 |
states = prop_get_string (bundle, "S<-sis", vt_key); |
| 259 |
|
| 260 |
|
| 261 |
state = gs_object_state (game, objnum); |
| 262 |
length = strlen (states); |
| 263 |
for (first = 0, count = state; first < length && count > 1; first++) |
| 264 |
{ |
| 265 |
if (states[first] == '|') |
| 266 |
count--; |
| 267 |
} |
| 268 |
if (count != 1) |
| 269 |
return NULL; |
| 270 |
|
| 271 |
|
| 272 |
for (last = first; last < length; last++) |
| 273 |
{ |
| 274 |
if (states[last] == '|') |
| 275 |
break; |
| 276 |
} |
| 277 |
|
| 278 |
|
| 279 |
string = sc_malloc (last - first + 1); |
| 280 |
memcpy (string, states + first, last - first); |
| 281 |
string[last - first] = NUL; |
| 282 |
|
| 283 |
return string; |
| 284 |
} |
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
sc_int |
| 293 |
obj_dynamic_object (sc_gameref_t game, sc_int n) |
| 294 |
{ |
| 295 |
sc_int object, count; |
| 296 |
|
| 297 |
|
| 298 |
count = n; |
| 299 |
for (object = 0; object < gs_object_count (game) && count >= 0; object++) |
| 300 |
{ |
| 301 |
if (!obj_is_static (game, object)) |
| 302 |
count--; |
| 303 |
} |
| 304 |
return object - 1; |
| 305 |
} |
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
sc_int |
| 314 |
obj_wearable_object (sc_gameref_t game, sc_int n) |
| 315 |
{ |
| 316 |
const sc_prop_setref_t bundle = gs_get_bundle (game); |
| 317 |
sc_int object, count; |
| 318 |
|
| 319 |
|
| 320 |
count = n; |
| 321 |
for (object = 0; object < gs_object_count (game) && count >= 0; object++) |
| 322 |
{ |
| 323 |
if (!obj_is_static (game, object)) |
| 324 |
{ |
| 325 |
sc_vartype_t vt_key[3]; |
| 326 |
|
| 327 |
vt_key[0].string = "Objects"; |
| 328 |
vt_key[1].integer = object; |
| 329 |
vt_key[2].string = "Wearable"; |
| 330 |
if (prop_get_boolean (bundle, "B<-sis", vt_key)) |
| 331 |
count--; |
| 332 |
} |
| 333 |
} |
| 334 |
return object - 1; |
| 335 |
} |
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
enum |
| 346 |
{ OBJ_DIMENSION_DIVISOR = 10, |
| 347 |
OBJ_DIMENSION_MULTIPLE = 3 |
| 348 |
}; |
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
sc_int |
| 361 |
obj_get_size (sc_gameref_t game, sc_int object) |
| 362 |
{ |
| 363 |
const sc_prop_setref_t bundle = gs_get_bundle (game); |
| 364 |
sc_vartype_t vt_key[3]; |
| 365 |
sc_int size, count; |
| 366 |
|
| 367 |
|
| 368 |
if (obj_is_static (game, object)) |
| 369 |
return 0; |
| 370 |
|
| 371 |
|
| 372 |
vt_key[0].string = "Objects"; |
| 373 |
vt_key[1].integer = object; |
| 374 |
vt_key[2].string = "SizeWeight"; |
| 375 |
count = prop_get_integer (bundle, "I<-sis", vt_key) / OBJ_DIMENSION_DIVISOR; |
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
size = 1; |
| 384 |
for (; count > 0; count--) |
| 385 |
size *= OBJ_DIMENSION_MULTIPLE; |
| 386 |
|
| 387 |
if (obj_trace) |
| 388 |
sc_trace ("Object: object %ld is size %ld\n", object, size); |
| 389 |
|
| 390 |
|
| 391 |
return size; |
| 392 |
} |
| 393 |
|
| 394 |
sc_int |
| 395 |
obj_get_weight (sc_gameref_t game, sc_int object) |
| 396 |
{ |
| 397 |
const sc_prop_setref_t bundle = gs_get_bundle (game); |
| 398 |
sc_vartype_t vt_key[3]; |
| 399 |
sc_int weight, count; |
| 400 |
|
| 401 |
|
| 402 |
if (obj_is_static (game, object)) |
| 403 |
return 0; |
| 404 |
|
| 405 |
|
| 406 |
vt_key[0].string = "Objects"; |
| 407 |
vt_key[1].integer = object; |
| 408 |
vt_key[2].string = "SizeWeight"; |
| 409 |
count = prop_get_integer (bundle, "I<-sis", vt_key) % OBJ_DIMENSION_DIVISOR; |
| 410 |
|
| 411 |
|
| 412 |
weight = 1; |
| 413 |
for (; count > 0; count--) |
| 414 |
weight *= OBJ_DIMENSION_MULTIPLE; |
| 415 |
|
| 416 |
|
| 417 |
if (obj_is_container (game, object) || obj_is_surface (game, object)) |
| 418 |
{ |
| 419 |
sc_int other; |
| 420 |
|
| 421 |
|
| 422 |
for (other = 0; other < gs_object_count (game); other++) |
| 423 |
{ |
| 424 |
if ((gs_object_position (game, other) == OBJ_IN_OBJECT |
| 425 |
|| gs_object_position (game, other) == OBJ_ON_OBJECT) |
| 426 |
&& gs_object_parent (game, other) == object) |
| 427 |
{ |
| 428 |
weight += obj_get_weight (game, other); |
| 429 |
} |
| 430 |
} |
| 431 |
} |
| 432 |
|
| 433 |
if (obj_trace) |
| 434 |
sc_trace ("Object: object %ld is weight %ld\n", object, weight); |
| 435 |
|
| 436 |
|
| 437 |
return weight; |
| 438 |
} |
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
static sc_int |
| 450 |
obj_convert_player_limit (sc_int value) |
| 451 |
{ |
| 452 |
sc_int retval, index_; |
| 453 |
|
| 454 |
|
| 455 |
retval = value / OBJ_DIMENSION_DIVISOR; |
| 456 |
for (index_ = 0; index_ < value % OBJ_DIMENSION_DIVISOR; index_++) |
| 457 |
retval *= OBJ_DIMENSION_MULTIPLE; |
| 458 |
|
| 459 |
return retval; |
| 460 |
} |
| 461 |
|
| 462 |
sc_int |
| 463 |
obj_get_player_size_limit (sc_gameref_t game) |
| 464 |
{ |
| 465 |
const sc_prop_setref_t bundle = gs_get_bundle (game); |
| 466 |
sc_vartype_t vt_key[2]; |
| 467 |
sc_int max_size; |
| 468 |
|
| 469 |
vt_key[0].string = "Globals"; |
| 470 |
vt_key[1].string = "MaxSize"; |
| 471 |
max_size = prop_get_integer (bundle, "I<-ss", vt_key); |
| 472 |
|
| 473 |
return obj_convert_player_limit (max_size); |
| 474 |
} |
| 475 |
|
| 476 |
sc_int |
| 477 |
obj_get_player_weight_limit (sc_gameref_t game) |
| 478 |
{ |
| 479 |
const sc_prop_setref_t bundle = gs_get_bundle (game); |
| 480 |
sc_vartype_t vt_key[2]; |
| 481 |
sc_int max_weight; |
| 482 |
|
| 483 |
vt_key[0].string = "Globals"; |
| 484 |
vt_key[1].string = "MaxWt"; |
| 485 |
max_weight = prop_get_integer (bundle, "I<-ss", vt_key); |
| 486 |
|
| 487 |
return obj_convert_player_limit (max_weight); |
| 488 |
} |
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
sc_int |
| 499 |
obj_get_container_maxsize (sc_gameref_t game, sc_int object) |
| 500 |
{ |
| 501 |
const sc_prop_setref_t bundle = gs_get_bundle (game); |
| 502 |
sc_vartype_t vt_key[3]; |
| 503 |
sc_int maxsize, count; |
| 504 |
|
| 505 |
|
| 506 |
vt_key[0].string = "Objects"; |
| 507 |
vt_key[1].integer = object; |
| 508 |
vt_key[2].string = "Capacity"; |
| 509 |
count = prop_get_integer (bundle, "I<-sis", vt_key) % OBJ_DIMENSION_DIVISOR; |
| 510 |
|
| 511 |
|
| 512 |
maxsize = 1; |
| 513 |
for (; count > 0; count--) |
| 514 |
maxsize *= OBJ_DIMENSION_MULTIPLE; |
| 515 |
|
| 516 |
if (obj_trace) |
| 517 |
sc_trace ("Object: object %ld has max size %ld\n", object, maxsize); |
| 518 |
|
| 519 |
return maxsize; |
| 520 |
} |
| 521 |
|
| 522 |
sc_int |
| 523 |
obj_get_container_capacity (sc_gameref_t game, sc_int object) |
| 524 |
{ |
| 525 |
const sc_prop_setref_t bundle = gs_get_bundle (game); |
| 526 |
sc_vartype_t vt_key[3]; |
| 527 |
sc_int capacity; |
| 528 |
|
| 529 |
|
| 530 |
vt_key[0].string = "Objects"; |
| 531 |
vt_key[1].integer = object; |
| 532 |
vt_key[2].string = "Capacity"; |
| 533 |
capacity = prop_get_integer (bundle, "I<-sis", vt_key) |
| 534 |
/ OBJ_DIMENSION_DIVISOR; |
| 535 |
|
| 536 |
if (obj_trace) |
| 537 |
sc_trace ("Object: object %ld has capacity %ld\n", object, capacity); |
| 538 |
|
| 539 |
return capacity; |
| 540 |
} |
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
enum |
| 545 |
{ OBJ_STANDABLE_MASK = 1 << 0, |
| 546 |
OBJ_LIEABLE_MASK = 1 << 1 |
| 547 |
}; |
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
sc_int |
| 555 |
obj_standable_object (sc_gameref_t game, sc_int n) |
| 556 |
{ |
| 557 |
const sc_prop_setref_t bundle = gs_get_bundle (game); |
| 558 |
sc_int object, count; |
| 559 |
|
| 560 |
|
| 561 |
count = n; |
| 562 |
for (object = 0; object < gs_object_count (game) && count >= 0; object++) |
| 563 |
{ |
| 564 |
sc_vartype_t vt_key[3]; |
| 565 |
sc_int sit_lie_flags; |
| 566 |
|
| 567 |
vt_key[0].string = "Objects"; |
| 568 |
vt_key[1].integer = object; |
| 569 |
vt_key[2].string = "SitLie"; |
| 570 |
sit_lie_flags = prop_get_integer (bundle, "I<-sis", vt_key); |
| 571 |
if (sit_lie_flags & OBJ_STANDABLE_MASK) |
| 572 |
count--; |
| 573 |
} |
| 574 |
return object - 1; |
| 575 |
} |
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
sc_int |
| 584 |
obj_lieable_object (sc_gameref_t game, sc_int n) |
| 585 |
{ |
| 586 |
const sc_prop_setref_t bundle = gs_get_bundle (game); |
| 587 |
sc_int object, count; |
| 588 |
|
| 589 |
|
| 590 |
count = n; |
| 591 |
for (object = 0; object < gs_object_count (game) && count >= 0; object++) |
| 592 |
{ |
| 593 |
sc_vartype_t vt_key[3]; |
| 594 |
sc_int sit_lie_flags; |
| 595 |
|
| 596 |
vt_key[0].string = "Objects"; |
| 597 |
vt_key[1].integer = object; |
| 598 |
vt_key[2].string = "SitLie"; |
| 599 |
sit_lie_flags = prop_get_integer (bundle, "I<-sis", vt_key); |
| 600 |
if (sit_lie_flags & OBJ_LIEABLE_MASK) |
| 601 |
count--; |
| 602 |
} |
| 603 |
return object - 1; |
| 604 |
} |
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
sc_bool |
| 617 |
obj_appears_plural (sc_gameref_t game, sc_int object) |
| 618 |
{ |
| 619 |
const sc_prop_setref_t bundle = gs_get_bundle (game); |
| 620 |
sc_vartype_t vt_key[3]; |
| 621 |
const sc_char *prefix, *name; |
| 622 |
|
| 623 |
|
| 624 |
vt_key[0].string = "Objects"; |
| 625 |
vt_key[1].integer = object; |
| 626 |
vt_key[2].string = "Prefix"; |
| 627 |
prefix = prop_get_string (bundle, "S<-sis", vt_key); |
| 628 |
|
| 629 |
if (!(sc_strempty (prefix) |
| 630 |
|| sc_compare_word (prefix, "a", 1) |
| 631 |
|| sc_compare_word (prefix, "an", 2))) |
| 632 |
{ |
| 633 |
sc_int length; |
| 634 |
|
| 635 |
|
| 636 |
vt_key[2].string = "Short"; |
| 637 |
name = prop_get_string (bundle, "S<-sis", vt_key); |
| 638 |
length = strlen (name); |
| 639 |
|
| 640 |
if (!sc_strempty (name) |
| 641 |
&& sc_tolower (name[length - 1]) == 's' |
| 642 |
&& (length < 2 || sc_tolower (name[length - 2]) != 'u')) |
| 643 |
return TRUE; |
| 644 |
} |
| 645 |
|
| 646 |
|
| 647 |
return FALSE; |
| 648 |
} |
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
static sc_bool |
| 658 |
obj_directly_in_room_internal (sc_gameref_t game, sc_int object, sc_int room) |
| 659 |
{ |
| 660 |
const sc_prop_setref_t bundle = gs_get_bundle (game); |
| 661 |
|
| 662 |
|
| 663 |
if (obj_is_static (game, object)) |
| 664 |
{ |
| 665 |
sc_vartype_t vt_key[5]; |
| 666 |
sc_int type; |
| 667 |
|
| 668 |
|
| 669 |
if (!gs_object_static_unmoved (game, object)) |
| 670 |
{ |
| 671 |
if (gs_object_position (game, object) == OBJ_HELD_PLAYER) |
| 672 |
return FALSE; |
| 673 |
else |
| 674 |
return gs_object_position (game, object) - 1 == room; |
| 675 |
} |
| 676 |
|
| 677 |
|
| 678 |
vt_key[0].string = "Objects"; |
| 679 |
vt_key[1].integer = object; |
| 680 |
vt_key[2].string = "Where"; |
| 681 |
vt_key[3].string = "Type"; |
| 682 |
type = prop_get_integer (bundle, "I<-siss", vt_key); |
| 683 |
switch (type) |
| 684 |
{ |
| 685 |
case ROOMLIST_ALL_ROOMS: |
| 686 |
return TRUE; |
| 687 |
case ROOMLIST_NO_ROOMS: |
| 688 |
case ROOMLIST_NPC_PART: |
| 689 |
return FALSE; |
| 690 |
|
| 691 |
case ROOMLIST_ONE_ROOM: |
| 692 |
vt_key[3].string = "Room"; |
| 693 |
return prop_get_integer (bundle, "I<-siss", vt_key) == room + 1; |
| 694 |
|
| 695 |
case ROOMLIST_SOME_ROOMS: |
| 696 |
vt_key[3].string = "Rooms"; |
| 697 |
vt_key[4].integer = room + 1; |
| 698 |
return prop_get_boolean (bundle, "B<-sissi", vt_key); |
| 699 |
|
| 700 |
default: |
| 701 |
sc_fatal ("obj_directly_in_room_internal:" |
| 702 |
" invalid type, %ld\n", type); |
| 703 |
return FALSE; |
| 704 |
} |
| 705 |
} |
| 706 |
else |
| 707 |
return gs_object_position (game, object) == room + 1; |
| 708 |
} |
| 709 |
|
| 710 |
sc_bool |
| 711 |
obj_directly_in_room (sc_gameref_t game, sc_int object, sc_int room) |
| 712 |
{ |
| 713 |
sc_bool result; |
| 714 |
|
| 715 |
|
| 716 |
result = obj_directly_in_room_internal (game, object, room); |
| 717 |
|
| 718 |
if (obj_trace) |
| 719 |
{ |
| 720 |
sc_trace ("Object: checking for object %ld directly in room %ld, %s\n", |
| 721 |
object, room, result ? "true" : "false"); |
| 722 |
} |
| 723 |
|
| 724 |
return result; |
| 725 |
} |
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
static sc_bool |
| 737 |
obj_indirectly_in_room_internal (sc_gameref_t game, sc_int object, sc_int room) |
| 738 |
{ |
| 739 |
const sc_prop_setref_t bundle = gs_get_bundle (game); |
| 740 |
|
| 741 |
|
| 742 |
if (obj_is_static (game, object)) |
| 743 |
{ |
| 744 |
sc_vartype_t vt_key[5]; |
| 745 |
sc_int type; |
| 746 |
|
| 747 |
|
| 748 |
if (!gs_object_static_unmoved (game, object)) |
| 749 |
{ |
| 750 |
if (gs_object_position (game, object) == OBJ_HELD_PLAYER) |
| 751 |
return gs_player_in_room (game, room); |
| 752 |
else |
| 753 |
return gs_object_position (game, object) - 1 == room; |
| 754 |
} |
| 755 |
|
| 756 |
|
| 757 |
vt_key[0].string = "Objects"; |
| 758 |
vt_key[1].integer = object; |
| 759 |
vt_key[2].string = "Where"; |
| 760 |
vt_key[3].string = "Type"; |
| 761 |
type = prop_get_integer (bundle, "I<-siss", vt_key); |
| 762 |
switch (type) |
| 763 |
{ |
| 764 |
case ROOMLIST_ALL_ROOMS: |
| 765 |
return TRUE; |
| 766 |
case ROOMLIST_NO_ROOMS: |
| 767 |
return FALSE; |
| 768 |
|
| 769 |
case ROOMLIST_ONE_ROOM: |
| 770 |
vt_key[3].string = "Room"; |
| 771 |
return prop_get_integer (bundle, "I<-siss", vt_key) == room + 1; |
| 772 |
|
| 773 |
case ROOMLIST_SOME_ROOMS: |
| 774 |
vt_key[3].string = "Rooms"; |
| 775 |
vt_key[4].integer = room + 1; |
| 776 |
return prop_get_boolean (bundle, "B<-sissi", vt_key); |
| 777 |
|
| 778 |
case ROOMLIST_NPC_PART: |
| 779 |
{ |
| 780 |
sc_int npc; |
| 781 |
|
| 782 |
vt_key[2].string = "Parent"; |
| 783 |
npc = prop_get_integer (bundle, "I<-sis", vt_key); |
| 784 |
if (npc == 0) |
| 785 |
return gs_player_in_room (game, room); |
| 786 |
else |
| 787 |
return npc_in_room (game, npc - 1, room); |
| 788 |
} |
| 789 |
|
| 790 |
default: |
| 791 |
sc_fatal ("obj_indirectly_in_room_internal:" |
| 792 |
" invalid type, %ld\n", type); |
| 793 |
return FALSE; |
| 794 |
} |
| 795 |
} |
| 796 |
else |
| 797 |
{ |
| 798 |
sc_int parent, position; |
| 799 |
|
| 800 |
|
| 801 |
parent = gs_object_parent (game, object); |
| 802 |
position = gs_object_position (game, object); |
| 803 |
|
| 804 |
|
| 805 |
switch (position) |
| 806 |
{ |
| 807 |
case OBJ_HIDDEN: |
| 808 |
return FALSE; |
| 809 |
|
| 810 |
case OBJ_HELD_PLAYER: |
| 811 |
case OBJ_WORN_PLAYER: |
| 812 |
return gs_player_in_room (game, room); |
| 813 |
|
| 814 |
case OBJ_HELD_NPC: |
| 815 |
case OBJ_WORN_NPC: |
| 816 |
return npc_in_room (game, parent, room); |
| 817 |
|
| 818 |
case OBJ_IN_OBJECT: |
| 819 |
{ |
| 820 |
sc_int openness; |
| 821 |
|
| 822 |
openness = gs_object_openness (game, parent); |
| 823 |
switch (openness) |
| 824 |
{ |
| 825 |
case OBJ_WONTCLOSE: |
| 826 |
case OBJ_OPEN: |
| 827 |
return obj_indirectly_in_room (game, parent, room); |
| 828 |
default: |
| 829 |
return FALSE; |
| 830 |
} |
| 831 |
} |
| 832 |
|
| 833 |
case OBJ_ON_OBJECT: |
| 834 |
return obj_indirectly_in_room (game, parent, room); |
| 835 |
|
| 836 |
default: |
| 837 |
if (position > gs_room_count (game) + 1) |
| 838 |
{ |
| 839 |
sc_error ("sc_object_indirectly_in_room:" |
| 840 |
" position out of bounds, %ld\n", position); |
| 841 |
} |
| 842 |
return position - 1 == room; |
| 843 |
} |
| 844 |
} |
| 845 |
} |
| 846 |
|
| 847 |
sc_bool |
| 848 |
obj_indirectly_in_room (sc_gameref_t game, |
| 849 |
sc_int object, sc_int room) |
| 850 |
{ |
| 851 |
sc_bool result; |
| 852 |
|
| 853 |
|
| 854 |
result = obj_indirectly_in_room_internal (game, object, room); |
| 855 |
|
| 856 |
if (obj_trace) |
| 857 |
{ |
| 858 |
sc_trace ("Object: checking for object %ld indirectly in room %ld, %s\n", |
| 859 |
object, room, result ? "true" : "false"); |
| 860 |
} |
| 861 |
|
| 862 |
return result; |
| 863 |
} |
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
static sc_bool |
| 874 |
obj_indirectly_held_by_player_internal (sc_gameref_t game, |
| 875 |
sc_int object) |
| 876 |
{ |
| 877 |
|
| 878 |
if (obj_is_static (game, object)) |
| 879 |
{ |
| 880 |
|
| 881 |
if (!gs_object_static_unmoved (game, object)) |
| 882 |
{ |
| 883 |
if (gs_object_position (game, object) == OBJ_HELD_PLAYER) |
| 884 |
return TRUE; |
| 885 |
else |
| 886 |
return FALSE; |
| 887 |
} |
| 888 |
|
| 889 |
|
| 890 |
return FALSE; |
| 891 |
} |
| 892 |
else |
| 893 |
{ |
| 894 |
sc_int parent, position; |
| 895 |
|
| 896 |
|
| 897 |
parent = gs_object_parent (game, object); |
| 898 |
position = gs_object_position (game, object); |
| 899 |
|
| 900 |
|
| 901 |
switch (position) |
| 902 |
{ |
| 903 |
case OBJ_HIDDEN: |
| 904 |
return FALSE; |
| 905 |
|
| 906 |
case OBJ_HELD_PLAYER: |
| 907 |
case OBJ_WORN_PLAYER: |
| 908 |
return TRUE; |
| 909 |
|
| 910 |
case OBJ_HELD_NPC: |
| 911 |
case OBJ_WORN_NPC: |
| 912 |
return FALSE; |
| 913 |
|
| 914 |
case OBJ_IN_OBJECT: |
| 915 |
{ |
| 916 |
sc_int openness; |
| 917 |
|
| 918 |
openness = gs_object_openness (game, parent); |
| 919 |
switch (openness) |
| 920 |
{ |
| 921 |
case OBJ_WONTCLOSE: |
| 922 |
case OBJ_OPEN: |
| 923 |
return obj_indirectly_held_by_player (game, parent); |
| 924 |
default: |
| 925 |
return FALSE; |
| 926 |
} |
| 927 |
} |
| 928 |
|
| 929 |
case OBJ_ON_OBJECT: |
| 930 |
return obj_indirectly_held_by_player (game, parent); |
| 931 |
|
| 932 |
default: |
| 933 |
return FALSE; |
| 934 |
} |
| 935 |
} |
| 936 |
} |
| 937 |
|
| 938 |
sc_bool |
| 939 |
obj_indirectly_held_by_player (sc_gameref_t game, sc_int object) |
| 940 |
{ |
| 941 |
sc_bool result; |
| 942 |
|
| 943 |
|
| 944 |
result = obj_indirectly_held_by_player_internal (game, object); |
| 945 |
|
| 946 |
if (obj_trace) |
| 947 |
{ |
| 948 |
sc_trace ("Object: checking for object %ld indirectly" |
| 949 |
" held by player, %s\n", object, result ? "true" : "false"); |
| 950 |
} |
| 951 |
|
| 952 |
return result; |
| 953 |
} |
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
sc_bool |
| 962 |
obj_shows_initial_description (sc_gameref_t game, sc_int object) |
| 963 |
{ |
| 964 |
const sc_prop_setref_t bundle = gs_get_bundle (game); |
| 965 |
sc_vartype_t vt_key[3]; |
| 966 |
sc_int onlywhennotmoved; |
| 967 |
|
| 968 |
|
| 969 |
vt_key[0].string = "Objects"; |
| 970 |
vt_key[1].integer = object; |
| 971 |
vt_key[2].string = "OnlyWhenNotMoved"; |
| 972 |
onlywhennotmoved = prop_get_integer (bundle, "I<-sis", vt_key); |
| 973 |
|
| 974 |
|
| 975 |
switch (onlywhennotmoved) |
| 976 |
{ |
| 977 |
case 0: |
| 978 |
return TRUE; |
| 979 |
|
| 980 |
case 1: |
| 981 |
return gs_object_unmoved (game, object); |
| 982 |
|
| 983 |
case 2: |
| 984 |
{ |
| 985 |
sc_int initialposition; |
| 986 |
|
| 987 |
if (gs_object_unmoved (game, object)) |
| 988 |
return TRUE; |
| 989 |
|
| 990 |
vt_key[2].string = "InitialPosition"; |
| 991 |
initialposition = prop_get_integer (bundle, "I<-sis", vt_key) - 3; |
| 992 |
return gs_object_position (game, object) == initialposition; |
| 993 |
} |
| 994 |
} |
| 995 |
|
| 996 |
|
| 997 |
return FALSE; |
| 998 |
} |
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
void |
| 1008 |
obj_turn_update (sc_gameref_t game) |
| 1009 |
{ |
| 1010 |
sc_int index_; |
| 1011 |
|
| 1012 |
|
| 1013 |
for (index_ = 0; index_ < gs_object_count (game); index_++) |
| 1014 |
{ |
| 1015 |
if (!gs_object_seen (game, index_) |
| 1016 |
&& obj_indirectly_in_room (game, index_, gs_playerroom (game))) |
| 1017 |
gs_set_object_seen (game, index_, TRUE); |
| 1018 |
} |
| 1019 |
} |
| 1020 |
|
| 1021 |
void |
| 1022 |
obj_setup_initial (sc_gameref_t game) |
| 1023 |
{ |
| 1024 |
|
| 1025 |
obj_turn_update (game); |
| 1026 |
} |
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
void |
| 1035 |
obj_debug_trace (sc_bool flag) |
| 1036 |
{ |
| 1037 |
obj_trace = flag; |
| 1038 |
} |