forked from FireEmblemUniverse/fireemblem8u
/
bmphase.c
72 lines (64 loc) · 1.66 KB
/
bmphase.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "global.h"
#include "bmunit.h"
#include "variables.h"
#include "bmphase.h"
int GetPhaseAbleUnitCount(int faction) {
int count = 0;
int id;
for (id = faction + 1; id < faction + 0x40; id++) {
struct Unit *unit = GetUnit(id);
if (UNIT_IS_VALID(unit)) {
u32 state = unit->state;
u32 notAble = (
US_UNSELECTABLE
| US_DEAD
| US_NOT_DEPLOYED
| US_RESCUED
| US_UNDER_A_ROOF
| US_BIT16);
if (!(state & notAble)) {
if (unit->statusIndex != UNIT_STATUS_SLEEP
&& unit->statusIndex != UNIT_STATUS_BERSERK)
{
if (!(UNIT_CATTRIBUTES(unit) & CA_UNSELECTABLE)) {
count += 1;
}
}
}
}
}
return count;
}
int CountUnitsInState(int faction, int state) {
int count = 0;
int id;
for (id = faction + 1; id < faction + 0x40; id++) {
struct Unit *unit = GetUnit(id);
if (UNIT_IS_VALID(unit)) {
if (!(unit->state & state)) {
count += 1;
}
}
}
return count;
}
s8 AreUnitsAllied(int left, int right) {
int a = left & 0x80;
int b = right & 0x80;
return (a == b);
}
s8 IsSameAllegiance(int left, int right) {
int ret;
if ((left & 0xc0) == (right & 0xc0)) {
ret = 1;
} else {
ret = 0;
};
return ret;
}
int GetCurrentPhase(void) {
return gPlaySt.faction & FACTION_RED;
}
int GetNonActiveFaction(void) {
return (gPlaySt.faction & FACTION_RED) ^ FACTION_RED;
}