Skip to content

Commit a410189

Browse files
Bsquosnailspeed3
authored andcommitted
Add AIPathManager and related structs
1 parent 7c6d515 commit a410189

File tree

12 files changed

+101
-31
lines changed

12 files changed

+101
-31
lines changed

config/RMCP01/module/symbols.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11227,7 +11227,7 @@ __dt__Q25Enemy10struct_121Fv = .text:0x00224EFC; // type:function size:0x40
1122711227
vf_0x0C__Q25Enemy10struct_121Fv = .text:0x00224F3C; // type:function size:0x4
1122811228
vf_0x10__Q25Enemy10struct_121Fv = .text:0x00224F40; // type:function size:0x4
1122911229
avoidPow__Q25Enemy14AITrickHandlerFv = .text:0x00224F44; // type:function size:0x10
11230-
isStartingAirborne__Q25Enemy14AITrickHandlerFv = .text:0x00224F54; // type:function size:0x40
11230+
allowTricking__Q25Enemy14AITrickHandlerFv = .text:0x00224F54; // type:function size:0x40
1123111231
shouldTrick__Q25Enemy14AITrickHandlerFv = .text:0x00224F94; // type:function size:0xB0
1123211232
__ct__Q25Enemy14AITrickHandlerFPQ25Enemy6AIInfo = .text:0x00225044; // type:function size:0x14
1123311233
__dt__Q25Enemy14AITrickHandlerFv = .text:0x00225058; // type:function size:0x40

include/rk_types.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include <stdint.h>
44
#include <stddef.h>
55
#include <macros.h>
6-
#include <rk_common.h>
76

87
//! Describes an unknown 32 bit value
98
typedef int unk32;

lib/egg/core/eggDisposer.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ class Heap;
1414

1515
//! @brief Base class for garbage-collected objects.
1616
//!
17-
//! Scene-specific, heap-allocated resources in mkw are typically not explicitly
17+
//! Scene-specific, heap-allocated resources in Mario Kart Wii are typically not explicitly
1818
//! freed. This isn't a memory leak, though: when a Scene transitions, all
1919
//! memory allocated within it is returned in one block. However, in C++, the
2020
//! destructor of an object must be called when its lifetime
2121
//! expires--otherwise, we could leak second-order resources and introduce
2222
//! use-after-free bugs.
2323
//!
2424
//! Disposer solves this issue: when a heap is destroyed,
25-
//! the linked list of dispoers is traversed and each destructor is called
25+
//! the linked list of disposers is traversed and each destructor is called
2626
//! in-order.
2727
//!
2828
class Disposer : private NonCopyable {

src/enemy/AIManager.hpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@
44
#include "AIRank.hpp"
55
#include "AISpeed.hpp"
66
#include <egg/core/eggDisposer.hpp>
7+
#include <rk_common.h>
78

89
namespace Enemy {
910

10-
class AIManager: public EGG::Disposer {
11+
class AIManagerEx {
12+
public:
13+
virtual ~AIManagerEx();
14+
};
15+
16+
class AIManager: public AIManagerEx, public EGG::Disposer {
1117
public:
1218
static AIManager* createInstance();
1319
static void destroyInstance();
@@ -17,6 +23,9 @@ namespace Enemy {
1723
inline AIRankManager* getRankManager() { return mpRankManager; }
1824

1925
private:
26+
AIManager();
27+
virtual ~AIManager();
28+
2029
static AIManager* spInstance;
2130

2231
s32 mPlayerCount;
@@ -26,9 +35,6 @@ namespace Enemy {
2635
AI* mpCpuPlayers[MAX_PLAYER_COUNT];
2736
AI* mpRealPlayers[MAX_PLAYER_COUNT];
2837
AIRankManager* mpRankManager;
29-
30-
AIManager();
31-
virtual ~AIManager();
3238
};
3339

3440
}

src/enemy/AIPath.hpp

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#pragma once
22

3-
#include <rk_types.h>
3+
#include <egg/math/eggVector.hpp>
4+
#include <rk_common.h>
45

56
namespace Enemy {
67

8+
struct AIPathManager;
9+
710
struct PointParam {
811
virtual ~PointParam();
912
virtual bool shouldEnterRouteIfHasMushroom();
@@ -30,8 +33,25 @@ namespace Enemy {
3033
f32 field_0x10;
3134
};
3235

33-
struct AIPathPoint {
34-
u8 field_0x00[0x44];
36+
struct AIPathPointInfo {
37+
AIPathPointInfo();
38+
virtual ~AIPathPointInfo();
39+
40+
AIPathManager* mpPathManager;
41+
s8 mStartingPoint;
42+
s8 mPointIdxLog[5]; // List of the last 5 enemy points that have been traversed
43+
s32 field_0x10;
44+
EGG::Vector3f mTargetTrans;
45+
f32 field_0x20;
46+
f32 field_0x24;
47+
f32 offsetRate;
48+
f32 field_0x2C;
49+
s32 mPlayerIdx;
50+
};
51+
52+
struct AIPathPoint: public AIPathPointInfo {
53+
void* mpBattleSearcher;
54+
EGG::Vector3f field_0x38;
3555
};
3656

3757
struct AIPathHandler {
@@ -40,10 +60,10 @@ namespace Enemy {
4060
bool isSwitchingPath();
4161

4262
bool mbIsSwitchingPath;
43-
PointParam* field_0x08;
44-
PointParam* field_0x0C;
45-
PointParam* field_0x10;
46-
AIPathPoint* field_0x14;
63+
PointParam* mpPrevPointParam;
64+
PointParam* mpCurrPointParam;
65+
PointParam* mpNextPointParam;
66+
AIPathPoint* mpPathPoint;
4767
s32 field_0x18;
4868
bool field_0x1C;
4969
bool field_0x20;
@@ -58,4 +78,40 @@ namespace Enemy {
5878
f32 field_0x3C;
5979
};
6080

81+
struct AIPathManager {
82+
AIPathManager();
83+
virtual ~AIPathManager();
84+
85+
AIPathHandler* mpPlayers[MAX_PLAYER_COUNT];
86+
u32 mPlayerCount;
87+
};
88+
89+
struct GoNextInfo {
90+
bool field_0x00;
91+
EGG::Vector3f field_0x04;
92+
u8 field_0x10;
93+
u8 field_0x11;
94+
s32 field_0x14;
95+
u32 field_0x18;
96+
bool field_0x1C;
97+
bool field_0x1D;
98+
bool mbInBullet;
99+
s32 mNextSearchMode;
100+
bool field_0x24;
101+
f32 field_0x28;
102+
103+
enum eSearchMode {
104+
GO_TO_RANDOM_POINT = 0,
105+
GO_TO_RANDOM_POINT_2 = 2,
106+
GO_TO_ITEM_POINT_HIGHEST = 3,
107+
GO_TO_ITEM_POINT_LOWEST = 4,
108+
GO_TO_FRIEND_POINT_HIGHEST = 5,
109+
GO_TO_RIVAL_POINT_HIGHEST = 6,
110+
GO_TO_FRIEND_POINT_LOWEST = 7,
111+
GO_TO_COIN_POINT_HIGHEST = 8,
112+
GO_TO_NEAREST_TARGET = 9,
113+
GO_TO_FARTHEST_TARGET = 10
114+
};
115+
};
116+
61117
}

src/enemy/AITrickHandler.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "AIProbability.hpp"
66
#include "AIControl.hpp"
77
#include "kart/KartState.hpp"
8+
#include <rk_common.h>
89

910
namespace Enemy {
1011

@@ -22,9 +23,13 @@ void AITrickHandler::avoidPow() {
2223
mpInfo->mpInput->setTrick(System::KPadRaceInputState::UP_TRICK);
2324
}
2425

25-
bool AITrickHandler::isStartingAirborne() {
26+
bool AITrickHandler::allowTricking() {
2627
Kart::KartState* state = mpInfo->mpAI->kartState();
2728

29+
/**
30+
* Ensure that CPUs can only request tricking when they are in the air and
31+
* not when they're on a jump pad or mushroom trampoline, or while hit with an object.
32+
*/
2833
if (state->on(Kart::KART_FLAG_AIR_START) && !state->on(Kart::KART_FLAG_JUMPPAD) && !state->on(Kart::KART_FLAG_HIT_ITEM_OR_OBJ)) {
2934
return true;
3035
}
@@ -35,7 +40,7 @@ bool AITrickHandler::isStartingAirborne() {
3540
bool AITrickHandler::shouldTrick() {
3641
AIProbabilityBase* probability = mpInfo->mpAI->mpEngine->mpControl->getAIProbability();
3742

38-
if (isStartingAirborne() && probability->getTrick()) {
43+
if (allowTricking() && probability->getTrick()) {
3944
return true;
4045
}
4146

@@ -58,12 +63,12 @@ void AITrickHandler::update() {
5863
if (shouldTrick()) {
5964
System::KPadRaceInputState* input = mpInfo->mpInput;
6065

61-
const int kartTricks[2] = {
66+
const System::KPadRaceInputState::eTrick kartTricks[2] = {
6267
System::KPadRaceInputState::UP_TRICK,
6368
System::KPadRaceInputState::DOWN_TRICK
6469
};
6570

66-
int rand = AIManager::getInstance()->getRandU32(ARRAY_COUNT(kartTricks));
71+
u32 rand = AIManager::getInstance()->getRandU32(ARRAY_COUNT(kartTricks));
6772
input->setTrick(kartTricks[rand]);
6873
}
6974
}
@@ -99,11 +104,11 @@ void AITrickHandlerBike::calcWheelie() {
99104

100105
System::KPadRaceInputState* input = mpInfo->mpInput;
101106

102-
if (pathHandler->field_0x0C->shouldWheelie() && probability->getWheelie() && !disableWheelie) {
107+
if (pathHandler->mpCurrPointParam->shouldWheelie() && probability->getWheelie() && !disableWheelie) {
103108
mbPerformWheelie = true;
104109
}
105110

106-
if (pathHandler->field_0x0C->shouldEndWheelie()) {
111+
if (pathHandler->mpCurrPointParam->shouldEndWheelie()) {
107112
mbPerformWheelie = false;
108113
input->setTrick(System::KPadRaceInputState::DOWN_TRICK);
109114
}
@@ -118,14 +123,14 @@ void AITrickHandlerBike::update() {
118123
if (shouldTrick()) {
119124
System::KPadRaceInputState* input = mpInfo->mpInput;
120125

121-
const int bikeTricks[4] = {
126+
const System::KPadRaceInputState::eTrick bikeTricks[4] = {
122127
System::KPadRaceInputState::UP_TRICK,
123128
System::KPadRaceInputState::DOWN_TRICK,
124129
System::KPadRaceInputState::LEFT_TRICK,
125130
System::KPadRaceInputState::RIGHT_TRICK,
126131
};
127132

128-
int rand = AIManager::getInstance()->getRandU32(ARRAY_COUNT(bikeTricks));
133+
u32 rand = AIManager::getInstance()->getRandU32(ARRAY_COUNT(bikeTricks));
129134
input->setTrick(bikeTricks[rand]);
130135
}
131136
}

src/enemy/AITrickHandler.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace Enemy {
2121
virtual void disableWheelie();
2222
virtual void update();
2323
void avoidPow();
24-
bool isStartingAirborne();
24+
bool allowTricking();
2525
bool shouldTrick();
2626

2727
AIInfo* mpInfo;

src/system/KPadController.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,16 @@ void KPadUIInputState::setStickY(u8 y) {
8484
mStick.y = rawStickToFloat(y);
8585
}
8686

87-
void KPadRaceInputState::setTrick(int trick) {
87+
void KPadRaceInputState::setTrick(eTrick trick) {
8888
mTrickRaw = trick;
89-
int actualTrick = trick;
89+
eTrick actualTrick = trick;
9090
if (KPadDirector::spInstance->mIsMirror) {
9191
switch (trick) {
92-
case 3:
93-
actualTrick = 4;
92+
case LEFT_TRICK:
93+
actualTrick = RIGHT_TRICK;
9494
break;
95-
case 4:
96-
actualTrick = 3;
95+
case RIGHT_TRICK:
96+
actualTrick = LEFT_TRICK;
9797
break;
9898
default:
9999
break;

src/system/KPadController.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ struct KPadRaceInputState {
3636
void setStickXMirrored(u8 x);
3737
void setStickXUnmirrored(u8 x);
3838
void setStickY(u8 y);
39-
void setTrick(int trick);
39+
void setTrick(eTrick trick);
4040

4141
u16 mButtons; // [this+0x04]
4242
u16 mButtonsRaw; // [this+0x06]

src/system/KPadDirector.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include <rk_types.h>
44

5+
#include <rk_common.h>
6+
57
#include <decomp.h>
68

79
#include <rvl/pad/pad.h>

0 commit comments

Comments
 (0)