From 59c269724c7b50ba2c5dc7c82b6cdac7336726d9 Mon Sep 17 00:00:00 2001 From: nomisum Date: Wed, 5 Jun 2024 20:27:11 +0200 Subject: [PATCH] uncomment deprecated comments to allow mission load --- .../Components/GRAD_ItemPlacementComponent.c | 401 ++++---- Scripts/Game/Player/GRAD_PlayerController.c | 898 +++++++++--------- 2 files changed, 652 insertions(+), 647 deletions(-) diff --git a/Scripts/Game/Components/GRAD_ItemPlacementComponent.c b/Scripts/Game/Components/GRAD_ItemPlacementComponent.c index 3c0ba36..80fb364 100644 --- a/Scripts/Game/Components/GRAD_ItemPlacementComponent.c +++ b/Scripts/Game/Components/GRAD_ItemPlacementComponent.c @@ -1,198 +1,203 @@ -//------------------------------------------------------------------------------------------------ -modded class SCR_ItemPlacementComponent : ScriptComponent -{ - // This modification bypasses the placing animation and adds item rotation in preview - - float m_fPlacementRotation = 0; - GRAD_PlacementOverrideComponent m_PlacementOverrideComponent; - bool m_bPlacementOverrideEnabled = false; - IEntity weaponEntity; - - //------------------------------------------------------------------------------------------------ - override protected void StartPlaceItem() - { - if (!m_bCanPlace) - return; - - IEntity controlledEntity = GetGame().GetPlayerController().GetControlledEntity(); - if (!controlledEntity) - return; - - SCR_CharacterControllerComponent characterController = GetCharacterController(controlledEntity); - if (!characterController) - return; - - characterController.SetDisableWeaponControls(true); - characterController.SetDisableMovementControls(true); - - if (characterController.IsUsingItem()) - return; - - ChimeraCharacter character = ChimeraCharacter.Cast(controlledEntity); - vector mat[4]; - Math3D.MatrixCopy(m_vCurrentMat, mat); - PointInfo ptWS = new PointInfo(); - mat[2] = (mat[3] - character.GetOrigin()).Normalized(); - mat[1] = vector.Up; - mat[0] = Vector(mat[2][2], mat[2][1], -mat[2][0]); - ptWS.Set(null, "", mat); - - /* ======================================== */ - // modded: disable placing animation - if (m_bPlacementOverrideEnabled) - { - SCR_ConsumableEffectAnimationParameters animParams; // added by mod - OnPlacingEnded(m_EquippedItem, true, animParams); // added by mod - DisablePreview(); - } - else - { - CharacterAnimationComponent animationComponent = character.GetAnimationComponent(); - int itemActionId = animationComponent.BindCommand("CMD_Item_Action"); - if (characterController.TryUseItemOverrideParams(m_EquippedItem, false, false, itemActionId, 1, 0, 15.0, 1, 0.0, false, ptWS)) - { - characterController.m_OnItemUseEndedInvoker.Insert(OnPlacingEnded); - DisablePreview(); - } - } - /* ======================================== */ - - characterController.GetAnimationComponent().GetCommandHandler().AlignNewTurns(); - - OrientToNormal(m_vCurrentMat[1]); - } - - //------------------------------------------------------------------------------------------------ - override void UseXYZPlacement(IEntity owner, float maxPlacementDistance, vector cameraMat[4]) - { - // Trace against terrain and entities to detect item placement position - TraceParam param = new TraceParam(); - param.Start = cameraMat[3]; - param.End = param.Start + cameraMat[2] * maxPlacementDistance; - param.Flags = TraceFlags.WORLD | TraceFlags.ENTS; - param.Exclude = SCR_PlayerController.GetLocalControlledEntity(); - param.LayerMask = EPhysicsLayerPresets.Projectile; - BaseWorld world = owner.GetWorld(); - float traceDistance = world.TraceMove(param, ExcludeWaterCallback); - m_PreviewEntity.GetTransform(m_vCurrentMat); - m_vCurrentMat[3] = param.Start + ((param.End - param.Start) * traceDistance); - vector up = param.TraceNorm; - - IEntity tracedEntity = param.TraceEnt; - - if (traceDistance == 1) // Assume we didn't hit anything and snap item on the ground - { - // Trace against terrain and entities to detect new placement position - TraceParam paramGround = new TraceParam(); - paramGround.Start = param.End + vector.Up; - paramGround.End = paramGround.Start - vector.Up * 20; - paramGround.Flags = TraceFlags.WORLD | TraceFlags.ENTS; - paramGround.Exclude = SCR_PlayerController.GetLocalControlledEntity(); - paramGround.LayerMask = EPhysicsLayerPresets.Projectile; - float traceGroundDistance = world.TraceMove(paramGround, ExcludeWaterCallback); - m_PreviewEntity.GetTransform(m_vCurrentMat); - m_vCurrentMat[3] = paramGround.Start + ((paramGround.End - paramGround.Start) * traceGroundDistance) + vector.Up * 0.01; // adding 1 cm to avoid collision with object under - - if (traceGroundDistance < 1) - up = paramGround.TraceNorm; - - tracedEntity = paramGround.TraceEnt; - } - - OrientToNormal(up); - - m_PreviewEntity.SetTransform(m_vCurrentMat); - - /* ======================================== */ - // modded: adding rotation to the preview - if (m_bPlacementOverrideEnabled) - { - vector angles = m_PreviewEntity.GetAngles(); - angles[1] = angles[1] + m_fPlacementRotation; - m_PreviewEntity.SetAngles(angles); - m_PreviewEntity.GetTransform(m_vCurrentMat); - } - /* ======================================== */ - - m_PreviewEntity.Update(); - - IEntity character = SCR_PlayerController.GetLocalControlledEntity(); - vector characterOrigin = character.GetOrigin(); - - if (Math.AbsFloat(m_vCurrentMat[3][1] - characterOrigin[1] > 0.4)) // Reject based on vertical distance from character - { - m_bCanPlace = false; - return; - } - - if (vector.Distance(m_vCurrentMat[3], characterOrigin) > maxPlacementDistance) // Reject based on distance from character (the maximum should be dictated by item settings) - { - m_bCanPlace = false; - return; - } - - m_bCanPlace = ValidatePlacement(up, tracedEntity, world, SCR_PlayerController.GetLocalControlledEntity()); - } - - - //------------------------------------------------------------------------------------------------ - override protected void DisablePreview() - { - InputManager inputManager = GetGame().GetInputManager(); - if (!inputManager) - return; - - if (m_bPlacementOverrideEnabled) - { - weaponEntity.SetFlags(weaponEntity.GetFlags() | EntityFlags.VISIBLE); - - inputManager.ActivateContext("RotatePreviewContext", 0); - inputManager.RemoveActionListener("RotateLeft", EActionTrigger.DOWN, RotateLeft); - inputManager.RemoveActionListener("RotateRight", EActionTrigger.DOWN, RotateRight); - } - - super.DisablePreview(); - } - - //------------------------------------------------------------------------------------------------ - override protected void EnablePreview(IEntity weapon) - { - m_PlacementOverrideComponent = GRAD_PlacementOverrideComponent.Cast(weapon.FindComponent(GRAD_PlacementOverrideComponent)); - - weaponEntity = weapon; - - if (m_PlacementOverrideComponent) - { - m_bPlacementOverrideEnabled = m_PlacementOverrideComponent.GetOverrideVanillaPlacement(); - } - - if (m_bPlacementOverrideEnabled) - { - weaponEntity.ClearFlags(EntityFlags.VISIBLE); - - //weaponEntity.SetScale(0.1); // doesn't work; perhaps because weapon is contineously transformed - - InputManager inputManager = GetGame().GetInputManager(); - if (!inputManager) - return; - - inputManager.AddActionListener("RotateLeft", EActionTrigger.DOWN, RotateLeft); - inputManager.AddActionListener("RotateRight", EActionTrigger.DOWN, RotateRight); - inputManager.ActivateContext("RotatePreviewContext", 3600000); - } - - super.EnablePreview(weapon); - } - - //------------------------------------------------------------------------------------------------ - protected void RotateLeft() - { - m_fPlacementRotation += 5; - } - - //------------------------------------------------------------------------------------------------ - protected void RotateRight() - { - m_fPlacementRotation -= 5; - } -}; +//------------------------------------------------------------------------------------------------ +modded class SCR_ItemPlacementComponent : ScriptComponent +{ + // This modification bypasses the placing animation and adds item rotation in preview + + float m_fPlacementRotation = 0; + GRAD_PlacementOverrideComponent m_PlacementOverrideComponent; + bool m_bPlacementOverrideEnabled = false; + IEntity weaponEntity; + + //------------------------------------------------------------------------------------------------ + override protected void StartPlaceItem() + { + if (!m_bCanPlace) + return; + + IEntity controlledEntity = GetGame().GetPlayerController().GetControlledEntity(); + if (!controlledEntity) + return; + + ChimeraCharacter character = ChimeraCharacter.Cast(controlledEntity); + if (!character) + return; + + CharacterControllerComponent characterController = character.GetCharacterController(); + if (!characterController) + return; + + characterController.SetDisableWeaponControls(true); + characterController.SetDisableMovementControls(true); + + if (characterController.IsUsingItem()) + return; + + vector mat[4]; + Math3D.MatrixCopy(m_vCurrentMat, mat); + PointInfo ptWS = new PointInfo(); + mat[2] = (mat[3] - character.GetOrigin()).Normalized(); + mat[1] = vector.Up; + mat[0] = Vector(mat[2][2], mat[2][1], -mat[2][0]); + ptWS.Set(null, "", mat); + + /* ======================================== */ + // modded: disable placing animation + /* + if (m_bPlacementOverrideEnabled) + { + ItemUseParameters animParams; // added by mod + OnPlacingEnded(m_EquippedItem, true, animParams); // added by mod + DisablePreview(); + } + else + { + CharacterAnimationComponent animationComponent = character.GetAnimationComponent(); + int itemActionId = animationComponent.BindCommand("CMD_Item_Action"); + if (characterController.TryUseItemOverrideParams(m_EquippedItem, false, false, itemActionId, 1, 0, 15.0, 1, 0.0, false, ptWS)) + { + characterController.m_OnItemUseEndedInvoker.Insert(OnPlacingEnded); + DisablePreview(); + } + } + */ + /* ======================================== */ + + characterController.GetAnimationComponent().GetCommandHandler().AlignNewTurns(); + + OrientToNormal(m_vCurrentMat[1]); + } + + //------------------------------------------------------------------------------------------------ + override void UseXYZPlacement(IEntity owner, float maxPlacementDistance, vector cameraMat[4]) + { + // Trace against terrain and entities to detect item placement position + TraceParam param = new TraceParam(); + param.Start = cameraMat[3]; + param.End = param.Start + cameraMat[2] * maxPlacementDistance; + param.Flags = TraceFlags.WORLD | TraceFlags.ENTS; + param.Exclude = SCR_PlayerController.GetLocalControlledEntity(); + param.LayerMask = EPhysicsLayerPresets.Projectile; + BaseWorld world = owner.GetWorld(); + float traceDistance = world.TraceMove(param, ExcludeWaterCallback); + m_PreviewEntity.GetTransform(m_vCurrentMat); + m_vCurrentMat[3] = param.Start + ((param.End - param.Start) * traceDistance); + vector up = param.TraceNorm; + + IEntity tracedEntity = param.TraceEnt; + + if (traceDistance == 1) // Assume we didn't hit anything and snap item on the ground + { + // Trace against terrain and entities to detect new placement position + TraceParam paramGround = new TraceParam(); + paramGround.Start = param.End + vector.Up; + paramGround.End = paramGround.Start - vector.Up * 20; + paramGround.Flags = TraceFlags.WORLD | TraceFlags.ENTS; + paramGround.Exclude = SCR_PlayerController.GetLocalControlledEntity(); + paramGround.LayerMask = EPhysicsLayerPresets.Projectile; + float traceGroundDistance = world.TraceMove(paramGround, ExcludeWaterCallback); + m_PreviewEntity.GetTransform(m_vCurrentMat); + m_vCurrentMat[3] = paramGround.Start + ((paramGround.End - paramGround.Start) * traceGroundDistance) + vector.Up * 0.01; // adding 1 cm to avoid collision with object under + + if (traceGroundDistance < 1) + up = paramGround.TraceNorm; + + tracedEntity = paramGround.TraceEnt; + } + + OrientToNormal(up); + + m_PreviewEntity.SetTransform(m_vCurrentMat); + + /* ======================================== */ + // modded: adding rotation to the preview + if (m_bPlacementOverrideEnabled) + { + vector angles = m_PreviewEntity.GetAngles(); + angles[1] = angles[1] + m_fPlacementRotation; + m_PreviewEntity.SetAngles(angles); + m_PreviewEntity.GetTransform(m_vCurrentMat); + } + /* ======================================== */ + + m_PreviewEntity.Update(); + + IEntity character = SCR_PlayerController.GetLocalControlledEntity(); + vector characterOrigin = character.GetOrigin(); + + if (Math.AbsFloat(m_vCurrentMat[3][1] - characterOrigin[1] > 0.4)) // Reject based on vertical distance from character + { + m_bCanPlace = false; + return; + } + + if (vector.Distance(m_vCurrentMat[3], characterOrigin) > maxPlacementDistance) // Reject based on distance from character (the maximum should be dictated by item settings) + { + m_bCanPlace = false; + return; + } + + m_bCanPlace = ValidatePlacement(up, tracedEntity, world, SCR_PlayerController.GetLocalControlledEntity()); + } + + + //------------------------------------------------------------------------------------------------ + override protected void DisablePreview() + { + InputManager inputManager = GetGame().GetInputManager(); + if (!inputManager) + return; + + if (m_bPlacementOverrideEnabled) + { + weaponEntity.SetFlags(weaponEntity.GetFlags() | EntityFlags.VISIBLE); + + inputManager.ActivateContext("RotatePreviewContext", 0); + inputManager.RemoveActionListener("RotateLeft", EActionTrigger.DOWN, RotateLeft); + inputManager.RemoveActionListener("RotateRight", EActionTrigger.DOWN, RotateRight); + } + + super.DisablePreview(); + } + + //------------------------------------------------------------------------------------------------ + override protected void EnablePreview(IEntity weapon) + { + m_PlacementOverrideComponent = GRAD_PlacementOverrideComponent.Cast(weapon.FindComponent(GRAD_PlacementOverrideComponent)); + + weaponEntity = weapon; + + if (m_PlacementOverrideComponent) + { + m_bPlacementOverrideEnabled = m_PlacementOverrideComponent.GetOverrideVanillaPlacement(); + } + + if (m_bPlacementOverrideEnabled) + { + weaponEntity.ClearFlags(EntityFlags.VISIBLE); + + //weaponEntity.SetScale(0.1); // doesn't work; perhaps because weapon is contineously transformed + + InputManager inputManager = GetGame().GetInputManager(); + if (!inputManager) + return; + + inputManager.AddActionListener("RotateLeft", EActionTrigger.DOWN, RotateLeft); + inputManager.AddActionListener("RotateRight", EActionTrigger.DOWN, RotateRight); + inputManager.ActivateContext("RotatePreviewContext", 3600000); + } + + super.EnablePreview(weapon); + } + + //------------------------------------------------------------------------------------------------ + protected void RotateLeft() + { + m_fPlacementRotation += 5; + } + + //------------------------------------------------------------------------------------------------ + protected void RotateRight() + { + m_fPlacementRotation -= 5; + } +}; diff --git a/Scripts/Game/Player/GRAD_PlayerController.c b/Scripts/Game/Player/GRAD_PlayerController.c index d641d99..dc1c59b 100644 --- a/Scripts/Game/Player/GRAD_PlayerController.c +++ b/Scripts/Game/Player/GRAD_PlayerController.c @@ -1,449 +1,449 @@ -//------------------------------------------------------------------------------------------------ -modded class SCR_PlayerController : PlayerController -{ - [Attribute(defvalue: "{257513225CC1D5FB}UI/OTF/OTF_Overlay.layout")] - protected ResourceName m_sOverlay; - - [Attribute(defvalue: "{B764E0A789AF2F5F}UI/OTF/OTF_CountdownTimer.layout")] - protected ResourceName m_sCountdownTimer; - - protected ref Widget m_wOverlayDisplay; - protected ref Widget m_wCountdownDisplay; - protected ref Widget m_wTimerDisplay; - - protected bool m_bCoutdownRunning = false; - protected bool m_bTimerRunning = false; - - protected int m_iCountdownDuration = 0; - protected int m_iTimerDuration = 0; - - protected ref GRAD_MapMarkerUI m_MapMarkerUI; - - //------------------------------------------------------------------------------------------------ - override void EOnInit(IEntity owner) - { - InitMapMarkerUI(); - } - - //------------------------------------------------------------------------------------------------ - void InitMapMarkerUI() - { - if (!m_MapMarkerUI) - { - m_MapMarkerUI = new GRAD_MapMarkerUI(); - m_MapMarkerUI.Init(); - } - } - - //------------------------------------------------------------------------------------------------ - void DeleteFortificationsFromInventory() - { - Rpc(RpcDo_Owner_DeleteFortificationsFromInventory); - } - - //------------------------------------------------------------------------------------------------ - [RplRpc(RplChannel.Reliable, RplRcver.Owner)] - protected void RpcDo_Owner_DeleteFortificationsFromInventory() - { - // executed locally on players PS_VirtualMachine - - IEntity entity = GetControlledEntity(); - - SCR_InventoryStorageManagerComponent inventoryStorageManager = SCR_InventoryStorageManagerComponent.Cast(entity.FindComponent(SCR_InventoryStorageManagerComponent)); - - array items = {}; - inventoryStorageManager.GetItems(items); - - int count = 0; - foreach(IEntity item : items) - { - // fortification items are identified by having the placementOverrideComponent - // strictly this would also be true for the barrel and for the traffic cone - GRAD_PlacementOverrideComponent placementOverrideComponent = GRAD_PlacementOverrideComponent.Cast(item.FindComponent(GRAD_PlacementOverrideComponent)); - if (placementOverrideComponent) - { - delete item; - count++; - } - } - - Print(string.Format("OTF - %1 fortification items deleted from inventory", count), LogLevel.NORMAL); - } - - //------------------------------------------------------------------------------------------------ - void InsertMarker(SCR_MapMarkerBase marker) - { - Rpc(RpcDo_Owner_InsertMarker, marker); - } - - //------------------------------------------------------------------------------------------------ - [RplRpc(RplChannel.Reliable, RplRcver.Owner)] - protected void RpcDo_Owner_InsertMarker(SCR_MapMarkerBase marker) - { - // executed locally on players PS_VirtualMachine - - SetMarker(marker); - } - - //------------------------------------------------------------------------------------------------ - protected void SetMarker(SCR_MapMarkerBase marker) - { - SCR_MapMarkerManagerComponent mapMarkerManager = SCR_MapMarkerManagerComponent.Cast(GetGame().GetGameMode().FindComponent(SCR_MapMarkerManagerComponent)); - - SCR_MapMarkerBase newMarker = new SCR_MapMarkerBase(); - newMarker.SetType(marker.GetType()); - int worldPos[2]; - marker.GetWorldPos(worldPos); - newMarker.SetWorldPos(worldPos[0], worldPos[1]); - newMarker.SetMarkerConfigID(marker.GetMarkerConfigID()); - newMarker.SetCustomText(marker.GetCustomText()); - newMarker.SetColorEntry(marker.GetColorEntry()); - newMarker.SetIconEntry(marker.GetIconEntry()); - - mapMarkerManager.InsertStaticMarker(newMarker); - } - - //------------------------------------------------------------------------------------------------ - void ToggleMap(bool open) - { - SCR_PlayerController pc = SCR_PlayerController.Cast(GetGame().GetPlayerController()); - if (!pc) return; - - SCR_ChimeraCharacter ch = SCR_ChimeraCharacter.Cast(pc.GetControlledEntity()); - if (!ch) return; - - SCR_GadgetManagerComponent gadgetManager = SCR_GadgetManagerComponent.Cast(ch.FindComponent(SCR_GadgetManagerComponent)); - if (!gadgetManager) return; - - if (!gadgetManager.GetGadgetByType(EGadgetType.MAP)) return; - - IEntity mapEntity = gadgetManager.GetGadgetByType(EGadgetType.MAP); - - if (open) - gadgetManager.SetGadgetMode(mapEntity, EGadgetMode.IN_HAND, true); - else - gadgetManager.SetGadgetMode(mapEntity, EGadgetMode.IN_SLOT, false); - } - - //------------------------------------------------------------------------------------------------ - void AddCircleMarker(float startX, float startY, float endX, float endY) - { - Rpc(RpcDo_Owner_AddCircleMarker, startX, startY, endX, endY); - } - - //------------------------------------------------------------------------------------------------ - [RplRpc(RplChannel.Reliable, RplRcver.Owner)] - protected void RpcDo_Owner_AddCircleMarker(float startX, float startY, float endX, float endY) - { - m_MapMarkerUI.AddCircle(startX, startY, endX, endY); - } - - //------------------------------------------------------------------------------------------------ - void ShowHint(string message, string title, int duration, bool isSilent) - { - Rpc(RpcDo_Owner_ShowHint, message, title, duration, isSilent); - } - - //------------------------------------------------------------------------------------------------ - [RplRpc(RplChannel.Reliable, RplRcver.Owner)] - protected void RpcDo_Owner_ShowHint(string message, string title, int duration, bool isSilent) - { - // executed locally on players machine - - SCR_HintManagerComponent.GetInstance().ShowCustomHint(message, title, duration, isSilent); - } - - //------------------------------------------------------------------------------------------------ - void ShowOverlay(string message, int duration) - { - Rpc(RpcDo_Owner_ShowOverlay, message, duration); - } - - //------------------------------------------------------------------------------------------------ - [RplRpc(RplChannel.Reliable, RplRcver.Owner)] - protected void RpcDo_Owner_ShowOverlay(string message, int duration) - { - // executed locally on players machine - - // Disable countdown/timer if new overlay will be displayed - m_bCoutdownRunning = false; - m_bTimerRunning = false; - - // Remove previously displays - RemoveOverlay(); - RemoveCountdown(); - RemoveTimer(); - - m_wOverlayDisplay = GetGame().GetWorkspace().CreateWidgets(m_sOverlay); - - TextWidget textWidget = TextWidget.Cast(m_wOverlayDisplay.FindAnyWidget("Text0")); - - if (textWidget) - textWidget.SetText(message); - - SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.TASK_CREATED); - - GetGame().GetCallqueue().CallLater(RemoveOverlay, duration * 1000, false); // x sec later - } - - //------------------------------------------------------------------------------------------------ - protected void RemoveOverlay() - { - if (m_wOverlayDisplay) - { - delete m_wOverlayDisplay; - } - } - - //------------------------------------------------------------------------------------------------ - void ShowCountdown(int duration) - { - Rpc(RpcDo_Owner_ShowCountdown, duration); - } - - //------------------------------------------------------------------------------------------------ - [RplRpc(RplChannel.Reliable, RplRcver.Owner)] - protected void RpcDo_Owner_ShowCountdown(int duration) - { - // executed locally on players machine - - // Disable countdown/timer if new overlay will be displayed - m_bCoutdownRunning = false; - m_bTimerRunning = false; - - // Remove previously displays - RemoveOverlay(); - RemoveCountdown(); - RemoveTimer(); - - m_wCountdownDisplay = GetGame().GetWorkspace().CreateWidgets(m_sCountdownTimer); - - m_bCoutdownRunning = true; - - m_iCountdownDuration = duration; - - UpdateCountdown(); - - // kill every previously running process - GetGame().GetCallqueue().Remove(UpdateCountdown); - GetGame().GetCallqueue().Remove(UpdateTimer); - - GetGame().GetCallqueue().CallLater(UpdateCountdown, 1000, true); // every second - } - - //------------------------------------------------------------------------------------------------ - protected void UpdateCountdown() - { - if (!m_bCoutdownRunning) - { - GetGame().GetCallqueue().Remove(UpdateCountdown); - return; - } - - int minutes = m_iCountdownDuration / 60; - int seconds = m_iCountdownDuration - (minutes * 60); - - string minutesStr; - string secondsStr; - - if (minutes < 10) - minutesStr = string.Format("0%1", minutes); - else - minutesStr = string.Format("%1", minutes); - - if (seconds < 10) - secondsStr = string.Format("0%1", seconds); - else - secondsStr = string.Format("%1", seconds); - - if (!m_wCountdownDisplay) - return; - - TextWidget textWidget = TextWidget.Cast(m_wCountdownDisplay.FindAnyWidget("Text0")); - - if (textWidget) - textWidget.SetText(string.Format("%1:%2", minutesStr, secondsStr)); - - if (m_iCountdownDuration == 0) - { - GetGame().GetCallqueue().Remove(UpdateCountdown); - - m_bCoutdownRunning = false; - - if (textWidget) - { - textWidget.SetColor(new Color(1.0, 0.0, 0.0, 1.0)); - SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_SIREN); - } - } - else - m_iCountdownDuration--; - } - - //------------------------------------------------------------------------------------------------ - protected void RemoveCountdown() - { - if (m_wCountdownDisplay) - { - delete m_wCountdownDisplay; - } - } - - //------------------------------------------------------------------------------------------------ - void ShowTimer() - { - Rpc(RpcDo_Owner_ShowTimer); - } - - //------------------------------------------------------------------------------------------------ - [RplRpc(RplChannel.Reliable, RplRcver.Owner)] - protected void RpcDo_Owner_ShowTimer() - { - // executed locally on players machine - - // Disable countdown/timer if new overlay will be displayed - m_bCoutdownRunning = false; - m_bTimerRunning = false; - - // Remove previously displays - RemoveOverlay(); - RemoveCountdown(); - RemoveTimer(); - - m_wTimerDisplay = GetGame().GetWorkspace().CreateWidgets(m_sCountdownTimer); - - m_bTimerRunning = true; - - m_iTimerDuration = 0; - - UpdateTimer(); - - // kill every previously running process - GetGame().GetCallqueue().Remove(UpdateTimer); - GetGame().GetCallqueue().Remove(UpdateCountdown); - - GetGame().GetCallqueue().CallLater(UpdateTimer, 1000, true); // every second - } - - //------------------------------------------------------------------------------------------------ - protected void UpdateTimer() - { - if (!m_bTimerRunning) - { - GetGame().GetCallqueue().Remove(UpdateTimer); - return; - } - - int minutes = m_iTimerDuration / 60; - int seconds = m_iTimerDuration - (minutes * 60); - - string minutesStr; - string secondsStr; - - if (minutes < 10) - minutesStr = string.Format("0%1", minutes); - else - minutesStr = string.Format("%1", minutes); - - if (seconds < 10) - secondsStr = string.Format("0%1", seconds); - else - secondsStr = string.Format("%1", seconds); - - if (!m_wTimerDisplay) - return; - - TextWidget textWidget = TextWidget.Cast(m_wTimerDisplay.FindAnyWidget("Text0")); - - if (textWidget) - textWidget.SetText(string.Format("%1:%2", minutesStr, secondsStr)); - - m_iTimerDuration++; - } - - //------------------------------------------------------------------------------------------------ - protected void RemoveTimer() - { - if (m_wTimerDisplay) - { - delete m_wTimerDisplay; - } - } - - //------------------------------------------------------------------------------------------------ - int GetTimerDuration() - { - return m_iTimerDuration; - } - - //------------------------------------------------------------------------------------------------ - void TeleportPlayer(vector pos) - { - Rpc(RpcDo_Owner_TeleportPlayer, pos); - } - - //------------------------------------------------------------------------------------------------ - [RplRpc(RplChannel.Reliable, RplRcver.Owner)] - protected void RpcDo_Owner_TeleportPlayer(vector pos) - { - // executed locally on players machine - - if(SCR_Global.TeleportLocalPlayer(pos, SCR_EPlayerTeleportedReason.DEFAULT)) - Print(string.Format("OTF - Player with ID %1 successfully teleported to position %2 - Deprecated", GetPlayerId(), pos), LogLevel.NORMAL); - else - Print(string.Format("OTF - Player with ID %1 NOT successfully teleported to position %2 - Deprecated", GetPlayerId(), pos), LogLevel.WARNING); - } - - //------------------------------------------------------------------------------------------------ - void TeleportPlayerToMapPos(int playerId, int mapPos[2]) - { - Rpc(Rpc_Do_Owner_TeleportPlayerToMapPos, playerId, mapPos); - } - - //------------------------------------------------------------------------------------------------ - [RplRpc(RplChannel.Reliable, RplRcver.Owner)] - protected void Rpc_Do_Owner_TeleportPlayerToMapPos(int playerId, int mapPos[2]) - { - // executed locally on players machine - - IEntity playerEntity = GetGame().GetPlayerManager().GetPlayerControlledEntity(playerId); - - if (!playerEntity) - { - Print(string.Format("OTF - Player entity missing; skipping teleport"), LogLevel.WARNING); - return; - } - - Print(string.Format("OTF - Player with ID %1 has position %2", playerId, playerEntity.GetOrigin()), LogLevel.NORMAL); - - bool teleportSuccessful = false; - - GRAD_OnTheFlyManager otfManager = GRAD_OnTheFlyManager.GetInstance(); - - vector newWorldPos; - - int teleportAttemptsCounter = 0; - - while (!teleportSuccessful) - { - if (teleportAttemptsCounter >= 5) - { - ShowHint("Teleport not successful. Contact your Game Master for manual teleport.", "On The Fly", 10, false); - Print(string.Format("OTF - Player with ID %1 NOT successfully teleported to position %2", GetPlayerId(), newWorldPos), LogLevel.NORMAL); - break; - } - - mapPos[0] = mapPos[0] + Math.RandomFloat(-30, 30); - mapPos[1] = mapPos[1] + Math.RandomFloat(-30, 30); - - newWorldPos = otfManager.MapPosToWorldPos(mapPos); - - teleportSuccessful = SCR_Global.TeleportLocalPlayer(newWorldPos, SCR_EPlayerTeleportedReason.DEFAULT); - - if (teleportSuccessful) - Print(string.Format("OTF - Player with ID %1 successfully teleported to position %2", GetPlayerId(), newWorldPos), LogLevel.NORMAL); - - teleportAttemptsCounter++; - } - } -}; +//------------------------------------------------------------------------------------------------ +modded class SCR_PlayerController : PlayerController +{ + [Attribute(defvalue: "{257513225CC1D5FB}UI/OTF/OTF_Overlay.layout")] + protected ResourceName m_sOverlay; + + [Attribute(defvalue: "{B764E0A789AF2F5F}UI/OTF/OTF_CountdownTimer.layout")] + protected ResourceName m_sCountdownTimer; + + protected ref Widget m_wOverlayDisplay; + protected ref Widget m_wCountdownDisplay; + protected ref Widget m_wTimerDisplay; + + protected bool m_bCoutdownRunning = false; + protected bool m_bTimerRunning = false; + + protected int m_iCountdownDuration = 0; + protected int m_iTimerDuration = 0; + + protected ref GRAD_MapMarkerUI m_MapMarkerUI; + + //------------------------------------------------------------------------------------------------ + override void EOnInit(IEntity owner) + { + InitMapMarkerUI(); + } + + //------------------------------------------------------------------------------------------------ + void InitMapMarkerUI() + { + if (!m_MapMarkerUI) + { + m_MapMarkerUI = new GRAD_MapMarkerUI(); + m_MapMarkerUI.Init(); + } + } + + //------------------------------------------------------------------------------------------------ + void DeleteFortificationsFromInventory() + { + Rpc(RpcDo_Owner_DeleteFortificationsFromInventory); + } + + //------------------------------------------------------------------------------------------------ + [RplRpc(RplChannel.Reliable, RplRcver.Owner)] + protected void RpcDo_Owner_DeleteFortificationsFromInventory() + { + // executed locally on players PS_VirtualMachine + + IEntity entity = GetControlledEntity(); + + SCR_InventoryStorageManagerComponent inventoryStorageManager = SCR_InventoryStorageManagerComponent.Cast(entity.FindComponent(SCR_InventoryStorageManagerComponent)); + + array items = {}; + inventoryStorageManager.GetItems(items); + + int count = 0; + foreach(IEntity item : items) + { + // fortification items are identified by having the placementOverrideComponent + // strictly this would also be true for the barrel and for the traffic cone + GRAD_PlacementOverrideComponent placementOverrideComponent = GRAD_PlacementOverrideComponent.Cast(item.FindComponent(GRAD_PlacementOverrideComponent)); + if (placementOverrideComponent) + { + delete item; + count++; + } + } + + Print(string.Format("OTF - %1 fortification items deleted from inventory", count), LogLevel.NORMAL); + } + + //------------------------------------------------------------------------------------------------ + void InsertMarker(SCR_MapMarkerBase marker) + { + Rpc(RpcDo_Owner_InsertMarker, marker); + } + + //------------------------------------------------------------------------------------------------ + [RplRpc(RplChannel.Reliable, RplRcver.Owner)] + protected void RpcDo_Owner_InsertMarker(SCR_MapMarkerBase marker) + { + // executed locally on players PS_VirtualMachine + + SetMarker(marker); + } + + //------------------------------------------------------------------------------------------------ + protected void SetMarker(SCR_MapMarkerBase marker) + { + SCR_MapMarkerManagerComponent mapMarkerManager = SCR_MapMarkerManagerComponent.Cast(GetGame().GetGameMode().FindComponent(SCR_MapMarkerManagerComponent)); + + SCR_MapMarkerBase newMarker = new SCR_MapMarkerBase(); + newMarker.SetType(marker.GetType()); + int worldPos[2]; + marker.GetWorldPos(worldPos); + newMarker.SetWorldPos(worldPos[0], worldPos[1]); + newMarker.SetMarkerConfigID(marker.GetMarkerConfigID()); + newMarker.SetCustomText(marker.GetCustomText()); + newMarker.SetColorEntry(marker.GetColorEntry()); + newMarker.SetIconEntry(marker.GetIconEntry()); + + mapMarkerManager.InsertStaticMarker(newMarker, true, true); + } + + //------------------------------------------------------------------------------------------------ + void ToggleMap(bool open) + { + SCR_PlayerController pc = SCR_PlayerController.Cast(GetGame().GetPlayerController()); + if (!pc) return; + + SCR_ChimeraCharacter ch = SCR_ChimeraCharacter.Cast(pc.GetControlledEntity()); + if (!ch) return; + + SCR_GadgetManagerComponent gadgetManager = SCR_GadgetManagerComponent.Cast(ch.FindComponent(SCR_GadgetManagerComponent)); + if (!gadgetManager) return; + + if (!gadgetManager.GetGadgetByType(EGadgetType.MAP)) return; + + IEntity mapEntity = gadgetManager.GetGadgetByType(EGadgetType.MAP); + + if (open) + gadgetManager.SetGadgetMode(mapEntity, EGadgetMode.IN_HAND, true); + else + gadgetManager.SetGadgetMode(mapEntity, EGadgetMode.IN_SLOT, false); + } + + //------------------------------------------------------------------------------------------------ + void AddCircleMarker(float startX, float startY, float endX, float endY) + { + Rpc(RpcDo_Owner_AddCircleMarker, startX, startY, endX, endY); + } + + //------------------------------------------------------------------------------------------------ + [RplRpc(RplChannel.Reliable, RplRcver.Owner)] + protected void RpcDo_Owner_AddCircleMarker(float startX, float startY, float endX, float endY) + { + m_MapMarkerUI.AddCircle(startX, startY, endX, endY); + } + + //------------------------------------------------------------------------------------------------ + void ShowHint(string message, string title, int duration, bool isSilent) + { + Rpc(RpcDo_Owner_ShowHint, message, title, duration, isSilent); + } + + //------------------------------------------------------------------------------------------------ + [RplRpc(RplChannel.Reliable, RplRcver.Owner)] + protected void RpcDo_Owner_ShowHint(string message, string title, int duration, bool isSilent) + { + // executed locally on players machine + + SCR_HintManagerComponent.GetInstance().ShowCustomHint(message, title, duration, isSilent); + } + + //------------------------------------------------------------------------------------------------ + void ShowOverlay(string message, int duration) + { + Rpc(RpcDo_Owner_ShowOverlay, message, duration); + } + + //------------------------------------------------------------------------------------------------ + [RplRpc(RplChannel.Reliable, RplRcver.Owner)] + protected void RpcDo_Owner_ShowOverlay(string message, int duration) + { + // executed locally on players machine + + // Disable countdown/timer if new overlay will be displayed + m_bCoutdownRunning = false; + m_bTimerRunning = false; + + // Remove previously displays + RemoveOverlay(); + RemoveCountdown(); + RemoveTimer(); + + m_wOverlayDisplay = GetGame().GetWorkspace().CreateWidgets(m_sOverlay); + + TextWidget textWidget = TextWidget.Cast(m_wOverlayDisplay.FindAnyWidget("Text0")); + + if (textWidget) + textWidget.SetText(message); + + SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.TASK_CREATED); + + GetGame().GetCallqueue().CallLater(RemoveOverlay, duration * 1000, false); // x sec later + } + + //------------------------------------------------------------------------------------------------ + protected void RemoveOverlay() + { + if (m_wOverlayDisplay) + { + delete m_wOverlayDisplay; + } + } + + //------------------------------------------------------------------------------------------------ + void ShowCountdown(int duration) + { + Rpc(RpcDo_Owner_ShowCountdown, duration); + } + + //------------------------------------------------------------------------------------------------ + [RplRpc(RplChannel.Reliable, RplRcver.Owner)] + protected void RpcDo_Owner_ShowCountdown(int duration) + { + // executed locally on players machine + + // Disable countdown/timer if new overlay will be displayed + m_bCoutdownRunning = false; + m_bTimerRunning = false; + + // Remove previously displays + RemoveOverlay(); + RemoveCountdown(); + RemoveTimer(); + + m_wCountdownDisplay = GetGame().GetWorkspace().CreateWidgets(m_sCountdownTimer); + + m_bCoutdownRunning = true; + + m_iCountdownDuration = duration; + + UpdateCountdown(); + + // kill every previously running process + GetGame().GetCallqueue().Remove(UpdateCountdown); + GetGame().GetCallqueue().Remove(UpdateTimer); + + GetGame().GetCallqueue().CallLater(UpdateCountdown, 1000, true); // every second + } + + //------------------------------------------------------------------------------------------------ + protected void UpdateCountdown() + { + if (!m_bCoutdownRunning) + { + GetGame().GetCallqueue().Remove(UpdateCountdown); + return; + } + + int minutes = m_iCountdownDuration / 60; + int seconds = m_iCountdownDuration - (minutes * 60); + + string minutesStr; + string secondsStr; + + if (minutes < 10) + minutesStr = string.Format("0%1", minutes); + else + minutesStr = string.Format("%1", minutes); + + if (seconds < 10) + secondsStr = string.Format("0%1", seconds); + else + secondsStr = string.Format("%1", seconds); + + if (!m_wCountdownDisplay) + return; + + TextWidget textWidget = TextWidget.Cast(m_wCountdownDisplay.FindAnyWidget("Text0")); + + if (textWidget) + textWidget.SetText(string.Format("%1:%2", minutesStr, secondsStr)); + + if (m_iCountdownDuration == 0) + { + GetGame().GetCallqueue().Remove(UpdateCountdown); + + m_bCoutdownRunning = false; + + if (textWidget) + { + textWidget.SetColor(new Color(1.0, 0.0, 0.0, 1.0)); + SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_SIREN); + } + } + else + m_iCountdownDuration--; + } + + //------------------------------------------------------------------------------------------------ + protected void RemoveCountdown() + { + if (m_wCountdownDisplay) + { + delete m_wCountdownDisplay; + } + } + + //------------------------------------------------------------------------------------------------ + void ShowTimer() + { + Rpc(RpcDo_Owner_ShowTimer); + } + + //------------------------------------------------------------------------------------------------ + [RplRpc(RplChannel.Reliable, RplRcver.Owner)] + protected void RpcDo_Owner_ShowTimer() + { + // executed locally on players machine + + // Disable countdown/timer if new overlay will be displayed + m_bCoutdownRunning = false; + m_bTimerRunning = false; + + // Remove previously displays + RemoveOverlay(); + RemoveCountdown(); + RemoveTimer(); + + m_wTimerDisplay = GetGame().GetWorkspace().CreateWidgets(m_sCountdownTimer); + + m_bTimerRunning = true; + + m_iTimerDuration = 0; + + UpdateTimer(); + + // kill every previously running process + GetGame().GetCallqueue().Remove(UpdateTimer); + GetGame().GetCallqueue().Remove(UpdateCountdown); + + GetGame().GetCallqueue().CallLater(UpdateTimer, 1000, true); // every second + } + + //------------------------------------------------------------------------------------------------ + protected void UpdateTimer() + { + if (!m_bTimerRunning) + { + GetGame().GetCallqueue().Remove(UpdateTimer); + return; + } + + int minutes = m_iTimerDuration / 60; + int seconds = m_iTimerDuration - (minutes * 60); + + string minutesStr; + string secondsStr; + + if (minutes < 10) + minutesStr = string.Format("0%1", minutes); + else + minutesStr = string.Format("%1", minutes); + + if (seconds < 10) + secondsStr = string.Format("0%1", seconds); + else + secondsStr = string.Format("%1", seconds); + + if (!m_wTimerDisplay) + return; + + TextWidget textWidget = TextWidget.Cast(m_wTimerDisplay.FindAnyWidget("Text0")); + + if (textWidget) + textWidget.SetText(string.Format("%1:%2", minutesStr, secondsStr)); + + m_iTimerDuration++; + } + + //------------------------------------------------------------------------------------------------ + protected void RemoveTimer() + { + if (m_wTimerDisplay) + { + delete m_wTimerDisplay; + } + } + + //------------------------------------------------------------------------------------------------ + int GetTimerDuration() + { + return m_iTimerDuration; + } + + //------------------------------------------------------------------------------------------------ + void TeleportPlayer(vector pos) + { + Rpc(RpcDo_Owner_TeleportPlayer, pos); + } + + //------------------------------------------------------------------------------------------------ + [RplRpc(RplChannel.Reliable, RplRcver.Owner)] + protected void RpcDo_Owner_TeleportPlayer(vector pos) + { + // executed locally on players machine + + if(SCR_Global.TeleportLocalPlayer(pos, SCR_EPlayerTeleportedReason.DEFAULT)) + Print(string.Format("OTF - Player with ID %1 successfully teleported to position %2 - Deprecated", GetPlayerId(), pos), LogLevel.NORMAL); + else + Print(string.Format("OTF - Player with ID %1 NOT successfully teleported to position %2 - Deprecated", GetPlayerId(), pos), LogLevel.WARNING); + } + + //------------------------------------------------------------------------------------------------ + void TeleportPlayerToMapPos(int playerId, int mapPos[2]) + { + Rpc(Rpc_Do_Owner_TeleportPlayerToMapPos, playerId, mapPos); + } + + //------------------------------------------------------------------------------------------------ + [RplRpc(RplChannel.Reliable, RplRcver.Owner)] + protected void Rpc_Do_Owner_TeleportPlayerToMapPos(int playerId, int mapPos[2]) + { + // executed locally on players machine + + IEntity playerEntity = GetGame().GetPlayerManager().GetPlayerControlledEntity(playerId); + + if (!playerEntity) + { + Print(string.Format("OTF - Player entity missing; skipping teleport"), LogLevel.WARNING); + return; + } + + Print(string.Format("OTF - Player with ID %1 has position %2", playerId, playerEntity.GetOrigin()), LogLevel.NORMAL); + + bool teleportSuccessful = false; + + GRAD_OnTheFlyManager otfManager = GRAD_OnTheFlyManager.GetInstance(); + + vector newWorldPos; + + int teleportAttemptsCounter = 0; + + while (!teleportSuccessful) + { + if (teleportAttemptsCounter >= 5) + { + ShowHint("Teleport not successful. Contact your Game Master for manual teleport.", "On The Fly", 10, false); + Print(string.Format("OTF - Player with ID %1 NOT successfully teleported to position %2", GetPlayerId(), newWorldPos), LogLevel.NORMAL); + break; + } + + mapPos[0] = mapPos[0] + Math.RandomFloat(-30, 30); + mapPos[1] = mapPos[1] + Math.RandomFloat(-30, 30); + + newWorldPos = otfManager.MapPosToWorldPos(mapPos); + + teleportSuccessful = SCR_Global.TeleportLocalPlayer(newWorldPos, SCR_EPlayerTeleportedReason.DEFAULT); + + if (teleportSuccessful) + Print(string.Format("OTF - Player with ID %1 successfully teleported to position %2", GetPlayerId(), newWorldPos), LogLevel.NORMAL); + + teleportAttemptsCounter++; + } + } +};