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,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2001 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2001 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992 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. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the Affero GNU General Public License |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * and the GNU General Public License along with this program. If not, see |
19 | * and the GNU General Public License along with this program. If not, see |
20 | * <http://www.gnu.org/licenses/>. |
20 | * <http://www.gnu.org/licenses/>. |
21 | * |
21 | * |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
23 | */ |
24 | |
24 | |
25 | #include <global.h> |
25 | #include <global.h> |
26 | #include <stdio.h> |
26 | #include <stdio.h> |
… | |
… | |
233 | |
233 | |
234 | /* Returns TRUE if every key_values in wants has a partner with the same value in has. */ |
234 | /* Returns TRUE if every key_values in wants has a partner with the same value in has. */ |
235 | static bool |
235 | static bool |
236 | compare_ob_value_lists_one (const object *wants, const object *has) |
236 | compare_ob_value_lists_one (const object *wants, const object *has) |
237 | { |
237 | { |
238 | /* n-squared behaviour (see kv_get), but I'm hoping both |
238 | /* n-squared behaviour (see kv.get), but I'm hoping both |
239 | * objects with lists are rare, and lists stay short. If not, use a |
239 | * objects with lists are rare, and lists stay short. If not, use a |
240 | * different structure or at least keep the lists sorted... |
240 | * different structure or at least keep the lists sorted... |
241 | */ |
241 | */ |
242 | |
242 | |
243 | /* For each field in wants, */ |
243 | /* For each field in wants, */ |
244 | for (key_value *kv = wants->key_values; kv; kv = kv->next) |
244 | for (key_value *kv = wants->kv.first; kv; kv = kv->next) |
245 | if (has->kv_get (kv->key) != kv->value) |
245 | if (has->kv.get (kv->key) != kv->value) |
246 | return false; |
246 | return false; |
247 | |
247 | |
248 | /* If we get here, every field in wants has a matching field in has. */ |
248 | /* If we get here, every field in wants has a matching field in has. */ |
249 | return true; |
249 | return true; |
250 | } |
250 | } |
… | |
… | |
274 | */ |
274 | */ |
275 | bool object::can_merge_slow (object *ob1, object *ob2) |
275 | bool object::can_merge_slow (object *ob1, object *ob2) |
276 | { |
276 | { |
277 | /* A couple quick sanity checks */ |
277 | /* A couple quick sanity checks */ |
278 | if (ob1 == ob2 |
278 | if (ob1 == ob2 |
279 | || ob1->type != ob2->type |
279 | || ob1->type != ob2->type |
280 | || ob1->value != ob2->value |
280 | || ob1->value != ob2->value |
281 | || ob1->name != ob2->name |
281 | || ob1->name != ob2->name |
|
|
282 | || ob1->custom_name != ob2->custom_name |
282 | || fabs (ob1->speed - ob2->speed) >= MIN_ACTIVE_SPEED) |
283 | || fabs (ob1->speed - ob2->speed) >= MIN_ACTIVE_SPEED) |
283 | return 0; |
284 | return 0; |
284 | |
285 | |
285 | /* Do not merge objects if nrof would overflow, assume nrof |
286 | /* Do not merge objects if nrof would overflow, assume nrof |
286 | * is always 0 .. 2**31-1 */ |
287 | * is always 0 .. 2**31-1 */ |
… | |
… | |
350 | /* inventory ok - still need to check rest of this object to see |
351 | /* inventory ok - still need to check rest of this object to see |
351 | * if it is valid. |
352 | * if it is valid. |
352 | */ |
353 | */ |
353 | } |
354 | } |
354 | |
355 | |
355 | /* Don't merge objects that are applied. With the new 'body' code, |
356 | /* Don't merge objects that are applied. With the new 'body' code, |
356 | * it is possible for most any character to have more than one of |
357 | * it is possible for most any character to have more than one of |
357 | * some items equipped, and we don't want those to merge. |
358 | * some items equipped, and we don't want those to merge. |
358 | */ |
359 | */ |
359 | if (ob1->flag [FLAG_APPLIED] || ob2->flag [FLAG_APPLIED]) |
360 | if (ob1->flag [FLAG_APPLIED] || ob2->flag [FLAG_APPLIED]) |
360 | return 0; |
361 | return 0; |
361 | |
362 | |
362 | /* Note sure why the following is the case - either the object has to |
363 | /* Not sure why the following is the case - either the object has to |
363 | * be animated or have a very low speed. Is this an attempted monster |
364 | * be animated or have a very low speed. Is this an attempted monster |
364 | * check? |
365 | * check? |
365 | */ |
366 | */ |
366 | if (!ob1->flag [FLAG_ANIMATE] && ob1->has_active_speed ()) |
367 | if (!ob1->flag [FLAG_ANIMATE] && ob1->has_active_speed ()) |
367 | return 0; |
368 | return 0; |
368 | |
369 | |
… | |
… | |
372 | if (ob1->level != ob2->level) |
373 | if (ob1->level != ob2->level) |
373 | return 0; |
374 | return 0; |
374 | break; |
375 | break; |
375 | } |
376 | } |
376 | |
377 | |
377 | if (ob1->key_values || ob2->key_values) |
378 | if (!ob1->kv.empty () || !ob2->kv.empty ()) |
378 | { |
379 | { |
379 | /* At least one of these has key_values. */ |
380 | /* At least one of these has key_values. */ |
380 | if ((!ob1->key_values) != (!ob2->key_values)) |
381 | if (ob1->kv.empty () != ob2->kv.empty ()) |
381 | return 0; /* One has fields, but the other one doesn't. */ |
382 | return 0; /* One has fields, but the other one doesn't. */ |
382 | |
383 | |
383 | if (!compare_ob_value_lists (ob1, ob2)) |
384 | if (!compare_ob_value_lists (ob1, ob2)) |
384 | return 0; |
385 | return 0; |
385 | } |
386 | } |
… | |
… | |
445 | |
446 | |
446 | return 0; |
447 | return 0; |
447 | } |
448 | } |
448 | |
449 | |
449 | // adjust weight per container type ("of holding") |
450 | // adjust weight per container type ("of holding") |
450 | static uint32 |
451 | static weight_t |
451 | weight_adjust_for (object *op, uint32 weight) |
452 | weight_adjust_for (object *op, weight_t weight) |
452 | { |
453 | { |
453 | return op->type == CONTAINER |
454 | if (op->type == CONTAINER) |
454 | ? weight - weight * op->stats.Str / 100 |
455 | weight -= weight * op->stats.Str / 100; |
455 | : weight; |
456 | |
|
|
457 | return weight; |
456 | } |
458 | } |
457 | |
459 | |
458 | /* |
460 | /* |
459 | * subtracts, then adds, the specified weight to an object, |
461 | * subtracts, then adds, the specified weight to an object, |
460 | * and also updates how much the environment(s) is/are carrying. |
462 | * and also updates how much the environment(s) is/are carrying. |
461 | */ |
463 | */ |
462 | static void |
464 | static void |
463 | adjust_weight (object *op, sint32 sub, sint32 add) |
465 | adjust_weight (object *op, weight_t sub, weight_t add) |
464 | { |
466 | { |
465 | while (op) |
467 | while (op) |
466 | { |
468 | { |
467 | sint32 ocarrying = op->carrying; |
469 | weight_t carrying = (weight_t)op->carrying |
|
|
470 | - weight_adjust_for (op, sub) |
|
|
471 | + weight_adjust_for (op, add); |
468 | |
472 | |
469 | op->carrying -= weight_adjust_for (op, sub); |
473 | sub = op->carrying; |
470 | op->carrying += weight_adjust_for (op, add); |
474 | op->carrying = carrying; |
|
|
475 | add = op->carrying; |
471 | |
476 | |
472 | if (object *pl = op->visible_to ()) |
477 | if (object *pl = op->visible_to ()) |
473 | if (pl != op) // player is handled lazily |
478 | if (pl != op) // player is handled lazily |
474 | esrv_update_item (UPD_WEIGHT, pl, op); |
479 | esrv_update_item (UPD_WEIGHT, pl, op); |
475 | |
480 | |
476 | sub = ocarrying; |
|
|
477 | add = op->carrying; |
|
|
478 | |
|
|
479 | op = op->env; |
481 | op = op->env; |
480 | } |
482 | } |
481 | } |
483 | } |
482 | |
484 | |
483 | /* |
485 | /* |
… | |
… | |
486 | * containers are carrying, and sums it up. |
488 | * containers are carrying, and sums it up. |
487 | */ |
489 | */ |
488 | void |
490 | void |
489 | object::update_weight () |
491 | object::update_weight () |
490 | { |
492 | { |
491 | sint32 sum = 0; |
493 | weight_t sum = 0; |
492 | |
494 | |
493 | for (object *op = inv; op; op = op->below) |
495 | for (object *op = inv; op; op = op->below) |
494 | { |
496 | { |
495 | op->update_weight (); |
497 | op->update_weight (); |
496 | |
498 | |
… | |
… | |
596 | LOG (llevError | logBacktrace, "tried to set owner of %s to %s\n", debug_desc (), owner->debug_desc ()); |
598 | LOG (llevError | logBacktrace, "tried to set owner of %s to %s\n", debug_desc (), owner->debug_desc ()); |
597 | return; |
599 | return; |
598 | } |
600 | } |
599 | |
601 | |
600 | this->owner = owner; |
602 | this->owner = owner; |
601 | } |
|
|
602 | |
|
|
603 | /* Zero the key_values on op, decrementing the shared-string |
|
|
604 | * refcounts and freeing the links. |
|
|
605 | */ |
|
|
606 | static void |
|
|
607 | free_key_values (object *op) |
|
|
608 | { |
|
|
609 | for (key_value *i = op->key_values; i; ) |
|
|
610 | { |
|
|
611 | key_value *next = i->next; |
|
|
612 | delete i; |
|
|
613 | |
|
|
614 | i = next; |
|
|
615 | } |
|
|
616 | |
|
|
617 | op->key_values = 0; |
|
|
618 | } |
603 | } |
619 | |
604 | |
620 | /* |
605 | /* |
621 | * copy_to first frees everything allocated by the dst object, |
606 | * copy_to first frees everything allocated by the dst object, |
622 | * and then copies the contents of itself into the second |
607 | * and then copies the contents of itself into the second |
… | |
… | |
628 | void |
613 | void |
629 | object::copy_to (object *dst) |
614 | object::copy_to (object *dst) |
630 | { |
615 | { |
631 | dst->remove (); |
616 | dst->remove (); |
632 | *(object_copy *)dst = *this; |
617 | *(object_copy *)dst = *this; |
|
|
618 | |
|
|
619 | // maybe move to object_copy? |
|
|
620 | dst->kv = kv; |
|
|
621 | |
633 | dst->flag [FLAG_REMOVED] = true; |
622 | dst->flag [FLAG_REMOVED] = true; |
634 | |
|
|
635 | /* Copy over key_values, if any. */ |
|
|
636 | if (key_values) |
|
|
637 | { |
|
|
638 | key_value *tail = 0; |
|
|
639 | dst->key_values = 0; |
|
|
640 | |
|
|
641 | for (key_value *i = key_values; i; i = i->next) |
|
|
642 | { |
|
|
643 | key_value *new_link = new key_value; |
|
|
644 | |
|
|
645 | new_link->next = 0; |
|
|
646 | new_link->key = i->key; |
|
|
647 | new_link->value = i->value; |
|
|
648 | |
|
|
649 | /* Try and be clever here, too. */ |
|
|
650 | if (!dst->key_values) |
|
|
651 | { |
|
|
652 | dst->key_values = new_link; |
|
|
653 | tail = new_link; |
|
|
654 | } |
|
|
655 | else |
|
|
656 | { |
|
|
657 | tail->next = new_link; |
|
|
658 | tail = new_link; |
|
|
659 | } |
|
|
660 | } |
|
|
661 | } |
|
|
662 | |
|
|
663 | dst->activate (); |
623 | dst->activate (); |
664 | } |
624 | } |
665 | |
625 | |
666 | void |
626 | void |
667 | object::instantiate () |
627 | object::instantiate () |
668 | { |
628 | { |
669 | if (!uuid.seq) // HACK |
629 | if (!uuid.seq) // HACK |
670 | uuid = UUID::gen (); |
630 | uuid = UUID::gen (); |
671 | |
631 | |
672 | // TODO: unclean state changes, should nt be done in copy_to AND instantiate |
632 | // TODO: unclean state changes, should not be done in copy_to AND instantiate |
673 | if (flag [FLAG_RANDOM_SPEED] && speed) |
633 | if (flag [FLAG_RANDOM_SPEED] && speed) |
674 | speed_left = - speed - rndm (); // TODO animation |
634 | speed_left = - speed - rndm (); // TODO animation |
675 | else |
635 | else |
676 | speed_left = -1.; |
636 | speed_left = -1.; |
677 | |
637 | |
678 | /* copy the body_info to the body_used - this is only really |
638 | /* copy the body_info to the body_used - this is only really |
679 | * need for monsters, but doesn't hurt to do it for everything. |
639 | * need for monsters, but doesn't hurt to do it for everything. |
680 | * by doing so, when a monster is created, it has good starting |
640 | * by doing so, when a monster is created, it has good starting |
681 | * values for the body_used info, so when items are created |
641 | * values for the body_used info, so when items are created |
682 | * for it, they can be properly equipped. |
642 | * for it, they can be properly equipped. |
683 | */ |
643 | */ |
684 | for (int i = NUM_BODY_LOCATIONS; i--; ) |
644 | for (int i = NUM_BODY_LOCATIONS; i--; ) |
685 | slot[i].used = slot[i].info; |
645 | slot[i].used = slot[i].info; |
686 | |
646 | |
… | |
… | |
778 | } |
738 | } |
779 | |
739 | |
780 | mapspace &m = op->ms (); |
740 | mapspace &m = op->ms (); |
781 | |
741 | |
782 | if (!(m.flags_ & P_UPTODATE)) |
742 | if (!(m.flags_ & P_UPTODATE)) |
783 | /* nop */; |
743 | m.update_up (); // nothing to do except copy up |
784 | else if (action == UP_OBJ_INSERT) |
744 | else if (action == UP_OBJ_INSERT) |
785 | { |
745 | { |
786 | #if 0 |
746 | #if 0 |
787 | // this is likely overkill, TODO: revisit (schmorp) |
747 | // this is likely overkill, TODO: revisit (schmorp) |
788 | if ((op->flag [FLAG_BLOCKSVIEW] && !(m.flags_ & P_BLOCKSVIEW)) |
748 | if ((op->flag [FLAG_BLOCKSVIEW] && !(m.flags_ & P_BLOCKSVIEW)) |
… | |
… | |
809 | * that is being removed. |
769 | * that is being removed. |
810 | */ |
770 | */ |
811 | else if (action == UP_OBJ_CHANGE || action == UP_OBJ_REMOVE) |
771 | else if (action == UP_OBJ_CHANGE || action == UP_OBJ_REMOVE) |
812 | m.invalidate (); |
772 | m.invalidate (); |
813 | else if (action == UP_OBJ_FACE) |
773 | else if (action == UP_OBJ_FACE) |
814 | /* Nothing to do for that case */ ; |
774 | m.update_up (); // nothing to do for that case, except copy up |
815 | else |
775 | else |
816 | LOG (llevError, "update_object called with invalid action: %d\n", action); |
776 | LOG (llevError, "update_object called with invalid action: %d\n", action); |
817 | |
777 | |
818 | if (op->more) |
778 | if (op->more) |
819 | update_object (op->more, action); |
779 | update_object (op->more, action); |
… | |
… | |
830 | |
790 | |
831 | object::~object () |
791 | object::~object () |
832 | { |
792 | { |
833 | unlink (); |
793 | unlink (); |
834 | |
794 | |
835 | free_key_values (this); |
795 | kv.clear (); |
836 | } |
796 | } |
837 | |
797 | |
838 | void object::link () |
798 | void object::link () |
839 | { |
799 | { |
840 | assert (!index);//D |
800 | assert (!index);//D |
… | |
… | |
939 | * if some form of movement is allowed, let objects |
899 | * if some form of movement is allowed, let objects |
940 | * drop on that space. |
900 | * drop on that space. |
941 | */ |
901 | */ |
942 | if (!drop_to_ground |
902 | if (!drop_to_ground |
943 | || !map |
903 | || !map |
944 | || map->in_memory != MAP_ACTIVE |
904 | || !map->linkable () |
945 | || map->no_drop |
905 | || map->no_drop |
946 | || ms ().move_block == MOVE_ALL) |
906 | || ms ().move_block == MOVE_ALL) |
947 | { |
907 | { |
948 | while (inv) |
908 | while (inv) |
949 | inv->destroy (); |
909 | inv->destroy (); |
… | |
… | |
1045 | li->count = count; |
1005 | li->count = count; |
1046 | |
1006 | |
1047 | freelist = li; |
1007 | freelist = li; |
1048 | ++free_count; |
1008 | ++free_count; |
1049 | } |
1009 | } |
1050 | |
|
|
1051 | static struct freed_map : maptile |
|
|
1052 | { |
|
|
1053 | freed_map () |
|
|
1054 | : maptile (3, 3) |
|
|
1055 | { |
|
|
1056 | path = "<freed objects map>"; |
|
|
1057 | name = "/internal/freed_objects_map"; |
|
|
1058 | no_drop = 1; |
|
|
1059 | no_reset = 1; |
|
|
1060 | |
|
|
1061 | in_memory = MAP_ACTIVE; |
|
|
1062 | } |
|
|
1063 | |
|
|
1064 | ~freed_map () |
|
|
1065 | { |
|
|
1066 | destroy (); |
|
|
1067 | } |
|
|
1068 | } freed_map; // freed objects are moved here to avoid crashes |
|
|
1069 | |
1010 | |
1070 | void |
1011 | void |
1071 | object::do_destroy () |
1012 | object::do_destroy () |
1072 | { |
1013 | { |
1073 | if (flag [FLAG_IS_LINKED]) |
1014 | if (flag [FLAG_IS_LINKED]) |
… | |
… | |
1239 | |
1180 | |
1240 | above = 0; |
1181 | above = 0; |
1241 | below = 0; |
1182 | below = 0; |
1242 | |
1183 | |
1243 | ms.invalidate (); |
1184 | ms.invalidate (); |
1244 | |
|
|
1245 | if (map->in_memory == MAP_SAVING) |
|
|
1246 | return; |
|
|
1247 | |
1185 | |
1248 | int check_walk_off = !flag [FLAG_NO_APPLY]; |
1186 | int check_walk_off = !flag [FLAG_NO_APPLY]; |
1249 | |
1187 | |
1250 | if (object *pl = ms.player ()) |
1188 | if (object *pl = ms.player ()) |
1251 | { |
1189 | { |
… | |
… | |
1386 | { |
1324 | { |
1387 | op->remove (); |
1325 | op->remove (); |
1388 | |
1326 | |
1389 | if (m == &freed_map)//D TODO: remove soon |
1327 | if (m == &freed_map)//D TODO: remove soon |
1390 | {//D |
1328 | {//D |
1391 | LOG (llevError | logBacktrace, "tries to insret object on freed objects map: %s", op->debug_desc ());//D |
1329 | LOG (llevError | logBacktrace, "tries to insert object on freed objects map: %s", op->debug_desc ());//D |
1392 | }//D |
1330 | }//D |
1393 | |
1331 | |
1394 | /* Ideally, the caller figures this out. However, it complicates a lot |
1332 | /* Ideally, the caller figures this out. However, it complicates a lot |
1395 | * of areas of callers (eg, anything that uses find_free_spot would now |
1333 | * of areas of callers (eg, anything that uses find_free_spot would now |
1396 | * need extra work |
1334 | * need extra work |
… | |
… | |
1643 | if (!items // testing !items ensures we can drop at least one item |
1581 | if (!items // testing !items ensures we can drop at least one item |
1644 | || (items < m->max_items |
1582 | || (items < m->max_items |
1645 | && ms.volume () < m->max_volume)) |
1583 | && ms.volume () < m->max_volume)) |
1646 | return true; |
1584 | return true; |
1647 | |
1585 | |
1648 | if (originator && originator->is_player ()) |
1586 | if (originator) |
1649 | originator->contr->failmsgf ( |
1587 | originator->failmsgf ( |
1650 | "No matter how hard you try, you just cannot put the %s here H<Try to remove some items from the floor first.>", |
1588 | "No matter how hard you try, you just cannot put the %s here! H<Try to remove some items from the floor first.>", |
1651 | query_name () |
1589 | query_name () |
1652 | ); |
1590 | ); |
1653 | |
1591 | |
1654 | return false; |
1592 | return false; |
1655 | } |
1593 | } |
… | |
… | |
1669 | |
1607 | |
1670 | nr = min (nr, nrof); |
1608 | nr = min (nr, nrof); |
1671 | |
1609 | |
1672 | if (nrof > nr) |
1610 | if (nrof > nr) |
1673 | { |
1611 | { |
1674 | sint64 oweight = total_weight (); |
1612 | weight_t oweight = total_weight (); |
1675 | |
1613 | |
1676 | nrof -= nr; |
1614 | nrof -= nr; |
1677 | |
1615 | |
1678 | if (object *pl = visible_to ()) |
1616 | if (object *pl = visible_to ()) |
1679 | esrv_update_item (UPD_NROF, pl, this); |
1617 | esrv_update_item (UPD_NROF, pl, this); |
… | |
… | |
1763 | if (object::can_merge (tmp, op)) |
1701 | if (object::can_merge (tmp, op)) |
1764 | { |
1702 | { |
1765 | /* return the original object and remove inserted object |
1703 | /* return the original object and remove inserted object |
1766 | (client prefers the original object) */ |
1704 | (client prefers the original object) */ |
1767 | |
1705 | |
1768 | // carring must be 0 for mergable objects |
1706 | // carrying must be 0 for mergable objects |
1769 | sint64 oweight = tmp->weight * tmp->nrof; |
1707 | weight_t oweight = weight_t (tmp->weight) * tmp->nrof; |
1770 | |
1708 | |
1771 | tmp->nrof += op->nrof; |
1709 | tmp->nrof += op->nrof; |
1772 | |
1710 | |
1773 | if (object *pl = tmp->visible_to ()) |
1711 | if (object *pl = tmp->visible_to ()) |
1774 | esrv_update_item (UPD_NROF, pl, tmp); |
1712 | esrv_update_item (UPD_NROF, pl, tmp); |
1775 | |
1713 | |
1776 | adjust_weight (this, oweight, tmp->weight * tmp->nrof); |
1714 | adjust_weight (this, oweight, weight_t (tmp->weight) * tmp->nrof); |
1777 | |
1715 | |
1778 | op->destroy (); |
1716 | op->destroy (); |
1779 | op = tmp; |
1717 | op = tmp; |
1780 | goto inserted; |
1718 | goto inserted; |
1781 | } |
1719 | } |
… | |
… | |
2071 | */ |
2009 | */ |
2072 | int |
2010 | int |
2073 | find_free_spot (const object *ob, maptile *m, int x, int y, int start, int stop) |
2011 | find_free_spot (const object *ob, maptile *m, int x, int y, int start, int stop) |
2074 | { |
2012 | { |
2075 | int altern[SIZEOFFREE]; |
2013 | int altern[SIZEOFFREE]; |
2076 | int index = 0, flag; |
2014 | int index = 0; |
2077 | |
2015 | |
2078 | for (int i = start; i < stop; i++) |
2016 | for (int i = start; i < stop; i++) |
2079 | { |
2017 | { |
2080 | mapxy pos (m, x, y); pos.move (i); |
2018 | mapxy pos (m, x, y); pos.move (i); |
2081 | |
2019 | |
… | |
… | |
2193 | * there is capable of. |
2131 | * there is capable of. |
2194 | */ |
2132 | */ |
2195 | int |
2133 | int |
2196 | find_dir (maptile *m, int x, int y, object *exclude) |
2134 | find_dir (maptile *m, int x, int y, object *exclude) |
2197 | { |
2135 | { |
2198 | int max = SIZEOFFREE, mflags; |
2136 | int max = SIZEOFFREE; |
2199 | MoveType move_type; |
2137 | MoveType move_type; |
2200 | |
2138 | |
2201 | if (exclude && exclude->head_ () != exclude) |
2139 | if (exclude && exclude->head_ () != exclude) |
2202 | { |
2140 | { |
2203 | exclude = exclude->head; |
2141 | exclude = exclude->head; |
… | |
… | |
2454 | return /*who->flag [FLAG_WIZ]|| */ |
2392 | return /*who->flag [FLAG_WIZ]|| */ |
2455 | (item->weight > 0 && !item->flag [FLAG_NO_PICK] && |
2393 | (item->weight > 0 && !item->flag [FLAG_NO_PICK] && |
2456 | !item->flag [FLAG_ALIVE] && !item->invisible && (who->is_player () || item->weight < who->weight / 3)); |
2394 | !item->flag [FLAG_ALIVE] && !item->invisible && (who->is_player () || item->weight < who->weight / 3)); |
2457 | } |
2395 | } |
2458 | |
2396 | |
|
|
2397 | //-GPL |
|
|
2398 | |
2459 | /* |
2399 | /* |
2460 | * create clone from object to another |
2400 | * create clone from object to another |
2461 | */ |
2401 | */ |
2462 | object * |
2402 | object * |
2463 | object::deep_clone () |
2403 | object::deep_clone () |
… | |
… | |
2493 | return tmp; |
2433 | return tmp; |
2494 | |
2434 | |
2495 | return 0; |
2435 | return 0; |
2496 | } |
2436 | } |
2497 | |
2437 | |
|
|
2438 | /* Zero the key_values on op, decrementing the shared-string |
|
|
2439 | * refcounts and freeing the links. |
|
|
2440 | */ |
|
|
2441 | void |
|
|
2442 | key_values::clear () |
|
|
2443 | { |
|
|
2444 | for (key_value *kvp = first; kvp; ) |
|
|
2445 | { |
|
|
2446 | key_value *next = kvp->next; |
|
|
2447 | delete kvp; |
|
|
2448 | kvp = next; |
|
|
2449 | } |
|
|
2450 | |
|
|
2451 | first = 0; |
|
|
2452 | } |
|
|
2453 | |
2498 | shstr_tmp |
2454 | shstr_tmp |
2499 | object::kv_get (shstr_tmp key) const |
2455 | key_values::get (shstr_tmp key) const |
2500 | { |
2456 | { |
2501 | for (key_value *kv = key_values; kv; kv = kv->next) |
2457 | for (key_value *kv = first; kv; kv = kv->next) |
2502 | if (kv->key == key) |
2458 | if (kv->key == key) |
2503 | return kv->value; |
2459 | return kv->value; |
2504 | |
2460 | |
2505 | return shstr (); |
2461 | return shstr (); |
2506 | } |
2462 | } |
2507 | |
2463 | |
2508 | void |
2464 | void |
|
|
2465 | key_values::add (shstr_tmp key, shstr_tmp value) |
|
|
2466 | { |
|
|
2467 | key_value *kv = new key_value; |
|
|
2468 | |
|
|
2469 | kv->next = first; |
|
|
2470 | kv->key = key; |
|
|
2471 | kv->value = value; |
|
|
2472 | |
|
|
2473 | first = kv; |
|
|
2474 | } |
|
|
2475 | |
|
|
2476 | void |
2509 | object::kv_set (shstr_tmp key, shstr_tmp value) |
2477 | key_values::set (shstr_tmp key, shstr_tmp value) |
2510 | { |
2478 | { |
2511 | for (key_value *kv = key_values; kv; kv = kv->next) |
2479 | for (key_value *kv = first; kv; kv = kv->next) |
2512 | if (kv->key == key) |
2480 | if (kv->key == key) |
2513 | { |
2481 | { |
2514 | kv->value = value; |
2482 | kv->value = value; |
2515 | return; |
2483 | return; |
2516 | } |
2484 | } |
2517 | |
2485 | |
2518 | key_value *kv = new key_value; |
2486 | add (key, value); |
2519 | |
|
|
2520 | kv->next = key_values; |
|
|
2521 | kv->key = key; |
|
|
2522 | kv->value = value; |
|
|
2523 | |
|
|
2524 | key_values = kv; |
|
|
2525 | } |
2487 | } |
2526 | |
2488 | |
2527 | void |
2489 | void |
2528 | object::kv_del (shstr_tmp key) |
2490 | key_values::del (shstr_tmp key) |
2529 | { |
2491 | { |
2530 | for (key_value **kvp = &key_values; *kvp; kvp = &(*kvp)->next) |
2492 | for (key_value **kvp = &first; *kvp; kvp = &(*kvp)->next) |
2531 | if ((*kvp)->key == key) |
2493 | if ((*kvp)->key == key) |
2532 | { |
2494 | { |
2533 | key_value *kv = *kvp; |
2495 | key_value *kv = *kvp; |
2534 | *kvp = (*kvp)->next; |
2496 | *kvp = (*kvp)->next; |
2535 | delete kv; |
2497 | delete kv; |
2536 | return; |
2498 | return; |
2537 | } |
2499 | } |
|
|
2500 | } |
|
|
2501 | |
|
|
2502 | void |
|
|
2503 | key_values::reverse () |
|
|
2504 | { |
|
|
2505 | key_value *prev = 0; |
|
|
2506 | key_value *head = first; |
|
|
2507 | |
|
|
2508 | while (head) |
|
|
2509 | { |
|
|
2510 | key_value *node = head; |
|
|
2511 | head = head->next; |
|
|
2512 | node->next = prev; |
|
|
2513 | prev = node; |
|
|
2514 | } |
|
|
2515 | |
|
|
2516 | first = prev; |
|
|
2517 | } |
|
|
2518 | |
|
|
2519 | key_values & |
|
|
2520 | key_values::operator =(const key_values &kv) |
|
|
2521 | { |
|
|
2522 | clear (); |
|
|
2523 | |
|
|
2524 | for (key_value *kvp = kv.first; kvp; kvp = kvp->next) |
|
|
2525 | add (kvp->key, kvp->value); |
|
|
2526 | |
|
|
2527 | reverse (); |
2538 | } |
2528 | } |
2539 | |
2529 | |
2540 | object::depth_iterator::depth_iterator (object *container) |
2530 | object::depth_iterator::depth_iterator (object *container) |
2541 | : iterator_base (container) |
2531 | : iterator_base (container) |
2542 | { |
2532 | { |
… | |
… | |
2625 | object::region () const |
2615 | object::region () const |
2626 | { |
2616 | { |
2627 | return map ? map->region (x, y) |
2617 | return map ? map->region (x, y) |
2628 | : region::default_region (); |
2618 | : region::default_region (); |
2629 | } |
2619 | } |
|
|
2620 | |
|
|
2621 | //+GPL |
2630 | |
2622 | |
2631 | void |
2623 | void |
2632 | object::open_container (object *new_container) |
2624 | object::open_container (object *new_container) |
2633 | { |
2625 | { |
2634 | if (container == new_container) |
2626 | if (container == new_container) |
… | |
… | |
2692 | } |
2684 | } |
2693 | // else if (!old_container->env && contr && contr->ns) |
2685 | // else if (!old_container->env && contr && contr->ns) |
2694 | // contr->ns->floorbox_reset (); |
2686 | // contr->ns->floorbox_reset (); |
2695 | } |
2687 | } |
2696 | |
2688 | |
|
|
2689 | //-GPL |
|
|
2690 | |
|
|
2691 | // prefetch some flat area around the player |
|
|
2692 | static void |
|
|
2693 | prefetch_surrounding_area (object *op, maptile *map, int range) |
|
|
2694 | { |
|
|
2695 | for (maprect *rect = map->split_to_tiles (mapwalk_buf, |
|
|
2696 | op->x - range , op->y - range , |
|
|
2697 | op->x + range + 1, op->y + range + 1); |
|
|
2698 | rect->m; |
|
|
2699 | ++rect) |
|
|
2700 | { |
|
|
2701 | rect->m->touch (); |
|
|
2702 | rect->m->activate (); |
|
|
2703 | } |
|
|
2704 | } |
|
|
2705 | |
|
|
2706 | // prefetch a generous area around the player, also up and down |
|
|
2707 | void |
|
|
2708 | object::prefetch_surrounding_maps () |
|
|
2709 | { |
|
|
2710 | prefetch_surrounding_area (this, map, 40); |
|
|
2711 | |
|
|
2712 | if (maptile *m = map->tile_available (TILE_DOWN)) |
|
|
2713 | prefetch_surrounding_area (this, m, 20); |
|
|
2714 | |
|
|
2715 | if (maptile *m = map->tile_available (TILE_UP)) |
|
|
2716 | prefetch_surrounding_area (this, m, 20); |
|
|
2717 | } |
|
|
2718 | |
|
|
2719 | //+GPL |
|
|
2720 | |
2697 | object * |
2721 | object * |
2698 | object::force_find (shstr_tmp name) |
2722 | object::force_find (shstr_tmp name) |
2699 | { |
2723 | { |
2700 | /* cycle through his inventory to look for the MARK we want to |
2724 | /* cycle through his inventory to look for the MARK we want to |
2701 | * place |
2725 | * place |
… | |
… | |
2705 | return splay (tmp); |
2729 | return splay (tmp); |
2706 | |
2730 | |
2707 | return 0; |
2731 | return 0; |
2708 | } |
2732 | } |
2709 | |
2733 | |
2710 | //-GPL |
|
|
2711 | |
|
|
2712 | void |
2734 | void |
2713 | object::force_set_timer (int duration) |
2735 | object::force_set_timer (int duration) |
2714 | { |
2736 | { |
2715 | this->duration = 1; |
2737 | this->duration = 1; |
2716 | this->speed_left = -1.f; |
2738 | this->speed_left = -1.f; |
… | |
… | |
2722 | object::force_add (shstr_tmp name, int duration) |
2744 | object::force_add (shstr_tmp name, int duration) |
2723 | { |
2745 | { |
2724 | if (object *force = force_find (name)) |
2746 | if (object *force = force_find (name)) |
2725 | force->destroy (); |
2747 | force->destroy (); |
2726 | |
2748 | |
2727 | object *force = get_archetype (FORCE_NAME); |
2749 | object *force = archetype::get (FORCE_NAME); |
2728 | |
2750 | |
2729 | force->slaying = name; |
2751 | force->slaying = name; |
2730 | force->force_set_timer (duration); |
2752 | force->force_set_timer (duration); |
2731 | force->flag [FLAG_APPLIED] = true; |
2753 | force->flag [FLAG_APPLIED] = true; |
2732 | |
2754 | |