BUG 2334: Nochmal Ponnuki

Monsters cannot attack or guard when they are fleeing
This commit is contained in:
Enno Rehling 2017-06-18 14:20:01 +02:00
parent eed93b7470
commit 8178f3f1e6
3 changed files with 24 additions and 25 deletions

View file

@ -760,7 +760,7 @@ unit *read_unit(struct gamedata *data)
assert(u_race(u)); assert(u_race(u));
for (;;) { for (;;) {
int n, level, weeks; int n = NOSKILL, level, weeks;
skill_t sk; skill_t sk;
READ_INT(data->store, &n); READ_INT(data->store, &n);
sk = (skill_t)n; sk = (skill_t)n;
@ -1662,7 +1662,7 @@ int read_game(gamedata *data) {
if (rmax < 0) { if (rmax < 0) {
rmax = nread; rmax = nread;
} }
log_debug(" - Einzulesende Regionen: %d/%d\r", rmax, nread); log_debug(" - Einzulesende Regionen: %d/%d", rmax, nread);
while (--nread >= 0) { while (--nread >= 0) {
unit **up; unit **up;
@ -1716,10 +1716,6 @@ int read_game(gamedata *data) {
update_interval(u->faction, r); update_interval(u->faction, r);
} }
if ((nread & 0x3FF) == 0) { /* das spart extrem Zeit */
log_debug(" - Einzulesende Regionen: %d/%d * %d,%d \r", rmax, nread, r->x, r->y);
}
--rmax; --rmax;
} }
read_borders(data); read_borders(data);

View file

@ -187,25 +187,28 @@ void monsters_desert(struct faction *monsters)
} }
} }
int monster_attacks(unit * monster, bool respect_buildings, bool rich_only) int monster_attacks(unit * monster, bool rich_only)
{ {
region *r = monster->region; if (monster->status < ST_AVOID) {
unit *u2; region *r = monster->region;
int money = 0; unit *u2;
int money = 0;
for (u2 = r->units; u2; u2 = u2->next) { for (u2 = r->units; u2; u2 = u2->next) {
if (u2->faction != monster->faction && cansee(monster->faction, r, u2, 0) && !in_safe_building(u2, monster)) { if (u2->faction != monster->faction && cansee(monster->faction, r, u2, 0) && !in_safe_building(u2, monster)) {
int m = get_money(u2); int m = get_money(u2);
if (!rich_only || m > 0) { if (!rich_only || m > 0) {
order *ord = monster_attack(monster, u2); order *ord = monster_attack(monster, u2);
if (ord) { if (ord) {
addlist(&monster->orders, ord); addlist(&monster->orders, ord);
money += m; money += m;
}
} }
} }
} }
return money;
} }
return money; return 0;
} }
static order *get_money_for_dragon(region * r, unit * udragon, int wanted) static order *get_money_for_dragon(region * r, unit * udragon, int wanted)
@ -226,7 +229,7 @@ static order *get_money_for_dragon(region * r, unit * udragon, int wanted)
* und holt sich Silber von Einheiten, vorausgesetzt er bewacht bereits */ * und holt sich Silber von Einheiten, vorausgesetzt er bewacht bereits */
money = 0; money = 0;
if (attacks && is_guard(udragon)) { if (attacks && is_guard(udragon)) {
money += monster_attacks(udragon, true, true); money += monster_attacks(udragon, true);
} }
/* falls die einnahmen erreicht werden, bleibt das monster noch eine */ /* falls die einnahmen erreicht werden, bleibt das monster noch eine */
@ -749,7 +752,7 @@ void plan_monsters(faction * f)
} }
if (attacking && (!r->land || is_guard(u))) { if (attacking && (!r->land || is_guard(u))) {
monster_attacks(u, true, false); monster_attacks(u, false);
} }
/* units with a plan to kill get ATTACK orders: */ /* units with a plan to kill get ATTACK orders: */
@ -773,7 +776,7 @@ void plan_monsters(faction * f)
} }
/* All monsters guard the region: */ /* All monsters guard the region: */
if (!monster_is_waiting(u) && r->land) { if (u->status < ST_FLEE && !monster_is_waiting(u) && r->land) {
addlist(&u->orders, create_order(K_GUARD, u->faction->locale, NULL)); addlist(&u->orders, create_order(K_GUARD, u->faction->locale, NULL));
} }

View file

@ -27,7 +27,7 @@
#include <string.h> #include <string.h>
extern void plan_monsters(struct faction *f); extern void plan_monsters(struct faction *f);
extern int monster_attacks(unit * monster, bool respect_buildings, bool rich_only); extern int monster_attacks(unit * monster, bool rich_only);
static order *find_order(const char *expected, const unit *unit) static order *find_order(const char *expected, const unit *unit)
{ {
@ -64,6 +64,7 @@ static void create_monsters(faction **player, faction **monsters, unit **u, unit
*u = test_create_unit(*player, r); *u = test_create_unit(*player, r);
unit_setid(*u, 1); unit_setid(*u, 1);
*m = test_create_unit(*monsters, r); *m = test_create_unit(*monsters, r);
unit_setstatus(*m, ST_FIGHT);
} }
static void test_monsters_attack(CuTest * tc) static void test_monsters_attack(CuTest * tc)
@ -72,7 +73,6 @@ static void test_monsters_attack(CuTest * tc)
unit *u, *m; unit *u, *m;
create_monsters(&f, &f2, &u, &m); create_monsters(&f, &f2, &u, &m);
setguard(m, true); setguard(m, true);
config_set("rules.monsters.attack_chance", "1"); config_set("rules.monsters.attack_chance", "1");
@ -112,7 +112,7 @@ static void test_monsters_waiting(CuTest * tc)
create_monsters(&f, &f2, &u, &m); create_monsters(&f, &f2, &u, &m);
setguard(m, true); setguard(m, true);
fset(m, UFL_ISNEW); fset(m, UFL_ISNEW);
monster_attacks(m, false, false); monster_attacks(m, false);
CuAssertPtrEquals(tc, 0, find_order("attack 1", m)); CuAssertPtrEquals(tc, 0, find_order("attack 1", m));
test_cleanup(); test_cleanup();
} }