Ejemplo n.º 1
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.º 2
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;
            }
        }