1/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
2/* If you are missing that file, acquire a complete release at teeworlds.com. */
3#include "character.h"
4
5#include "laser.h"
6#include "projectile.h"
7
8#include <engine/shared/config.h>
9
10#include <generated/client_data.h>
11
12#include <game/collision.h>
13#include <game/mapitems.h>
14
15#include <limits>
16
17// Character, "physical" player's part
18
19void CCharacter::SetWeapon(int Weapon)
20{
21 if(Weapon == m_Core.m_ActiveWeapon)
22 return;
23
24 m_LastWeapon = m_Core.m_ActiveWeapon;
25 m_QueuedWeapon = -1;
26 SetActiveWeapon(Weapon);
27
28 GameWorld()->CreatePredictedSound(Pos: m_Pos, SoundId: SOUND_WEAPON_SWITCH, Id: GetCid());
29}
30
31void CCharacter::SetSolo(bool Solo)
32{
33 m_Core.m_Solo = Solo;
34 TeamsCore()->SetSolo(ClientId: GetCid(), Value: Solo);
35}
36
37void CCharacter::SetSuper(bool Super)
38{
39 m_Core.m_Super = Super;
40 if(m_Core.m_Super)
41 TeamsCore()->Team(ClientId: GetCid(), Team: TeamsCore()->TeamSuper());
42}
43
44bool CCharacter::IsGrounded()
45{
46 if(Collision()->IsOnGround(Pos: m_Pos, Size: GetProximityRadius()))
47 return true;
48
49 int MoveRestrictionsBelow = Collision()->GetMoveRestrictions(Pos: m_Pos + vec2(0, GetProximityRadius() / 2 + 4), Distance: 0.0f);
50 return (MoveRestrictionsBelow & CANTMOVE_DOWN) != 0;
51}
52
53void CCharacter::HandleJetpack()
54{
55 if(m_NumInputs < 2)
56 return;
57
58 if(m_Core.m_ActiveWeapon < 0)
59 return;
60
61 vec2 Direction = normalize(v: vec2(m_LatestInput.m_TargetX, m_LatestInput.m_TargetY));
62
63 bool FullAuto = false;
64 if(m_Core.m_ActiveWeapon == WEAPON_GRENADE || m_Core.m_ActiveWeapon == WEAPON_SHOTGUN || m_Core.m_ActiveWeapon == WEAPON_LASER)
65 FullAuto = true;
66 if(m_Core.m_Jetpack && m_Core.m_ActiveWeapon == WEAPON_GUN)
67 FullAuto = true;
68
69 // check if we gonna fire
70 bool WillFire = false;
71 if(CountInput(Prev: m_LatestPrevInput.m_Fire, Cur: m_LatestInput.m_Fire).m_Presses)
72 WillFire = true;
73
74 if(FullAuto && (m_LatestInput.m_Fire & 1) && m_Core.m_aWeapons[m_Core.m_ActiveWeapon].m_Ammo)
75 WillFire = true;
76
77 if(!WillFire)
78 return;
79
80 // check for ammo
81 if(!m_Core.m_aWeapons[m_Core.m_ActiveWeapon].m_Ammo || m_FreezeTime)
82 {
83 return;
84 }
85
86 switch(m_Core.m_ActiveWeapon)
87 {
88 case WEAPON_GUN:
89 {
90 if(m_Core.m_Jetpack)
91 {
92 float Strength = GetTuning(i: GetOverriddenTuneZone())->m_JetpackStrength;
93 TakeDamage(Force: Direction * -1.0f * (Strength / 100.0f / 6.11f), Dmg: 0, From: GetCid(), Weapon: m_Core.m_ActiveWeapon);
94 }
95 }
96 }
97}
98
99void CCharacter::RemoveNinja()
100{
101 m_Core.m_Ninja.m_CurrentMoveTime = 0;
102 m_Core.m_aWeapons[WEAPON_NINJA].m_Got = false;
103 m_Core.m_ActiveWeapon = m_LastWeapon;
104
105 SetWeapon(m_Core.m_ActiveWeapon);
106}
107
108void CCharacter::HandleNinja()
109{
110 if(m_Core.m_ActiveWeapon != WEAPON_NINJA)
111 return;
112
113 if((GameWorld()->GameTick() - m_Core.m_Ninja.m_ActivationTick) > (g_pData->m_Weapons.m_Ninja.m_Duration * GameWorld()->GameTickSpeed() / 1000))
114 {
115 // time's up, return
116 RemoveNinja();
117 return;
118 }
119
120 // force ninja Weapon
121 SetWeapon(WEAPON_NINJA);
122
123 m_Core.m_Ninja.m_CurrentMoveTime--;
124
125 if(m_Core.m_Ninja.m_CurrentMoveTime == 0)
126 {
127 // reset velocity
128 m_Core.m_Vel = m_Core.m_Ninja.m_ActivationDir * m_Core.m_Ninja.m_OldVelAmount;
129 }
130
131 if(m_Core.m_Ninja.m_CurrentMoveTime > 0)
132 {
133 // Set velocity
134 m_Core.m_Vel = m_Core.m_Ninja.m_ActivationDir * g_pData->m_Weapons.m_Ninja.m_Velocity;
135 vec2 OldPos = m_Pos;
136 Collision()->MoveBox(pInoutPos: &m_Core.m_Pos, pInoutVel: &m_Core.m_Vel, Size: vec2(m_ProximityRadius, m_ProximityRadius), Elasticity: vec2(GetTuning(i: GetOverriddenTuneZone())->m_GroundElasticityX, GetTuning(i: GetOverriddenTuneZone())->m_GroundElasticityY));
137
138 // reset velocity so the client doesn't predict stuff
139 m_Core.m_Vel = vec2(0.f, 0.f);
140
141 // check if we Hit anything along the way
142 {
143 CEntity *apEnts[MAX_CLIENTS];
144 float Radius = m_ProximityRadius * 2.0f;
145 int Num = GameWorld()->FindEntities(Pos: OldPos, Radius, ppEnts: apEnts, Max: MAX_CLIENTS, Type: CGameWorld::ENTTYPE_CHARACTER);
146
147 // check that we're not in solo part
148 if(TeamsCore()->GetSolo(ClientId: GetCid()))
149 return;
150
151 for(int i = 0; i < Num; ++i)
152 {
153 auto *pChr = static_cast<CCharacter *>(apEnts[i]);
154 if(pChr == this)
155 continue;
156
157 // Don't hit players in other teams
158 if(Team() != pChr->Team())
159 continue;
160
161 const int ClientId = pChr->GetCid();
162
163 // Don't hit players in solo parts
164 if(TeamsCore()->GetSolo(ClientId))
165 continue;
166
167 // make sure we haven't Hit this object before
168 bool AlreadyHit = false;
169 for(int j = 0; j < m_NumObjectsHit; j++)
170 {
171 if(m_aHitObjects[j] == ClientId)
172 AlreadyHit = true;
173 }
174 if(AlreadyHit)
175 continue;
176
177 // check so we are sufficiently close
178 if(distance(a: pChr->m_Pos, b: m_Pos) > Radius)
179 continue;
180
181 // Hit a player, give them damage and stuffs...
182 GameWorld()->CreatePredictedSound(Pos: pChr->m_Pos, SoundId: SOUND_NINJA_HIT, Id: GetCid());
183 // set their velocity to fast upward (for now)
184 dbg_assert(m_NumObjectsHit < MAX_CLIENTS, "m_aHitObjects overflow");
185 m_aHitObjects[m_NumObjectsHit++] = ClientId;
186
187 pChr->TakeDamage(Force: vec2(0, -10.0f), Dmg: g_pData->m_Weapons.m_Ninja.m_pBase->m_Damage, From: GetCid(), Weapon: WEAPON_NINJA);
188 }
189 }
190
191 return;
192 }
193}
194
195void CCharacter::DoWeaponSwitch()
196{
197 // make sure we can switch
198 if(m_ReloadTimer != 0 || m_QueuedWeapon == -1)
199 return;
200 if(m_Core.m_aWeapons[WEAPON_NINJA].m_Got || !m_Core.m_aWeapons[m_QueuedWeapon].m_Got)
201 return;
202
203 // switch Weapon
204 SetWeapon(m_QueuedWeapon);
205}
206
207void CCharacter::HandleWeaponSwitch()
208{
209 if(m_NumInputs < 2)
210 return;
211
212 int WantedWeapon = m_Core.m_ActiveWeapon;
213 if(m_QueuedWeapon != -1)
214 WantedWeapon = m_QueuedWeapon;
215
216 bool Anything = false;
217 for(int i = 0; i < NUM_WEAPONS - 1; ++i)
218 if(m_Core.m_aWeapons[i].m_Got)
219 Anything = true;
220 if(!Anything)
221 return;
222 // select Weapon
223 int Next = CountInput(Prev: m_LatestPrevInput.m_NextWeapon, Cur: m_LatestInput.m_NextWeapon).m_Presses;
224 int Prev = CountInput(Prev: m_LatestPrevInput.m_PrevWeapon, Cur: m_LatestInput.m_PrevWeapon).m_Presses;
225
226 if(Next < 128) // make sure we only try sane stuff
227 {
228 while(Next) // Next Weapon selection
229 {
230 WantedWeapon = (WantedWeapon + 1) % NUM_WEAPONS;
231 if(m_Core.m_aWeapons[WantedWeapon].m_Got)
232 Next--;
233 }
234 }
235
236 if(Prev < 128) // make sure we only try sane stuff
237 {
238 while(Prev) // Prev Weapon selection
239 {
240 WantedWeapon = (WantedWeapon - 1) < 0 ? NUM_WEAPONS - 1 : WantedWeapon - 1;
241 if(m_Core.m_aWeapons[WantedWeapon].m_Got)
242 Prev--;
243 }
244 }
245
246 // Direct Weapon selection
247 if(m_LatestInput.m_WantedWeapon)
248 WantedWeapon = m_Input.m_WantedWeapon - 1;
249
250 // check for insane values
251 if(WantedWeapon >= 0 && WantedWeapon < NUM_WEAPONS && WantedWeapon != m_Core.m_ActiveWeapon && m_Core.m_aWeapons[WantedWeapon].m_Got)
252 m_QueuedWeapon = WantedWeapon;
253
254 DoWeaponSwitch();
255}
256
257void CCharacter::FireWeapon()
258{
259 if(m_NumInputs < 2)
260 return;
261
262 if(!GameWorld()->m_WorldConfig.m_PredictWeapons)
263 return;
264
265 if(m_ReloadTimer != 0)
266 return;
267
268 DoWeaponSwitch();
269 vec2 Direction = normalize(v: vec2(m_LatestInput.m_TargetX, m_LatestInput.m_TargetY));
270
271 bool FullAuto = false;
272 if(m_Core.m_ActiveWeapon == WEAPON_GRENADE || m_Core.m_ActiveWeapon == WEAPON_SHOTGUN || m_Core.m_ActiveWeapon == WEAPON_LASER)
273 FullAuto = true;
274 if(m_Core.m_Jetpack && m_Core.m_ActiveWeapon == WEAPON_GUN)
275 FullAuto = true;
276 if(m_FrozenLastTick)
277 FullAuto = true;
278
279 // don't fire hammer when player is deep and sv_deepfly is disabled
280 if(!g_Config.m_SvDeepfly && m_Core.m_ActiveWeapon == WEAPON_HAMMER && m_Core.m_DeepFrozen)
281 return;
282
283 // check if we gonna fire
284 bool WillFire = false;
285 if(CountInput(Prev: m_LatestPrevInput.m_Fire, Cur: m_LatestInput.m_Fire).m_Presses)
286 WillFire = true;
287
288 if(FullAuto && (m_LatestInput.m_Fire & 1) && m_Core.m_ActiveWeapon >= 0 && m_Core.m_aWeapons[m_Core.m_ActiveWeapon].m_Ammo)
289 WillFire = true;
290
291 if(!WillFire)
292 return;
293
294 if(m_FreezeTime)
295 {
296 // Timer stuff to avoid shrieking orchestra caused by unfreeze-plasma
297 if(m_PainSoundTimer <= 0 && !(m_LatestPrevInput.m_Fire & 1))
298 {
299 m_PainSoundTimer = 1 * GameWorld()->GameTickSpeed();
300 GameWorld()->CreatePredictedSound(Pos: m_Pos, SoundId: SOUND_PLAYER_PAIN_LONG, Id: GetCid());
301 }
302 return;
303 }
304
305 // check for ammo
306 if(m_Core.m_ActiveWeapon < 0 || !m_Core.m_aWeapons[m_Core.m_ActiveWeapon].m_Ammo || m_FreezeTime)
307 {
308 return;
309 }
310
311 vec2 ProjStartPos = m_Pos + Direction * m_ProximityRadius * 0.75f;
312
313 switch(m_Core.m_ActiveWeapon)
314 {
315 case WEAPON_HAMMER:
316 {
317 if(m_Core.m_HammerHitDisabled)
318 break;
319
320 GameWorld()->CreatePredictedSound(Pos: m_Pos, SoundId: SOUND_HAMMER_FIRE, Id: GetCid());
321
322 CEntity *apEnts[MAX_CLIENTS];
323 int Hits = 0;
324 int Num = GameWorld()->FindEntities(Pos: ProjStartPos, Radius: m_ProximityRadius * 0.5f, ppEnts: apEnts,
325 Max: MAX_CLIENTS, Type: CGameWorld::ENTTYPE_CHARACTER);
326
327 for(int i = 0; i < Num; ++i)
328 {
329 auto *pTarget = static_cast<CCharacter *>(apEnts[i]);
330
331 if((pTarget == this || !CanCollide(ClientId: pTarget->GetCid())))
332 continue;
333
334 // set their velocity to fast upward (for now)
335 if(length(a: pTarget->m_Pos - ProjStartPos) > 0.0f)
336 GameWorld()->CreatePredictedHammerHitEvent(Pos: pTarget->m_Pos - normalize(v: pTarget->m_Pos - ProjStartPos) * GetProximityRadius() * 0.5f, Id: GetCid());
337 else
338 GameWorld()->CreatePredictedHammerHitEvent(Pos: ProjStartPos, Id: GetCid());
339
340 vec2 Dir;
341 if(length(a: pTarget->m_Pos - m_Pos) > 0.0f)
342 Dir = normalize(v: pTarget->m_Pos - m_Pos);
343 else
344 Dir = vec2(0.f, -1.f);
345
346 float Strength = GetTuning(i: GetOverriddenTuneZone())->m_HammerStrength;
347
348 vec2 Temp = pTarget->m_Core.m_Vel + normalize(v: Dir + vec2(0.f, -1.1f)) * 10.0f;
349 Temp = ClampVel(MoveRestriction: pTarget->m_MoveRestrictions, Vel: Temp);
350 Temp -= pTarget->m_Core.m_Vel;
351
352 vec2 Force = vec2(0.f, -1.0f) + Temp;
353
354 if(GameWorld()->m_WorldConfig.m_IsFNG)
355 {
356 if(m_GameTeam == pTarget->m_GameTeam && pTarget->m_LastSnapWeapon == WEAPON_NINJA) // melt hammer
357 {
358 Force.x *= 50 * 0.01f;
359 Force.y *= 50 * 0.01f;
360 }
361 else
362 {
363 Force.x *= 320 * 0.01f;
364 Force.y *= 120 * 0.01f;
365 }
366 }
367 else
368 {
369 Force *= Strength;
370 }
371
372 pTarget->TakeDamage(Force, Dmg: g_pData->m_Weapons.m_Hammer.m_pBase->m_Damage,
373 From: GetCid(), Weapon: m_Core.m_ActiveWeapon);
374 pTarget->Unfreeze();
375
376 Hits++;
377
378 AntiPingInterference(ClientId: pTarget->GetCid());
379 }
380
381 // if we Hit anything, we have to wait for the reload
382 if(Hits)
383 {
384 float FireDelay = GetTuning(i: GetOverriddenTuneZone())->m_HammerHitFireDelay;
385 m_ReloadTimer = FireDelay * GameWorld()->GameTickSpeed() / 1000;
386 }
387 }
388 break;
389
390 case WEAPON_GUN:
391 {
392 if(!m_Core.m_Jetpack)
393 {
394 int Lifetime = (int)(GameWorld()->GameTickSpeed() * GetTuning(i: GetOverriddenTuneZone())->m_GunLifetime);
395
396 new CProjectile(
397 GameWorld(),
398 WEAPON_GUN, //Type
399 GetCid(), //Owner
400 ProjStartPos, //Pos
401 Direction, //Dir
402 Lifetime, //Span
403 false, //Freeze
404 false, //Explosive
405 0, //Force
406 -1 //SoundImpact
407 );
408
409 GameWorld()->CreatePredictedSound(Pos: m_Pos, SoundId: SOUND_GUN_FIRE, Id: GetCid()); // NOLINT(clang-analyzer-unix.Malloc)
410 }
411 }
412 break;
413
414 case WEAPON_SHOTGUN:
415 {
416 if(GameWorld()->m_WorldConfig.m_IsVanilla)
417 {
418 int ShotSpread = 2;
419 for(int i = -ShotSpread; i <= ShotSpread; ++i)
420 {
421 const float aSpreading[] = {-0.185f, -0.070f, 0, 0.070f, 0.185f};
422 float a = angle(a: Direction);
423 a += aSpreading[i + 2];
424 float v = 1 - (absolute(a: i) / (float)ShotSpread);
425 float Speed = mix(a: (float)GlobalTuning()->m_ShotgunSpeeddiff, b: 1.0f, amount: v);
426 new CProjectile(
427 GameWorld(),
428 WEAPON_SHOTGUN, //Type
429 GetCid(), //Owner
430 ProjStartPos, //Pos
431 direction(angle: a) * Speed, //Dir
432 (int)(GameWorld()->GameTickSpeed() * GlobalTuning()->m_ShotgunLifetime), //Span
433 false, //Freeze
434 false, //Explosive
435 -1 //SoundImpact
436 );
437 }
438 }
439 else if(GameWorld()->m_WorldConfig.m_IsDDRace)
440 {
441 float LaserReach = GetTuning(i: GetOverriddenTuneZone())->m_LaserReach;
442
443 new CLaser(GameWorld(), m_Pos, Direction, LaserReach, GetCid(), WEAPON_SHOTGUN);
444 }
445
446 GameWorld()->CreatePredictedSound(Pos: m_Pos, SoundId: SOUND_SHOTGUN_FIRE, Id: GetCid());
447 }
448 break;
449
450 case WEAPON_GRENADE:
451 {
452 int Lifetime = (int)(GameWorld()->GameTickSpeed() * GetTuning(i: GetOverriddenTuneZone())->m_GrenadeLifetime);
453
454 new CProjectile(
455 GameWorld(),
456 WEAPON_GRENADE, //Type
457 GetCid(), //Owner
458 ProjStartPos, //Pos
459 Direction, //Dir
460 Lifetime, //Span
461 false, //Freeze
462 true, //Explosive
463 SOUND_GRENADE_EXPLODE //SoundImpact
464 ); //SoundImpact
465
466 GameWorld()->CreatePredictedSound(Pos: m_Pos, SoundId: SOUND_GRENADE_FIRE, Id: GetCid());
467 }
468 break;
469
470 case WEAPON_LASER:
471 {
472 float LaserReach = GetTuning(i: GetOverriddenTuneZone())->m_LaserReach;
473
474 new CLaser(GameWorld(), m_Pos, Direction, LaserReach, GetCid(), WEAPON_LASER);
475 GameWorld()->CreatePredictedSound(Pos: m_Pos, SoundId: SOUND_LASER_FIRE, Id: GetCid());
476 }
477 break;
478
479 case WEAPON_NINJA:
480 {
481 // reset Hit objects
482 m_NumObjectsHit = 0;
483
484 m_Core.m_Ninja.m_ActivationDir = Direction;
485 m_Core.m_Ninja.m_CurrentMoveTime = g_pData->m_Weapons.m_Ninja.m_Movetime * GameWorld()->GameTickSpeed() / 1000;
486
487 // clamp to prevent massive MoveBox calculation lag with SG bug
488 m_Core.m_Ninja.m_OldVelAmount = std::clamp(val: length(a: m_Core.m_Vel), lo: 0.0f, hi: 6000.0f);
489
490 GameWorld()->CreatePredictedSound(Pos: m_Pos, SoundId: SOUND_NINJA_FIRE, Id: GetCid());
491 }
492 break;
493 }
494
495 m_AttackTick = GameWorld()->GameTick(); // NOLINT(clang-analyzer-unix.Malloc)
496
497 // -1 is no weapon, handled here so pain sound still plays when firing in freeze
498 if(!m_ReloadTimer && m_Core.m_ActiveWeapon != -1)
499 {
500 m_ReloadTimer = GetTuning(i: GetOverriddenTuneZone())->GetWeaponFireDelay(Weapon: m_Core.m_ActiveWeapon) * GameWorld()->GameTickSpeed();
501 }
502}
503
504void CCharacter::HandleWeapons()
505{
506 //ninja
507 HandleNinja();
508 HandleJetpack();
509
510 if(m_PainSoundTimer > 0)
511 m_PainSoundTimer--;
512
513 // check reload timer
514 if(m_ReloadTimer)
515 {
516 m_ReloadTimer--;
517 return;
518 }
519
520 // fire Weapon, if wanted
521 FireWeapon();
522}
523
524void CCharacter::GiveNinja()
525{
526 m_Core.m_Ninja.m_ActivationTick = GameWorld()->GameTick();
527 m_Core.m_aWeapons[WEAPON_NINJA].m_Got = true;
528 if(m_FreezeTime == 0)
529 m_Core.m_aWeapons[WEAPON_NINJA].m_Ammo = -1;
530 if(m_Core.m_ActiveWeapon != WEAPON_NINJA)
531 m_LastWeapon = m_Core.m_ActiveWeapon;
532 SetActiveWeapon(WEAPON_NINJA);
533
534 if(GameWorld()->m_WorldConfig.m_IsVanilla)
535 GameWorld()->CreatePredictedSound(Pos: m_Pos, SoundId: SOUND_PICKUP_NINJA, Id: GetCid());
536}
537
538void CCharacter::OnPredictedInput(const CNetObj_PlayerInput *pNewInput)
539{
540 // skip the input if chat is active
541 if(!GameWorld()->m_WorldConfig.m_BugDDRaceInput && pNewInput->m_PlayerFlags & PLAYERFLAG_CHATTING)
542 {
543 // save the reset input
544 mem_copy(dest: &m_SavedInput, source: &m_Input, size: sizeof(m_SavedInput));
545 return;
546 }
547
548 // copy new input
549 const int PrevTargetX = m_Input.m_TargetX;
550 const int PrevTargetY = m_Input.m_TargetY;
551 mem_copy(dest: &m_Input, source: pNewInput, size: sizeof(m_Input));
552
553 // reset target due to spectator mode input not being in aim space
554 if(pNewInput->m_PlayerFlags & PLAYERFLAG_SPEC_CAM)
555 {
556 m_Input.m_TargetX = PrevTargetX;
557 m_Input.m_TargetY = PrevTargetY;
558 }
559
560 // it is not allowed to aim in the center
561 if(m_Input.m_TargetX == 0 && m_Input.m_TargetY == 0)
562 m_Input.m_TargetY = -1;
563
564 mem_copy(dest: &m_SavedInput, source: &m_Input, size: sizeof(m_SavedInput));
565}
566
567void CCharacter::OnDirectInput(const CNetObj_PlayerInput *pNewInput)
568{
569 // skip the input if chat is active
570 if(!GameWorld()->m_WorldConfig.m_BugDDRaceInput && pNewInput->m_PlayerFlags & PLAYERFLAG_CHATTING)
571 {
572 // reset input
573 ResetInput();
574 // mods that do not allow inputs to be held while chatting also do not allow to hold hook
575 m_Input.m_Hook = 0;
576 return;
577 }
578
579 m_NumInputs++;
580 mem_copy(dest: &m_LatestPrevInput, source: &m_LatestInput, size: sizeof(m_LatestInput));
581 mem_copy(dest: &m_LatestInput, source: pNewInput, size: sizeof(m_LatestInput));
582
583 // reset target due to spectator mode input not being in aim space
584 if(pNewInput->m_PlayerFlags & PLAYERFLAG_SPEC_CAM)
585 {
586 m_LatestInput.m_TargetX = m_LatestPrevInput.m_TargetX;
587 m_LatestInput.m_TargetY = m_LatestPrevInput.m_TargetY;
588 }
589
590 // it is not allowed to aim in the center
591 if(m_LatestInput.m_TargetX == 0 && m_LatestInput.m_TargetY == 0)
592 m_LatestInput.m_TargetY = -1;
593
594 if(m_NumInputs > 1 && Team() != TEAM_SPECTATORS)
595 {
596 HandleWeaponSwitch();
597 FireWeapon();
598 }
599
600 mem_copy(dest: &m_LatestPrevInput, source: &m_LatestInput, size: sizeof(m_LatestInput));
601}
602
603void CCharacter::ReleaseHook()
604{
605 m_Core.SetHookedPlayer(-1);
606 m_Core.m_HookState = HOOK_RETRACTED;
607 m_Core.m_TriggeredEvents |= COREEVENT_HOOK_RETRACT;
608}
609
610void CCharacter::ResetHook()
611{
612 ReleaseHook();
613 m_Core.m_HookPos = m_Core.m_Pos;
614}
615
616void CCharacter::ResetInput()
617{
618 m_Input.m_Direction = 0;
619 // m_Input.m_Hook = 0;
620 // simulate releasing the fire button
621 if((m_Input.m_Fire & 1) != 0)
622 m_Input.m_Fire++;
623 m_Input.m_Fire &= INPUT_STATE_MASK;
624 m_Input.m_Jump = 0;
625 m_LatestPrevInput = m_LatestInput = m_Input;
626}
627
628void CCharacter::PreTick()
629{
630 DDRaceTick();
631
632 m_Core.m_Input = m_Input;
633 m_Core.Tick(UseInput: true, DoDeferredTick: !m_pGameWorld->m_WorldConfig.m_NoWeakHookAndBounce);
634}
635
636void CCharacter::Tick()
637{
638 if(m_pGameWorld->m_WorldConfig.m_NoWeakHookAndBounce)
639 {
640 m_Core.TickDeferred();
641 }
642 else
643 {
644 PreTick();
645 }
646
647 // handle Weapons
648 HandleWeapons();
649
650 DDRacePostCoreTick();
651
652 // antiping
653 if(IsInterfering())
654 {
655 // Disable dynamic interaction based antiping when player moved or hooked a wall
656 if((!m_FreezeTime || g_Config.m_ClAntiPingPlayers != 3) &&
657 (m_Input.m_Direction != m_PrevInput.m_Direction || m_Input.m_Jump != m_PrevInput.m_Jump || m_Core.m_TriggeredEvents & COREEVENT_HOOK_ATTACH_GROUND))
658 {
659 m_Interfering = false;
660 }
661 }
662
663 // Previnput
664 m_PrevInput = m_Input;
665
666 m_PrevPrevPos = m_PrevPos;
667 m_PrevPos = m_Core.m_Pos;
668}
669
670void CCharacter::TickDeferred()
671{
672 m_Core.Move();
673 m_Core.Quantize();
674 m_Pos = m_Core.m_Pos;
675}
676
677bool CCharacter::TakeDamage(vec2 Force, int Dmg, int From, int Weapon)
678{
679 vec2 Temp = m_Core.m_Vel + Force;
680 m_Core.m_Vel = ClampVel(MoveRestriction: m_MoveRestrictions, Vel: Temp);
681 return true;
682}
683
684// DDRace
685
686bool CCharacter::CanCollide(int ClientId)
687{
688 return TeamsCore()->CanCollide(ClientId1: GetCid(), ClientId2: ClientId);
689}
690
691bool CCharacter::SameTeam(int ClientId)
692{
693 return TeamsCore()->SameTeam(ClientId1: GetCid(), ClientId2: ClientId);
694}
695
696int CCharacter::Team()
697{
698 return TeamsCore()->Team(ClientId: GetCid());
699}
700
701void CCharacter::HandleSkippableTiles(int Index)
702{
703 if(Index < 0)
704 return;
705
706 // handle speedup tiles
707 if(Collision()->IsSpeedup(Index))
708 {
709 vec2 Direction, TempVel = m_Core.m_Vel;
710 int Force, Type, MaxSpeed = 0;
711 Collision()->GetSpeedup(Index, pDir: &Direction, pForce: &Force, pMaxSpeed: &MaxSpeed, pType: &Type);
712
713 if(Type == TILE_SPEED_BOOST_OLD)
714 {
715 float TeeAngle, SpeederAngle, DiffAngle, SpeedLeft, TeeSpeed;
716 if(Force == 255 && MaxSpeed)
717 {
718 m_Core.m_Vel = Direction * (MaxSpeed / 5);
719 }
720 else
721 {
722 if(MaxSpeed > 0 && MaxSpeed < 5)
723 MaxSpeed = 5;
724 if(MaxSpeed > 0)
725 {
726 if(Direction.x > 0.0000001f)
727 SpeederAngle = -std::atan(x: Direction.y / Direction.x);
728 else if(Direction.x < 0.0000001f)
729 SpeederAngle = std::atan(x: Direction.y / Direction.x) + 2.0f * std::asin(x: 1.0f);
730 else if(Direction.y > 0.0000001f)
731 SpeederAngle = std::asin(x: 1.0f);
732 else
733 SpeederAngle = std::asin(x: -1.0f);
734
735 if(SpeederAngle < 0)
736 SpeederAngle = 4.0f * std::asin(x: 1.0f) + SpeederAngle;
737
738 if(TempVel.x > 0.0000001f)
739 TeeAngle = -std::atan(x: TempVel.y / TempVel.x);
740 else if(TempVel.x < 0.0000001f)
741 TeeAngle = std::atan(x: TempVel.y / TempVel.x) + 2.0f * std::asin(x: 1.0f);
742 else if(TempVel.y > 0.0000001f)
743 TeeAngle = std::asin(x: 1.0f);
744 else
745 TeeAngle = std::asin(x: -1.0f);
746
747 if(TeeAngle < 0)
748 TeeAngle = 4.0f * std::asin(x: 1.0f) + TeeAngle;
749
750 TeeSpeed = std::sqrt(x: std::pow(x: TempVel.x, y: 2) + std::pow(x: TempVel.y, y: 2));
751
752 DiffAngle = SpeederAngle - TeeAngle;
753 SpeedLeft = MaxSpeed / 5.0f - std::cos(x: DiffAngle) * TeeSpeed;
754 // A tee at rest takes its angle from atan(0/0), leaving SpeedLeft NaN, which
755 // converts to INT_MIN. That has no absolute value, so it does not exceed.
756 const int SpeedLeftInt = round_truncate(f: SpeedLeft);
757 const bool Exceeds = SpeedLeftInt != std::numeric_limits<int>::min() && absolute(a: SpeedLeftInt) > Force;
758 if(Exceeds && SpeedLeft > 0.0000001f)
759 TempVel += Direction * Force;
760 else if(Exceeds)
761 TempVel += Direction * -Force;
762 else
763 TempVel += Direction * SpeedLeft;
764 }
765 else
766 {
767 TempVel += Direction * Force;
768 }
769
770 m_Core.m_Vel = ClampVel(MoveRestriction: m_MoveRestrictions, Vel: TempVel);
771 }
772 }
773 else if(Type == TILE_SPEED_BOOST)
774 {
775 constexpr float MaxSpeedScale = 5.0f;
776 if(MaxSpeed == 0)
777 {
778 float MaxRampSpeed = GetTuning(i: GetOverriddenTuneZone())->m_VelrampRange / (50 * log(x: std::max(a: (float)GetTuning(i: GetOverriddenTuneZone())->m_VelrampCurvature, b: 1.01f)));
779 MaxSpeed = std::max(a: MaxRampSpeed, b: GetTuning(i: GetOverriddenTuneZone())->m_VelrampStart / 50) * MaxSpeedScale;
780 }
781
782 // (signed) length of projection
783 float CurrentDirectionalSpeed = dot(a: Direction, b: m_Core.m_Vel);
784 float TempMaxSpeed = MaxSpeed / MaxSpeedScale;
785 if(CurrentDirectionalSpeed + Force > TempMaxSpeed)
786 TempVel += Direction * (TempMaxSpeed - CurrentDirectionalSpeed);
787 else
788 TempVel += Direction * Force;
789 m_Core.m_Vel = ClampVel(MoveRestriction: m_MoveRestrictions, Vel: TempVel);
790 }
791 }
792}
793
794bool CCharacter::IsSwitchActiveCb(unsigned char Number, void *pUser)
795{
796 CCharacter *pThis = (CCharacter *)pUser;
797 auto &aSwitchers = pThis->Switchers();
798 return !aSwitchers.empty() && pThis->Team() != pThis->TeamsCore()->TeamSuper() && aSwitchers[Number].m_aStatus[pThis->Team()];
799}
800
801void CCharacter::HandleTiles(int Index)
802{
803 int MapIndex = Index;
804 m_TileIndex = Collision()->GetTileIndex(Index: MapIndex);
805 m_TileFIndex = Collision()->GetFrontTileIndex(Index: MapIndex);
806 m_MoveRestrictions = Collision()->GetMoveRestrictions(pfnSwitchActive: IsSwitchActiveCb, pUser: this, Pos: m_Pos, Distance: 18.0f, OverrideCenterTileIndex: MapIndex);
807
808 if(!GameWorld()->m_WorldConfig.m_PredictTiles)
809 return;
810
811 if(Index < 0)
812 {
813 m_LastRefillJumps = false;
814 return;
815 }
816
817 int TeleCheckpoint = Collision()->IsTeleCheckpoint(Index: MapIndex);
818 if(TeleCheckpoint)
819 m_TeleCheckpoint = TeleCheckpoint;
820
821 // freeze
822 if(((m_TileIndex == TILE_FREEZE) || (m_TileFIndex == TILE_FREEZE)) && !m_Core.m_Super && !m_Core.m_Invincible && !m_Core.m_DeepFrozen)
823 {
824 Freeze();
825 }
826 else if(((m_TileIndex == TILE_UNFREEZE) || (m_TileFIndex == TILE_UNFREEZE)) && !m_Core.m_DeepFrozen)
827 {
828 Unfreeze();
829 }
830
831 // deep freeze
832 if(((m_TileIndex == TILE_DFREEZE) || (m_TileFIndex == TILE_DFREEZE)) && !m_Core.m_Super && !m_Core.m_Invincible && !m_Core.m_DeepFrozen)
833 {
834 m_Core.m_DeepFrozen = true;
835 }
836 else if(((m_TileIndex == TILE_DUNFREEZE) || (m_TileFIndex == TILE_DUNFREEZE)) && !m_Core.m_Super && !m_Core.m_Invincible && m_Core.m_DeepFrozen)
837 {
838 m_Core.m_DeepFrozen = false;
839 }
840
841 // live freeze
842 if(((m_TileIndex == TILE_LFREEZE) || (m_TileFIndex == TILE_LFREEZE)) && !m_Core.m_Super && !m_Core.m_Invincible)
843 {
844 m_Core.m_LiveFrozen = true;
845 }
846 else if(((m_TileIndex == TILE_LUNFREEZE) || (m_TileFIndex == TILE_LUNFREEZE)) && !m_Core.m_Super && !m_Core.m_Invincible)
847 {
848 m_Core.m_LiveFrozen = false;
849 }
850
851 // endless hook
852 if(((m_TileIndex == TILE_EHOOK_ENABLE) || (m_TileFIndex == TILE_EHOOK_ENABLE)) && !m_Core.m_EndlessHook)
853 {
854 m_Core.m_EndlessHook = true;
855 }
856 else if(((m_TileIndex == TILE_EHOOK_DISABLE) || (m_TileFIndex == TILE_EHOOK_DISABLE)) && m_Core.m_EndlessHook)
857 {
858 m_Core.m_EndlessHook = false;
859 }
860
861 // hit others
862 if(((m_TileIndex == TILE_HIT_DISABLE) || (m_TileFIndex == TILE_HIT_DISABLE)) && (!m_Core.m_HammerHitDisabled || !m_Core.m_ShotgunHitDisabled || !m_Core.m_GrenadeHitDisabled || !m_Core.m_LaserHitDisabled))
863 {
864 m_Core.m_HammerHitDisabled = true;
865 m_Core.m_ShotgunHitDisabled = true;
866 m_Core.m_GrenadeHitDisabled = true;
867 m_Core.m_LaserHitDisabled = true;
868 }
869 else if(((m_TileIndex == TILE_HIT_ENABLE) || (m_TileFIndex == TILE_HIT_ENABLE)) && (m_Core.m_HammerHitDisabled || m_Core.m_ShotgunHitDisabled || m_Core.m_GrenadeHitDisabled || m_Core.m_LaserHitDisabled))
870 {
871 m_Core.m_ShotgunHitDisabled = false;
872 m_Core.m_GrenadeHitDisabled = false;
873 m_Core.m_HammerHitDisabled = false;
874 m_Core.m_LaserHitDisabled = false;
875 }
876
877 // collide with others
878 if(((m_TileIndex == TILE_NPC_DISABLE) || (m_TileFIndex == TILE_NPC_DISABLE)) && !m_Core.m_CollisionDisabled)
879 {
880 m_Core.m_CollisionDisabled = true;
881 }
882 else if(((m_TileIndex == TILE_NPC_ENABLE) || (m_TileFIndex == TILE_NPC_ENABLE)) && m_Core.m_CollisionDisabled)
883 {
884 m_Core.m_CollisionDisabled = false;
885 }
886
887 // hook others
888 if(((m_TileIndex == TILE_NPH_DISABLE) || (m_TileFIndex == TILE_NPH_DISABLE)) && !m_Core.m_HookHitDisabled)
889 {
890 m_Core.m_HookHitDisabled = true;
891 }
892 else if(((m_TileIndex == TILE_NPH_ENABLE) || (m_TileFIndex == TILE_NPH_ENABLE)) && m_Core.m_HookHitDisabled)
893 {
894 m_Core.m_HookHitDisabled = false;
895 }
896
897 // unlimited air jumps
898 if(((m_TileIndex == TILE_UNLIMITED_JUMPS_ENABLE) || (m_TileFIndex == TILE_UNLIMITED_JUMPS_ENABLE)) && !m_Core.m_EndlessJump)
899 {
900 m_Core.m_EndlessJump = true;
901 }
902 else if(((m_TileIndex == TILE_UNLIMITED_JUMPS_DISABLE) || (m_TileFIndex == TILE_UNLIMITED_JUMPS_DISABLE)) && m_Core.m_EndlessJump)
903 {
904 m_Core.m_EndlessJump = false;
905 }
906
907 // walljump
908 if((m_TileIndex == TILE_WALLJUMP) || (m_TileFIndex == TILE_WALLJUMP))
909 {
910 if(m_Core.m_Vel.y > 0 && m_Core.m_Colliding && m_Core.m_LeftWall)
911 {
912 m_Core.m_LeftWall = false;
913 m_Core.m_JumpedTotal = m_Core.m_Jumps >= 2 ? m_Core.m_Jumps - 2 : 0;
914 m_Core.m_Jumped = 1;
915 }
916 }
917
918 // jetpack gun
919 if(((m_TileIndex == TILE_JETPACK_ENABLE) || (m_TileFIndex == TILE_JETPACK_ENABLE)) && !m_Core.m_Jetpack)
920 {
921 m_Core.m_Jetpack = true;
922 }
923 else if(((m_TileIndex == TILE_JETPACK_DISABLE) || (m_TileFIndex == TILE_JETPACK_DISABLE)) && m_Core.m_Jetpack)
924 {
925 m_Core.m_Jetpack = false;
926 }
927
928 // solo part
929 if(((m_TileIndex == TILE_SOLO_ENABLE) || (m_TileFIndex == TILE_SOLO_ENABLE)) && !TeamsCore()->GetSolo(ClientId: GetCid()))
930 {
931 SetSolo(true);
932 }
933 else if(((m_TileIndex == TILE_SOLO_DISABLE) || (m_TileFIndex == TILE_SOLO_DISABLE)) && TeamsCore()->GetSolo(ClientId: GetCid()))
934 {
935 SetSolo(false);
936 }
937
938 // refill jumps
939 if(((m_TileIndex == TILE_REFILL_JUMPS) || (m_TileFIndex == TILE_REFILL_JUMPS)) && !m_LastRefillJumps)
940 {
941 m_Core.m_JumpedTotal = 0;
942 m_Core.m_Jumped = 0;
943 m_LastRefillJumps = true;
944 }
945 if((m_TileIndex != TILE_REFILL_JUMPS) && (m_TileFIndex != TILE_REFILL_JUMPS))
946 {
947 m_LastRefillJumps = false;
948 }
949
950 // Teleport gun
951 if(((m_TileIndex == TILE_TELE_GUN_ENABLE) || (m_TileFIndex == TILE_TELE_GUN_ENABLE)) && !m_Core.m_HasTelegunGun)
952 {
953 m_Core.m_HasTelegunGun = true;
954 }
955 else if(((m_TileIndex == TILE_TELE_GUN_DISABLE) || (m_TileFIndex == TILE_TELE_GUN_DISABLE)) && m_Core.m_HasTelegunGun)
956 {
957 m_Core.m_HasTelegunGun = false;
958 }
959
960 if(((m_TileIndex == TILE_TELE_GRENADE_ENABLE) || (m_TileFIndex == TILE_TELE_GRENADE_ENABLE)) && !m_Core.m_HasTelegunGrenade)
961 {
962 m_Core.m_HasTelegunGrenade = true;
963 }
964 else if(((m_TileIndex == TILE_TELE_GRENADE_DISABLE) || (m_TileFIndex == TILE_TELE_GRENADE_DISABLE)) && m_Core.m_HasTelegunGrenade)
965 {
966 m_Core.m_HasTelegunGrenade = false;
967 }
968
969 if(((m_TileIndex == TILE_TELE_LASER_ENABLE) || (m_TileFIndex == TILE_TELE_LASER_ENABLE)) && !m_Core.m_HasTelegunLaser)
970 {
971 m_Core.m_HasTelegunLaser = true;
972 }
973 else if(((m_TileIndex == TILE_TELE_LASER_DISABLE) || (m_TileFIndex == TILE_TELE_LASER_DISABLE)) && m_Core.m_HasTelegunLaser)
974 {
975 m_Core.m_HasTelegunLaser = false;
976 }
977
978 // stopper
979 if(m_Core.m_Vel.y > 0 && (m_MoveRestrictions & CANTMOVE_DOWN))
980 {
981 m_Core.m_Jumped = 0;
982 m_Core.m_JumpedTotal = 0;
983 }
984 m_Core.m_Vel = ClampVel(MoveRestriction: m_MoveRestrictions, Vel: m_Core.m_Vel);
985
986 // handle switch tiles
987 const int SwitchType = Collision()->GetSwitchType(Index: MapIndex);
988 const int SwitchNumber = Collision()->GetSwitchNumber(Index: MapIndex);
989 const int SwitchDelay = Collision()->GetSwitchDelay(Index: MapIndex);
990 if(SwitchType == TILE_SWITCHOPEN && Team() != TeamsCore()->TeamSuper() && SwitchNumber > 0)
991 {
992 Switchers()[SwitchNumber].m_aStatus[Team()] = true;
993 Switchers()[SwitchNumber].m_aEndTick[Team()] = 0;
994 Switchers()[SwitchNumber].m_aType[Team()] = TILE_SWITCHOPEN;
995 Switchers()[SwitchNumber].m_aLastUpdateTick[Team()] = GameWorld()->GameTick();
996 }
997 else if(SwitchType == TILE_SWITCHTIMEDOPEN && Team() != TeamsCore()->TeamSuper() && SwitchNumber > 0)
998 {
999 Switchers()[SwitchNumber].m_aStatus[Team()] = true;
1000 Switchers()[SwitchNumber].m_aEndTick[Team()] = GameWorld()->GameTick() + 1 + SwitchDelay * GameWorld()->GameTickSpeed();
1001 Switchers()[SwitchNumber].m_aType[Team()] = TILE_SWITCHTIMEDOPEN;
1002 Switchers()[SwitchNumber].m_aLastUpdateTick[Team()] = GameWorld()->GameTick();
1003 }
1004 else if(SwitchType == TILE_SWITCHTIMEDCLOSE && Team() != TeamsCore()->TeamSuper() && SwitchNumber > 0)
1005 {
1006 Switchers()[SwitchNumber].m_aStatus[Team()] = false;
1007 Switchers()[SwitchNumber].m_aEndTick[Team()] = GameWorld()->GameTick() + 1 + SwitchDelay * GameWorld()->GameTickSpeed();
1008 Switchers()[SwitchNumber].m_aType[Team()] = TILE_SWITCHTIMEDCLOSE;
1009 Switchers()[SwitchNumber].m_aLastUpdateTick[Team()] = GameWorld()->GameTick();
1010 }
1011 else if(SwitchType == TILE_SWITCHCLOSE && Team() != TeamsCore()->TeamSuper() && SwitchNumber > 0)
1012 {
1013 Switchers()[SwitchNumber].m_aStatus[Team()] = false;
1014 Switchers()[SwitchNumber].m_aEndTick[Team()] = 0;
1015 Switchers()[SwitchNumber].m_aType[Team()] = TILE_SWITCHCLOSE;
1016 Switchers()[SwitchNumber].m_aLastUpdateTick[Team()] = GameWorld()->GameTick();
1017 }
1018 else if(SwitchType == TILE_FREEZE && Team() != TeamsCore()->TeamSuper() && !m_Core.m_Invincible)
1019 {
1020 if(SwitchNumber == 0 || Switchers()[SwitchNumber].m_aStatus[Team()])
1021 {
1022 Freeze(Seconds: SwitchDelay);
1023 }
1024 }
1025 else if(SwitchType == TILE_DFREEZE && Team() != TeamsCore()->TeamSuper() && !m_Core.m_Invincible)
1026 {
1027 if(SwitchNumber == 0 || Switchers()[SwitchNumber].m_aStatus[Team()])
1028 m_Core.m_DeepFrozen = true;
1029 }
1030 else if(SwitchType == TILE_DUNFREEZE && Team() != TeamsCore()->TeamSuper() && !m_Core.m_Invincible)
1031 {
1032 if(SwitchNumber == 0 || Switchers()[SwitchNumber].m_aStatus[Team()])
1033 m_Core.m_DeepFrozen = false;
1034 }
1035 else if(SwitchType == TILE_LFREEZE && Team() != TeamsCore()->TeamSuper() && !m_Core.m_Invincible)
1036 {
1037 if(SwitchNumber == 0 || Switchers()[SwitchNumber].m_aStatus[Team()])
1038 {
1039 m_Core.m_LiveFrozen = true;
1040 }
1041 }
1042 else if(SwitchType == TILE_LUNFREEZE && Team() != TeamsCore()->TeamSuper() && !m_Core.m_Invincible)
1043 {
1044 if(SwitchNumber == 0 || Switchers()[SwitchNumber].m_aStatus[Team()])
1045 {
1046 m_Core.m_LiveFrozen = false;
1047 }
1048 }
1049 else if(SwitchType == TILE_HIT_ENABLE && m_Core.m_HammerHitDisabled && SwitchDelay == WEAPON_HAMMER)
1050 {
1051 m_Core.m_HammerHitDisabled = false;
1052 }
1053 else if(SwitchType == TILE_HIT_DISABLE && !m_Core.m_HammerHitDisabled && SwitchDelay == WEAPON_HAMMER)
1054 {
1055 m_Core.m_HammerHitDisabled = true;
1056 }
1057 else if(SwitchType == TILE_HIT_ENABLE && m_Core.m_ShotgunHitDisabled && SwitchDelay == WEAPON_SHOTGUN)
1058 {
1059 m_Core.m_ShotgunHitDisabled = false;
1060 }
1061 else if(SwitchType == TILE_HIT_DISABLE && !m_Core.m_ShotgunHitDisabled && SwitchDelay == WEAPON_SHOTGUN)
1062 {
1063 m_Core.m_ShotgunHitDisabled = true;
1064 }
1065 else if(SwitchType == TILE_HIT_ENABLE && m_Core.m_GrenadeHitDisabled && SwitchDelay == WEAPON_GRENADE)
1066 {
1067 m_Core.m_GrenadeHitDisabled = false;
1068 }
1069 else if(SwitchType == TILE_HIT_DISABLE && !m_Core.m_GrenadeHitDisabled && SwitchDelay == WEAPON_GRENADE)
1070 {
1071 m_Core.m_GrenadeHitDisabled = true;
1072 }
1073 else if(SwitchType == TILE_HIT_ENABLE && m_Core.m_LaserHitDisabled && SwitchDelay == WEAPON_LASER)
1074 {
1075 m_Core.m_LaserHitDisabled = false;
1076 }
1077 else if(SwitchType == TILE_HIT_DISABLE && !m_Core.m_LaserHitDisabled && SwitchDelay == WEAPON_LASER)
1078 {
1079 m_Core.m_LaserHitDisabled = true;
1080 }
1081 else if(SwitchType == TILE_JUMP)
1082 {
1083 int NewJumps = SwitchDelay;
1084 if(NewJumps == 255)
1085 {
1086 NewJumps = -1;
1087 }
1088
1089 if(NewJumps != m_Core.m_Jumps)
1090 m_Core.m_Jumps = NewJumps;
1091 }
1092}
1093
1094void CCharacter::HandleTuneLayer()
1095{
1096 int CurrentIndex = Collision()->GetMapIndex(Pos: m_Pos);
1097 SetTuneZone(GameWorld()->m_WorldConfig.m_UseTuneZones ? Collision()->IsTune(Index: CurrentIndex) : 0);
1098 m_Core.m_Tuning = *GetTuning(i: GetOverriddenTuneZone());
1099}
1100
1101void CCharacter::DDRaceTick()
1102{
1103 mem_copy(dest: &m_Input, source: &m_SavedInput, size: sizeof(m_Input));
1104 if(m_Core.m_LiveFrozen && !m_CanMoveInFreeze && !m_Core.m_Super && !m_Core.m_Invincible)
1105 {
1106 m_Input.m_Direction = 0;
1107 m_Input.m_Jump = 0;
1108 //Hook and weapons are possible in live freeze
1109 }
1110 if(m_FreezeTime > 0)
1111 {
1112 m_FreezeTime--;
1113 if(!m_CanMoveInFreeze)
1114 {
1115 m_Input.m_Direction = 0;
1116 m_Input.m_Jump = 0;
1117 m_Input.m_Hook = 0;
1118 }
1119 if(m_FreezeTime == 1)
1120 Unfreeze();
1121 }
1122
1123 HandleTuneLayer();
1124
1125 // check if the tee is in any type of freeze
1126 int Index = Collision()->GetPureMapIndex(Pos: m_Pos);
1127 const int aTiles[] = {
1128 Collision()->GetTileIndex(Index),
1129 Collision()->GetFrontTileIndex(Index),
1130 Collision()->GetSwitchType(Index)};
1131 m_Core.m_IsInFreeze = false;
1132 for(const int Tile : aTiles)
1133 {
1134 if(Tile == TILE_FREEZE || Tile == TILE_DFREEZE || Tile == TILE_LFREEZE || Tile == TILE_DEATH)
1135 {
1136 m_Core.m_IsInFreeze = true;
1137 break;
1138 }
1139 }
1140 m_Core.m_IsInFreeze |= (Collision()->GetCollisionAt(x: m_Pos.x + GetProximityRadius() / 3.f, y: m_Pos.y - GetProximityRadius() / 3.f) == TILE_DEATH ||
1141 Collision()->GetCollisionAt(x: m_Pos.x + GetProximityRadius() / 3.f, y: m_Pos.y + GetProximityRadius() / 3.f) == TILE_DEATH ||
1142 Collision()->GetCollisionAt(x: m_Pos.x - GetProximityRadius() / 3.f, y: m_Pos.y - GetProximityRadius() / 3.f) == TILE_DEATH ||
1143 Collision()->GetCollisionAt(x: m_Pos.x - GetProximityRadius() / 3.f, y: m_Pos.y + GetProximityRadius() / 3.f) == TILE_DEATH ||
1144 Collision()->GetFrontCollisionAt(x: m_Pos.x + GetProximityRadius() / 3.f, y: m_Pos.y - GetProximityRadius() / 3.f) == TILE_DEATH ||
1145 Collision()->GetFrontCollisionAt(x: m_Pos.x + GetProximityRadius() / 3.f, y: m_Pos.y + GetProximityRadius() / 3.f) == TILE_DEATH ||
1146 Collision()->GetFrontCollisionAt(x: m_Pos.x - GetProximityRadius() / 3.f, y: m_Pos.y - GetProximityRadius() / 3.f) == TILE_DEATH ||
1147 Collision()->GetFrontCollisionAt(x: m_Pos.x - GetProximityRadius() / 3.f, y: m_Pos.y + GetProximityRadius() / 3.f) == TILE_DEATH);
1148}
1149
1150void CCharacter::DDRacePostCoreTick()
1151{
1152 if(!GameWorld()->m_WorldConfig.m_PredictDDRace)
1153 return;
1154
1155 if(m_Core.m_EndlessHook)
1156 m_Core.m_HookTick = 0;
1157
1158 m_FrozenLastTick = false;
1159
1160 if(m_Core.m_DeepFrozen && !m_Core.m_Super && !m_Core.m_Invincible)
1161 Freeze();
1162
1163 // following jump rules can be overridden by tiles, like Refill Jumps, Stopper and Wall Jump
1164 if(m_Core.m_Jumps == -1)
1165 {
1166 // The player has only one ground jump, so their feet are always dark
1167 m_Core.m_Jumped |= 2;
1168 }
1169 else if(m_Core.m_Jumps == 0)
1170 {
1171 // The player has no jumps at all, so their feet are always dark
1172 m_Core.m_Jumped |= 2;
1173 }
1174 else if(m_Core.m_Jumps == 1 && m_Core.m_Jumped > 0)
1175 {
1176 // If the player has only one jump, each jump is the last one
1177 m_Core.m_Jumped |= 2;
1178 }
1179 else if(m_Core.m_JumpedTotal < m_Core.m_Jumps - 1 && m_Core.m_Jumped > 1)
1180 {
1181 // The player has not yet used up all their jumps, so their feet remain light
1182 m_Core.m_Jumped = 1;
1183 }
1184
1185 if((m_Core.m_Super || m_Core.m_EndlessJump) && m_Core.m_Jumped > 1)
1186 {
1187 // Super players and players with infinite jumps always have light feet
1188 m_Core.m_Jumped = 1;
1189 }
1190
1191 int CurrentIndex = Collision()->GetMapIndex(Pos: m_Pos);
1192 HandleSkippableTiles(Index: CurrentIndex);
1193
1194 // handle Anti-Skip tiles
1195 std::vector<int> vIndices = Collision()->GetMapIndices(PrevPos: m_PrevPos, Pos: m_Pos);
1196 if(!vIndices.empty())
1197 {
1198 for(int Index : vIndices)
1199 HandleTiles(Index);
1200 }
1201 else
1202 {
1203 HandleTiles(Index: CurrentIndex);
1204 }
1205}
1206
1207bool CCharacter::Freeze(int Seconds)
1208{
1209 if(!GameWorld()->m_WorldConfig.m_PredictFreeze)
1210 return false;
1211 if(Seconds <= 0 || m_Core.m_Super || m_Core.m_Invincible || m_FreezeTime > Seconds * GameWorld()->GameTickSpeed())
1212 return false;
1213 if(m_Core.m_FreezeStart < GameWorld()->GameTick() - GameWorld()->GameTickSpeed())
1214 {
1215 m_FreezeTime = Seconds * GameWorld()->GameTickSpeed();
1216 m_Core.m_FreezeStart = GameWorld()->GameTick();
1217 m_Core.m_FreezeEnd = m_Core.m_DeepFrozen ? -1 : (m_FreezeTime == 0 ? 0 : GameWorld()->GameTick() + m_FreezeTime);
1218 return true;
1219 }
1220 return false;
1221}
1222
1223bool CCharacter::Freeze()
1224{
1225 return Freeze(Seconds: g_Config.m_SvFreezeDelay);
1226}
1227
1228bool CCharacter::Unfreeze()
1229{
1230 if(m_FreezeTime > 0)
1231 {
1232 if(m_Core.m_ActiveWeapon >= 0 && !m_Core.m_aWeapons[m_Core.m_ActiveWeapon].m_Got)
1233 m_Core.m_ActiveWeapon = WEAPON_GUN;
1234 m_FreezeTime = 0;
1235 m_Core.m_FreezeStart = 0;
1236 m_Core.m_FreezeEnd = m_Core.m_DeepFrozen ? -1 : 0;
1237 if(GameWorld()->m_WorldConfig.m_PredictDDRace)
1238 m_FrozenLastTick = true;
1239 return true;
1240 }
1241 return false;
1242}
1243
1244void CCharacter::GiveWeapon(int Weapon, bool Remove)
1245{
1246 if(Weapon == WEAPON_NINJA)
1247 {
1248 if(Remove)
1249 RemoveNinja();
1250 else
1251 GiveNinja();
1252 return;
1253 }
1254
1255 if(Remove)
1256 {
1257 if(GetActiveWeapon() == Weapon)
1258 SetActiveWeapon(WEAPON_GUN);
1259 }
1260 else
1261 {
1262 m_Core.m_aWeapons[Weapon].m_Ammo = -1;
1263 }
1264
1265 m_Core.m_aWeapons[Weapon].m_Got = !Remove;
1266}
1267
1268void CCharacter::GiveAllWeapons()
1269{
1270 for(int i = WEAPON_GUN; i < NUM_WEAPONS - 1; i++)
1271 {
1272 GiveWeapon(Weapon: i);
1273 }
1274}
1275
1276void CCharacter::ResetVelocity()
1277{
1278 m_Core.m_Vel = vec2(0, 0);
1279}
1280
1281// The method is needed only to reproduce 'shotgun bug' ddnet#5258
1282// Use SetVelocity() instead.
1283void CCharacter::SetVelocity(const vec2 NewVelocity)
1284{
1285 m_Core.m_Vel = ClampVel(MoveRestriction: m_MoveRestrictions, Vel: NewVelocity);
1286}
1287
1288void CCharacter::SetRawVelocity(const vec2 NewVelocity)
1289{
1290 m_Core.m_Vel = NewVelocity;
1291}
1292
1293void CCharacter::AddVelocity(const vec2 Addition)
1294{
1295 SetVelocity(m_Core.m_Vel + Addition);
1296}
1297
1298void CCharacter::ApplyMoveRestrictions()
1299{
1300 m_Core.m_Vel = ClampVel(MoveRestriction: m_MoveRestrictions, Vel: m_Core.m_Vel);
1301}
1302
1303CTeamsCore *CCharacter::TeamsCore()
1304{
1305 return GameWorld()->Teams();
1306}
1307
1308CCharacter::CCharacter(CGameWorld *pGameWorld, int Id, CNetObj_Character *pChar, CNetObj_DDNetCharacter *pExtended) :
1309 CEntity(pGameWorld, CGameWorld::ENTTYPE_CHARACTER, vec2(0, 0), CCharacterCore::PhysicalSize())
1310{
1311 m_Id = Id;
1312 m_IsLocal = false;
1313
1314 m_LastWeapon = WEAPON_HAMMER;
1315 m_LastSnapWeapon = -1;
1316 m_QueuedWeapon = -1;
1317 m_LastRefillJumps = false;
1318 m_PrevPrevPos = m_PrevPos = m_Pos = vec2(pChar->m_X, pChar->m_Y);
1319 m_Core.Reset();
1320 m_Core.Init(pWorld: &GameWorld()->m_Core, pCollision: GameWorld()->Collision(), pTeams: GameWorld()->Teams());
1321 m_Core.m_Id = Id;
1322 m_Core.m_ActiveWeapon = -1; // set by the first Read below
1323 mem_zero(block: &m_Core.m_Ninja, size: sizeof(m_Core.m_Ninja));
1324 m_Core.m_LeftWall = true;
1325 m_ReloadTimer = 0;
1326 m_NumObjectsHit = 0;
1327 m_LastRefillJumps = false;
1328 m_CanMoveInFreeze = false;
1329 m_TeleCheckpoint = 0;
1330 m_StrongWeakId = 0;
1331 m_TuneZone = 0;
1332 m_TuneZoneOverride = TuneZone::OVERRIDE_NONE;
1333
1334 mem_zero(block: &m_Input, size: sizeof(m_Input));
1335 // never initialize both to zero
1336 m_Input.m_TargetX = 0;
1337 m_Input.m_TargetY = -1;
1338
1339 m_LatestPrevInput = m_LatestInput = m_PrevInput = m_SavedInput = m_Input;
1340
1341 ResetPrediction();
1342 Read(pChar, pExtended, IsLocal: false);
1343}
1344
1345void CCharacter::AntiPingInterference(int ClientId, bool DisallowReset, bool HasToBeUnfrozen)
1346{
1347 // Enable antiping for players that we hook or bump while unfrozen, the unfrozen check helps when being saved in gores
1348 // If we interfered with a player that bounces or hooks someone else, we want to chain the prediction
1349 // thus interfering players can enable antiping on others
1350 if(HasToBeUnfrozen && m_FreezeTime)
1351 return;
1352
1353 CCharacter *pChar = GameWorld()->GetCharacterById(Id: ClientId);
1354 if(!pChar)
1355 return;
1356
1357 bool AllowEnablePrediction = m_IsLocal || m_Interfering;
1358 if(!AllowEnablePrediction && !DisallowReset)
1359 {
1360 // disable antiping on players if a non-predicted player interacts with them, but not player bounces here
1361 if(!pChar->m_FreezeTime || g_Config.m_ClAntiPingPlayers != 3)
1362 {
1363 pChar->m_Interfering = false;
1364 }
1365 }
1366 else if(AllowEnablePrediction)
1367 {
1368 pChar->m_Interfering = true;
1369 }
1370}
1371
1372void CCharacter::ResetPrediction()
1373{
1374 SetSolo(false);
1375 SetSuper(false);
1376 m_Core.m_EndlessHook = false;
1377 m_Core.m_HammerHitDisabled = false;
1378 m_Core.m_ShotgunHitDisabled = false;
1379 m_Core.m_GrenadeHitDisabled = false;
1380 m_Core.m_LaserHitDisabled = false;
1381 m_Core.m_EndlessJump = false;
1382 m_Core.m_Jetpack = false;
1383 m_NinjaJetpack = false;
1384 m_Core.m_Jumps = 2;
1385 m_Core.m_HookHitDisabled = false;
1386 m_Core.m_CollisionDisabled = false;
1387 m_NumInputs = 0;
1388 m_FreezeTime = 0;
1389 m_Core.m_FreezeStart = 0;
1390 m_Core.m_IsInFreeze = false;
1391 m_Core.m_DeepFrozen = false;
1392 m_Core.m_LiveFrozen = false;
1393 m_FrozenLastTick = false;
1394 for(int w = 0; w < NUM_WEAPONS; w++)
1395 {
1396 SetWeaponGot(Type: w, Value: false);
1397 SetWeaponAmmo(Type: w, Value: -1);
1398 }
1399 if(m_Core.HookedPlayer() >= 0)
1400 {
1401 m_Core.SetHookedPlayer(-1);
1402 m_Core.m_HookState = HOOK_IDLE;
1403 }
1404 m_LastWeaponSwitchTick = 0;
1405 m_LastTuneZoneTick = 0;
1406 m_Interfering = false;
1407}
1408
1409void CCharacter::Read(CNetObj_Character *pChar, CNetObj_DDNetCharacter *pExtended, bool IsLocal)
1410{
1411 m_Core.Read(pObjCore: (const CNetObj_CharacterCore *)pChar);
1412 m_IsLocal = IsLocal;
1413
1414 if(pExtended)
1415 {
1416 SetSolo(pExtended->m_Flags & CHARACTERFLAG_SOLO);
1417 SetSuper(pExtended->m_Flags & CHARACTERFLAG_SUPER);
1418
1419 m_TeleCheckpoint = pExtended->m_TeleCheckpoint;
1420 m_StrongWeakId = pExtended->m_StrongWeakId;
1421 m_TuneZoneOverride = pExtended->m_TuneZoneOverride;
1422
1423 const bool Ninja = (pExtended->m_Flags & CHARACTERFLAG_WEAPON_NINJA) != 0;
1424 if(Ninja && m_Core.m_ActiveWeapon != WEAPON_NINJA)
1425 GiveNinja();
1426 else if(!Ninja && m_Core.m_ActiveWeapon == WEAPON_NINJA)
1427 RemoveNinja();
1428
1429 if(GameWorld()->m_WorldConfig.m_PredictFreeze && pExtended->m_FreezeEnd != 0)
1430 {
1431 if(pExtended->m_FreezeEnd > 0)
1432 {
1433 if(m_FreezeTime == 0)
1434 Freeze();
1435 m_FreezeTime = std::max(a: 1, b: pExtended->m_FreezeEnd - GameWorld()->GameTick());
1436 }
1437 else if(pExtended->m_FreezeEnd == -1)
1438 {
1439 m_Core.m_DeepFrozen = true;
1440 }
1441
1442 // We wait for the server to tell us who is frozen instead of using predicted Freeze() function
1443 // because that can still mispredict and would cause jitter by enabling and disabling antiping
1444 if(pExtended->m_FreezeEnd != 0 && g_Config.m_ClAntiPingPlayers == 3)
1445 {
1446 // If wanted, every frozen player will always be predicted to catch them easier
1447 m_Interfering = true;
1448 }
1449 }
1450 else
1451 {
1452 Unfreeze();
1453 }
1454
1455 m_Core.ReadDDNet(pObjDDNet: pExtended);
1456
1457 if(!GameWorld()->m_WorldConfig.m_PredictFreeze)
1458 {
1459 Unfreeze();
1460 }
1461 }
1462 else
1463 {
1464 // ddnetcharacter is not available, try to get some info from the tunings and the character netobject instead.
1465
1466 // remove weapons that are unavailable. if the current weapon is ninja just set ammo to zero in case the player is frozen
1467 if(m_Core.m_ActiveWeapon >= 0 && pChar->m_Weapon != m_Core.m_ActiveWeapon)
1468 {
1469 if(pChar->m_Weapon == WEAPON_NINJA)
1470 {
1471 m_Core.m_aWeapons[m_Core.m_ActiveWeapon].m_Ammo = 0;
1472 }
1473 else
1474 {
1475 if(m_Core.m_ActiveWeapon == WEAPON_NINJA)
1476 {
1477 SetNinjaActivationDir(vec2(0, 0));
1478 SetNinjaActivationTick(-500);
1479 SetNinjaCurrentMoveTime(0);
1480 }
1481 if(pChar->m_Weapon == m_LastSnapWeapon)
1482 m_Core.m_aWeapons[m_Core.m_ActiveWeapon].m_Got = false;
1483 }
1484 }
1485 // add weapon
1486 if(pChar->m_Weapon >= 0 && pChar->m_Weapon != WEAPON_NINJA)
1487 {
1488 m_Core.m_aWeapons[pChar->m_Weapon].m_Got = true;
1489 }
1490
1491 // without ddnetcharacter we don't know if we have jetpack, so try to predict jetpack if strength isn't 0, on vanilla it's always 0
1492 if(GameWorld()->m_WorldConfig.m_PredictWeapons && GetTuning(i: GetOverriddenTuneZone())->m_JetpackStrength != 0)
1493 {
1494 m_Core.m_Jetpack = true;
1495 m_Core.m_aWeapons[WEAPON_GUN].m_Got = true;
1496 m_Core.m_aWeapons[WEAPON_GUN].m_Ammo = -1;
1497 m_NinjaJetpack = pChar->m_Weapon == WEAPON_NINJA;
1498 }
1499 else if(pChar->m_Weapon != WEAPON_NINJA)
1500 {
1501 m_Core.m_Jetpack = false;
1502 }
1503
1504 // number of jumps
1505 if(GameWorld()->m_WorldConfig.m_PredictTiles)
1506 {
1507 if(pChar->m_Jumped & 2)
1508 {
1509 m_Core.m_EndlessJump = false;
1510 if(m_Core.m_Jumps > m_Core.m_JumpedTotal && m_Core.m_JumpedTotal > 0 && m_Core.m_Jumps > 2)
1511 m_Core.m_Jumps = m_Core.m_JumpedTotal + 1;
1512 }
1513 else if(m_Core.m_Jumps < 2)
1514 {
1515 m_Core.m_Jumps = m_Core.m_JumpedTotal + 2;
1516 }
1517 if(GetTuning(i: GetOverriddenTuneZone())->m_AirJumpImpulse == 0)
1518 {
1519 m_Core.m_Jumps = 0;
1520 m_Core.m_Jumped = 3;
1521 }
1522 }
1523
1524 // set player collision
1525 SetSolo(!GetTuning(i: GetOverriddenTuneZone())->m_PlayerCollision && !GetTuning(i: GetOverriddenTuneZone())->m_PlayerHooking);
1526 m_Core.m_CollisionDisabled = !GetTuning(i: GetOverriddenTuneZone())->m_PlayerCollision;
1527 m_Core.m_HookHitDisabled = !GetTuning(i: GetOverriddenTuneZone())->m_PlayerHooking;
1528
1529 if(m_Core.m_HookTick != 0)
1530 m_Core.m_EndlessHook = false;
1531
1532 // detect unfreeze (in case the player was frozen in the tile prediction and not correctly unfrozen)
1533 if(pChar->m_Emote != EMOTE_PAIN && pChar->m_Emote != EMOTE_NORMAL)
1534 m_Core.m_DeepFrozen = false;
1535 if(pChar->m_Weapon != WEAPON_NINJA || pChar->m_AttackTick > m_Core.m_FreezeStart || absolute(a: pChar->m_VelX) == 256 * 10 || !GameWorld()->m_WorldConfig.m_PredictFreeze)
1536 {
1537 m_Core.m_DeepFrozen = false;
1538 Unfreeze();
1539 }
1540
1541 m_TuneZoneOverride = TuneZone::OVERRIDE_NONE;
1542 }
1543
1544 vec2 PosBefore = m_Pos;
1545 m_Pos = m_Core.m_Pos;
1546
1547 if(distance(a: PosBefore, b: m_Pos) > 2.f) // misprediction, don't use prevpos
1548 m_PrevPos = m_Pos;
1549
1550 if(distance(a: m_PrevPos, b: m_Pos) > 10.f * 32.f) // reset prevpos if the distance is high
1551 m_PrevPos = m_Pos;
1552
1553 if(pChar->m_Jumped & 2)
1554 m_Core.m_JumpedTotal = m_Core.m_Jumps;
1555 m_AttackTick = pChar->m_AttackTick;
1556 m_LastSnapWeapon = pChar->m_Weapon;
1557
1558 SetTuneZone(GameWorld()->m_WorldConfig.m_UseTuneZones ? Collision()->IsTune(Index: Collision()->GetMapIndex(Pos: m_Pos)) : 0);
1559
1560 // set the current weapon
1561 if(pChar->m_Weapon != WEAPON_NINJA)
1562 {
1563 if(pChar->m_Weapon >= 0)
1564 m_Core.m_aWeapons[pChar->m_Weapon].m_Ammo = (GameWorld()->m_WorldConfig.m_InfiniteAmmo || pChar->m_Weapon == WEAPON_HAMMER) ? -1 : pChar->m_AmmoCount;
1565
1566 if(pChar->m_Weapon != m_Core.m_ActiveWeapon)
1567 SetActiveWeapon(pChar->m_Weapon);
1568 }
1569 else if(m_Core.m_ActiveWeapon < 0)
1570 {
1571 SetActiveWeapon(pChar->m_Weapon);
1572 }
1573
1574 // reset all input except direction and hook for non-local players (as in vanilla prediction)
1575 if(!IsLocal)
1576 {
1577 mem_zero(block: &m_Input, size: sizeof(m_Input));
1578 mem_zero(block: &m_SavedInput, size: sizeof(m_SavedInput));
1579 m_Input.m_Direction = m_SavedInput.m_Direction = m_Core.m_Direction;
1580 m_Input.m_Hook = m_SavedInput.m_Hook = (m_Core.m_HookState != HOOK_IDLE);
1581
1582 if(pExtended && pExtended->m_TargetX != 0 && pExtended->m_TargetY != 0)
1583 {
1584 m_Input.m_TargetX = m_SavedInput.m_TargetX = pExtended->m_TargetX;
1585 m_Input.m_TargetY = m_SavedInput.m_TargetY = pExtended->m_TargetY;
1586 }
1587 else
1588 {
1589 m_Input.m_TargetX = m_SavedInput.m_TargetX = std::cos(x: pChar->m_Angle / 256.0f) * 256.0f;
1590 m_Input.m_TargetY = m_SavedInput.m_TargetY = std::sin(x: pChar->m_Angle / 256.0f) * 256.0f;
1591 }
1592 }
1593
1594 // in most cases the reload timer can be determined from the last attack tick
1595 // (this is only needed for autofire weapons to prevent the predicted reload timer from desyncing)
1596 if(IsLocal && m_Core.m_ActiveWeapon != -1 && m_Core.m_ActiveWeapon != WEAPON_HAMMER && !m_Core.m_aWeapons[WEAPON_NINJA].m_Got)
1597 {
1598 if(std::max(a: m_LastTuneZoneTick, b: m_LastWeaponSwitchTick) + GameWorld()->GameTickSpeed() < GameWorld()->GameTick())
1599 {
1600 const int FireDelayTicks = GetTuning(i: GetOverriddenTuneZone())->GetWeaponFireDelay(Weapon: m_Core.m_ActiveWeapon) * GameWorld()->GameTickSpeed();
1601 m_ReloadTimer = std::max(a: 0, b: m_AttackTick + FireDelayTicks - GameWorld()->GameTick());
1602 }
1603 }
1604}
1605
1606void CCharacter::SetCoreWorld(CGameWorld *pGameWorld)
1607{
1608 m_Core.SetCoreWorld(pWorld: &pGameWorld->m_Core, pCollision: pGameWorld->Collision(), pTeams: pGameWorld->Teams());
1609 m_Core.SetAntiPingInterfereCallback([this](int ClientId, bool DisallowReset) {
1610 AntiPingInterference(ClientId, DisallowReset, HasToBeUnfrozen: true);
1611 });
1612}
1613
1614bool CCharacter::Match(CCharacter *pChar) const
1615{
1616 return distance(a: pChar->m_Core.m_Pos, b: m_Core.m_Pos) <= 32.f;
1617}
1618
1619void CCharacter::SetActiveWeapon(int ActiveWeapon)
1620{
1621 if(ActiveWeapon < WEAPON_HAMMER || ActiveWeapon >= NUM_WEAPONS)
1622 {
1623 m_Core.m_ActiveWeapon = -1;
1624 }
1625 else
1626 {
1627 m_Core.m_ActiveWeapon = ActiveWeapon;
1628 }
1629 m_LastWeaponSwitchTick = GameWorld()->GameTick();
1630}
1631
1632void CCharacter::SetTuneZone(int Zone)
1633{
1634 if(Zone == m_TuneZone)
1635 return;
1636 m_TuneZone = Zone;
1637 m_LastTuneZoneTick = GameWorld()->GameTick();
1638}
1639
1640int CCharacter::GetOverriddenTuneZone() const
1641{
1642 return m_TuneZoneOverride == TuneZone::OVERRIDE_NONE ? m_TuneZone : m_TuneZoneOverride;
1643}
1644
1645int CCharacter::GetPureTuneZone() const
1646{
1647 return m_TuneZone;
1648}
1649
1650CCharacter::~CCharacter()
1651{
1652 if(GameWorld())
1653 GameWorld()->RemoveCharacter(pChar: this);
1654}
1655