Skip to content

Commit

Permalink
Merge pull request #674 from minirop/goto-pattern
Browse files Browse the repository at this point in the history
Deciphering the goto pattern
  • Loading branch information
RevoSucks authored Oct 22, 2024
2 parents c545425 + c87bddc commit a42b7d2
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 86 deletions.
87 changes: 44 additions & 43 deletions src/cp_battle.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,70 +151,71 @@ s8 AiAttemptCombatWithinMovement(s8 (* isEnemy)(struct Unit * unit))
BmMapFill(gBmMapMovement, -1);
gBmMapMovement[gActiveUnit->yPos][gActiveUnit->xPos] = 0;

if (GetRiddenBallistaAt(gActiveUnit->xPos, gActiveUnit->yPos) != 0) {
goto _0803D7EA;
if (GetRiddenBallistaAt(gActiveUnit->xPos, gActiveUnit->yPos) == 0) {
TryRemoveUnitFromBallista(gActiveUnit);
goto else_stmt;
}

TryRemoveUnitFromBallista(gActiveUnit);
}
else
{
else_stmt:
SetWorkingBmMap(gBmMapRange);

SetWorkingBmMap(gBmMapRange);

for (i = 0; i < UNIT_ITEM_COUNT; i++) {
u16 item = gActiveUnit->items[i];
for (i = 0; i < UNIT_ITEM_COUNT; i++) {
u16 item = gActiveUnit->items[i];

if (item == 0) {
break;
}
if (item == 0) {
break;
}

if (item == ITEM_NIGHTMARE) {
continue;
}
if (item == ITEM_NIGHTMARE) {
continue;
}

if (!CanUnitUseWeapon(gActiveUnit, item)) {
continue;
}
if (!CanUnitUseWeapon(gActiveUnit, item)) {
continue;
}

tmpResult.itemSlot = i;
tmpResult.itemSlot = i;

{
int uid;
for (uid = 1; uid < 0xC0; uid++) {
struct Unit* unit = GetUnit(uid);
{
int uid;
for (uid = 1; uid < 0xC0; uid++) {
struct Unit* unit = GetUnit(uid);

if (!UNIT_IS_VALID(unit)) {
continue;
}
if (!UNIT_IS_VALID(unit)) {
continue;
}

if (unit->state & (US_HIDDEN | US_DEAD | US_RESCUED | US_BIT16)) {
continue;
}
if (unit->state & (US_HIDDEN | US_DEAD | US_RESCUED | US_BIT16)) {
continue;
}

if (!isEnemy(unit)) {
continue;
}
if (!isEnemy(unit)) {
continue;
}

if (!AiReachesByBirdsEyeDistance(gActiveUnit, unit, item)) {
continue;
}
if (!AiReachesByBirdsEyeDistance(gActiveUnit, unit, item)) {
continue;
}

AiFillReversedAttackRangeMap(unit, item);
AiFillReversedAttackRangeMap(unit, item);

tmpResult.targetId = unit->index;
tmpResult.targetId = unit->index;

if (!AiSimulateBestBattleAgainstTarget(&tmpResult)) {
continue;
}
if (!AiSimulateBestBattleAgainstTarget(&tmpResult)) {
continue;
}

if (tmpResult.score >= finalResult.score) {
finalResult = tmpResult;
finalResult.itemSlot = i;
if (tmpResult.score >= finalResult.score) {
finalResult = tmpResult;
finalResult.itemSlot = i;
}
}
}
}
}

_0803D7EA:
if (UNIT_CATTRIBUTES(gActiveUnit) & CA_BALLISTAE) {
if (AiAttemptBallistaCombat(isEnemy, &tmpResult) == 1) {
if (tmpResult.score >= finalResult.score) {
Expand Down
86 changes: 43 additions & 43 deletions src/playerphase.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,38 +312,43 @@ void PlayerPhase_MainIdle(ProcPtr proc)

Proc_Break(proc);

goto _0801CB38;
break;

case PLAYER_SELECT_NOCONTROL:
UnitBeginAction(unit);
gBmSt.swapActionRangeCount = 0;

Proc_Goto(proc, 11);

goto _0801CB38;
break;

default:
goto else_stmt;
}
}

if ((gKeyStatusPtr->newKeys & START_BUTTON) && !(gKeyStatusPtr->heldKeys & SELECT_BUTTON))
else
{
struct Unit * unit = GetUnit(gBmMapUnit[gBmSt.playerCursor.y][gBmSt.playerCursor.x]);

if (unit)
else_stmt:
if ((gKeyStatusPtr->newKeys & START_BUTTON) && !(gKeyStatusPtr->heldKeys & SELECT_BUTTON))
{
EndAllMus();
ShowUnitSprite(unit);
}
struct Unit * unit = GetUnit(gBmMapUnit[gBmSt.playerCursor.y][gBmSt.playerCursor.x]);

EndPlayerPhaseSideWindows();
StartMinimapPlayerPhase();
if (unit)
{
EndAllMus();
ShowUnitSprite(unit);
}

Proc_Goto(proc, 9);
EndPlayerPhaseSideWindows();
StartMinimapPlayerPhase();

return;
Proc_Goto(proc, 9);

return;
}
}
}

_0801CB38:
UnitSpriteHoverUpdate();

PutMapCursor(
Expand Down Expand Up @@ -492,14 +497,10 @@ void PlayerPhase_RangeDisplayIdle(ProcPtr proc)
{
action = ACT_CANCEL;
}

goto _0801CDE2;
}

if (StartDestSelectedEvent())
else if (StartDestSelectedEvent())
{
action = ACT_EVENT;
goto _0801CDE2;
}
else
{
Expand All @@ -513,43 +514,42 @@ void PlayerPhase_RangeDisplayIdle(ProcPtr proc)
{
action = ACT_CANCEL;
}

goto _0801CDE2;
}
else if (!CanMoveActiveUnitTo(gBmSt.playerCursor.x, gBmSt.playerCursor.y))
{
action = ACT_FAIL;
}
else
{
if (!CanMoveActiveUnitTo(gBmSt.playerCursor.x, gBmSt.playerCursor.y))
{
action = ACT_FAIL;
goto _0801CDE2;
}

action = ACT_MOVE;
goto else_stmt;
}
}
}

if (gKeyStatusPtr->newKeys & B_BUTTON)
else
{
if (gActiveUnit->state & US_HAS_MOVED)
else_stmt:
if (gKeyStatusPtr->newKeys & B_BUTTON)
{
action = ACT_FAIL;
if (gActiveUnit->state & US_HAS_MOVED)
{
action = ACT_FAIL;
}
else
{
action = ACT_CANCEL;
}
}
else
else if (gKeyStatusPtr->newKeys & R_BUTTON)
{
action = ACT_CANCEL;
action = ACT_INFOSCREEN;
}
else if (gKeyStatusPtr->newKeys & L_BUTTON)
{
action = ACT_RESET_CURSOR;
}
}
else if (gKeyStatusPtr->newKeys & R_BUTTON)
{
action = ACT_INFOSCREEN;
}
else if (gKeyStatusPtr->newKeys & L_BUTTON)
{
action = ACT_RESET_CURSOR;
}

_0801CDE2:
switch (action)
{
case ACT_FAIL:
Expand Down

0 comments on commit a42b7d2

Please sign in to comment.