public void removeHexagon(GridPoint g) { HexagonBase hb = getHexagon(g); if (hb != null) { hb.gameObject.SetActive(false); } grid [g.u + 50] [g.v + 50] = ((GameObject)Instantiate(hexagonDummy, SpacePoint(g), Quaternion.identity)).GetComponent <HexagonDummy> (); grid [g.u + 50] [g.v + 50].gridPoint = g; grid [g.u + 50] [g.v + 50].hexField = this; GridPoint[] neis = g.AdjacentPointsCircular(); for (int i = 1; i <= 6; ++i) { if ((!inRange(neis [i])) || (!inRange(neis [i - 1])) || (!inRange(neis [i + 1]))) { HexagonBase newHex = ((GameObject)Instantiate(hexagon, SpacePoint(g), Quaternion.identity)).GetComponent <HexagonPower> (); grid [g.u + 50] [g.v + 50].gameObject.SetActive(false); grid [g.u + 50] [g.v + 50] = newHex; newHex.transform.SetParent(map.transform); newHex.hexField = this; newHex.gridPoint = g; break; } if (getHexagon(neis [i]) is HexagonDummy) { getHexagon(neis [i]).gameObject.SetActive(false); GridPoint gpToRotate = neis [i - 1]; if (neis [i - 1].RawPlainPoint().SqrMagnitude() < neis [i + 1].RawPlainPoint().SqrMagnitude()) { gpToRotate = neis [i + 1]; } HexagonBase hexToRotate = getHexagon(gpToRotate); if (hexToRotate is HexagonPower && (!((HexagonPower)hexToRotate).isRotating())) { if (!hexToRotate.gridPoint.Equals(gpToRotate)) { throw new MissingComponentException("Hexagon is not at its grid point " + gpToRotate.ToString() + " but instead at " + hexToRotate.gridPoint); } HexagonBase hd = ((GameObject)Instantiate(hexagonDummyTrans, SpacePoint(gpToRotate), Quaternion.identity)).GetComponent <HexagonBase> (); hd.gridPoint = gpToRotate; hd.hexField = this; ((HexagonPower)hexToRotate).TransitionTo(neis [i], g, hd); grid [neis [i].u + 50] [neis [i].v + 50] = hexToRotate; grid [gpToRotate.u + 50] [gpToRotate.v + 50] = hd; break; } } } }
void hoverWireRecursion(GridPoint currentGridPoint, int powerEntryPoint) { GridPoint nextGridPoint = currentGridPoint.AdjacentPointsCircular() [powerEntryPoint + 3]; if (inRange(nextGridPoint)) { HexagonBase hexBase = getHexagon(nextGridPoint); if (hexBase is HexagonPower) { HexagonPower nextHexPower = (HexagonPower)hexBase; Wire activeWire = nextHexPower.getWireAtEntryPoint(powerEntryPoint); if ((activeWire != null) && !nextHexPower.isRotating() && !activeWire.hover) { activeWire.setHover(true); int nextPowerEntryPoint = nextHexPower.otherEndpointOfWire(powerEntryPoint); hoverWires.Add(activeWire); hoverWireRecursion(nextGridPoint, (nextPowerEntryPoint + 3) % 6); } } } }
void emitPowerRecursion(GridPoint currentGridPoint, int powerEntryPoint) { GridPoint nextGridPoint = currentGridPoint.AdjacentPointsCircular() [powerEntryPoint + 3]; if (hexField.inRange(nextGridPoint)) { HexagonBase hexBase = hexField.getHexagon(nextGridPoint); if (hexBase is HexagonPower) { HexagonPower nextHexPower = (HexagonPower)hexBase; Wire activeWire = nextHexPower.getWireAtEntryPoint(powerEntryPoint); if ((activeWire != null) && !nextHexPower.isRotating()) { activeWire.setPowered(true); int nextPowerEntryPoint = nextHexPower.otherEndpointOfWire(powerEntryPoint); poweredWires.Add(activeWire); emitPowerRecursion(nextGridPoint, ((nextPowerEntryPoint + 9) % 6)); } } } }