/// <summary> /// This function will perform a building cycle if the number of ticks since the last cycle is equal to TICKS_PER_CYCLE. /// </summary> /// <returns>true if the building is complete and the action is finished, false otherwise.</returns> public override bool Work() { if (!building.Completed) { if (curTicks % TICKS_PER_CYCLE == 0) { // Check if unit is adjacent to building. if (isUnitNextToBuilding()) { UnitComponent unit = (UnitComponent)Parent.Parent; unit.State = UnitComponent.UnitState.BUILDING; UnitComponent worker = (UnitComponent)Parent.Parent; // Add the building to the model if we have not done so yet. if (building.Parent == null) { // TODO: Ensure that the spaces are cleared. Perhaps wait/give up, as with move? PlayerComponent player = Parent.Parent.Parent.Parent as PlayerComponent; if (!map.addBuildingToMap(building)) // add building to the map { return(false); } player.addBuilding(building); // add building to player's building list } updateBuildingProgress(building, worker); } else { // Move towards the building. Insert a move action into the Unit's action queue. CellComponent targetCell = findClosestCell(((UnitComponent)Parent.Parent).PointLocation); MoveAction moveAction = new MoveAction(targetCell.X, targetCell.Y, map, ((UnitComponent)Parent.Parent)); Parent.AddChildAt(moveAction, 0); } } } curTicks++; return(building.Completed); }