public bool CancelLastTrainingInstance(string unitTypeToCancel) { bool wasCanceled = false; if (TrainingQueue.Count > 0) { int lastIndex = TrainingQueue.LastIndexOf(unitTypeToCancel); if (lastIndex > -1) { TrainingQueue.RemoveAt(lastIndex); ButtonCountDisplays[unitTypeToCancel]--; if (lastIndex == 0) { if (TrainingQueue.Count > 0) { TryStartTraining(CurrentTrainingUnit); } } if (ButtonCountDisplays[unitTypeToCancel] == 0) { ProgressPercents[unitTypeToCancel] = 0; } this.UpdateStatus?.Invoke(this, new UpdateStatusEventArgs()); wasCanceled = true; } } return(wasCanceled); }
private void TrainingActivity() { if (TrainingQueue.Count > 0) { var trainingUnit = CurrentTrainingUnit; ProgressPercents[trainingUnit] = TrainingProgress; if (IsTrainingComplete) { TrainingQueue.RemoveAt(0); ButtonCountDisplays[trainingUnit]--; if (TrainingQueue.Count > 0) { TryStartTraining(CurrentTrainingUnit); } //Spawn the unit after qeueuing up a new unit for training. //This will ensure the ui can properly update to show if the unit has enough capacity or if there is a queued unit. var spawnPosition = new Vector3() { X = UnitSpawnX, Y = UnitSpawnY, Z = 1 }; // so the units don't stack in a line line: spawnPosition.Y += FlatRedBallServices.Random.Between(0, 1); spawnPosition.X += FlatRedBallServices.Random.Between(0, 1); var newUnit = ((Screens.GameScreen)ScreenManager.CurrentScreen).SpawnNewUnit(trainingUnit, spawnPosition); if (RallyPoint.HasValue) { newUnit.AssignMoveGoal(RallyPoint.Value.X, RallyPoint.Value.Y); } } else if (TrainingQueue.Count > 0 && DidTrainingStall) { //If the queue greater than 0 we check if we stalled, which is a negative start time. TryStartTraining(CurrentTrainingUnit); } this.UpdateStatus?.Invoke(this, new UpdateStatusEventArgs()); } }
public bool TryAddUnitToTrain(string unit) { bool wasSuccessful = true; //If the queue is empty, we try start the training. //If not we will add the unit to the end of the queue and inform the caller. if (TrainingQueue.Count == 0) { wasSuccessful = TryStartTraining(unit); } if (wasSuccessful) { TrainingQueue.Add(unit); //We will initialize the dictionary with all posible units. ButtonCountDisplays[unit]++; this.UpdateStatus?.Invoke(this, new UpdateStatusEventArgs()); } return(wasSuccessful); }