Skip to content

Commit

Permalink
Merge pull request #7 from MunasheDov/munashe-debugdraw
Browse files Browse the repository at this point in the history
Munashe debugdraw
  • Loading branch information
InvalidArgument3 authored May 1, 2024
2 parents 74a214a + 217cd5f commit 484fc6a
Show file tree
Hide file tree
Showing 5 changed files with 6,313 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,6 @@ private bool IsYardValid(IMyEntity entity, List<IMyCubeBlock> tools)
foreach (IMyCubeBlock tool in tools)
{
Vector3D point = tool.PositionComp.GetPosition();
//the grid position is not consistent with rotation, but world position is always the center of the block
//get the Vector3I of the center of the block and calculate APO on that
Vector3I adjustedPoint = ((IMyCubeGrid)entity).WorldToGridInteger(point);
gridPoints.Add(adjustedPoint);
}
Expand All @@ -321,6 +319,23 @@ private bool IsYardValid(IMyEntity entity, List<IMyCubeBlock> tools)
return false;
}

// Check if any two corner points are more than 1km apart
const double maxDistanceSquared = 1000 * 1000; // 1km squared
for (int i = 0; i < tools.Count - 1; i++)
{
for (int j = i + 1; j < tools.Count; j++)
{
double distanceSquared = Vector3D.DistanceSquared(tools[i].GetPosition(), tools[j].GetPosition());
if (distanceSquared > maxDistanceSquared)
{
Logging.Instance.WriteDebug($"Yard {entity.EntityId} failed: Corner distance exceeds 1km");
foreach (var tool in tools)
Communication.SendCustomInfo(tool.EntityId, "Invalid Shipyard: Corner distance exceeds 1km!");
return false;
}
}
}

if (!AreToolsConnected(tools))
{
Logging.Instance.WriteDebug($"Yard {entity.EntityId} failed: ATC");
Expand Down
114 changes: 109 additions & 5 deletions ShipyardsRevival/Data/Scripts/ShipyardMod/ShipyardCorner.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sandbox.Common.ObjectBuilders;
using Sandbox.Game.EntityComponents;
Expand All @@ -13,8 +14,13 @@
using VRage.Game.Components;
using VRage.Game.ModAPI;
using VRage.ModAPI;
using VRageMath;
using VRage.ObjectBuilders;
using VRage.Utils;
using VRageRender.Import;
using Sandbox.Engine.Physics;
using System.Text.RegularExpressions;
using ShipyardMod.ProcessHandlers;

namespace ShipyardMod
{
Expand Down Expand Up @@ -57,6 +63,104 @@ public override void Close()
NeedsUpdate = MyEntityUpdateEnum.NONE;
}

public override void UpdateAfterSimulation()
{
if (_block?.CubeGrid?.Physics == null)
{
return;
}

// Check if the corner is part of a valid shipyard
bool isValidShipyard = ProcessShipyardDetection.ShipyardsList.Any(yard => yard.Tools.Contains(_block));

if (!isValidShipyard)
{
var pos = _block.GetPosition();
var offset = 2.5f;
var mat = _block.WorldMatrix;
float width = 0.125f;
pos += -mat.Forward * offset;
pos += -mat.Left * offset;
pos += -mat.Up * offset;

Vector3D[] directions = new Vector3D[] {
mat.Forward,
mat.Left,
mat.Up
};

var red = (VRageMath.Vector4)Color.Red;
var yellow = (VRageMath.Vector4)Color.Yellow;
var blue = (VRageMath.Vector4)Color.Blue;

var material = MyStringId.GetOrCompute("Square");
var blend = VRageRender.MyBillboard.BlendTypeEnum.PostPP;

string subtypeShipyardCorner = _block.BlockDefinition.SubtypeId.ToString();
float maxLength = 1000.0f;
var cells = new List<Vector3I>();
foreach (var direction in directions)
{
var endPoint = pos + direction * maxLength;
cells.Clear();
_block.CubeGrid.RayCastCells(pos, endPoint, cells);

int indexOfOpposingShipyardCorner = -1;
for (int i = 0; i < cells.Count; i++)
{
var block = _block.CubeGrid.GetCubeBlock(cells[i]);
if (block != null)
{
var subtypeOther = block.BlockDefinition.Id.SubtypeId.ToString();
if (subtypeOther == subtypeShipyardCorner && block.SlimId() != _block.SlimBlock.SlimId())
{
indexOfOpposingShipyardCorner = i;
break;
}
}
}
if (indexOfOpposingShipyardCorner > -1)
{
endPoint = pos + direction * (indexOfOpposingShipyardCorner + 4.5);
var blockedByInvalid = false;
var pathHasEmptyCells = false;
for (int i = 3; i < indexOfOpposingShipyardCorner - 1; i++)
{
var block = _block.CubeGrid.GetCubeBlock(cells[i]);
if (block != null)
{
var subtypeOther = block.BlockDefinition.Id.SubtypeId.ToString();
if (!(subtypeOther == "ShipyardConveyor_Large" || subtypeOther == "ShipyardConveyorMount_Large"))
{
blockedByInvalid = true;
break;
}
}
else
{
pathHasEmptyCells = true;
}
}
if (blockedByInvalid)
{
MySimpleObjectDraw.DrawLine(pos, endPoint, material, ref red, width, blend);
continue;
}
else if (pathHasEmptyCells)
{
MySimpleObjectDraw.DrawLine(pos, endPoint, material, ref yellow, width, blend);
continue;
}
}
else
{
MySimpleObjectDraw.DrawLine(pos, endPoint, material, ref blue, width, blend);
continue;
}
}
}
}

public override void UpdateOnceBeforeFrame()
{
if (_init)
Expand Down Expand Up @@ -89,7 +193,7 @@ public override void UpdateOnceBeforeFrame()
var lockSwitch = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlOnOffSwitch, IMyCollector>("Shipyard_LockSwitch");
lockSwitch.Title = MyStringId.GetOrCompute("Advanced Locking");
lockSwitch.Tooltip = MyStringId.GetOrCompute("Toggles locking grids in the shipyard when grinding or welding while moving.");
lockSwitch.OnText=MyStringId.GetOrCompute("On");
lockSwitch.OnText = MyStringId.GetOrCompute("On");
lockSwitch.OffText = MyStringId.GetOrCompute("Off");
lockSwitch.Visible = b => b.BlockDefinition.SubtypeId.Equals("ShipyardCorner_Small");
lockSwitch.Enabled = b => b.BlockDefinition.SubtypeId.Equals("ShipyardCorner_Small") && GetYard(b) != null;
Expand Down Expand Up @@ -137,7 +241,7 @@ public override void UpdateOnceBeforeFrame()
stopButton.Action = b => Communication.SendYardCommand(b.CubeGrid.EntityId, ShipyardType.Disabled);
MyAPIGateway.TerminalControls.AddControl<IMyCollector>(stopButton);
Controls.Add(stopButton);

IMyTerminalControlSlider beamCountSlider = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlSlider, IMyCollector>("Shipyard_BeamCount");
beamCountSlider.Title = MyStringId.GetOrCompute("Beam Count");

Expand Down Expand Up @@ -205,7 +309,7 @@ public override void UpdateOnceBeforeFrame()
weldAction.Icon = @"Textures\GUI\Icons\Actions\Start.dds";
weldAction.Action = b => Communication.SendYardCommand(b.CubeGrid.EntityId, ShipyardType.Weld);
MyAPIGateway.TerminalControls.AddAction<IMyCollector>(weldAction);

IMyTerminalAction stopAction = MyAPIGateway.TerminalControls.CreateAction<IMyCollector>("Shipyard_StopAction");
stopAction.Enabled = b => b.BlockDefinition.SubtypeId.Contains("ShipyardCorner");
stopAction.Name = new StringBuilder("Stop");
Expand Down Expand Up @@ -307,7 +411,7 @@ private void SetLockEnabled(IMyCubeBlock b, bool value)

if (value == GetLockEnabled(b))
return;

YardSettingsStruct settings = ShipyardSettings.Instance.GetYardSettings(b.CubeGrid.EntityId);
settings.AdvancedLocking = value;

Expand Down Expand Up @@ -355,7 +459,7 @@ private void SetWeldSpeed(IMyCubeBlock b, float value)

if (value == GetWeldSpeed(b))
return;

YardSettingsStruct settings = ShipyardSettings.Instance.GetYardSettings(b.CubeGrid.EntityId);
settings.WeldMultiplier = value;

Expand Down
33 changes: 33 additions & 0 deletions ShipyardsRevival/concat_recursive.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@echo off
setlocal enabledelayedexpansion

echo Starting operation...

set OUTPUT=newfile.txt
set /a COUNT=0
set /a ERRORS=0

if exist "%OUTPUT%" (
echo Existing output file found. Deleting...
del "%OUTPUT%"
)

for /r %%i in (*.cs) do (
echo Processing: "%%i"
type "%%i" >> "%OUTPUT%"
if errorlevel 1 (
echo Error processing "%%i".
set /a ERRORS+=1
) else (
set /a COUNT+=1
)
)

echo Operation completed.
echo Total files processed: %COUNT%
if %ERRORS% gtr 0 (
echo There were %ERRORS% errors during the operation.
) else (
echo No errors encountered.
)
pause
Loading

0 comments on commit 484fc6a

Please sign in to comment.