private Vector3D GetReferenceVector(ShipControlCommons shipControl, Base6Directions.Direction direction) { var offset = shipControl.Reference.Position + Base6Directions.GetIntVector(direction); return(Vector3D.Normalize(shipControl.Reference.CubeGrid.GridIntegerToWorld(offset) - shipControl.ReferencePoint)); }
private void EraseFaceTriangles(Vector3I pos, Base6Directions.Direction direction) { m_tmpTriangleList.Clear(); Vector3I directionVec = Base6Directions.GetIntVector((int)direction); List <int> triList = null; if (m_smallTriangleRegistry.TryGetValue(pos, out triList)) { foreach (var index in triList) { var triangle = GetTriangle(index); if (IsFaceTriangle(triangle, pos, directionVec)) { m_tmpTriangleList.Add(new KeyValuePair <MyNavigationTriangle, Vector3I>(triangle, pos)); } } } foreach (var triangle in m_tmpTriangleList) { RemoveTriangle(triangle.Key, triangle.Value); } m_tmpTriangleList.Clear(); }
static void GenerateConvexVertices() { List <Vector3> tmpHelperVerts = new List <Vector3>(27); var topologyValues = Enum.GetValues(typeof(MyCubeTopology)); Cache = new List <Vector3> [topologyValues.Length][]; foreach (var topologyObj in topologyValues) { var topology = (MyCubeTopology)topologyObj; GetTopologySwitch(topology, tmpHelperVerts); Cache[(int)topology] = new List <Vector3> [6 * 6]; foreach (var forward in Base6Directions.EnumDirections) { foreach (var up in Base6Directions.EnumDirections) { if (forward == up || Base6Directions.GetIntVector(forward) == -Base6Directions.GetIntVector(up)) { continue; } var list = new List <Vector3>(tmpHelperVerts.Count); Cache[(int)topology][(int)forward * 6 + (int)up] = list; var orientation = new MyBlockOrientation(forward, up); foreach (var vert in tmpHelperVerts) { list.Add(Vector3.TransformNormal(vert, orientation)); } } } tmpHelperVerts.Clear(); } }
private void MarkExploredDirections(ref MyNavmeshComponents.ClosedCellInfo cellInfo) { foreach (var direction in Base6Directions.EnumDirections) { var dirFlag = Base6Directions.GetDirectionFlag(direction); if (cellInfo.ExploredDirections.HasFlag(dirFlag)) { continue; } Vector3I dirVec = Base6Directions.GetIntVector(direction); MyCellCoord otherCoord = new MyCellCoord(); otherCoord.Lod = MyVoxelNavigationMesh.NAVMESH_LOD; otherCoord.CoordInLod = m_currentCell + dirVec; if (otherCoord.CoordInLod.X == -1 || otherCoord.CoordInLod.Y == -1 || otherCoord.CoordInLod.Z == -1) { continue; } ulong otherPackedCoord = otherCoord.PackId64(); if (m_triangleLists.ContainsKey(otherPackedCoord)) { m_navmeshComponents.MarkExplored(otherPackedCoord, Base6Directions.GetFlippedDirection(direction)); cellInfo.ExploredDirections |= Base6Directions.GetDirectionFlag(direction); } } m_navmeshComponents.SetExplored(m_packedCoord, cellInfo.ExploredDirections); }
protected override void Update() { Calculations(); TempData tempData = new TempData(); Vector3 meWorldPosition = Me.CubeGrid.GridIntegerToWorld(Me.Position); tempData.facing = Me.CubeGrid.GridIntegerToWorld(Me.Position + Base6Directions.GetIntVector(Me.Orientation.Forward)) - meWorldPosition; tempData.facing.Normalize(); tempData.facingLeft = Me.CubeGrid.GridIntegerToWorld(Me.Position + Base6Directions.GetIntVector(Me.Orientation.Left)) - meWorldPosition; tempData.facingLeft.Normalize(); tempData.facingUp = Me.CubeGrid.GridIntegerToWorld(Me.Position + Base6Directions.GetIntVector(Me.Orientation.Up)) - meWorldPosition; tempData.facingUp.Normalize(); if (command != null) { tempData.navData = command.GetNavData(program); program.Echo(string.Format("Nav command: {0}", command.GetType().Name)); } /*Vector3 optimalThrustSpeed = HandleThrust( tempData ); * if(!tempData.navData.desiredFacing.HasValue) * tempData.navData.desiredFacing = optimalThrustSpeed;*/ HandleFacingInLocalCoords(tempData); }
private unsafe void MarkExploredDirections(ref MyNavmeshComponents.ClosedCellInfo cellInfo) { foreach (Base6Directions.Direction direction in Base6Directions.EnumDirections) { Base6Directions.DirectionFlags directionFlag = Base6Directions.GetDirectionFlag(direction); if (!cellInfo.ExploredDirections.HasFlag(directionFlag)) { Vector3I intVector = Base6Directions.GetIntVector(direction); MyCellCoord coord = new MyCellCoord { Lod = 0, CoordInLod = (Vector3I)(this.m_currentCell + intVector) }; if (((coord.CoordInLod.X != -1) && (coord.CoordInLod.Y != -1)) && (coord.CoordInLod.Z != -1)) { ulong key = coord.PackId64(); if (this.m_triangleLists.ContainsKey(key)) { this.m_navmeshComponents.MarkExplored(key, Base6Directions.GetFlippedDirection(direction)); Base6Directions.DirectionFlags *flagsPtr1 = (Base6Directions.DirectionFlags *) ref cellInfo.ExploredDirections; *((sbyte *)flagsPtr1) = *(((byte *)flagsPtr1)) | Base6Directions.GetDirectionFlag(direction); } } } } this.m_navmeshComponents.SetExplored(this.m_packedCoord, cellInfo.ExploredDirections); }
public IMyHighLevelComponent GetComponent(MyHighLevelPrimitive primitive) { ulong num; Base6Directions.DirectionFlags flags; if (!this.m_navmeshComponents.GetComponentCell(primitive.Index, out num)) { return(null); } if (!this.m_navmeshComponents.GetComponentInfo(primitive.Index, num, out flags)) { return(null); } MyCellCoord coord = new MyCellCoord(); coord.SetUnpack(num); foreach (Base6Directions.Direction direction in Base6Directions.EnumDirections) { Base6Directions.DirectionFlags directionFlag = Base6Directions.GetDirectionFlag(direction); if (!flags.HasFlag(directionFlag)) { Vector3I position = (Vector3I)(coord.CoordInLod + Base6Directions.GetIntVector(direction)); if (this.m_exploredCells.Contains(ref position)) { flags |= directionFlag; } } } return(new Component(primitive.Index, flags)); }
private void MainTargetScan() { targetedScanRuntime = 0; targetedScan = Me.CubeGrid.GridIntegerToWorld(Me.Position + Base6Directions.GetIntVector(Me.Orientation.Forward)) - Me.CubeGrid.GridIntegerToWorld(Me.Position); targetedScan.Normalize(); program.logMessages.Enqueue(string.Format("Initiating targeted scan: {0:0.00},{1:0.00},{2:0.00}", targetedScan.X, targetedScan.Y, targetedScan.Z)); }
private MyShipMergeBlock GetOtherMergeBlock() { Vector3I minI, maxI; CalculateMergeArea(out minI, out maxI); Vector3I pos = minI; for (Vector3I_RangeIterator it = new Vector3I_RangeIterator(ref minI, ref maxI); it.IsValid(); it.GetNext(out pos)) { var block = this.CubeGrid.GetCubeBlock(pos); if (block != null && block.FatBlock != null) { var mergeBlock = block.FatBlock as MyShipMergeBlock; if (mergeBlock == null) { continue; } Vector3I otherMinI, otherMaxI; mergeBlock.CalculateMergeArea(out otherMinI, out otherMaxI); Vector3I faceNormal = Base6Directions.GetIntVector(this.Orientation.TransformDirection(m_forward)); // Bounding box test of minI <-> maxI and otherMinI(shifted by faceNormal) <-> otherMaxI(shifted by faceNormal) otherMinI = maxI - (otherMinI + faceNormal); otherMaxI = otherMaxI + faceNormal - minI; if (otherMinI.X < 0) { continue; } if (otherMinI.Y < 0) { continue; } if (otherMinI.Z < 0) { continue; } if (otherMaxI.X < 0) { continue; } if (otherMaxI.Y < 0) { continue; } if (otherMaxI.Z < 0) { continue; } return(mergeBlock); } } return(null); }
public void SetLauncherReference(IMyCubeBlock launcherReference, Base6Directions.Direction direction = Base6Directions.Direction.Forward) { LauncherReferencePoint = launcherReference.GetPosition(); var forward3I = launcherReference.Position + Base6Directions.GetIntVector(launcherReference.Orientation.TransformDirection(direction)); var forwardPoint = launcherReference.CubeGrid.GridIntegerToWorld(forward3I); LauncherReferenceDirection = Vector3D.Normalize(forwardPoint - LauncherReferencePoint); }
private void Update() { //-Prepare data // >get local gravity vector // >normalise vector to simplify angle calculation Vector3D worldGravity = controller.GetNaturalGravity(); worldGravity.Normalize(); //Check each thruster to see if it is safe to enable //-only check thrusters on our grid //-check that we have access to the thruster //-disable any that are pointing down // >(with safetyCutoff tolerance) // >enable any others GridTerminalSystem.GetBlocksOfType <IMyThrust>(temp); int count = 0; for (int i = 0; i < temp.Count; i++) { IMyThrust thruster = (IMyThrust)temp[i]; if (thruster.CubeGrid != controller.CubeGrid) { continue; } count++; //Check if we can actually use the thruster if (ValidateBlock(thruster, callbackRequired: false)) { Vector3D worldThruster = GridToWorld( Base6Directions.GetIntVector(thruster.Orientation.Forward), thruster.CubeGrid); //Compare the dot product of gravity and thrust direction (normalised) // 1.0 => 0 degrees // 0.0 => 90 degrees //-1.0 => 180 degrees //safe iff angle <= safetyCutoffAngle //=> safe iff dot product >= cos(safetyCutoffAngle) bool safe = Vector3D.Dot(worldGravity, worldThruster) >= safetyCutoff *worldThruster.Length(); if (thruster.Enabled != safe) { thruster.RequestEnable(safe); } } } //end for Echo(temp.Count.ToString() + " thrusters found."); Echo(count.ToString() + " processed."); }
public void DebugDraw() { if (MyFakes.DEBUG_DRAW_NAVMESH_EXPLORED_HL_CELLS) { foreach (var cell in m_exploredCells) { BoundingBoxD cellAABB; Vector3I cellCopy = cell; MyVoxelCoordSystems.GeometryCellCoordToWorldAABB(m_mesh.VoxelMapReferencePosition, ref cellCopy, out cellAABB); VRageRender.MyRenderProxy.DebugDrawAABB(cellAABB, Color.Sienna, 1.0f, 1.0f, false); } } if (MyFakes.DEBUG_DRAW_NAVMESH_FRINGE_HL_CELLS) { foreach (var packedCoord in m_navmeshComponents.GetPresentCells()) { MyCellCoord coord = new MyCellCoord(); coord.SetUnpack(packedCoord); Vector3I cellCoord = coord.CoordInLod; if (m_exploredCells.Contains(ref cellCoord)) { MyNavmeshComponents.CellInfo cellInfo = new MyNavmeshComponents.CellInfo(); if (m_navmeshComponents.TryGetCell(packedCoord, out cellInfo)) { for (int i = 0; i < cellInfo.ComponentNum; ++i) { int componentIndex = cellInfo.StartingIndex + i; var primitive = m_mesh.HighLevelGroup.GetPrimitive(componentIndex); foreach (var direction in Base6Directions.EnumDirections) { var dirFlag = Base6Directions.GetDirectionFlag(direction); if (cellInfo.ExploredDirections.HasFlag(dirFlag)) { continue; } if (m_exploredCells.Contains(cellCoord + Base6Directions.GetIntVector(direction))) { continue; } Vector3 dirVec = Base6Directions.GetVector(direction); VRageRender.MyRenderProxy.DebugDrawLine3D(primitive.WorldPosition, primitive.WorldPosition + dirVec * 3.0f, Color.Red, Color.Red, false); } } } } } } }
public void Run(ZACommons commons, EventDriver eventDriver) { var shipControl = (ShipControlCommons)commons; ResetIfNotLive(commons, eventDriver); if (!Active) { return; } // Determine velocity var velocity = shipControl.LinearVelocity; // If we have no velocity, we have no ship controllers. // In theory, ResetIfNotLive should have caught it above if (velocity != null) { var cruiseDirectionFlipped = Base6Directions.GetFlippedDirection(CruiseDirection); // Determine forward vector var forward3I = shipControl.Reference.Position + Base6Directions.GetIntVector(shipControl.ShipBlockOrientation.TransformDirection(CruiseDirection)); var forward = Vector3D.Normalize(shipControl.Reference.CubeGrid.GridIntegerToWorld(forward3I) - shipControl.ReferencePoint); CurrentSpeed = Vector3D.Dot((Vector3D)velocity, forward); var error = TargetSpeed - CurrentSpeed; var force = thrustPID.Compute(error); //commons.Echo("Force: " + force); var thrustControl = shipControl.ThrustControl; var collect = ParseCruiseFlags(); if (Math.Abs(error) < CRUISE_CONTROL_DEAD_ZONE * TargetSpeed) { // Close enough, just disable both sets of thrusters thrustControl.Enable(CruiseDirection, false, collect); thrustControl.Enable(cruiseDirectionFlipped, false, collect); } else if (force > 0.0) { // Thrust forward thrustControl.Enable(CruiseDirection, true, collect); thrustControl.SetOverride(CruiseDirection, force, collect); thrustControl.Enable(cruiseDirectionFlipped, false, collect); } else { thrustControl.Enable(CruiseDirection, false, collect); thrustControl.Enable(cruiseDirectionFlipped, true, collect); thrustControl.SetOverride(cruiseDirectionFlipped, -force, collect); } } eventDriver.Schedule(FramesPerRun, Run); }
public bool TurnForward() { control.ClearWaypoints(); Vector3 controlWorldPos = Me.CubeGrid.GridIntegerToWorld(control.Position); control.AddWaypoint(controlWorldPos + forward * 100, "[AUTO]Forward"); SwitchFlyMode(false); if (!control.IsAutoPilotEnabled) { control.SetAutoPilotEnabled(true); } return(Vector3.Dot(Me.CubeGrid.GridIntegerToWorld(control.Position + Base6Directions.GetIntVector(control.Orientation.Forward)) - controlWorldPos, forward) < 0.1f); }
public static Vector3I TransformGridPosToBlockPos(Vector3I blockPos, IMyCubeBlock origin) { Vector3I[] vec = { -Base6Directions.GetIntVector(origin.Orientation.Left), Base6Directions.GetIntVector(origin.Orientation.Up), -Base6Directions.GetIntVector(origin.Orientation.Forward) }; Vector3I[] inv = { new Vector3I(vec[0].X, vec[1].X, vec[2].X), new Vector3I(vec[0].Y, vec[1].Y, vec[2].Y), new Vector3I(vec[0].Z, vec[1].Z, vec[2].Z) }; Vector3I input = blockPos - origin.Position; input = (input.X * inv[0]) + (input.Y * inv[1]) + (input.Z * inv[2]); var result = (input.X * vec[0]) + (input.Y * vec[1]) + (input.Z * vec[2]) + origin.Position; return(input); }
public void TryClearCell(ulong packedCoord) { if (m_triangleLists.ContainsKey(packedCoord)) { ClearCachedCell(packedCoord); } RemoveExplored(packedCoord); MyNavmeshComponents.CellInfo cellInfo; if (!m_navmeshComponents.TryGetCell(packedCoord, out cellInfo)) { return; } for (int i = 0; i < cellInfo.ComponentNum; ++i) { int componentIndex = cellInfo.StartingIndex + i; m_mesh.HighLevelGroup.RemovePrimitive(componentIndex); } foreach (var direction in Base6Directions.EnumDirections) { Base6Directions.DirectionFlags dirFlag = Base6Directions.GetDirectionFlag(direction); if (cellInfo.ExploredDirections.HasFlag(dirFlag)) { Vector3I dirVec = Base6Directions.GetIntVector(direction); MyCellCoord otherCoord = new MyCellCoord(); otherCoord.SetUnpack(packedCoord); Debug.Assert(otherCoord.Lod == MyVoxelNavigationMesh.NAVMESH_LOD); otherCoord.CoordInLod = otherCoord.CoordInLod + dirVec; MyNavmeshComponents.CellInfo otherCellInfo; if (m_navmeshComponents.TryGetCell(otherCoord.PackId64(), out otherCellInfo)) { Base6Directions.DirectionFlags flippedFlag = Base6Directions.GetDirectionFlag(Base6Directions.GetFlippedDirection(direction)); m_navmeshComponents.SetExplored(otherCoord.PackId64(), otherCellInfo.ExploredDirections & ~flippedFlag); } else { Debug.Assert(false, "Could not get the oposite explored cell!"); } } } m_navmeshComponents.ClearCell(packedCoord, ref cellInfo); }
private float CalculateDesiredAngle(IMyMotorStator AZ, Vector3 toTarget) { Vector3 origin = AZ.CubeGrid.GridIntegerToWorld(AZ.Position); Vector3 rotorLf = AZ.CubeGrid.GridIntegerToWorld(AZ.Position + Base6Directions.GetIntVector(AZ.Orientation.Left)) - origin; Vector3 rotorFw = AZ.CubeGrid.GridIntegerToWorld(AZ.Position + Base6Directions.GetIntVector(AZ.Orientation.Forward)) - origin; rotorLf.Normalize(); rotorFw.Normalize(); Vector3 normalizedDir; Vector3.Normalize(ref toTarget, out normalizedDir); return((float)Math.Atan2(Vector3.Dot(normalizedDir, rotorLf), -Vector3.Dot(normalizedDir, rotorFw))); }
public void remoteControlReference() { var list = new List <IMyTerminalBlock>(); GridTerminalSystem.GetBlocksOfType <IMyRemoteControl>(list); var reference = list[0] as IMyRemoteControl; var currentPosition = reference.Position; var forwardPos = reference.Position + Base6Directions.GetIntVector(reference.Orientation.TransformDirection(Base6Directions.Direction.Forward)); var forward = reference.CubeGrid.GridIntegerToWorld(forwardPos); var forwardVector = Vector3D.Normalize(forward - reference.GetPosition()); Echo(currentPosition.ToString()) }
protected static bool CheckConnectivityOnGrid(MySlimBlock block, ref MatrixI transform, ref MyGridPlacementSettings settings, MyCubeGrid hitGrid) { Vector3I position; Vector3I.Transform(ref block.Position, ref transform, out position); Vector3I forward = Base6Directions.GetIntVector(transform.GetDirection(block.Orientation.Forward)); Vector3I up = Base6Directions.GetIntVector(transform.GetDirection(block.Orientation.Up)); MyBlockOrientation blockOrientation = new MyBlockOrientation(Base6Directions.GetDirection(forward), Base6Directions.GetDirection(up)); Quaternion rotation; blockOrientation.GetQuaternion(out rotation); return(MyCubeGrid.CheckConnectivity(hitGrid, block.BlockDefinition, ref rotation, ref position)); }
public Corridor(IMyGravityGenerator core, Program program) { this.core = core; main = program; int offset; if (!int.TryParse(core.CustomData, out offset)) { offset = 1; } position = core.Position - offset * Base6Directions.GetIntVector(core.Orientation.Up); referenceOffset = (position - main.reference.Position) * 2.5f; core.Orientation.GetMatrix(out localRotationMatrix); localRotationMatrix = Matrix.Transpose(localRotationMatrix); }
// Use externally-measured velocity public void Cruise(ShipControlCommons shipControl, double targetSpeed, Vector3D velocity, Func <IMyThrust, bool> condition = null, bool enableForward = true, bool enableBackward = true) { // Determine forward unit vector var forward3I = shipControl.Me.Position + Base6Directions.GetIntVector(shipControl.ShipBlockOrientation.TransformDirection(LocalForward)); var referenceForward = Vector3D.Normalize(shipControl.Me.CubeGrid.GridIntegerToWorld(forward3I) - shipControl.Me.GetPosition()); // Take dot product with forward unit vector var speed = Vector3D.Dot(velocity, referenceForward); var error = targetSpeed - speed; //shipControl.Echo(string.Format("Set Speed: {0:F1} m/s", targetSpeed)); //shipControl.Echo(string.Format("Actual Speed: {0:F1} m/s", speed)); //shipControl.Echo(string.Format("Error: {0:F1} m/s", error)); var force = thrustPID.Compute(error); var thrustControl = shipControl.ThrustControl; if (Math.Abs(error) < ThrustDeadZone * targetSpeed) { // Close enough, just disable both sets of thrusters thrustControl.Enable(LocalForward, false, condition); thrustControl.Enable(LocalBackward, false, condition); } else if (force > 0.0) { // Thrust forward thrustControl.Enable(LocalForward, enableForward, condition); if (enableForward) { thrustControl.SetOverride(LocalForward, force, condition); } thrustControl.Enable(LocalBackward, false, condition); } else { thrustControl.Enable(LocalForward, false, condition); thrustControl.Enable(LocalBackward, enableBackward, condition); if (enableBackward) { thrustControl.SetOverride(LocalBackward, -force, condition); } } }
private static void GenerateConvexVertices() { List <Vector3> verts = new List <Vector3>(0x1b); Array values = Enum.GetValues(typeof(MyCubeTopology)); Cache = new List <Vector3> [values.Length][]; foreach (MyCubeTopology topology in values) { GetTopologySwitch(topology, verts); Cache[(int)topology] = new List <Vector3> [0x24]; Base6Directions.Direction[] enumDirections = Base6Directions.EnumDirections; int index = 0; while (true) { if (index >= enumDirections.Length) { verts.Clear(); break; } Base6Directions.Direction dir = enumDirections[index]; Base6Directions.Direction[] directionArray2 = Base6Directions.EnumDirections; int num2 = 0; while (true) { if (num2 >= directionArray2.Length) { index++; break; } Base6Directions.Direction direction2 = directionArray2[num2]; if ((dir != direction2) && (Base6Directions.GetIntVector(dir) != -Base6Directions.GetIntVector(direction2))) { List <Vector3> list2 = new List <Vector3>(verts.Count); Cache[(int)topology][(int)((dir * (Base6Directions.Direction.Forward | Base6Directions.Direction.Left | Base6Directions.Direction.Up)) + direction2)] = list2; MyBlockOrientation orientation = new MyBlockOrientation(dir, direction2); foreach (Vector3 vector in verts) { list2.Add(Vector3.TransformNormal(vector, orientation)); } } num2++; } } } }
public IMyHighLevelComponent GetComponent(MyHighLevelPrimitive primitive) { ulong cellIndex; if (m_navmeshComponents.GetComponentCell(primitive.Index, out cellIndex)) { Base6Directions.DirectionFlags exploredDirections; if (m_navmeshComponents.GetComponentInfo(primitive.Index, cellIndex, out exploredDirections)) { MyCellCoord coord = new MyCellCoord(); coord.SetUnpack(cellIndex); // Look at present unexplored cells around this cell. // Their direction can be marked as explored, because there was no geometry when they were being explored foreach (var direction in Base6Directions.EnumDirections) { var directionFlag = Base6Directions.GetDirectionFlag(direction); if (exploredDirections.HasFlag(directionFlag)) { continue; } Vector3I neighbor = coord.CoordInLod + Base6Directions.GetIntVector(direction); if (m_exploredCells.Contains(ref neighbor)) { exploredDirections |= directionFlag; } } return(new Component(primitive.Index, exploredDirections)); } else { return(null); } } else { return(null); } }
private void CalculateMergeArea(out Vector3I minI, out Vector3I maxI) { Vector3I faceNormal = Base6Directions.GetIntVector(this.Orientation.TransformDirection(m_forward)); // Shift block maximal and minimal coords one block in the direction of the merge face normal minI = this.Min + faceNormal; maxI = this.Max + faceNormal; // Get maxI and minI into plane by shifting one of them to the other if (faceNormal.X + faceNormal.Y + faceNormal.Z == -1) { // minI is outside the block, get maxI outside too maxI += (maxI - minI) * faceNormal; } else { // maxI is outside the block, get minI outside too minI += (maxI - minI) * faceNormal; } }
public static IMyShipMergeBlock OtherMergeBlock(IMyShipMergeBlock merge) { if (merge == null) { return(null); } // This is a massive hack. Keen f****d up when they made the Small Grid 1x1x1 merge and it is oriented so the connection // is Base6Directions.Direction.Up, not Base6Directions.Direction.Right like the previous merges. This uses the length // of the subtype name (24 characters) of the 1x1x1 small grid merge to do the exception, where as the older two are 19 // characters. If you ever have a mod merge block that is 24 characters, you'll need to do something else here. Vector3I otherPosition = merge.Position + Base6Directions.GetIntVector(merge.Orientation.TransformDirection( merge.BlockDefinition.SubtypeName.Length == 24? Base6Directions.Direction.Up : Base6Directions.Direction.Right)); IMyShipMergeBlock otherMerge = merge.CubeGrid.GetCubeBlock(otherPosition)?.FatBlock as IMyShipMergeBlock; if (otherMerge == merge) { return(null); } return(otherMerge); }
private bool Initialise() { status.initialised = false; Echo("initialising..."); //Find Controller and verify that it is operable if (!(FindBlock <IMyShipController>(out controller, nameController, ref temp) && ValidateBlock(controller, callbackRequired: true))) { return(false); } //Set up command bus busCommand = new CommandBus(Me); //Initialise ship data shipForward = Base6Directions.GetIntVector(controller.Orientation.Forward); status.initialised = true; Echo("Initialisation completed with no errors."); return(true); }
public FilledDisplay[] EnumerateFloor() { FilledDisplay[] floor = new FilledDisplay[9]; IMyCubeBlock topLeft = GridTerminalSystem.GetBlockWithName("P_FLOOR"); if (topLeft != null && topLeft is IMyTextPanel) { DanceSprite[] sprites = DanceSprite.ALL(); Vector3I origin = topLeft.Position; Vector3I Y = Base6Directions.GetIntVector(topLeft.Orientation.Up) * -1; Vector3I X = Base6Directions.GetIntVector(topLeft.Orientation.Left) * -1; Vector3I[] positions = new Vector3I[9]; for (int y = 0; y < 3; y++) { for (int x = 0; x < 3; x++) { positions[(y * 3) + x] = origin + (Y * y) + (X * x); } } int found = 0; List <IMyTextPanel> panels = new List <IMyTextPanel>(); GridTerminalSystem.GetBlocksOfType(panels); foreach (IMyTextPanel panel in panels) { for (int i = 0; i < positions.Length; i++) { if (panel.Position == positions[i]) { floor[i] = new FilledDisplay(panel, sprites[i].Sprite, panel); floor[i].Draw(); Log(String.Format("Addded floor #{0} in position {1}", i, panel.Position)); found++; } } } } return(floor); }
protected static bool TestBlockPlacementOnGrid(MySlimBlock block, ref MatrixI transform, ref MyGridPlacementSettings settings, MyCubeGrid hitGrid) { Vector3I positionMin; Vector3I.Transform(ref block.Min, ref transform, out positionMin); Vector3I positionMax; Vector3I.Transform(ref block.Max, ref transform, out positionMax); Vector3I min = Vector3I.Min(positionMin, positionMax); Vector3I max = Vector3I.Max(positionMin, positionMax); Vector3I forward = Base6Directions.GetIntVector(transform.GetDirection(block.Orientation.Forward)); Vector3I up = Base6Directions.GetIntVector(transform.GetDirection(block.Orientation.Up)); MyBlockOrientation blockOrientation = new MyBlockOrientation(Base6Directions.GetDirection(forward), Base6Directions.GetDirection(up)); if (!hitGrid.CanAddCubes(min, max, blockOrientation, block.BlockDefinition)) { return(false); } return(MyCubeGrid.TestPlacementAreaCube(hitGrid, ref settings, min, max, blockOrientation, block.BlockDefinition, ignoredEntity: hitGrid)); }
private void EraseFaceTriangles(Vector3I pos, Base6Directions.Direction direction) { m_tmpTriangleList.Clear(); Vector3I intVector = Base6Directions.GetIntVector((int)direction); List <int> list = null; if (this.m_smallTriangleRegistry.TryGetValue(pos, out list)) { foreach (int num in list) { MyNavigationTriangle triangle = base.GetTriangle(num); if (this.IsFaceTriangle(triangle, pos, intVector)) { m_tmpTriangleList.Add(new KeyValuePair <MyNavigationTriangle, Vector3I>(triangle, pos)); } } } foreach (KeyValuePair <MyNavigationTriangle, Vector3I> pair in m_tmpTriangleList) { this.RemoveTriangle(pair.Key, pair.Value); } m_tmpTriangleList.Clear(); }
public unsafe void TryClearCell(ulong packedCoord) { MyNavmeshComponents.CellInfo info; if (this.m_triangleLists.ContainsKey(packedCoord)) { this.ClearCachedCell(packedCoord); } this.RemoveExplored(packedCoord); if (this.m_navmeshComponents.TryGetCell(packedCoord, out info)) { for (int i = 0; i < info.ComponentNum; i++) { int index = info.StartingIndex + i; this.m_mesh.HighLevelGroup.RemovePrimitive(index); } foreach (Base6Directions.Direction direction in Base6Directions.EnumDirections) { Base6Directions.DirectionFlags directionFlag = Base6Directions.GetDirectionFlag(direction); if (info.ExploredDirections.HasFlag(directionFlag)) { MyNavmeshComponents.CellInfo info2; Vector3I intVector = Base6Directions.GetIntVector(direction); MyCellCoord coord = new MyCellCoord(); coord.SetUnpack(packedCoord); MyCellCoord *coordPtr1 = (MyCellCoord *)ref coord; coordPtr1->CoordInLod = (Vector3I)(coord.CoordInLod + intVector); if (this.m_navmeshComponents.TryGetCell(coord.PackId64(), out info2)) { Base6Directions.DirectionFlags flags2 = Base6Directions.GetDirectionFlag(Base6Directions.GetFlippedDirection(direction)); this.m_navmeshComponents.SetExplored(coord.PackId64(), info2.ExploredDirections & ((byte)~flags2)); } } } this.m_navmeshComponents.ClearCell(packedCoord, ref info); } }