public override void CompleteEvent(object eventData) { if (eventData == MoveQueueEventData) { if (EnteredVisitors.Count > 0) { Visitor served = EnteredVisitors.Dequeue(); MessageFeed.RegisterMessage("Návštěvník vjíždí na sjezdovku " + Name); parent.RegisterEvent(served, (int)Math.Ceiling(Length / (AverageSpeed * served.SpeedFactor)), this); ridecount++; } if (ridecount == MaintenanceFrequency) { parent.RegisterEvent(this, MaintenanceTime, MoveQueueEventData); MessageFeed.RegisterMessage("Nastává úprava sjezdovky " + Name + ". Další návštěvníci na ni vjedou až za " + MaintenanceTime.ToString() + " sekund."); ridecount = 0; } else if ((random.Next(1000000001) / 1000000000.0) < AccidentProbability) { parent.ModifyEventsOf(this, 30); MessageFeed.RegisterMessage("Nehoda na sjezdovce " + Name + ". Návštěvníci jsou zdrženi o 30 sekund"); parent.RegisterEvent(this, DequeueFrequency + 30, MoveQueueEventData); } else { parent.RegisterEvent(this, DequeueFrequency, MoveQueueEventData); } } }
public bool PerformSimulationStep() { if (CurrentTimeEvents.Count == 0) { if (ActiveEvents.Count > 0) { int mintime = int.MaxValue; foreach (SimulationEvent se in ActiveEvents) { if (se.FinishTime < mintime) { mintime = se.FinishTime; } } CurrentTime = mintime; MessageFeed.RegisterMessage("Změna aktuálního času simulace - " + CurrentTime); foreach (SimulationEvent se in ActiveEvents) { if (se.FinishTime == mintime) { CurrentTimeEvents.Add(se); } } foreach (SimulationEvent se in CurrentTimeEvents) { ActiveEvents.Remove(se); } return(true); } else { return(false); } } else { SimulationEvent se = CurrentTimeEvents[CurrentTimeEvents.Count - 1]; CurrentTimeEvents.RemoveAt(CurrentTimeEvents.Count - 1); se.Who.CompleteEvent(se.EventData); return(true); } }
public override void CompleteEvent(object eventData) { if (eventData == MoveQueueEventData) { if (EnteredVisitors.Count > 0) { Visitor served = EnteredVisitors.Dequeue(); MessageFeed.RegisterMessage("Návštěvníka právě odbavil vlek " + Name); parent.RegisterEvent(served, RideTime, this); } if ((random.Next(1000000001) / 1000000000.0) < AccidentProbability) { parent.ModifyEventsOf(this, 60); MessageFeed.RegisterMessage("Nehoda na vleku " + Name + ". Pasažéři vleku jsou zdrženi o 60 sekund"); parent.RegisterEvent(this, DequeueFrequency + 60, MoveQueueEventData); } else { parent.RegisterEvent(this, DequeueFrequency, MoveQueueEventData); } } }
public void VisitorExit(Visitor who) { Visitors.Remove(who); MessageFeed.RegisterMessage("Návštěvník odchází."); }
public override void CompleteEvent(object eventData) { #region Finish Building interaction if (eventData == null) { MessageFeed.RegisterMessage("Nový návštěvník dorazil."); } if (eventData != null && eventData is ResortBuilding) { CurrentLocation = (eventData as ResortBuilding).Exit; if (eventData is SkiHill) { SkiHill ridden = eventData as SkiHill; FoodNeed += (int)Math.Ceiling(3 * ridden.Length * ((int)ridden.Skill / 2.0)); } else if (eventData is SkiLift) { LiftRidesLeft--; } else if (eventData is FastFood) { FoodNeed = 0; } else if (eventData is EquipmentRental) { Rents = false; } } #endregion IEnumerable <ResortBuilding> nextTargets = parent.GetAvailableBuildings(CurrentLocation); #region Decide if Downhill if (CurrentLocation == ELocation.Downhill) { if (Rents && LiftRidesLeft > 0) { IEnumerable <EquipmentRental> rentals = nextTargets.Where(rb => (rb is EquipmentRental)).Select(rb => (rb as EquipmentRental)); if (rentals.Count() > 0) { EquipmentRental best = GetLeastCrowdedBuilding(rentals) as EquipmentRental; MessageFeed.RegisterMessage("Návštěvník jde do půjčovny " + best.ToString()); best.Use(this); return; } } if (Rents && FoodNeed == 0) { parent.VisitorExit(this); return; } if (LiftRidesLeft == 0) { IEnumerable <FastFood> foods = nextTargets.Where(rb => (rb is FastFood)).Select(rb => (rb as FastFood)); if (FoodNeed == 0 && foods.Count() == 0) { parent.VisitorExit(this); return; } else if (foods.Count() > 0) { FastFood best = GetLeastCrowdedBuilding(foods) as FastFood; MessageFeed.RegisterMessage("Návštěvník jde na jídlo do " + best.ToString()); best.Use(this); return; } } if (FoodNeed > (random.Next(100) + 1)) { IEnumerable <FastFood> foods = nextTargets.Where(rb => (rb is FastFood)).Select(rb => (rb as FastFood)); if (foods.Count() > 0) { FastFood best = GetLeastCrowdedBuilding(foods) as FastFood; MessageFeed.RegisterMessage("Návštěvník jde na jídlo do " + best.ToString()); best.Use(this); return; } } IEnumerable <SkiLift> lifts = nextTargets.Where(rb => (rb is SkiLift)).Select(rb => (rb as SkiLift)); IEnumerable <SkiHill> hills = parent.GetAvailableBuildings(ELocation.Uphill).Where(rb => (rb is SkiHill)).Select(rb => (rb as SkiHill)); if (Skill <= ESkill.Red) { hills = hills.Where(sh => (sh.Skill != ESkill.Black)); } if (Skill == ESkill.Blue) { hills = hills.Where(sh => (sh.Skill != ESkill.Red)); } if (lifts.Count() > 0 && hills.Count() > 0) { SkiLift best = GetLeastCrowdedBuilding(lifts) as SkiLift; MessageFeed.RegisterMessage("Návštěvník jde na vlek " + best.ToString()); best.Use(this); return; } parent.VisitorExit(this); return; } #endregion #region Decide if Uphill else { if (FoodNeed > (random.Next(100) + 1)) { IEnumerable <FastFood> foods = nextTargets.Where(rb => (rb is FastFood)).Select(rb => (rb as FastFood)); if (foods.Count() > 0) { FastFood bestf = GetLeastCrowdedBuilding(foods) as FastFood; MessageFeed.RegisterMessage("Návštěvník jde na jídlo do " + bestf.ToString()); return; } } IEnumerable <SkiHill> hills = nextTargets.Where(rb => (rb is SkiHill)).Select(rb => (rb as SkiHill)); IEnumerable <SkiHill> bluehills = hills.Where(sh => (sh.Skill == ESkill.Blue)); IEnumerable <SkiHill> redhills = hills.Where(sh => (sh.Skill == ESkill.Red)); IEnumerable <SkiHill> blackhills = hills.Where(sh => (sh.Skill == ESkill.Black)); SkiHill bestblue = GetLeastCrowdedBuilding(bluehills) as SkiHill; SkiHill bestred = GetLeastCrowdedBuilding(redhills) as SkiHill; SkiHill bestblack = GetLeastCrowdedBuilding(blackhills) as SkiHill; SkiHill best = null; if (Skill == ESkill.Black) { if (best == null && bestblack != null) { best = bestblack; } } if (Skill >= ESkill.Red) { if (bestred != null) { if (best == null) { best = bestred; } else if (bestred.EnteredVisitors.Count + 30 < best.EnteredVisitors.Count) { best = bestred; } } } if (bestblue != null) { if (best == null) { best = bestblue; } else if (bestblue.EnteredVisitors.Count + 30 < best.EnteredVisitors.Count) { best = bestblue; } } if (best != null) { MessageFeed.RegisterMessage("Návštěvník jde na sjezdovku " + best.ToString()); best.Use(this); return; } else //FAILPROOF - Should never happen { MessageFeed.RegisterMessage("Warning!"); parent.VisitorExit(this); return; } } #endregion }