From 1d7c193de6f5b1e0fd4ed655ae01fc20da2aa9b6 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 31 Oct 2014 19:01:13 +0100 Subject: [PATCH 1/9] more test coverage for resource pooling. --- src/kernel/pool.test.c | 76 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/src/kernel/pool.test.c b/src/kernel/pool.test.c index 7a45475db..e6594bfac 100644 --- a/src/kernel/pool.test.c +++ b/src/kernel/pool.test.c @@ -15,6 +15,34 @@ #include #include +void test_reservation(CuTest *tc) { + unit *u; + faction *f; + region *r; + struct resource_type *rtype; + test_cleanup(); + test_create_world(); + rtype = rt_get_or_create("money"); + it_get_or_create(rtype); + f = test_create_faction(0); + r = findregion(0, 0); + assert(r && f && rtype && rtype->itype); + u = test_create_unit(f, r); + assert(u); + i_change(&u->items, rtype->itype, 100); + CuAssertIntEquals(tc, 100, get_resource(u, rtype)); + CuAssertIntEquals(tc, 0, get_reservation(u, rtype)); + CuAssertIntEquals(tc, 50, change_reservation(u, rtype, 50)); + CuAssertIntEquals(tc, 100, change_reservation(u, rtype, 50)); + CuAssertIntEquals(tc, 50, set_resvalue(u, rtype, 50)); + CuAssertIntEquals(tc, 100, get_resource(u, rtype)); + CuAssertIntEquals(tc, 200, change_resource(u, rtype, 100)); + CuAssertIntEquals(tc, 200, get_resource(u, rtype)); + CuAssertIntEquals(tc, 200, i_get(u->items, rtype->itype)); + + test_cleanup(); +} + void test_pool(CuTest *tc) { unit *u1, *u2, *u3; faction *f; @@ -60,6 +88,52 @@ void test_pool(CuTest *tc) { CuAssertIntEquals(tc, 300, get_pooled(u1, rtype, GET_ALL, INT_MAX)); } +void test_pool_use(CuTest *tc) { + unit *u1, *u2, *u3; + faction *f; + region *r; + struct resource_type *rtype; + ally *al; + + test_cleanup(); + test_create_world(); + rtype = rt_get_or_create("money"); + it_get_or_create(rtype); + f = test_create_faction(0); + r = findregion(0, 0); + assert(r && f && rtype && rtype->itype); + u1 = test_create_unit(f, r); + u2 = test_create_unit(f, r); + u3 = test_create_unit(test_create_faction(0), r); + assert(u1 && u2); + i_change(&u1->items, rtype->itype, 100); + set_resvalue(u1, rtype, 50); + i_change(&u2->items, rtype->itype, 200); + set_resvalue(u2, rtype, 100); + i_change(&u3->items, rtype->itype, 400); + set_resvalue(u3, rtype, 200); + al = ally_add(&u3->faction->allies, f); + al->status = HELP_MONEY; + + CuAssertIntEquals(tc, 10, use_pooled(u1, rtype, GET_SLACK, 10)); + CuAssertIntEquals(tc, 40, use_pooled(u1, rtype, GET_SLACK, 50)); + CuAssertIntEquals(tc, 50, i_get(u1->items, rtype->itype)); + + CuAssertIntEquals(tc, 50, get_reservation(u1, rtype)); + CuAssertIntEquals(tc, 10, use_pooled(u1, rtype, GET_RESERVE, 10)); + CuAssertIntEquals(tc, 40, i_get(u1->items, rtype->itype)); + CuAssertIntEquals(tc, 40, get_reservation(u1, rtype)); + CuAssertIntEquals(tc, 40, use_pooled(u1, rtype, GET_RESERVE, 50)); + + CuAssertIntEquals(tc, 10, use_pooled(u1, rtype, GET_POOLED_SLACK, 10)); + CuAssertIntEquals(tc, 90, use_pooled(u1, rtype, GET_POOLED_SLACK, 100)); + CuAssertIntEquals(tc, 100, i_get(u2->items, rtype->itype)); + CuAssertIntEquals(tc, 10, use_pooled(u1, rtype, GET_POOLED_RESERVE, 10)); + CuAssertIntEquals(tc, 90, get_reservation(u2, rtype)); + CuAssertIntEquals(tc, 90, use_pooled(u1, rtype, GET_POOLED_RESERVE, 100)); + CuAssertIntEquals(tc, 0, i_get(u2->items, rtype->itype)); +} + void test_change_resource(CuTest * tc) { struct unit * u; @@ -90,7 +164,9 @@ void test_change_resource(CuTest * tc) CuSuite *get_pool_suite(void) { CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_reservation); SUITE_ADD_TEST(suite, test_pool); + SUITE_ADD_TEST(suite, test_pool_use); SUITE_ADD_TEST(suite, test_change_resource); return suite; } From 483a2ba3de4ea54a11d35de9143a7d50e69022f6 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 31 Oct 2014 19:15:26 +0100 Subject: [PATCH 2/9] add missing tests for groups. --- src/kernel/CMakeLists.txt | 1 + src/kernel/group.h | 4 ---- src/kernel/group.test.c | 45 +++++++++++++++++++++++++++++++++++++++ src/test_eressea.c | 1 + 4 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 src/kernel/group.test.c diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index 9566317e7..a1ea20a64 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -3,6 +3,7 @@ project(kernel C) SET(_TEST_FILES build.test.c config.test.c +group.test.c faction.test.c unit.test.c save.test.c diff --git a/src/kernel/group.h b/src/kernel/group.h index ea312542c..076761d98 100755 --- a/src/kernel/group.h +++ b/src/kernel/group.h @@ -22,9 +22,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. extern "C" { #endif -/* bitfield value for group::flags */ -#define GFL_ALIVE 0x01 /* There is at least one struct unit in the group */ - struct gamedata; typedef struct group { @@ -34,7 +31,6 @@ extern "C" { struct attrib *attribs; char *name; struct ally *allies; - int flags; int gid; int members; } group; diff --git a/src/kernel/group.test.c b/src/kernel/group.test.c new file mode 100644 index 000000000..c1bd01d59 --- /dev/null +++ b/src/kernel/group.test.c @@ -0,0 +1,45 @@ +#include +#include "types.h" +#include "group.h" +#include "faction.h" +#include "unit.h" +#include "region.h" + +#include +#include +#include + +static void test_group(CuTest * tc) +{ + unit *u; + region *r; + faction *f; + group *g; + + test_cleanup(); + test_create_world(); + r = findregion(0, 0); + f = test_create_faction(0); + assert(r && f); + u = test_create_unit(f, r); + assert(u); + CuAssertTrue(tc, join_group(u, "hodor")); + CuAssertPtrNotNull(tc, (g = get_group(u))); + CuAssertStrEquals(tc, "hodor", g->name); + CuAssertIntEquals(tc, 1, g->members); + set_group(u, 0); + CuAssertIntEquals(tc, 0, g->members); + CuAssertPtrEquals(tc, 0, get_group(u)); + set_group(u, g); + CuAssertIntEquals(tc, 1, g->members); + CuAssertPtrEquals(tc, g, get_group(u)); + test_cleanup(); +} + +CuSuite *get_group_suite(void) +{ + CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_group); + return suite; +} + diff --git a/src/test_eressea.c b/src/test_eressea.c index 6fa8767cb..17958c7b2 100644 --- a/src/test_eressea.c +++ b/src/test_eressea.c @@ -40,6 +40,7 @@ int RunAllTests(void) /* kernel */ ADD_TESTS(suite, unit); ADD_TESTS(suite, faction); + ADD_TESTS(suite, group); ADD_TESTS(suite, build); ADD_TESTS(suite, pool); ADD_TESTS(suite, curse); From 5b6663cad799d5db6c71c1f4e1493ada6f45a634 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 31 Oct 2014 22:03:00 +0100 Subject: [PATCH 3/9] Assert that magicians are single-person units in a few places. Bug 2028 claims that this is not always the case, though I cannot prove it. --- src/kernel/unit.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/kernel/unit.c b/src/kernel/unit.c index a039d9c3a..6e7f1eaa0 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -702,6 +702,7 @@ void set_level(unit * u, skill_t sk, int value) { skill *sv = u->skills; + assert(sk != SK_MAGIC || is_monsters(u->faction) || u->number == 1); if (!skill_enabled(sk)) return; @@ -1165,8 +1166,8 @@ skill *add_skill(unit * u, skill_t id) sv->weeks = 1; sv->old = 0; sv->id = id; - if (id == SK_MAGIC && u->faction) { - assert(max_magicians(u->faction) >= u->number); + if (id == SK_MAGIC && u->faction && !is_monsters(u->faction)) { + assert(u->number==1 && max_magicians(u->faction) >= u->number); } return sv; } From af616b5b09e98dc9cd08b5df394829025572d7c3 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 31 Oct 2014 22:10:41 +0100 Subject: [PATCH 4/9] fix segmentation fault in test. --- src/kernel/faction.test.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/kernel/faction.test.c b/src/kernel/faction.test.c index 31747bd6c..b59a46f63 100644 --- a/src/kernel/faction.test.c +++ b/src/kernel/faction.test.c @@ -47,6 +47,7 @@ static void test_remove_empty_factions(CuTest *tc) { static void test_remove_dead_factions(CuTest *tc) { faction *f, *fm; region *r; + int fno; test_cleanup(); r = test_create_region(0, 0, 0); @@ -60,8 +61,9 @@ static void test_remove_dead_factions(CuTest *tc) { CuAssertPtrNotNull(tc, get_monsters()); fm->alive = 0; f->alive = 0; + fno = f->no; remove_empty_factions(); - CuAssertPtrEquals(tc, 0, findfaction(f->no)); + CuAssertPtrEquals(tc, 0, findfaction(fno)); CuAssertPtrEquals(tc, fm, get_monsters()); test_cleanup(); } From a29e6a7f40be059b22ba39a59c153b71eef623f8 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 31 Oct 2014 22:20:07 +0100 Subject: [PATCH 5/9] fix segmentation fault in new assert (units without a faction) --- conf/eressea.ini | 27 ++++++++++++++------------- src/kernel/unit.c | 2 +- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/conf/eressea.ini b/conf/eressea.ini index 6834005cc..1bc14283d 100644 --- a/conf/eressea.ini +++ b/conf/eressea.ini @@ -1,18 +1,19 @@ + [eressea] -base = . -report = reports -verbose = 0 -lomem = 0 -debug = 0 -memcheck = 0 -locales = de,en -;game_id = 0 +base = . +report = reports +verbose = 0 +lomem = 0 +debug = 0 +memcheck = 0 +locales = de,en [lua] -install = ../git -paths = ../git/lunit:../git/scripts -maxnmrs = 20 -rules = e2 ; can use -r to override +install = ../git +paths = lunit:scripts +maxnmrs = 20 +rules = e2 [editor] -color = 1 +color = 1 + diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 6e7f1eaa0..65b3bd4bb 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -702,7 +702,7 @@ void set_level(unit * u, skill_t sk, int value) { skill *sv = u->skills; - assert(sk != SK_MAGIC || is_monsters(u->faction) || u->number == 1); + assert(sk != SK_MAGIC || !u->faction || is_monsters(u->faction) || u->number == 1); if (!skill_enabled(sk)) return; From 81bfb598d0f0b04e5de0a541abf9ed8687ca5f7e Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 1 Nov 2014 12:09:56 +0100 Subject: [PATCH 6/9] 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 --- src/CMakeLists.txt | 3 +- src/attributes/CMakeLists.txt | 10 +- src/attributes/attributes.c | 4 +- src/{ => attributes}/stealth.c | 2 +- src/{ => attributes}/stealth.h | 0 src/{ => attributes}/stealth.test.c | 0 src/battle.c | 1 + src/{build.h => buildno.h} | 0 src/creport.c | 6 +- src/kernel/build.c | 38 +++--- src/kernel/building.c | 1 - src/kernel/config.c | 197 +--------------------------- src/kernel/config.h | 18 +-- src/kernel/curse.c | 1 - src/kernel/magic.c | 42 +++--- src/kernel/pool.c | 1 - src/kernel/race.c | 1 - src/kernel/save.c | 3 +- src/kernel/skills.c | 1 - src/kernel/spell.test.c | 1 - src/kernel/spellbook.c | 1 - src/kernel/unit.c | 3 +- src/laws.c | 158 +++++++++++++++++++++- src/laws.h | 10 ++ src/main.c | 2 +- src/monsters.c | 1 + src/move.c | 6 +- src/report.c | 1 + src/reports.c | 3 +- src/spells.c | 1 + src/spy.c | 4 +- src/util/language.c | 37 ++++++ src/util/language.h | 3 + 33 files changed, 285 insertions(+), 275 deletions(-) rename src/{ => attributes}/stealth.c (97%) rename src/{ => attributes}/stealth.h (100%) rename src/{ => attributes}/stealth.test.c (100%) rename src/{build.h => buildno.h} (100%) 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 } From 1af315ebf20c51d7eca5832d94c52c1467e83c0d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 1 Nov 2014 12:57:01 +0100 Subject: [PATCH 7/9] move magic out of kernel, into src. clean up/remove a ton of includes, especially of types.h (include in header if you need it, not in every .c file). --- src/CMakeLists.txt | 2 ++ src/alchemy.c | 1 - src/attributes/alliance.c | 1 - src/battle.c | 1 - src/battle.h | 3 +++ src/battle.test.c | 1 - src/bind_config.c | 1 - src/bind_eressea.c | 1 - src/bind_faction.c | 1 - src/bind_gmtool.c | 1 - src/bind_monsters.c | 2 -- src/bind_process.c | 11 +++++------ src/bind_settings.c | 1 - src/bind_ship.c | 1 - src/bind_storage.c | 1 - src/bind_unit.c | 2 -- src/bindings.c | 1 - src/creation.c | 1 - src/direction.test.c | 1 - src/economy.c | 2 -- src/economy.test.c | 1 - src/give.c | 1 - src/items.c | 2 +- src/items/artrewards.c | 1 - src/items/xerewards.c | 3 ++- src/json.c | 1 - src/json.test.c | 1 - src/kernel/CMakeLists.txt | 2 -- src/kernel/build.c | 1 - src/kernel/building.test.c | 1 - src/kernel/equipment.test.c | 4 ++-- src/kernel/faction.test.c | 1 - src/kernel/item.test.c | 1 - src/kernel/pool.test.c | 1 - src/kernel/ship.test.c | 1 - src/kernel/spell.test.c | 1 - src/kernel/spellbook.test.c | 2 -- src/kernel/unit.c | 1 - src/keyword.test.c | 1 - src/laws.c | 1 - src/laws.test.c | 1 - src/{kernel => }/magic.c | 1 - src/{kernel => }/magic.h | 3 +++ src/{kernel => }/magic.test.c | 4 ++-- src/main.c | 1 - src/market.test.c | 1 - src/modules/arena.c | 1 - src/modules/score.c | 1 - src/move.c | 1 - src/move.test.c | 1 - src/names.c | 1 - src/randenc.c | 1 - src/reports.h | 1 + src/reports.test.c | 1 - src/skill.test.c | 1 - src/spells.c | 2 -- src/spells/alp.c | 1 - src/spells/borders.c | 1 - src/spells/combatspells.c | 2 -- src/spells/regioncurse.c | 2 +- src/spy.c | 1 - src/study.c | 1 - src/tests.c | 1 - src/triggers/clonedied.c | 3 ++- src/triggers/shock.c | 3 ++- src/upkeep.c | 1 - 66 files changed, 26 insertions(+), 76 deletions(-) rename src/{kernel => }/magic.c (99%) rename src/{kernel => }/magic.h (99%) rename src/{kernel => }/magic.test.c (99%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a4da76513..635427916 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -83,6 +83,7 @@ set (ERESSEA_SRC give.c items.c laws.c + magic.c market.c monster.c randenc.c @@ -166,6 +167,7 @@ set(TESTS_SRC json.test.c keyword.test.c laws.test.c + magic.test.c market.test.c move.test.c skill.test.c diff --git a/src/alchemy.c b/src/alchemy.c index c9516740a..0b0a506e7 100644 --- a/src/alchemy.c +++ b/src/alchemy.c @@ -26,7 +26,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include #include #include diff --git a/src/attributes/alliance.c b/src/attributes/alliance.c index c774ef26b..b0f2c6301 100644 --- a/src/attributes/alliance.c +++ b/src/attributes/alliance.c @@ -17,7 +17,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. **/ #include -#include #include "alliance.h" #include diff --git a/src/battle.c b/src/battle.c index 4d85acabd..7b2bc236b 100644 --- a/src/battle.c +++ b/src/battle.c @@ -32,7 +32,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include #include #include diff --git a/src/battle.h b/src/battle.h index 95d869ff3..89e0873b2 100644 --- a/src/battle.h +++ b/src/battle.h @@ -18,6 +18,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef H_KRNL_BATTLE #define H_KRNL_BATTLE + +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/battle.test.c b/src/battle.test.c index 47e0d69d8..5f0e75fbd 100644 --- a/src/battle.test.c +++ b/src/battle.test.c @@ -1,4 +1,3 @@ -#include #include #include "battle.h" diff --git a/src/bind_config.c b/src/bind_config.c index e87f65fb5..35f04eaa6 100644 --- a/src/bind_config.c +++ b/src/bind_config.c @@ -1,7 +1,6 @@ #include "bind_config.h" #include -#include #include #include #include diff --git a/src/bind_eressea.c b/src/bind_eressea.c index 664808b17..a345f6c19 100755 --- a/src/bind_eressea.c +++ b/src/bind_eressea.c @@ -5,7 +5,6 @@ #include "json.h" #include -#include #include #include diff --git a/src/bind_faction.c b/src/bind_faction.c index fafd6bc21..163685a36 100644 --- a/src/bind_faction.c +++ b/src/bind_faction.c @@ -11,7 +11,6 @@ without prior permission by the authors of Eressea. */ #include -#include #include "bind_faction.h" #include "bind_unit.h" #include "bindings.h" diff --git a/src/bind_gmtool.c b/src/bind_gmtool.c index d1111f16a..76d85281f 100644 --- a/src/bind_gmtool.c +++ b/src/bind_gmtool.c @@ -1,6 +1,5 @@ #include #include -#include #include "bind_gmtool.h" #include "gmtool.h" diff --git a/src/bind_monsters.c b/src/bind_monsters.c index 22ae645c0..dc7bc012b 100644 --- a/src/bind_monsters.c +++ b/src/bind_monsters.c @@ -1,10 +1,8 @@ #include -#include #include "spells/shipcurse.h" #include #include -#include #include #include #include diff --git a/src/bind_process.c b/src/bind_process.c index 3bcfd835b..2a036e49e 100755 --- a/src/bind_process.c +++ b/src/bind_process.c @@ -1,21 +1,20 @@ #include "bind_process.h" #include -#include #include #include -#include #include #include #include #include #include "battle.h" -#include "move.h" #include "economy.h" -#include "laws.h" -#include "market.h" -#include "study.h" #include "keyword.h" +#include "laws.h" +#include "magic.h" +#include "market.h" +#include "move.h" +#include "study.h" #define PROC_LAND_REGION 0x0001 #define PROC_LONG_ORDER 0x0002 diff --git a/src/bind_settings.c b/src/bind_settings.c index a864a242f..1224939a9 100755 --- a/src/bind_settings.c +++ b/src/bind_settings.c @@ -1,7 +1,6 @@ #include "bind_settings.h" #include -#include #include const char * settings_get(const char *key) diff --git a/src/bind_ship.c b/src/bind_ship.c index a089ab084..affc024ee 100644 --- a/src/bind_ship.c +++ b/src/bind_ship.c @@ -11,7 +11,6 @@ without prior permission by the authors of Eressea. */ #include -#include #include "bind_ship.h" #include "bind_unit.h" diff --git a/src/bind_storage.c b/src/bind_storage.c index 05f735929..8aa363d43 100644 --- a/src/bind_storage.c +++ b/src/bind_storage.c @@ -12,7 +12,6 @@ without prior permission by the authors of Eressea. #include #include -#include #include "bind_storage.h" #include diff --git a/src/bind_unit.c b/src/bind_unit.c index a7dc1cab5..58ca6cae2 100755 --- a/src/bind_unit.c +++ b/src/bind_unit.c @@ -11,7 +11,6 @@ without prior permission by the authors of Eressea. */ #include -#include #include "bind_unit.h" #ifdef BSON_ATTRIB @@ -31,7 +30,6 @@ without prior permission by the authors of Eressea. #include #include #include -#include #include #include #include diff --git a/src/bindings.c b/src/bindings.c index 1446dac15..cb7da3899 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -11,7 +11,6 @@ without prior permission by the authors of Eressea. */ #include -#include #include "bindings.h" #include "bind_unit.h" #include "bind_storage.h" diff --git a/src/creation.c b/src/creation.c index aa555d708..f8e0ae502 100644 --- a/src/creation.c +++ b/src/creation.c @@ -26,7 +26,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include #include #include diff --git a/src/direction.test.c b/src/direction.test.c index e47ab5034..66b854f5a 100644 --- a/src/direction.test.c +++ b/src/direction.test.c @@ -1,5 +1,4 @@ #include -#include #include "direction.h" #include "tests.h" diff --git a/src/economy.c b/src/economy.c index bf7e4f288..c7f7d7dce 100644 --- a/src/economy.c +++ b/src/economy.c @@ -19,7 +19,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -#include #include "economy.h" #include "alchemy.h" @@ -38,7 +37,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include #include #include diff --git a/src/economy.test.c b/src/economy.test.c index 395f97a84..0374d4f45 100644 --- a/src/economy.test.c +++ b/src/economy.test.c @@ -1,6 +1,5 @@ #include #include -#include #include "economy.h" #include diff --git a/src/give.c b/src/give.c index a3dd08f98..2b3d0ab91 100644 --- a/src/give.c +++ b/src/give.c @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include diff --git a/src/items.c b/src/items.c index 4c67894ab..49d7a2652 100644 --- a/src/items.c +++ b/src/items.c @@ -4,12 +4,12 @@ #include "study.h" #include "move.h" +#include "magic.h" #include #include #include #include -#include #include #include #include diff --git a/src/items/artrewards.c b/src/items/artrewards.c index 9226bb301..d25cba68d 100644 --- a/src/items/artrewards.c +++ b/src/items/artrewards.c @@ -29,7 +29,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include /* util includes */ diff --git a/src/items/xerewards.c b/src/items/xerewards.c index 8b7978073..a0ade546a 100644 --- a/src/items/xerewards.c +++ b/src/items/xerewards.c @@ -20,6 +20,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include "xerewards.h" +#include "magic.h" + /* kernel includes */ #include #include @@ -27,7 +29,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include /* util includes */ diff --git a/src/json.c b/src/json.c index 103e530af..ec0c4febf 100644 --- a/src/json.c +++ b/src/json.c @@ -3,7 +3,6 @@ #include "json.h" -#include #include #include #include diff --git a/src/json.test.c b/src/json.test.c index 1c6d72d70..79ee2d2c9 100644 --- a/src/json.test.c +++ b/src/json.test.c @@ -3,7 +3,6 @@ #include #include -#include #include #include diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index a1ea20a64..fe95c5965 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -11,7 +11,6 @@ ship.test.c spell.test.c ally.test.c building.test.c -magic.test.c equipment.test.c curse.test.c item.test.c @@ -37,7 +36,6 @@ equipment.c faction.c group.c item.c -magic.c messages.c order.c pathfinder.c diff --git a/src/kernel/build.c b/src/kernel/build.c index 1ba9331aa..73199d94a 100644 --- a/src/kernel/build.c +++ b/src/kernel/build.c @@ -34,7 +34,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include #include #include diff --git a/src/kernel/building.test.c b/src/kernel/building.test.c index 61ca0fa1c..cd29601eb 100644 --- a/src/kernel/building.test.c +++ b/src/kernel/building.test.c @@ -1,7 +1,6 @@ #include #include -#include #include #include #include diff --git a/src/kernel/equipment.test.c b/src/kernel/equipment.test.c index 66872af0e..54bdc113f 100644 --- a/src/kernel/equipment.test.c +++ b/src/kernel/equipment.test.c @@ -1,10 +1,10 @@ #include -#include +#include "magic.h" + #include #include #include -#include #include #include diff --git a/src/kernel/faction.test.c b/src/kernel/faction.test.c index b59a46f63..34adf3ea0 100644 --- a/src/kernel/faction.test.c +++ b/src/kernel/faction.test.c @@ -2,7 +2,6 @@ #include #include -#include #include #include #include diff --git a/src/kernel/item.test.c b/src/kernel/item.test.c index 8d4285a54..a99749ec7 100644 --- a/src/kernel/item.test.c +++ b/src/kernel/item.test.c @@ -1,6 +1,5 @@ #include -#include #include #include #include diff --git a/src/kernel/pool.test.c b/src/kernel/pool.test.c index e6594bfac..9135c0bf8 100644 --- a/src/kernel/pool.test.c +++ b/src/kernel/pool.test.c @@ -1,5 +1,4 @@ #include -#include #include "ally.h" #include "pool.h" diff --git a/src/kernel/ship.test.c b/src/kernel/ship.test.c index 3b8108fca..86d0b8597 100644 --- a/src/kernel/ship.test.c +++ b/src/kernel/ship.test.c @@ -1,7 +1,6 @@ #include #include -#include #include #include #include diff --git a/src/kernel/spell.test.c b/src/kernel/spell.test.c index a75a5f377..7a10edd21 100644 --- a/src/kernel/spell.test.c +++ b/src/kernel/spell.test.c @@ -1,7 +1,6 @@ #include #include -#include #include #include diff --git a/src/kernel/spellbook.test.c b/src/kernel/spellbook.test.c index 4e4bfe779..f11f77c75 100644 --- a/src/kernel/spellbook.test.c +++ b/src/kernel/spellbook.test.c @@ -1,7 +1,5 @@ #include -#include -#include #include #include #include diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 100c4dd1b..a99023919 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -18,7 +18,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -#include #include "unit.h" #include "building.h" diff --git a/src/keyword.test.c b/src/keyword.test.c index 3f6828c76..66f5c84c6 100644 --- a/src/keyword.test.c +++ b/src/keyword.test.c @@ -1,5 +1,4 @@ #include -#include "kernel/types.h" #include "kernel/config.h" #include "kernel/order.h" #include "keyword.h" diff --git a/src/laws.c b/src/laws.c index 8128a5eb9..a64cda300 100755 --- a/src/laws.c +++ b/src/laws.c @@ -45,7 +45,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include #include #include diff --git a/src/laws.test.c b/src/laws.test.c index 6549d1bf6..65b360f6f 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -1,5 +1,4 @@ #include -#include #include "laws.h" #include diff --git a/src/kernel/magic.c b/src/magic.c similarity index 99% rename from src/kernel/magic.c rename to src/magic.c index 04e3adc51..5a4cc6404 100644 --- a/src/kernel/magic.c +++ b/src/magic.c @@ -19,7 +19,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -#include #include "magic.h" #include "skill.h" diff --git a/src/kernel/magic.h b/src/magic.h similarity index 99% rename from src/kernel/magic.h rename to src/magic.h index 00a752cf3..03aee8fcb 100644 --- a/src/kernel/magic.h +++ b/src/magic.h @@ -18,6 +18,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef H_KRNL_MAGIC #define H_KRNL_MAGIC + +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/kernel/magic.test.c b/src/magic.test.c similarity index 99% rename from src/kernel/magic.test.c rename to src/magic.test.c index 3f134016f..300f8cd88 100644 --- a/src/kernel/magic.test.c +++ b/src/magic.test.c @@ -1,9 +1,9 @@ #include -#include +#include "magic.h" + #include #include -#include #include #include #include diff --git a/src/main.c b/src/main.c index 32a68d071..10cb2c002 100644 --- a/src/main.c +++ b/src/main.c @@ -20,7 +20,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -#include #include #include #include "eressea.h" diff --git a/src/market.test.c b/src/market.test.c index 3670dd4f3..bb2c682ba 100644 --- a/src/market.test.c +++ b/src/market.test.c @@ -1,5 +1,4 @@ #include -#include #include "market.h" #include "tests.h" diff --git a/src/modules/arena.c b/src/modules/arena.c index 7ec4a91bd..ff752a5a4 100644 --- a/src/modules/arena.c +++ b/src/modules/arena.c @@ -32,7 +32,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include #include #include diff --git a/src/modules/score.c b/src/modules/score.c index a6b49dc58..5bad3ab68 100644 --- a/src/modules/score.c +++ b/src/modules/score.c @@ -26,7 +26,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include #include #include diff --git a/src/move.c b/src/move.c index 93c595a34..4a9bd7ba7 100644 --- a/src/move.c +++ b/src/move.c @@ -32,7 +32,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include #include #include diff --git a/src/move.test.c b/src/move.test.c index 83c7c7066..cc2571f7b 100644 --- a/src/move.test.c +++ b/src/move.test.c @@ -1,4 +1,3 @@ -#include #include #include #include "move.h" diff --git a/src/names.c b/src/names.c index 264beee3c..1fb61930f 100644 --- a/src/names.c +++ b/src/names.c @@ -24,7 +24,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include #include #include diff --git a/src/randenc.c b/src/randenc.c index d52ba1fa8..e4bd79c46 100644 --- a/src/randenc.c +++ b/src/randenc.c @@ -31,7 +31,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include #include #include diff --git a/src/reports.h b/src/reports.h index ea488f80d..cb4ab54f3 100644 --- a/src/reports.h +++ b/src/reports.h @@ -21,6 +21,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include +#include #ifdef __cplusplus extern "C" { diff --git a/src/reports.test.c b/src/reports.test.c index a757183e7..5f9ce5ae0 100644 --- a/src/reports.test.c +++ b/src/reports.test.c @@ -1,5 +1,4 @@ #include -#include #include "reports.h" #include diff --git a/src/skill.test.c b/src/skill.test.c index 48b293e04..08235cf89 100644 --- a/src/skill.test.c +++ b/src/skill.test.c @@ -1,5 +1,4 @@ #include -#include "kernel/types.h" #include "skill.h" #include "util/language.h" #include "tests.h" diff --git a/src/spells.c b/src/spells.c index 07b4ab0c3..daf114640 100644 --- a/src/spells.c +++ b/src/spells.c @@ -13,7 +13,6 @@ */ #include -#include #include #include "spy.h" @@ -38,7 +37,6 @@ #include #include #include -#include #include #include #include diff --git a/src/spells/alp.c b/src/spells/alp.c index 0f2901d79..82cf8c02f 100644 --- a/src/spells/alp.c +++ b/src/spells/alp.c @@ -17,7 +17,6 @@ #include #include -#include #include #include #include diff --git a/src/spells/borders.c b/src/spells/borders.c index b1288b60a..ec64d8692 100644 --- a/src/spells/borders.c +++ b/src/spells/borders.c @@ -1,5 +1,4 @@ #include -#include #include "borders.h" diff --git a/src/spells/combatspells.c b/src/spells/combatspells.c index 16bc4b71a..cb17fac85 100644 --- a/src/spells/combatspells.c +++ b/src/spells/combatspells.c @@ -11,7 +11,6 @@ */ #include #include -#include #include "combatspells.h" /* kernel includes */ @@ -20,7 +19,6 @@ #include #include #include -#include #include #include #include diff --git a/src/spells/regioncurse.c b/src/spells/regioncurse.c index 5a2d9a5a6..71138ac2b 100644 --- a/src/spells/regioncurse.c +++ b/src/spells/regioncurse.c @@ -14,10 +14,10 @@ #include #include #include "regioncurse.h" +#include "magic.h" /* kernel includes */ #include -#include #include #include #include diff --git a/src/spy.c b/src/spy.c index cdf393f81..00616a47e 100644 --- a/src/spy.c +++ b/src/spy.c @@ -26,7 +26,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* kernel includes */ #include #include -#include #include #include #include diff --git a/src/study.c b/src/study.c index f0686c766..6bc889a59 100644 --- a/src/study.c +++ b/src/study.c @@ -29,7 +29,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include #include #include diff --git a/src/tests.c b/src/tests.c index ebd8c7bf4..db9bcbc69 100644 --- a/src/tests.c +++ b/src/tests.c @@ -1,5 +1,4 @@ #include -#include #include "tests.h" #include "keyword.h" diff --git a/src/triggers/clonedied.c b/src/triggers/clonedied.c index e8b28f054..898597cbf 100644 --- a/src/triggers/clonedied.c +++ b/src/triggers/clonedied.c @@ -20,9 +20,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include "clonedied.h" +#include "magic.h" + /* kernel includes */ #include -#include #include /* util includes */ diff --git a/src/triggers/shock.c b/src/triggers/shock.c index 874c6d22b..09c3d488c 100644 --- a/src/triggers/shock.c +++ b/src/triggers/shock.c @@ -20,10 +20,11 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include "shock.h" +#include "magic.h" + /* kernel includes */ #include #include -#include #include #include #include diff --git a/src/upkeep.c b/src/upkeep.c index d105baed0..c807ec1d1 100644 --- a/src/upkeep.c +++ b/src/upkeep.c @@ -1,7 +1,6 @@ #include #include "upkeep.h" -#include #include #include #include From 27f94783bc97bd9565b22c8a8e40a9457e34d3c8 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 1 Nov 2014 13:10:22 +0100 Subject: [PATCH 8/9] fix gcc build, forward-declare structs in the header. MSVC allows structs to be declared in a function signature, gcc wants to know about them earlier. --- src/alchemy.h | 6 +++++ src/gmtool.h | 10 +++++--- src/kernel/connection.h | 7 ++++++ src/kernel/equipment.h | 54 +++++++++++++++++++++-------------------- src/kernel/item.h | 16 ++++++------ src/kernel/plane.h | 4 +++ src/kernel/pool.h | 4 +++ src/kernel/save.h | 7 ++++++ src/kernel/spell.h | 9 ++++++- src/laws.h | 27 +++++++++++++-------- src/move.h | 2 ++ src/spells/shipcurse.h | 22 ++++++++++------- 12 files changed, 111 insertions(+), 57 deletions(-) diff --git a/src/alchemy.h b/src/alchemy.h index af7adf459..46feeb689 100644 --- a/src/alchemy.h +++ b/src/alchemy.h @@ -23,6 +23,12 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. extern "C" { #endif + struct potion_type; + struct unit; + struct region; + struct item_type; + struct order; + enum { /* Stufe 1 */ P_FAST, diff --git a/src/gmtool.h b/src/gmtool.h index 0359973b5..4e3570de2 100644 --- a/src/gmtool.h +++ b/src/gmtool.h @@ -14,10 +14,12 @@ #ifdef __cplusplus extern "C" { #endif - struct lua_State; - struct selection; - struct state; - struct region; + + struct lua_State; + struct selection; + struct state; + struct region; + struct terrain_type; int gmmain(int argc, char *argv[]); int curses_readline(struct lua_State *L, char *buffer, size_t size, diff --git a/src/kernel/connection.h b/src/kernel/connection.h index edbf23bb5..dd168b413 100644 --- a/src/kernel/connection.h +++ b/src/kernel/connection.h @@ -25,6 +25,13 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. extern "C" { #endif + struct attrib; + struct attrib_type; + struct faction; + struct region; + struct storage; + struct unit; + extern int nextborder; typedef struct connection { diff --git a/src/kernel/equipment.h b/src/kernel/equipment.h index 9eee8b5d8..619b05193 100644 --- a/src/kernel/equipment.h +++ b/src/kernel/equipment.h @@ -24,34 +24,36 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifdef __cplusplus extern "C" { #endif - struct spell; + struct spell; + struct item; + struct unit; - typedef struct itemdata { - const struct item_type *itype; - char *value; - struct itemdata *next; - } itemdata; - - typedef struct subsetitem { - struct equipment *set; - float chance; - } subsetitem; - - typedef struct subset { - float chance; - subsetitem *sets; - } subset; - - typedef struct equipment { - char *name; - struct itemdata *items; - char *skills[MAXSKILLS]; - struct spellbook *spellbook; - struct subset *subsets; - struct equipment *next; - void (*callback) (const struct equipment *, struct unit *); - } equipment; + typedef struct itemdata { + const struct item_type *itype; + char *value; + struct itemdata *next; + } itemdata; + typedef struct subsetitem { + struct equipment *set; + float chance; + } subsetitem; + + typedef struct subset { + float chance; + subsetitem *sets; + } subset; + + typedef struct equipment { + char *name; + struct itemdata *items; + char *skills[MAXSKILLS]; + struct spellbook *spellbook; + struct subset *subsets; + struct equipment *next; + void (*callback) (const struct equipment *, struct unit *); + } equipment; + extern struct equipment *create_equipment(const char *eqname); extern struct equipment *get_equipment(const char *eqname); diff --git a/src/kernel/item.h b/src/kernel/item.h index bbb2653ad..790911ba6 100644 --- a/src/kernel/item.h +++ b/src/kernel/item.h @@ -26,13 +26,15 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. extern "C" { #endif - struct unit; - struct attrib; - struct attrib_type; - struct region; - struct resource_type; - struct locale; - struct troop; + struct unit; + struct attrib; + struct attrib_type; + struct region; + struct resource_type; + struct locale; + struct troop; + struct item; + struct order; typedef struct item { struct item *next; diff --git a/src/kernel/plane.h b/src/kernel/plane.h index 1c7e505dc..e28e67266 100644 --- a/src/kernel/plane.h +++ b/src/kernel/plane.h @@ -22,6 +22,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. extern "C" { #endif + struct region; + struct plane; + struct storage; + #define PFL_NOCOORDS 1 /* not in use */ #define PFL_NORECRUITS 2 #define PFL_NOALLIANCES 4 diff --git a/src/kernel/pool.h b/src/kernel/pool.h index d6f4766c6..6c47a5c14 100644 --- a/src/kernel/pool.h +++ b/src/kernel/pool.h @@ -22,6 +22,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. extern "C" { #endif + struct unit; + struct resource_type; + struct region; + /* bitfield values for get/use/change operations */ #define GET_SLACK 0x01 #define GET_RESERVE 0x02 diff --git a/src/kernel/save.h b/src/kernel/save.h index 775624f11..2c119a5eb 100644 --- a/src/kernel/save.h +++ b/src/kernel/save.h @@ -22,6 +22,13 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. extern "C" { #endif + struct attrib; + struct item; + struct storage; + struct spell; + struct spellbook; + struct unit; + typedef struct gamedata { struct storage *store; int version; diff --git a/src/kernel/spell.h b/src/kernel/spell.h index 40404b4d2..7d10df60b 100644 --- a/src/kernel/spell.h +++ b/src/kernel/spell.h @@ -22,7 +22,14 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. extern "C" { #endif - struct castorder; + struct castorder; + struct unit; + struct region; + struct spell; + struct spell_component; + struct quicklist; + struct attrib_type; + typedef int (*spell_f)(struct castorder * co); typedef void(*fumble_f)(const struct castorder * co); diff --git a/src/laws.h b/src/laws.h index 0d86c4225..8ab6ea469 100755 --- a/src/laws.h +++ b/src/laws.h @@ -22,17 +22,24 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. extern "C" { #endif - extern int writepasswd(void); - void demographics(void); - void update_guards(void); - void update_subscriptions(void); - void deliverMail(struct faction *f, struct region *r, struct unit *u, - const char *s, struct unit *receiver); + struct unit; + struct region; + struct building; + struct faction; + struct order; + struct attrib_type; - bool renamed_building(const struct building * b); - int rename_building(struct unit * u, struct order * ord, struct building * b, const char *name); - void get_food(struct region * r); - extern int can_contact(const struct region *r, const struct unit *u, const struct unit *u2); + int writepasswd(void); + void demographics(void); + void update_guards(void); + void update_subscriptions(void); + void deliverMail(struct faction *f, struct region *r, struct unit *u, + const char *s, struct unit *receiver); + + bool renamed_building(const struct building * b); + int rename_building(struct unit * u, struct order * ord, struct building * b, const char *name); + void get_food(struct region * r); + int can_contact(const struct region *r, const struct unit *u, const struct unit *u2); /* eressea-specific. put somewhere else, please. */ void processorders(void); diff --git a/src/move.h b/src/move.h index 4b0a9e4c7..27704d4a4 100644 --- a/src/move.h +++ b/src/move.h @@ -26,6 +26,8 @@ extern "C" { #endif struct unit; + struct region; + struct region_list; struct ship; struct building_type; diff --git a/src/spells/shipcurse.h b/src/spells/shipcurse.h index ab60d7232..551d1a920 100644 --- a/src/spells/shipcurse.h +++ b/src/spells/shipcurse.h @@ -20,15 +20,19 @@ extern "C" { #endif - struct locale; - struct message; - extern struct message *cinfo_ship(const void *obj, objtype_t typ, - const struct curse *c, int self); - extern void register_shipcurse(void); - extern struct curse *shipcurse_flyingship(struct ship *sh, struct unit *mage, - float power, int duration); - int levitate_ship(struct ship *sh, struct unit *mage, float power, - int duration); + struct locale; + struct message; + struct ship; + struct unit; + struct curse; + + struct message *cinfo_ship(const void *obj, objtype_t typ, + const struct curse *c, int self); + void register_shipcurse(void); + struct curse *shipcurse_flyingship(struct ship *sh, struct unit *mage, + float power, int duration); + int levitate_ship(struct ship *sh, struct unit *mage, float power, + int duration); #ifdef __cplusplus } From 59c1c2332485861e2b19f412321e8dda4a43cc8f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 1 Nov 2014 18:34:53 +0100 Subject: [PATCH 9/9] refactor config.c, move the find* functions into the modules they belong to. --- src/battle.c | 28 -------------- src/creation.c | 2 +- src/kernel/config.c | 90 -------------------------------------------- src/kernel/config.h | 24 +++--------- src/kernel/faction.c | 34 +++++++++++++++++ src/kernel/faction.h | 4 ++ src/kernel/unit.c | 33 ++++++++++++++++ src/kernel/unit.h | 13 +++++-- src/laws.c | 28 ++++++++++++++ src/laws.h | 1 + 10 files changed, 116 insertions(+), 141 deletions(-) diff --git a/src/battle.c b/src/battle.c index 7b2bc236b..a5e553f2e 100644 --- a/src/battle.c +++ b/src/battle.c @@ -210,34 +210,6 @@ static void message_faction(battle * b, faction * f, struct message *m) add_message(&f->battles->msgs, m); } -int armedmen(const unit * u, bool siege_weapons) -{ - item *itm; - int n = 0; - if (!(urace(u)->flags & RCF_NOWEAPONS)) { - if (effskill(u, SK_WEAPONLESS) >= 1) { - /* kann ohne waffen bewachen: fuer drachen */ - n = u->number; - } - else { - /* alle Waffen werden gezaehlt, und dann wird auf die Anzahl - * Personen minimiert */ - for (itm = u->items; itm; itm = itm->next) { - const weapon_type *wtype = resource2weapon(itm->type->rtype); - if (wtype == NULL || (!siege_weapons && (wtype->flags & WTF_SIEGE))) - continue; - if (effskill(u, wtype->skill) >= wtype->minskill) - n += itm->number; - /* if (effskill(u, wtype->skill) >= wtype->minskill) n += itm->number; */ - if (n > u->number) - break; - } - n = _min(n, u->number); - } - } - return n; -} - void message_all(battle * b, message * m) { bfaction *bf; diff --git a/src/creation.c b/src/creation.c index f8e0ae502..7cf540f30 100644 --- a/src/creation.c +++ b/src/creation.c @@ -1,5 +1,5 @@ /* -Copyright (c) 1998-2010, Enno Rehling +Copyright (c) 1998-2014, Enno Rehling Katja Zedel diff --git a/src/kernel/config.c b/src/kernel/config.c index 1cff32930..b2889af8a 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -520,34 +520,6 @@ int shipspeed(const ship * sh, const unit * u) return (int)k; } -#define FMAXHASH 2039 -faction *factionhash[FMAXHASH]; - -void fhash(faction * f) -{ - int index = f->no % FMAXHASH; - f->nexthash = factionhash[index]; - factionhash[index] = f; -} - -void funhash(faction * f) -{ - int index = f->no % FMAXHASH; - faction **fp = factionhash + index; - while (*fp && (*fp) != f) - fp = &(*fp)->nexthash; - *fp = f->nexthash; -} - -static faction *ffindhash(int no) -{ - int index = no % FMAXHASH; - faction *f = factionhash[index]; - while (f && f->no != no) - f = f->nexthash; - return f; -} - /* ----------------------------------------------------------------------- */ void verify_data(void) @@ -633,29 +605,6 @@ unsigned int atoip(const char *s) return n; } -region *findunitregion(const unit * su) -{ -#ifndef SLOW_REGION - return su->region; -#else - region *r; - const unit *u; - - for (r = regions; r; r = r->next) { - for (u = r->units; u; u = u->next) { - if (su == u) { - return r; - } - } - } - - /* This should never happen */ - assert(!"Die unit wurde nicht gefunden"); - - return (region *) NULL; -#endif -} - bool unit_has_cursed_item(unit * u) { item *itm = u->items; @@ -1036,50 +985,11 @@ param_t getparam(const struct locale * lang) return s ? findparam(s, lang) : NOPARAM; } -faction *findfaction(int n) -{ - faction *f = ffindhash(n); - return f; -} - faction *getfaction(void) { return findfaction(getid()); } -unit *findunitr(const region * r, int n) -{ - unit *u; - - /* findunit regional! */ - - for (u = r->units; u; u = u->next) - if (u->no == n) - return u; - - return 0; -} - -unit *findunit(int n) -{ - if (n <= 0) { - return NULL; - } - return ufindhash(n); -} - -unit *findunitg(int n, const region * hint) -{ - - /* Abfangen von Syntaxfehlern. */ - if (n <= 0) - return NULL; - - /* findunit global! */ - hint = 0; - return ufindhash(n); -} - unit *getnewunit(const region * r, const faction * f) { int n; diff --git a/src/kernel/config.h b/src/kernel/config.h index 95da6ba63..570d7c953 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -102,11 +102,6 @@ extern "C" { #define i2b(i) ((bool)((i)?(true):(false))) - typedef struct strlist { - struct strlist *next; - char *s; - } strlist; - #define fval(u, i) ((u)->flags & (i)) #define fset(u, i) ((u)->flags |= (i)) #define freset(u, i) ((u)->flags &= ~(i)) @@ -126,9 +121,13 @@ extern "C" { /* special units */ void make_undead_unit(struct unit *); - void addstrlist(strlist ** SP, const char *s); + typedef struct strlist { + struct strlist *next; + char *s; + } strlist; - int armedmen(const struct unit *u, bool siege_weapons); + void addstrlist(strlist ** SP, const char *s); + void freestrlist(strlist * s); unsigned int atoip(const char *s); unsigned int getuint(void); @@ -179,15 +178,8 @@ extern "C" { int alliedgroup(const struct plane *pl, const struct faction *f, const struct faction *f2, const struct ally *sf, int mode); - struct faction *findfaction(int n); struct faction *getfaction(void); - struct unit *findunitg(int n, const struct region *hint); - struct unit *findunit(int n); - - struct unit *findunitr(const struct region *r, int n); - struct region *findunitregion(const struct unit *su); - char *estring(const char *s); char *estring_i(char *s); char *cstring(const char *s); @@ -240,7 +232,6 @@ extern "C" { * sonst großes Unglück. Durch asserts an ein paar Stellen abgesichert. */ void verify_data(void); - void freestrlist(strlist * s); int change_hitpoints(struct unit *u, int value); @@ -251,9 +242,6 @@ extern "C" { struct region *firstregion(struct faction *f); struct region *lastregion(struct faction *f); - void fhash(struct faction *f); - void funhash(struct faction *f); - bool idle(struct faction *f); bool unit_has_cursed_item(struct unit *u); diff --git a/src/kernel/faction.c b/src/kernel/faction.c index 5cb152e47..b1adb70eb 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -99,6 +99,40 @@ void free_faction(faction * f) freelist(f->ursprung); } +#define FMAXHASH 2039 +faction *factionhash[FMAXHASH]; + +void fhash(faction * f) +{ + int index = f->no % FMAXHASH; + f->nexthash = factionhash[index]; + factionhash[index] = f; +} + +void funhash(faction * f) +{ + int index = f->no % FMAXHASH; + faction **fp = factionhash + index; + while (*fp && (*fp) != f) + fp = &(*fp)->nexthash; + *fp = f->nexthash; +} + +static faction *ffindhash(int no) +{ + int index = no % FMAXHASH; + faction *f = factionhash[index]; + while (f && f->no != no) + f = f->nexthash; + return f; +} + +faction *findfaction(int n) +{ + faction *f = ffindhash(n); + return f; +} + void set_show_item(faction * f, const struct item_type *itype) { attrib *a = a_add(&f->attribs, a_new(&at_showitem)); diff --git a/src/kernel/faction.h b/src/kernel/faction.h index 92878ceef..25d8f20b5 100644 --- a/src/kernel/faction.h +++ b/src/kernel/faction.h @@ -112,6 +112,10 @@ typedef struct faction { extern struct faction *factions; +void fhash(struct faction *f); +void funhash(struct faction *f); + +struct faction *findfaction(int n); struct faction *get_monsters(void); struct faction *get_or_create_monsters(void); int max_magicians(const faction * f); diff --git a/src/kernel/unit.c b/src/kernel/unit.c index a99023919..affd4471d 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -72,6 +72,39 @@ attrib_type at_creator = { /* Rest ist NULL; temporaeres, nicht alterndes Attribut */ }; +unit *findunitr(const region * r, int n) +{ + unit *u; + + /* findunit regional! */ + + for (u = r->units; u; u = u->next) + if (u->no == n) + return u; + + return 0; +} + +unit *findunit(int n) +{ + if (n <= 0) { + return NULL; + } + return ufindhash(n); +} + +unit *findunitg(int n, const region * hint) +{ + + /* Abfangen von Syntaxfehlern. */ + if (n <= 0) + return NULL; + + /* findunit global! */ + hint = 0; + return ufindhash(n); +} + #define UMAXHASH MAXUNITS static unit *unithash[UMAXHASH]; static unit *delmarker = (unit *)unithash; /* a funny hack */ diff --git a/src/kernel/unit.h b/src/kernel/unit.h index a3db732dd..6a089d2d4 100644 --- a/src/kernel/unit.h +++ b/src/kernel/unit.h @@ -114,6 +114,7 @@ extern "C" { int wants; /* enno: attribut? */ } unit; + extern struct attrib_type at_creator; extern struct attrib_type at_alias; extern struct attrib_type at_siege; extern struct attrib_type at_target; @@ -216,9 +217,9 @@ extern "C" { int number, const struct race *rc, int id, const char *dname, struct unit *creator); - extern void uhash(struct unit *u); - extern void uunhash(struct unit *u); - extern struct unit *ufindhash(int i); + void uhash(struct unit *u); + void uunhash(struct unit *u); + struct unit *ufindhash(int i); const char *unit_getname(const struct unit *u); void unit_setname(struct unit *u, const char *name); @@ -241,7 +242,11 @@ extern "C" { void remove_empty_units_in_region(struct region * r); void remove_empty_units(void); - extern struct attrib_type at_creator; + struct unit *findunitg(int n, const struct region *hint); + struct unit *findunit(int n); + + struct unit *findunitr(const struct region *r, int n); + #ifdef __cplusplus } #endif diff --git a/src/laws.c b/src/laws.c index a64cda300..474f37299 100755 --- a/src/laws.c +++ b/src/laws.c @@ -4182,6 +4182,34 @@ void process(void) } +int armedmen(const unit * u, bool siege_weapons) +{ + item *itm; + int n = 0; + if (!(urace(u)->flags & RCF_NOWEAPONS)) { + if (effskill(u, SK_WEAPONLESS) >= 1) { + /* kann ohne waffen bewachen: fuer drachen */ + n = u->number; + } + else { + /* alle Waffen werden gezaehlt, und dann wird auf die Anzahl + * Personen minimiert */ + for (itm = u->items; itm; itm = itm->next) { + const weapon_type *wtype = resource2weapon(itm->type->rtype); + if (wtype == NULL || (!siege_weapons && (wtype->flags & WTF_SIEGE))) + continue; + if (effskill(u, wtype->skill) >= wtype->minskill) + n += itm->number; + /* if (effskill(u, wtype->skill) >= wtype->minskill) n += itm->number; */ + if (n > u->number) + break; + } + n = _min(n, u->number); + } + } + return n; +} + int siege_cmd(unit * u, order * ord) { region *r = u->region; diff --git a/src/laws.h b/src/laws.h index 8ab6ea469..02fdc6c09 100755 --- a/src/laws.h +++ b/src/laws.h @@ -99,6 +99,7 @@ extern "C" { int modifier); bool seefaction(const struct faction *f, const struct region *r, const struct unit *u, int modifier); + int armedmen(const struct unit *u, bool siege_weapons); #ifdef __cplusplus