--- deliantra/server/server/cfperl.xs 2007/02/15 03:19:02 1.168 +++ deliantra/server/server/cfperl.xs 2007/04/27 02:23:07 1.196 @@ -6,7 +6,7 @@ * This code is placed under the GNU General Public Licence (GPL) * * Copyright (C) 2001-2005 by Chachkoff Yann - * Copyright (C) 2006 by Marc Lehmann + * Copyright (C) 2006,2007 by Marc Lehmann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,6 +26,8 @@ #define PLUGIN_NAME "perl" #define PLUGIN_VERSION "cfperl 0.5" +#define CEDES_PER_TICK 5 + #include #include #include @@ -52,6 +54,13 @@ typedef object object_ornull; typedef maptile maptile_ornull; +typedef char *octet_string; +typedef char *utf8_string; +typedef const char *const_octet_string; +typedef const char *const_utf8_string; + +typedef std::string std__string; + #if IVSIZE >= 8 typedef IV val64; # define newSVval64 newSViv @@ -72,7 +81,7 @@ global gbl_ev; static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; -static SV *sv_runtime; +static SV *sv_runtime, *sv_next_tick; static HV *stash_cf, @@ -129,7 +138,6 @@ // self *must* be null now because thats sv_unmagic's job. assert (!this->self); - flags |= 0x80; // severed //D } } @@ -139,7 +147,6 @@ if (self && SvREFCNT (self) == 1 && !HvTOTALKEYS (self)) - flags |= 0x40,//D sever_self (); } @@ -167,7 +174,6 @@ if (self) sever_self (); - flags |= 0x20; //D mortals.push_back (this); } @@ -202,10 +208,8 @@ obj->refcnt_chk (); // unborrow from perl, if necessary - //if (obj->refcnt > 0 || obj->self) if (obj->refcnt || obj->self) { -//printf ("%p rc %d\n", obj, obj->refcnt_cnt ());//D ++i; // further delay freeing if (!(i & 0x3ff)) @@ -272,9 +276,6 @@ { obj->self = newHV (); sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); - obj->flags |= (obj->flags & 0xc0) << 8; - obj->flags &= ~0xc0;//D - obj->flags |= 0x10;//D // now bless the object _once_ return sv_bless (newRV_inc ((SV *)obj->self), stash); @@ -350,8 +351,8 @@ inline SV *to_sv (object & v) { return to_sv (&v); } inline SV *to_sv (living & v) { return to_sv (&v); } -inline SV *to_sv (facetile * v) { return to_sv (v->name); } -inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } +inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } +inline SV *to_sv (const treasurelist *v) { return to_sv (v->name); } inline SV *to_sv (UUID v) { @@ -385,8 +386,8 @@ inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); } inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } -inline void sv_to (SV *sv, facetile * &v) { v = &new_faces[FindFace (SvPV_nolen (sv), 0)]; } -inline void sv_to (SV *sv, treasurelist * &v) { v = find_treasurelist (SvPV_nolen (sv)); } +//inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } +inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } template inline void sv_to (SV *sv, refptr &v) { T *tmp; sv_to (sv, tmp); v = tmp; } @@ -400,6 +401,13 @@ inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); } inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); } +inline void sv_to (SV *sv, std::string &v) +{ + STRLEN len; + char *data = SvPVbyte (sv, len); + v.assign (data, len); +} + inline void sv_to (SV *sv, UUID &v) { unsigned int version; @@ -599,7 +607,7 @@ PL_exit_flags |= PERL_EXIT_DESTRUCT_END; - char *argv[] = { + const char *argv[] = { "", "-e" "use Event; use Coro;" // required for bootstrap @@ -608,7 +616,8 @@ "require cf;" }; - if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) + if (perl_parse (perl, xs_init, 2, (char **)argv, (char **)NULL) + || perl_run (perl)) { printf ("unable to initialize perl-interpreter, aborting.\n"); exit (EXIT_FAILURE); @@ -937,8 +946,53 @@ struct CoroAPI *coroapi::GCoroAPI; int coroapi::cede_counter; +double (*coroapi::time)(); +double coroapi::next_cede; + +void coroapi::do_cede_to_tick () +{ + cede_counter = 0; + + cede (); + + next_cede += (TICK / CEDES_PER_TICK) * 0.99; + if (next_cede > SvNV (sv_next_tick) - 0.02) + next_cede = SvNV (sv_next_tick); +} -static void iw_dispatch (pe_event *ev) +void coroapi::do_cede_every () +{ + cede_counter = 0; + + if (coroapi::nready ()) + coroapi::cede (); +} + +void coroapi::do_cede_to_tick_every () +{ + cede_counter = 0; + + cede_to_tick (); +} + +void +coroapi::wait_for_tick () +{ + CALL_BEGIN (0); + CALL_CALL ("cf::wait_for_tick", G_DISCARD); + CALL_END; +} + +void +coroapi::wait_for_tick_begin () +{ + CALL_BEGIN (0); + CALL_CALL ("cf::wait_for_tick_begin", G_DISCARD); + CALL_END; +} + +static void +iw_dispatch (pe_event *ev) { iw *w = (iw *)ev->ext_data; w->call (*w); @@ -1011,8 +1065,8 @@ stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); - sv_runtime = get_sv ("cf::RUNTIME", 1); - sv_upgrade (sv_runtime, SVt_NV); + sv_runtime = get_sv ("cf::RUNTIME" , 1); sv_upgrade (sv_runtime , SVt_NV); + sv_next_tick = get_sv ("cf::NEXT_TICK", 1); sv_upgrade (sv_next_tick, SVt_NV); cb_global = get_av ("cf::CB_GLOBAL", 1); cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); @@ -1027,529 +1081,200 @@ BOOT: { - _connect_to_perl (); - I_EVENT_API (PACKAGE); watcher_base::GEventAPI = GEventAPI; I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI; + _connect_to_perl (); + newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); + { + require_pv ("Time::HiRes"); + + SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0); + if (!svp) croak ("Time::HiRes is required"); + if (!SvIOK(*svp)) croak ("Time::NVtime isn’t a function pointer"); + coroapi::time = INT2PTR (double(*)(), SvIV(*svp)); + } + static const struct { const char *name; IV iv; } *civ, const_iv[] = { # define const_iv(name) { # name, (IV)name }, - const_iv (llevError) - const_iv (llevInfo) - const_iv (llevDebug) - const_iv (llevMonster) + const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster) + + const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) + + const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) const_iv (MAX_TIME) - const_iv (PLAYER) - const_iv (TRANSPORT) - const_iv (ROD) - const_iv (TREASURE) - const_iv (POTION) - const_iv (FOOD) - const_iv (POISON) - const_iv (BOOK) - const_iv (CLOCK) - const_iv (ARROW) - const_iv (BOW) - const_iv (WEAPON) - const_iv (ARMOUR) - const_iv (PEDESTAL) - const_iv (ALTAR) - const_iv (LOCKED_DOOR) - const_iv (SPECIAL_KEY) - const_iv (MAP) - const_iv (DOOR) - const_iv (KEY) - const_iv (TIMED_GATE) - const_iv (TRIGGER) - const_iv (GRIMREAPER) - const_iv (MAGIC_EAR) - const_iv (TRIGGER_BUTTON) - const_iv (TRIGGER_ALTAR) - const_iv (TRIGGER_PEDESTAL) - const_iv (SHIELD) - const_iv (HELMET) - const_iv (HORN) - const_iv (MONEY) - const_iv (CLASS) - const_iv (GRAVESTONE) - const_iv (AMULET) - const_iv (PLAYERMOVER) - const_iv (TELEPORTER) - const_iv (CREATOR) - const_iv (SKILL) - const_iv (EARTHWALL) - const_iv (GOLEM) - const_iv (THROWN_OBJ) - const_iv (BLINDNESS) - const_iv (GOD) - const_iv (DETECTOR) - const_iv (TRIGGER_MARKER) - const_iv (DEAD_OBJECT) - const_iv (DRINK) - const_iv (MARKER) - const_iv (HOLY_ALTAR) - const_iv (PLAYER_CHANGER) - const_iv (BATTLEGROUND) - const_iv (PEACEMAKER) - const_iv (GEM) - const_iv (FIREWALL) - const_iv (ANVIL) - const_iv (CHECK_INV) - const_iv (MOOD_FLOOR) - const_iv (EXIT) - const_iv (ENCOUNTER) - const_iv (SHOP_FLOOR) - const_iv (SHOP_MAT) - const_iv (RING) - const_iv (FLOOR) - const_iv (FLESH) - const_iv (INORGANIC) - const_iv (SKILL_TOOL) - const_iv (LIGHTER) - const_iv (BUILDABLE_WALL) - const_iv (MISC_OBJECT) - const_iv (LAMP) - const_iv (DUPLICATOR) - const_iv (SPELLBOOK) - const_iv (CLOAK) - const_iv (SPINNER) - const_iv (GATE) - const_iv (BUTTON) - const_iv (CF_HANDLE) - const_iv (HOLE) - const_iv (TRAPDOOR) - const_iv (SIGN) - const_iv (BOOTS) - const_iv (GLOVES) - const_iv (SPELL) - const_iv (SPELL_EFFECT) - const_iv (CONVERTER) - const_iv (BRACERS) - const_iv (POISONING) - const_iv (SAVEBED) - const_iv (WAND) - const_iv (SCROLL) - const_iv (DIRECTOR) - const_iv (GIRDLE) - const_iv (FORCE) - const_iv (POTION_EFFECT) - const_iv (EVENT_CONNECTOR) - const_iv (CLOSE_CON) - const_iv (CONTAINER) - const_iv (ARMOUR_IMPROVER) - const_iv (WEAPON_IMPROVER) - const_iv (SKILLSCROLL) - const_iv (DEEP_SWAMP) - const_iv (IDENTIFY_ALTAR) - const_iv (MENU) - const_iv (RUNE) - const_iv (TRAP) - const_iv (POWER_CRYSTAL) - const_iv (CORPSE) - const_iv (DISEASE) - const_iv (SYMPTOM) - const_iv (BUILDER) - const_iv (MATERIAL) - const_iv (ITEM_TRANSFORMER) + + const_iv (PLAYER) const_iv (TRANSPORT) const_iv (ROD) const_iv (TREASURE) + const_iv (POTION) const_iv (FOOD) const_iv (POISON) const_iv (BOOK) + const_iv (CLOCK) const_iv (ARROW) const_iv (BOW) const_iv (WEAPON) + const_iv (ARMOUR) const_iv (PEDESTAL) const_iv (ALTAR) const_iv (LOCKED_DOOR) + const_iv (SPECIAL_KEY) const_iv (MAP) const_iv (DOOR) const_iv (KEY) + const_iv (TIMED_GATE) const_iv (TRIGGER) const_iv (GRIMREAPER) const_iv (MAGIC_EAR) + const_iv (TRIGGER_BUTTON) const_iv (TRIGGER_ALTAR) const_iv (TRIGGER_PEDESTAL) const_iv (SHIELD) + const_iv (HELMET) const_iv (HORN) const_iv (MONEY) const_iv (CLASS) + const_iv (GRAVESTONE) const_iv (AMULET) const_iv (PLAYERMOVER) const_iv (TELEPORTER) + const_iv (CREATOR) const_iv (SKILL) const_iv (EARTHWALL) const_iv (GOLEM) + const_iv (THROWN_OBJ) const_iv (BLINDNESS) const_iv (GOD) const_iv (DETECTOR) + const_iv (TRIGGER_MARKER) const_iv (DEAD_OBJECT) const_iv (DRINK) const_iv (MARKER) + const_iv (HOLY_ALTAR) const_iv (PLAYER_CHANGER) const_iv (BATTLEGROUND) const_iv (PEACEMAKER) + const_iv (GEM) const_iv (FIREWALL) const_iv (ANVIL) const_iv (CHECK_INV) + const_iv (MOOD_FLOOR) const_iv (EXIT) const_iv (ENCOUNTER) const_iv (SHOP_FLOOR) + const_iv (SHOP_MAT) const_iv (RING) const_iv (FLOOR) const_iv (FLESH) + const_iv (INORGANIC) const_iv (SKILL_TOOL) const_iv (LIGHTER) const_iv (BUILDABLE_WALL) + const_iv (MISC_OBJECT) const_iv (LAMP) const_iv (DUPLICATOR) const_iv (SPELLBOOK) + const_iv (CLOAK) const_iv (SPINNER) const_iv (GATE) const_iv (BUTTON) + const_iv (CF_HANDLE) const_iv (HOLE) const_iv (TRAPDOOR) const_iv (SIGN) + const_iv (BOOTS) const_iv (GLOVES) const_iv (SPELL) const_iv (SPELL_EFFECT) + const_iv (CONVERTER) const_iv (BRACERS) const_iv (POISONING) const_iv (SAVEBED) + const_iv (WAND) const_iv (SCROLL) const_iv (DIRECTOR) const_iv (GIRDLE) + const_iv (FORCE) const_iv (POTION_EFFECT) const_iv (EVENT_CONNECTOR) const_iv (CLOSE_CON) + const_iv (CONTAINER) const_iv (ARMOUR_IMPROVER) const_iv (WEAPON_IMPROVER) const_iv (SKILLSCROLL) + const_iv (DEEP_SWAMP) const_iv (IDENTIFY_ALTAR) const_iv (MENU) const_iv (RUNE) + const_iv (TRAP) const_iv (POWER_CRYSTAL) const_iv (CORPSE) const_iv (DISEASE) + const_iv (SYMPTOM) const_iv (BUILDER) const_iv (MATERIAL) const_iv (ITEM_TRANSFORMER) const_iv (NUM_SUBTYPES) - const_iv (ST_BD_BUILD) - const_iv (ST_BD_REMOVE) + const_iv (ST_BD_BUILD) const_iv (ST_BD_REMOVE) + const_iv (ST_MAT_FLOOR) const_iv (ST_MAT_WALL) const_iv (ST_MAT_ITEM) + + const_iv (AT_PHYSICAL) const_iv (AT_MAGIC) const_iv (AT_FIRE) const_iv (AT_ELECTRICITY) + const_iv (AT_COLD) const_iv (AT_CONFUSION) const_iv (AT_ACID) const_iv (AT_DRAIN) + const_iv (AT_WEAPONMAGIC) const_iv (AT_GHOSTHIT) const_iv (AT_POISON) const_iv (AT_SLOW) + const_iv (AT_PARALYZE) const_iv (AT_TURN_UNDEAD) const_iv (AT_FEAR) const_iv (AT_CANCELLATION) + const_iv (AT_DEPLETE) const_iv (AT_DEATH) const_iv (AT_CHAOS) const_iv (AT_COUNTERSPELL) + const_iv (AT_GODPOWER) const_iv (AT_HOLYWORD) const_iv (AT_BLIND) const_iv (AT_INTERNAL) + const_iv (AT_LIFE_STEALING) const_iv (AT_DISEASE) - const_iv (ST_MAT_FLOOR) - const_iv (ST_MAT_WALL) - const_iv (ST_MAT_ITEM) - - const_iv (AT_PHYSICAL) - const_iv (AT_MAGIC) - const_iv (AT_FIRE) - const_iv (AT_ELECTRICITY) - const_iv (AT_COLD) - const_iv (AT_CONFUSION) - const_iv (AT_ACID) - const_iv (AT_DRAIN) - const_iv (AT_WEAPONMAGIC) - const_iv (AT_GHOSTHIT) - const_iv (AT_POISON) - const_iv (AT_SLOW) - const_iv (AT_PARALYZE) - const_iv (AT_TURN_UNDEAD) - const_iv (AT_FEAR) - const_iv (AT_CANCELLATION) - const_iv (AT_DEPLETE) - const_iv (AT_DEATH) - const_iv (AT_CHAOS) - const_iv (AT_COUNTERSPELL) - const_iv (AT_GODPOWER) - const_iv (AT_HOLYWORD) - const_iv (AT_BLIND) - const_iv (AT_INTERNAL) - const_iv (AT_LIFE_STEALING) - const_iv (AT_DISEASE) - - const_iv (WEAP_HIT) - const_iv (WEAP_SLASH) - const_iv (WEAP_PIERCE) - const_iv (WEAP_CLEAVE) - const_iv (WEAP_SLICE) - const_iv (WEAP_STAB) - const_iv (WEAP_WHIP) - const_iv (WEAP_CRUSH) + const_iv (WEAP_HIT) const_iv (WEAP_SLASH) const_iv (WEAP_PIERCE) const_iv (WEAP_CLEAVE) + const_iv (WEAP_SLICE) const_iv (WEAP_STAB) const_iv (WEAP_WHIP) const_iv (WEAP_CRUSH) const_iv (WEAP_BLUD) - const_iv (FLAG_ALIVE) - const_iv (FLAG_WIZ) - const_iv (FLAG_REMOVED) - const_iv (FLAG_FREED) - const_iv (FLAG_WAS_WIZ) - const_iv (FLAG_APPLIED) - const_iv (FLAG_UNPAID) - const_iv (FLAG_USE_SHIELD) - const_iv (FLAG_NO_PICK) - const_iv (FLAG_ANIMATE) - const_iv (FLAG_MONSTER) - const_iv (FLAG_FRIENDLY) - const_iv (FLAG_GENERATOR) - const_iv (FLAG_IS_THROWN) - const_iv (FLAG_AUTO_APPLY) - const_iv (FLAG_PLAYER_SOLD) - const_iv (FLAG_SEE_INVISIBLE) - const_iv (FLAG_CAN_ROLL) - const_iv (FLAG_OVERLAY_FLOOR) - const_iv (FLAG_IS_TURNABLE) - const_iv (FLAG_IS_USED_UP) - const_iv (FLAG_IDENTIFIED) - const_iv (FLAG_REFLECTING) - const_iv (FLAG_CHANGING) - const_iv (FLAG_SPLITTING) - const_iv (FLAG_HITBACK) - const_iv (FLAG_STARTEQUIP) - const_iv (FLAG_BLOCKSVIEW) - const_iv (FLAG_UNDEAD) - const_iv (FLAG_SCARED) - const_iv (FLAG_UNAGGRESSIVE) - const_iv (FLAG_REFL_MISSILE) - const_iv (FLAG_REFL_SPELL) - const_iv (FLAG_NO_MAGIC) - const_iv (FLAG_NO_FIX_PLAYER) - const_iv (FLAG_IS_LIGHTABLE) - const_iv (FLAG_TEAR_DOWN) - const_iv (FLAG_RUN_AWAY) - const_iv (FLAG_PICK_UP) - const_iv (FLAG_UNIQUE) - const_iv (FLAG_NO_DROP) - const_iv (FLAG_WIZCAST) - const_iv (FLAG_CAST_SPELL) - const_iv (FLAG_USE_SCROLL) - const_iv (FLAG_USE_RANGE) - const_iv (FLAG_USE_BOW) - const_iv (FLAG_USE_ARMOUR) - const_iv (FLAG_USE_WEAPON) - const_iv (FLAG_USE_RING) - const_iv (FLAG_READY_RANGE) - const_iv (FLAG_READY_BOW) - const_iv (FLAG_XRAYS) - const_iv (FLAG_NO_APPLY) - const_iv (FLAG_IS_FLOOR) - const_iv (FLAG_LIFESAVE) - const_iv (FLAG_NO_STRENGTH) - const_iv (FLAG_SLEEP) - const_iv (FLAG_STAND_STILL) - const_iv (FLAG_RANDOM_MOVE) - const_iv (FLAG_ONLY_ATTACK) - const_iv (FLAG_CONFUSED) - const_iv (FLAG_STEALTH) - const_iv (FLAG_WIZPASS) - const_iv (FLAG_IS_LINKED) - const_iv (FLAG_CURSED) - const_iv (FLAG_DAMNED) - const_iv (FLAG_SEE_ANYWHERE) - const_iv (FLAG_KNOWN_MAGICAL) - const_iv (FLAG_KNOWN_CURSED) - const_iv (FLAG_CAN_USE_SKILL) - const_iv (FLAG_BEEN_APPLIED) - const_iv (FLAG_READY_SCROLL) - const_iv (FLAG_USE_ROD) - const_iv (FLAG_USE_HORN) - const_iv (FLAG_MAKE_INVIS) - const_iv (FLAG_INV_LOCKED) - const_iv (FLAG_IS_WOODED) - const_iv (FLAG_IS_HILLY) - const_iv (FLAG_READY_SKILL) - const_iv (FLAG_READY_WEAPON) - const_iv (FLAG_NO_SKILL_IDENT) - const_iv (FLAG_BLIND) - const_iv (FLAG_SEE_IN_DARK) - const_iv (FLAG_IS_CAULDRON) - const_iv (FLAG_NO_STEAL) - const_iv (FLAG_ONE_HIT) - const_iv (FLAG_CLIENT_SENT) - const_iv (FLAG_BERSERK) - const_iv (FLAG_NEUTRAL) - const_iv (FLAG_NO_ATTACK) - const_iv (FLAG_NO_DAMAGE) - const_iv (FLAG_OBJ_ORIGINAL) - const_iv (FLAG_OBJ_SAVE_ON_OVL) - const_iv (FLAG_ACTIVATE_ON_PUSH) - const_iv (FLAG_ACTIVATE_ON_RELEASE) - const_iv (FLAG_IS_WATER) - const_iv (FLAG_CONTENT_ON_GEN) - const_iv (FLAG_IS_A_TEMPLATE) - const_iv (FLAG_IS_BUILDABLE) - const_iv (FLAG_DESTROY_ON_DEATH) - const_iv (FLAG_NO_MAP_SAVE) - - const_iv (NDI_BLACK) - const_iv (NDI_WHITE) - const_iv (NDI_NAVY) - const_iv (NDI_RED) - const_iv (NDI_ORANGE) - const_iv (NDI_BLUE) - const_iv (NDI_DK_ORANGE) - const_iv (NDI_GREEN) - const_iv (NDI_LT_GREEN) - const_iv (NDI_GREY) - const_iv (NDI_BROWN) - const_iv (NDI_GOLD) - const_iv (NDI_TAN) - const_iv (NDI_MAX_COLOR) - const_iv (NDI_COLOR_MASK) - const_iv (NDI_UNIQUE) + const_iv (FLAG_ALIVE) const_iv (FLAG_WIZ) const_iv (FLAG_REMOVED) const_iv (FLAG_FREED) + const_iv (FLAG_WAS_WIZ) const_iv (FLAG_APPLIED) const_iv (FLAG_UNPAID) const_iv (FLAG_USE_SHIELD) + const_iv (FLAG_NO_PICK) const_iv (FLAG_ANIMATE) const_iv (FLAG_MONSTER) const_iv (FLAG_FRIENDLY) + const_iv (FLAG_GENERATOR) const_iv (FLAG_IS_THROWN) const_iv (FLAG_AUTO_APPLY) const_iv (FLAG_PLAYER_SOLD) + const_iv (FLAG_SEE_INVISIBLE) const_iv (FLAG_CAN_ROLL) const_iv (FLAG_OVERLAY_FLOOR) const_iv (FLAG_IS_TURNABLE) + const_iv (FLAG_IS_USED_UP) const_iv (FLAG_IDENTIFIED) const_iv (FLAG_REFLECTING) const_iv (FLAG_CHANGING) + const_iv (FLAG_SPLITTING) const_iv (FLAG_HITBACK) const_iv (FLAG_STARTEQUIP) const_iv (FLAG_BLOCKSVIEW) + const_iv (FLAG_UNDEAD) const_iv (FLAG_SCARED) const_iv (FLAG_UNAGGRESSIVE) const_iv (FLAG_REFL_MISSILE) + const_iv (FLAG_REFL_SPELL) const_iv (FLAG_NO_MAGIC) const_iv (FLAG_NO_FIX_PLAYER) const_iv (FLAG_IS_LIGHTABLE) + const_iv (FLAG_TEAR_DOWN) const_iv (FLAG_RUN_AWAY) const_iv (FLAG_PICK_UP) const_iv (FLAG_UNIQUE) + const_iv (FLAG_NO_DROP) const_iv (FLAG_WIZCAST) const_iv (FLAG_CAST_SPELL) const_iv (FLAG_USE_SCROLL) + const_iv (FLAG_USE_RANGE) const_iv (FLAG_USE_BOW) const_iv (FLAG_USE_ARMOUR) const_iv (FLAG_USE_WEAPON) + const_iv (FLAG_USE_RING) const_iv (FLAG_READY_RANGE) const_iv (FLAG_READY_BOW) const_iv (FLAG_XRAYS) + const_iv (FLAG_NO_APPLY) const_iv (FLAG_IS_FLOOR) const_iv (FLAG_LIFESAVE) const_iv (FLAG_NO_STRENGTH) + const_iv (FLAG_SLEEP) const_iv (FLAG_STAND_STILL) const_iv (FLAG_RANDOM_MOVE) const_iv (FLAG_ONLY_ATTACK) + const_iv (FLAG_CONFUSED) const_iv (FLAG_STEALTH) const_iv (FLAG_WIZPASS) const_iv (FLAG_IS_LINKED) + const_iv (FLAG_CURSED) const_iv (FLAG_DAMNED) const_iv (FLAG_SEE_ANYWHERE) const_iv (FLAG_KNOWN_MAGICAL) + const_iv (FLAG_KNOWN_CURSED) const_iv (FLAG_CAN_USE_SKILL) const_iv (FLAG_BEEN_APPLIED) const_iv (FLAG_READY_SCROLL) + const_iv (FLAG_USE_ROD) const_iv (FLAG_USE_HORN) const_iv (FLAG_MAKE_INVIS) const_iv (FLAG_INV_LOCKED) + const_iv (FLAG_IS_WOODED) const_iv (FLAG_IS_HILLY) const_iv (FLAG_READY_SKILL) const_iv (FLAG_READY_WEAPON) + const_iv (FLAG_NO_SKILL_IDENT) const_iv (FLAG_BLIND) const_iv (FLAG_SEE_IN_DARK) const_iv (FLAG_IS_CAULDRON) + const_iv (FLAG_NO_STEAL) const_iv (FLAG_ONE_HIT) const_iv (FLAG_CLIENT_SENT) const_iv (FLAG_BERSERK) + const_iv (FLAG_NEUTRAL) const_iv (FLAG_NO_ATTACK) const_iv (FLAG_NO_DAMAGE) const_iv (FLAG_OBJ_ORIGINAL) + const_iv (FLAG_OBJ_SAVE_ON_OVL) const_iv (FLAG_ACTIVATE_ON_PUSH) const_iv (FLAG_ACTIVATE_ON_RELEASE) const_iv (FLAG_IS_WATER) + const_iv (FLAG_CONTENT_ON_GEN) const_iv (FLAG_IS_A_TEMPLATE) const_iv (FLAG_IS_BUILDABLE) + const_iv (FLAG_DESTROY_ON_DEATH) const_iv (FLAG_NO_MAP_SAVE) + + const_iv (NDI_BLACK) const_iv (NDI_WHITE) const_iv (NDI_NAVY) const_iv (NDI_RED) + const_iv (NDI_ORANGE) const_iv (NDI_BLUE) const_iv (NDI_DK_ORANGE) const_iv (NDI_GREEN) + const_iv (NDI_LT_GREEN) const_iv (NDI_GREY) const_iv (NDI_BROWN) const_iv (NDI_GOLD) + const_iv (NDI_TAN) const_iv (NDI_MAX_COLOR) const_iv (NDI_COLOR_MASK) const_iv (NDI_UNIQUE) const_iv (NDI_ALL) - const_iv (UPD_LOCATION) - const_iv (UPD_FLAGS) - const_iv (UPD_WEIGHT) - const_iv (UPD_FACE) - const_iv (UPD_NAME) - const_iv (UPD_ANIM) - const_iv (UPD_ANIMSPEED) - const_iv (UPD_NROF) - - const_iv (UPD_SP_MANA) - const_iv (UPD_SP_GRACE) - const_iv (UPD_SP_DAMAGE) - - const_iv (F_APPLIED) - const_iv (F_LOCATION) - const_iv (F_UNPAID) - const_iv (F_MAGIC) - const_iv (F_CURSED) - const_iv (F_DAMNED) - const_iv (F_OPEN) - const_iv (F_NOPICK) + const_iv (UPD_LOCATION) const_iv (UPD_FLAGS) const_iv (UPD_WEIGHT) const_iv (UPD_FACE) + const_iv (UPD_NAME) const_iv (UPD_ANIM) const_iv (UPD_ANIMSPEED) const_iv (UPD_NROF) + + const_iv (UPD_SP_MANA) const_iv (UPD_SP_GRACE) const_iv (UPD_SP_DAMAGE) + + const_iv (F_APPLIED) const_iv (F_LOCATION) const_iv (F_UNPAID) const_iv (F_MAGIC) + const_iv (F_CURSED) const_iv (F_DAMNED) const_iv (F_OPEN) const_iv (F_NOPICK) const_iv (F_LOCKED) - const_iv (F_BUY) - const_iv (F_SHOP) - const_iv (F_SELL) - - const_iv (P_BLOCKSVIEW) - const_iv (P_PLAYER) - const_iv (P_NO_MAGIC) - const_iv (P_IS_ALIVE) - const_iv (P_NO_CLERIC) - const_iv (P_OUT_OF_MAP) - const_iv (P_NEW_MAP) - const_iv (P_UPTODATE) - - const_iv (UP_OBJ_INSERT) - const_iv (UP_OBJ_REMOVE) - const_iv (UP_OBJ_CHANGE) - const_iv (UP_OBJ_FACE) - - const_iv (INS_NO_MERGE) - const_iv (INS_ABOVE_FLOOR_ONLY) - const_iv (INS_NO_WALK_ON) - const_iv (INS_ON_TOP) - const_iv (INS_BELOW_ORIGINATOR) - const_iv (INS_MAP_LOAD) - - const_iv (WILL_APPLY_HANDLE) - const_iv (WILL_APPLY_TREASURE) - const_iv (WILL_APPLY_EARTHWALL) - const_iv (WILL_APPLY_DOOR) - const_iv (WILL_APPLY_FOOD) - - const_iv (SAVE_MODE) - const_iv (SAVE_DIR_MODE) - - const_iv (M_PAPER) - const_iv (M_IRON) - const_iv (M_GLASS) - const_iv (M_LEATHER) - const_iv (M_WOOD) - const_iv (M_ORGANIC) - const_iv (M_STONE) - const_iv (M_CLOTH) - const_iv (M_ADAMANT) - const_iv (M_LIQUID) - const_iv (M_SOFT_METAL) - const_iv (M_BONE) - const_iv (M_ICE) - const_iv (M_SPECIAL) - - const_iv (SK_EXP_ADD_SKILL) - const_iv (SK_EXP_TOTAL) - const_iv (SK_EXP_NONE) - const_iv (SK_SUBTRACT_SKILL_EXP) - const_iv (SK_EXP_SKILL_ONLY) - - const_iv (SK_LOCKPICKING) - const_iv (SK_HIDING) - const_iv (SK_SMITHERY) - const_iv (SK_BOWYER) - const_iv (SK_JEWELER) - const_iv (SK_ALCHEMY) - const_iv (SK_STEALING) - const_iv (SK_LITERACY) - const_iv (SK_BARGAINING) - const_iv (SK_JUMPING) - const_iv (SK_DET_MAGIC) - const_iv (SK_ORATORY) - const_iv (SK_SINGING) - const_iv (SK_DET_CURSE) - const_iv (SK_FIND_TRAPS) - const_iv (SK_MEDITATION) - const_iv (SK_PUNCHING) - const_iv (SK_FLAME_TOUCH) - const_iv (SK_KARATE) - const_iv (SK_CLIMBING) - const_iv (SK_WOODSMAN) - const_iv (SK_INSCRIPTION) - const_iv (SK_ONE_HANDED_WEAPON) - const_iv (SK_MISSILE_WEAPON) - const_iv (SK_THROWING) - const_iv (SK_USE_MAGIC_ITEM) - const_iv (SK_DISARM_TRAPS) - const_iv (SK_SET_TRAP) - const_iv (SK_THAUMATURGY) - const_iv (SK_PRAYING) - const_iv (SK_CLAWING) - const_iv (SK_LEVITATION) - const_iv (SK_SUMMONING) - const_iv (SK_PYROMANCY) - const_iv (SK_EVOCATION) - const_iv (SK_SORCERY) - const_iv (SK_TWO_HANDED_WEAPON) - const_iv (SK_SPARK_TOUCH) - const_iv (SK_SHIVER) - const_iv (SK_ACID_SPLASH) + const_iv (F_BUY) const_iv (F_SHOP) const_iv (F_SELL) + + const_iv (P_BLOCKSVIEW) const_iv (P_PLAYER) const_iv (P_NO_MAGIC) const_iv (P_IS_ALIVE) + const_iv (P_NO_CLERIC) const_iv (P_OUT_OF_MAP) const_iv (P_NEW_MAP) const_iv (P_UPTODATE) + + const_iv (UP_OBJ_INSERT) const_iv (UP_OBJ_REMOVE) const_iv (UP_OBJ_CHANGE) const_iv (UP_OBJ_FACE) + + const_iv (INS_NO_MERGE) const_iv (INS_ABOVE_FLOOR_ONLY) const_iv (INS_NO_WALK_ON) + const_iv (INS_ON_TOP) const_iv (INS_BELOW_ORIGINATOR) const_iv (INS_MAP_LOAD) + + const_iv (WILL_APPLY_HANDLE) const_iv (WILL_APPLY_TREASURE) const_iv (WILL_APPLY_EARTHWALL) + const_iv (WILL_APPLY_DOOR) const_iv (WILL_APPLY_FOOD) + + const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) + + const_iv (M_PAPER) const_iv (M_IRON) const_iv (M_GLASS) const_iv (M_LEATHER) + const_iv (M_WOOD) const_iv (M_ORGANIC) const_iv (M_STONE) const_iv (M_CLOTH) + const_iv (M_ADAMANT) const_iv (M_LIQUID) const_iv (M_SOFT_METAL) const_iv (M_BONE) + const_iv (M_ICE) const_iv (M_SPECIAL) + + const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE) + const_iv (SK_SUBTRACT_SKILL_EXP) const_iv (SK_EXP_SKILL_ONLY) + + const_iv (SK_LOCKPICKING) const_iv (SK_HIDING) const_iv (SK_SMITHERY) const_iv (SK_BOWYER) + const_iv (SK_JEWELER) const_iv (SK_ALCHEMY) const_iv (SK_STEALING) const_iv (SK_LITERACY) + const_iv (SK_BARGAINING) const_iv (SK_JUMPING) const_iv (SK_DET_MAGIC) const_iv (SK_ORATORY) + const_iv (SK_SINGING) const_iv (SK_DET_CURSE) const_iv (SK_FIND_TRAPS) const_iv (SK_MEDITATION) + const_iv (SK_PUNCHING) const_iv (SK_FLAME_TOUCH) const_iv (SK_KARATE) const_iv (SK_CLIMBING) + const_iv (SK_WOODSMAN) const_iv (SK_INSCRIPTION) const_iv (SK_ONE_HANDED_WEAPON) const_iv (SK_MISSILE_WEAPON) + const_iv (SK_THROWING) const_iv (SK_USE_MAGIC_ITEM) const_iv (SK_DISARM_TRAPS) const_iv (SK_SET_TRAP) + const_iv (SK_THAUMATURGY) const_iv (SK_PRAYING) const_iv (SK_CLAWING) const_iv (SK_LEVITATION) + const_iv (SK_SUMMONING) const_iv (SK_PYROMANCY) const_iv (SK_EVOCATION) const_iv (SK_SORCERY) + const_iv (SK_TWO_HANDED_WEAPON) const_iv (SK_SPARK_TOUCH) const_iv (SK_SHIVER) const_iv (SK_ACID_SPLASH) const_iv (SK_POISON_NAIL) - const_iv (SOUND_NEW_PLAYER) - const_iv (SOUND_FIRE_ARROW) - const_iv (SOUND_LEARN_SPELL) - const_iv (SOUND_FUMBLE_SPELL) - const_iv (SOUND_WAND_POOF) - const_iv (SOUND_OPEN_DOOR) - const_iv (SOUND_PUSH_PLAYER) - const_iv (SOUND_PLAYER_HITS1) - const_iv (SOUND_PLAYER_HITS2) - const_iv (SOUND_PLAYER_HITS3) - const_iv (SOUND_PLAYER_HITS4) - const_iv (SOUND_PLAYER_IS_HIT1) - const_iv (SOUND_PLAYER_IS_HIT2) - const_iv (SOUND_PLAYER_IS_HIT3) - const_iv (SOUND_PLAYER_KILLS) - const_iv (SOUND_PET_IS_KILLED) - const_iv (SOUND_PLAYER_DIES) - const_iv (SOUND_OB_EVAPORATE) - const_iv (SOUND_OB_EXPLODE) - const_iv (SOUND_CLOCK) - const_iv (SOUND_TURN_HANDLE) - const_iv (SOUND_FALL_HOLE) - const_iv (SOUND_DRINK_POISON) - const_iv (SOUND_CAST_SPELL_0) - - const_iv (PREFER_LOW) - const_iv (PREFER_HIGH) - - const_iv (ATNR_PHYSICAL) - const_iv (ATNR_MAGIC) - const_iv (ATNR_FIRE) - const_iv (ATNR_ELECTRICITY) - const_iv (ATNR_COLD) - const_iv (ATNR_CONFUSION) - const_iv (ATNR_ACID) - const_iv (ATNR_DRAIN) - const_iv (ATNR_WEAPONMAGIC) - const_iv (ATNR_GHOSTHIT) - const_iv (ATNR_POISON) - const_iv (ATNR_SLOW) - const_iv (ATNR_PARALYZE) - const_iv (ATNR_TURN_UNDEAD) - const_iv (ATNR_FEAR) - const_iv (ATNR_CANCELLATION) - const_iv (ATNR_DEPLETE) - const_iv (ATNR_DEATH) - const_iv (ATNR_CHAOS) - const_iv (ATNR_COUNTERSPELL) - const_iv (ATNR_GODPOWER) - const_iv (ATNR_HOLYWORD) - const_iv (ATNR_BLIND) - const_iv (ATNR_INTERNAL) - const_iv (ATNR_LIFE_STEALING) - const_iv (ATNR_DISEASE) - - const_iv (MAP_IN_MEMORY) - const_iv (MAP_SWAPPED) - const_iv (MAP_LOADING) - const_iv (MAP_SAVING) - - const_iv (KLASS_ATTACHABLE) - const_iv (KLASS_GLOBAL) - const_iv (KLASS_OBJECT) - const_iv (KLASS_CLIENT) - const_iv (KLASS_PLAYER) - const_iv (KLASS_MAP) - - const_iv (CS_QUERY_YESNO) - const_iv (CS_QUERY_SINGLECHAR) - const_iv (CS_QUERY_HIDEINPUT) - - const_iv (ST_DEAD) - const_iv (ST_SETUP) - const_iv (ST_PLAYING) - const_iv (ST_CUSTOM) - - const_iv (ST_CHANGE_CLASS) - - const_iv (IO_HEADER) - const_iv (IO_OBJECTS) - const_iv (IO_UNIQUES) + const_iv (SOUND_NEW_PLAYER) const_iv (SOUND_FIRE_ARROW) const_iv (SOUND_LEARN_SPELL) const_iv (SOUND_FUMBLE_SPELL) + const_iv (SOUND_WAND_POOF) const_iv (SOUND_OPEN_DOOR) const_iv (SOUND_PUSH_PLAYER) const_iv (SOUND_PLAYER_HITS1) + const_iv (SOUND_PLAYER_HITS2) const_iv (SOUND_PLAYER_HITS3) const_iv (SOUND_PLAYER_HITS4) const_iv (SOUND_PLAYER_IS_HIT1) + const_iv (SOUND_PLAYER_IS_HIT2) const_iv (SOUND_PLAYER_IS_HIT3) const_iv (SOUND_PLAYER_KILLS) const_iv (SOUND_PET_IS_KILLED) + const_iv (SOUND_PLAYER_DIES) const_iv (SOUND_OB_EVAPORATE) const_iv (SOUND_OB_EXPLODE) const_iv (SOUND_CLOCK) + const_iv (SOUND_TURN_HANDLE) const_iv (SOUND_FALL_HOLE) const_iv (SOUND_DRINK_POISON) const_iv (SOUND_CAST_SPELL_0) + + const_iv (PREFER_LOW) const_iv (PREFER_HIGH) + + const_iv (ATNR_PHYSICAL) const_iv (ATNR_MAGIC) const_iv (ATNR_FIRE) const_iv (ATNR_ELECTRICITY) + const_iv (ATNR_COLD) const_iv (ATNR_CONFUSION) const_iv (ATNR_ACID) const_iv (ATNR_DRAIN) + const_iv (ATNR_WEAPONMAGIC) const_iv (ATNR_GHOSTHIT) const_iv (ATNR_POISON) const_iv (ATNR_SLOW) + const_iv (ATNR_PARALYZE) const_iv (ATNR_TURN_UNDEAD) const_iv (ATNR_FEAR) const_iv (ATNR_CANCELLATION) + const_iv (ATNR_DEPLETE) const_iv (ATNR_DEATH) const_iv (ATNR_CHAOS) const_iv (ATNR_COUNTERSPELL) + const_iv (ATNR_GODPOWER) const_iv (ATNR_HOLYWORD) const_iv (ATNR_BLIND) const_iv (ATNR_INTERNAL) + const_iv (ATNR_LIFE_STEALING) const_iv (ATNR_DISEASE) + + const_iv (MAP_IN_MEMORY) const_iv (MAP_SWAPPED) const_iv (MAP_LOADING) const_iv (MAP_SAVING) + + const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT) + const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP) + + const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) + + const_iv (ST_DEAD) const_iv (ST_SETUP) const_iv (ST_PLAYING) const_iv (ST_CUSTOM) + + const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) // random map generator - const_iv (LAYOUT_NONE) - const_iv (LAYOUT_ONION) - const_iv (LAYOUT_MAZE) - const_iv (LAYOUT_SPIRAL) - const_iv (LAYOUT_ROGUELIKE) - const_iv (LAYOUT_SNAKE) - const_iv (LAYOUT_SQUARE_SPIRAL) - - const_iv (RMOPT_RANDOM) - const_iv (RMOPT_CENTERED) - const_iv (RMOPT_LINEAR) - const_iv (RMOPT_BOTTOM_C) - const_iv (RMOPT_BOTTOM_R) - const_iv (RMOPT_IRR_SPACE) - const_iv (RMOPT_WALL_OFF) - const_iv (RMOPT_WALLS_ONLY) - const_iv (RMOPT_NO_DOORS) - - const_iv (SYMMETRY_RANDOM) - const_iv (SYMMETRY_NONE) - const_iv (SYMMETRY_X) - const_iv (SYMMETRY_Y) - const_iv (SYMMETRY_XY) + const_iv (LAYOUT_NONE) const_iv (LAYOUT_ONION) const_iv (LAYOUT_MAZE) const_iv (LAYOUT_SPIRAL) + const_iv (LAYOUT_ROGUELIKE) const_iv (LAYOUT_SNAKE) const_iv (LAYOUT_SQUARE_SPIRAL) + + const_iv (RMOPT_RANDOM) const_iv (RMOPT_CENTERED) const_iv (RMOPT_LINEAR) + const_iv (RMOPT_BOTTOM_C) const_iv (RMOPT_BOTTOM_R) const_iv (RMOPT_IRR_SPACE) + const_iv (RMOPT_WALL_OFF) const_iv (RMOPT_WALLS_ONLY) const_iv (RMOPT_NO_DOORS) + + const_iv (SYMMETRY_RANDOM) const_iv (SYMMETRY_NONE) const_iv (SYMMETRY_X) + const_iv (SYMMETRY_Y) const_iv (SYMMETRY_XY) + + const_iv (GT_ENVIRONMENT) const_iv (GT_INVISIBLE) const_iv (GT_STARTEQUIP) + const_iv (GT_APPLY) const_iv (GT_ONLY_GOOD) const_iv (GT_UPDATE_INV) + const_iv (GT_MINIMAL) }; for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) @@ -1587,17 +1312,56 @@ for_all_clients (ns) ns->reattach (); - for_all_players (pl) - pl->reattach (); - - //TODO - //for (map_container::iterator i = maps.begin (); i != maps.end (); ++i) - // i->second->reattach (); - for_all_objects (op) op->reattach (); } +void _post_tick () + CODE: + coroapi::next_cede = SvNV (sv_next_tick) - TICK * (1. - 1. / CEDES_PER_TICK); + +# support function for map-world.ext +void _quantise (SV *data_sv, SV *plt_sv) + CODE: +{ + if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV) + croak ("_quantise called with invalid agruments"); + + plt_sv = SvRV (plt_sv); + SV **plt = AvARRAY (plt_sv); + int plt_count = AvFILL (plt_sv) + 1; + + STRLEN len; + char *data = SvPVbyte (data_sv, len); + char *dst = data; + + while (len >= 3) + { + for (SV **val_sv = plt + plt_count; val_sv-- > plt; ) + { + char *val = SvPVX (*val_sv); + + if (val [0] == data [0] + && val [1] == data [1] + && val [2] == data [2]) + { + *dst++ = val [3]; + goto next; + } + } + + croak ("_quantise: color not found in palette: #%02x%02x%02x, at offset %d %d", + (uint8_t)data [0], (uint8_t)data [1], (uint8_t)data [2], + dst - SvPVX (data_sv), len); + + next: + data += 3; + len -= 3; + } + + SvCUR_set (data_sv, dst - SvPVX (data_sv)); +} + NV floor (NV x) NV ceil (NV x) @@ -1620,18 +1384,18 @@ server_tick (); void -LOG (int level, char *msg) +LOG (int level, utf8_string msg) PROTOTYPE: $$ C_ARGS: (LogLevel)level, "%s", msg -char *path_combine (char *base, char *path) +octet_string path_combine (octet_string base, octet_string path) PROTOTYPE: $$ -char *path_combine_and_normalize (char *base, char *path) +octet_string path_combine_and_normalize (octet_string base, octet_string path) PROTOTYPE: $$ -const char * -get_maps_directory (char *path) +const_octet_string +get_maps_directory (octet_string path) PROTOTYPE: $ ALIAS: maps_directory = 0 CODE: @@ -1643,7 +1407,7 @@ CODE: PL_sub_generation++; -char * +const_octet_string mapdir () PROTOTYPE: ALIAS: @@ -1669,9 +1433,9 @@ void abort () -void fork_abort (char *cause = "cf::fork_abort") +void fork_abort (octet_string cause = "cf::fork_abort") -void cleanup (const char *cause, bool make_core = false) +void cleanup (octet_string cause, bool make_core = false) void emergency_save () @@ -1691,12 +1455,12 @@ #endif -int find_animation (char *text) +int find_animation (utf8_string text) PROTOTYPE: $ int random_roll (int min, int max, object *op, int goodbad); -const char *cost_string_from_value(uint64 cost, int approx = 0) +const_utf8_string cost_string_from_value(uint64 cost, int approx = 0) int exp_to_level (val64 exp) @@ -1738,10 +1502,7 @@ OUTPUT: RETVAL bool -load_regions (const char *filename) - CODE: - RETVAL = loader_region ().load (filename); - OUTPUT: RETVAL +load_resource_file (octet_string filename) MODULE = cf PACKAGE = cf::attachable @@ -1769,7 +1530,7 @@ # RETVAL = index < attachable::mortals.size () ? attachable::mortals [index] : 0; # OUTPUT: RETVAL -INCLUDE: $PERL genacc attachable ../include/cfperl.h | +INCLUDE: $PERL $srcdir/genacc attachable ../include/cfperl.h | MODULE = cf PACKAGE = cf::global @@ -1783,7 +1544,7 @@ MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ -INCLUDE: $PERL genacc object ../include/object.h | +INCLUDE: $PERL $srcdir/genacc object ../include/object.h | int invoke (object *op, int event, ...) CODE: @@ -1850,7 +1611,7 @@ RETVAL = NUM_ANIMATIONS (op); OUTPUT: RETVAL -object *find_best_object_match (object *op, const char *match) +object *find_best_object_match (object *op, utf8_string match) object *find_marked_object (object *op) @@ -1858,6 +1619,12 @@ int apply_shop_mat (object *shop_mat, object *op); +int move_player (object *op, int dir) + CODE: + RETVAL = move_player (op, dir); + OUTPUT: + RETVAL + int move (object *op, int dir, object *originator = op) CODE: RETVAL = move_ob (op, dir, originator); @@ -1874,7 +1641,7 @@ int cast_heal (object *op, object *caster, object *spell, int dir = 0) -object *cf_object_present_archname_inside (object *op, char *whatstr) +object *cf_object_present_archname_inside (object *op, utf8_string whatstr) int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0) @@ -1904,9 +1671,9 @@ void pay_player (object *op, uint64 amount) -val64 pay_player_arch (object *op, const char *arch, uint64 amount) +val64 pay_player_arch (object *op, utf8_string arch, uint64 amount) -int cast_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg = 0) +int cast_spell (object *op, object *caster, int dir, object *spell_ob, utf8_string stringarg = 0) void learn_spell (object *op, object *sp, int special_prayer = 0) CODE: @@ -1916,7 +1683,7 @@ CODE: do_forget_spell (op, query_name (sp)); -object *check_for_spell (object *op, char *spellname) +object *check_for_spell (object *op, utf8_string spellname) CODE: RETVAL = check_spell_known (op, spellname); OUTPUT: RETVAL @@ -1939,9 +1706,9 @@ void update_object (object *op, int action) -object *cf_create_object_by_name (const char *name) +object *cf_create_object_by_name (utf8_string name) -void change_exp (object *op, uint64 exp, const char *skill_name = 0, int flag = 0) +void change_exp (object *op, uint64 exp, utf8_string skill_name = 0, int flag = 0) void player_lvl_adj (object *who, object *skill = 0) @@ -1965,7 +1732,7 @@ # no clean way to get an object from an archetype - stupid idiotic # dumb kludgy misdesigned plug-in api slowly gets on my nerves. -object *new (const char *archetype = 0) +object *new (utf8_string archetype = 0) PROTOTYPE: ;$ CODE: RETVAL = archetype ? get_archetype (archetype) : cf_create_object (); @@ -1980,21 +1747,14 @@ RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); } -# syntatic sugar for easier use in event callbacks. -const char *options (object *op) - CODE: - RETVAL = op->name; - OUTPUT: - RETVAL - player *contr (object *op) CODE: RETVAL = op->contr; OUTPUT: RETVAL -const char *get_ob_key_value (object *op, const char *key) +const_utf8_string get_ob_key_value (object *op, utf8_string key) -bool set_ob_key_value (object *op, const char *key, const char *value = 0, int add_key = 1) +bool set_ob_key_value (object *op, utf8_string key, utf8_string value = 0, int add_key = 1) object *get_nearest_player (object *ob) ALIAS: nearest_player = 0 @@ -2020,7 +1780,7 @@ RETVAL = on_same_map (ob, other); OUTPUT: RETVAL -const char * +const_utf8_string base_name (object *op, int plural = op->nrof > 1) CODE: RETVAL = query_base_name (op, plural); @@ -2037,13 +1797,13 @@ void check_score (object *op) -void message (object *op, char *txt, int flags = NDI_ORANGE | NDI_UNIQUE) +void message (object *op, utf8_string txt, int flags = NDI_ORANGE | NDI_UNIQUE) CODE: new_draw_info (flags, 0, op, txt); object *cf_player_send_inventory (object *op) -char *cf_player_get_ip (object *op) +octet_string cf_player_get_ip (object *op) ALIAS: ip = 0 object *cf_player_get_marked_item (object *op) @@ -2063,18 +1823,14 @@ void clear_los (object *op) -int command_summon (object *op, char *params) - -int command_arrest (object *op, char *params) - -int command_kick (object *op, char *params) +int command_summon (object *op, utf8_string params) -int command_banish (object *op, char *params) +int command_arrest (object *op, utf8_string params) MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ -INCLUDE: $PERL genacc player ../include/player.h | +INCLUDE: $PERL $srcdir/genacc player ../include/player.h | int invoke (player *pl, int event, ...) CODE: @@ -2159,7 +1915,7 @@ SV *registry (maptile *map) -INCLUDE: $PERL genacc maptile ../include/map.h | +INCLUDE: $PERL $srcdir/genacc maptile ../include/map.h | void maptile::instantiate () @@ -2250,6 +2006,31 @@ THIS->regionmap = regionmap; } +void +maptile::create_region_treasure () + CODE: +{ + object *op = object::create (); + op->type = FLOOR; + op->map = THIS; + + for (int x = 0; x < THIS->width; ++x) + for (int y = 0; y < THIS->height; ++y) + { + region *rgn = THIS->region (x, y); + + //fprintf (stderr, "%d,%d %f %p\n", x, y, rgn->treasure_density,rgn->treasure);//D + if (rgn->treasure && rndm () < rgn->treasure_density) + { + op->x = x; + op->y = y; + create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); + } + } + + op->destroy (); +} + void play_sound_map (maptile *map, int x, int y, int sound_num) int out_of_map (maptile *map, int x, int y) @@ -2344,19 +2125,19 @@ bool _create_random_map (\ maptile *self,\ - char *wallstyle,\ - char *wall_name,\ - char *floorstyle,\ - char *monsterstyle,\ - char *treasurestyle,\ - char *layoutstyle,\ - char *doorstyle,\ - char *decorstyle,\ - char *origin_map,\ - char *final_map,\ - char *exitstyle,\ - char *this_map,\ - char *exit_on_final_map,\ + utf8_string wallstyle,\ + utf8_string wall_name,\ + utf8_string floorstyle,\ + utf8_string monsterstyle,\ + utf8_string treasurestyle,\ + utf8_string layoutstyle,\ + utf8_string doorstyle,\ + utf8_string decorstyle,\ + utf8_string origin_map,\ + utf8_string final_map,\ + utf8_string exitstyle,\ + utf8_string this_map,\ + utf8_string exit_on_final_map,\ int xsize,\ int ysize,\ int expand2x,\ @@ -2379,7 +2160,7 @@ int treasureoptions,\ int symmetry_used,\ region *region,\ - char *custom\ + utf8_string custom\ ) CODE: { @@ -2430,7 +2211,7 @@ MODULE = cf PACKAGE = cf::arch -archetype *find (const char *name) +archetype *find (utf8_string name) CODE: RETVAL = archetype::find (name); OUTPUT: @@ -2442,7 +2223,7 @@ RETVAL = first_archetype; OUTPUT: RETVAL -INCLUDE: $PERL genacc archetype ../include/object.h | +INCLUDE: $PERL $srcdir/genacc archetype ../include/object.h | MODULE = cf PACKAGE = cf::party @@ -2452,7 +2233,7 @@ RETVAL = get_firstparty (); OUTPUT: RETVAL -INCLUDE: $PERL genacc partylist ../include/player.h | +INCLUDE: $PERL $srcdir/genacc partylist ../include/player.h | MODULE = cf PACKAGE = cf::region @@ -2462,31 +2243,38 @@ for_all_regions (rgn) XPUSHs (sv_2mortal (to_sv (rgn))); -region *find (char *name) +region *find (utf8_string name) PROTOTYPE: $ CODE: RETVAL = region::find (name); OUTPUT: RETVAL -region *find_fuzzy (char *name) +region *find_fuzzy (utf8_string name) PROTOTYPE: $ CODE: RETVAL = region::find_fuzzy (name); OUTPUT: RETVAL -INCLUDE: $PERL genacc region ../include/map.h | +int specificity (region *rgn) + CODE: + RETVAL = 0; + while (rgn = rgn->parent) + RETVAL++; + OUTPUT: RETVAL + +INCLUDE: $PERL $srcdir/genacc region ../include/region.h | MODULE = cf PACKAGE = cf::living -INCLUDE: $PERL genacc living ../include/living.h | +INCLUDE: $PERL $srcdir/genacc living ../include/living.h | MODULE = cf PACKAGE = cf::settings -INCLUDE: $PERL genacc Settings ../include/global.h | +INCLUDE: $PERL $srcdir/genacc Settings ../include/global.h | MODULE = cf PACKAGE = cf::client -INCLUDE: $PERL genacc client ../include/client.h | +INCLUDE: $PERL $srcdir/genacc client ../include/client.h | int invoke (client *ns, int event, ...) CODE: @@ -2515,3 +2303,116 @@ THIS->send_packet (buf, len); } +MODULE = cf PACKAGE = cf::face PREFIX = face_ + +#INCLUDE: $PERL $srcdir/genacc faceset ../include/face.h | + +faceidx face_find (utf8_string name, faceidx defidx = 0) + +faceidx alloc (utf8_string name) + CODE: +{ + do + { + RETVAL = faces.size (); + faces.resize (RETVAL + 1); + } + while (!RETVAL); // crude way to leave index 0 + + faces [RETVAL].name = name; + facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); + + if (!strcmp (name, BLANK_FACE_NAME)) blank_face = RETVAL; + if (!strcmp (name, EMPTY_FACE_NAME)) empty_face = RETVAL; +} + OUTPUT: RETVAL + +void set (faceidx idx, int visibility, int magicmap) + CODE: + faceinfo *f = face_info (idx); + assert (f); + f->visibility = visibility; + f->magicmap = magicmap; + +void set_smooth (faceidx idx, faceidx smooth, int smoothlevel) + CODE: + faceinfo *f = face_info (idx); assert (f); + f->smooth = smooth; + f->smoothlevel = smoothlevel; + +void set_data (faceidx idx, int faceset, SV *data, SV *chksum) + CODE: +{ + facedata *d = face_data (idx, faceset); + assert (d); + sv_to (data, d->data); + STRLEN clen; + char *cdata = SvPVbyte (chksum, clen); + clen = min (CHKSUM_SIZE, clen); + + if (memcmp (d->chksum, cdata, clen)) + { + memcpy (d->chksum, cdata, clen); + + // invalidate existing client face info + for_all_clients (ns) + if (ns->faceset == faceset) + { + ns->faces_sent [idx] = false; + ns->force_newmap = true; + } + } +} + +void invalidate (faceidx idx) + CODE: + for_all_clients (ns) + { + ns->faces_sent [idx] = false; + ns->force_newmap = true; + } + +void invalidate_all () + CODE: + for_all_clients (ns) + { + ns->faces_sent.reset (); + ns->force_newmap = true; + } + +MODULE = cf PACKAGE = cf::anim PREFIX = anim_ + +#INCLUDE: $PERL $srcdir/genacc faceset ../include/anim.h | + +animidx anim_find (utf8_string name) + CODE: + RETVAL = animation::find (name).number; + OUTPUT: RETVAL + +animidx set (utf8_string name, SV *frames, int facings = 1) + CODE: +{ + if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV) + croak ("frames must be an arrayref"); + + AV *av = (AV *)SvRV (frames); + + animation *anim = &animation::find (name); + if (anim->number) + { + anim->resize (av_len (av) + 1); + anim->facings = facings; + } + else + anim = &animation::create (name, av_len (av) + 1, facings); + + for (int i = 0; i < anim->num_animations; ++i) + anim->faces [i] = face_find (SvPVutf8_nolen (*av_fetch (av, i, 1))); +} + OUTPUT: RETVAL + +void invalidate_all () + CODE: + for_all_clients (ns) + ns->anims_sent.reset (); +