1 | /*****************************************************************************/ |
|
|
2 | /* CrossFire, A Multiplayer game for the X Window System */ |
|
|
3 | /*****************************************************************************/ |
|
|
4 | |
|
|
5 | /* |
1 | /* |
|
|
2 | * CrossFire, A Multiplayer game |
|
|
3 | * |
6 | * This code is placed under the GNU General Public Licence (GPL) |
4 | * This code is placed under the GNU General Public Licence (GPL) |
7 | * |
5 | * |
8 | * Copyright (C) 2001-2005 by Chachkoff Yann |
6 | * Copyright (C) 2001-2005 by Chachkoff Yann |
9 | * Copyright (C) 2006,2007 by Marc Lehmann <cf@schmorp.de> |
7 | * Copyright (C) 2006,2007 by Marc Lehmann <cf@schmorp.de> |
10 | * |
8 | * |
… | |
… | |
86 | double runtime; |
84 | double runtime; |
87 | |
85 | |
88 | global gbl_ev; |
86 | global gbl_ev; |
89 | static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; |
87 | static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; |
90 | static SV *sv_runtime, *sv_next_tick; |
88 | static SV *sv_runtime, *sv_next_tick; |
|
|
89 | |
|
|
90 | bitset<NUM_EVENT_TYPES> ev_want_event; |
|
|
91 | bitset<NUM_TYPES> ev_want_type; |
91 | |
92 | |
92 | static HV |
93 | static HV |
93 | *stash_cf, |
94 | *stash_cf, |
94 | *stash_cf_object_wrap, |
95 | *stash_cf_object_wrap, |
95 | *stash_cf_object_player_wrap, |
96 | *stash_cf_object_player_wrap, |
… | |
… | |
404 | inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } |
405 | inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } |
405 | |
406 | |
406 | template<int N> |
407 | template<int N> |
407 | inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } |
408 | inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } |
408 | |
409 | |
409 | inline void sv_to (SV *sv, rangetype &v) { v = (rangetype) SvIV (sv); } |
|
|
410 | inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); } |
410 | inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); } |
411 | inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); } |
411 | inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); } |
412 | inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); } |
412 | inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); } |
413 | inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); } |
413 | inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); } |
414 | |
414 | |
… | |
… | |
718 | } |
718 | } |
719 | |
719 | |
720 | void |
720 | void |
721 | global::gather_callbacks (AV *&callbacks, event_type event) const |
721 | global::gather_callbacks (AV *&callbacks, event_type event) const |
722 | { |
722 | { |
723 | ::gather_callbacks (callbacks, cb_object, event); |
723 | ::gather_callbacks (callbacks, cb_global, event); |
724 | } |
724 | } |
725 | |
725 | |
726 | void |
726 | void |
727 | object::gather_callbacks (AV *&callbacks, event_type event) const |
727 | object::gather_callbacks (AV *&callbacks, event_type event) const |
728 | { |
728 | { |
729 | if (subtype && type + subtype * NUM_SUBTYPES <= AvFILLp (cb_type)) |
729 | if (subtype && type + subtype * NUM_TYPES <= AvFILLp (cb_type)) |
730 | { |
730 | { |
731 | SV *registry = AvARRAY (cb_type)[type + subtype * NUM_SUBTYPES]; |
731 | SV *registry = AvARRAY (cb_type)[type + subtype * NUM_TYPES]; |
732 | |
732 | |
733 | if (registry && SvROK (registry) && SvTYPE (SvRV (registry)) == SVt_PVAV) |
733 | if (registry && SvROK (registry) && SvTYPE (SvRV (registry)) == SVt_PVAV) |
734 | ::gather_callbacks (callbacks, (AV *)SvRV (registry), event); |
734 | ::gather_callbacks (callbacks, (AV *)SvRV (registry), event); |
735 | } |
735 | } |
736 | |
736 | |
… | |
… | |
772 | { |
772 | { |
773 | attachable::gather_callbacks (callbacks, event); |
773 | attachable::gather_callbacks (callbacks, event); |
774 | ::gather_callbacks (callbacks, cb_map, event); |
774 | ::gather_callbacks (callbacks, cb_map, event); |
775 | } |
775 | } |
776 | |
776 | |
|
|
777 | void |
|
|
778 | _recalc_want (bitset<NUM_EVENT_TYPES> &set, AV *registry) |
|
|
779 | { |
|
|
780 | for (int event = 0; event <= AvFILLp (registry); ++event) |
|
|
781 | { |
|
|
782 | SV *cbs_ = AvARRAY (registry)[event]; |
|
|
783 | |
|
|
784 | // element must be list of callback entries |
|
|
785 | if (cbs_ && SvROK (cbs_) && SvTYPE (SvRV (cbs_)) == SVt_PVAV) |
|
|
786 | { |
|
|
787 | AV *cbs = (AV *)SvRV (cbs_); |
|
|
788 | |
|
|
789 | // no callback entries, no callbacks to call |
|
|
790 | if (AvFILLp (cbs) >= 0) |
|
|
791 | set.set (event); |
|
|
792 | } |
|
|
793 | } |
|
|
794 | } |
|
|
795 | |
|
|
796 | // very slow and inefficient way to recalculate the global want bitsets |
|
|
797 | void |
|
|
798 | _recalc_want () |
|
|
799 | { |
|
|
800 | ev_want_event.reset (); |
|
|
801 | |
|
|
802 | _recalc_want (ev_want_event, cb_global); |
|
|
803 | _recalc_want (ev_want_event, cb_attachable); |
|
|
804 | _recalc_want (ev_want_event, cb_object); |
|
|
805 | _recalc_want (ev_want_event, cb_client); |
|
|
806 | _recalc_want (ev_want_event, cb_player); |
|
|
807 | _recalc_want (ev_want_event, cb_map); |
|
|
808 | |
|
|
809 | ev_want_type.reset (); |
|
|
810 | |
|
|
811 | for (int type = 0; type <= AvFILLp (cb_type); ++type) |
|
|
812 | { |
|
|
813 | SV *cbs_ = AvARRAY (cb_type)[type]; |
|
|
814 | |
|
|
815 | // element must be list of callback entries |
|
|
816 | if (cbs_ && SvROK (cbs_) && SvTYPE (SvRV (cbs_)) == SVt_PVAV) |
|
|
817 | { |
|
|
818 | AV *cbs = (AV *)SvRV (cbs_); |
|
|
819 | |
|
|
820 | // no callback entries, no callbacks to call |
|
|
821 | if (AvFILLp (cbs) >= 0) |
|
|
822 | ev_want_type.set (type % NUM_TYPES); |
|
|
823 | } |
|
|
824 | } |
|
|
825 | } |
|
|
826 | |
777 | bool |
827 | bool |
778 | attachable::invoke (event_type event, ...) |
828 | attachable::vinvoke (event_type event, va_list &ap) |
779 | { |
829 | { |
780 | data_type dt; |
830 | data_type dt; |
781 | va_list ap; |
|
|
782 | |
|
|
783 | va_start (ap, event); |
|
|
784 | |
831 | |
785 | // callback call ordering should be: |
832 | // callback call ordering should be: |
786 | // 1. per-object callback |
833 | // 1. per-object callback |
787 | // 2. per-class object |
834 | // 2. per-class object |
788 | // 3. per-type callback |
835 | // 3. per-type callback |
… | |
… | |
1135 | const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) |
1182 | const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) |
1136 | |
1183 | |
1137 | const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) |
1184 | const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) |
1138 | |
1185 | |
1139 | const_iv (MAX_TIME) |
1186 | const_iv (MAX_TIME) |
|
|
1187 | |
|
|
1188 | const_iv (NUM_BODY_LOCATIONS) |
|
|
1189 | const_iv (body_range) const_iv (body_shield) const_iv (body_combat) |
|
|
1190 | const_iv (body_arm) const_iv (body_torso) const_iv (body_head) |
|
|
1191 | const_iv (body_neck) const_iv (body_skill) const_iv (body_finger) |
|
|
1192 | const_iv (body_shoulder) const_iv (body_foot) const_iv (body_hand) |
|
|
1193 | const_iv (body_wrist) const_iv (body_waist) |
1140 | |
1194 | |
1141 | const_iv (PLAYER) const_iv (TRANSPORT) const_iv (ROD) const_iv (TREASURE) |
1195 | const_iv (PLAYER) const_iv (TRANSPORT) const_iv (ROD) const_iv (TREASURE) |
1142 | const_iv (POTION) const_iv (FOOD) const_iv (POISON) const_iv (BOOK) |
1196 | const_iv (POTION) const_iv (FOOD) const_iv (POISON) const_iv (BOOK) |
1143 | const_iv (CLOCK) const_iv (ARROW) const_iv (BOW) const_iv (WEAPON) |
1197 | const_iv (CLOCK) const_iv (ARROW) const_iv (BOW) const_iv (WEAPON) |
1144 | const_iv (ARMOUR) const_iv (PEDESTAL) const_iv (ALTAR) const_iv (LOCKED_DOOR) |
1198 | const_iv (ARMOUR) const_iv (PEDESTAL) const_iv (ALTAR) const_iv (LOCKED_DOOR) |
… | |
… | |
1165 | const_iv (CONTAINER) const_iv (ARMOUR_IMPROVER) const_iv (WEAPON_IMPROVER) const_iv (SKILLSCROLL) |
1219 | const_iv (CONTAINER) const_iv (ARMOUR_IMPROVER) const_iv (WEAPON_IMPROVER) const_iv (SKILLSCROLL) |
1166 | const_iv (DEEP_SWAMP) const_iv (IDENTIFY_ALTAR) const_iv (MENU) const_iv (RUNE) |
1220 | const_iv (DEEP_SWAMP) const_iv (IDENTIFY_ALTAR) const_iv (MENU) const_iv (RUNE) |
1167 | const_iv (TRAP) const_iv (POWER_CRYSTAL) const_iv (CORPSE) const_iv (DISEASE) |
1221 | const_iv (TRAP) const_iv (POWER_CRYSTAL) const_iv (CORPSE) const_iv (DISEASE) |
1168 | const_iv (SYMPTOM) const_iv (BUILDER) const_iv (MATERIAL) const_iv (ITEM_TRANSFORMER) |
1222 | const_iv (SYMPTOM) const_iv (BUILDER) const_iv (MATERIAL) const_iv (ITEM_TRANSFORMER) |
1169 | |
1223 | |
1170 | const_iv (NUM_SUBTYPES) |
1224 | const_iv (NUM_TYPES) const_iv (NUM_SUBTYPES) |
1171 | |
1225 | |
1172 | const_iv (ST_BD_BUILD) const_iv (ST_BD_REMOVE) |
1226 | const_iv (ST_BD_BUILD) const_iv (ST_BD_REMOVE) |
1173 | const_iv (ST_MAT_FLOOR) const_iv (ST_MAT_WALL) const_iv (ST_MAT_ITEM) |
1227 | const_iv (ST_MAT_FLOOR) const_iv (ST_MAT_WALL) const_iv (ST_MAT_ITEM) |
1174 | |
1228 | |
1175 | const_iv (AT_PHYSICAL) const_iv (AT_MAGIC) const_iv (AT_FIRE) const_iv (AT_ELECTRICITY) |
1229 | const_iv (AT_PHYSICAL) const_iv (AT_MAGIC) const_iv (AT_FIRE) const_iv (AT_ELECTRICITY) |
… | |
… | |
1183 | const_iv (WEAP_HIT) const_iv (WEAP_SLASH) const_iv (WEAP_PIERCE) const_iv (WEAP_CLEAVE) |
1237 | const_iv (WEAP_HIT) const_iv (WEAP_SLASH) const_iv (WEAP_PIERCE) const_iv (WEAP_CLEAVE) |
1184 | const_iv (WEAP_SLICE) const_iv (WEAP_STAB) const_iv (WEAP_WHIP) const_iv (WEAP_CRUSH) |
1238 | const_iv (WEAP_SLICE) const_iv (WEAP_STAB) const_iv (WEAP_WHIP) const_iv (WEAP_CRUSH) |
1185 | const_iv (WEAP_BLUD) |
1239 | const_iv (WEAP_BLUD) |
1186 | |
1240 | |
1187 | const_iv (FLAG_ALIVE) const_iv (FLAG_WIZ) const_iv (FLAG_REMOVED) const_iv (FLAG_FREED) |
1241 | const_iv (FLAG_ALIVE) const_iv (FLAG_WIZ) const_iv (FLAG_REMOVED) const_iv (FLAG_FREED) |
1188 | const_iv (FLAG_WAS_WIZ) const_iv (FLAG_APPLIED) const_iv (FLAG_UNPAID) const_iv (FLAG_USE_SHIELD) |
1242 | const_iv (FLAG_APPLIED) const_iv (FLAG_UNPAID) const_iv (FLAG_USE_SHIELD) |
1189 | const_iv (FLAG_NO_PICK) const_iv (FLAG_ANIMATE) const_iv (FLAG_MONSTER) const_iv (FLAG_FRIENDLY) |
1243 | const_iv (FLAG_NO_PICK) const_iv (FLAG_ANIMATE) const_iv (FLAG_MONSTER) const_iv (FLAG_FRIENDLY) |
1190 | const_iv (FLAG_GENERATOR) const_iv (FLAG_IS_THROWN) const_iv (FLAG_AUTO_APPLY) const_iv (FLAG_PLAYER_SOLD) |
1244 | const_iv (FLAG_GENERATOR) const_iv (FLAG_IS_THROWN) const_iv (FLAG_AUTO_APPLY) const_iv (FLAG_PLAYER_SOLD) |
1191 | const_iv (FLAG_SEE_INVISIBLE) const_iv (FLAG_CAN_ROLL) const_iv (FLAG_OVERLAY_FLOOR) const_iv (FLAG_IS_TURNABLE) |
1245 | const_iv (FLAG_SEE_INVISIBLE) const_iv (FLAG_CAN_ROLL) const_iv (FLAG_OVERLAY_FLOOR) const_iv (FLAG_IS_TURNABLE) |
1192 | const_iv (FLAG_IS_USED_UP) const_iv (FLAG_IDENTIFIED) const_iv (FLAG_REFLECTING) const_iv (FLAG_CHANGING) |
1246 | const_iv (FLAG_IS_USED_UP) const_iv (FLAG_IDENTIFIED) const_iv (FLAG_REFLECTING) const_iv (FLAG_CHANGING) |
1193 | const_iv (FLAG_SPLITTING) const_iv (FLAG_HITBACK) const_iv (FLAG_STARTEQUIP) const_iv (FLAG_BLOCKSVIEW) |
1247 | const_iv (FLAG_SPLITTING) const_iv (FLAG_HITBACK) const_iv (FLAG_STARTEQUIP) const_iv (FLAG_BLOCKSVIEW) |
… | |
… | |
1331 | } |
1385 | } |
1332 | } |
1386 | } |
1333 | |
1387 | |
1334 | void _connect_to_perl () |
1388 | void _connect_to_perl () |
1335 | |
1389 | |
|
|
1390 | void _recalc_want () |
|
|
1391 | |
1336 | void _global_reattach () |
1392 | void _global_reattach () |
1337 | CODE: |
1393 | CODE: |
1338 | { |
1394 | { |
1339 | // reattach to all attachable objects in the game. |
1395 | // reattach to all attachable objects in the game. |
1340 | for_all_clients (ns) |
1396 | for_all_clients (ns) |
… | |
… | |
1403 | case 2: RETVAL = rndm (SvIV (ST (0)), SvIV (ST (1))); break; |
1459 | case 2: RETVAL = rndm (SvIV (ST (0)), SvIV (ST (1))); break; |
1404 | default: croak ("cf::rndm requires none, one or two parameters."); break; |
1460 | default: croak ("cf::rndm requires none, one or two parameters."); break; |
1405 | } |
1461 | } |
1406 | OUTPUT: |
1462 | OUTPUT: |
1407 | RETVAL |
1463 | RETVAL |
|
|
1464 | |
|
|
1465 | NV clamp (NV value, NV min_value, NV max_value) |
|
|
1466 | CODE: |
|
|
1467 | RETVAL = clamp (value, min_value, max_value); |
|
|
1468 | OUTPUT: |
|
|
1469 | RETVAL |
|
|
1470 | |
|
|
1471 | NV lerp (NV value, NV min_in, NV max_in, NV min_out, NV max_out) |
|
|
1472 | CODE: |
|
|
1473 | RETVAL = lerp (value, min_in, max_in, min_out, max_out); |
|
|
1474 | OUTPUT: |
|
|
1475 | RETVAL |
|
|
1476 | |
|
|
1477 | void cede_to_tick () |
|
|
1478 | CODE: |
|
|
1479 | coroapi::cede_to_tick (); |
1408 | |
1480 | |
1409 | void server_tick () |
1481 | void server_tick () |
1410 | CODE: |
1482 | CODE: |
1411 | runtime = SvNVx (sv_runtime); |
1483 | runtime = SvNVx (sv_runtime); |
1412 | server_tick (); |
1484 | server_tick (); |
… | |
… | |
1607 | object *actives (U32 index) |
1679 | object *actives (U32 index) |
1608 | CODE: |
1680 | CODE: |
1609 | RETVAL = index < actives.size () ? actives [index] : 0; |
1681 | RETVAL = index < actives.size () ? actives [index] : 0; |
1610 | OUTPUT: RETVAL |
1682 | OUTPUT: RETVAL |
1611 | |
1683 | |
|
|
1684 | const char *slot_save_name (U32 slot) |
|
|
1685 | ALIAS: |
|
|
1686 | slot_use_name = 1 |
|
|
1687 | slot_nonuse_name = 2 |
|
|
1688 | CODE: |
|
|
1689 | { |
|
|
1690 | if (slot >= NUM_BODY_LOCATIONS) |
|
|
1691 | croak ("body slot index out of range"); |
|
|
1692 | |
|
|
1693 | switch (ix) |
|
|
1694 | { |
|
|
1695 | case 0: RETVAL = body_locations[slot].save_name; break; |
|
|
1696 | case 1: RETVAL = body_locations[slot].use_name; break; |
|
|
1697 | case 2: RETVAL = body_locations[slot].nonuse_name; break; |
|
|
1698 | } |
|
|
1699 | } |
|
|
1700 | OUTPUT: |
|
|
1701 | RETVAL |
|
|
1702 | |
1612 | # missing properties |
1703 | # missing properties |
1613 | |
1704 | |
1614 | object *head (object *op) |
1705 | object *head (object *op) |
1615 | PROTOTYPE: $ |
1706 | PROTOTYPE: $ |
1616 | CODE: |
1707 | CODE: |
… | |
… | |
1641 | int |
1732 | int |
1642 | num_animations (object *op) |
1733 | num_animations (object *op) |
1643 | CODE: |
1734 | CODE: |
1644 | RETVAL = NUM_ANIMATIONS (op); |
1735 | RETVAL = NUM_ANIMATIONS (op); |
1645 | OUTPUT: RETVAL |
1736 | OUTPUT: RETVAL |
|
|
1737 | |
|
|
1738 | int slot_info (object *op, UV slot, int value = 0) |
|
|
1739 | ALIAS: |
|
|
1740 | slot_used = 1 |
|
|
1741 | CODE: |
|
|
1742 | { |
|
|
1743 | if (slot >= NUM_BODY_LOCATIONS) |
|
|
1744 | croak ("body slot index out of range"); |
|
|
1745 | |
|
|
1746 | RETVAL = ix ? op->slot[slot].used : op->slot[slot].info; |
|
|
1747 | |
|
|
1748 | if (items > 2) |
|
|
1749 | if (ix) |
|
|
1750 | op->slot[slot].used = value; |
|
|
1751 | else |
|
|
1752 | op->slot[slot].info = value; |
|
|
1753 | } |
|
|
1754 | OUTPUT: |
|
|
1755 | RETVAL |
1646 | |
1756 | |
1647 | object *find_best_object_match (object *op, utf8_string match) |
1757 | object *find_best_object_match (object *op, utf8_string match) |
1648 | |
1758 | |
1649 | object *find_marked_object (object *op) |
1759 | object *find_marked_object (object *op) |
1650 | |
1760 | |
… | |
… | |
2002 | ob->flag [FLAG_NO_MAP_SAVE] = true; |
2112 | ob->flag [FLAG_NO_MAP_SAVE] = true; |
2003 | THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); |
2113 | THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); |
2004 | |
2114 | |
2005 | if (ob->randomitems) |
2115 | if (ob->randomitems) |
2006 | { |
2116 | { |
2007 | // do not generate treasure when there is something here already |
|
|
2008 | if (!ob->above) |
2117 | if (!ob->above) |
|
|
2118 | { |
2009 | ob->create_treasure (ob->randomitems); |
2119 | ob->create_treasure (ob->randomitems); |
|
|
2120 | |
|
|
2121 | for (object *op = ob->above; op; op = op->above) |
|
|
2122 | op->flag [FLAG_NO_MAP_SAVE] = true; |
|
|
2123 | } |
2010 | |
2124 | |
2011 | ob->randomitems = 0; |
2125 | ob->randomitems = 0; |
2012 | } |
2126 | } |
2013 | } |
2127 | } |
2014 | } |
2128 | } |