62 s32 BattleEnemy_SelectWeightedAction(
u8 *weights) {
73 while (++actionIndex <= 7) {
74 total += weights[actionIndex];
76 selectedAction = actionIndex;
81 return selectedAction;
85 needsChoice = itemsAllowed = 1;
103 strategyKind = *actionStrategy;
104 switch (strategyKind) {
141 useItem = (*itemActionMask >>
selection) & 1;
142 useItem &= itemsAllowed;
145 if (useItem != 0 && retry != 0) {
166 flags = itemAction->
flags;
184 if (needsChoice != 0) {
246 switch (targetMode) {
250 if (allyTarget == -2) {
256 if (allyTarget != -1) {
257 request->
target = allyTarget;
263 if (opponentTarget == -2) {
269 if (opponentTarget != -1) {
270 request->
target = opponentTarget;
279 request->
target = opponentTarget;
289 if (needsChoice != 0 && failedChoices > 16) {
294 if (needsChoice != 0)
u8 gBattleCommand_SelectionWeights[3][8]
What every part of the battle object shares: its includes, in their original order,...
#define ITEM_USE_CONSUMED
one is used up
#define ALLY_MAX
the last party member's unit id
#define ABILITY_ATTACK
the ability "Attack"
#define TARGET_MODE_ALLIES
@ CMD_ABILITY
an enemy's ability
@ CMD_DEFEND2
an enemy's Total Defense (effect 47)
@ ABILITY_EFFECT_TOTAL_DEFENSE
Total Defense, Flash.
@ ABILITY_EFFECT_DEFEND
Defend, Granite.
@ ABILITY_EFFECT_FLEE
Flee.
s32 BattleCommand_SelectAutomatic(struct BattleActionRecord *request, s32 retry)
Chooses an enemy's action (a party member's is chosen in the menu): one of the eight in its definitio...
struct BattleUnit * UnitGetFar(u32 owner)
struct ItemDefinition * Item_GetDirectFar(s32 item)
struct BattleAct * BattleActGet(s32 actionId)
Far call to BattleAction_GetDirect.
const u8 * Enemy_GetDefinitionFar(s32 selector)
s32 BattleRandomFar(void)
s32 Battle_FindTaggedSlotByValue(u32 unitId)
Returns the list place of unit id, or -1 if it is in neither list: the party's as 0x100 | place,...
An ability's definition, a row of gBattleAction_DefinitionTable: its targeting, kind,...
u8 ppCost
PP the ability costs.
u8 effect
enum AbilityEffect
u8 range
the aimed unit and range - 1 either side, or ABILITY_RANGE_ALL
u8 targetMode
TARGET_MODE_NONE, _FOES, _ALLIES or _SELF.
u8 flags
bits: 7 usable in battle | 6 usable in the field | 5..4 clear in every row | 3..0 kind (ABILITY_KIND_...
A unit's chosen action for the turn: its command, the command's parameter, its target and range,...
s16 target
the aimed unit's id
s16 parameter
an ability id, or CMD_ITEM's inventory index (-1 gone)
s16 command
enum BattleCommand
s16 range
the action's range
An enemy's memory of its action choice, kept in BattleUnit.rewards (0 in every row of enemies....
unsigned selection
the place in its action list, 0 to 7
unsigned remaining
not used here
unsigned initialized
strategy 3 has drawn its random start
A unit in battle: a party member's or an enemy's stats, Psynergy, items, Djinn and ailments.
u32 rewards
Copied from the enemy's definition, where it is 0 in every row.
u8 psySeal
bits: 7..3 Luff (16 when cast, minus 8 a turn) | 2..0 Bind's turns (7 when cast).
s8 challenge
Set by the challenge effect: an enemy with it never chooses to flee.
u8 classId
Who the unit is: a character's id (ISAAC to JENNA, below 8) or an enemy's id (BattleUnitSet).
u8 classIndex
The character's class, worked out from its Djinn (Unit_UpdateClass); 0 marks an enemy,...
u16 inventory[15]
Items held, one entry each: bits 15..11 quantity | 10 broken | 9 equipped | 8..0 item id (INVENTORY_*...
An enemy's definition: its level and stats, items, element preset, the actions it chooses from and it...
u8 itemActions
one bit per place in actions: use an item held instead
s8 targetStrategy
Whom a single-target attack favours: the target with the most HP left (0), the most maximum HP (1) or...
s8 actionStrategy
How the action is chosen from actions (BattleCommand_SelectAutomatic): one of three weight tables (0 ...
u16 actions[8]
the abilities the enemy chooses from
An item's definition: its price, type, who can equip it, its bonuses and unleash, its effects and the...
u8 useType
what using it costs (ITEM_USE_), or 0 for nothing
u16 actionId
the ability used, or taught as Psynergy
u32 Ability_IsPsynergy(s32 abilityId)
Returns 1 for an ability that costs PP, and for Psy Drain, which costs none.
s32 BattleTarget_SelectForAction(s32 actorId, struct BattleAct *action)
Picks the target of an enemy's ability (or a confused unit's), as a place code: among the units of th...
s32 BattleTarget_SelectRandomPosition(s32 requireLivingUnit)
Picks a random place: with requireLivingUnit, a party member still standing; otherwise any enemy plac...