making init_battle a bit faster by being a bit smarter.

This commit is contained in:
Enno Rehling 2008-05-05 16:08:46 +00:00
parent 2df1fbf0e9
commit 0af00c10ec
1 changed files with 15 additions and 11 deletions

View File

@ -3153,6 +3153,7 @@ join_battle(battle * b, unit * u, boolean attack, fighter ** cp)
for (s=b->sides;s!=b->sides+b->nsides;++s) { for (s=b->sides;s!=b->sides+b->nsides;++s) {
fighter *fig; fighter *fig;
if (s->faction==u->faction) {
for (fig=s->fighters;fig;fig=fig->next) { for (fig=s->fighters;fig;fig=fig->next) {
if (fig->unit == u) { if (fig->unit == u) {
c = fig; c = fig;
@ -3163,6 +3164,7 @@ join_battle(battle * b, unit * u, boolean attack, fighter ** cp)
} }
} }
} }
}
if (!c) { if (!c) {
*cp = make_fighter(b, u, NULL, attack); *cp = make_fighter(b, u, NULL, attack);
return *cp!=NULL; return *cp!=NULL;
@ -3330,14 +3332,16 @@ battle_report(battle * b)
bfaction *bf; bfaction *bf;
for (s=b->sides;s!=b->sides+b->nsides;++s) { for (s=b->sides;s!=b->sides+b->nsides;++s) {
if (s->alive-s->removed > 0) {
for (s2=b->sides;s2!=b->sides+b->nsides;++s2) { for (s2=b->sides;s2!=b->sides+b->nsides;++s2) {
if (s->alive-s->removed > 0 && s2->alive-s2->removed > 0 && enemy(s, s2)) { if (s2->alive-s2->removed > 0 && enemy(s, s2)) {
cont = true; cont = true;
break; break;
} }
} }
if (cont) break; if (cont) break;
} }
}
printf(" %d", b->turn); printf(" %d", b->turn);
fflush(stdout); fflush(stdout);