Beispiel #1
0
        //Creates a firetruck at the firehouse with
        //the tile at the given point as destination
        public void SpawnFireTruck(int x, int z)
        {
            truckCount++;

            Vector2 fireHouseTilePos;

            _map.Map.GetFireHouseCoordinates(out fireHouseTilePos);

            Vector3 truckPos = _map.GetPositionForTile(Mathf.FloorToInt(fireHouseTilePos.x),
                                                       Mathf.FloorToInt(fireHouseTilePos.y));

            truckPos.x += .5f;
            truckPos.z -= .5f;

            GameObject truck = (GameObject)Instantiate(firetruckPrefab);

            truck.transform.position = truckPos;

            EGFiretruck firetruck = truck.GetComponent <EGFiretruck>();

            firetruck.SetPosition(truckPos);
            firetruck.SetMap(_map);

            EGDispatcher.Instance.SendTruckToTile(firetruck, x, -z);
        }
Beispiel #2
0
        public void SetSelectedTruck(EGFiretruck selected)
        {
            if (selectedTruck != null)
            {
                selectedTruck.SetSelected(false);
            }

            selectedTruck = selected;
            selectedTruck.SetSelected(true);
        }
Beispiel #3
0
 void OnTriggerExit(Collider other)
 {
     if (!transform.parent.Equals(other.transform.parent) &&
         other.gameObject.tag.Equals("Truck"))
     {
         EGFiretruck otherTruck = other.transform.root.gameObject.GetComponent <EGFiretruck>();
         if (otherTruck != null)
         {
             truck.removeOtherTruck(other.transform.root.gameObject);
         }
     }
 }
Beispiel #4
0
        public void SendTruckToTile(EGFiretruck truckToSend, int x, int y)
        {
            TDPath truckPath = new TDPath();
            TDMap  dataMap   = _map.Map;

            truckPath.BuildPath(dataMap,
                                dataMap.GetTile(Mathf.FloorToInt(truckToSend.GetPosition().x), Mathf.FloorToInt(-truckToSend.GetPosition().z)),
                                dataMap.GetTile(x, y));
            truckToSend.SetPath(truckPath);
            truckToSend.SetIdle(false);

            _dispatcher.AddActiveTruck(truckToSend);
        }
Beispiel #5
0
 void OnTriggerStay(Collider other)
 {
     if (!transform.parent.Equals(other.transform.parent) &&
         other.gameObject.tag.Equals("Truck"))
     {
         EGFiretruck otherTruck   = other.transform.root.gameObject.GetComponent <EGFiretruck>();
         Vector3     closestPoint = other.ClosestPointOnBounds(truck.GetPosition());
         if (otherTruck != null)
         {
             truck.addOtherTruck(other.transform.root.gameObject, closestPoint);
         }
     }
 }
Beispiel #6
0
        // Update is called once per frame
        void Update()
        {
            //Sort through trucks so that they are kept in the right sets, active and idle
            List <EGFiretruck> toMoveToIdle = new List <EGFiretruck> ();

            for (int i = 0; i < _dispatcher.GetActiveTrucks().Count; i++)
            {
                EGFiretruck truck = _dispatcher.GetActiveTruckAtIndex(i);

                if (!truck.IsActive() && !truck.IsPuttingOutFire())
                {
                    //Don't remove them while iterating, remove afterwards
                    toMoveToIdle.Add(truck);
                }
            }

            //Set the trucks that need setting
            for (int i = 0; i < toMoveToIdle.Count; i++)
            {
                EGFiretruck truck = toMoveToIdle[i];
                SetTruckIdle(truck);
            }

            //Identify trucks that need to be removed
            List <EGFiretruck> toDestroy = new List <EGFiretruck> ();

            for (int i = 0; i < _dispatcher.GetIdleTrucks().Count; i++)
            {
                EGFiretruck truck = _dispatcher.GetIdleTruckAtIndex(i);

                TDTile truckTile = _map.GetTileForWorldPosition(truck.transform.position);
                //Trucks that are idle at the firehouse need to be removed
                if (truckTile.type == TDTile.Type.FIREHOUSE)
                {
                    toDestroy.Add(truck);
                }
            }

            //Remove trucks that need to be removed
            for (int i = 0; i < toDestroy.Count; i++)
            {
                EGFiretruck truck = toDestroy[i];
                _dispatcher.RemoveIdleTruck(truck);
                _firehouse.DecreaseTruckCount();
                Destroy(truck.gameObject);
            }
        }
Beispiel #7
0
        public void SendIdleToPosition(int x, int z)
        {
            EGFiretruck truckToSend = null;

            if (selectedTruck != null)
            {
                truckToSend = selectedTruck;
                _dispatcher.RemoveIdleTruck(truckToSend);
                selectedTruck.SetSelected(false);
                selectedTruck = null;
            }
            else if (_dispatcher.GetIdleTrucks().Count > 0)
            {
                truckToSend = _dispatcher.GetClosestIdleTruck(new Vector3(x, 0, z));
            }

            if (truckToSend != null)
            {
                SendTruckToTile(truckToSend, x, -z);
            }
        }
Beispiel #8
0
        public void SetTruckIdle(EGFiretruck truck)
        {
            if (truck != null)
            {
                _dispatcher.RemoveActiveTruck(truck);
                _dispatcher.AddIdleTruck(truck);

                if (truck.returnWhenIdle)
                {
                    Vector2 fireHouseTilePos = new Vector2();
                    _map.Map.GetFireHouseCoordinates(out fireHouseTilePos);

                    TDTile start           = _map.GetTileForWorldPosition(truck.transform.position);
                    TDTile end             = _map.Map.GetTile(Mathf.FloorToInt(fireHouseTilePos.x), Mathf.FloorToInt(fireHouseTilePos.y));
                    TDPath pathToFirehouse = new TDPath();
                    pathToFirehouse.BuildPath(_map.Map, start, end);

                    truck.SetPath(pathToFirehouse);
                }

                truck.SetIdle(true);
            }
        }
Beispiel #9
0
 void Start()
 {
     truck = truckObject.GetComponent <EGFiretruck> ();
 }