… | |
… | |
330 | |
330 | |
331 | /* Everything passes, must be OK. */ |
331 | /* Everything passes, must be OK. */ |
332 | return 1; |
332 | return 1; |
333 | } |
333 | } |
334 | |
334 | |
|
|
335 | // find player who can see this object |
|
|
336 | object * |
|
|
337 | object::visible_to () const |
|
|
338 | { |
|
|
339 | if (!flag [FLAG_REMOVED]) |
|
|
340 | { |
|
|
341 | // see if we are in a container of sorts |
|
|
342 | if (env) |
|
|
343 | { |
|
|
344 | // the player inventory itself is always visible |
|
|
345 | if (env->type == PLAYER) |
|
|
346 | return env; |
|
|
347 | |
|
|
348 | // else a player could have our env open |
|
|
349 | object *envest = env->outer_env (); |
|
|
350 | |
|
|
351 | // the player itself is always on a map, so we will find him here |
|
|
352 | // even if our inv is in a player. |
|
|
353 | if (envest->is_on_map ()) |
|
|
354 | if (object *pl = envest->ms ().player ()) |
|
|
355 | if (pl->container == env) |
|
|
356 | return pl; |
|
|
357 | } |
|
|
358 | else |
|
|
359 | { |
|
|
360 | // maybe there is a player standing on the same mapspace |
|
|
361 | // this will catch the case where "this" is a player |
|
|
362 | if (object *pl = ms ().player ()) |
|
|
363 | return pl; |
|
|
364 | } |
|
|
365 | } |
|
|
366 | |
|
|
367 | return 0; |
|
|
368 | } |
|
|
369 | |
335 | // adjust weight per container type ("of holding") |
370 | // adjust weight per container type ("of holding") |
336 | static sint32 |
371 | static sint32 |
337 | weight_adjust (object *op, sint32 weight) |
372 | weight_adjust (object *op, sint32 weight) |
338 | { |
373 | { |
339 | return op->type == CONTAINER |
374 | return op->type == CONTAINER |
… | |
… | |
356 | return; |
391 | return; |
357 | |
392 | |
358 | op->carrying += weight; |
393 | op->carrying += weight; |
359 | |
394 | |
360 | if (object *pl = op->visible_to ()) |
395 | if (object *pl = op->visible_to ()) |
|
|
396 | if (pl != op) // player is handled lazily |
361 | esrv_update_item (UPD_WEIGHT, pl, op); |
397 | esrv_update_item (UPD_WEIGHT, pl, op); |
362 | |
398 | |
363 | op = op->env; |
399 | op = op->env; |
364 | } |
400 | } |
365 | } |
401 | } |
366 | |
402 | |
… | |
… | |
387 | if (sum != carrying) |
423 | if (sum != carrying) |
388 | { |
424 | { |
389 | carrying = sum; |
425 | carrying = sum; |
390 | |
426 | |
391 | if (object *pl = visible_to ()) |
427 | if (object *pl = visible_to ()) |
|
|
428 | if (pl != this) // player is handled lazily |
392 | esrv_update_item (UPD_WEIGHT, pl, this); |
429 | esrv_update_item (UPD_WEIGHT, pl, this); |
393 | } |
430 | } |
394 | } |
431 | } |
395 | |
432 | |
396 | /* |
433 | /* |
397 | * Used by: Server DM commands: dumpbelow, dump. Some error messages. |
434 | * Used by: Server DM commands: dumpbelow, dump. Some error messages. |
… | |
… | |
930 | } |
967 | } |
931 | |
968 | |
932 | void |
969 | void |
933 | object::do_destroy () |
970 | object::do_destroy () |
934 | { |
971 | { |
935 | if (object *pl = visible_to ()) |
|
|
936 | esrv_del_item (pl->contr, count); |
|
|
937 | |
|
|
938 | attachable::do_destroy (); |
|
|
939 | |
|
|
940 | if (flag [FLAG_IS_LINKED]) |
972 | if (flag [FLAG_IS_LINKED]) |
941 | remove_button_link (this); |
973 | remove_button_link (this); |
942 | |
974 | |
943 | if (flag [FLAG_FRIENDLY]) |
975 | if (flag [FLAG_FRIENDLY]) |
944 | remove_friendly_object (this); |
976 | remove_friendly_object (this); |
945 | |
977 | |
946 | if (!flag [FLAG_REMOVED]) |
|
|
947 | remove (); |
978 | remove (); |
|
|
979 | |
|
|
980 | attachable::do_destroy (); |
948 | |
981 | |
949 | destroy_inv (true); |
982 | destroy_inv (true); |
950 | |
983 | |
951 | deactivate (); |
984 | deactivate (); |
952 | unlink (); |
985 | unlink (); |
… | |
… | |
1020 | object::do_remove () |
1053 | object::do_remove () |
1021 | { |
1054 | { |
1022 | object *tmp, *last = 0; |
1055 | object *tmp, *last = 0; |
1023 | object *otmp; |
1056 | object *otmp; |
1024 | |
1057 | |
1025 | if (QUERY_FLAG (this, FLAG_REMOVED)) |
1058 | if (flag [FLAG_REMOVED]) |
1026 | return; |
1059 | return; |
1027 | |
1060 | |
1028 | SET_FLAG (this, FLAG_REMOVED); |
|
|
1029 | INVOKE_OBJECT (REMOVE, this); |
1061 | INVOKE_OBJECT (REMOVE, this); |
|
|
1062 | |
|
|
1063 | if (object *pl = visible_to ()) |
|
|
1064 | esrv_del_item (pl->contr, count); |
|
|
1065 | |
|
|
1066 | flag [FLAG_REMOVED] = true; |
1030 | |
1067 | |
1031 | if (more) |
1068 | if (more) |
1032 | more->remove (); |
1069 | more->remove (); |
1033 | |
1070 | |
1034 | /* |
1071 | /* |
… | |
… | |
1169 | if (!top) |
1206 | if (!top) |
1170 | for (top = op; top && top->above; top = top->above) |
1207 | for (top = op; top && top->above; top = top->above) |
1171 | ; |
1208 | ; |
1172 | |
1209 | |
1173 | for (; top; top = top->below) |
1210 | for (; top; top = top->below) |
1174 | { |
|
|
1175 | if (top == op) |
|
|
1176 | continue; |
|
|
1177 | |
|
|
1178 | if (object::can_merge (op, top)) |
1211 | if (object::can_merge (op, top)) |
1179 | { |
1212 | { |
1180 | top->nrof += op->nrof; |
1213 | top->nrof += op->nrof; |
1181 | |
1214 | |
1182 | /* CLEAR_FLAG(top,FLAG_STARTEQUIP);*/ |
1215 | if (object *pl = top->visible_to ()) |
1183 | op->weight = 0; /* Don't want any adjustements now */ |
1216 | esrv_update_item (UPD_NROF, pl, top); |
|
|
1217 | |
|
|
1218 | op->weight = 0; // cancel the addition above |
|
|
1219 | op->carrying = 0; // must be 0 already |
|
|
1220 | |
1184 | op->destroy (); |
1221 | op->destroy (1); |
|
|
1222 | |
1185 | return top; |
1223 | return top; |
1186 | } |
1224 | } |
1187 | } |
|
|
1188 | |
1225 | |
1189 | return 0; |
1226 | return 0; |
1190 | } |
1227 | } |
1191 | |
1228 | |
1192 | void |
1229 | void |
… | |
… | |
1494 | return where->env->insert (this); |
1531 | return where->env->insert (this); |
1495 | else |
1532 | else |
1496 | return where->map->insert (this, where->x, where->y, originator, flags); |
1533 | return where->map->insert (this, where->x, where->y, originator, flags); |
1497 | } |
1534 | } |
1498 | |
1535 | |
1499 | // find player who can see this object |
|
|
1500 | object * |
|
|
1501 | object::visible_to () const |
|
|
1502 | { |
|
|
1503 | if (!flag [FLAG_REMOVED]) |
|
|
1504 | { |
|
|
1505 | // see if we are in a container of sorts |
|
|
1506 | if (env) |
|
|
1507 | { |
|
|
1508 | // the player inventory itself is always visible |
|
|
1509 | if (env->type == PLAYER) |
|
|
1510 | return env; |
|
|
1511 | |
|
|
1512 | // else a player could have our env open |
|
|
1513 | object *envest = env->outer_env (); |
|
|
1514 | |
|
|
1515 | // the player itself is always on a map, so we will find him here |
|
|
1516 | // even if our inv is in a player. |
|
|
1517 | if (envest->is_on_map ()) |
|
|
1518 | if (object *pl = envest->ms ().player ()) |
|
|
1519 | if (pl->container == env) |
|
|
1520 | return pl; |
|
|
1521 | } |
|
|
1522 | else |
|
|
1523 | { |
|
|
1524 | // maybe there is a player standing on the same mapspace |
|
|
1525 | // this will catch the case where "this" is a player |
|
|
1526 | if (object *pl = ms ().player ()) |
|
|
1527 | return pl; |
|
|
1528 | } |
|
|
1529 | } |
|
|
1530 | |
|
|
1531 | return 0; |
|
|
1532 | } |
|
|
1533 | |
|
|
1534 | /* |
1536 | /* |
1535 | * decrease(object, number) decreases a specified number from |
1537 | * decrease(object, number) decreases a specified number from |
1536 | * the amount of an object. If the amount reaches 0, the object |
1538 | * the amount of an object. If the amount reaches 0, the object |
1537 | * is subsequently removed and freed. |
1539 | * is subsequently removed and freed. |
1538 | * |
1540 | * |
… | |
… | |
1638 | if (object::can_merge (tmp, op)) |
1640 | if (object::can_merge (tmp, op)) |
1639 | { |
1641 | { |
1640 | /* return the original object and remove inserted object |
1642 | /* return the original object and remove inserted object |
1641 | (client needs the original object) */ |
1643 | (client needs the original object) */ |
1642 | tmp->nrof += op->nrof; |
1644 | tmp->nrof += op->nrof; |
|
|
1645 | |
|
|
1646 | if (object *pl = tmp->visible_to ()) |
|
|
1647 | esrv_update_item (UPD_NROF, pl, tmp); |
|
|
1648 | |
1643 | adjust_weight (this, op->total_weight ()); |
1649 | adjust_weight (this, op->total_weight ()); |
1644 | |
1650 | |
1645 | op->destroy (1); |
1651 | op->destroy (1); |
1646 | op = tmp; |
1652 | op = tmp; |
1647 | goto inserted; |
1653 | goto inserted; |
… | |
… | |
1661 | |
1667 | |
1662 | inv = op; |
1668 | inv = op; |
1663 | |
1669 | |
1664 | op->flag [FLAG_REMOVED] = 0; |
1670 | op->flag [FLAG_REMOVED] = 0; |
1665 | |
1671 | |
|
|
1672 | if (object *pl = op->visible_to ()) |
|
|
1673 | esrv_send_item (pl, op); |
|
|
1674 | |
1666 | adjust_weight (this, op->total_weight ()); |
1675 | adjust_weight (this, op->total_weight ()); |
1667 | |
1676 | |
1668 | inserted: |
1677 | inserted: |
1669 | /* reset the light list and los of the players on the map */ |
1678 | /* reset the light list and los of the players on the map */ |
1670 | if (op->glow_radius && map && map->darkness) |
1679 | if (op->glow_radius && map && map->darkness) |
1671 | update_all_los (map, x, y); |
1680 | update_all_los (map, x, y); |
1672 | |
1681 | |
1673 | if (object *otmp = in_player ()) |
1682 | // if this is a player's inventory, update stats |
1674 | if (otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) |
1683 | if (type == PLAYER && !flag [FLAG_NO_FIX_PLAYER]) |
1675 | otmp->update_stats (); |
1684 | update_stats (); |
1676 | |
1685 | |
1677 | INVOKE_OBJECT (INSERT, this); |
1686 | INVOKE_OBJECT (INSERT, this); |
1678 | |
1687 | |
1679 | return op; |
1688 | return op; |
1680 | } |
1689 | } |
… | |
… | |
2610 | if (object *closer = old_container->inv) |
2619 | if (object *closer = old_container->inv) |
2611 | if (closer->type == CLOSE_CON) |
2620 | if (closer->type == CLOSE_CON) |
2612 | closer->destroy (); |
2621 | closer->destroy (); |
2613 | #endif |
2622 | #endif |
2614 | |
2623 | |
2615 | old_container->flag [FLAG_APPLIED] = 0; |
2624 | old_container->flag [FLAG_APPLIED] = false; |
2616 | container = 0; |
2625 | container = 0; |
2617 | |
2626 | |
2618 | esrv_update_item (UPD_FLAGS, this, old_container); |
2627 | esrv_update_item (UPD_FLAGS, this, old_container); |
2619 | new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container)); |
2628 | new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container)); |
2620 | play_sound (sound_find ("chest_close")); |
2629 | play_sound (sound_find ("chest_close")); |
… | |
… | |
2636 | } |
2645 | } |
2637 | #endif |
2646 | #endif |
2638 | |
2647 | |
2639 | new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", query_name (new_container)); |
2648 | new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", query_name (new_container)); |
2640 | |
2649 | |
2641 | new_container->flag [FLAG_APPLIED] = 1; |
2650 | new_container->flag [FLAG_APPLIED] = true; |
2642 | container = new_container; |
2651 | container = new_container; |
2643 | |
2652 | |
2644 | esrv_update_item (UPD_FLAGS, this, new_container); |
2653 | esrv_update_item (UPD_FLAGS, this, new_container); |
2645 | esrv_send_inventory (this, new_container); |
2654 | esrv_send_inventory (this, new_container); |
2646 | play_sound (sound_find ("chest_open")); |
2655 | play_sound (sound_find ("chest_open")); |