… | |
… | |
333 | |
333 | |
334 | /* objects now have a materialname. try to patch it in */ |
334 | /* objects now have a materialname. try to patch it in */ |
335 | if (material == MATERIAL_NULL && !(is_weapon () && level > 0)) |
335 | if (material == MATERIAL_NULL && !(is_weapon () && level > 0)) |
336 | select_material (this, map ? map->difficulty : 5); |
336 | select_material (this, map ? map->difficulty : 5); |
337 | |
337 | |
|
|
338 | if (speed < 0.) |
|
|
339 | { |
|
|
340 | flag [FLAG_RANDOM_SPEED] = true; |
|
|
341 | speed = -speed; |
|
|
342 | // speed_left will be randomised in instantiate () and copy_to () |
|
|
343 | } |
|
|
344 | |
338 | /* only do these when program is first run - a bit |
345 | /* only do these when program is first run - a bit |
339 | * excessive to do this at every run - most of this is |
346 | * excessive to do this at every run - most of this is |
340 | * really just to catch any errors - program will still run, but |
347 | * really just to catch any errors - program will still run, but |
341 | * not in the ideal fashion. |
348 | * not in the ideal fashion. |
342 | */ |
349 | */ |
… | |
… | |
480 | animate_object (this, direction); |
487 | animate_object (this, direction); |
481 | } |
488 | } |
482 | } |
489 | } |
483 | |
490 | |
484 | static void |
491 | static void |
485 | set_move (MoveType &mt, const char *str) |
492 | set_move (MoveType &mt, object_thawer &f) |
486 | { |
493 | { |
487 | static const struct flagstr { |
494 | static const struct flagstr { |
488 | const char *name; |
495 | const char *name; |
489 | MoveType flags; |
496 | MoveType flags; |
490 | } move_flags[] = { |
497 | } move_flags[] = { |
… | |
… | |
496 | { "boat" , MOVE_BOAT }, |
503 | { "boat" , MOVE_BOAT }, |
497 | { "ship" , MOVE_SHIP }, |
504 | { "ship" , MOVE_SHIP }, |
498 | { "all" , MOVE_ALL }, |
505 | { "all" , MOVE_ALL }, |
499 | }; |
506 | }; |
500 | |
507 | |
501 | if (!str) |
508 | const char *str = f.get_str (); |
502 | { |
|
|
503 | mt = 0; |
|
|
504 | return; |
|
|
505 | } |
|
|
506 | |
509 | |
507 | if (isdigit (*str)) |
510 | if (!*str || isdigit (*str)) |
508 | { |
511 | { |
509 | mt = atoi (str); |
512 | mt = atoi (str); |
510 | return; |
513 | return; |
511 | } |
514 | } |
512 | |
515 | |
513 | mt = 0; |
516 | mt = 0; |
514 | |
517 | |
515 | for (str = strtok ((char *) str, " "); str; str = strtok (0, " ")) |
518 | for (str = strtok ((char *)str, " "); str; str = strtok (0, " ")) |
516 | { |
519 | { |
517 | bool negate = 0; |
520 | bool negate = 0; |
518 | |
521 | |
519 | if (*str == '-') |
522 | if (*str == '-') |
520 | { |
523 | { |
… | |
… | |
554 | for (;;) |
557 | for (;;) |
555 | { |
558 | { |
556 | switch (f.kw) |
559 | switch (f.kw) |
557 | { |
560 | { |
558 | case KW_uuid: |
561 | case KW_uuid: |
559 | if (const char *s = f.get_str ()) |
|
|
560 | if (!uuid.parse (s)) |
562 | if (!uuid.parse (f.get_str ())) |
561 | { |
563 | { |
562 | f.parse_warn ("unparseable uuid"); |
564 | f.parse_warn ("unparseable uuid"); |
563 | uuid = UUID::gen (); |
565 | uuid = UUID::gen (); |
564 | } |
566 | } |
565 | break; |
567 | break; |
566 | |
568 | |
567 | case KW_oid: |
569 | case KW_oid: |
568 | f.get (this, f.get_sint32 ()); |
570 | f.get (this, f.get_sint32 ()); |
569 | break; |
571 | break; |
… | |
… | |
634 | case KW_animation: |
636 | case KW_animation: |
635 | { |
637 | { |
636 | CLEAR_FLAG (this, FLAG_ANIMATE); |
638 | CLEAR_FLAG (this, FLAG_ANIMATE); |
637 | animation_id = 0; |
639 | animation_id = 0; |
638 | |
640 | |
639 | const char *str = f.get_str (); |
|
|
640 | if (str && (animation_id = find_animation (str))) |
641 | if (f.has_value () && (animation_id = find_animation (f.get_str ()))) |
641 | SET_FLAG (this, FLAG_ANIMATE); //TODO: should not be forced to true here |
642 | SET_FLAG (this, FLAG_ANIMATE); //TODO: should not be forced to true here |
642 | } |
643 | } |
643 | break; |
644 | break; |
644 | |
645 | |
645 | case KW_last_heal: f.get (last_heal); break; |
646 | case KW_last_heal: f.get (last_heal); break; |
646 | case KW_last_sp: f.get (last_sp); break; |
647 | case KW_last_sp: f.get (last_sp); break; |
647 | case KW_last_grace: f.get (last_grace); break; |
648 | case KW_last_grace: f.get (last_grace); break; |
648 | case KW_last_eat: f.get (last_eat); break; |
649 | case KW_last_eat: f.get (last_eat); break; |
|
|
650 | case KW_sl: |
649 | case KW_speed_left: f.get (speed_left); break; |
651 | case KW_speed_left: f.get (speed_left); break; |
650 | |
652 | |
651 | case KW_speed: |
653 | case KW_speed: |
652 | f.get (speed); |
654 | f.get (speed); |
653 | |
655 | |
… | |
… | |
662 | move_slow |= MOVE_WALK; |
664 | move_slow |= MOVE_WALK; |
663 | f.get (move_slow_penalty); |
665 | f.get (move_slow_penalty); |
664 | break; |
666 | break; |
665 | |
667 | |
666 | case KW_face: |
668 | case KW_face: |
667 | face = face_find (f.get_str ()); |
669 | face = f.has_value () ? face_find (f.get_str ()) : blank_face; |
668 | break; |
670 | break; |
669 | |
671 | |
670 | case KW_sound: |
672 | case KW_sound: |
|
|
673 | if (f.has_value ()) |
|
|
674 | { |
671 | sound = sound_find (f.get_str ()); |
675 | sound = sound_find (f.get_str ()); |
672 | if (!sound) |
676 | if (!sound) |
673 | f.parse_warn ("sound not found"); |
677 | f.parse_warn (format ("sound '%s' not found", f.get_str ())); |
|
|
678 | } |
|
|
679 | else |
|
|
680 | sound = 0; |
674 | break; |
681 | break; |
675 | |
682 | |
676 | case KW_sound_destroy: |
683 | case KW_sound_destroy: |
|
|
684 | if (f.has_value ()) |
|
|
685 | { |
677 | sound_destroy = sound_find (f.get_str ()); |
686 | sound_destroy = sound_find (f.get_str ()); |
678 | if (!sound_destroy) |
687 | if (!sound_destroy) |
679 | f.parse_warn ("sound not found"); |
688 | f.parse_warn (format ("sound '%s' not found", f.get_str ())); |
|
|
689 | } |
|
|
690 | else |
|
|
691 | sound_destroy = 0; |
680 | break; |
692 | break; |
681 | |
693 | |
682 | case KW_x: f.get (x); break; |
694 | case KW_x: f.get (x); break; |
683 | case KW_y: f.get (y); break; |
695 | case KW_y: f.get (y); break; |
684 | |
696 | |
… | |
… | |
735 | material = name_to_material (sh); |
747 | material = name_to_material (sh); |
736 | } |
748 | } |
737 | break; |
749 | break; |
738 | |
750 | |
739 | /* These are the new values */ |
751 | /* These are the new values */ |
740 | case KW_move_block: set_move (move_block, f.get_str ()); break; |
752 | case KW_move_block: set_move (move_block, f); break; |
741 | case KW_move_allow: set_move (move_allow, f.get_str ()); break; |
753 | case KW_move_allow: set_move (move_allow, f); break; |
742 | case KW_move_type: set_move (move_type, f.get_str ()); break; |
754 | case KW_move_type: set_move (move_type , f); break; |
743 | case KW_move_on: set_move (move_on, f.get_str ()); break; |
755 | case KW_move_on: set_move (move_on , f); break; |
744 | case KW_move_off: set_move (move_off, f.get_str ()); break; |
756 | case KW_move_off: set_move (move_off , f); break; |
745 | case KW_move_slow: set_move (move_slow, f.get_str ()); break; |
757 | case KW_move_slow: set_move (move_slow , f); break; |
746 | |
758 | |
747 | /* These are all legacy - any new objects should use the move_ .. values */ |
759 | /* These are all legacy - any new objects should use the move_ .. values */ |
748 | case KW_no_pass: |
760 | case KW_no_pass: |
749 | { |
761 | { |
750 | if (f.get_sint32 ()) |
762 | if (f.get_sint32 ()) |
… | |
… | |
912 | case KW_berserk: GET_FLAG (this, FLAG_BERSERK); break; |
924 | case KW_berserk: GET_FLAG (this, FLAG_BERSERK); break; |
913 | case KW_is_buildable: GET_FLAG (this, FLAG_IS_BUILDABLE); break; |
925 | case KW_is_buildable: GET_FLAG (this, FLAG_IS_BUILDABLE); break; |
914 | case KW_destroy_on_death: GET_FLAG (this, FLAG_DESTROY_ON_DEATH); break; |
926 | case KW_destroy_on_death: GET_FLAG (this, FLAG_DESTROY_ON_DEATH); break; |
915 | case KW_treasure_env: GET_FLAG (this, FLAG_TREASURE_ENV); break; |
927 | case KW_treasure_env: GET_FLAG (this, FLAG_TREASURE_ENV); break; |
916 | case KW_precious: GET_FLAG (this, FLAG_PRECIOUS); break; |
928 | case KW_precious: GET_FLAG (this, FLAG_PRECIOUS); break; |
|
|
929 | case KW_random_speed: GET_FLAG (this, FLAG_RANDOM_SPEED); break; |
917 | |
930 | |
918 | case KW_armour: f.get (resist[ATNR_PHYSICAL]); break; |
931 | case KW_armour: f.get (resist[ATNR_PHYSICAL]); break; |
919 | case KW_resist_physical: f.get (resist[ATNR_PHYSICAL]); break; |
932 | case KW_resist_physical: f.get (resist[ATNR_PHYSICAL]); break; |
920 | case KW_resist_magic: f.get (resist[ATNR_MAGIC]); break; |
933 | case KW_resist_magic: f.get (resist[ATNR_MAGIC]); break; |
921 | case KW_resist_fire: f.get (resist[ATNR_FIRE]); break; |
934 | case KW_resist_fire: f.get (resist[ATNR_FIRE]); break; |
… | |
… | |
996 | add_link (map, connected); |
1009 | add_link (map, connected); |
997 | } |
1010 | } |
998 | break; |
1011 | break; |
999 | |
1012 | |
1000 | case KW_randomitems: |
1013 | case KW_randomitems: |
1001 | if (f.get_str ()) |
1014 | if (f.has_value ()) |
1002 | { |
1015 | { |
1003 | randomitems = |
1016 | randomitems = |
1004 | loading_arch |
1017 | loading_arch |
1005 | ? treasurelist::get (f.get_str ()) |
1018 | ? treasurelist::get (f.get_str ()) |
1006 | : treasurelist::find (f.get_str ()); |
1019 | : treasurelist::find (f.get_str ()); |
… | |
… | |
1242 | /* 100 */ |
1255 | /* 100 */ |
1243 | KW_neutral, |
1256 | KW_neutral, |
1244 | KW_no_attack, |
1257 | KW_no_attack, |
1245 | KW_no_damage, |
1258 | KW_no_damage, |
1246 | KW_obj_original, |
1259 | KW_obj_original, |
1247 | KW_NULL, |
1260 | KW_random_speed, |
1248 | KW_activate_on_push, |
1261 | KW_activate_on_push, |
1249 | KW_activate_on_release, |
1262 | KW_activate_on_release, |
1250 | KW_is_water, |
1263 | KW_is_water, |
1251 | KW_use_content_on_gen, |
1264 | KW_use_content_on_gen, |
1252 | KW_NULL, |
1265 | KW_NULL, |
… | |
… | |
1287 | *ptr++ = '\n'; |
1300 | *ptr++ = '\n'; |
1288 | |
1301 | |
1289 | f.alloc (ptr - cur); |
1302 | f.alloc (ptr - cur); |
1290 | } |
1303 | } |
1291 | |
1304 | |
1292 | #define CMP_OUT(v) if (expect_false (op->v != arch->v)) f.put (KW_ ## v, op->v) |
1305 | #define CMP_OUT(v) if (expect_false (op->v != arch->v)) f.put (KW (v), op->v) |
1293 | #define CMP_OUT2(k,v) if (expect_false (op->v != arch->v)) f.put (KW_ ## k, op->v) |
1306 | #define CMP_OUT2(k,v) if (expect_false (op->v != arch->v)) f.put (KW (k), op->v) |
1294 | |
1307 | |
1295 | CMP_OUT (x); |
1308 | CMP_OUT (x); |
1296 | CMP_OUT (y); |
1309 | CMP_OUT (y); |
1297 | |
1310 | |
1298 | CMP_OUT (type); |
1311 | CMP_OUT (type); |
1299 | CMP_OUT (subtype); |
1312 | CMP_OUT (subtype); |
1300 | CMP_OUT (direction); |
1313 | CMP_OUT (direction); |
1301 | |
1314 | |
1302 | CMP_OUT (name); |
1315 | CMP_OUT (name); |
1303 | CMP_OUT (name_pl); |
1316 | CMP_OUT (name_pl); |
1304 | |
|
|
1305 | CMP_OUT (speed); |
1317 | CMP_OUT (speed); |
1306 | |
1318 | |
1307 | // speed_left is a major time-burner, and has good locality, so |
1319 | // speed_left is a major time-burner, and has good locality, so |
1308 | // we use a simple lookup-cache to avoid the very slow printf. |
1320 | // we use a simple lookup-cache to avoid the very slow printf. |
1309 | if (op->speed_left != arch->speed_left) |
1321 | if (op->speed_left != arch->speed_left) |
1310 | { |
1322 | { |
1311 | static double last_speed_left = 0.; |
1323 | static double last_speed_left = 0.; |
1312 | static char last_speed_left_str [256] = "speed_left 0\n"; |
1324 | static char last_speed_left_str [256] = "sl 0\n"; |
1313 | static int last_speed_left_len = sizeof ("speed_left 0\n") - 1; |
1325 | static int last_speed_left_len = sizeof ("sl 0\n") - 1; |
1314 | |
1326 | |
1315 | if (last_speed_left != op->speed_left) |
1327 | if (last_speed_left != op->speed_left) |
1316 | { |
1328 | { |
1317 | last_speed_left = op->speed_left; |
1329 | last_speed_left = op->speed_left; |
1318 | last_speed_left_len = sizeof ("speed_left ") - 1 |
1330 | last_speed_left_len = sizeof ("sl ") - 1 |
1319 | + sprintf (last_speed_left_str + sizeof ("speed_left ") - 1, "%.7g\n", last_speed_left); |
1331 | + sprintf (last_speed_left_str + sizeof ("sl ") - 1, "%.7g\n", last_speed_left); |
1320 | } |
1332 | } |
1321 | |
1333 | |
1322 | f.add (last_speed_left_str, last_speed_left_len); |
1334 | f.add (last_speed_left_str, last_speed_left_len); |
1323 | } |
1335 | } |
1324 | |
1336 | |
… | |
… | |
1329 | |
1341 | |
1330 | CMP_OUT (tag); |
1342 | CMP_OUT (tag); |
1331 | CMP_OUT (custom_name); |
1343 | CMP_OUT (custom_name); |
1332 | |
1344 | |
1333 | if (object *owner = op->owner) |
1345 | if (object *owner = op->owner) |
1334 | f.put (KW_owner, static_cast<const char *>(owner->ref ())); |
1346 | f.put (KW(owner), static_cast<const char *>(owner->ref ())); |
1335 | |
1347 | |
1336 | // memory, attacked_by, chosen_skill, spellitem, spell, current_weapon, arch not saved |
1348 | // memory, attacked_by, chosen_skill, spellitem, spell, current_weapon, arch not saved |
1337 | |
1349 | |
1338 | CMP_OUT (other_arch); |
1350 | CMP_OUT (other_arch); |
1339 | |
1351 | |
1340 | if (op->msg != arch->msg ) f.put (KW_msg , KW_endmsg , op->msg ); |
1352 | if (op->msg != arch->msg ) f.put (KW(msg) , KW(endmsg) , op->msg ); |
1341 | if (op->lore != arch->lore) f.put (KW_lore, KW_endlore, op->lore); |
1353 | if (op->lore != arch->lore) f.put (KW(lore), KW(endlore), op->lore); |
1342 | |
1354 | |
1343 | if (op->face != arch->face ) f.put (KW_face , op->face ? &faces [op->face ] : 0); |
1355 | if (op->face != arch->face ) f.put (KW(face) , op->face ? &faces [op->face ] : 0); |
1344 | if (op->sound != arch->sound ) f.put (KW_sound , op->sound ? &faces [op->sound ] : 0); |
1356 | if (op->sound != arch->sound ) f.put (KW(sound) , op->sound ? &faces [op->sound ] : 0); |
1345 | if (op->sound_destroy != arch->sound_destroy) f.put (KW_sound_destroy, op->sound_destroy ? &faces [op->sound_destroy] : 0); |
1357 | if (op->sound_destroy != arch->sound_destroy) f.put (KW(sound_destroy), op->sound_destroy ? &faces [op->sound_destroy] : 0); |
1346 | |
1358 | |
1347 | if (op->animation_id != arch->animation_id) |
1359 | if (op->animation_id != arch->animation_id) |
1348 | if (op->has_anim ()) |
1360 | if (op->has_anim ()) |
1349 | f.put (KW_animation, op->anim ().name); |
1361 | f.put (KW(animation), op->anim ().name); |
1350 | else |
1362 | else |
1351 | { |
1363 | { |
1352 | f.put (KW_animation, (const char *)0); |
1364 | f.put (KW(animation)); |
1353 | op->flag [FLAG_ANIMATE] = false; // TODO: why force to false here? |
1365 | op->flag [FLAG_ANIMATE] = false; // TODO: why force to false here? |
1354 | } |
1366 | } |
1355 | |
1367 | |
1356 | CMP_OUT2 (str, stats.Str); |
1368 | CMP_OUT2 (str, stats.Str); |
1357 | CMP_OUT2 (dex, stats.Dex); |
1369 | CMP_OUT2 (dex, stats.Dex); |
… | |
… | |
1393 | CMP_OUT (path_repelled); |
1405 | CMP_OUT (path_repelled); |
1394 | CMP_OUT (path_denied); |
1406 | CMP_OUT (path_denied); |
1395 | |
1407 | |
1396 | CMP_OUT2 (material, materials);//TODO: nuke |
1408 | CMP_OUT2 (material, materials);//TODO: nuke |
1397 | if (op->material != arch->material) |
1409 | if (op->material != arch->material) |
1398 | f.put (KW_materialname, op->material->name); |
1410 | f.put (KW(materialname), op->material->name); |
1399 | |
1411 | |
1400 | CMP_OUT (value); |
1412 | CMP_OUT (value); |
1401 | CMP_OUT (carrying); |
1413 | CMP_OUT (carrying); |
1402 | CMP_OUT (weight); |
1414 | CMP_OUT (weight); |
1403 | CMP_OUT (invisible); |
1415 | CMP_OUT (invisible); |
… | |
… | |
1409 | CMP_OUT (last_eat); |
1421 | CMP_OUT (last_eat); |
1410 | CMP_OUT (glow_radius); |
1422 | CMP_OUT (glow_radius); |
1411 | |
1423 | |
1412 | if (op->flag [FLAG_IS_LINKED]) |
1424 | if (op->flag [FLAG_IS_LINKED]) |
1413 | if (auto (ol, op->find_link ())) |
1425 | if (auto (ol, op->find_link ())) |
1414 | f.put (KW_connected, ol->id); |
1426 | f.put (KW(connected), ol->id); |
1415 | |
1427 | |
1416 | CMP_OUT (randomitems); |
1428 | CMP_OUT (randomitems); |
|
|
1429 | |
1417 | CMP_OUT2 (container, weight_limit); |
1430 | CMP_OUT2 (container, weight_limit); |
1418 | |
1431 | |
1419 | CMP_OUT (run_away); |
1432 | CMP_OUT (run_away); |
1420 | CMP_OUT (pick_up); |
1433 | CMP_OUT (pick_up); |
1421 | CMP_OUT (will_apply); |
1434 | CMP_OUT (will_apply); |
… | |
… | |
1439 | CMP_OUT (move_slow_penalty); |
1452 | CMP_OUT (move_slow_penalty); |
1440 | |
1453 | |
1441 | object::flags_t diff = (op->flag ^ arch->flag) & flagmask; |
1454 | object::flags_t diff = (op->flag ^ arch->flag) & flagmask; |
1442 | |
1455 | |
1443 | if (diff [FLAG_OBJ_ORIGINAL]) |
1456 | if (diff [FLAG_OBJ_ORIGINAL]) |
1444 | f.put (flag_names [FLAG_OBJ_ORIGINAL], op->flag [FLAG_OBJ_ORIGINAL] ? "1" : "0"); |
1457 | f.put (flag_names [FLAG_OBJ_ORIGINAL], op->flag [FLAG_OBJ_ORIGINAL] ? CS(1) : CS(0)); |
1445 | |
1458 | |
1446 | diff.reset (FLAG_OBJ_ORIGINAL); |
1459 | diff.reset (FLAG_OBJ_ORIGINAL); |
1447 | |
1460 | |
1448 | // quickly test whether any other flags differ |
1461 | // quickly test whether any other flags differ |
1449 | if (expect_true (diff.any ())) |
1462 | if (expect_true (diff.any ())) |
1450 | for (int i = 0; i < NUM_FLAGS; i++) |
1463 | for (int i = 0; i < NUM_FLAGS; i++) |
1451 | if (expect_false (diff [i])) |
1464 | if (expect_false (diff [i])) |
1452 | f.put (flag_names [i], op->flag [i] ? "1" : "0"); |
1465 | f.put (flag_names [i], op->flag [i] ? CS(1) : CS(0)); |
1453 | |
1466 | |
1454 | // save body locations. gcc's memcmp does an abysmal job when used |
1467 | // save body locations. gcc's memcmp does an abysmal job when used |
1455 | for (int i = 0; i < NUM_BODY_LOCATIONS; i++) |
1468 | for (int i = 0; i < NUM_BODY_LOCATIONS; i++) |
1456 | if (expect_false (op->slot[i].info != arch->slot[i].info)) |
1469 | if (expect_false (op->slot[i].info != arch->slot[i].info)) |
1457 | f.put (body_locations[i].save_name, op->slot[i].info); |
1470 | f.put (body_locations[i].save_name, op->slot[i].info); |
… | |
… | |
1463 | * the only place this is not set is when saving the player. |
1476 | * the only place this is not set is when saving the player. |
1464 | */ |
1477 | */ |
1465 | bool |
1478 | bool |
1466 | object::write (object_freezer &f) |
1479 | object::write (object_freezer &f) |
1467 | { |
1480 | { |
1468 | if (is_arch ()) |
1481 | if (expect_false (is_arch ())) |
1469 | { |
1482 | { |
1470 | f.put (KW_object, arch->archname); |
1483 | f.put (KW(object), arch->archname); |
1471 | write_diff (f, this, archetype::empty); |
1484 | write_diff (f, this, archetype::empty); |
1472 | } |
1485 | } |
1473 | else |
1486 | else |
1474 | { |
1487 | { |
1475 | f.put (KW_arch, arch->archname); |
1488 | f.put (KW(arch), arch->archname); |
1476 | write_diff (f, this, arch); |
1489 | write_diff (f, this, arch); |
1477 | } |
1490 | } |
1478 | |
1491 | |
1479 | for (object *tmp = inv; tmp; tmp = tmp->below) |
1492 | for (object *tmp = inv; tmp; tmp = tmp->below) |
1480 | tmp->write (f); |
1493 | tmp->write (f); |
1481 | |
1494 | |
1482 | f.put (this); |
1495 | f.put (this); |
1483 | f.put (KW_end); |
1496 | f.put (KW(end)); |
1484 | |
1497 | |
1485 | return true; |
1498 | return true; |
1486 | } |
1499 | } |
1487 | |
1500 | |
1488 | ///////////////////////////////////////////////////////////////////////////// |
1501 | ///////////////////////////////////////////////////////////////////////////// |