From ef7b25226067876678f7e2a197805d0c2453e369 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 16 Nov 2015 14:31:53 +0100 Subject: [PATCH 1/8] fix intermittent test --- scripts/tests/e3/castles.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/tests/e3/castles.lua b/scripts/tests/e3/castles.lua index b32f80f5d..f061d1ea4 100644 --- a/scripts/tests/e3/castles.lua +++ b/scripts/tests/e3/castles.lua @@ -4,6 +4,7 @@ module("tests.e3.castles", package.seeall, lunit.testcase ) function setup() eressea.game.reset() + eressea.settings.set("rules.food.flags", "4") end function test_small_castles() From 8e4b9283a31affa7c88e54e0e9af43c8d36ffc20 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 16 Nov 2015 14:34:30 +0100 Subject: [PATCH 2/8] release version 3.7.2 --- src/buildno.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/buildno.h b/src/buildno.h index ecfc833e6..9dcd4a3e9 100644 --- a/src/buildno.h +++ b/src/buildno.h @@ -1,3 +1,3 @@ #define VERSION_MAJOR 3 #define VERSION_MINOR 7 -#define VERSION_BUILD 1 +#define VERSION_BUILD 2 From f0a47321d6b1fc71421e2703a8f3eeae2e4391de Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 21 Nov 2015 21:49:33 +0100 Subject: [PATCH 3/8] reduce log spam --- src/kernel/jsonconf.c | 2 +- src/util/umlaut.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/kernel/jsonconf.c b/src/kernel/jsonconf.c index 9efbc0250..a16cef76f 100644 --- a/src/kernel/jsonconf.c +++ b/src/kernel/jsonconf.c @@ -526,7 +526,7 @@ static void disable_feature(const char *str) { for (k = 0; k != MAXKEYWORDS; ++k) { // FIXME: this loop is slow as balls. if (strcmp(keywords[k], str) == 0) { - log_info("disable keyword %s\n", str); + log_debug("disable keyword %s\n", str); enable_keyword(k, false); return; } diff --git a/src/util/umlaut.c b/src/util/umlaut.c index 73a4195c2..872ad8ffd 100644 --- a/src/util/umlaut.c +++ b/src/util/umlaut.c @@ -260,7 +260,7 @@ int findtoken(const void * root, const char *key, variant * result) ref = ref->nexthash; str += len; if (!ref) { - log_info("findtoken | token not found '%s'\n", key); + log_debug("findtoken | token not found '%s'\n", key); return E_TOK_NOMATCH; } tk = ref->node; @@ -269,6 +269,6 @@ int findtoken(const void * root, const char *key, variant * result) *result = tk->id; return E_TOK_SUCCESS; } - log_info("findtoken | token not found '%s'\n", key); + log_debug("findtoken | token not found '%s'\n", key); return E_TOK_NOMATCH; } From c7ab0e8f59be7f0d187445f8cd8a7ea8c085adf3 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 23 Nov 2015 12:37:42 +0100 Subject: [PATCH 4/8] fix https://bugs.eressea.de/view.php?id=2164 (ships get no damage when they drift). simplify attack_chance configuration, set it only once. this way, I can more easily fudge it to 1.0 in the debugger. --- conf/e2/config.json | 1 - conf/e3/config.json | 1 - conf/e4/config.json | 1 - src/monsters.c | 19 +++++++------------ src/util/umlaut.c | 4 ++-- 5 files changed, 9 insertions(+), 17 deletions(-) diff --git a/conf/e2/config.json b/conf/e2/config.json index 6b11dceff..1ae7f77e5 100644 --- a/conf/e2/config.json +++ b/conf/e2/config.json @@ -23,7 +23,6 @@ "world.era": 2, "seed.population.min": 8, "seed.population.max": 8, - "rules.ship.damage_drift": 0.00, "rules.reserve.twophase": true, "rules.give.max_men": -1, "rules.check_overload": false, diff --git a/conf/e3/config.json b/conf/e3/config.json index a6685a06f..9e360de77 100644 --- a/conf/e3/config.json +++ b/conf/e3/config.json @@ -61,7 +61,6 @@ "rules.stealth.anon_battle": false, "rules.check_overload": false, "rules.combat.goblinbonus": 3, - "rules.ship.damage_drift": 0.00, "rules.alliances": true, "rules.combat.herospeed": 3, "rules.combat.demon_vampire": 5, diff --git a/conf/e4/config.json b/conf/e4/config.json index 90c60d72b..3b4bff30d 100644 --- a/conf/e4/config.json +++ b/conf/e4/config.json @@ -59,7 +59,6 @@ "rules.stealth.anon_battle": false, "rules.check_overload": false, "rules.combat.goblinbonus": 3, - "rules.ship.damage_drift": 0.00, "rules.alliances": true, "rules.combat.herospeed": 3, "rules.combat.demon_vampire": 5, diff --git a/src/monsters.c b/src/monsters.c index 0ab88fa61..432e4bb96 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -75,16 +75,14 @@ #define DRAGON_RANGE 20 /* Max. Distanz zum nächsten Drachenziel */ #define MAXILLUSION_TEXTS 3 +static double attack_chance; /* rules.monsters.attack_chance, or default 0.4 */ + static void give_peasants(unit *u, const item_type *itype, int reduce) { char buf[64]; slprintf(buf, sizeof(buf), "%s 0 %d %s", LOC(u->faction->locale, keyword(K_GIVE)), reduce, LOC(u->faction->locale, itype->rtype->_name)); unit_addorder(u, parse_order(buf, u->faction->locale)); } -static double monster_attack_chance(void) { - return get_param_flt(global.parameters, "rules.monsters.attack_chance", 0.4f); -} - static void reduce_weight(unit * u) { int capacity, weight = 0; @@ -160,7 +158,7 @@ static order *monster_attack(unit * u, const unit * target) static order *get_money_for_dragon(region * r, unit * u, int wanted) { int n; - bool attacks = monster_attack_chance() > 0.0; + bool attacks = attack_chance > 0.0; /* falls genug geld in der region ist, treiben wir steuern ein. */ if (rmoney(r) >= wanted) { @@ -759,14 +757,13 @@ static order *plan_dragon(unit * u) void plan_monsters(faction * f) { region *r; - double attack_chance = monster_attack_chance(); - + assert(f); + attack_chance = get_param_flt(global.parameters, "rules.monsters.attack_chance", 0.4); f->lastorders = turn; for (r = regions; r; r = r->next) { unit *u; - double rchance = attack_chance; bool attacking = false; for (u = r->units; u; u = u->next) { @@ -785,10 +782,8 @@ void plan_monsters(faction * f) produceexp(u, SK_PERCEPTION, u->number); } - if (rchance > 0.0) { - if (chance(rchance)) - attacking = true; - rchance = 0.0; + if (!attacking) { + if (chance(attack_chance)) attacking = true; } if (u->status > ST_BEHIND) { setstatus(u, ST_FIGHT); diff --git a/src/util/umlaut.c b/src/util/umlaut.c index 73a4195c2..872ad8ffd 100644 --- a/src/util/umlaut.c +++ b/src/util/umlaut.c @@ -260,7 +260,7 @@ int findtoken(const void * root, const char *key, variant * result) ref = ref->nexthash; str += len; if (!ref) { - log_info("findtoken | token not found '%s'\n", key); + log_debug("findtoken | token not found '%s'\n", key); return E_TOK_NOMATCH; } tk = ref->node; @@ -269,6 +269,6 @@ int findtoken(const void * root, const char *key, variant * result) *result = tk->id; return E_TOK_SUCCESS; } - log_info("findtoken | token not found '%s'\n", key); + log_debug("findtoken | token not found '%s'\n", key); return E_TOK_NOMATCH; } From b6a947ca0c190d5827af13c9d6349060252f992b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 23 Nov 2015 15:35:26 +0100 Subject: [PATCH 5/8] =?UTF-8?q?https://bugs.eressea.de/view.php=3Fid=3D216?= =?UTF-8?q?5=20Monster=20bewachten=20nicht,=20wenn=20sie=20nicht=20ausreic?= =?UTF-8?q?hend=20bewaffnet=20waren,=20weil=20der=20n=C3=B6tige=20Check=20?= =?UTF-8?q?nicht=20in=20can=5Fstart=5Fguarding=20gemacht=20wurde,=20sonder?= =?UTF-8?q?n=20in=20guard=5Fon=5Fcmd.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/laws.c | 31 ++++++++++++------------------- src/laws.test.c | 18 +++++++++++++++++- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/laws.c b/src/laws.c index 15c5404b4..f508c4b69 100755 --- a/src/laws.c +++ b/src/laws.c @@ -2673,13 +2673,12 @@ int combatspell_cmd(unit * u, struct order *ord) return 0; } -/* Beachten: einige Monster sollen auch unbewaffent die Region bewachen -* können */ guard_t can_start_guarding(const unit * u) { if (u->status >= ST_FLEE || fval(u, UFL_FLEEING)) return E_GUARD_FLEEING; - if (fval(u_race(u), RCF_UNARMEDGUARD)) + /* Monster der Monsterpartei dürfen immer bewachen */ + if (is_monsters(u->faction) || fval(u_race(u), RCF_UNARMEDGUARD)) return E_GUARD_OK; if (!armedmen(u, true)) return E_GUARD_UNARMED; @@ -2713,24 +2712,18 @@ int guard_on_cmd(unit * u, struct order *ord) cmistake(u, ord, 95, MSG_EVENT); } else { - /* Monster der Monsterpartei dürfen immer bewachen */ - if (is_monsters(u->faction)) { + int err = can_start_guarding(u); + if (err == E_GUARD_OK) { guard(u, GUARD_ALL); } - else { - int err = can_start_guarding(u); - if (err == E_GUARD_OK) { - guard(u, GUARD_ALL); - } - else if (err == E_GUARD_UNARMED) { - ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "unit_unarmed", "")); - } - else if (err == E_GUARD_FLEEING) { - cmistake(u, ord, 320, MSG_EVENT); - } - else if (err == E_GUARD_NEWBIE) { - cmistake(u, ord, 304, MSG_EVENT); - } + else if (err == E_GUARD_UNARMED) { + ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "unit_unarmed", "")); + } + else if (err == E_GUARD_FLEEING) { + cmistake(u, ord, 320, MSG_EVENT); + } + else if (err == E_GUARD_NEWBIE) { + cmistake(u, ord, 304, MSG_EVENT); } } } diff --git a/src/laws.test.c b/src/laws.test.c index e829eff27..daa67eb86 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -635,6 +635,7 @@ static void test_newbie_cannot_guard(CuTest *tc) { setup_guard(&fix, true); set_param(&global.parameters, "NewbieImmunity", "4"); CuAssertTrue(tc, IsImmune(fix.u->faction)); + CuAssertIntEquals(tc, E_GUARD_NEWBIE, can_start_guarding(fix.u)); update_guards(); CuAssertTrue(tc, !fval(fix.u, UFL_GUARD)); test_cleanup(); @@ -644,6 +645,7 @@ static void test_unarmed_cannot_guard(CuTest *tc) { guard_fixture fix; setup_guard(&fix, false); + CuAssertIntEquals(tc, E_GUARD_UNARMED, can_start_guarding(fix.u)); update_guards(); CuAssertTrue(tc, !fval(fix.u, UFL_GUARD)); test_cleanup(); @@ -656,6 +658,18 @@ static void test_unarmed_races_can_guard(CuTest *tc) { setup_guard(&fix, false); rc = rc_get_or_create(fix.u->_race->_name); rc->flags |= RCF_UNARMEDGUARD; + CuAssertIntEquals(tc, E_GUARD_OK, can_start_guarding(fix.u)); + update_guards(); + CuAssertTrue(tc, fval(fix.u, UFL_GUARD)); + test_cleanup(); +} + +static void test_monsters_can_guard(CuTest *tc) { + guard_fixture fix; + + setup_guard(&fix, false); + u_setfaction(fix.u, get_or_create_monsters()); + CuAssertIntEquals(tc, E_GUARD_OK, can_start_guarding(fix.u)); update_guards(); CuAssertTrue(tc, fval(fix.u, UFL_GUARD)); test_cleanup(); @@ -666,7 +680,7 @@ static void test_low_skill_cannot_guard(CuTest *tc) { setup_guard(&fix, true); set_level(fix.u, SK_MELEE, 1); - fix.u->status = ST_FLEE; + CuAssertIntEquals(tc, E_GUARD_UNARMED, can_start_guarding(fix.u)); update_guards(); CuAssertTrue(tc, !fval(fix.u, UFL_GUARD)); test_cleanup(); @@ -677,6 +691,7 @@ static void test_fleeing_cannot_guard(CuTest *tc) { setup_guard(&fix, true); fix.u->status = ST_FLEE; + CuAssertIntEquals(tc, E_GUARD_FLEEING, can_start_guarding(fix.u)); update_guards(); CuAssertTrue(tc, !fval(fix.u, UFL_GUARD)); test_cleanup(); @@ -1269,6 +1284,7 @@ CuSuite *get_laws_suite(void) SUITE_ADD_TEST(suite, test_newbie_cannot_guard); SUITE_ADD_TEST(suite, test_unarmed_cannot_guard); SUITE_ADD_TEST(suite, test_unarmed_races_can_guard); + SUITE_ADD_TEST(suite, test_monsters_can_guard); SUITE_ADD_TEST(suite, test_fleeing_cannot_guard); SUITE_ADD_TEST(suite, test_low_skill_cannot_guard); SUITE_ADD_TEST(suite, test_reserve_self); From defd870cd106a8cd2e5bfb738a5c2be1f55e2ca0 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 23 Nov 2015 16:48:05 +0100 Subject: [PATCH 6/8] https://bugs.eressea.de/view.php?id=2163 Fix order of Arguments when checking for defensive building. Solthar reminds us that good variable names are good. --- src/monsters.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/monsters.c b/src/monsters.c index 432e4bb96..d6deaaab1 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -155,7 +155,7 @@ static order *monster_attack(unit * u, const unit * target) return create_order(K_ATTACK, u->faction->locale, "%i", target->no); } -static order *get_money_for_dragon(region * r, unit * u, int wanted) +static order *get_money_for_dragon(region * r, unit * udragon, int wanted) { int n; bool attacks = attack_chance > 0.0; @@ -163,7 +163,7 @@ static order *get_money_for_dragon(region * r, unit * u, int wanted) /* falls genug geld in der region ist, treiben wir steuern ein. */ if (rmoney(r) >= wanted) { /* 5% chance, dass der drache aus einer laune raus attackiert */ - if (!attacks || chance(1.0 - u_race(u)->aggression)) { + if (!attacks || chance(1.0 - u_race(udragon)->aggression)) { /* Drachen haben in E3 und E4 keine Einnahmen. Neuer Befehl Pluendern erstmal nur fuer Monster?*/ return create_order(K_LOOT, default_locale, NULL); } @@ -172,15 +172,15 @@ static order *get_money_for_dragon(region * r, unit * u, int wanted) /* falls der drache launisch ist, oder das regionssilber knapp, greift er alle an * und holt sich Silber von Einheiten, vorausgesetzt er bewacht bereits */ n = 0; - if (attacks && is_guard(u, GUARD_TAX)) { - unit *u2; - for (u2 = r->units; u2; u2 = u2->next) { - if (u2->faction != u->faction && cansee(u->faction, r, u2, 0) && !in_safe_building(u, u2)) { - int m = get_money(u2); + if (attacks && is_guard(udragon, GUARD_TAX)) { + unit *u; + for (u = r->units; u; u = u->next) { + if (u->faction != udragon->faction && cansee(udragon->faction, r, u, 0) && !in_safe_building(u, udragon)) { + int m = get_money(u); if (m != 0) { - order *ord = monster_attack(u, u2); + order *ord = monster_attack(udragon, u); if (ord) { - addlist(&u->orders, ord); + addlist(&udragon->orders, ord); n += m; } } From 4b7b32cbb547a25445d26666b034449d2fabb66f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 23 Nov 2015 17:00:07 +0100 Subject: [PATCH 7/8] use monster_attack, not explicit create_order, because we need to check buildings, etc. --- src/monsters.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/monsters.c b/src/monsters.c index d6deaaab1..3474c6b45 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -797,8 +797,10 @@ void plan_monsters(faction * f) if (ta && !monster_is_waiting(u)) { unit *tu = (unit *)ta->data.v; if (tu && tu->region == r) { - addlist(&u->orders, - create_order(K_ATTACK, u->faction->locale, "%i", tu->no)); + order * ord = monster_attack(u, tu); + if (ord) { + addlist(&u->orders, ord); + } } else if (tu) { tu = findunitg(ta->data.i, NULL); From 1ed0eaf4732a4490431f933db4ce208142eb41ec Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 23 Nov 2015 17:10:49 +0100 Subject: [PATCH 8/8] release version 3.7.3 --- src/buildno.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/buildno.h b/src/buildno.h index 9dcd4a3e9..78925eaed 100644 --- a/src/buildno.h +++ b/src/buildno.h @@ -1,3 +1,3 @@ #define VERSION_MAJOR 3 #define VERSION_MINOR 7 -#define VERSION_BUILD 2 +#define VERSION_BUILD 3