Exemplo n.º 1
0
    IEnumerator FindResource()
    {
        while (actionIsDone == false)
        {
            if (collected)
            {
                Vector3 housePosition = BlackBoard.Instance.GetTaskTree(clan).GetOwnedNode(agentComponent.getAgentNumber()).GetPosition();
                walker.StartWalking(housePosition);

                if (walker.hasArrived == true)
                {
                    Debug.Log("*DELIVERED-" + facts[1] + "*");

                    AudioSource.PlayClipAtPoint(getSounds[1], housePosition, 0.5f);
                    BlackBoard.Instance.GetTaskTree(clan).RemoveNode(agentComponent);

                    collected    = false;
                    actionIsDone = true;

                    agentComponent.SetSkillpoints("collect");
                    agentComponent.RemoveEnergy();
                }
            }
            else
            {
                //TODO: Denna information borde plockas ut från buildingposition
                if (agentComponent.GetWMemory().GetFact(facts[1]).Count > 0)
                {
                    //TODO: choose the nearest source to go to
                    moveToPosition = (Vector3)agentComponent.GetWMemory().GetFact(facts[1])[0].GetFactValue();
                    walker.StartWalking(moveToPosition);

                    if (walker.hasArrived == true)
                    {
                        Debug.Log("*GOT-" + facts[1] + "*");
                        AudioSource.PlayClipAtPoint(getSounds[0], moveToPosition, 0.75f);

                        collected = true;
                    }
                }
                else
                {
                    walker.StartWalking(moveToPosition);

                    if (walker.hasArrived == true)
                    {
                        moveToPosition = new Vector3(Random.Range(agentObject.transform.position.x - 10.0f, agentObject.transform.position.x + 10.0f), 1.0f, Random.Range(agentObject.transform.position.z - 10.0f, agentObject.transform.position.z + 10.0f));
                        walker.StartWalking(moveToPosition);
                    }
                }
            }
            yield return(null);
        }
    }
Exemplo n.º 2
0
    IEnumerator FindResource()
    {
        Debug.Log("Scouting for: " + facts[1]);
        while (BlackBoard.Instance.GetFact(clan, facts[1]).Count == 0)          //continue to scout for resource as long as no one has found one
        {
            walker.StartWalking(moveToPosition);

            if (walker.hasArrived == true)            //has arrived at new searchlocation need a new one
            {
                moveToPosition = GeneratePosition();

                walker.StartWalking(moveToPosition);
            }


            yield return(null);
        }

        BlackBoard.Instance.GetTaskTree(clan).RemoveNode(agentComponent);
    }
Exemplo n.º 3
0
    IEnumerator FindResource()
    {
        Debug.Log("Letar efter:  " + facts[1]);
        while (BlackBoard.Instance.GetFact(clan, facts[1]).Count == 0)
        {
            walker.StartWalking(moveToPosition);

            if (walker.hasArrived == true)
            {
                moveToPosition = GeneratePosition();


                walker.StartWalking(moveToPosition);
            }


            yield return(null);
        }

        BlackBoard.Instance.GetTaskTree(clan).RemoveNode(agentComponent);
    }
Exemplo n.º 4
0
    IEnumerator Assist()
    {
        while (actionIsDone == false)
        {
            walker.StartWalking(moveToPosition);                                                                                                     //walk to position

            if (BlackBoard.Instance.GetTaskTree(clan).GetOwnedNode(agentComponent.GetAgentNumber()).GetPosition().Equals(new Vector3(30, 0.5f, 30))) //if done with action (no owned node) the we are done with the action
            {
                ((AIPath)agentObject.GetComponent("AIPath")).canMove   = false;                                                                      //agent cant move
                ((AIPath)agentObject.GetComponent("AIPath")).canSearch = false;                                                                      //agent cant search
                actionIsDone = true;
            }
            yield return(null);
        }
    }
Exemplo n.º 5
0
    IEnumerator Migrate()
    {
        while (actionIsDone == false)
        {
            walker.StartWalking(moveToPosition);

            if (walker.hasArrived == true)
            {
                ((AIPath)agentObject.GetComponent("AIPath")).canMove   = false;
                ((AIPath)agentObject.GetComponent("AIPath")).canSearch = false;
                //agentComponent.RemoveEnergy();
                actionIsDone = true;
            }
            yield return(null);
        }
    }
Exemplo n.º 6
0
    IEnumerator Assist()
    {
        while (actionIsDone == false)
        {
            walker.StartWalking(moveToPosition);

            if (BlackBoard.Instance.GetTaskTree(clan).GetOwnedNode(agentComponent.getAgentNumber()).GetPosition().Equals(new Vector3(30, 0.5f, 30)))
            {
                ((AIPath)agentObject.GetComponent("AIPath")).canMove   = false;
                ((AIPath)agentObject.GetComponent("AIPath")).canSearch = false;
                agentComponent.RemoveEnergy();
                actionIsDone = true;
            }
            yield return(null);
        }
    }
Exemplo n.º 7
0
    IEnumerator Migrate()
    {
        while (actionIsDone == false)
        {
            walker.StartWalking(moveToPosition);

            if (walker.hasArrived == true)
            {
                //agentComponent.RemoveEnergy();
                actionIsDone = true;
            }
            yield return(null);
        }

        BlackBoard.Instance.GetTaskTree(agentComponent.GetClan()).RemoveNode(agentComponent);
    }
Exemplo n.º 8
0
    IEnumerator Build()
    {
        while (actionIsDone == false)
        {
            walker.StartWalking(moveToPosition);

            if (walker.hasArrived == true)            //agent has arrived at the position
            {
                //check if all assisters are here too
                bool         assistersAreNearby = false;
                bool         temp      = false;
                List <Agent> assisters = BlackBoard.Instance.GetTaskTree(clan).GetOwnedNode(agentComponent.GetAgentNumber()).GetAssisters();
                foreach (Agent assister in assisters)
                {
                    if (Vector3.Distance(moveToPosition, assister.transform.position) >= 3.0f)
                    {
                        temp = true;
                    }
                }

                if (temp == false)
                {
                    assistersAreNearby = true;
                }

                if (assistersAreNearby)               //all helpers are nearby so we can build the building
                {
                    buildingSounds = (AudioClip)Resources.Load("SFX/industry005");
                    AudioSource.PlayClipAtPoint(buildingSounds, moveToPosition, 0.5f);                          //play building sound at center of building

                    yield return(new WaitForSeconds((100 - agentComponent.GetSkill("buildSkillpoints")) / 10)); //wait this amount of time until the buidling is completed (based on skill)


                    //remove the wireframe for the building
                    GameObject[] tiles = GameObject.FindGameObjectsWithTag("wireframe");

                    foreach (GameObject tile in tiles)
                    {
                        if (Vector3.Distance(tile.transform.position, moveToPosition) < 0.01f)
                        {
                            Destroy(tile);
                        }
                    }

                    //add the prefab for the bulding in place of the wireframe
                    GameObject building = (GameObject)Instantiate(Resources.Load(("Prefabs/Building"), typeof(GameObject)));
                    building.transform.position      = moveToPosition;
                    building.transform.parent        = GameObject.Find(clan).transform.FindChild("Buildings");
                    building.renderer.material.color = BlackBoard.Instance.GetColorForObject(facts[1]);
                    building.tag  = facts[1] + facts[2];
                    building.name = facts[1] + facts[2];

                    AstarPath.active.UpdateGraphs(building.collider.bounds);                      //update the gridgraph with the position of the building


                    //if a factory was built add new resource location
                    if (facts[1] == "Green" || facts[1] == "Orange" || facts[1] == "Magenta" || facts[1] == "Black")
                    {
                        //add new resource location to the working memory
                        agentComponent.GetWMemory().SetFact(facts[1], new WorkingMemoryValue(building.transform.position));

                        WorldState newState = new WorldState();
                        newState.SetProperty(char.ToLower(facts[1][0]) + facts[1].Substring(1) + "ResourceIsAvailable", new WorldStateValue(true));

                        //Report the new worldstate (new resource is available) to the blackboard
                        BlackBoard.Instance.SetCurrentWorldstate(agentComponent.GetClan(), newState);
                    }

                    //update the score for the clan
                    BlackBoard.Instance.UpdateScore(clan, facts[1] + " " + facts[2]);

                    //update the skill for the agent
                    agentComponent.SetSkillpoints("build");

                    Debug.Log("*" + facts[1] + facts[2] + "-IS-BUILT*");
                    BlackBoard.Instance.GetTaskTree(clan).RemoveNode(agentComponent);    //action is done so remove this node from the tasktree

                    BlackBoard.Instance.IncreasePopulationCap(clan);                     //increase the population cap for the clan

                    actionIsDone = true;
                }
            }
            yield return(null);
        }
    }
Exemplo n.º 9
0
 void Start()
 {
     walker         = (WalkSubsystem)gameObject.GetComponent("WalkSubsystem");
     moveToPosition = agentObject.transform.position;
     walker.StartWalking(moveToPosition);
 }
Exemplo n.º 10
0
 void Start()
 {
     walker = (WalkSubsystem)gameObject.GetComponent("WalkSubsystem");
     moveToPosition = agentObject.transform.position;
     walker.StartWalking(moveToPosition);
 }
Exemplo n.º 11
0
 void Start()
 {
     walker         = (WalkSubsystem)gameObject.GetComponent("WalkSubsystem");
     moveToPosition = new Vector3(30, 0, 30);
     walker.StartWalking(moveToPosition);
 }
Exemplo n.º 12
0
 void Start()
 {
     walker = (WalkSubsystem)gameObject.GetComponent("WalkSubsystem");
     moveToPosition = new Vector3(30, 0, 30);
     walker.StartWalking(moveToPosition);
 }
Exemplo n.º 13
0
    IEnumerator FindResource()
    {
        while (actionIsDone == false)
        {
            if (collected)                                                                                                                 //if the resource is collected
            {
                Vector3 housePosition = BlackBoard.Instance.GetTaskTree(clan).GetOwnedNode(agentComponent.GetAgentNumber()).GetPosition(); //get the position to deliver it to
                walker.StartWalking(housePosition);

                if (walker.hasArrived == true)                //has arived at building position
                {
                    Debug.Log("*DELIVERED-" + facts[1] + "*");

                    AudioSource.PlayClipAtPoint(getSounds[1], housePosition, 0.5f);                     //play sound for resource is delivered
                    BlackBoard.Instance.GetTaskTree(clan).RemoveNode(agentComponent);                   //remove owned node frmo taskTree

                    collected    = false;
                    actionIsDone = true;

                    agentComponent.SetSkillpoints("collect");                     //get better at collecting
                }
            }
            else               //its not collected, agent need to go get it at resource location
            {
                walker.StartWalking(moveToPosition);

                if (walker.hasArrived == true)
                {
                    //check if the resource is still att the position said in the blackboard
                    List <Collider> tempList       = ((ResourceSensor)agentObject.transform.FindChild("Sensors").FindChild("ResourceSensor").GetComponent("ResourceSensor")).colliderList;
                    bool            resourceIsHere = false;
                    foreach (Collider collider in tempList)
                    {
                        if (collider.gameObject.transform.position == moveToPosition)
                        {
                            resourceIsHere = true;
                        }
                    }


                    if (!resourceIsHere)                      //If resource is not here (no amount left) or if its empty (before it has been taken away)
                    {
                        Debug.Log("HÄR SKULLE DET VARA EN RESOURCE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
                        agentComponent.GetWMemory().RemoveFact(facts[1], new WorkingMemoryValue(moveToPosition));                         //remove it from the workingMemory

                        if (agentComponent.GetWMemory().GetFact(facts[1]).Count == 0)
                        {
                            //No resources of that color exist, so update the worldstate
                            WorldState newState = new WorldState();
                            newState.SetProperty(char.ToLower(facts[1][0]) + facts[1].Substring(1) + "ResourceIsAvailable", new WorldStateValue(false));

                            //Report the new worldstate to the blackboard
                            BlackBoard.Instance.SetCurrentWorldstate(agentComponent.GetClan(), newState);

                            //Create a new plan with the new information
                            WorldState tempState = new WorldState();
                            tempState.SetProperty(char.ToLower(facts[1][0]) + facts[1].Substring(1) + "ResourceIsAvailable", new WorldStateValue(true));
                            agentComponent.CreateNewPlan((WorldState)BlackBoard.Instance.GetFact(agentComponent.GetClan(), "currentWorldState")[0].GetFactValue(), tempState);
                        }
                        else
                        {
                            //There are more resources, choose one of them
                            //TODO: choose the nearest source to go to
                            moveToPosition = (Vector3)agentComponent.GetWMemory().GetFact(facts[1])[0].GetFactValue();
                        }
                    }
                    else                                                                                              //harvesting resource
                    {
                        AudioSource.PlayClipAtPoint(getSounds[0], moveToPosition, 0.75f);                             //play harvesting sound

                        yield return(new WaitForSeconds((100 - agentComponent.GetSkill("collectSkillpoints")) / 20)); //wait a time to harvest depending on the skill

                        Debug.Log("*GOT-" + facts[1] + "*");
                        collected = true;
                    }
                }
            }

            yield return(null);
        }
    }
Exemplo n.º 14
0
    IEnumerator FindResource()
    {
        while (actionIsDone == false)
        {
            if (collected)
            {
                Vector3 housePosition = BlackBoard.Instance.GetTaskTree(clan).GetOwnedNode(agentComponent.getAgentNumber()).GetPosition();
                Debug.Log("!!!!!!!!!!!!!!!!!!!!!!!!!!! Ska lämna vid " + housePosition);
                walker.StartWalking(housePosition);

                if (walker.hasArrived == true)
                {
                    Debug.Log("*DELIVERED-" + facts[1] + "*");

                    AudioSource.PlayClipAtPoint(getSounds[1], housePosition, 0.5f);
                    BlackBoard.Instance.GetTaskTree(clan).RemoveNode(agentComponent);

                    collected    = false;
                    actionIsDone = true;

                    agentComponent.SetSkillpoints("collect");
                    agentComponent.RemoveEnergy();
                }
            }
            else
            {
                walker.StartWalking(moveToPosition);

                if (walker.hasArrived == true)
                {
                    List <Collider> tempList       = ((ResourceSensor)agentObject.transform.FindChild("Sensors").FindChild("ResourceSensor").GetComponent("ResourceSensor")).colliderList;
                    bool            resourceIsHere = false;
                    foreach (Collider collider in tempList)
                    {
                        if (collider.gameObject.transform.position == moveToPosition)
                        {
                            resourceIsHere = true;
                        }
                    }

                    if (!resourceIsHere)
                    {
                        Debug.Log("HÄR SKULLE DET VARA EN RESOURCE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
                        agentComponent.GetWMemory().RemoveFact(facts[1], new WorkingMemoryValue(moveToPosition));

                        if (agentComponent.GetWMemory().GetFact(facts[1]).Count == 0)
                        {
                            //No resources of that color exist, so update the worldstate
                            WorldState newState = new WorldState();
                            newState.setProperty(char.ToLower(facts[1][0]) + facts[1].Substring(1) + "ResourceIsAvailable", new WorldStateValue(false));

                            //Report the new worldstate to the blackboard
                            BlackBoard.Instance.SetCurrentWorldstate(agentComponent.GetClan(), newState);

                            //Create a new plan with the new information
                            WorldState tempState = new WorldState();
                            tempState.setProperty(char.ToLower(facts[1][0]) + facts[1].Substring(1) + "ResourceIsAvailable", new WorldStateValue(true));
                            agentComponent.CreateNewPlan((WorldState)BlackBoard.Instance.GetFact(agentComponent.GetClan(), "currentWorldState")[0].GetFactValue(), tempState);
                        }
                        else
                        {
                            //There are more resources, choose one of them
                            //TODO: choose the nearest source to go to
                            moveToPosition = (Vector3)agentComponent.GetWMemory().GetFact(facts[1])[0].GetFactValue();
                        }
                    }
                    else
                    {
                        AudioSource.PlayClipAtPoint(getSounds[0], moveToPosition, 0.75f);
                        yield return(new WaitForSeconds((100 - agentComponent.GetSkill("collectSkillpoints")) / 20));

                        Debug.Log("*GOT-" + facts[1] + "*");


                        foreach (Transform resourceItem in GameObject.Find("Resources").transform)                        //TODO: Use sensor instead of loop?
                        {
                            if (resourceItem.position == moveToPosition)
                            {
                                //TODO: Implement collectskill instead of 1, check if available resources is takeable (amount left is more or equal to what the agent wants?)
                                ((ResourceObject)resourceItem.GetComponent("ResourceObject")).UpdateResource(clan, 1 /* *collectSkill */);
                            }
                        }
                        collected = true;
                    }
                }
            }
            yield return(null);
        }
    }
Exemplo n.º 15
0
    IEnumerator Build()
    {
        while (actionIsDone == false)
        {
            walker.StartWalking(moveToPosition);

            if (walker.hasArrived == true)
            {
                bool         assistersAreNearby = false;
                bool         temp      = false;
                List <Agent> assisters = BlackBoard.Instance.GetTaskTree(clan).GetOwnedNode(agentComponent.getAgentNumber()).GetAssisters();
                foreach (Agent assister in assisters)
                {
                    if (Vector3.Distance(moveToPosition, assister.transform.position) >= 3.0f)
                    {
                        temp = true;
                    }
                }

                if (temp == false)
                {
                    assistersAreNearby = true;
                }

                if (assistersAreNearby)               //all helpers are nearby
                {
                    GameObject[] tiles = GameObject.FindGameObjectsWithTag("wireframe");

                    foreach (GameObject tile in tiles)
                    {
                        if (tile.transform.position == moveToPosition)
                        {
                            Destroy(tile);
                        }
                    }

                    Building building = (Building)Instantiate(Resources.Load(("Prefabs/Building"), typeof(Building)));

                    if (facts[2] != "Floor")                   //Build house
                    {
                        building.transform.position      = moveToPosition;
                        building.transform.parent        = GameObject.Find(clan).transform.FindChild("Buildings");
                        building.renderer.material.color = BlackBoard.Instance.GetColorForObject(facts[1]);
                        building.tag  = facts[1] + facts[2];
                        building.name = facts[1] + facts[2];

                        AstarPath.active.UpdateGraphs(building.collider.bounds);


                        //if a factory was built add new resource location
                        if (facts[1] == "Green" || facts[1] == "Orange" || facts[1] == "Magenta")
                        {
                            //TODO: ta bort denna och hämta information ifrån buildings sen i get-subsystem
                            agentComponent.GetWMemory().SetFact(facts[1], new WorkingMemoryValue(building.transform.position));
                        }

                        BlackBoard.Instance.UpdateScore(clan, facts[1] + " " + facts[2]);
                    }
                    else                         //adding a floor to an excisting house

                    {
                        foreach (Transform buildingItem in GameObject.Find(clan).transform.FindChild("Buildings"))
                        {
                            Debug.Log("88888888888888888 " + buildingItem.position + " == " + moveToPosition);



                            if (buildingItem.position == moveToPosition)
                            {
                                int numberFloors = buildingItem.childCount + 1;
                                building.transform.position      = moveToPosition + new Vector3(0, 1.0f, 0) * numberFloors;
                                building.transform.parent        = buildingItem;
                                building.renderer.material.color = BlackBoard.Instance.GetColorForObject(facts[1]);
                                building.tag  = "HouseFloor";
                                building.name = facts[1] + "Floor";
                            }
                        }
                    }


                    agentComponent.SetSkillpoints("build");
                    agentComponent.RemoveEnergy();

                    Debug.Log("*" + facts[1] + facts[2] + "-IS-BUILT*");
                    BlackBoard.Instance.GetTaskTree(clan).RemoveNode(agentComponent);

                    buildingSounds = (AudioClip)Resources.Load("SFX/industry005");
                    AudioSource.PlayClipAtPoint(buildingSounds, building.transform.position, 0.5f);

                    BlackBoard.Instance.IncreasePopulationCap(clan);

                    actionIsDone = true;
                }
            }
            yield return(null);
        }
    }