diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0da16a3cd..a4da76513 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -67,7 +67,6 @@ set (ERESSEA_SRC spells.c battle.c alchemy.c - stealth.c upkeep.c vortex.c names.c @@ -161,7 +160,6 @@ set(TESTS_SRC vortex.test.c tests.test.c reports.test.c - stealth.test.c callback.test.c direction.test.c economy.test.c @@ -172,6 +170,7 @@ set(TESTS_SRC move.test.c skill.test.c upkeep.test.c + ${ATTRIBUTES_TESTS} ${UTIL_TESTS} ${KERNEL_TESTS} ${ERESSEA_SRC} diff --git a/src/attributes/CMakeLists.txt b/src/attributes/CMakeLists.txt index 34299b4b2..05d3a17a5 100644 --- a/src/attributes/CMakeLists.txt +++ b/src/attributes/CMakeLists.txt @@ -1,4 +1,8 @@ PROJECT(attributes C) +SET(_TEST_FILES +stealth.test.c +) + SET(_FILES alliance.c attributes.c @@ -18,10 +22,14 @@ overrideroads.c racename.c raceprefix.c reduceproduction.c +stealth.c targetregion.c ) FOREACH(_FILE ${_FILES}) LIST(APPEND _SOURCES ${PROJECT_NAME}/${_FILE}) ENDFOREACH(_FILE) SET(ATTRIBUTES_SRC ${_SOURCES} PARENT_SCOPE) - +FOREACH(_FILE ${_TEST_FILES}) + LIST(APPEND _TESTS ${PROJECT_NAME}/${_FILE}) +ENDFOREACH(_FILE) +SET(ATTRIBUTES_TESTS ${_TESTS} PARENT_SCOPE) diff --git a/src/attributes/attributes.c b/src/attributes/attributes.c index 139c63f8c..d9d62149d 100644 --- a/src/attributes/attributes.c +++ b/src/attributes/attributes.c @@ -26,6 +26,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "hate.h" #include "iceberg.h" #include "key.h" +#include "stealth.h" #include "moved.h" #include "movement.h" #include "object.h" @@ -57,7 +58,8 @@ attrib_type at_unitdissolve = { void register_attributes(void) { - at_register(&at_object); + at_register(&at_stealth); + at_register(&at_object); at_register(&at_unitdissolve); at_register(&at_overrideroads); at_register(&at_raceprefix); diff --git a/src/stealth.c b/src/attributes/stealth.c similarity index 97% rename from src/stealth.c rename to src/attributes/stealth.c index 9ad973ca5..129802c09 100644 --- a/src/stealth.c +++ b/src/attributes/stealth.c @@ -1,10 +1,10 @@ #include #include -#include "stealth.h" #include #include #include #include +#include #include diff --git a/src/stealth.h b/src/attributes/stealth.h similarity index 100% rename from src/stealth.h rename to src/attributes/stealth.h diff --git a/src/stealth.test.c b/src/attributes/stealth.test.c similarity index 100% rename from src/stealth.test.c rename to src/attributes/stealth.test.c diff --git a/src/battle.c b/src/battle.c index fb5f6e035..4d85acabd 100644 --- a/src/battle.c +++ b/src/battle.c @@ -21,6 +21,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "battle.h" #include "alchemy.h" #include "move.h" +#include "laws.h" #include "skill.h" #include diff --git a/src/build.h b/src/buildno.h similarity index 100% rename from src/build.h rename to src/buildno.h diff --git a/src/creport.c b/src/creport.c index a56c28888..3ac20fcc5 100644 --- a/src/creport.c +++ b/src/creport.c @@ -9,7 +9,7 @@ without prior permission by the authors of Eressea. #include #include -#include "build.h" +#include "buildno.h" #include "creport.h" /* tweakable features */ @@ -22,15 +22,15 @@ without prior permission by the authors of Eressea. /* attributes include */ #include -#include #include #include +#include #include +#include /* gamecode includes */ #include "laws.h" #include "economy.h" -#include "stealth.h" #include "move.h" #include "reports.h" #include "alchemy.h" diff --git a/src/kernel/build.c b/src/kernel/build.c index 22ae245b4..1ba9331aa 100644 --- a/src/kernel/build.c +++ b/src/kernel/build.c @@ -20,28 +20,30 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include "build.h" -/* kernel includes */ #include "alchemy.h" -#include "alliance.h" -#include "connection.h" #include "direction.h" -#include "building.h" -#include "curse.h" -#include "faction.h" -#include "group.h" -#include "item.h" -#include "magic.h" -#include "messages.h" #include "move.h" -#include "order.h" -#include "pool.h" -#include "race.h" -#include "region.h" -#include "ship.h" +#include "laws.h" #include "skill.h" -#include "terrain.h" -#include "terrainid.h" -#include "unit.h" + +/* kernel includes */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include /* from libutil */ #include diff --git a/src/kernel/building.c b/src/kernel/building.c index 1fd0b5efa..bf8bb8d08 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -29,7 +29,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "race.h" #include "region.h" #include "skill.h" -#include "magic.h" #include "save.h" #include "version.h" diff --git a/src/kernel/config.c b/src/kernel/config.c index 15e77b987..1cff32930 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -36,7 +36,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "group.h" #include "item.h" #include "keyword.h" -#include "magic.h" #include "messages.h" #include "move.h" #include "objtypes.h" @@ -50,10 +49,12 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "ship.h" #include "skill.h" #include "terrain.h" +#include "types.h" #include "unit.h" #include #include + /* util includes */ #include #include @@ -74,8 +75,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -#include - #ifdef USE_LIBXML2 /* libxml includes */ #include @@ -787,161 +786,6 @@ int alliedunit(const unit * u, const faction * f2, int mode) return 0; } -bool -seefaction(const faction * f, const region * r, const unit * u, int modifier) -{ - if (((f == u->faction) || !fval(u, UFL_ANON_FACTION)) - && cansee(f, r, u, modifier)) - return true; - return false; -} - -bool -cansee(const faction * f, const region * r, const unit * u, int modifier) -/* r kann != u->region sein, wenn es um durchreisen geht */ -/* und es muss niemand aus f in der region sein, wenn sie vom Turm - * erblickt wird */ -{ - int stealth, rings; - unit *u2 = r->units; - - if (u->faction == f || omniscient(f)) { - return true; - } - else if (fval(u_race(u), RCF_INVISIBLE)) { - return false; - } - else if (u->number == 0) { - attrib *a = a_find(u->attribs, &at_creator); - if (a) { /* u is an empty temporary unit. In this special case - we look at the creating unit. */ - u = (unit *)a->data.v; - } - else { - return false; - } - } - - if (leftship(u)) - return true; - - while (u2 && u2->faction != f) - u2 = u2->next; - if (u2 == NULL) - return false; - - /* simple visibility, just gotta have a unit in the region to see 'em */ - if (is_guard(u, GUARD_ALL) != 0 || usiege(u) || u->building || u->ship) { - return true; - } - - rings = invisible(u, NULL); - stealth = eff_stealth(u, r) - modifier; - - while (u2) { - if (rings < u->number || invisible(u, u2) < u->number) { - if (skill_enabled(SK_PERCEPTION)) { - int observation = eff_skill(u2, SK_PERCEPTION, r); - - if (observation >= stealth) { - return true; - } - } - else { - return true; - } - } - - /* find next unit in our faction */ - do { - u2 = u2->next; - } while (u2 && u2->faction != f); - } - return false; -} - -bool cansee_unit(const unit * u, const unit * target, int modifier) -/* target->region kann != u->region sein, wenn es um durchreisen geht */ -{ - if (fval(u_race(target), RCF_INVISIBLE) || target->number == 0) - return false; - else if (target->faction == u->faction) - return true; - else { - int n, rings, o; - - if (is_guard(target, GUARD_ALL) != 0 || usiege(target) || target->building - || target->ship) { - return true; - } - - n = eff_stealth(target, target->region) - modifier; - rings = invisible(target, NULL); - if (rings == 0 && n <= 0) { - return true; - } - - if (rings && invisible(target, u) >= target->number) { - return false; - } - if (skill_enabled(SK_PERCEPTION)) { - o = eff_skill(u, SK_PERCEPTION, target->region); - if (o >= n) { - return true; - } - } - else { - return true; - } - } - return false; -} - -bool -cansee_durchgezogen(const faction * f, const region * r, const unit * u, -int modifier) -/* r kann != u->region sein, wenn es um durchreisen geht */ -/* und es muss niemand aus f in der region sein, wenn sie vom Turm - * erblickt wird */ -{ - int n; - unit *u2; - - if (fval(u_race(u), RCF_INVISIBLE) || u->number == 0) - return false; - else if (u->faction == f) - return true; - else { - int rings; - - if (is_guard(u, GUARD_ALL) != 0 || usiege(u) || u->building || u->ship) { - return true; - } - - n = eff_stealth(u, r) - modifier; - rings = invisible(u, NULL); - if (rings == 0 && n <= 0) { - return true; - } - - for (u2 = r->units; u2; u2 = u2->next) { - if (u2->faction == f) { - int o; - - if (rings && invisible(u, u2) >= u->number) - continue; - - o = eff_skill(u2, SK_PERCEPTION, r); - - if (o >= n) { - return true; - } - } - } - } - return false; -} - #ifndef NDEBUG const char *strcheck(const char *s, size_t maxlen) { @@ -1685,42 +1529,6 @@ void *gc_add(void *p) return p; } -void add_translation(critbit_tree **cbp, const char *key, int i) { - char buffer[256]; - char * str = transliterate(buffer, sizeof(buffer) - sizeof(int), key); - critbit_tree * cb = *cbp; - if (str) { - size_t len = strlen(str); - if (!cb) { - *cbp = cb = (critbit_tree *)calloc(1, sizeof(critbit_tree *)); - } - len = cb_new_kv(str, len, &i, sizeof(int), buffer); - cb_insert(cb, buffer, len); - } - else { - log_error("could not transliterate '%s'\n", key); - } -} - -void init_translations(const struct locale *lang, int ut, const char * (*string_cb)(int i), int maxstrings) -{ - void **tokens; - int i; - - assert(string_cb); - assert(maxstrings > 0); - tokens = get_translations(lang, ut); - for (i = 0; i != maxstrings; ++i) { - const char * s = string_cb(i); - const char * key = s ? locale_string(lang, s) : 0; - key = key ? key : s; - if (key) { - critbit_tree ** cb = (critbit_tree **)tokens; - add_translation(cb, key, i); - } - } -} - static const char * parameter_key(int i) { assert(i < MAXPARAMS && i >= 0); @@ -2503,7 +2311,6 @@ void attrib_init(void) at_register(&at_clone); at_register(&at_clonemage); at_register(&at_eventhandler); - at_register(&at_stealth); at_register(&at_mage); at_register(&at_countdown); at_register(&at_curse); diff --git a/src/kernel/config.h b/src/kernel/config.h index c7fd0f225..95da6ba63 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -27,7 +27,6 @@ extern "C" { #include "types.h" struct _dictionary_; - struct critbit_tree; /* experimental gameplay features (that don't affect the savefile) */ /* TODO: move these settings to settings.h or into configuration files */ #define GOBLINKILL /* Goblin-Spezialklau kann tödlich enden */ @@ -91,16 +90,14 @@ extern "C" { #define OBJECTIDSIZE (NAMESIZE+5+IDSIZE) /* max. Länge der Strings, die * von struct unitname, etc. zurückgegeben werden. ohne die 0 */ -#define BAGCAPACITY 20000 /* soviel paßt in einen Bag of Holding */ -#define STRENGTHCAPACITY 50000 /* zusätzliche Tragkraft beim Kraftzauber (deprecated) */ -#define STRENGTHMULTIPLIER 50 /* multiplier for trollbelt */ +#define BAGCAPACITY 20000 /* soviel paßt in einen Bag of Holding */ +#define STRENGTHCAPACITY 50000 /* zusätzliche Tragkraft beim Kraftzauber (deprecated) */ +#define STRENGTHMULTIPLIER 50 /* multiplier for trollbelt */ /* ----------------- Befehle ----------------------------------- */ #define want(option) (1<no) #define curseid(x) itoa36((x)->no) - bool cansee(const struct faction *f, const struct region *r, - const struct unit *u, int modifier); - bool cansee_durchgezogen(const struct faction *f, const struct region *r, - const struct unit *u, int modifier); - bool cansee_unit(const struct unit *u, const struct unit *target, - int modifier); - bool seefaction(const struct faction *f, const struct region *r, - const struct unit *u, int modifier); - const char * game_name(void); int game_id(void); int lovar(double xpct_x2); diff --git a/src/kernel/curse.c b/src/kernel/curse.c index 7735e3333..fb807b125 100644 --- a/src/kernel/curse.c +++ b/src/kernel/curse.c @@ -23,7 +23,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* kernel includes */ #include "building.h" #include "faction.h" -#include "magic.h" #include "messages.h" #include "objtypes.h" #include "race.h" diff --git a/src/kernel/magic.c b/src/kernel/magic.c index b609fcff6..04e3adc51 100644 --- a/src/kernel/magic.c +++ b/src/kernel/magic.c @@ -22,27 +22,29 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include "magic.h" -#include "building.h" -#include "curse.h" -#include "faction.h" -#include "item.h" -#include "messages.h" -#include "objtypes.h" -#include "order.h" -#include "pathfinder.h" -#include "plane.h" -#include "pool.h" -#include "race.h" -#include "region.h" -#include "save.h" -#include "ship.h" #include "skill.h" -#include "spell.h" -#include "spellbook.h" -#include "teleport.h" -#include "terrain.h" -#include "unit.h" -#include "version.h" +#include "laws.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include diff --git a/src/kernel/pool.c b/src/kernel/pool.c index 6706ed80c..198387c50 100644 --- a/src/kernel/pool.c +++ b/src/kernel/pool.c @@ -22,7 +22,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "faction.h" #include "item.h" -#include "magic.h" #include "order.h" #include "region.h" #include "race.h" diff --git a/src/kernel/race.c b/src/kernel/race.c index e424e5915..875920d28 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -27,7 +27,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "faction.h" #include "group.h" #include "item.h" -#include "magic.h" #include "names.h" #include "pathfinder.h" #include "region.h" diff --git a/src/kernel/save.c b/src/kernel/save.c index f6fb4c540..6b23bb544 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -20,7 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include "save.h" -#include "../build.h" +#include "../buildno.h" #include "alchemy.h" #include "alliance.h" @@ -30,7 +30,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "faction.h" #include "group.h" #include "item.h" -#include "magic.h" #include "messages.h" #include "move.h" #include "objtypes.h" diff --git a/src/kernel/skills.c b/src/kernel/skills.c index fef434bf0..cb865e740 100644 --- a/src/kernel/skills.c +++ b/src/kernel/skills.c @@ -22,7 +22,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "curse.h" #include "item.h" -#include "magic.h" #include "race.h" #include "region.h" #include "terrain.h" diff --git a/src/kernel/spell.test.c b/src/kernel/spell.test.c index 90ab1cdf0..a75a5f377 100644 --- a/src/kernel/spell.test.c +++ b/src/kernel/spell.test.c @@ -3,7 +3,6 @@ #include #include #include -#include #include #include diff --git a/src/kernel/spellbook.c b/src/kernel/spellbook.c index ac2faf622..6634e04f6 100644 --- a/src/kernel/spellbook.c +++ b/src/kernel/spellbook.c @@ -1,7 +1,6 @@ #include #include #include -#include #include #include diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 65b3bd4bb..100c4dd1b 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -42,6 +42,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include /* util includes */ #include @@ -56,8 +57,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -#include - #include /* libc includes */ diff --git a/src/laws.c b/src/laws.c index ed319023e..8128a5eb9 100755 --- a/src/laws.c +++ b/src/laws.c @@ -63,9 +63,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include /* attributes includes */ +#include #include #include -#include +#include /* util includes */ #include @@ -4554,3 +4555,158 @@ void update_subscriptions(void) } fclose(F); } + +bool +cansee(const faction * f, const region * r, const unit * u, int modifier) +/* r kann != u->region sein, wenn es um durchreisen geht */ +/* und es muss niemand aus f in der region sein, wenn sie vom Turm +* erblickt wird */ +{ + int stealth, rings; + unit *u2 = r->units; + + if (u->faction == f || omniscient(f)) { + return true; + } + else if (fval(u_race(u), RCF_INVISIBLE)) { + return false; + } + else if (u->number == 0) { + attrib *a = a_find(u->attribs, &at_creator); + if (a) { /* u is an empty temporary unit. In this special case + we look at the creating unit. */ + u = (unit *)a->data.v; + } + else { + return false; + } + } + + if (leftship(u)) + return true; + + while (u2 && u2->faction != f) + u2 = u2->next; + if (u2 == NULL) + return false; + + /* simple visibility, just gotta have a unit in the region to see 'em */ + if (is_guard(u, GUARD_ALL) != 0 || usiege(u) || u->building || u->ship) { + return true; + } + + rings = invisible(u, NULL); + stealth = eff_stealth(u, r) - modifier; + + while (u2) { + if (rings < u->number || invisible(u, u2) < u->number) { + if (skill_enabled(SK_PERCEPTION)) { + int observation = eff_skill(u2, SK_PERCEPTION, r); + + if (observation >= stealth) { + return true; + } + } + else { + return true; + } + } + + /* find next unit in our faction */ + do { + u2 = u2->next; + } while (u2 && u2->faction != f); + } + return false; +} + +bool cansee_unit(const unit * u, const unit * target, int modifier) +/* target->region kann != u->region sein, wenn es um durchreisen geht */ +{ + if (fval(u_race(target), RCF_INVISIBLE) || target->number == 0) + return false; + else if (target->faction == u->faction) + return true; + else { + int n, rings, o; + + if (is_guard(target, GUARD_ALL) != 0 || usiege(target) || target->building + || target->ship) { + return true; + } + + n = eff_stealth(target, target->region) - modifier; + rings = invisible(target, NULL); + if (rings == 0 && n <= 0) { + return true; + } + + if (rings && invisible(target, u) >= target->number) { + return false; + } + if (skill_enabled(SK_PERCEPTION)) { + o = eff_skill(u, SK_PERCEPTION, target->region); + if (o >= n) { + return true; + } + } + else { + return true; + } + } + return false; +} + +bool +cansee_durchgezogen(const faction * f, const region * r, const unit * u, +int modifier) +/* r kann != u->region sein, wenn es um durchreisen geht */ +/* und es muss niemand aus f in der region sein, wenn sie vom Turm +* erblickt wird */ +{ + int n; + unit *u2; + + if (fval(u_race(u), RCF_INVISIBLE) || u->number == 0) + return false; + else if (u->faction == f) + return true; + else { + int rings; + + if (is_guard(u, GUARD_ALL) != 0 || usiege(u) || u->building || u->ship) { + return true; + } + + n = eff_stealth(u, r) - modifier; + rings = invisible(u, NULL); + if (rings == 0 && n <= 0) { + return true; + } + + for (u2 = r->units; u2; u2 = u2->next) { + if (u2->faction == f) { + int o; + + if (rings && invisible(u, u2) >= u->number) + continue; + + o = eff_skill(u2, SK_PERCEPTION, r); + + if (o >= n) { + return true; + } + } + } + } + return false; +} + +bool +seefaction(const faction * f, const region * r, const unit * u, int modifier) +{ + if (((f == u->faction) || !fval(u, UFL_ANON_FACTION)) + && cansee(f, r, u, modifier)) + return true; + return false; +} diff --git a/src/laws.h b/src/laws.h index c9fdc095f..0d86c4225 100755 --- a/src/laws.h +++ b/src/laws.h @@ -84,6 +84,16 @@ extern "C" { extern int claim_cmd(struct unit *u, struct order *ord); extern int follow_cmd(struct unit *u, struct order *ord); + bool cansee(const struct faction *f, const struct region *r, + const struct unit *u, int modifier); + bool cansee_durchgezogen(const struct faction *f, const struct region *r, + const struct unit *u, int modifier); + bool cansee_unit(const struct unit *u, const struct unit *target, + int modifier); + bool seefaction(const struct faction *f, const struct region *r, + const struct unit *u, int modifier); + + #ifdef __cplusplus } #endif diff --git a/src/main.c b/src/main.c index 7ad39a2df..32a68d071 100644 --- a/src/main.c +++ b/src/main.c @@ -28,7 +28,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "gmtool.h" #endif -#include "build.h" +#include "buildno.h" #include "bindings.h" #include "races/races.h" #include "spells.h" diff --git a/src/monsters.c b/src/monsters.c index c0047c3f3..4136d04a6 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -25,6 +25,7 @@ #include "economy.h" #include "give.h" #include "monster.h" +#include "laws.h" /* triggers includes */ #include diff --git a/src/move.c b/src/move.c index 2505b6449..93c595a34 100644 --- a/src/move.c +++ b/src/move.c @@ -20,6 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include "move.h" +#include "laws.h" #include "reports.h" #include "alchemy.h" #include "vortex.h" @@ -60,15 +61,14 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -#include - #include /* attributes includes */ #include -#include #include #include +#include +#include /* libc includes */ #include diff --git a/src/report.c b/src/report.c index 4856390a9..0b41598d4 100644 --- a/src/report.c +++ b/src/report.c @@ -22,6 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include "reports.h" +#include "laws.h" /* modules includes */ #include diff --git a/src/reports.c b/src/reports.c index e7ca9c314..29159d0c2 100644 --- a/src/reports.c +++ b/src/reports.c @@ -19,6 +19,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include "reports.h" +#include "laws.h" /* kernel includes */ #include @@ -64,9 +65,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include #include "move.h" -#include "stealth.h" bool nocr = false; bool nonr = false; diff --git a/src/spells.c b/src/spells.c index 41b6e313c..07b4ab0c3 100644 --- a/src/spells.c +++ b/src/spells.c @@ -18,6 +18,7 @@ #include "spy.h" #include "vortex.h" +#include "laws.h" #include "spells.h" #include "direction.h" diff --git a/src/spy.c b/src/spy.c index 4648b529b..cdf393f81 100644 --- a/src/spy.c +++ b/src/spy.c @@ -20,7 +20,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include "spy.h" #include "laws.h" -#include "stealth.h" #include "move.h" #include "reports.h" @@ -37,8 +36,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include /* attributes includes */ -#include #include +#include +#include /* util includes */ #include diff --git a/src/util/language.c b/src/util/language.c index 1e8cd1a4b..3899a533b 100644 --- a/src/util/language.c +++ b/src/util/language.c @@ -28,6 +28,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include /** importing **/ @@ -234,6 +235,42 @@ void ** get_translations(const struct locale *lang, int index) return lstrs[0].tokens + index; } +void add_translation(struct critbit_tree **cbp, const char *key, int i) { + char buffer[256]; + char * str = transliterate(buffer, sizeof(buffer) - sizeof(int), key); + struct critbit_tree * cb = *cbp; + if (str) { + size_t len = strlen(str); + if (!cb) { + *cbp = cb = (struct critbit_tree *)calloc(1, sizeof(struct critbit_tree *)); + } + len = cb_new_kv(str, len, &i, sizeof(int), buffer); + cb_insert(cb, buffer, len); + } + else { + log_error("could not transliterate '%s'\n", key); + } +} + +void init_translations(const struct locale *lang, int ut, const char * (*string_cb)(int i), int maxstrings) +{ + void **tokens; + int i; + + assert(string_cb); + assert(maxstrings > 0); + tokens = get_translations(lang, ut); + for (i = 0; i != maxstrings; ++i) { + const char * s = string_cb(i); + const char * key = s ? locale_string(lang, s) : 0; + key = key ? key : s; + if (key) { + struct critbit_tree ** cb = (struct critbit_tree **)tokens; + add_translation(cb, key, i); + } + } +} + void *get_translation(const struct locale *lang, const char *str, int index) { void **tokens = get_translations(lang, index); variant var; diff --git a/src/util/language.h b/src/util/language.h index 5dd35c7b2..d02a562ea 100644 --- a/src/util/language.h +++ b/src/util/language.h @@ -25,6 +25,7 @@ extern "C" { #define MAXLOCALES 3 struct locale; + struct critbit_tree; /** managing multiple locales: **/ extern struct locale *get_locale(const char *name); @@ -69,6 +70,8 @@ extern "C" { void ** get_translations(const struct locale *lang, int type); void * get_translation(const struct locale *lang, const char *str, int type); + void init_translations(const struct locale *lang, int ut, const char * (*string_cb)(int i), int maxstrings); + void add_translation(struct critbit_tree **cb, const char *str, int i); #ifdef __cplusplus }