Skip to content

Commit e760732

Browse files
authored
Implement W3DWaypointBuffer (#795)
1 parent 27210e3 commit e760732

File tree

11 files changed

+533
-3
lines changed

11 files changed

+533
-3
lines changed

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ set(GAMEENGINE_SRC
305305
platform/w3dengine/client/w3dmouse.cpp
306306
platform/w3dengine/client/w3dterrainlogic.cpp
307307
platform/w3dengine/client/w3dterraintracks.cpp
308+
platform/w3dengine/client/w3dwaypointbuffer.cpp
308309
platform/w3dengine/common/thing/w3dmodulefactory.cpp
309310
w3d/lib/buff.cpp
310311
w3d/lib/bufffileclass.cpp

src/game/client/ingameui.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ class InGameUI : public SubsystemInterface, public SnapShot
185185
int Get_Drawable_Caption_Size() const { return m_drawableCaptionPointSize; }
186186
Utf8String Get_Drawable_Caption_Font() const { return m_drawableCaptionFont; }
187187
int Get_Drawable_Caption_Color() const { return m_drawableCaptionColor; }
188+
bool Is_In_Waypoint_Mode() const { return m_waypointMode; }
188189

189190
protected:
190191
struct MoveHintStruct
@@ -301,7 +302,7 @@ class InGameUI : public SubsystemInterface, public SnapShot
301302
float m_floatingTextMoveVanishRate;
302303
PopupMessageData *m_popupMessageData;
303304
int m_popupMessageColor;
304-
bool m_unk1; // not 100% identified yet
305+
bool m_waypointMode;
305306
bool m_unk2; // not 100% identified yet
306307
bool m_unk3; // not 100% identified yet
307308
bool m_unk4; // not 100% identified yet

src/game/logic/ai/aistates.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,12 @@ bool Out_Of_Weapon_Range_Object(State *state, void *user_data)
5353
return false;
5454
#endif
5555
}
56+
57+
const Coord3D *AIStateMachine::Get_Goal_Path_Position(int i) const
58+
{
59+
if (i < 0 || i >= static_cast<int>(m_goalPath.size())) {
60+
return nullptr;
61+
}
62+
63+
return &m_goalPath[i];
64+
}

src/game/logic/ai/aistates.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,52 @@
1616
#include "always.h"
1717
#include "statemachine.h"
1818

19+
enum AIStateType
20+
{
21+
AI_IDLE = 0,
22+
AI_MOVE_TO = 1,
23+
AI_FOLLOW_WAYPOINT_PATH_AS_TEAM = 2,
24+
AI_FOLLOW_WAYPOINT_PATH_AS_INDIVIDUALS = 3,
25+
AI_FOLLOW_WAYPOINT_PATH_EXACT_AS_TEAM = 4,
26+
AI_FOLLOW_WAYPOINT_PATH_EXACT_AS_INDIVIDUALS = 5,
27+
AI_FOLLOW_PATH = 6,
28+
AI_FOLLOW_EXITPRODUCTION_PATH = 7,
29+
AI_WAIT = 8,
30+
AI_ATTACK_POSITION = 9,
31+
AI_ATTACK_OBJECT = 10,
32+
AI_FORCE_ATTACK_OBJECT = 11,
33+
AI_ATTACK_AND_FOLLOW_OBJECT = 12,
34+
AI_DEAD = 13,
35+
AI_DOCK = 14,
36+
AI_ENTER = 15,
37+
AI_GUARD = 16,
38+
AI_HUNT = 17,
39+
AI_WANDER = 18,
40+
AI_PANIC = 19,
41+
AI_ATTACK_SQUAD = 20,
42+
AI_GUARD_TUNNEL_NETWORK = 21,
43+
AI_MOVE_OUT_OF_THE_WAY = 23,
44+
AI_MOVE_AND_TIGHTEN = 24,
45+
AI_MOVE_AND_EVACUATE = 25,
46+
AI_MOVE_AND_EVACUATE_AND_EXIT = 26,
47+
AI_MOVE_AND_DELETE = 27,
48+
AI_ATTACK_AREA = 28,
49+
AI_ATTACK_MOVE_TO = 30,
50+
AI_ATTACKFOLLOW_WAYPOINT_PATH_AS_INDIVIDUALS = 31,
51+
AI_ATTACKFOLLOW_WAYPOINT_PATH_AS_TEAM = 32,
52+
AI_FACE_POSITION = 33,
53+
AI_FACE_OBJECT = 34,
54+
AI_RAPPEL = 35,
55+
AI_EXIT = 37,
56+
AI_PICK_UP_CRATE = 38,
57+
AI_MOVE_AWAY_FROM_REPULSORS = 39,
58+
AI_WANDER_IN_PLACE = 40,
59+
AI_BUSY = 41,
60+
AI_EXIT_INSTANTLY = 42,
61+
AI_GUARD_RETALIATE = 43,
62+
NUM_AI_STATES = 44,
63+
};
64+
1965
class Squad;
2066

2167
class AIStateMachine : public StateMachine
@@ -32,6 +78,9 @@ class AIStateMachine : public StateMachine
3278
virtual Utf8String Get_Current_State_Name() override;
3379
#endif
3480

81+
int Get_Goal_Path_Count() const { return m_goalPath.size(); }
82+
const Coord3D *Get_Goal_Path_Position(int i) const;
83+
3584
private:
3685
std::vector<Coord3D> m_goalPath;
3786
Waypoint *m_goalWaypoint;

src/game/logic/object/contain/opencontain.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,38 @@ class ContainModuleInterface
9696
virtual unsigned int Get_Weapon_Bonus_Passed_To_Passengers() const = 0;
9797
virtual bool Get_Container_Pips_To_Show(int &max, int &count);
9898
};
99+
100+
enum ExitDoorType
101+
{
102+
EXIT_DOOR_UNK,
103+
};
104+
105+
class ExitInterface
106+
{
107+
public:
108+
virtual bool Is_Exit_Busy() const = 0;
109+
virtual ExitDoorType Reserve_Door_For_Exit(const ThingTemplate *tmplate, Object *obj) = 0;
110+
virtual void Exit_Object_Via_Door(Object *obj, ExitDoorType type) = 0;
111+
virtual void Exit_Object_Via_Budding(Object *obj, Object *obj2) = 0;
112+
virtual void Unreserve_Door_For_Exit(ExitDoorType type) = 0;
113+
virtual void Exit_Object_In_A_Hurry(Object *obj) {}
114+
virtual void Set_Rally_Point(const Coord3D *point) = 0;
115+
virtual const Coord3D *Get_Rally_Point() = 0;
116+
virtual bool Use_Spawn_Rally_Point() { return false; }
117+
118+
virtual bool Get_Natural_Rally_Point(Coord3D &coord, bool b)
119+
{
120+
coord.x = 0.0f;
121+
coord.y = 0.0f;
122+
coord.z = 0.0f;
123+
return false;
124+
}
125+
126+
virtual bool Get_Exit_Position(Coord3D &coord)
127+
{
128+
coord.x = 0.0f;
129+
coord.y = 0.0f;
130+
coord.z = 0.0f;
131+
return false;
132+
}
133+
};

src/game/logic/object/object.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "experiencetracker.h"
2020
#include "gamelogic.h"
2121
#include "globaldata.h"
22+
#include "opencontain.h"
2223
#include "playerlist.h"
2324
#include "team.h"
2425
#include "updatemodule.h"
@@ -286,6 +287,29 @@ void Object::On_Collide(Object *other, const Coord3D *loc, const Coord3D *normal
286287
}
287288
}
288289

290+
ExitInterface *Object::Get_Object_Exit_Interface() const
291+
{
292+
ExitInterface *exit = nullptr;
293+
294+
for (BehaviorModule **module = m_allModules; *module != nullptr; module++) {
295+
exit = (*module)->Get_Update_Exit_Interface();
296+
297+
if (exit != nullptr) {
298+
break;
299+
}
300+
}
301+
302+
if (exit == nullptr) {
303+
ContainModuleInterface *contain = Get_Contain();
304+
305+
if (contain != nullptr) {
306+
return contain->Get_Contain_Exit_Interface();
307+
}
308+
}
309+
310+
return exit;
311+
}
312+
289313
void Object::Set_Disabled(DisabledType type)
290314
{
291315
Set_Disabled_Until(type, 0x3FFFFFFF);

src/game/logic/object/update/aiupdate.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,27 @@ void AIUpdateInterface::Reset_Next_Mood_Check_Time()
8686
Call_Method<void, AIUpdateInterface>(PICK_ADDRESS(0x005D6030, 0x007FBAB5), this);
8787
#endif
8888
}
89+
90+
AIStateType AIUpdateInterface::Get_AI_State_Type() const
91+
{
92+
return static_cast<AIStateType>(Get_State_Machine()->Get_Current_State_ID());
93+
}
94+
95+
int AIUpdateInterface::Friend_Get_Waypoint_Goal_Path_Size() const
96+
{
97+
if (Get_AI_State_Type() != AI_FOLLOW_PATH) {
98+
return 0;
99+
}
100+
101+
return Get_State_Machine()->Get_Goal_Path_Count();
102+
}
103+
104+
const Coord3D *AIUpdateInterface::Get_Goal_Path_Position(int i) const
105+
{
106+
return Get_State_Machine()->Get_Goal_Path_Position(i);
107+
}
108+
109+
const Coord3D *AIUpdateInterface::Get_Goal_Position() const
110+
{
111+
return Get_State_Machine()->Get_Goal_Position();
112+
}

src/game/logic/object/update/aiupdate.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ class AIUpdateInterface : public UpdateModule, public AICommandInterface
248248
void Reset_Next_Mood_Check_Time();
249249

250250
bool Has_Locomotor_For_Surface(LocomotorSurfaceType t);
251+
int Friend_Get_Waypoint_Goal_Path_Size() const;
252+
AIStateType Get_AI_State_Type() const;
253+
const Coord3D *Get_Goal_Path_Position(int i) const;
254+
const Coord3D *Get_Goal_Position() const;
251255

252256
const Locomotor *Get_Cur_Locomotor() const { return m_curLocomotor; }
253257
Locomotor *Get_Cur_Locomotor() { return m_curLocomotor; }
@@ -270,6 +274,7 @@ class AIUpdateInterface : public UpdateModule, public AICommandInterface
270274
void Set_Current_Turret(WhichTurretType t) { m_currentTurret = t; }
271275

272276
bool Are_Turrets_Linked() const { return Get_AI_Update_Module_Data()->m_turretsLinked; }
277+
int Get_Current_Goal_Path_Index() const { return m_currentGoalPathIndex; }
273278

274279
private:
275280
unsigned char unk[0x8];
@@ -278,7 +283,9 @@ class AIUpdateInterface : public UpdateModule, public AICommandInterface
278283
Path *m_path;
279284
unsigned char unk3[0x20];
280285
ObjectID m_ignoreObstacleID;
281-
unsigned char unk4[0x48];
286+
unsigned char unk4[0x3C];
287+
int m_currentGoalPathIndex;
288+
unsigned char unk5[0x8];
282289
LocomotorSet m_locomotorSet;
283290
Locomotor *m_curLocomotor;
284291
LocomotorSetType m_curLocomotorSet;
@@ -288,6 +295,6 @@ class AIUpdateInterface : public UpdateModule, public AICommandInterface
288295
WhichTurretType m_currentTurret;
289296
AttitudeType m_attitude;
290297
unsigned int m_nextMoodCheckTime;
291-
unsigned char unk5[0x16];
298+
unsigned char unk6[0x16];
292299
bool m_isRecruitable;
293300
};

src/hooker/setuphooks_zh.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@
181181
#include "w3dview.h"
182182
#include "w3dvolumetricshadow.h"
183183
#include "w3dwater.h"
184+
#include "w3dwaypointbuffer.h"
184185
#include "weapon.h"
185186
#include "win32gameengine.h"
186187
#include "win32localfilesystem.h"
@@ -2437,4 +2438,10 @@ void Setup_Hooks()
24372438
Hook_Any(0x00797A20, W3DPropBuffer::Remove_Props_For_Construction);
24382439
Hook_Any(0x00797B60, W3DPropBuffer::Notify_Shroud_Changed);
24392440
Hook_Any(0x00797BA0, W3DPropBuffer::Draw_Props);
2441+
2442+
// w3dwaypointbuffer.h
2443+
Hook_Any(0x00789CB0, W3DWaypointBuffer::Hook_Ctor);
2444+
Hook_Any(0x00789DA0, W3DWaypointBuffer::Hook_Dtor);
2445+
Hook_Any(0x00789DE0, W3DWaypointBuffer::Draw_Waypoints);
2446+
24402447
}

0 commit comments

Comments
 (0)