Esempio n. 1
0
    public void Prebuild(Vector3 point, UnitTower tower)
    {
        if (nodeGraph == null || nodeGraph.Length == 0)
        {
            return;
        }

        NodeTD node = PathFinderTD.GetNearestNode(point, nodeGraph, 0);

        node.walkable = false;

        List <NodeTD> nodeList = PathFinderTD.GetNodeInFootprint(node, tower.GetFootprint());

        foreach (NodeTD n in nodeList)
        {
            n.walkable = false;
        }

        tower.SetPlatform(this, node);

        foreach (PathOnPlatform pathObj in pathObjects)
        {
            queue.Add(pathObj.thisWP);

            PathFinderTD.GetPath(pathObj.startN, pathObj.endN, nodeGraph, this.SetPath);
        }
    }
Esempio n. 2
0
    public void Build(Vector3 point, UnitTower tower)
    {
        //pathfinding related code, only call if this platform is walkable;
        if (walkable)
        {
            if (tower.type != _TowerType.Mine)
            {
                //if build on the node last check for block, use the cached node and path
                if (nextBuildNode != null && Vector3.Distance(nextBuildNode.pos, point) < BuildManager.GetGridSize() / 2)
                {
                    //Debug.Log("use cached path");
                    nextBuildNode.walkable = false;

                    List <NodeTD> nodeList = PathFinderTD.GetNodeInFootprint(nextBuildNode, tower.GetFootprint());
                    foreach (NodeTD node in nodeList)
                    {
                        node.walkable = false;
                    }

                    tower.SetPlatform(this, nextBuildNode);
                    foreach (PathOnPlatform pathObj in pathObjects)
                    {
                        int rand = pathObj.pathID;
                        while (rand == pathObj.pathID)
                        {
                            rand = Random.Range(-999999, 999999);
                        }
                        pathObj.SetPath(pathObj.altPath, rand);
                        //forceSearch doesnt smooth path so path smoothing is call
                        //smoothPath will only valid path smoothing is enable in PathFinder
                        pathObj.SmoothPath();
                    }
                }
                //if build on node that is unchecked, find the block node and initiate a new path search
                else
                {
                    //Debug.Log("unexpected build point, query for new path");
                    NodeTD node = PathFinderTD.GetNearestNode(point, nodeGraph);
                    node.walkable = false;
                    //~ Debug.Log(node.ID);

                    List <NodeTD> nodeList = PathFinderTD.GetNodeInFootprint(node, tower.GetFootprint());
                    foreach (NodeTD n in nodeList)
                    {
                        n.walkable = false;
                    }

                    tower.SetPlatform(this, node);
                    foreach (PathOnPlatform pathObj in pathObjects)
                    {
                        queue.Add(pathObj.thisWP);

                        PathFinderTD.GetPath(pathObj.startN, pathObj.endN, nodeGraph, this.SetPath);
                    }
                }
            }
        }
    }
Esempio n. 3
0
    public void UnBuild(NodeTD node, int footprint)
    {
        footprint = 0;

        //Debug.Log("unbuild  "+node.ID);

        node.walkable = true;

        List <NodeTD> nodeList = PathFinderTD.GetNodeInFootprint(node, footprint);

        foreach (NodeTD n in nodeList)
        {
            n.walkable = true;
        }

        foreach (PathOnPlatform pathObj in pathObjects)
        {
            //~ Debug.Log("update path");

            queue.Add(pathObj.thisWP);
            PathFinderTD.GetPath(pathObj.startN, pathObj.endN, nodeGraph, this.SetPath);
        }
    }