示例#1
0
        private void MapDistancesToGoal()
        {
            HexEntry goalHex = null;

            foreach (HexEntry hex in scenarioLoader.HexGrid.Values)
            {
                if (hex.Terrain == Terrain.Goal)
                {
                    goalHex = hex;
                }

                hex.aiDistanceToGoal = int.MaxValue;
            }

            if (goalHex == null)
            {
                Debug.Log("No goal");
                return;
            }

            foreach (HexEntry hex in scenarioLoader.HexGrid.Values)
            {
                if (hex != goalHex)
                {
                    hex.aiDistanceToGoal = (int)HexVectorUtil.AxialDistance(goalHex.BoardPos, hex.BoardPos);
                }
                else
                {
                    hex.aiDistanceToGoal = -10; // Used because the distance is a direct weighting factor
                }
            }
        }
示例#2
0
文件: Axe.cs 项目: GBudee/deft-Sample
        protected override List <IUnitController> CheckHit(List <HexEntry> recentPath)
        {
            if (recentPath.Count < 2)
            {
                return(new List <IUnitController>());
            }

            HexEntry current = recentPath[recentPath.Count - 1];
            HexEntry last    = recentPath[recentPath.Count - 2];

            Vector2 displacement = current.BoardPos - last.BoardPos;
            Vector2 targetPos1   = current.BoardPos + HexVectorUtil.RotateClockwise(displacement);
            Vector2 targetPos2   = current.BoardPos + HexVectorUtil.RotateCounterclockwise(displacement);

            List <IUnitController> results = new List <IUnitController>();

            if (scenarioLoader.HexGrid.ContainsKey(targetPos1))
            {
                results.Add(scenarioLoader.HexGrid[targetPos1].SimOccupant);
            }
            if (scenarioLoader.HexGrid.ContainsKey(targetPos2))
            {
                results.Add(scenarioLoader.HexGrid[targetPos2].SimOccupant);
            }
            return(results);
        }
示例#3
0
        private void PopulateHexDistancesToEnemies(int player)
        {
            // Reset hex distances
            foreach (HexEntry hex in scenarioLoader.HexGrid.Values)
            {
                hex.AIDistanceToEnemy = int.MaxValue;
                hex.aiAdjacentEnemies = 0;
            }

            foreach (int p in selectionManager.UnitsByPlayer.Keys)
            {
                if (p == player)   // Only enemy units
                {
                    continue;
                }

                foreach (IUnitController unit in selectionManager.UnitsByPlayer[p])
                {
                    foreach (HexEntry hex in scenarioLoader.HexGrid.Values)
                    {
                        int distanceToUnit = (int)HexVectorUtil.AxialDistance(unit.Position.BoardPos, hex.BoardPos);
                        if (distanceToUnit < hex.AIDistanceToEnemy)
                        {
                            hex.AIDistanceToEnemy = distanceToUnit; // Update nearest enemy distance
                        }
                        if (distanceToUnit == 1)
                        {
                            hex.aiAdjacentEnemies++; // Update adjacent enemies
                        }
                    }
                }
            }
        }
示例#4
0
        private void LoadGrid()
        {
            string mapName;

            if (Vaults.mapName != null)
            {
                mapName = Vaults.mapName;
            }
            else
            {
                mapName = Config.defaultMapName;
            }

            TextAsset map = (TextAsset)Resources.Load(Config.mapLocation + mapName, typeof(TextAsset));

            string[] hexDescriptions = map.text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);

            foreach (string description in hexDescriptions)
            {
                try {
                    //Parse file input
                    string desc;
                    string q = description.Substring(0, description.IndexOf(','));
                    desc = description.Substring(description.IndexOf(',') + 1, description.Length - description.IndexOf(',') - 1);
                    string r = desc.Substring(0, desc.IndexOf(','));
                    desc = desc.Substring(desc.IndexOf(',') + 1, desc.Length - desc.IndexOf(',') - 1);
                    string t = desc;

                    int qVal;
                    int rVal;
                    qVal = int.Parse(q);
                    rVal = int.Parse(r);
                    Terrain terrain = (Terrain)Enum.Parse(typeof(Terrain), t);

                    //Instantiate in-game hexes
                    Vector2    hexCoords   = new Vector2(qVal, rVal);
                    Vector2    worldCoords = HexVectorUtil.worldPositionOfHexCoord(hexCoords);
                    GameObject hex         = Instantiate(basicHex, new Vector3(worldCoords.x, worldCoords.y, 1), Quaternion.identity);
                    hex.transform.SetParent(hexContainer);

                    HexEntry newHex = new HexEntry(hex, hexCoords, terrain);
                    HexGrid.Add(hexCoords, newHex);
                    hexesByUniqueID.Add(newHex);

                    //Text stuff:
                    GameObject hexText = Instantiate(textPrefab, Vector2.Scale(worldCoords, Config.worldToCanvasCoordScaler), Quaternion.identity);
                    hexText.GetComponent <UnityEngine.UI.Text>().text = hexCoords.ToString();
                    //hexText.GetComponent<UnityEngine.UI.Text>().text = "[_ _]";
                    hexText.transform.SetParent(worldCanvas.transform, false);
                    newHex.debugText = hexText.GetComponent <UnityEngine.UI.Text>();

                    if (terrain == Terrain.Goal)
                    {
                        turnsRemainingText.transform.position = new Vector3(worldCoords.x, worldCoords.y + 0.23f, 0);
                        turnsRemainingText.gameObject.SetActive(true);
                    }
                } catch { }
            }
        }
示例#5
0
        private void OrientArrow(HexEntry start, HexEntry dest, GameObject arrow)
        {
            Vector2 startWorldPos = HexVectorUtil.worldPositionOfHexCoord(start.BoardPos);
            Vector2 destWorldPos  = HexVectorUtil.worldPositionOfHexCoord(dest.BoardPos);

            arrow.transform.position = new Vector3(startWorldPos.x, startWorldPos.y, -3) + (Config.hitArrowPosScaler) * Vector3.Normalize(destWorldPos - startWorldPos);
            arrow.transform.rotation = Quaternion.FromToRotation(Vector2.right, destWorldPos - startWorldPos);
        }
示例#6
0
        private void OrientSegment(HexEntry start, HexEntry dest, GameObject segment)
        {
            Vector2 startWorldPos = HexVectorUtil.worldPositionOfHexCoord(start.BoardPos);
            Vector2 destWorldPos  = HexVectorUtil.worldPositionOfHexCoord(dest.BoardPos);

            segment.transform.position = new Vector3(startWorldPos.x, startWorldPos.y, 2);
            segment.transform.rotation = Quaternion.FromToRotation(Vector2.right, destWorldPos - startWorldPos);
        }
示例#7
0
        public void CreateFriendlyFireWarning(HexEntry hex)
        {
            GameObject newFFWarning = Instantiate(friendlyFireWarning, HexVectorUtil.worldPositionOfHexCoord(hex.BoardPos), Quaternion.identity);

            newFFWarning.GetComponent <SpriteRenderer>().color = Config.Palette.attack;
            newFFWarning.transform.SetParent(hitArrowContainer.transform);
            ffWarnings.Add(newFFWarning);
        }
示例#8
0
        public void SnapToHexCoords(Vector2 hexCoords)
        {
            Vector2 newCameraSpot = HexVectorUtil.worldPositionOfHexCoord(hexCoords);

            newCameraSpot = ConformToBounds(newCameraSpot);

            mainCamera.transform.position = new Vector3(newCameraSpot.x, newCameraSpot.y, -10);
            cameraLerp = false;
        }
示例#9
0
        public void LerpToHexCoords(Vector2 hexCoords)
        {
            Vector2 newCameraSpot = HexVectorUtil.worldPositionOfHexCoord(hexCoords);

            newCameraSpot = ConformToBounds(newCameraSpot);

            cameraLerpTarget = new Vector3(newCameraSpot.x, newCameraSpot.y, -10);
            cameraLerp       = true;
        }
示例#10
0
 public override int CheckSupport(IUnitController target)
 {
     if (HexVectorUtil.AxialDistance(unitController.SimPosition.BoardPos, target.SimPosition.BoardPos) <= 3 && target != unitController)
     {
         return(unitController.DamageOutput);
     }
     else
     {
         return(0);
     }
 }
示例#11
0
        public List <IUnitController> permittedUnits; // If null, not checked

        public void Initialize()
        {
            gameManager      = GetComponent <GameManager>();
            selectionManager = GetComponent <SelectionManager>();
            scenarioLoader   = GetComponent <ScenarioLoader>();
            cameraHandler    = GetComponent <CameraHandler>();

            EnableInputs();

            cameraHandler.Initialize(scenarioLoader.HexGrid.Values
                                     .Select(x => HexVectorUtil.worldPositionOfHexCoord(x.BoardPos)).ToList(), new Vector2(0, 0), new Vector2(1, 1));
        }
示例#12
0
        public override int CheckRetal(List <HexEntry> recentPath, IUnitController enemy)
        {
            if (recentPath.Count < 2 || enemy.PlayerOwner == unitController.PlayerOwner)
            {
                return(0);
            }

            HexEntry current = recentPath[recentPath.Count - 1];
            HexEntry last    = recentPath[recentPath.Count - 2];

            if (HexVectorUtil.AxialDistance(current.BoardPos, unitController.SimPosition.BoardPos) == 3)
            {
                if (HexVectorUtil.AxialDistance(last.BoardPos, unitController.SimPosition.BoardPos) > 3)
                {
                    return(unitController.DamageOutput);
                }
            }

            return(0);
        }
示例#13
0
        // Tell each HexEntry about the HexEntries that are immediately adjacent
        public void ConnectNeighbors()
        {
            foreach (KeyValuePair <Vector2, HexEntry> entry in HexGrid)
            {
                Vector2  loc      = entry.Key;
                HexEntry hexEntry = entry.Value;
                IDictionary <Bearing, HexEntry> neighbors = new Dictionary <Bearing, HexEntry>();

                foreach (Bearing b in Enum.GetValues(typeof(Bearing)))
                {
                    Vector2 neighborLoc = loc + HexVectorUtil.NeighborOffsetFromBearing(b);
                    if (HexGrid.ContainsKey(neighborLoc))
                    {
                        neighbors.Add(b, HexGrid[neighborLoc]);
                    }
                }

                hexEntry.SetNeighbors(neighbors);
            }
        }
示例#14
0
        protected override List <IUnitController> CheckHit(List <HexEntry> recentPath)
        {
            if (recentPath.Count < 2)
            {
                return(new List <IUnitController>());
            }

            HexEntry current = recentPath[recentPath.Count - 1];
            HexEntry last    = recentPath[recentPath.Count - 2];

            Vector2        displacement    = current.BoardPos - last.BoardPos;
            List <Vector2> targetPositions = new List <Vector2>();

            targetPositions.Add(current.BoardPos + displacement);
            targetPositions.Add(current.BoardPos + HexVectorUtil.RotateClockwise(displacement));
            targetPositions.Add(current.BoardPos + HexVectorUtil.RotateClockwise(HexVectorUtil.RotateClockwise(displacement)));
            targetPositions.Add(current.BoardPos + HexVectorUtil.RotateCounterclockwise(displacement));
            targetPositions.Add(current.BoardPos + HexVectorUtil.RotateCounterclockwise(HexVectorUtil.RotateCounterclockwise(displacement)));

            /* // For some unknowable reason this implementation doesn't work right
             * // The unit tries to attack itself I guess (includes current position)?
             * // But the behavior it creates depends on where you hover your mouse prior to clicking
             * List<Vector2> targetPositions = new List<Vector2>();
             * foreach (Bearing b in Enum.GetValues(typeof(Bearing))) {
             *  targetPositions.Add(current.BoardPos + HexVectorUtil.NeighborOffsetFromBearing(b));
             * }*/

            List <IUnitController> results = new List <IUnitController>();

            foreach (Vector2 targetPos in targetPositions)
            {
                if (scenarioLoader.HexGrid.ContainsKey(targetPos))
                {
                    results.Add(scenarioLoader.HexGrid[targetPos].SimOccupant);
                }
            }
            return(results);
        }
示例#15
0
 private Vector2 FindCorner(HexEntry hex, float angle)
 {
     return(HexVectorUtil.worldPositionOfHexCoord(hex.BoardPos) + (Vector2)(Quaternion.AngleAxis(angle, Vector3.back) * Vector3.right * (Config.hexSize)));
 }