Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ennorehling committed Nov 24, 2024
2 parents 2d34f16 + f589390 commit e386bd7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/battle.c
Original file line number Diff line number Diff line change
Expand Up @@ -3692,7 +3692,7 @@ void join_allies(battle * b)
}
}

for (si = 0; si != num_sides; ++si) {
for (num_sides = arrlen(b->sides), si = 0; si != num_sides; ++si) {
side* s = b->sides[si];
size_t sei;
faction *f = s->bf->faction;
Expand Down
31 changes: 22 additions & 9 deletions src/battle.test.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "kernel/building.h"
#include "kernel/faction.h"
#include "kernel/curse.h"
#include "kernel/group.h"
#include "kernel/item.h"
#include "kernel/order.h"
#include "kernel/race.h"
Expand Down Expand Up @@ -1326,28 +1327,40 @@ static void test_join_allies(CuTest *tc) {
battle *b = NULL;
unit *u1, *u2, *u3;
region *r;
fighter *fig;
fighter *f1, *f2, *f3;

test_setup();
r = test_create_plain(0, 0);
u1 = test_create_unit(test_create_faction(), r);
u2 = test_create_unit(test_create_faction(), r);
u3 = test_create_unit(u2->faction, r);
join_group(u3, "Fools");

unit_setstatus(u1, ST_FIGHT);
unit_setstatus(u2, ST_FLEE);
unit_setstatus(u3, ST_FIGHT);
unit_addorder(u1, create_order(K_ATTACK, u1->faction->locale, itoa36(u2->no)));
CuAssertTrue(tc, start_battle(r, &b));
CuAssertPtrNotNull(tc, fig = test_find_fighter(b, u1));
CuAssertIntEquals(tc, FIG_ATTACKER, fig->flags & FIG_ATTACKER);
CuAssertIntEquals(tc, u1->number, fig->alive);
CuAssertPtrNotNull(tc, fig = test_find_fighter(b, u2));
CuAssertIntEquals(tc, 0, fig->flags & FIG_ATTACKER);
CuAssertIntEquals(tc, u2->number, fig->alive);
CuAssertPtrNotNull(tc, f1 = test_find_fighter(b, u1));
CuAssertIntEquals(tc, FIG_ATTACKER, f1->flags & FIG_ATTACKER);
CuAssertIntEquals(tc, u1->number, f1->alive);
CuAssertPtrNotNull(tc, f2 = test_find_fighter(b, u2));
CuAssertIntEquals(tc, E_ENEMY|E_ATTACKING, get_relation(f1->side, f2->side));
CuAssertIntEquals(tc, E_ENEMY, get_relation(f2->side, f1->side));
CuAssertTrue(tc, f1->side != f2->side);
CuAssertIntEquals(tc, 0, f2->flags & FIG_ATTACKER);
CuAssertIntEquals(tc, u2->number, f2->alive);
CuAssertPtrEquals(tc, NULL, test_find_fighter(b, u3));
join_allies(b);
CuAssertPtrNotNull(tc, fig = test_find_fighter(b, u3));
CuAssertIntEquals(tc, 0, fig->flags & FIG_ATTACKER);
CuAssertPtrNotNull(tc, f3 = test_find_fighter(b, u3));
CuAssertIntEquals(tc, 0, f3->flags & FIG_ATTACKER);
CuAssertIntEquals(tc, u3->number, f3->alive);
CuAssertTrue(tc, f3->side != f2->side);
CuAssertTrue(tc, f3->side != f1->side);
CuAssertIntEquals(tc, E_FRIEND, get_relation(f3->side, f2->side));
CuAssertIntEquals(tc, E_FRIEND, get_relation(f2->side, f3->side));
CuAssertIntEquals(tc, E_ENEMY, get_relation(f3->side, f1->side));
CuAssertIntEquals(tc, E_ENEMY, get_relation(f1->side, f3->side));

free_battle(b);
test_teardown();
Expand Down

0 comments on commit e386bd7

Please sign in to comment.