示例#1
0
    public void ImmigratingAgentArriving(Agent immigrant)     //New immigrants arriving, add layer and upgrade excisting house
    {
        //find house to upgrade
        //increase layer
        //add layer in right color to it

        //Gå igenom alla bostadshus clanen har och om man hittar ett med children mindre än 3 så lägg till ett floor på det huset
        //Debug.Log ("??????????????????????????Immigrant arriving adding floor");


        if (!blackBoard.GetColorsInClan(clan).Contains(immigrant.getAgentType()))
        {
            blackBoard.AddColorToClan(clan, immigrant.getAgentType());
        }


        foreach (Transform building in GameObject.Find(clan).transform.FindChild("Buildings"))
        {
            string buildingName = building.name.Substring(building.name.Length - 5, 5);
            if (buildingName.Substring(buildingName.Length - 5, buildingName.Length) == "House")
            {
                int numberFloors = ((Building)building.GetComponent("Building")).GetFloors();

                if (numberFloors < 3)                //max floors = 3
                {
                    goalIndex++;
                    planner.SetGoalWorldState(new WorldState(char.ToLower(immigrant.getAgentType()[0]) + immigrant.getAgentType().Substring(1) + "FloorIsBuilt", new WorldStateValue(true)));
                    plan = planner.RunAStar((WorldState)blackBoard.GetFact(clan, "currentWorldState")[0].GetFactValue());
                    //Debug.Log ("***********Plan Size " + plan.Count);

                    List <TreeNode> planList = new List <TreeNode>();
                    Vector3         positionOfHouseToUpgrade = building.position;

                    //Debug.Log("6666666666666666666666 floor ska byggas på " + positionOfHouseToUpgrade + " " + building.name);

                    TreeNode tempNode = new TreeNode(positionOfHouseToUpgrade, plan[1].GetName(), null, goalIndex);
                    tempNode.SetOwner(immigrant);

                    planList.Add(tempNode);

                    tempNode = new TreeNode(positionOfHouseToUpgrade, plan[0].GetName(), planList[0], goalIndex);
                    tempNode.SetOwner(immigrant);

                    planList.Add(tempNode);

                    blackBoard.AddToTaskTree(clan, planList);

                    numberFloors++;
                    ((Building)building.GetComponent("Building")).SetFloors(numberFloors);


                    break;
                }
            }
        }
    }