示例#1
0
    // might not need this if a generic BuildingPassenger is impossible
    public override Building CreateBuilding()
    {
        BuildingPassenger building = (BuildingPassenger)base.CreateBuilding();

        building.SetupNodes();

        return(building);
    }
示例#2
0
    /*
     * public void AssignWorkBuilding(BuildingEmployee building_employee)
     * {
     *      work_building = building_employee;
     *
     *      finalDestination = new Vector2(work_building.GetWorkDestination (this).x, work_building.GetWorkDestination (this).z);
     *      steering.Visit (finalDestination);
     *
     *      state = STATE_MOVING_TO_WORK;
     * }*/

    public void AssignWorkBuilding(BuildingPassenger building_employee)
    {
        building  = building_employee;
        behaviour = building.VisitBuilding(this);

        finalDestination = behaviour.GetEntrancePosition();
        steering.Visit(finalDestination);

        state = STATE_MOVING_TO_WORK;
    }
示例#3
0
    /*
    public void AssignWorkBuilding(BuildingEmployee building_employee)
    {
        work_building = building_employee;

        finalDestination = new Vector2(work_building.GetWorkDestination (this).x, work_building.GetWorkDestination (this).z);
        steering.Visit (finalDestination);

        state = STATE_MOVING_TO_WORK;
    }*/
    public void AssignWorkBuilding(BuildingPassenger building_employee)
    {
        building = building_employee;
        behaviour = building.VisitBuilding(this);

        finalDestination = behaviour.GetEntrancePosition();
        steering.Visit(finalDestination);

        state = STATE_MOVING_TO_WORK;
    }
    public PassengerBehaviour(BuildingPassenger _building, Person _person, 
							   string[] behaviourArray)
    {
        behaviours = behaviourArray;
        building = _building;
        currentBehaviour = 0;
        person = _person;

        if (person is Employee) {
            employee = true;
            behaviours = new string[] {	"visit employee",
                                        "work",
                                        "exit" };
        }
    }
    public PassengerBehaviour(BuildingPassenger _building, Person _person,
                              string[] behaviourArray)
    {
        behaviours       = behaviourArray;
        building         = _building;
        currentBehaviour = 0;
        person           = _person;

        if (person is Employee)
        {
            employee   = true;
            behaviours = new string[] { "visit employee",
                                        "work",
                                        "exit" };
        }
    }
示例#6
0
    bool VisitPassengerBuilding(string type_name, int start_state, int new_exit_state)
    {
        visitBuilding = BuildingList.GetPassengerBuilding(this, type_name);

        if (visitBuilding == null)
        {
            return(false);
        }
        else
        {
            //finalDestination = visitBuilding.GetEnterQueuePosition(); DISABLED FOR PASSENGER BUILDING
            steering.Visit(finalDestination);
            state_passenger_building = start_state;
            exit_state = new_exit_state;

            // don't forget to remove eventual message
            speechBubbleController.RemoveMessageImmediate(this);

            return(true);
        }
    }
示例#7
0
    bool VisitBuilding(string type_name, int _exit_state)
    {
        // get building
        buildingPassenger = (BuildingPassenger)BuildingList.GetPassengerBuilding(this, type_name);

        if (buildingPassenger == null)
        {
            print("could not find building)");
            return(false);
        }
        else
        {
            behaviour        = buildingPassenger.VisitBuilding(this);
            finalDestination = behaviour.GetEntrancePosition();
            steering.Visit(finalDestination);
            state_passenger   = STATE_BUILDING_GOTO;
            buildingExitState = _exit_state;

            // don't forget to remove eventual message
            speechBubbleController.RemoveMessageImmediate(this);
            return(true);
        }
    }
示例#8
0
    bool VisitPassengerBuilding(string type_name, int start_state, int new_exit_state)
    {
        visitBuilding = BuildingList.GetPassengerBuilding (this, type_name);

        if (visitBuilding == null) {
            return false;
        } else {
            //finalDestination = visitBuilding.GetEnterQueuePosition(); DISABLED FOR PASSENGER BUILDING
            steering.Visit(finalDestination);
            state_passenger_building = start_state;
            exit_state = new_exit_state;

            // don't forget to remove eventual message
            speechBubbleController.RemoveMessageImmediate(this);

            return true;
        }
    }
示例#9
0
    void VisitGateUpdate()
    {
        // if the boarding process has started, skip ahead past benches
        if (startedBoardingInterrupt && (state_passenger_building != STATE_GATE_GOTO_ENTER &&
                   state_passenger_building != STATE_GATE_GOTO_SEAT &&
                   state_passenger_building != STATE_GATE_SEAT_ROTATE)) {

            // if already entering benches, wait to get to seating part
            if (state_passenger_building == STATE_GATE_SEAT) {
                StartBoarding();
            } else {
                state_passenger_building = STATE_GATE_GOTO_QUEUE;
                finalDestination = new Vector2(this.transform.position.x, this.transform.position.z);
            }
            startedBoardingInterrupt = false;
        }

        if (state_passenger_building == STATE_GATE_GOTO) {
            finalDestination = gate.GetEnterBenchesPosition();
            steering.Visit(finalDestination);
            state_passenger_building = STATE_GATE_GOTO_ENTER;
        } else if (state_passenger_building == STATE_GATE_GOTO_ENTER) {
            if (HasArrived(GridHelper.GetGridCellSize() / 5)) {
                bench = gate.AddToBench(this);
                if (bench != null) {
                    Vector2[] exitPath = bench.GetBenchEnterPath(this);
                    steering.Visit(exitPath);
                    finalDestination = exitPath[0];
                    state_passenger_building = STATE_GATE_GOTO_SEAT;
                }
            }
        } else if (state_passenger_building == STATE_GATE_GOTO_SEAT) {
            if (HasArrived(GridHelper.GetGridCellSize() / 10f)) {
                steering.FullStop ();
                finalDestination = new Vector2 (99999f, 99999f);
                state_passenger_building = STATE_GATE_SEAT_ROTATE;
            }
        } else if (state_passenger_building == STATE_GATE_SEAT_ROTATE) {
             iTween.RotateTo(gameObject,iTween.Hash(
             	"rotation", bench.GetSeatRotation(this),
             	"easetype", iTween.EaseType.easeInOutQuad,
             	"time",1.0f));
            state_passenger_building = STATE_GATE_SEAT;
        } else if (state_passenger_building == STATE_GATE_SEAT) {
         		// on seat, waiting for boarding
         	} else if (state_passenger_building == STATE_GATE_GOTO_QUEUE) {
         		if (HasArrived(GridHelper.GetGridCellSize())) {
         			// go to enter queue position
         			//finalDestination = gate.GetEnterQueuePosition(); DISABLED FOR PASSENGER BUILDING
                steering.Seek(finalDestination);

         			state_passenger_building = STATE_GATE_GOTO_QUEUE_ENTER;
         		}
         	} else if (state_passenger_building == STATE_GATE_GOTO_QUEUE_ENTER) {

         		hasArrivedCounter++;

         		if (hasArrivedCounter > 200) {
         			print("stuck on has arrived (" + GetID() + ")");
         			print("this position = " + this.position + " | targetPos = " + targetPos + " | finalDestination = " + finalDestination);
         			finalDestination = this.position;
         		}

         		if (HasArrived(GridHelper.GetGridCellSize())) {
         			//print("has arrived");
                // send back to visitPassengerUpdate() because that will do the whole queue thing (except for exit path?)
         			visitBuilding = gate;
         			exit_state = STATE_GATE_EXIT;

         			//finalDestination = visitBuilding.EnterQueueAndGetPosition(this); DISABLED FOR PASSENGER BUILDING
                steering.Arrive(finalDestination);

                state_passenger_building = STATE_PASSENGER_BUILDING_QUEUE_ENTER;
                state = STATE_GATE_BOARDING_QUEUE;
         		}

         	}
    }
示例#10
0
    bool VisitBuilding(string type_name, int _exit_state)
    {
        // get building
        buildingPassenger = (BuildingPassenger) BuildingList.GetPassengerBuilding (this, type_name);

        if (buildingPassenger == null) {
            print("could not find building)");
            return false;
        } else  {
            behaviour = buildingPassenger.VisitBuilding(this);
            finalDestination = behaviour.GetEntrancePosition();
            steering.Visit(finalDestination);
            state_passenger = STATE_BUILDING_GOTO;
            buildingExitState = _exit_state;

            // don't forget to remove eventual message
            speechBubbleController.RemoveMessageImmediate(this);
            return true;
        }
    }
示例#11
0
    void VisitGateUpdate()
    {
        // if the boarding process has started, skip ahead past benches
        if (startedBoardingInterrupt && (state_passenger_building != STATE_GATE_GOTO_ENTER &&
                                         state_passenger_building != STATE_GATE_GOTO_SEAT &&
                                         state_passenger_building != STATE_GATE_SEAT_ROTATE))
        {
            // if already entering benches, wait to get to seating part
            if (state_passenger_building == STATE_GATE_SEAT)
            {
                StartBoarding();
            }
            else
            {
                state_passenger_building = STATE_GATE_GOTO_QUEUE;
                finalDestination         = new Vector2(this.transform.position.x, this.transform.position.z);
            }
            startedBoardingInterrupt = false;
        }

        if (state_passenger_building == STATE_GATE_GOTO)
        {
            finalDestination = gate.GetEnterBenchesPosition();
            steering.Visit(finalDestination);
            state_passenger_building = STATE_GATE_GOTO_ENTER;
        }
        else if (state_passenger_building == STATE_GATE_GOTO_ENTER)
        {
            if (HasArrived(GridHelper.GetGridCellSize() / 5))
            {
                bench = gate.AddToBench(this);
                if (bench != null)
                {
                    Vector2[] exitPath = bench.GetBenchEnterPath(this);
                    steering.Visit(exitPath);
                    finalDestination         = exitPath[0];
                    state_passenger_building = STATE_GATE_GOTO_SEAT;
                }
            }
        }
        else if (state_passenger_building == STATE_GATE_GOTO_SEAT)
        {
            if (HasArrived(GridHelper.GetGridCellSize() / 10f))
            {
                steering.FullStop();
                finalDestination         = new Vector2(99999f, 99999f);
                state_passenger_building = STATE_GATE_SEAT_ROTATE;
            }
        }
        else if (state_passenger_building == STATE_GATE_SEAT_ROTATE)
        {
            iTween.RotateTo(gameObject, iTween.Hash(
                                "rotation", bench.GetSeatRotation(this),
                                "easetype", iTween.EaseType.easeInOutQuad,
                                "time", 1.0f));
            state_passenger_building = STATE_GATE_SEAT;
        }
        else if (state_passenger_building == STATE_GATE_SEAT)
        {
            // on seat, waiting for boarding
        }
        else if (state_passenger_building == STATE_GATE_GOTO_QUEUE)
        {
            if (HasArrived(GridHelper.GetGridCellSize()))
            {
                // go to enter queue position
                //finalDestination = gate.GetEnterQueuePosition(); DISABLED FOR PASSENGER BUILDING
                steering.Seek(finalDestination);

                state_passenger_building = STATE_GATE_GOTO_QUEUE_ENTER;
            }
        }
        else if (state_passenger_building == STATE_GATE_GOTO_QUEUE_ENTER)
        {
            hasArrivedCounter++;

            if (hasArrivedCounter > 200)
            {
                print("stuck on has arrived (" + GetID() + ")");
                print("this position = " + this.position + " | targetPos = " + targetPos + " | finalDestination = " + finalDestination);
                finalDestination = this.position;
            }

            if (HasArrived(GridHelper.GetGridCellSize()))
            {
                //print("has arrived");
                // send back to visitPassengerUpdate() because that will do the whole queue thing (except for exit path?)
                visitBuilding = gate;
                exit_state    = STATE_GATE_EXIT;

                //finalDestination = visitBuilding.EnterQueueAndGetPosition(this); DISABLED FOR PASSENGER BUILDING
                steering.Arrive(finalDestination);

                state_passenger_building = STATE_PASSENGER_BUILDING_QUEUE_ENTER;
                state = STATE_GATE_BOARDING_QUEUE;
            }
        }
    }
    /*
     * Return building of type that is closest to person
     * 1) look for all buildings in search treshold (between min and max)
     *      a) if multiple buildings, find one with shortest queue size
     *      b) if one building, return that building
     *      c) if no buildings, multiply search treshold by 5 and search again
     *
     */
    public static BuildingPassenger GetPassengerBuilding(Person person, string type_name)
    {
        // parameters
        float searchTresholdMax  = GridHelper.GetGridCellSize() * 50f;
        float searchTresholdMin  = 0;
        float tresholdMultiplier = 5;

        List <BuildingPassenger> buildingEmployeeList = GetEmployeeBuildingsOfType(type_name);
        List <BuildingPassenger> queueCompareList     = new List <BuildingPassenger> ();

        //Debug.Log ("Found " + buildingEmployeeList.Count + " buildings of type " + type_name);

        for (int i = 1; i <= 3; i++)           // 3 treshold search stages
        // loop through all biuldings
        {
            foreach (BuildingPassenger loop_building in buildingEmployeeList)
            {
                // add if within min and max search treshold
                if (Vector2.Distance(loop_building.GetWorldPosition2(), person.position) < searchTresholdMax &&
                    Vector2.Distance(loop_building.GetWorldPosition2(), person.position) >= searchTresholdMin)
                {
                    // also make sure there is space
                    if (loop_building.PassengerPriority() >= 0)
                    {
                        queueCompareList.Add(loop_building);
                    }
                }
            }

            //Debug.Log("loop = " + i + " found " + queueCompareList.Count + " buildings");

            if (queueCompareList.Count == 0)
            {
                searchTresholdMin = searchTresholdMax;
                searchTresholdMax = searchTresholdMax * tresholdMultiplier;
            }
            else if (queueCompareList.Count == 1)
            {
                return(queueCompareList[0]);
            }
            else if (queueCompareList.Count > 1)
            {
                // loop through buildings to find shortest queue
                BuildingPassenger shortestQueueBuilding = queueCompareList[0];
                foreach (BuildingPassenger loop_building in buildingEmployeeList)
                {
                    // WRITE DEBUG HERE
                    if (loop_building.PassengerPriority() > shortestQueueBuilding.PassengerPriority())
                    {
                        shortestQueueBuilding = loop_building;
                    }

                    /*
                     * if (loop_building.GetQueueSize() < shortestQueueBuilding.GetQueueSize()) {
                     *      shortestQueueBuilding = loop_building;
                     * }*/
                }
                return(shortestQueueBuilding);
            }
            else
            {
                Debug.Log("something went horribly wrong");
            }
        }

        return(null);
    }
    /*
     * void ManageEmployees()
     * {
     *      // first find any buildings that may need employees
     *      //List<BuildingEmployee> buildingList = airport.GetAllEmployeeBuildings ();
     *
     *      Employee employee = GetFreeEmployee();
     *
     *      if (employee == null) // if there is no free employees, return
     *              return;
     *
     *      List<BuildingEmployee> needEmployeeBuildingList = new List<BuildingEmployee> ();
     *
     *      foreach (BuildingEmployee building_employee in airport.GetAllEmployeeBuildings ()) {
     *              if (building_employee.NeedsEmployees() > 0) {
     *                      needEmployeeBuildingList.Add (building_employee);
     *              }
     *      }
     *
     *      if (needEmployeeBuildingList.Count == 0) // if there are no buildings that need employees, return
     *              return;
     *
     *      // now find building that is closest
     *      float lowestDistance = 99999f;
     *      BuildingEmployee lowestDistanceBuilding = null;;
     *
     *      foreach (BuildingEmployee building_employee in needEmployeeBuildingList) {
     *              if (Vector3.Distance (building_employee.transform.position, employee.transform.position) < lowestDistance) {
     *                      lowestDistance = Vector3.Distance (building_employee.transform.position, employee.transform.position);
     *                      lowestDistanceBuilding = building_employee;
     *              }
     *      }
     *
     *      lowestDistanceBuilding.AssignEmployee(employee);
     *      employee.AssignWorkBuilding(lowestDistanceBuilding);
     *      print ("Assigned employee to building");
     *
     * }*/


    void ManageEmployeesNew()
    {
        // first find any buildings that may need employees
        //List<BuildingEmployee> buildingList = airport.GetAllEmployeeBuildings ();

        Employee employee = GetFreeEmployee();

        if (employee == null)         // if there is no free employees, return
        {
            return;
        }

        List <BuildingPassenger> needEmployeeBuildingList = new List <BuildingPassenger> ();
        BuildingPassenger        highestPriorityBuilding  = null;
        int highestPriority = 0;

        foreach (BuildingPassenger building in airport.GetAllPassengerBuildings())
        {
            if (building.EmployeePriority() > 0)
            {
                needEmployeeBuildingList.Add(building);
            }

            if (building.EmployeePriority() > highestPriority)
            {
                highestPriority         = building.EmployeePriority();
                highestPriorityBuilding = building;

                // if there is a building with same priority as current highest,
                //there is not just one with highest priority, so search for closest
            }
            else if (building.EmployeePriority() == highestPriority)
            {
                highestPriorityBuilding = null;
            }
        }

        if (needEmployeeBuildingList.Count == 0)         // if there are no buildings that need employees, return
        {
            return;
        }
        else if (highestPriorityBuilding != null)           // if there is only one building
        {
            highestPriorityBuilding.AssignEmployee(employee);
            employee.AssignWorkBuilding(highestPriorityBuilding);
            print("Assigned employee to building");
        }
        else
        {
            // there are multiple buildings
            // now find building that is closest
            float             lowestDistance         = 99999f;
            BuildingPassenger lowestDistanceBuilding = null;;

            foreach (BuildingPassenger building in needEmployeeBuildingList)
            {
                if (Vector3.Distance(building.transform.position, employee.transform.position) < lowestDistance)
                {
                    lowestDistance         = Vector3.Distance(building.transform.position, employee.transform.position);
                    lowestDistanceBuilding = building;
                }
            }

            lowestDistanceBuilding.AssignEmployee(employee);
            employee.AssignWorkBuilding(lowestDistanceBuilding);
            print("Assigned employee to building");
        }
    }