| 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 "pickup.h" |
| 7 | #include "projectile.h" |
| 8 | |
| 9 | #include <antibot/antibot_data.h> |
| 10 | |
| 11 | #include <base/log.h> |
| 12 | |
| 13 | #include <engine/antibot.h> |
| 14 | #include <engine/shared/config.h> |
| 15 | |
| 16 | #include <generated/protocol.h> |
| 17 | #include <generated/server_data.h> |
| 18 | |
| 19 | #include <game/mapitems.h> |
| 20 | #include <game/server/gamecontext.h> |
| 21 | #include <game/server/gamecontroller.h> |
| 22 | #include <game/server/player.h> |
| 23 | #include <game/server/score.h> |
| 24 | #include <game/server/teams.h> |
| 25 | #include <game/team_state.h> |
| 26 | |
| 27 | MACRO_ALLOC_POOL_ID_IMPL(CCharacter, MAX_CLIENTS) |
| 28 | |
| 29 | // Character, "physical" player's part |
| 30 | CCharacter::CCharacter(CGameWorld *pWorld, CNetObj_PlayerInput LastInput) : |
| 31 | CEntity(pWorld, CGameWorld::ENTTYPE_CHARACTER, vec2(0, 0), CCharacterCore::PhysicalSize()) |
| 32 | { |
| 33 | m_Health = 0; |
| 34 | m_Armor = 0; |
| 35 | m_TriggeredEvents7 = 0; |
| 36 | m_StrongWeakId = 0; |
| 37 | |
| 38 | m_Input = LastInput; |
| 39 | // never initialize both to zero |
| 40 | m_Input.m_TargetX = 0; |
| 41 | m_Input.m_TargetY = -1; |
| 42 | |
| 43 | m_LatestPrevPrevInput = m_LatestPrevInput = m_LatestInput = m_PrevInput = m_SavedInput = m_Input; |
| 44 | |
| 45 | m_LastTimeCp = -1; |
| 46 | m_LastTimeCpBroadcasted = -1; |
| 47 | for(float &CurrentTimeCp : m_aCurrentTimeCp) |
| 48 | { |
| 49 | CurrentTimeCp = 0.0f; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | void CCharacter::Reset() |
| 54 | { |
| 55 | StopRecording(); |
| 56 | Destroy(); |
| 57 | } |
| 58 | |
| 59 | bool CCharacter::Spawn(CPlayer *pPlayer, vec2 Pos) |
| 60 | { |
| 61 | m_EmoteStop = -1; |
| 62 | m_LastAction = -1; |
| 63 | m_LastNoAmmoSound = -1; |
| 64 | m_LastWeapon = WEAPON_HAMMER; |
| 65 | m_QueuedWeapon = -1; |
| 66 | m_LastRefillJumps = false; |
| 67 | m_LastPenalty = false; |
| 68 | m_LastBonus = false; |
| 69 | |
| 70 | m_TeleGunTeleport = false; |
| 71 | m_IsBlueTeleGunTeleport = false; |
| 72 | |
| 73 | m_pPlayer = pPlayer; |
| 74 | m_Pos = Pos; |
| 75 | |
| 76 | mem_zero(block: &m_LatestPrevPrevInput, size: sizeof(m_LatestPrevPrevInput)); |
| 77 | m_LatestPrevPrevInput.m_TargetY = -1; |
| 78 | m_NumInputs = 0; |
| 79 | m_SpawnTick = Server()->Tick(); |
| 80 | m_WeaponChangeTick = Server()->Tick(); |
| 81 | Antibot()->OnSpawn(ClientId: m_pPlayer->GetCid()); |
| 82 | |
| 83 | m_Core.Reset(); |
| 84 | m_Core.Init(pWorld: &GameServer()->m_World.m_Core, pCollision: Collision()); |
| 85 | m_Core.m_ActiveWeapon = WEAPON_GUN; |
| 86 | m_Core.m_Pos = m_Pos; |
| 87 | m_Core.m_Id = m_pPlayer->GetCid(); |
| 88 | int TuneZone = Collision()->IsTune(Index: Collision()->GetMapIndex(Pos)); |
| 89 | m_Core.m_Tuning = TuningList()[TuneZone]; |
| 90 | GameServer()->m_World.m_Core.m_apCharacters[m_pPlayer->GetCid()] = &m_Core; |
| 91 | |
| 92 | m_ReckoningTick = 0; |
| 93 | m_SendCore = CCharacterCore(); |
| 94 | m_ReckoningCore = CCharacterCore(); |
| 95 | |
| 96 | GameServer()->m_World.InsertEntity(pEntity: this); |
| 97 | m_Alive = true; |
| 98 | |
| 99 | GameServer()->m_pController->OnCharacterSpawn(pChr: this); |
| 100 | |
| 101 | DDRaceInit(); |
| 102 | |
| 103 | m_TuneZone = TuneZone; |
| 104 | m_TuneZoneOld = -1; // no zone leave msg on spawn |
| 105 | m_NeededFaketuning = 0; // reset fake tunings on respawn and send the client |
| 106 | SendZoneMsgs(); // we want a entermessage also on spawn |
| 107 | GameServer()->SendTuningParams(ClientId: m_pPlayer->GetCid(), Zone: m_TuneZone); |
| 108 | |
| 109 | TrySetRescue(RescueMode: RESCUEMODE_MANUAL); |
| 110 | Server()->StartRecord(ClientId: m_pPlayer->GetCid()); |
| 111 | |
| 112 | int Team = GameServer()->m_aTeamMapping[m_pPlayer->GetCid()]; |
| 113 | |
| 114 | if(Team != -1) |
| 115 | { |
| 116 | GameServer()->m_pController->Teams().SetForceCharacterTeam(ClientId: m_pPlayer->GetCid(), Team); |
| 117 | GameServer()->m_aTeamMapping[m_pPlayer->GetCid()] = -1; |
| 118 | |
| 119 | if(GameServer()->m_apSavedTeams[Team]) |
| 120 | { |
| 121 | GameServer()->m_apSavedTeams[Team]->Load(pGameServer: GameServer(), Team, KeepCurrentWeakStrong: true, IgnorePlayers: true); |
| 122 | delete GameServer()->m_apSavedTeams[Team]; |
| 123 | GameServer()->m_apSavedTeams[Team] = nullptr; |
| 124 | } |
| 125 | |
| 126 | if(GameServer()->m_apSavedTees[m_pPlayer->GetCid()]) |
| 127 | { |
| 128 | GameServer()->m_apSavedTees[m_pPlayer->GetCid()]->Load(pChr: m_pPlayer->GetCharacter(), Team); |
| 129 | delete GameServer()->m_apSavedTees[m_pPlayer->GetCid()]; |
| 130 | GameServer()->m_apSavedTees[m_pPlayer->GetCid()] = nullptr; |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | return true; |
| 135 | } |
| 136 | |
| 137 | void CCharacter::Destroy() |
| 138 | { |
| 139 | GameServer()->m_World.m_Core.m_apCharacters[m_pPlayer->GetCid()] = nullptr; |
| 140 | m_Alive = false; |
| 141 | SetSolo(false); |
| 142 | } |
| 143 | |
| 144 | void CCharacter::SetWeapon(int W) |
| 145 | { |
| 146 | if(W == m_Core.m_ActiveWeapon) |
| 147 | return; |
| 148 | |
| 149 | m_LastWeapon = m_Core.m_ActiveWeapon; |
| 150 | m_QueuedWeapon = -1; |
| 151 | m_Core.m_ActiveWeapon = W; |
| 152 | GameServer()->CreateSound(Pos: m_Pos, Sound: SOUND_WEAPON_SWITCH, Mask: TeamMask()); |
| 153 | |
| 154 | if(m_Core.m_ActiveWeapon < 0 || m_Core.m_ActiveWeapon >= NUM_WEAPONS) |
| 155 | m_Core.m_ActiveWeapon = 0; |
| 156 | } |
| 157 | |
| 158 | void CCharacter::SetJetpack(bool Active) |
| 159 | { |
| 160 | m_Core.m_Jetpack = Active; |
| 161 | } |
| 162 | |
| 163 | void CCharacter::SetEndlessJump(bool Active) |
| 164 | { |
| 165 | m_Core.m_EndlessJump = Active; |
| 166 | } |
| 167 | |
| 168 | void CCharacter::SetJumps(int Jumps) |
| 169 | { |
| 170 | m_Core.m_Jumps = Jumps; |
| 171 | } |
| 172 | |
| 173 | void CCharacter::SetSolo(bool Solo) |
| 174 | { |
| 175 | m_Core.m_Solo = Solo; |
| 176 | Teams()->m_Core.SetSolo(ClientId: m_pPlayer->GetCid(), Value: Solo); |
| 177 | } |
| 178 | |
| 179 | void CCharacter::SetSuper(bool Super) |
| 180 | { |
| 181 | // Disable invincible mode before activating super mode. Both modes active at the same time wouldn't necessarily break anything but it's not useful. |
| 182 | if(Super) |
| 183 | SetInvincible(false); |
| 184 | |
| 185 | bool WasSuper = m_Core.m_Super; |
| 186 | m_Core.m_Super = Super; |
| 187 | if(Super && !WasSuper) |
| 188 | { |
| 189 | m_TeamBeforeSuper = Team(); |
| 190 | char aError[512]; |
| 191 | if(!Teams()->SetCharacterTeam(ClientId: GetPlayer()->GetCid(), Team: TEAM_SUPER, pError: aError, ErrorSize: sizeof(aError))) |
| 192 | log_error("character" , "failed to set super: %s" , aError); |
| 193 | m_DDRaceState = ERaceState::CHEATED; |
| 194 | } |
| 195 | else if(!Super && WasSuper) |
| 196 | { |
| 197 | Teams()->SetForceCharacterTeam(ClientId: GetPlayer()->GetCid(), Team: m_TeamBeforeSuper); |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | void CCharacter::SetInvincible(bool Invincible) |
| 202 | { |
| 203 | // Disable super mode before activating invincible mode. Both modes active at the same time wouldn't necessarily break anything but it's not useful. |
| 204 | if(Invincible) |
| 205 | SetSuper(false); |
| 206 | |
| 207 | m_Core.m_Invincible = Invincible; |
| 208 | if(Invincible) |
| 209 | UnFreeze(); |
| 210 | |
| 211 | SetEndlessJump(Invincible); |
| 212 | } |
| 213 | |
| 214 | void CCharacter::SetCollisionDisabled(bool CollisionDisabled) |
| 215 | { |
| 216 | m_Core.m_CollisionDisabled = CollisionDisabled; |
| 217 | } |
| 218 | |
| 219 | void CCharacter::SetHookHitDisabled(bool HookHitDisabled) |
| 220 | { |
| 221 | m_Core.m_HookHitDisabled = HookHitDisabled; |
| 222 | } |
| 223 | |
| 224 | void CCharacter::SetLiveFrozen(bool Active) |
| 225 | { |
| 226 | m_Core.m_LiveFrozen = Active; |
| 227 | } |
| 228 | |
| 229 | void CCharacter::SetDeepFrozen(bool Active) |
| 230 | { |
| 231 | m_Core.m_DeepFrozen = Active; |
| 232 | } |
| 233 | |
| 234 | bool CCharacter::IsGrounded() |
| 235 | { |
| 236 | if(Collision()->CheckPoint(x: m_Pos.x + GetProximityRadius() / 2, y: m_Pos.y + GetProximityRadius() / 2 + 5)) |
| 237 | return true; |
| 238 | if(Collision()->CheckPoint(x: m_Pos.x - GetProximityRadius() / 2, y: m_Pos.y + GetProximityRadius() / 2 + 5)) |
| 239 | return true; |
| 240 | |
| 241 | int MoveRestrictionsBelow = Collision()->GetMoveRestrictions(Pos: m_Pos + vec2(0, GetProximityRadius() / 2 + 4), Distance: 0.0f); |
| 242 | return (MoveRestrictionsBelow & CANTMOVE_DOWN) != 0; |
| 243 | } |
| 244 | |
| 245 | void CCharacter::HandleJetpack() |
| 246 | { |
| 247 | vec2 Direction = normalize(v: vec2(m_LatestInput.m_TargetX, m_LatestInput.m_TargetY)); |
| 248 | |
| 249 | bool FullAuto = false; |
| 250 | if(m_Core.m_ActiveWeapon == WEAPON_GRENADE || m_Core.m_ActiveWeapon == WEAPON_SHOTGUN || m_Core.m_ActiveWeapon == WEAPON_LASER) |
| 251 | FullAuto = true; |
| 252 | if(m_Core.m_Jetpack && m_Core.m_ActiveWeapon == WEAPON_GUN) |
| 253 | FullAuto = true; |
| 254 | |
| 255 | // check if we gonna fire |
| 256 | bool WillFire = false; |
| 257 | if(CountInput(Prev: m_LatestPrevInput.m_Fire, Cur: m_LatestInput.m_Fire).m_Presses) |
| 258 | WillFire = true; |
| 259 | |
| 260 | if(FullAuto && (m_LatestInput.m_Fire & 1) && m_Core.m_aWeapons[m_Core.m_ActiveWeapon].m_Ammo) |
| 261 | WillFire = true; |
| 262 | |
| 263 | if(!WillFire) |
| 264 | return; |
| 265 | |
| 266 | // check for ammo |
| 267 | if(!m_Core.m_aWeapons[m_Core.m_ActiveWeapon].m_Ammo || m_FreezeTime) |
| 268 | { |
| 269 | return; |
| 270 | } |
| 271 | |
| 272 | switch(m_Core.m_ActiveWeapon) |
| 273 | { |
| 274 | case WEAPON_GUN: |
| 275 | { |
| 276 | if(m_Core.m_Jetpack) |
| 277 | { |
| 278 | float Strength = GetTuning(Zone: m_TuneZone)->m_JetpackStrength; |
| 279 | TakeDamage(Force: Direction * -1.0f * (Strength / 100.0f / 6.11f), Dmg: 0, From: m_pPlayer->GetCid(), Weapon: m_Core.m_ActiveWeapon); |
| 280 | } |
| 281 | } |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | void CCharacter::HandleNinja() |
| 286 | { |
| 287 | if(m_Core.m_ActiveWeapon != WEAPON_NINJA) |
| 288 | return; |
| 289 | |
| 290 | if((Server()->Tick() - m_Core.m_Ninja.m_ActivationTick) > (g_pData->m_Weapons.m_Ninja.m_Duration * Server()->TickSpeed() / 1000)) |
| 291 | { |
| 292 | // time's up, return |
| 293 | RemoveNinja(); |
| 294 | return; |
| 295 | } |
| 296 | |
| 297 | int NinjaTime = m_Core.m_Ninja.m_ActivationTick + (g_pData->m_Weapons.m_Ninja.m_Duration * Server()->TickSpeed() / 1000) - Server()->Tick(); |
| 298 | |
| 299 | if(NinjaTime % Server()->TickSpeed() == 0 && NinjaTime / Server()->TickSpeed() <= 5) |
| 300 | { |
| 301 | GameServer()->CreateDamageInd(Pos: m_Pos, AngleMod: 0, Amount: NinjaTime / Server()->TickSpeed(), Mask: TeamMask() & GameServer()->ClientsMaskExcludeClientVersionAndHigher(Version: VERSION_DDNET_NEW_HUD)); |
| 302 | } |
| 303 | |
| 304 | GameServer()->m_pController->SetArmorProgress(pCharacter: this, Progress: NinjaTime); |
| 305 | |
| 306 | // force ninja Weapon |
| 307 | SetWeapon(WEAPON_NINJA); |
| 308 | |
| 309 | m_Core.m_Ninja.m_CurrentMoveTime--; |
| 310 | |
| 311 | if(m_Core.m_Ninja.m_CurrentMoveTime == 0) |
| 312 | { |
| 313 | // reset velocity |
| 314 | m_Core.m_Vel = m_Core.m_Ninja.m_ActivationDir * m_Core.m_Ninja.m_OldVelAmount; |
| 315 | } |
| 316 | |
| 317 | if(m_Core.m_Ninja.m_CurrentMoveTime > 0) |
| 318 | { |
| 319 | // Set velocity |
| 320 | m_Core.m_Vel = m_Core.m_Ninja.m_ActivationDir * g_pData->m_Weapons.m_Ninja.m_Velocity; |
| 321 | vec2 OldPos = m_Pos; |
| 322 | vec2 GroundElasticity = vec2( |
| 323 | GetTuning(Zone: m_TuneZone)->m_GroundElasticityX, |
| 324 | GetTuning(Zone: m_TuneZone)->m_GroundElasticityY); |
| 325 | |
| 326 | Collision()->MoveBox(pInoutPos: &m_Core.m_Pos, pInoutVel: &m_Core.m_Vel, Size: vec2(GetProximityRadius(), GetProximityRadius()), Elasticity: GroundElasticity); |
| 327 | |
| 328 | // reset velocity so the client doesn't predict stuff |
| 329 | ResetVelocity(); |
| 330 | |
| 331 | // check if we Hit anything along the way |
| 332 | { |
| 333 | CEntity *apEnts[MAX_CLIENTS]; |
| 334 | float Radius = GetProximityRadius() * 2.0f; |
| 335 | int Num = GameServer()->m_World.FindEntities(Pos: OldPos, Radius, ppEnts: apEnts, Max: MAX_CLIENTS, Type: CGameWorld::ENTTYPE_CHARACTER); |
| 336 | |
| 337 | // check that we're not in solo part |
| 338 | if(Teams()->m_Core.GetSolo(ClientId: m_pPlayer->GetCid())) |
| 339 | return; |
| 340 | |
| 341 | for(int i = 0; i < Num; ++i) |
| 342 | { |
| 343 | auto *pChr = static_cast<CCharacter *>(apEnts[i]); |
| 344 | if(pChr == this) |
| 345 | continue; |
| 346 | |
| 347 | // Don't hit players in other teams |
| 348 | if(Team() != pChr->Team()) |
| 349 | continue; |
| 350 | |
| 351 | const int ClientId = pChr->m_pPlayer->GetCid(); |
| 352 | |
| 353 | // Don't hit players in solo parts |
| 354 | if(Teams()->m_Core.GetSolo(ClientId)) |
| 355 | return; |
| 356 | |
| 357 | // make sure we haven't Hit this object before |
| 358 | bool AlreadyHit = false; |
| 359 | for(int j = 0; j < m_NumObjectsHit; j++) |
| 360 | { |
| 361 | if(m_aHitObjects[j] == ClientId) |
| 362 | AlreadyHit = true; |
| 363 | } |
| 364 | if(AlreadyHit) |
| 365 | continue; |
| 366 | |
| 367 | // check so we are sufficiently close |
| 368 | if(distance(a: pChr->m_Pos, b: m_Pos) > Radius) |
| 369 | continue; |
| 370 | |
| 371 | // Hit a player, give them damage and stuffs... |
| 372 | GameServer()->CreateSound(Pos: pChr->m_Pos, Sound: SOUND_NINJA_HIT, Mask: TeamMask()); |
| 373 | // set his velocity to fast upward (for now) |
| 374 | dbg_assert(m_NumObjectsHit < MAX_CLIENTS, "m_aHitObjects overflow" ); |
| 375 | m_aHitObjects[m_NumObjectsHit++] = ClientId; |
| 376 | |
| 377 | pChr->TakeDamage(Force: vec2(0, -10.0f), Dmg: g_pData->m_Weapons.m_Ninja.m_pBase->m_Damage, From: m_pPlayer->GetCid(), Weapon: WEAPON_NINJA); |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | return; |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | void CCharacter::DoWeaponSwitch() |
| 386 | { |
| 387 | // make sure we can switch |
| 388 | if(m_ReloadTimer != 0 || m_QueuedWeapon == -1 || m_Core.m_aWeapons[WEAPON_NINJA].m_Got || !m_Core.m_aWeapons[m_QueuedWeapon].m_Got) |
| 389 | return; |
| 390 | |
| 391 | // switch Weapon |
| 392 | SetWeapon(m_QueuedWeapon); |
| 393 | } |
| 394 | |
| 395 | void CCharacter::HandleWeaponSwitch() |
| 396 | { |
| 397 | int WantedWeapon = m_Core.m_ActiveWeapon; |
| 398 | if(m_QueuedWeapon != -1) |
| 399 | WantedWeapon = m_QueuedWeapon; |
| 400 | |
| 401 | bool Anything = false; |
| 402 | for(int i = 0; i < NUM_WEAPONS - 1; ++i) |
| 403 | if(m_Core.m_aWeapons[i].m_Got) |
| 404 | Anything = true; |
| 405 | if(!Anything) |
| 406 | return; |
| 407 | // select Weapon |
| 408 | int Next = CountInput(Prev: m_LatestPrevInput.m_NextWeapon, Cur: m_LatestInput.m_NextWeapon).m_Presses; |
| 409 | int Prev = CountInput(Prev: m_LatestPrevInput.m_PrevWeapon, Cur: m_LatestInput.m_PrevWeapon).m_Presses; |
| 410 | |
| 411 | if(Next < 128) // make sure we only try sane stuff |
| 412 | { |
| 413 | while(Next) // Next Weapon selection |
| 414 | { |
| 415 | WantedWeapon = (WantedWeapon + 1) % NUM_WEAPONS; |
| 416 | if(m_Core.m_aWeapons[WantedWeapon].m_Got) |
| 417 | Next--; |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | if(Prev < 128) // make sure we only try sane stuff |
| 422 | { |
| 423 | while(Prev) // Prev Weapon selection |
| 424 | { |
| 425 | WantedWeapon = (WantedWeapon - 1) < 0 ? NUM_WEAPONS - 1 : WantedWeapon - 1; |
| 426 | if(m_Core.m_aWeapons[WantedWeapon].m_Got) |
| 427 | Prev--; |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | // Direct Weapon selection |
| 432 | if(m_LatestInput.m_WantedWeapon) |
| 433 | WantedWeapon = m_Input.m_WantedWeapon - 1; |
| 434 | |
| 435 | // check for insane values |
| 436 | if(WantedWeapon >= 0 && WantedWeapon < NUM_WEAPONS && WantedWeapon != m_Core.m_ActiveWeapon && m_Core.m_aWeapons[WantedWeapon].m_Got) |
| 437 | m_QueuedWeapon = WantedWeapon; |
| 438 | |
| 439 | DoWeaponSwitch(); |
| 440 | } |
| 441 | |
| 442 | void CCharacter::FireWeapon() |
| 443 | { |
| 444 | if(m_ReloadTimer != 0) |
| 445 | { |
| 446 | if(m_LatestInput.m_Fire & 1) |
| 447 | { |
| 448 | Antibot()->OnHammerFireReloading(ClientId: m_pPlayer->GetCid()); |
| 449 | } |
| 450 | return; |
| 451 | } |
| 452 | |
| 453 | DoWeaponSwitch(); |
| 454 | vec2 MouseTarget = vec2(m_LatestInput.m_TargetX, m_LatestInput.m_TargetY); |
| 455 | vec2 Direction = normalize(v: MouseTarget); |
| 456 | |
| 457 | bool FullAuto = false; |
| 458 | if(m_Core.m_ActiveWeapon == WEAPON_GRENADE || m_Core.m_ActiveWeapon == WEAPON_SHOTGUN || m_Core.m_ActiveWeapon == WEAPON_LASER) |
| 459 | FullAuto = true; |
| 460 | if(m_Core.m_Jetpack && m_Core.m_ActiveWeapon == WEAPON_GUN) |
| 461 | FullAuto = true; |
| 462 | // allow firing directly after coming out of freeze or being unfrozen |
| 463 | // by something |
| 464 | if(m_FrozenLastTick) |
| 465 | FullAuto = true; |
| 466 | |
| 467 | // don't fire hammer when player is deep and sv_deepfly is disabled |
| 468 | if(!g_Config.m_SvDeepfly && m_Core.m_ActiveWeapon == WEAPON_HAMMER && m_Core.m_DeepFrozen) |
| 469 | return; |
| 470 | |
| 471 | // check if we gonna fire |
| 472 | bool WillFire = false; |
| 473 | if(CountInput(Prev: m_LatestPrevInput.m_Fire, Cur: m_LatestInput.m_Fire).m_Presses) |
| 474 | WillFire = true; |
| 475 | |
| 476 | if(FullAuto && (m_LatestInput.m_Fire & 1) && m_Core.m_aWeapons[m_Core.m_ActiveWeapon].m_Ammo) |
| 477 | WillFire = true; |
| 478 | |
| 479 | if(!WillFire) |
| 480 | return; |
| 481 | |
| 482 | if(m_FreezeTime) |
| 483 | { |
| 484 | // Timer stuff to avoid shrieking orchestra caused by unfreeze-plasma |
| 485 | if(m_PainSoundTimer <= 0 && !(m_LatestPrevInput.m_Fire & 1)) |
| 486 | { |
| 487 | m_PainSoundTimer = 1 * Server()->TickSpeed(); |
| 488 | GameServer()->CreateSound(Pos: m_Pos, Sound: SOUND_PLAYER_PAIN_LONG, Mask: TeamMask()); // NOLINT(clang-analyzer-unix.Malloc) |
| 489 | } |
| 490 | return; |
| 491 | } |
| 492 | |
| 493 | // check for ammo |
| 494 | if(!m_Core.m_aWeapons[m_Core.m_ActiveWeapon].m_Ammo) |
| 495 | return; |
| 496 | |
| 497 | vec2 ProjStartPos = m_Pos + Direction * GetProximityRadius() * 0.75f; |
| 498 | |
| 499 | switch(m_Core.m_ActiveWeapon) |
| 500 | { |
| 501 | case WEAPON_HAMMER: |
| 502 | { |
| 503 | GameServer()->CreateSound(Pos: m_Pos, Sound: SOUND_HAMMER_FIRE, Mask: TeamMask()); // NOLINT(clang-analyzer-unix.Malloc) |
| 504 | |
| 505 | Antibot()->OnHammerFire(ClientId: m_pPlayer->GetCid()); |
| 506 | |
| 507 | if(m_Core.m_HammerHitDisabled) |
| 508 | break; |
| 509 | |
| 510 | CEntity *apEnts[MAX_CLIENTS]; |
| 511 | int Hits = 0; |
| 512 | int Num = GameServer()->m_World.FindEntities(Pos: ProjStartPos, Radius: GetProximityRadius() * 0.5f, ppEnts: apEnts, |
| 513 | Max: MAX_CLIENTS, Type: CGameWorld::ENTTYPE_CHARACTER); |
| 514 | |
| 515 | for(int i = 0; i < Num; ++i) |
| 516 | { |
| 517 | auto *pTarget = static_cast<CCharacter *>(apEnts[i]); |
| 518 | |
| 519 | if((pTarget == this || (pTarget->IsAlive() && !CanCollide(ClientId: pTarget->GetPlayer()->GetCid())))) |
| 520 | continue; |
| 521 | |
| 522 | // set his velocity to fast upward (for now) |
| 523 | if(length(a: pTarget->m_Pos - ProjStartPos) > 0.0f) |
| 524 | GameServer()->CreateHammerHit(Pos: pTarget->m_Pos - normalize(v: pTarget->m_Pos - ProjStartPos) * GetProximityRadius() * 0.5f, Mask: TeamMask()); |
| 525 | else |
| 526 | GameServer()->CreateHammerHit(Pos: ProjStartPos, Mask: TeamMask()); |
| 527 | |
| 528 | vec2 Dir; |
| 529 | if(length(a: pTarget->m_Pos - m_Pos) > 0.0f) |
| 530 | Dir = normalize(v: pTarget->m_Pos - m_Pos); |
| 531 | else |
| 532 | Dir = vec2(0.f, -1.f); |
| 533 | |
| 534 | float Strength = GetTuning(Zone: m_TuneZone)->m_HammerStrength; |
| 535 | |
| 536 | vec2 Temp = pTarget->m_Core.m_Vel + normalize(v: Dir + vec2(0.f, -1.1f)) * 10.0f; |
| 537 | Temp = ClampVel(MoveRestriction: pTarget->m_MoveRestrictions, Vel: Temp); |
| 538 | Temp -= pTarget->m_Core.m_Vel; |
| 539 | pTarget->TakeDamage(Force: (vec2(0.f, -1.0f) + Temp) * Strength, Dmg: g_pData->m_Weapons.m_Hammer.m_pBase->m_Damage, |
| 540 | From: m_pPlayer->GetCid(), Weapon: m_Core.m_ActiveWeapon); |
| 541 | pTarget->UnFreeze(); |
| 542 | |
| 543 | Antibot()->OnHammerHit(ClientId: m_pPlayer->GetCid(), TargetId: pTarget->GetPlayer()->GetCid()); |
| 544 | |
| 545 | Hits++; |
| 546 | } |
| 547 | |
| 548 | // if we Hit anything, we have to wait for the reload |
| 549 | if(Hits) |
| 550 | { |
| 551 | float FireDelay = GetTuning(Zone: m_TuneZone)->m_HammerHitFireDelay; |
| 552 | m_ReloadTimer = FireDelay * Server()->TickSpeed() / 1000; |
| 553 | } |
| 554 | } |
| 555 | break; |
| 556 | |
| 557 | case WEAPON_GUN: |
| 558 | { |
| 559 | if(!m_Core.m_Jetpack || !m_pPlayer->m_NinjaJetpack || m_Core.m_HasTelegunGun) |
| 560 | { |
| 561 | int Lifetime = (int)(Server()->TickSpeed() * GetTuning(Zone: m_TuneZone)->m_GunLifetime); |
| 562 | |
| 563 | new CProjectile( |
| 564 | GameWorld(), |
| 565 | WEAPON_GUN, //Type |
| 566 | m_pPlayer->GetCid(), //Owner |
| 567 | ProjStartPos, //Pos |
| 568 | Direction, //Dir |
| 569 | Lifetime, //Span |
| 570 | false, //Freeze |
| 571 | false, //Explosive |
| 572 | -1, //SoundImpact |
| 573 | MouseTarget //InitDir |
| 574 | ); |
| 575 | |
| 576 | GameServer()->CreateSound(Pos: m_Pos, Sound: SOUND_GUN_FIRE, Mask: TeamMask()); // NOLINT(clang-analyzer-unix.Malloc) |
| 577 | } |
| 578 | } |
| 579 | break; |
| 580 | |
| 581 | case WEAPON_SHOTGUN: |
| 582 | { |
| 583 | float LaserReach = GetTuning(Zone: m_TuneZone)->m_LaserReach; |
| 584 | |
| 585 | new CLaser(&GameServer()->m_World, m_Pos, Direction, LaserReach, m_pPlayer->GetCid(), WEAPON_SHOTGUN); |
| 586 | GameServer()->CreateSound(Pos: m_Pos, Sound: SOUND_SHOTGUN_FIRE, Mask: TeamMask()); // NOLINT(clang-analyzer-unix.Malloc) |
| 587 | } |
| 588 | break; |
| 589 | |
| 590 | case WEAPON_GRENADE: |
| 591 | { |
| 592 | int Lifetime = (int)(Server()->TickSpeed() * GetTuning(Zone: m_TuneZone)->m_GrenadeLifetime); |
| 593 | |
| 594 | new CProjectile( |
| 595 | GameWorld(), |
| 596 | WEAPON_GRENADE, //Type |
| 597 | m_pPlayer->GetCid(), //Owner |
| 598 | ProjStartPos, //Pos |
| 599 | Direction, //Dir |
| 600 | Lifetime, //Span |
| 601 | false, //Freeze |
| 602 | true, //Explosive |
| 603 | SOUND_GRENADE_EXPLODE, //SoundImpact |
| 604 | MouseTarget // MouseTarget |
| 605 | ); |
| 606 | |
| 607 | GameServer()->CreateSound(Pos: m_Pos, Sound: SOUND_GRENADE_FIRE, Mask: TeamMask()); // NOLINT(clang-analyzer-unix.Malloc) |
| 608 | } |
| 609 | break; |
| 610 | |
| 611 | case WEAPON_LASER: |
| 612 | { |
| 613 | float LaserReach = GetTuning(Zone: m_TuneZone)->m_LaserReach; |
| 614 | |
| 615 | new CLaser(GameWorld(), m_Pos, Direction, LaserReach, m_pPlayer->GetCid(), WEAPON_LASER); |
| 616 | GameServer()->CreateSound(Pos: m_Pos, Sound: SOUND_LASER_FIRE, Mask: TeamMask()); // NOLINT(clang-analyzer-unix.Malloc) |
| 617 | } |
| 618 | break; |
| 619 | |
| 620 | case WEAPON_NINJA: |
| 621 | { |
| 622 | // reset Hit objects |
| 623 | m_NumObjectsHit = 0; |
| 624 | |
| 625 | m_Core.m_Ninja.m_ActivationDir = Direction; |
| 626 | m_Core.m_Ninja.m_CurrentMoveTime = g_pData->m_Weapons.m_Ninja.m_Movetime * Server()->TickSpeed() / 1000; |
| 627 | |
| 628 | // clamp to prevent massive MoveBox calculation lag with SG bug |
| 629 | m_Core.m_Ninja.m_OldVelAmount = std::clamp(val: length(a: m_Core.m_Vel), lo: 0.0f, hi: 6000.0f); |
| 630 | |
| 631 | GameServer()->CreateSound(Pos: m_Pos, Sound: SOUND_NINJA_FIRE, Mask: TeamMask()); // NOLINT(clang-analyzer-unix.Malloc) |
| 632 | } |
| 633 | break; |
| 634 | } |
| 635 | |
| 636 | m_AttackTick = Server()->Tick(); |
| 637 | |
| 638 | if(!m_ReloadTimer) |
| 639 | { |
| 640 | float FireDelay; |
| 641 | GetTuning(Zone: m_TuneZone)->Get(offsetof(CTuningParams, m_HammerFireDelay) / sizeof(CTuneParam) + m_Core.m_ActiveWeapon, pValue: &FireDelay); |
| 642 | m_ReloadTimer = FireDelay * Server()->TickSpeed() / 1000; |
| 643 | } |
| 644 | } |
| 645 | |
| 646 | void CCharacter::HandleWeapons() |
| 647 | { |
| 648 | //ninja |
| 649 | HandleNinja(); |
| 650 | HandleJetpack(); |
| 651 | |
| 652 | if(m_PainSoundTimer > 0) |
| 653 | m_PainSoundTimer--; |
| 654 | |
| 655 | // check reload timer |
| 656 | if(m_ReloadTimer) |
| 657 | { |
| 658 | m_ReloadTimer--; |
| 659 | return; |
| 660 | } |
| 661 | |
| 662 | // fire Weapon, if wanted |
| 663 | FireWeapon(); |
| 664 | } |
| 665 | |
| 666 | void CCharacter::GiveNinja() |
| 667 | { |
| 668 | m_Core.m_Ninja.m_ActivationTick = Server()->Tick(); |
| 669 | m_Core.m_aWeapons[WEAPON_NINJA].m_Got = true; |
| 670 | m_Core.m_aWeapons[WEAPON_NINJA].m_Ammo = -1; |
| 671 | if(m_Core.m_ActiveWeapon != WEAPON_NINJA) |
| 672 | m_LastWeapon = m_Core.m_ActiveWeapon; |
| 673 | m_Core.m_ActiveWeapon = WEAPON_NINJA; |
| 674 | |
| 675 | if(!m_Core.m_aWeapons[WEAPON_NINJA].m_Got) |
| 676 | GameServer()->CreateSound(Pos: m_Pos, Sound: SOUND_PICKUP_NINJA, Mask: TeamMask()); |
| 677 | } |
| 678 | |
| 679 | void CCharacter::RemoveNinja() |
| 680 | { |
| 681 | m_Core.m_Ninja.m_ActivationDir = vec2(0, 0); |
| 682 | m_Core.m_Ninja.m_ActivationTick = 0; |
| 683 | m_Core.m_Ninja.m_CurrentMoveTime = 0; |
| 684 | m_Core.m_Ninja.m_OldVelAmount = 0; |
| 685 | m_Core.m_aWeapons[WEAPON_NINJA].m_Got = false; |
| 686 | m_Core.m_aWeapons[WEAPON_NINJA].m_Ammo = 0; |
| 687 | m_Core.m_ActiveWeapon = m_LastWeapon; |
| 688 | |
| 689 | SetWeapon(m_Core.m_ActiveWeapon); |
| 690 | } |
| 691 | |
| 692 | void CCharacter::SetEmote(int Emote, int Tick) |
| 693 | { |
| 694 | m_EmoteType = Emote; |
| 695 | m_EmoteStop = Tick; |
| 696 | } |
| 697 | |
| 698 | int CCharacter::DetermineEyeEmote() |
| 699 | { |
| 700 | const bool IsFrozen = m_Core.m_DeepFrozen || m_FreezeTime > 0 || m_Core.m_LiveFrozen; |
| 701 | const bool HasNinjajetpack = m_pPlayer->m_NinjaJetpack && m_Core.m_Jetpack && m_Core.m_ActiveWeapon == WEAPON_GUN; |
| 702 | |
| 703 | if(GetPlayer()->IsAfk() || GetPlayer()->IsPaused()) |
| 704 | return IsFrozen ? EMOTE_NORMAL : EMOTE_BLINK; |
| 705 | if(m_EmoteType != EMOTE_NORMAL) // user manually set an eye emote using /emote |
| 706 | return m_EmoteType; |
| 707 | if(IsFrozen) |
| 708 | return (m_Core.m_DeepFrozen || m_Core.m_LiveFrozen) ? EMOTE_PAIN : EMOTE_BLINK; |
| 709 | if(HasNinjajetpack && !m_Core.m_DeepFrozen && m_FreezeTime == 0 && !m_Core.m_HasTelegunGun) |
| 710 | return EMOTE_HAPPY; |
| 711 | if(5 * Server()->TickSpeed() - ((Server()->Tick() - m_LastAction) % (5 * Server()->TickSpeed())) < 5) |
| 712 | return EMOTE_BLINK; |
| 713 | return EMOTE_NORMAL; |
| 714 | } |
| 715 | |
| 716 | void CCharacter::OnPredictedInput(const CNetObj_PlayerInput *pNewInput) |
| 717 | { |
| 718 | // check for changes |
| 719 | if(mem_comp(a: &m_SavedInput, b: pNewInput, size: sizeof(CNetObj_PlayerInput)) != 0) |
| 720 | m_LastAction = Server()->Tick(); |
| 721 | |
| 722 | // copy new input |
| 723 | mem_copy(dest: &m_Input, source: pNewInput, size: sizeof(m_Input)); |
| 724 | |
| 725 | // it is not allowed to aim in the center |
| 726 | if(m_Input.m_TargetX == 0 && m_Input.m_TargetY == 0) |
| 727 | m_Input.m_TargetY = -1; |
| 728 | |
| 729 | mem_copy(dest: &m_SavedInput, source: &m_Input, size: sizeof(m_SavedInput)); |
| 730 | } |
| 731 | |
| 732 | void CCharacter::OnDirectInput(const CNetObj_PlayerInput *pNewInput) |
| 733 | { |
| 734 | mem_copy(dest: &m_LatestPrevInput, source: &m_LatestInput, size: sizeof(m_LatestInput)); |
| 735 | mem_copy(dest: &m_LatestInput, source: pNewInput, size: sizeof(m_LatestInput)); |
| 736 | m_NumInputs++; |
| 737 | |
| 738 | // it is not allowed to aim in the center |
| 739 | if(m_LatestInput.m_TargetX == 0 && m_LatestInput.m_TargetY == 0) |
| 740 | m_LatestInput.m_TargetY = -1; |
| 741 | |
| 742 | Antibot()->OnDirectInput(ClientId: m_pPlayer->GetCid()); |
| 743 | |
| 744 | if(m_NumInputs > 1 && m_pPlayer->GetTeam() != TEAM_SPECTATORS) |
| 745 | { |
| 746 | HandleWeaponSwitch(); |
| 747 | FireWeapon(); |
| 748 | } |
| 749 | |
| 750 | mem_copy(dest: &m_LatestPrevPrevInput, source: &m_LatestPrevInput, size: sizeof(m_LatestInput)); |
| 751 | mem_copy(dest: &m_LatestPrevInput, source: &m_LatestInput, size: sizeof(m_LatestInput)); |
| 752 | } |
| 753 | |
| 754 | void CCharacter::ReleaseHook() |
| 755 | { |
| 756 | m_Core.SetHookedPlayer(-1); |
| 757 | m_Core.m_HookState = HOOK_RETRACTED; |
| 758 | m_Core.m_TriggeredEvents |= COREEVENT_HOOK_RETRACT; |
| 759 | } |
| 760 | |
| 761 | void CCharacter::ResetHook() |
| 762 | { |
| 763 | ReleaseHook(); |
| 764 | m_Core.m_HookPos = m_Core.m_Pos; |
| 765 | } |
| 766 | |
| 767 | void CCharacter::ResetInput() |
| 768 | { |
| 769 | m_Input.m_Direction = 0; |
| 770 | // simulate releasing the fire button |
| 771 | if((m_Input.m_Fire & 1) != 0) |
| 772 | m_Input.m_Fire++; |
| 773 | m_Input.m_Fire &= INPUT_STATE_MASK; |
| 774 | m_Input.m_Jump = 0; |
| 775 | m_LatestPrevInput = m_LatestInput = m_Input; |
| 776 | } |
| 777 | |
| 778 | void CCharacter::PreTick() |
| 779 | { |
| 780 | if(m_StartTime > Server()->Tick()) |
| 781 | { |
| 782 | // Prevent the player from getting a negative time |
| 783 | // The main reason why this can happen is because of time penalty tiles |
| 784 | // However, other reasons are hereby also excluded |
| 785 | GameServer()->SendChatTarget(To: m_pPlayer->GetCid(), pText: "You died of old age" ); |
| 786 | Die(Killer: m_pPlayer->GetCid(), Weapon: WEAPON_WORLD); |
| 787 | } |
| 788 | |
| 789 | if(m_Paused) |
| 790 | return; |
| 791 | |
| 792 | // set emote |
| 793 | if(m_EmoteStop < Server()->Tick()) |
| 794 | { |
| 795 | SetEmote(Emote: m_pPlayer->GetDefaultEmote(), Tick: -1); |
| 796 | } |
| 797 | |
| 798 | DDRaceTick(); |
| 799 | |
| 800 | Antibot()->OnCharacterTick(ClientId: m_pPlayer->GetCid()); |
| 801 | |
| 802 | m_Core.m_Input = m_Input; |
| 803 | m_Core.Tick(UseInput: true, DoDeferredTick: !g_Config.m_SvNoWeakHook); |
| 804 | } |
| 805 | |
| 806 | void CCharacter::Tick() |
| 807 | { |
| 808 | if(g_Config.m_SvNoWeakHook) |
| 809 | { |
| 810 | if(m_Paused) |
| 811 | return; |
| 812 | |
| 813 | m_Core.TickDeferred(); |
| 814 | } |
| 815 | else |
| 816 | { |
| 817 | PreTick(); |
| 818 | } |
| 819 | |
| 820 | if(!m_PrevInput.m_Hook && m_Input.m_Hook && !(m_Core.m_TriggeredEvents & COREEVENT_HOOK_ATTACH_PLAYER)) |
| 821 | { |
| 822 | Antibot()->OnHookAttach(ClientId: m_pPlayer->GetCid(), Player: false); |
| 823 | } |
| 824 | |
| 825 | // handle Weapons |
| 826 | HandleWeapons(); |
| 827 | |
| 828 | DDRacePostCoreTick(); |
| 829 | |
| 830 | if(m_Core.m_TriggeredEvents & COREEVENT_HOOK_ATTACH_PLAYER) |
| 831 | { |
| 832 | const int HookedPlayer = m_Core.HookedPlayer(); |
| 833 | if(HookedPlayer != -1 && GameServer()->m_apPlayers[HookedPlayer]->GetTeam() != TEAM_SPECTATORS) |
| 834 | { |
| 835 | Antibot()->OnHookAttach(ClientId: m_pPlayer->GetCid(), Player: true); |
| 836 | } |
| 837 | } |
| 838 | |
| 839 | // Previnput |
| 840 | m_PrevInput = m_Input; |
| 841 | |
| 842 | m_PrevPos = m_Core.m_Pos; |
| 843 | } |
| 844 | |
| 845 | void CCharacter::TickDeferred() |
| 846 | { |
| 847 | // advance the dummy |
| 848 | { |
| 849 | CWorldCore TempWorld; |
| 850 | m_ReckoningCore.Init(pWorld: &TempWorld, pCollision: Collision(), pTeams: &Teams()->m_Core); |
| 851 | m_ReckoningCore.m_Id = m_pPlayer->GetCid(); |
| 852 | m_ReckoningCore.m_Tuning = CTuningParams(); |
| 853 | m_ReckoningCore.Tick(UseInput: false); |
| 854 | m_ReckoningCore.Move(); |
| 855 | m_ReckoningCore.Quantize(); |
| 856 | } |
| 857 | |
| 858 | //lastsentcore |
| 859 | vec2 StartPos = m_Core.m_Pos; |
| 860 | vec2 StartVel = m_Core.m_Vel; |
| 861 | bool StuckBefore = Collision()->TestBox(Pos: m_Core.m_Pos, Size: CCharacterCore::PhysicalSizeVec2()); |
| 862 | |
| 863 | m_Core.m_Id = m_pPlayer->GetCid(); |
| 864 | m_Core.Move(); |
| 865 | bool StuckAfterMove = Collision()->TestBox(Pos: m_Core.m_Pos, Size: CCharacterCore::PhysicalSizeVec2()); |
| 866 | m_Core.Quantize(); |
| 867 | bool StuckAfterQuant = Collision()->TestBox(Pos: m_Core.m_Pos, Size: CCharacterCore::PhysicalSizeVec2()); |
| 868 | m_Pos = m_Core.m_Pos; |
| 869 | |
| 870 | if(!StuckBefore && (StuckAfterMove || StuckAfterQuant)) |
| 871 | { |
| 872 | // Hackish solution to get rid of strict-aliasing warning |
| 873 | union |
| 874 | { |
| 875 | float f; |
| 876 | unsigned u; |
| 877 | } StartPosX, StartPosY, StartVelX, StartVelY; |
| 878 | |
| 879 | StartPosX.f = StartPos.x; |
| 880 | StartPosY.f = StartPos.y; |
| 881 | StartVelX.f = StartVel.x; |
| 882 | StartVelY.f = StartVel.y; |
| 883 | |
| 884 | char aBuf[256]; |
| 885 | str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "STUCK!!! %d %d %d %f %f %f %f %x %x %x %x" , |
| 886 | StuckBefore, |
| 887 | StuckAfterMove, |
| 888 | StuckAfterQuant, |
| 889 | StartPos.x, StartPos.y, |
| 890 | StartVel.x, StartVel.y, |
| 891 | StartPosX.u, StartPosY.u, |
| 892 | StartVelX.u, StartVelY.u); |
| 893 | GameServer()->Console()->Print(Level: IConsole::OUTPUT_LEVEL_DEBUG, pFrom: "game" , pStr: aBuf); |
| 894 | } |
| 895 | |
| 896 | { |
| 897 | int Events = m_Core.m_TriggeredEvents; |
| 898 | int CID = m_pPlayer->GetCid(); |
| 899 | |
| 900 | // Some sounds are triggered client-side for the acting player (or for all players on Sixup) |
| 901 | // so we need to avoid duplicating them |
| 902 | CClientMask TeamMaskExceptSelfAndSixup = Teams()->TeamMask(Team: Team(), ExceptId: CID, Asker: CID, VersionFlags: CGameContext::FLAG_SIX); |
| 903 | // Some are triggered client-side but only on Sixup |
| 904 | CClientMask TeamMaskExceptSixup = Teams()->TeamMask(Team: Team(), ExceptId: -1, Asker: CID, VersionFlags: CGameContext::FLAG_SIX); |
| 905 | |
| 906 | if(Events & COREEVENT_GROUND_JUMP) |
| 907 | GameServer()->CreateSound(Pos: m_Pos, Sound: SOUND_PLAYER_JUMP, Mask: TeamMaskExceptSelfAndSixup); |
| 908 | |
| 909 | if(Events & COREEVENT_HOOK_ATTACH_PLAYER) |
| 910 | GameServer()->CreateSound(Pos: m_Pos, Sound: SOUND_HOOK_ATTACH_PLAYER, Mask: TeamMaskExceptSixup); |
| 911 | |
| 912 | if(Events & COREEVENT_HOOK_ATTACH_GROUND) |
| 913 | GameServer()->CreateSound(Pos: m_Pos, Sound: SOUND_HOOK_ATTACH_GROUND, Mask: TeamMaskExceptSelfAndSixup); |
| 914 | |
| 915 | if(Events & COREEVENT_HOOK_HIT_NOHOOK) |
| 916 | GameServer()->CreateSound(Pos: m_Pos, Sound: SOUND_HOOK_NOATTACH, Mask: TeamMaskExceptSelfAndSixup); |
| 917 | |
| 918 | if(Events & COREEVENT_GROUND_JUMP) |
| 919 | m_TriggeredEvents7 |= protocol7::COREEVENTFLAG_GROUND_JUMP; |
| 920 | if(Events & COREEVENT_AIR_JUMP) |
| 921 | m_TriggeredEvents7 |= protocol7::COREEVENTFLAG_AIR_JUMP; |
| 922 | if(Events & COREEVENT_HOOK_ATTACH_PLAYER) |
| 923 | m_TriggeredEvents7 |= protocol7::COREEVENTFLAG_HOOK_ATTACH_PLAYER; |
| 924 | if(Events & COREEVENT_HOOK_ATTACH_GROUND) |
| 925 | m_TriggeredEvents7 |= protocol7::COREEVENTFLAG_HOOK_ATTACH_GROUND; |
| 926 | if(Events & COREEVENT_HOOK_HIT_NOHOOK) |
| 927 | m_TriggeredEvents7 |= protocol7::COREEVENTFLAG_HOOK_HIT_NOHOOK; |
| 928 | } |
| 929 | |
| 930 | if(m_pPlayer->GetTeam() == TEAM_SPECTATORS) |
| 931 | { |
| 932 | m_Pos.x = m_Input.m_TargetX; |
| 933 | m_Pos.y = m_Input.m_TargetY; |
| 934 | } |
| 935 | |
| 936 | // update the m_SendCore if needed |
| 937 | { |
| 938 | CNetObj_Character Predicted; |
| 939 | CNetObj_Character Current; |
| 940 | mem_zero(block: &Predicted, size: sizeof(Predicted)); |
| 941 | mem_zero(block: &Current, size: sizeof(Current)); |
| 942 | m_ReckoningCore.Write(pObjCore: &Predicted); |
| 943 | m_Core.Write(pObjCore: &Current); |
| 944 | |
| 945 | // only allow dead reckoning for a top of 3 seconds |
| 946 | if(m_Core.m_Reset || m_ReckoningTick + Server()->TickSpeed() * 3 < Server()->Tick() || mem_comp(a: &Predicted, b: &Current, size: sizeof(CNetObj_Character)) != 0) |
| 947 | { |
| 948 | m_ReckoningTick = Server()->Tick(); |
| 949 | m_SendCore = m_Core; |
| 950 | m_ReckoningCore = m_Core; |
| 951 | m_Core.m_Reset = false; |
| 952 | } |
| 953 | } |
| 954 | } |
| 955 | |
| 956 | void CCharacter::TickPaused() |
| 957 | { |
| 958 | ++m_AttackTick; |
| 959 | ++m_DamageTakenTick; |
| 960 | ++m_Core.m_Ninja.m_ActivationTick; |
| 961 | ++m_ReckoningTick; |
| 962 | if(m_LastAction != -1) |
| 963 | ++m_LastAction; |
| 964 | if(m_Core.m_aWeapons[m_Core.m_ActiveWeapon].m_AmmoRegenStart > -1) |
| 965 | ++m_Core.m_aWeapons[m_Core.m_ActiveWeapon].m_AmmoRegenStart; |
| 966 | if(m_EmoteStop > -1) |
| 967 | ++m_EmoteStop; |
| 968 | } |
| 969 | |
| 970 | bool CCharacter::IncreaseHealth(int Amount) |
| 971 | { |
| 972 | if(m_Health >= 10) |
| 973 | return false; |
| 974 | m_Health = std::clamp(val: m_Health + Amount, lo: 0, hi: 10); |
| 975 | return true; |
| 976 | } |
| 977 | |
| 978 | bool CCharacter::IncreaseArmor(int Amount) |
| 979 | { |
| 980 | if(m_Armor >= 10) |
| 981 | return false; |
| 982 | m_Armor = std::clamp(val: m_Armor + Amount, lo: 0, hi: 10); |
| 983 | return true; |
| 984 | } |
| 985 | |
| 986 | void CCharacter::StopRecording() |
| 987 | { |
| 988 | if(Server()->IsRecording(ClientId: m_pPlayer->GetCid())) |
| 989 | { |
| 990 | CPlayerData *pData = GameServer()->Score()->PlayerData(Id: m_pPlayer->GetCid()); |
| 991 | |
| 992 | if(pData->m_RecordStopTick - Server()->Tick() <= Server()->TickSpeed() && pData->m_RecordStopTick != -1) |
| 993 | Server()->SaveDemo(ClientId: m_pPlayer->GetCid(), Time: pData->m_RecordFinishTime); |
| 994 | else |
| 995 | Server()->StopRecord(ClientId: m_pPlayer->GetCid()); |
| 996 | |
| 997 | pData->m_RecordStopTick = -1; |
| 998 | } |
| 999 | } |
| 1000 | |
| 1001 | void CCharacter::Die(int Killer, int Weapon, bool SendKillMsg) |
| 1002 | { |
| 1003 | if(Killer != WEAPON_GAME && m_SetSavePos[RESCUEMODE_AUTO]) |
| 1004 | GetPlayer()->m_LastDeath = m_RescueTee[RESCUEMODE_AUTO]; |
| 1005 | StopRecording(); |
| 1006 | int ModeSpecial = GameServer()->m_pController->OnCharacterDeath(pVictim: this, pKiller: GameServer()->m_apPlayers[Killer], Weapon); |
| 1007 | |
| 1008 | log_info("game" , "kill killer='%d:%s' victim='%d:%s' weapon=%d special=%d" , |
| 1009 | Killer, Server()->ClientName(Killer), |
| 1010 | m_pPlayer->GetCid(), Server()->ClientName(m_pPlayer->GetCid()), Weapon, ModeSpecial); |
| 1011 | |
| 1012 | if(SendKillMsg) |
| 1013 | { |
| 1014 | SendDeathMessageIfNotInLockedTeam(Killer, Weapon, ModeSpecial); |
| 1015 | } |
| 1016 | |
| 1017 | // a nice sound, and bursting tee death effect |
| 1018 | GameServer()->CreateSound(Pos: m_Pos, Sound: SOUND_PLAYER_DIE, Mask: TeamMask()); |
| 1019 | GameServer()->CreateDeath(Pos: m_Pos, ClientId: m_pPlayer->GetCid(), Mask: TeamMask()); |
| 1020 | |
| 1021 | // this is to rate limit respawning to 3 secs |
| 1022 | m_pPlayer->m_PreviousDieTick = m_pPlayer->m_DieTick; |
| 1023 | m_pPlayer->m_DieTick = Server()->Tick(); |
| 1024 | |
| 1025 | m_Alive = false; |
| 1026 | SetSolo(false); |
| 1027 | |
| 1028 | GameServer()->m_World.RemoveEntity(pEntity: this); |
| 1029 | GameServer()->m_World.m_Core.m_apCharacters[m_pPlayer->GetCid()] = nullptr; |
| 1030 | Teams()->OnCharacterDeath(ClientId: GetPlayer()->GetCid(), Weapon); |
| 1031 | CancelSwapRequests(); |
| 1032 | } |
| 1033 | |
| 1034 | bool CCharacter::TakeDamage(vec2 Force, int Dmg, int From, int Weapon) |
| 1035 | { |
| 1036 | if(Dmg) |
| 1037 | { |
| 1038 | SetEmote(Emote: EMOTE_PAIN, Tick: Server()->Tick() + 500 * Server()->TickSpeed() / 1000); |
| 1039 | } |
| 1040 | |
| 1041 | vec2 Temp = m_Core.m_Vel + Force; |
| 1042 | m_Core.m_Vel = ClampVel(MoveRestriction: m_MoveRestrictions, Vel: Temp); |
| 1043 | |
| 1044 | return true; |
| 1045 | } |
| 1046 | |
| 1047 | void CCharacter::SendDeathMessageIfNotInLockedTeam(int Killer, int Weapon, int ModeSpecial) |
| 1048 | { |
| 1049 | if((Team() == TEAM_FLOCK || Teams()->TeamFlock(Team: Team()) || Teams()->Count(Team: Team()) == 1 || Teams()->GetTeamState(Team: Team()) == ETeamState::OPEN || !Teams()->TeamLocked(Team: Team()))) |
| 1050 | { |
| 1051 | CNetMsg_Sv_KillMsg Msg; |
| 1052 | Msg.m_Killer = Killer; |
| 1053 | Msg.m_Victim = m_pPlayer->GetCid(); |
| 1054 | Msg.m_Weapon = Weapon; |
| 1055 | Msg.m_ModeSpecial = ModeSpecial; |
| 1056 | Server()->SendPackMsg(pMsg: &Msg, Flags: MSGFLAG_VITAL, ClientId: -1); |
| 1057 | } |
| 1058 | } |
| 1059 | |
| 1060 | void CCharacter::CancelSwapRequests() |
| 1061 | { |
| 1062 | for(auto &pPlayer : GameServer()->m_apPlayers) |
| 1063 | { |
| 1064 | if(pPlayer && pPlayer->m_SwapTargetsClientId == GetPlayer()->GetCid()) |
| 1065 | pPlayer->m_SwapTargetsClientId = -1; |
| 1066 | } |
| 1067 | GetPlayer()->m_SwapTargetsClientId = -1; |
| 1068 | } |
| 1069 | |
| 1070 | void CCharacter::SnapCharacter(int SnappingClient, int Id) |
| 1071 | { |
| 1072 | int SnappingClientVersion = GameServer()->GetClientVersion(ClientId: SnappingClient); |
| 1073 | CCharacterCore *pCore; |
| 1074 | int Weapon = m_Core.m_ActiveWeapon, AmmoCount = 0, |
| 1075 | Health = 0, Armor = 0; |
| 1076 | int Emote = DetermineEyeEmote(); |
| 1077 | int Tick; |
| 1078 | if(!m_ReckoningTick || GameServer()->m_World.m_Paused) |
| 1079 | { |
| 1080 | Tick = 0; |
| 1081 | pCore = &m_Core; |
| 1082 | } |
| 1083 | else |
| 1084 | { |
| 1085 | Tick = m_ReckoningTick; |
| 1086 | pCore = &m_SendCore; |
| 1087 | } |
| 1088 | |
| 1089 | // use ninja graphic for old clients if player is frozen |
| 1090 | if(m_Core.m_DeepFrozen || m_FreezeTime > 0 || m_Core.m_LiveFrozen) |
| 1091 | { |
| 1092 | if((m_Core.m_DeepFrozen || m_FreezeTime > 0) && SnappingClientVersion < VERSION_DDNET_NEW_HUD) |
| 1093 | Weapon = WEAPON_NINJA; |
| 1094 | } |
| 1095 | |
| 1096 | // solo, collision, jetpack and ninjajetpack prediction |
| 1097 | if(m_pPlayer->GetCid() == SnappingClient) |
| 1098 | { |
| 1099 | int Faketuning = 0; |
| 1100 | if(m_pPlayer->GetClientVersion() < VERSION_DDNET_NEW_HUD) |
| 1101 | { |
| 1102 | if(m_Core.m_Jetpack && Weapon != WEAPON_NINJA) |
| 1103 | Faketuning |= FAKETUNE_JETPACK; |
| 1104 | if(m_Core.m_Solo) |
| 1105 | Faketuning |= FAKETUNE_SOLO; |
| 1106 | if(m_Core.m_HammerHitDisabled) |
| 1107 | Faketuning |= FAKETUNE_NOHAMMER; |
| 1108 | if(m_Core.m_CollisionDisabled) |
| 1109 | Faketuning |= FAKETUNE_NOCOLL; |
| 1110 | if(m_Core.m_HookHitDisabled) |
| 1111 | Faketuning |= FAKETUNE_NOHOOK; |
| 1112 | if(!m_Core.m_EndlessJump && m_Core.m_Jumps == 0) |
| 1113 | Faketuning |= FAKETUNE_NOJUMP; |
| 1114 | } |
| 1115 | if(Faketuning != m_NeededFaketuning) |
| 1116 | { |
| 1117 | m_NeededFaketuning = Faketuning; |
| 1118 | GameServer()->SendTuningParams(ClientId: m_pPlayer->GetCid(), Zone: m_TuneZone); // update tunings |
| 1119 | } |
| 1120 | } |
| 1121 | |
| 1122 | // use ninja graphic and set ammo count if player has ninjajetpack |
| 1123 | if(m_pPlayer->m_NinjaJetpack && m_Core.m_Jetpack && m_Core.m_ActiveWeapon == WEAPON_GUN && !m_Core.m_DeepFrozen && m_FreezeTime == 0 && !m_Core.m_HasTelegunGun) |
| 1124 | { |
| 1125 | Weapon = WEAPON_NINJA; |
| 1126 | AmmoCount = 10; |
| 1127 | } |
| 1128 | |
| 1129 | if(m_pPlayer->GetCid() == SnappingClient || SnappingClient == SERVER_DEMO_CLIENT || |
| 1130 | (!g_Config.m_SvStrictSpectateMode && m_pPlayer->GetCid() == GameServer()->m_apPlayers[SnappingClient]->SpectatorId())) |
| 1131 | { |
| 1132 | Health = m_Health; |
| 1133 | Armor = m_Armor; |
| 1134 | AmmoCount = (m_FreezeTime == 0) ? m_Core.m_aWeapons[m_Core.m_ActiveWeapon].m_Ammo : 0; |
| 1135 | } |
| 1136 | |
| 1137 | if(!Server()->IsSixup(ClientId: SnappingClient)) |
| 1138 | { |
| 1139 | CNetObj_Character *pCharacter = Server()->SnapNewItem<CNetObj_Character>(Id); |
| 1140 | if(!pCharacter) |
| 1141 | return; |
| 1142 | |
| 1143 | pCore->Write(pObjCore: pCharacter); |
| 1144 | |
| 1145 | pCharacter->m_Tick = Tick; |
| 1146 | pCharacter->m_Emote = Emote; |
| 1147 | |
| 1148 | if(pCharacter->m_HookedPlayer != -1) |
| 1149 | { |
| 1150 | if(!Server()->Translate(Target&: pCharacter->m_HookedPlayer, Client: SnappingClient)) |
| 1151 | pCharacter->m_HookedPlayer = -1; |
| 1152 | } |
| 1153 | |
| 1154 | pCharacter->m_AttackTick = m_AttackTick; |
| 1155 | pCharacter->m_Direction = m_Input.m_Direction; |
| 1156 | pCharacter->m_Weapon = Weapon; |
| 1157 | pCharacter->m_AmmoCount = AmmoCount; |
| 1158 | pCharacter->m_Health = Health; |
| 1159 | pCharacter->m_Armor = Armor; |
| 1160 | pCharacter->m_PlayerFlags = GetPlayer()->m_PlayerFlags; |
| 1161 | } |
| 1162 | else |
| 1163 | { |
| 1164 | protocol7::CNetObj_Character *pCharacter = Server()->SnapNewItem<protocol7::CNetObj_Character>(Id); |
| 1165 | if(!pCharacter) |
| 1166 | return; |
| 1167 | |
| 1168 | pCore->Write(pObjCore: reinterpret_cast<CNetObj_CharacterCore *>(static_cast<protocol7::CNetObj_CharacterCore *>(pCharacter))); |
| 1169 | if(pCharacter->m_Angle > (int)(pi * 256.0f)) |
| 1170 | { |
| 1171 | pCharacter->m_Angle -= (int)(2.0f * pi * 256.0f); |
| 1172 | } |
| 1173 | |
| 1174 | // m_HookTick can be negative when using the hook_duration tune, which 0.7 clients |
| 1175 | // will consider invalid. https://github.com/ddnet/ddnet/issues/3915 |
| 1176 | pCharacter->m_HookTick = maximum(a: 0, b: pCharacter->m_HookTick); |
| 1177 | |
| 1178 | pCharacter->m_Tick = Tick; |
| 1179 | pCharacter->m_Emote = Emote; |
| 1180 | pCharacter->m_AttackTick = m_AttackTick; |
| 1181 | pCharacter->m_Direction = m_Input.m_Direction; |
| 1182 | pCharacter->m_Weapon = Weapon; |
| 1183 | pCharacter->m_AmmoCount = AmmoCount; |
| 1184 | |
| 1185 | if(m_FreezeTime > 0 || m_Core.m_DeepFrozen) |
| 1186 | pCharacter->m_AmmoCount = m_Core.m_FreezeStart + g_Config.m_SvFreezeDelay * Server()->TickSpeed(); |
| 1187 | else if(Weapon == WEAPON_NINJA) |
| 1188 | pCharacter->m_AmmoCount = m_Core.m_Ninja.m_ActivationTick + g_pData->m_Weapons.m_Ninja.m_Duration * Server()->TickSpeed() / 1000; |
| 1189 | |
| 1190 | pCharacter->m_Health = Health; |
| 1191 | pCharacter->m_Armor = Armor; |
| 1192 | pCharacter->m_TriggeredEvents = m_TriggeredEvents7; |
| 1193 | } |
| 1194 | } |
| 1195 | |
| 1196 | bool CCharacter::CanSnapCharacter(int SnappingClient) |
| 1197 | { |
| 1198 | if(SnappingClient == SERVER_DEMO_CLIENT) |
| 1199 | return true; |
| 1200 | |
| 1201 | CCharacter *pSnapChar = GameServer()->GetPlayerChar(ClientId: SnappingClient); |
| 1202 | CPlayer *pSnapPlayer = GameServer()->m_apPlayers[SnappingClient]; |
| 1203 | |
| 1204 | if(pSnapPlayer->GetTeam() == TEAM_SPECTATORS || pSnapPlayer->IsPaused()) |
| 1205 | { |
| 1206 | if(pSnapPlayer->SpectatorId() != SPEC_FREEVIEW && !CanCollide(ClientId: pSnapPlayer->SpectatorId()) && (pSnapPlayer->m_ShowOthers == SHOW_OTHERS_OFF || (pSnapPlayer->m_ShowOthers == SHOW_OTHERS_ONLY_TEAM && !SameTeam(ClientId: pSnapPlayer->SpectatorId())))) |
| 1207 | return false; |
| 1208 | else if(pSnapPlayer->SpectatorId() == SPEC_FREEVIEW && !CanCollide(ClientId: SnappingClient) && pSnapPlayer->m_SpecTeam && !SameTeam(ClientId: SnappingClient)) |
| 1209 | return false; |
| 1210 | } |
| 1211 | else if(pSnapChar && !pSnapChar->m_Core.m_Super && !CanCollide(ClientId: SnappingClient) && (pSnapPlayer->m_ShowOthers == SHOW_OTHERS_OFF || (pSnapPlayer->m_ShowOthers == SHOW_OTHERS_ONLY_TEAM && !SameTeam(ClientId: SnappingClient)))) |
| 1212 | return false; |
| 1213 | |
| 1214 | return true; |
| 1215 | } |
| 1216 | |
| 1217 | bool CCharacter::IsSnappingCharacterInView(int SnappingClientId) |
| 1218 | { |
| 1219 | int Id = m_pPlayer->GetCid(); |
| 1220 | |
| 1221 | // A player may not be clipped away if his hook or a hook attached to him is in the field of view |
| 1222 | bool PlayerAndHookNotInView = NetworkClippedLine(SnappingClient: SnappingClientId, StartPos: m_Pos, EndPos: m_Core.m_HookPos); |
| 1223 | bool AttachedHookInView = false; |
| 1224 | if(PlayerAndHookNotInView) |
| 1225 | { |
| 1226 | for(const auto &AttachedPlayerId : m_Core.m_AttachedPlayers) |
| 1227 | { |
| 1228 | const CCharacter *pOtherPlayer = GameServer()->GetPlayerChar(ClientId: AttachedPlayerId); |
| 1229 | if(pOtherPlayer && pOtherPlayer->m_Core.HookedPlayer() == Id) |
| 1230 | { |
| 1231 | if(!NetworkClippedLine(SnappingClient: SnappingClientId, StartPos: m_Pos, EndPos: pOtherPlayer->m_Pos)) |
| 1232 | { |
| 1233 | AttachedHookInView = true; |
| 1234 | break; |
| 1235 | } |
| 1236 | } |
| 1237 | } |
| 1238 | } |
| 1239 | if(PlayerAndHookNotInView && !AttachedHookInView) |
| 1240 | { |
| 1241 | return false; |
| 1242 | } |
| 1243 | return true; |
| 1244 | } |
| 1245 | |
| 1246 | void CCharacter::Snap(int SnappingClient) |
| 1247 | { |
| 1248 | int Id = m_pPlayer->GetCid(); |
| 1249 | |
| 1250 | if(!Server()->Translate(Target&: Id, Client: SnappingClient)) |
| 1251 | return; |
| 1252 | |
| 1253 | if(!CanSnapCharacter(SnappingClient)) |
| 1254 | { |
| 1255 | return; |
| 1256 | } |
| 1257 | |
| 1258 | // always snap the snapping client, even if it is not in view |
| 1259 | if(!IsSnappingCharacterInView(SnappingClientId: SnappingClient) && Id != SnappingClient) |
| 1260 | return; |
| 1261 | |
| 1262 | SnapCharacter(SnappingClient, Id); |
| 1263 | |
| 1264 | CNetObj_DDNetCharacter *pDDNetCharacter = Server()->SnapNewItem<CNetObj_DDNetCharacter>(Id); |
| 1265 | if(!pDDNetCharacter) |
| 1266 | return; |
| 1267 | |
| 1268 | pDDNetCharacter->m_Flags = 0; |
| 1269 | if(m_Core.m_Solo) |
| 1270 | pDDNetCharacter->m_Flags |= CHARACTERFLAG_SOLO; |
| 1271 | if(m_Core.m_Super) |
| 1272 | pDDNetCharacter->m_Flags |= CHARACTERFLAG_SUPER; |
| 1273 | if(m_Core.m_Invincible) |
| 1274 | pDDNetCharacter->m_Flags |= CHARACTERFLAG_INVINCIBLE; |
| 1275 | if(m_Core.m_EndlessHook) |
| 1276 | pDDNetCharacter->m_Flags |= CHARACTERFLAG_ENDLESS_HOOK; |
| 1277 | if(m_Core.m_CollisionDisabled || !GetTuning(Zone: m_TuneZone)->m_PlayerCollision) |
| 1278 | pDDNetCharacter->m_Flags |= CHARACTERFLAG_COLLISION_DISABLED; |
| 1279 | if(m_Core.m_HookHitDisabled || !GetTuning(Zone: m_TuneZone)->m_PlayerHooking) |
| 1280 | pDDNetCharacter->m_Flags |= CHARACTERFLAG_HOOK_HIT_DISABLED; |
| 1281 | if(m_Core.m_EndlessJump) |
| 1282 | pDDNetCharacter->m_Flags |= CHARACTERFLAG_ENDLESS_JUMP; |
| 1283 | if(m_Core.m_Jetpack) |
| 1284 | pDDNetCharacter->m_Flags |= CHARACTERFLAG_JETPACK; |
| 1285 | if(m_Core.m_HammerHitDisabled) |
| 1286 | pDDNetCharacter->m_Flags |= CHARACTERFLAG_HAMMER_HIT_DISABLED; |
| 1287 | if(m_Core.m_ShotgunHitDisabled) |
| 1288 | pDDNetCharacter->m_Flags |= CHARACTERFLAG_SHOTGUN_HIT_DISABLED; |
| 1289 | if(m_Core.m_GrenadeHitDisabled) |
| 1290 | pDDNetCharacter->m_Flags |= CHARACTERFLAG_GRENADE_HIT_DISABLED; |
| 1291 | if(m_Core.m_LaserHitDisabled) |
| 1292 | pDDNetCharacter->m_Flags |= CHARACTERFLAG_LASER_HIT_DISABLED; |
| 1293 | if(m_Core.m_HasTelegunGun) |
| 1294 | pDDNetCharacter->m_Flags |= CHARACTERFLAG_TELEGUN_GUN; |
| 1295 | if(m_Core.m_HasTelegunGrenade) |
| 1296 | pDDNetCharacter->m_Flags |= CHARACTERFLAG_TELEGUN_GRENADE; |
| 1297 | if(m_Core.m_HasTelegunLaser) |
| 1298 | pDDNetCharacter->m_Flags |= CHARACTERFLAG_TELEGUN_LASER; |
| 1299 | if(m_Core.m_aWeapons[WEAPON_HAMMER].m_Got) |
| 1300 | pDDNetCharacter->m_Flags |= CHARACTERFLAG_WEAPON_HAMMER; |
| 1301 | if(m_Core.m_aWeapons[WEAPON_GUN].m_Got) |
| 1302 | pDDNetCharacter->m_Flags |= CHARACTERFLAG_WEAPON_GUN; |
| 1303 | if(m_Core.m_aWeapons[WEAPON_SHOTGUN].m_Got) |
| 1304 | pDDNetCharacter->m_Flags |= CHARACTERFLAG_WEAPON_SHOTGUN; |
| 1305 | if(m_Core.m_aWeapons[WEAPON_GRENADE].m_Got) |
| 1306 | pDDNetCharacter->m_Flags |= CHARACTERFLAG_WEAPON_GRENADE; |
| 1307 | if(m_Core.m_aWeapons[WEAPON_LASER].m_Got) |
| 1308 | pDDNetCharacter->m_Flags |= CHARACTERFLAG_WEAPON_LASER; |
| 1309 | if(m_Core.m_ActiveWeapon == WEAPON_NINJA) |
| 1310 | pDDNetCharacter->m_Flags |= CHARACTERFLAG_WEAPON_NINJA; |
| 1311 | if(m_Core.m_LiveFrozen) |
| 1312 | pDDNetCharacter->m_Flags |= CHARACTERFLAG_MOVEMENTS_DISABLED; |
| 1313 | |
| 1314 | pDDNetCharacter->m_FreezeEnd = m_Core.m_DeepFrozen ? -1 : (m_FreezeTime == 0 ? 0 : Server()->Tick() + m_FreezeTime); |
| 1315 | pDDNetCharacter->m_Jumps = m_Core.m_Jumps; |
| 1316 | pDDNetCharacter->m_TeleCheckpoint = m_TeleCheckpoint; |
| 1317 | pDDNetCharacter->m_StrongWeakId = m_StrongWeakId; |
| 1318 | |
| 1319 | // Display Information |
| 1320 | pDDNetCharacter->m_JumpedTotal = m_Core.m_JumpedTotal; |
| 1321 | pDDNetCharacter->m_NinjaActivationTick = m_Core.m_Ninja.m_ActivationTick; |
| 1322 | pDDNetCharacter->m_FreezeStart = m_Core.m_FreezeStart; |
| 1323 | if(m_Core.m_IsInFreeze) |
| 1324 | { |
| 1325 | pDDNetCharacter->m_Flags |= CHARACTERFLAG_IN_FREEZE; |
| 1326 | } |
| 1327 | if(Teams()->IsPractice(Team: Team())) |
| 1328 | { |
| 1329 | pDDNetCharacter->m_Flags |= CHARACTERFLAG_PRACTICE_MODE; |
| 1330 | } |
| 1331 | if(Teams()->TeamLocked(Team: Team())) |
| 1332 | { |
| 1333 | pDDNetCharacter->m_Flags |= CHARACTERFLAG_LOCK_MODE; |
| 1334 | } |
| 1335 | if(Teams()->TeamFlock(Team: Team())) |
| 1336 | { |
| 1337 | pDDNetCharacter->m_Flags |= CHARACTERFLAG_TEAM0_MODE; |
| 1338 | } |
| 1339 | pDDNetCharacter->m_TargetX = m_Core.m_Input.m_TargetX; |
| 1340 | pDDNetCharacter->m_TargetY = m_Core.m_Input.m_TargetY; |
| 1341 | |
| 1342 | // OVERRIDE_NONE is the default value, SnapNewItem zeroes the object, so it would incorrectly become 0 |
| 1343 | pDDNetCharacter->m_TuneZoneOverride = TuneZone::OVERRIDE_NONE; |
| 1344 | } |
| 1345 | |
| 1346 | void CCharacter::PostGlobalSnap() |
| 1347 | { |
| 1348 | m_TriggeredEvents7 = 0; |
| 1349 | } |
| 1350 | |
| 1351 | // DDRace |
| 1352 | |
| 1353 | bool CCharacter::CanCollide(int ClientId) |
| 1354 | { |
| 1355 | return Teams()->m_Core.CanCollide(ClientId1: GetPlayer()->GetCid(), ClientId2: ClientId); |
| 1356 | } |
| 1357 | bool CCharacter::SameTeam(int ClientId) |
| 1358 | { |
| 1359 | return Teams()->m_Core.SameTeam(ClientId1: GetPlayer()->GetCid(), ClientId2: ClientId); |
| 1360 | } |
| 1361 | |
| 1362 | int CCharacter::Team() |
| 1363 | { |
| 1364 | return Teams()->m_Core.Team(ClientId: m_pPlayer->GetCid()); |
| 1365 | } |
| 1366 | |
| 1367 | void CCharacter::FillAntibot(CAntibotCharacterData *pData) |
| 1368 | { |
| 1369 | pData->m_Pos = m_Pos; |
| 1370 | pData->m_Vel = m_Core.m_Vel; |
| 1371 | pData->m_Angle = m_Core.m_Angle; |
| 1372 | pData->m_HookedPlayer = m_Core.HookedPlayer(); |
| 1373 | pData->m_SpawnTick = m_SpawnTick; |
| 1374 | pData->m_WeaponChangeTick = m_WeaponChangeTick; |
| 1375 | |
| 1376 | // 0 |
| 1377 | pData->m_aLatestInputs[0].m_Direction = m_LatestInput.m_Direction; |
| 1378 | pData->m_aLatestInputs[0].m_TargetX = m_LatestInput.m_TargetX; |
| 1379 | pData->m_aLatestInputs[0].m_TargetY = m_LatestInput.m_TargetY; |
| 1380 | pData->m_aLatestInputs[0].m_Jump = m_LatestInput.m_Jump; |
| 1381 | pData->m_aLatestInputs[0].m_Fire = m_LatestInput.m_Fire; |
| 1382 | pData->m_aLatestInputs[0].m_Hook = m_LatestInput.m_Hook; |
| 1383 | pData->m_aLatestInputs[0].m_PlayerFlags = m_LatestInput.m_PlayerFlags; |
| 1384 | pData->m_aLatestInputs[0].m_WantedWeapon = m_LatestInput.m_WantedWeapon; |
| 1385 | pData->m_aLatestInputs[0].m_NextWeapon = m_LatestInput.m_NextWeapon; |
| 1386 | pData->m_aLatestInputs[0].m_PrevWeapon = m_LatestInput.m_PrevWeapon; |
| 1387 | |
| 1388 | // 1 |
| 1389 | pData->m_aLatestInputs[1].m_Direction = m_LatestPrevInput.m_Direction; |
| 1390 | pData->m_aLatestInputs[1].m_TargetX = m_LatestPrevInput.m_TargetX; |
| 1391 | pData->m_aLatestInputs[1].m_TargetY = m_LatestPrevInput.m_TargetY; |
| 1392 | pData->m_aLatestInputs[1].m_Jump = m_LatestPrevInput.m_Jump; |
| 1393 | pData->m_aLatestInputs[1].m_Fire = m_LatestPrevInput.m_Fire; |
| 1394 | pData->m_aLatestInputs[1].m_Hook = m_LatestPrevInput.m_Hook; |
| 1395 | pData->m_aLatestInputs[1].m_PlayerFlags = m_LatestPrevInput.m_PlayerFlags; |
| 1396 | pData->m_aLatestInputs[1].m_WantedWeapon = m_LatestPrevInput.m_WantedWeapon; |
| 1397 | pData->m_aLatestInputs[1].m_NextWeapon = m_LatestPrevInput.m_NextWeapon; |
| 1398 | pData->m_aLatestInputs[1].m_PrevWeapon = m_LatestPrevInput.m_PrevWeapon; |
| 1399 | |
| 1400 | // 2 |
| 1401 | pData->m_aLatestInputs[2].m_Direction = m_LatestPrevPrevInput.m_Direction; |
| 1402 | pData->m_aLatestInputs[2].m_TargetX = m_LatestPrevPrevInput.m_TargetX; |
| 1403 | pData->m_aLatestInputs[2].m_TargetY = m_LatestPrevPrevInput.m_TargetY; |
| 1404 | pData->m_aLatestInputs[2].m_Jump = m_LatestPrevPrevInput.m_Jump; |
| 1405 | pData->m_aLatestInputs[2].m_Fire = m_LatestPrevPrevInput.m_Fire; |
| 1406 | pData->m_aLatestInputs[2].m_Hook = m_LatestPrevPrevInput.m_Hook; |
| 1407 | pData->m_aLatestInputs[2].m_PlayerFlags = m_LatestPrevPrevInput.m_PlayerFlags; |
| 1408 | pData->m_aLatestInputs[2].m_WantedWeapon = m_LatestPrevPrevInput.m_WantedWeapon; |
| 1409 | pData->m_aLatestInputs[2].m_NextWeapon = m_LatestPrevPrevInput.m_NextWeapon; |
| 1410 | pData->m_aLatestInputs[2].m_PrevWeapon = m_LatestPrevPrevInput.m_PrevWeapon; |
| 1411 | } |
| 1412 | |
| 1413 | void CCharacter::HandleBroadcast() |
| 1414 | { |
| 1415 | CPlayerData *pData = GameServer()->Score()->PlayerData(Id: m_pPlayer->GetCid()); |
| 1416 | |
| 1417 | if(m_DDRaceState == ERaceState::STARTED && m_pPlayer->GetClientVersion() == VERSION_VANILLA && !Server()->IsSixup(ClientId: m_pPlayer->GetCid()) && |
| 1418 | m_LastTimeCpBroadcasted != m_LastTimeCp && m_LastTimeCp > -1 && |
| 1419 | m_TimeCpBroadcastEndTick > Server()->Tick() && pData->m_BestTime && pData->m_aBestTimeCp[m_LastTimeCp] != 0) |
| 1420 | { |
| 1421 | char aBroadcast[128]; |
| 1422 | float Diff = m_aCurrentTimeCp[m_LastTimeCp] - pData->m_aBestTimeCp[m_LastTimeCp]; |
| 1423 | str_format(buffer: aBroadcast, buffer_size: sizeof(aBroadcast), format: "Checkpoint | Diff : %+5.2f" , Diff); |
| 1424 | GameServer()->SendBroadcast(pText: aBroadcast, ClientId: m_pPlayer->GetCid()); |
| 1425 | m_LastTimeCpBroadcasted = m_LastTimeCp; |
| 1426 | m_LastBroadcast = Server()->Tick(); |
| 1427 | } |
| 1428 | else if((m_pPlayer->m_TimerType == CPlayer::TIMERTYPE_BROADCAST || m_pPlayer->m_TimerType == CPlayer::TIMERTYPE_GAMETIMER_AND_BROADCAST) && m_DDRaceState == ERaceState::STARTED && m_LastBroadcast + Server()->TickSpeed() * g_Config.m_SvTimeInBroadcastInterval <= Server()->Tick()) |
| 1429 | { |
| 1430 | char aBuf[32]; |
| 1431 | int Time = (int64_t)100 * ((float)(Server()->Tick() - m_StartTime) / ((float)Server()->TickSpeed())); |
| 1432 | str_time(centisecs: Time, format: TIME_HOURS, buffer: aBuf, buffer_size: sizeof(aBuf)); |
| 1433 | GameServer()->SendBroadcast(pText: aBuf, ClientId: m_pPlayer->GetCid(), IsImportant: false); |
| 1434 | m_LastTimeCpBroadcasted = m_LastTimeCp; |
| 1435 | m_LastBroadcast = Server()->Tick(); |
| 1436 | } |
| 1437 | } |
| 1438 | |
| 1439 | void CCharacter::HandleSkippableTiles(int Index) |
| 1440 | { |
| 1441 | // handle death-tiles and leaving gamelayer |
| 1442 | if((Collision()->GetCollisionAt(x: m_Pos.x + GetProximityRadius() / 3.f, y: m_Pos.y - GetProximityRadius() / 3.f) == TILE_DEATH || |
| 1443 | Collision()->GetCollisionAt(x: m_Pos.x + GetProximityRadius() / 3.f, y: m_Pos.y + GetProximityRadius() / 3.f) == TILE_DEATH || |
| 1444 | Collision()->GetCollisionAt(x: m_Pos.x - GetProximityRadius() / 3.f, y: m_Pos.y - GetProximityRadius() / 3.f) == TILE_DEATH || |
| 1445 | Collision()->GetCollisionAt(x: m_Pos.x - GetProximityRadius() / 3.f, y: m_Pos.y + GetProximityRadius() / 3.f) == TILE_DEATH || |
| 1446 | Collision()->GetFrontCollisionAt(x: m_Pos.x + GetProximityRadius() / 3.f, y: m_Pos.y - GetProximityRadius() / 3.f) == TILE_DEATH || |
| 1447 | Collision()->GetFrontCollisionAt(x: m_Pos.x + GetProximityRadius() / 3.f, y: m_Pos.y + GetProximityRadius() / 3.f) == TILE_DEATH || |
| 1448 | Collision()->GetFrontCollisionAt(x: m_Pos.x - GetProximityRadius() / 3.f, y: m_Pos.y - GetProximityRadius() / 3.f) == TILE_DEATH || |
| 1449 | Collision()->GetFrontCollisionAt(x: m_Pos.x - GetProximityRadius() / 3.f, y: m_Pos.y + GetProximityRadius() / 3.f) == TILE_DEATH) && |
| 1450 | !m_Core.m_Super && !m_Core.m_Invincible && !(Team() && Teams()->TeeFinished(ClientId: m_pPlayer->GetCid()))) |
| 1451 | { |
| 1452 | if(Teams()->IsPractice(Team: Team())) |
| 1453 | { |
| 1454 | Freeze(); |
| 1455 | // Rate limit death effects to once per second |
| 1456 | if(Server()->Tick() - m_pPlayer->m_DieTick >= Server()->TickSpeed()) |
| 1457 | { |
| 1458 | m_pPlayer->m_DieTick = Server()->Tick(); |
| 1459 | GameServer()->CreateSound(Pos: m_Pos, Sound: SOUND_PLAYER_DIE, Mask: TeamMask()); |
| 1460 | GameServer()->CreateDeath(Pos: m_Pos, ClientId: m_pPlayer->GetCid(), Mask: TeamMask()); |
| 1461 | } |
| 1462 | } |
| 1463 | else |
| 1464 | { |
| 1465 | Die(Killer: m_pPlayer->GetCid(), Weapon: WEAPON_WORLD); |
| 1466 | return; |
| 1467 | } |
| 1468 | } |
| 1469 | |
| 1470 | if(GameLayerClipped(CheckPos: m_Pos)) |
| 1471 | { |
| 1472 | Die(Killer: m_pPlayer->GetCid(), Weapon: WEAPON_WORLD); |
| 1473 | return; |
| 1474 | } |
| 1475 | |
| 1476 | if(Index < 0) |
| 1477 | return; |
| 1478 | |
| 1479 | // handle speedup tiles |
| 1480 | if(Collision()->IsSpeedup(Index)) |
| 1481 | { |
| 1482 | vec2 Direction, TempVel = m_Core.m_Vel; |
| 1483 | int Force, Type, MaxSpeed = 0; |
| 1484 | Collision()->GetSpeedup(Index, pDir: &Direction, pForce: &Force, pMaxSpeed: &MaxSpeed, pType: &Type); |
| 1485 | |
| 1486 | if(Type == TILE_SPEED_BOOST_OLD) |
| 1487 | { |
| 1488 | float TeeAngle, SpeederAngle, DiffAngle, SpeedLeft, TeeSpeed; |
| 1489 | if(Force == 255 && MaxSpeed) |
| 1490 | { |
| 1491 | m_Core.m_Vel = Direction * (MaxSpeed / 5); |
| 1492 | } |
| 1493 | else |
| 1494 | { |
| 1495 | if(MaxSpeed > 0 && MaxSpeed < 5) |
| 1496 | MaxSpeed = 5; |
| 1497 | if(MaxSpeed > 0) |
| 1498 | { |
| 1499 | if(Direction.x > 0.0000001f) |
| 1500 | SpeederAngle = -std::atan(x: Direction.y / Direction.x); |
| 1501 | else if(Direction.x < 0.0000001f) |
| 1502 | SpeederAngle = std::atan(x: Direction.y / Direction.x) + 2.0f * std::asin(x: 1.0f); |
| 1503 | else if(Direction.y > 0.0000001f) |
| 1504 | SpeederAngle = std::asin(x: 1.0f); |
| 1505 | else |
| 1506 | SpeederAngle = std::asin(x: -1.0f); |
| 1507 | |
| 1508 | if(SpeederAngle < 0) |
| 1509 | SpeederAngle = 4.0f * std::asin(x: 1.0f) + SpeederAngle; |
| 1510 | |
| 1511 | if(TempVel.x > 0.0000001f) |
| 1512 | TeeAngle = -std::atan(x: TempVel.y / TempVel.x); |
| 1513 | else if(TempVel.x < 0.0000001f) |
| 1514 | TeeAngle = std::atan(x: TempVel.y / TempVel.x) + 2.0f * std::asin(x: 1.0f); |
| 1515 | else if(TempVel.y > 0.0000001f) |
| 1516 | TeeAngle = std::asin(x: 1.0f); |
| 1517 | else |
| 1518 | TeeAngle = std::asin(x: -1.0f); |
| 1519 | |
| 1520 | if(TeeAngle < 0) |
| 1521 | TeeAngle = 4.0f * std::asin(x: 1.0f) + TeeAngle; |
| 1522 | |
| 1523 | TeeSpeed = std::sqrt(x: std::pow(x: TempVel.x, y: 2) + std::pow(x: TempVel.y, y: 2)); |
| 1524 | |
| 1525 | DiffAngle = SpeederAngle - TeeAngle; |
| 1526 | SpeedLeft = MaxSpeed / 5.0f - std::cos(x: DiffAngle) * TeeSpeed; |
| 1527 | if(absolute(a: (int)SpeedLeft) > Force && SpeedLeft > 0.0000001f) |
| 1528 | TempVel += Direction * Force; |
| 1529 | else if(absolute(a: (int)SpeedLeft) > Force) |
| 1530 | TempVel += Direction * -Force; |
| 1531 | else |
| 1532 | TempVel += Direction * SpeedLeft; |
| 1533 | } |
| 1534 | else |
| 1535 | TempVel += Direction * Force; |
| 1536 | |
| 1537 | m_Core.m_Vel = ClampVel(MoveRestriction: m_MoveRestrictions, Vel: TempVel); |
| 1538 | } |
| 1539 | } |
| 1540 | else if(Type == TILE_SPEED_BOOST) |
| 1541 | { |
| 1542 | constexpr float MaxSpeedScale = 5.0f; |
| 1543 | if(MaxSpeed == 0) |
| 1544 | { |
| 1545 | float MaxRampSpeed = GetTuning(Zone: m_TuneZone)->m_VelrampRange / (50 * log(x: maximum(a: (float)GetTuning(Zone: m_TuneZone)->m_VelrampCurvature, b: 1.01f))); |
| 1546 | MaxSpeed = maximum(a: MaxRampSpeed, b: GetTuning(Zone: m_TuneZone)->m_VelrampStart / 50) * MaxSpeedScale; |
| 1547 | } |
| 1548 | |
| 1549 | // (signed) length of projection |
| 1550 | float CurrentDirectionalSpeed = dot(a: Direction, b: m_Core.m_Vel); |
| 1551 | float TempMaxSpeed = MaxSpeed / MaxSpeedScale; |
| 1552 | if(CurrentDirectionalSpeed + Force > TempMaxSpeed) |
| 1553 | TempVel += Direction * (TempMaxSpeed - CurrentDirectionalSpeed); |
| 1554 | else |
| 1555 | TempVel += Direction * Force; |
| 1556 | |
| 1557 | m_Core.m_Vel = ClampVel(MoveRestriction: m_MoveRestrictions, Vel: TempVel); |
| 1558 | } |
| 1559 | } |
| 1560 | } |
| 1561 | |
| 1562 | bool CCharacter::IsSwitchActiveCb(int Number, void *pUser) |
| 1563 | { |
| 1564 | CCharacter *pThis = (CCharacter *)pUser; |
| 1565 | auto &aSwitchers = pThis->Switchers(); |
| 1566 | return !aSwitchers.empty() && pThis->Team() != TEAM_SUPER && aSwitchers[Number].m_aStatus[pThis->Team()]; |
| 1567 | } |
| 1568 | |
| 1569 | void CCharacter::SetTimeCheckpoint(int TimeCheckpoint) |
| 1570 | { |
| 1571 | if(TimeCheckpoint > -1 && m_DDRaceState == ERaceState::STARTED && m_aCurrentTimeCp[TimeCheckpoint] == 0.0f && m_Time != 0.0f) |
| 1572 | { |
| 1573 | m_LastTimeCp = TimeCheckpoint; |
| 1574 | m_aCurrentTimeCp[m_LastTimeCp] = m_Time; |
| 1575 | m_TimeCpBroadcastEndTick = Server()->Tick() + Server()->TickSpeed() * 2; |
| 1576 | if(m_pPlayer->GetClientVersion() >= VERSION_DDRACE || Server()->IsSixup(ClientId: m_pPlayer->GetCid())) |
| 1577 | { |
| 1578 | CPlayerData *pData = GameServer()->Score()->PlayerData(Id: m_pPlayer->GetCid()); |
| 1579 | if(pData->m_aBestTimeCp[m_LastTimeCp] != 0.0f) |
| 1580 | { |
| 1581 | if(Server()->IsSixup(ClientId: m_pPlayer->GetCid())) |
| 1582 | { |
| 1583 | protocol7::CNetMsg_Sv_Checkpoint Msg; |
| 1584 | float Diff = (m_aCurrentTimeCp[m_LastTimeCp] - pData->m_aBestTimeCp[m_LastTimeCp]) * 1000; |
| 1585 | Msg.m_Diff = (int)Diff; |
| 1586 | Server()->SendPackMsg(pMsg: &Msg, Flags: MSGFLAG_VITAL, ClientId: m_pPlayer->GetCid()); |
| 1587 | } |
| 1588 | else |
| 1589 | { |
| 1590 | CNetMsg_Sv_DDRaceTime Msg; |
| 1591 | Msg.m_Time = (int)(m_Time * 100.0f); |
| 1592 | Msg.m_Finish = 0; |
| 1593 | float Diff = (m_aCurrentTimeCp[m_LastTimeCp] - pData->m_aBestTimeCp[m_LastTimeCp]) * 100; |
| 1594 | Msg.m_Check = (int)Diff; |
| 1595 | Server()->SendPackMsg(pMsg: &Msg, Flags: MSGFLAG_VITAL, ClientId: m_pPlayer->GetCid()); |
| 1596 | } |
| 1597 | } |
| 1598 | } |
| 1599 | } |
| 1600 | } |
| 1601 | |
| 1602 | void CCharacter::HandleTiles(int Index) |
| 1603 | { |
| 1604 | int MapIndex = Index; |
| 1605 | m_TileIndex = Collision()->GetTileIndex(Index: MapIndex); |
| 1606 | m_TileFIndex = Collision()->GetFrontTileIndex(Index: MapIndex); |
| 1607 | m_MoveRestrictions = Collision()->GetMoveRestrictions(pfnSwitchActive: IsSwitchActiveCb, pUser: this, Pos: m_Pos, Distance: 18.0f, OverrideCenterTileIndex: MapIndex); |
| 1608 | if(Index < 0) |
| 1609 | { |
| 1610 | m_LastRefillJumps = false; |
| 1611 | m_LastPenalty = false; |
| 1612 | m_LastBonus = false; |
| 1613 | return; |
| 1614 | } |
| 1615 | SetTimeCheckpoint(Collision()->IsTimeCheckpoint(Index: MapIndex)); |
| 1616 | SetTimeCheckpoint(Collision()->IsFrontTimeCheckpoint(Index: MapIndex)); |
| 1617 | int TeleCheckpoint = Collision()->IsTeleCheckpoint(Index: MapIndex); |
| 1618 | if(TeleCheckpoint) |
| 1619 | m_TeleCheckpoint = TeleCheckpoint; |
| 1620 | |
| 1621 | GameServer()->m_pController->HandleCharacterTiles(pChr: this, MapIndex: Index); |
| 1622 | if(!m_Alive) |
| 1623 | return; |
| 1624 | |
| 1625 | // freeze |
| 1626 | if(((m_TileIndex == TILE_FREEZE) || (m_TileFIndex == TILE_FREEZE)) && !m_Core.m_Super && !m_Core.m_Invincible && !m_Core.m_DeepFrozen) |
| 1627 | { |
| 1628 | Freeze(); |
| 1629 | } |
| 1630 | else if(((m_TileIndex == TILE_UNFREEZE) || (m_TileFIndex == TILE_UNFREEZE)) && !m_Core.m_DeepFrozen) |
| 1631 | UnFreeze(); |
| 1632 | |
| 1633 | // deep freeze |
| 1634 | if(((m_TileIndex == TILE_DFREEZE) || (m_TileFIndex == TILE_DFREEZE)) && !m_Core.m_Super && !m_Core.m_Invincible && !m_Core.m_DeepFrozen) |
| 1635 | m_Core.m_DeepFrozen = true; |
| 1636 | else if(((m_TileIndex == TILE_DUNFREEZE) || (m_TileFIndex == TILE_DUNFREEZE)) && !m_Core.m_Super && !m_Core.m_Invincible && m_Core.m_DeepFrozen) |
| 1637 | m_Core.m_DeepFrozen = false; |
| 1638 | |
| 1639 | // live freeze |
| 1640 | if(((m_TileIndex == TILE_LFREEZE) || (m_TileFIndex == TILE_LFREEZE)) && !m_Core.m_Super && !m_Core.m_Invincible) |
| 1641 | { |
| 1642 | m_Core.m_LiveFrozen = true; |
| 1643 | } |
| 1644 | else if(((m_TileIndex == TILE_LUNFREEZE) || (m_TileFIndex == TILE_LUNFREEZE)) && !m_Core.m_Super && !m_Core.m_Invincible) |
| 1645 | { |
| 1646 | m_Core.m_LiveFrozen = false; |
| 1647 | } |
| 1648 | |
| 1649 | // endless hook |
| 1650 | if(((m_TileIndex == TILE_EHOOK_ENABLE) || (m_TileFIndex == TILE_EHOOK_ENABLE))) |
| 1651 | { |
| 1652 | SetEndlessHook(true); |
| 1653 | } |
| 1654 | else if(((m_TileIndex == TILE_EHOOK_DISABLE) || (m_TileFIndex == TILE_EHOOK_DISABLE))) |
| 1655 | { |
| 1656 | SetEndlessHook(false); |
| 1657 | } |
| 1658 | |
| 1659 | // hit others |
| 1660 | 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)) |
| 1661 | { |
| 1662 | GameServer()->SendChatTarget(To: GetPlayer()->GetCid(), pText: "You can't hit others" ); |
| 1663 | m_Core.m_HammerHitDisabled = true; |
| 1664 | m_Core.m_ShotgunHitDisabled = true; |
| 1665 | m_Core.m_GrenadeHitDisabled = true; |
| 1666 | m_Core.m_LaserHitDisabled = true; |
| 1667 | } |
| 1668 | 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)) |
| 1669 | { |
| 1670 | GameServer()->SendChatTarget(To: GetPlayer()->GetCid(), pText: "You can hit others" ); |
| 1671 | m_Core.m_ShotgunHitDisabled = false; |
| 1672 | m_Core.m_GrenadeHitDisabled = false; |
| 1673 | m_Core.m_HammerHitDisabled = false; |
| 1674 | m_Core.m_LaserHitDisabled = false; |
| 1675 | } |
| 1676 | |
| 1677 | // collide with others |
| 1678 | if(((m_TileIndex == TILE_NPC_DISABLE) || (m_TileFIndex == TILE_NPC_DISABLE)) && !m_Core.m_CollisionDisabled) |
| 1679 | { |
| 1680 | GameServer()->SendChatTarget(To: GetPlayer()->GetCid(), pText: "You can't collide with others" ); |
| 1681 | m_Core.m_CollisionDisabled = true; |
| 1682 | } |
| 1683 | else if(((m_TileIndex == TILE_NPC_ENABLE) || (m_TileFIndex == TILE_NPC_ENABLE)) && m_Core.m_CollisionDisabled) |
| 1684 | { |
| 1685 | GameServer()->SendChatTarget(To: GetPlayer()->GetCid(), pText: "You can collide with others" ); |
| 1686 | m_Core.m_CollisionDisabled = false; |
| 1687 | } |
| 1688 | |
| 1689 | // hook others |
| 1690 | if(((m_TileIndex == TILE_NPH_DISABLE) || (m_TileFIndex == TILE_NPH_DISABLE)) && !m_Core.m_HookHitDisabled) |
| 1691 | { |
| 1692 | GameServer()->SendChatTarget(To: GetPlayer()->GetCid(), pText: "You can't hook others" ); |
| 1693 | m_Core.m_HookHitDisabled = true; |
| 1694 | } |
| 1695 | else if(((m_TileIndex == TILE_NPH_ENABLE) || (m_TileFIndex == TILE_NPH_ENABLE)) && m_Core.m_HookHitDisabled) |
| 1696 | { |
| 1697 | GameServer()->SendChatTarget(To: GetPlayer()->GetCid(), pText: "You can hook others" ); |
| 1698 | m_Core.m_HookHitDisabled = false; |
| 1699 | } |
| 1700 | |
| 1701 | // unlimited air jumps |
| 1702 | if(((m_TileIndex == TILE_UNLIMITED_JUMPS_ENABLE) || (m_TileFIndex == TILE_UNLIMITED_JUMPS_ENABLE)) && !m_Core.m_EndlessJump) |
| 1703 | { |
| 1704 | GameServer()->SendChatTarget(To: GetPlayer()->GetCid(), pText: "You have unlimited air jumps" ); |
| 1705 | m_Core.m_EndlessJump = true; |
| 1706 | } |
| 1707 | else if(((m_TileIndex == TILE_UNLIMITED_JUMPS_DISABLE) || (m_TileFIndex == TILE_UNLIMITED_JUMPS_DISABLE)) && m_Core.m_EndlessJump) |
| 1708 | { |
| 1709 | GameServer()->SendChatTarget(To: GetPlayer()->GetCid(), pText: "You don't have unlimited air jumps" ); |
| 1710 | m_Core.m_EndlessJump = false; |
| 1711 | } |
| 1712 | |
| 1713 | // walljump |
| 1714 | if((m_TileIndex == TILE_WALLJUMP) || (m_TileFIndex == TILE_WALLJUMP)) |
| 1715 | { |
| 1716 | if(m_Core.m_Vel.y > 0 && m_Core.m_Colliding && m_Core.m_LeftWall) |
| 1717 | { |
| 1718 | m_Core.m_LeftWall = false; |
| 1719 | m_Core.m_JumpedTotal = m_Core.m_Jumps >= 2 ? m_Core.m_Jumps - 2 : 0; |
| 1720 | m_Core.m_Jumped = 1; |
| 1721 | } |
| 1722 | } |
| 1723 | |
| 1724 | // jetpack gun |
| 1725 | if(((m_TileIndex == TILE_JETPACK_ENABLE) || (m_TileFIndex == TILE_JETPACK_ENABLE)) && !m_Core.m_Jetpack) |
| 1726 | { |
| 1727 | GameServer()->SendChatTarget(To: GetPlayer()->GetCid(), pText: "You have a jetpack gun" ); |
| 1728 | m_Core.m_Jetpack = true; |
| 1729 | } |
| 1730 | else if(((m_TileIndex == TILE_JETPACK_DISABLE) || (m_TileFIndex == TILE_JETPACK_DISABLE)) && m_Core.m_Jetpack) |
| 1731 | { |
| 1732 | GameServer()->SendChatTarget(To: GetPlayer()->GetCid(), pText: "You lost your jetpack gun" ); |
| 1733 | m_Core.m_Jetpack = false; |
| 1734 | } |
| 1735 | |
| 1736 | // refill jumps |
| 1737 | if(((m_TileIndex == TILE_REFILL_JUMPS) || (m_TileFIndex == TILE_REFILL_JUMPS)) && !m_LastRefillJumps) |
| 1738 | { |
| 1739 | m_Core.m_JumpedTotal = 0; |
| 1740 | m_Core.m_Jumped = 0; |
| 1741 | m_LastRefillJumps = true; |
| 1742 | } |
| 1743 | if((m_TileIndex != TILE_REFILL_JUMPS) && (m_TileFIndex != TILE_REFILL_JUMPS)) |
| 1744 | { |
| 1745 | m_LastRefillJumps = false; |
| 1746 | } |
| 1747 | |
| 1748 | // Teleport gun |
| 1749 | if(((m_TileIndex == TILE_TELE_GUN_ENABLE) || (m_TileFIndex == TILE_TELE_GUN_ENABLE)) && !m_Core.m_HasTelegunGun) |
| 1750 | { |
| 1751 | m_Core.m_HasTelegunGun = true; |
| 1752 | |
| 1753 | GameServer()->SendChatTarget(To: GetPlayer()->GetCid(), pText: "Teleport gun enabled" ); |
| 1754 | } |
| 1755 | else if(((m_TileIndex == TILE_TELE_GUN_DISABLE) || (m_TileFIndex == TILE_TELE_GUN_DISABLE)) && m_Core.m_HasTelegunGun) |
| 1756 | { |
| 1757 | m_Core.m_HasTelegunGun = false; |
| 1758 | |
| 1759 | GameServer()->SendChatTarget(To: GetPlayer()->GetCid(), pText: "Teleport gun disabled" ); |
| 1760 | } |
| 1761 | |
| 1762 | if(((m_TileIndex == TILE_TELE_GRENADE_ENABLE) || (m_TileFIndex == TILE_TELE_GRENADE_ENABLE)) && !m_Core.m_HasTelegunGrenade) |
| 1763 | { |
| 1764 | m_Core.m_HasTelegunGrenade = true; |
| 1765 | |
| 1766 | GameServer()->SendChatTarget(To: GetPlayer()->GetCid(), pText: "Teleport grenade enabled" ); |
| 1767 | } |
| 1768 | else if(((m_TileIndex == TILE_TELE_GRENADE_DISABLE) || (m_TileFIndex == TILE_TELE_GRENADE_DISABLE)) && m_Core.m_HasTelegunGrenade) |
| 1769 | { |
| 1770 | m_Core.m_HasTelegunGrenade = false; |
| 1771 | |
| 1772 | GameServer()->SendChatTarget(To: GetPlayer()->GetCid(), pText: "Teleport grenade disabled" ); |
| 1773 | } |
| 1774 | |
| 1775 | if(((m_TileIndex == TILE_TELE_LASER_ENABLE) || (m_TileFIndex == TILE_TELE_LASER_ENABLE)) && !m_Core.m_HasTelegunLaser) |
| 1776 | { |
| 1777 | m_Core.m_HasTelegunLaser = true; |
| 1778 | |
| 1779 | GameServer()->SendChatTarget(To: GetPlayer()->GetCid(), pText: "Teleport laser enabled" ); |
| 1780 | } |
| 1781 | else if(((m_TileIndex == TILE_TELE_LASER_DISABLE) || (m_TileFIndex == TILE_TELE_LASER_DISABLE)) && m_Core.m_HasTelegunLaser) |
| 1782 | { |
| 1783 | m_Core.m_HasTelegunLaser = false; |
| 1784 | |
| 1785 | GameServer()->SendChatTarget(To: GetPlayer()->GetCid(), pText: "Teleport laser disabled" ); |
| 1786 | } |
| 1787 | |
| 1788 | // stopper |
| 1789 | if(m_Core.m_Vel.y > 0 && (m_MoveRestrictions & CANTMOVE_DOWN)) |
| 1790 | { |
| 1791 | m_Core.m_Jumped = 0; |
| 1792 | m_Core.m_JumpedTotal = 0; |
| 1793 | } |
| 1794 | ApplyMoveRestrictions(); |
| 1795 | |
| 1796 | // handle switch tiles |
| 1797 | if(Collision()->GetSwitchType(Index: MapIndex) == TILE_SWITCHOPEN && Team() != TEAM_SUPER && Collision()->GetSwitchNumber(Index: MapIndex) > 0) |
| 1798 | { |
| 1799 | Switchers()[Collision()->GetSwitchNumber(Index: MapIndex)].m_aStatus[Team()] = true; |
| 1800 | Switchers()[Collision()->GetSwitchNumber(Index: MapIndex)].m_aEndTick[Team()] = 0; |
| 1801 | Switchers()[Collision()->GetSwitchNumber(Index: MapIndex)].m_aType[Team()] = TILE_SWITCHOPEN; |
| 1802 | Switchers()[Collision()->GetSwitchNumber(Index: MapIndex)].m_aLastUpdateTick[Team()] = Server()->Tick(); |
| 1803 | } |
| 1804 | else if(Collision()->GetSwitchType(Index: MapIndex) == TILE_SWITCHTIMEDOPEN && Team() != TEAM_SUPER && Collision()->GetSwitchNumber(Index: MapIndex) > 0) |
| 1805 | { |
| 1806 | Switchers()[Collision()->GetSwitchNumber(Index: MapIndex)].m_aStatus[Team()] = true; |
| 1807 | Switchers()[Collision()->GetSwitchNumber(Index: MapIndex)].m_aEndTick[Team()] = Server()->Tick() + 1 + Collision()->GetSwitchDelay(Index: MapIndex) * Server()->TickSpeed(); |
| 1808 | Switchers()[Collision()->GetSwitchNumber(Index: MapIndex)].m_aType[Team()] = TILE_SWITCHTIMEDOPEN; |
| 1809 | Switchers()[Collision()->GetSwitchNumber(Index: MapIndex)].m_aLastUpdateTick[Team()] = Server()->Tick(); |
| 1810 | } |
| 1811 | else if(Collision()->GetSwitchType(Index: MapIndex) == TILE_SWITCHTIMEDCLOSE && Team() != TEAM_SUPER && Collision()->GetSwitchNumber(Index: MapIndex) > 0) |
| 1812 | { |
| 1813 | Switchers()[Collision()->GetSwitchNumber(Index: MapIndex)].m_aStatus[Team()] = false; |
| 1814 | Switchers()[Collision()->GetSwitchNumber(Index: MapIndex)].m_aEndTick[Team()] = Server()->Tick() + 1 + Collision()->GetSwitchDelay(Index: MapIndex) * Server()->TickSpeed(); |
| 1815 | Switchers()[Collision()->GetSwitchNumber(Index: MapIndex)].m_aType[Team()] = TILE_SWITCHTIMEDCLOSE; |
| 1816 | Switchers()[Collision()->GetSwitchNumber(Index: MapIndex)].m_aLastUpdateTick[Team()] = Server()->Tick(); |
| 1817 | } |
| 1818 | else if(Collision()->GetSwitchType(Index: MapIndex) == TILE_SWITCHCLOSE && Team() != TEAM_SUPER && Collision()->GetSwitchNumber(Index: MapIndex) > 0) |
| 1819 | { |
| 1820 | Switchers()[Collision()->GetSwitchNumber(Index: MapIndex)].m_aStatus[Team()] = false; |
| 1821 | Switchers()[Collision()->GetSwitchNumber(Index: MapIndex)].m_aEndTick[Team()] = 0; |
| 1822 | Switchers()[Collision()->GetSwitchNumber(Index: MapIndex)].m_aType[Team()] = TILE_SWITCHCLOSE; |
| 1823 | Switchers()[Collision()->GetSwitchNumber(Index: MapIndex)].m_aLastUpdateTick[Team()] = Server()->Tick(); |
| 1824 | } |
| 1825 | else if(Collision()->GetSwitchType(Index: MapIndex) == TILE_FREEZE && Team() != TEAM_SUPER && !m_Core.m_Invincible) |
| 1826 | { |
| 1827 | if(Collision()->GetSwitchNumber(Index: MapIndex) == 0 || Switchers()[Collision()->GetSwitchNumber(Index: MapIndex)].m_aStatus[Team()]) |
| 1828 | { |
| 1829 | Freeze(Seconds: Collision()->GetSwitchDelay(Index: MapIndex)); |
| 1830 | } |
| 1831 | } |
| 1832 | else if(Collision()->GetSwitchType(Index: MapIndex) == TILE_DFREEZE && Team() != TEAM_SUPER && !m_Core.m_Invincible) |
| 1833 | { |
| 1834 | if(Collision()->GetSwitchNumber(Index: MapIndex) == 0 || Switchers()[Collision()->GetSwitchNumber(Index: MapIndex)].m_aStatus[Team()]) |
| 1835 | m_Core.m_DeepFrozen = true; |
| 1836 | } |
| 1837 | else if(Collision()->GetSwitchType(Index: MapIndex) == TILE_DUNFREEZE && Team() != TEAM_SUPER && !m_Core.m_Invincible) |
| 1838 | { |
| 1839 | if(Collision()->GetSwitchNumber(Index: MapIndex) == 0 || Switchers()[Collision()->GetSwitchNumber(Index: MapIndex)].m_aStatus[Team()]) |
| 1840 | m_Core.m_DeepFrozen = false; |
| 1841 | } |
| 1842 | else if(Collision()->GetSwitchType(Index: MapIndex) == TILE_LFREEZE && Team() != TEAM_SUPER && !m_Core.m_Invincible) |
| 1843 | { |
| 1844 | if(Collision()->GetSwitchNumber(Index: MapIndex) == 0 || Switchers()[Collision()->GetSwitchNumber(Index: MapIndex)].m_aStatus[Team()]) |
| 1845 | { |
| 1846 | m_Core.m_LiveFrozen = true; |
| 1847 | } |
| 1848 | } |
| 1849 | else if(Collision()->GetSwitchType(Index: MapIndex) == TILE_LUNFREEZE && Team() != TEAM_SUPER && !m_Core.m_Invincible) |
| 1850 | { |
| 1851 | if(Collision()->GetSwitchNumber(Index: MapIndex) == 0 || Switchers()[Collision()->GetSwitchNumber(Index: MapIndex)].m_aStatus[Team()]) |
| 1852 | { |
| 1853 | m_Core.m_LiveFrozen = false; |
| 1854 | } |
| 1855 | } |
| 1856 | else if(Collision()->GetSwitchType(Index: MapIndex) == TILE_HIT_ENABLE && m_Core.m_HammerHitDisabled && Collision()->GetSwitchDelay(Index: MapIndex) == WEAPON_HAMMER) |
| 1857 | { |
| 1858 | GameServer()->SendChatTarget(To: GetPlayer()->GetCid(), pText: "You can hammer hit others" ); |
| 1859 | m_Core.m_HammerHitDisabled = false; |
| 1860 | } |
| 1861 | else if(Collision()->GetSwitchType(Index: MapIndex) == TILE_HIT_DISABLE && !(m_Core.m_HammerHitDisabled) && Collision()->GetSwitchDelay(Index: MapIndex) == WEAPON_HAMMER) |
| 1862 | { |
| 1863 | GameServer()->SendChatTarget(To: GetPlayer()->GetCid(), pText: "You can't hammer hit others" ); |
| 1864 | m_Core.m_HammerHitDisabled = true; |
| 1865 | } |
| 1866 | else if(Collision()->GetSwitchType(Index: MapIndex) == TILE_HIT_ENABLE && m_Core.m_ShotgunHitDisabled && Collision()->GetSwitchDelay(Index: MapIndex) == WEAPON_SHOTGUN) |
| 1867 | { |
| 1868 | GameServer()->SendChatTarget(To: GetPlayer()->GetCid(), pText: "You can shoot others with shotgun" ); |
| 1869 | m_Core.m_ShotgunHitDisabled = false; |
| 1870 | } |
| 1871 | else if(Collision()->GetSwitchType(Index: MapIndex) == TILE_HIT_DISABLE && !(m_Core.m_ShotgunHitDisabled) && Collision()->GetSwitchDelay(Index: MapIndex) == WEAPON_SHOTGUN) |
| 1872 | { |
| 1873 | GameServer()->SendChatTarget(To: GetPlayer()->GetCid(), pText: "You can't shoot others with shotgun" ); |
| 1874 | m_Core.m_ShotgunHitDisabled = true; |
| 1875 | } |
| 1876 | else if(Collision()->GetSwitchType(Index: MapIndex) == TILE_HIT_ENABLE && m_Core.m_GrenadeHitDisabled && Collision()->GetSwitchDelay(Index: MapIndex) == WEAPON_GRENADE) |
| 1877 | { |
| 1878 | GameServer()->SendChatTarget(To: GetPlayer()->GetCid(), pText: "You can shoot others with grenade" ); |
| 1879 | m_Core.m_GrenadeHitDisabled = false; |
| 1880 | } |
| 1881 | else if(Collision()->GetSwitchType(Index: MapIndex) == TILE_HIT_DISABLE && !(m_Core.m_GrenadeHitDisabled) && Collision()->GetSwitchDelay(Index: MapIndex) == WEAPON_GRENADE) |
| 1882 | { |
| 1883 | GameServer()->SendChatTarget(To: GetPlayer()->GetCid(), pText: "You can't shoot others with grenade" ); |
| 1884 | m_Core.m_GrenadeHitDisabled = true; |
| 1885 | } |
| 1886 | else if(Collision()->GetSwitchType(Index: MapIndex) == TILE_HIT_ENABLE && m_Core.m_LaserHitDisabled && Collision()->GetSwitchDelay(Index: MapIndex) == WEAPON_LASER) |
| 1887 | { |
| 1888 | GameServer()->SendChatTarget(To: GetPlayer()->GetCid(), pText: "You can shoot others with laser" ); |
| 1889 | m_Core.m_LaserHitDisabled = false; |
| 1890 | } |
| 1891 | else if(Collision()->GetSwitchType(Index: MapIndex) == TILE_HIT_DISABLE && !(m_Core.m_LaserHitDisabled) && Collision()->GetSwitchDelay(Index: MapIndex) == WEAPON_LASER) |
| 1892 | { |
| 1893 | GameServer()->SendChatTarget(To: GetPlayer()->GetCid(), pText: "You can't shoot others with laser" ); |
| 1894 | m_Core.m_LaserHitDisabled = true; |
| 1895 | } |
| 1896 | else if(Collision()->GetSwitchType(Index: MapIndex) == TILE_JUMP) |
| 1897 | { |
| 1898 | int NewJumps = Collision()->GetSwitchDelay(Index: MapIndex); |
| 1899 | if(NewJumps == 255) |
| 1900 | { |
| 1901 | NewJumps = -1; |
| 1902 | } |
| 1903 | |
| 1904 | if(NewJumps != m_Core.m_Jumps) |
| 1905 | { |
| 1906 | char aBuf[256]; |
| 1907 | if(NewJumps == -1) |
| 1908 | str_copy(dst&: aBuf, src: "You only have your ground jump now" ); |
| 1909 | else if(NewJumps == 1) |
| 1910 | str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "You can jump %d time" , NewJumps); |
| 1911 | else |
| 1912 | str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "You can jump %d times" , NewJumps); |
| 1913 | GameServer()->SendChatTarget(To: GetPlayer()->GetCid(), pText: aBuf); |
| 1914 | m_Core.m_Jumps = NewJumps; |
| 1915 | } |
| 1916 | } |
| 1917 | else if(Collision()->GetSwitchType(Index: MapIndex) == TILE_ADD_TIME && !m_LastPenalty) |
| 1918 | { |
| 1919 | const int Minutes = Collision()->GetSwitchDelay(Index: MapIndex); |
| 1920 | const int Seconds = Collision()->GetSwitchNumber(Index: MapIndex); |
| 1921 | int Team = Teams()->m_Core.Team(ClientId: m_Core.m_Id); |
| 1922 | |
| 1923 | m_StartTime -= (Minutes * 60 + Seconds) * Server()->TickSpeed(); |
| 1924 | |
| 1925 | if((g_Config.m_SvTeam == SV_TEAM_FORCED_SOLO || (Team != TEAM_FLOCK && !Teams()->TeamFlock(Team))) && Team != TEAM_SUPER) |
| 1926 | { |
| 1927 | for(int i = 0; i < MAX_CLIENTS; i++) |
| 1928 | { |
| 1929 | if(Teams()->m_Core.Team(ClientId: i) == Team && i != m_Core.m_Id && GameServer()->m_apPlayers[i]) |
| 1930 | { |
| 1931 | CCharacter *pChar = GameServer()->m_apPlayers[i]->GetCharacter(); |
| 1932 | |
| 1933 | if(pChar) |
| 1934 | pChar->m_StartTime = m_StartTime; |
| 1935 | } |
| 1936 | } |
| 1937 | } |
| 1938 | |
| 1939 | m_LastPenalty = true; |
| 1940 | } |
| 1941 | else if(Collision()->GetSwitchType(Index: MapIndex) == TILE_SUBTRACT_TIME && !m_LastBonus) |
| 1942 | { |
| 1943 | const int Minutes = Collision()->GetSwitchDelay(Index: MapIndex); |
| 1944 | const int Seconds = Collision()->GetSwitchNumber(Index: MapIndex); |
| 1945 | int Team = Teams()->m_Core.Team(ClientId: m_Core.m_Id); |
| 1946 | |
| 1947 | m_StartTime += (Minutes * 60 + Seconds) * Server()->TickSpeed(); |
| 1948 | if(m_StartTime > Server()->Tick()) |
| 1949 | m_StartTime = Server()->Tick(); |
| 1950 | |
| 1951 | if((g_Config.m_SvTeam == SV_TEAM_FORCED_SOLO || (Team != TEAM_FLOCK && !Teams()->TeamFlock(Team))) && Team != TEAM_SUPER) |
| 1952 | { |
| 1953 | for(int i = 0; i < MAX_CLIENTS; i++) |
| 1954 | { |
| 1955 | if(Teams()->m_Core.Team(ClientId: i) == Team && i != m_Core.m_Id && GameServer()->m_apPlayers[i]) |
| 1956 | { |
| 1957 | CCharacter *pChar = GameServer()->m_apPlayers[i]->GetCharacter(); |
| 1958 | |
| 1959 | if(pChar) |
| 1960 | pChar->m_StartTime = m_StartTime; |
| 1961 | } |
| 1962 | } |
| 1963 | } |
| 1964 | |
| 1965 | m_LastBonus = true; |
| 1966 | } |
| 1967 | |
| 1968 | if(Collision()->GetSwitchType(Index: MapIndex) != TILE_ADD_TIME) |
| 1969 | { |
| 1970 | m_LastPenalty = false; |
| 1971 | } |
| 1972 | |
| 1973 | if(Collision()->GetSwitchType(Index: MapIndex) != TILE_SUBTRACT_TIME) |
| 1974 | { |
| 1975 | m_LastBonus = false; |
| 1976 | } |
| 1977 | |
| 1978 | int z = Collision()->IsTeleport(Index: MapIndex); |
| 1979 | if(!g_Config.m_SvOldTeleportHook && !g_Config.m_SvOldTeleportWeapons && z && !Collision()->TeleOuts(Number: z - 1).empty()) |
| 1980 | { |
| 1981 | if(m_Core.m_Super || m_Core.m_Invincible) |
| 1982 | return; |
| 1983 | int TeleOut = GameWorld()->m_Core.RandomOr0(BelowThis: Collision()->TeleOuts(Number: z - 1).size()); |
| 1984 | m_Core.m_Pos = Collision()->TeleOuts(Number: z - 1)[TeleOut]; |
| 1985 | if(!g_Config.m_SvTeleportHoldHook) |
| 1986 | { |
| 1987 | ResetHook(); |
| 1988 | } |
| 1989 | if(g_Config.m_SvTeleportLoseWeapons) |
| 1990 | ResetPickups(); |
| 1991 | return; |
| 1992 | } |
| 1993 | const int EvilTeleport = Collision()->IsEvilTeleport(Index: MapIndex); |
| 1994 | if(EvilTeleport && !Collision()->TeleOuts(Number: EvilTeleport - 1).empty()) |
| 1995 | { |
| 1996 | if(m_Core.m_Super || m_Core.m_Invincible) |
| 1997 | return; |
| 1998 | int TeleOut = GameWorld()->m_Core.RandomOr0(BelowThis: Collision()->TeleOuts(Number: EvilTeleport - 1).size()); |
| 1999 | m_Core.m_Pos = Collision()->TeleOuts(Number: EvilTeleport - 1)[TeleOut]; |
| 2000 | if(!g_Config.m_SvOldTeleportHook && !g_Config.m_SvOldTeleportWeapons) |
| 2001 | { |
| 2002 | m_Core.m_Vel = vec2(0, 0); |
| 2003 | |
| 2004 | if(!g_Config.m_SvTeleportHoldHook) |
| 2005 | { |
| 2006 | ResetHook(); |
| 2007 | GameWorld()->ReleaseHooked(ClientId: GetPlayer()->GetCid()); |
| 2008 | } |
| 2009 | if(g_Config.m_SvTeleportLoseWeapons) |
| 2010 | { |
| 2011 | ResetPickups(); |
| 2012 | } |
| 2013 | } |
| 2014 | return; |
| 2015 | } |
| 2016 | if(Collision()->IsCheckEvilTeleport(Index: MapIndex)) |
| 2017 | { |
| 2018 | if(m_Core.m_Super || m_Core.m_Invincible) |
| 2019 | return; |
| 2020 | // first check if there is a TeleCheckOut for the current recorded checkpoint, if not check previous checkpoints |
| 2021 | for(int k = m_TeleCheckpoint - 1; k >= 0; k--) |
| 2022 | { |
| 2023 | if(!Collision()->TeleCheckOuts(Number: k).empty()) |
| 2024 | { |
| 2025 | int TeleOut = GameWorld()->m_Core.RandomOr0(BelowThis: Collision()->TeleCheckOuts(Number: k).size()); |
| 2026 | m_Core.m_Pos = Collision()->TeleCheckOuts(Number: k)[TeleOut]; |
| 2027 | m_Core.m_Vel = vec2(0, 0); |
| 2028 | |
| 2029 | if(!g_Config.m_SvTeleportHoldHook) |
| 2030 | { |
| 2031 | ResetHook(); |
| 2032 | GameWorld()->ReleaseHooked(ClientId: GetPlayer()->GetCid()); |
| 2033 | } |
| 2034 | |
| 2035 | return; |
| 2036 | } |
| 2037 | } |
| 2038 | // if no checkpointout have been found (or if there no recorded checkpoint), teleport to start |
| 2039 | vec2 SpawnPos; |
| 2040 | if(GameServer()->m_pController->CanSpawn(Team: m_pPlayer->GetTeam(), pOutPos: &SpawnPos, ClientId: GetPlayer()->GetCid())) |
| 2041 | { |
| 2042 | m_Core.m_Pos = SpawnPos; |
| 2043 | m_Core.m_Vel = vec2(0, 0); |
| 2044 | |
| 2045 | if(!g_Config.m_SvTeleportHoldHook) |
| 2046 | { |
| 2047 | ResetHook(); |
| 2048 | GameWorld()->ReleaseHooked(ClientId: GetPlayer()->GetCid()); |
| 2049 | } |
| 2050 | } |
| 2051 | return; |
| 2052 | } |
| 2053 | if(Collision()->IsCheckTeleport(Index: MapIndex)) |
| 2054 | { |
| 2055 | if(m_Core.m_Super || m_Core.m_Invincible) |
| 2056 | return; |
| 2057 | // first check if there is a TeleCheckOut for the current recorded checkpoint, if not check previous checkpoints |
| 2058 | for(int k = m_TeleCheckpoint - 1; k >= 0; k--) |
| 2059 | { |
| 2060 | if(!Collision()->TeleCheckOuts(Number: k).empty()) |
| 2061 | { |
| 2062 | int TeleOut = GameWorld()->m_Core.RandomOr0(BelowThis: Collision()->TeleCheckOuts(Number: k).size()); |
| 2063 | m_Core.m_Pos = Collision()->TeleCheckOuts(Number: k)[TeleOut]; |
| 2064 | |
| 2065 | if(!g_Config.m_SvTeleportHoldHook) |
| 2066 | { |
| 2067 | ResetHook(); |
| 2068 | } |
| 2069 | |
| 2070 | return; |
| 2071 | } |
| 2072 | } |
| 2073 | // if no checkpointout have been found (or if there no recorded checkpoint), teleport to start |
| 2074 | vec2 SpawnPos; |
| 2075 | if(GameServer()->m_pController->CanSpawn(Team: m_pPlayer->GetTeam(), pOutPos: &SpawnPos, ClientId: GetPlayer()->GetCid())) |
| 2076 | { |
| 2077 | m_Core.m_Pos = SpawnPos; |
| 2078 | |
| 2079 | if(!g_Config.m_SvTeleportHoldHook) |
| 2080 | { |
| 2081 | ResetHook(); |
| 2082 | } |
| 2083 | } |
| 2084 | return; |
| 2085 | } |
| 2086 | } |
| 2087 | |
| 2088 | void CCharacter::HandleTuneLayer() |
| 2089 | { |
| 2090 | m_TuneZoneOld = m_TuneZone; |
| 2091 | int CurrentIndex = Collision()->GetMapIndex(Pos: m_Pos); |
| 2092 | m_TuneZone = Collision()->IsTune(Index: CurrentIndex); |
| 2093 | m_Core.m_Tuning = TuningList()[m_TuneZone]; // throw tunings from specific zone into gamecore |
| 2094 | |
| 2095 | if(m_TuneZone != m_TuneZoneOld) // don't send tunigs all the time |
| 2096 | { |
| 2097 | // send zone msgs |
| 2098 | SendZoneMsgs(); |
| 2099 | } |
| 2100 | } |
| 2101 | |
| 2102 | void CCharacter::SendZoneMsgs() |
| 2103 | { |
| 2104 | // send zone leave msg |
| 2105 | // (m_TuneZoneOld >= 0: avoid zone leave msgs on spawn) |
| 2106 | if(m_TuneZoneOld >= 0 && GameServer()->m_aaZoneLeaveMsg[m_TuneZoneOld][0]) |
| 2107 | { |
| 2108 | const char *pCur = GameServer()->m_aaZoneLeaveMsg[m_TuneZoneOld]; |
| 2109 | const char *pPos; |
| 2110 | while((pPos = str_find(haystack: pCur, needle: "\\n" ))) |
| 2111 | { |
| 2112 | char aBuf[256]; |
| 2113 | str_copy(dst: aBuf, src: pCur, dst_size: pPos - pCur + 1); |
| 2114 | aBuf[pPos - pCur + 1] = '\0'; |
| 2115 | pCur = pPos + 2; |
| 2116 | GameServer()->SendChatTarget(To: m_pPlayer->GetCid(), pText: aBuf); |
| 2117 | } |
| 2118 | GameServer()->SendChatTarget(To: m_pPlayer->GetCid(), pText: pCur); |
| 2119 | } |
| 2120 | // send zone enter msg |
| 2121 | if(GameServer()->m_aaZoneEnterMsg[m_TuneZone][0]) |
| 2122 | { |
| 2123 | const char *pCur = GameServer()->m_aaZoneEnterMsg[m_TuneZone]; |
| 2124 | const char *pPos; |
| 2125 | while((pPos = str_find(haystack: pCur, needle: "\\n" ))) |
| 2126 | { |
| 2127 | char aBuf[256]; |
| 2128 | str_copy(dst: aBuf, src: pCur, dst_size: pPos - pCur + 1); |
| 2129 | aBuf[pPos - pCur + 1] = '\0'; |
| 2130 | pCur = pPos + 2; |
| 2131 | GameServer()->SendChatTarget(To: m_pPlayer->GetCid(), pText: aBuf); |
| 2132 | } |
| 2133 | GameServer()->SendChatTarget(To: m_pPlayer->GetCid(), pText: pCur); |
| 2134 | } |
| 2135 | } |
| 2136 | |
| 2137 | IAntibot *CCharacter::Antibot() |
| 2138 | { |
| 2139 | return GameServer()->Antibot(); |
| 2140 | } |
| 2141 | |
| 2142 | void CCharacter::SetTeams(CGameTeams *pTeams) |
| 2143 | { |
| 2144 | m_pTeams = pTeams; |
| 2145 | m_Core.SetTeamsCore(&m_pTeams->m_Core); |
| 2146 | } |
| 2147 | |
| 2148 | bool CCharacter::TrySetRescue(int RescueMode) |
| 2149 | { |
| 2150 | bool Set = false; |
| 2151 | if(g_Config.m_SvRescue || ((g_Config.m_SvTeam == SV_TEAM_FORCED_SOLO || Team() > TEAM_FLOCK) && Teams()->IsValidTeamNumber(Team: Team()))) |
| 2152 | { |
| 2153 | // check for nearby health pickups (also freeze) |
| 2154 | bool InHealthPickup = false; |
| 2155 | if(!m_Core.m_IsInFreeze) |
| 2156 | { |
| 2157 | CEntity *apEnts[9]; |
| 2158 | int Num = GameWorld()->FindEntities(Pos: m_Pos, Radius: GetProximityRadius() + CPickup::ms_CollisionExtraSize, ppEnts: apEnts, Max: std::size(apEnts), Type: CGameWorld::ENTTYPE_PICKUP); |
| 2159 | for(int i = 0; i < Num; ++i) |
| 2160 | { |
| 2161 | CPickup *pPickup = static_cast<CPickup *>(apEnts[i]); |
| 2162 | if(pPickup->Type() == POWERUP_HEALTH) |
| 2163 | { |
| 2164 | // This uses a separate variable InHealthPickup instead of setting m_Core.m_IsInFreeze |
| 2165 | // as the latter causes freezebars to flicker when standing in the freeze range of a |
| 2166 | // health pickup. When the same code for client prediction is added, the freezebars |
| 2167 | // still flicker, but only when standing at the edge of the health pickup's freeze range. |
| 2168 | InHealthPickup = true; |
| 2169 | break; |
| 2170 | } |
| 2171 | } |
| 2172 | } |
| 2173 | |
| 2174 | if(!m_Core.m_IsInFreeze && IsGrounded() && !m_Core.m_DeepFrozen && !InHealthPickup) |
| 2175 | { |
| 2176 | ForceSetRescue(RescueMode); |
| 2177 | Set = true; |
| 2178 | } |
| 2179 | } |
| 2180 | |
| 2181 | return Set; |
| 2182 | } |
| 2183 | |
| 2184 | void CCharacter::ForceSetRescue(int RescueMode) |
| 2185 | { |
| 2186 | m_RescueTee[RescueMode].Save(pChr: this); |
| 2187 | m_SetSavePos[RescueMode] = true; |
| 2188 | } |
| 2189 | |
| 2190 | void CCharacter::DDRaceTick() |
| 2191 | { |
| 2192 | mem_copy(dest: &m_Input, source: &m_SavedInput, size: sizeof(m_Input)); |
| 2193 | GameServer()->m_pController->SetArmorProgress(pCharacter: this, Progress: m_FreezeTime); |
| 2194 | if(m_Input.m_Direction != 0 || m_Input.m_Jump != 0) |
| 2195 | m_LastMove = Server()->Tick(); |
| 2196 | |
| 2197 | if(m_Core.m_LiveFrozen && !m_Core.m_Super && !m_Core.m_Invincible) |
| 2198 | { |
| 2199 | m_Input.m_Direction = 0; |
| 2200 | m_Input.m_Jump = 0; |
| 2201 | // Hook is possible in live freeze |
| 2202 | } |
| 2203 | if(m_FreezeTime > 0) |
| 2204 | { |
| 2205 | if(m_FreezeTime % Server()->TickSpeed() == Server()->TickSpeed() - 1) |
| 2206 | { |
| 2207 | GameServer()->CreateDamageInd(Pos: m_Pos, AngleMod: 0, Amount: (m_FreezeTime + 1) / Server()->TickSpeed(), Mask: TeamMask() & GameServer()->ClientsMaskExcludeClientVersionAndHigher(Version: VERSION_DDNET_NEW_HUD)); |
| 2208 | } |
| 2209 | m_FreezeTime--; |
| 2210 | m_Input.m_Direction = 0; |
| 2211 | m_Input.m_Jump = 0; |
| 2212 | m_Input.m_Hook = 0; |
| 2213 | if(m_FreezeTime == 1) |
| 2214 | UnFreeze(); |
| 2215 | } |
| 2216 | |
| 2217 | HandleTuneLayer(); // need this before coretick |
| 2218 | |
| 2219 | // check if the tee is in any type of freeze |
| 2220 | int Index = Collision()->GetPureMapIndex(Pos: m_Pos); |
| 2221 | const int aTiles[] = { |
| 2222 | Collision()->GetTileIndex(Index), |
| 2223 | Collision()->GetFrontTileIndex(Index), |
| 2224 | Collision()->GetSwitchType(Index)}; |
| 2225 | m_Core.m_IsInFreeze = false; |
| 2226 | for(const int Tile : aTiles) |
| 2227 | { |
| 2228 | if(Tile == TILE_FREEZE || Tile == TILE_DFREEZE || Tile == TILE_LFREEZE || Tile == TILE_DEATH) |
| 2229 | { |
| 2230 | m_Core.m_IsInFreeze = true; |
| 2231 | break; |
| 2232 | } |
| 2233 | } |
| 2234 | m_Core.m_IsInFreeze |= (Collision()->GetCollisionAt(x: m_Pos.x + GetProximityRadius() / 3.f, y: m_Pos.y - GetProximityRadius() / 3.f) == TILE_DEATH || |
| 2235 | Collision()->GetCollisionAt(x: m_Pos.x + GetProximityRadius() / 3.f, y: m_Pos.y + GetProximityRadius() / 3.f) == TILE_DEATH || |
| 2236 | Collision()->GetCollisionAt(x: m_Pos.x - GetProximityRadius() / 3.f, y: m_Pos.y - GetProximityRadius() / 3.f) == TILE_DEATH || |
| 2237 | Collision()->GetCollisionAt(x: m_Pos.x - GetProximityRadius() / 3.f, y: m_Pos.y + GetProximityRadius() / 3.f) == TILE_DEATH || |
| 2238 | Collision()->GetFrontCollisionAt(x: m_Pos.x + GetProximityRadius() / 3.f, y: m_Pos.y - GetProximityRadius() / 3.f) == TILE_DEATH || |
| 2239 | Collision()->GetFrontCollisionAt(x: m_Pos.x + GetProximityRadius() / 3.f, y: m_Pos.y + GetProximityRadius() / 3.f) == TILE_DEATH || |
| 2240 | Collision()->GetFrontCollisionAt(x: m_Pos.x - GetProximityRadius() / 3.f, y: m_Pos.y - GetProximityRadius() / 3.f) == TILE_DEATH || |
| 2241 | Collision()->GetFrontCollisionAt(x: m_Pos.x - GetProximityRadius() / 3.f, y: m_Pos.y + GetProximityRadius() / 3.f) == TILE_DEATH); |
| 2242 | |
| 2243 | // look for save position for rescue feature |
| 2244 | // always update auto rescue |
| 2245 | TrySetRescue(RescueMode: RESCUEMODE_AUTO); |
| 2246 | |
| 2247 | m_Core.m_Id = GetPlayer()->GetCid(); |
| 2248 | } |
| 2249 | |
| 2250 | void CCharacter::DDRacePostCoreTick() |
| 2251 | { |
| 2252 | m_Time = (float)(Server()->Tick() - m_StartTime) / ((float)Server()->TickSpeed()); |
| 2253 | |
| 2254 | if(m_Core.m_EndlessHook || (m_Core.m_Super && g_Config.m_SvEndlessSuperHook)) |
| 2255 | m_Core.m_HookTick = 0; |
| 2256 | |
| 2257 | m_FrozenLastTick = false; |
| 2258 | |
| 2259 | if(m_Core.m_DeepFrozen && !m_Core.m_Super && !m_Core.m_Invincible) |
| 2260 | Freeze(); |
| 2261 | |
| 2262 | // following jump rules can be overridden by tiles, like Refill Jumps, Stopper and Wall Jump |
| 2263 | if(m_Core.m_Jumps == -1) |
| 2264 | { |
| 2265 | // The player has only one ground jump, so his feet are always dark |
| 2266 | m_Core.m_Jumped |= 2; |
| 2267 | } |
| 2268 | else if(m_Core.m_Jumps == 0) |
| 2269 | { |
| 2270 | // The player has no jumps at all, so his feet are always dark |
| 2271 | m_Core.m_Jumped |= 2; |
| 2272 | } |
| 2273 | else if(m_Core.m_Jumps == 1 && m_Core.m_Jumped > 0) |
| 2274 | { |
| 2275 | // If the player has only one jump, each jump is the last one |
| 2276 | m_Core.m_Jumped |= 2; |
| 2277 | } |
| 2278 | else if(m_Core.m_JumpedTotal < m_Core.m_Jumps - 1 && m_Core.m_Jumped > 1) |
| 2279 | { |
| 2280 | // The player has not yet used up all his jumps, so his feet remain light |
| 2281 | m_Core.m_Jumped = 1; |
| 2282 | } |
| 2283 | |
| 2284 | if((m_Core.m_Super || m_Core.m_EndlessJump) && m_Core.m_Jumped > 1) |
| 2285 | { |
| 2286 | // Super players and players with infinite jumps always have light feet |
| 2287 | m_Core.m_Jumped = 1; |
| 2288 | } |
| 2289 | |
| 2290 | int CurrentIndex = Collision()->GetMapIndex(Pos: m_Pos); |
| 2291 | HandleSkippableTiles(Index: CurrentIndex); |
| 2292 | if(!m_Alive) |
| 2293 | return; |
| 2294 | |
| 2295 | // handle Anti-Skip tiles |
| 2296 | std::vector<int> vIndices = Collision()->GetMapIndices(PrevPos: m_PrevPos, Pos: m_Pos); |
| 2297 | if(!vIndices.empty()) |
| 2298 | { |
| 2299 | for(int &Index : vIndices) |
| 2300 | { |
| 2301 | HandleTiles(Index); |
| 2302 | if(!m_Alive) |
| 2303 | return; |
| 2304 | } |
| 2305 | } |
| 2306 | else |
| 2307 | { |
| 2308 | HandleTiles(Index: CurrentIndex); |
| 2309 | if(!m_Alive) |
| 2310 | return; |
| 2311 | } |
| 2312 | |
| 2313 | // teleport gun |
| 2314 | if(m_TeleGunTeleport) |
| 2315 | { |
| 2316 | GameServer()->CreateDeath(Pos: m_Pos, ClientId: m_pPlayer->GetCid(), Mask: TeamMask()); |
| 2317 | m_Core.m_Pos = m_TeleGunPos; |
| 2318 | if(!m_IsBlueTeleGunTeleport) |
| 2319 | m_Core.m_Vel = vec2(0, 0); |
| 2320 | GameServer()->CreateDeath(Pos: m_TeleGunPos, ClientId: m_pPlayer->GetCid(), Mask: TeamMask()); |
| 2321 | GameServer()->CreateSound(Pos: m_TeleGunPos, Sound: SOUND_WEAPON_SPAWN, Mask: TeamMask()); |
| 2322 | m_TeleGunTeleport = false; |
| 2323 | m_IsBlueTeleGunTeleport = false; |
| 2324 | } |
| 2325 | |
| 2326 | HandleBroadcast(); |
| 2327 | } |
| 2328 | |
| 2329 | bool CCharacter::Freeze(int Seconds) |
| 2330 | { |
| 2331 | if(Seconds <= 0 || m_Core.m_Super || m_Core.m_Invincible || m_FreezeTime > Seconds * Server()->TickSpeed()) |
| 2332 | return false; |
| 2333 | if(m_FreezeTime == 0 || m_Core.m_FreezeStart < Server()->Tick() - Server()->TickSpeed()) |
| 2334 | { |
| 2335 | m_Armor = 0; |
| 2336 | m_FreezeTime = Seconds * Server()->TickSpeed(); |
| 2337 | m_Core.m_FreezeStart = Server()->Tick(); |
| 2338 | return true; |
| 2339 | } |
| 2340 | return false; |
| 2341 | } |
| 2342 | |
| 2343 | bool CCharacter::Freeze() |
| 2344 | { |
| 2345 | return Freeze(Seconds: g_Config.m_SvFreezeDelay); |
| 2346 | } |
| 2347 | |
| 2348 | bool CCharacter::UnFreeze() |
| 2349 | { |
| 2350 | if(m_FreezeTime > 0) |
| 2351 | { |
| 2352 | m_Armor = 10; |
| 2353 | if(!m_Core.m_aWeapons[m_Core.m_ActiveWeapon].m_Got) |
| 2354 | m_Core.m_ActiveWeapon = WEAPON_GUN; |
| 2355 | m_FreezeTime = 0; |
| 2356 | m_Core.m_FreezeStart = 0; |
| 2357 | m_FrozenLastTick = true; |
| 2358 | return true; |
| 2359 | } |
| 2360 | return false; |
| 2361 | } |
| 2362 | |
| 2363 | void CCharacter::ResetJumps() |
| 2364 | { |
| 2365 | m_Core.m_JumpedTotal = 0; |
| 2366 | m_Core.m_Jumped = 0; |
| 2367 | } |
| 2368 | |
| 2369 | void CCharacter::GiveWeapon(int Weapon, bool Remove) |
| 2370 | { |
| 2371 | if(Weapon == WEAPON_NINJA) |
| 2372 | { |
| 2373 | if(Remove) |
| 2374 | RemoveNinja(); |
| 2375 | else |
| 2376 | GiveNinja(); |
| 2377 | return; |
| 2378 | } |
| 2379 | |
| 2380 | if(Remove) |
| 2381 | { |
| 2382 | if(GetActiveWeapon() == Weapon) |
| 2383 | SetActiveWeapon(WEAPON_GUN); |
| 2384 | } |
| 2385 | else |
| 2386 | { |
| 2387 | m_Core.m_aWeapons[Weapon].m_Ammo = -1; |
| 2388 | } |
| 2389 | |
| 2390 | m_Core.m_aWeapons[Weapon].m_Got = !Remove; |
| 2391 | } |
| 2392 | |
| 2393 | void CCharacter::GiveAllWeapons() |
| 2394 | { |
| 2395 | for(int i = WEAPON_GUN; i < NUM_WEAPONS - 1; i++) |
| 2396 | { |
| 2397 | GiveWeapon(Weapon: i); |
| 2398 | } |
| 2399 | } |
| 2400 | |
| 2401 | void CCharacter::ResetPickups() |
| 2402 | { |
| 2403 | for(int i = WEAPON_SHOTGUN; i < NUM_WEAPONS - 1; i++) |
| 2404 | { |
| 2405 | m_Core.m_aWeapons[i].m_Got = false; |
| 2406 | if(m_Core.m_ActiveWeapon == i) |
| 2407 | m_Core.m_ActiveWeapon = WEAPON_GUN; |
| 2408 | } |
| 2409 | } |
| 2410 | |
| 2411 | void CCharacter::SetEndlessHook(bool Enable) |
| 2412 | { |
| 2413 | if(m_Core.m_EndlessHook == Enable) |
| 2414 | { |
| 2415 | return; |
| 2416 | } |
| 2417 | GameServer()->SendChatTarget(To: GetPlayer()->GetCid(), pText: Enable ? "Endless hook has been activated" : "Endless hook has been deactivated" ); |
| 2418 | |
| 2419 | m_Core.m_EndlessHook = Enable; |
| 2420 | } |
| 2421 | |
| 2422 | void CCharacter::Pause(bool Pause) |
| 2423 | { |
| 2424 | m_Paused = Pause; |
| 2425 | if(Pause) |
| 2426 | { |
| 2427 | GameServer()->m_World.m_Core.m_apCharacters[m_pPlayer->GetCid()] = nullptr; |
| 2428 | GameServer()->m_World.RemoveEntity(pEntity: this); |
| 2429 | |
| 2430 | if(m_Core.HookedPlayer() != -1) // Keeping hook would allow cheats |
| 2431 | { |
| 2432 | ResetHook(); |
| 2433 | GameWorld()->ReleaseHooked(ClientId: GetPlayer()->GetCid()); |
| 2434 | } |
| 2435 | m_PausedTick = Server()->Tick(); |
| 2436 | } |
| 2437 | else |
| 2438 | { |
| 2439 | m_Core.m_Vel = vec2(0, 0); |
| 2440 | GameServer()->m_World.m_Core.m_apCharacters[m_pPlayer->GetCid()] = &m_Core; |
| 2441 | GameServer()->m_World.InsertEntity(pEntity: this); |
| 2442 | if(m_Core.m_FreezeStart > 0 && m_PausedTick >= 0) |
| 2443 | { |
| 2444 | m_Core.m_FreezeStart += Server()->Tick() - m_PausedTick; |
| 2445 | } |
| 2446 | } |
| 2447 | } |
| 2448 | |
| 2449 | void CCharacter::DDRaceInit() |
| 2450 | { |
| 2451 | m_Paused = false; |
| 2452 | m_DDRaceState = ERaceState::NONE; |
| 2453 | m_PrevPos = m_Pos; |
| 2454 | for(bool &Set : m_SetSavePos) |
| 2455 | Set = false; |
| 2456 | m_LastBroadcast = 0; |
| 2457 | m_TeamBeforeSuper = 0; |
| 2458 | m_Core.m_Id = GetPlayer()->GetCid(); |
| 2459 | m_TeleCheckpoint = 0; |
| 2460 | m_Core.m_EndlessHook = g_Config.m_SvEndlessDrag; |
| 2461 | if(g_Config.m_SvHit) |
| 2462 | { |
| 2463 | m_Core.m_HammerHitDisabled = false; |
| 2464 | m_Core.m_ShotgunHitDisabled = false; |
| 2465 | m_Core.m_GrenadeHitDisabled = false; |
| 2466 | m_Core.m_LaserHitDisabled = false; |
| 2467 | } |
| 2468 | else |
| 2469 | { |
| 2470 | m_Core.m_HammerHitDisabled = true; |
| 2471 | m_Core.m_ShotgunHitDisabled = true; |
| 2472 | m_Core.m_GrenadeHitDisabled = true; |
| 2473 | m_Core.m_LaserHitDisabled = true; |
| 2474 | } |
| 2475 | m_Core.m_Jumps = 2; |
| 2476 | |
| 2477 | int Team = Teams()->m_Core.Team(ClientId: m_Core.m_Id); |
| 2478 | |
| 2479 | if(Teams()->TeamLocked(Team) && !Teams()->TeamFlock(Team)) |
| 2480 | { |
| 2481 | for(int i = 0; i < MAX_CLIENTS; i++) |
| 2482 | { |
| 2483 | if(Teams()->m_Core.Team(ClientId: i) == Team && i != m_Core.m_Id && GameServer()->m_apPlayers[i]) |
| 2484 | { |
| 2485 | CCharacter *pChar = GameServer()->m_apPlayers[i]->GetCharacter(); |
| 2486 | |
| 2487 | if(pChar) |
| 2488 | { |
| 2489 | m_DDRaceState = pChar->m_DDRaceState; |
| 2490 | m_StartTime = pChar->m_StartTime; |
| 2491 | } |
| 2492 | } |
| 2493 | } |
| 2494 | } |
| 2495 | |
| 2496 | if(g_Config.m_SvTeam == SV_TEAM_MANDATORY && Team == TEAM_FLOCK) |
| 2497 | { |
| 2498 | GameServer()->SendStartWarning(ClientId: GetPlayer()->GetCid(), pMessage: "Please join a team before you start" ); |
| 2499 | } |
| 2500 | } |
| 2501 | |
| 2502 | void CCharacter::Rescue() |
| 2503 | { |
| 2504 | if(m_SetSavePos[GetPlayer()->m_RescueMode] && !m_Core.m_Super && !m_Core.m_Invincible) |
| 2505 | { |
| 2506 | if(m_LastRescue + (int64_t)g_Config.m_SvRescueDelay * Server()->TickSpeed() > Server()->Tick() && !Teams()->IsPractice(Team: Team())) |
| 2507 | { |
| 2508 | char aBuf[256]; |
| 2509 | str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "You have to wait %d seconds until you can rescue yourself" , (int)((m_LastRescue + (int64_t)g_Config.m_SvRescueDelay * Server()->TickSpeed() - Server()->Tick()) / Server()->TickSpeed())); |
| 2510 | GameServer()->SendChatTarget(To: GetPlayer()->GetCid(), pText: aBuf); |
| 2511 | return; |
| 2512 | } |
| 2513 | |
| 2514 | m_LastRescue = Server()->Tick(); |
| 2515 | int StartTime = m_StartTime; |
| 2516 | m_RescueTee[GetPlayer()->m_RescueMode].Load(pChr: this); |
| 2517 | // Don't load these from saved tee: |
| 2518 | m_Core.m_Vel = vec2(0, 0); |
| 2519 | m_Core.m_HookState = HOOK_IDLE; |
| 2520 | m_StartTime = StartTime; |
| 2521 | m_SavedInput.m_Direction = 0; |
| 2522 | m_SavedInput.m_Jump = 0; |
| 2523 | // simulate releasing the fire button |
| 2524 | if((m_SavedInput.m_Fire & 1) != 0) |
| 2525 | m_SavedInput.m_Fire++; |
| 2526 | m_SavedInput.m_Fire &= INPUT_STATE_MASK; |
| 2527 | m_SavedInput.m_Hook = 0; |
| 2528 | m_pPlayer->Pause(State: CPlayer::PAUSE_NONE, Force: true); |
| 2529 | } |
| 2530 | } |
| 2531 | |
| 2532 | CClientMask CCharacter::TeamMask() |
| 2533 | { |
| 2534 | return Teams()->TeamMask(Team: Team(), ExceptId: -1, Asker: GetPlayer()->GetCid()); |
| 2535 | } |
| 2536 | |
| 2537 | void CCharacter::SetPosition(const vec2 &Position) |
| 2538 | { |
| 2539 | m_Core.m_Pos = Position; |
| 2540 | } |
| 2541 | |
| 2542 | void CCharacter::Move(vec2 RelPos) |
| 2543 | { |
| 2544 | m_Core.m_Pos += RelPos; |
| 2545 | } |
| 2546 | |
| 2547 | void CCharacter::ResetVelocity() |
| 2548 | { |
| 2549 | m_Core.m_Vel = vec2(0, 0); |
| 2550 | } |
| 2551 | |
| 2552 | void CCharacter::SetVelocity(vec2 NewVelocity) |
| 2553 | { |
| 2554 | m_Core.m_Vel = ClampVel(MoveRestriction: m_MoveRestrictions, Vel: NewVelocity); |
| 2555 | } |
| 2556 | |
| 2557 | // The method is needed only to reproduce 'shotgun bug' ddnet#5258 |
| 2558 | // Use SetVelocity() instead. |
| 2559 | void CCharacter::SetRawVelocity(vec2 NewVelocity) |
| 2560 | { |
| 2561 | m_Core.m_Vel = NewVelocity; |
| 2562 | } |
| 2563 | |
| 2564 | void CCharacter::AddVelocity(vec2 Addition) |
| 2565 | { |
| 2566 | SetVelocity(m_Core.m_Vel + Addition); |
| 2567 | } |
| 2568 | |
| 2569 | void CCharacter::ApplyMoveRestrictions() |
| 2570 | { |
| 2571 | m_Core.m_Vel = ClampVel(MoveRestriction: m_MoveRestrictions, Vel: m_Core.m_Vel); |
| 2572 | } |
| 2573 | |
| 2574 | void CCharacter::SwapClients(int Client1, int Client2) |
| 2575 | { |
| 2576 | const int HookedPlayer = m_Core.HookedPlayer(); |
| 2577 | m_Core.SetHookedPlayer(HookedPlayer == Client1 ? Client2 : (HookedPlayer == Client2 ? Client1 : HookedPlayer)); |
| 2578 | } |
| 2579 | |