clean up plan_monsters and make it a bit more readable

This commit is contained in:
Enno Rehling 2015-11-02 15:27:01 +01:00
parent 072bfd3912
commit f70b385bef
1 changed files with 13 additions and 14 deletions

View File

@ -769,13 +769,14 @@ static order *plan_dragon(unit * u)
void plan_monsters(faction * f) void plan_monsters(faction * f)
{ {
region *r; region *r;
double attack_chance = monster_attack_chance();
assert(f); assert(f);
f->lastorders = turn; f->lastorders = turn;
for (r = regions; r; r = r->next) { for (r = regions; r; r = r->next) {
unit *u; unit *u;
double attack_chance = monster_attack_chance(); double rchance = attack_chance;
bool attacking = false; bool attacking = false;
for (u = r->units; u; u = u->next) { for (u = r->units; u; u = u->next) {
@ -786,25 +787,23 @@ void plan_monsters(faction * f)
if (!is_monsters(u->faction)) if (!is_monsters(u->faction))
continue; continue;
if (attack_chance > 0.0) { /* Befehle müssen jede Runde neu gegeben werden: */
if (chance(attack_chance)) free_orders(&u->orders);
attacking = true;
attack_chance = 0.0;
}
if (u->status > ST_BEHIND) {
setstatus(u, ST_FIGHT);
/* all monsters fight */
}
if (skill_enabled(SK_PERCEPTION)) { if (skill_enabled(SK_PERCEPTION)) {
/* Monster bekommen jede Runde ein paar Tage Wahrnehmung dazu */ /* Monster bekommen jede Runde ein paar Tage Wahrnehmung dazu */
/* TODO: this only works for playerrace */ /* TODO: this only works for playerrace */
produceexp(u, SK_PERCEPTION, u->number); produceexp(u, SK_PERCEPTION, u->number);
} }
/* Befehle müssen jede Runde neu gegeben werden: */ if (rchance > 0.0) {
free_orders(&u->orders); if (chance(rchance))
attacking = true;
rchance = 0.0;
}
if (u->status > ST_BEHIND) {
setstatus(u, ST_FIGHT);
/* all monsters fight */
}
if (attacking && is_guard(u, GUARD_TAX)) { if (attacking && is_guard(u, GUARD_TAX)) {
monster_attacks(u); monster_attacks(u);
} }