Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
npc.h File Reference

Go to the source code of this file.

Data Structures

struct  QuizRequirement
 
struct  NpcBlueprint
 
struct  MobileAISettings
 
struct  GuardAISettings
 
struct  FireBarAISettings
 
struct  FireBarData
 
struct  NpcSettings
 
struct  ItemDrop
 
struct  StatDrop
 Describes heart/flower drop chances after defeating an Npc in the overworld. More...
 
struct  EnemyDrops
 
struct  EnemyDetectVolume
 
struct  EnemyTerritoryWander
 
struct  EnemyTerritoryPatrol
 
union  EnemyTerritory
 
union  NpcInitialVars
 
struct  NpcData
 
struct  NpcGroup
 Zero-terminated. More...
 
struct  Enemy
 
struct  Encounter
 
struct  FieldStatus
 
struct  EncounterStatus
 
struct  NpcData.animations
 
union  Enemy.__unnamed54__
 

Macros

#define NPC_GROUP(args...)   VFUNC(NPC_GROUP, args)
 
#define NPC_GROUP1(npcs)   { sizeof(npcs) / sizeof(NpcData), (NpcData*) &npcs, 0, 0 }
 
#define NPC_GROUP2(npcs, battle)   { sizeof(npcs) / sizeof(NpcData), (NpcData*) &npcs, battle, 0 }
 
#define NPC_GROUP3(npcs, battle, stage)   { sizeof(npcs) / sizeof(NpcData), (NpcData*) &npcs, battle, stage + 1 }
 
#define NPC_GROUP_EXPLICIT_SIZE(args...)   VFUNC(NPC_GROUP_EXPLICIT_SIZE, args)
 
#define NPC_GROUP_EXPLICIT_SIZE3(npcs, start, count)   { count, (NpcData*) &npcs[start], 0, 0 }
 
#define NPC_GROUP_EXPLICIT_SIZE4(npcs, start, count, battle)   { count, (NpcData*) &npcs[start], battle, 0 }
 
#define NPC_GROUP_EXPLICIT_SIZE5(npcs, start, count, battle, stage)   { count, (NpcData*) &npcs[start], battle, stage + 1 }
 
#define NO_DROPS
 
#define STANDARD_HEART_DROPS(attempts)
 
#define GENEROUS_HEART_DROPS(attempts)
 
#define GENEROUS_WHEN_LOW_HEART_DROPS(attempts)
 
#define STANDARD_FLOWER_DROPS(attempts)
 
#define GENEROUS_WHEN_LOW_FLOWER_DROPS(attempts)
 
#define REDUCED_FLOWER_DROPS(attempts)
 
#define OVERRIDE_MOVEMENT_SPEED(speed)   ((s32)(speed * 32767))
 
#define NO_OVERRIDE_MOVEMENT_SPEED   OVERRIDE_MOVEMENT_SPEED(-1.0f)
 

Typedefs

typedef void(* FireBarCallback) (struct FireBarData *, s32)
 
typedef NpcGroup NpcGroupList[]
 
typedef void AIStateHandler(Evt *script, MobileAISettings *settings, EnemyDetectVolume *territory)
 

Enumerations

enum  TerritoryShape { SHAPE_CYLINDER , SHAPE_RECT }
 

Functions

b32 basic_ai_check_player_dist (EnemyDetectVolume *arg0, Enemy *arg1, f32 arg2, f32 arg3, s8 arg4)
 
void STUB_npc_callback (Npc *)
 The default Npc::onUpdate and Npc::onRender callback.
 
void mtx_ident_mirror_y (Matrix4f mtx)
 
void clear_npcs (void)
 
void init_npc_list (void)
 Points the current NPC list to the world or battle lists depending on game state.
 
s32 create_npc_impl (NpcBlueprint *blueprint, AnimID *animList, s32 skipLoadingAnims)
 
s32 create_basic_npc (NpcBlueprint *blueprint)
 
s32 create_standard_npc (NpcBlueprint *blueprint, AnimID *animList)
 
s32 create_peach_npc (NpcBlueprint *blueprint)
 
void free_npc_by_index (s32 listIndex)
 
void free_npc (Npc *npc)
 
Npcget_npc_by_index (s32 listIndex)
 
void npc_do_world_collision (Npc *npc)
 
void npc_do_other_npc_collision (Npc *npc)
 
s32 npc_do_player_collision (Npc *npc)
 
void npc_try_apply_gravity (Npc *npc)
 
s32 npc_try_snap_to_ground (Npc *npc, f32 velocity)
 
void update_npcs (void)
 Updates all NPCs.
 
f32 npc_get_render_yaw (Npc *npc)
 
void appendGfx_npc (void *data)
 
void render_npcs (void)
 Renders all NPCs.
 
void npc_move_heading (Npc *npc, f32 speed, f32 yaw)
 
Npcget_npc_unsafe (s32 npcID)
 
Npcget_npc_safe (s32 npcID)
 
void enable_npc_shadow (Npc *npc)
 
void disable_npc_shadow (Npc *npc)
 
void update_npc_blur (Npc *npc)
 
void appendGfx_npc_blur (void *npc)
 
void npc_enable_collisions (void)
 
void npc_disable_collisions (void)
 
void func_8003B1A8 (void)
 
void npc_reload_all (void)
 
void set_npc_yaw (Npc *npc, f32 yaw)
 
void npc_set_palswap_mode_A (Npc *npc, s32 arg1)
 
void npc_set_palswap_mode_B (Npc *npc, s32 arg1)
 
void npc_revert_palswap_mode (Npc *npc)
 
void npc_set_palswap_1 (Npc *npc, s32 palIndexA, s32 palIndexB, s32 timeHoldA, s32 timeAB)
 
void npc_set_palswap_2 (Npc *npc, s32 timeHoldB, s32 timeBA, s32 palIndexC, s32 palIndexD)
 
void npc_draw_with_palswap (Npc *npc, s32 arg1, Matrix4f mtx)
 
void npc_render_without_adjusted_palettes (Npc *npc, s32 arg1, Matrix4f mtx)
 
void npc_render_with_watt_idle_palettes (Npc *, s32, Matrix4f mtx)
 
u16 npc_blend_palette_colors (u16 colorA, u16 colorB, s32 lerpAlpha)
 
void npc_render_with_single_pal_blending (Npc *, s32, s32, Matrix4f mtx)
 
void npc_render_with_double_pal_blending (Npc *, s32, Matrix4f mtx)
 
void npc_set_decoration (Npc *npc, s32 idx, s32 decorationType)
 
void npc_remove_decoration (Npc *npc, s32 idx)
 
void npc_update_decorations (Npc *npc)
 
void npc_reset_current_decoration (Npc *npc, s32 idx)
 
void npc_update_decoration_none (Npc *npc, s32 idx)
 
void npc_remove_decoration_none (Npc *npc, s32 idx)
 
void npc_update_decoration_bowser_aura (Npc *npc, s32 idx)
 
void npc_remove_decoration_bowser_aura (Npc *npc, s32 idx)
 
void npc_update_decoration_sweat (Npc *npc, s32 idx)
 
void npc_remove_decoration_sweat (Npc *npc, s32 idx)
 
void npc_update_decoration_seeing_stars (Npc *npc, s32 idx)
 
void npc_remove_decoration_seeing_stars (Npc *npc, s32 idx)
 
void npc_update_decoration_glow_in_front (Npc *npc, s32 idx)
 
void npc_remove_decoration_glow_in_front (Npc *npc, s32 idx)
 
void npc_update_decoration_glow_behind (Npc *npc, s32 idx)
 
void npc_remove_decoration_glow_behind (Npc *npc, s32 idx)
 
void npc_update_decoration_charged (Npc *npc, s32 idx)
 
void npc_remove_decoration_charged (Npc *npc, s32 idx)
 
Npcnpc_find_closest (f32 x, f32 y, f32 z, f32 radius)
 Finds the closest NPC to a given point within a radius.
 
Npcnpc_find_closest_simple (f32 x, f32 y, f32 z, f32 radius)
 Finds the closest simple-hitbox NPC to a given point within a radius.
 
s32 npc_get_collider_below (Npc *npc)
 
void npc_imgfx_update (Npc *npc)
 
void npc_set_imgfx_params (Npc *npc, s32 arg1, s32 arg2, s32 arg3, s32 arg4, s32 arg5, s32 arg6)
 
void npc_surface_spawn_fx (Npc *npc, SurfaceInteractMode mode)
 
void spawn_default_surface_effects (Npc *npc, SurfaceInteractMode mode)
 
void spawn_flower_surface_effects (Npc *npc, SurfaceInteractMode mode)
 
void spawn_cloud_surface_effects (Npc *npc, SurfaceInteractMode mode)
 
void spawn_snow_surface_effects (Npc *npc, SurfaceInteractMode mode)
 
void spawn_hedge_surface_effects (Npc *npc, SurfaceInteractMode mode)
 
void spawn_water_surface_effects (Npc *npc, SurfaceInteractMode mode)
 
void COPY_set_defeated (s32 mapID, s32 encounterID)
 Duplicate of set_defeated().
 
void init_encounter_status (void)
 
void clear_encounter_status (void)
 
void func_8003E50C (void)
 
void func_8003E514 (s8 arg0)
 
void update_encounters (void)
 
void draw_encounter_ui (void)
 
void draw_first_strike_ui (void)
 
void npc_render_worker_do_nothing (void)
 
void make_npcs (s32 flags, s32 mapID, s32 *npcGroupList)
 
void kill_encounter (Enemy *enemy)
 
void kill_enemy (Enemy *enemy)
 
s32 bind_enemy_ai (Enemy *enemy, EvtScript *aiScriptBytecode)
 Binds the specified ai script to the specified enemy.
 
s32 bind_enemy_aux (Enemy *enemy, EvtScript *auxScriptBytecode)
 Binds the specified auxillary script to the specified enemy.
 
s32 bind_enemy_interact (Enemy *enemy, EvtScript *interactScriptBytecode)
 Binds the specified interact script to the specified enemy.
 
void bind_npc_ai (s32 npcID, EvtScript *npcAiBytecode)
 Binds the specified ai script to the npc matching the specified npcId.
 
void bind_npc_aux (s32 npcID, EvtScript *npcAuxBytecode)
 Binds the specified auxillary script to the npc matching the specified npcId.
 
void bind_npc_interact (s32 npcID, EvtScript *npcInteractBytecode)
 Binds the specified interact script to the npc matching the specified npcId.
 
Enemyget_enemy (s32 npcID)
 Looks for an enemy matching the specified npcID.
 
Enemyget_enemy_safe (s32 npcID)
 Same as get_enemy(), with the exception of always returning a value if an enemy is not found.
 
void set_npc_sprite (Npc *npc, s32 anim, AnimID *extraAnimList)
 

Variables

EncounterStatus gCurrentEncounter
 

Data Structure Documentation

◆ QuizRequirement

struct QuizRequirement
Data Fields
s32 requiredStoryProgress
s32 numQuestionsUnlocked

◆ MobileAISettings

struct MobileAISettings
Data Fields
f32 moveSpeed
s32 moveTime
s32 waitTime
f32 alertRadius
f32 alertOffsetDist
s32 playerSearchInterval
f32 chaseSpeed
s32 chaseTurnRate
s32 chaseUpdateInterval
f32 chaseRadius
f32 chaseOffsetDist
s32 unk_AI_2C

◆ GuardAISettings

struct GuardAISettings
Data Fields
f32 alertRadius
f32 alertOffsetDist
s32 playerSearchInterval
f32 chaseSpeed
s32 chaseTurnRate
s32 chaseUpdateInterval
f32 chaseRadius
f32 chaseOffsetDist
s32 unk_AI_20

◆ FireBarAISettings

struct FireBarAISettings
Data Fields
Vec3i centerPos
s32 rotRate
s32 firstNpc
s32 npcCount
FireBarCallback callback

◆ FireBarData

struct FireBarData
Data Fields
s32 flags
Vec3f centerPos
f32 rotRate
s32 firstNpc
s32 npcCount
FireBarCallback callback
s32 soundIndex
f32 lastDeltaYaw
f32 yaw
FireBarAISettings * settings

◆ NpcSettings

struct NpcSettings
Data Fields
AnimID defaultAnim
s16 height
s16 radius
void * otherAI
EvtScript * onInteract
EvtScript * ai
EvtScript * onHit
EvtScript * aux
EvtScript * onDefeat
s32 flags
s32 unk_24
s16 level
s16 actionFlags

◆ ItemDrop

struct ItemDrop
Data Fields
s16 item
s16 weight
s16 flagIdx

◆ StatDrop

struct StatDrop
Data Fields
s16 cutoff % of max HP/FP. If current HP/FP > cutoff, no hearts/flowers can be dropped.
s16 generalChance % chance for any hearts/flowers to be dropped at all from this StatDrop.
s16 attempts Maximum number of hearts/flowers that can be dropped from this StatDrop.
s16 chancePerAttempt % chance for a single heart/flower to be dropped from each attempt.

◆ EnemyDrops

struct EnemyDrops
Data Fields
u8 dropFlags
u8 itemDropChance
ItemDrop itemDrops[8]
StatDrop heartDrops[8]
StatDrop flowerDrops[8]
s16 minCoinBonus
s16 maxCoinBonus
char unk_DE[2]

◆ EnemyDetectVolume

struct EnemyDetectVolume
Data Fields
s32 skipPlayerDetectChance
enum TerritoryShape shape
s32 pointX
s32 pointZ
s32 sizeX
s32 sizeZ
f32 halfHeight
s16 detectFlags

◆ EnemyTerritoryWander

struct EnemyTerritoryWander
Data Fields
Vec3i centerPos
VecXZi wanderSize
s32 moveSpeedOverride
enum TerritoryShape wanderShape
Vec3i detectPos
VecXZi detectSize
enum TerritoryShape detectShape
b32 isFlying

◆ EnemyTerritoryPatrol

struct EnemyTerritoryPatrol
Data Fields
s32 numPoints
Vec3i points[10]
s32 moveSpeedOverride
Vec3i detectPos
VecXZi detectSize
enum TerritoryShape detectShape
b32 isFlying

◆ EnemyTerritory

union EnemyTerritory
Data Fields
EnemyTerritoryWander wander
EnemyTerritoryPatrol patrol
char PADDING[0xC0]

◆ NpcInitialVars

union NpcInitialVars
Data Fields
s32 value
s8 bytes[4]
s32 * array

◆ NpcData

struct NpcData
Data Fields
s32 id
NpcSettings * settings
Vec3f pos
s32 flags
EvtScript * init
s32 initVarCount
NpcInitialVars initVar
s32 yaw
EnemyDrops drops
EnemyTerritory territory
struct NpcData.animations animations
s8 unk__1E0
s8 unk__1E1
s8 unk__1E2
u8 aiDetectFlags
u32 aiFlags
AnimID * extraAnimations
s32 tattle

◆ NpcGroup

struct NpcGroup
Data Fields
s32 npcCount
NpcData * npcs
s16 battle
s16 stage

◆ Enemy

struct Enemy
Data Fields
s32 flags
s8 encounterIndex
s8 encountered
u8 scriptGroup
s8 hitboxIsActive
s16 npcID
s16 spawnPos[3]
Vec3s unk_10
char unk_16[2]
NpcSettings * npcSettings
EvtScript * initBytecode
EvtScript * interactBytecode
EvtScript * aiBytecode
EvtScript * hitBytecode
EvtScript * auxBytecode
EvtScript * defeatBytecode
struct Evt * initScript
struct Evt * interactScript
struct Evt * aiScript
struct Evt * hitScript
struct Evt * auxScript
struct Evt * defeatScript
s32 initScriptID
s32 interactScriptID
s32 aiScriptID
s32 hitScriptID
s32 auxScriptID
s32 defeatScriptID
void * unk_64
char unk_68[4]
union Enemy.__unnamed54__ __unnamed__
u8 aiDetectFlags
char unk_AD[3]
u32 aiFlags
s8 aiSuspendTime
s8 instigatorValue
char unk_B6[2]
EvtScript * unk_B8
struct Evt * unk_BC
s32 unk_C0
s32 unk_C4
s32 unk_C8
s32 * animList
EnemyTerritory * territory
EnemyDrops * drops
u32 tattleMsg
s32 unk_DC
s16 savedNpcYaw
char unk_E2[6]

◆ Encounter

struct Encounter
Data Fields
s32 count
Enemy * enemy[16]
s16 battle
s16 stage
s16 encounterID
char unk_4C[2]

◆ FieldStatus

struct FieldStatus
Data Fields
s8 status
char pad_01
s16 duration

◆ EncounterStatus

struct EncounterStatus
Data Fields
s32 flags
s8 firstStrikeType
s8 hitType
s8 hitTier
char unk_07
s8 unk_08
s8 battleOutcome
s8 battleTriggerCooldown set to 15 after victory, 45 after fleeing
b8 hasMerleeCoinBonus
u8 damageTaken
char unk_0D
s16 coinsEarned
s8 instigatorValue
s8 forbidFleeing
s8 scriptedBattle battle started by StartBattle but not by encounter
s8 dropWhackaBump
s32 songID
s32 unk_18
s8 numEncounters
s8 curAreaIndex
u8 curMapIndex
u8 curEntryIndex
s8 mapID
s8 resetMapEncounterFlags
char unk_22[2]
s32 * npcGroupList
Encounter * encounterList[24]
Encounter * curEncounter
Enemy * curEnemy
s32 fadeOutAmount
s32 substateDelay
s32 fadeOutAccel
s32 battleStartCountdown
FieldStatus dizzyAttack
FieldStatus unusedAttack1
FieldStatus unusedAttack2
FieldStatus unusedAttack3
s32 defeatFlags[60][12]
s16 recentMaps[2]

◆ NpcData.animations

struct NpcData.animations
Data Fields
s32 idle
s32 walk
s32 run
s32 chase
s32 anim_4
s32 anim_5
s32 death
s32 hit
s32 anim_8
s32 anim_9
s32 anim_A
s32 anim_B
s32 anim_C
s32 anim_D
s32 anim_E
s32 anim_F

◆ Enemy.__unnamed54__

union Enemy.__unnamed54__
Data Fields
s32 varTable[16]
f32 varTableF[16]
void * varTablePtr[16]

Macro Definition Documentation

◆ NPC_GROUP

#define NPC_GROUP ( args...)    VFUNC(NPC_GROUP, args)

Definition at line 13 of file npc.h.

◆ NPC_GROUP1

#define NPC_GROUP1 ( npcs)    { sizeof(npcs) / sizeof(NpcData), (NpcData*) &npcs, 0, 0 }

Definition at line 14 of file npc.h.

◆ NPC_GROUP2

#define NPC_GROUP2 ( npcs,
battle )   { sizeof(npcs) / sizeof(NpcData), (NpcData*) &npcs, battle, 0 }

Definition at line 15 of file npc.h.

◆ NPC_GROUP3

#define NPC_GROUP3 ( npcs,
battle,
stage )   { sizeof(npcs) / sizeof(NpcData), (NpcData*) &npcs, battle, stage + 1 }

Definition at line 16 of file npc.h.

◆ NPC_GROUP_EXPLICIT_SIZE

#define NPC_GROUP_EXPLICIT_SIZE ( args...)    VFUNC(NPC_GROUP_EXPLICIT_SIZE, args)

Definition at line 18 of file npc.h.

◆ NPC_GROUP_EXPLICIT_SIZE3

#define NPC_GROUP_EXPLICIT_SIZE3 ( npcs,
start,
count )   { count, (NpcData*) &npcs[start], 0, 0 }

Definition at line 19 of file npc.h.

◆ NPC_GROUP_EXPLICIT_SIZE4

#define NPC_GROUP_EXPLICIT_SIZE4 ( npcs,
start,
count,
battle )   { count, (NpcData*) &npcs[start], battle, 0 }

Definition at line 20 of file npc.h.

◆ NPC_GROUP_EXPLICIT_SIZE5

#define NPC_GROUP_EXPLICIT_SIZE5 ( npcs,
start,
count,
battle,
stage )   { count, (NpcData*) &npcs[start], battle, stage + 1 }

Definition at line 21 of file npc.h.

◆ NO_DROPS

#define NO_DROPS
Value:
{ \
.dropFlags = NPC_DROP_FLAG_80, \
.heartDrops = { { F16(100), F16(0), 0, F16(0) } }, \
.flowerDrops = { { F16(100), F16(0), 0, F16(0) } }, \
}
@ NPC_DROP_FLAG_80
Definition enums.h:4674
#define F16(f)
Fixed-point short literal.
Definition macros.h:182

Definition at line 23 of file npc.h.

23#define NO_DROPS { \
24 .dropFlags = NPC_DROP_FLAG_80, \
25 .heartDrops = { { F16(100), F16(0), 0, F16(0) } }, \
26 .flowerDrops = { { F16(100), F16(0), 0, F16(0) } }, \
27}

◆ STANDARD_HEART_DROPS

#define STANDARD_HEART_DROPS ( attempts)
Value:
{ \
{ F16(20), F16(70), attempts, F16(50) }, \
{ F16(30), F16(60), attempts, F16(50) }, \
{ F16(50), F16(50), attempts, F16(40) }, \
{ F16(80), F16(40), attempts, F16(40) }, \
{ F16(100), F16(30), attempts, F16(30) }, \
}

Definition at line 29 of file npc.h.

29#define STANDARD_HEART_DROPS(attempts) { \
30 { F16(20), F16(70), attempts, F16(50) }, \
31 { F16(30), F16(60), attempts, F16(50) }, \
32 { F16(50), F16(50), attempts, F16(40) }, \
33 { F16(80), F16(40), attempts, F16(40) }, \
34 { F16(100), F16(30), attempts, F16(30) }, \
35}

◆ GENEROUS_HEART_DROPS

#define GENEROUS_HEART_DROPS ( attempts)
Value:
{ \
{ F16(20), F16(80), attempts, F16(50) }, \
{ F16(30), F16(70), attempts, F16(50) }, \
{ F16(50), F16(60), attempts, F16(40) }, \
{ F16(80), F16(50), attempts, F16(40) }, \
{ F16(100), F16(40), attempts, F16(30) }, \
}

Definition at line 37 of file npc.h.

37#define GENEROUS_HEART_DROPS(attempts) { \
38 { F16(20), F16(80), attempts, F16(50) }, \
39 { F16(30), F16(70), attempts, F16(50) }, \
40 { F16(50), F16(60), attempts, F16(40) }, \
41 { F16(80), F16(50), attempts, F16(40) }, \
42 { F16(100), F16(40), attempts, F16(30) }, \
43}

◆ GENEROUS_WHEN_LOW_HEART_DROPS

#define GENEROUS_WHEN_LOW_HEART_DROPS ( attempts)
Value:
{ \
{ F16(20), F16(80), attempts, F16(60) }, \
{ F16(30), F16(70), attempts, F16(50) }, \
{ F16(50), F16(60), attempts, F16(50) }, \
{ F16(80), F16(50), attempts, F16(40) }, \
{ F16(100), F16(30), attempts, F16(30) }, \
}

Definition at line 45 of file npc.h.

45#define GENEROUS_WHEN_LOW_HEART_DROPS(attempts) { \
46 { F16(20), F16(80), attempts, F16(60) }, \
47 { F16(30), F16(70), attempts, F16(50) }, \
48 { F16(50), F16(60), attempts, F16(50) }, \
49 { F16(80), F16(50), attempts, F16(40) }, \
50 { F16(100), F16(30), attempts, F16(30) }, \
51}

◆ STANDARD_FLOWER_DROPS

#define STANDARD_FLOWER_DROPS ( attempts)
Value:
{ \
{ F16(20), F16(50), attempts, F16(40) }, \
{ F16(30), F16(40), attempts, F16(40) }, \
{ F16(50), F16(40), attempts, F16(40) }, \
{ F16(80), F16(40), attempts, F16(40) }, \
{ F16(100), F16(30), attempts, F16(40) }, \
}

Definition at line 53 of file npc.h.

53#define STANDARD_FLOWER_DROPS(attempts) { \
54 { F16(20), F16(50), attempts, F16(40) }, \
55 { F16(30), F16(40), attempts, F16(40) }, \
56 { F16(50), F16(40), attempts, F16(40) }, \
57 { F16(80), F16(40), attempts, F16(40) }, \
58 { F16(100), F16(30), attempts, F16(40) }, \
59}

◆ GENEROUS_WHEN_LOW_FLOWER_DROPS

#define GENEROUS_WHEN_LOW_FLOWER_DROPS ( attempts)
Value:
{ \
{ F16(20), F16(70), attempts, F16(50) }, \
{ F16(30), F16(60), attempts, F16(50) }, \
{ F16(50), F16(50), attempts, F16(40) }, \
{ F16(80), F16(40), attempts, F16(40) }, \
{ F16(100), F16(30), attempts, F16(40) }, \
}

Definition at line 61 of file npc.h.

61#define GENEROUS_WHEN_LOW_FLOWER_DROPS(attempts) { \
62 { F16(20), F16(70), attempts, F16(50) }, \
63 { F16(30), F16(60), attempts, F16(50) }, \
64 { F16(50), F16(50), attempts, F16(40) }, \
65 { F16(80), F16(40), attempts, F16(40) }, \
66 { F16(100), F16(30), attempts, F16(40) }, \
67}

◆ REDUCED_FLOWER_DROPS

#define REDUCED_FLOWER_DROPS ( attempts)
Value:
{ \
{ F16(20), F16(40), attempts, F16(40) }, \
{ F16(30), F16(40), attempts, F16(40) }, \
{ F16(50), F16(40), attempts, F16(40) }, \
{ F16(80), F16(40), attempts, F16(40) }, \
{ F16(100), F16(30), attempts, F16(40) }, \
}

Definition at line 69 of file npc.h.

69#define REDUCED_FLOWER_DROPS(attempts) { \
70 { F16(20), F16(40), attempts, F16(40) }, \
71 { F16(30), F16(40), attempts, F16(40) }, \
72 { F16(50), F16(40), attempts, F16(40) }, \
73 { F16(80), F16(40), attempts, F16(40) }, \
74 { F16(100), F16(30), attempts, F16(40) }, \
75}

◆ OVERRIDE_MOVEMENT_SPEED

#define OVERRIDE_MOVEMENT_SPEED ( speed)    ((s32)(speed * 32767))

Definition at line 77 of file npc.h.

◆ NO_OVERRIDE_MOVEMENT_SPEED

#define NO_OVERRIDE_MOVEMENT_SPEED   OVERRIDE_MOVEMENT_SPEED(-1.0f)

Definition at line 78 of file npc.h.

Typedef Documentation

◆ FireBarCallback

typedef void(* FireBarCallback) (struct FireBarData *, s32)

Definition at line 120 of file npc.h.

◆ NpcGroupList

typedef NpcGroup NpcGroupList[]

Definition at line 289 of file npc.h.

◆ AIStateHandler

typedef void AIStateHandler(Evt *script, MobileAISettings *settings, EnemyDetectVolume *territory)

Definition at line 292 of file npc.h.

Enumeration Type Documentation

◆ TerritoryShape

Enumerator
SHAPE_CYLINDER 
SHAPE_RECT 

Definition at line 197 of file npc.h.

@ SHAPE_CYLINDER
Definition npc.h:197
@ SHAPE_RECT
Definition npc.h:197

Function Documentation

◆ basic_ai_check_player_dist()

b32 basic_ai_check_player_dist ( EnemyDetectVolume * arg0,
Enemy * arg1,
f32 arg2,
f32 arg3,
s8 arg4 )

Definition at line 429 of file 23680.c.

429 {
430 Npc* npc = get_npc_unsafe(enemy->npcID);
433 f32 x, y, z;
434 f32 dist;
436
437 if (enemy->aiFlags & AI_FLAG_CANT_DETECT_PLAYER) {
438 return false;
439 }
440
442 if (partnerStatus->actingPartner == PARTNER_BOW && partnerStatus->partnerActionState
443 && !(territory->detectFlags & AI_TERRITORY_IGNORE_HIDING)) {
444 return false;
445 }
446
447 if (partnerStatus->actingPartner == PARTNER_SUSHIE && partnerStatus->partnerActionState
448 && !(territory->detectFlags & AI_TERRITORY_IGNORE_HIDING)) {
449 return false;
450 }
451
452 if (territory->skipPlayerDetectChance < 0) {
453 return false;
454 }
455
456 if (territory->halfHeight <= fabsf(npc->pos.y - playerStatus->pos.y)
457 && !(territory->detectFlags & AI_TERRITORY_IGNORE_ELEVATION)) {
458 return false;
459 }
460
461 if (territory->sizeX | territory->sizeZ && is_point_outside_territory(territory->shape,
462 territory->pointX, territory->pointZ,
463 playerStatus->pos.x, playerStatus->pos.z,
464 territory->sizeX, territory->sizeZ)) {
465 return false;
466 }
467
468 if ((playerStatus->actionState == ACTION_STATE_USE_SPINNING_FLOWER)) {
469 return false;
470 }
471
472 // check for unbroken line of sight
473 if (enemy->aiDetectFlags & AI_DETECT_SIGHT) {
474 x = npc->pos.x;
475 y = npc->pos.y + npc->collisionHeight * 0.5;
476 z = npc->pos.z;
477 dist = dist2D(npc->pos.x, npc->pos.z, playerStatus->pos.x, playerStatus->pos.z);
479 &x, &y, &z,
480 dist, atan2(npc->pos.x, npc->pos.z, playerStatus->pos.x, playerStatus->pos.z),
481 0.1f, 0.1f)) {
482 return false;
483 }
484 }
485
486 if (territory->skipPlayerDetectChance == 0) {
488 } else {
489 skipCheckForPlayer = rand_int(territory->skipPlayerDetectChance + 1);
490 }
491
492 if (skipCheckForPlayer == 0) {
493 if (enemy->aiDetectFlags & AI_DETECT_SENSITIVE_MOTION) {
494 if (playerStatus->actionState == ACTION_STATE_WALK) {
495 radius *= 1.15;
496 } else if (playerStatus->actionState == ACTION_STATE_RUN) {
497 radius *= 1.3;
498 }
499 }
500 x = npc->pos.x;
501 z = npc->pos.z;
502 if (useWorldYaw & 0xFF) {
503 add_vec2D_polar(&x, &z, fwdPosOffset, npc->yaw);
504 } else {
505 add_vec2D_polar(&x, &z, fwdPosOffset, 270.0f - npc->renderYaw);
506 }
507 if (dist2D(x, z, playerStatus->pos.x, playerStatus->pos.z) <= radius) {
508 return true;
509 }
510 }
511
512 return false;
513}
b32 is_point_outside_territory(s32 shape, f32 centerX, f32 centerZ, f32 pointX, f32 pointZ, f32 sizeX, f32 sizeZ)
Definition 23680.c:412
BSS s32 PopupMenu_SelectedIndex
#define rand_int
#define atan2
@ AI_DETECT_SIGHT
Definition enums.h:4206
@ AI_DETECT_SENSITIVE_MOTION
Definition enums.h:4207
@ AI_FLAG_CANT_DETECT_PLAYER
Definition enums.h:4155
@ COLLIDER_FLAG_IGNORE_PLAYER
Definition enums.h:4281
@ COLLISION_IGNORE_ENTITIES
Definition enums.h:4283
@ AI_TERRITORY_IGNORE_HIDING
Definition enums.h:4212
@ AI_TERRITORY_IGNORE_ELEVATION
Definition enums.h:4213
@ PARTNER_BOW
Definition enums.h:2928
@ PARTNER_SUSHIE
Definition enums.h:2926
@ ACTION_STATE_USE_SPINNING_FLOWER
Definition enums.h:2443
@ ACTION_STATE_WALK
Definition enums.h:2413
@ ACTION_STATE_RUN
Definition enums.h:2414
f32 fabsf(f32 f)
f32 dist2D(f32 ax, f32 ay, f32 bx, f32 by)
Definition 43F0.c:670
b32 npc_test_move_simple_with_slipping(s32, f32 *, f32 *, f32 *, f32, f32, f32, f32)
void add_vec2D_polar(f32 *x, f32 *y, f32 r, f32 theta)
Definition 43F0.c:685
Npc * get_npc_unsafe(s32 npcID)
Definition npc.c:992
f32 renderYaw
s16 collisionHeight
Vec3f pos
PartnerStatus gPartnerStatus
Definition partners.c:42
PlayerStatus gPlayerStatus
Definition 77480.c:38

Referenced by AvoidPlayerAI_Chase(), AvoidPlayerAI_ChaseInit(), basic_ai_chase(), basic_ai_loiter(), basic_ai_wander(), CleftAI_FindPlayer(), CleftAI_Hiding(), CleftAI_ReturnHome(), ClubbaNappingAI_Loiter(), ClubbaNappingAI_ReturnHome(), ClubbaNappingAI_Sleep(), FlyingAI_Loiter(), FlyingAI_Wander(), FlyingNoAttackAI_13(), GuardAI_Chase(), GuardAI_Idle(), GuardAI_ReturnHome(), HoppingAI_Chase(), HoppingAI_Hop(), HoppingAI_Loiter(), LakituAI_Loiter(), LakituAI_Wander(), MagikoopaAI_CanShootSpell(), PatrolAI_Chase(), PatrolAI_Loiter(), PatrolAI_Move(), PiranhaPlantAI_01(), PiranhaPlantAI_LosePlayer(), SentinelAI_Chase(), SentinelAI_Descend(), SentinelAI_ReturnHome(), and UnkNpcAIFunc48().

◆ STUB_npc_callback()

void STUB_npc_callback ( Npc * npc)

The default Npc::onUpdate and Npc::onRender callback.

Definition at line 48 of file npc.c.

48 {
49}

Referenced by create_npc_impl().

◆ mtx_ident_mirror_y()

void mtx_ident_mirror_y ( Matrix4f mtx)

Definition at line 51 of file npc.c.

51 {
52 guMtxIdentF(mtx);
53 mtx[0][0] = 1.0f;
54 mtx[1][1] = -1.0f;
55 mtx[2][2] = 1.0f;
56 mtx[3][3] = 1.0f;
57}

Referenced by appendGfx_npc().

◆ clear_npcs()

void clear_npcs ( void )

Definition at line 59 of file npc.c.

59 {
60 s32 i;
61
63 gCurrentNpcListPtr = &gWorldNpcList;
64 } else {
65 gCurrentNpcListPtr = &gBattleNpcList;
66 }
67
68 for (i = 0; i < MAX_NPCS; i++) {
69 (*gCurrentNpcListPtr)[i] = nullptr;
70 }
71
72 gNpcCount = 0;
73 gNpcPlayerCollisionsEnabled = true;
74}
@ CONTEXT_WORLD
Definition enums.h:3562
s16 gNpcCount
Definition npc.c:9
#define MAX_NPCS
Definition macros.h:90
GameStatus * gGameStatusPtr
Definition main_loop.c:31

Referenced by load_demo_battle(), load_engine_data(), load_map_by_IDs(), state_init_logos(), state_init_title_screen(), state_step_battle(), state_step_demo(), state_step_intro(), state_step_pause(), state_step_startup(), and state_step_title_screen().

◆ init_npc_list()

void init_npc_list ( void )

Points the current NPC list to the world or battle lists depending on game state.

Definition at line 76 of file npc.c.

76 {
78 gCurrentNpcListPtr = &gWorldNpcList;
79 } else {
80 gCurrentNpcListPtr = &gBattleNpcList;
81 }
82
83 gNpcCount = 0;
84 gNpcPlayerCollisionsEnabled = true;
85}

Referenced by state_step_end_battle(), and state_step_unpause().

◆ create_npc_impl()

s32 create_npc_impl ( NpcBlueprint * blueprint,
AnimID * animList,
s32 skipLoadingAnims )

Definition at line 87 of file npc.c.

87 {
88 Npc* npc;
89 s32 i;
90 s32 j;
91
92 for (i = 0; i < MAX_NPCS; i++) {
93 if ((*gCurrentNpcListPtr)[i] == nullptr) {
94 break;
95 }
96 }
97 ASSERT(i < MAX_NPCS);
98
99 (*gCurrentNpcListPtr)[i] = npc = heap_malloc(sizeof(*npc));
100 gNpcCount++;
101 ASSERT(npc != nullptr);
102
104 if (isPeachNpc) {
106 }
107
108 npc->collisionDiameter = 32;
109 npc->collisionHeight = 64;
110 npc->renderMode = 13;
111 npc->blur.any = nullptr;
112 npc->yaw = 0.0f;
113 npc->jumpVel = 0.0f;
114 npc->pos.x = 0.0f;
115 npc->pos.y = 0.0f;
116 npc->pos.z = 0.0f;
117 npc->colliderPos.x = 0.0f;
118 npc->colliderPos.y = 0.0f;
119 npc->colliderPos.z = 0.0f;
120 npc->rotPivotOffsetY = 0.0f;
121 npc->rot.x = 0.0f;
122 npc->rot.y = 0.0f;
123 npc->rot.z = 0.0f;
124 npc->homePos.x = 0.0f;
125 npc->homePos.y = 0.0f;
126 npc->homePos.z = 0.0f;
127 npc->unk_96 = 0; // TODO: fix
128 npc->verticalRenderOffset = 0;
129 npc->alpha = 255;
130 npc->hideAlpha = 255;
131 npc->jumpScale = 1.0f;
132 npc->moveSpeed = 4.0f;
133 npc->scale.x = 1.0f;
134 npc->scale.y = 1.0f;
135 npc->scale.z = 1.0f;
136 npc->curAnim = blueprint->initialAnim;
137 npc->animationSpeed = 1.0f;
138 npc->renderYaw = 0.0f;
139 npc->imgfxType = IMGFX_CLEAR;
140 npc->imgfxFlags = 0;
142 npc->isFacingAway = false;
143 npc->yawCamOffset = 0;
145 npc->curFloor = NO_COLLIDER;
146 npc->curWall = NO_COLLIDER;
149 npc->screenSpaceOffset2D[0] = 0.0f;
150 npc->screenSpaceOffset2D[1] = 0.0f;
151 npc->verticalStretch = 1.0f;
152
153 for (j = 0; j < ARRAY_COUNT(npc->decorations); j++) {
154 npc->decorations[j] = 0;
155 npc->decorationType[j] = 0;
156 }
157
158 npc->onUpdate = blueprint->onUpdate;
159 if (npc->onUpdate == nullptr) {
161 }
162
163 npc->onRender = blueprint->onRender;
164 if (npc->onRender == nullptr) {
166 }
167 if (!isPeachNpc) {
168 npc->extraAnimList = animList;
169 if (!(npc->flags & NPC_FLAG_HAS_NO_SPRITE)) {
170 if (!(npc->flags & NPC_FLAG_PARTNER)) {
171 npc->spriteInstanceID = spr_load_npc_sprite(npc->curAnim, animList);
172 } else {
174 }
175 } else {
177 }
178 }
179
181 npc->shadowScale = 1.0f;
182
185 }
186 return i;
187}
#define ASSERT(condition)
@ IMGFX_CLEAR
Definition enums.h:4702
@ NPC_PAL_ADJUST_NONE
Definition enums.h:1954
@ SHADOW_VARYING_CIRCLE
Definition enums.h:2521
@ COLLIDER_FLAG_IGNORE_NPC
Definition enums.h:4282
@ NPC_FLAG_HAS_NO_SPRITE
Definition enums.h:3056
@ NPC_FLAG_HAS_SHADOW
Definition enums.h:3036
@ NPC_FLAG_ENABLED
Definition enums.h:3032
@ NPC_FLAG_TOUCHES_GROUND
Definition enums.h:3054
@ NPC_FLAG_DIRTY_SHADOW
Definition enums.h:3048
@ NPC_FLAG_PARTNER
Definition enums.h:3058
@ NPC_FLAG_INVISIBLE
Definition enums.h:3033
@ NPC_FLAG_NO_ANIMS_LOADED
Definition enums.h:3062
s32 create_shadow_type(s32 type, f32 x, f32 y, f32 z)
Definition entity.c:1525
void * heap_malloc(s32 size)
Definition heap.c:34
void STUB_npc_callback(Npc *npc)
The default Npc::onUpdate and Npc::onRender callback.
Definition npc.c:48
#define ARRAY_COUNT(arr)
Definition macros.h:39
#define BATTLE_NPC_ID_BIT
Definition macros.h:156
#define NO_COLLIDER
Definition macros.h:167
s32 spr_load_npc_sprite(s32 animID, u32 *extraAnimList)
Definition sprite.c:1015
@ SPRITE_ID_TAIL_ALLOCATE
Definition sprite.h:18
void(* onRender)(struct Npc *)
Definition npc.h:89
void(* onUpdate)(struct Npc *)
Definition npc.h:88
s32 initialAnim
Definition npc.h:87
s32 flags
Definition npc.h:86
struct EffectInstance * decorations[2]
s16 collisionDiameter
void(* onUpdate)(struct Npc *)
Run before anything else for this NPC in update_npcs()
f32 jumpScale
Vec3f scale
f32 jumpVel
f32 animationSpeed
s8 renderMode
s16 unk_96
s16 imgfxType
s32 flags
s8 decorationType[2]
s32 spriteInstanceID
AnimID curAnim
s8 palSwapType
f32 shadowScale
u8 hideAlpha
Used when hiding NPCs; Multiplied with Npc::alpha.
f32 screenSpaceOffset2D[2]
s32 collisionChannel
b16 isFacingAway
Vec3f colliderPos
s16 turnAroundYawAdjustment
Vec3f rot
s8 verticalRenderOffset
s16 yawCamOffset
u16 imgfxFlags
s8 palSwapPrevType
f32 verticalStretch
AnimID * extraAnimList
s16 curFloor
f32 rotPivotOffsetY
f32 moveSpeed
Vec3s homePos
union Npc::@0 blur
s16 curWall
s32 shadowIndex
void(* onRender)(struct Npc *)
Run after the display list for this NPC is built.

Referenced by create_basic_npc(), create_peach_npc(), and create_standard_npc().

◆ create_basic_npc()

s32 create_basic_npc ( NpcBlueprint * blueprint)

Definition at line 189 of file npc.c.

189 {
190 return create_npc_impl(blueprint, nullptr, false);
191}
s32 create_npc_impl(NpcBlueprint *blueprint, AnimID *animList, s32 isPeachNpc)
Definition npc.c:87

Referenced by create_partner_npc().

◆ create_standard_npc()

s32 create_standard_npc ( NpcBlueprint * blueprint,
AnimID * animList )

Definition at line 193 of file npc.c.

193 {
194 return create_npc_impl(blueprint, animList, false);
195}

Referenced by create_encounters(), and peach_make_disguise_npc().

◆ create_peach_npc()

s32 create_peach_npc ( NpcBlueprint * blueprint)

Definition at line 197 of file npc.c.

197 {
198 return create_npc_impl(blueprint, nullptr, true);
199}

Referenced by create_encounters().

◆ free_npc_by_index()

void free_npc_by_index ( s32 listIndex)

Definition at line 201 of file npc.c.

201 {
202 Npc* npc;
203 s32 i;
204
205 listIndex &= ~BATTLE_NPC_ID_BIT;
206
207 npc = (*gCurrentNpcListPtr)[listIndex];
208 if (npc != nullptr) {
209 if (npc->flags) {
210 if (npc->blur.any != nullptr) {
211 heap_free(npc->blur.any);
212 npc->blur.any = nullptr;
213 }
214
215 if (!(npc->flags & NPC_FLAG_NO_ANIMS_LOADED)) {
217 }
218
220
221 for (i = 0; i < MAX_NPC_DECORATIONS; i++) {
222 npc_remove_decoration(npc, i);
223 }
224
225 if (npc->flags & NPC_FLAG_MOTION_BLUR) {
226 disable_npc_blur(npc);
227 }
228
229 heap_free((*gCurrentNpcListPtr)[listIndex]);
230 (*gCurrentNpcListPtr)[listIndex] = nullptr;
231 gNpcCount--;
232 }
233 }
234}
#define MAX_NPC_DECORATIONS
@ NPC_FLAG_MOTION_BLUR
Definition enums.h:3052
s32 heap_free(void *ptr)
Definition heap.c:42
void delete_shadow(s32)
Definition entity.c:626
void disable_npc_blur(Npc *npc)
Definition npc.c:1085
void npc_remove_decoration(Npc *npc, s32 idx)
Definition npc.c:1738
s32 spr_free_sprite(s32 spriteInstanceID)
Definition sprite.c:1162

Referenced by action_update_parasol(), partner_free_npc(), and peach_force_disguise_action().

◆ free_npc()

void free_npc ( Npc * npc)

Definition at line 236 of file npc.c.

236 {
237 s32 i;
238
239 if (npc->blur.any != nullptr) {
240 heap_free(npc->blur.any);
241 npc->blur.any = nullptr;
242 }
243
244 if (!(npc->flags & NPC_FLAG_NO_ANIMS_LOADED)) {
246 }
247
249
250 for (i = 0; i < MAX_NPC_DECORATIONS; i++) {
251 npc_remove_decoration(npc, i);
252 }
253
254 if (npc->flags & NPC_FLAG_MOTION_BLUR) {
255 disable_npc_blur(npc);
256 }
257
258 heap_free(npc);
259
260 for (i = 0; i < MAX_NPCS; i++) {
261 if ((*gCurrentNpcListPtr)[i] == npc) {
262 break;
263 }
264 }
265
266 (*gCurrentNpcListPtr)[i] = nullptr;
267 gNpcCount--;
268}

Referenced by kill_enemy().

◆ get_npc_by_index()

◆ npc_do_world_collision()

void npc_do_world_collision ( Npc * npc)

Definition at line 277 of file npc.c.

277 {
279 s32 hit;
280 f32 testX;
281 f32 testY;
282 f32 testZ;
283
286 } else if (
287 (npc->pos.x != npc->colliderPos.x)
288 || (npc->pos.y != npc->colliderPos.y)
289 || (npc->pos.z != npc->colliderPos.z)
291 ) {
293 testAngle = clamp_angle(npc->yaw);
294 testX = npc->pos.x;
295 testY = npc->pos.y;
296 testZ = npc->pos.z;
297
298 if (!(npc->flags & NPC_FLAG_PARTNER)) {
300 } else {
302 }
303
304 if (hit) {
307 npc->pos.x = testX;
308 npc->pos.z = testZ;
309 } else {
311 }
312
313 testAngle = clamp_angle(npc->yaw + 45.0f);
314 testX = npc->pos.x;
315 testY = npc->pos.y;
316 testZ = npc->pos.z;
317
318 if (!(npc->flags & NPC_FLAG_PARTNER)) {
320 } else {
322 }
323
324 if (hit) {
326 npc->pos.x = testX;
327 npc->pos.z = testZ;
328 } else {
330 }
331
332 testAngle = clamp_angle(npc->yaw - 45.0f);
333 testX = npc->pos.x;
334 testY = npc->pos.y;
335 testZ = npc->pos.z;
336 if (!(npc->flags & NPC_FLAG_PARTNER)) {
338 } else {
340 }
341
342 if (hit != 0) {
344 npc->pos.x = testX;
345 npc->pos.z = testZ;
346 } else {
348 }
349
350 if (npc->flags & NPC_FLAG_PARTNER) {
351 testAngle = clamp_angle(npc->yaw + 45.0f + 180.0f);
352 testX = npc->pos.x;
353 testY = npc->pos.y;
354 testZ = npc->pos.z;
356 npc->collisionDiameter) != 0) {
358 npc->pos.x = testX;
359 npc->pos.z = testZ;
360 } else {
362 }
363
364 testAngle = clamp_angle((npc->yaw - 45.0f) + 180.0f);
365 testX = npc->pos.x;
366 testY = npc->pos.y;
367 testZ = npc->pos.z;
369 npc->collisionDiameter) != 0) {
371 npc->pos.x = testX;
372 npc->pos.z = testZ;
373 return;
374 }
376 }
377 }
378}
#define clamp_angle
@ NPC_FLAG_WORLD_COLLISION_DIRTY
Definition enums.h:3059
@ NPC_FLAG_IGNORE_WORLD_COLLISION
Definition enums.h:3038
@ NPC_FLAG_COLLDING_FORWARD_WITH_WORLD
Definition enums.h:3046
@ NPC_FLAG_COLLDING_WITH_WORLD
Definition enums.h:3045
s32 npc_test_move_complex_with_slipping(s32, f32 *, f32 *, f32 *, f32, f32, f32, f32)
b32 npc_test_move_taller_with_slipping(s32, f32 *, f32 *, f32 *, f32, f32, f32, f32)
s32 NpcHitQueryColliderID

Referenced by partner_get_out(), partner_move_to_goal(), and update_npcs().

◆ npc_do_other_npc_collision()

void npc_do_other_npc_collision ( Npc * npc)

Definition at line 380 of file npc.c.

380 {
381 Npc* otherNpc;
382 f32 angle;
384 f32 thisBuf;
387 f32 xDiff, zDiff;
388 f32 dist;
390 s32 i;
391
394 thisBuf = npc->collisionDiameter * 0.5f;
395 thisX = npc->pos.x;
396 thisY = npc->pos.y;
397 thisZ = npc->pos.z;
398
399 for (i = 0; i < MAX_NPCS; i++) {
401 if (otherNpc != nullptr && npc != otherNpc) {
402 if (otherNpc->flags != 0 && !(otherNpc->flags & (NPC_FLAG_SUSPENDED | NPC_FLAG_IGNORE_PLAYER_COLLISION))) {
403 if (!(otherNpc->pos.y + otherNpc->collisionHeight < thisY) &&
404 !(thisY + npc->collisionHeight < otherNpc->pos.y))
405 {
406 otherX = otherNpc->pos.x;
407 xDiff = otherX - thisX;
408 otherZ = otherNpc->pos.z;
409 zDiff = otherZ - thisZ;
410 otherBuf = otherNpc->collisionDiameter * 0.5f;
411 dist = sqrtf(SQ(xDiff) + SQ(zDiff));
412
413 if (!(thisBuf + otherBuf <= dist)) {
414 collision = false;
415 if (npc->flags & NPC_FLAG_PARTNER) {
417 } else if (!(otherNpc->flags & NPC_FLAG_PARTNER) ||
419 {
420 collision = true;
421 }
422
423 if (collision) {
425 dist = (thisBuf + otherBuf) - dist;
426 xDiff = dist * sin_rad(angle);
427 zDiff = -dist * cos_rad(angle);
428 thisX += xDiff * 0.1f;
429 thisZ += zDiff * 0.1f;
430 }
432 }
433 }
434 }
435 }
436 }
437 npc->pos.x = thisX;
438 npc->pos.z = thisZ;
439 }
440}
#define sqrtf
@ PARTNER_ACTION_NONE
Definition enums.h:2966
@ NPC_FLAG_SUSPENDED
Definition enums.h:3063
@ NPC_FLAG_IGNORE_PLAYER_COLLISION
Definition enums.h:3040
@ NPC_FLAG_COLLIDING_WITH_NPC
Definition enums.h:3057
f32 cos_rad(f32 x)
Definition 43F0.c:717
f32 sin_rad(f32 x)
Definition 43F0.c:713
Npc * get_npc_by_index(s32 listIndex)
Definition npc.c:270
#define DEG_TO_RAD(deg)
Definition macros.h:145
#define SQ(x)
Definition macros.h:177

Referenced by update_npcs().

◆ npc_do_player_collision()

s32 npc_do_player_collision ( Npc * npc)
Returns
true if a collision occurred

Definition at line 442 of file npc.c.

442 {
445 f32 playerYaw, yaw;
446 f32 npcX, npcZ;
447 f32 dist, colDist, distToNpc;
450
452 return false;
453 }
454
455 if (npc->flags & NPC_FLAG_PARTNER) {
456 return false;
457 }
458
459 if (!gNpcPlayerCollisionsEnabled) {
460 return false;
461 }
462
463 if (playerStatus->pos.y + playerStatus->colliderHeight < npc->pos.y) {
464 return false;
465 }
466
467 if (npc->pos.y + npc->collisionHeight < playerStatus->pos.y) {
468 return false;
469 }
470
472 playerZ = playerStatus->pos.z;
473
475 playerColRadius = playerStatus->colliderDiameter / 2;
476
477 npcX = npc->pos.x;
478 npcZ = npc->pos.z;
479
480 deltaX = playerX - npcX;
481 deltaZ = playerZ - npcZ;
482
485 if (colDist < distToNpc) {
486 return false;
487 }
488
490
491 npcX = npc->colliderPos.x;
492 npcZ = npc->colliderPos.z;
493
494 deltaX = playerX - npcX;
495 deltaZ = playerZ - npcZ;
496
497 dist = sqrtf(SQ(deltaX) + SQ(deltaZ));
498 yaw = atan2(playerX, playerZ, npcX, npcZ);
499
500 playerYaw = playerStatus->targetYaw;
501 dist = colDist - dist;
502 deltaX = dist * sin_rad(DEG_TO_RAD(yaw));
503 deltaZ = -dist * cos_rad(DEG_TO_RAD(yaw));
504
505 if (playerStatus->animFlags & PA_FLAG_RIDING_PARTNER) {
506 if (fabsf(get_clamped_angle_diff(yaw, playerYaw)) < 45.0f) {
507 playerStatus->pos.x -= deltaX;
508 playerStatus->pos.z -= deltaZ;
511 } else {
512 playerStatus->pos.x -= deltaX * 0.5f;
513 playerStatus->pos.z -= deltaZ * 0.5f;
514 wPartnerNpc->pos.x -= deltaX * 0.5f;
515 wPartnerNpc->pos.z -= deltaZ * 0.5f;
516 }
517 } else {
519 playerStatus->pos.x -= deltaX * 0.4f;
520 playerStatus->pos.z -= deltaZ * 0.4f;
521 } else {
522 dist = get_clamped_angle_diff(yaw, playerYaw); // required to match
523 if (fabsf(dist) < 45.0f) {
524 playerStatus->pos.x -= deltaX;
525 playerStatus->pos.z -= deltaZ;
526 } else {
527 playerStatus->pos.x -= deltaX * 0.5f;
528 playerStatus->pos.z -= deltaZ * 0.5f;
529 }
530 }
531 }
532 npc->pos.x = npc->colliderPos.x;
533 npc->pos.y = npc->colliderPos.y;
534 npc->pos.z = npc->colliderPos.z;
535 return true;
536}
@ PS_FLAG_FALLING
Definition enums.h:3070
@ PS_FLAG_JUMPING
Definition enums.h:3069
@ PA_FLAG_NPC_COLLIDED
Definition enums.h:3140
@ PA_FLAG_RIDING_PARTNER
Definition enums.h:3150
f32 get_clamped_angle_diff(f32, f32)
Definition 43F0.c:606
Npc * wPartnerNpc
Definition partners.c:43

Referenced by update_npcs().

◆ npc_try_apply_gravity()

void npc_try_apply_gravity ( Npc * npc)

Definition at line 540 of file npc.c.

540 {
541 f32 x, y, z, testLength;
542 f32 length;
543 s32 hitID;
544
545 if (!(npc->flags & NPC_FLAG_GRAVITY)) {
546 return;
547 }
548
549 if (npc->flags & NPC_FLAG_JUMPING) {
551 return;
552 }
553
554 npc->jumpScale = 1.0f;
555 npc->jumpVel -= npc->jumpScale;
556 npc->pos.y += npc->jumpVel;
557
558 x = npc->pos.x;
559 y = npc->pos.y + 13;
560 z = npc->pos.z;
561 testLength = length = fabsf(npc->jumpVel) + 16;
562
563 if (!(npc->flags & NPC_FLAG_PARTNER)) {
564 hitID = npc_raycast_down_sides(npc->collisionChannel, &x, &y, &z, &length);
565 } else {
566 hitID = npc_raycast_down_around(npc->collisionChannel, &x, &y, &z, &length, npc->yaw, npc->collisionDiameter);
567 }
568
569 if (hitID && length <= testLength) {
570 npc->jumpVel = 0.0f;
571 npc->flags |= NPC_FLAG_GROUNDED;
572 npc->pos.y = y;
574 } else {
576 }
577}
#define npc_raycast_down_sides
@ NPC_FLAG_JUMPING
Definition enums.h:3043
@ NPC_FLAG_GRAVITY
Definition enums.h:3041
@ NPC_FLAG_GROUNDED
Definition enums.h:3044
b32 npc_raycast_down_around(s32, f32 *, f32 *, f32 *, f32 *, f32, f32)

Referenced by update_npcs().

◆ npc_try_snap_to_ground()

s32 npc_try_snap_to_ground ( Npc * npc,
f32 velocity )

Definition at line 580 of file npc.c.

580 {
581 f32 x, y, z, testLength;
582 f32 length;
583 s32 hitID;
584
585 if (npc->flags & (NPC_FLAG_GRAVITY | NPC_FLAG_FLYING)) {
586 return false;
587 }
588
589 if (npc->flags & NPC_FLAG_JUMPING) {
591 return false;
592 }
593
594 length = testLength = fabsf(velocity) + 16;
595 x = npc->pos.x;
596 y = npc->pos.y + 13;
597 z = npc->pos.z;
598
599 if (!(npc->flags & NPC_FLAG_PARTNER)) {
600 hitID = npc_raycast_down_sides(npc->collisionChannel, &x, &y, &z, &length);
601 } else {
602 hitID = npc_raycast_down_around(npc->collisionChannel, &x, &y, &z, &length, npc->yaw, npc->collisionDiameter);
603 }
604
605 if (hitID != 0 && length <= testLength) {
606 npc->pos.y = y;
608 npc->flags |= NPC_FLAG_GROUNDED;
609 return true;
610 }
611
613 return false;
614}
@ NPC_FLAG_FLYING
Definition enums.h:3035

Referenced by partner_get_out(), and update_npcs().

◆ update_npcs()

void update_npcs ( void )

Updates all NPCs.

Definition at line 616 of file npc.c.

616 {
618 f32 x, y, z;
620
623 s32 i;
624
625 for (i = 0; i < MAX_NPCS; i++) {
626 Npc* npc = (*gCurrentNpcListPtr)[i];
627
628 if (npc != nullptr) {
629 if (npc->flags != 0) {
632 continue;
633 }
634
635 npc->onUpdate(npc);
638 } else {
640 }
641
642 npc->curFloor = NO_COLLIDER;
643 npc->curWall = NO_COLLIDER;
645
648 npc_try_snap_to_ground(npc, 0.0f);
651
652 if (npc->flags & NPC_FLAG_MOTION_BLUR) {
653 update_npc_blur(npc);
654 }
655
656 if ((npc->pos.y < -2000.0f) && !(npc->flags & NPC_FLAG_PARTNER)) {
657 npc->pos.y = playerStatus->pos.y;
658 npc->jumpVel = 0.0f;
659 npc->moveSpeed = 0.0f;
660 npc->jumpScale = 0.0f;
661 npc->flags &= ~NPC_FLAG_JUMPING;
662 }
663
664 if (!(npc->flags & NPC_FLAG_NO_ANIMS_LOADED)) {
665 if (!(npc->flags & NPC_FLAG_HAS_NO_SPRITE)) {
666 if (npc->curAnim != 0) {
667 if (npc->spriteInstanceID >= 0) {
669 }
670 }
671 }
672 } else {
674 }
675
676 if (npc->flags & NPC_FLAG_HAS_SHADOW) {
677 Shadow* shadow = get_shadow_by_index(npc->shadowIndex);
679
681 if (npc->flags & NPC_FLAG_REFLECT_WALL) {
683 }
684
685 x = npc->pos.x;
686 y = npc->pos.y;
687 z = npc->pos.z;
688 if (!(npc->flags & NPC_FLAG_NO_SHADOW_RAYCAST)) {
689 if ( x != npc->colliderPos.x
690 || y != npc->colliderPos.y
691 || z != npc->colliderPos.z
692 || (npc->flags & NPC_FLAG_DIRTY_SHADOW)
693 ) {
694 x = npc->pos.x;
695 y = npc->pos.y + (npc->collisionHeight / 2);
696 z = npc->pos.z;
697 hitLength = 1000.0f;
700 shadow->pos.x = x;
701 shadow->pos.y = y;
702 shadow->pos.z = z;
703 shadow->rot.x = hitYaw;
704 shadow->rot.y = npc->renderYaw;
705 shadow->rot.z = hitPitch;
706 shadow->scale.x *= npc->shadowScale;
708 }
709 } else {
711 shadow->pos.x = npc->pos.x;
712 shadow->pos.z = npc->pos.z;
713 } else {
714 shadow->pos.x = npc->pos.x;
715 shadow->pos.y = npc->pos.y;
716 shadow->pos.z = npc->pos.z;
717 }
718 }
719 }
720
721 npc->colliderPos.x = npc->pos.x;
722 npc->colliderPos.y = npc->pos.y;
723 npc->colliderPos.z = npc->pos.z;
725
726 if (!(npc->flags & NPC_FLAG_NO_ANIMS_LOADED)) {
727 if (!(npc->flags & NPC_FLAG_HAS_NO_SPRITE)) {
728 if (npc->spriteInstanceID < 0) {
729 npc->spriteInstanceID++;
730 if (npc->spriteInstanceID == -1) {
732 ASSERT(npc->spriteInstanceID >= 0);
734 }
735 }
736 }
737 }
738 }
739 }
740 }
741 }
742}
s16 entityModelID
Vec3f scale
EntityModel * get_entity_model(s32 idx)
@ ENTITY_MODEL_FLAG_REFLECT
Definition enums.h:4604
@ GLOBAL_OVERRIDES_800
Definition enums.h:3915
@ GLOBAL_OVERRIDES_400
Definition enums.h:3914
@ NPC_FLAG_IGNORE_ENTITY_COLLISION
Definition enums.h:3047
@ NPC_FLAG_REFLECT_WALL
Definition enums.h:3049
@ NPC_FLAG_INACTIVE
Definition enums.h:3034
@ NPC_FLAG_NO_SHADOW_RAYCAST
Definition enums.h:3037
@ NPC_FLAG_DONT_UPDATE_SHADOW_Y
Definition enums.h:3042
b32 entity_raycast_down(f32 *, f32 *, f32 *, f32 *, f32 *, f32 *)
Mostly used for shadows.
Definition entity.c:1634
Shadow * get_shadow_by_index(s32 index)
Definition entity.c:534
void set_npc_shadow_scale(Shadow *shadow, f32 height, f32 npcRadius)
Definition entity.c:1684
s32 npc_try_snap_to_ground(Npc *npc, f32 velocity)
Definition npc.c:580
void npc_do_other_npc_collision(Npc *npc)
Definition npc.c:380
void npc_try_apply_gravity(Npc *npc)
Definition npc.c:540
void npc_do_world_collision(Npc *npc)
Definition npc.c:277
void npc_update_decorations(Npc *npc)
Definition npc.c:1765
s32 npc_do_player_collision(Npc *npc)
Definition npc.c:442
void update_npc_blur(Npc *npc)
Definition npc.c:1094
s32 spr_update_sprite(s32 spriteInstanceID, s32 animID, f32 timeScale)
Definition sprite.c:1061
s32 spr_update_player_sprite(s32 spriteInstanceID, s32 animID, f32 timeScale)
Definition sprite.c:820
@ PLAYER_SPRITE_AUX1
Definition sprite.h:31
s32 gOverrideFlags
Definition main_loop.c:10

Referenced by state_step_battle(), state_step_change_map(), state_step_enter_world(), state_step_game_over(), state_step_intro(), state_step_logos(), state_step_pause(), state_step_title_screen(), state_step_unpause(), and state_step_world().

◆ npc_get_render_yaw()

f32 npc_get_render_yaw ( Npc * npc)

Definition at line 744 of file npc.c.

744 {
748 f32 yaw;
749 s32 direction;
750
754
756 direction = 0;
757 camRelativeYaw = 0.0f;
758 } else if (camRelativeYaw > 5.0f && camRelativeYaw < 175.0f) {
759 direction = 1;
760 camRelativeYaw = 180.0f;
761 } else {
762 // direction is close to flipping, use saved value
763 direction = 2;
765 }
766
768
770 if (npc->isFacingAway != direction && direction != 2) {
771 npc->isFacingAway = direction;
772
773 if (npc->isFacingAway) {
774 npc->turnAroundYawAdjustment = 180;
775 } else {
776 npc->turnAroundYawAdjustment = -180;
777 }
778
779 if (fabsf(get_clamped_angle_diff(cameraYaw, npc->yaw)) >= 90.0f) {
781 }
782 }
783
784 if (npc->turnAroundYawAdjustment != 0) {
785 if (npc->turnAroundYawAdjustment < 0) {
786 npc->turnAroundYawAdjustment += 20;
787 }
788 if (npc->turnAroundYawAdjustment > 0) {
789 npc->turnAroundYawAdjustment -= 20;
790 }
791 }
792
793 if (npc->flags & NPC_FLAG_FLIP_INSTANTLY) {
795 }
796
798 yaw = npc->renderYaw;
799 } else {
800 yaw = npc->renderYaw;
801 }
802 } else {
803 yaw = npc->renderYaw;
804 }
805 return yaw;
806}
@ GLOBAL_OVERRIDES_PREV_400
Definition enums.h:3918
@ GLOBAL_OVERRIDES_PREV_800
Definition enums.h:3919
@ NPC_FLAG_FLIP_INSTANTLY
Definition enums.h:3053
@ NPC_FLAG_IGNORE_CAMERA_FOR_YAW
Definition enums.h:3050
Camera gCameras[4]
Definition cam_main.c:16
s16 gCurrentCamID
Definition cam_main.c:12

Referenced by appendGfx_npc().

◆ appendGfx_npc()

void appendGfx_npc ( void * data)

Definition at line 808 of file npc.c.

808 {
809 Npc* npc = data;
811 f32 renderYaw = npc_get_render_yaw(npc);
812
813 guTranslateF(mtx1, npc->pos.x, npc->pos.y + npc->verticalRenderOffset, npc->pos.z);
814 if (npc->flags & NPC_FLAG_UPSIDE_DOWN) {
817 }
818
819 if (npc->rotPivotOffsetY != 0.0f) {
820 guTranslateF(mtx2, 0.0f, npc->rotPivotOffsetY, 0.0f);
822 }
823
824 if (npc->rot.y != 0.0f) {
825 guRotateF(mtx2, npc->rot.y, 0.0f, 1.0f, 0.0f);
827 }
828
829 if (npc->rot.x != 0.0f) {
830 guRotateF(mtx2, npc->rot.x, 1.0f, 0.0f, 0.0f);
832 }
833
834 if (npc->rot.z != 0.0f) {
835 guRotateF(mtx2, npc->rot.z, 0.0f, 0.0f, 1.0f);
837 }
838
839 if (npc->rotPivotOffsetY != 0.0f) {
840 guTranslateF(mtx2, 0.0f, -npc->rotPivotOffsetY, 0.0f);
842 }
843
844 if ((npc->screenSpaceOffset2D[0] != 0.0f) || (npc->screenSpaceOffset2D[1] != 0.0f)) {
847 }
848
849 if (npc->scale.x * SPRITE_WORLD_SCALE_D != 1.0f
850 || (npc->scale.y * npc->verticalStretch) * SPRITE_WORLD_SCALE_D != 1.0f
851 || npc->scale.z * SPRITE_WORLD_SCALE_D != 1.0f
852 ) {
856 }
857
858 if (!(npc->flags & NPC_FLAG_NO_ANIMS_LOADED)) {
859 if (!(npc->flags & NPC_FLAG_HAS_NO_SPRITE) && (npc->curAnim != 0) && (npc->spriteInstanceID >= 0)) {
860 npc_draw_with_palswap(npc, renderYaw, mtx1);
862 }
863 } else {
864 npc_draw_with_palswap(npc, renderYaw, mtx1);
866 }
867
868 if (npc->flags & NPC_FLAG_REFLECT_WALL) {
869 guTranslateF(mtx1, npc->pos.x, npc->pos.y + npc->verticalRenderOffset, -npc->pos.z);
870 if (npc->flags & NPC_FLAG_UPSIDE_DOWN) {
873 }
874 if ((npc->rot.y != 0.0f) || (npc->rot.x != 0.0f) || (npc->rot.z != 0.0f)) {
875 guRotateRPYF(mtx2, npc->rot.x, npc->rot.y, npc->rot.z);
877 }
878
879 if (npc->scale.x * SPRITE_WORLD_SCALE_D != 1.0f
880 || (npc->scale.y * npc->verticalStretch) * SPRITE_WORLD_SCALE_D != 1.0f
881 || npc->scale.z * SPRITE_WORLD_SCALE_D != 1.0f
882 ) {
888
889 }
890
891 if (!(npc->flags & NPC_FLAG_NO_ANIMS_LOADED)) {
892 if (!(npc->flags & NPC_FLAG_HAS_NO_SPRITE) && (npc->curAnim != 0)) {
893 spr_draw_npc_sprite(npc->spriteInstanceID, renderYaw, 0, 0, mtx1);
894 }
895 } else {
897 }
898 }
899
900 if (npc->flags & NPC_FLAG_REFLECT_FLOOR) {
901 guTranslateF(mtx1, npc->pos.x, -(npc->pos.y + npc->verticalRenderOffset), npc->pos.z);
904
905 if (npc->rot.y != 0.0f || npc->rot.x != 0.0f || npc->rot.z != 0.0f) {
906 guRotateRPYF(mtx2, npc->rot.x, npc->rot.y, npc->rot.z);
908 }
909
910 if (npc->scale.x * SPRITE_WORLD_SCALE_D != 1.0f
911 || (npc->scale.y * npc->verticalStretch) * SPRITE_WORLD_SCALE_D != 1.0f
912 || npc->scale.z * SPRITE_WORLD_SCALE_D != 1.0f
913 ) {
919 }
920 if (!(npc->flags & NPC_FLAG_NO_ANIMS_LOADED)) {
921 if (!(npc->flags & NPC_FLAG_HAS_NO_SPRITE) && (npc->curAnim != 0)) {
922 spr_draw_npc_sprite(npc->spriteInstanceID, renderYaw, 0, 0, mtx1);
923 }
924 } else {
926 }
927 }
928 npc->onRender(npc);
929}
f32 Matrix4f[4][4]
#define guRotateF
#define guTranslateF
#define guMtxCatF
#define guScaleF
@ NPC_FLAG_UPSIDE_DOWN
Definition enums.h:3039
@ NPC_FLAG_REFLECT_FLOOR
Definition enums.h:3051
void npc_draw_with_palswap(Npc *npc, s32 yaw, Matrix4f mtx)
Definition npc.c:1298
void mtx_ident_mirror_y(Matrix4f mtx)
Definition npc.c:51
f32 npc_get_render_yaw(Npc *npc)
Definition npc.c:744
#define SPRITE_WORLD_SCALE_D
Definition macros.h:151
s32 spr_get_notify_value(s32 spriteInstanceID)
Definition sprite.c:1158
s32 spr_draw_npc_sprite(s32 spriteInstanceID, s32 yaw, s32 alphaIn, PAL_PTR *paletteList, Matrix4f mtx)
Definition sprite.c:1094
s32 func_802DDEC4(s32 spriteIdx)
Definition sprite.c:954
s32 spr_draw_player_sprite(s32 spriteInstanceID, s32 yaw, s32 alphaIn, PAL_PTR *paletteList, Matrix4f mtx)
Definition sprite.c:867
@ DRAW_SPRITE_OVERRIDE_YAW
Definition sprite.h:25
s32 animNotifyValue

Referenced by render_npcs().

◆ render_npcs()

void render_npcs ( void )

Renders all NPCs.

Definition at line 931 of file npc.c.

931 {
935 f32 x, y, z, s;
937 s32 i;
938
939 for (i = 0; i < MAX_NPCS; i++) {
940 Npc* npc = (*gCurrentNpcListPtr)[i];
941 if ((npc != nullptr)
942 && (npc->flags != 0)
944 ) {
945 transform_point(cam->mtxPerspective, npc->pos.x, npc->pos.y, npc->pos.z, 1.0f, &x, &y, &z, &s);
946 if (!(s < 0.01) || !(s > -0.01)) {
947 renderDist = ((z * 5000.0f) / s) + 5000.0f;
948 if (renderDist < 0.0f) {
949 renderDist = 0.0f;
950 } else if (renderDist > 10000.0f) {
951 renderDist = 10000.0f;
952 }
953
954 renderTaskPtr->dist = -renderDist;
955 renderTaskPtr->appendGfxArg = npc;
956 renderTaskPtr->appendGfx = appendGfx_npc;
958
959 if (npc->flags & NPC_FLAG_HIDING) {
960 u8 r, g, b, a;
961 mdl_get_shroud_tint_params(&r, &g, &b, &a);
962 npc->hideAlpha = 255 - a;
963 } else {
964 npc->hideAlpha = 255;
965 }
966
967 if (npc->hideAlpha != 0) {
969 }
970
971 if (npc->flags & NPC_FLAG_MOTION_BLUR) {
972 renderTaskPtr->dist = -renderDist;
974 renderTaskPtr->appendGfxArg = npc;
977 }
978 }
979 }
980 }
981}
#define transform_point
#define queue_render_task
#define mdl_get_shroud_tint_params
@ RENDER_MODE_SURFACE_XLU_LAYER1
Definition enums.h:3316
@ NPC_FLAG_HIDING
Definition enums.h:3055
void appendGfx_npc_blur(void *data)
Definition npc.c:1110
void appendGfx_npc(void *data)
Definition npc.c:808

Referenced by render_frame().

◆ npc_move_heading()

◆ get_npc_unsafe()

Npc * get_npc_unsafe ( s32 npcID)

Definition at line 992 of file npc.c.

992 {
993 s32 i;
994 Npc* npc;
995
996 for (i = 0; i < MAX_NPCS; i++) {
997 npc = (*gCurrentNpcListPtr)[i];
998 if (npc != nullptr && npc->flags != 0 && npc->npcID == npcID) {
999 break;
1000 }
1001 }
1002 ASSERT(i < MAX_NPCS);
1003
1004 return npc;
1005}

Referenced by ai_check_player_dist(), ai_suspend_for_time(), ai_try_set_state(), AvoidPlayerAI_Chase(), AvoidPlayerAI_ChaseInit(), AvoidPlayerAI_LosePlayer(), basic_ai_chase(), basic_ai_chase_init(), basic_ai_check_player_dist(), basic_ai_found_player_jump(), basic_ai_found_player_jump_init(), basic_ai_loiter(), basic_ai_loiter_init(), basic_ai_lose_player(), basic_ai_suspend(), basic_ai_wander(), basic_ai_wander_init(), BooPatrolAI_Loiter(), BooPatrolAI_Move(), can_dismount(), check_conversation_trigger(), CleftAI_Ambush(), CleftAI_CanSeePlayer(), CleftAI_Disguise(), CleftAI_DisguiseInit(), CleftAI_FindPlayer(), CleftAI_FindPlayerInit(), CleftAI_Hiding(), CleftAI_HidingInit(), CleftAI_LosePlayer(), CleftAI_PostDisguise(), CleftAI_PreAmbush(), CleftAI_ReturnHome(), CleftAI_RevUp(), CleftAI_RevUpInit(), CleftAI_Tackle(), ClubbaNappingAI_FallAsleep(), ClubbaNappingAI_Init(), ClubbaNappingAI_Loiter(), ClubbaNappingAI_LoiterInit(), ClubbaNappingAI_ReturnHome(), ClubbaNappingAI_ReturnHomeInit(), ClubbaNappingAI_Sleep(), ClubbaNappingAI_WakeUp(), draw_encounters_pre_battle(), FlyingAI_Chase(), FlyingAI_ChaseInit(), FlyingAI_Jump(), FlyingAI_JumpInit(), FlyingAI_Loiter(), FlyingAI_LoiterInit(), FlyingAI_LosePlayer(), FlyingAI_Wander(), FlyingAI_WanderInit(), FlyingMagikoopaAI_10(), FlyingMagikoopaAI_11(), FlyingMagikoopaAI_15(), FlyingMagikoopaAI_16(), FlyingMagikoopaAI_17(), FlyingMagikoopaAI_20(), FlyingMagikoopaAI_21(), FlyingMagikoopaAI_22(), FlyingMagikoopaAI_23(), FlyingMagikoopaAI_24(), FlyingMagikoopaAI_50(), FlyingNoAttackAI_12(), FlyingNoAttackAI_13(), FlyingNoAttackAI_20(), func_80048F0C(), get_npc_pos(), GrooveGuyAI_02(), GrooveGuyAI_03(), GuardAI_Alert(), GuardAI_AlertInit(), GuardAI_Chase(), GuardAI_ChaseInit(), GuardAI_Idle(), GuardAI_IdleInit(), GuardAI_LosePlayer(), GuardAI_ReturnHome(), GuardAI_ReturnHomeInit(), HoppingAI_Chase(), HoppingAI_ChaseInit(), HoppingAI_Hop(), HoppingAI_HopInit(), HoppingAI_Loiter(), HoppingAI_LoiterInit(), HoppingAI_LosePlayer(), kill_enemy(), LakituAI_Loiter(), LakituAI_Wander(), MagikoopaAI_00(), MagikoopaAI_01(), MagikoopaAI_05(), MagikoopaAI_06(), MagikoopaAI_10(), MagikoopaAI_11(), MagikoopaAI_20(), MagikoopaAI_21(), MagikoopaAI_22(), MagikoopaAI_23(), MagikoopaAI_24(), MagikoopaAI_CanShootSpell(), MeleeHitbox_30(), MeleeHitbox_31(), MeleeHitbox_32(), MeleeHitbox_33(), MeleeHitbox_CanSeePlayer(), ParatroopaAI_Dive(), ParatroopaAI_Overshoot(), ParatroopaAI_Reset(), ParatroopaAI_Windup(), PatrolAI_Chase(), PatrolAI_ChaseInit(), PatrolAI_Jump(), PatrolAI_JumpInit(), PatrolAI_Loiter(), PatrolAI_LoiterInit(), PatrolAI_LosePlayer(), PatrolAI_Move(), PatrolAI_MoveInit(), PatrolAI_PostLoiter(), PatrolNoAttackAI_15(), PiranhaPlantAI_00(), PiranhaPlantAI_01(), PiranhaPlantAI_10(), PiranhaPlantAI_11(), PiranhaPlantAI_12(), PiranhaPlantAI_13(), PiranhaPlantAI_LosePlayer(), ProjectileHitbox_30(), ProjectileHitbox_31(), ProjectileHitbox_32(), ProjectileHitbox_33(), ProjectileHitbox_GetUsableProjectileID(), reset_outta_sight_alpha_on_menu_close(), SentinelAI_Chase(), SentinelAI_ChaseInit(), SentinelAI_Descend(), SentinelAI_DescendInit(), SentinelAI_GrabPlayer(), SentinelAI_LosePlayer(), SentinelAI_LosePlayerInit(), SentinelAI_PostLosePlayer(), SentinelAI_ReturnHome(), SentinelAI_ReturnHomeInit(), set_script_owner_npc_anim(), set_script_owner_npc_col_height(), ShyGuyPatrolAI_14(), ShyGuyPatrolAI_15(), ShyGuyPatrolAI_16(), ShyGuyPatrolAI_17(), ShyGuyWanderAI_14(), ShyGuyWanderAI_15(), ShyGuyWanderAI_16(), ShyGuyWanderAI_17(), spawn_drops(), SpearGuyAI_Loiter(), SpearGuyAI_LoiterInit(), StoneChompAI_ChaseInit(), StoneChompAI_HopInit(), sync_player_position(), UnkDistFunc(), UnkNpcAIFunc12(), UnkNpcAIFunc48(), update_encounters_neutral(), update_encounters_post_battle(), and update_player().

◆ get_npc_safe()

Npc * get_npc_safe ( s32 npcID)
Returns
nullptr if not found

Definition at line 1007 of file npc.c.

1007 {
1008 s32 i;
1009 Npc* npc;
1010
1011 for (i = 0; i < MAX_NPCS; i++) {
1012 npc = (*gCurrentNpcListPtr)[i];
1013 if (npc != nullptr && npc->flags != 0 && npc->npcID == npcID) {
1014 break;
1015 }
1016 }
1017 if (i >= MAX_NPCS) {
1018 return nullptr;
1019 }
1020
1021 return npc;
1022}

Referenced by resolve_npc(), sfx_play_sound_at_npc(), and unkVtxFunc001().

◆ enable_npc_shadow()

void enable_npc_shadow ( Npc * npc)

Definition at line 1024 of file npc.c.

1024 {
1025 Shadow* shadow;
1026
1027 if (!(npc->flags & NPC_FLAG_HAS_SHADOW)) {
1028 shadow = get_shadow_by_index(npc->shadowIndex);
1029 shadow->flags &= ~ENTITY_FLAG_HIDDEN;
1031 }
1032}

Referenced by CleftAI_PreAmbush(), and MagikoopaAI_11().

◆ disable_npc_shadow()

void disable_npc_shadow ( Npc * npc)

Definition at line 1034 of file npc.c.

1034 {
1035 Shadow* shadow;
1036
1037 if (npc->flags & NPC_FLAG_HAS_SHADOW) {
1038 shadow = get_shadow_by_index(npc->shadowIndex);
1039 shadow->flags |= ENTITY_FLAG_HIDDEN;
1042 }
1043}
@ ENTITY_FLAG_HIDDEN
Definition enums.h:2599

Referenced by action_update_use_tweester(), CleftAI_HidingInit(), MagikoopaAI_01(), and peach_make_disguise_npc().

◆ update_npc_blur()

void update_npc_blur ( Npc * npc)

Definition at line 1094 of file npc.c.

1094 {
1095 NpcMotionBlur* motionBlur = npc->blur.motion;
1096 s32 index = motionBlur->index;
1097
1098 motionBlur->posX[index] = npc->pos.x;
1099 motionBlur->posY[index] = npc->pos.y;
1100 motionBlur->posZ[index] = npc->pos.z;
1101
1102 index++;
1103 if (index >= 20) {
1104 index = 0;
1105 }
1106
1107 motionBlur->index = index;
1108}
Ring buffer of an NPC's position over the past 20 frames.

Referenced by update_npcs().

◆ appendGfx_npc_blur()

void appendGfx_npc_blur ( void * npc)

Definition at line 1110 of file npc.c.

1110 {
1111 Npc* npc = (Npc*) data;
1112 Matrix4f mtx, tempMtx;
1113 f32 x, y, z;
1114 f32 yaw;
1115 s32 strideIdx;
1116 s32 drawIdx;
1117 s32 bufPos;
1118 NpcMotionBlur* blur;
1119
1120 strideIdx = 0;
1121 drawIdx = 0;
1122 blur = npc->blur.motion;
1123 bufPos = blur->index;
1124
1125 while (true) {
1126 bufPos--;
1127 strideIdx++;
1128
1129 if (bufPos < 0) {
1130 bufPos = NPC_BLUR_FRAMES - 1;
1131 }
1132
1133 if (bufPos == blur->index) {
1134 break;
1135 }
1136
1137 // only draw every third blur frame
1138 if (strideIdx < 3) {
1139 continue;
1140 }
1141
1142 strideIdx = 0;
1143 drawIdx++;
1144
1145 // draw three blur samples
1146 if (drawIdx > 3) {
1147 break;
1148 }
1149
1150 x = blur->posX[bufPos];
1151 y = blur->posY[bufPos];
1152 z = blur->posZ[bufPos];
1153 set_npc_imgfx_all(npc->spriteInstanceID, IMGFX_SET_ALPHA, 255, 255, 255, 120 - (drawIdx * 20), 0);
1154 yaw = npc->renderYaw;
1155 guTranslateF(mtx, x, y, z);
1156
1157 if (npc->rot.y != 0.0f) {
1158 guRotateF(tempMtx, npc->rot.y, 0.0f, 1.0f, 0.0f);
1159 guMtxCatF(tempMtx, mtx, mtx);
1160 }
1161 if (npc->rot.x != 0.0f) {
1162 guRotateF(tempMtx, npc->rot.y, 0.0f, 1.0f, 0.0f);
1163 guMtxCatF(tempMtx, mtx, mtx);
1164 }
1165 if (npc->rot.z != 0.0f) {
1166 guRotateF(tempMtx, npc->rot.y, 0.0f, 1.0f, 0.0f);
1167 guMtxCatF(tempMtx, mtx, mtx);
1168 }
1169
1170 if ((npc->scale.x * SPRITE_WORLD_SCALE_D) != 1.0
1171 || ((npc->scale.y * npc->verticalStretch) * SPRITE_WORLD_SCALE_D) != 1.0
1172 || (npc->scale.z * SPRITE_WORLD_SCALE_D) != 1.0
1173 ) {
1174 guScaleF(
1175 tempMtx,
1179 );
1180 guMtxCatF(tempMtx, mtx, mtx);
1181 }
1182
1183 if (!(npc->flags & NPC_FLAG_NO_ANIMS_LOADED)) {
1184 if (!(npc->flags & NPC_FLAG_HAS_NO_SPRITE)) {
1185 spr_draw_npc_sprite(npc->spriteInstanceID, yaw, 0, 0, mtx);
1186 }
1187 } else {
1189 }
1190 }
1191 npc_imgfx_update(npc);
1192}
#define NPC_BLUR_FRAMES
s8 index
Current blur ring buffer index.
@ IMGFX_SET_ALPHA
Definition enums.h:4709
void npc_imgfx_update(Npc *npc)
Definition npc.c:2090
void set_npc_imgfx_all(s32 spriteIdx, ImgFXType imgfxType, s32 imgfxArg1, s32 imgfxArg2, s32 imgfxArg3, s32 imgfxArg4, s32 imgfxArg5)
Definition sprite.c:1238

Referenced by render_npcs().

◆ npc_enable_collisions()

void npc_enable_collisions ( void )

Definition at line 1194 of file npc.c.

1194 {
1195 gNpcPlayerCollisionsEnabled = true;
1196}

◆ npc_disable_collisions()

void npc_disable_collisions ( void )

Definition at line 1198 of file npc.c.

1198 {
1199 gNpcPlayerCollisionsEnabled = false;
1200}

◆ func_8003B1A8()

void func_8003B1A8 ( void )

Definition at line 1202 of file npc.c.

1202 {
1203}

Referenced by state_step_battle(), and state_step_pause().

◆ npc_reload_all()

void npc_reload_all ( void )

Definition at line 1205 of file npc.c.

1205 {
1206 s32 i;
1207 s32 j;
1208
1209 for (i = 0; i < MAX_NPCS; i++) {
1210 Npc* npc = (*gCurrentNpcListPtr)[i];
1211 if (npc != nullptr) {
1212 if (npc->flags && !(npc->flags & NPC_FLAG_NO_ANIMS_LOADED)) {
1213 if (!(npc->flags & NPC_FLAG_HAS_NO_SPRITE)) {
1214 if (!(npc->flags & NPC_FLAG_PARTNER)) {
1216 } else {
1218 }
1219 }
1220 if (!(npc->flags & NPC_FLAG_NO_ANIMS_LOADED)) {
1221 if (!(npc->flags & NPC_FLAG_HAS_NO_SPRITE) && (npc->palSwapType != NPC_PAL_ADJUST_NONE)) {
1223 npc->originalPalettesCount = 0;
1224 while (npc->originalPalettesList[npc->originalPalettesCount] != (PAL_PTR) -1) {
1225 npc->originalPalettesCount++;
1226 }
1228 }
1229 if (!(npc->flags & NPC_FLAG_NO_ANIMS_LOADED)) {
1230 if (!(npc->flags & NPC_FLAG_HAS_NO_SPRITE)) {
1231 for (j = 0; j < MAX_NPC_DECORATIONS; j++) {
1233 }
1234 npc_imgfx_update(npc);
1235 }
1236 }
1237 }
1238 }
1239 }
1240 }
1241}
#define PAL_PTR
void npc_reset_current_decoration(Npc *npc, s32 idx)
Definition npc.c:1795
s32 spr_get_npc_color_variations(s32 npcSpriteID)
Definition sprite.c:1306
PAL_PTR * spr_get_npc_palettes(s32 npcSpriteID)
Definition sprite.c:1296
s8 originalPalettesCount
u16 ** originalPalettesList
s8 spriteColorVariations

Referenced by state_step_end_battle(), and state_step_unpause().

◆ set_npc_yaw()

void set_npc_yaw ( Npc * npc,
f32 yaw )

Definition at line 1243 of file npc.c.

1243 {
1244 npc->yaw = yaw;
1245
1246 if (get_clamped_angle_diff(gCameras[gCurrentCameraID].curYaw, yaw) >= 0.0f) {
1247 npc->yawCamOffset = 180;
1248 npc->isFacingAway = true;
1249 } else {
1250 npc->yawCamOffset = 0;
1251 npc->isFacingAway = false;
1252 }
1253}
s32 gCurrentCameraID
Definition cam_math.c:5

Referenced by create_encounters(), GrooveGuyAI_02(), GrooveGuyAI_03(), peach_make_disguise_npc(), SpearGuyAI_Loiter(), and SpearGuyAI_LoiterInit().

◆ npc_set_palswap_mode_A()

void npc_set_palswap_mode_A ( Npc * npc,
s32 arg1 )

Definition at line 1255 of file npc.c.

1255 {
1256 if (npc->palSwapType != mode) {
1257 npc->palSwapPrevType = npc->palSwapType;
1258 npc->palSwapType = mode;
1260 npc->resetPalAdjust = 1;
1261 }
1262}
@ PAL_SWAP_HOLD_A
Definition npc.c:18
s8 palAnimState
s8 resetPalAdjust

◆ npc_set_palswap_mode_B()

void npc_set_palswap_mode_B ( Npc * npc,
s32 arg1 )

Definition at line 1264 of file npc.c.

1264 {
1265 if (npc->palSwapType != mode) {
1266 npc->palSwapPrevType = npc->palSwapType;
1267 npc->palSwapType = mode;
1269 npc->resetPalAdjust = -1;
1270 }
1271}

◆ npc_revert_palswap_mode()

void npc_revert_palswap_mode ( Npc * npc)

Definition at line 1273 of file npc.c.

1273 {
1276 return;
1277 }
1278 npc->palSwapType = npc->palSwapPrevType;
1281 npc->resetPalAdjust = 1;
1282}

◆ npc_set_palswap_1()

void npc_set_palswap_1 ( Npc * npc,
s32 palIndexA,
s32 palIndexB,
s32 timeHoldA,
s32 timeAB )

Definition at line 1284 of file npc.c.

1284 {
1285 npc->blendPalA = palIndexA;
1286 npc->blendPalB = palIndexB;
1288 npc->palswapTimeAtoB = timeAB;
1289}
s16 blendPalB
s16 palswapTimeAtoB
s16 blendPalA
u16 palswapTimeHoldA

◆ npc_set_palswap_2()

void npc_set_palswap_2 ( Npc * npc,
s32 timeHoldB,
s32 timeBA,
s32 palIndexC,
s32 palIndexD )

Definition at line 1291 of file npc.c.

1291 {
1293 npc->palswapTimeBtoA = timeBA;
1294 npc->blendPalC = palIndexC;
1295 npc->blendPalD = palIndexD;
1296}
s16 palswapTimeBtoA
s16 blendPalC
s16 blendPalD
s16 palswapTimeHoldB

◆ npc_draw_with_palswap()

void npc_draw_with_palswap ( Npc * npc,
s32 arg1,
Matrix4f mtx )

Definition at line 1298 of file npc.c.

1298 {
1299 switch (npc->palSwapType) {
1302 break;
1305 break;
1307 npc_render_with_single_pal_blending(npc, yaw, false, mtx);
1308 break;
1310 npc_render_with_single_pal_blending(npc, yaw, true, mtx);
1311 break;
1314 break;
1315 }
1316}
@ NPC_PAL_ADJUST_BLEND_DOUBLE_PALETTES
Definition enums.h:1958
@ NPC_PAL_ADJUST_BLEND_PALETTES_UNIFORM_INTERVALS
Definition enums.h:1956
@ NPC_PAL_ADJUST_BLEND_PALETTES_VARYING_INTERVALS
Definition enums.h:1957
@ NPC_PAL_ADJUST_WATT_IDLE
Definition enums.h:1955
void npc_render_without_adjusted_palettes(Npc *npc, s32 arg1, Matrix4f mtx)
Definition npc.c:1318
void npc_render_with_watt_idle_palettes(Npc *npc, s32 arg1, Matrix4f mtx)
Definition npc.c:1340
void npc_render_with_single_pal_blending(Npc *npc, s32 yaw, b32 hasDifferentIntervals, Matrix4f mtx)
Definition npc.c:1445
void npc_render_with_double_pal_blending(Npc *npc, s32 yaw, Matrix4f mtx)
Definition npc.c:1581

Referenced by appendGfx_npc().

◆ npc_render_without_adjusted_palettes()

void npc_render_without_adjusted_palettes ( Npc * npc,
s32 arg1,
Matrix4f mtx )

Definition at line 1318 of file npc.c.

1318 {
1319 if (npc->resetPalAdjust != 0) {
1320 npc->verticalStretch = 1.0f;
1321 npc->screenSpaceOffset2D[0] = 0.0f;
1322 npc->screenSpaceOffset2D[1] = 0.0f;
1323 npc->resetPalAdjust = 0;
1324 }
1325
1326 if (!(npc->flags & NPC_FLAG_NO_ANIMS_LOADED)) {
1327 s32 alpha = (npc->alpha * npc->hideAlpha / 255);
1328 u32 mask;
1329 if (alpha < 255) {
1331 } else {
1332 mask = 0;
1333 }
1334 spr_draw_npc_sprite(npc->spriteInstanceID | mask, arg1, alpha, nullptr, mtx);
1335 } else {
1337 }
1338}
@ DRAW_SPRITE_OVERRIDE_ALPHA
Definition sprite.h:26

Referenced by npc_draw_with_palswap().

◆ npc_render_with_watt_idle_palettes()

void npc_render_with_watt_idle_palettes ( Npc * npc,
s32 arg1,
Matrix4f mtx )

Definition at line 1340 of file npc.c.

1340 {
1341 s32 i, j;
1342 s32 brightness;
1343 PAL_PTR src;
1344 PAL_PTR dst;
1345
1346 if (npc->resetPalAdjust != 0) {
1348 npc->originalPalettesCount = 0;
1349 while ((s32)npc->originalPalettesList[npc->originalPalettesCount] != -1) {
1350 npc->originalPalettesCount++;
1351 }
1352
1354 for (i = 0; i < npc->originalPalettesCount; i++) {
1355 dst = npc->copiedPalettes[i];
1356 src = npc->originalPalettesList[i];
1357 if (src != nullptr) {
1358 for (j = 0; j < SPR_PAL_SIZE; j++) {
1359 *dst++ = *src++;
1360 }
1361 }
1362 }
1363
1364 npc->palAnimState = -2;
1365 npc->palBlendAlpha = 0;
1366 npc->resetPalAdjust = 0;
1367 npc->nextPalTime = 0;
1368 }
1369
1370 if (npc->nextPalTime == 0) {
1371 npc->palAnimState += 2;
1372 brightness = wWattIdlePalettesAnim[npc->palAnimState];
1373 if (brightness == 255) {
1374 npc->palAnimState = 0;
1375 }
1376 npc->nextPalTime = wWattIdlePalettesAnim[npc->palAnimState + 1] / 2;
1377 }
1378
1379 brightness = wWattIdlePalettesAnim[npc->palAnimState];
1380 npc->nextPalTime--;
1381
1382 switch(brightness) {
1383 case WATT_DEFAULT:
1384 for (i = 0; i < npc->spriteColorVariations; i++) {
1385 dst = npc->copiedPalettes[i];
1386 src = npc->originalPalettesList[i];
1387 if (src != nullptr) {
1388 for (j = 0; j < SPR_PAL_SIZE; j++) {
1389 *dst++ = *src++;
1390 }
1391 }
1392 }
1393 break;
1394 case WATT_BRIGHTEST:
1395 for (i = 0; i < npc->spriteColorVariations; i++) {
1396 // use watt's Brightest palettes
1397 dst = npc->copiedPalettes[i];
1399 if (src != nullptr) {
1400 for (j = 0; j < SPR_PAL_SIZE; j++) {
1401 *dst++ = *src++;
1402 }
1403 }
1404 }
1405 break;
1406 case WATT_BRIGHTER:
1407 for (i = 0; i < npc->spriteColorVariations; i++) {
1408 // use watt's Brighter palettes
1409 dst = npc->copiedPalettes[i];
1411 if (src != nullptr) {
1412 for (j = 0; j < SPR_PAL_SIZE; j++) {
1413 *dst++ = *src++;
1414 }
1415 }
1416 }
1417 break;
1418 }
1419
1420 for (i = 0; i < npc->originalPalettesCount; i++) {
1421 npc->adjustedPalettes[i] = npc->copiedPalettes[i];
1422 }
1423
1424 if (!(npc->flags & NPC_FLAG_NO_ANIMS_LOADED)) {
1425 s32 alpha = npc->alpha * npc->hideAlpha / 255;
1426 u32 mask = 0;
1427 if (alpha < 255) {
1429 }
1431 spr_draw_npc_sprite(npc->spriteInstanceID | mask, arg1, alpha, npc->adjustedPalettes, mtx);
1432 }
1433 npc->palBlendAlpha--;
1434}
u8 wWattIdlePalettesAnim[]
Definition npc.c:31
@ WATT_BRIGHTER
Definition npc.c:28
@ WATT_DEFAULT
Definition npc.c:26
@ WATT_BRIGHTEST
Definition npc.c:27
#define SPR_PAL_SIZE
Definition macros.h:153
@ DRAW_SPRITE_OVERRIDE_PALETTES
Definition sprite.h:24
s16 nextPalTime
s16 palBlendAlpha
u16 * adjustedPalettes[16]
u16 copiedPalettes[16][16]

Referenced by npc_draw_with_palswap().

◆ npc_blend_palette_colors()

u16 npc_blend_palette_colors ( u16 colorA,
u16 colorB,
s32 lerpAlpha )

Definition at line 1436 of file npc.c.

1436 {
1437 u8 r = (UNPACK_PAL_R(colorA) * (255 - lerpAlpha) + UNPACK_PAL_R(colorB) * lerpAlpha) / 255;
1438 u8 g = (UNPACK_PAL_G(colorA) * (255 - lerpAlpha) + UNPACK_PAL_G(colorB) * lerpAlpha) / 255;
1439 u8 b = (UNPACK_PAL_B(colorA) * (255 - lerpAlpha) + UNPACK_PAL_B(colorB) * lerpAlpha) / 255;
1440 u8 a = UNPACK_PAL_A(colorB);
1441
1442 return PACK_PAL_RGBA(r, g, b, a);
1443}
#define UNPACK_PAL_B(color)
Definition macros.h:280
#define UNPACK_PAL_R(color)
Definition macros.h:278
#define UNPACK_PAL_A(color)
Definition macros.h:281
#define UNPACK_PAL_G(color)
Definition macros.h:279
#define PACK_PAL_RGBA(r, g, b, a)
Definition macros.h:283

Referenced by npc_render_with_double_pal_blending(), and npc_render_with_single_pal_blending().

◆ npc_render_with_single_pal_blending()

void npc_render_with_single_pal_blending ( Npc * npc,
s32 yaw,
s32 hasDifferentIntervals,
Matrix4f mtx )

Definition at line 1445 of file npc.c.

1445 {
1446 PAL_PTR color1;
1447 PAL_PTR color2;
1449 s32 i, j;
1451
1452 // copy palettes from sprite data
1453 if (npc->resetPalAdjust != 0) {
1454 if (!(npc->flags & NPC_FLAG_NO_ANIMS_LOADED)) {
1456 }
1457
1458 npc->originalPalettesCount = 0;
1459 while ((s32)npc->originalPalettesList[npc->originalPalettesCount] != -1) {
1460 npc->originalPalettesCount++;
1461 }
1462
1463 if (npc->resetPalAdjust == 1) {
1465 npc->palBlendAlpha = 0;
1466 } else {
1468 npc->palBlendAlpha = 255;
1469 }
1470
1471 for (i = 0; i < npc->originalPalettesCount; i++) {
1472 color1 = npc->copiedPalettes[i];
1473 color2 = npc->originalPalettesList[i];
1474 npc->adjustedPalettes[i] = color1;
1475 if (color2 != nullptr) {
1476 for (j = 0; j < SPR_PAL_SIZE; j++) {
1477 *color1++ = *color2++;
1478 }
1479 }
1480 }
1481
1482 if (!hasDifferentIntervals) {
1485 npc->palswapTimeBtoA = npc->palswapTimeAtoB;
1486 npc->palswapTimeHoldA = 0;
1487 }
1488
1489 npc->nextPalTime = npc->palswapTimeHoldA;
1490 npc->palBlendAlpha = 0;
1492 npc->resetPalAdjust = 0;
1493 }
1494
1495 // blending from A -> B
1496 switch (npc->palAnimState) {
1497 case PAL_SWAP_HOLD_A:
1498 if (npc->nextPalTime != 0) {
1499 npc->nextPalTime--;
1500 break;
1501 } else {
1502 npc->palBlendAlpha = 0;
1504 }
1505 // fallthrough
1506 case PAL_SWAP_A_TO_B:
1507 npc->palBlendAlpha += 25600 / npc->palswapTimeAtoB;
1508 if (npc->palBlendAlpha > 25500) {
1509 npc->palBlendAlpha = 25500;
1510 }
1511 blendAlpha = npc->palBlendAlpha / 100;
1512 // blend two palettes
1513 outColor = npc->copiedPalettes[0];
1514 color2 = npc->originalPalettesList[npc->blendPalA];
1515 color1 = npc->originalPalettesList[npc->blendPalB];
1516 npc->adjustedPalettes[0] = outColor;
1517
1518 for (j = 0; j < SPR_PAL_SIZE; j++) {
1519 *outColor++ = npc_blend_palette_colors(*color2++, *color1++, blendAlpha);
1520 }
1521
1522 if (blendAlpha == 255) {
1524 npc->nextPalTime = npc->palswapTimeHoldB;
1525 }
1526 break;
1527 }
1528
1529 // blending from B -> A
1530 switch (npc->palAnimState) {
1531 case PAL_SWAP_HOLD_B:
1532 if (npc->nextPalTime != 0) {
1533 npc->nextPalTime--;
1534 break;
1535 } else {
1536 npc->palBlendAlpha = 0;
1538 }
1539 // fallthrough
1540 case PAL_SWAP_B_TO_A:
1541 npc->palBlendAlpha += 25600 / npc->palswapTimeBtoA;
1542 if (npc->palBlendAlpha > 25500) {
1543 npc->palBlendAlpha = 25500;
1544 }
1545 blendAlpha = npc->palBlendAlpha / 100;
1546 // blend two palettes
1547 outColor = npc->copiedPalettes[0];
1548 color2 = npc->originalPalettesList[npc->blendPalB];
1549 color1 = npc->originalPalettesList[npc->blendPalA];
1550 npc->adjustedPalettes[0] = outColor;
1551
1552 for (j = 0; j < SPR_PAL_SIZE; j++) {
1553 *outColor++ = npc_blend_palette_colors(*color2++, *color1++, blendAlpha);
1554 }
1555
1556 if (blendAlpha == 255) {
1558 npc->nextPalTime = npc->palswapTimeHoldA;
1559 }
1560 break;
1561 }
1562
1563 switch (npc->palAnimState) {
1564 case PAL_SWAP_HOLD_A:
1565 case PAL_SWAP_A_TO_B:
1566 case PAL_SWAP_HOLD_B:
1567 case PAL_SWAP_B_TO_A:
1568 if (!(npc->flags & NPC_FLAG_NO_ANIMS_LOADED)) {
1569 u32 mask = 0;
1570 blendAlpha = npc->alpha * npc->hideAlpha / 255;
1571 if (blendAlpha < 255) {
1573 }
1576 }
1577 break;
1578 }
1579}
@ PAL_SWAP_HOLD_B
Definition npc.c:20
@ PAL_SWAP_B_TO_A
Definition npc.c:21
@ PAL_SWAP_A_TO_B
Definition npc.c:19
u16 npc_blend_palette_colors(u16 colorA, u16 colorB, s32 lerpAlpha)
Definition npc.c:1436

Referenced by npc_draw_with_palswap().

◆ npc_render_with_double_pal_blending()

void npc_render_with_double_pal_blending ( Npc * npc,
s32 yaw,
Matrix4f mtx )
Bug
? should this be index 3?

Definition at line 1581 of file npc.c.

1581 {
1582 PAL_PTR color1;
1583 PAL_PTR color2;
1585 s32 i, j;
1586 u8 blendAlpha;
1587
1588 // copy palettes from sprite data
1589 if (npc->resetPalAdjust != 0) {
1590 if (!(npc->flags & NPC_FLAG_NO_ANIMS_LOADED)) {
1592 }
1593
1594 npc->originalPalettesCount = 0;
1595 while ((s32)npc->originalPalettesList[npc->originalPalettesCount] != -1) {
1596 npc->originalPalettesCount++;
1597 }
1598
1599 if (npc->resetPalAdjust == 1) {
1601 npc->palBlendAlpha = 0;
1602 } else {
1604 npc->palBlendAlpha = 255;
1605 }
1606
1607 for (i = 0; i < npc->originalPalettesCount; i++) {
1608 color1 = npc->copiedPalettes[i];
1609 color2 = npc->originalPalettesList[i];
1610 npc->adjustedPalettes[i] = color1;
1611 if (color2 != nullptr) {
1612 for (j = 0; j < SPR_PAL_SIZE; j++) {
1613 *color1++ = *color2++;
1614 }
1615 }
1616 }
1617
1618 npc->nextPalTime = npc->palswapTimeHoldA;
1619 npc->palBlendAlpha = 0;
1621 npc->resetPalAdjust = 0;
1622 }
1623
1624 // blending from A -> B
1625 switch (npc->palAnimState) {
1626 case PAL_SWAP_HOLD_A:
1627 if (npc->nextPalTime != 0) {
1628 npc->nextPalTime--;
1629 break;
1630 }
1631 npc->palBlendAlpha = 0;
1633 // fallthrough
1634 case PAL_SWAP_A_TO_B:
1635 npc->palBlendAlpha += 25600 / npc->palswapTimeAtoB;
1636 if (npc->palBlendAlpha > 25500) {
1637 npc->palBlendAlpha = 25500;
1638 }
1639 blendAlpha = npc->palBlendAlpha / 100;
1640
1641 // blend first two palettes
1642 outColor = npc->copiedPalettes[0];
1643 color2 = npc->originalPalettesList[npc->blendPalA];
1644 color1 = npc->originalPalettesList[npc->blendPalB];
1645 npc->adjustedPalettes[0] = outColor;
1646
1647 for (j = 0; j < SPR_PAL_SIZE; j++) {
1648 *outColor++ = npc_blend_palette_colors(*color2++, *color1++, blendAlpha);
1649 }
1650
1651 // blend next palettes
1652 outColor = npc->copiedPalettes[3];
1653 color2 = npc->originalPalettesList[npc->blendPalC];
1654 color1 = npc->originalPalettesList[npc->blendPalD];
1655 npc->adjustedPalettes[3] = outColor;
1656
1657 for (j = 0; j < SPR_PAL_SIZE; j++) {
1658 *outColor++ = npc_blend_palette_colors(*color2++, *color1++, blendAlpha);
1659 }
1660
1661 if (blendAlpha == 255) {
1663 npc->nextPalTime = npc->palswapTimeHoldB;
1664 }
1665 break;
1666 }
1667
1668 // blending from B -> A
1669 switch (npc->palAnimState) {
1670 case PAL_SWAP_HOLD_B:
1671 if (npc->nextPalTime != 0) {
1672 npc->nextPalTime--;
1673 break;
1674 } else {
1675 npc->palBlendAlpha = 0;
1677 }
1678 // fallthrough
1679 case PAL_SWAP_B_TO_A:
1680 npc->palBlendAlpha += 25600 / npc->palswapTimeBtoA;
1681 if (npc->palBlendAlpha > 25500) {
1682 npc->palBlendAlpha = 25500;
1683 }
1684 blendAlpha = npc->palBlendAlpha / 100;
1685
1686 // blend first two palettes
1687 outColor = npc->copiedPalettes[0];
1688 color2 = npc->originalPalettesList[npc->blendPalB];
1689 color1 = npc->originalPalettesList[npc->blendPalA];
1690 npc->adjustedPalettes[0] = outColor;
1691
1692 for (j = 0; j < SPR_PAL_SIZE; j++) {
1693 *outColor++ = npc_blend_palette_colors(*color2++, *color1++, blendAlpha);
1694 }
1695
1696 // blend next palettes
1697 outColor = npc->copiedPalettes[1];
1698 color2 = npc->originalPalettesList[npc->blendPalD];
1699 color1 = npc->originalPalettesList[npc->blendPalC];
1700 npc->adjustedPalettes[3] = npc->copiedPalettes[3];
1701
1702 for (j = 0; j < SPR_PAL_SIZE; j++) {
1703 *outColor++ = npc_blend_palette_colors(*color2++, *color1++, blendAlpha);
1704 }
1705
1706 if (blendAlpha == 255) {
1708 npc->nextPalTime = npc->palswapTimeHoldA;
1709 }
1710 break;
1711 }
1712
1713 switch (npc->palAnimState) {
1714 case PAL_SWAP_HOLD_A:
1715 case PAL_SWAP_A_TO_B:
1716 case PAL_SWAP_HOLD_B:
1717 case PAL_SWAP_B_TO_A:
1718 if (!(npc->flags & NPC_FLAG_NO_ANIMS_LOADED)) {
1719 u32 mask = 0;
1720 blendAlpha = npc->alpha * npc->hideAlpha / 255;
1721 if (blendAlpha < 255) {
1723 }
1726 }
1727 break;
1728 }
1729}

Referenced by npc_draw_with_palswap().

◆ npc_set_decoration()

void npc_set_decoration ( Npc * npc,
s32 idx,
s32 decorationType )

Definition at line 1731 of file npc.c.

1731 {
1733 npc->decorationType[idx] = decorationType;
1734 npc->changedDecoration[idx] = 1;
1735 npc->decorationInitialized[idx] = 0;
1736}
s8 changedDecoration[2]
s8 decorationInitialized[2]

◆ npc_remove_decoration()

void npc_remove_decoration ( Npc * npc,
s32 idx )

Definition at line 1738 of file npc.c.

1738 {
1739 switch (npc->decorationType[idx]) {
1742 break;
1745 break;
1748 break;
1751 break;
1754 break;
1757 break;
1760 break;
1761 }
1763}
@ NPC_DECORATION_WHITE_GLOW_BEHIND
Definition enums.h:1949
@ NPC_DECORATION_BOWSER_AURA
Definition enums.h:1945
@ NPC_DECORATION_CHARGED
Definition enums.h:1950
@ NPC_DECORATION_SWEAT
Definition enums.h:1946
@ NPC_DECORATION_NONE
Definition enums.h:1944
@ NPC_DECORATION_WHITE_GLOW_FRONT
Definition enums.h:1948
@ NPC_DECORATION_SEEING_STARS
Definition enums.h:1947
void npc_remove_decoration_glow_in_front(Npc *npc, s32 idx)
Definition npc.c:1903
void npc_remove_decoration_sweat(Npc *npc, s32 idx)
Definition npc.c:1861
void npc_remove_decoration_bowser_aura(Npc *npc, s32 idx)
Definition npc.c:1836
void npc_remove_decoration_none(Npc *npc, s32 idx)
Definition npc.c:1813
void npc_remove_decoration_glow_behind(Npc *npc, s32 idx)
Definition npc.c:1925
void npc_remove_decoration_charged(Npc *npc, s32 idx)
Definition npc.c:1963
void npc_remove_decoration_seeing_stars(Npc *npc, s32 idx)
Definition npc.c:1881

Referenced by free_npc(), free_npc_by_index(), and npc_set_decoration().

◆ npc_update_decorations()

void npc_update_decorations ( Npc * npc)

Definition at line 1765 of file npc.c.

1765 {
1766 s32 i;
1767
1768 for (i = 0; i < MAX_NPC_DECORATIONS; i++) {
1769 switch (npc->decorationType[i]) {
1772 break;
1775 break;
1778 break;
1781 break;
1784 break;
1787 break;
1790 break;
1791 }
1792 }
1793}
void npc_update_decoration_charged(Npc *npc, s32 idx)
Definition npc.c:1929
void npc_update_decoration_seeing_stars(Npc *npc, s32 idx)
Definition npc.c:1864
void npc_update_decoration_glow_in_front(Npc *npc, s32 idx)
Definition npc.c:1885
void npc_update_decoration_bowser_aura(Npc *npc, s32 idx)
Definition npc.c:1816
void npc_update_decoration_glow_behind(Npc *npc, s32 idx)
Definition npc.c:1907
void npc_update_decoration_sweat(Npc *npc, s32 idx)
Definition npc.c:1840
void npc_update_decoration_none(Npc *npc, s32 idx)
Definition npc.c:1810

Referenced by update_npcs().

◆ npc_reset_current_decoration()

void npc_reset_current_decoration ( Npc * npc,
s32 idx )

Definition at line 1795 of file npc.c.

1795 {
1796 switch (npc->decorationType[idx]) {
1803 break;
1805 npc->decorationInitialized[idx] = 0;
1806 break;
1807 }
1808}

Referenced by npc_reload_all().

◆ npc_update_decoration_none()

void npc_update_decoration_none ( Npc * npc,
s32 idx )

Definition at line 1810 of file npc.c.

1810 {
1811}

Referenced by npc_update_decorations().

◆ npc_remove_decoration_none()

void npc_remove_decoration_none ( Npc * npc,
s32 idx )

Definition at line 1813 of file npc.c.

1813 {
1814}

Referenced by npc_remove_decoration().

◆ npc_update_decoration_bowser_aura()

void npc_update_decoration_bowser_aura ( Npc * npc,
s32 idx )

Definition at line 1816 of file npc.c.

1816 {
1817 AuraFXData* data;
1818
1819 switch (npc->decorationInitialized[idx]) {
1820 case 0:
1821 fx_aura(FX_AURA_BLUE, npc->pos.x, npc->pos.y, npc->pos.z, 1.0f, &npc->decorations[idx]);
1822 npc->decorationInitialized[idx] = 1;
1823 // fallthrough
1824 case 1:
1825 data = npc->decorations[idx]->data.aura;
1826 data->posA.x = npc->pos.x;
1827 data->posA.y = npc->pos.y;
1828 data->posA.z = npc->pos.z;
1829 data->scale.x = (npc->scale.x * npc->collisionDiameter) * 0.01;
1830 data->scale.y = (npc->scale.y * npc->collisionHeight) * 0.01;
1831 data->renderYaw = npc->renderYaw;
1832 break;
1833 }
1834}
f32 renderYaw
Definition effects.h:1013
Vec2f scale
Definition effects.h:996
Vec3f posA
Definition effects.h:994
EffectInstanceDataPtr data
Definition effects.h:2605
@ FX_AURA_BLUE
Definition effects.h:988
struct AuraFXData * aura
Definition effects.h:2523

Referenced by npc_update_decorations().

◆ npc_remove_decoration_bowser_aura()

void npc_remove_decoration_bowser_aura ( Npc * npc,
s32 idx )

Definition at line 1836 of file npc.c.

1836 {
1837 npc->decorations[idx]->data.aura->fadeTime = 5;
1838}
s32 fadeTime
Definition effects.h:999

Referenced by npc_remove_decoration().

◆ npc_update_decoration_sweat()

void npc_update_decoration_sweat ( Npc * npc,
s32 idx )

Definition at line 1840 of file npc.c.

1840 {
1841 switch (npc->decorationInitialized[idx]) {
1842 case 0:
1843 if (npc->yawCamOffset > 90) {
1844 fx_sweat(0, npc->pos.x, npc->pos.y + npc->collisionHeight, npc->pos.z, 5.0f, 45.0f, 20);
1845 } else {
1846 fx_sweat(0, npc->pos.x, npc->pos.y + npc->collisionHeight, npc->pos.z, 5.0f, -45.0f, 20);
1847 }
1848 npc->decorationGlowPhase[idx] = 10;
1849 npc->decorationInitialized[idx] = 1;
1850 break;
1851 case 1:
1852 if (npc->decorationGlowPhase[idx] != 0) {
1853 npc->decorationGlowPhase[idx]--;
1854 } else {
1855 npc->decorationInitialized[idx] = 0;
1856 }
1857 break;
1858 }
1859}
s16 decorationGlowPhase[2]

Referenced by npc_update_decorations().

◆ npc_remove_decoration_sweat()

void npc_remove_decoration_sweat ( Npc * npc,
s32 idx )

Definition at line 1861 of file npc.c.

1861 {
1862}

Referenced by npc_remove_decoration().

◆ npc_update_decoration_seeing_stars()

void npc_update_decoration_seeing_stars ( Npc * npc,
s32 idx )

Definition at line 1864 of file npc.c.

1864 {
1865 StarsOrbitingFXData* data;
1866
1867 switch (npc->decorationInitialized[idx]) {
1868 case 0:
1869 fx_stars_orbiting(0, npc->pos.x, npc->pos.y + npc->collisionHeight, npc->pos.z, 20.0f, 3, &npc->decorations[idx]);
1870 npc->decorationInitialized[idx] = 1;
1871 break;
1872 case 1:
1873 data = npc->decorations[idx]->data.starsOrbiting;
1874 data->pos.x = npc->pos.x;
1875 data->pos.y = npc->pos.y + npc->collisionHeight;
1876 data->pos.z = npc->pos.z;
1877 break;
1878 }
1879}
struct StarsOrbitingFXData * starsOrbiting
Definition effects.h:2511

Referenced by npc_update_decorations().

◆ npc_remove_decoration_seeing_stars()

void npc_remove_decoration_seeing_stars ( Npc * npc,
s32 idx )

Definition at line 1881 of file npc.c.

1881 {
1883}
#define remove_effect

Referenced by npc_remove_decoration().

◆ npc_update_decoration_glow_in_front()

void npc_update_decoration_glow_in_front ( Npc * npc,
s32 idx )

Definition at line 1885 of file npc.c.

1885 {
1886 EnergyOrbWaveFXData* data;
1887
1888 switch (npc->decorationInitialized[idx]) {
1889 case 0:
1890 npc->decorations[idx] = fx_energy_orb_wave(2, npc->pos.x, npc->pos.y + npc->collisionHeight * 0.5, npc->pos.z, npc->scale.x * 0.8 + 0.2f, -1);
1891 npc->decorationInitialized[idx] = 1;
1892 break;
1893 case 1:
1894 data = npc->decorations[idx]->data.energyOrbWave;
1895 data->pos.x = npc->pos.x;
1896 data->pos.y = npc->pos.y + npc->collisionHeight * 0.5 * npc->scale.x;
1897 data->pos.z = npc->pos.z;
1898 data->scale = npc->scale.x * 0.8 + 0.2f;
1899 break;
1900 }
1901}
struct EnergyOrbWaveFXData * energyOrbWave
Definition effects.h:2546

Referenced by npc_update_decorations().

◆ npc_remove_decoration_glow_in_front()

void npc_remove_decoration_glow_in_front ( Npc * npc,
s32 idx )

Definition at line 1903 of file npc.c.

1903 {
1905}

Referenced by npc_remove_decoration().

◆ npc_update_decoration_glow_behind()

void npc_update_decoration_glow_behind ( Npc * npc,
s32 idx )

Definition at line 1907 of file npc.c.

1907 {
1908 EnergyOrbWaveFXData* data;
1909
1910 switch (npc->decorationInitialized[idx]) {
1911 case 0:
1912 npc->decorations[idx] = fx_energy_orb_wave(2, npc->pos.x, npc->pos.y + npc->collisionHeight * 0.5, npc->pos.z - 5.0f, 1.0f, 0);
1913 npc->decorationInitialized[idx] = 1;
1914 break;
1915 case 1:
1916 data = npc->decorations[idx]->data.energyOrbWave;
1917 data->pos.x = npc->pos.x;
1918 data->pos.y = npc->pos.y + npc->collisionHeight * 0.5;
1919 data->pos.z = npc->pos.z - 5.0f;
1920 data->scale = 1.0f;
1921 break;
1922 }
1923}

Referenced by npc_update_decorations().

◆ npc_remove_decoration_glow_behind()

void npc_remove_decoration_glow_behind ( Npc * npc,
s32 idx )

Definition at line 1925 of file npc.c.

1925 {
1927}

Referenced by npc_remove_decoration().

◆ npc_update_decoration_charged()

void npc_update_decoration_charged ( Npc * npc,
s32 idx )

Definition at line 1929 of file npc.c.

1929 {
1930 #define RGBA_BUF_SIZE 20
1934 s32 color;
1935 s32 alpha;
1936 s32 i;
1937
1938 if (npc->decorationInitialized[idx] == 0) {
1940 npc->decorationInitialized[idx] = 1;
1941 }
1942 if (npc->decorationInitialized[idx] == 1) {
1943 npc->decorationGlowPhase[idx] += 7;
1944 if (npc->decorationGlowPhase[idx] >= 360) {
1945 npc->decorationGlowPhase[idx] %= 360;
1946 }
1947
1948 for (i = 0; i < RGBA_BUF_SIZE; i++) {
1949 rbuf[i] = (cosine(npc->decorationGlowPhase[idx] + (25 * i)) + 1.0) * 80.0f;
1950 gbuf[i] = (cosine(npc->decorationGlowPhase[idx] + (25 * i) + 45) + 1.0) * 80.0f;
1951 bbuf[i] = (cosine(npc->decorationGlowPhase[idx] + (25 * i) + 90) + 1.0) * 80.0f;
1952 }
1953
1954 alpha = 255;
1955 for (i = 0; i < RGBA_BUF_SIZE; i++) {
1956 color = (rbuf[i] << 24) | (gbuf[i] << 16) | (bbuf[i] << 8) | alpha;
1958 }
1959 }
1960 #undef RGBA_BUF_SIZE
1961}
@ IMGFX_ALLOC_COLOR_BUF
Definition enums.h:4719
@ IMGFX_COLOR_BUF_SET_MODULATE
Definition enums.h:4714
f32 cosine(s16 arg0)
Definition 43F0.c:352
#define RGBA_BUF_SIZE

Referenced by npc_update_decorations().

◆ npc_remove_decoration_charged()

void npc_remove_decoration_charged ( Npc * npc,
s32 idx )

Definition at line 1963 of file npc.c.

1963 {
1964}

Referenced by npc_remove_decoration().

◆ npc_find_closest()

Npc * npc_find_closest ( f32 x,
f32 y,
f32 z,
f32 radius )

Finds the closest NPC to a given point within a radius.

Ignores Y position.

NPCs with NPC_FLAG_PARTNER set are ignored. See also npc_find_closest_simple(), which requires that NPC_FLAG_PARTNER be set.

Parameters
xX position
yY position (unused)
zZ position
radiusNo NPCs further than this distance will be considered
Returns
nullptr if there are no NPCs within radius

Definition at line 1966 of file npc.c.

1966 {
1967 Npc* closestNpc = nullptr;
1968 f32 closestDist = radius;
1969 f32 maxDist = radius;
1970 s32 i;
1971
1972 for (i = 0; i < ARRAY_COUNT(*gCurrentNpcListPtr); i++) {
1973 Npc* npc = (*gCurrentNpcListPtr)[i];
1974
1975 if (npc != nullptr && npc->flags != 0 && !(npc->flags & NPC_FLAG_PARTNER)) {
1976 if (!(npc->flags & (NPC_FLAG_SUSPENDED | NPC_FLAG_INACTIVE))) {
1977 f32 distance = fabsf(dist2D(npc->pos.x, npc->pos.z, x, z));
1978
1979 if (distance <= maxDist) {
1980 if (distance < closestDist) {
1982 closestNpc = npc;
1983 }
1984 }
1985 }
1986 }
1987 }
1988
1989 return closestNpc;
1990}

Referenced by parasol_get_npc().

◆ npc_find_closest_simple()

Npc * npc_find_closest_simple ( f32 x,
f32 y,
f32 z,
f32 radius )

Finds the closest simple-hitbox NPC to a given point within a radius.

Ignores Y position.

Only NPCs with NPC_FLAG_PARTNER set are considered. See also npc_find_closest(), which requires that NPC_FLAG_PARTNER be unset.

Parameters
xX position
yY position (unused)
zZ position
radiusNo NPCs further than this distance will be considered
Returns
nullptr if there are no NPCs within radius

Definition at line 1992 of file npc.c.

1992 {
1993 Npc* closestNpc = nullptr;
1994 f32 closestDist = radius;
1995 f32 maxDist = radius;
1996 s32 i;
1997
1998 for (i = 0; i < ARRAY_COUNT(*gCurrentNpcListPtr); i++) {
1999 Npc* npc = (*gCurrentNpcListPtr)[i];
2000
2001 if (npc != nullptr && npc->flags != 0 && (npc->flags & NPC_FLAG_PARTNER)) {
2002 if (!(npc->flags & (NPC_FLAG_SUSPENDED | NPC_FLAG_INACTIVE))) {
2003 f32 distance = fabsf(dist2D(npc->pos.x, npc->pos.z, x, z));
2004
2005 if (distance <= maxDist) {
2006 if (distance < closestDist) {
2008 closestNpc = npc;
2009 }
2010 }
2011 }
2012 }
2013 }
2014
2015 return closestNpc;
2016}

Referenced by entity_Tweester_idle().

◆ npc_get_collider_below()

s32 npc_get_collider_below ( Npc * npc)

Definition at line 2066 of file npc.c.

2066 {
2067 f32 x;
2068 f32 y;
2069 f32 z;
2070 f32 yaw;
2071
2072 if (npc->flags & NPC_FLAG_PARTNER) {
2073 y = get_shadow_by_index(npc->shadowIndex)->pos.y + 13.0f;
2074 } else {
2075 y = npc->pos.y + 13.0f;
2076 }
2077
2078 yaw = 16.0f;
2079 x = npc->pos.x;
2080 z = npc->pos.z;
2081
2083 if (yaw <= 16.0f) {
2084 return NpcHitQueryColliderID;
2085 }
2086 }
2087 return 0;
2088}
@ COLLIDER_FLAG_IGNORE_SHELL
Definition enums.h:4280

Referenced by npc_find_standing_on_entity().

◆ npc_imgfx_update()

void npc_imgfx_update ( Npc * npc)

Definition at line 2090 of file npc.c.

2090 {
2091 s32 imgfxType = npc->imgfxType;
2092 s32 imgfxArg1 = npc->imgfxArg1;
2093 s32 imgfxArg2 = npc->imgfxArg2;
2094 s32 imgfxArg3 = npc->imgfxArg3;
2095 s32 imgfxArg4 = npc->imgfxArg4;
2096 s32 imgfxFlags = npc->imgfxFlags;
2097
2098 set_npc_imgfx_all(npc->spriteInstanceID, IMGFX_CLEAR, 0, 0, 0, 0, 0);
2099
2100 switch (imgfxType) {
2101 case IMGFX_CLEAR:
2103 set_npc_imgfx_all(npc->spriteInstanceID, IMGFX_CLEAR, 0, 0, 0, 0, imgfxFlags);
2104 break;
2105 case IMGFX_UNK_2:
2106 case IMGFX_RESET:
2108 // fallthrough
2109 case IMGFX_UNK_1:
2110 set_npc_imgfx_all(npc->spriteInstanceID, imgfxType, 0, 0, 0, 0, imgfxFlags);
2111 break;
2112 case IMGFX_SET_WAVY:
2114 set_npc_imgfx_all(npc->spriteInstanceID, IMGFX_SET_WAVY, imgfxArg1, imgfxArg2, imgfxArg3, 0, imgfxFlags);
2115 break;
2116 case IMGFX_SET_COLOR:
2118 set_npc_imgfx_all(npc->spriteInstanceID, IMGFX_SET_COLOR, imgfxArg1, imgfxArg2, imgfxArg3, 255, imgfxFlags);
2119 break;
2120 case IMGFX_SET_ALPHA:
2122 set_npc_imgfx_all(npc->spriteInstanceID, IMGFX_SET_ALPHA, 255, 255, 255, imgfxArg1, imgfxFlags);
2123 break;
2124 case IMGFX_SET_TINT:
2126 set_npc_imgfx_all(npc->spriteInstanceID, IMGFX_SET_TINT, imgfxArg1, imgfxArg2, imgfxArg3, imgfxArg4, imgfxFlags);
2127 break;
2130 set_npc_imgfx_all(npc->spriteInstanceID, IMGFX_SET_WHITE_FADE, imgfxArg1, imgfxArg2, imgfxArg3, 255, imgfxFlags);
2131 break;
2134 set_npc_imgfx_all(npc->spriteInstanceID, IMGFX_SET_CREDITS_FADE, imgfxArg1, imgfxArg2, imgfxArg3, imgfxArg4, imgfxFlags);
2135 break;
2136 case IMGFX_SET_ANIM:
2138 set_npc_imgfx_all(npc->spriteInstanceID, IMGFX_SET_ANIM, imgfxArg1, imgfxArg2, imgfxArg3, 0, imgfxFlags);
2139 break;
2140 case IMGFX_HOLOGRAM:
2142 set_npc_imgfx_all(npc->spriteInstanceID, IMGFX_HOLOGRAM, imgfxArg1, imgfxArg2, imgfxArg3, imgfxArg4, imgfxFlags);
2143 break;
2144 case IMGFX_FILL_COLOR:
2146 set_npc_imgfx_all(npc->spriteInstanceID, IMGFX_FILL_COLOR, imgfxArg1, imgfxArg2, imgfxArg3, 255, imgfxFlags);
2147 break;
2148 case IMGFX_OVERLAY:
2150 set_npc_imgfx_all(npc->spriteInstanceID, IMGFX_OVERLAY, imgfxArg1, 255, 0, 255, imgfxFlags);
2151 break;
2152 case IMGFX_OVERLAY_XLU:
2154 set_npc_imgfx_all(npc->spriteInstanceID, IMGFX_OVERLAY, imgfxArg1, imgfxArg2, 0, imgfxArg2, imgfxFlags);
2155 break;
2156 }
2157}
@ IMGFX_RESET
Definition enums.h:4705
@ IMGFX_HOLOGRAM
Definition enums.h:4715
@ IMGFX_SET_COLOR
Definition enums.h:4708
@ IMGFX_OVERLAY_XLU
Definition enums.h:4718
@ IMGFX_OVERLAY
Definition enums.h:4717
@ IMGFX_SET_WAVY
Definition enums.h:4706
@ IMGFX_FILL_COLOR
Definition enums.h:4716
@ IMGFX_SET_CREDITS_FADE
Definition enums.h:4712
@ IMGFX_SET_TINT
Definition enums.h:4710
@ IMGFX_SET_WHITE_FADE
Definition enums.h:4711
@ IMGFX_SET_ANIM
Definition enums.h:4707
@ IMGFX_UNK_2
Definition enums.h:4704
@ IMGFX_UNK_1
Definition enums.h:4703
@ RENDER_MODE_SURFACE_XLU_LAYER2
Definition enums.h:3321
@ RENDER_MODE_ALPHATEST
Definition enums.h:3310
s16 imgfxArg2
s16 imgfxArg3
s16 imgfxArg4
s16 imgfxArg1

Referenced by appendGfx_npc_blur(), npc_reload_all(), and npc_set_imgfx_params().

◆ npc_set_imgfx_params()

void npc_set_imgfx_params ( Npc * npc,
s32 arg1,
s32 arg2,
s32 arg3,
s32 arg4,
s32 arg5,
s32 arg6 )

Definition at line 2159 of file npc.c.

2159 {
2160 npc->imgfxType = imgfxType;
2161 npc->imgfxArg1 = arg2;
2162 npc->imgfxArg2 = arg3;
2163 npc->imgfxArg3 = arg4;
2164 npc->imgfxArg4 = arg5;
2165 npc->imgfxFlags = arg6;
2166 npc_imgfx_update(npc);
2167}

Referenced by end_outta_sight_cleanup(), reset_outta_sight_alpha_on_menu_close(), and update_riding_physics().

◆ npc_surface_spawn_fx()

void npc_surface_spawn_fx ( Npc * npc,
SurfaceInteractMode mode )

Definition at line 394 of file surfaces.c.

394 {
396
397 if ((npc->flags & NPC_FLAG_INVISIBLE) || !(npc->flags & NPC_FLAG_TOUCHES_GROUND) || npc->moveSpeed == 0.0f) {
398 return;
399 }
400
402 switch (surfaceType) {
405 break;
408 break;
410 npc_surface_spawn_snow_fx(npc, mode);
411 break;
414 break;
417 break;
418 default:
420 break;
421 }
422}
@ SURFACE_TYPE_HEDGES
used within hedge maze in flo_11
Definition enums.h:4264
@ SURFACE_TYPE_SNOW
Definition enums.h:4263
@ SURFACE_TYPE_WATER
Definition enums.h:4256
@ SURFACE_TYPE_CLOUD
used with clouds in flo_19 and flo_21
Definition enums.h:4262
@ SURFACE_TYPE_FLOWERS
Definition enums.h:4261
@ COLLIDER_FLAGS_SURFACE_TYPE_MASK
Definition enums.h:4278
s32 get_collider_flags(s32 colliderID)
Definition collision.c:481
void npc_surface_spawn_water_fx(Npc *npc, SurfaceInteractMode mode)
Definition surfaces.c:574
void npc_surface_spawn_snow_fx(Npc *npc, SurfaceInteractMode mode)
Definition surfaces.c:540
void npc_surface_spawn_flower_fx(Npc *npc, SurfaceInteractMode mode)
Definition surfaces.c:469
void npc_surface_spawn_cloud_fx(Npc *npc, SurfaceInteractMode mode)
Definition surfaces.c:502
void npc_surface_spawn_basic_fx(Npc *npc, SurfaceInteractMode mode)
Definition surfaces.c:424
void npc_surface_spawn_hedges_fx(Npc *npc, SurfaceInteractMode mode)
Definition surfaces.c:560

Referenced by _npc_jump_to(), AvoidPlayerAI_Chase(), basic_ai_chase(), CleftAI_Tackle(), GuardAI_Chase(), partner_get_out(), partner_move_to_goal(), partner_walking_follow_player(), PatrolAI_Chase(), PatrolAI_Move(), player_jump(), and update_riding_physics().

◆ spawn_default_surface_effects()

void spawn_default_surface_effects ( Npc * npc,
SurfaceInteractMode mode )

◆ spawn_flower_surface_effects()

void spawn_flower_surface_effects ( Npc * npc,
SurfaceInteractMode mode )

◆ spawn_cloud_surface_effects()

void spawn_cloud_surface_effects ( Npc * npc,
SurfaceInteractMode mode )

◆ spawn_snow_surface_effects()

void spawn_snow_surface_effects ( Npc * npc,
SurfaceInteractMode mode )

◆ spawn_hedge_surface_effects()

void spawn_hedge_surface_effects ( Npc * npc,
SurfaceInteractMode mode )

◆ spawn_water_surface_effects()

void spawn_water_surface_effects ( Npc * npc,
SurfaceInteractMode mode )

◆ COPY_set_defeated()

void COPY_set_defeated ( s32 mapID,
s32 encounterID )

Duplicate of set_defeated().

Definition at line 2169 of file npc.c.

2169 {
2171 s32 encounterIdx = encounterID / 32;
2173 s32 flag;
2174
2175 flag = encounterID % 32;
2176 encounterShift = flag;
2178 currentEncounter->defeatFlags[mapID][encounterIdx] = flag | (1 << encounterShift);
2179
2180 // TODO: The below should work but has regalloc issues:
2181 /*EncounterStatus *currentEncounter = &gCurrentEncounter;
2182 s32 encounterIdx = encounterID / 32;
2183 s32 encounterShift = encounterID % 32;
2184
2185 currentEncounter->defeatFlags[mapID][encounterIdx] |= (1 << encounterShift);*/
2186}
EncounterStatus gCurrentEncounter
Definition encounter.c:175
s32 defeatFlags[60][12]
Definition npc.h:403

Referenced by kill_enemy().

◆ init_encounter_status()

void init_encounter_status ( void )

Definition at line 2188 of file npc.c.

2188 {
2190 s32 i;
2191 s32 j;
2192
2193 for (i = 0; i < ARRAY_COUNT(currentEncounter->encounterList); i++) {
2195 }
2196
2198 currentEncounter->numEncounters = 0;
2199 currentEncounter->firstStrikeType = FIRST_STRIKE_NONE;
2200 currentEncounter->hitType = 0;
2201 currentEncounter->battleTriggerCooldown = 0;
2202 currentEncounter->npcGroupList = 0;
2203 currentEncounter->unk_08 = 0;
2204 currentEncounter->dropWhackaBump = false;
2205
2206 for (i = 0; i < ARRAY_COUNT(currentEncounter->defeatFlags); i++) {
2207 for (j = 0; j < ARRAY_COUNT(currentEncounter->defeatFlags[i]); j++) {
2208 currentEncounter->defeatFlags[i][j] = 0;
2209 }
2210 }
2211
2212 for (i = 0; i < ARRAY_COUNT(currentEncounter->recentMaps); i++) {
2213 currentEncounter->recentMaps[i] = -1;
2214 }
2215
2216 func_80045AC0();
2219}
@ ENCOUNTER_FLAG_NONE
Definition enums.h:4571
@ ENCOUNTER_STATE_NONE
Definition enums.h:5879
@ FIRST_STRIKE_NONE
Definition enums.h:3492
void func_80045AC0(void)
s32 create_worker_scene(void(*updateFunc)(void), void(*renderFunc)(void))
Definition worker.c:32
void npc_render_worker_do_nothing(void)
Definition npc.c:2325
Encounter * encounterList[24]
Definition npc.h:392
s32 gEncounterState
Definition encounter.c:173

Referenced by load_engine_data(), state_step_demo(), state_step_intro(), and state_step_startup().

◆ clear_encounter_status()

void clear_encounter_status ( void )

Definition at line 2221 of file npc.c.

2221 {
2223 s32 i;
2224 s32 j;
2225
2226 for (i = 0; i < ARRAY_COUNT(currentEncounter->encounterList); i++) {
2228 }
2229
2231 for (i = 0; i < ARRAY_COUNT(currentEncounter->defeatFlags); i++) {
2232 for (j = 0; j < ARRAY_COUNT(currentEncounter->defeatFlags[i]); j++) {
2233 currentEncounter->defeatFlags[i][j] = 0;
2234 }
2235 }
2236
2238 for (i = 0; i < ARRAY_COUNT(currentEncounter->recentMaps); i++) {
2239 currentEncounter->recentMaps[i] = -1;
2240 }
2241 }
2242 }
2243
2244 currentEncounter->numEncounters = 0;
2245 currentEncounter->firstStrikeType = FIRST_STRIKE_NONE;
2246 currentEncounter->hitType = 0;
2247 currentEncounter->battleTriggerCooldown = 0;
2248 currentEncounter->curAreaIndex = gGameStatusPtr->areaID;
2249 currentEncounter->curMapIndex = gGameStatusPtr->mapID;
2250 currentEncounter->curEntryIndex = gGameStatusPtr->entryID;
2251 currentEncounter->npcGroupList = 0;
2252 currentEncounter->unk_08 = 0;
2253 currentEncounter->scriptedBattle = false;
2254
2255 func_80045AC0();
2258}

Referenced by load_demo_battle(), and load_map_by_IDs().

◆ func_8003E50C()

void func_8003E50C ( void )

Definition at line 2260 of file npc.c.

2260 {
2261}

◆ func_8003E514()

void func_8003E514 ( s8 arg0)

Definition at line 2263 of file npc.c.

2263 {
2265}

Referenced by btl_state_update_end_battle().

◆ update_encounters()

void update_encounters ( void )

Definition at line 2267 of file npc.c.

2267 {
2268 switch (gEncounterState) {
2270 break;
2273 break;
2276 break;
2279 break;
2282 break;
2285 break;
2286 }
2287
2289}
@ ENCOUNTER_STATE_POST_BATTLE
Definition enums.h:5884
@ ENCOUNTER_STATE_CONVERSATION
Definition enums.h:5883
@ ENCOUNTER_STATE_NEUTRAL
Definition enums.h:5881
@ ENCOUNTER_STATE_PRE_BATTLE
Definition enums.h:5882
@ ENCOUNTER_STATE_CREATE
Definition enums.h:5880
void create_encounters(void)
Definition encounter.c:2460
void update_encounters_conversation(void)
Definition encounter.c:2262
void update_encounters_neutral(void)
Definition encounter.c:480
void update_encounters_post_battle(void)
Definition encounter.c:1618
void update_encounters_pre_battle(void)
Definition encounter.c:1260
void update_merlee_messages(void)

Referenced by state_step_battle(), state_step_change_map(), state_step_enter_world(), state_step_game_over(), state_step_intro(), state_step_pause(), state_step_unpause(), and state_step_world().

◆ draw_encounter_ui()

void draw_encounter_ui ( void )

Definition at line 2291 of file npc.c.

2291 {
2292 switch (gEncounterState) {
2294 break;
2297 break;
2300 break;
2303 break;
2306 break;
2309 break;
2310 }
2311
2313}
void init_encounters_ui(void)
Definition encounter.c:2812
void draw_encounters_pre_battle(void)
Definition encounter.c:1486
void draw_merlee_messages(void)
void draw_encounters_conversation(void)
Definition encounter.c:2318
void draw_encounters_neutral(void)
Definition encounter.c:1257
void draw_encounters_post_battle(void)
Definition encounter.c:2252

Referenced by state_drawUI_battle(), and state_drawUI_world().

◆ draw_first_strike_ui()

void draw_first_strike_ui ( void )

Definition at line 2315 of file npc.c.

2315 {
2316 switch (gEncounterState) {
2318 break;
2321 break;
2322 }
2323}
void show_first_strike_message(void)
Definition encounter.c:1562

Referenced by state_world_draw_aux_ui().

◆ npc_render_worker_do_nothing()

void npc_render_worker_do_nothing ( void )

Definition at line 2325 of file npc.c.

2325 {
2326}

Referenced by clear_encounter_status(), and init_encounter_status().

◆ make_npcs()

void make_npcs ( s32 flags,
s32 mapID,
s32 * npcGroupList )

Definition at line 2328 of file npc.c.

2328 {
2330 s32 i;
2331 s32 j;
2332
2334 currentEncounter->mapID = mapID;
2335 currentEncounter->npcGroupList = npcGroupList;
2336
2338 for (i = 0; i < ARRAY_COUNT(currentEncounter->defeatFlags); i++) {
2339 for (j = 0; j < ARRAY_COUNT(currentEncounter->defeatFlags[i]); j++) {
2340 currentEncounter->defeatFlags[i][j] = 0;
2341 }
2342 }
2343
2345 for (i = 0; i < ARRAY_COUNT(currentEncounter->recentMaps); i++) {
2346 currentEncounter->recentMaps[i] = -1;
2347 }
2348 }
2349 }
2350
2351 if (npcGroupList != nullptr) {
2353 EncounterStateChanged = true;
2355 }
2356}
s8 flags
Definition demo_api.c:15
@ ENCOUNTER_SUBSTATE_CREATE_INIT
Definition enums.h:5888
s8 resetMapEncounterFlags
Definition npc.h:389
b32 EncounterStateChanged
Definition encounter.c:23
s32 gEncounterSubState
Definition encounter.c:174

◆ kill_encounter()

void kill_encounter ( Enemy * enemy)

Definition at line 2358 of file npc.c.

2358 {
2360 s32 i;
2361
2362 for (i = 0; i < encounter->count; i++) {
2363 Enemy* currentEnemy = encounter->enemy[i];
2364 if (currentEnemy != nullptr) {
2366 encounter->enemy[i] = nullptr;
2367 }
2368 }
2369}
void kill_enemy(Enemy *enemy)
Definition npc.c:2371
s8 encounterIndex
Definition npc.h:296
Definition npc.h:294

◆ kill_enemy()

void kill_enemy ( Enemy * enemy)

Definition at line 2371 of file npc.c.

2371 {
2373 Encounter* encounter = encounterStatus->encounterList[enemy->encounterIndex];
2374 s32 i;
2375 s32 j;
2376
2377 for (i = 0; i < encounter->count; i++) {
2378 Enemy* currentEnemy = encounter->enemy[i];
2379 if (currentEnemy == enemy) {
2380 break;
2381 }
2382 }
2383
2384 if (enemy->initScript != nullptr) {
2386 }
2387 if (enemy->interactScript != nullptr) {
2389 }
2390 if (enemy->aiScript != nullptr) {
2392 }
2393 if (enemy->hitScript != nullptr) {
2395 }
2396 if (enemy->auxScript != nullptr) {
2398 }
2399 if (enemy->defeatScript != nullptr) {
2401 }
2402
2403 enemy->interactBytecode = nullptr;
2404 enemy->aiBytecode = nullptr;
2405 enemy->hitBytecode = nullptr;
2406 enemy->auxBytecode = nullptr;
2407 enemy->defeatBytecode = nullptr;
2408
2409 #if DX_DEBUG_MENU
2410 if (enemy->npcID != (s16) DX_DEBUG_DUMMY_ID) {
2411 free_npc(get_npc_unsafe(enemy->npcID));
2412 }
2413 #else
2414 free_npc(get_npc_unsafe(enemy->npcID));
2415 #endif
2416
2417 if (enemy->unk_64 != nullptr) {
2418 heap_free(enemy->unk_64);
2419 }
2420
2421 for (j = 0; j < ARRAY_COUNT(encounter->enemy); j++) {
2422 if (encounter->enemy[j] == enemy) {
2423 encounter->enemy[j] = nullptr;
2424 }
2425 }
2426
2427 if (!(enemy->flags & ENEMY_FLAG_DO_NOT_KILL)
2428 && (!(enemy->flags & ENEMY_FLAG_ENABLE_HIT_SCRIPT) || (enemy == encounterStatus->curEnemy))
2429 && !(enemy->flags & ENEMY_FLAG_PASSIVE)
2430 && !(enemy->flags & ENEMY_FLAG_FLED)
2431 ) {
2432 COPY_set_defeated(encounterStatus->mapID, encounter->encounterID + i);
2433 }
2434
2435 heap_free(enemy);
2436}
@ ENEMY_FLAG_DO_NOT_KILL
Definition enums.h:4108
@ ENEMY_FLAG_PASSIVE
Definition enums.h:4106
@ ENEMY_FLAG_FLED
Definition enums.h:4110
@ ENEMY_FLAG_ENABLE_HIT_SCRIPT
Definition enums.h:4109
void kill_script_by_ID(s32 id)
void free_npc(Npc *npc)
Definition npc.c:236
Npc * get_npc_unsafe(s32 npcID)
Definition npc.c:992
void COPY_set_defeated(s32 mapID, s32 encounterID)
Duplicate of set_defeated().
Definition npc.c:2169
struct Evt * interactScript
Definition npc.h:312
s32 flags
Definition npc.h:295
s16 npcID
Definition npc.h:300
s32 interactScriptID
Definition npc.h:318
struct Evt * hitScript
Definition npc.h:314
EvtScript * hitBytecode
Definition npc.h:308
s32 auxScriptID
Definition npc.h:321
s32 initScriptID
Definition npc.h:317
struct Evt * defeatScript
Definition npc.h:316
EvtScript * interactBytecode
Definition npc.h:306
s32 aiScriptID
Definition npc.h:319
struct Evt * initScript
Definition npc.h:311
s32 defeatScriptID
Definition npc.h:322
struct Evt * auxScript
Definition npc.h:315
void * unk_64
Definition npc.h:323
EvtScript * defeatBytecode
Definition npc.h:310
EvtScript * aiBytecode
Definition npc.h:307
struct Evt * aiScript
Definition npc.h:313
EvtScript * auxBytecode
Definition npc.h:309
s32 hitScriptID
Definition npc.h:320

Referenced by kill_encounter(), and update_encounters_post_battle().

◆ bind_enemy_ai()

s32 bind_enemy_ai ( Enemy * enemy,
EvtScript * aiScriptBytecode )

Binds the specified ai script to the specified enemy.

Parameters
enemypointer to the enemy to bind the script to
aiScriptBytecodepointer to the script to be bound.

Definition at line 2438 of file npc.c.

2438 {
2439 Evt* aiScript;
2440 s32 id;
2441
2442 if (enemy->aiScript != nullptr) {
2443 kill_script_by_ID(enemy->aiScript->id);
2444 }
2446 aiScript = enemy->aiScript = start_script(aiScriptBytecode, EVT_PRIORITY_A, 0);
2447 id = enemy->aiScriptID = aiScript->id;
2448 aiScript->owner1.enemy = enemy;
2449 return id;
2450}
union Evt::@10 owner1
Initially -1.
@ EVT_PRIORITY_A
Definition evt.h:154
Evt * start_script(EvtScript *source, s32 priority, s32 initialState)

Referenced by bind_npc_ai().

◆ bind_enemy_aux()

s32 bind_enemy_aux ( Enemy * enemy,
EvtScript * auxScriptBytecode )

Binds the specified auxillary script to the specified enemy.

Parameters
enemypointer to the enemy to bind the script to
auxScriptBytecodepointer to the script to be bound.

Definition at line 2452 of file npc.c.

2452 {
2453 Evt* auxScript;
2454 s32 id;
2455
2456 if (enemy->auxScript != nullptr) {
2458 }
2460 auxScript = enemy->auxScript = start_script(auxScriptBytecode, EVT_PRIORITY_A, 0);
2461 id = enemy->auxScriptID = auxScript->id;
2462 auxScript->owner1.enemy = enemy;
2463 return id;
2464}

Referenced by bind_npc_aux().

◆ bind_enemy_interact()

s32 bind_enemy_interact ( Enemy * enemy,
EvtScript * interactScriptBytecode )

Binds the specified interact script to the specified enemy.

Parameters
enemypointer to the enemy to bind the script to
interactScriptBytecodepointer to the script to be bound.

Definition at line 2466 of file npc.c.

2466 {
2467 Evt* interactScript;
2468 s32 id;
2469
2470 if (enemy->interactScript != nullptr) {
2472 }
2475 id = enemy->interactScriptID = interactScript->id;
2476 interactScript->owner1.enemy = enemy;
2477 return id;
2478}

Referenced by bind_npc_interact().

◆ bind_npc_ai()

void bind_npc_ai ( s32 npcID,
EvtScript * npcAiBytecode )

Binds the specified ai script to the npc matching the specified npcId.

Parameters
npcIDID of the desired npc
npcAiBytecodepointer to the script to be bound.

Definition at line 2480 of file npc.c.

2480 {
2482 s32 i;
2483 s32 j;
2484
2485 for (i = 0; i < currentEncounterStatus->numEncounters; i++) {
2487 if (currentEncounter != nullptr) {
2488 for (j = 0; j < currentEncounter->count; j++) {
2490 if ((currentEnemy != nullptr) && (currentEnemy->npcID == npcID)) {
2492 break;
2493 }
2494 }
2495 }
2496 }
2497}
s32 bind_enemy_ai(Enemy *enemy, EvtScript *aiScriptBytecode)
Binds the specified ai script to the specified enemy.
Definition npc.c:2438

◆ bind_npc_aux()

void bind_npc_aux ( s32 npcID,
EvtScript * npcAuxBytecode )

Binds the specified auxillary script to the npc matching the specified npcId.

Parameters
npcIDID of the desired npc
npcAuxBytecodepointer to the script to be bound.

Definition at line 2499 of file npc.c.

2499 {
2501 s32 i;
2502 s32 j;
2503
2504 for (i = 0; i < currentEncounterStatus->numEncounters; i++) {
2506 if (currentEncounter != nullptr) {
2507 for (j = 0; j < currentEncounter->count; j++) {
2509 if ((currentEnemy != nullptr) && (currentEnemy->npcID == npcID)) {
2511 break;
2512 }
2513 }
2514 }
2515 }
2516}
s32 bind_enemy_aux(Enemy *enemy, EvtScript *auxScriptBytecode)
Binds the specified auxillary script to the specified enemy.
Definition npc.c:2452

◆ bind_npc_interact()

void bind_npc_interact ( s32 npcID,
EvtScript * npcInteractBytecode )

Binds the specified interact script to the npc matching the specified npcId.

Parameters
npcIDID of the desired npc
npcInteractBytecodepointer to the script to be bound.

Definition at line 2518 of file npc.c.

2518 {
2520 s32 i;
2521 s32 j;
2522
2523 for (i = 0; i < currentEncounterStatus->numEncounters; i++) {
2525 if (currentEncounter != nullptr) {
2526 for (j = 0; j < currentEncounter->count; j++) {
2528 if ((currentEnemy != nullptr) && (currentEnemy->npcID == npcID)) {
2530 break;
2531 }
2532 }
2533 }
2534 }
2535}
s32 bind_enemy_interact(Enemy *enemy, EvtScript *interactScriptBytecode)
Binds the specified interact script to the specified enemy.
Definition npc.c:2466

◆ get_enemy()

Enemy * get_enemy ( s32 npcID)

Looks for an enemy matching the specified npcID.

Parameters
npcIDID of the npc bound to the desired enemy.
Returns
pointer to Enemy struct, if one is found. If one is not found, a panic occurs.

Definition at line 2537 of file npc.c.

2537 {
2539 s32 i;
2540 s32 j;
2541
2542 for (i = 0; i < currentEncounterStatus->numEncounters; i++) {
2544 if (currentEncounter != nullptr) {
2545 for (j = 0; j < currentEncounter->count; j++) {
2547 if ((currentEnemy != nullptr) && (currentEnemy->npcID == npcID)) {
2548 return currentEnemy;
2549 }
2550 }
2551 }
2552 }
2553 PANIC();
2554}
#define PANIC()
Definition macros.h:54

Referenced by ai_enemy_play_sound(), FlyingMagikoopaAI_23(), LakituAI_GetAvailableSpiny(), MagikoopaAI_23(), MagikoopaAI_CanShootSpell(), MeleeHitbox_CanSeePlayer(), ProjectileHitbox_30(), ProjectileHitbox_32(), ProjectileHitbox_GetUsableProjectileID(), SentinelAI_DescendInit(), set_npc_animation(), and UnkNpcAIFunc48().

◆ get_enemy_safe()

Enemy * get_enemy_safe ( s32 npcID)

Same as get_enemy(), with the exception of always returning a value if an enemy is not found.

Parameters
npcIDID of the npc bound to the desired enemy.
Returns
pointer to Enemy struct, if one is found. Otherwise, nullptr.

Definition at line 2556 of file npc.c.

2556 {
2558 s32 i;
2559 s32 j;
2560
2561 for (i = 0; i < currentEncounterStatus->numEncounters; i++) {
2563
2564 if (currentEncounter != nullptr) {
2565 for (j = 0; j < currentEncounter->count; j++) {
2567 if ((currentEnemy != nullptr) && (currentEnemy->npcID == npcID)) {
2568 return currentEnemy;
2569 }
2570 }
2571 }
2572 }
2573 return nullptr;
2574}

◆ set_npc_sprite()

void set_npc_sprite ( Npc * npc,
s32 anim,
AnimID * extraAnimList )

Definition at line 1045 of file npc.c.

1045 {
1047
1048 npc->extraAnimList = extraAnimList;
1049
1050 if (!(npc->flags & NPC_FLAG_HAS_NO_SPRITE)) {
1051 npc->spriteInstanceID = spr_load_npc_sprite(anim, extraAnimList);
1052 ASSERT(npc->spriteInstanceID >= 0);
1053 }
1054
1055 npc->curAnim = anim;
1056
1057 if (!(npc->flags & NPC_FLAG_NO_ANIMS_LOADED)) {
1058 if (!(npc->flags & NPC_FLAG_HAS_NO_SPRITE)) {
1060 }
1061 }
1062}

Variable Documentation

◆ gCurrentEncounter