Esempio n. 1
0
    /* Types - Altruism, Behavioural-Inaction, Panic, Fear-Flight
     * Also set colour according to the behaviour type
     */
    public void setType(RAINAgent ai)
    {
        if (ai != null)
        {
            int random = monteCarlo();

            if (random < 20)
            {
                ai.Agent.actionContext.SetContextItem <string>("type", "altruism");
                type = "altruism";
                this.gameObject.transform.Find("Sphere").renderer.material.color = Color.green;
            }
            else if (random < 45)
            {
                type = "behaviouralinaction";
                ai.Agent.actionContext.SetContextItem <string>("type", "behaviouralinaction");
                this.gameObject.transform.Find("Sphere").renderer.material.color = Color.yellow;
            }
            else if (random < 50)
            {
                type = "panic";
                ai.Agent.actionContext.SetContextItem <string>("type", "panic");
                this.gameObject.transform.Find("Sphere").renderer.material.color = Color.red;
            }
            else
            {
                type = "fearflight";
                ai.Agent.actionContext.SetContextItem <string>("type", "fearflight");
                this.gameObject.transform.Find("Sphere").renderer.material.color = Color.gray;
            }
        }
    }
Esempio n. 2
0
 //set behaviours manually, including colour and variable in the action context
 public void setTypeManual(RAINAgent ai)
 {
     if (ai != null)
     {
         if (type == "altruism")
         {
             ai.Agent.actionContext.SetContextItem <string>("type", "altruism");
             this.gameObject.transform.Find("Sphere").renderer.material.color = Color.green;
         }
         else if (type == "behaviouralinaction")
         {
             ai.Agent.actionContext.SetContextItem <string>("type", "behaviouralinaction");
             this.gameObject.transform.Find("Sphere").renderer.material.color = Color.yellow;
         }
         else if (type == "panic")
         {
             ai.Agent.actionContext.SetContextItem <string>("type", "panic");
             this.gameObject.transform.Find("Sphere").renderer.material.color = Color.red;
         }
         else
         {
             ai.Agent.actionContext.SetContextItem <string>("type", "fearflight");
             this.gameObject.transform.Find("Sphere").renderer.material.color = Color.gray;
         }
     }
 }
Esempio n. 3
0
    //when another game object collides with this one, trigger an action
    void OnTriggerEnter(Collider other)
    {
        RAINAgent ai      = GetComponent <RAINAgent>();
        RAINAgent otherAI = other.gameObject.GetComponent <RAINAgent>();

        //check if this passenger is already running a coroutine
        runningCoroutine = ai.Agent.actionContext.GetContextItem <bool>("runningCoroutine");
        if (runningCoroutine)
        {
            return;
        }

        //if the other agent is not null, check if it is a passenger
        //if yes and a number smaller than 75 is generated, wait and give priority to other
        //passenger
        if (other.gameObject.name == "Passenger" && otherAI != null && i < limit)
        {
            int random = Random.Range(0, 100);

            if (random < 75)
            {
                StartCoroutine(Wait(ai));
                i++;
            }
        }
    }
Esempio n. 4
0
    // start the assignment of behaviours
    void StartBeh()
    {
        //get the agent
        RAINAgent ai = GetComponent <RAINAgent>();

        //assign type
        setType(ai);

        //set coroutine variable
        ai.Agent.actionContext.SetContextItem <bool>("runningCoroutine", false);


        //according to behaviour type, add script or start coroutines
        if (type == "panic")
        {
            StartCoroutine(Wait(ai));
            setPanicPosition(ai);
        }
        else if (type == "fearflight" || type == "behaviouralinaction")
        {
            StartCoroutine(Wait(ai));
        }
        else if (type == "altruism")
        {
            StartCoroutine(Wait(ai));
            this.gameObject.AddComponent("trigPass");
        }
    }
Esempio n. 5
0
    /* Types - Altruism, Behavioural-Inaction, Panic, Fear-Flight
     * Also set colour according to the behaviour type
     */
    public void setType(RAINAgent ai)
    {
        if (ai!=null){
            int random = monteCarlo();

            if (random < 20){
                ai.Agent.actionContext.SetContextItem<string>("type", "altruism");
                type = "altruism";
                this.gameObject.transform.Find("Sphere").renderer.material.color = Color.green;
            }
            else if (random < 45){
                type = "behaviouralinaction";
                ai.Agent.actionContext.SetContextItem<string>("type", "behaviouralinaction");
                this.gameObject.transform.Find("Sphere").renderer.material.color = Color.yellow;
            }
            else if (random < 50){
                type = "panic";
                ai.Agent.actionContext.SetContextItem<string>("type", "panic");
                this.gameObject.transform.Find("Sphere").renderer.material.color = Color.red;
            }
            else{
                type = "fearflight";
                ai.Agent.actionContext.SetContextItem<string>("type", "fearflight");
                this.gameObject.transform.Find("Sphere").renderer.material.color = Color.gray;
            }
        }
    }
Esempio n. 6
0
 /* create a random position for the panic passenger to move to before moving to its
  * closest door
  */
 public void setPanicPosition(RAINAgent ai)
 {
     Vector3 currPos = this.gameObject.transform.position;
     float z = Random.Range(currPos.z - 10, currPos.z + 10);
     Vector3 newPos = new Vector3((float)17, (float)8, z);
     ai.Agent.actionContext.SetContextItem<Vector3>("newpos", newPos);
 }
Esempio n. 7
0
 // Use this for initialization
 void Start()
 {
     ai = GetComponent <RAINAgent>();
     if (ai != null)
     {
         ai.Agent.actionContext.SetContextItem <float>(varName, level);
     }
 }
Esempio n. 8
0
    /* create a random position for the panic passenger to move to before moving to its
     * closest door
     */
    public void setPanicPosition(RAINAgent ai)
    {
        Vector3 currPos = this.gameObject.transform.position;
        float   z       = Random.Range(currPos.z - 10, currPos.z + 10);
        Vector3 newPos  = new Vector3((float)17, (float)8, z);

        ai.Agent.actionContext.SetContextItem <Vector3>("newpos", newPos);
    }
Esempio n. 9
0
    //method used for assigning behaviours in custom simulations
    void StartBehManual()
    {
        RAINAgent ai = GetComponent <RAINAgent>();

        setTypeManual(ai);

        if (type == "panic")
        {
            StartCoroutine(Wait(ai));
            setPanicPosition(ai);
        }
        else if (type == "fearflight" || type == "behaviouralinaction")
        {
            StartCoroutine(Wait(ai));
        }
        else if (type == "altruism")
        {
            this.gameObject.AddComponent("trigPass");
        }
    }
Esempio n. 10
0
    /* Make them wait at the start before evacuation begins */
    IEnumerator Wait(RAINAgent ai)
    {
        //set the value corresponding to coroutines to be true, so the passenger does not
        //enter another coroutine before exiting the present one
        ai.Agent.actionContext.SetContextItem <bool>("runningCoroutine", true);

        float x    = ai.maxSpeed;
        float mass = this.gameObject.rigidbody.mass;
        int   time = 0;

        //modify waiting times and masses according to behaviour type
        if (type == "panic")
        {
            time = Random.Range(5, 10);
            this.gameObject.rigidbody.mass = 30;
        }
        else if (type == "fearflight" || type == "altruism")
        {
            time = Random.Range(10, 15);
            this.gameObject.rigidbody.mass = 20;
        }
        else if (type == "behaviouralinaction")
        {
            time = Random.Range(15, 25);
            this.gameObject.rigidbody.mass = 50;
        }

        if (ai != null)
        {
            ai.maxSpeed = 0;
        }
        // suspend the execution of the coroutine for the specified amount of time
        yield return(new WaitForSeconds(time));

        //return speed and mass to original values
        ai.maxSpeed = x;
        this.gameObject.rigidbody.mass = mass;

        //register exit from coroutine
        ai.Agent.actionContext.SetContextItem <bool>("runningCoroutine", false);
    }
Esempio n. 11
0
 //set behaviours manually, including colour and variable in the action context
 public void setTypeManual(RAINAgent ai)
 {
     if (ai!=null){
         if (type == "altruism"){
             ai.Agent.actionContext.SetContextItem<string>("type", "altruism");
             this.gameObject.transform.Find("Sphere").renderer.material.color = Color.green;
         }
         else if (type == "behaviouralinaction"){
             ai.Agent.actionContext.SetContextItem<string>("type", "behaviouralinaction");
             this.gameObject.transform.Find("Sphere").renderer.material.color = Color.yellow;
         }
         else if (type == "panic"){
             ai.Agent.actionContext.SetContextItem<string>("type", "panic");
             this.gameObject.transform.Find("Sphere").renderer.material.color = Color.red;
         }
         else {
             ai.Agent.actionContext.SetContextItem<string>("type", "fearflight");
             this.gameObject.transform.Find("Sphere").renderer.material.color = Color.gray;
         }
     }
 }
Esempio n. 12
0
    //coroutine that makes the passenger wait
    IEnumerator Wait(RAINAgent ai)
    {
        ai.Agent.actionContext.SetContextItem<bool>("runningCoroutine", true);

        //remember the original speed and mass
        float x= ai.maxSpeed;
        float mass = this.gameObject.rigidbody.mass;
        int time = Random.Range(2, 8);

        //stop the passenger for time seconds
        if (ai != null){
            //print ("not null");
            ai.maxSpeed = 0;
            this.gameObject.rigidbody.mass = 50;
        }
        yield return new WaitForSeconds(time);

        //return original speed and mass
        ai.maxSpeed = x;
        this.gameObject.rigidbody.mass = mass;

        ai.Agent.actionContext.SetContextItem<bool>("runningCoroutine", false);
    }
Esempio n. 13
0
    //coroutine that makes the passenger wait
    IEnumerator Wait(RAINAgent ai)
    {
        ai.Agent.actionContext.SetContextItem <bool>("runningCoroutine", true);

        //remember the original speed and mass
        float x    = ai.maxSpeed;
        float mass = this.gameObject.rigidbody.mass;
        int   time = Random.Range(2, 8);

        //stop the passenger for time seconds
        if (ai != null)
        {
            //print ("not null");
            ai.maxSpeed = 0;
            this.gameObject.rigidbody.mass = 50;
        }
        yield return(new WaitForSeconds(time));

        //return original speed and mass
        ai.maxSpeed = x;
        this.gameObject.rigidbody.mass = mass;

        ai.Agent.actionContext.SetContextItem <bool>("runningCoroutine", false);
    }
Esempio n. 14
0
    public void calculateDoor()
    {
        //calculates closest door from the middle of the aisle
        Vector3 positionMiddle = new Vector3((float)17.56, transform.position.y, transform.position.z);

        //get the position of all the doors in the model
        GameObject plane = GameObject.FindGameObjectWithTag("plane");

        //get list of doors from script that allows adding and removing of doors
        doorScript = (getDoors)plane.GetComponent("getDoors");
        doorslist  = doorScript.doorslist;

        //calculate and assign an initial door
        float  minDistance = Vector3.Distance(transform.position, doorslist[0].transform.position);
        string doorName    = doorslist[0].name;

        targetPosition = doorslist[0].transform.position;


        string  doorName2       = null;
        Vector3 targetPosition2 = new Vector3(0, 0, 0);
        int     i = 1;

        //going through all the doors in the list, calculate which is closer
        while (i < doorslist.Count)
        {
            float distance  = Vector3.Distance(transform.position, doorslist[i].transform.position);
            float distance2 = Vector3.Distance(positionMiddle, doorslist[i].transform.position);
            //if distance is less than minimum distance, assign a new closest door
            if (distance < minDistance)
            {
                doorName       = doorslist[i].name;
                minDistance    = distance;
                targetPosition = doorslist[i].transform.position;
                //if the distance from the middle of the aisle is less than the one
                //calculated above, keep track of doorname and position
                if (distance2 < distance)
                {
                    doorName2       = doorslist[i].name;
                    targetPosition2 = doorslist[i].transform.position;
                }
            }
            i++;
        }

        RAINAgent ai = GetComponent <RAINAgent>();

        if (ai != null)
        {
            //generate a random number
            if (Random.Range(0, 100) < 50 && doorName2 != null)
            {
                //if number is  < 50 and there is a closer door, assign it to the passenger
                ai.Agent.actionContext.SetContextItem <Vector3>("door", targetPosition2);
                ai.Agent.actionContext.SetContextItem <string>("doorName", doorName2);
            }
            else
            {
                //add the initial door
                ai.Agent.actionContext.SetContextItem <Vector3>("door", targetPosition);
                ai.Agent.actionContext.SetContextItem <string>("doorName", doorName);
            }
            string type = ai.Agent.actionContext.GetContextItem <string>("type");

            //add trigger script to passenger if he is of type "altruism"
            if (type == "altruism")
            {
                Debug.Log("trigpass");
                this.gameObject.AddComponent("trigPass");
            }
        }
        else
        {
            print("null");
        }
    }
Esempio n. 15
0
    /* Make them wait at the start before evacuation begins */
    IEnumerator Wait(RAINAgent ai)
    {
        //set the value corresponding to coroutines to be true, so the passenger does not
        //enter another coroutine before exiting the present one
        ai.Agent.actionContext.SetContextItem<bool>("runningCoroutine", true);

        float x= ai.maxSpeed;
        float mass = this.gameObject.rigidbody.mass;
        int time = 0;

        //modify waiting times and masses according to behaviour type
        if (type == "panic"){
            time = Random.Range(5, 10);
            this.gameObject.rigidbody.mass = 30;
        }
        else if (type == "fearflight" || type == "altruism"){
            time = Random.Range(10, 15);
            this.gameObject.rigidbody.mass = 20;
        }
        else if (type == "behaviouralinaction"){
            time = Random.Range(15, 25);
            this.gameObject.rigidbody.mass = 50;
        }

        if (ai!=null){
            ai.maxSpeed = 0;
        }
        // suspend the execution of the coroutine for the specified amount of time
        yield return new WaitForSeconds(time);

        //return speed and mass to original values
        ai.maxSpeed = x;
        this.gameObject.rigidbody.mass=mass;

        //register exit from coroutine
        ai.Agent.actionContext.SetContextItem<bool>("runningCoroutine", false);
    }