ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/cfperl.xs
(Generate patch)

Comparing deliantra/server/server/cfperl.xs (file contents):
Revision 1.194 by root, Mon Apr 23 18:09:57 2007 UTC vs.
Revision 1.214 by root, Sat May 26 15:44:07 2007 UTC

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 *
21 * You should have received a copy of the GNU General Public License 19 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software 20 * along with this program; if not, write to the Free Software
23 * Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 21 * Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 */ 22 */
25 23
24#include "autoconf.h"
25
26#define PLUGIN_NAME "perl" 26#define PLUGIN_NAME "perl"
27#define PLUGIN_VERSION "cfperl 0.5" 27#define PLUGIN_VERSION "cfperl 0.5"
28 28
29#define CEDES_PER_TICK 5 29#define CEDES_PER_TICK 5
30
31#if HAVE_EXECINFO_H
32# include <execinfo.h>
33#endif
30 34
31#include <plugin_common.h> 35#include <plugin_common.h>
32#include <sounds.h> 36#include <sounds.h>
33#include <cstdarg> 37#include <cstdarg>
34#include <sproto.h> 38#include <sproto.h>
80double runtime; 84double runtime;
81 85
82global gbl_ev; 86global gbl_ev;
83static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; 87static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map;
84static SV *sv_runtime, *sv_next_tick; 88static SV *sv_runtime, *sv_next_tick;
89
90bitset<NUM_EVENT_TYPES> ev_want_event;
91bitset<NUM_TYPES> ev_want_type;
85 92
86static HV 93static HV
87 *stash_cf, 94 *stash_cf,
88 *stash_cf_object_wrap, 95 *stash_cf_object_wrap,
89 *stash_cf_object_player_wrap, 96 *stash_cf_object_player_wrap,
111 118
112unordered_vector<attachable *> attachable::mortals; 119unordered_vector<attachable *> attachable::mortals;
113 120
114attachable::~attachable () 121attachable::~attachable ()
115{ 122{
116 flags |=0x3300;//D
117 assert (!self); 123 assert (!self);
118 assert (!cb); 124 assert (!cb);
119} 125}
120 126
121int 127int
137 sv_unmagic ((SV *)self, PERL_MAGIC_ext); 143 sv_unmagic ((SV *)self, PERL_MAGIC_ext);
138 SvREFCNT_dec (self); 144 SvREFCNT_dec (self);
139 145
140 // self *must* be null now because thats sv_unmagic's job. 146 // self *must* be null now because thats sv_unmagic's job.
141 assert (!this->self); 147 assert (!this->self);
142 flags |= 0x80; // severed //D
143 } 148 }
144} 149}
145 150
146void 151void
147attachable::optimise () 152attachable::optimise ()
148{ 153{
149 if (self 154 if (self
150 && SvREFCNT (self) == 1 155 && SvREFCNT (self) == 1
151 && !HvTOTALKEYS (self)) 156 && !HvTOTALKEYS (self))
152 flags |= 0x40,//D
153 sever_self (); 157 sever_self ();
154} 158}
155 159
156// check wether the object really is dead 160// check wether the object really is dead
157void 161void
164} 168}
165 169
166void 170void
167attachable::do_destroy () 171attachable::do_destroy ()
168{ 172{
169 invoke (EVENT_ATTACHABLE_DESTROY, DT_END); 173 INVOKE_ATTACHABLE (DESTROY, this);
170 174
171 if (cb) 175 if (cb)
172 { 176 {
173 SvREFCNT_dec (cb); 177 SvREFCNT_dec (cb);
174 cb = 0; 178 cb = 0;
175 } 179 }
176 180
177 if (self)
178 sever_self ();
179
180 flags |= 0x20; //D
181 mortals.push_back (this); 181 mortals.push_back (this);
182} 182}
183 183
184void 184void
185attachable::destroy () 185attachable::destroy ()
187 if (destroyed ()) 187 if (destroyed ())
188 return; 188 return;
189 189
190 flags |= F_DESTROYED; 190 flags |= F_DESTROYED;
191 do_destroy (); 191 do_destroy ();
192 sever_self ();
192} 193}
193 194
194void 195void
195attachable::check_mortals () 196attachable::check_mortals ()
196{ 197{
201 if (i >= mortals.size ()) 202 if (i >= mortals.size ())
202 { 203 {
203 i = 0; 204 i = 0;
204 205
205 if (mortals.size () > 1000) 206 if (mortals.size () > 1000)
206 fprintf (stderr, "mortal queue size (%d) exceeds 1000.\n", (int)mortals.size ()); 207 LOG (llevInfo, "mortal queue size (%d) exceeds 1000.\n", (int)mortals.size ());
207 208
208 break; 209 break;
209 } 210 }
210 211
211 attachable *obj = mortals [i]; 212 attachable *obj = mortals [i];
212 213
213 obj->refcnt_chk (); // unborrow from perl, if necessary 214#if 0
214 215 if (obj->self)//D make this an assert later
215 //if (obj->refcnt > 0 || obj->self)
216 if (obj->refcnt || obj->self)
217 { 216 {
218//printf ("%p rc %d\n", obj, obj->refcnt_cnt ());//D 217 LOG (llevError, "check_mortals: object '%s' still has self\n", typeid (obj).name ());
218 obj->sever_self ();
219 }
220#endif
221
222 if (obj->refcnt)
223 {
219 ++i; // further delay freeing 224 ++i; // further delay freeing
220 225
221 if (!(i & 0x3ff)) 226 if (!(i & 0x3ff))
222 break; 227 break;
223 } 228 }
224 else 229 else
225 { 230 {
226 mortals.erase (i); 231 mortals.erase (i);
232 obj->sever_self ();
227 delete obj; 233 delete obj;
228 } 234 }
229 } 235 }
230} 236}
231 237
280 286
281 if (!obj->self) 287 if (!obj->self)
282 { 288 {
283 obj->self = newHV (); 289 obj->self = newHV ();
284 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); 290 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0);
285 obj->flags |= (obj->flags & 0xc0) << 8;
286 obj->flags &= ~0xc0;//D
287 obj->flags |= 0x10;//D
288 291
289 // now bless the object _once_ 292 // now bless the object _once_
290 return sv_bless (newRV_inc ((SV *)obj->self), stash); 293 return sv_bless (newRV_inc ((SV *)obj->self), stash);
291 } 294 }
292 else 295 else
402inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } 405inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; }
403 406
404template<int N> 407template<int N>
405inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } 408inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); }
406 409
407inline void sv_to (SV *sv, rangetype &v) { v = (rangetype) SvIV (sv); }
408inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); } 410inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); }
409inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); } 411inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); }
410inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); } 412inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); }
411inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); } 413inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); }
412 414
615 perl_construct (perl); 617 perl_construct (perl);
616 618
617 PL_exit_flags |= PERL_EXIT_DESTRUCT_END; 619 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
618 620
619 const char *argv[] = { 621 const char *argv[] = {
620 "", 622 settings.argv [0],
621 "-e" 623 "-e"
622 "use Event; use Coro;" // required for bootstrap 624 "use Event; use Coro;" // required for bootstrap
623 "cf->bootstrap;" // required for datadir :*> 625 "cf->bootstrap;" // required for datadir :*>
624 "unshift @INC, cf::datadir ();" 626 "unshift @INC, cf::datadir ();"
625 "require cf;" 627 "require cf;"
653void 655void
654attachable::instantiate () 656attachable::instantiate ()
655{ 657{
656 if (attach) 658 if (attach)
657 { 659 {
658 invoke (EVENT_ATTACHABLE_INSTANTIATE, ARG_STRING (attach), DT_END); 660 INVOKE_ATTACHABLE (INSTANTIATE, this, ARG_STRING (attach));
659 attach = 0; 661 attach = 0;
660 } 662 }
661} 663}
662 664
663void 665void
664attachable::reattach () 666attachable::reattach ()
665{ 667{
666 optimise (); 668 optimise ();
667 //TODO: check for _attachment's, very important for restarts 669 //TODO: check for _attachment's, very important for restarts
668 invoke (EVENT_ATTACHABLE_REATTACH, DT_END); 670 INVOKE_ATTACHABLE (REATTACH, this);
669} 671}
670 672
671static event_klass klass_of[NUM_EVENT_TYPES] = { 673static event_klass klass_of[NUM_EVENT_TYPES] = {
672# define def(type,name) KLASS_ ## type, 674# define def(type,name) KLASS_ ## type,
673# include "eventinc.h" 675# include "eventinc.h"
716} 718}
717 719
718void 720void
719global::gather_callbacks (AV *&callbacks, event_type event) const 721global::gather_callbacks (AV *&callbacks, event_type event) const
720{ 722{
721 ::gather_callbacks (callbacks, cb_object, event); 723 ::gather_callbacks (callbacks, cb_global, event);
722} 724}
723 725
724void 726void
725object::gather_callbacks (AV *&callbacks, event_type event) const 727object::gather_callbacks (AV *&callbacks, event_type event) const
726{ 728{
727 if (subtype && type + subtype * NUM_SUBTYPES <= AvFILLp (cb_type)) 729 if (subtype && type + subtype * NUM_TYPES <= AvFILLp (cb_type))
728 { 730 {
729 SV *registry = AvARRAY (cb_type)[type + subtype * NUM_SUBTYPES]; 731 SV *registry = AvARRAY (cb_type)[type + subtype * NUM_TYPES];
730 732
731 if (registry && SvROK (registry) && SvTYPE (SvRV (registry)) == SVt_PVAV) 733 if (registry && SvROK (registry) && SvTYPE (SvRV (registry)) == SVt_PVAV)
732 ::gather_callbacks (callbacks, (AV *)SvRV (registry), event); 734 ::gather_callbacks (callbacks, (AV *)SvRV (registry), event);
733 } 735 }
734 736
770{ 772{
771 attachable::gather_callbacks (callbacks, event); 773 attachable::gather_callbacks (callbacks, event);
772 ::gather_callbacks (callbacks, cb_map, event); 774 ::gather_callbacks (callbacks, cb_map, event);
773} 775}
774 776
777void
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
797void
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
775bool 827bool
776attachable::invoke (event_type event, ...) 828attachable::invoke (event_type event, ...)
777{ 829{
778 data_type dt; 830 data_type dt;
779 va_list ap;
780
781 va_start (ap, event);
782 831
783 // callback call ordering should be: 832 // callback call ordering should be:
784 // 1. per-object callback 833 // 1. per-object callback
785 // 2. per-class object 834 // 2. per-class object
786 // 3. per-type callback 835 // 3. per-type callback
790 gather_callbacks (callbacks, event); 839 gather_callbacks (callbacks, event);
791 840
792 // short-circuit processing if no callbacks found/defined 841 // short-circuit processing if no callbacks found/defined
793 if (!callbacks) 842 if (!callbacks)
794 return 0; 843 return 0;
844
845 va_list ap;
846 va_start (ap, event);
795 847
796 CALL_BEGIN (3); 848 CALL_BEGIN (3);
797 CALL_ARG_SV (newSViv (event)); // only used for debugging nowadays 849 CALL_ARG_SV (newSViv (event)); // only used for debugging nowadays
798 CALL_ARG_SV (newRV_noinc ((SV *)callbacks)); 850 CALL_ARG_SV (newRV_noinc ((SV *)callbacks));
799 851
876 CALL_ARG (make_core); 928 CALL_ARG (make_core);
877 CALL_CALL ("cf::post_cleanup", G_VOID); 929 CALL_CALL ("cf::post_cleanup", G_VOID);
878 CALL_END; 930 CALL_END;
879} 931}
880 932
933void
934cfperl_make_book (object *book, int level)
935{
936 CALL_BEGIN (2);
937 CALL_ARG (book);
938 CALL_ARG (level);
939 CALL_CALL ("ext::books::make_book", G_VOID);
940 CALL_END;
941}
942
881maptile * 943maptile *
882maptile::find_sync (const char *path, maptile *origin) 944maptile::find_sync (const char *path, maptile *origin)
883{ 945{
884 CALL_BEGIN (2); 946 CALL_BEGIN (2);
885 CALL_ARG (path); 947 CALL_ARG (path);
945 CALL_BEGIN (2); 1007 CALL_BEGIN (2);
946 CALL_ARG (this); 1008 CALL_ARG (this);
947 CALL_ARG (exit); 1009 CALL_ARG (exit);
948 CALL_CALL ("cf::object::player::enter_exit", G_VOID); 1010 CALL_CALL ("cf::object::player::enter_exit", G_VOID);
949 CALL_END; 1011 CALL_END;
1012}
1013
1014void
1015log_backtrace (const char *msg)
1016{
1017#if HAVE_BACKTRACE
1018 void *addr [20];
1019 int size = backtrace (addr, 20);
1020
1021 CALL_BEGIN (size);
1022 CALL_ARG (msg);
1023 for (int i = 0; i < size; ++i)
1024 CALL_ARG ((IV)addr [i]);
1025 CALL_CALL ("cf::_log_backtrace", G_VOID);
1026 CALL_END;
1027#endif
950} 1028}
951 1029
952///////////////////////////////////////////////////////////////////////////// 1030/////////////////////////////////////////////////////////////////////////////
953 1031
954struct EventAPI *watcher_base::GEventAPI; 1032struct EventAPI *watcher_base::GEventAPI;
1110 const char *name; 1188 const char *name;
1111 IV iv; 1189 IV iv;
1112 } *civ, const_iv[] = { 1190 } *civ, const_iv[] = {
1113# define const_iv(name) { # name, (IV)name }, 1191# define const_iv(name) { # name, (IV)name },
1114 const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster) 1192 const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster)
1193 const_iv (logBacktrace)
1115 1194
1116 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) 1195 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd)
1117 1196
1118 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1197 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1119 1198
1120 const_iv (MAX_TIME) 1199 const_iv (MAX_TIME)
1200
1201 const_iv (NUM_BODY_LOCATIONS)
1202 const_iv (body_range) const_iv (body_shield) const_iv (body_combat)
1203 const_iv (body_arm) const_iv (body_torso) const_iv (body_head)
1204 const_iv (body_neck) const_iv (body_skill) const_iv (body_finger)
1205 const_iv (body_shoulder) const_iv (body_foot) const_iv (body_hand)
1206 const_iv (body_wrist) const_iv (body_waist)
1121 1207
1122 const_iv (PLAYER) const_iv (TRANSPORT) const_iv (ROD) const_iv (TREASURE) 1208 const_iv (PLAYER) const_iv (TRANSPORT) const_iv (ROD) const_iv (TREASURE)
1123 const_iv (POTION) const_iv (FOOD) const_iv (POISON) const_iv (BOOK) 1209 const_iv (POTION) const_iv (FOOD) const_iv (POISON) const_iv (BOOK)
1124 const_iv (CLOCK) const_iv (ARROW) const_iv (BOW) const_iv (WEAPON) 1210 const_iv (CLOCK) const_iv (ARROW) const_iv (BOW) const_iv (WEAPON)
1125 const_iv (ARMOUR) const_iv (PEDESTAL) const_iv (ALTAR) const_iv (LOCKED_DOOR) 1211 const_iv (ARMOUR) const_iv (PEDESTAL) const_iv (ALTAR) const_iv (LOCKED_DOOR)
1146 const_iv (CONTAINER) const_iv (ARMOUR_IMPROVER) const_iv (WEAPON_IMPROVER) const_iv (SKILLSCROLL) 1232 const_iv (CONTAINER) const_iv (ARMOUR_IMPROVER) const_iv (WEAPON_IMPROVER) const_iv (SKILLSCROLL)
1147 const_iv (DEEP_SWAMP) const_iv (IDENTIFY_ALTAR) const_iv (MENU) const_iv (RUNE) 1233 const_iv (DEEP_SWAMP) const_iv (IDENTIFY_ALTAR) const_iv (MENU) const_iv (RUNE)
1148 const_iv (TRAP) const_iv (POWER_CRYSTAL) const_iv (CORPSE) const_iv (DISEASE) 1234 const_iv (TRAP) const_iv (POWER_CRYSTAL) const_iv (CORPSE) const_iv (DISEASE)
1149 const_iv (SYMPTOM) const_iv (BUILDER) const_iv (MATERIAL) const_iv (ITEM_TRANSFORMER) 1235 const_iv (SYMPTOM) const_iv (BUILDER) const_iv (MATERIAL) const_iv (ITEM_TRANSFORMER)
1150 1236
1151 const_iv (NUM_SUBTYPES) 1237 const_iv (NUM_TYPES) const_iv (NUM_SUBTYPES)
1152 1238
1153 const_iv (ST_BD_BUILD) const_iv (ST_BD_REMOVE) 1239 const_iv (ST_BD_BUILD) const_iv (ST_BD_REMOVE)
1154 const_iv (ST_MAT_FLOOR) const_iv (ST_MAT_WALL) const_iv (ST_MAT_ITEM) 1240 const_iv (ST_MAT_FLOOR) const_iv (ST_MAT_WALL) const_iv (ST_MAT_ITEM)
1155 1241
1156 const_iv (AT_PHYSICAL) const_iv (AT_MAGIC) const_iv (AT_FIRE) const_iv (AT_ELECTRICITY) 1242 const_iv (AT_PHYSICAL) const_iv (AT_MAGIC) const_iv (AT_FIRE) const_iv (AT_ELECTRICITY)
1164 const_iv (WEAP_HIT) const_iv (WEAP_SLASH) const_iv (WEAP_PIERCE) const_iv (WEAP_CLEAVE) 1250 const_iv (WEAP_HIT) const_iv (WEAP_SLASH) const_iv (WEAP_PIERCE) const_iv (WEAP_CLEAVE)
1165 const_iv (WEAP_SLICE) const_iv (WEAP_STAB) const_iv (WEAP_WHIP) const_iv (WEAP_CRUSH) 1251 const_iv (WEAP_SLICE) const_iv (WEAP_STAB) const_iv (WEAP_WHIP) const_iv (WEAP_CRUSH)
1166 const_iv (WEAP_BLUD) 1252 const_iv (WEAP_BLUD)
1167 1253
1168 const_iv (FLAG_ALIVE) const_iv (FLAG_WIZ) const_iv (FLAG_REMOVED) const_iv (FLAG_FREED) 1254 const_iv (FLAG_ALIVE) const_iv (FLAG_WIZ) const_iv (FLAG_REMOVED) const_iv (FLAG_FREED)
1169 const_iv (FLAG_WAS_WIZ) const_iv (FLAG_APPLIED) const_iv (FLAG_UNPAID) const_iv (FLAG_USE_SHIELD) 1255 const_iv (FLAG_APPLIED) const_iv (FLAG_UNPAID) const_iv (FLAG_USE_SHIELD)
1170 const_iv (FLAG_NO_PICK) const_iv (FLAG_ANIMATE) const_iv (FLAG_MONSTER) const_iv (FLAG_FRIENDLY) 1256 const_iv (FLAG_NO_PICK) const_iv (FLAG_ANIMATE) const_iv (FLAG_MONSTER) const_iv (FLAG_FRIENDLY)
1171 const_iv (FLAG_GENERATOR) const_iv (FLAG_IS_THROWN) const_iv (FLAG_AUTO_APPLY) const_iv (FLAG_PLAYER_SOLD) 1257 const_iv (FLAG_GENERATOR) const_iv (FLAG_IS_THROWN) const_iv (FLAG_AUTO_APPLY) const_iv (FLAG_PLAYER_SOLD)
1172 const_iv (FLAG_SEE_INVISIBLE) const_iv (FLAG_CAN_ROLL) const_iv (FLAG_OVERLAY_FLOOR) const_iv (FLAG_IS_TURNABLE) 1258 const_iv (FLAG_SEE_INVISIBLE) const_iv (FLAG_CAN_ROLL) const_iv (FLAG_OVERLAY_FLOOR) const_iv (FLAG_IS_TURNABLE)
1173 const_iv (FLAG_IS_USED_UP) const_iv (FLAG_IDENTIFIED) const_iv (FLAG_REFLECTING) const_iv (FLAG_CHANGING) 1259 const_iv (FLAG_IS_USED_UP) const_iv (FLAG_IDENTIFIED) const_iv (FLAG_REFLECTING) const_iv (FLAG_CHANGING)
1174 const_iv (FLAG_SPLITTING) const_iv (FLAG_HITBACK) const_iv (FLAG_STARTEQUIP) const_iv (FLAG_BLOCKSVIEW) 1260 const_iv (FLAG_SPLITTING) const_iv (FLAG_HITBACK) const_iv (FLAG_STARTEQUIP) const_iv (FLAG_BLOCKSVIEW)
1201 const_iv (UPD_LOCATION) const_iv (UPD_FLAGS) const_iv (UPD_WEIGHT) const_iv (UPD_FACE) 1287 const_iv (UPD_LOCATION) const_iv (UPD_FLAGS) const_iv (UPD_WEIGHT) const_iv (UPD_FACE)
1202 const_iv (UPD_NAME) const_iv (UPD_ANIM) const_iv (UPD_ANIMSPEED) const_iv (UPD_NROF) 1288 const_iv (UPD_NAME) const_iv (UPD_ANIM) const_iv (UPD_ANIMSPEED) const_iv (UPD_NROF)
1203 1289
1204 const_iv (UPD_SP_MANA) const_iv (UPD_SP_GRACE) const_iv (UPD_SP_DAMAGE) 1290 const_iv (UPD_SP_MANA) const_iv (UPD_SP_GRACE) const_iv (UPD_SP_DAMAGE)
1205 1291
1292 const_iv (SP_RAISE_DEAD)
1293 const_iv (SP_RUNE)
1294 const_iv (SP_MAKE_MARK)
1295 const_iv (SP_BOLT)
1296 const_iv (SP_BULLET)
1297 const_iv (SP_EXPLOSION)
1298 const_iv (SP_CONE)
1299 const_iv (SP_BOMB)
1300 const_iv (SP_WONDER)
1301 const_iv (SP_SMITE)
1302 const_iv (SP_MAGIC_MISSILE)
1303 const_iv (SP_SUMMON_GOLEM)
1304 const_iv (SP_DIMENSION_DOOR)
1305 const_iv (SP_MAGIC_MAPPING)
1306 const_iv (SP_MAGIC_WALL)
1307 const_iv (SP_DESTRUCTION)
1308 const_iv (SP_PERCEIVE_SELF)
1309 const_iv (SP_WORD_OF_RECALL)
1310 const_iv (SP_INVISIBLE)
1311 const_iv (SP_PROBE)
1312 const_iv (SP_HEALING)
1313 const_iv (SP_CREATE_FOOD)
1314 const_iv (SP_EARTH_TO_DUST)
1315 const_iv (SP_CHANGE_ABILITY)
1316 const_iv (SP_BLESS)
1317 const_iv (SP_CURSE)
1318 const_iv (SP_SUMMON_MONSTER)
1319 const_iv (SP_CHARGING)
1320 const_iv (SP_POLYMORPH)
1321 const_iv (SP_ALCHEMY)
1322 const_iv (SP_REMOVE_CURSE)
1323 const_iv (SP_IDENTIFY)
1324 const_iv (SP_DETECTION)
1325 const_iv (SP_MOOD_CHANGE)
1326 const_iv (SP_MOVING_BALL)
1327 const_iv (SP_SWARM)
1328 const_iv (SP_CHANGE_MANA)
1329 const_iv (SP_DISPEL_RUNE)
1330 const_iv (SP_CREATE_MISSILE)
1331 const_iv (SP_CONSECRATE)
1332 const_iv (SP_ANIMATE_WEAPON)
1333 const_iv (SP_LIGHT)
1334 const_iv (SP_CHANGE_MAP_LIGHT)
1335 const_iv (SP_FAERY_FIRE)
1336 const_iv (SP_CAUSE_DISEASE)
1337 const_iv (SP_AURA)
1338 const_iv (SP_TOWN_PORTAL)
1339 const_iv (SP_PARTY_SPELL)
1340
1206 const_iv (F_APPLIED) const_iv (F_LOCATION) const_iv (F_UNPAID) const_iv (F_MAGIC) 1341 const_iv (F_APPLIED) const_iv (F_LOCATION) const_iv (F_UNPAID) const_iv (F_MAGIC)
1207 const_iv (F_CURSED) const_iv (F_DAMNED) const_iv (F_OPEN) const_iv (F_NOPICK) 1342 const_iv (F_CURSED) const_iv (F_DAMNED) const_iv (F_OPEN) const_iv (F_NOPICK)
1208 const_iv (F_LOCKED) 1343 const_iv (F_LOCKED)
1209 1344
1210 const_iv (F_BUY) const_iv (F_SHOP) const_iv (F_SELL) 1345 const_iv (F_BUY) const_iv (F_SHOP) const_iv (F_SELL)
1266 1401
1267 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) 1402 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT)
1268 1403
1269 const_iv (ST_DEAD) const_iv (ST_SETUP) const_iv (ST_PLAYING) const_iv (ST_CUSTOM) 1404 const_iv (ST_DEAD) const_iv (ST_SETUP) const_iv (ST_PLAYING) const_iv (ST_CUSTOM)
1270 1405
1271 const_iv (ST_CHANGE_CLASS)
1272
1273 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) 1406 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES)
1274 1407
1275 // random map generator 1408 // random map generator
1276 const_iv (LAYOUT_NONE) const_iv (LAYOUT_ONION) const_iv (LAYOUT_MAZE) const_iv (LAYOUT_SPIRAL) 1409 const_iv (LAYOUT_NONE) const_iv (LAYOUT_ONION) const_iv (LAYOUT_MAZE) const_iv (LAYOUT_SPIRAL)
1277 const_iv (LAYOUT_ROGUELIKE) const_iv (LAYOUT_SNAKE) const_iv (LAYOUT_SQUARE_SPIRAL) 1410 const_iv (LAYOUT_ROGUELIKE) const_iv (LAYOUT_SNAKE) const_iv (LAYOUT_SQUARE_SPIRAL)
1280 const_iv (RMOPT_BOTTOM_C) const_iv (RMOPT_BOTTOM_R) const_iv (RMOPT_IRR_SPACE) 1413 const_iv (RMOPT_BOTTOM_C) const_iv (RMOPT_BOTTOM_R) const_iv (RMOPT_IRR_SPACE)
1281 const_iv (RMOPT_WALL_OFF) const_iv (RMOPT_WALLS_ONLY) const_iv (RMOPT_NO_DOORS) 1414 const_iv (RMOPT_WALL_OFF) const_iv (RMOPT_WALLS_ONLY) const_iv (RMOPT_NO_DOORS)
1282 1415
1283 const_iv (SYMMETRY_RANDOM) const_iv (SYMMETRY_NONE) const_iv (SYMMETRY_X) 1416 const_iv (SYMMETRY_RANDOM) const_iv (SYMMETRY_NONE) const_iv (SYMMETRY_X)
1284 const_iv (SYMMETRY_Y) const_iv (SYMMETRY_XY) 1417 const_iv (SYMMETRY_Y) const_iv (SYMMETRY_XY)
1418
1419 const_iv (GT_ENVIRONMENT) const_iv (GT_INVISIBLE) const_iv (GT_STARTEQUIP)
1420 const_iv (GT_APPLY) const_iv (GT_ONLY_GOOD) const_iv (GT_UPDATE_INV)
1421 const_iv (GT_MINIMAL)
1285 }; 1422 };
1286 1423
1287 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1424 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1288 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); 1425 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv));
1289 1426
1310 } 1447 }
1311} 1448}
1312 1449
1313void _connect_to_perl () 1450void _connect_to_perl ()
1314 1451
1452void _recalc_want ()
1453
1315void _global_reattach () 1454void _global_reattach ()
1316 CODE: 1455 CODE:
1317{ 1456{
1318 // reattach to all attachable objects in the game. 1457 // reattach to all attachable objects in the game.
1319 for_all_clients (ns) 1458 for_all_clients (ns)
1383 default: croak ("cf::rndm requires none, one or two parameters."); break; 1522 default: croak ("cf::rndm requires none, one or two parameters."); break;
1384 } 1523 }
1385 OUTPUT: 1524 OUTPUT:
1386 RETVAL 1525 RETVAL
1387 1526
1527NV clamp (NV value, NV min_value, NV max_value)
1528 CODE:
1529 RETVAL = clamp (value, min_value, max_value);
1530 OUTPUT:
1531 RETVAL
1532
1533NV lerp (NV value, NV min_in, NV max_in, NV min_out, NV max_out)
1534 CODE:
1535 RETVAL = lerp (value, min_in, max_in, min_out, max_out);
1536 OUTPUT:
1537 RETVAL
1538
1539void cede_to_tick ()
1540 CODE:
1541 coroapi::cede_to_tick ();
1542
1388void server_tick () 1543void server_tick ()
1389 CODE: 1544 CODE:
1390 runtime = SvNVx (sv_runtime); 1545 runtime = SvNVx (sv_runtime);
1391 server_tick (); 1546 server_tick ();
1392 1547
1393void 1548void
1549log_backtrace (utf8_string msg)
1550
1551void
1394LOG (int level, utf8_string msg) 1552LOG (int flags, utf8_string msg)
1395 PROTOTYPE: $$ 1553 PROTOTYPE: $$
1396 C_ARGS: (LogLevel)level, "%s", msg 1554 C_ARGS: flags, "%s", msg
1397 1555
1398octet_string path_combine (octet_string base, octet_string path) 1556octet_string path_combine (octet_string base, octet_string path)
1399 PROTOTYPE: $$ 1557 PROTOTYPE: $$
1400 1558
1401octet_string path_combine_and_normalize (octet_string base, octet_string path) 1559octet_string path_combine_and_normalize (octet_string base, octet_string path)
1438 } 1596 }
1439 OUTPUT: RETVAL 1597 OUTPUT: RETVAL
1440 1598
1441void abort () 1599void abort ()
1442 1600
1601void reset_signals ()
1602
1443void fork_abort (octet_string cause = "cf::fork_abort") 1603void fork_abort (octet_string cause = "cf::fork_abort")
1444 1604
1445void cleanup (octet_string cause, bool make_core = false) 1605void cleanup (octet_string cause, bool make_core = false)
1446 1606
1447void emergency_save () 1607void emergency_save ()
1581object *actives (U32 index) 1741object *actives (U32 index)
1582 CODE: 1742 CODE:
1583 RETVAL = index < actives.size () ? actives [index] : 0; 1743 RETVAL = index < actives.size () ? actives [index] : 0;
1584 OUTPUT: RETVAL 1744 OUTPUT: RETVAL
1585 1745
1746const char *slot_save_name (U32 slot)
1747 ALIAS:
1748 slot_use_name = 1
1749 slot_nonuse_name = 2
1750 CODE:
1751{
1752 if (slot >= NUM_BODY_LOCATIONS)
1753 croak ("body slot index out of range");
1754
1755 switch (ix)
1756 {
1757 case 0: RETVAL = body_locations[slot].save_name; break;
1758 case 1: RETVAL = body_locations[slot].use_name; break;
1759 case 2: RETVAL = body_locations[slot].nonuse_name; break;
1760 }
1761}
1762 OUTPUT:
1763 RETVAL
1764
1586# missing properties 1765# missing properties
1587 1766
1588object *head (object *op) 1767object *head (object *op)
1589 PROTOTYPE: $ 1768 PROTOTYPE: $
1590 CODE: 1769 CODE:
1615int 1794int
1616num_animations (object *op) 1795num_animations (object *op)
1617 CODE: 1796 CODE:
1618 RETVAL = NUM_ANIMATIONS (op); 1797 RETVAL = NUM_ANIMATIONS (op);
1619 OUTPUT: RETVAL 1798 OUTPUT: RETVAL
1799
1800int slot_info (object *op, UV slot, int value = 0)
1801 ALIAS:
1802 slot_used = 1
1803 CODE:
1804{
1805 if (slot >= NUM_BODY_LOCATIONS)
1806 croak ("body slot index out of range");
1807
1808 RETVAL = ix ? op->slot[slot].used : op->slot[slot].info;
1809
1810 if (items > 2)
1811 if (ix)
1812 op->slot[slot].used = value;
1813 else
1814 op->slot[slot].info = value;
1815}
1816 OUTPUT:
1817 RETVAL
1620 1818
1621object *find_best_object_match (object *op, utf8_string match) 1819object *find_best_object_match (object *op, utf8_string match)
1622 1820
1623object *find_marked_object (object *op) 1821object *find_marked_object (object *op)
1624 1822
1805void check_score (object *op) 2003void check_score (object *op)
1806 2004
1807void message (object *op, utf8_string txt, int flags = NDI_ORANGE | NDI_UNIQUE) 2005void message (object *op, utf8_string txt, int flags = NDI_ORANGE | NDI_UNIQUE)
1808 CODE: 2006 CODE:
1809 new_draw_info (flags, 0, op, txt); 2007 new_draw_info (flags, 0, op, txt);
1810
1811object *cf_player_send_inventory (object *op)
1812
1813octet_string cf_player_get_ip (object *op)
1814 ALIAS: ip = 0
1815
1816object *cf_player_get_marked_item (object *op)
1817 ALIAS: marked_item = 0
1818
1819void cf_player_set_marked_item (object *op, object *ob)
1820
1821partylist *cf_player_get_party (object *op)
1822 ALIAS: party = 0
1823
1824void cf_player_set_party (object *op, partylist *party)
1825 2008
1826void kill_player (object *op) 2009void kill_player (object *op)
1827 2010
1828void esrv_update_item (object *op, int what, object *item) 2011void esrv_update_item (object *op, int what, object *item)
1829 C_ARGS: what, op, item 2012 C_ARGS: what, op, item
1973 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) 2156 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
1974 { 2157 {
1975 object *ob = get_archetype (SvPVutf8_nolen (*elem)); 2158 object *ob = get_archetype (SvPVutf8_nolen (*elem));
1976 ob->flag [FLAG_NO_MAP_SAVE] = true; 2159 ob->flag [FLAG_NO_MAP_SAVE] = true;
1977 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); 2160 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2161
2162 if (ob->randomitems)
2163 {
2164 if (!ob->above)
2165 {
2166 ob->create_treasure (ob->randomitems);
2167
2168 for (object *op = ob->above; op; op = op->above)
2169 op->flag [FLAG_NO_MAP_SAVE] = true;
2170 }
2171
2172 ob->randomitems = 0;
2173 }
1978 } 2174 }
1979 } 2175 }
1980 } 2176 }
1981 2177
1982 skip_space: ; 2178 skip_space: ;
2202 rmp.decoroptions = decoroptions; 2398 rmp.decoroptions = decoroptions;
2203 rmp.orientation = orientation; 2399 rmp.orientation = orientation;
2204 rmp.origin_y = origin_y; 2400 rmp.origin_y = origin_y;
2205 rmp.origin_x = origin_x; 2401 rmp.origin_x = origin_x;
2206 rmp.random_seed = random_seed; 2402 rmp.random_seed = random_seed;
2207 rmp.total_map_hp = total_map_hp; 2403 rmp.total_map_hp = (uint64_t) total_map_hp;
2208 rmp.map_layout_style = map_layout_style; 2404 rmp.map_layout_style = map_layout_style;
2209 rmp.treasureoptions = treasureoptions; 2405 rmp.treasureoptions = treasureoptions;
2210 rmp.symmetry_used = symmetry_used; 2406 rmp.symmetry_used = symmetry_used;
2211 rmp.region = region; 2407 rmp.region = region;
2212 rmp.custom = custom; 2408 rmp.custom = custom;
2227archetype *first() 2423archetype *first()
2228 PROTOTYPE: 2424 PROTOTYPE:
2229 CODE: 2425 CODE:
2230 RETVAL = first_archetype; 2426 RETVAL = first_archetype;
2231 OUTPUT: RETVAL 2427 OUTPUT: RETVAL
2428
2429object *instantiate (archetype *arch)
2430 CODE:
2431 RETVAL = arch_to_object (arch);
2432 OUTPUT:
2433 RETVAL
2232 2434
2233INCLUDE: $PERL $srcdir/genacc archetype ../include/object.h | 2435INCLUDE: $PERL $srcdir/genacc archetype ../include/object.h |
2234 2436
2235MODULE = cf PACKAGE = cf::party 2437MODULE = cf PACKAGE = cf::party
2236 2438

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines