Ejemplo n.º 1
0
        internal void RescheduleActivity(ActivityInfo activity, ScheduledActivity scheduledActivity, bool ignoreOther)
        {
            bool multiDorm = activity.Flags.HasFlag(ActivityFlags.MultiDorm);

            AvailableActivitiesToday.Remove(activity.ID);
            if (multiDorm)
            {
                AvailableMultiDormActivitiesToday.Remove(activity.ID);
            }

            if (activity.Flags.HasFlag(ActivityFlags.Repeatable))
            {
                RepeatableTodayHistory.Add(activity.ID);
            }

            ActivitiesDoneToday.Add(activity.ID);
            if (activity.IncompatibleActivities.Any())
            {
                AvailableActivitiesToday.ExceptWith(activity.IncompatibleActivities);
                AvailableMultiDormActivitiesToday.ExceptWith(activity.IncompatibleActivities);
            }

            if (!ignoreOther && scheduledActivity.HasOther)
            {
                if (DormPriorities.TryGetValue(scheduledActivity.OtherDorm, out InterDormTracking interDorm))
                {
                    interDorm.RescheduleActivity(!OtherDormsDoneToday.Add(scheduledActivity.OtherDorm));
                }
            }
            else
            {
                OtherDormsDoneToday.Add(Dorm);
            }
        }
Ejemplo n.º 2
0
        public bool ScheduleActivity(ScheduledActivity scheduledActivity, bool doneToday, bool repeatable, bool multiDorm)
        {
            if (doneToday)
            {
                Options        = 0;
                AvailableToday = false;
            }
            else if (!scheduledActivity.HasOther)
            {
                --Options;
            }

            ScheduleHistory.Add(scheduledActivity.Abbreviation);

            bool soloTracker = ThisDorm == Dorm;

            if (repeatable && (!soloTracker || multiDorm))
            {
                if (!PreviousRepeatableActivities.Add(scheduledActivity.Activity))
                {
                    throw new NotImplementedException("Did a repeatable activity twice with the same Dorm.");
                }
            }

            if (!soloTracker && --Priority == 0)
            {
                Options        = 0;
                AvailableToday = false;
                return(true);
            }

            return(false);
        }
Ejemplo n.º 3
0
            public StringableScheduled(ScheduledActivity activity)
            {
                string   activityAbbrv = Schedule.Activities[activity.Activity].Abbreviation;
                DormInfo dorm          = Schedule.Dorms[activity.Dorm];

                DormAgeIndex = dorm.AgeIndex;
                DormEntry    = dorm.Abbreviation + " - " + activityAbbrv;
                HasOther     = activity.HasOther;
                if (HasOther)
                {
                    dorm = Schedule.Dorms[activity.OtherDorm];
                    OtherDormAgeIndex = dorm.AgeIndex;
                    OtherDormEntry    = dorm.Abbreviation + " - " + activityAbbrv;
                }
                Duration = activity.Duration;
            }
Ejemplo n.º 4
0
        public void ClearFromHistory(ScheduledActivity scheduledActivity, bool repeatable, bool multiDorm)
        {
            bool soloTracker = ThisDorm == Dorm;

            if (!soloTracker)
            {
                ++Priority;
                AvailableToday = true;
            }

            if (repeatable && (!soloTracker || multiDorm))
            {
                if (!PreviousRepeatableActivities.Remove(scheduledActivity.Activity))
                {
                    throw new NotImplementedException("Activity not found in PreviousRepeatableActivities.");
                }
            }

            ScheduleHistory.Remove(scheduledActivity.Abbreviation);
        }
Ejemplo n.º 5
0
        public void ScheduleActivity(ActivityInfo activity, ScheduledActivity scheduledActivity)
        {
            if (!activity.Flags.HasFlag(ActivityFlags.Manual) && (!activity.Flags.HasFlag(ActivityFlags.Exclusive) || !activity.Flags.HasFlag(ActivityFlags.Excess)))
            {
                TotalScheduledDuration += activity.Duration;
            }
            else
            {
                TotalManualDuration += activity.Duration;
            }

            bool repeatable = activity.Flags.HasFlag(ActivityFlags.Repeatable);
            bool multiDorm  = activity.Flags.HasFlag(ActivityFlags.MultiDorm);

            AvailableActivitiesToday.Remove(activity.ID);
            if (multiDorm)
            {
                AvailableMultiDormActivitiesToday.Remove(activity.ID);
            }

            bool clear = !repeatable;

            if (repeatable)
            {
                if (!RepeatableHistory.Add(activity.ID))
                {
                    clear = true;
                }
                else
                {
                    if (ActivityPriorities.TryGetValue(activity.ID, out int activityPriority))
                    {
                        if (--activityPriority == 0)
                        {
                            ActivityPriorities.Remove(activity.ID);
                        }
                    }
                    else
                    {
                        ActivityPriorities.Add(activity.ID, -1);
                    }
                }

                /*if (!RepeatableTodayHistory.Add(activity.ID))
                 *  throw new IndexOutOfRangeException("Activity repeated twice the same day.");*/
            }

            if (clear)
            {
                AvailableActivities.Remove(activity.ID);
                if (multiDorm)
                {
                    AvailableMultiDormActivities.Remove(activity.ID);
                }
            }

            ActivitiesDoneToday.Add(activity.ID);
            if (activity.IncompatibleActivities.Any())
            {
                AvailableActivitiesToday.ExceptWith(activity.IncompatibleActivities);
                AvailableMultiDormActivitiesToday.ExceptWith(activity.IncompatibleActivities);
            }

            ScheduleHistory.Add(scheduledActivity.Abbreviation);
            if (scheduledActivity.HasOther)
            {
                if (scheduledActivity.Dorm == Dorm)
                {
                    if (
                        DormPriorities.TryGetValue(
                            scheduledActivity.OtherDorm,
                            out InterDormTracking otherDorm
                            ) && otherDorm.ScheduleActivity(
                            scheduledActivity,
                            !OtherDormsDoneToday.Add(scheduledActivity.OtherDorm),
                            repeatable, multiDorm
                            )
                        )
                    {
                        UsedUpOtherDorms.Add((InterDormTracking)otherDorm.Clone());
                        DormPriorities.Remove(scheduledActivity.OtherDorm);
                    }
                }
            }
            else
            {
                DormPriorities[Dorm].ScheduleActivity(scheduledActivity, false, repeatable, multiDorm);
                OtherDormsDoneToday.Add(Dorm);
            }
        }
Ejemplo n.º 6
0
        internal void ClearFromHistory(ScheduledActivity scheduledActivity, bool ignoreHasOther = false)
        {
            ScheduleHistory.Remove(scheduledActivity.Abbreviation);
            var activity = Schedule.Activities[scheduledActivity.Activity];

            bool repeatable = activity.Flags.HasFlag(ActivityFlags.Repeatable);
            bool multiDorm  = activity.Flags.HasFlag(ActivityFlags.MultiDorm);

            if (activity.IncompatibleActivities.Any())
            {
                var incompat = new SortedSet <int>(activity.IncompatibleActivities);
                incompat.ExceptWith(ActivitiesDoneToday);
                if (incompat.Any())
                {
                    AvailableActivitiesToday.UnionWith(incompat);
                    AvailableMultiDormActivitiesToday.UnionWith(incompat.Intersect(ActivityInfo.MultiDormActivities));
                }
            }
            ActivitiesDoneToday.Remove(activity.ID);

            if (scheduledActivity.HasOther)
            {
                if (!ignoreHasOther)
                {
                    if (!DormPriorities.TryGetValue(scheduledActivity.OtherDorm, out InterDormTracking interDorm))
                    {
                        var index = UsedUpOtherDorms.FindIndex(d => d.Dorm == scheduledActivity.OtherDorm);
                        interDorm = (InterDormTracking)UsedUpOtherDorms[index].Clone();
                        UsedUpOtherDorms.RemoveAt(index);
                        DormPriorities.Add(scheduledActivity.OtherDorm, interDorm);
                    }

                    interDorm.ClearFromHistory(scheduledActivity, repeatable, multiDorm);
                    OtherDormsDoneToday.Remove(scheduledActivity.OtherDorm);
                }
            }
            else
            {
                DormPriorities[Dorm].ClearFromHistory(scheduledActivity, repeatable, multiDorm);
                OtherDormsDoneToday.Remove(Dorm);
            }

            if (repeatable)
            {
                if (RepeatableHistory.Contains(activity.ID))
                {
                    // if it wasn't cleared, it was the first time the activity was done by that dorm
                    if (!AvailableActivities.Add(activity.ID))
                    {
                        RepeatableHistory.Remove(activity.ID);
                    }
                    if (multiDorm)
                    {
                        AvailableMultiDormActivities.Add(activity.ID);
                    }
                    RepeatableTodayHistory.Remove(activity.ID);
                }
                else
                {
                    throw new NotImplementedException("Activity being cleared hasn't been undergone.");
                }

                if (ActivityPriorities.TryGetValue(activity.ID, out int activityPriority))
                {
                    if (++activityPriority == 0)
                    {
                        ActivityPriorities.Remove(activity.ID);
                    }
                }
                else
                {
                    ActivityPriorities.Add(activity.ID, 1);
                }
            }
            else
            {
                if (!AvailableActivities.Add(activity.ID))
                {
                    throw new NotImplementedException("Activity being cleared hasn't been undergone.");
                }
                if (multiDorm)
                {
                    AvailableMultiDormActivities.Add(activity.ID);
                }
            }

            AvailableActivitiesToday.Add(activity.ID);
            if (multiDorm)
            {
                AvailableMultiDormActivitiesToday.Add(activity.ID);
            }

            if (!activity.Flags.HasFlag(ActivityFlags.Manual) && (!activity.Flags.HasFlag(ActivityFlags.Exclusive) || !activity.Flags.HasFlag(ActivityFlags.Excess)))
            {
                TotalScheduledDuration -= activity.Duration;
            }
            else
            {
                TotalManualDuration -= activity.Duration;
            }
        }