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.65 by root, Wed Mar 14 04:12:27 2007 UTC vs.
Revision 1.71 by root, Tue Apr 17 18:59:05 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 },
473 CLEAR_FLAG (op, flag) \ 473 CLEAR_FLAG (op, flag) \
474 474
475bool 475bool
476object::parse_kv (object_thawer &f) 476object::parse_kv (object_thawer &f)
477{ 477{
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; 478 object *op_inv = inv;
486 479
487 for (;;) 480 for (;;)
488 { 481 {
489 switch (f.kw) 482 switch (f.kw)
551 } 544 }
552 } 545 }
553 continue; 546 continue;
554 547
555 case KW_other_arch: 548 case KW_other_arch:
549 other_arch =
550 loading_arch
551 ? archetype::get (f.get_str ())
556 other_arch = archetype::find (f.get_str ()); 552 : archetype::find (f.get_str ());
553
554 if (!other_arch)
555 LOG (llevError, "%s uses unknown other_arch '%s'.\n", debug_desc (), f.get_str ());
557 break; 556 break;
558 557
559 case KW_animation: 558 case KW_animation:
560 { 559 {
561 CLEAR_FLAG (this, FLAG_ANIMATE); 560 CLEAR_FLAG (this, FLAG_ANIMATE);
908 case KW_connected: 907 case KW_connected:
909 add_button_link (this, map, f.get_sint32 ()); 908 add_button_link (this, map, f.get_sint32 ());
910 break; 909 break;
911 910
912 case KW_randomitems: 911 case KW_randomitems:
913 randomitems = find_treasurelist (f.get_str ()); 912 if (f.get_str ())
913 {
914 randomitems =
915 loading_arch
916 ? treasurelist::get (f.get_str ())
917 : treasurelist::find (f.get_str ());
918
914 //if (!randomitems) 919 if (!randomitems)
915 // LOG (llevError, "%s uses unknown randomitems '%s'.\n", debug_desc (), f.get_str ()); 920 LOG (llevError, "%s uses unknown randomitems '%s'.\n", debug_desc (), f.get_str ());
921 }
916 break; 922 break;
917 923
918 case KW_msg: 924 case KW_msg:
919 f.get_ml (KW_endmsg, msg); 925 f.get_ml (KW_endmsg, msg);
920 //TODO: allow longer messages 926 //TODO: allow longer messages
941 break; 947 break;
942 948
943 case KW_end: 949 case KW_end:
944 check_loaded_object (this); 950 check_loaded_object (this);
945 951
946 if (!arch_init) 952 if (!loading_arch)
947 instantiate (); 953 instantiate ();
948 954
949 f.next (); 955 f.next ();
950 return true; 956 return true;
951 957
977 arch = archetype::find ("earthwall"); 983 arch = archetype::find ("earthwall");
978 } 984 }
979 985
980 assert (arch); //D maybe use exception handling of sorts? 986 assert (arch); //D maybe use exception handling of sorts?
981 987
988 f.next ();
989
982 object *op = object::create (); 990 object *op = object::create ();
983 991
984 op->map = map; 992 op->map = map;
985 op->arch = arch;
986 arch->clone.copy_to (op); 993 arch->clone.copy_to (op);
987 // copy_to activates, this should be fixed properly 994 // copy_to activates, this should be fixed properly
988 op->deactivate (); 995 op->deactivate ();
989 996
990 if (!op->parse_kv (f)) 997 if (!op->parse_kv (f))
991 { 998 {
992 delete op; 999 op->destroy (true);
993 return 0; 1000 return 0;
994 } 1001 }
995 1002
996 return op; 1003 return op;
997} 1004}
1005int 1012int
1006set_variable (object *op, char *buf) 1013set_variable (object *op, char *buf)
1007{ 1014{
1008 object_thawer f (buf, (AV *)0); 1015 object_thawer f (buf, (AV *)0);
1009 1016
1010 f.kw = KW_arch; // special hack so that parse_kv skips 1017 f.next ();
1011 return op->parse_kv (f); 1018 return op->parse_kv (f);
1012} 1019}
1013 1020
1014/* This returns a string of the integer movement type */ 1021/* This returns a string of the integer movement type */
1015#if 0 1022#if 0
1243 f.put (KW_msg, KW_endmsg, op->msg); 1250 f.put (KW_msg, KW_endmsg, op->msg);
1244 if (op->lore != tmp->lore) 1251 if (op->lore != tmp->lore)
1245 f.put (KW_lore, KW_endlore, op->lore); 1252 f.put (KW_lore, KW_endlore, op->lore);
1246 1253
1247 CMP_OUT (other_arch); 1254 CMP_OUT (other_arch);
1248 CMP_OUT (face); 1255
1256 if (op->face != tmp->face) f.put (KW_face, op->face ? &faces [op->face] : 0);
1249 1257
1250 if (op->animation_id != tmp->animation_id) 1258 if (op->animation_id != tmp->animation_id)
1251 if (op->animation_id) 1259 if (op->animation_id)
1252 { 1260 {
1253 f.put (KW_animation, animations[GET_ANIM_ID (op)].name); 1261 f.put (KW_animation, animations[GET_ANIM_ID (op)].name);
1386 return true; 1394 return true;
1387} 1395}
1388 1396
1389///////////////////////////////////////////////////////////////////////////// 1397/////////////////////////////////////////////////////////////////////////////
1390 1398
1399// generic resource file load,
1400// currently supports: region, treasures, archetypes
1391bool load_resource_file (const char *filename) 1401bool load_resource_file (const char *filename)
1392{ 1402{
1393 object_thawer f (filename); 1403 object_thawer f (filename);
1404
1405 bool success = false;
1406 bool seen_arch = false;
1394 1407
1395 f.next (); 1408 f.next ();
1396 1409
1397 for (;;) 1410 for (;;)
1398 { 1411 {
1399 switch (f.kw) 1412 switch (f.kw)
1400 { 1413 {
1401 case KW_region: 1414 case KW_region:
1402 if (!region::read (f)) 1415 if (!region::read (f))
1403 return false; 1416 goto finish;
1417 break;
1418
1419 case KW_treasure:
1420 case KW_treasureone:
1421 if (!treasurelist::read (f))
1422 goto finish;
1423 break;
1424
1425 case KW_object:
1426 seen_arch = true;
1427 if (!archetype::read (f))
1428 goto finish;
1404 break; 1429 break;
1405 1430
1406 case KW_EOF: 1431 case KW_EOF:
1407 return true; 1432 success = true;
1433 goto finish;
1408 1434
1409 default: 1435 default:
1410 if (!f.parse_error ("resource file")) 1436 if (!f.parse_error ("resource file"))
1411 return false; 1437 goto finish;
1412 } 1438 }
1413
1414 f.next ();
1415 } 1439 }
1440
1441finish:
1442 if (seen_arch)
1443 init_archetype_pointers ();
1444
1445 return success;
1416} 1446}
1417 1447

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines