internal bool Draw(uint tick) { Color color = new Color(); switch (Type) { case LineType.MainTravel: color = Color.Blue; break; case LineType.MainHit: color = Color.Red; break; case LineType.ShrapnelTravel: color = Color.Green; break; case LineType.ShrapnelHit: color = Color.Orange; break; } DsDebugDraw.DrawLine(Line, color, 0.1f); return(tick - StartTick < 1200); }
private void DrawHelper() { if (_age < 1800) { return; } if (Vector3D.DistanceSquared(MyAPIGateway.Session.Player.Character.PositionComp.WorldAABB.Center, Emitter.PositionComp.WorldAABB.Center) < 2250000) { var controller = ShieldComp.DefenseShields; var needsUpdate = controller.GridIsMobile && (ShieldComp.GridIsMoving || _updateLosState); var blockCam = controller.ShieldEnt.PositionComp.WorldVolume; if (MyAPIGateway.Session.Camera.IsInFrustum(ref blockCam)) { if (_lCount % 2 == 1) { if (_count == 59 && needsUpdate) { UpdateLosState(_updateLosState); _updateLosState = false; } else if (needsUpdate) { UpdateUnitSphere(); } } else { if (needsUpdate) { UpdateUnitSphere(); } foreach (var blocking in _blocksLos.Keys) { var blockedPos = LosScaledCloud[blocking]; DsDebugDraw.DrawLosBlocked(blockedPos, MyGrid.PositionComp.LocalMatrix, blockCam.Radius / 25); } } foreach (var clear in _vertsSighted) { var blockedPos = LosScaledCloud[clear]; DsDebugDraw.DrawLosClear(blockedPos, MyGrid.PositionComp.LocalMatrix, blockCam.Radius / 25); } var blocked = _blocksLos.Count; var needed = -300 + _vertsSighted.Count; if (_count == 0) { BroadCastLosMessage(blocked, needed, controller); } } } }
internal void LosDebuging() { for (var i = LosDebugList.Count - 1; i >= 0; i--) { var info = LosDebugList[i]; DsDebugDraw.DrawLine(info.Line, Color.Red, 0.15f); if (Tick - info.HitTick > 1200) { LosDebugList.RemoveAtFast(i); WeaponLosDebugActive.Remove(info.Weapon); } } }
public void WeaponDebug(Weapon w) { DsDebugDraw.DrawLine(w.MyPivotTestLine, Color.Red, 0.05f); DsDebugDraw.DrawLine(w.MyBarrelTestLine, Color.Blue, 0.05f); DsDebugDraw.DrawLine(w.MyCenterTestLine, Color.Green, 0.05f); DsDebugDraw.DrawLine(w.MyAimTestLine, Color.Black, 0.07f); DsDebugDraw.DrawSingleVec(w.MyPivotPos, 1f, Color.White); //DsDebugDraw.DrawBox(w.targetBox, Color.Plum); DsDebugDraw.DrawLine(w.LimitLine.From, w.LimitLine.To, Color.Orange, 0.05f); if (w.Target.HasTarget) { DsDebugDraw.DrawLine(w.MyShootAlignmentLine, Color.Yellow, 0.05f); } }
private void DrawDisabledGuns() { if (Tick600 || Tick60 && QuickDisableGunsCheck) { QuickDisableGunsCheck = false; _nearbyGridsTestSphere.Center = CameraPos; _gridsNearCamera.Clear(); _uninitializedBlocks.Clear(); MyGamePruningStructure.GetAllTopMostEntitiesInSphere(ref _nearbyGridsTestSphere, _gridsNearCamera); for (int i = _gridsNearCamera.Count - 1; i >= 0; i--) { var grid = _gridsNearCamera[i] as MyCubeGrid; if (grid?.Physics != null && !grid.MarkedForClose && !grid.IsPreview && !grid.Physics.IsPhantom) { var fatBlocks = grid.GetFatBlocks(); for (int j = 0; j < fatBlocks.Count; j++) { var block = fatBlocks[j]; if (block.IsFunctional && WeaponPlatforms.ContainsKey(block.BlockDefinition.Id)) { GridAi gridAi; if (!GridTargetingAIs.TryGetValue(block.CubeGrid, out gridAi) || !gridAi.WeaponBase.ContainsKey(block)) { _uninitializedBlocks.Add(block); } } } } } } for (int i = 0; i < _uninitializedBlocks.Count; i++) { var badBlock = _uninitializedBlocks[i]; if (badBlock.InScene) { var lookSphere = new BoundingSphereD(badBlock.PositionComp.WorldAABB.Center, 30f); if (Camera.IsInFrustum(ref lookSphere)) { MyOrientedBoundingBoxD blockBox; SUtils.GetBlockOrientedBoundingBox(badBlock, out blockBox); DsDebugDraw.DrawBox(blockBox, _uninitializedColor); } } } }
internal void SmartLosDebug() { if (PosChangedTick != System.Session.Tick) { UpdatePivotPos(); } var info = GetScope.Info; var checkLevel = Comp.Ai.IsStatic ? 1 : 5; var angle = Comp.Session.Tick20 ? GetAngle() : _losAngle; for (int i = 0; i < checkLevel; i++) { var source = GetSmartLosPosition(i, ref info, angle); IHitInfo hitInfo; Comp.Ai.Session.Physics.CastRay(source, info.Position, out hitInfo, 15, false); var grid = hitInfo?.HitEntity?.GetTopMostParent() as MyCubeGrid; var hit = grid != null && grid.IsInSameLogicalGroupAs(Comp.Ai.MyGrid) && grid.GetTargetedBlock(hitInfo.Position + (-info.Direction * 0.1f)) != Comp.MyCube.SlimBlock; var line = new LineD(source, info.Position); DsDebugDraw.DrawLine(line, hit ? Color.Red : Color.Blue, 0.05f); } }
internal void UpdateInputState() { var s = _session; WheelForward = false; WheelBackward = false; AimRay = new LineD(); if (!s.InGridAiBlock) { s.UpdateLocalAiAndCockpit(); } if (s.InGridAiBlock && !s.InMenu) { MouseButtonPressed = MyAPIGateway.Input.IsAnyMousePressed(); MouseButtonLeftWasPressed = ClientInputState.MouseButtonLeft; MouseButtonMenuWasPressed = ClientInputState.MouseButtonMenu; MouseButtonRightWasPressed = ClientInputState.MouseButtonRight; WasInMenu = ClientInputState.InMenu; ClientInputState.InMenu = _session.InMenu; if (MouseButtonPressed) { ClientInputState.MouseButtonLeft = MyAPIGateway.Input.IsMousePressed(MyMouseButtonsEnum.Left); ClientInputState.MouseButtonMenu = MyAPIGateway.Input.IsMousePressed(MouseButtonMenu); ClientInputState.MouseButtonRight = MyAPIGateway.Input.IsMousePressed(MyMouseButtonsEnum.Right); } else { ClientInputState.MouseButtonLeft = false; ClientInputState.MouseButtonMenu = false; ClientInputState.MouseButtonRight = false; } _session.PlayerMouseStates[_session.PlayerId] = ClientInputState; if (_session.MpActive) { var shootButtonActive = ClientInputState.MouseButtonLeft || ClientInputState.MouseButtonRight; MouseShootWasOn = MouseShootOn; if ((_session.ManualShot || s.Tick - _lastInputUpdate >= 29) && shootButtonActive && !MouseShootOn) { _lastInputUpdate = s.Tick; MouseShootOn = true; } else if (MouseShootOn && !shootButtonActive) { MouseShootOn = false; } InputChanged = MouseShootOn != MouseShootWasOn || WasInMenu != ClientInputState.InMenu; _session.ManualShot = false; } ShiftReleased = MyAPIGateway.Input.IsNewKeyReleased(MyKeys.LeftShift); ShiftPressed = MyAPIGateway.Input.IsKeyPress(MyKeys.LeftShift); ActionKeyReleased = MyAPIGateway.Input.IsNewKeyReleased(ActionKey); if (ShiftPressed) { ShiftTime++; LongShift = ShiftTime > 59; } else { if (LongShift) { ShiftReleased = false; } ShiftTime = 0; LongShift = false; } AltPressed = MyAPIGateway.Input.IsAnyAltKeyPressed(); CtrlPressed = MyAPIGateway.Input.IsKeyPress(MyKeys.Control); KeyPrevPressed = AnyKeyPressed; AnyKeyPressed = MyAPIGateway.Input.IsAnyKeyPress(); UiKeyWasPressed = UiKeyPressed; UiKeyPressed = CtrlPressed || AltPressed || ShiftPressed; PlayerCamera = MyAPIGateway.Session.IsCameraControlledObject; FirstPersonView = PlayerCamera && MyAPIGateway.Session.CameraController.IsInFirstPersonView; if ((!UiKeyPressed && !UiKeyWasPressed) || !AltPressed && CtrlPressed && !FirstPersonView) { PreviousWheel = MyAPIGateway.Input.PreviousMouseScrollWheelValue(); CurrentWheel = MyAPIGateway.Input.MouseScrollWheelValue(); } } else if (!s.InMenu) { CtrlPressed = MyAPIGateway.Input.IsKeyPress(MyKeys.Control); ActionKeyPressed = MyAPIGateway.Input.IsKeyPress(ActionKey); if (CtrlPressed && ActionKeyPressed && GetAimRay(s, out AimRay) && Debug) { DsDebugDraw.DrawLine(AimRay, Color.Red, 0.1f); } } if (_session.MpActive && !s.InGridAiBlock) { if (ClientInputState.InMenu || ClientInputState.MouseButtonRight || ClientInputState.MouseButtonMenu || ClientInputState.MouseButtonRight) { ClientInputState.InMenu = false; ClientInputState.MouseButtonLeft = false; ClientInputState.MouseButtonMenu = false; ClientInputState.MouseButtonRight = false; InputChanged = true; } } if (CurrentWheel != PreviousWheel && CurrentWheel > PreviousWheel) { WheelForward = true; } else if (s.UiInput.CurrentWheel != s.UiInput.PreviousWheel) { WheelBackward = true; } }
internal void UpdateInputState() { var s = _session; WheelForward = false; WheelBackward = false; AimRay = new LineD(); if (!s.InGridAiBlock) { s.UpdateLocalAiAndCockpit(); } if (s.InGridAiBlock && !s.InMenu) { MouseButtonPressed = MyAPIGateway.Input.IsAnyMousePressed(); MouseButtonLeftWasPressed = ClientInputState.MouseButtonLeft; MouseButtonMenuWasPressed = ClientInputState.MouseButtonMenu; MouseButtonRightWasPressed = ClientInputState.MouseButtonRight; WasInMenu = ClientInputState.InMenu; ClientInputState.InMenu = _session.InMenu; if (MouseButtonPressed) { ClientInputState.MouseButtonLeft = MyAPIGateway.Input.IsMousePressed(MyMouseButtonsEnum.Left); ClientInputState.MouseButtonMenu = MyAPIGateway.Input.IsMousePressed(MouseButtonMenu); ClientInputState.MouseButtonRight = MyAPIGateway.Input.IsMousePressed(MyMouseButtonsEnum.Right); } else { ClientInputState.MouseButtonLeft = false; ClientInputState.MouseButtonMenu = false; ClientInputState.MouseButtonRight = false; } _session.PlayerMouseStates[_session.PlayerId] = ClientInputState; if (_session.MpActive) { var shootButtonActive = ClientInputState.MouseButtonLeft || ClientInputState.MouseButtonRight; MouseShootWasOn = MouseShootOn; if ((_session.ManualShot || s.Tick - _lastInputUpdate >= 29) && shootButtonActive && !MouseShootOn) { _lastInputUpdate = s.Tick; MouseShootOn = true; } else if (MouseShootOn && !shootButtonActive) { MouseShootOn = false; } InputChanged = MouseShootOn != MouseShootWasOn || WasInMenu != ClientInputState.InMenu; _session.ManualShot = false; } ShiftReleased = MyAPIGateway.Input.IsNewKeyReleased(MyKeys.LeftShift); ShiftPressed = MyAPIGateway.Input.IsKeyPress(MyKeys.LeftShift); ControlKeyReleased = MyAPIGateway.Input.IsNewKeyReleased(ControlKey); if (ShiftPressed) { ShiftTime++; LongShift = ShiftTime > 59; } else { if (LongShift) { ShiftReleased = false; } ShiftTime = 0; LongShift = false; } AltPressed = MyAPIGateway.Input.IsAnyAltKeyPressed(); CtrlPressed = MyAPIGateway.Input.IsKeyPress(MyKeys.Control); KeyPrevPressed = AnyKeyPressed; AnyKeyPressed = MyAPIGateway.Input.IsAnyKeyPress(); UiKeyWasPressed = UiKeyPressed; UiKeyPressed = CtrlPressed || AltPressed || ShiftPressed; PlayerCamera = MyAPIGateway.Session.IsCameraControlledObject; FirstPersonView = PlayerCamera && MyAPIGateway.Session.CameraController.IsInFirstPersonView; CameraBlockView = !PlayerCamera && !FirstPersonView && s.ActiveCameraBlock != null && s.ActiveCameraBlock.IsActive && s.ActiveCameraBlock.IsWorking; if (CameraBlockView && s.ActiveCameraBlock != null) { CameraChannelId = s.CameraChannelMappings[s.ActiveCameraBlock]; } else { CameraChannelId = 0; } if ((!UiKeyPressed && !UiKeyWasPressed) || !AltPressed && CtrlPressed && !FirstPersonView) { PreviousWheel = MyAPIGateway.Input.PreviousMouseScrollWheelValue(); CurrentWheel = MyAPIGateway.Input.MouseScrollWheelValue(); } } else if (!s.InMenu) { CtrlPressed = MyAPIGateway.Input.IsKeyPress(MyKeys.Control); ControlKeyPressed = MyAPIGateway.Input.IsKeyPress(ControlKey); CameraChannelId = 0; if (CtrlPressed && ControlKeyPressed && GetAimRay(s, out AimRay) && Debug) { DsDebugDraw.DrawLine(AimRay, Color.Red, 0.1f); } } if (!s.InMenu) { //ActionKeyReleased = MyAPIGateway.Input.IsNewKeyReleased(ActionKey); ActionKeyPressed = MyAPIGateway.Input.IsKeyPress(ActionKey); InfoKeyReleased = MyAPIGateway.Input.IsNewKeyReleased(InfoKey); if (ActionKeyPressed || InfoKeyReleased) { if (!BlackListActive1) { BlackList1(true); } if (ActionKeyPressed && _session.CanChangeHud) { var evenTicks = _session.Tick % 2 == 0; if (evenTicks) { if (MyAPIGateway.Input.IsKeyPress(MyKeys.Up)) { _session.Settings.ClientConfig.HudPos.Y += 0.01f; _session.Settings.VersionControl.UpdateClientCfgFile(); } else if (MyAPIGateway.Input.IsKeyPress(MyKeys.Down)) { _session.Settings.ClientConfig.HudPos.Y -= 0.01f; _session.Settings.VersionControl.UpdateClientCfgFile(); } else if (MyAPIGateway.Input.IsKeyPress(MyKeys.Left)) { _session.Settings.ClientConfig.HudPos.X -= 0.01f; _session.Settings.VersionControl.UpdateClientCfgFile(); } else if (MyAPIGateway.Input.IsKeyPress(MyKeys.Right)) { _session.Settings.ClientConfig.HudPos.X += 0.01f; _session.Settings.VersionControl.UpdateClientCfgFile(); } } if (_session.Tick10) { if (MyAPIGateway.Input.IsKeyPress(MyKeys.Add)) { _session.HudUi.NeedsUpdate = true; _session.Settings.ClientConfig.HudScale = MathHelper.Clamp(_session.Settings.ClientConfig.HudScale + 0.01f, 0.1f, 10f); _session.Settings.VersionControl.UpdateClientCfgFile(); } else if (MyAPIGateway.Input.IsKeyPress(MyKeys.Subtract)) { _session.HudUi.NeedsUpdate = true; _session.Settings.ClientConfig.HudScale = MathHelper.Clamp(_session.Settings.ClientConfig.HudScale - 0.01f, 0.1f, 10f); _session.Settings.VersionControl.UpdateClientCfgFile(); } } } if (InfoKeyReleased) { _session.Settings.ClientConfig.MinimalHud = !_session.Settings.ClientConfig.MinimalHud; _session.Settings.VersionControl.UpdateClientCfgFile(); } } } else { ActionKeyPressed = false; ActionKeyReleased = false; InfoKeyPressed = false; InfoKeyReleased = false; } if (_session.MpActive && !s.InGridAiBlock) { if (ClientInputState.InMenu || ClientInputState.MouseButtonRight || ClientInputState.MouseButtonMenu || ClientInputState.MouseButtonRight) { ClientInputState.InMenu = false; ClientInputState.MouseButtonLeft = false; ClientInputState.MouseButtonMenu = false; ClientInputState.MouseButtonRight = false; InputChanged = true; } } if (CurrentWheel != PreviousWheel && CurrentWheel > PreviousWheel) { WheelForward = true; } else if (s.UiInput.CurrentWheel != s.UiInput.PreviousWheel) { WheelBackward = true; } if (!ActionKeyPressed && BlackListActive1) { BlackList1(false); } }
private void UpdatePlacer() { if (!Placer.Visible) { Placer = null; } if (!MyCubeBuilder.Static.DynamicMode && MyCubeBuilder.Static.HitInfo.HasValue) { var hit = MyCubeBuilder.Static.HitInfo.Value as IHitInfo; var grid = hit.HitEntity as MyCubeGrid; GridAi gridAi; if (grid != null && GridToMasterAi.TryGetValue(grid, out gridAi)) { if (MyCubeBuilder.Static.CurrentBlockDefinition != null) { var subtypeIdHash = MyCubeBuilder.Static.CurrentBlockDefinition.Id.SubtypeId; WeaponCount weaponCount; if (gridAi.WeaponCounter.TryGetValue(subtypeIdHash, out weaponCount)) { if (weaponCount.Max > 0 && gridAi.Construct.GetWeaponCount(subtypeIdHash) >= weaponCount.Max) { MyCubeBuilder.Static.NotifyPlacementUnable(); MyCubeBuilder.Static.Deactivate(); return; } } if (WeaponAreaRestrictions.ContainsKey(subtypeIdHash)) { MyOrientedBoundingBoxD restrictedBox; MyOrientedBoundingBoxD buildBox = MyCubeBuilder.Static.GetBuildBoundingBox(); BoundingSphereD restrictedSphere; if (IsWeaponAreaRestricted(subtypeIdHash, buildBox, grid, 0, null, out restrictedBox, out restrictedSphere)) { DsDebugDraw.DrawBox(buildBox, _uninitializedColor); } if (MyAPIGateway.Session.Config.HudState == 1) { if (restrictedBox.HalfExtent.AbsMax() > 0) { DsDebugDraw.DrawBox(restrictedBox, _restrictionAreaColor); } if (restrictedSphere.Radius > 0) { DsDebugDraw.DrawSphere(restrictedSphere, _restrictionAreaColor); } for (int i = 0; i < gridAi.Weapons.Count; i++) { MyOrientedBoundingBoxD b; BoundingSphereD s; CoreComponent Comp = gridAi.Weapons[i]; MyOrientedBoundingBoxD blockBox; SUtils.GetBlockOrientedBoundingBox(Comp.MyCube, out blockBox); CalculateRestrictedShapes(Comp.MyCube.BlockDefinition.Id.SubtypeId, blockBox, out b, out s); if (s.Radius > 0) { DsDebugDraw.DrawSphere(s, _restrictionAreaColor); } if (b.HalfExtent.AbsMax() > 0) { DsDebugDraw.DrawBox(b, _restrictionAreaColor); } } } } } } } }
private void DrawDisabledGuns() { if (Tick600 || Tick60 && QuickDisableGunsCheck) { QuickDisableGunsCheck = false; _nearbyGridsTestSphere.Center = CameraPos; _gridsNearCamera.Clear(); _uninitializedBlocks.Clear(); _debugBlocks.Clear(); MyGamePruningStructure.GetAllTopMostEntitiesInSphere(ref _nearbyGridsTestSphere, _gridsNearCamera); for (int i = _gridsNearCamera.Count - 1; i >= 0; i--) { var grid = _gridsNearCamera[i] as MyCubeGrid; if (grid?.Physics != null && !grid.MarkedForClose && !grid.IsPreview && !grid.Physics.IsPhantom) { var fatBlocks = grid.GetFatBlocks(); for (int j = 0; j < fatBlocks.Count; j++) { var block = fatBlocks[j]; if (block.IsFunctional && WeaponPlatforms.ContainsKey(block.BlockDefinition.Id)) { GridAi gridAi; WeaponComponent comp; if (!GridTargetingAIs.TryGetValue(block.CubeGrid, out gridAi) || !gridAi.WeaponBase.TryGetValue(block, out comp)) { _uninitializedBlocks.Add(block); } else if (comp != null && comp.Data.Repo.Base.Set.Overrides.Debug) { _debugBlocks.Add(comp); } } } } } } for (int i = 0; i < _uninitializedBlocks.Count; i++) { var badBlock = _uninitializedBlocks[i]; if (badBlock.InScene) { var lookSphere = new BoundingSphereD(badBlock.PositionComp.WorldAABB.Center, 30f); if (Camera.IsInFrustum(ref lookSphere)) { MyOrientedBoundingBoxD blockBox; SUtils.GetBlockOrientedBoundingBox(badBlock, out blockBox); DsDebugDraw.DrawBox(blockBox, _uninitializedColor); } } } for (int i = 0; i < _debugBlocks.Count; i++) { var comp = _debugBlocks[i]; if (comp.MyCube.InScene) { var lookSphere = new BoundingSphereD(comp.MyCube.PositionComp.WorldAABB.Center, 100f); if (Camera.IsInFrustum(ref lookSphere)) { foreach (var w in comp.Platform.Weapons) { if (!w.AiEnabled && w.ActiveAmmoDef.AmmoDef.Trajectory.Guidance == WeaponDefinition.AmmoDef.TrajectoryDef.GuidanceType.Smart) { w.SmartLosDebug(); } } } } } }