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.190 by root, Tue Apr 17 18:24:31 2007 UTC vs.
Revision 1.222 by root, Sun Jun 24 04:09:29 2007 UTC

1/*****************************************************************************/
2/* CrossFire, A Multiplayer game for the X Window System */
3/*****************************************************************************/
4
5/* 1/*
6 * This code is placed under the GNU General Public Licence (GPL) 2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
7 * 3 *
4 * Copyright (©) 2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team
8 * Copyright (C) 2001-2005 by Chachkoff Yann 5 * Copyright (©) 2001-2005,2007 by Chachkoff Yann
9 * Copyright (C) 2006,2007 by Marc Lehmann <cf@schmorp.de> 6 * Copyright (©) 2006,2007 by Marc Lehmann <cf@schmorp.de>
10 * 7 *
11 * This program is free software; you can redistribute it and/or modify 8 * Crossfire TRT is free software; you can redistribute it and/or modify it
12 * it under the terms of the GNU General Public License as published by 9 * under the terms of the GNU General Public License as published by the Free
13 * the Free Software Foundation; either version 2 of the License, or 10 * Software Foundation; either version 2 of the License, or (at your option)
14 * (at your option) any later version. 11 * any later version.
15 * 12 *
16 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful, but
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 * GNU General Public License for more details. 16 * for more details.
20 * 17 *
21 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License along
22 * along with this program; if not, write to the Free Software 19 * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51
23 * Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 *
22 * The authors can be reached via e-mail to <crossfire@schmorp.de>
24 */ 23 */
24
25#include "autoconf.h"
25 26
26#define PLUGIN_NAME "perl" 27#define PLUGIN_NAME "perl"
27#define PLUGIN_VERSION "cfperl 0.5" 28#define PLUGIN_VERSION "cfperl 0.5"
28 29
29#define CEDES_PER_TICK 5 30#define CEDES_PER_TICK 5
31
32#if HAVE_EXECINFO_H
33# include <execinfo.h>
34#endif
30 35
31#include <plugin_common.h> 36#include <plugin_common.h>
32#include <sounds.h> 37#include <sounds.h>
33#include <cstdarg> 38#include <cstdarg>
34#include <sproto.h> 39#include <sproto.h>
56 61
57typedef char *octet_string; 62typedef char *octet_string;
58typedef char *utf8_string; 63typedef char *utf8_string;
59typedef const char *const_octet_string; 64typedef const char *const_octet_string;
60typedef const char *const_utf8_string; 65typedef const char *const_utf8_string;
66
67typedef std::string std__string;
61 68
62#if IVSIZE >= 8 69#if IVSIZE >= 8
63 typedef IV val64; 70 typedef IV val64;
64# define newSVval64 newSViv 71# define newSVval64 newSViv
65# define SvVAL64 SvIV 72# define SvVAL64 SvIV
68# define newSVval64 newSVnv 75# define newSVval64 newSVnv
69# define SvVAL64 SvNV 76# define SvVAL64 SvNV
70#endif 77#endif
71 78
72static f_plug_api gethook = cfapi_get_hooks; 79static f_plug_api gethook = cfapi_get_hooks;
73static f_plug_api object_set_property = cfapi_object_set_property;
74static f_plug_api object_insert = cfapi_object_insert; 80static f_plug_api object_insert = cfapi_object_insert;
75 81
76static PerlInterpreter *perl; 82static PerlInterpreter *perl;
77 83
78double runtime; 84tstamp NOW, runtime;
79 85
80global gbl_ev; 86global gbl_ev;
81static 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;
82static 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;
83 92
84static HV 93static HV
85 *stash_cf, 94 *stash_cf,
86 *stash_cf_object_wrap, 95 *stash_cf_object_wrap,
87 *stash_cf_object_player_wrap, 96 *stash_cf_object_player_wrap,
109 118
110unordered_vector<attachable *> attachable::mortals; 119unordered_vector<attachable *> attachable::mortals;
111 120
112attachable::~attachable () 121attachable::~attachable ()
113{ 122{
114 flags |=0x3300;//D
115 assert (!self); 123 assert (!self);
116 assert (!cb); 124 assert (!cb);
117} 125}
118 126
119int 127int
135 sv_unmagic ((SV *)self, PERL_MAGIC_ext); 143 sv_unmagic ((SV *)self, PERL_MAGIC_ext);
136 SvREFCNT_dec (self); 144 SvREFCNT_dec (self);
137 145
138 // self *must* be null now because thats sv_unmagic's job. 146 // self *must* be null now because thats sv_unmagic's job.
139 assert (!this->self); 147 assert (!this->self);
140 flags |= 0x80; // severed //D
141 } 148 }
142} 149}
143 150
144void 151void
145attachable::optimise () 152attachable::optimise ()
146{ 153{
147 if (self 154 if (self
148 && SvREFCNT (self) == 1 155 && SvREFCNT (self) == 1
149 && !HvTOTALKEYS (self)) 156 && !HvTOTALKEYS (self))
150 flags |= 0x40,//D
151 sever_self (); 157 sever_self ();
152} 158}
153 159
154// check wether the object really is dead 160// check wether the object really is dead
155void 161void
162} 168}
163 169
164void 170void
165attachable::do_destroy () 171attachable::do_destroy ()
166{ 172{
167 invoke (EVENT_ATTACHABLE_DESTROY, DT_END); 173 INVOKE_ATTACHABLE (DESTROY, this);
168 174
169 if (cb) 175 if (cb)
170 { 176 {
171 SvREFCNT_dec (cb); 177 SvREFCNT_dec (cb);
172 cb = 0; 178 cb = 0;
173 } 179 }
174 180
175 if (self)
176 sever_self ();
177
178 flags |= 0x20; //D
179 mortals.push_back (this); 181 mortals.push_back (this);
180} 182}
181 183
182void 184void
183attachable::destroy () 185attachable::destroy ()
185 if (destroyed ()) 187 if (destroyed ())
186 return; 188 return;
187 189
188 flags |= F_DESTROYED; 190 flags |= F_DESTROYED;
189 do_destroy (); 191 do_destroy ();
192 sever_self ();
190} 193}
191 194
192void 195void
193attachable::check_mortals () 196attachable::check_mortals ()
194{ 197{
198 { 201 {
199 if (i >= mortals.size ()) 202 if (i >= mortals.size ())
200 { 203 {
201 i = 0; 204 i = 0;
202 205
203 if (mortals.size () > 1000) 206 if (mortals.size () >= 512)
204 fprintf (stderr, "mortal queue size (%d) exceeds 1000.\n", (int)mortals.size ()); 207 {
208 static int last_mortalcount;
209 if (mortals.size () != last_mortalcount)
210 {
211 last_mortalcount = mortals.size ();
212 LOG (llevInfo, "%d mortals.\n", (int)mortals.size ());
213
214 if (0)
215 {
216 for (int j = 0; j < mortals.size (); ++j)//D
217 fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D
218 fprintf (stderr, "\n");//D
219 }
220 }
221 }
205 222
206 break; 223 break;
207 } 224 }
208 225
209 attachable *obj = mortals [i]; 226 attachable *obj = mortals [i];
210 227
211 obj->refcnt_chk (); // unborrow from perl, if necessary 228#if 0
212 229 if (obj->self)//D make this an assert later
213 //if (obj->refcnt > 0 || obj->self)
214 if (obj->refcnt || obj->self)
215 { 230 {
216//printf ("%p rc %d\n", obj, obj->refcnt_cnt ());//D 231 LOG (llevError, "check_mortals: object '%s' still has self\n", typeid (obj).name ());
232 obj->sever_self ();
233 }
234#endif
235
236 if (obj->refcnt)
237 {
217 ++i; // further delay freeing 238 ++i; // further delay freeing
218 239
219 if (!(i & 0x3ff)) 240 if (!(i & 0x3ff))
220 break; 241 break;
221 } 242 }
222 else 243 else
223 { 244 {
224 mortals.erase (i); 245 mortals.erase (i);
246 obj->sever_self ();
225 delete obj; 247 delete obj;
226 } 248 }
227 } 249 }
228} 250}
229 251
233 //if (self || cb) 255 //if (self || cb)
234 //INVOKE_OBJECT (CLONE, this, ARG_OBJECT (dst)); 256 //INVOKE_OBJECT (CLONE, this, ARG_OBJECT (dst));
235 257
236 attach = src.attach; 258 attach = src.attach;
237 return *this; 259 return *this;
260}
261
262template<typename T>
263static bool
264find_backref (void *ptr, T *obj)
265{
266 char *s = (char *)obj;
267 while (s < (char *)obj + sizeof (T))
268 {
269 if (ptr == *(void **)s)
270 return true;
271
272 s += sizeof (void *); // assume natural alignment
273 }
274
275 return false;
276}
277
278// for debugging, find "live" objects containing this ptr
279void
280find_backref (void *ptr)
281{
282 for_all_objects (op)
283 if (find_backref (ptr, op))
284 fprintf (stderr, "O %p %d:'%s'\n", op, op->count, &op->name);
285
286 for_all_players (pl)
287 if (find_backref (ptr, pl))
288 fprintf (stderr, "P %p\n", pl);
289
290 for_all_clients (ns)
291 if (find_backref (ptr, ns))
292 fprintf (stderr, "C %p\n", ns);
293
238} 294}
239 295
240////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 296//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
241 297
242static SV * 298static SV *
278 334
279 if (!obj->self) 335 if (!obj->self)
280 { 336 {
281 obj->self = newHV (); 337 obj->self = newHV ();
282 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); 338 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0);
283 obj->flags |= (obj->flags & 0xc0) << 8;
284 obj->flags &= ~0xc0;//D
285 obj->flags |= 0x10;//D
286 339
287 // now bless the object _once_ 340 // now bless the object _once_
288 return sv_bless (newRV_inc ((SV *)obj->self), stash); 341 return sv_bless (newRV_inc ((SV *)obj->self), stash);
289 } 342 }
290 else 343 else
356inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } 409inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); }
357 410
358inline SV *to_sv (object & v) { return to_sv (&v); } 411inline SV *to_sv (object & v) { return to_sv (&v); }
359inline SV *to_sv (living & v) { return to_sv (&v); } 412inline SV *to_sv (living & v) { return to_sv (&v); }
360 413
361//inline SV *to_sv (faceinfo * v) { return to_sv (v->name); }
362inline SV *to_sv (treasurelist * v) { return to_sv (v->name); }
363inline SV *to_sv (std::string & v) { return newSVpvn (v.data (), v.size ()); } 414inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); }
415inline SV *to_sv (const treasurelist *v) { return to_sv (v->name); }
364 416
365inline SV *to_sv (UUID v) 417inline SV *to_sv (UUID v)
366{ 418{
367 char buf[128]; 419 char buf[128];
368 snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq); 420 snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq);
401inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } 453inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; }
402 454
403template<int N> 455template<int N>
404inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } 456inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); }
405 457
406inline void sv_to (SV *sv, rangetype &v) { v = (rangetype) SvIV (sv); }
407inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); } 458inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); }
408inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); } 459inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); }
409inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); } 460inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); }
410inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); } 461inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); }
411 462
614 perl_construct (perl); 665 perl_construct (perl);
615 666
616 PL_exit_flags |= PERL_EXIT_DESTRUCT_END; 667 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
617 668
618 const char *argv[] = { 669 const char *argv[] = {
619 "", 670 settings.argv [0],
620 "-e" 671 "-e"
621 "use Event; use Coro;" // required for bootstrap 672 "use Event; use Coro;" // required for bootstrap
622 "cf->bootstrap;" // required for datadir :*> 673 "cf->bootstrap;" // required for datadir :*>
623 "unshift @INC, cf::datadir ();" 674 "unshift @INC, cf::datadir ();"
624 "require cf;" 675 "require cf;"
652void 703void
653attachable::instantiate () 704attachable::instantiate ()
654{ 705{
655 if (attach) 706 if (attach)
656 { 707 {
657 invoke (EVENT_ATTACHABLE_INSTANTIATE, ARG_STRING (attach), DT_END); 708 INVOKE_ATTACHABLE (INSTANTIATE, this, ARG_STRING (attach));
658 attach = 0; 709 attach = 0;
659 } 710 }
660} 711}
661 712
662void 713void
663attachable::reattach () 714attachable::reattach ()
664{ 715{
665 optimise (); 716 optimise ();
666 //TODO: check for _attachment's, very important for restarts 717 //TODO: check for _attachment's, very important for restarts
667 invoke (EVENT_ATTACHABLE_REATTACH, DT_END); 718 INVOKE_ATTACHABLE (REATTACH, this);
668} 719}
669 720
670static event_klass klass_of[NUM_EVENT_TYPES] = { 721static event_klass klass_of[NUM_EVENT_TYPES] = {
671# define def(type,name) KLASS_ ## type, 722# define def(type,name) KLASS_ ## type,
672# include "eventinc.h" 723# include "eventinc.h"
715} 766}
716 767
717void 768void
718global::gather_callbacks (AV *&callbacks, event_type event) const 769global::gather_callbacks (AV *&callbacks, event_type event) const
719{ 770{
720 ::gather_callbacks (callbacks, cb_object, event); 771 ::gather_callbacks (callbacks, cb_global, event);
721} 772}
722 773
723void 774void
724object::gather_callbacks (AV *&callbacks, event_type event) const 775object::gather_callbacks (AV *&callbacks, event_type event) const
725{ 776{
726 if (subtype && type + subtype * NUM_SUBTYPES <= AvFILLp (cb_type)) 777 if (subtype && type + subtype * NUM_TYPES <= AvFILLp (cb_type))
727 { 778 {
728 SV *registry = AvARRAY (cb_type)[type + subtype * NUM_SUBTYPES]; 779 SV *registry = AvARRAY (cb_type)[type + subtype * NUM_TYPES];
729 780
730 if (registry && SvROK (registry) && SvTYPE (SvRV (registry)) == SVt_PVAV) 781 if (registry && SvROK (registry) && SvTYPE (SvRV (registry)) == SVt_PVAV)
731 ::gather_callbacks (callbacks, (AV *)SvRV (registry), event); 782 ::gather_callbacks (callbacks, (AV *)SvRV (registry), event);
732 } 783 }
733 784
769{ 820{
770 attachable::gather_callbacks (callbacks, event); 821 attachable::gather_callbacks (callbacks, event);
771 ::gather_callbacks (callbacks, cb_map, event); 822 ::gather_callbacks (callbacks, cb_map, event);
772} 823}
773 824
825void
826_recalc_want (bitset<NUM_EVENT_TYPES> &set, AV *registry)
827{
828 for (int event = 0; event <= AvFILLp (registry); ++event)
829 {
830 SV *cbs_ = AvARRAY (registry)[event];
831
832 // element must be list of callback entries
833 if (cbs_ && SvROK (cbs_) && SvTYPE (SvRV (cbs_)) == SVt_PVAV)
834 {
835 AV *cbs = (AV *)SvRV (cbs_);
836
837 // no callback entries, no callbacks to call
838 if (AvFILLp (cbs) >= 0)
839 set.set (event);
840 }
841 }
842}
843
844// very slow and inefficient way to recalculate the global want bitsets
845void
846_recalc_want ()
847{
848 ev_want_event.reset ();
849
850 _recalc_want (ev_want_event, cb_global);
851 _recalc_want (ev_want_event, cb_attachable);
852 _recalc_want (ev_want_event, cb_object);
853 _recalc_want (ev_want_event, cb_client);
854 _recalc_want (ev_want_event, cb_player);
855 _recalc_want (ev_want_event, cb_map);
856
857 ev_want_type.reset ();
858
859 for (int type = 0; type <= AvFILLp (cb_type); ++type)
860 {
861 SV *cbs_ = AvARRAY (cb_type)[type];
862
863 // element must be list of callback entries
864 if (cbs_ && SvROK (cbs_) && SvTYPE (SvRV (cbs_)) == SVt_PVAV)
865 {
866 AV *cbs = (AV *)SvRV (cbs_);
867
868 // no callback entries, no callbacks to call
869 if (AvFILLp (cbs) >= 0)
870 ev_want_type.set (type % NUM_TYPES);
871 }
872 }
873}
874
774bool 875bool
775attachable::invoke (event_type event, ...) 876attachable::invoke (event_type event, ...)
776{ 877{
777 data_type dt; 878 data_type dt;
778 va_list ap;
779
780 va_start (ap, event);
781 879
782 // callback call ordering should be: 880 // callback call ordering should be:
783 // 1. per-object callback 881 // 1. per-object callback
784 // 2. per-class object 882 // 2. per-class object
785 // 3. per-type callback 883 // 3. per-type callback
789 gather_callbacks (callbacks, event); 887 gather_callbacks (callbacks, event);
790 888
791 // short-circuit processing if no callbacks found/defined 889 // short-circuit processing if no callbacks found/defined
792 if (!callbacks) 890 if (!callbacks)
793 return 0; 891 return 0;
892
893 va_list ap;
894 va_start (ap, event);
794 895
795 CALL_BEGIN (3); 896 CALL_BEGIN (3);
796 CALL_ARG_SV (newSViv (event)); // only used for debugging nowadays 897 CALL_ARG_SV (newSViv (event)); // only used for debugging nowadays
797 CALL_ARG_SV (newRV_noinc ((SV *)callbacks)); 898 CALL_ARG_SV (newRV_noinc ((SV *)callbacks));
798 899
875 CALL_ARG (make_core); 976 CALL_ARG (make_core);
876 CALL_CALL ("cf::post_cleanup", G_VOID); 977 CALL_CALL ("cf::post_cleanup", G_VOID);
877 CALL_END; 978 CALL_END;
878} 979}
879 980
981void
982cfperl_make_book (object *book, int level)
983{
984 CALL_BEGIN (2);
985 CALL_ARG (book);
986 CALL_ARG (level);
987 CALL_CALL ("ext::books::make_book", G_VOID);
988 CALL_END;
989}
990
991void
992cfperl_send_msg (client *ns, int color, const char *type, const char *msg)
993{
994 CALL_BEGIN (4);
995 CALL_ARG (ns);
996 CALL_ARG (color);
997 CALL_ARG (type);
998 CALL_ARG (msg);
999 CALL_CALL ("cf::client::send_msg", G_VOID);
1000 CALL_END;
1001}
1002
880maptile * 1003maptile *
881maptile::find_sync (const char *path, maptile *origin) 1004maptile::find_sync (const char *path, maptile *origin)
882{ 1005{
883 CALL_BEGIN (2); 1006 CALL_BEGIN (2);
884 CALL_ARG (path); 1007 CALL_ARG (path);
946 CALL_ARG (exit); 1069 CALL_ARG (exit);
947 CALL_CALL ("cf::object::player::enter_exit", G_VOID); 1070 CALL_CALL ("cf::object::player::enter_exit", G_VOID);
948 CALL_END; 1071 CALL_END;
949} 1072}
950 1073
1074void
1075log_backtrace (const char *msg)
1076{
1077#if HAVE_BACKTRACE
1078 void *addr [20];
1079 int size = backtrace (addr, 20);
1080
1081 CALL_BEGIN (size);
1082 CALL_ARG (msg);
1083 for (int i = 0; i < size; ++i)
1084 CALL_ARG ((IV)addr [i]);
1085 CALL_CALL ("cf::_log_backtrace", G_VOID);
1086 CALL_END;
1087#endif
1088}
1089
951///////////////////////////////////////////////////////////////////////////// 1090/////////////////////////////////////////////////////////////////////////////
952 1091
953struct EventAPI *watcher_base::GEventAPI; 1092struct EventAPI *watcher_base::GEventAPI;
954struct CoroAPI *coroapi::GCoroAPI; 1093struct CoroAPI *coroapi::GCoroAPI;
955 1094
956int coroapi::cede_counter; 1095int coroapi::cede_counter;
957double (*coroapi::time)();
958double coroapi::next_cede; 1096tstamp coroapi::next_cede;
959 1097
960void coroapi::do_cede_to_tick () 1098void coroapi::do_cede_to_tick ()
961{ 1099{
962 cede_counter = 0; 1100 cede_counter = 0;
963 1101
1094 1232
1095 _connect_to_perl (); 1233 _connect_to_perl ();
1096 1234
1097 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); 1235 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1));
1098 1236
1099 { 1237 //{
1100 require_pv ("Time::HiRes"); 1238 // require_pv ("Time::HiRes");
1101 1239 //
1102 SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0); 1240 // SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0);
1103 if (!svp) croak ("Time::HiRes is required"); 1241 // if (!svp) croak ("Time::HiRes is required");
1104 if (!SvIOK(*svp)) croak ("Time::NVtime isn’t a function pointer"); 1242 // if (!SvIOK(*svp)) croak ("Time::NVtime isn’t a function pointer");
1105 coroapi::time = INT2PTR (double(*)(), SvIV(*svp)); 1243 // coroapi::time = INT2PTR (double(*)(), SvIV(*svp));
1106 } 1244 //}
1107 1245
1108 static const struct { 1246 static const struct {
1109 const char *name; 1247 const char *name;
1110 IV iv; 1248 IV iv;
1111 } *civ, const_iv[] = { 1249 } *civ, const_iv[] = {
1112# define const_iv(name) { # name, (IV)name }, 1250# define const_iv(name) { # name, (IV)name },
1113 const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster) 1251 const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster)
1252 const_iv (logBacktrace)
1114 1253
1115 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) 1254 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd)
1116 1255
1117 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1256 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1118 1257
1119 const_iv (MAX_TIME) 1258 const_iv (MAX_TIME)
1259
1260 const_iv (NUM_BODY_LOCATIONS)
1261 const_iv (body_range) const_iv (body_shield) const_iv (body_combat)
1262 const_iv (body_arm) const_iv (body_torso) const_iv (body_head)
1263 const_iv (body_neck) const_iv (body_skill) const_iv (body_finger)
1264 const_iv (body_shoulder) const_iv (body_foot) const_iv (body_hand)
1265 const_iv (body_wrist) const_iv (body_waist)
1120 1266
1121 const_iv (PLAYER) const_iv (TRANSPORT) const_iv (ROD) const_iv (TREASURE) 1267 const_iv (PLAYER) const_iv (TRANSPORT) const_iv (ROD) const_iv (TREASURE)
1122 const_iv (POTION) const_iv (FOOD) const_iv (POISON) const_iv (BOOK) 1268 const_iv (POTION) const_iv (FOOD) const_iv (POISON) const_iv (BOOK)
1123 const_iv (CLOCK) const_iv (ARROW) const_iv (BOW) const_iv (WEAPON) 1269 const_iv (CLOCK) const_iv (ARROW) const_iv (BOW) const_iv (WEAPON)
1124 const_iv (ARMOUR) const_iv (PEDESTAL) const_iv (ALTAR) const_iv (LOCKED_DOOR) 1270 const_iv (ARMOUR) const_iv (PEDESTAL) const_iv (ALTAR) const_iv (LOCKED_DOOR)
1145 const_iv (CONTAINER) const_iv (ARMOUR_IMPROVER) const_iv (WEAPON_IMPROVER) const_iv (SKILLSCROLL) 1291 const_iv (CONTAINER) const_iv (ARMOUR_IMPROVER) const_iv (WEAPON_IMPROVER) const_iv (SKILLSCROLL)
1146 const_iv (DEEP_SWAMP) const_iv (IDENTIFY_ALTAR) const_iv (MENU) const_iv (RUNE) 1292 const_iv (DEEP_SWAMP) const_iv (IDENTIFY_ALTAR) const_iv (MENU) const_iv (RUNE)
1147 const_iv (TRAP) const_iv (POWER_CRYSTAL) const_iv (CORPSE) const_iv (DISEASE) 1293 const_iv (TRAP) const_iv (POWER_CRYSTAL) const_iv (CORPSE) const_iv (DISEASE)
1148 const_iv (SYMPTOM) const_iv (BUILDER) const_iv (MATERIAL) const_iv (ITEM_TRANSFORMER) 1294 const_iv (SYMPTOM) const_iv (BUILDER) const_iv (MATERIAL) const_iv (ITEM_TRANSFORMER)
1149 1295
1150 const_iv (NUM_SUBTYPES) 1296 const_iv (NUM_TYPES) const_iv (NUM_SUBTYPES)
1151 1297
1152 const_iv (ST_BD_BUILD) const_iv (ST_BD_REMOVE) 1298 const_iv (ST_BD_BUILD) const_iv (ST_BD_REMOVE)
1153 const_iv (ST_MAT_FLOOR) const_iv (ST_MAT_WALL) const_iv (ST_MAT_ITEM) 1299 const_iv (ST_MAT_FLOOR) const_iv (ST_MAT_WALL) const_iv (ST_MAT_ITEM)
1154 1300
1155 const_iv (AT_PHYSICAL) const_iv (AT_MAGIC) const_iv (AT_FIRE) const_iv (AT_ELECTRICITY) 1301 const_iv (AT_PHYSICAL) const_iv (AT_MAGIC) const_iv (AT_FIRE) const_iv (AT_ELECTRICITY)
1163 const_iv (WEAP_HIT) const_iv (WEAP_SLASH) const_iv (WEAP_PIERCE) const_iv (WEAP_CLEAVE) 1309 const_iv (WEAP_HIT) const_iv (WEAP_SLASH) const_iv (WEAP_PIERCE) const_iv (WEAP_CLEAVE)
1164 const_iv (WEAP_SLICE) const_iv (WEAP_STAB) const_iv (WEAP_WHIP) const_iv (WEAP_CRUSH) 1310 const_iv (WEAP_SLICE) const_iv (WEAP_STAB) const_iv (WEAP_WHIP) const_iv (WEAP_CRUSH)
1165 const_iv (WEAP_BLUD) 1311 const_iv (WEAP_BLUD)
1166 1312
1167 const_iv (FLAG_ALIVE) const_iv (FLAG_WIZ) const_iv (FLAG_REMOVED) const_iv (FLAG_FREED) 1313 const_iv (FLAG_ALIVE) const_iv (FLAG_WIZ) const_iv (FLAG_REMOVED) const_iv (FLAG_FREED)
1168 const_iv (FLAG_WAS_WIZ) const_iv (FLAG_APPLIED) const_iv (FLAG_UNPAID) const_iv (FLAG_USE_SHIELD) 1314 const_iv (FLAG_APPLIED) const_iv (FLAG_UNPAID) const_iv (FLAG_USE_SHIELD)
1169 const_iv (FLAG_NO_PICK) const_iv (FLAG_ANIMATE) const_iv (FLAG_MONSTER) const_iv (FLAG_FRIENDLY) 1315 const_iv (FLAG_NO_PICK) const_iv (FLAG_ANIMATE) const_iv (FLAG_MONSTER) const_iv (FLAG_FRIENDLY)
1170 const_iv (FLAG_GENERATOR) const_iv (FLAG_IS_THROWN) const_iv (FLAG_AUTO_APPLY) const_iv (FLAG_PLAYER_SOLD) 1316 const_iv (FLAG_GENERATOR) const_iv (FLAG_IS_THROWN) const_iv (FLAG_AUTO_APPLY) const_iv (FLAG_PLAYER_SOLD)
1171 const_iv (FLAG_SEE_INVISIBLE) const_iv (FLAG_CAN_ROLL) const_iv (FLAG_OVERLAY_FLOOR) const_iv (FLAG_IS_TURNABLE) 1317 const_iv (FLAG_SEE_INVISIBLE) const_iv (FLAG_CAN_ROLL) const_iv (FLAG_OVERLAY_FLOOR) const_iv (FLAG_IS_TURNABLE)
1172 const_iv (FLAG_IS_USED_UP) const_iv (FLAG_IDENTIFIED) const_iv (FLAG_REFLECTING) const_iv (FLAG_CHANGING) 1318 const_iv (FLAG_IS_USED_UP) const_iv (FLAG_IDENTIFIED) const_iv (FLAG_REFLECTING) const_iv (FLAG_CHANGING)
1173 const_iv (FLAG_SPLITTING) const_iv (FLAG_HITBACK) const_iv (FLAG_STARTEQUIP) const_iv (FLAG_BLOCKSVIEW) 1319 const_iv (FLAG_SPLITTING) const_iv (FLAG_HITBACK) const_iv (FLAG_STARTEQUIP) const_iv (FLAG_BLOCKSVIEW)
1200 const_iv (UPD_LOCATION) const_iv (UPD_FLAGS) const_iv (UPD_WEIGHT) const_iv (UPD_FACE) 1346 const_iv (UPD_LOCATION) const_iv (UPD_FLAGS) const_iv (UPD_WEIGHT) const_iv (UPD_FACE)
1201 const_iv (UPD_NAME) const_iv (UPD_ANIM) const_iv (UPD_ANIMSPEED) const_iv (UPD_NROF) 1347 const_iv (UPD_NAME) const_iv (UPD_ANIM) const_iv (UPD_ANIMSPEED) const_iv (UPD_NROF)
1202 1348
1203 const_iv (UPD_SP_MANA) const_iv (UPD_SP_GRACE) const_iv (UPD_SP_DAMAGE) 1349 const_iv (UPD_SP_MANA) const_iv (UPD_SP_GRACE) const_iv (UPD_SP_DAMAGE)
1204 1350
1351 const_iv (SP_RAISE_DEAD)
1352 const_iv (SP_RUNE)
1353 const_iv (SP_MAKE_MARK)
1354 const_iv (SP_BOLT)
1355 const_iv (SP_BULLET)
1356 const_iv (SP_EXPLOSION)
1357 const_iv (SP_CONE)
1358 const_iv (SP_BOMB)
1359 const_iv (SP_WONDER)
1360 const_iv (SP_SMITE)
1361 const_iv (SP_MAGIC_MISSILE)
1362 const_iv (SP_SUMMON_GOLEM)
1363 const_iv (SP_DIMENSION_DOOR)
1364 const_iv (SP_MAGIC_MAPPING)
1365 const_iv (SP_MAGIC_WALL)
1366 const_iv (SP_DESTRUCTION)
1367 const_iv (SP_PERCEIVE_SELF)
1368 const_iv (SP_WORD_OF_RECALL)
1369 const_iv (SP_INVISIBLE)
1370 const_iv (SP_PROBE)
1371 const_iv (SP_HEALING)
1372 const_iv (SP_CREATE_FOOD)
1373 const_iv (SP_EARTH_TO_DUST)
1374 const_iv (SP_CHANGE_ABILITY)
1375 const_iv (SP_BLESS)
1376 const_iv (SP_CURSE)
1377 const_iv (SP_SUMMON_MONSTER)
1378 const_iv (SP_CHARGING)
1379 const_iv (SP_POLYMORPH)
1380 const_iv (SP_ALCHEMY)
1381 const_iv (SP_REMOVE_CURSE)
1382 const_iv (SP_IDENTIFY)
1383 const_iv (SP_DETECTION)
1384 const_iv (SP_MOOD_CHANGE)
1385 const_iv (SP_MOVING_BALL)
1386 const_iv (SP_SWARM)
1387 const_iv (SP_CHANGE_MANA)
1388 const_iv (SP_DISPEL_RUNE)
1389 const_iv (SP_CREATE_MISSILE)
1390 const_iv (SP_CONSECRATE)
1391 const_iv (SP_ANIMATE_WEAPON)
1392 const_iv (SP_LIGHT)
1393 const_iv (SP_CHANGE_MAP_LIGHT)
1394 const_iv (SP_FAERY_FIRE)
1395 const_iv (SP_CAUSE_DISEASE)
1396 const_iv (SP_AURA)
1397 const_iv (SP_TOWN_PORTAL)
1398 const_iv (SP_PARTY_SPELL)
1399
1205 const_iv (F_APPLIED) const_iv (F_LOCATION) const_iv (F_UNPAID) const_iv (F_MAGIC) 1400 const_iv (F_APPLIED) const_iv (F_LOCATION) const_iv (F_UNPAID) const_iv (F_MAGIC)
1206 const_iv (F_CURSED) const_iv (F_DAMNED) const_iv (F_OPEN) const_iv (F_NOPICK) 1401 const_iv (F_CURSED) const_iv (F_DAMNED) const_iv (F_OPEN) const_iv (F_NOPICK)
1207 const_iv (F_LOCKED) 1402 const_iv (F_LOCKED)
1208 1403
1209 const_iv (F_BUY) const_iv (F_SHOP) const_iv (F_SELL) 1404 const_iv (F_BUY) const_iv (F_SHOP) const_iv (F_SELL)
1265 1460
1266 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) 1461 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT)
1267 1462
1268 const_iv (ST_DEAD) const_iv (ST_SETUP) const_iv (ST_PLAYING) const_iv (ST_CUSTOM) 1463 const_iv (ST_DEAD) const_iv (ST_SETUP) const_iv (ST_PLAYING) const_iv (ST_CUSTOM)
1269 1464
1270 const_iv (ST_CHANGE_CLASS)
1271
1272 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) 1465 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES)
1273 1466
1274 // random map generator 1467 // random map generator
1275 const_iv (LAYOUT_NONE) const_iv (LAYOUT_ONION) const_iv (LAYOUT_MAZE) const_iv (LAYOUT_SPIRAL) 1468 const_iv (LAYOUT_NONE) const_iv (LAYOUT_ONION) const_iv (LAYOUT_MAZE) const_iv (LAYOUT_SPIRAL)
1276 const_iv (LAYOUT_ROGUELIKE) const_iv (LAYOUT_SNAKE) const_iv (LAYOUT_SQUARE_SPIRAL) 1469 const_iv (LAYOUT_ROGUELIKE) const_iv (LAYOUT_SNAKE) const_iv (LAYOUT_SQUARE_SPIRAL)
1279 const_iv (RMOPT_BOTTOM_C) const_iv (RMOPT_BOTTOM_R) const_iv (RMOPT_IRR_SPACE) 1472 const_iv (RMOPT_BOTTOM_C) const_iv (RMOPT_BOTTOM_R) const_iv (RMOPT_IRR_SPACE)
1280 const_iv (RMOPT_WALL_OFF) const_iv (RMOPT_WALLS_ONLY) const_iv (RMOPT_NO_DOORS) 1473 const_iv (RMOPT_WALL_OFF) const_iv (RMOPT_WALLS_ONLY) const_iv (RMOPT_NO_DOORS)
1281 1474
1282 const_iv (SYMMETRY_RANDOM) const_iv (SYMMETRY_NONE) const_iv (SYMMETRY_X) 1475 const_iv (SYMMETRY_RANDOM) const_iv (SYMMETRY_NONE) const_iv (SYMMETRY_X)
1283 const_iv (SYMMETRY_Y) const_iv (SYMMETRY_XY) 1476 const_iv (SYMMETRY_Y) const_iv (SYMMETRY_XY)
1477
1478 const_iv (GT_ENVIRONMENT) const_iv (GT_INVISIBLE) const_iv (GT_STARTEQUIP)
1479 const_iv (GT_APPLY) const_iv (GT_ONLY_GOOD) const_iv (GT_UPDATE_INV)
1480 const_iv (GT_MINIMAL)
1284 }; 1481 };
1285 1482
1286 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1483 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1287 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); 1484 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv));
1288 1485
1309 } 1506 }
1310} 1507}
1311 1508
1312void _connect_to_perl () 1509void _connect_to_perl ()
1313 1510
1511void _recalc_want ()
1512
1314void _global_reattach () 1513void _global_reattach ()
1315 CODE: 1514 CODE:
1316{ 1515{
1317 // reattach to all attachable objects in the game. 1516 // reattach to all attachable objects in the game.
1318 for_all_clients (ns) 1517 for_all_clients (ns)
1323} 1522}
1324 1523
1325void _post_tick () 1524void _post_tick ()
1326 CODE: 1525 CODE:
1327 coroapi::next_cede = SvNV (sv_next_tick) - TICK * (1. - 1. / CEDES_PER_TICK); 1526 coroapi::next_cede = SvNV (sv_next_tick) - TICK * (1. - 1. / CEDES_PER_TICK);
1527
1528# support function for map-world.ext
1529void _quantise (SV *data_sv, SV *plt_sv)
1530 CODE:
1531{
1532 if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV)
1533 croak ("_quantise called with invalid agruments");
1534
1535 plt_sv = SvRV (plt_sv);
1536 SV **plt = AvARRAY (plt_sv);
1537 int plt_count = AvFILL (plt_sv) + 1;
1538
1539 STRLEN len;
1540 char *data = SvPVbyte (data_sv, len);
1541 char *dst = data;
1542
1543 while (len >= 3)
1544 {
1545 for (SV **val_sv = plt + plt_count; val_sv-- > plt; )
1546 {
1547 char *val = SvPVX (*val_sv);
1548
1549 if (val [0] == data [0]
1550 && val [1] == data [1]
1551 && val [2] == data [2])
1552 {
1553 *dst++ = val [3];
1554 goto next;
1555 }
1556 }
1557
1558 croak ("_quantise: color not found in palette: #%02x%02x%02x, at offset %d %d",
1559 (uint8_t)data [0], (uint8_t)data [1], (uint8_t)data [2],
1560 dst - SvPVX (data_sv), len);
1561
1562 next:
1563 data += 3;
1564 len -= 3;
1565 }
1566
1567 SvCUR_set (data_sv, dst - SvPVX (data_sv));
1568}
1328 1569
1329NV floor (NV x) 1570NV floor (NV x)
1330 1571
1331NV ceil (NV x) 1572NV ceil (NV x)
1332 1573
1340 default: croak ("cf::rndm requires none, one or two parameters."); break; 1581 default: croak ("cf::rndm requires none, one or two parameters."); break;
1341 } 1582 }
1342 OUTPUT: 1583 OUTPUT:
1343 RETVAL 1584 RETVAL
1344 1585
1586NV clamp (NV value, NV min_value, NV max_value)
1587 CODE:
1588 RETVAL = clamp (value, min_value, max_value);
1589 OUTPUT:
1590 RETVAL
1591
1592NV lerp (NV value, NV min_in, NV max_in, NV min_out, NV max_out)
1593 CODE:
1594 RETVAL = lerp (value, min_in, max_in, min_out, max_out);
1595 OUTPUT:
1596 RETVAL
1597
1598void cede_to_tick ()
1599 CODE:
1600 coroapi::cede_to_tick ();
1601
1345void server_tick () 1602void server_tick ()
1346 CODE: 1603 CODE:
1604 NOW = now ();
1347 runtime = SvNVx (sv_runtime); 1605 runtime = SvNVx (sv_runtime);
1348 server_tick (); 1606 server_tick ();
1349 1607
1350void 1608void
1609log_backtrace (utf8_string msg)
1610
1611void
1351LOG (int level, utf8_string msg) 1612LOG (int flags, utf8_string msg)
1352 PROTOTYPE: $$ 1613 PROTOTYPE: $$
1353 C_ARGS: (LogLevel)level, "%s", msg 1614 C_ARGS: flags, "%s", msg
1354 1615
1355octet_string path_combine (octet_string base, octet_string path) 1616octet_string path_combine (octet_string base, octet_string path)
1356 PROTOTYPE: $$ 1617 PROTOTYPE: $$
1357 1618
1358octet_string path_combine_and_normalize (octet_string base, octet_string path) 1619octet_string path_combine_and_normalize (octet_string base, octet_string path)
1395 } 1656 }
1396 OUTPUT: RETVAL 1657 OUTPUT: RETVAL
1397 1658
1398void abort () 1659void abort ()
1399 1660
1661void reset_signals ()
1662
1400void fork_abort (octet_string cause = "cf::fork_abort") 1663void fork_abort (octet_string cause = "cf::fork_abort")
1401 1664
1402void cleanup (octet_string cause, bool make_core = false) 1665void cleanup (octet_string cause, bool make_core = false)
1403 1666
1404void emergency_save () 1667void emergency_save ()
1466 OUTPUT: RETVAL 1729 OUTPUT: RETVAL
1467 1730
1468bool 1731bool
1469load_resource_file (octet_string filename) 1732load_resource_file (octet_string filename)
1470 1733
1471bool
1472load_archetype_file (octet_string filename)
1473
1474MODULE = cf PACKAGE = cf::attachable 1734MODULE = cf PACKAGE = cf::attachable
1475 1735
1476int 1736int
1477valid (SV *obj) 1737valid (SV *obj)
1478 CODE: 1738 CODE:
1541object *actives (U32 index) 1801object *actives (U32 index)
1542 CODE: 1802 CODE:
1543 RETVAL = index < actives.size () ? actives [index] : 0; 1803 RETVAL = index < actives.size () ? actives [index] : 0;
1544 OUTPUT: RETVAL 1804 OUTPUT: RETVAL
1545 1805
1806const char *slot_use_name (U32 slot)
1807 ALIAS:
1808 slot_nonuse_name = 1
1809 CODE:
1810{
1811 if (slot >= NUM_BODY_LOCATIONS)
1812 croak ("body slot index out of range");
1813
1814 switch (ix)
1815 {
1816 case 0: RETVAL = body_locations[slot].use_name; break;
1817 case 1: RETVAL = body_locations[slot].nonuse_name; break;
1818 }
1819}
1820 OUTPUT:
1821 RETVAL
1822
1546# missing properties 1823# missing properties
1547 1824
1548object *head (object *op) 1825object *head (object *op)
1549 PROTOTYPE: $ 1826 PROTOTYPE: $
1550 CODE: 1827 CODE:
1551 RETVAL = op->head_ (); 1828 RETVAL = op->head_ ();
1552 OUTPUT: RETVAL
1553
1554int is_head (object *op)
1555 PROTOTYPE: $
1556 CODE:
1557 RETVAL = op->head_ () == op;
1558 OUTPUT: RETVAL 1829 OUTPUT: RETVAL
1559 1830
1560void 1831void
1561inv (object *obj) 1832inv (object *obj)
1562 PROTOTYPE: $ 1833 PROTOTYPE: $
1575int 1846int
1576num_animations (object *op) 1847num_animations (object *op)
1577 CODE: 1848 CODE:
1578 RETVAL = NUM_ANIMATIONS (op); 1849 RETVAL = NUM_ANIMATIONS (op);
1579 OUTPUT: RETVAL 1850 OUTPUT: RETVAL
1851
1852int slot_info (object *op, UV slot, int value = 0)
1853 ALIAS:
1854 slot_used = 1
1855 CODE:
1856{
1857 if (slot >= NUM_BODY_LOCATIONS)
1858 croak ("body slot index out of range");
1859
1860 RETVAL = ix ? op->slot[slot].used : op->slot[slot].info;
1861
1862 if (items > 2)
1863 if (ix)
1864 op->slot[slot].used = value;
1865 else
1866 op->slot[slot].info = value;
1867}
1868 OUTPUT:
1869 RETVAL
1580 1870
1581object *find_best_object_match (object *op, utf8_string match) 1871object *find_best_object_match (object *op, utf8_string match)
1582 1872
1583object *find_marked_object (object *op) 1873object *find_marked_object (object *op)
1584 1874
1700# dumb kludgy misdesigned plug-in api slowly gets on my nerves. 1990# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
1701 1991
1702object *new (utf8_string archetype = 0) 1992object *new (utf8_string archetype = 0)
1703 PROTOTYPE: ;$ 1993 PROTOTYPE: ;$
1704 CODE: 1994 CODE:
1705 RETVAL = archetype ? get_archetype (archetype) : cf_create_object (); 1995 RETVAL = archetype ? get_archetype (archetype) : object::create ();
1706 OUTPUT: 1996 OUTPUT:
1707 RETVAL 1997 RETVAL
1708 1998
1999# TODO: nuke
1709object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y) 2000object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y)
1710 PROTOTYPE: $$$$$$ 2001 PROTOTYPE: $$$$$$
1711 CODE: 2002 CODE:
1712{ 2003{
1713 int unused_type; 2004 int unused_type;
1766 2057
1767void message (object *op, utf8_string txt, int flags = NDI_ORANGE | NDI_UNIQUE) 2058void message (object *op, utf8_string txt, int flags = NDI_ORANGE | NDI_UNIQUE)
1768 CODE: 2059 CODE:
1769 new_draw_info (flags, 0, op, txt); 2060 new_draw_info (flags, 0, op, txt);
1770 2061
1771object *cf_player_send_inventory (object *op)
1772
1773octet_string cf_player_get_ip (object *op)
1774 ALIAS: ip = 0
1775
1776object *cf_player_get_marked_item (object *op)
1777 ALIAS: marked_item = 0
1778
1779void cf_player_set_marked_item (object *op, object *ob)
1780
1781partylist *cf_player_get_party (object *op)
1782 ALIAS: party = 0
1783
1784void cf_player_set_party (object *op, partylist *party)
1785
1786void kill_player (object *op) 2062void kill_player (object *op)
1787 2063
1788void esrv_update_item (object *op, int what, object *item) 2064void esrv_update_item (object *op, int what, object *item)
1789 C_ARGS: what, op, item 2065 C_ARGS: what, op, item
1790
1791void clear_los (object *op)
1792 2066
1793int command_summon (object *op, utf8_string params) 2067int command_summon (object *op, utf8_string params)
1794 2068
1795int command_arrest (object *op, utf8_string params) 2069int command_arrest (object *op, utf8_string params)
1796 2070
1814 CODE: 2088 CODE:
1815 pl->ob->stats.hp = pl->ob->stats.maxhp; 2089 pl->ob->stats.hp = pl->ob->stats.maxhp;
1816 pl->ob->stats.sp = pl->ob->stats.maxsp; 2090 pl->ob->stats.sp = pl->ob->stats.maxsp;
1817 pl->ob->stats.grace = pl->ob->stats.maxgrace; 2091 pl->ob->stats.grace = pl->ob->stats.maxgrace;
1818 pl->orig_stats = pl->ob->stats; 2092 pl->orig_stats = pl->ob->stats;
2093
2094void clear_los (player *pl)
1819 2095
1820void cf_player_move (player *pl, int dir) 2096void cf_player_move (player *pl, int dir)
1821 2097
1822void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); 2098void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0);
1823 2099
1933 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) 2209 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
1934 { 2210 {
1935 object *ob = get_archetype (SvPVutf8_nolen (*elem)); 2211 object *ob = get_archetype (SvPVutf8_nolen (*elem));
1936 ob->flag [FLAG_NO_MAP_SAVE] = true; 2212 ob->flag [FLAG_NO_MAP_SAVE] = true;
1937 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); 2213 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2214
2215 if (ob->randomitems)
2216 {
2217 if (!ob->above)
2218 {
2219 ob->create_treasure (ob->randomitems);
2220
2221 for (object *op = ob->above; op; op = op->above)
2222 op->flag [FLAG_NO_MAP_SAVE] = true;
2223 }
2224
2225 ob->randomitems = 0;
2226 }
1938 } 2227 }
1939 } 2228 }
1940 } 2229 }
1941 2230
1942 skip_space: ; 2231 skip_space: ;
1969 sfree (THIS->regions, THIS->size ()); 2258 sfree (THIS->regions, THIS->size ());
1970 free (THIS->regionmap); 2259 free (THIS->regionmap);
1971 2260
1972 THIS->regions = regions; 2261 THIS->regions = regions;
1973 THIS->regionmap = regionmap; 2262 THIS->regionmap = regionmap;
2263}
2264
2265void
2266maptile::create_region_treasure ()
2267 CODE:
2268{
2269 object *op = object::create ();
2270 op->type = FLOOR;
2271 op->map = THIS;
2272
2273 for (int x = 0; x < THIS->width; ++x)
2274 for (int y = 0; y < THIS->height; ++y)
2275 {
2276 region *rgn = THIS->region (x, y);
2277
2278 //fprintf (stderr, "%d,%d %f %p\n", x, y, rgn->treasure_density,rgn->treasure);//D
2279 if (rgn->treasure && rndm () < rgn->treasure_density)
2280 {
2281 op->x = x;
2282 op->y = y;
2283 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty);
2284 }
2285 }
2286
2287 op->destroy ();
1974} 2288}
1975 2289
1976void play_sound_map (maptile *map, int x, int y, int sound_num) 2290void play_sound_map (maptile *map, int x, int y, int sound_num)
1977 2291
1978int out_of_map (maptile *map, int x, int y) 2292int out_of_map (maptile *map, int x, int y)
2137 rmp.decoroptions = decoroptions; 2451 rmp.decoroptions = decoroptions;
2138 rmp.orientation = orientation; 2452 rmp.orientation = orientation;
2139 rmp.origin_y = origin_y; 2453 rmp.origin_y = origin_y;
2140 rmp.origin_x = origin_x; 2454 rmp.origin_x = origin_x;
2141 rmp.random_seed = random_seed; 2455 rmp.random_seed = random_seed;
2142 rmp.total_map_hp = total_map_hp; 2456 rmp.total_map_hp = (uint64_t) total_map_hp;
2143 rmp.map_layout_style = map_layout_style; 2457 rmp.map_layout_style = map_layout_style;
2144 rmp.treasureoptions = treasureoptions; 2458 rmp.treasureoptions = treasureoptions;
2145 rmp.symmetry_used = symmetry_used; 2459 rmp.symmetry_used = symmetry_used;
2146 rmp.region = region; 2460 rmp.region = region;
2147 rmp.custom = custom; 2461 rmp.custom = custom;
2157 CODE: 2471 CODE:
2158 RETVAL = archetype::find (name); 2472 RETVAL = archetype::find (name);
2159 OUTPUT: 2473 OUTPUT:
2160 RETVAL 2474 RETVAL
2161 2475
2162archetype *first() 2476int archetypes_size ()
2163 PROTOTYPE: 2477 CODE:
2164 CODE:
2165 RETVAL = first_archetype; 2478 RETVAL = archetypes.size ();
2479 OUTPUT: RETVAL
2480
2481archetype *archetypes (U32 index)
2482 CODE:
2483 RETVAL = index < archetypes.size () ? archetypes [index] : 0;
2484 OUTPUT: RETVAL
2485
2486object *instantiate (archetype *arch)
2487 CODE:
2488 RETVAL = arch_to_object (arch);
2489 OUTPUT:
2166 OUTPUT: RETVAL 2490 RETVAL
2167 2491
2168INCLUDE: $PERL $srcdir/genacc archetype ../include/object.h | 2492INCLUDE: $PERL $srcdir/genacc archetype ../include/object.h |
2169 2493
2170MODULE = cf PACKAGE = cf::party 2494MODULE = cf PACKAGE = cf::party
2171 2495
2202 RETVAL = 0; 2526 RETVAL = 0;
2203 while (rgn = rgn->parent) 2527 while (rgn = rgn->parent)
2204 RETVAL++; 2528 RETVAL++;
2205 OUTPUT: RETVAL 2529 OUTPUT: RETVAL
2206 2530
2207INCLUDE: $PERL $srcdir/genacc region ../include/map.h | 2531INCLUDE: $PERL $srcdir/genacc region ../include/region.h |
2208 2532
2209MODULE = cf PACKAGE = cf::living 2533MODULE = cf PACKAGE = cf::living
2210 2534
2211INCLUDE: $PERL $srcdir/genacc living ../include/living.h | 2535INCLUDE: $PERL $srcdir/genacc living ../include/living.h |
2212 2536

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines