Skip to content

Commit

Permalink
Merge branch 'main' into dx
Browse files Browse the repository at this point in the history
  • Loading branch information
bates64 committed Oct 3, 2024
2 parents 85f1851 + 5929e49 commit a24d942
Show file tree
Hide file tree
Showing 147 changed files with 5,036 additions and 927 deletions.
3 changes: 3 additions & 0 deletions .clangd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CompileFlags:
Add: -Wno-unknown-warning-option
Remove: [-m*, -f*]
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,8 @@ build/
*.crash

/tools/n64crc

# clangd
.cache/clangd/
# compile_commands.json requires hardcoded paths, so it can't be committed
compile_commands.json
2 changes: 1 addition & 1 deletion include/common_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1394,7 +1394,7 @@ typedef struct GameStatus {
/* 0x06A */ s8 demoStickX;
/* 0x06B */ s8 demoStickY;
/* 0x06C */ s32 mainScriptID;
/* 0x070 */ s8 isBattle;
/* 0x070 */ s8 context;
/* 0x071 */ s8 demoState; // see DemoState enum
/* 0x072 */ s8 nextDemoScene; /* which part of the demo to play next */
/* 0x073 */ u8 contBitPattern;
Expand Down
24 changes: 15 additions & 9 deletions include/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -3525,6 +3525,12 @@ enum EffectGfxDataFlags {

#include "move_enum.h"

enum GameContext {
CONTEXT_WORLD = 0,
CONTEXT_BATTLE = 1,
CONTEXT_PAUSE = 2,
};

enum DemoState {
DEMO_STATE_NONE = 0,
DEMO_STATE_ACTIVE = 1,
Expand Down Expand Up @@ -4555,14 +4561,14 @@ enum EnemyFlags {

// used with enemy->aiFlags
enum EnemyAIFlags {
ENEMY_AI_FLAG_1 = 0x00000001,
ENEMY_AI_FLAG_2 = 0x00000002, // do not move; do not sense player
ENEMY_AI_FLAG_SUSPEND = 0x00000004,
ENEMY_AI_FLAG_8 = 0x00000008,
ENEMY_AI_FLAG_10 = 0x00000010,
ENEMY_AI_FLAG_20 = 0x00000020,
ENEMY_AI_FLAG_40 = 0x00000040,
ENEMY_AI_FLAG_80 = 0x00000080,
AI_FLAG_1 = 0x00000001,
AI_FLAG_CANT_DETECT_PLAYER = 0x00000002,
AI_FLAG_SUSPEND = 0x00000004,
AI_FLAG_SKIP_EMOTE_AFTER_FLEE = 0x00000008,
AI_FLAG_SKIP_IDLE_ANIM_AFTER_FLEE = 0x00000010,
AI_FLAG_OUTSIDE_TERRITORY = 0x00000020,
AI_FLAG_NEEDS_HEADING = 0x00000040,
AI_FLAG_80 = 0x00000080,
};

enum EnemyAIStates {
Expand Down Expand Up @@ -4612,7 +4618,7 @@ enum EnemyDetectFlags {
AI_DETECT_FLAG_8 = 0x08,
};

enum EnemyTerritoryFlags {
enum TerritoryFlags {
AI_TERRITORY_IGNORE_HIDING = 0x01, // bow and sushi dont prevent enemy detection
AI_TERRITORY_IGNORE_ELEVATION = 0x02, // vertical size of detection volume is ignored
};
Expand Down
7 changes: 7 additions & 0 deletions include/mapfs/kpa_08_hit.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#if VERSION_JP
#define COLLIDER_o90 0x12
#define COLLIDER_o19 0x10
#define COLLIDER_ttw 0x6
#define COLLIDER_deilie 0x0
#else
#define COLLIDER_Root 0x13
#define COLLIDER_move2 0x12
#define COLLIDER_o90 0x11
Expand All @@ -18,6 +24,7 @@
#define COLLIDER_ne 0x2
#define COLLIDER_deilite 0x1
#define COLLIDER_deilie 0x0
#endif

#define ZONE_Root 0x4
#define ZONE_g14 0x3
Expand Down
8 changes: 8 additions & 0 deletions include/mapfs/kpa_09_hit.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
#if VERSION_JP
#define COLLIDER_o106 0x13
#define COLLIDER_o19 0x11
#define COLLIDER_tte 0x7
#define COLLIDER_deilie 0x5
#define COLLIDER_ttw 0x2
#else
#define COLLIDER_Root 0x14
#define COLLIDER_move2 0x13
#define COLLIDER_o106 0x12
Expand All @@ -19,6 +26,7 @@
#define COLLIDER_ttw 0x2
#define COLLIDER_deilitw 0x1
#define COLLIDER_deiliw 0x0
#endif

#define ZONE_Root 0x4
#define ZONE_g14 0x3
Expand Down
7 changes: 7 additions & 0 deletions include/mapfs/kpa_130_shape.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#if VERSION_JP
#define MODEL_o455 0x13
#define MODEL_o454 0x11
#define MODEL_o11 0xF
#define MODEL_o9 0xD
#else
#define MODEL_Root 0xB5
#define MODEL_g128 0xB4
#define MODEL_o464 0xB3
Expand Down Expand Up @@ -180,4 +186,5 @@
#define MODEL_ew_hisi 0x2
#define MODEL_ew_sai 0x1
#define MODEL_ew_yuka 0x0
#endif

7 changes: 7 additions & 0 deletions include/mapfs/kpa_41_hit.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#if VERSION_JP
#define COLLIDER_deili4 0x1C
#define COLLIDER_deili3 0x17
#define COLLIDER_deilie 0x12
#define COLLIDER_deiliw 0xD
#else
#define COLLIDER_Root 0x1F
#define COLLIDER_exit4 0x1E
#define COLLIDER_tt4 0x1D
Expand Down Expand Up @@ -30,6 +36,7 @@
#define COLLIDER_kaidann 0x2
#define COLLIDER_k_sokumen2 0x1
#define COLLIDER_k_sokumen 0x0
#endif

#define ZONE_Root 0x4
#define ZONE_yuka 0x3
Expand Down
6 changes: 6 additions & 0 deletions include/mapfs/kpa_50_hit.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#if VERSION_JP
#define COLLIDER_tte 0xF
#define COLLIDER_ttw 0xA
#define COLLIDER_deiliw 0x9
#else
#define COLLIDER_Root 0x11
#define COLLIDER_exit 0x10
#define COLLIDER_e2 0xF
Expand All @@ -16,6 +21,7 @@
#define COLLIDER_1_isi 0x2
#define COLLIDER_e1_sai 0x1
#define COLLIDER_e2_sai 0x0
#endif

#define ZONE_Root 0x5
#define ZONE_exit 0x4
Expand Down
6 changes: 6 additions & 0 deletions include/mapfs/kpa_52_hit.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#if VERSION_JP
#define COLLIDER_tte2 0x1A
#define COLLIDER_ttw 0x15
#define COLLIDER_tte1 0x10
#else
#define COLLIDER_Root 0x1C
#define COLLIDER_exit3 0x1B
#define COLLIDER_ne2 0x1A
Expand Down Expand Up @@ -27,6 +32,7 @@
#define COLLIDER_kaidann 0x2
#define COLLIDER_o159 0x1
#define COLLIDER_o158 0x0
#endif

#define ZONE_Root 0x4
#define ZONE_g9 0x3
Expand Down
2 changes: 1 addition & 1 deletion include/npc.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ typedef struct EncounterStatus {

extern EncounterStatus gCurrentEncounter;

s32 basic_ai_check_player_dist(EnemyDetectVolume* arg0, Enemy* arg1, f32 arg2, f32 arg3, s8 arg4);
s32 basic_ai_check_player_dist(EnemyDetectVolume* arg0, Enemy* arg1, f32 arg2, f32 arg3, b8 arg4);

/// The default Npc::onUpdate and Npc::onRender callback.
void STUB_npc_callback(Npc*);
Expand Down
6 changes: 3 additions & 3 deletions src/111f0_len_860.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void state_step_enter_world(void) {
break;
}

gGameStatusPtr->isBattle = FALSE;
gGameStatusPtr->context = CONTEXT_WORLD;
gGameStatusPtr->debugScripts = DEBUG_SCRIPTS_NONE;

if (!gLoadedFromFileSelect) {
Expand Down Expand Up @@ -155,7 +155,7 @@ void state_step_change_map(void) {
if (gMapTransitionStateTime != 0) {
gMapTransitionStateTime--;
} else {
gGameStatusPtr->isBattle = FALSE;
gGameStatusPtr->context = CONTEXT_WORLD;
gGameStatusPtr->debugScripts = DEBUG_SCRIPTS_NONE;
load_map_by_IDs(gGameStatusPtr->areaID, gGameStatusPtr->mapID, LOAD_FROM_MAP);
set_time_freeze_mode(TIME_FREEZE_NORMAL);
Expand Down Expand Up @@ -230,7 +230,7 @@ void state_step_game_over(void) {
if (gMapTransitionStateTime != 0) {
gMapTransitionStateTime--;
} else {
gGameStatusPtr->isBattle = FALSE;
gGameStatusPtr->context = CONTEXT_WORLD;
gGameStatusPtr->debugScripts = DEBUG_SCRIPTS_NONE;
load_map_by_IDs(gGameStatusPtr->areaID, gGameStatusPtr->mapID, LOAD_FROM_MAP);
nuContRmbForceStopEnd();
Expand Down
65 changes: 34 additions & 31 deletions src/23680.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,16 +312,16 @@ void spawn_drops(Enemy* enemy) {
s32 get_coin_drop_amount(Enemy* enemy) {
EncounterStatus* currentEncounter = &gCurrentEncounter;
EnemyDrops* enemyDrops = enemy->drops;
s32 maxCoinBonus = enemyDrops->maxCoinBonus;
s32 max = enemyDrops->maxCoinBonus;
s32 amt = enemyDrops->minCoinBonus;
s32 minTemp = enemyDrops->minCoinBonus;

if (maxCoinBonus < amt) {
if (max < amt) {
amt = enemyDrops->maxCoinBonus;
maxCoinBonus = enemyDrops->minCoinBonus;
max = enemyDrops->minCoinBonus;
}

minTemp = maxCoinBonus - amt;
minTemp = max - amt;
if ((amt < 0) || (minTemp != 0)) {
amt = rand_int(minTemp) - -amt;
}
Expand Down Expand Up @@ -409,32 +409,32 @@ s32 func_80048F0C(void) {
return 0;
}

s32 is_point_within_region(s32 shape, f32 pointX, f32 pointY, f32 centerX, f32 centerY, f32 sizeX, f32 sizeZ) {
b32 is_point_outside_territory(s32 shape, f32 centerX, f32 centerZ, f32 pointX, f32 pointZ, f32 sizeX, f32 sizeZ) {
f32 dist1;
f32 dist2;

switch (shape) {
case 0:
dist1 = dist2D(pointX, pointY, centerX, centerY);
case SHAPE_CYLINDER:
dist1 = dist2D(centerX, centerZ, pointX, pointZ);
return (sizeX < dist1);
case 1:
dist1 = dist2D(pointX, 0, centerX, 0);
dist2 = dist2D(0, pointY, 0, centerY);
case SHAPE_RECT:
dist1 = dist2D(centerX, 0, pointX, 0);
dist2 = dist2D(0, centerZ, 0, pointZ);
return ((sizeX < dist1) || (sizeZ < dist2));
default:
return FALSE;
}
}

s32 basic_ai_check_player_dist(EnemyDetectVolume* territory, Enemy* enemy, f32 radius, f32 fwdPosOffset, s8 useWorldYaw) {
b32 basic_ai_check_player_dist(EnemyDetectVolume* territory, Enemy* enemy, f32 radius, f32 fwdPosOffset, b8 useWorldYaw) {
Npc* npc = get_npc_unsafe(enemy->npcID);
PlayerStatus* playerStatus = &gPlayerStatus;
PartnerStatus* partnerStatus;
f32 x, y, z;
f32 dist;
s32 skipCheckForPlayer;

if (enemy->aiFlags & ENEMY_AI_FLAG_2) {
if (enemy->aiFlags & AI_FLAG_CANT_DETECT_PLAYER) {
return FALSE;
}

Expand All @@ -458,7 +458,7 @@ s32 basic_ai_check_player_dist(EnemyDetectVolume* territory, Enemy* enemy, f32 r
return FALSE;
}

if (territory->sizeX | territory->sizeZ && is_point_within_region(territory->shape,
if (territory->sizeX | territory->sizeZ && is_point_outside_territory(territory->shape,
territory->pointX, territory->pointZ,
playerStatus->pos.x, playerStatus->pos.z,
territory->sizeX, territory->sizeZ)) {
Expand Down Expand Up @@ -580,8 +580,8 @@ void basic_ai_wander_init(Evt* script, MobileAISettings* npcAISettings, EnemyDet
npc->moveSpeed = enemy->territory->wander.moveSpeedOverride / 32767.0;
}

enemy->aiFlags &= ~ENEMY_AI_FLAG_40;
enemy->aiFlags &= ~ENEMY_AI_FLAG_20;
enemy->aiFlags &= ~AI_FLAG_NEEDS_HEADING;
enemy->aiFlags &= ~AI_FLAG_OUTSIDE_TERRITORY;
script->AI_TEMP_STATE = AI_STATE_WANDER;
}

Expand All @@ -593,6 +593,7 @@ void basic_ai_wander(Evt* script, MobileAISettings* aiSettings, EnemyDetectVolum
EffectInstance* sp34;
f32 yaw;

// search for the player
if (aiSettings->playerSearchInterval >= 0) {
if (script->functionTemp[1] <= 0) {
script->functionTemp[1] = aiSettings->playerSearchInterval;
Expand All @@ -605,8 +606,8 @@ void basic_ai_wander(Evt* script, MobileAISettings* aiSettings, EnemyDetectVolum
npc->yaw = yaw;
ai_enemy_play_sound(npc, SOUND_AI_ALERT_A, SOUND_PARAM_MORE_QUIET);
fx_emote(EMOTE_EXCLAMATION, npc, 0, npc->collisionHeight, 1.0f, 2.0f, -20.0f, 15, &sp34);
enemy->aiFlags &= ~ENEMY_AI_FLAG_40;
enemy->aiFlags &= ~ENEMY_AI_FLAG_20;
enemy->aiFlags &= ~AI_FLAG_NEEDS_HEADING;
enemy->aiFlags &= ~AI_FLAG_OUTSIDE_TERRITORY;

if (enemy->npcSettings->actionFlags & AI_ACTION_JUMP_WHEN_SEE_PLAYER) {
script->AI_TEMP_STATE = AI_STATE_ALERT_INIT;
Expand All @@ -620,37 +621,39 @@ void basic_ai_wander(Evt* script, MobileAISettings* aiSettings, EnemyDetectVolum
script->functionTemp[1]--;
}

// check if the wander we've reached the boundary of the territory
if (is_point_within_region(enemy->territory->wander.wanderShape,
// check if we've wandered beyond the boundary of the territory
if (is_point_outside_territory(enemy->territory->wander.wanderShape,
enemy->territory->wander.centerPos.x,
enemy->territory->wander.centerPos.z,
npc->pos.x,
npc->pos.z,
enemy->territory->wander.wanderSize.x,
enemy->territory->wander.wanderSize.z)
&& npc->moveSpeed < dist2D(enemy->territory->wander.centerPos.x, enemy->territory->wander.centerPos.z, npc->pos.x, npc->pos.z)) {
if (!(enemy->aiFlags & ENEMY_AI_FLAG_20)) {
enemy->aiFlags |= (ENEMY_AI_FLAG_20 | ENEMY_AI_FLAG_40);
&& npc->moveSpeed < dist2D(enemy->territory->wander.centerPos.x, enemy->territory->wander.centerPos.z, npc->pos.x, npc->pos.z)
) {
if (!(enemy->aiFlags & AI_FLAG_OUTSIDE_TERRITORY)) {
enemy->aiFlags |= (AI_FLAG_OUTSIDE_TERRITORY | AI_FLAG_NEEDS_HEADING);
}

if (enemy->aiFlags & ENEMY_AI_FLAG_40) {
if (enemy->aiFlags & AI_FLAG_NEEDS_HEADING) {
npc->yaw = clamp_angle(atan2(npc->pos.x, npc->pos.z, enemy->territory->wander.centerPos.x, enemy->territory->wander.centerPos.z));
enemy->aiFlags &= ~ENEMY_AI_FLAG_40;
enemy->aiFlags &= ~AI_FLAG_NEEDS_HEADING;
}

// if current heading is deflected by a wall, recalculate yaw to continue pursuing centerPos
x = npc->pos.x;
y = npc->pos.y;
z = npc->pos.z;
if (npc_test_move_simple_with_slipping(npc->collisionChannel, &x, &y, &z, 2.0 * npc->moveSpeed, npc->yaw, npc->collisionHeight, npc->collisionDiameter)) {
yaw = clamp_angle(atan2(npc->pos.x, npc->pos.z, enemy->territory->wander.centerPos.x, enemy->territory->wander.centerPos.z));
enemy->aiFlags &= ~ENEMY_AI_FLAG_40;
enemy->aiFlags &= ~AI_FLAG_NEEDS_HEADING;
ai_check_fwd_collisions(npc, 5.0f, &yaw, NULL, NULL, NULL);
npc->yaw = yaw;
}
stillWithinTerritory = TRUE;
} else if (enemy->aiFlags & ENEMY_AI_FLAG_20) {
enemy->aiFlags &= ~ENEMY_AI_FLAG_20;
enemy->aiFlags &= ~ENEMY_AI_FLAG_40;
} else if (enemy->aiFlags & AI_FLAG_OUTSIDE_TERRITORY) {
enemy->aiFlags &= ~AI_FLAG_OUTSIDE_TERRITORY;
enemy->aiFlags &= ~AI_FLAG_NEEDS_HEADING;
}

// perform the motion
Expand Down Expand Up @@ -870,7 +873,7 @@ API_CALLABLE(BasicAI_Main) {
territory.halfHeight = 65.0f;
territory.detectFlags = 0;

if (isInitialCall || enemy->aiFlags & ENEMY_AI_FLAG_SUSPEND) {
if (isInitialCall || enemy->aiFlags & AI_FLAG_SUSPEND) {
script->AI_TEMP_STATE = AI_STATE_WANDER_INIT;
npc->duration = 0;

Expand All @@ -885,14 +888,14 @@ API_CALLABLE(BasicAI_Main) {
npc->flags |= NPC_FLAG_FLYING;
}

if (enemy->aiFlags & ENEMY_AI_FLAG_SUSPEND) {
if (enemy->aiFlags & AI_FLAG_SUSPEND) {
script->AI_TEMP_STATE = AI_STATE_SUSPEND;
script->functionTemp[1] = AI_STATE_WANDER_INIT;
} else if (enemy->flags & ENEMY_FLAG_BEGIN_WITH_CHASING) {
script->AI_TEMP_STATE = AI_STATE_CHASE_INIT;
}

enemy->aiFlags &= ~ENEMY_AI_FLAG_SUSPEND;
enemy->aiFlags &= ~AI_FLAG_SUSPEND;
enemy->flags &= ~ENEMY_FLAG_BEGIN_WITH_CHASING;
}

Expand Down
2 changes: 1 addition & 1 deletion src/25AF0.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ s32 ai_check_fwd_collisions(Npc* npc, f32 time, f32* outYaw, f32* outDistFwd, f3
f32 cwHitDist = -1.0f;
f32 ccwHitDist = -1.0f;
f32 yaw;
s32 fwdHit;
b32 fwdHit;

x1 = npc->pos.x;
y1 = npc->pos.y;
Expand Down
Loading

0 comments on commit a24d942

Please sign in to comment.