move ApplyPhysicsAtRespawn to an overridable label

This commit is contained in:
Beu 2021-12-19 16:13:19 +01:00
parent 1b6ad5014c
commit 825637338f

View File

@ -139,40 +139,7 @@ foreach (Event in UIManager.PendingEvents) { // TODO: Add Secure token to admins
} }
} }
foreach (Event in RacePendingEvents) { ---PhysicsController_ApplyPhysicsAtRespawn---
Log::Log("[RacePendingEvents] Event.Type: " ^ Event.Type);
if (Event.Type == Events::C_Type_StartLine || Event.Type == Events::C_Type_GiveUp || Event.Type == Events::C_Type_SkipOutro) {
ApplyPhysicsAtRespawn_Queue[Event.Player.User.WebServicesUserId] = K_RespawnStatus {
ResetBeforeAppling = False,
RespawnTime = Now
} ;
} else if (Event.Type == Events::C_Type_Respawn) {
declare netwrite K_PlayerPhysics Net_PlayerPhysics for Event.Player = InitPlayerPhysicsVariable();
ApplyPhysicsAtRespawn_Queue[Event.Player.User.WebServicesUserId] = K_RespawnStatus {
ResetBeforeAppling = True,
RespawnTime = Now
} ;
}
}
if (Now % 100 == 0 && ApplyPhysicsAtRespawn_Queue.count > 0) {
foreach (AccountId => RespawnStatus in ApplyPhysicsAtRespawn_Queue) {
declare CSmPlayer Player = ModeUtils::GetPlayerFromAccountId(AccountId);
if (Player != Null && (Player.SpawnStatus == CSmPlayer::ESpawnStatus::Spawned || Player.SpawnStatus == CSmPlayer::ESpawnStatus::Spawning)) {
Log::Log("[ApplyPhysicsAtRespawn] Player: " ^ Player.User.Name);
if (RespawnStatus.ResetBeforeAppling) SetPhysicsChange("Reset", "", Player);
ApplyPhysicsAtRespawn(Player);
ApplyPhysicsAtRespawn_Queue.removekey(AccountId);
} else if (RespawnStatus.RespawnTime > Now || RespawnStatus.RespawnTime + 10000 < Now ) { // Clear ApplyPhysicsAtRespawn_Queue array if player is DC
Log::Log("[ApplyPhysicsAtRespawn] Clear from array after 10s: " ^ AccountId);
if (Player != Null) {
declare netwrite K_PlayerPhysics Net_PlayerPhysics for Player = InitPlayerPhysicsVariable();
Net_PlayerPhysics = InitPlayerPhysicsVariable();
}
ApplyPhysicsAtRespawn_Queue.removekey(AccountId);
}
}
}
if (Last_AdminPlayers != S_AdminPlayers) { if (Last_AdminPlayers != S_AdminPlayers) {
Last_AdminPlayers = S_AdminPlayers; Last_AdminPlayers = S_AdminPlayers;
@ -235,6 +202,44 @@ if (Net_ServerAllowPlayersToBeControledBySpectators != S_AllowPlayersToBeControl
} }
*** ***
***PhysicsController_ApplyPhysicsAtRespawn***
***
foreach (Event in RacePendingEvents) {
Log::Log("[RacePendingEvents] Event.Type: " ^ Event.Type);
if (Event.Type == Events::C_Type_StartLine || Event.Type == Events::C_Type_GiveUp || Event.Type == Events::C_Type_SkipOutro) {
ApplyPhysicsAtRespawn_Queue[Event.Player.User.WebServicesUserId] = K_RespawnStatus {
ResetBeforeAppling = False,
RespawnTime = Now
} ;
} else if (Event.Type == Events::C_Type_Respawn) {
declare netwrite K_PlayerPhysics Net_PlayerPhysics for Event.Player = InitPlayerPhysicsVariable();
ApplyPhysicsAtRespawn_Queue[Event.Player.User.WebServicesUserId] = K_RespawnStatus {
ResetBeforeAppling = True,
RespawnTime = Now
} ;
}
}
if (Now % 100 == 0 && ApplyPhysicsAtRespawn_Queue.count > 0) {
foreach (AccountId => RespawnStatus in ApplyPhysicsAtRespawn_Queue) {
declare CSmPlayer Player = ModeUtils::GetPlayerFromAccountId(AccountId);
if (Player != Null && (Player.SpawnStatus == CSmPlayer::ESpawnStatus::Spawned || Player.SpawnStatus == CSmPlayer::ESpawnStatus::Spawning)) {
Log::Log("[ApplyPhysicsAtRespawn] Player: " ^ Player.User.Name);
if (RespawnStatus.ResetBeforeAppling) SetPhysicsChange("Reset", "", Player);
ApplyPhysicsAtRespawn(Player);
ApplyPhysicsAtRespawn_Queue.removekey(AccountId);
} else if (RespawnStatus.RespawnTime > Now || RespawnStatus.RespawnTime + 10000 < Now ) { // Clear ApplyPhysicsAtRespawn_Queue array if player is DC
Log::Log("[ApplyPhysicsAtRespawn] Clear from array after 10s: " ^ AccountId);
if (Player != Null) {
declare netwrite K_PlayerPhysics Net_PlayerPhysics for Player = InitPlayerPhysicsVariable();
Net_PlayerPhysics = InitPlayerPhysicsVariable();
}
ApplyPhysicsAtRespawn_Queue.removekey(AccountId);
}
}
}
***
K_PlayerPhysics InitPlayerPhysicsVariable() { K_PlayerPhysics InitPlayerPhysicsVariable() {
return K_PlayerPhysics { return K_PlayerPhysics {
AccelCoef = 1., AccelCoef = 1.,