… | |
… | |
29 | #include <sys/types.h> |
29 | #include <sys/types.h> |
30 | #include <sys/uio.h> |
30 | #include <sys/uio.h> |
31 | #include <object.h> |
31 | #include <object.h> |
32 | #include <funcpoint.h> |
32 | #include <funcpoint.h> |
33 | #include <loader.h> |
33 | #include <loader.h> |
|
|
34 | |
|
|
35 | #include <bitset> |
34 | |
36 | |
35 | int nrofallocobjects = 0; |
37 | int nrofallocobjects = 0; |
36 | static UUID uuid; |
38 | static UUID uuid; |
37 | const uint64 UUID_SKIP = 1<<19; |
39 | const uint64 UUID_SKIP = 1<<19; |
38 | |
40 | |
… | |
… | |
183 | * |
185 | * |
184 | * Note that this function appears a lot longer than the macro it |
186 | * Note that this function appears a lot longer than the macro it |
185 | * replaces - this is mostly for clarity - a decent compiler should hopefully |
187 | * replaces - this is mostly for clarity - a decent compiler should hopefully |
186 | * reduce this to the same efficiency. |
188 | * reduce this to the same efficiency. |
187 | * |
189 | * |
188 | * Check nrof variable *before* calling CAN_MERGE() |
190 | * Check nrof variable *before* calling can_merge() |
189 | * |
191 | * |
190 | * Improvements made with merge: Better checking on potion, and also |
192 | * Improvements made with merge: Better checking on potion, and also |
191 | * check weight |
193 | * check weight |
192 | */ |
194 | */ |
193 | |
195 | |
194 | bool object::can_merge (object *ob1, object *ob2) |
196 | bool object::can_merge_slow (object *ob1, object *ob2) |
195 | { |
197 | { |
196 | /* A couple quicksanity checks */ |
198 | /* A couple quicksanity checks */ |
197 | if ((ob1 == ob2) || (ob1->type != ob2->type)) |
199 | if (ob1 == ob2 |
|
|
200 | || ob1->type != ob2->type |
|
|
201 | || ob1->speed != ob2->speed |
|
|
202 | || ob1->value != ob2->value |
|
|
203 | || ob1->name != ob2->name) |
198 | return 0; |
204 | return 0; |
199 | |
205 | |
200 | if (ob1->speed != ob2->speed) |
206 | //TODO: this ain't working well, use nicer and correct overflow check |
201 | return 0; |
|
|
202 | |
|
|
203 | /* Do not merge objects if nrof would overflow. We use 1UL<<31 since that |
207 | /* Do not merge objects if nrof would overflow. We use 1UL<<31 since that |
204 | * value could not be stored in a sint32 (which unfortunately sometimes is |
208 | * value could not be stored in a sint32 (which unfortunately sometimes is |
205 | * used to store nrof). |
209 | * used to store nrof). |
206 | */ |
210 | */ |
207 | if (ob1->nrof + ob2->nrof >= 1UL << 31) |
211 | if (ob1->nrof + ob2->nrof >= 1UL << 31) |
… | |
… | |
217 | SET_FLAG (ob1, FLAG_BEEN_APPLIED); |
221 | SET_FLAG (ob1, FLAG_BEEN_APPLIED); |
218 | |
222 | |
219 | if (QUERY_FLAG (ob2, FLAG_IDENTIFIED)) |
223 | if (QUERY_FLAG (ob2, FLAG_IDENTIFIED)) |
220 | SET_FLAG (ob2, FLAG_BEEN_APPLIED); |
224 | SET_FLAG (ob2, FLAG_BEEN_APPLIED); |
221 | |
225 | |
222 | |
226 | if ((ob1->flags ^ ob2->flags).reset (FLAG_INV_LOCKED).reset (FLAG_CLIENT_SENT).any () |
223 | /* the 0x400000 on flags2 is FLAG_INV_LOCK. I don't think something |
227 | || ob1->arch != ob2->arch |
224 | * being locked in inventory should prevent merging. |
|
|
225 | * 0x4 in flags3 is CLIENT_SENT |
|
|
226 | */ |
|
|
227 | if ((ob1->arch != ob2->arch) || |
|
|
228 | (ob1->flags[0] != ob2->flags[0]) || |
|
|
229 | (ob1->flags[1] != ob2->flags[1]) || |
|
|
230 | ((ob1->flags[2] & ~0x400000) != (ob2->flags[2] & ~0x400000)) || |
|
|
231 | ((ob1->flags[3] & ~0x4) != (ob2->flags[3] & ~0x4)) || |
|
|
232 | (ob1->name != ob2->name) || |
228 | || ob1->name != ob2->name |
233 | (ob1->title != ob2->title) || |
229 | || ob1->title != ob2->title |
234 | (ob1->msg != ob2->msg) || |
230 | || ob1->msg != ob2->msg |
235 | (ob1->weight != ob2->weight) || |
231 | || ob1->weight != ob2->weight |
236 | (memcmp (&ob1->resist, &ob2->resist, sizeof (ob1->resist)) != 0) || |
232 | || memcmp (&ob1->resist, &ob2->resist, sizeof (ob1->resist)) |
237 | (memcmp (&ob1->stats, &ob2->stats, sizeof (ob1->stats)) != 0) || |
233 | || memcmp (&ob1->stats , &ob2->stats , sizeof (ob1->stats) ) |
238 | (ob1->attacktype != ob2->attacktype) || |
234 | || ob1->attacktype != ob2->attacktype |
239 | (ob1->magic != ob2->magic) || |
235 | || ob1->magic != ob2->magic |
240 | (ob1->slaying != ob2->slaying) || |
236 | || ob1->slaying != ob2->slaying |
241 | (ob1->skill != ob2->skill) || |
237 | || ob1->skill != ob2->skill |
242 | (ob1->value != ob2->value) || |
238 | || ob1->value != ob2->value |
243 | (ob1->animation_id != ob2->animation_id) || |
239 | || ob1->animation_id != ob2->animation_id |
244 | (ob1->client_type != ob2->client_type) || |
240 | || ob1->client_type != ob2->client_type |
245 | (ob1->materialname != ob2->materialname) || |
241 | || ob1->materialname != ob2->materialname |
246 | (ob1->lore != ob2->lore) || |
242 | || ob1->lore != ob2->lore |
247 | (ob1->subtype != ob2->subtype) || |
243 | || ob1->subtype != ob2->subtype |
248 | (ob1->move_type != ob2->move_type) || |
244 | || ob1->move_type != ob2->move_type |
249 | (ob1->move_block != ob2->move_block) || |
245 | || ob1->move_block != ob2->move_block |
250 | (ob1->move_allow != ob2->move_allow) || |
246 | || ob1->move_allow != ob2->move_allow |
251 | (ob1->move_on != ob2->move_on) || |
247 | || ob1->move_on != ob2->move_on |
252 | (ob1->move_off != ob2->move_off) || (ob1->move_slow != ob2->move_slow) || (ob1->move_slow_penalty != ob2->move_slow_penalty)) |
248 | || ob1->move_off != ob2->move_off |
|
|
249 | || ob1->move_slow != ob2->move_slow |
|
|
250 | || ob1->move_slow_penalty != ob2->move_slow_penalty) |
253 | return 0; |
251 | return 0; |
254 | |
252 | |
255 | /* This is really a spellbook check - really, we should |
253 | /* This is really a spellbook check - really, we should |
256 | * check all objects in the inventory. |
254 | * check all objects in the inventory. |
257 | */ |
255 | */ |
… | |
… | |
260 | /* if one object has inventory but the other doesn't, not equiv */ |
258 | /* if one object has inventory but the other doesn't, not equiv */ |
261 | if ((ob1->inv && !ob2->inv) || (ob2->inv && !ob1->inv)) |
259 | if ((ob1->inv && !ob2->inv) || (ob2->inv && !ob1->inv)) |
262 | return 0; |
260 | return 0; |
263 | |
261 | |
264 | /* Now check to see if the two inventory objects could merge */ |
262 | /* Now check to see if the two inventory objects could merge */ |
265 | if (!CAN_MERGE (ob1->inv, ob2->inv)) |
263 | if (!object::can_merge (ob1->inv, ob2->inv)) |
266 | return 0; |
264 | return 0; |
267 | |
265 | |
268 | /* inventory ok - still need to check rest of this object to see |
266 | /* inventory ok - still need to check rest of this object to see |
269 | * if it is valid. |
267 | * if it is valid. |
270 | */ |
268 | */ |
… | |
… | |
350 | object * |
348 | object * |
351 | object_get_env_recursive (object *op) |
349 | object_get_env_recursive (object *op) |
352 | { |
350 | { |
353 | while (op->env != NULL) |
351 | while (op->env != NULL) |
354 | op = op->env; |
352 | op = op->env; |
355 | return op; |
|
|
356 | } |
|
|
357 | |
|
|
358 | /* |
|
|
359 | * Eneq(@csd.uu.se): Since we can have items buried in a character we need |
|
|
360 | * a better check. We basically keeping traversing up until we can't |
|
|
361 | * or find a player. |
|
|
362 | */ |
|
|
363 | |
|
|
364 | object * |
|
|
365 | is_player_inv (object *op) |
|
|
366 | { |
|
|
367 | for (; op != NULL && op->type != PLAYER; op = op->env) |
|
|
368 | if (op->env == op) |
|
|
369 | op->env = NULL; |
|
|
370 | return op; |
353 | return op; |
371 | } |
354 | } |
372 | |
355 | |
373 | /* |
356 | /* |
374 | * Used by: Crossedit: dump. Server DM commands: dumpbelow, dump. |
357 | * Used by: Crossedit: dump. Server DM commands: dumpbelow, dump. |
… | |
… | |
1057 | |
1040 | |
1058 | /* NO_FIX_PLAYER is set when a great many changes are being |
1041 | /* NO_FIX_PLAYER is set when a great many changes are being |
1059 | * made to players inventory. If set, avoiding the call |
1042 | * made to players inventory. If set, avoiding the call |
1060 | * to save cpu time. |
1043 | * to save cpu time. |
1061 | */ |
1044 | */ |
1062 | if ((otmp = is_player_inv (env)) != NULL && otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) |
1045 | if ((otmp = in_player ()) && otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) |
1063 | fix_player (otmp); |
1046 | fix_player (otmp); |
1064 | |
1047 | |
1065 | if (above != NULL) |
1048 | if (above != NULL) |
1066 | above->below = below; |
1049 | above->below = below; |
1067 | else |
1050 | else |
… | |
… | |
1138 | { |
1121 | { |
1139 | CLEAR_FLAG (this, FLAG_APPLIED); |
1122 | CLEAR_FLAG (this, FLAG_APPLIED); |
1140 | tmp->container = 0; |
1123 | tmp->container = 0; |
1141 | } |
1124 | } |
1142 | |
1125 | |
1143 | tmp->contr->socket.update_look = 1; |
1126 | tmp->contr->socket->floorbox_update (); |
1144 | } |
1127 | } |
1145 | |
1128 | |
1146 | /* See if player moving off should effect something */ |
1129 | /* See if player moving off should effect something */ |
1147 | if (check_walk_off |
1130 | if (check_walk_off |
1148 | && ((move_type & tmp->move_off) |
1131 | && ((move_type & tmp->move_off) |
… | |
… | |
1200 | |
1183 | |
1201 | for (; top != NULL; top = top->below) |
1184 | for (; top != NULL; top = top->below) |
1202 | { |
1185 | { |
1203 | if (top == op) |
1186 | if (top == op) |
1204 | continue; |
1187 | continue; |
1205 | if (CAN_MERGE (op, top)) |
1188 | |
|
|
1189 | if (object::can_merge (op, top)) |
1206 | { |
1190 | { |
1207 | top->nrof += op->nrof; |
1191 | top->nrof += op->nrof; |
1208 | |
1192 | |
1209 | /* CLEAR_FLAG(top,FLAG_STARTEQUIP);*/ |
1193 | /* CLEAR_FLAG(top,FLAG_STARTEQUIP);*/ |
1210 | op->weight = 0; /* Don't want any adjustements now */ |
1194 | op->weight = 0; /* Don't want any adjustements now */ |
… | |
… | |
1343 | |
1327 | |
1344 | /* this has to be done after we translate the coordinates. |
1328 | /* this has to be done after we translate the coordinates. |
1345 | */ |
1329 | */ |
1346 | if (op->nrof && !(flag & INS_NO_MERGE)) |
1330 | if (op->nrof && !(flag & INS_NO_MERGE)) |
1347 | for (tmp = GET_MAP_OB (op->map, x, y); tmp != NULL; tmp = tmp->above) |
1331 | for (tmp = GET_MAP_OB (op->map, x, y); tmp != NULL; tmp = tmp->above) |
1348 | if (CAN_MERGE (op, tmp)) |
1332 | if (object::can_merge (op, tmp)) |
1349 | { |
1333 | { |
1350 | op->nrof += tmp->nrof; |
1334 | op->nrof += tmp->nrof; |
1351 | tmp->destroy (); |
1335 | tmp->destroy (); |
1352 | } |
1336 | } |
1353 | |
1337 | |
… | |
… | |
1484 | * it, so save a few ticks and start from there. |
1468 | * it, so save a few ticks and start from there. |
1485 | */ |
1469 | */ |
1486 | if (!(flag & INS_MAP_LOAD)) |
1470 | if (!(flag & INS_MAP_LOAD)) |
1487 | for (tmp = floor ? floor : GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) |
1471 | for (tmp = floor ? floor : GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) |
1488 | if (tmp->type == PLAYER) |
1472 | if (tmp->type == PLAYER) |
1489 | tmp->contr->socket.update_look = 1; |
1473 | tmp->contr->socket->floorbox_update (); |
1490 | |
1474 | |
1491 | /* If this object glows, it may affect lighting conditions that are |
1475 | /* If this object glows, it may affect lighting conditions that are |
1492 | * visible to others on this map. But update_all_los is really |
1476 | * visible to others on this map. But update_all_los is really |
1493 | * an inefficient way to do this, as it means los for all players |
1477 | * an inefficient way to do this, as it means los for all players |
1494 | * on the map will get recalculated. The players could very well |
1478 | * on the map will get recalculated. The players could very well |
… | |
… | |
1502 | |
1486 | |
1503 | /* updates flags (blocked, alive, no magic, etc) for this map space */ |
1487 | /* updates flags (blocked, alive, no magic, etc) for this map space */ |
1504 | update_object (op, UP_OBJ_INSERT); |
1488 | update_object (op, UP_OBJ_INSERT); |
1505 | |
1489 | |
1506 | /* Don't know if moving this to the end will break anything. However, |
1490 | /* Don't know if moving this to the end will break anything. However, |
1507 | * we want to have update_look set above before calling this. |
1491 | * we want to have floorbox_update called before calling this. |
1508 | * |
1492 | * |
1509 | * check_move_on() must be after this because code called from |
1493 | * check_move_on() must be after this because code called from |
1510 | * check_move_on() depends on correct map flags (so functions like |
1494 | * check_move_on() depends on correct map flags (so functions like |
1511 | * blocked() and wall() work properly), and these flags are updated by |
1495 | * blocked() and wall() work properly), and these flags are updated by |
1512 | * update_object(). |
1496 | * update_object(). |
… | |
… | |
1615 | if (i > op->nrof) |
1599 | if (i > op->nrof) |
1616 | i = op->nrof; |
1600 | i = op->nrof; |
1617 | |
1601 | |
1618 | if (QUERY_FLAG (op, FLAG_REMOVED)) |
1602 | if (QUERY_FLAG (op, FLAG_REMOVED)) |
1619 | op->nrof -= i; |
1603 | op->nrof -= i; |
1620 | else if (op->env != NULL) |
1604 | else if (op->env) |
1621 | { |
1605 | { |
1622 | /* is this object in the players inventory, or sub container |
1606 | /* is this object in the players inventory, or sub container |
1623 | * therein? |
1607 | * therein? |
1624 | */ |
1608 | */ |
1625 | tmp = is_player_inv (op->env); |
1609 | tmp = op->in_player (); |
1626 | /* nope. Is this a container the player has opened? |
1610 | /* nope. Is this a container the player has opened? |
1627 | * If so, set tmp to that player. |
1611 | * If so, set tmp to that player. |
1628 | * IMO, searching through all the players will mostly |
1612 | * IMO, searching through all the players will mostly |
1629 | * likely be quicker than following op->env to the map, |
1613 | * likely be quicker than following op->env to the map, |
1630 | * and then searching the map for a player. |
1614 | * and then searching the map for a player. |
1631 | */ |
1615 | */ |
1632 | if (!tmp) |
1616 | if (!tmp) |
1633 | { |
1617 | { |
1634 | for (pl = first_player; pl; pl = pl->next) |
1618 | for (pl = first_player; pl; pl = pl->next) |
1635 | if (pl->ob->container == op->env) |
1619 | if (pl->ob->container == op->env) |
|
|
1620 | { |
|
|
1621 | tmp = pl->ob; |
1636 | break; |
1622 | break; |
1637 | if (pl) |
1623 | } |
1638 | tmp = pl->ob; |
|
|
1639 | else |
|
|
1640 | tmp = NULL; |
|
|
1641 | } |
1624 | } |
1642 | |
1625 | |
1643 | if (i < op->nrof) |
1626 | if (i < op->nrof) |
1644 | { |
1627 | { |
1645 | sub_weight (op->env, op->weight * i); |
1628 | sub_weight (op->env, op->weight * i); |
1646 | op->nrof -= i; |
1629 | op->nrof -= i; |
1647 | if (tmp) |
1630 | if (tmp) |
1648 | { |
|
|
1649 | esrv_send_item (tmp, op); |
1631 | esrv_send_item (tmp, op); |
1650 | } |
|
|
1651 | } |
1632 | } |
1652 | else |
1633 | else |
1653 | { |
1634 | { |
1654 | op->remove (); |
1635 | op->remove (); |
1655 | op->nrof = 0; |
1636 | op->nrof = 0; |
1656 | if (tmp) |
1637 | if (tmp) |
1657 | { |
|
|
1658 | esrv_del_item (tmp->contr, op->count); |
1638 | esrv_del_item (tmp->contr, op->count); |
1659 | } |
|
|
1660 | } |
1639 | } |
1661 | } |
1640 | } |
1662 | else |
1641 | else |
1663 | { |
1642 | { |
1664 | object *above = op->above; |
1643 | object *above = op->above; |
… | |
… | |
1670 | op->remove (); |
1649 | op->remove (); |
1671 | op->nrof = 0; |
1650 | op->nrof = 0; |
1672 | } |
1651 | } |
1673 | |
1652 | |
1674 | /* Since we just removed op, op->above is null */ |
1653 | /* Since we just removed op, op->above is null */ |
1675 | for (tmp = above; tmp != NULL; tmp = tmp->above) |
1654 | for (tmp = above; tmp; tmp = tmp->above) |
1676 | if (tmp->type == PLAYER) |
1655 | if (tmp->type == PLAYER) |
1677 | { |
1656 | { |
1678 | if (op->nrof) |
1657 | if (op->nrof) |
1679 | esrv_send_item (tmp, op); |
1658 | esrv_send_item (tmp, op); |
1680 | else |
1659 | else |
… | |
… | |
1685 | if (op->nrof) |
1664 | if (op->nrof) |
1686 | return op; |
1665 | return op; |
1687 | else |
1666 | else |
1688 | { |
1667 | { |
1689 | op->destroy (); |
1668 | op->destroy (); |
1690 | return NULL; |
1669 | return 0; |
1691 | } |
1670 | } |
1692 | } |
1671 | } |
1693 | |
1672 | |
1694 | /* |
1673 | /* |
1695 | * add_weight(object, weight) adds the specified weight to an object, |
1674 | * add_weight(object, weight) adds the specified weight to an object, |
… | |
… | |
1755 | CLEAR_FLAG (op, FLAG_OBJ_ORIGINAL); |
1734 | CLEAR_FLAG (op, FLAG_OBJ_ORIGINAL); |
1756 | CLEAR_FLAG (op, FLAG_REMOVED); |
1735 | CLEAR_FLAG (op, FLAG_REMOVED); |
1757 | if (op->nrof) |
1736 | if (op->nrof) |
1758 | { |
1737 | { |
1759 | for (tmp = inv; tmp != NULL; tmp = tmp->below) |
1738 | for (tmp = inv; tmp != NULL; tmp = tmp->below) |
1760 | if (CAN_MERGE (tmp, op)) |
1739 | if (object::can_merge (tmp, op)) |
1761 | { |
1740 | { |
1762 | /* return the original object and remove inserted object |
1741 | /* return the original object and remove inserted object |
1763 | (client needs the original object) */ |
1742 | (client needs the original object) */ |
1764 | tmp->nrof += op->nrof; |
1743 | tmp->nrof += op->nrof; |
1765 | /* Weight handling gets pretty funky. Since we are adding to |
1744 | /* Weight handling gets pretty funky. Since we are adding to |
… | |
… | |
1783 | add_weight (this, op->weight * op->nrof); |
1762 | add_weight (this, op->weight * op->nrof); |
1784 | } |
1763 | } |
1785 | else |
1764 | else |
1786 | add_weight (this, (op->weight + op->carrying)); |
1765 | add_weight (this, (op->weight + op->carrying)); |
1787 | |
1766 | |
1788 | otmp = is_player_inv (this); |
1767 | otmp = this->in_player (); |
1789 | if (otmp && otmp->contr) |
1768 | if (otmp && otmp->contr) |
1790 | if (!QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) |
1769 | if (!QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) |
1791 | fix_player (otmp); |
1770 | fix_player (otmp); |
1792 | |
1771 | |
1793 | op->map = NULL; |
1772 | op->map = 0; |
1794 | op->env = this; |
1773 | op->env = this; |
1795 | op->above = NULL; |
1774 | op->above = 0; |
1796 | op->below = NULL; |
1775 | op->below = 0; |
1797 | op->x = 0, op->y = 0; |
1776 | op->x = 0, op->y = 0; |
1798 | |
1777 | |
1799 | /* reset the light list and los of the players on the map */ |
1778 | /* reset the light list and los of the players on the map */ |
1800 | if ((op->glow_radius != 0) && map) |
1779 | if ((op->glow_radius != 0) && map) |
1801 | { |
1780 | { |
… | |
… | |
2138 | * if the space being examined only has a wall to the north and empty |
2117 | * if the space being examined only has a wall to the north and empty |
2139 | * spaces in all the other directions, this will reduce the search space |
2118 | * spaces in all the other directions, this will reduce the search space |
2140 | * to only the spaces immediately surrounding the target area, and |
2119 | * to only the spaces immediately surrounding the target area, and |
2141 | * won't look 2 spaces south of the target space. |
2120 | * won't look 2 spaces south of the target space. |
2142 | */ |
2121 | */ |
2143 | else if ((flag & AB_NO_PASS) && maxfree[i] < stop) |
2122 | else if ((flag & P_NO_PASS) && maxfree[i] < stop) |
2144 | stop = maxfree[i]; |
2123 | stop = maxfree[i]; |
2145 | } |
2124 | } |
|
|
2125 | |
2146 | if (!index) |
2126 | if (!index) |
2147 | return -1; |
2127 | return -1; |
|
|
2128 | |
2148 | return altern[RANDOM () % index]; |
2129 | return altern[RANDOM () % index]; |
2149 | } |
2130 | } |
2150 | |
2131 | |
2151 | /* |
2132 | /* |
2152 | * find_first_free_spot(archetype, maptile, x, y) works like |
2133 | * find_first_free_spot(archetype, maptile, x, y) works like |