From 49ccb3825fc344b5a6a26591c5dccb1c65cb67ca Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 11 Sep 2016 15:54:03 +0200 Subject: [PATCH 1/3] test and cache all the rules! --- src/kernel/config.c | 25 +++++++++++++++++++------ src/kernel/config.test.c | 20 ++++++++++++++++++++ 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/kernel/config.c b/src/kernel/config.c index 135df78c5..d78362f3c 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -867,21 +867,29 @@ bool rule_stealth_other(void) bool rule_stealth_anon(void) { - int rule = config_get_int("stealth.faction.anon", 1); + static int rule, config; + if (config_changed(&config)) { + rule = config_get_int("stealth.faction.anon", 1); + } return rule != 0; } bool rule_region_owners(void) { - int rule = config_get_int("rules.region_owners", 0); + static int rule, config; + if (config_changed(&config)) { + rule = config_get_int("rules.region_owners", 0); + } return rule != 0; } int rule_blessed_harvest(void) { - int rule = config_get_int("rules.blessed_harvest.flags", - HARVEST_WORK); - assert(rule >= 0); + static int rule, config; + if (config_changed(&config)) { + rule = config_get_int("rules.blessed_harvest.flags", HARVEST_WORK); + assert(rule >= 0); + } return rule; } @@ -1053,7 +1061,12 @@ int entertainmoney(const region * r) int rule_give(void) { - return config_get_int("rules.give.flags", GIVE_DEFAULT); + static int config; + static int rule; + if (config_changed(&config)) { + rule = config_get_int("rules.give.flags", GIVE_DEFAULT); + } + return rule; } bool markets_module(void) diff --git a/src/kernel/config.test.c b/src/kernel/config.test.c index c8fc84a1a..405587443 100644 --- a/src/kernel/config.test.c +++ b/src/kernel/config.test.c @@ -204,6 +204,26 @@ static void test_config_cache(CuTest *tc) { } static void test_rules(CuTest *tc) { + CuAssertIntEquals(tc, HARVEST_WORK, rule_blessed_harvest()); + config_set("rules.blessed_harvest.flags", "15"); + CuAssertIntEquals(tc, 15, rule_blessed_harvest()); + + CuAssertTrue(tc, !rule_region_owners()); + config_set("rules.region_owners", "1"); + CuAssertTrue(tc, rule_region_owners()); + + CuAssertTrue(tc, rule_stealth_anon()); + config_set("stealth.faction.anon", "0"); + CuAssertTrue(tc, !rule_stealth_anon()); + + CuAssertTrue(tc, rule_stealth_other()); + config_set("stealth.faction.other", "0"); + CuAssertTrue(tc, !rule_stealth_other()); + + CuAssertIntEquals(tc, GIVE_DEFAULT, rule_give()); + config_set("rules.give.flags", "15"); + CuAssertIntEquals(tc, 15, rule_give()); + CuAssertIntEquals(tc, 0, rule_alliance_limit()); config_set("rules.limit.alliance", "1"); CuAssertIntEquals(tc, 1, rule_alliance_limit()); From 402c19d8fc4bde1db22a067aa5893c3fa06e287d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 11 Sep 2016 16:35:55 +0200 Subject: [PATCH 2/3] dn't warn new player about NMR. newbie info text was no longer valid. --- conf/e2/config.xml | 2 +- conf/e3/config.xml | 2 +- conf/e4/config.xml | 2 +- res/eressea/strings.xml | 8 +------- src/kernel/faction.c | 1 + src/kernel/faction.h | 4 +--- src/kernel/faction.test.c | 2 +- src/report.c | 9 ++------- 8 files changed, 9 insertions(+), 21 deletions(-) diff --git a/conf/e2/config.xml b/conf/e2/config.xml index 5516fd601..f7f227824 100644 --- a/conf/e2/config.xml +++ b/conf/e2/config.xml @@ -57,7 +57,7 @@ eressea-server@eressea.de eressea-server@eressea.de - + Bitte denke daran, deine Befehle mit dem Betreff ERESSEA 2 BEFEHLE an eressea-server@eressea.de zu senden. Remember to send your orders to diff --git a/conf/e3/config.xml b/conf/e3/config.xml index 04af3858d..d337ead42 100644 --- a/conf/e3/config.xml +++ b/conf/e3/config.xml @@ -49,7 +49,7 @@ eressea-server@eressea.de eressea-server@eressea.de - + Bitte denke daran, deine Befehle mit dem Betreff ERESSEA 3 BEFEHLE an eressea-server@eressea.de zu senden. Remember to send your orders to diff --git a/conf/e4/config.xml b/conf/e4/config.xml index 2def4f1a8..5c99f7d7e 100644 --- a/conf/e4/config.xml +++ b/conf/e4/config.xml @@ -50,7 +50,7 @@ eressea-server@eressea.de eressea-server@eressea.de - + Bitte denke daran, deine Befehle mit dem Betreff ERESSEA 4 BEFEHLE an eressea-server@eressea.de zu senden. Remember to send your orders to diff --git a/res/eressea/strings.xml b/res/eressea/strings.xml index b7db0eb4b..61a35ebe5 100644 --- a/res/eressea/strings.xml +++ b/res/eressea/strings.xml @@ -268,13 +268,7 @@ Muscheln seashells - - - Die ersten beiden Züge mußt du abgeben, sonst wird deine - Partei sofort wieder gelöscht, um Karteileichen zu vermeiden. - If you fail to send in orders for one of the first two turns, your faction will be erased from the game to reduce the number of inactive players in Eressea. - - + Mit der ersten Auswertung bekommst du einen Computerreport, den du mit vielen Tools wie z.B. Magellan benutzen kannst. Wenn du ihn weiterhin bekommen willst, gib einer deiner Einheiten den Befehl OPTION diff --git a/src/kernel/faction.c b/src/kernel/faction.c index 8ca5297b0..6e249bca7 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -261,6 +261,7 @@ faction *addfaction(const char *email, const char *password, f->magiegebiet = 0; f->locale = loc; f->subscription = subscription; + f->flags = FFL_ISNEW; f->options = want(O_REPORT) | want(O_ZUGVORLAGE) | want(O_COMPUTER) | want(O_COMPRESS) | diff --git a/src/kernel/faction.h b/src/kernel/faction.h index 5f7e1f91f..2cb2fc9f3 100644 --- a/src/kernel/faction.h +++ b/src/kernel/faction.h @@ -40,7 +40,6 @@ extern "C" { /* faction flags */ #define FFL_NEWID (1<<0) /* Die Partei hat bereits einmal ihre no gewechselt */ #define FFL_ISNEW (1<<1) -#define FFL_RESTART (1<<2) #define FFL_QUIT (1<<3) #define FFL_CURSED (1<<4) /* you're going to have a bad time */ #define FFL_DEFENDER (1<<10) @@ -52,8 +51,7 @@ extern "C" { * FL_MARK hinterher löschen) */ #define FFL_NOIDLEOUT (1<<24) /* Partei stirbt nicht an NMRs */ #define FFL_NPC (1<<25) /* eine Partei mit Monstern */ -#define FFL_DBENTRY (1<<28) /* Partei ist in Datenbank eingetragen */ -#define FFL_SAVEMASK (FFL_DEFENDER|FFL_NEWID|FFL_NPC|FFL_DBENTRY|FFL_NOIDLEOUT|FFL_CURSED) +#define FFL_SAVEMASK (FFL_DEFENDER|FFL_NEWID|FFL_NPC|FFL_NOIDLEOUT|FFL_CURSED) typedef struct faction { struct faction *next; diff --git a/src/kernel/faction.test.c b/src/kernel/faction.test.c index 0d7e7b877..f1917242c 100644 --- a/src/kernel/faction.test.c +++ b/src/kernel/faction.test.c @@ -117,7 +117,7 @@ static void test_addfaction(CuTest *tc) { CuAssertTrue(tc, checkpasswd(f, "hurrdurr")); CuAssertPtrEquals(tc, (void *)lang, (void *)f->locale); CuAssertIntEquals(tc, 1234, f->subscription); - CuAssertIntEquals(tc, 0, f->flags); + CuAssertIntEquals(tc, FFL_ISNEW, f->flags); CuAssertIntEquals(tc, 0, f->age); CuAssertTrue(tc, faction_alive(f)); CuAssertIntEquals(tc, M_GRAY, f->magiegebiet); diff --git a/src/report.c b/src/report.c index e77ee3038..be6c2273f 100644 --- a/src/report.c +++ b/src/report.c @@ -2106,19 +2106,14 @@ const char *charset) if (f->age <= 2) { const char *s; - s = locale_getstring(f->locale, "newbie_info_1"); - if (s) { - newline(out); - centre(out, s, true); - } - s = locale_getstring(f->locale, "newbie_info_2"); + s = locale_getstring(f->locale, "newbie_info_game"); if (s) { newline(out); centre(out, s, true); } if ((f->options & want(O_COMPUTER)) == 0) { f->options |= want(O_COMPUTER); - s = locale_getstring(f->locale, "newbie_info_3"); + s = locale_getstring(f->locale, "newbie_info_cr"); if (s) { newline(out); centre(out, s, true); From 0124bafdc4e36dd28924ad343f36adb259080dcf Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 11 Sep 2016 16:39:41 +0200 Subject: [PATCH 3/3] delete dead code --- scripts/tests/faction.lua | 2 +- src/battle.c | 22 +--------------------- src/bind_ship.c | 10 +--------- src/bind_unit.c | 22 ---------------------- src/main.c | 4 ---- src/report.c | 18 ------------------ 6 files changed, 3 insertions(+), 75 deletions(-) diff --git a/scripts/tests/faction.lua b/scripts/tests/faction.lua index f0cd9335c..38fdc4eb7 100644 --- a/scripts/tests/faction.lua +++ b/scripts/tests/faction.lua @@ -17,7 +17,7 @@ function setup() end function test_faction_flags() - assert_equal(0, f.flags) + assert_equal(2, f.flags) -- FFL_ISNEW f.flags = 42 assert_equal(42, f.flags) end diff --git a/src/battle.c b/src/battle.c index 4686a942a..392b24441 100644 --- a/src/battle.c +++ b/src/battle.c @@ -88,7 +88,6 @@ static FILE *bdebug; #define TDIFF_CHANGE 5 /* 5% höher pro Stufe */ #define DAMAGE_QUOTIENT 2 /* damage += skilldiff/DAMAGE_QUOTIENT */ -#undef DEBUG_FAST /* should be disabled when b->fast and b->rowcache works */ #define DEBUG_SELECT /* should be disabled if select_enemy works */ typedef enum combatmagic { @@ -205,12 +204,7 @@ static const char *sideabkz(side * s, bool truename) const faction *f = (s->stealthfaction && !truename) ? s->stealthfaction : s->faction; -#undef SIDE_ABKZ -#ifdef SIDE_ABKZ - abkz(f->name, sideabkz_buf, sizeof(sideabkz_buf), 3); -#else strlcpy(sideabkz_buf, itoa36(f->no), sizeof(sideabkz_buf)); -#endif return sideabkz_buf; } @@ -471,13 +465,7 @@ static int get_unitrow(const fighter * af, const side * vs) b->rowcache.result = get_row(af->side, row, vs); return b->rowcache.result; } -#ifdef DEBUG_FAST /* validation code */ - { - int i = get_row(af->side, row, vs); - assert(i == b->rowcache.result); - } -#endif - return b->rowcache.result; + return b->rowcache.result; } } @@ -1445,18 +1433,10 @@ int select) if (b->alive == b->fast.alive && as == b->fast.side && sr == b->fast.status && minrow == b->fast.minrow && maxrow == b->fast.maxrow) { if (b->fast.enemies[select] >= 0) { -#ifdef DEBUG_FAST - int i = count_enemies_i(b, af, minrow, maxrow, select); - assert(i == b->fast.enemies[select]); -#endif return b->fast.enemies[select]; } else if (select & SELECT_FIND) { if (b->fast.enemies[select - SELECT_FIND] >= 0) { -#ifdef DEBUG_FAST - int i = count_enemies_i(b, af, minrow, maxrow, select); - assert((i > 0) == (b->fast.enemies[select - SELECT_FIND] > 0)); -#endif return b->fast.enemies[select - SELECT_FIND]; } } diff --git a/src/bind_ship.c b/src/bind_ship.c index 22015f673..f1c1c412a 100644 --- a/src/bind_ship.c +++ b/src/bind_ship.c @@ -233,15 +233,7 @@ void tolua_ship_open(lua_State * L) tolua_variable(L, TOLUA_CAST "type", tolua_ship_get_type, 0); tolua_variable(L, TOLUA_CAST "damage", tolua_ship_get_damage, tolua_ship_set_damage); - -#ifdef TODO - .property("weight", &ship_getweight) - .property("capacity", &ship_getcapacity) - .property("maxsize", &ship_maxsize) - .def_readwrite("damage", &ship::damage) - .def_readwrite("size", &ship::size) -#endif - tolua_variable(L, TOLUA_CAST "objects", tolua_ship_get_objects, 0); + tolua_variable(L, TOLUA_CAST "objects", tolua_ship_get_objects, 0); tolua_function(L, TOLUA_CAST "create", tolua_ship_create); } diff --git a/src/bind_unit.c b/src/bind_unit.c index 353bd4667..a7ba3fe96 100755 --- a/src/bind_unit.c +++ b/src/bind_unit.c @@ -767,25 +767,6 @@ static int tolua_unit_get_spells(lua_State * L) return tolua_quicklist_push(L, "spellbook", "spell_entry", slist); } -#ifdef TODO /* spellbooks */ -static void unit_removespell(unit * u, spell * sp) -{ - quicklist **isptr; - - isptr = get_spelllist(get_mage(u), u->faction); - ql_set_remove(isptr, sp); -} - -static int tolua_unit_removespell(lua_State * L) -{ - unit *self = (unit *) tolua_tousertype(L, 1, 0); - spell *sp = (spell *) tolua_tousertype(L, 2, 0); - unit_removespell(self, sp); - return 0; -} - -#endif - static int tolua_unit_get_orders(lua_State * L) { unit *self = (unit *)tolua_tousertype(L, 1, 0); @@ -1019,9 +1000,6 @@ void tolua_unit_open(lua_State * L) tolua_variable(L, TOLUA_CAST "race_name", &tolua_unit_get_racename, &tolua_unit_set_racename); tolua_function(L, TOLUA_CAST "add_spell", &tolua_unit_addspell); -#ifdef TODO /* spellbooks */ - tolua_function(L, TOLUA_CAST "remove_spell", &tolua_unit_removespell); -#endif tolua_variable(L, TOLUA_CAST "spells", &tolua_unit_get_spells, 0); tolua_function(L, TOLUA_CAST "cast_spell", &tolua_unit_castspell); diff --git a/src/main.c b/src/main.c index 3748c2d49..d3d2cbe50 100644 --- a/src/main.c +++ b/src/main.c @@ -322,10 +322,6 @@ int main(int argc, char **argv) log_error("script %s failed with code %d\n", luafile, err); return err; } -#ifdef MSPACES - malloc_stats(); -#endif - game_done(); lua_done(L); log_close(); diff --git a/src/report.c b/src/report.c index be6c2273f..2c79209b9 100644 --- a/src/report.c +++ b/src/report.c @@ -2128,23 +2128,6 @@ const char *charset) RENDER(f, buf, sizeof(buf), ("nr_score", "score average", score, avg)); centre(out, buf, true); } -#ifdef COUNT_AGAIN - no_units = 0; - no_people = 0; - for (u = f->units; u; u = u->nextF) { - if (playerrace(u_race(u))) { - ++no_people; - no_units += u->number; - assert(f == u->faction); - } - } - if (no_units != f->no_units) { - f->no_units = no_units; - } - if (no_people != f->num_people) { - f->num_people = no_people; -} -#else no_units = count_units(f); no_people = count_all(f); if (f->flags & FFL_NPC) { @@ -2153,7 +2136,6 @@ const char *charset) else { no_people = f->num_people; } -#endif m = msg_message("nr_population", "population units limit", no_people, no_units, rule_faction_limit()); nr_render(m, f->locale, buf, sizeof(buf), f); msg_release(m);