ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/loader.C
(Generate patch)

Comparing deliantra/server/common/loader.C (file contents):
Revision 1.62 by root, Mon Feb 19 19:10:31 2007 UTC vs.
Revision 1.83 by root, Sat May 19 00:08:11 2007 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game for X-windows 2 * CrossFire, A Multiplayer game
3 * 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
7 * 7 *
29#include <global.h> 29#include <global.h>
30#include <loader.h> 30#include <loader.h>
31#include <sproto.h> 31#include <sproto.h>
32 32
33///////////////////////////////////////////////////////////////////////////// 33/////////////////////////////////////////////////////////////////////////////
34
35/* Maps the MOVE_* values to names */
36static const char *const move_name[] = { "walk", "fly_low", "fly_high", "swim", "boat", NULL };
37 34
38/* This table is only necessary to convert objects that existed before the 35/* This table is only necessary to convert objects that existed before the
39 * spell object conversion to the new object. It was not practical 36 * spell object conversion to the new object. It was not practical
40 * to go through every mapping looking for every potion, rod, wand, etc 37 * to go through every mapping looking for every potion, rod, wand, etc
41 * that had a sp set and update to the new value. So this maps the 38 * that had a sp set and update to the new value. So this maps the
253 "spell_cause_rabies", /* 204 */ 250 "spell_cause_rabies", /* 204 */
254 "spell_glyph", /* 205 */ 251 "spell_glyph", /* 205 */
255 NULL 252 NULL
256}; 253};
257 254
258extern int arch_init; 255extern bool loading_arch;
259 256
260/* This function checks the object after it has been loaded (when we 257/* This function checks the object after it has been loaded (when we
261 * get the 'end' in the input stream). This function can be used to 258 * get the 'end' in the input stream). This function can be used to
262 * deal with legacy objects where fields may have changed. It can also be used 259 * deal with legacy objects where fields may have changed. It can also be used
263 * to check for objects to make sure there are no common errors. 260 * to check for objects to make sure there are no common errors.
264 */ 261 */
265static void 262void
266check_loaded_object (object *op) 263object::post_load_check ()
267{ 264{
265 if (type >= NUM_TYPES)
266 {
267 LOG (llevError, "%s: type out of range, resetting to 0.\n", debug_desc ());
268 type = 0;
269 }
270
271 switch (type)
272 {
273 case BOW:
274 case WAND:
275 case ROD:
276 case HORN:
277 if (slot [body_range].info != -1)
278 {
279 LOG (llevError, "%s: body_range %d != -1\n", debug_desc (), slot [body_range].info);
280 slot [body_range].info = -1;
281 }
282 break;
283
284 case WEAPON:
285 if (slot [body_combat].info != -1)
286 {
287 LOG (llevError, "%s: body_combat %d != -1\n", debug_desc (), slot [body_combat].info);
288 slot [body_combat].info = -1;
289 }
290 break;
291
292 case SHIELD:
293 if (slot [body_shield].info != -1)
294 {
295 LOG (llevError, "%s: body_shield %d != -1\n", debug_desc (), slot [body_shield].info);
296 slot [body_shield].info = -1;
297 }
298 break;
299
300 case PLAYER:
301 if (slot [body_shield].info != 1)
302 {
303 LOG (llevError, "%s: body_shield %d != 1\n", debug_desc (), slot [body_shield].info);
304 slot [body_shield].info = 1;
305 }
306
307 if (slot [body_combat].info != 1)
308 {
309 LOG (llevError, "%s: body_combat %d != 1\n", debug_desc (), slot [body_combat].info);
310 slot [body_combat].info = 1;
311 }
312
313 if (slot [body_range].info != 1)
314 {
315 LOG (llevError, "%s: body_range %d != 1\n", debug_desc (), slot [body_range].info);
316 slot [body_range].info = 1;
317 }
318 break;
319 }
320
268 /* We do some specialised handling to handle legacy cases of name_pl. 321 /* We do some specialised handling to handle legacy cases of name_pl.
269 * If the object doesn't have a name_pl, we just use the object name - 322 * If the object doesn't have a name_pl, we just use the object name -
270 * this isn't perfect (things won't be properly pluralised), but works to 323 * this isn't perfect (things won't be properly pluralised), but works to
271 * that degree (5 heart is still quite understandable). But the case we 324 * that degree (5 heart is still quite understandable). But the case we
272 * also have to catch is if this object is not using the normal name for 325 * also have to catch is if this object is not using the normal name for
273 * the object. In that case, we also want to use the loaded name. 326 * the object. In that case, we also want to use the loaded name.
274 * Otherwise, what happens is that the the plural name will lose 327 * Otherwise, what happens is that the the plural name will lose
275 * information (appear as just 'hearts' and not 'goblins heart') 328 * information (appear as just 'hearts' and not 'goblins heart')
276 */ 329 */
277 if (op->arch && op->name != op->arch->clone.name && op->name_pl == op->arch->clone.name_pl) 330 if (arch && name != arch->clone.name && name_pl == arch->clone.name_pl)
278 op->name_pl = 0; 331 name_pl = 0;
279 332
280 if (!op->name_pl) 333 if (!name_pl)
281 op->name_pl = op->name; 334 name_pl = name;
282 335
283 /* objects now have a materialname. try to patch it in */ 336 /* objects now have a materialname. try to patch it in */
284 if (!(op->is_weapon () && op->level > 0)) 337 if (!(is_weapon () && level > 0))
285 { 338 set_materialname (this, map ? map->difficulty : 5, 0);
286 if (op->map != NULL)
287 set_materialname (op, op->map->difficulty, NULL);
288 else
289 set_materialname (op, 5, NULL);
290 }
291 339
292 /* only do these when program is first run - a bit 340 /* only do these when program is first run - a bit
293 * excessive to do this at every run - most of this is 341 * excessive to do this at every run - most of this is
294 * really just to catch any errors - program will still run, but 342 * really just to catch any errors - program will still run, but
295 * not in the ideal fashion. 343 * not in the ideal fashion.
296 */ 344 */
297 if ((op->type == WEAPON || op->type == BOW) && arch_init) 345 if (loading_arch && (type == WEAPON || type == BOW || type == ROD || type == HORN || type == WAND))
298 { 346 {
299 if (!op->skill) 347 if (!skill)
300 LOG (llevError, "Weapon %s lacks a skill.\n", op->debug_desc ()); 348 LOG (llevError, "Weapon %s lacks a skill.\n", debug_desc ());
301 else if ((!strcmp (op->skill, "one handed weapons") && op->body_info[1] != -1) || 349 else if ((!strcmp (skill, "one handed weapons") && slot[body_arm].info != -1) ||
302 (!strcmp (op->skill, "two handed weapons") && op->body_info[1] != -2)) 350 (!strcmp (skill, "two handed weapons") && slot[body_arm].info != -2))
303 LOG (llevError, "weapon %s arm usage does not match skill: %d, %s\n", op->debug_desc (), op->body_info[1], &op->skill); 351 LOG (llevError, "weapon %s arm usage does not match skill: %d, %s\n", debug_desc (), slot[body_arm].info, &skill);
304 } 352 }
305 353
306 /* We changed last_heal to gen_sp_armour, which is what it 354 /* We changed last_heal to gen_sp_armour, which is what it
307 * really does for many objects. Need to catch any in maps 355 * really does for many objects. Need to catch any in maps
308 * that may have an old value. 356 * that may have an old value.
309 */ 357 */
310 if (op->type == WEAPON 358 if (type == WEAPON
311 || op->type == ARMOUR || op->type == HELMET 359 || type == ARMOUR || type == HELMET
312 || op->type == SHIELD || op->type == RING 360 || type == SHIELD || type == RING
313 || op->type == BOOTS || op->type == GLOVES 361 || type == BOOTS || type == GLOVES
314 || op->type == AMULET || op->type == GIRDLE 362 || type == AMULET || type == GIRDLE
315 || op->type == BRACERS || op->type == CLOAK) 363 || type == BRACERS || type == CLOAK)
316 { 364 {
317 if (op->last_heal) 365 if (last_heal)
318 { 366 {
319 LOG (llevDebug, "Object %s still has last_heal set, not gen_sp_armour\n", op->debug_desc ()); 367 LOG (llevDebug, "Object %s still has last_heal set, not gen_sp_armour\n", debug_desc ());
320 op->gen_sp_armour = op->last_heal; 368 gen_sp_armour = last_heal;
321 op->last_heal = 0; 369 last_heal = 0;
322 } 370 }
323 371
324 int ip = calc_item_power (op, 0); 372 int ip = calc_item_power (this, 0);
325 373
326 /* Legacy objects from before item power was in the game */ 374 /* Legacy objects from before item power was in the game */
327 if (!op->item_power && ip) 375 if (!item_power && ip)
328 { 376 {
329 if (ip > 3) 377 if (ip > 3)
330 LOG (llevDebug, "Object %s had no item power, using %d\n", op->debug_desc (), ip); 378 LOG (llevDebug, "Object %s had no item power, using %d\n", debug_desc (), ip);
331 379
332 op->item_power = ip; 380 item_power = ip;
333 } 381 }
334 382
335 /* Check for possibly bogus values. Has to meet both these criteria - 383 /* Check for possibly bogus values. Has to meet both these criteria -
336 * something that has item_power 1 is probably just fine if our calculated 384 * something that has item_power 1 is probably just fine if our calculated
337 * value is 1 or 2 - these values are small enough that hard to be precise. 385 * value is 1 or 2 - these values are small enough that hard to be precise.
338 * similarly, it item_power is 0, the first check will always pass, 386 * similarly, it item_power is 0, the first check will always pass,
339 * but not the second one. 387 * but not the second one.
340 */ 388 */
341 if (ip > 2 * op->item_power && ip > (op->item_power + 3)) 389 if (ip > 2 * item_power && ip > (item_power + 3))
342 LOG (llevDebug, "Object %s seems to have too low item power? %d > %d\n", op->debug_desc (), ip, op->item_power); 390 LOG (llevDebug, "Object %s seems to have too low item power? %d > %d\n", debug_desc (), ip, item_power);
343 } 391 }
344 392
345 /* Old spellcasting object - need to load in the appropiate object */ 393 /* Old spellcasting object - need to load in the appropiate object */
346 if ((op->type == ROD || op->type == WAND || op->type == SCROLL || op->type == HORN || op->type == FIREWALL || 394 if ((type == ROD || type == WAND || type == SCROLL || type == HORN || type == FIREWALL ||
347 /* POTIONS and ALTARS don't always cast spells, but if they do, update them */ 395 /* POTIONS and ALTARS don't always cast spells, but if they do, update them */
348 ((op->type == POTION || op->type == ALTAR) && op->stats.sp)) && !op->inv && !arch_init) 396 ((type == POTION || type == ALTAR) && stats.sp)) && !inv && !loading_arch)
349 { 397 {
350 /* Fireall is bizarre in that spell type was stored in dam. Rest are 'normal' 398 /* Fireall is bizarre in that spell type was stored in dam. Rest are 'normal'
351 * in that spell was stored in sp. 399 * in that spell was stored in sp.
352 */ 400 */
353 object *tmp = get_archetype (spell_mapping[op->type == FIREWALL ? op->stats.dam : op->stats.sp]); 401 object *tmp = get_archetype (spell_mapping[type == FIREWALL ? stats.dam : stats.sp]);
354 insert_ob_in_ob (tmp, op); 402 insert_ob_in_ob (tmp, this);
355 op->randomitems = NULL; /* So another spell isn't created for this object */ 403 randomitems = NULL; /* So another spell isn't created for this object */
356 } 404 }
357 405
358 /* spellbooks & runes use slaying. But not to arch name, but to spell name */ 406 /* spellbooks & runes use slaying. But not to arch name, but to spell name */
359 if ((op->type == SPELLBOOK || op->type == RUNE) && op->slaying && !op->inv && !arch_init) 407 if ((type == SPELLBOOK || type == RUNE) && slaying && !inv && !loading_arch)
360 { 408 {
361 object *tmp = get_archetype_by_object_name (op->slaying); 409 object *tmp = get_archetype_by_object_name (slaying);
362 insert_ob_in_ob (tmp, op); 410 insert_ob_in_ob (tmp, this);
363 op->randomitems = NULL; /* So another spell isn't created for this object */ 411 randomitems = NULL; /* So another spell isn't created for this object */
364 /* without this, value is all screwed up */ 412 /* without this, value is all screwed up */
365 op->value = op->arch->clone.value * op->inv->value; 413 value = arch->clone.value * inv->value;
366 } 414 }
367 415
368 if (QUERY_FLAG (op, FLAG_MONSTER)) 416 if (QUERY_FLAG (this, FLAG_MONSTER))
369 { 417 {
370 if (op->stats.hp > op->stats.maxhp) 418 if (stats.hp > stats.maxhp)
371 { 419 {
372 LOG (llevDebug, "Monster %s has hp set higher than maxhp (%d>%d)\n", op->debug_desc (), op->stats.hp, op->stats.maxhp); 420 LOG (llevDebug, "Monster %s has hp set higher than maxhp (%d>%d)\n", debug_desc (), stats.hp, stats.maxhp);
373 op->stats.maxhp = op->stats.hp; 421 stats.maxhp = stats.hp;
374 } 422 }
375 423
376 /* The archs just need to be updated for this */ 424 /* The archs just need to be updated for this */
377 if (op->move_type == 0) 425 if (move_type == 0)
378 op->move_type = MOVE_WALK; 426 move_type = MOVE_WALK;
379 } 427 }
380 428
381 if ((QUERY_FLAG (op, FLAG_GENERATOR) && QUERY_FLAG (op, FLAG_CONTENT_ON_GEN)) || op->type == CREATOR || op->type == CONVERTER) 429 if ((QUERY_FLAG (this, FLAG_GENERATOR) && QUERY_FLAG (this, FLAG_CONTENT_ON_GEN)) || type == CREATOR || type == CONVERTER)
382 { 430 {
383 /* Object will duplicate it's content as part of the 431 /* Object will duplicate it's content as part of the
384 * generation process. To do this, we must flag inventory 432 * generation process. To do this, we must flag inventory
385 * so it remains unevaluated concerning the randomitems and 433 * so it remains unevaluated concerning the randomitems and
386 * the living (a demonlord shouldn't cast from inside generator!) 434 * the living (a demonlord shouldn't cast from inside generator!)
387 */ 435 */
388 flag_inv (op, FLAG_IS_A_TEMPLATE); 436 flag_inv (this, FLAG_IS_A_TEMPLATE);
389 } 437 }
390 438
391 /* Handle player movers. We use move_type for player movers 439 /* Handle player movers. We use move_type for player movers
392 * because they operate on their own time (move_on 440 * because they operate on their own time (move_on
393 * would potentially cause them to be triggered when someone steps 441 * would potentially cause them to be triggered when someone steps
394 * on them). If move_type is set, presume person knows what they 442 * on them). If move_type is set, presume person knows what they
395 * are doing, otherwise, set move_type based on maxhp value. 443 * are doing, otherwise, set move_type based on maxhp value.
396 */ 444 */
397 if (op->type == PLAYERMOVER) 445 if (type == PLAYERMOVER)
398 { 446 {
399 if (!op->move_type) 447 if (!move_type)
400 { 448 {
401 if (op->stats.maxhp) 449 if (stats.maxhp)
402 { 450 {
403 op->move_type = MOVE_ALL; 451 move_type = MOVE_ALL;
404 op->stats.maxhp = 0; 452 stats.maxhp = 0;
405 } 453 }
406 else 454 else
407 op->move_type = MOVE_WALK; 455 move_type = MOVE_WALK;
408 } 456 }
409 } 457 }
410
411} 458}
412 459
413static void 460static void
414set_move (MoveType & mt, const char *str) 461set_move (MoveType &mt, const char *str)
415{ 462{
463 static const struct flagstr {
464 const char *name;
465 MoveType flags;
466 } move_flags[] = {
467 { "walk" , MOVE_WALK },
468 { "flying" , MOVE_FLY_LOW | MOVE_FLY_HIGH },
469 { "fly_low" , MOVE_FLY_LOW },
470 { "fly_high", MOVE_FLY_HIGH },
471 { "swim" , MOVE_SWIM },
472 { "boat" , MOVE_BOAT },
473 { "ship" , MOVE_SHIP },
474 { "all" , MOVE_ALL },
475 };
476
416 if (!str) 477 if (!str)
417 { 478 {
418 mt = 0; 479 mt = 0;
419 return; 480 return;
420 } 481 }
427 488
428 mt = 0; 489 mt = 0;
429 490
430 for (str = strtok ((char *) str, " "); str; str = strtok (0, " ")) 491 for (str = strtok ((char *) str, " "); str; str = strtok (0, " "))
431 { 492 {
432 if (!strcasecmp (str, "all")) 493 bool negate = 0;
433 mt |= MOVE_ALL; 494
434 else 495 if (*str == '-')
435 { 496 {
436 int i, negate = 0; 497 negate = 1;
498 str++;
499 }
437 500
438 if (*str == '-') 501 for (const flagstr *f = move_flags; f < move_flags + sizeof (move_flags) / sizeof (move_flags [0]); ++f)
502 {
503 if (!strcmp (f->name, str))
439 { 504 {
440 negate = 1;
441 str++;
442 }
443
444 for (i = 0; move_name[i]; i++)
445 {
446 if (!strcasecmp (move_name[i], str))
447 {
448 if (negate) 505 if (negate)
449 mt &= ~(1 << i); 506 mt &= ~f->flags;
450 else
451 mt |= (1 << i);
452
453 break;
454 }
455 }
456
457 if (!move_name[i])
458 {
459 /* fly is a special case - covers both fly_low and
460 * fly_high - since it doesn't match to a specific
461 * single bit, have to special case it.
462 */
463 if (!strcasecmp (str, "flying"))
464 {
465 if (negate)
466 mt &= ~MOVE_FLYING;
467 else
468 mt |= MOVE_FLYING;
469 }
470 else 507 else
471 LOG (llevDebug, "common/loader.l: set_move - unknown move string '%s'\n", str); 508 mt |= f->flags;
509
510 goto next;
472 } 511 }
473 } 512 }
513
514 LOG (llevDebug, "common/loader.C: set_move - unknown move string '%s'\n", str);
515
516next: ;
474 } 517 }
475} 518}
476 519
477#define GET_FLAG(op,flag) \ 520#define GET_FLAG(op,flag) \
478 if (f.get_sint32 ()) \ 521 if (f.get_sint32 ()) \
481 CLEAR_FLAG (op, flag) \ 524 CLEAR_FLAG (op, flag) \
482 525
483bool 526bool
484object::parse_kv (object_thawer &f) 527object::parse_kv (object_thawer &f)
485{ 528{
486 assert (f.kw == KW_object || f.kw == KW_arch);
487
488 if (f.kw == KW_object)
489 f.get (name); // preset name from object name
490
491 f.next ();
492
493 object *op_inv = inv; 529 object *op_inv = inv;
494 530
495 for (;;) 531 for (;;)
496 { 532 {
497 switch (f.kw) 533 switch (f.kw)
559 } 595 }
560 } 596 }
561 continue; 597 continue;
562 598
563 case KW_other_arch: 599 case KW_other_arch:
600 other_arch =
601 loading_arch
602 ? archetype::get (f.get_str ())
564 other_arch = archetype::find (f.get_str ()); 603 : archetype::find (f.get_str ());
604
605 if (!other_arch)
606 LOG (llevError, "%s uses unknown other_arch '%s'.\n", debug_desc (), f.get_str ());
565 break; 607 break;
566 608
567 case KW_animation: 609 case KW_animation:
568 { 610 {
569 CLEAR_FLAG (this, FLAG_ANIMATE); 611 CLEAR_FLAG (this, FLAG_ANIMATE);
595 move_slow |= MOVE_WALK; 637 move_slow |= MOVE_WALK;
596 f.get (move_slow_penalty); 638 f.get (move_slow_penalty);
597 break; 639 break;
598 640
599 case KW_face: 641 case KW_face:
600 face = &new_faces[FindFace (f.get_str (), 0)]; 642 face = face_find (f.get_str ());
601 break; 643 break;
602 644
603 case KW_x: f.get (x); break; 645 case KW_x: f.get (x); break;
604 case KW_y: f.get (y); break; 646 case KW_y: f.get (y); break;
605 647
730 GET_FLAG (this, FLAG_IDENTIFIED); 772 GET_FLAG (this, FLAG_IDENTIFIED);
731 //TODO: move to check_object or so 773 //TODO: move to check_object or so
732 if (QUERY_FLAG (this, FLAG_IDENTIFIED)) 774 if (QUERY_FLAG (this, FLAG_IDENTIFIED))
733 CLEAR_FLAG (this, FLAG_KNOWN_MAGICAL); 775 CLEAR_FLAG (this, FLAG_KNOWN_MAGICAL);
734 776
735 break;
736
737 case KW_wiz:
738 GET_FLAG (this, FLAG_WIZ);
739 //TODO: move to check_object
740 if (QUERY_FLAG (this, FLAG_WIZ))
741 {
742 SET_FLAG (this, FLAG_WAS_WIZ);
743 SET_FLAG (this, FLAG_WIZPASS);
744 SET_FLAG (this, FLAG_WIZCAST);
745 }
746 else
747 {
748 CLEAR_FLAG (this, FLAG_WIZPASS);
749 CLEAR_FLAG (this, FLAG_WIZCAST);
750 }
751 break; 777 break;
752 778
753 case KW_friendly: 779 case KW_friendly:
754 if (f.get_sint32 ()) 780 if (f.get_sint32 ())
755 if (type != PLAYER) 781 if (type != PLAYER)
788 case KW_reflect_missile: GET_FLAG (this, FLAG_REFL_MISSILE); break; 814 case KW_reflect_missile: GET_FLAG (this, FLAG_REFL_MISSILE); break;
789 case KW_reflect_spell: GET_FLAG (this, FLAG_REFL_SPELL); break; 815 case KW_reflect_spell: GET_FLAG (this, FLAG_REFL_SPELL); break;
790 case KW_no_magic: GET_FLAG (this, FLAG_NO_MAGIC); break; 816 case KW_no_magic: GET_FLAG (this, FLAG_NO_MAGIC); break;
791 case KW_no_drop: GET_FLAG (this, FLAG_NO_DROP); break; 817 case KW_no_drop: GET_FLAG (this, FLAG_NO_DROP); break;
792 case KW_random_movement: GET_FLAG (this, FLAG_RANDOM_MOVE); break; 818 case KW_random_movement: GET_FLAG (this, FLAG_RANDOM_MOVE); break;
793 case KW_was_wiz: GET_FLAG (this, FLAG_WAS_WIZ); break;
794 case KW_no_fix_player: GET_FLAG (this, FLAG_NO_FIX_PLAYER); break; 819 case KW_no_fix_player: GET_FLAG (this, FLAG_NO_FIX_PLAYER); break;
795 case KW_is_lightable: GET_FLAG (this, FLAG_IS_LIGHTABLE); break; 820 case KW_is_lightable: GET_FLAG (this, FLAG_IS_LIGHTABLE); break;
796 case KW_tear_down: GET_FLAG (this, FLAG_TEAR_DOWN); break; 821 case KW_tear_down: GET_FLAG (this, FLAG_TEAR_DOWN); break;
797 case KW_can_use_shield: GET_FLAG (this, FLAG_USE_SHIELD); break; 822 case KW_can_use_shield: GET_FLAG (this, FLAG_USE_SHIELD); break;
798 case KW_can_cast_spell: GET_FLAG (this, FLAG_CAST_SPELL); break; 823 case KW_can_cast_spell: GET_FLAG (this, FLAG_CAST_SPELL); break;
841 case KW_no_steal: GET_FLAG (this, FLAG_NO_STEAL); break; 866 case KW_no_steal: GET_FLAG (this, FLAG_NO_STEAL); break;
842 case KW_one_hit: GET_FLAG (this, FLAG_ONE_HIT); break; 867 case KW_one_hit: GET_FLAG (this, FLAG_ONE_HIT); break;
843 case KW_berserk: GET_FLAG (this, FLAG_BERSERK); break; 868 case KW_berserk: GET_FLAG (this, FLAG_BERSERK); break;
844 case KW_is_buildable: GET_FLAG (this, FLAG_IS_BUILDABLE); break; 869 case KW_is_buildable: GET_FLAG (this, FLAG_IS_BUILDABLE); break;
845 case KW_destroy_on_death: GET_FLAG (this, FLAG_DESTROY_ON_DEATH); break; 870 case KW_destroy_on_death: GET_FLAG (this, FLAG_DESTROY_ON_DEATH); break;
871 case KW_treasure_env: GET_FLAG (this, FLAG_TREASURE_ENV); break;
872 case KW_precious: GET_FLAG (this, FLAG_PRECIOUS); break;
846 873
847 case KW_armour: f.get (resist[ATNR_PHYSICAL]); break; 874 case KW_armour: f.get (resist[ATNR_PHYSICAL]); break;
848 case KW_resist_physical: f.get (resist[ATNR_PHYSICAL]); break; 875 case KW_resist_physical: f.get (resist[ATNR_PHYSICAL]); break;
849 case KW_resist_magic: f.get (resist[ATNR_MAGIC]); break; 876 case KW_resist_magic: f.get (resist[ATNR_MAGIC]); break;
850 case KW_resist_fire: f.get (resist[ATNR_FIRE]); break; 877 case KW_resist_fire: f.get (resist[ATNR_FIRE]); break;
886 case KW_glow_radius: f.get (glow_radius); break; 913 case KW_glow_radius: f.get (glow_radius); break;
887 case KW_weapontype: f.get (weapontype); break; 914 case KW_weapontype: f.get (weapontype); break;
888 case KW_tooltype: f.get (tooltype); break; 915 case KW_tooltype: f.get (tooltype); break;
889 case KW_casting_time: f.get (casting_time); break; 916 case KW_casting_time: f.get (casting_time); break;
890 case KW_elevation: f.get (elevation); break; 917 case KW_elevation: f.get (elevation); break;
891 case KW_smoothlevel: f.get (smoothlevel); break; 918 case KW_smoothlevel: f.get (smoothlevel); smoothlevel = clamp (smoothlevel, 0, 255); break;
892 case KW_client_type: f.get (client_type); break; 919 case KW_client_type: f.get (client_type); break;
893 case KW_duration: f.get (duration); break; 920 case KW_duration: f.get (duration); break;
894 case KW_range: f.get (range); break; 921 case KW_range: f.get (range); break;
895 case KW_range_modifier: f.get (range_modifier); break; 922 case KW_range_modifier: f.get (range_modifier); break;
896 case KW_dam_modifier: f.get (dam_modifier); break; 923 case KW_dam_modifier: f.get (dam_modifier); break;
897 case KW_duration_modifier: f.get (duration_modifier); break; 924 case KW_duration_modifier: f.get (duration_modifier); break;
898 925
899 //TODO: mechanism to ensure that KW_xxx is consecutive needed from include/preprocess 926 //TODO: mechanism to ensure that KW_xxx is consecutive needed from include/preprocess
900 //TODO: parse from other include files 927 //TODO: parse from other include files
901 case KW_body_range: f.get (body_info[0]); break; 928 case KW_body_range: slot[body_range] .info = f.get_sint32 (); break;
902 case KW_body_arm: f.get (body_info[1]); break; 929 case KW_body_shield: slot[body_shield] .info = f.get_sint32 (); break;
903 case KW_body_torso: f.get (body_info[2]); break; 930 case KW_body_combat: slot[body_combat] .info = f.get_sint32 (); break;
904 case KW_body_head: f.get (body_info[3]); break; 931 case KW_body_arm: slot[body_arm] .info = f.get_sint32 (); break;
905 case KW_body_neck: f.get (body_info[4]); break; 932 case KW_body_torso: slot[body_torso] .info = f.get_sint32 (); break;
906 case KW_body_skill: f.get (body_info[5]); break; 933 case KW_body_head: slot[body_head] .info = f.get_sint32 (); break;
907 case KW_body_finger: f.get (body_info[6]); break; 934 case KW_body_neck: slot[body_neck] .info = f.get_sint32 (); break;
908 case KW_body_shoulder: f.get (body_info[7]); break; 935 case KW_body_skill: slot[body_skill] .info = f.get_sint32 (); break;
909 case KW_body_foot: f.get (body_info[8]); break; 936 case KW_body_finger: slot[body_finger] .info = f.get_sint32 (); break;
910 case KW_body_hand: f.get (body_info[9]); break; 937 case KW_body_shoulder: slot[body_shoulder].info = f.get_sint32 (); break;
911 case KW_body_wrist: f.get (body_info[10]); break; 938 case KW_body_foot: slot[body_foot] .info = f.get_sint32 (); break;
912 case KW_body_waist: f.get (body_info[11]); break; 939 case KW_body_hand: slot[body_hand] .info = f.get_sint32 (); break;
940 case KW_body_wrist: slot[body_wrist] .info = f.get_sint32 (); break;
941 case KW_body_waist: slot[body_waist] .info = f.get_sint32 (); break;
913 case KW_can_apply: 942 case KW_can_apply:
914 break; 943 break;
915 944
916 case KW_connected: 945 case KW_connected:
917 add_button_link (this, map, f.get_sint32 ()); 946 add_button_link (this, map, f.get_sint32 ());
918 break; 947 break;
919 948
920 case KW_randomitems: 949 case KW_randomitems:
921 randomitems = find_treasurelist (f.get_str ()); 950 if (f.get_str ())
951 {
952 randomitems =
953 loading_arch
954 ? treasurelist::get (f.get_str ())
955 : treasurelist::find (f.get_str ());
956
922 //if (!randomitems) 957 if (!randomitems)
923 // LOG (llevError, "%s uses unknown randomitems '%s'.\n", debug_desc (), f.get_str ()); 958 LOG (llevError, "%s uses unknown randomitems '%s'.\n", debug_desc (), f.get_str ());
959 }
960 else
961 randomitems = 0;
924 break; 962 break;
925 963
926 case KW_msg: 964 case KW_msg:
927 f.get_ml (KW_endmsg, msg); 965 f.get_ml (KW_endmsg, msg);
928 //TODO: allow longer messages 966 //TODO: allow longer messages
947 case KW_editable: 985 case KW_editable:
948 case KW_editor_folder: 986 case KW_editor_folder:
949 break; 987 break;
950 988
951 case KW_end: 989 case KW_end:
952 check_loaded_object (this);
953
954 if (!arch_init) 990 if (!loading_arch)
955 instantiate (); 991 instantiate ();
956 992
957 f.next (); 993 f.next ();
958 return true; 994 return true;
959 995
985 arch = archetype::find ("earthwall"); 1021 arch = archetype::find ("earthwall");
986 } 1022 }
987 1023
988 assert (arch); //D maybe use exception handling of sorts? 1024 assert (arch); //D maybe use exception handling of sorts?
989 1025
1026 f.next ();
1027
990 object *op = object::create (); 1028 object *op = object::create ();
991 1029
992 op->map = map; 1030 op->map = map;
993 op->arch = arch;
994 arch->clone.copy_to (op); 1031 arch->clone.copy_to (op);
995 // copy_to activates, this should be fixed properly 1032 // copy_to activates, this should be fixed properly
996 op->deactivate (); 1033 op->deactivate ();
997 1034
998 if (!op->parse_kv (f)) 1035 if (!op->parse_kv (f))
999 { 1036 {
1000 delete op; 1037 op->destroy (true);
1001 return 0; 1038 return 0;
1002 } 1039 }
1003 1040
1041 op->post_load_check ();
1004 return op; 1042 return op;
1005} 1043}
1006 1044
1007/* This takes a buffer, scans it for variables, and sets those variables 1045/* This takes a buffer, scans it for variables, and sets those variables
1008 * as appropriate in op. 1046 * as appropriate in op.
1013int 1051int
1014set_variable (object *op, char *buf) 1052set_variable (object *op, char *buf)
1015{ 1053{
1016 object_thawer f (buf, (AV *)0); 1054 object_thawer f (buf, (AV *)0);
1017 1055
1018 f.kw = KW_arch; // special hack so that parse_kv skips 1056 f.next ();
1019 return op->parse_kv (f); 1057 return op->parse_kv (f);
1020} 1058}
1021 1059
1022/* This returns a string of the integer movement type */ 1060/* This returns a string of the integer movement type */
1023#if 0 1061#if 0
1085 * the 15'th element of this array should match that name. 1123 * the 15'th element of this array should match that name.
1086 * If an entry is NULL, that is a flag not to loaded/saved. 1124 * If an entry is NULL, that is a flag not to loaded/saved.
1087 */ 1125 */
1088 static const keyword flag_names [NUM_FLAGS] = { 1126 static const keyword flag_names [NUM_FLAGS] = {
1089 KW_alive, 1127 KW_alive,
1090 KW_wiz,
1091 KW_NULL, 1128 KW_NULL,
1092 KW_NULL, 1129 KW_NULL,
1093 KW_was_wiz, 1130 KW_NULL,
1131 KW_NULL,
1094 KW_applied, 1132 KW_applied,
1095 KW_unpaid, 1133 KW_unpaid,
1096 KW_can_use_shield, 1134 KW_can_use_shield,
1097 KW_no_pick, 1135 KW_no_pick,
1098 KW_NULL, // walk_on 1136 KW_NULL, // walk_on
1104 KW_monster, 1142 KW_monster,
1105 KW_friendly, 1143 KW_friendly,
1106 KW_generator, 1144 KW_generator,
1107 KW_is_thrown, 1145 KW_is_thrown,
1108 KW_auto_apply, 1146 KW_auto_apply,
1109 KW_NULL, // was KW_treasure 1147 KW_treasure_env,
1110 KW_player_sold, 1148 KW_player_sold,
1111 /* 20 */ 1149 /* 20 */
1112 KW_see_invisible, 1150 KW_see_invisible,
1113 KW_can_roll, 1151 KW_can_roll,
1114 KW_overlay_floor, 1152 KW_overlay_floor,
1175 KW_can_use_skill, 1213 KW_can_use_skill,
1176 KW_been_applied, 1214 KW_been_applied,
1177 /* 80 */ 1215 /* 80 */
1178 KW_has_ready_scroll, 1216 KW_has_ready_scroll,
1179 KW_can_use_rod, 1217 KW_can_use_rod,
1180 KW_NULL, 1218 KW_precious,
1181 KW_can_use_horn, 1219 KW_can_use_horn,
1182 KW_make_invisible, 1220 KW_make_invisible,
1183 KW_inv_locked, 1221 KW_inv_locked,
1184 KW_is_wooded, 1222 KW_is_wooded,
1185 KW_is_hilly, 1223 KW_is_hilly,
1251 f.put (KW_msg, KW_endmsg, op->msg); 1289 f.put (KW_msg, KW_endmsg, op->msg);
1252 if (op->lore != tmp->lore) 1290 if (op->lore != tmp->lore)
1253 f.put (KW_lore, KW_endlore, op->lore); 1291 f.put (KW_lore, KW_endlore, op->lore);
1254 1292
1255 CMP_OUT (other_arch); 1293 CMP_OUT (other_arch);
1256 CMP_OUT (face); 1294
1295 if (op->face != tmp->face) f.put (KW_face, op->face ? &faces [op->face] : 0);
1257 1296
1258 if (op->animation_id != tmp->animation_id) 1297 if (op->animation_id != tmp->animation_id)
1259 if (op->animation_id) 1298 if (op->animation_id)
1260 { 1299 {
1261 f.put (KW_animation, animations[GET_ANIM_ID (op)].name); 1300 f.put (KW_animation, animations[GET_ANIM_ID (op)].name);
1358 if (op->flag != tmp->flag) 1397 if (op->flag != tmp->flag)
1359 for (i = 0; i <= NUM_FLAGS; i++) 1398 for (i = 0; i <= NUM_FLAGS; i++)
1360 if (flag_names [i] && op->flag [i] != tmp->flag [i]) 1399 if (flag_names [i] && op->flag [i] != tmp->flag [i])
1361 f.put (flag_names [i], op->flag [i] ? "1" : "0"); 1400 f.put (flag_names [i], op->flag [i] ? "1" : "0");
1362 1401
1363 /* Save body locations */ 1402 // save body locations
1364 for (i = 0; i < NUM_BODY_LOCATIONS; i++) 1403 for (i = 0; i < NUM_BODY_LOCATIONS; i++)
1365 if (op->body_info[i] != tmp->body_info[i]) 1404 if (op->slot[i].info != tmp->slot[i].info)
1366 f.put (body_locations[i].save_name, op->body_info[i]); 1405 f.put (body_locations[i].save_name, op->slot[i].info);
1367} 1406}
1368 1407
1369/* 1408/*
1370 * Dumps all variables in an object to a file. 1409 * Dumps all variables in an object to a file.
1371 * If bit 0 of flag is set, unpaid objects will be saved. As of now, 1410 * If bit 0 of flag is set, unpaid objects will be saved. As of now,
1394 return true; 1433 return true;
1395} 1434}
1396 1435
1397///////////////////////////////////////////////////////////////////////////// 1436/////////////////////////////////////////////////////////////////////////////
1398 1437
1438// generic resource file load,
1439// currently supports: region, treasures, archetypes
1399bool load_resource_file (const char *filename) 1440bool load_resource_file (const char *filename)
1400{ 1441{
1401 object_thawer f (filename); 1442 object_thawer f (filename);
1443
1444 bool success = false;
1445 bool seen_arch = false;
1402 1446
1403 f.next (); 1447 f.next ();
1404 1448
1405 for (;;) 1449 for (;;)
1406 { 1450 {
1407 switch (f.kw) 1451 switch (f.kw)
1408 { 1452 {
1409 case KW_region: 1453 case KW_region:
1410 if (!region::read (f)) 1454 if (!region::read (f))
1411 return false; 1455 goto finish;
1456 break;
1457
1458 case KW_treasure:
1459 case KW_treasureone:
1460 if (!treasurelist::read (f))
1461 goto finish;
1462 break;
1463
1464 case KW_object:
1465 seen_arch = true;
1466 if (!archetype::read (f))
1467 goto finish;
1412 break; 1468 break;
1413 1469
1414 case KW_EOF: 1470 case KW_EOF:
1415 return true; 1471 success = true;
1472 goto finish;
1416 1473
1417 default: 1474 default:
1418 if (!f.parse_error ("resource file")) 1475 if (!f.parse_error ("resource file"))
1419 return false; 1476 goto finish;
1477
1478 f.next ();
1479 break;
1420 } 1480 }
1421
1422 f.next ();
1423 } 1481 }
1482
1483finish:
1484 if (seen_arch)
1485 init_archetype_pointers ();
1486
1487 return success;
1424} 1488}
1425 1489

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines