1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2001 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * the terms of the Affero GNU General Public License as published by the |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * option) any later version. |
11 | * option) any later version. |
… | |
… | |
26 | #include <stdio.h> |
26 | #include <stdio.h> |
27 | #include <sys/types.h> |
27 | #include <sys/types.h> |
28 | #include <sys/uio.h> |
28 | #include <sys/uio.h> |
29 | #include <object.h> |
29 | #include <object.h> |
30 | #include <sproto.h> |
30 | #include <sproto.h> |
31 | #include <loader.h> |
|
|
32 | |
31 | |
33 | #include <bitset> |
32 | #include <bitset> |
34 | |
33 | |
35 | UUID UUID::cur; |
34 | UUID UUID::cur; |
36 | static uint64_t seq_next_save; |
35 | static uint64_t seq_next_save; |
… | |
… | |
77 | CALL_CALL ("cf::write_uuid", G_DISCARD); |
76 | CALL_CALL ("cf::write_uuid", G_DISCARD); |
78 | CALL_END; |
77 | CALL_END; |
79 | } |
78 | } |
80 | |
79 | |
81 | static void |
80 | static void |
82 | read_uuid (void) |
81 | read_uuid () |
83 | { |
82 | { |
84 | char filename[MAX_BUF]; |
83 | char filename[MAX_BUF]; |
85 | |
84 | |
86 | sprintf (filename, "%s/uuid", settings.localdir); |
85 | sprintf (filename, "%s/uuid", settings.localdir); |
87 | |
86 | |
… | |
… | |
248 | * Improvements made with merge: Better checking on potion, and also |
247 | * Improvements made with merge: Better checking on potion, and also |
249 | * check weight |
248 | * check weight |
250 | */ |
249 | */ |
251 | bool object::can_merge_slow (object *ob1, object *ob2) |
250 | bool object::can_merge_slow (object *ob1, object *ob2) |
252 | { |
251 | { |
253 | /* A couple quicksanity checks */ |
252 | /* A couple quick sanity checks */ |
254 | if (ob1 == ob2 |
253 | if (ob1 == ob2 |
255 | || ob1->type != ob2->type |
254 | || ob1->type != ob2->type |
256 | || fabs (ob1->speed - ob2->speed) >= MIN_ACTIVE_SPEED |
|
|
257 | || ob1->value != ob2->value |
255 | || ob1->value != ob2->value |
258 | || ob1->name != ob2->name) |
256 | || ob1->name != ob2->name |
|
|
257 | || fabs (ob1->speed - ob2->speed) >= MIN_ACTIVE_SPEED) |
259 | return 0; |
258 | return 0; |
260 | |
259 | |
261 | /* Do not merge objects if nrof would overflow, assume nrof |
260 | /* Do not merge objects if nrof would overflow, assume nrof |
262 | * is always 0 .. 2**31-1 */ |
261 | * is always 0 .. 2**31-1 */ |
263 | if (ob1->nrof > 0x7fffffff - ob2->nrof) |
262 | if (ob1->nrof > 0x7fffffff - ob2->nrof) |
… | |
… | |
284 | || ob1->magic != ob2->magic |
283 | || ob1->magic != ob2->magic |
285 | || ob1->slaying != ob2->slaying |
284 | || ob1->slaying != ob2->slaying |
286 | || ob1->skill != ob2->skill |
285 | || ob1->skill != ob2->skill |
287 | || ob1->value != ob2->value |
286 | || ob1->value != ob2->value |
288 | || ob1->animation_id != ob2->animation_id |
287 | || ob1->animation_id != ob2->animation_id |
289 | || (ob1->face != ob2->face && !ob1->animation_id) // face and animation are dependent on each other |
288 | || (ob1->face != ob2->face && !ob1->animation_id) // face and animation are dependend on each other |
290 | || ob1->client_type != ob2->client_type |
289 | || ob1->client_type != ob2->client_type |
291 | || ob1->materialname != ob2->materialname |
290 | || ob1->material != ob2->material |
292 | || ob1->lore != ob2->lore |
291 | || ob1->lore != ob2->lore |
293 | || ob1->subtype != ob2->subtype |
292 | || ob1->subtype != ob2->subtype |
294 | || ob1->move_type != ob2->move_type |
293 | || ob1->move_type != ob2->move_type |
295 | || ob1->move_block != ob2->move_block |
294 | || ob1->move_block != ob2->move_block |
296 | || ob1->move_allow != ob2->move_allow |
295 | || ob1->move_allow != ob2->move_allow |
… | |
… | |
521 | |
520 | |
522 | return 0; |
521 | return 0; |
523 | } |
522 | } |
524 | |
523 | |
525 | /* |
524 | /* |
|
|
525 | * Returns the object which has the uuid equal to the argument. |
|
|
526 | * MOAR VERRRY slow. |
|
|
527 | */ |
|
|
528 | |
|
|
529 | object * |
|
|
530 | find_object_uuid (UUID i) |
|
|
531 | { |
|
|
532 | for_all_objects (op) |
|
|
533 | if (op->uuid == i) |
|
|
534 | return op; |
|
|
535 | |
|
|
536 | return 0; |
|
|
537 | } |
|
|
538 | |
|
|
539 | /* |
526 | * Returns the first object which has a name equal to the argument. |
540 | * Returns the first object which has a name equal to the argument. |
527 | * Used only by the patch command, but not all that useful. |
541 | * Used only by the patch command, but not all that useful. |
528 | * Enables features like "patch <name-of-other-player> food 999" |
542 | * Enables features like "patch <name-of-other-player> food 999" |
529 | */ |
543 | */ |
530 | object * |
544 | object * |
… | |
… | |
600 | { |
614 | { |
601 | // now check wether any body locations became invalid, in which case |
615 | // now check wether any body locations became invalid, in which case |
602 | // we cannot apply the weapon at the moment. |
616 | // we cannot apply the weapon at the moment. |
603 | for (int i = 0; i < NUM_BODY_LOCATIONS; ++i) |
617 | for (int i = 0; i < NUM_BODY_LOCATIONS; ++i) |
604 | if (slot[i].used < 0) |
618 | if (slot[i].used < 0) |
605 | { |
619 | { |
|
|
620 | if (chosen_skill) |
|
|
621 | chosen_skill->flag [FLAG_APPLIED] = false; |
|
|
622 | |
606 | current_weapon = chosen_skill = 0; |
623 | current_weapon = chosen_skill = 0; |
607 | update_stats (); |
624 | update_stats (); |
608 | |
625 | |
609 | new_draw_info_format (NDI_UNIQUE, 0, this, |
626 | new_draw_info_format (NDI_UNIQUE, 0, this, |
610 | "You try to balance all your items at once, " |
627 | "You try to balance all your items at once, " |
611 | "but the %s is just too much for your body. " |
628 | "but the %s is just too much for your body. " |
612 | "[You need to unapply some items first - use the 'body' command to see " |
629 | "[You need to unapply some items first - use the 'body' command to see " |
613 | "how many items you cna wera on a specific body part.]", &ob->name); |
630 | "how many items you can wear on a specific body part.]", &ob->name); |
614 | return false; |
631 | return false; |
615 | } |
632 | } |
616 | |
633 | |
617 | //new_draw_info_format (NDI_UNIQUE, 0, this, "You switch to your %s.", &ob->name); |
634 | //new_draw_info_format (NDI_UNIQUE, 0, this, "You switch to your %s.", &ob->name); |
618 | } |
635 | } |
… | |
… | |
687 | tail = new_link; |
704 | tail = new_link; |
688 | } |
705 | } |
689 | } |
706 | } |
690 | } |
707 | } |
691 | |
708 | |
692 | if (speed < 0) |
|
|
693 | dst->speed_left -= rndm (); |
|
|
694 | |
|
|
695 | dst->activate (); |
709 | dst->activate (); |
696 | } |
710 | } |
697 | |
711 | |
698 | void |
712 | void |
699 | object::instantiate () |
713 | object::instantiate () |
700 | { |
714 | { |
701 | if (!uuid.seq) // HACK |
715 | if (!uuid.seq) // HACK |
702 | uuid = UUID::gen (); |
716 | uuid = UUID::gen (); |
703 | |
717 | |
|
|
718 | // TODO: unclean state changes, should nt be done in copy_to AND instantiate |
|
|
719 | if (flag [FLAG_RANDOM_SPEED] && speed) |
|
|
720 | speed_left = - speed - rndm (); // TODO animation |
|
|
721 | else |
704 | speed_left = -0.1f; |
722 | speed_left = -1.; |
|
|
723 | |
705 | /* copy the body_info to the body_used - this is only really |
724 | /* copy the body_info to the body_used - this is only really |
706 | * need for monsters, but doesn't hurt to do it for everything. |
725 | * need for monsters, but doesn't hurt to do it for everything. |
707 | * by doing so, when a monster is created, it has good starting |
726 | * by doing so, when a monster is created, it has good starting |
708 | * values for the body_used info, so when items are created |
727 | * values for the body_used info, so when items are created |
709 | * for it, they can be properly equipped. |
728 | * for it, they can be properly equipped. |
… | |
… | |
717 | object * |
736 | object * |
718 | object::clone () |
737 | object::clone () |
719 | { |
738 | { |
720 | object *neu = create (); |
739 | object *neu = create (); |
721 | copy_to (neu); |
740 | copy_to (neu); |
|
|
741 | |
|
|
742 | // TODO: unclean state changes, should not be done in clone AND instantiate |
|
|
743 | if (neu->flag [FLAG_RANDOM_SPEED] && neu->speed) |
|
|
744 | neu->speed_left = - neu->speed - rndm (); // TODO animation |
|
|
745 | |
722 | neu->map = map; // not copied by copy_to |
746 | neu->map = map; // not copied by copy_to |
723 | return neu; |
747 | return neu; |
724 | } |
748 | } |
725 | |
749 | |
726 | /* |
750 | /* |
… | |
… | |
844 | object::object () |
868 | object::object () |
845 | { |
869 | { |
846 | SET_FLAG (this, FLAG_REMOVED); |
870 | SET_FLAG (this, FLAG_REMOVED); |
847 | |
871 | |
848 | //expmul = 1.0; declared const for the time being |
872 | //expmul = 1.0; declared const for the time being |
849 | face = blank_face; |
873 | face = blank_face; |
|
|
874 | material = MATERIAL_NULL; |
850 | } |
875 | } |
851 | |
876 | |
852 | object::~object () |
877 | object::~object () |
853 | { |
878 | { |
854 | unlink (); |
879 | unlink (); |
… | |
… | |
1125 | |
1150 | |
1126 | above = 0; |
1151 | above = 0; |
1127 | below = 0; |
1152 | below = 0; |
1128 | env = 0; |
1153 | env = 0; |
1129 | |
1154 | |
1130 | /* NO_FIX_PLAYER is set when a great many changes are being |
1155 | if (pl && pl->is_player ()) |
1131 | * made to players inventory. If set, avoiding the call |
|
|
1132 | * to save cpu time. |
|
|
1133 | */ |
|
|
1134 | if (pl) |
|
|
1135 | if (pl->is_player () && (glow_radius || !QUERY_FLAG (pl, FLAG_NO_FIX_PLAYER))) |
|
|
1136 | { |
1156 | { |
1137 | pl->update_stats (); |
1157 | pl->contr->queue_stats_update (); |
1138 | |
1158 | |
1139 | if (glow_radius && pl->is_on_map ()) |
1159 | if (glow_radius && pl->is_on_map ()) |
1140 | update_all_los (pl->map, pl->x, pl->y); |
1160 | update_all_los (pl->map, pl->x, pl->y); |
1141 | } |
1161 | } |
1142 | } |
1162 | } |
1143 | else if (map) |
1163 | else if (map) |
1144 | { |
1164 | { |
1145 | map->dirty = true; |
1165 | map->dirty = true; |
1146 | mapspace &ms = this->ms (); |
1166 | mapspace &ms = this->ms (); |
… | |
… | |
1266 | |
1286 | |
1267 | object *prev = this; |
1287 | object *prev = this; |
1268 | |
1288 | |
1269 | for (archetype *at = (archetype *)arch->more; at; at = (archetype *)at->more) |
1289 | for (archetype *at = (archetype *)arch->more; at; at = (archetype *)at->more) |
1270 | { |
1290 | { |
1271 | object *op = arch_to_object (at); |
1291 | object *op = at->instance (); |
1272 | |
1292 | |
1273 | op->name = name; |
1293 | op->name = name; |
1274 | op->name_pl = name_pl; |
1294 | op->name_pl = name_pl; |
1275 | op->title = title; |
1295 | op->title = title; |
1276 | |
1296 | |
… | |
… | |
1314 | * Passing 0 for flag gives proper default values, so flag really only needs |
1334 | * Passing 0 for flag gives proper default values, so flag really only needs |
1315 | * to be set if special handling is needed. |
1335 | * to be set if special handling is needed. |
1316 | * |
1336 | * |
1317 | * Return value: |
1337 | * Return value: |
1318 | * new object if 'op' was merged with other object |
1338 | * new object if 'op' was merged with other object |
1319 | * NULL if 'op' was destroyed |
1339 | * NULL if there was an error (destroyed, blocked etc.) |
1320 | * just 'op' otherwise |
1340 | * just 'op' otherwise |
1321 | */ |
1341 | */ |
1322 | object * |
1342 | object * |
1323 | insert_ob_in_map (object *op, maptile *m, object *originator, int flag) |
1343 | insert_ob_in_map (object *op, maptile *m, object *originator, int flag) |
1324 | { |
1344 | { |
… | |
… | |
1551 | |
1571 | |
1552 | for (object *tmp = op->ms ().bot; tmp; tmp = tmp->above) |
1572 | for (object *tmp = op->ms ().bot; tmp; tmp = tmp->above) |
1553 | if (tmp->arch->archname == archname) /* same archetype */ |
1573 | if (tmp->arch->archname == archname) /* same archetype */ |
1554 | tmp->destroy (); |
1574 | tmp->destroy (); |
1555 | |
1575 | |
1556 | object *tmp = arch_to_object (archetype::find (archname)); |
1576 | object *tmp = archetype::find (archname)->instance (); |
1557 | |
1577 | |
1558 | tmp->x = op->x; |
1578 | tmp->x = op->x; |
1559 | tmp->y = op->y; |
1579 | tmp->y = op->y; |
1560 | |
1580 | |
1561 | insert_ob_in_map (tmp, op->map, op, 0); |
1581 | insert_ob_in_map (tmp, op->map, op, 0); |
… | |
… | |
1737 | if (op->glow_radius && is_on_map ()) |
1757 | if (op->glow_radius && is_on_map ()) |
1738 | { |
1758 | { |
1739 | update_stats (); |
1759 | update_stats (); |
1740 | update_all_los (map, x, y); |
1760 | update_all_los (map, x, y); |
1741 | } |
1761 | } |
1742 | else if (is_player () && !flag [FLAG_NO_FIX_PLAYER]) |
1762 | else if (is_player ()) |
1743 | // if this is a player's inventory, update stats |
1763 | // if this is a player's inventory, update stats |
1744 | update_stats (); |
1764 | contr->queue_stats_update (); |
1745 | |
1765 | |
1746 | INVOKE_OBJECT (INSERT, this); |
1766 | INVOKE_OBJECT (INSERT, this); |
1747 | |
1767 | |
1748 | return op; |
1768 | return op; |
1749 | } |
1769 | } |
… | |
… | |
2517 | { |
2537 | { |
2518 | return map ? map->region (x, y) |
2538 | return map ? map->region (x, y) |
2519 | : region::default_region (); |
2539 | : region::default_region (); |
2520 | } |
2540 | } |
2521 | |
2541 | |
2522 | const materialtype_t * |
|
|
2523 | object::dominant_material () const |
|
|
2524 | { |
|
|
2525 | if (materialtype_t *mt = name_to_material (materialname)) |
|
|
2526 | return mt; |
|
|
2527 | |
|
|
2528 | return name_to_material (shstr_unknown); |
|
|
2529 | } |
|
|
2530 | |
|
|
2531 | void |
2542 | void |
2532 | object::open_container (object *new_container) |
2543 | object::open_container (object *new_container) |
2533 | { |
2544 | { |
2534 | if (container == new_container) |
2545 | if (container == new_container) |
2535 | return; |
2546 | return; |
… | |
… | |
2569 | // TODO: this does not seem to serve any purpose anymore? |
2580 | // TODO: this does not seem to serve any purpose anymore? |
2570 | #if 0 |
2581 | #if 0 |
2571 | // insert the "Close Container" object. |
2582 | // insert the "Close Container" object. |
2572 | if (archetype *closer = new_container->other_arch) |
2583 | if (archetype *closer = new_container->other_arch) |
2573 | { |
2584 | { |
2574 | object *closer = arch_to_object (new_container->other_arch); |
2585 | object *closer = new_container->other_arch->instance (); |
2575 | closer->flag [FLAG_NO_MAP_SAVE] = 1; |
2586 | closer->flag [FLAG_NO_MAP_SAVE] = 1; |
2576 | new_container->insert (closer); |
2587 | new_container->insert (closer); |
2577 | } |
2588 | } |
2578 | #endif |
2589 | #endif |
2579 | |
2590 | |
… | |
… | |
2685 | |
2696 | |
2686 | insert (force); |
2697 | insert (force); |
2687 | } |
2698 | } |
2688 | } |
2699 | } |
2689 | |
2700 | |
|
|
2701 | void object::change_move_type (MoveType mt) |
|
|
2702 | { |
|
|
2703 | if (move_type == mt) |
|
|
2704 | return; |
|
|
2705 | |
|
|
2706 | if (is_on_map ()) |
|
|
2707 | { |
|
|
2708 | // we are on the map, so handle move_on/off effects |
|
|
2709 | remove (); |
|
|
2710 | move_type = mt; |
|
|
2711 | map->insert (this, x, y, this); |
|
|
2712 | } |
|
|
2713 | else |
|
|
2714 | move_type = mt; |
|
|
2715 | } |
|
|
2716 | |