… | |
… | |
21 | * You should have received a copy of the GNU General Public License |
21 | * You should have received a copy of the GNU General Public License |
22 | * along with this program; if not, write to the Free Software |
22 | * along with this program; if not, write to the Free Software |
23 | * Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
23 | * Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
24 | */ |
24 | */ |
25 | |
25 | |
|
|
26 | #include "autoconf.h" |
|
|
27 | |
26 | #define PLUGIN_NAME "perl" |
28 | #define PLUGIN_NAME "perl" |
27 | #define PLUGIN_VERSION "cfperl 0.5" |
29 | #define PLUGIN_VERSION "cfperl 0.5" |
28 | |
30 | |
29 | #define CEDES_PER_TICK 5 |
31 | #define CEDES_PER_TICK 5 |
|
|
32 | |
|
|
33 | #if HAVE_EXECINFO_H |
|
|
34 | # include <execinfo.h> |
|
|
35 | #endif |
30 | |
36 | |
31 | #include <plugin_common.h> |
37 | #include <plugin_common.h> |
32 | #include <sounds.h> |
38 | #include <sounds.h> |
33 | #include <cstdarg> |
39 | #include <cstdarg> |
34 | #include <sproto.h> |
40 | #include <sproto.h> |
… | |
… | |
56 | |
62 | |
57 | typedef char *octet_string; |
63 | typedef char *octet_string; |
58 | typedef char *utf8_string; |
64 | typedef char *utf8_string; |
59 | typedef const char *const_octet_string; |
65 | typedef const char *const_octet_string; |
60 | typedef const char *const_utf8_string; |
66 | typedef const char *const_utf8_string; |
|
|
67 | |
|
|
68 | typedef std::string std__string; |
61 | |
69 | |
62 | #if IVSIZE >= 8 |
70 | #if IVSIZE >= 8 |
63 | typedef IV val64; |
71 | typedef IV val64; |
64 | # define newSVval64 newSViv |
72 | # define newSVval64 newSViv |
65 | # define SvVAL64 SvIV |
73 | # define SvVAL64 SvIV |
… | |
… | |
109 | |
117 | |
110 | unordered_vector<attachable *> attachable::mortals; |
118 | unordered_vector<attachable *> attachable::mortals; |
111 | |
119 | |
112 | attachable::~attachable () |
120 | attachable::~attachable () |
113 | { |
121 | { |
114 | flags |=0x3300;//D |
|
|
115 | assert (!self); |
122 | assert (!self); |
116 | assert (!cb); |
123 | assert (!cb); |
117 | } |
124 | } |
118 | |
125 | |
119 | int |
126 | int |
… | |
… | |
135 | sv_unmagic ((SV *)self, PERL_MAGIC_ext); |
142 | sv_unmagic ((SV *)self, PERL_MAGIC_ext); |
136 | SvREFCNT_dec (self); |
143 | SvREFCNT_dec (self); |
137 | |
144 | |
138 | // self *must* be null now because thats sv_unmagic's job. |
145 | // self *must* be null now because thats sv_unmagic's job. |
139 | assert (!this->self); |
146 | assert (!this->self); |
140 | flags |= 0x80; // severed //D |
|
|
141 | } |
147 | } |
142 | } |
148 | } |
143 | |
149 | |
144 | void |
150 | void |
145 | attachable::optimise () |
151 | attachable::optimise () |
146 | { |
152 | { |
147 | if (self |
153 | if (self |
148 | && SvREFCNT (self) == 1 |
154 | && SvREFCNT (self) == 1 |
149 | && !HvTOTALKEYS (self)) |
155 | && !HvTOTALKEYS (self)) |
150 | flags |= 0x40,//D |
|
|
151 | sever_self (); |
156 | sever_self (); |
152 | } |
157 | } |
153 | |
158 | |
154 | // check wether the object really is dead |
159 | // check wether the object really is dead |
155 | void |
160 | void |
… | |
… | |
170 | { |
175 | { |
171 | SvREFCNT_dec (cb); |
176 | SvREFCNT_dec (cb); |
172 | cb = 0; |
177 | cb = 0; |
173 | } |
178 | } |
174 | |
179 | |
175 | if (self) |
|
|
176 | sever_self (); |
|
|
177 | |
|
|
178 | flags |= 0x20; //D |
|
|
179 | mortals.push_back (this); |
180 | mortals.push_back (this); |
180 | } |
181 | } |
181 | |
182 | |
182 | void |
183 | void |
183 | attachable::destroy () |
184 | attachable::destroy () |
… | |
… | |
185 | if (destroyed ()) |
186 | if (destroyed ()) |
186 | return; |
187 | return; |
187 | |
188 | |
188 | flags |= F_DESTROYED; |
189 | flags |= F_DESTROYED; |
189 | do_destroy (); |
190 | do_destroy (); |
|
|
191 | sever_self (); |
190 | } |
192 | } |
191 | |
193 | |
192 | void |
194 | void |
193 | attachable::check_mortals () |
195 | attachable::check_mortals () |
194 | { |
196 | { |
… | |
… | |
199 | if (i >= mortals.size ()) |
201 | if (i >= mortals.size ()) |
200 | { |
202 | { |
201 | i = 0; |
203 | i = 0; |
202 | |
204 | |
203 | if (mortals.size () > 1000) |
205 | if (mortals.size () > 1000) |
204 | fprintf (stderr, "mortal queue size (%d) exceeds 1000.\n", (int)mortals.size ()); |
206 | LOG (llevInfo, "mortal queue size (%d) exceeds 1000.\n", (int)mortals.size ()); |
205 | |
207 | |
206 | break; |
208 | break; |
207 | } |
209 | } |
208 | |
210 | |
209 | attachable *obj = mortals [i]; |
211 | attachable *obj = mortals [i]; |
210 | |
212 | |
211 | obj->refcnt_chk (); // unborrow from perl, if necessary |
213 | #if 0 |
212 | |
214 | if (obj->self)//D make this an assert later |
213 | //if (obj->refcnt > 0 || obj->self) |
|
|
214 | if (obj->refcnt || obj->self) |
|
|
215 | { |
215 | { |
216 | //printf ("%p rc %d\n", obj, obj->refcnt_cnt ());//D |
216 | LOG (llevError, "check_mortals: object '%s' still has self\n", typeid (obj).name ()); |
|
|
217 | obj->sever_self (); |
|
|
218 | } |
|
|
219 | #endif |
|
|
220 | |
|
|
221 | if (obj->refcnt) |
|
|
222 | { |
217 | ++i; // further delay freeing |
223 | ++i; // further delay freeing |
218 | |
224 | |
219 | if (!(i & 0x3ff)) |
225 | if (!(i & 0x3ff)) |
220 | break; |
226 | break; |
221 | } |
227 | } |
222 | else |
228 | else |
223 | { |
229 | { |
224 | mortals.erase (i); |
230 | mortals.erase (i); |
|
|
231 | obj->sever_self (); |
225 | delete obj; |
232 | delete obj; |
226 | } |
233 | } |
227 | } |
234 | } |
228 | } |
235 | } |
229 | |
236 | |
… | |
… | |
278 | |
285 | |
279 | if (!obj->self) |
286 | if (!obj->self) |
280 | { |
287 | { |
281 | obj->self = newHV (); |
288 | obj->self = newHV (); |
282 | sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); |
289 | 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 | |
290 | |
287 | // now bless the object _once_ |
291 | // now bless the object _once_ |
288 | return sv_bless (newRV_inc ((SV *)obj->self), stash); |
292 | return sv_bless (newRV_inc ((SV *)obj->self), stash); |
289 | } |
293 | } |
290 | else |
294 | else |
… | |
… | |
356 | inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } |
360 | inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } |
357 | |
361 | |
358 | inline SV *to_sv (object & v) { return to_sv (&v); } |
362 | inline SV *to_sv (object & v) { return to_sv (&v); } |
359 | inline SV *to_sv (living & v) { return to_sv (&v); } |
363 | inline SV *to_sv (living & v) { return to_sv (&v); } |
360 | |
364 | |
361 | //inline SV *to_sv (faceinfo * v) { return to_sv (v->name); } |
|
|
362 | inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } |
|
|
363 | inline SV *to_sv (std::string & v) { return newSVpvn (v.data (), v.size ()); } |
365 | inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } |
|
|
366 | inline SV *to_sv (const treasurelist *v) { return to_sv (v->name); } |
364 | |
367 | |
365 | inline SV *to_sv (UUID v) |
368 | inline SV *to_sv (UUID v) |
366 | { |
369 | { |
367 | char buf[128]; |
370 | char buf[128]; |
368 | snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq); |
371 | snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq); |
… | |
… | |
401 | inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } |
404 | inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } |
402 | |
405 | |
403 | template<int N> |
406 | template<int N> |
404 | inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } |
407 | inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } |
405 | |
408 | |
406 | inline void sv_to (SV *sv, rangetype &v) { v = (rangetype) SvIV (sv); } |
|
|
407 | inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); } |
409 | inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); } |
408 | inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); } |
410 | inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); } |
409 | inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); } |
411 | inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); } |
410 | inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); } |
412 | inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); } |
411 | |
413 | |
… | |
… | |
614 | perl_construct (perl); |
616 | perl_construct (perl); |
615 | |
617 | |
616 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
618 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
617 | |
619 | |
618 | const char *argv[] = { |
620 | const char *argv[] = { |
619 | "", |
621 | settings.argv [0], |
620 | "-e" |
622 | "-e" |
621 | "use Event; use Coro;" // required for bootstrap |
623 | "use Event; use Coro;" // required for bootstrap |
622 | "cf->bootstrap;" // required for datadir :*> |
624 | "cf->bootstrap;" // required for datadir :*> |
623 | "unshift @INC, cf::datadir ();" |
625 | "unshift @INC, cf::datadir ();" |
624 | "require cf;" |
626 | "require cf;" |
… | |
… | |
946 | CALL_ARG (exit); |
948 | CALL_ARG (exit); |
947 | CALL_CALL ("cf::object::player::enter_exit", G_VOID); |
949 | CALL_CALL ("cf::object::player::enter_exit", G_VOID); |
948 | CALL_END; |
950 | CALL_END; |
949 | } |
951 | } |
950 | |
952 | |
|
|
953 | void |
|
|
954 | log_backtrace (const char *msg) |
|
|
955 | { |
|
|
956 | #if HAVE_BACKTRACE |
|
|
957 | void *addr [20]; |
|
|
958 | int size = backtrace (addr, 20); |
|
|
959 | |
|
|
960 | CALL_BEGIN (size); |
|
|
961 | CALL_ARG (msg); |
|
|
962 | for (int i = 0; i < size; ++i) |
|
|
963 | CALL_ARG ((IV)addr [i]); |
|
|
964 | CALL_CALL ("cf::_log_backtrace", G_VOID); |
|
|
965 | CALL_END; |
|
|
966 | #endif |
|
|
967 | } |
|
|
968 | |
951 | ///////////////////////////////////////////////////////////////////////////// |
969 | ///////////////////////////////////////////////////////////////////////////// |
952 | |
970 | |
953 | struct EventAPI *watcher_base::GEventAPI; |
971 | struct EventAPI *watcher_base::GEventAPI; |
954 | struct CoroAPI *coroapi::GCoroAPI; |
972 | struct CoroAPI *coroapi::GCoroAPI; |
955 | |
973 | |
… | |
… | |
1109 | const char *name; |
1127 | const char *name; |
1110 | IV iv; |
1128 | IV iv; |
1111 | } *civ, const_iv[] = { |
1129 | } *civ, const_iv[] = { |
1112 | # define const_iv(name) { # name, (IV)name }, |
1130 | # define const_iv(name) { # name, (IV)name }, |
1113 | const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster) |
1131 | const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster) |
|
|
1132 | const_iv (logBacktrace) |
1114 | |
1133 | |
1115 | const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) |
1134 | const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) |
1116 | |
1135 | |
1117 | const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) |
1136 | const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) |
1118 | |
1137 | |
… | |
… | |
1265 | |
1284 | |
1266 | const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) |
1285 | const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) |
1267 | |
1286 | |
1268 | const_iv (ST_DEAD) const_iv (ST_SETUP) const_iv (ST_PLAYING) const_iv (ST_CUSTOM) |
1287 | const_iv (ST_DEAD) const_iv (ST_SETUP) const_iv (ST_PLAYING) const_iv (ST_CUSTOM) |
1269 | |
1288 | |
1270 | const_iv (ST_CHANGE_CLASS) |
|
|
1271 | |
|
|
1272 | const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) |
1289 | const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) |
1273 | |
1290 | |
1274 | // random map generator |
1291 | // random map generator |
1275 | const_iv (LAYOUT_NONE) const_iv (LAYOUT_ONION) const_iv (LAYOUT_MAZE) const_iv (LAYOUT_SPIRAL) |
1292 | 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) |
1293 | 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) |
1296 | 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) |
1297 | const_iv (RMOPT_WALL_OFF) const_iv (RMOPT_WALLS_ONLY) const_iv (RMOPT_NO_DOORS) |
1281 | |
1298 | |
1282 | const_iv (SYMMETRY_RANDOM) const_iv (SYMMETRY_NONE) const_iv (SYMMETRY_X) |
1299 | const_iv (SYMMETRY_RANDOM) const_iv (SYMMETRY_NONE) const_iv (SYMMETRY_X) |
1283 | const_iv (SYMMETRY_Y) const_iv (SYMMETRY_XY) |
1300 | const_iv (SYMMETRY_Y) const_iv (SYMMETRY_XY) |
|
|
1301 | |
|
|
1302 | const_iv (GT_ENVIRONMENT) const_iv (GT_INVISIBLE) const_iv (GT_STARTEQUIP) |
|
|
1303 | const_iv (GT_APPLY) const_iv (GT_ONLY_GOOD) const_iv (GT_UPDATE_INV) |
|
|
1304 | const_iv (GT_MINIMAL) |
1284 | }; |
1305 | }; |
1285 | |
1306 | |
1286 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1307 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1287 | newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); |
1308 | newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); |
1288 | |
1309 | |
… | |
… | |
1324 | |
1345 | |
1325 | void _post_tick () |
1346 | void _post_tick () |
1326 | CODE: |
1347 | CODE: |
1327 | coroapi::next_cede = SvNV (sv_next_tick) - TICK * (1. - 1. / CEDES_PER_TICK); |
1348 | coroapi::next_cede = SvNV (sv_next_tick) - TICK * (1. - 1. / CEDES_PER_TICK); |
1328 | |
1349 | |
|
|
1350 | # support function for map-world.ext |
|
|
1351 | void _quantise (SV *data_sv, SV *plt_sv) |
|
|
1352 | CODE: |
|
|
1353 | { |
|
|
1354 | if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV) |
|
|
1355 | croak ("_quantise called with invalid agruments"); |
|
|
1356 | |
|
|
1357 | plt_sv = SvRV (plt_sv); |
|
|
1358 | SV **plt = AvARRAY (plt_sv); |
|
|
1359 | int plt_count = AvFILL (plt_sv) + 1; |
|
|
1360 | |
|
|
1361 | STRLEN len; |
|
|
1362 | char *data = SvPVbyte (data_sv, len); |
|
|
1363 | char *dst = data; |
|
|
1364 | |
|
|
1365 | while (len >= 3) |
|
|
1366 | { |
|
|
1367 | for (SV **val_sv = plt + plt_count; val_sv-- > plt; ) |
|
|
1368 | { |
|
|
1369 | char *val = SvPVX (*val_sv); |
|
|
1370 | |
|
|
1371 | if (val [0] == data [0] |
|
|
1372 | && val [1] == data [1] |
|
|
1373 | && val [2] == data [2]) |
|
|
1374 | { |
|
|
1375 | *dst++ = val [3]; |
|
|
1376 | goto next; |
|
|
1377 | } |
|
|
1378 | } |
|
|
1379 | |
|
|
1380 | croak ("_quantise: color not found in palette: #%02x%02x%02x, at offset %d %d", |
|
|
1381 | (uint8_t)data [0], (uint8_t)data [1], (uint8_t)data [2], |
|
|
1382 | dst - SvPVX (data_sv), len); |
|
|
1383 | |
|
|
1384 | next: |
|
|
1385 | data += 3; |
|
|
1386 | len -= 3; |
|
|
1387 | } |
|
|
1388 | |
|
|
1389 | SvCUR_set (data_sv, dst - SvPVX (data_sv)); |
|
|
1390 | } |
|
|
1391 | |
1329 | NV floor (NV x) |
1392 | NV floor (NV x) |
1330 | |
1393 | |
1331 | NV ceil (NV x) |
1394 | NV ceil (NV x) |
1332 | |
1395 | |
1333 | NV rndm (...) |
1396 | NV rndm (...) |
… | |
… | |
1346 | CODE: |
1409 | CODE: |
1347 | runtime = SvNVx (sv_runtime); |
1410 | runtime = SvNVx (sv_runtime); |
1348 | server_tick (); |
1411 | server_tick (); |
1349 | |
1412 | |
1350 | void |
1413 | void |
|
|
1414 | log_backtrace (utf8_string msg) |
|
|
1415 | |
|
|
1416 | void |
1351 | LOG (int level, utf8_string msg) |
1417 | LOG (int flags, utf8_string msg) |
1352 | PROTOTYPE: $$ |
1418 | PROTOTYPE: $$ |
1353 | C_ARGS: (LogLevel)level, "%s", msg |
1419 | C_ARGS: flags, "%s", msg |
1354 | |
1420 | |
1355 | octet_string path_combine (octet_string base, octet_string path) |
1421 | octet_string path_combine (octet_string base, octet_string path) |
1356 | PROTOTYPE: $$ |
1422 | PROTOTYPE: $$ |
1357 | |
1423 | |
1358 | octet_string path_combine_and_normalize (octet_string base, octet_string path) |
1424 | octet_string path_combine_and_normalize (octet_string base, octet_string path) |
… | |
… | |
1395 | } |
1461 | } |
1396 | OUTPUT: RETVAL |
1462 | OUTPUT: RETVAL |
1397 | |
1463 | |
1398 | void abort () |
1464 | void abort () |
1399 | |
1465 | |
|
|
1466 | void reset_signals () |
|
|
1467 | |
1400 | void fork_abort (octet_string cause = "cf::fork_abort") |
1468 | void fork_abort (octet_string cause = "cf::fork_abort") |
1401 | |
1469 | |
1402 | void cleanup (octet_string cause, bool make_core = false) |
1470 | void cleanup (octet_string cause, bool make_core = false) |
1403 | |
1471 | |
1404 | void emergency_save () |
1472 | void emergency_save () |
… | |
… | |
1465 | XSRETURN_UNDEF; |
1533 | XSRETURN_UNDEF; |
1466 | OUTPUT: RETVAL |
1534 | OUTPUT: RETVAL |
1467 | |
1535 | |
1468 | bool |
1536 | bool |
1469 | load_resource_file (octet_string filename) |
1537 | load_resource_file (octet_string filename) |
1470 | |
|
|
1471 | bool |
|
|
1472 | load_archetype_file (octet_string filename) |
|
|
1473 | |
|
|
1474 | bool |
|
|
1475 | load_treasure_file (octet_string filename) |
|
|
1476 | |
1538 | |
1477 | MODULE = cf PACKAGE = cf::attachable |
1539 | MODULE = cf PACKAGE = cf::attachable |
1478 | |
1540 | |
1479 | int |
1541 | int |
1480 | valid (SV *obj) |
1542 | valid (SV *obj) |
… | |
… | |
1936 | if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) |
1998 | if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) |
1937 | { |
1999 | { |
1938 | object *ob = get_archetype (SvPVutf8_nolen (*elem)); |
2000 | object *ob = get_archetype (SvPVutf8_nolen (*elem)); |
1939 | ob->flag [FLAG_NO_MAP_SAVE] = true; |
2001 | ob->flag [FLAG_NO_MAP_SAVE] = true; |
1940 | THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); |
2002 | THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); |
|
|
2003 | |
|
|
2004 | if (ob->randomitems) |
|
|
2005 | { |
|
|
2006 | if (!ob->above) |
|
|
2007 | { |
|
|
2008 | ob->create_treasure (ob->randomitems); |
|
|
2009 | |
|
|
2010 | for (object *op = ob->above; op; op = op->above) |
|
|
2011 | op->flag [FLAG_NO_MAP_SAVE] = true; |
|
|
2012 | } |
|
|
2013 | |
|
|
2014 | ob->randomitems = 0; |
|
|
2015 | } |
1941 | } |
2016 | } |
1942 | } |
2017 | } |
1943 | } |
2018 | } |
1944 | |
2019 | |
1945 | skip_space: ; |
2020 | skip_space: ; |
… | |
… | |
1972 | sfree (THIS->regions, THIS->size ()); |
2047 | sfree (THIS->regions, THIS->size ()); |
1973 | free (THIS->regionmap); |
2048 | free (THIS->regionmap); |
1974 | |
2049 | |
1975 | THIS->regions = regions; |
2050 | THIS->regions = regions; |
1976 | THIS->regionmap = regionmap; |
2051 | THIS->regionmap = regionmap; |
|
|
2052 | } |
|
|
2053 | |
|
|
2054 | void |
|
|
2055 | maptile::create_region_treasure () |
|
|
2056 | CODE: |
|
|
2057 | { |
|
|
2058 | object *op = object::create (); |
|
|
2059 | op->type = FLOOR; |
|
|
2060 | op->map = THIS; |
|
|
2061 | |
|
|
2062 | for (int x = 0; x < THIS->width; ++x) |
|
|
2063 | for (int y = 0; y < THIS->height; ++y) |
|
|
2064 | { |
|
|
2065 | region *rgn = THIS->region (x, y); |
|
|
2066 | |
|
|
2067 | //fprintf (stderr, "%d,%d %f %p\n", x, y, rgn->treasure_density,rgn->treasure);//D |
|
|
2068 | if (rgn->treasure && rndm () < rgn->treasure_density) |
|
|
2069 | { |
|
|
2070 | op->x = x; |
|
|
2071 | op->y = y; |
|
|
2072 | create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); |
|
|
2073 | } |
|
|
2074 | } |
|
|
2075 | |
|
|
2076 | op->destroy (); |
1977 | } |
2077 | } |
1978 | |
2078 | |
1979 | void play_sound_map (maptile *map, int x, int y, int sound_num) |
2079 | void play_sound_map (maptile *map, int x, int y, int sound_num) |
1980 | |
2080 | |
1981 | int out_of_map (maptile *map, int x, int y) |
2081 | int out_of_map (maptile *map, int x, int y) |
… | |
… | |
2205 | RETVAL = 0; |
2305 | RETVAL = 0; |
2206 | while (rgn = rgn->parent) |
2306 | while (rgn = rgn->parent) |
2207 | RETVAL++; |
2307 | RETVAL++; |
2208 | OUTPUT: RETVAL |
2308 | OUTPUT: RETVAL |
2209 | |
2309 | |
2210 | INCLUDE: $PERL $srcdir/genacc region ../include/map.h | |
2310 | INCLUDE: $PERL $srcdir/genacc region ../include/region.h | |
2211 | |
2311 | |
2212 | MODULE = cf PACKAGE = cf::living |
2312 | MODULE = cf PACKAGE = cf::living |
2213 | |
2313 | |
2214 | INCLUDE: $PERL $srcdir/genacc living ../include/living.h | |
2314 | INCLUDE: $PERL $srcdir/genacc living ../include/living.h | |
2215 | |
2315 | |