public (bool legal, bool connected) LegalSectionCheck(Section a, Point aLocation, Section b, Point bLocation) { var bFromA = HexagonHelpers.GetDirectionFromOffset(aLocation, bLocation - aLocation); var aFromB = HexagonHelpers.GetDirectionFromOffset(bLocation, aLocation - bLocation); if (!bFromA.HasValue || !aFromB.HasValue) { return(false, false); } var aBig = a.ConnectionLayout.GetLargeConnectorDirections(a.Rotation).Contains(bFromA.Value); var bBig = b.ConnectionLayout.GetLargeConnectorDirections(b.Rotation).Contains(aFromB.Value); var aSmall = a.ConnectionLayout.GetSmallConnectorDirections(a.Rotation).Contains(bFromA.Value); var bSmall = b.ConnectionLayout.GetSmallConnectorDirections(b.Rotation).Contains(aFromB.Value); Console.WriteLine($"a pos {aLocation} b pos {bLocation}"); Console.WriteLine($"a->b dir {HexagonHelpers.GetDirectionString(bFromA)} "); Console.WriteLine($"b->a dir {HexagonHelpers.GetDirectionString(aFromB)} "); Console.WriteLine($"a rot: {a.Rotation} b rot: {b.Rotation}"); Console.WriteLine($"a big: {aBig} small: {aSmall}"); Console.WriteLine($"b big: {bBig} small: {bSmall}"); Console.WriteLine("a small:"); foreach (var dir in a.ConnectionLayout.SmallConectors) { Console.WriteLine(HexagonHelpers.GetDirectionString(dir)); } Console.WriteLine("a large:"); foreach (var dir in a.ConnectionLayout.LargeConnectors) { Console.WriteLine(HexagonHelpers.GetDirectionString(dir)); } Console.WriteLine("b small:"); foreach (var dir in b.ConnectionLayout.SmallConectors) { Console.WriteLine(HexagonHelpers.GetDirectionString(dir)); } Console.WriteLine("b large:"); foreach (var dir in b.ConnectionLayout.LargeConnectors) { Console.WriteLine(HexagonHelpers.GetDirectionString(dir)); } var matchBig = aBig && bBig; var matchSmall = aSmall && bSmall; var noConnections = !aSmall && !aBig && !bSmall && !bBig; var connected = matchBig || matchSmall; return(connected || noConnections, connected); }
/// <summary> /// Used to identify a split ship. /// </summary> public void PerformPartsAnalysis() { var directions = new[] { 0, 1, 2, 3, 4, 5 }; var available = Topology.AllSections.ToList(); if (available.Count < 1) { return; } var clusters = new List <List <Section> >(); while (available.Count > 0) { var localCluster = new List <Section>(); var stack = new Stack <Section>(); stack.Push(available[0]); available.RemoveAt(0); while (stack.Count > 0) { var processing = stack.Pop(); localCluster.Add(processing); foreach (var direction in directions) { var gridLoc = HexagonHelpers.GetFromDirection(processing.GridLocation, direction); var neighbour = Topology.SectionAt(gridLoc); if (neighbour != null && available.Contains(neighbour)) { available.Remove(neighbour); } } } clusters.Add(localCluster); } var orderedClusters = clusters.OrderByDescending(x => x.Count()).ToArray(); if (orderedClusters.Length > 1) { for (var i = 1; i < orderedClusters.Length; i++) { foreach (var section in orderedClusters[i]) { Damage(section.GridLocation, 999); } } } }
public void Initialise() { for (var gridX = 0; gridX < _shipTopology.GridWidth; gridX++) { for (var gridZ = 0; gridZ < _shipTopology.GridHeight; gridZ++) { var gridPosition = new Point(gridX, gridZ); var child = Entity.Create(); child.Add(new Transform { Location = HexagonHelpers.GetGridWorldPosition(gridPosition), Rotation = Quaternion.CreateFromYawPitchRoll(0, 0, 0) }); child.Add(new BuildNode(gridPosition, _shipTopology)); } } }
public void Render(RenderContext context) { if (PlacingSection != null) { if (HoverNode != null) { _shipRenderer.Render( context, new Transform { Location = HexagonHelpers.GetGridWorldPosition(HoverNode.GridLocation) }.WorldTransform, PlacingSection ); } } }
public bool LegalSectionCheck(Section section, Point gridLocation) { var connected = false; foreach (var surroundingLocation in HexagonHelpers.GetSurroundingCells(gridLocation)) { var neighbour = SectionAt(surroundingLocation); if (neighbour != null) { var res = LegalSectionCheck(section, gridLocation, neighbour, surroundingLocation); if (!res.legal) { return(false); } connected = connected || res.connected; } } return(connected); }
public override void OnDestruction(FlightShip ship, FlightNode node) { for (var direction = 0; direction < 6; direction++) { var gridLocation = HexagonHelpers.GetFromDirection(node.GridLocation, (int)direction); // Boom ship.Damage(gridLocation, 300); } var explosionEnt = ship.Entity.EntityManager.Create(); explosionEnt.Add(new Transform() { Location = node.GlobalLocation }); explosionEnt.Add(new ClusterExplosionEffect() { DistanceScaleFactor = 2f, ScaleFactor = 3f, Components = 16 }); }
public void Initialise() { _flightNode = new FlightNode[_topology.GridWidth, _topology.GridHeight]; this.Update(() => { for (var gridX = 0; gridX < _topology.GridWidth; gridX++) { for (var gridZ = 0; gridZ < _topology.GridHeight; gridZ++) { var gridPosition = new Point(gridX, gridZ); var child = Entity.Create(); child.Add(new Transform(Transform) { Location = HexagonHelpers.GetGridWorldPosition(gridPosition), Rotation = Quaternion.CreateFromYawPitchRoll(0, 0, 0) }); _flightNode[gridX, gridZ] = child.Add(new FlightNode(this, gridPosition, _topology)); } } Fuel = MaxFuel; Energy = MaxEnergy; }); }
public override void Initialise() { AddSingleton(new SpaceBackgroundScroll()); var focusLocation = HexagonHelpers.GetGridWorldPosition(new Point(2, 2)); var camera = Create(); var cameraPos = camera.Add(new Transform() { Rotation = Quaternion.CreateFromYawPitchRoll(0, 0, (float)(Math.PI)), Location = focusLocation + (Vector3.Backward + Vector3.Up * 1.8f) * 10 }); //CameraManager.ActiveCamera = camera.Add(new Camera(new OrthographicCameraParameters(10))); CameraManager.ActiveCamera = camera.Add(new Camera(new PerspectiveCameraParameters() { AspectRatio = GraphicsDevice.Viewport.AspectRatio })); CameraManager.ActiveCamera.LookAt(focusLocation); CameraManager.ActiveCamera.Recalculate(); camera.Add(new BuildCameraControl()); // Background planet. var planetEnt = Create(); planetEnt.Add(new Transform() { Location = cameraPos.Location + CameraManager.ActiveCamera.Forwards * 100 + Vector3.Forward * 50 }); var planetRenderer = planetEnt.Add(new PlanetRenderer() { AutoRender = true, Planet = _planet, Scale = 80f, RenderOrder = 20 }); var floor = Create(); floor.Add(new BuildFloor(_shipTopology)); var productionLine = AddSingleton(new ProductionLine()); var gameMode = AddSingleton(new BuildMode(_shipTopology, _planet)); var placerEnt = Create(); var placer = placerEnt.Add(new BuildPlacer(CameraManager.ActiveCamera, _shipTopology, productionLine)); placerEnt.Add(new BuildPlacerCursor()); var shipRenderer = AddSingleton(new ShipSectionRenderer()); UserInterfaceManager.AddSceneUI(this, new BuildScreenTemplate(gameMode, _planet, productionLine, placer, shipRenderer)); if (_planet == Planet.Earth) { UIDispose closeBeginScreen = null; closeBeginScreen = UserInterfaceManager.Create(new BeginScreenTemplate(() => { gameMode.Start(); EntityManager.Update(() => { closeBeginScreen?.Invoke(); }); })); } else { gameMode.Start(); } MusicManager.Start("Building"); }