Пример #1
0
    void Start()
    {
        map          = owner.GetComponent <UnitBasics>().map;
        basics       = gameObject.GetComponent <UnitBasics>();
        basics.map   = map;
        basics.speed = speed;
        basics.turns = range / speed;

        basics.timePerMove = FindObjectOfType <ManagementScript>().resultsTimer / speed;

        player.Spawn(gameObject);
    }
Пример #2
0
 public void PlayerEndTurn()
 {
     Debug.Log("pEnd");
     foreach (GameObject unit in units)
     {
         UnitBasics basics = unit.GetComponent <UnitBasics>();
         if (basics.shortPath == null || basics.shortPath.Count == 0)
         {
             basics.shortPath.Add(map.graph[basics.tileX, basics.tileY, basics.tileZ]);
         }
     }
     gm.endTurnRequests++;
 }
Пример #3
0
    void Start()
    {
        shot         = 0;
        ammo         = 4;
        speed        = agility;
        health       = energy * 15;
        basics       = gameObject.GetComponent <UnitBasics>();
        basics.speed = speed;

        vision = experience;
        if (loadout.Contains("pistol"))
        {
            vision += 5;
        }
        else if (loadout.Contains("sniper"))
        {
            vision += 8;
        }
        //else if (loadout.Contains("shotgun"))
        //	vision += 4;

        if (fours)
        {
            trust = true;
        }
        if (spare)
        {
            freeShots++;
        }

        foreach (GameObject p in FindObjectOfType <ManagementScript>().players)
        {
            if (basics.playerNum == p.GetComponent <PlayerScript>().num)
            {
                player = p.GetComponent <PlayerScript>();
            }
        }

        transform.parent = player.transform;
        player.units.Add(gameObject);

        basics.timePerMove = FindObjectOfType <ManagementScript>().resultsTimer / speed;
    }
Пример #4
0
    public void GeneratePathTo(int x, int y, int z)
    {
        if (gm.playResults)
        {
            return;
        }

        Node        source = null;
        List <Node> path   = new List <Node>();

        UnitBasics unit = selectedUnit.GetComponent <UnitBasics>();

        if (unit.plannedPath == null)
        {
            source = graph[
                unit.tileX,
                unit.tileY,
                unit.tileZ
                     ];
        }

        else if (unit.plannedPath.Count <= 1)
        {
            source = graph[
                unit.tileX,
                unit.tileY,
                unit.tileZ
                     ];
            unit.plannedPath = new List <Node>();
        }
        else
        {
            source = unit.plannedPath[unit.plannedPath.Count - 1];
        }

        Dictionary <Node, float> dist = new Dictionary <Node, float>();
        Dictionary <Node, Node>  prev = new Dictionary <Node, Node>();

        // Setup the "Q" -- the list of nodes we haven't checked yet.
        List <Node> unvisited = new List <Node>();

        Node target = graph[x, y, z];

        if (selectedUnit.GetComponent <UnitBasics>() != null)
        {
            if (selectedUnit.GetComponent <UnitBasics>().keyPoints.Count == 0)
            {
                selectedUnit.GetComponent <UnitBasics>().keyPoints.Add(source);
            }
            if (!selectedUnit.GetComponent <UnitBasics>().fullPath)
            {
                selectedUnit.GetComponent <UnitBasics>().keyPoints.Add(target);
            }
        }

        dist[source] = 0;
        prev[source] = null;

        // Initialize everything to have INFINITY distance, since
        // we don't know any better right now. Also, it's possible
        // that some nodes CAN'T be reached from the source,
        // which would make INFINITY a reasonable value
        foreach (Node v in graph)
        {
            if (v != source)
            {
                dist[v] = Mathf.Infinity;
                prev[v] = null;
            }

            unvisited.Add(v);
        }

        while (unvisited.Count > 0)
        {
            // "nxt" is going to be the unvisited node with the smallest distance.
            Node nxt = null;

            foreach (Node potentialNext in unvisited)
            {
                if (nxt == null || dist[potentialNext] < dist[nxt])
                {
                    nxt = potentialNext;
                }
            }

            if (nxt == target)
            {
                break;                  // Exit the while loop!
            }

            unvisited.Remove(nxt);

            foreach (Node neighbor in nxt.neighbors)
            {
                float alt = dist[nxt] + nxt.DistanceTo(neighbor)
                            + CostToEnter(neighbor.x, neighbor.y, neighbor.z, nxt.x, nxt.y, nxt.z);

                if (alt < dist[neighbor])
                {
                    dist[neighbor] = alt;
                    prev[neighbor] = nxt;
                }
            }
        }

        // If we get there, the either we found the shortest route
        // to our target, or there is no route at ALL to our target.

        if (prev[target] == null)
        {
            // No route between our target and the source
            return;
        }

        Node currentStep = target;

        // Step through the "prev" chain and add it to our path
        while (currentStep != null)
        {
            path.Add(currentStep);
            currentStep = prev[currentStep];
        }

        // Right now, currentPath describes a route from out target to our source
        // So we need to invert it!

        path.Add(graph[unit.tileX, unit.tileY, unit.tileZ]);
        path.Reverse();

        if (unit.plannedPath == null)
        {
            unit.plannedPath = path;
        }
        else
        {
            for (int n = 1; n < path.Count; n++)
            {
                unit.plannedPath.Add(path[n]);
            }
        }
        unit.CheckPath();
    }
Пример #5
0
 public void AddToPath(UnitBasics unit, int x, int y, int z)
 {
     unit.shortPath.Add(graph[x, y, z]);
 }