… | |
… | |
29 | #include <cstdarg> |
29 | #include <cstdarg> |
30 | #include <typeinfo> |
30 | #include <typeinfo> |
31 | |
31 | |
32 | #include "global.h" |
32 | #include "global.h" |
33 | #include "rmg.h" |
33 | #include "rmg.h" |
|
|
34 | #include "noise.h" |
34 | #include "evthread.h" |
35 | #include "evthread.h" |
35 | #include "sproto.h" |
36 | #include "sproto.h" |
36 | |
37 | |
37 | #include <unistd.h> |
38 | #include <unistd.h> |
38 | #if _POSIX_MEMLOCK |
39 | #if _POSIX_MEMLOCK |
… | |
… | |
66 | static int tick_inhibit; |
67 | static int tick_inhibit; |
67 | static int tick_pending; |
68 | static int tick_pending; |
68 | |
69 | |
69 | global gbl_ev; |
70 | global gbl_ev; |
70 | static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; |
71 | static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; |
71 | static SV *sv_runtime, *sv_tick_start, *sv_next_tick, *sv_now; |
72 | static SV *sv_runtime, *sv_tick_start, *sv_next_tick, *sv_now, *sv_server_tick; |
72 | static AV *av_reflect; |
73 | static AV *av_reflect; |
73 | |
74 | |
74 | bitset<NUM_EVENT_TYPES> ev_want_event; |
75 | bitset<NUM_EVENT_TYPES> ev_want_event; |
75 | bitset<NUM_TYPES> ev_want_type; |
76 | bitset<NUM_TYPES> ev_want_type; |
76 | |
77 | |
… | |
… | |
252 | { |
253 | { |
253 | static int last_mortalcount; |
254 | static int last_mortalcount; |
254 | if (mortals.size () != last_mortalcount) |
255 | if (mortals.size () != last_mortalcount) |
255 | { |
256 | { |
256 | last_mortalcount = mortals.size (); |
257 | last_mortalcount = mortals.size (); |
257 | LOG (llevInfo, "%d mortals.\n", (int)mortals.size ()); |
258 | object *specimen = is_a<object> (mortals [rndm (mortals.size ())]); |
|
|
259 | |
|
|
260 | LOG (llevInfo, "%d mortals (random specimen: %s).\n", |
|
|
261 | (int)mortals.size (), specimen ? specimen->debug_desc () : "(not an object)"); |
258 | |
262 | |
259 | if (0) |
263 | if (0) |
260 | { |
264 | { |
261 | for (int j = 0; j < mortals.size (); ++j)//D |
265 | for (int j = 0; j < mortals.size (); ++j)//D |
262 | fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D |
266 | fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D |
… | |
… | |
1403 | stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); |
1407 | stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); |
1404 | stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); |
1408 | stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); |
1405 | stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1); |
1409 | stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1); |
1406 | stash_ext_map_world = gv_stashpv ("ext::map_world" , 1); |
1410 | stash_ext_map_world = gv_stashpv ("ext::map_world" , 1); |
1407 | |
1411 | |
1408 | sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); |
1412 | sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); |
1409 | sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV); |
1413 | sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV); |
|
|
1414 | sv_server_tick = get_sv ("cf::SERVER_TICK", 1); SvUPGRADE (sv_server_tick, SVt_IV); |
1410 | sv_tick_start = get_sv ("cf::TICK_START", 1); SvUPGRADE (sv_tick_start, SVt_NV); |
1415 | sv_tick_start = get_sv ("cf::TICK_START" , 1); SvUPGRADE (sv_tick_start , SVt_NV); |
1411 | sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV); |
1416 | sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV); |
1412 | |
1417 | |
1413 | cb_global = get_av ("cf::CB_GLOBAL", 1); |
1418 | cb_global = get_av ("cf::CB_GLOBAL", 1); |
1414 | cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); |
1419 | cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); |
1415 | cb_object = get_av ("cf::CB_OBJECT", 1); |
1420 | cb_object = get_av ("cf::CB_OBJECT", 1); |
1416 | cb_player = get_av ("cf::CB_PLAYER", 1); |
1421 | cb_player = get_av ("cf::CB_PLAYER", 1); |
… | |
… | |
1485 | const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) |
1490 | const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) |
1486 | |
1491 | |
1487 | const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE) |
1492 | const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE) |
1488 | const_iv (SK_SUBTRACT_SKILL_EXP) const_iv (SK_EXP_SKILL_ONLY) |
1493 | const_iv (SK_SUBTRACT_SKILL_EXP) const_iv (SK_EXP_SKILL_ONLY) |
1489 | |
1494 | |
1490 | const_iv (MAP_ACTIVE) const_iv (MAP_SWAPPED) const_iv (MAP_LOADING) const_iv (MAP_SAVING) |
|
|
1491 | const_iv (MAP_INACTIVE) |
|
|
1492 | |
|
|
1493 | const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT) |
1495 | const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT) |
1494 | const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP) |
1496 | const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP) |
1495 | |
1497 | |
1496 | const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) |
1498 | const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) |
1497 | |
1499 | |
… | |
… | |
1557 | |
1559 | |
1558 | for_all_objects (op) |
1560 | for_all_objects (op) |
1559 | op->reattach (); |
1561 | op->reattach (); |
1560 | } |
1562 | } |
1561 | |
1563 | |
1562 | # support function for map-world.ext |
|
|
1563 | void _quantise (SV *data_sv, SV *plt_sv) |
|
|
1564 | CODE: |
|
|
1565 | { |
|
|
1566 | if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV) |
|
|
1567 | croak ("_quantise called with invalid agruments"); |
|
|
1568 | |
|
|
1569 | plt_sv = SvRV (plt_sv); |
|
|
1570 | SV **plt = AvARRAY (plt_sv); |
|
|
1571 | int plt_count = AvFILL (plt_sv) + 1; |
|
|
1572 | |
|
|
1573 | STRLEN len; |
|
|
1574 | char *data = SvPVbyte (data_sv, len); |
|
|
1575 | char *dst = data; |
|
|
1576 | |
|
|
1577 | while (len >= 3) |
|
|
1578 | { |
|
|
1579 | for (SV **val_sv = plt + plt_count; val_sv-- > plt; ) |
|
|
1580 | { |
|
|
1581 | char *val = SvPVX (*val_sv); |
|
|
1582 | |
|
|
1583 | if (val [0] == data [0] |
|
|
1584 | && val [1] == data [1] |
|
|
1585 | && val [2] == data [2]) |
|
|
1586 | { |
|
|
1587 | *dst++ = val [3]; |
|
|
1588 | goto next; |
|
|
1589 | } |
|
|
1590 | } |
|
|
1591 | |
|
|
1592 | croak ("_quantise: color not found in palette: #%02x%02x%02x, at offset %d %d", |
|
|
1593 | (uint8_t)data [0], (uint8_t)data [1], (uint8_t)data [2], |
|
|
1594 | dst - SvPVX (data_sv), len); |
|
|
1595 | |
|
|
1596 | next: |
|
|
1597 | data += 3; |
|
|
1598 | len -= 3; |
|
|
1599 | } |
|
|
1600 | |
|
|
1601 | SvCUR_set (data_sv, dst - SvPVX (data_sv)); |
|
|
1602 | } |
|
|
1603 | |
|
|
1604 | void init_anim () |
1564 | void init_anim () |
1605 | |
1565 | |
1606 | void init_globals () |
1566 | void init_globals () |
1607 | |
1567 | |
1608 | void init_attackmess () |
1568 | void init_attackmess () |
… | |
… | |
1654 | { |
1614 | { |
1655 | ev_async_send (EV_DEFAULT, &tick_watcher); |
1615 | ev_async_send (EV_DEFAULT, &tick_watcher); |
1656 | coroapi::cede (); |
1616 | coroapi::cede (); |
1657 | } |
1617 | } |
1658 | |
1618 | |
1659 | void server_tick () |
1619 | void one_tick () |
1660 | CODE: |
1620 | CODE: |
1661 | { |
1621 | { |
1662 | ev_now_update (EV_DEFAULT); |
1622 | ev_now_update (EV_DEFAULT); |
1663 | NOW = ev_now (EV_DEFAULT); |
1623 | NOW = ev_now (EV_DEFAULT); |
1664 | SvNV_set (sv_now, NOW); SvNOK_only (sv_now); |
1624 | SvNV_set (sv_now, NOW); SvNOK_only (sv_now); |
1665 | SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start); |
1625 | SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start); |
1666 | runtime = SvNVX (sv_runtime); |
1626 | runtime = SvNVX (sv_runtime); |
1667 | |
1627 | |
|
|
1628 | one_tick (); |
|
|
1629 | |
1668 | server_tick (); |
1630 | ++server_tick; |
|
|
1631 | SvUV_set (sv_server_tick, server_tick); SvIOK_only_UV (sv_server_tick); |
1669 | |
1632 | |
1670 | ev_now_update (EV_DEFAULT); |
1633 | ev_now_update (EV_DEFAULT); |
1671 | NOW = ev_now (EV_DEFAULT); |
1634 | NOW = ev_now (EV_DEFAULT); |
1672 | SvNV_set (sv_now, NOW); SvNOK_only (sv_now); |
1635 | SvNV_set (sv_now, NOW); SvNOK_only (sv_now); |
|
|
1636 | |
1673 | runtime += TICK; |
1637 | runtime += TICK; |
1674 | SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime); |
1638 | SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime); |
1675 | } |
1639 | } |
1676 | |
1640 | |
1677 | NV floor (NV x) |
1641 | NV floor (NV x) |
… | |
… | |
2144 | # dumb kludgy misdesigned plug-in api slowly gets on my nerves. |
2108 | # dumb kludgy misdesigned plug-in api slowly gets on my nerves. |
2145 | |
2109 | |
2146 | object *new (utf8_string archetype = 0) |
2110 | object *new (utf8_string archetype = 0) |
2147 | PROTOTYPE: ;$ |
2111 | PROTOTYPE: ;$ |
2148 | CODE: |
2112 | CODE: |
2149 | RETVAL = archetype ? get_archetype (archetype) : object::create (); |
2113 | RETVAL = archetype |
|
|
2114 | ? archetype::get (archetype) |
|
|
2115 | : object::create (); |
2150 | OUTPUT: |
2116 | OUTPUT: |
2151 | RETVAL |
2117 | RETVAL |
2152 | |
2118 | |
2153 | object *generate (utf8_string arch, object *creator) |
2119 | object *generate (utf8_string arch, object *creator) |
2154 | CODE: |
2120 | CODE: |
2155 | object *obj = get_archetype (arch); |
2121 | object *obj = archetype::get (arch); |
2156 | fix_generated_item (obj, creator, 0, 0, GT_MINIMAL); |
2122 | fix_generated_item (obj, creator, 0, 0, GT_MINIMAL); |
2157 | RETVAL = obj; |
2123 | RETVAL = obj; |
2158 | OUTPUT: |
2124 | OUTPUT: |
2159 | RETVAL |
2125 | RETVAL |
2160 | |
2126 | |
… | |
… | |
2173 | RETVAL = 0; |
2139 | RETVAL = 0; |
2174 | } |
2140 | } |
2175 | |
2141 | |
2176 | shstr |
2142 | shstr |
2177 | object::kv_get (shstr key) |
2143 | object::kv_get (shstr key) |
|
|
2144 | CODE: |
|
|
2145 | RETVAL = THIS->kv.get (key); |
|
|
2146 | OUTPUT: |
|
|
2147 | RETVAL |
2178 | |
2148 | |
2179 | void |
2149 | void |
2180 | object::kv_del (shstr key) |
2150 | object::kv_del (shstr key) |
|
|
2151 | CODE: |
|
|
2152 | THIS->kv.del (key); |
2181 | |
2153 | |
2182 | void |
2154 | void |
2183 | object::kv_set (shstr key, shstr value) |
2155 | object::kv_set (shstr key, shstr value) |
|
|
2156 | CODE: |
|
|
2157 | THIS->kv.set (key, value); |
2184 | |
2158 | |
2185 | object *get_nearest_player (object *ob) |
2159 | object *get_nearest_player (object *ob) |
2186 | ALIAS: nearest_player = 0 |
2160 | ALIAS: nearest_player = 0 |
2187 | PREINIT: |
2161 | PREINIT: |
2188 | extern object *get_nearest_player (object *); |
2162 | extern object *get_nearest_player (object *); |
… | |
… | |
2391 | if (pl->ob && pl->ob->map == THIS) |
2365 | if (pl->ob && pl->ob->map == THIS) |
2392 | PUSHs (sv_2mortal (to_sv (pl->ob))); |
2366 | PUSHs (sv_2mortal (to_sv (pl->ob))); |
2393 | } |
2367 | } |
2394 | |
2368 | |
2395 | void |
2369 | void |
|
|
2370 | maptile::gen_quadmap (int x, int y, int z) |
|
|
2371 | CODE: |
|
|
2372 | gen_quadmap (THIS, x * 50, y * 50, z); |
|
|
2373 | |
|
|
2374 | void |
2396 | maptile::add_underlay (SV *data, int offset, int stride, SV *palette) |
2375 | maptile::add_underlay (SV *data, int offset, int stride, SV *palette) |
2397 | CODE: |
2376 | CODE: |
2398 | { |
2377 | { |
2399 | if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) |
2378 | if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) |
2400 | croak ("maptile::add_underlay: palette must be arrayref"); |
2379 | croak ("maptile::add_underlay: palette must be arrayref"); |
… | |
… | |
2416 | |
2395 | |
2417 | if (IN_RANGE_EXC (offs, 0, idxlen)) |
2396 | if (IN_RANGE_EXC (offs, 0, idxlen)) |
2418 | { |
2397 | { |
2419 | if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) |
2398 | if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) |
2420 | { |
2399 | { |
2421 | object *ob = get_archetype (cfSvPVutf8_nolen (*elem)); |
2400 | object *ob = archetype::get (cfSvPVutf8_nolen (*elem)); |
2422 | ob->flag [FLAG_NO_MAP_SAVE] = true; |
2401 | ob->flag [FLAG_NO_MAP_SAVE] = true; |
2423 | THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); |
2402 | THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); |
2424 | |
2403 | |
2425 | if (ob->randomitems && !ob->above) |
2404 | if (ob->randomitems && !ob->above) |
2426 | { |
2405 | { |
… | |
… | |
2430 | op->flag [FLAG_NO_MAP_SAVE] = true; |
2409 | op->flag [FLAG_NO_MAP_SAVE] = true; |
2431 | // TODO: if this is a pickable object, then the item |
2410 | // TODO: if this is a pickable object, then the item |
2432 | // will at a bit weird - saving inside the player |
2411 | // will at a bit weird - saving inside the player |
2433 | // will clear the flag, but when the player drops |
2412 | // will clear the flag, but when the player drops |
2434 | // it without logging out, it keeps the flag. |
2413 | // it without logging out, it keeps the flag. |
2435 | // nobody ahs reported this, but this can be rather |
2414 | // nobody has reported this, but this can be rather |
2436 | // annoying on persistent maps. |
2415 | // annoying on persistent maps. |
2437 | } |
2416 | } |
2438 | } |
2417 | } |
2439 | } |
2418 | } |
2440 | } |
2419 | } |
2441 | |
|
|
2442 | skip: ; |
2420 | skip: ; |
2443 | } |
2421 | } |
2444 | } |
2422 | } |
2445 | |
2423 | |
2446 | void |
2424 | void |
… | |
… | |
2477 | for (int x = 0; x < THIS->width; ++x) |
2455 | for (int x = 0; x < THIS->width; ++x) |
2478 | for (int y = 0; y < THIS->height; ++y) |
2456 | for (int y = 0; y < THIS->height; ++y) |
2479 | { |
2457 | { |
2480 | region *rgn = THIS->region (x, y); |
2458 | region *rgn = THIS->region (x, y); |
2481 | |
2459 | |
2482 | //fprintf (stderr, "%d,%d %f %p\n", x, y, rgn->treasure_density,rgn->treasure);//D |
|
|
2483 | if (object *op = THIS->at (x, y).top) |
2460 | if (object *op = THIS->at (x, y).top) |
2484 | if (rgn->treasure && rndm () < rgn->treasure_density) |
2461 | if (rgn->treasure && rndm () < rgn->treasure_density) |
2485 | create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); |
2462 | create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); |
2486 | } |
2463 | } |
2487 | |
2464 | |