private void StopCompletedJobs() { for (int i = 0; i < ActiveJobs.Count; i++) { var job = ActiveJobs[i]; if (job.GetCompletionPercentage() >= 1.0f) { Money += job.Job.Job.OfferedReward; var finalDestination = job.Job.Job.To; var finalPlace = WorldState.GetStateForPlace(job.Job.Job.To); job.Job.Job.JobWasCompletedSuccesfully(); // Stay at location if owned + setting to stay there is enabled, or if it is the original location. // else return to original location. if (WorldState.PlaceOwned(finalDestination) && (job.Assignment.StayAtLocation || job.Employee.OriginalLocation == finalDestination)) { ActiveJobs.RemoveAt(i); i--; // Employee is now in the employee list of the destination place. job.Employee.CurrentJob = null; finalPlace.AddEmployee(job.Employee); continue; } else { ActiveJobs.RemoveAt(i); i--; // If the final stop place is not owned, make driver go back to original location. var scheduledJob = new ScheduledJob(job.Job.Job.Reverse(), job.Job.ShipTimes); ActiveJob returnJob = new ActiveJob(scheduledJob, job.Assignment, GetNextLeavingTimeslot(), job.Employee); job.Employee.CurrentJob = returnJob; ActiveJobs.Add(returnJob); finalPlace.EmployeeStateChanged(); continue; } } } }
private void StartJob(PlaceState place, ShipTimeAssignment assignee, ScheduledJob job) { if (!place.Employees.Contains(assignee.AssignedEmployee)) { job.Job.JobWasCompletedUnsuccesfully(); MessageLog.AddError(string.Format("{0} {1} missed their trip to {2} from {3} at {4}", assignee.AssignedEmployee.Name, assignee.AssignedEmployee.Id, job.Job.To.Name, job.Job.From.Name, assignee.Time.ToString("h':'m''"))); return; } var employee = assignee.AssignedEmployee; if (employee.AssignedTruck == null) { MessageLog.AddError(string.Format("{0} {1} does not have a truck to drive to {2} from {3} at {4}", assignee.AssignedEmployee.Name, assignee.AssignedEmployee.Id, job.Job.To.Name, job.Job.From.Name, assignee.Time.ToString("h':'m''"))); return; } if (employee.CurrentJob == null) { employee.CurrentLocation = null; place.Employees.Remove(assignee.AssignedEmployee); var activeJob = new ActiveJob(job, assignee, Time - TimeSpan.FromMinutes(Time.Minute % 15), employee); Money -= activeJob.GasPrice(); employee.CurrentJob = activeJob; ActiveJobs.Add(activeJob); MessageLog.AddInfo(string.Format("{0} left {1}, driving to {2}", assignee.AssignedEmployee.Name, job.Job.From.Name, job.Job.To.Name)); } }