private int CalcuatePathValue(List <Node> path)
    {
        int value, resultingValue = 0, numCapturedTiles = 0;

        //Step through path, tally each captured
        for (int steps = 0; steps < path.Count; steps++)
        {
            Node          node = path[steps];
            ClickableTile tile = map.tiles[node.pos.x, node.pos.y];

            int sum = tile.GetValue() + steps;
            if (sum % 10 == 0)
            {
                numCapturedTiles += tile.GetValue() / 10;
            }

            //last node in path, check what final value will be
            if (steps == path.Count - 1)
            {
                if (sum % 10 == 0)
                {
                    resultingValue = 1;
                }
                else
                {
                    resultingValue = sum;
                }
            }
        }

        // Values increase as captured tiles increase and resulting values decrease
        value = numCapturedTiles - resultingValue;
        return(value);
    }
Example #2
0
    public int GetTileValue(Coord target)
    {
        ClickableTile ct    = tiles[target.x, target.y];
        int           value = ct.GetValue();

        //Debug.Log("Tile value at " + target + " is " + value);
        return(value);
    }
 private void UpdateInformation()
 {
     currentTile    = map.tiles[unit.pos.x, unit.pos.y];
     currentNode    = map.nodes[unit.pos.x, unit.pos.y];
     currentValue   = currentTile.GetValue();
     availableTiles = unit.GetAvailableTileOptions(currentNode, unit.GetMoveSpeed());
     paths.Clear();
     sortedPaths.Clear();
 }
 void ClearDrawPath()
 {
     while (drawPathStack.Count > 0)
     {
         Node          popped = drawPathStack.Pop();
         ClickableTile tile   = map.tiles[popped.pos.x, popped.pos.y];
         if (!tile.IsAvailable())
         {
             tile.Highlight(false);
         }
         tile.SetValueText(tile.GetValue());
     }
 }
    void DrawPath()
    {
        if (Input.GetButtonUp("Fire1"))
        {
            //We have let go, return to idle state
            state = ControllerState.idle;

            //All moves used?
            if (drawPathStack.Count - 1 == selectedUnit.GetMoveSpeed())
            {
                //Is this a valid path that leads to a destination tile?
                Node finalNode = drawPathStack.Peek();
                if (map.tiles[finalNode.pos.x, finalNode.pos.y].IsAvailable())
                {
                    //Feed our unit this path
                    Debug.Log("sending drawn path to unit");
                    List <Node> path = new List <Node>(drawPathStack);
                    path.Reverse();
                    selectedUnit.SetPath(path);
                }
            }
            else
            {
                map.ResetTileDrawPath();
            }
            ClearDrawPath();
            return;
        }

        Node       currentNode = drawPathStack.Peek();
        RaycastHit hit;

        //Check if we are hovering over tile
        if (MouseCast(out hit))
        {
            if (hit.transform.tag == "Tile")
            {
                ClickableTile tempTile = hit.transform.GetComponent <ClickableTile>();
                Node          tempNode = map.nodes[tempTile.pos.x, tempTile.pos.y];

                //Is the tile a walkable neighbor tile?
                if (NodeIsNeighbour(currentNode, tempNode) && map.UnitCanEnterTile(tempNode.pos, selectedUnit))
                {
                    //Is it the previous path node?
                    if (drawPathStack.Contains(tempNode))
                    {
                        //pop current position
                        Node          popped = drawPathStack.Pop();
                        ClickableTile tile   = map.tiles[popped.pos.x, popped.pos.y].GetComponent <ClickableTile>();
                        Debug.Log(tile.GetValue());
                        tile.DrawHighlight(false, .01f);
                        tile.SetValueText(tile.GetValue());

                        audioSource.volume = .4f;
                        audioSource.pitch  = 1.9f;
                        audioSource.clip   = sndClickUp;
                        audioSource.Play();

                        //adjust available tiles
                        var coordOptions = selectedUnit.GetAvailableTileOptions(tempNode, selectedUnit.GetMoveSpeed() - drawPathStack.Count + 1);
                        map.ResetTileAvailability();
                        List <Map.Coord> coordList = new List <Map.Coord>();
                        for (int i = 0; i < selectedUnit.coordOptions.Length; i++)
                        {
                            if (coordOptions.Contains(selectedUnit.coordOptions[i]))
                            {
                                coordList.Add(selectedUnit.coordOptions[i]);
                            }
                        }
                        map.MakeTilesAvailable(coordList.ToArray());
                    }
                    //If not, we can push this neighbor is we have remianing moves, one step closer to destination
                    else if (drawPathStack.Count - 1 < selectedUnit.GetMoveSpeed())
                    {
                        {
                            //adjust available tiles
                            var coordOptions = selectedUnit.GetAvailableTileOptions(tempNode, selectedUnit.GetMoveSpeed() - drawPathStack.Count);
                            map.ResetTileAvailability();
                            List <Map.Coord> coordList = new List <Map.Coord>();
                            for (int i = 0; i < selectedUnit.coordOptions.Length; i++)
                            {
                                if (coordOptions.Contains(selectedUnit.coordOptions[i]))
                                {
                                    coordList.Add(selectedUnit.coordOptions[i]);
                                }
                            }
                            map.MakeTilesAvailable(coordList.ToArray());

                            drawPathStack.Push(tempNode);
                            //highlight tempTile? show its part of path
                            tempTile.DrawHighlight(true, .02f);
                            tempTile.SetValueText(tempTile.GetValue() + drawPathStack.Count - 1);

                            audioSource.volume = .95f;
                            audioSource.pitch  = (((float)drawPathStack.Count - 1f) / (float)selectedUnit.GetMoveSpeed()) * .1f + .9f;
                            audioSource.clip   = sndClickDown;
                            audioSource.Play();
                        }
                    }
                }
            } //end MouseCast
        }
    }