Esempio n. 1
0
    public List<CandidatePath> getCandidatesInPlaceByObject(CandidatePath obj)
    {
        GameObject room;
        if (obj.checkPoint.tag == "Player" || obj.checkPoint.tag == "npc") {
            room = obj.checkPoint.GetComponent<characterValues>().currentRoom;
        } else {
            room = Utils.getFirstParentWithComponent (obj.checkPoint, "Room");
        }
        List<CandidatePath> candidates = new List<CandidatePath> ();
        foreach (GameObject childDoor in Utils.getChildrenWithTag(room, "door")) {
            GameObject connectedDoor = childDoor.GetComponent<Door>().connectedDoor;
            GameObject parent = Utils.getFirstParentWithComponent(connectedDoor, "Room");
            GameObject parentEntity = parent.GetComponent<Room>().building;
            bool sameEntity = (parentEntity == targetEntity);

            int weightRoom;
            if(sameEntity){
                weightRoom = Mathf.Abs(parent.GetComponent<Room>().getRoomDepth() - targetRoom.GetComponent<Room>().getRoomDepth());
            }else{
                weightRoom = parent.GetComponent<Room>().getRoomDepth() + targetRoom.GetComponent<Room>().getRoomDepth();
            }

            if(candidateObject == null)
            {
                candidateObject = new GameObject ();
            }

            CandidatePath candidate = candidateObject.AddComponent<CandidatePath>();
            candidate.transform.tag = "candidate";
            candidate.weight = weightRoom;
            candidate.currentWeight = obj.currentWeight + 1;
            int weight = candidate.weight + candidate.currentWeight;
            candidate.keyWeight = weight;
            candidate.checkPoint = connectedDoor;
            candidate.previousCandidatePath = obj;

            candidates.Add(candidate);

        }
        foreach (GameObject childStair in Utils.getChildrenWithTag(room, "stair")) {
            GameObject connectedStair = childStair.GetComponent<Stair>().connectedStair;
            GameObject parent = Utils.getFirstParentWithComponent(connectedStair, "Room");
            GameObject parentEntity = parent.GetComponent<Room>().building;
            bool sameEntity = (parentEntity == targetEntity);

            int weightRoom;
            if(sameEntity){
                weightRoom = Mathf.Abs(parent.GetComponent<Room>().getRoomDepth() - targetRoom.GetComponent<Room>().getRoomDepth());
            }else{
                weightRoom = parent.GetComponent<Room>().getRoomDepth() + targetRoom.GetComponent<Room>().getRoomDepth();
            }

            GameObject candidateObject = new GameObject ();
            CandidatePath candidate = candidateObject.AddComponent<CandidatePath>();
            candidate.weight = weightRoom;
            candidate.currentWeight = obj.currentWeight + 1;
            int weight = candidate.weight + candidate.currentWeight;
            candidate.keyWeight = weight;
            candidate.transform.tag = "candidate";
            candidate.checkPoint = connectedStair;
            candidate.previousCandidatePath = obj;
            candidates.Add(candidate);
        }
        GameObject[] gameObjects =  GameObject.FindGameObjectsWithTag ("candidate");
        foreach (GameObject target in gameObjects) {
            GameObject.Destroy(target);
        }
        return candidates;
    }
Esempio n. 2
0
 public void putCandidateInClosedList(CandidatePath candidate)
 {
     closedList.Add (candidate);
     openList.Remove (candidate);
 }