… | |
… | |
52 | 0, |
52 | 0, |
53 | -1, -1, 0, 1, 1, 1, 0, -1, |
53 | -1, -1, 0, 1, 1, 1, 0, -1, |
54 | -2, -2, -2, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, |
54 | -2, -2, -2, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, |
55 | -3, -3, -3, -3, -2, -1, 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3 |
55 | -3, -3, -3, -3, -2, -1, 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3 |
56 | }; |
56 | }; |
57 | int maxfree[SIZEOFFREE] = { |
|
|
58 | 0, |
|
|
59 | 9, 10, 13, 14, 17, 18, 21, 22, |
|
|
60 | 25, 26, 27, 30, 31, 32, 33, 36, 37, 39, 39, 42, 43, 44, 45, 48, |
|
|
61 | 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49 |
|
|
62 | }; |
|
|
63 | int freedir[SIZEOFFREE] = { |
57 | int freedir[SIZEOFFREE] = { |
64 | 0, |
58 | 0, |
65 | 1, 2, 3, 4, 5, 6, 7, 8, |
59 | 1, 2, 3, 4, 5, 6, 7, 8, |
66 | 1, 2, 2, 2, 3, 4, 4, 4, 5, 6, 6, 6, 7, 8, 8, 8, |
60 | 1, 2, 2, 2, 3, 4, 4, 4, 5, 6, 6, 6, 7, 8, 8, 8, |
67 | 1, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4, 5, 6, 6, 6, 6, 6, 7, 8, 8, 8, 8, 8 |
61 | 1, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4, 5, 6, 6, 6, 6, 6, 7, 8, 8, 8, 8, 8 |
|
|
62 | }; |
|
|
63 | |
|
|
64 | static int maxfree[SIZEOFFREE] = { |
|
|
65 | 0, |
|
|
66 | 9, 10, 13, 14, 17, 18, 21, 22, |
|
|
67 | 25, 26, 27, 30, 31, 32, 33, 36, 37, 39, 39, 42, 43, 44, 45, 48, |
|
|
68 | 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49 |
68 | }; |
69 | }; |
69 | |
70 | |
70 | static void |
71 | static void |
71 | write_uuid (uval64 skip, bool sync) |
72 | write_uuid (uval64 skip, bool sync) |
72 | { |
73 | { |
… | |
… | |
185 | bool object::can_merge_slow (object *ob1, object *ob2) |
186 | bool object::can_merge_slow (object *ob1, object *ob2) |
186 | { |
187 | { |
187 | /* A couple quicksanity checks */ |
188 | /* A couple quicksanity checks */ |
188 | if (ob1 == ob2 |
189 | if (ob1 == ob2 |
189 | || ob1->type != ob2->type |
190 | || ob1->type != ob2->type |
190 | || ob1->speed != ob2->speed |
191 | || fabs (ob1->speed - ob2->speed) >= MIN_ACTIVE_SPEED |
191 | || ob1->value != ob2->value |
192 | || ob1->value != ob2->value |
192 | || ob1->name != ob2->name) |
193 | || ob1->name != ob2->name) |
193 | return 0; |
194 | return 0; |
194 | |
195 | |
195 | /* Do not merge objects if nrof would overflow, assume nrof |
196 | /* Do not merge objects if nrof would overflow, assume nrof |
… | |
… | |
229 | || ob1->move_block != ob2->move_block |
230 | || ob1->move_block != ob2->move_block |
230 | || ob1->move_allow != ob2->move_allow |
231 | || ob1->move_allow != ob2->move_allow |
231 | || ob1->move_on != ob2->move_on |
232 | || ob1->move_on != ob2->move_on |
232 | || ob1->move_off != ob2->move_off |
233 | || ob1->move_off != ob2->move_off |
233 | || ob1->move_slow != ob2->move_slow |
234 | || ob1->move_slow != ob2->move_slow |
234 | || ob1->move_slow_penalty != ob2->move_slow_penalty |
235 | || fabs (ob1->move_slow_penalty - ob2->move_slow_penalty) >= (1.f / 1024.f) |
235 | || memcmp (&ob1->resist, &ob2->resist, sizeof (ob1->resist)) |
236 | || memcmp (&ob1->resist, &ob2->resist, sizeof (ob1->resist)) |
236 | || memcmp (&ob1->stats , &ob2->stats , sizeof (ob1->stats))) |
237 | || memcmp (&ob1->stats , &ob2->stats , sizeof (ob1->stats))) |
237 | return 0; |
238 | return 0; |
238 | |
239 | |
239 | if ((ob1->flag ^ ob2->flag) |
240 | if ((ob1->flag ^ ob2->flag) |
… | |
… | |
441 | { |
442 | { |
442 | return dump_object (this); |
443 | return dump_object (this); |
443 | } |
444 | } |
444 | |
445 | |
445 | /* |
446 | /* |
446 | * get_nearest_part(multi-object, object 2) returns the part of the |
|
|
447 | * multi-object 1 which is closest to the second object. |
|
|
448 | * If it's not a multi-object, it is returned. |
|
|
449 | */ |
|
|
450 | object * |
|
|
451 | get_nearest_part (object *op, const object *pl) |
|
|
452 | { |
|
|
453 | object *tmp, *closest; |
|
|
454 | int last_dist, i; |
|
|
455 | |
|
|
456 | if (!op->more) |
|
|
457 | return op; |
|
|
458 | |
|
|
459 | for (last_dist = distance (op, pl), closest = op, tmp = op->more; |
|
|
460 | tmp; |
|
|
461 | tmp = tmp->more) |
|
|
462 | if ((i = distance (tmp, pl)) < last_dist) |
|
|
463 | closest = tmp, last_dist = i; |
|
|
464 | |
|
|
465 | return closest; |
|
|
466 | } |
|
|
467 | |
|
|
468 | /* |
|
|
469 | * Returns the object which has the count-variable equal to the argument. |
447 | * Returns the object which has the count-variable equal to the argument. |
470 | * VERRRY slow. |
448 | * VERRRY slow. |
471 | */ |
449 | */ |
472 | object * |
450 | object * |
473 | find_object (tag_t i) |
451 | find_object (tag_t i) |
… | |
… | |
701 | * This function needs to be called whenever the speed of an object changes. |
679 | * This function needs to be called whenever the speed of an object changes. |
702 | */ |
680 | */ |
703 | void |
681 | void |
704 | object::set_speed (float speed) |
682 | object::set_speed (float speed) |
705 | { |
683 | { |
706 | if (flag [FLAG_FREED] && speed) |
|
|
707 | { |
|
|
708 | LOG (llevError, "Object %s is freed but has speed.\n", &name); |
|
|
709 | speed = 0; |
|
|
710 | } |
|
|
711 | |
|
|
712 | this->speed = speed; |
684 | this->speed = speed; |
713 | |
685 | |
714 | if (has_active_speed ()) |
686 | if (has_active_speed ()) |
715 | activate (); |
687 | activate (); |
716 | else |
688 | else |
… | |
… | |
766 | |
738 | |
767 | if (!(m.flags_ & P_UPTODATE)) |
739 | if (!(m.flags_ & P_UPTODATE)) |
768 | /* nop */; |
740 | /* nop */; |
769 | else if (action == UP_OBJ_INSERT) |
741 | else if (action == UP_OBJ_INSERT) |
770 | { |
742 | { |
|
|
743 | #if 0 |
771 | // this is likely overkill, TODO: revisit (schmorp) |
744 | // this is likely overkill, TODO: revisit (schmorp) |
772 | if ((QUERY_FLAG (op, FLAG_BLOCKSVIEW) && !(m.flags_ & P_BLOCKSVIEW)) |
745 | if ((QUERY_FLAG (op, FLAG_BLOCKSVIEW) && !(m.flags_ & P_BLOCKSVIEW)) |
773 | || (QUERY_FLAG (op, FLAG_NO_MAGIC) && !(m.flags_ & P_NO_MAGIC)) |
746 | || (QUERY_FLAG (op, FLAG_NO_MAGIC) && !(m.flags_ & P_NO_MAGIC)) |
774 | || (op->is_player () && !(m.flags_ & P_PLAYER)) |
747 | || (op->is_player () && !(m.flags_ & P_PLAYER)) |
775 | || (op->type == SAFE_GROUND && !(m.flags_ & P_SAFE)) |
748 | || (op->type == SAFE_GROUND && !(m.flags_ & P_SAFE)) |
… | |
… | |
780 | || (m.move_slow | op->move_slow) != m.move_slow |
753 | || (m.move_slow | op->move_slow) != m.move_slow |
781 | /* This isn't perfect, but I don't expect a lot of objects to |
754 | /* This isn't perfect, but I don't expect a lot of objects to |
782 | * have move_allow right now. |
755 | * have move_allow right now. |
783 | */ |
756 | */ |
784 | || ((m.move_block | op->move_block) & ~op->move_allow) != m.move_block |
757 | || ((m.move_block | op->move_block) & ~op->move_allow) != m.move_block |
785 | || 1) // the above is not strong enough a test to skip updating. los maybe? TODO (Schmorp) |
|
|
786 | m.invalidate (); |
758 | m.invalidate (); |
|
|
759 | #else |
|
|
760 | // the above is not strong enough a test to skip updating. los maybe? TODO (schmorp) |
|
|
761 | m.invalidate (); |
|
|
762 | #endif |
787 | } |
763 | } |
788 | /* if the object is being removed, we can't make intelligent |
764 | /* if the object is being removed, we can't make intelligent |
789 | * decisions, because remove_ob can't really pass the object |
765 | * decisions, because remove_ob can't really pass the object |
790 | * that is being removed. |
766 | * that is being removed. |
791 | */ |
767 | */ |
… | |
… | |
1527 | return where->env->insert (this); |
1503 | return where->env->insert (this); |
1528 | else |
1504 | else |
1529 | return where->map->insert (this, where->x, where->y, originator, flags); |
1505 | return where->map->insert (this, where->x, where->y, originator, flags); |
1530 | } |
1506 | } |
1531 | |
1507 | |
|
|
1508 | // check whether we can put this into the map, respect max_nrof, max_volume, max_items |
|
|
1509 | bool |
|
|
1510 | object::can_drop_at (maptile *m, int x, int y, object *originator) |
|
|
1511 | { |
|
|
1512 | mapspace &ms = m->at (x, y); |
|
|
1513 | |
|
|
1514 | int items = ms.items (); |
|
|
1515 | |
|
|
1516 | if (!items // testing !items ensures we can drop at least one item |
|
|
1517 | || (items < m->max_items |
|
|
1518 | && ms.volume () < m->max_volume |
|
|
1519 | && nrof <= m->max_nrof)) |
|
|
1520 | return true; |
|
|
1521 | |
|
|
1522 | if (originator && originator->is_player ()) |
|
|
1523 | originator->contr->failmsg (format ( |
|
|
1524 | "No matter how hard you try, you just cannot put the %s here H<Try to remove some items from the floor first.>", |
|
|
1525 | query_name () |
|
|
1526 | )); |
|
|
1527 | |
|
|
1528 | return false; |
|
|
1529 | } |
|
|
1530 | |
1532 | /* |
1531 | /* |
1533 | * decrease(object, number) decreases a specified number from |
1532 | * decrease(object, number) decreases a specified number from |
1534 | * the amount of an object. If the amount reaches 0, the object |
1533 | * the amount of an object. If the amount reaches 0, the object |
1535 | * is subsequently removed and freed. |
1534 | * is subsequently removed and freed. |
1536 | * |
1535 | * |
… | |
… | |
2173 | * This basically means that if direction is 15, then it could either go |
2172 | * This basically means that if direction is 15, then it could either go |
2174 | * direction 4, 14, or 16 to get back to where we are. |
2173 | * direction 4, 14, or 16 to get back to where we are. |
2175 | * Moved from spell_util.c to object.c with the other related direction |
2174 | * Moved from spell_util.c to object.c with the other related direction |
2176 | * functions. |
2175 | * functions. |
2177 | */ |
2176 | */ |
2178 | const int reduction_dir[SIZEOFFREE][3] = { |
2177 | static const int reduction_dir[SIZEOFFREE][3] = { |
2179 | {0, 0, 0}, /* 0 */ |
2178 | {0, 0, 0}, /* 0 */ |
2180 | {0, 0, 0}, /* 1 */ |
2179 | {0, 0, 0}, /* 1 */ |
2181 | {0, 0, 0}, /* 2 */ |
2180 | {0, 0, 0}, /* 2 */ |
2182 | {0, 0, 0}, /* 3 */ |
2181 | {0, 0, 0}, /* 3 */ |
2183 | {0, 0, 0}, /* 4 */ |
2182 | {0, 0, 0}, /* 4 */ |