Esempio n. 1
0
    private void ForceCompleteUnloadingTask(UnloadingTask task)
    {
        Unload(ship.cargo, task.dock);

        string content = string.Format("{0} ship {1} finished unloading!", ship.Industry.ToString(), ship.Name);

        GameObject.Find("NotificationSystem").GetComponent <NotificationSystem> ().Notify(NotificationType.Success, content);
    }
Esempio n. 2
0
    private void ReserveUnloadingTask(UnloadingTask task)
    {
        if (!reservationOnDocks.ContainsKey(task.dock))
        {
            reservationOnDocks.Add(task.dock, new List <Reservation>());
        }

        List <Reservation> reservationList = reservationOnDocks[task.dock];
        Reservation        reservation     = new Reservation();

        reservation.StartTime = task.StartTime - safetyTime;
        reservation.EndTime   = task.EndTime + safetyTime;
        reservationList.Add(reservation);
    }
Esempio n. 3
0
    private bool UnloadingTaskHasConflict(UnloadingTask task)
    {
        if (!reservationOnDocks.ContainsKey(task.dock))
        {
            return(false);
        }

        List <Reservation> reservationList = reservationOnDocks[task.dock];

        foreach (Reservation reservation in reservationList)
        {
            if (reservation.ConflictWithTask(task.StartTime, task.EndTime))
            {
                return(true);
            }
        }
        return(false);
    }
Esempio n. 4
0
    private void processUnloadingTask(UnloadingTask task)
    {
        Timer    timer       = GameObject.Find("Timer").GetComponent <Timer>();
        DateTime currentTime = timer.VirtualTime;
        TimeSpan timeElapsed = timer.TimeElapsed;

        double   cargoRemaining = ship.cargo;
        TimeSpan timeRemaining  = task.EndTime.Subtract(currentTime);
        double   speedRequired  = cargoRemaining / timeRemaining.TotalSeconds;
        double   cargoCanUnload = timeElapsed.TotalSeconds * speedRequired;

        if (cargoCanUnload > cargoRemaining)
        {
            cargoCanUnload = cargoRemaining;
        }

        Unload(cargoCanUnload, task.dock);

        this.status = ShipStatus.Unloading;
    }
Esempio n. 5
0
    private void ResolveConflictForUnloadingTask(UnloadingTask task, ShipSchedule schedule)
    {
        if (!UnloadingTaskHasConflict(task))
        {
            return;
        }

        List <Reservation> reservationList = reservationOnDocks[task.dock];
        TimeSpan           minTimeSpan     = TimeSpan.MaxValue;

        foreach (Reservation reservation in reservationList)
        {
            TimeSpan timeDiff = reservation.EndTime + safetyTime - task.StartTime;
            if (timeDiff.CompareTo(TimeSpan.Zero) < 0)
            {
                continue;
            }

            if (reservation.ConflictWithTask(task.StartTime + timeDiff, task.EndTime + timeDiff))
            {
                continue;
            }

            if (timeDiff < minTimeSpan)
            {
                minTimeSpan = timeDiff;
            }
        }

        if (minTimeSpan == TimeSpan.Zero)
        {
            minTimeSpan = minTimeSpan.Add(new TimeSpan(0, 0, 1));
        }

        schedule.Postpone(minTimeSpan);
    }
Esempio n. 6
0
    private ShipSchedule PathToSchedule(ShipPath path)
    {
        double       defaultShipSpeed = GameObject.Find("SceneSetting").GetComponent <SceneSetting>().ShipSpeed;
        double       shipSpeed        = defaultShipSpeed;
        ShipSchedule schedule         = new ShipSchedule();
        MapUtil      mapUtil          = GameObject.Find("MapUtil").GetComponent <MapUtil>();

        DateTime currentTime        = GameObject.Find("Timer").GetComponent <Timer>().VirtualTime;
        Vector2  currentPosition    = new Vector2((float)ship.Ship.X, (float)ship.Ship.Y);
        bool     unloadingScheduled = false;

        Node previousNode = null;

        foreach (Node node in path.path)
        {
            ShipMoveTask moveTask = new ShipMoveTask();
            moveTask.Position = new Vector2((float)node.X, (float)node.Y);

            if (previousNode != null)
            {
                moveTask.connection = mapUtil.GetConnection(previousNode, node);
                shipSpeed           = moveTask.connection.Speed;
            }
            else
            {
                shipSpeed = defaultShipSpeed;
            }


            double   distance = Math.Pow(Math.Pow(node.X - currentPosition.x, 2) + Math.Pow(node.Y - currentPosition.y, 2), 0.5);
            TimeSpan duration = new TimeSpan(0, 0, (int)Math.Round(distance / shipSpeed));
            moveTask.StartTime = currentTime;
            moveTask.EndTime   = currentTime.Add(duration);


            previousNode = node;

            currentTime     = currentTime.Add(duration);
            currentPosition = new Vector2((float)node.X, (float)node.Y);

            schedule.AppendTask(moveTask);

            // Unloading task
            double unloadingSpeed = GameObject.Find("SceneSetting").GetComponent <SceneSetting>().UnloadingSpeed;
            Dock   dock           = mapUtil.GetDockByNode(node);
            if (!unloadingScheduled && dock != null)
            {
                TimeSpan      unloadingDuration = new TimeSpan(0, 0, (int)Math.Round(ship.Ship.cargo / unloadingSpeed));
                UnloadingTask unloadingTask     = new UnloadingTask();
                unloadingTask.Position  = currentPosition;
                unloadingTask.StartTime = currentTime;
                unloadingTask.EndTime   = currentTime.Add(unloadingDuration);
                unloadingTask.dock      = dock;
                currentTime             = currentTime.Add(unloadingDuration);
                schedule.AppendTask(unloadingTask);
                unloadingScheduled = true;
            }

            // Task
            List <Node> exits = mapUtil.ExitNodes();
            if (exits.Contains(node))
            {
                VanishTask vanishTask = new VanishTask();
                vanishTask.StartTime = currentTime;
                vanishTask.EndTime   = currentTime;
                schedule.AppendTask(vanishTask);
            }
        }
        return(schedule);
    }