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.63 by root, Mon Mar 5 15:36:29 2007 UTC vs.
Revision 1.72 by root, Sat Apr 21 12:28:31 2007 UTC

250 "spell_cause_rabies", /* 204 */ 250 "spell_cause_rabies", /* 204 */
251 "spell_glyph", /* 205 */ 251 "spell_glyph", /* 205 */
252 NULL 252 NULL
253}; 253};
254 254
255extern int arch_init; 255extern bool loading_arch;
256 256
257/* 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
258 * 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
259 * 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
260 * 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.
289 /* only do these when program is first run - a bit 289 /* only do these when program is first run - a bit
290 * excessive to do this at every run - most of this is 290 * excessive to do this at every run - most of this is
291 * really just to catch any errors - program will still run, but 291 * really just to catch any errors - program will still run, but
292 * not in the ideal fashion. 292 * not in the ideal fashion.
293 */ 293 */
294 if ((op->type == WEAPON || op->type == BOW) && arch_init) 294 if ((op->type == WEAPON || op->type == BOW) && loading_arch)
295 { 295 {
296 if (!op->skill) 296 if (!op->skill)
297 LOG (llevError, "Weapon %s lacks a skill.\n", op->debug_desc ()); 297 LOG (llevError, "Weapon %s lacks a skill.\n", op->debug_desc ());
298 else if ((!strcmp (op->skill, "one handed weapons") && op->body_info[1] != -1) || 298 else if ((!strcmp (op->skill, "one handed weapons") && op->body_info[1] != -1) ||
299 (!strcmp (op->skill, "two handed weapons") && op->body_info[1] != -2)) 299 (!strcmp (op->skill, "two handed weapons") && op->body_info[1] != -2))
340 } 340 }
341 341
342 /* Old spellcasting object - need to load in the appropiate object */ 342 /* Old spellcasting object - need to load in the appropiate object */
343 if ((op->type == ROD || op->type == WAND || op->type == SCROLL || op->type == HORN || op->type == FIREWALL || 343 if ((op->type == ROD || op->type == WAND || op->type == SCROLL || op->type == HORN || op->type == FIREWALL ||
344 /* POTIONS and ALTARS don't always cast spells, but if they do, update them */ 344 /* POTIONS and ALTARS don't always cast spells, but if they do, update them */
345 ((op->type == POTION || op->type == ALTAR) && op->stats.sp)) && !op->inv && !arch_init) 345 ((op->type == POTION || op->type == ALTAR) && op->stats.sp)) && !op->inv && !loading_arch)
346 { 346 {
347 /* Fireall is bizarre in that spell type was stored in dam. Rest are 'normal' 347 /* Fireall is bizarre in that spell type was stored in dam. Rest are 'normal'
348 * in that spell was stored in sp. 348 * in that spell was stored in sp.
349 */ 349 */
350 object *tmp = get_archetype (spell_mapping[op->type == FIREWALL ? op->stats.dam : op->stats.sp]); 350 object *tmp = get_archetype (spell_mapping[op->type == FIREWALL ? op->stats.dam : op->stats.sp]);
351 insert_ob_in_ob (tmp, op); 351 insert_ob_in_ob (tmp, op);
352 op->randomitems = NULL; /* So another spell isn't created for this object */ 352 op->randomitems = NULL; /* So another spell isn't created for this object */
353 } 353 }
354 354
355 /* spellbooks & runes use slaying. But not to arch name, but to spell name */ 355 /* spellbooks & runes use slaying. But not to arch name, but to spell name */
356 if ((op->type == SPELLBOOK || op->type == RUNE) && op->slaying && !op->inv && !arch_init) 356 if ((op->type == SPELLBOOK || op->type == RUNE) && op->slaying && !op->inv && !loading_arch)
357 { 357 {
358 object *tmp = get_archetype_by_object_name (op->slaying); 358 object *tmp = get_archetype_by_object_name (op->slaying);
359 insert_ob_in_ob (tmp, op); 359 insert_ob_in_ob (tmp, op);
360 op->randomitems = NULL; /* So another spell isn't created for this object */ 360 op->randomitems = NULL; /* So another spell isn't created for this object */
361 /* without this, value is all screwed up */ 361 /* without this, value is all screwed up */
409 409
410static void 410static void
411set_move (MoveType &mt, const char *str) 411set_move (MoveType &mt, const char *str)
412{ 412{
413 static const struct flagstr { 413 static const struct flagstr {
414 char *name; 414 const char *name;
415 MoveType flags; 415 MoveType flags;
416 } move_flags[] = { 416 } move_flags[] = {
417 { "walk" , MOVE_WALK }, 417 { "walk" , MOVE_WALK },
418 { "flying" , MOVE_FLY_LOW | MOVE_FLY_HIGH }, 418 { "flying" , MOVE_FLY_LOW | MOVE_FLY_HIGH },
419 { "fly_low" , MOVE_FLY_LOW }, 419 { "fly_low" , MOVE_FLY_LOW },
420 { "fly_high", MOVE_FLY_HIGH }, 420 { "fly_high", MOVE_FLY_HIGH },
421 { "swim" , MOVE_SWIM }, 421 { "swim" , MOVE_SWIM },
422 { "boat" , MOVE_BOAT }, 422 { "boat" , MOVE_BOAT },
423 { "ship" , MOVE_SHIP },
423 { "all" , MOVE_ALL }, 424 { "all" , MOVE_ALL },
424 }; 425 };
425 426
426 if (!str) 427 if (!str)
427 { 428 {
473 CLEAR_FLAG (op, flag) \ 474 CLEAR_FLAG (op, flag) \
474 475
475bool 476bool
476object::parse_kv (object_thawer &f) 477object::parse_kv (object_thawer &f)
477{ 478{
478 assert (f.kw == KW_object || f.kw == KW_arch);
479
480 if (f.kw == KW_object)
481 f.get (name); // preset name from object name
482
483 f.next ();
484
485 object *op_inv = inv; 479 object *op_inv = inv;
486 480
487 for (;;) 481 for (;;)
488 { 482 {
489 switch (f.kw) 483 switch (f.kw)
551 } 545 }
552 } 546 }
553 continue; 547 continue;
554 548
555 case KW_other_arch: 549 case KW_other_arch:
550 other_arch =
551 loading_arch
552 ? archetype::get (f.get_str ())
556 other_arch = archetype::find (f.get_str ()); 553 : archetype::find (f.get_str ());
554
555 if (!other_arch)
556 LOG (llevError, "%s uses unknown other_arch '%s'.\n", debug_desc (), f.get_str ());
557 break; 557 break;
558 558
559 case KW_animation: 559 case KW_animation:
560 { 560 {
561 CLEAR_FLAG (this, FLAG_ANIMATE); 561 CLEAR_FLAG (this, FLAG_ANIMATE);
587 move_slow |= MOVE_WALK; 587 move_slow |= MOVE_WALK;
588 f.get (move_slow_penalty); 588 f.get (move_slow_penalty);
589 break; 589 break;
590 590
591 case KW_face: 591 case KW_face:
592 face = &new_faces[FindFace (f.get_str (), 0)]; 592 face = face_find (f.get_str ());
593 break; 593 break;
594 594
595 case KW_x: f.get (x); break; 595 case KW_x: f.get (x); break;
596 case KW_y: f.get (y); break; 596 case KW_y: f.get (y); break;
597 597
878 case KW_glow_radius: f.get (glow_radius); break; 878 case KW_glow_radius: f.get (glow_radius); break;
879 case KW_weapontype: f.get (weapontype); break; 879 case KW_weapontype: f.get (weapontype); break;
880 case KW_tooltype: f.get (tooltype); break; 880 case KW_tooltype: f.get (tooltype); break;
881 case KW_casting_time: f.get (casting_time); break; 881 case KW_casting_time: f.get (casting_time); break;
882 case KW_elevation: f.get (elevation); break; 882 case KW_elevation: f.get (elevation); break;
883 case KW_smoothlevel: f.get (smoothlevel); break; 883 case KW_smoothlevel: f.get (smoothlevel); smoothlevel = clamp (smoothlevel, 0, 255); break;
884 case KW_client_type: f.get (client_type); break; 884 case KW_client_type: f.get (client_type); break;
885 case KW_duration: f.get (duration); break; 885 case KW_duration: f.get (duration); break;
886 case KW_range: f.get (range); break; 886 case KW_range: f.get (range); break;
887 case KW_range_modifier: f.get (range_modifier); break; 887 case KW_range_modifier: f.get (range_modifier); break;
888 case KW_dam_modifier: f.get (dam_modifier); break; 888 case KW_dam_modifier: f.get (dam_modifier); break;
908 case KW_connected: 908 case KW_connected:
909 add_button_link (this, map, f.get_sint32 ()); 909 add_button_link (this, map, f.get_sint32 ());
910 break; 910 break;
911 911
912 case KW_randomitems: 912 case KW_randomitems:
913 randomitems = find_treasurelist (f.get_str ()); 913 if (f.get_str ())
914 {
915 randomitems =
916 loading_arch
917 ? treasurelist::get (f.get_str ())
918 : treasurelist::find (f.get_str ());
919
914 //if (!randomitems) 920 if (!randomitems)
915 // LOG (llevError, "%s uses unknown randomitems '%s'.\n", debug_desc (), f.get_str ()); 921 LOG (llevError, "%s uses unknown randomitems '%s'.\n", debug_desc (), f.get_str ());
922 }
916 break; 923 break;
917 924
918 case KW_msg: 925 case KW_msg:
919 f.get_ml (KW_endmsg, msg); 926 f.get_ml (KW_endmsg, msg);
920 //TODO: allow longer messages 927 //TODO: allow longer messages
941 break; 948 break;
942 949
943 case KW_end: 950 case KW_end:
944 check_loaded_object (this); 951 check_loaded_object (this);
945 952
946 if (!arch_init) 953 if (!loading_arch)
947 instantiate (); 954 instantiate ();
948 955
949 f.next (); 956 f.next ();
950 return true; 957 return true;
951 958
977 arch = archetype::find ("earthwall"); 984 arch = archetype::find ("earthwall");
978 } 985 }
979 986
980 assert (arch); //D maybe use exception handling of sorts? 987 assert (arch); //D maybe use exception handling of sorts?
981 988
989 f.next ();
990
982 object *op = object::create (); 991 object *op = object::create ();
983 992
984 op->map = map; 993 op->map = map;
985 op->arch = arch;
986 arch->clone.copy_to (op); 994 arch->clone.copy_to (op);
987 // copy_to activates, this should be fixed properly 995 // copy_to activates, this should be fixed properly
988 op->deactivate (); 996 op->deactivate ();
989 997
990 if (!op->parse_kv (f)) 998 if (!op->parse_kv (f))
991 { 999 {
992 delete op; 1000 op->destroy (true);
993 return 0; 1001 return 0;
994 } 1002 }
995 1003
996 return op; 1004 return op;
997} 1005}
1005int 1013int
1006set_variable (object *op, char *buf) 1014set_variable (object *op, char *buf)
1007{ 1015{
1008 object_thawer f (buf, (AV *)0); 1016 object_thawer f (buf, (AV *)0);
1009 1017
1010 f.kw = KW_arch; // special hack so that parse_kv skips 1018 f.next ();
1011 return op->parse_kv (f); 1019 return op->parse_kv (f);
1012} 1020}
1013 1021
1014/* This returns a string of the integer movement type */ 1022/* This returns a string of the integer movement type */
1015#if 0 1023#if 0
1243 f.put (KW_msg, KW_endmsg, op->msg); 1251 f.put (KW_msg, KW_endmsg, op->msg);
1244 if (op->lore != tmp->lore) 1252 if (op->lore != tmp->lore)
1245 f.put (KW_lore, KW_endlore, op->lore); 1253 f.put (KW_lore, KW_endlore, op->lore);
1246 1254
1247 CMP_OUT (other_arch); 1255 CMP_OUT (other_arch);
1248 CMP_OUT (face); 1256
1257 if (op->face != tmp->face) f.put (KW_face, op->face ? &faces [op->face] : 0);
1249 1258
1250 if (op->animation_id != tmp->animation_id) 1259 if (op->animation_id != tmp->animation_id)
1251 if (op->animation_id) 1260 if (op->animation_id)
1252 { 1261 {
1253 f.put (KW_animation, animations[GET_ANIM_ID (op)].name); 1262 f.put (KW_animation, animations[GET_ANIM_ID (op)].name);
1386 return true; 1395 return true;
1387} 1396}
1388 1397
1389///////////////////////////////////////////////////////////////////////////// 1398/////////////////////////////////////////////////////////////////////////////
1390 1399
1400// generic resource file load,
1401// currently supports: region, treasures, archetypes
1391bool load_resource_file (const char *filename) 1402bool load_resource_file (const char *filename)
1392{ 1403{
1393 object_thawer f (filename); 1404 object_thawer f (filename);
1405
1406 bool success = false;
1407 bool seen_arch = false;
1394 1408
1395 f.next (); 1409 f.next ();
1396 1410
1397 for (;;) 1411 for (;;)
1398 { 1412 {
1399 switch (f.kw) 1413 switch (f.kw)
1400 { 1414 {
1401 case KW_region: 1415 case KW_region:
1402 if (!region::read (f)) 1416 if (!region::read (f))
1403 return false; 1417 goto finish;
1418 break;
1419
1420 case KW_treasure:
1421 case KW_treasureone:
1422 if (!treasurelist::read (f))
1423 goto finish;
1424 break;
1425
1426 case KW_object:
1427 seen_arch = true;
1428 if (!archetype::read (f))
1429 goto finish;
1404 break; 1430 break;
1405 1431
1406 case KW_EOF: 1432 case KW_EOF:
1407 return true; 1433 success = true;
1434 goto finish;
1408 1435
1409 default: 1436 default:
1410 if (!f.parse_error ("resource file")) 1437 if (!f.parse_error ("resource file"))
1411 return false; 1438 goto finish;
1412 } 1439 }
1413
1414 f.next ();
1415 } 1440 }
1441
1442finish:
1443 if (seen_arch)
1444 init_archetype_pointers ();
1445
1446 return success;
1416} 1447}
1417 1448

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines