forked from github/server
refactoring modules, cleaning out the config.c kitchen sink.
- cansee_* rules to laws.c - translations to language.c - stealth to attributes/, - rename build.h -> buildno.h
This commit is contained in:
parent
a29e6a7f40
commit
81bfb598d0
33 changed files with 285 additions and 275 deletions
|
@ -67,7 +67,6 @@ set (ERESSEA_SRC
|
||||||
spells.c
|
spells.c
|
||||||
battle.c
|
battle.c
|
||||||
alchemy.c
|
alchemy.c
|
||||||
stealth.c
|
|
||||||
upkeep.c
|
upkeep.c
|
||||||
vortex.c
|
vortex.c
|
||||||
names.c
|
names.c
|
||||||
|
@ -161,7 +160,6 @@ set(TESTS_SRC
|
||||||
vortex.test.c
|
vortex.test.c
|
||||||
tests.test.c
|
tests.test.c
|
||||||
reports.test.c
|
reports.test.c
|
||||||
stealth.test.c
|
|
||||||
callback.test.c
|
callback.test.c
|
||||||
direction.test.c
|
direction.test.c
|
||||||
economy.test.c
|
economy.test.c
|
||||||
|
@ -172,6 +170,7 @@ set(TESTS_SRC
|
||||||
move.test.c
|
move.test.c
|
||||||
skill.test.c
|
skill.test.c
|
||||||
upkeep.test.c
|
upkeep.test.c
|
||||||
|
${ATTRIBUTES_TESTS}
|
||||||
${UTIL_TESTS}
|
${UTIL_TESTS}
|
||||||
${KERNEL_TESTS}
|
${KERNEL_TESTS}
|
||||||
${ERESSEA_SRC}
|
${ERESSEA_SRC}
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
PROJECT(attributes C)
|
PROJECT(attributes C)
|
||||||
|
SET(_TEST_FILES
|
||||||
|
stealth.test.c
|
||||||
|
)
|
||||||
|
|
||||||
SET(_FILES
|
SET(_FILES
|
||||||
alliance.c
|
alliance.c
|
||||||
attributes.c
|
attributes.c
|
||||||
|
@ -18,10 +22,14 @@ overrideroads.c
|
||||||
racename.c
|
racename.c
|
||||||
raceprefix.c
|
raceprefix.c
|
||||||
reduceproduction.c
|
reduceproduction.c
|
||||||
|
stealth.c
|
||||||
targetregion.c
|
targetregion.c
|
||||||
)
|
)
|
||||||
FOREACH(_FILE ${_FILES})
|
FOREACH(_FILE ${_FILES})
|
||||||
LIST(APPEND _SOURCES ${PROJECT_NAME}/${_FILE})
|
LIST(APPEND _SOURCES ${PROJECT_NAME}/${_FILE})
|
||||||
ENDFOREACH(_FILE)
|
ENDFOREACH(_FILE)
|
||||||
SET(ATTRIBUTES_SRC ${_SOURCES} PARENT_SCOPE)
|
SET(ATTRIBUTES_SRC ${_SOURCES} PARENT_SCOPE)
|
||||||
|
FOREACH(_FILE ${_TEST_FILES})
|
||||||
|
LIST(APPEND _TESTS ${PROJECT_NAME}/${_FILE})
|
||||||
|
ENDFOREACH(_FILE)
|
||||||
|
SET(ATTRIBUTES_TESTS ${_TESTS} PARENT_SCOPE)
|
||||||
|
|
|
@ -26,6 +26,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include "hate.h"
|
#include "hate.h"
|
||||||
#include "iceberg.h"
|
#include "iceberg.h"
|
||||||
#include "key.h"
|
#include "key.h"
|
||||||
|
#include "stealth.h"
|
||||||
#include "moved.h"
|
#include "moved.h"
|
||||||
#include "movement.h"
|
#include "movement.h"
|
||||||
#include "object.h"
|
#include "object.h"
|
||||||
|
@ -57,7 +58,8 @@ attrib_type at_unitdissolve = {
|
||||||
|
|
||||||
void register_attributes(void)
|
void register_attributes(void)
|
||||||
{
|
{
|
||||||
at_register(&at_object);
|
at_register(&at_stealth);
|
||||||
|
at_register(&at_object);
|
||||||
at_register(&at_unitdissolve);
|
at_register(&at_unitdissolve);
|
||||||
at_register(&at_overrideroads);
|
at_register(&at_overrideroads);
|
||||||
at_register(&at_raceprefix);
|
at_register(&at_raceprefix);
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <platform.h>
|
#include <platform.h>
|
||||||
#include "stealth.h"
|
|
||||||
#include <kernel/unit.h>
|
#include <kernel/unit.h>
|
||||||
#include <kernel/region.h>
|
#include <kernel/region.h>
|
||||||
#include <kernel/save.h>
|
#include <kernel/save.h>
|
||||||
#include <util/attrib.h>
|
#include <util/attrib.h>
|
||||||
|
#include <attributes/stealth.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
|
@ -21,6 +21,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include "battle.h"
|
#include "battle.h"
|
||||||
#include "alchemy.h"
|
#include "alchemy.h"
|
||||||
#include "move.h"
|
#include "move.h"
|
||||||
|
#include "laws.h"
|
||||||
#include "skill.h"
|
#include "skill.h"
|
||||||
|
|
||||||
#include <kernel/alliance.h>
|
#include <kernel/alliance.h>
|
||||||
|
|
|
@ -9,7 +9,7 @@ without prior permission by the authors of Eressea.
|
||||||
|
|
||||||
#include <platform.h>
|
#include <platform.h>
|
||||||
#include <kernel/config.h>
|
#include <kernel/config.h>
|
||||||
#include "build.h"
|
#include "buildno.h"
|
||||||
#include "creport.h"
|
#include "creport.h"
|
||||||
|
|
||||||
/* tweakable features */
|
/* tweakable features */
|
||||||
|
@ -22,15 +22,15 @@ without prior permission by the authors of Eressea.
|
||||||
|
|
||||||
/* attributes include */
|
/* attributes include */
|
||||||
#include <attributes/follow.h>
|
#include <attributes/follow.h>
|
||||||
#include <attributes/racename.h>
|
|
||||||
#include <attributes/orcification.h>
|
#include <attributes/orcification.h>
|
||||||
#include <attributes/otherfaction.h>
|
#include <attributes/otherfaction.h>
|
||||||
|
#include <attributes/racename.h>
|
||||||
#include <attributes/raceprefix.h>
|
#include <attributes/raceprefix.h>
|
||||||
|
#include <attributes/stealth.h>
|
||||||
|
|
||||||
/* gamecode includes */
|
/* gamecode includes */
|
||||||
#include "laws.h"
|
#include "laws.h"
|
||||||
#include "economy.h"
|
#include "economy.h"
|
||||||
#include "stealth.h"
|
|
||||||
#include "move.h"
|
#include "move.h"
|
||||||
#include "reports.h"
|
#include "reports.h"
|
||||||
#include "alchemy.h"
|
#include "alchemy.h"
|
||||||
|
|
|
@ -20,28 +20,30 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <kernel/config.h>
|
#include <kernel/config.h>
|
||||||
#include "build.h"
|
#include "build.h"
|
||||||
|
|
||||||
/* kernel includes */
|
|
||||||
#include "alchemy.h"
|
#include "alchemy.h"
|
||||||
#include "alliance.h"
|
|
||||||
#include "connection.h"
|
|
||||||
#include "direction.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 "move.h"
|
||||||
#include "order.h"
|
#include "laws.h"
|
||||||
#include "pool.h"
|
|
||||||
#include "race.h"
|
|
||||||
#include "region.h"
|
|
||||||
#include "ship.h"
|
|
||||||
#include "skill.h"
|
#include "skill.h"
|
||||||
#include "terrain.h"
|
|
||||||
#include "terrainid.h"
|
/* kernel includes */
|
||||||
#include "unit.h"
|
#include <kernel/alliance.h>
|
||||||
|
#include <kernel/connection.h>
|
||||||
|
#include <kernel/building.h>
|
||||||
|
#include <kernel/curse.h>
|
||||||
|
#include <kernel/faction.h>
|
||||||
|
#include <kernel/group.h>
|
||||||
|
#include <kernel/item.h>
|
||||||
|
#include <kernel/magic.h>
|
||||||
|
#include <kernel/messages.h>
|
||||||
|
#include <kernel/order.h>
|
||||||
|
#include <kernel/pool.h>
|
||||||
|
#include <kernel/race.h>
|
||||||
|
#include <kernel/region.h>
|
||||||
|
#include <kernel/ship.h>
|
||||||
|
#include <kernel/terrain.h>
|
||||||
|
#include <kernel/terrainid.h>
|
||||||
|
#include <kernel/unit.h>
|
||||||
|
|
||||||
/* from libutil */
|
/* from libutil */
|
||||||
#include <util/attrib.h>
|
#include <util/attrib.h>
|
||||||
|
|
|
@ -29,7 +29,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include "race.h"
|
#include "race.h"
|
||||||
#include "region.h"
|
#include "region.h"
|
||||||
#include "skill.h"
|
#include "skill.h"
|
||||||
#include "magic.h"
|
|
||||||
#include "save.h"
|
#include "save.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include "group.h"
|
#include "group.h"
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "keyword.h"
|
#include "keyword.h"
|
||||||
#include "magic.h"
|
|
||||||
#include "messages.h"
|
#include "messages.h"
|
||||||
#include "move.h"
|
#include "move.h"
|
||||||
#include "objtypes.h"
|
#include "objtypes.h"
|
||||||
|
@ -50,10 +49,12 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include "ship.h"
|
#include "ship.h"
|
||||||
#include "skill.h"
|
#include "skill.h"
|
||||||
#include "terrain.h"
|
#include "terrain.h"
|
||||||
|
#include "types.h"
|
||||||
#include "unit.h"
|
#include "unit.h"
|
||||||
|
|
||||||
#include <kernel/spell.h>
|
#include <kernel/spell.h>
|
||||||
#include <kernel/spellbook.h>
|
#include <kernel/spellbook.h>
|
||||||
|
|
||||||
/* util includes */
|
/* util includes */
|
||||||
#include <util/attrib.h>
|
#include <util/attrib.h>
|
||||||
#include <util/base36.h>
|
#include <util/base36.h>
|
||||||
|
@ -74,8 +75,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <util/umlaut.h>
|
#include <util/umlaut.h>
|
||||||
#include <util/xml.h>
|
#include <util/xml.h>
|
||||||
|
|
||||||
#include <stealth.h>
|
|
||||||
|
|
||||||
#ifdef USE_LIBXML2
|
#ifdef USE_LIBXML2
|
||||||
/* libxml includes */
|
/* libxml includes */
|
||||||
#include <libxml/tree.h>
|
#include <libxml/tree.h>
|
||||||
|
@ -787,161 +786,6 @@ int alliedunit(const unit * u, const faction * f2, int mode)
|
||||||
return 0;
|
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
|
#ifndef NDEBUG
|
||||||
const char *strcheck(const char *s, size_t maxlen)
|
const char *strcheck(const char *s, size_t maxlen)
|
||||||
{
|
{
|
||||||
|
@ -1685,42 +1529,6 @@ void *gc_add(void *p)
|
||||||
return 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)
|
static const char * parameter_key(int i)
|
||||||
{
|
{
|
||||||
assert(i < MAXPARAMS && i >= 0);
|
assert(i < MAXPARAMS && i >= 0);
|
||||||
|
@ -2503,7 +2311,6 @@ void attrib_init(void)
|
||||||
at_register(&at_clone);
|
at_register(&at_clone);
|
||||||
at_register(&at_clonemage);
|
at_register(&at_clonemage);
|
||||||
at_register(&at_eventhandler);
|
at_register(&at_eventhandler);
|
||||||
at_register(&at_stealth);
|
|
||||||
at_register(&at_mage);
|
at_register(&at_mage);
|
||||||
at_register(&at_countdown);
|
at_register(&at_countdown);
|
||||||
at_register(&at_curse);
|
at_register(&at_curse);
|
||||||
|
|
|
@ -27,7 +27,6 @@ extern "C" {
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
struct _dictionary_;
|
struct _dictionary_;
|
||||||
struct critbit_tree;
|
|
||||||
/* experimental gameplay features (that don't affect the savefile) */
|
/* experimental gameplay features (that don't affect the savefile) */
|
||||||
/* TODO: move these settings to settings.h or into configuration files */
|
/* TODO: move these settings to settings.h or into configuration files */
|
||||||
#define GOBLINKILL /* Goblin-Spezialklau kann tödlich enden */
|
#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
|
#define OBJECTIDSIZE (NAMESIZE+5+IDSIZE) /* max. Länge der Strings, die
|
||||||
* von struct unitname, etc. zurückgegeben werden. ohne die 0 */
|
* von struct unitname, etc. zurückgegeben werden. ohne die 0 */
|
||||||
|
|
||||||
#define BAGCAPACITY 20000 /* soviel paßt in einen Bag of Holding */
|
#define BAGCAPACITY 20000 /* soviel paßt in einen Bag of Holding */
|
||||||
#define STRENGTHCAPACITY 50000 /* zusätzliche Tragkraft beim Kraftzauber (deprecated) */
|
#define STRENGTHCAPACITY 50000 /* zusätzliche Tragkraft beim Kraftzauber (deprecated) */
|
||||||
#define STRENGTHMULTIPLIER 50 /* multiplier for trollbelt */
|
#define STRENGTHMULTIPLIER 50 /* multiplier for trollbelt */
|
||||||
|
|
||||||
/* ----------------- Befehle ----------------------------------- */
|
/* ----------------- Befehle ----------------------------------- */
|
||||||
|
|
||||||
#define want(option) (1<<option)
|
#define want(option) (1<<option)
|
||||||
/* ------------------------------------------------------------- */
|
/* ------------------------------------------------------------- */
|
||||||
void add_translation(struct critbit_tree **cb, const char *str, int i);
|
|
||||||
void init_translations(const struct locale *lang, int ut, const char * (*string_cb)(int i), int maxstrings);
|
|
||||||
int shipspeed(const struct ship *sh, const struct unit *u);
|
int shipspeed(const struct ship *sh, const struct unit *u);
|
||||||
|
|
||||||
#define i2b(i) ((bool)((i)?(true):(false)))
|
#define i2b(i) ((bool)((i)?(true):(false)))
|
||||||
|
@ -155,15 +152,6 @@ extern "C" {
|
||||||
#define factionid(x) itoa36((x)->no)
|
#define factionid(x) itoa36((x)->no)
|
||||||
#define curseid(x) itoa36((x)->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);
|
const char * game_name(void);
|
||||||
int game_id(void);
|
int game_id(void);
|
||||||
int lovar(double xpct_x2);
|
int lovar(double xpct_x2);
|
||||||
|
|
|
@ -23,7 +23,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
/* kernel includes */
|
/* kernel includes */
|
||||||
#include "building.h"
|
#include "building.h"
|
||||||
#include "faction.h"
|
#include "faction.h"
|
||||||
#include "magic.h"
|
|
||||||
#include "messages.h"
|
#include "messages.h"
|
||||||
#include "objtypes.h"
|
#include "objtypes.h"
|
||||||
#include "race.h"
|
#include "race.h"
|
||||||
|
|
|
@ -22,27 +22,29 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <kernel/types.h>
|
#include <kernel/types.h>
|
||||||
#include "magic.h"
|
#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 "skill.h"
|
||||||
#include "spell.h"
|
#include "laws.h"
|
||||||
#include "spellbook.h"
|
|
||||||
#include "teleport.h"
|
#include <kernel/building.h>
|
||||||
#include "terrain.h"
|
#include <kernel/curse.h>
|
||||||
#include "unit.h"
|
#include <kernel/faction.h>
|
||||||
#include "version.h"
|
#include <kernel/item.h>
|
||||||
|
#include <kernel/messages.h>
|
||||||
|
#include <kernel/objtypes.h>
|
||||||
|
#include <kernel/order.h>
|
||||||
|
#include <kernel/pathfinder.h>
|
||||||
|
#include <kernel/plane.h>
|
||||||
|
#include <kernel/pool.h>
|
||||||
|
#include <kernel/race.h>
|
||||||
|
#include <kernel/region.h>
|
||||||
|
#include <kernel/save.h>
|
||||||
|
#include <kernel/ship.h>
|
||||||
|
#include <kernel/spell.h>
|
||||||
|
#include <kernel/spellbook.h>
|
||||||
|
#include <kernel/teleport.h>
|
||||||
|
#include <kernel/terrain.h>
|
||||||
|
#include <kernel/unit.h>
|
||||||
|
#include <kernel/version.h>
|
||||||
|
|
||||||
#include <triggers/timeout.h>
|
#include <triggers/timeout.h>
|
||||||
#include <triggers/shock.h>
|
#include <triggers/shock.h>
|
||||||
|
|
|
@ -22,7 +22,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
#include "faction.h"
|
#include "faction.h"
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "magic.h"
|
|
||||||
#include "order.h"
|
#include "order.h"
|
||||||
#include "region.h"
|
#include "region.h"
|
||||||
#include "race.h"
|
#include "race.h"
|
||||||
|
|
|
@ -27,7 +27,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include "faction.h"
|
#include "faction.h"
|
||||||
#include "group.h"
|
#include "group.h"
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "magic.h"
|
|
||||||
#include "names.h"
|
#include "names.h"
|
||||||
#include "pathfinder.h"
|
#include "pathfinder.h"
|
||||||
#include "region.h"
|
#include "region.h"
|
||||||
|
|
|
@ -20,7 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <kernel/config.h>
|
#include <kernel/config.h>
|
||||||
#include "save.h"
|
#include "save.h"
|
||||||
|
|
||||||
#include "../build.h"
|
#include "../buildno.h"
|
||||||
|
|
||||||
#include "alchemy.h"
|
#include "alchemy.h"
|
||||||
#include "alliance.h"
|
#include "alliance.h"
|
||||||
|
@ -30,7 +30,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include "faction.h"
|
#include "faction.h"
|
||||||
#include "group.h"
|
#include "group.h"
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "magic.h"
|
|
||||||
#include "messages.h"
|
#include "messages.h"
|
||||||
#include "move.h"
|
#include "move.h"
|
||||||
#include "objtypes.h"
|
#include "objtypes.h"
|
||||||
|
|
|
@ -22,7 +22,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
#include "curse.h"
|
#include "curse.h"
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "magic.h"
|
|
||||||
#include "race.h"
|
#include "race.h"
|
||||||
#include "region.h"
|
#include "region.h"
|
||||||
#include "terrain.h"
|
#include "terrain.h"
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
#include <quicklist.h>
|
#include <quicklist.h>
|
||||||
#include <kernel/types.h>
|
#include <kernel/types.h>
|
||||||
#include <kernel/spell.h>
|
#include <kernel/spell.h>
|
||||||
#include <kernel/magic.h>
|
|
||||||
|
|
||||||
#include <CuTest.h>
|
#include <CuTest.h>
|
||||||
#include <tests.h>
|
#include <tests.h>
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#include <platform.h>
|
#include <platform.h>
|
||||||
#include <kernel/config.h>
|
#include <kernel/config.h>
|
||||||
#include <kernel/spell.h>
|
#include <kernel/spell.h>
|
||||||
#include <kernel/magic.h>
|
|
||||||
#include <quicklist.h>
|
#include <quicklist.h>
|
||||||
#include <util/log.h>
|
#include <util/log.h>
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <attributes/moved.h>
|
#include <attributes/moved.h>
|
||||||
#include <attributes/otherfaction.h>
|
#include <attributes/otherfaction.h>
|
||||||
#include <attributes/racename.h>
|
#include <attributes/racename.h>
|
||||||
|
#include <attributes/stealth.h>
|
||||||
|
|
||||||
/* util includes */
|
/* util includes */
|
||||||
#include <util/attrib.h>
|
#include <util/attrib.h>
|
||||||
|
@ -56,8 +57,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <util/rng.h>
|
#include <util/rng.h>
|
||||||
#include <util/variant.h>
|
#include <util/variant.h>
|
||||||
|
|
||||||
#include <stealth.h>
|
|
||||||
|
|
||||||
#include <storage.h>
|
#include <storage.h>
|
||||||
|
|
||||||
/* libc includes */
|
/* libc includes */
|
||||||
|
|
158
src/laws.c
158
src/laws.c
|
@ -63,9 +63,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <kernel/unit.h>
|
#include <kernel/unit.h>
|
||||||
|
|
||||||
/* attributes includes */
|
/* attributes includes */
|
||||||
|
#include <attributes/object.h>
|
||||||
#include <attributes/racename.h>
|
#include <attributes/racename.h>
|
||||||
#include <attributes/raceprefix.h>
|
#include <attributes/raceprefix.h>
|
||||||
#include <attributes/object.h>
|
#include <attributes/stealth.h>
|
||||||
|
|
||||||
/* util includes */
|
/* util includes */
|
||||||
#include <util/attrib.h>
|
#include <util/attrib.h>
|
||||||
|
@ -4554,3 +4555,158 @@ void update_subscriptions(void)
|
||||||
}
|
}
|
||||||
fclose(F);
|
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;
|
||||||
|
}
|
||||||
|
|
10
src/laws.h
10
src/laws.h
|
@ -84,6 +84,16 @@ extern "C" {
|
||||||
extern int claim_cmd(struct unit *u, struct order *ord);
|
extern int claim_cmd(struct unit *u, struct order *ord);
|
||||||
extern int follow_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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -28,7 +28,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include "gmtool.h"
|
#include "gmtool.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "build.h"
|
#include "buildno.h"
|
||||||
#include "bindings.h"
|
#include "bindings.h"
|
||||||
#include "races/races.h"
|
#include "races/races.h"
|
||||||
#include "spells.h"
|
#include "spells.h"
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "economy.h"
|
#include "economy.h"
|
||||||
#include "give.h"
|
#include "give.h"
|
||||||
#include "monster.h"
|
#include "monster.h"
|
||||||
|
#include "laws.h"
|
||||||
|
|
||||||
/* triggers includes */
|
/* triggers includes */
|
||||||
#include <triggers/removecurse.h>
|
#include <triggers/removecurse.h>
|
||||||
|
|
|
@ -20,6 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <platform.h>
|
#include <platform.h>
|
||||||
#include <kernel/config.h>
|
#include <kernel/config.h>
|
||||||
#include "move.h"
|
#include "move.h"
|
||||||
|
#include "laws.h"
|
||||||
#include "reports.h"
|
#include "reports.h"
|
||||||
#include "alchemy.h"
|
#include "alchemy.h"
|
||||||
#include "vortex.h"
|
#include "vortex.h"
|
||||||
|
@ -60,15 +61,14 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <util/rand.h>
|
#include <util/rand.h>
|
||||||
#include <util/rng.h>
|
#include <util/rng.h>
|
||||||
|
|
||||||
#include <stealth.h>
|
|
||||||
|
|
||||||
#include <storage.h>
|
#include <storage.h>
|
||||||
|
|
||||||
/* attributes includes */
|
/* attributes includes */
|
||||||
#include <attributes/follow.h>
|
#include <attributes/follow.h>
|
||||||
#include <attributes/targetregion.h>
|
|
||||||
#include <attributes/movement.h>
|
#include <attributes/movement.h>
|
||||||
#include <attributes/otherfaction.h>
|
#include <attributes/otherfaction.h>
|
||||||
|
#include <attributes/stealth.h>
|
||||||
|
#include <attributes/targetregion.h>
|
||||||
|
|
||||||
/* libc includes */
|
/* libc includes */
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
|
@ -22,6 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <kernel/config.h>
|
#include <kernel/config.h>
|
||||||
|
|
||||||
#include "reports.h"
|
#include "reports.h"
|
||||||
|
#include "laws.h"
|
||||||
/* modules includes */
|
/* modules includes */
|
||||||
#include <modules/score.h>
|
#include <modules/score.h>
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <platform.h>
|
#include <platform.h>
|
||||||
#include <kernel/config.h>
|
#include <kernel/config.h>
|
||||||
#include "reports.h"
|
#include "reports.h"
|
||||||
|
#include "laws.h"
|
||||||
|
|
||||||
/* kernel includes */
|
/* kernel includes */
|
||||||
#include <kernel/alliance.h>
|
#include <kernel/alliance.h>
|
||||||
|
@ -64,9 +65,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <attributes/follow.h>
|
#include <attributes/follow.h>
|
||||||
#include <attributes/otherfaction.h>
|
#include <attributes/otherfaction.h>
|
||||||
#include <attributes/racename.h>
|
#include <attributes/racename.h>
|
||||||
|
#include <attributes/stealth.h>
|
||||||
|
|
||||||
#include "move.h"
|
#include "move.h"
|
||||||
#include "stealth.h"
|
|
||||||
|
|
||||||
bool nocr = false;
|
bool nocr = false;
|
||||||
bool nonr = false;
|
bool nonr = false;
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
#include "spy.h"
|
#include "spy.h"
|
||||||
#include "vortex.h"
|
#include "vortex.h"
|
||||||
|
#include "laws.h"
|
||||||
#include "spells.h"
|
#include "spells.h"
|
||||||
#include "direction.h"
|
#include "direction.h"
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <kernel/config.h>
|
#include <kernel/config.h>
|
||||||
#include "spy.h"
|
#include "spy.h"
|
||||||
#include "laws.h"
|
#include "laws.h"
|
||||||
#include "stealth.h"
|
|
||||||
#include "move.h"
|
#include "move.h"
|
||||||
#include "reports.h"
|
#include "reports.h"
|
||||||
|
|
||||||
|
@ -37,8 +36,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <kernel/unit.h>
|
#include <kernel/unit.h>
|
||||||
|
|
||||||
/* attributes includes */
|
/* attributes includes */
|
||||||
#include <attributes/racename.h>
|
|
||||||
#include <attributes/otherfaction.h>
|
#include <attributes/otherfaction.h>
|
||||||
|
#include <attributes/racename.h>
|
||||||
|
#include <attributes/stealth.h>
|
||||||
|
|
||||||
/* util includes */
|
/* util includes */
|
||||||
#include <util/attrib.h>
|
#include <util/attrib.h>
|
||||||
|
|
|
@ -28,6 +28,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <critbit.h>
|
||||||
|
|
||||||
/** importing **/
|
/** importing **/
|
||||||
|
|
||||||
|
@ -234,6 +235,42 @@ void ** get_translations(const struct locale *lang, int index)
|
||||||
return lstrs[0].tokens + 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 *get_translation(const struct locale *lang, const char *str, int index) {
|
||||||
void **tokens = get_translations(lang, index);
|
void **tokens = get_translations(lang, index);
|
||||||
variant var;
|
variant var;
|
||||||
|
|
|
@ -25,6 +25,7 @@ extern "C" {
|
||||||
#define MAXLOCALES 3
|
#define MAXLOCALES 3
|
||||||
|
|
||||||
struct locale;
|
struct locale;
|
||||||
|
struct critbit_tree;
|
||||||
|
|
||||||
/** managing multiple locales: **/
|
/** managing multiple locales: **/
|
||||||
extern struct locale *get_locale(const char *name);
|
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_translations(const struct locale *lang, int type);
|
||||||
void * get_translation(const struct locale *lang, const char *str, 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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue