/// <summary> /// Initializes a new instance of the <see cref="TargetBuildingInfo" /> class. /// </summary> /// <param name="buildingId">The building identifier.</param> /// <param name="building">The building.</param> /// <param name="dispatcherType">Type of the dispatcher.</param> /// <param name="demand">The demand.</param> public TargetBuildingInfo(ushort buildingId, ref Building building, Dispatcher.DispatcherTypes dispatcherType, ServiceDemand demand) { this.BuildingId = buildingId; this.dispatcherType = dispatcherType; if (this.dispatcherType == Dispatcher.DispatcherTypes.AmbulanceDispatcher) { this.citizens = new Dictionary <uint, TargetCitizenInfo>(); } this.Update(ref building, demand); }
/// <summary> /// Seeds the database with mock data /// </summary> /// <param name="context"></param> public static void Initialize(PocDbContext context) { context.Database.EnsureCreated(); if (context.Users.Any()) { return; } var users = new User[] { new User { Id = 1, Username = "******", Password = "******", RoleId = Role.USER.Id }, new User { Id = 0, Username = "******", Password = "******", RoleId = Role.ADMIN.Id } }; context.AddRange(users); context.SaveChanges(); var demands = new ServiceDemand[] { new ServiceDemand { CreatedAt = DateTime.Now, Description = "Service 1", LastEdit = DateTime.Now, StatusId = Status.CREATED.Id, OwnerId = users[0].Id }, new ServiceDemand { CreatedAt = DateTime.Now, Description = "Service 2", LastEdit = DateTime.Now, StatusId = Status.CREATED.Id, OwnerId = users[0].Id }, new ServiceDemand { CreatedAt = DateTime.Now, Description = "Service 3", LastEdit = DateTime.Now, StatusId = Status.IN_ANALISYS.Id, OwnerId = users[1].Id }, new ServiceDemand { CreatedAt = DateTime.Now, Description = "Service 4", LastEdit = DateTime.Now, StatusId = Status.IN_PROGRESS.Id, OwnerId = users[1].Id } }; context.AddRange(demands); context.SaveChanges(); }
/// <summary> /// Updates the building. /// </summary> /// <param name="building">The building.</param> /// <param name="demand">The demand.</param> /// <exception cref="System.Exception">Loop counter too high.</exception> public void Update(ref Building building, ServiceDemand demand) { this.lastUpdate = Global.CurrentFrame; Notification.Problem problemToCheck; switch (this.dispatcherType) { case Dispatcher.DispatcherTypes.HearseDispatcher: this.UpdateCitizens(ref building); this.ProblemValue = ((ushort)building.m_deathProblemTimer << 8); problemToCheck = Notification.Problem.Death; break; case Dispatcher.DispatcherTypes.GarbageTruckDispatcher: this.ProblemValue = building.m_garbageBuffer; this.ProblemSize = building.m_garbageBuffer; problemToCheck = Notification.Problem.Garbage; break; case Dispatcher.DispatcherTypes.AmbulanceDispatcher: this.UpdateCitizens(ref building); this.ProblemValue = (ushort)building.m_healthProblemTimer << 8; problemToCheck = BuildingHelper.HealthProblems; break; default: this.ProblemValue = 0; this.ProblemSize = 0; problemToCheck = Notification.Problem.None; break; } if (Global.ServiceProblems == null) { this.serviceProblemCountValue = 0; this.serviceProblemSizeValue = 0; this.ServiceProblemMagnitude = 0; this.ProblemWeight = this.ProblemValue; } else { Global.ServiceProblems.GetTargetBuildingProblemInfo(this.BuildingId, out this.serviceProblemCountValue, out this.serviceProblemSizeValue); if (this.serviceProblemSizeValue > 0 && this.serviceProblemCountValue > 0) { uint multiplier = (uint)(Math.Min(10.0, Math.Round(0.5 + (float)this.serviceProblemCountValue / 4.0, 0.0))); this.ServiceProblemMagnitude = (uint)this.serviceProblemSizeValue * multiplier; long weight = this.ProblemValue - this.ServiceProblemMagnitude; this.ProblemWeight = (int)Math.Max(Math.Min(weight, int.MaxValue), 0L); //if (Log.LogALot) //{ // ServiceProblemKeeper.DevLog("TargetBuildingProblemWeighting", // Log.Data("TargetBuilding", this.BuildingId, BuildingHelper.GetBuildingName(this.BuildingId)), // Log.Data("BuildingProblem", this.serviceProblemCountValue, this.serviceProblemSizeValue), // Log.Data("Modifier", multiplier, this.ServiceProblemMagnitude, weight), // Log.Data("Weight", this.ProblemValue, this.ProblemWeight, this.ProblemWeight - this.ProblemValue)); //} } else { this.ServiceProblemMagnitude = 0; this.ProblemWeight = this.ProblemValue; } } this.HasProblem = (this.ProblemSize > 0) && ((building.m_problems & problemToCheck) != Notification.Problem.None || this.ProblemValue >= Dispatcher.ProblemLimit); this.Position = building.m_position; this.UpdateValues(ref building, false); this.NeedsService = (this.ProblemSize > 0) && (this.HasProblem || demand == ServiceDemand.NeedsService); this.WantsService = (this.ProblemSize > 0) && (this.NeedsService || demand == ServiceDemand.WantsService); if (this.WantsService || this.lastWantStamp == 0) { this.lastWantStamp = Global.CurrentFrame; } this.checkThis = this.WantsService && ((Global.RecheckInterval == 0 || this.lastCheck == 0 || Global.CurrentFrame - this.lastCheck >= Global.RecheckInterval) && (Global.RecheckHandledInterval == 0 || this.lastHandled == 0 || Global.CurrentFrame - this.lastHandled >= Global.RecheckHandledInterval)); }