// FUNCTIONS /////////////////////////////////////////////////////////////////////////// public DrawInfo(FogMap map, FogShape shape, float xradius, float yradius) { // convert size to fog space fogForward = shape.Forward; forwardAngle = FogTools.ClockwiseAngle(Vector2.up, fogForward) * Mathf.Deg2Rad; float sin = Mathf.Sin(-forwardAngle); float cos = Mathf.Cos(-forwardAngle); Vector2 relativeoffset = new Vector2(shape.Offset.x * cos - shape.Offset.y * sin, shape.Offset.x * sin + shape.Offset.y * cos); fogCenterPos = FogConversion.WorldToFog(FogConversion.WorldToFogPlane(shape.EyePosition, map.Plane) + relativeoffset, map.Offset, map.Resolution, map.Size); fogEyePos = new Vector2_1(FogConversion.WorldToFog(shape.EyePosition, map.Plane, map.Offset, map.Resolution, map.Size)); // find ranges if (shape.VisibleCells == null) { xMin = Mathf.Max(0, Mathf.RoundToInt(fogCenterPos.x - xradius)); xMax = Mathf.Min(map.Resolution.x - 1, Mathf.RoundToInt(fogCenterPos.x + xradius)); yMin = Mathf.Max(0, Mathf.RoundToInt(fogCenterPos.y - yradius)); yMax = Mathf.Min(map.Resolution.y - 1, Mathf.RoundToInt(fogCenterPos.y + yradius)); } else { fogCenterPos = FogConversion.SnapToNearestFogPixel(fogCenterPos); fogEyePos = new Vector2_1(FogConversion.SnapToNearestFogPixel(FogConversion.WorldToFog(shape.EyePosition, map.Offset, map.Resolution, map.Size))); Vector2_1 pos = new Vector2_1(Mathf.RoundToInt(fogCenterPos.x), Mathf.RoundToInt(fogCenterPos.y)); Vector2_1 rad = new Vector2_1(Mathf.RoundToInt(xradius), Mathf.RoundToInt(yradius)); xMin = Mathf.Max(0, Mathf.RoundToInt(pos.x - rad.x)); xMax = Mathf.Min(map.Resolution.x - 1, Mathf.RoundToInt(pos.x + rad.x)); yMin = Mathf.Max(0, Mathf.RoundToInt(pos.y - rad.y)); yMax = Mathf.Min(map.Resolution.y - 1, Mathf.RoundToInt(pos.y + rad.y)); } }
public void TestInitialisation() { var map = Map.Create() .AddNode(out var n1) .AddNode(out var n2) .GetResult(); var p = Generate.Prime(); var cMap1 = FogMap.Create(map, 1, p); var cMap2 = FogMap.Create(map, 1, p); var t1_1 = cMap1.Initilize.Phase0Async(); var t1_2 = cMap2.Initilize.Phase0Async(); Task.WaitAll(t1_1, t1_2); var phase1_1 = t1_1.Result; var phase1_2 = t1_2.Result; var t2_1 = cMap1.Initilize.Phase1Async(phase1_2); var t2_2 = cMap2.Initilize.Phase1Async(phase1_1); Task.WaitAll(t2_1, t2_2); var phase2_1 = t2_1.Result; var phase2_2 = t2_2.Result; Task.WaitAll( cMap1.Initilize.Phase2Async(phase2_2), cMap2.Initilize.Phase2Async(phase2_1)); Assert.IsTrue(cMap1.IsInitilzied); Assert.IsTrue(cMap2.IsInitilzied); }
// Create action map public void CreateActionMap(GamePiece piece, GameMap gameMap, FogMap fogOfWarMap) { ClearActionTiles(); if (piece == null) { return; } Vector3Int hexCoords = piece.gameHex.hexCoords; List <Vector3Int> visibleTileCoords = fogOfWarMap.GetVisibleTileCoords(); if (piece.pieceType == PieceType.Unit) { Unit unit = (Unit)piece; int remainingSpeed = unit.remainingSpeed; int range = unit.range; // Get hexes in range of unit movement and set tiles List <GameHex> gameHexes = gameMap.GetHexesInRange(gameMap.hexCoordsDict, hexCoords, remainingSpeed + range); for (int i = 0; i < gameHexes.Count; i++) { GameHex gameHex = gameHexes[i]; Vector3Int tileCoords = Hex.HexToTileCoords(gameHex.hexCoords); int distance = Hex.GetDistanceHexCoords(hexCoords, gameHex.hexCoords); // Set tile to appropriate movement tile type if (!gameHex.HasPiece()) { if (distance <= remainingSpeed) { paintedTiles[tileCoords] = movementTile; } } else { if (gameHex.piece.GetPlayerId() != unit.GetPlayerId() && visibleTileCoords.Contains(tileCoords)) { paintedTiles[tileCoords] = attackTile; } } } } }
public virtual void Initialise(FogMap map) { _Map = map; OnInitialise(); }
// Set fog map public void SetFogMap(FogMap fogMap) { this.fogMap = fogMap; }
// Draw action map public void DrawActionMap(GamePiece piece, GameMap gameMap, FogMap fogOfWarMap) { ClearPaintedTiles(); actionMap.CreateActionMap(piece, gameMap, fogOfWarMap); PaintActionMap(); }