-
Notifications
You must be signed in to change notification settings - Fork 2
/
fight.d
224 lines (176 loc) · 5.53 KB
/
fight.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
* Fight mode functions
*/
/*
* Switch to fist mode
*/
func void FM_SetToFistMode (var int slfInstance) {
var C_NPC slf; slf = Hlp_GetNpc (slfInstance);
if (Npc_IsInFightMode (slf, FMODE_FIST)) { return; };
var int itemPtr; itemPtr = oCNpc_GetWeapon (slf);
if (itemPtr) {
AI_RemoveWeapon (slf);
};
AI_DrawWeapon_Ext (slf, FMODE_FIST, 1); //Melee - fists
};
/*
* Switch to fight mode (specific melee weapon)
*/
func void FM_SetToMelee (var int slfInstance, var int itemInstanceID) {
var C_NPC slf; slf = Hlp_GetNpc (slfInstance);
if (!Npc_HasItems (slf, itemInstanceID)) { return; };
var int itemPtr; itemPtr = oCNpc_GetWeapon (slf);
if (itemPtr) {
var oCItem itm; itm = _^ (itemPtr);
//Is this weapon that we want to draw?
if (Hlp_GetInstanceID (itm) == itemInstanceID) {
return;
};
};
if ((itemPtr) || (Npc_IsInFightMode (slf, FMODE_FIST))) {
AI_RemoveWeapon (slf);
};
if (Npc_GetInvItem (slf, itemInstanceID)) {
if ((item.Flags & ITEM_ACTIVE_LEGO) == FALSE) {
AI_UnequipMeleeWeapon (slf);
AI_EquipItemPtr (slf, _@ (item));
};
};
AI_DrawWeapon_Ext (slf, FMODE_FIST, 0); //Melee
};
/*
* Switch to fight mode (specific ranged weapon)
*/
func void FM_SetToRanged (var int slfInstance, var int itemInstanceID) {
var C_NPC slf; slf = Hlp_GetNpc (slfInstance);
if (!Npc_HasItems (slf, itemInstanceID)) { return; };
var int itemPtr; itemPtr = oCNpc_GetWeapon (slf);
if (itemPtr) {
var oCItem itm; itm = _^ (itemPtr);
//Is this weapon that we want to draw?
if (Hlp_GetInstanceID (itm) == itemInstanceID) {
return;
};
};
//Remove weapon
if ((itemPtr) || (Npc_IsInFightMode (slf, FMODE_FIST))) {
AI_RemoveWeapon (slf);
};
//Equip weapon if not equipped
if (Npc_GetInvItem (slf, itemInstanceID)) {
if ((item.Flags & ITEM_ACTIVE_LEGO) == FALSE) {
AI_UnequipRangedWeapon (slf);
AI_EquipItemPtr (slf, _@ (item));
};
};
AI_DrawWeapon_Ext (slf, FMODE_FAR, 0); //Ranged
};
/*
* Engine functions
*/
/*
* oCNpc_FightAttackMelee
*/
func int oCNpc_FightAttackMelee (var int slfInstance, var int fightMove) {
//0x007499D0 private: int __thiscall oCNpc::FightAttackMelee(int)
const int oCNpc__FightAttackMelee_G1 = 7641552;
//0x0067EEC0 private: int __thiscall oCNpc::FightAttackMelee(int)
const int oCNpc__FightAttackMelee_G2 = 6811328;
var oCNpc slf; slf = Hlp_GetNPC (slfInstance);
if (!Hlp_IsValidNPC (slf)) { return FALSE; };
var int slfPtr; slfPtr = _@ (slf);
var int retVal;
const int call = 0;
if (CALL_Begin(call)) {
CALL_PutRetValTo (_@ (retVal));
CALL_IntParam (_@ (fightMove));
CALL__thiscall (_@ (slfPtr), MEMINT_SwitchG1G2 (oCNpc__FightAttackMelee_G1, oCNpc__FightAttackMelee_G2));
call = CALL_End();
};
return + retVal;
};
/*
* oCNpc_ThinkNextFightAction
*/
func int oCNpc_ThinkNextFightAction (var int slfInstance) {
//0x00749150 private: int __thiscall oCNpc::ThinkNextFightAction(void)
const int oCNpc__ThinkNextFightAction_G1 = 7639376;
//0x0067E350 private: int __thiscall oCNpc::ThinkNextFightAction(void)
const int oCNpc__ThinkNextFightAction_G2 = 6808400;
var oCNpc slf; slf = Hlp_GetNPC (slfInstance);
if (!Hlp_IsValidNPC (slf)) { return FALSE; };
var int slfPtr; slfPtr = _@ (slf);
var int retVal;
const int call = 0;
if (CALL_Begin(call)) {
CALL_PutRetValTo (_@ (retVal));
CALL__thiscall (_@ (slfPtr), MEMINT_SwitchG1G2 (oCNpc__ThinkNextFightAction_G1, oCNpc__ThinkNextFightAction_G2));
call = CALL_End();
};
return + retVal;
};
/*
* oCNpc_FightAttackMagic
*/
func int oCNpc_FightAttackMagic (var int slfInstance) {
//0x0074A800 private: int __thiscall oCNpc::FightAttackMagic(void)
const int oCNpc__FightAttackMagic_G1 = 7645184;
//0x0067FA60 private: int __thiscall oCNpc::FightAttackMagic(void)
const int oCNpc__FightAttackMagic_G2 = 6814304;
var oCNpc slf; slf = Hlp_GetNPC (slfInstance);
if (!Hlp_IsValidNPC (slf)) { return 0; };
var int retVal;
var int slfPtr; slfPtr = _@ (slf);
const int call = 0;
if (CALL_Begin(call)) {
CALL_PutRetValTo (_@ (retVal));
CALL__thiscall (_@ (slfPtr), MEMINT_SwitchG1G2 (oCNpc__FightAttackMagic_G1, oCNpc__FightAttackMagic_G2));
call = CALL_End();
};
return + retVal;
};
/*
* AI functions
*/
/*
* AI_Attack_Ext
* - function allows us to define attack type in parameter subType: EV_ATTACKFORWARD, EV_ATTACKRUN, EV_ATTACKLEFT, EV_ATTACKRIGHT
*/
func void AI_Attack_Ext (var int slfInstance, var int subType, var int combo) {
var oCNpc slf; slf = Hlp_GetNPC (slfInstance);
if (!Hlp_IsValidNPC (slf)) { return; };
if (!slf.AniCtrl) { return; };
var oCAniCtrl_Human aniCtrl; aniCtrl = _^ (slf.AniCtrl);
//Default
var int aniID; aniID = -1;
if (subType == EV_ATTACKFORWARD) { aniID = aniCtrl._t_hitf; };
if (subType == EV_ATTACKRUN) { aniID = aniCtrl._t_hitfrun; };
if (subType == EV_ATTACKLEFT) { aniID = aniCtrl._t_hitl; };
if (subType == EV_ATTACKRIGHT) { aniID = aniCtrl._t_hitr; };
//Default
if (aniID == -1) {
subType = EV_ATTACKFORWARD;
aniID = aniCtrl._t_hitf;
};
var int eMsg; eMsg = oCMsgAttack_Create (subType, 0, FLOATNULL, aniID, combo);
//Get Event Manager
var int eMgr; eMgr = zCVob_GetEM (_@ (slf));
//Add new msg to Event Manager
zCEventManager_OnMessage (eMgr, eMsg, _@ (slf));
};
/*
func void testComboFistFight () {
var oCNpc slf; slf = Hlp_GetNpc (PC_Thief);
Npc_ClearAIQueue (slf);
slf.enemy = _@ (hero);
FM_SetToFistMode (slf);
AI_Attack_Ext (slf, EV_ATTACKFORWARD, 2);
};
func void testComboFight () {
var oCNpc slf; slf = Hlp_GetNpc (PC_Thief);
Npc_ClearAIQueue (slf);
slf.enemy = _@ (hero);
AI_ReadyMeleeWeapon (slf);
AI_Attack_Ext (slf, EV_ATTACKFORWARD, 4);
};
*/