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.84 by root, Tue May 22 10:49:58 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 */
389#if 0 //TODO
341 if (ip > 2 * op->item_power && ip > (op->item_power + 3)) 390 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); 391 LOG (llevDebug, "Object %s seems to have too low item power? %d > %d\n", debug_desc (), ip, item_power);
392#endif
343 } 393 }
344 394
345 /* Old spellcasting object - need to load in the appropiate object */ 395 /* 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 || 396 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 */ 397 /* 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) 398 ((type == POTION || type == ALTAR) && stats.sp)) && !inv && !loading_arch)
349 { 399 {
350 /* Fireall is bizarre in that spell type was stored in dam. Rest are 'normal' 400 /* Fireall is bizarre in that spell type was stored in dam. Rest are 'normal'
351 * in that spell was stored in sp. 401 * in that spell was stored in sp.
352 */ 402 */
353 object *tmp = get_archetype (spell_mapping[op->type == FIREWALL ? op->stats.dam : op->stats.sp]); 403 object *tmp = get_archetype (spell_mapping[type == FIREWALL ? stats.dam : stats.sp]);
354 insert_ob_in_ob (tmp, op); 404 insert_ob_in_ob (tmp, this);
355 op->randomitems = NULL; /* So another spell isn't created for this object */ 405 randomitems = NULL; /* So another spell isn't created for this object */
356 } 406 }
357 407
358 /* spellbooks & runes use slaying. But not to arch name, but to spell name */ 408 /* 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) 409 if ((type == SPELLBOOK || type == RUNE) && slaying && !inv && !loading_arch)
360 { 410 {
361 object *tmp = get_archetype_by_object_name (op->slaying); 411 object *tmp = get_archetype_by_object_name (slaying);
362 insert_ob_in_ob (tmp, op); 412 insert_ob_in_ob (tmp, this);
363 op->randomitems = NULL; /* So another spell isn't created for this object */ 413 randomitems = NULL; /* So another spell isn't created for this object */
364 /* without this, value is all screwed up */ 414 /* without this, value is all screwed up */
365 op->value = op->arch->clone.value * op->inv->value; 415 value = arch->clone.value * inv->value;
366 } 416 }
367 417
368 if (QUERY_FLAG (op, FLAG_MONSTER)) 418 if (QUERY_FLAG (this, FLAG_MONSTER))
369 { 419 {
370 if (op->stats.hp > op->stats.maxhp) 420 if (stats.hp > stats.maxhp)
371 { 421 {
372 LOG (llevDebug, "Monster %s has hp set higher than maxhp (%d>%d)\n", op->debug_desc (), op->stats.hp, op->stats.maxhp); 422 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; 423 stats.maxhp = stats.hp;
374 } 424 }
375 425
376 /* The archs just need to be updated for this */ 426 /* The archs just need to be updated for this */
377 if (op->move_type == 0) 427 if (move_type == 0)
378 op->move_type = MOVE_WALK; 428 move_type = MOVE_WALK;
379 } 429 }
380 430
381 if ((QUERY_FLAG (op, FLAG_GENERATOR) && QUERY_FLAG (op, FLAG_CONTENT_ON_GEN)) || op->type == CREATOR || op->type == CONVERTER) 431 if ((QUERY_FLAG (this, FLAG_GENERATOR) && QUERY_FLAG (this, FLAG_CONTENT_ON_GEN)) || type == CREATOR || type == CONVERTER)
382 { 432 {
383 /* Object will duplicate it's content as part of the 433 /* Object will duplicate it's content as part of the
384 * generation process. To do this, we must flag inventory 434 * generation process. To do this, we must flag inventory
385 * so it remains unevaluated concerning the randomitems and 435 * so it remains unevaluated concerning the randomitems and
386 * the living (a demonlord shouldn't cast from inside generator!) 436 * the living (a demonlord shouldn't cast from inside generator!)
387 */ 437 */
388 flag_inv (op, FLAG_IS_A_TEMPLATE); 438 flag_inv (this, FLAG_IS_A_TEMPLATE);
389 } 439 }
390 440
391 /* Handle player movers. We use move_type for player movers 441 /* Handle player movers. We use move_type for player movers
392 * because they operate on their own time (move_on 442 * because they operate on their own time (move_on
393 * would potentially cause them to be triggered when someone steps 443 * would potentially cause them to be triggered when someone steps
394 * on them). If move_type is set, presume person knows what they 444 * on them). If move_type is set, presume person knows what they
395 * are doing, otherwise, set move_type based on maxhp value. 445 * are doing, otherwise, set move_type based on maxhp value.
396 */ 446 */
397 if (op->type == PLAYERMOVER) 447 if (type == PLAYERMOVER)
398 { 448 {
399 if (!op->move_type) 449 if (!move_type)
400 { 450 {
401 if (op->stats.maxhp) 451 if (stats.maxhp)
402 { 452 {
403 op->move_type = MOVE_ALL; 453 move_type = MOVE_ALL;
404 op->stats.maxhp = 0; 454 stats.maxhp = 0;
405 } 455 }
406 else 456 else
407 op->move_type = MOVE_WALK; 457 move_type = MOVE_WALK;
408 } 458 }
409 } 459 }
410
411} 460}
412 461
413static void 462static void
414set_move (MoveType & mt, const char *str) 463set_move (MoveType &mt, const char *str)
415{ 464{
465 static const struct flagstr {
466 const char *name;
467 MoveType flags;
468 } move_flags[] = {
469 { "walk" , MOVE_WALK },
470 { "flying" , MOVE_FLY_LOW | MOVE_FLY_HIGH },
471 { "fly_low" , MOVE_FLY_LOW },
472 { "fly_high", MOVE_FLY_HIGH },
473 { "swim" , MOVE_SWIM },
474 { "boat" , MOVE_BOAT },
475 { "ship" , MOVE_SHIP },
476 { "all" , MOVE_ALL },
477 };
478
416 if (!str) 479 if (!str)
417 { 480 {
418 mt = 0; 481 mt = 0;
419 return; 482 return;
420 } 483 }
427 490
428 mt = 0; 491 mt = 0;
429 492
430 for (str = strtok ((char *) str, " "); str; str = strtok (0, " ")) 493 for (str = strtok ((char *) str, " "); str; str = strtok (0, " "))
431 { 494 {
432 if (!strcasecmp (str, "all")) 495 bool negate = 0;
433 mt |= MOVE_ALL; 496
434 else 497 if (*str == '-')
435 { 498 {
436 int i, negate = 0; 499 negate = 1;
500 str++;
501 }
437 502
438 if (*str == '-') 503 for (const flagstr *f = move_flags; f < move_flags + sizeof (move_flags) / sizeof (move_flags [0]); ++f)
504 {
505 if (!strcmp (f->name, str))
439 { 506 {
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) 507 if (negate)
449 mt &= ~(1 << i); 508 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 509 else
471 LOG (llevDebug, "common/loader.l: set_move - unknown move string '%s'\n", str); 510 mt |= f->flags;
511
512 goto next;
472 } 513 }
473 } 514 }
515
516 LOG (llevDebug, "common/loader.C: set_move - unknown move string '%s'\n", str);
517
518next: ;
474 } 519 }
475} 520}
476 521
477#define GET_FLAG(op,flag) \ 522#define GET_FLAG(op,flag) \
478 if (f.get_sint32 ()) \ 523 if (f.get_sint32 ()) \
481 CLEAR_FLAG (op, flag) \ 526 CLEAR_FLAG (op, flag) \
482 527
483bool 528bool
484object::parse_kv (object_thawer &f) 529object::parse_kv (object_thawer &f)
485{ 530{
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; 531 object *op_inv = inv;
494 532
495 for (;;) 533 for (;;)
496 { 534 {
497 switch (f.kw) 535 switch (f.kw)
559 } 597 }
560 } 598 }
561 continue; 599 continue;
562 600
563 case KW_other_arch: 601 case KW_other_arch:
602 other_arch =
603 loading_arch
604 ? archetype::get (f.get_str ())
564 other_arch = archetype::find (f.get_str ()); 605 : archetype::find (f.get_str ());
606
607 if (!other_arch)
608 LOG (llevError, "%s uses unknown other_arch '%s'.\n", debug_desc (), f.get_str ());
565 break; 609 break;
566 610
567 case KW_animation: 611 case KW_animation:
568 { 612 {
569 CLEAR_FLAG (this, FLAG_ANIMATE); 613 CLEAR_FLAG (this, FLAG_ANIMATE);
595 move_slow |= MOVE_WALK; 639 move_slow |= MOVE_WALK;
596 f.get (move_slow_penalty); 640 f.get (move_slow_penalty);
597 break; 641 break;
598 642
599 case KW_face: 643 case KW_face:
600 face = &new_faces[FindFace (f.get_str (), 0)]; 644 face = face_find (f.get_str ());
601 break; 645 break;
602 646
603 case KW_x: f.get (x); break; 647 case KW_x: f.get (x); break;
604 case KW_y: f.get (y); break; 648 case KW_y: f.get (y); break;
605 649
730 GET_FLAG (this, FLAG_IDENTIFIED); 774 GET_FLAG (this, FLAG_IDENTIFIED);
731 //TODO: move to check_object or so 775 //TODO: move to check_object or so
732 if (QUERY_FLAG (this, FLAG_IDENTIFIED)) 776 if (QUERY_FLAG (this, FLAG_IDENTIFIED))
733 CLEAR_FLAG (this, FLAG_KNOWN_MAGICAL); 777 CLEAR_FLAG (this, FLAG_KNOWN_MAGICAL);
734 778
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; 779 break;
752 780
753 case KW_friendly: 781 case KW_friendly:
754 if (f.get_sint32 ()) 782 if (f.get_sint32 ())
755 if (type != PLAYER) 783 if (type != PLAYER)
788 case KW_reflect_missile: GET_FLAG (this, FLAG_REFL_MISSILE); break; 816 case KW_reflect_missile: GET_FLAG (this, FLAG_REFL_MISSILE); break;
789 case KW_reflect_spell: GET_FLAG (this, FLAG_REFL_SPELL); break; 817 case KW_reflect_spell: GET_FLAG (this, FLAG_REFL_SPELL); break;
790 case KW_no_magic: GET_FLAG (this, FLAG_NO_MAGIC); break; 818 case KW_no_magic: GET_FLAG (this, FLAG_NO_MAGIC); break;
791 case KW_no_drop: GET_FLAG (this, FLAG_NO_DROP); break; 819 case KW_no_drop: GET_FLAG (this, FLAG_NO_DROP); break;
792 case KW_random_movement: GET_FLAG (this, FLAG_RANDOM_MOVE); break; 820 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; 821 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; 822 case KW_is_lightable: GET_FLAG (this, FLAG_IS_LIGHTABLE); break;
796 case KW_tear_down: GET_FLAG (this, FLAG_TEAR_DOWN); break; 823 case KW_tear_down: GET_FLAG (this, FLAG_TEAR_DOWN); break;
797 case KW_can_use_shield: GET_FLAG (this, FLAG_USE_SHIELD); break; 824 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; 825 case KW_can_cast_spell: GET_FLAG (this, FLAG_CAST_SPELL); break;
841 case KW_no_steal: GET_FLAG (this, FLAG_NO_STEAL); break; 868 case KW_no_steal: GET_FLAG (this, FLAG_NO_STEAL); break;
842 case KW_one_hit: GET_FLAG (this, FLAG_ONE_HIT); break; 869 case KW_one_hit: GET_FLAG (this, FLAG_ONE_HIT); break;
843 case KW_berserk: GET_FLAG (this, FLAG_BERSERK); break; 870 case KW_berserk: GET_FLAG (this, FLAG_BERSERK); break;
844 case KW_is_buildable: GET_FLAG (this, FLAG_IS_BUILDABLE); break; 871 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; 872 case KW_destroy_on_death: GET_FLAG (this, FLAG_DESTROY_ON_DEATH); break;
873 case KW_treasure_env: GET_FLAG (this, FLAG_TREASURE_ENV); break;
874 case KW_precious: GET_FLAG (this, FLAG_PRECIOUS); break;
846 875
847 case KW_armour: f.get (resist[ATNR_PHYSICAL]); break; 876 case KW_armour: f.get (resist[ATNR_PHYSICAL]); break;
848 case KW_resist_physical: f.get (resist[ATNR_PHYSICAL]); break; 877 case KW_resist_physical: f.get (resist[ATNR_PHYSICAL]); break;
849 case KW_resist_magic: f.get (resist[ATNR_MAGIC]); break; 878 case KW_resist_magic: f.get (resist[ATNR_MAGIC]); break;
850 case KW_resist_fire: f.get (resist[ATNR_FIRE]); break; 879 case KW_resist_fire: f.get (resist[ATNR_FIRE]); break;
886 case KW_glow_radius: f.get (glow_radius); break; 915 case KW_glow_radius: f.get (glow_radius); break;
887 case KW_weapontype: f.get (weapontype); break; 916 case KW_weapontype: f.get (weapontype); break;
888 case KW_tooltype: f.get (tooltype); break; 917 case KW_tooltype: f.get (tooltype); break;
889 case KW_casting_time: f.get (casting_time); break; 918 case KW_casting_time: f.get (casting_time); break;
890 case KW_elevation: f.get (elevation); break; 919 case KW_elevation: f.get (elevation); break;
891 case KW_smoothlevel: f.get (smoothlevel); break; 920 case KW_smoothlevel: f.get (smoothlevel); smoothlevel = clamp (smoothlevel, 0, 255); break;
892 case KW_client_type: f.get (client_type); break; 921 case KW_client_type: f.get (client_type); break;
893 case KW_duration: f.get (duration); break; 922 case KW_duration: f.get (duration); break;
894 case KW_range: f.get (range); break; 923 case KW_range: f.get (range); break;
895 case KW_range_modifier: f.get (range_modifier); break; 924 case KW_range_modifier: f.get (range_modifier); break;
896 case KW_dam_modifier: f.get (dam_modifier); break; 925 case KW_dam_modifier: f.get (dam_modifier); break;
897 case KW_duration_modifier: f.get (duration_modifier); break; 926 case KW_duration_modifier: f.get (duration_modifier); break;
898 927
899 //TODO: mechanism to ensure that KW_xxx is consecutive needed from include/preprocess 928 //TODO: mechanism to ensure that KW_xxx is consecutive needed from include/preprocess
900 //TODO: parse from other include files 929 //TODO: parse from other include files
901 case KW_body_range: f.get (body_info[0]); break; 930 case KW_body_range: slot[body_range] .info = f.get_sint32 (); break;
902 case KW_body_arm: f.get (body_info[1]); break; 931 case KW_body_shield: slot[body_shield] .info = f.get_sint32 (); break;
903 case KW_body_torso: f.get (body_info[2]); break; 932 case KW_body_combat: slot[body_combat] .info = f.get_sint32 (); break;
904 case KW_body_head: f.get (body_info[3]); break; 933 case KW_body_arm: slot[body_arm] .info = f.get_sint32 (); break;
905 case KW_body_neck: f.get (body_info[4]); break; 934 case KW_body_torso: slot[body_torso] .info = f.get_sint32 (); break;
906 case KW_body_skill: f.get (body_info[5]); break; 935 case KW_body_head: slot[body_head] .info = f.get_sint32 (); break;
907 case KW_body_finger: f.get (body_info[6]); break; 936 case KW_body_neck: slot[body_neck] .info = f.get_sint32 (); break;
908 case KW_body_shoulder: f.get (body_info[7]); break; 937 case KW_body_skill: slot[body_skill] .info = f.get_sint32 (); break;
909 case KW_body_foot: f.get (body_info[8]); break; 938 case KW_body_finger: slot[body_finger] .info = f.get_sint32 (); break;
910 case KW_body_hand: f.get (body_info[9]); break; 939 case KW_body_shoulder: slot[body_shoulder].info = f.get_sint32 (); break;
911 case KW_body_wrist: f.get (body_info[10]); break; 940 case KW_body_foot: slot[body_foot] .info = f.get_sint32 (); break;
912 case KW_body_waist: f.get (body_info[11]); break; 941 case KW_body_hand: slot[body_hand] .info = f.get_sint32 (); break;
942 case KW_body_wrist: slot[body_wrist] .info = f.get_sint32 (); break;
943 case KW_body_waist: slot[body_waist] .info = f.get_sint32 (); break;
913 case KW_can_apply: 944 case KW_can_apply:
914 break; 945 break;
915 946
916 case KW_connected: 947 case KW_connected:
917 add_button_link (this, map, f.get_sint32 ()); 948 add_button_link (this, map, f.get_sint32 ());
918 break; 949 break;
919 950
920 case KW_randomitems: 951 case KW_randomitems:
921 randomitems = find_treasurelist (f.get_str ()); 952 if (f.get_str ())
953 {
954 randomitems =
955 loading_arch
956 ? treasurelist::get (f.get_str ())
957 : treasurelist::find (f.get_str ());
958
922 //if (!randomitems) 959 if (!randomitems)
923 // LOG (llevError, "%s uses unknown randomitems '%s'.\n", debug_desc (), f.get_str ()); 960 LOG (llevError, "%s uses unknown randomitems '%s'.\n", debug_desc (), f.get_str ());
961 }
962 else
963 randomitems = 0;
924 break; 964 break;
925 965
926 case KW_msg: 966 case KW_msg:
927 f.get_ml (KW_endmsg, msg); 967 f.get_ml (KW_endmsg, msg);
928 //TODO: allow longer messages 968 //TODO: allow longer messages
947 case KW_editable: 987 case KW_editable:
948 case KW_editor_folder: 988 case KW_editor_folder:
949 break; 989 break;
950 990
951 case KW_end: 991 case KW_end:
952 check_loaded_object (this);
953
954 if (!arch_init) 992 if (!loading_arch)
955 instantiate (); 993 instantiate ();
956 994
957 f.next (); 995 f.next ();
958 return true; 996 return true;
959 997
985 arch = archetype::find ("earthwall"); 1023 arch = archetype::find ("earthwall");
986 } 1024 }
987 1025
988 assert (arch); //D maybe use exception handling of sorts? 1026 assert (arch); //D maybe use exception handling of sorts?
989 1027
1028 f.next ();
1029
990 object *op = object::create (); 1030 object *op = object::create ();
991 1031
992 op->map = map; 1032 op->map = map;
993 op->arch = arch;
994 arch->clone.copy_to (op); 1033 arch->clone.copy_to (op);
995 // copy_to activates, this should be fixed properly 1034 // copy_to activates, this should be fixed properly
996 op->deactivate (); 1035 op->deactivate ();
997 1036
998 if (!op->parse_kv (f)) 1037 if (!op->parse_kv (f))
999 { 1038 {
1000 delete op; 1039 op->destroy (true);
1001 return 0; 1040 return 0;
1002 } 1041 }
1003 1042
1043 op->post_load_check ();
1004 return op; 1044 return op;
1005} 1045}
1006 1046
1007/* This takes a buffer, scans it for variables, and sets those variables 1047/* This takes a buffer, scans it for variables, and sets those variables
1008 * as appropriate in op. 1048 * as appropriate in op.
1013int 1053int
1014set_variable (object *op, char *buf) 1054set_variable (object *op, char *buf)
1015{ 1055{
1016 object_thawer f (buf, (AV *)0); 1056 object_thawer f (buf, (AV *)0);
1017 1057
1018 f.kw = KW_arch; // special hack so that parse_kv skips 1058 f.next ();
1019 return op->parse_kv (f); 1059 return op->parse_kv (f);
1020} 1060}
1021 1061
1022/* This returns a string of the integer movement type */ 1062/* This returns a string of the integer movement type */
1023#if 0 1063#if 0
1085 * the 15'th element of this array should match that name. 1125 * 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. 1126 * If an entry is NULL, that is a flag not to loaded/saved.
1087 */ 1127 */
1088 static const keyword flag_names [NUM_FLAGS] = { 1128 static const keyword flag_names [NUM_FLAGS] = {
1089 KW_alive, 1129 KW_alive,
1090 KW_wiz,
1091 KW_NULL, 1130 KW_NULL,
1092 KW_NULL, 1131 KW_NULL,
1093 KW_was_wiz, 1132 KW_NULL,
1133 KW_NULL,
1094 KW_applied, 1134 KW_applied,
1095 KW_unpaid, 1135 KW_unpaid,
1096 KW_can_use_shield, 1136 KW_can_use_shield,
1097 KW_no_pick, 1137 KW_no_pick,
1098 KW_NULL, // walk_on 1138 KW_NULL, // walk_on
1104 KW_monster, 1144 KW_monster,
1105 KW_friendly, 1145 KW_friendly,
1106 KW_generator, 1146 KW_generator,
1107 KW_is_thrown, 1147 KW_is_thrown,
1108 KW_auto_apply, 1148 KW_auto_apply,
1109 KW_NULL, // was KW_treasure 1149 KW_treasure_env,
1110 KW_player_sold, 1150 KW_player_sold,
1111 /* 20 */ 1151 /* 20 */
1112 KW_see_invisible, 1152 KW_see_invisible,
1113 KW_can_roll, 1153 KW_can_roll,
1114 KW_overlay_floor, 1154 KW_overlay_floor,
1175 KW_can_use_skill, 1215 KW_can_use_skill,
1176 KW_been_applied, 1216 KW_been_applied,
1177 /* 80 */ 1217 /* 80 */
1178 KW_has_ready_scroll, 1218 KW_has_ready_scroll,
1179 KW_can_use_rod, 1219 KW_can_use_rod,
1180 KW_NULL, 1220 KW_precious,
1181 KW_can_use_horn, 1221 KW_can_use_horn,
1182 KW_make_invisible, 1222 KW_make_invisible,
1183 KW_inv_locked, 1223 KW_inv_locked,
1184 KW_is_wooded, 1224 KW_is_wooded,
1185 KW_is_hilly, 1225 KW_is_hilly,
1251 f.put (KW_msg, KW_endmsg, op->msg); 1291 f.put (KW_msg, KW_endmsg, op->msg);
1252 if (op->lore != tmp->lore) 1292 if (op->lore != tmp->lore)
1253 f.put (KW_lore, KW_endlore, op->lore); 1293 f.put (KW_lore, KW_endlore, op->lore);
1254 1294
1255 CMP_OUT (other_arch); 1295 CMP_OUT (other_arch);
1256 CMP_OUT (face); 1296
1297 if (op->face != tmp->face) f.put (KW_face, op->face ? &faces [op->face] : 0);
1257 1298
1258 if (op->animation_id != tmp->animation_id) 1299 if (op->animation_id != tmp->animation_id)
1259 if (op->animation_id) 1300 if (op->animation_id)
1260 { 1301 {
1261 f.put (KW_animation, animations[GET_ANIM_ID (op)].name); 1302 f.put (KW_animation, animations[GET_ANIM_ID (op)].name);
1358 if (op->flag != tmp->flag) 1399 if (op->flag != tmp->flag)
1359 for (i = 0; i <= NUM_FLAGS; i++) 1400 for (i = 0; i <= NUM_FLAGS; i++)
1360 if (flag_names [i] && op->flag [i] != tmp->flag [i]) 1401 if (flag_names [i] && op->flag [i] != tmp->flag [i])
1361 f.put (flag_names [i], op->flag [i] ? "1" : "0"); 1402 f.put (flag_names [i], op->flag [i] ? "1" : "0");
1362 1403
1363 /* Save body locations */ 1404 // save body locations
1364 for (i = 0; i < NUM_BODY_LOCATIONS; i++) 1405 for (i = 0; i < NUM_BODY_LOCATIONS; i++)
1365 if (op->body_info[i] != tmp->body_info[i]) 1406 if (op->slot[i].info != tmp->slot[i].info)
1366 f.put (body_locations[i].save_name, op->body_info[i]); 1407 f.put (body_locations[i].save_name, op->slot[i].info);
1367} 1408}
1368 1409
1369/* 1410/*
1370 * Dumps all variables in an object to a file. 1411 * 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, 1412 * If bit 0 of flag is set, unpaid objects will be saved. As of now,
1394 return true; 1435 return true;
1395} 1436}
1396 1437
1397///////////////////////////////////////////////////////////////////////////// 1438/////////////////////////////////////////////////////////////////////////////
1398 1439
1440// generic resource file load,
1441// currently supports: region, treasures, archetypes
1399bool load_resource_file (const char *filename) 1442bool load_resource_file (const char *filename)
1400{ 1443{
1401 object_thawer f (filename); 1444 object_thawer f (filename);
1445
1446 bool success = false;
1447 bool seen_arch = false;
1402 1448
1403 f.next (); 1449 f.next ();
1404 1450
1405 for (;;) 1451 for (;;)
1406 { 1452 {
1407 switch (f.kw) 1453 switch (f.kw)
1408 { 1454 {
1409 case KW_region: 1455 case KW_region:
1410 if (!region::read (f)) 1456 if (!region::read (f))
1411 return false; 1457 goto finish;
1458 break;
1459
1460 case KW_treasure:
1461 case KW_treasureone:
1462 if (!treasurelist::read (f))
1463 goto finish;
1464 break;
1465
1466 case KW_object:
1467 seen_arch = true;
1468 if (!archetype::read (f))
1469 goto finish;
1412 break; 1470 break;
1413 1471
1414 case KW_EOF: 1472 case KW_EOF:
1415 return true; 1473 success = true;
1474 goto finish;
1416 1475
1417 default: 1476 default:
1418 if (!f.parse_error ("resource file")) 1477 if (!f.parse_error ("resource file"))
1419 return false; 1478 goto finish;
1479
1480 f.next ();
1481 break;
1420 } 1482 }
1421
1422 f.next ();
1423 } 1483 }
1484
1485finish:
1486 if (seen_arch)
1487 init_archetype_pointers ();
1488
1489 return success;
1424} 1490}
1425 1491

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines