forked from DaaGvda/xray-oxygen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomDetector.cpp
380 lines (321 loc) · 7.4 KB
/
CustomDetector.cpp
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
#include "stdafx.h"
#include "customdetector.h"
#include "ui/ArtefactDetectorUI.h"
#include "hudmanager.h"
#include "inventory.h"
#include "level.h"
#include "map_manager.h"
#include "ActorEffector.h"
#include "Actor.h"
#include "../xrUICore/UIWindow.h"
#include "player_hud.h"
#include "items/weapon.h"
ITEM_INFO::ITEM_INFO()
{
pParticle = nullptr;
curr_ref = nullptr;
}
ITEM_INFO::~ITEM_INFO()
{
if (pParticle)
CParticlesObject::Destroy(pParticle);
}
bool CCustomDetector::CheckCompatibilityInt(CHudItem* itm, u16* slot_to_activate)
{
if (itm == nullptr)
return true;
CInventoryItem& iitm = itm->item();
u32 slot = iitm.BaseSlot();
bool bres = (slot == INV_SLOT_2 || slot == KNIFE_SLOT || slot == BOLT_SLOT);
if (!bres && slot_to_activate)
{
*slot_to_activate = NO_ACTIVE_SLOT;
if (m_pInventory->ItemFromSlot(BOLT_SLOT))
*slot_to_activate = BOLT_SLOT;
if (m_pInventory->ItemFromSlot(KNIFE_SLOT))
*slot_to_activate = KNIFE_SLOT;
if (m_pInventory->ItemFromSlot(INV_SLOT_3) && m_pInventory->ItemFromSlot(INV_SLOT_3)->BaseSlot() != INV_SLOT_3)
*slot_to_activate = INV_SLOT_3;
if (m_pInventory->ItemFromSlot(INV_SLOT_2) && m_pInventory->ItemFromSlot(INV_SLOT_2)->BaseSlot() != INV_SLOT_3)
*slot_to_activate = INV_SLOT_2;
if (*slot_to_activate != NO_ACTIVE_SLOT)
bres = true;
}
if (itm->GetState() != CHUDState::eShowing)
bres = bres && !itm->IsPending();
if (bres)
{
CWeapon* W = smart_cast<CWeapon*>(itm);
if (W)
bres = bres &&
(W->GetState() != CHUDState::eBore) &&
(W->GetState() != CWeapon::eReload) &&
(W->GetState() != CWeapon::eSwitch) &&
!W->IsZoomed();
}
return bres;
}
bool CCustomDetector::CheckCompatibility(CHudItem* itm)
{
if (!inherited::CheckCompatibility(itm))
return false;
if (!CheckCompatibilityInt(itm, nullptr))
{
HideDetector(true);
return false;
}
return true;
}
void CCustomDetector::HideDetector(bool bFastMode)
{
if (GetState() == eIdle)
{
ToggleDetector(bFastMode);
return;
}
bool bClimb = ((Actor()->MovingState()&mcClimb) != 0);
if (bClimb && GetState() == eShowing)
{
StopCurrentAnimWithoutCallback();
SetState(eIdle);
ToggleDetector(bFastMode);
}
}
void CCustomDetector::ShowDetector(bool bFastMode)
{
if (GetState() == eHidden)
ToggleDetector(bFastMode);
}
void CCustomDetector::ToggleDetector(bool bFastMode)
{
m_bNeedActivation = false;
m_bFastAnimMode = bFastMode;
if (GetState() == eHidden)
{
PIItem iitem = m_pInventory->ActiveItem();
CHudItem* itm = (iitem) ? iitem->cast_hud_item() : nullptr;
u16 slot_to_activate = NO_ACTIVE_SLOT;
if (CheckCompatibilityInt(itm, &slot_to_activate))
{
if (slot_to_activate != NO_ACTIVE_SLOT)
{
m_pInventory->Activate(slot_to_activate);
m_bNeedActivation = true;
}
else
{
SwitchState(eShowing);
TurnDetectorInternal(true);
}
}
}
else
if (GetState() == eIdle)
SwitchState(eHiding);
}
void CCustomDetector::OnStateSwitch(u32 S, u32 oldState)
{
inherited::OnStateSwitch(S, oldState);
switch (S)
{
case eShowing:
{
g_player_hud->attach_item(this);
m_sounds.PlaySound("sndShow", Fvector().set(0, 0, 0), this, true, false);
PlayHUDMotion(m_bFastAnimMode ? "anm_show_fast" : "anm_show", FALSE, this, GetState());
SetPending(TRUE);
break;
}
case eHiding:
{
if (oldState != eHiding)
{
m_sounds.PlaySound("sndHide", Fvector().set(0, 0, 0), this, true, false);
PlayHUDMotion(m_bFastAnimMode ? "anm_hide_fast" : "anm_hide", FALSE, this, GetState());
SetPending(TRUE);
}
break;
}
case eIdle:
{
PlayAnimIdle();
SetPending(FALSE);
break;
}
}
}
void CCustomDetector::OnAnimationEnd(u32 state)
{
inherited::OnAnimationEnd(state);
switch (state)
{
case eShowing:
{
SwitchState(eIdle);
} break;
case eHiding:
{
SwitchState(eHidden);
TurnDetectorInternal(false);
g_player_hud->detach_item(this);
} break;
}
}
void CCustomDetector::UpdateXForm()
{
CInventoryItem::UpdateXForm();
}
void CCustomDetector::OnActiveItem()
{
}
void CCustomDetector::OnHiddenItem()
{
}
CCustomDetector::CCustomDetector()
{
m_ui = nullptr;
m_bFastAnimMode = false;
m_bNeedActivation = false;
}
CCustomDetector::~CCustomDetector()
{
m_artefacts.destroy();
TurnDetectorInternal(false);
xr_delete(m_ui);
}
BOOL CCustomDetector::net_Spawn(CSE_Abstract* DC)
{
TurnDetectorInternal(false);
return (inherited::net_Spawn(DC));
}
void CCustomDetector::Load(LPCSTR section)
{
inherited::Load(section);
m_fAfDetectRadius = pSettings->r_float(section, "af_radius");
m_fAfVisRadius = pSettings->r_float(section, "af_vis_radius");
m_artefacts.load(section, "af");
m_sounds.LoadSound(section, "snd_draw", "sndShow");
m_sounds.LoadSound(section, "snd_holster", "sndHide");
}
void CCustomDetector::shedule_Update(u32 dt)
{
inherited::shedule_Update(dt);
if (IsWorking())
{
Position().set(H_Parent()->Position());
Fvector P;
P.set(H_Parent()->Position());
m_artefacts.feel_touch_update(P, m_fAfDetectRadius);
}
}
bool CCustomDetector::IsWorking()
{
return m_bWorking && H_Parent() && H_Parent() == Level().CurrentViewEntity();
}
void CCustomDetector::UpfateWork()
{
UpdateAf();
m_ui->update();
}
void CCustomDetector::UpdateVisibility()
{
//check visibility
attachable_hud_item* pAttachable = g_player_hud->attached_item(0);
if (pAttachable && HudItemData())
{
bool bClimb = ((Actor()->MovingState()&mcClimb) != 0);
if (bClimb)
{
HideDetector(true);
m_bNeedActivation = true;
}
else
{
CWeapon* wpn = smart_cast<CWeapon*>(pAttachable->m_parent_hud_item);
if (wpn)
{
u32 state = wpn->GetState();
if (wpn->IsZoomed() || state == CWeapon::eReload || state == CWeapon::eSwitch)
{
HideDetector(true);
m_bNeedActivation = true;
}
}
}
}
else if (m_bNeedActivation)
{
attachable_hud_item* i0 = g_player_hud->attached_item(0);
bool bClimb = ((Actor()->MovingState()&mcClimb) != 0);
if (!bClimb)
{
CHudItem* huditem = (i0) ? i0->m_parent_hud_item : nullptr;
bool bChecked = !huditem || CheckCompatibilityInt(huditem, nullptr);
if (bChecked)
ShowDetector(true);
}
}
}
void CCustomDetector::UpdateCL()
{
inherited::UpdateCL();
if (H_Parent() != Level().CurrentEntity()) return;
UpdateVisibility();
if (!IsWorking()) return;
UpfateWork();
}
void CCustomDetector::OnH_A_Chield()
{
inherited::OnH_A_Chield();
}
void CCustomDetector::OnH_B_Independent(bool just_before_destroy)
{
inherited::OnH_B_Independent(just_before_destroy);
m_artefacts.clear();
if (GetState() != eHidden)
{
// Detaching hud item and animation stop in OnH_A_Independent
TurnDetectorInternal(false);
SwitchState(eHidden);
}
}
void CCustomDetector::OnMoveToRuck(const SInvItemPlace& prev)
{
inherited::OnMoveToRuck(prev);
if (prev.type == eItemPlaceSlot)
{
SwitchState(eHidden);
g_player_hud->detach_item(this);
}
TurnDetectorInternal(false);
StopCurrentAnimWithoutCallback();
}
void CCustomDetector::OnMoveToSlot(const SInvItemPlace& prev)
{
inherited::OnMoveToSlot(prev);
}
void CCustomDetector::TurnDetectorInternal(bool b)
{
m_bWorking = b;
if (b && !m_ui)
{
CreateUI();
UpdateNightVisionMode(b);
}
}
#include "game_base.h"
void CCustomDetector::UpdateNightVisionMode(bool b_on)
{
}
BOOL CAfList::feel_touch_contact(CObject* O)
{
TypesMapIt it = m_TypesMap.find(O->cNameSect());
bool res = (it != m_TypesMap.end());
if (res)
{
CArtefact* pAf = smart_cast<CArtefact*>(O);
if (pAf->GetAfRank()>m_af_rank)
res = false;
}
return res;
}