/// <summary> /// Searches the entire area within control of the country and finds the closest /// and highest priority job for this worker. /// </summary> /// <returns>A <see cref="WorkerActionInfo"/> object with information regarding /// the location and type of work to perform. For more inforation, see the /// <see cref="WorkerActionInfo"/> object.</returns> protected virtual WorkerActionInfo FindCellToImprove() { City next = this.parentCity; GameRoot root = GameRoot.Instance; GridCell currentCell = root.Grid.GetCell(this.Coordinates); WorkerActionInfo info = new WorkerActionInfo(WorkerAction.None, currentCell); if (next == null) { next = currentCell.FindClosestDomesticCity(ParentCountry); } else { NamedObjectCollection <City> exceptions = new NamedObjectCollection <City>(); bool found = false; while (!found) { info = next.RetrieveWorkItem(); if (info.WorkerAction != WorkerAction.None) { found = true; break; } else { exceptions.Add(next); } next = currentCell.FindClosestDomesticCity(ParentCountry, exceptions); } } return(info); }
/// <summary> /// Gets the best suited work to be performed on the cell. /// </summary> /// <returns></returns> public WorkerActionInfo FindWorkerAction() { WorkerActionInfo info = new WorkerActionInfo(WorkerAction.None, this); if (this.IsPolluted) { info.WorkerAction = WorkerAction.CleanPollution; info.Priority = 10; } else if (!this.HasRoad && this.IsDry) { info.WorkerAction = WorkerAction.BuildRoad; info.Priority = 8; } else if (!this.IsIrrigated && this.IsDry) { info.WorkerAction = WorkerAction.Irrigate; info.Priority = 6; } return(info); }
/// <summary> /// Takes a turn for the worker. /// </summary> public override void DoTurn() { if (this.status != WorkerStatus.Idle) { this.turnsToComplete--; if (this.turnsToComplete <= 0) { GameRoot root = GameRoot.Instance; GridCell currentCell = root.Grid.GetCell(this.Coordinates); switch (this.status) { case WorkerStatus.BuildingRailroad: currentCell.HasRailroad = true; break; case WorkerStatus.BuildingRoad: currentCell.HasRoad = true; break; case WorkerStatus.CleaningPollution: currentCell.IsPolluted = false; break; case WorkerStatus.ClearingForest: throw new NotImplementedException(); case WorkerStatus.ClearingJungle: throw new NotImplementedException(); case WorkerStatus.Irrigating: currentCell.IsIrrigated = true; break; case WorkerStatus.Mining: currentCell.HasMine = true; break; } this.status = WorkerStatus.Idle; Active = true; if (this.workQueue.Count > 0) { this.currentAction = (WorkerActionInfo)this.workQueue.Dequeue(); } else { this.currentAction = null; } this.MovesLeft = this.MovesPerTurn; } } else if (this.currentAction != null) { InvokeCurrentAction(); } else if (this.workQueue.Count > 0) { this.currentAction = (WorkerActionInfo)this.workQueue.Dequeue(); InvokeCurrentAction(); } else if (this.automated && this.workQueue.Count == 0) { //automated workers that are idle need to find something to //do. this.currentAction = FindCellToImprove(); InvokeCurrentAction(); } base.DoTurn(); }