Ejemplo n.º 1
0
 bool CarsTrapped()
 {
     if (nextTile != null && nextTile.Vehicle != null &&
         !World.Current.ParkingTiles.Contains(nextTile))
     {
         Vehicle v1 = nextTile.Vehicle;
         if (v1.nextTile != null && v1.nextTile.Vehicle != null)
         {
             Vehicle v2 = v1.nextTile.Vehicle;
             if (v2.nextTile != null && v2.nextTile.Vehicle != null)
             {
                 foreach (Tile t in World.Current.VehicleEndingTiles)
                 {
                     if (Direction == Direction.Left)
                     {
                         if (t.Y < Y)
                         {
                             destTile = t;
                         }
                     }
                 }
                 VehiclePath_AStar = null;
                 return(true);
             }
         }
     }
     return(false);
 }
Ejemplo n.º 2
0
    bool ReachedDestination()
    {
        if (currTile[0] == destTile)
        {
            //Vehicle has parked and just needs to wait until they leave
            if (World.Current.ParkingTiles.Contains(currTile[0]))
            {
                currTile[0].Vehicle = this;
                CreateAShopper();
                Parked = true;

                destTile = World.Current.GetTileAt(0, 2);
                UpdatePath();
                return(true);
            }
            //Means they've reached the entrace to car park and are waiting to park
            if (WantsToShop)
            {
                WantsToShop = false;
                TimeToWait  = 1f;
                Tile ParkingSpace = EmptyParkingSpace();
                if (ParkingSpace == null)
                {
                    foreach (Tile t in World.Current.VehicleEndingTiles)
                    {
                        if (Direction == Direction.Down)
                        {
                            if (t.Y < Y)
                            {
                                destTile = t;
                            }
                        }
                        else if (Direction == Direction.Up)
                        {
                            if (t.Y > Y)
                            {
                                destTile = t;
                            }
                        }
                    }
                    UpdatePath();
                    WantsToShop = false;
                    return(false);
                }
                destTile             = ParkingSpace;
                ParkingSpace.Vehicle = this;
                UpdatePath();
                return(true);
            }

            VehiclePath_AStar = null;
            RemoveVehicle();
            return(true);
        }
        return(false);
    }
Ejemplo n.º 3
0
 void LeaveWork()
 {
     currJob = new Job(World.Current.PedestrianExitTiles[0],
                       Words.Current.WalkingHome,
                       Words.Current.WalkingHome,
                       null,
                       0f);
     OnTill   = false;
     destTile = currJob.tile;
     currJob.RegisterJobCompleteCallback(OnJobCompleted);
     currJob.RegisterJobCancelCallback(OnJobCompleted);
     WalkingPath_AStar = new Path_ASTar(World.Current, CurrTile, destTile, false, false, Direction);
     if (WalkingPath_AStar.Length() == 0)
     {
         Debug.LogError("No route to dest");
         AbandonJob();
         destTile = currTile;
     }
 }
Ejemplo n.º 4
0
    public void StartShift()
    {
        OnShift  = true;
        CurrTile = World.Current.PedestrianExitTiles[0];

        int r = UnityEngine.Random.Range(0, World.Current.StockRoomTiles.Count);

        currJob = new Job(World.Current.StockRoomTiles[r],
                          Words.Current.WalkingToWork,
                          Words.Current.WalkingToWork,
                          null,
                          Numbers.Current.LoiterJobTime);
        destTile = currJob.tile;
        currJob.RegisterJobCompleteCallback(OnJobCompleted);
        currJob.RegisterJobCancelCallback(OnJobCompleted);

        WalkingPath_AStar = new Path_ASTar(World.Current, CurrTile, destTile, false, false, Direction);
        if (WalkingPath_AStar.Length() == 0)
        {
            Debug.LogError("No route to dest");
            AbandonJob();
            destTile = currTile;
        }
    }
Ejemplo n.º 5
0
 void UpdatePath()
 {
     if (nextTile == null || nextTile == currTile[0])
     {
         if (VehiclePath_AStar == null || VehiclePath_AStar.Length() == 0)
         {
             //Create a path
             VehiclePath_AStar = new Path_ASTar(World.Current, currTile[0], destTile, true, false, Direction);
             if (VehiclePath_AStar.Length() == 0)
             {
                 Debug.LogError("No route to destination");
                 VehiclePath_AStar = null;
                 return;
             }
             nextTile   = VehiclePath_AStar.Dequeue();
             secondTile = VehiclePath_AStar.Dequeue();
             thirdTile  = VehiclePath_AStar.Dequeue();
         }
         nextTile   = secondTile;
         secondTile = thirdTile;
         thirdTile  = VehiclePath_AStar.Dequeue();
         CheckDirection();
     }
 }
Ejemplo n.º 6
0
    void Update_DoMovement(float deltaTime)
    {
        if (currTile == destTile)
        {
            WalkingPath_AStar = null;
            return;
        }

        if (nextTile == null || nextTile == currTile)
        {
            if (WalkingPath_AStar == null || WalkingPath_AStar.Length() == 0)
            {
                WalkingPath_AStar = new Path_ASTar(World.Current, CurrTile, destTile, false, true, Direction);
                if (WalkingPath_AStar.Length() == 0)
                {
                    Debug.LogError("No path to dest");
                    return;
                }
                nextTile = WalkingPath_AStar.Dequeue();
            }
            nextTile = WalkingPath_AStar.Dequeue();
            CheckDirection();
        }


        if (nextTile != null && nextTile.IsEnterable(CurrTile) == Enterability.Never)
        {
            nextTile          = null;
            WalkingPath_AStar = null;
            return;
        }
        else if (nextTile != null && nextTile.IsEnterable(CurrTile) == Enterability.Soon)
        {
            if (!World.Current.ShopOpen)
            {
                //Shop is closed, I should see how long until it's open
                TimeSpan waitingTime = World.Current.Today.OpeningTime - WorldTime.Current.Date;
                if ((waitingTime.Days > 0 || waitingTime.Hours > 0 || waitingTime.Minutes > 15) &&
                    (!World.Current.ShopTiles.Contains(CurrTile) && !World.Current.StockRoomTiles.Contains(CurrTile)))
                {
                    TimeToWait = 1f;
                    LeaveShop();
                    nextTile          = null;
                    WalkingPath_AStar = null;
                    return;
                }
            }
            return;
        }
        //Total dist from A to B
        if (nextTile == null)
        {
            Debug.Log("Wtf");
        }
        float speedWalking = Speed;

        if (XModifier > 0.5f || XModifier < -0.5f || YModifier > 0.5f || YModifier < -0.5f)
        {
            if (!ModifiersCorrect(Numbers.Current.GetRandomTileModerator(), Numbers.Current.GetRandomTileModerator()))
            {
                speedWalking = speedWalking / 2;
            }
        }
        if (nextTile != null && currTile != null)
        {
            float distToTravel = Mathf.Sqrt(Mathf.Pow(currTile.X - nextTile.X, 2) + Mathf.Pow(currTile.Y - nextTile.Y, 2));
            //How much can we travel this update
            float distThisFrame = (speedWalking / nextTile.PersonMovementCost) * deltaTime;
            //How much in terms of percentage?
            float percThisFrame = distThisFrame / distToTravel;
            //Add to overral percentage travelled
            MovementPercentage += percThisFrame;


            if (MovementPercentage >= 1)
            {
                CurrTile           = nextTile;
                MovementPercentage = 0f;
            }


            if (cbPersonPositionChanged != null)
            {
                cbPersonPositionChanged(this);
            }
        }
    }
Ejemplo n.º 7
0
    void GetNewActivity()
    {
        //If I still have a shopping list, let's go get it!
        if (ShoppingList.Count > 0)
        {
            currActivity = new Activity(
                Words.Current.ShopActivity,
                ShoppingList[0].ShopShelf.CustomerTile,
                Numbers.Current.ShopTime,
                ShoppingList[0].ShopShelf.InteractDirection,
                ActivityComplete,
                ActivityCanclled,
                ShoppingList[0].ShopShelf.InteractXModifier,
                ShoppingList[0].ShopShelf.InteractYModifier
                );
        }
        else
        {
            //Was I able to pick anything up?
            if (ItemsInHand.Count > 0)
            {
                //I no longer have a shopping list. Have I paid?
                if (!Paid && ItemsInHand.Count > 0)
                {
                    currActivity = new Activity(
                        Words.Current.PayActivity,
                        World.Current.Checkouts[0].CustomerTile,
                        Numbers.Current.TimeWillWaitForCashier,
                        World.Current.Checkouts[0].InteractDirection,
                        ActivityComplete,
                        ActivityCanclled,
                        World.Current.Checkouts[0].InteractXModifier,
                        World.Current.Checkouts[0].InteractYModifier);
                    World.Current.PeopleInQueue++;

                    //If I'm heading to the till we better put a job in the Checkout Queue
                    World.Current.CheckoutQueue.Enqueue(new Job(
                                                            World.Current.Checkouts[0].Tile,
                                                            Words.Current.CheckoutQueue,
                                                            "",
                                                            ServedByStaff,
                                                            ItemsInHand.Count * Numbers.Current.TimeToScanItem));
                }
            }
            else
            {
                currActivity = null;
                LeaveShop();
            }
        }

        if (currActivity == null)
        {
            return;
        }
        destTile = currActivity.tile;

        WalkingPath_AStar = new Path_ASTar(World.Current, CurrTile, destTile, false, true, Direction);
        if (WalkingPath_AStar.Length() == 0)
        {
            Debug.LogError("No route to dest");
            destTile = currTile;
        }
    }
Ejemplo n.º 8
0
    void GetNewJob()
    {
        if (!TimeToLeave)
        {
            Job newJob = World.Current.JobQueue.GetJob(PriorityList, this);
            if (newJob == null)
            {
                if ((currJob != null && currJob.jobQueue == Words.Current.LoiterQueue))
                {
                    return;
                }

                if (PriorityList.Contains(Words.Current.CheckoutQueue) && !SomeoneElseOnTill())
                {
                    OnTill  = true;
                    currJob = new Job(World.Current.CheckoutTile,
                                      Words.Current.ManEmptyCheckout,
                                      Words.Current.CheckoutQueue,
                                      null,
                                      0f);
                }
                else
                {
                    OnTill = false;
                    int r = UnityEngine.Random.Range(0, World.Current.ShopTiles.Count);
                    currJob = new Job(World.Current.ShopTiles[r],
                                      Words.Current.LoiterQueue,
                                      Words.Current.LoiterQueue,
                                      null,
                                      Numbers.Current.LoiterJobTime);
                }
            }
            else
            {
                currJob = newJob;
            }

            destTile = currJob.tile;

            if (currJob.jobQueue == Words.Current.StockQueue)
            {//I've just got a restock job and need to go get the items first.
                OnTill           = false;
                ItemNeeded       = currJob.tile.Fixture.ItemOnShelf;
                NumberItemNeeded = currJob.jobTime;
                if (NumberItemNeeded == 0)
                {
                    currJob          = null;
                    ItemNeeded       = null;
                    NumberItemNeeded = 0;
                    return;
                }
                // Before I do anything I should check whether I've got enough stock in the Stock Room
                if (ItemNeeded.StockShelf.GetItemsOnShelf().Count == 0)
                {
                    //Don't have anything in the stock room to restock
                    currJob.jobTime = -1;
                    World.Current.StockQueue.Enqueue(currJob);
                    currJob          = null;
                    ItemNeeded       = null;
                    NumberItemNeeded = 0;
                    return;
                }
                destTile = ItemNeeded.StockShelf.EmployeeTile;
            }
            else if (currJob.jobQueue == Words.Current.CostChangeQueue)
            {
                OnTill     = false;
                ItemNeeded = currJob.tile.Fixture.ItemOnShelf;
                destTile   = ItemNeeded.ShopShelf.EmployeeTile;
            }


            currJob.RegisterJobCompleteCallback(OnJobCompleted);
            currJob.RegisterJobCancelCallback(OnJobCompleted);

            WalkingPath_AStar = new Path_ASTar(World.Current, CurrTile, destTile, false, false, Direction);
            if (WalkingPath_AStar.Length() == 0)
            {
                Debug.LogError("No route to dest");
                AbandonJob();
                destTile = currTile;
            }
        }
        else
        {
            LeaveWork();
        }
    }
Ejemplo n.º 9
0
    void Update_DoMovement(float deltaTime)
    {
        if (CurrTile == destTile)
        {
            WalkingPath_AStar = null;
            return;
        }

        if (nextTile == null || nextTile == currTile)
        {
            if (WalkingPath_AStar == null || WalkingPath_AStar.Length() == 0)
            {
                WalkingPath_AStar = new Path_ASTar(World.Current, CurrTile, destTile, false, false, Direction);
                if (WalkingPath_AStar.Length() == 0)
                {
                    Debug.LogError("No path to dest");
                    AbandonJob();
                    return;
                }
                nextTile = WalkingPath_AStar.Dequeue();
            }
            nextTile = WalkingPath_AStar.Dequeue();
            CheckDirection();
        }

        if (nextTile != null && nextTile.IsEnterable(CurrTile) == Enterability.Never)
        {
            nextTile          = null;
            WalkingPath_AStar = null;
            return;
        }
        else if (nextTile != null && nextTile.IsEnterable(CurrTile) == Enterability.Soon)
        {
            return;
        }
        if (!ModifiersCorrect(0, 0.2f))
        {
            return;
        }
        //Total dist from A to B
        float distToTravel = Mathf.Sqrt(Mathf.Pow(currTile.X - nextTile.X, 2) + Mathf.Pow(currTile.Y - nextTile.Y, 2));
        //How much can we travel this update
        float distThisFrame = (Speed / nextTile.PersonMovementCost) * deltaTime;
        //How much in terms of percentage?
        float percThisFrame = distThisFrame / distToTravel;

        //Add to overral percentage travelled
        MovementPercentage += percThisFrame;


        CheckDirection();
        if (MovementPercentage >= 1)
        {
            CurrTile           = nextTile;
            MovementPercentage = 0f;
        }

        if (cbEmployeePositionChanged != null)
        {
            cbEmployeePositionChanged(this);
        }
    }