/// <summary> /// Called when an avatar completes a station, this will remove that station's states /// </summary> public void RemoveStation(ModelStation station) { if (station is HoldingStation) { // Holding stations don't need to be removed return; } WalkToStationState thisStationWalkState = mWalkToStationStates[station]; mAtStationStates.Remove(station); mWalkToStationStates.Remove(station); foreach (WalkToStationState walkState in mWalkToStationStates.Values) { walkState.RemoveTransition(thisStationWalkState); } mWalkToCenterState.RemoveTransition(thisStationWalkState); mWalkToEndGoalState.RemoveTransition(thisStationWalkState); }
/// <summary> /// Constructs a FashionModelStateMachine for the given model. Model must have needs before creating the state machine (so that the proper states for each station can be created) /// </summary> public FashionModelStateMachine(FashionModel model, FashionLevel level) { if (model == null) { throw new ArgumentNullException("model"); } mModel = model; mInactiveState = new ModelInactiveState(model); mWalkToEndGoalState = new WalkToEndGoal(model, level); mInactiveState.AddTransition(mWalkToEndGoalState); mWalkToEndGoalState.AddTransition(mInactiveState); mWalkToCenterState = new WalkToCenterState(model, level); mWalkToCenterState.AddTransition(mInactiveState); List <ModelStation> possibleStations = new List <ModelStation>(model.RequiredStations); foreach (HoldingStation station in level.HoldingStations) { possibleStations.Add(station); } foreach (ModelStation station in possibleStations) { WalkToStationState walkToStation = new WalkToStationState(model, station, level); AtStationState atStation = new AtStationState(model, station); atStation.AddTransition(mWalkToCenterState); atStation.AddTransition(mInactiveState); // All the WalkToStation states can enter the corresponding AtStation state walkToStation.AddTransition(atStation); walkToStation.AddTransition(mInactiveState); mAtStationStates.Add(station, atStation); // If the model doesn't need to stay at this station, it could go back to walk to center walkToStation.AddTransition(mWalkToCenterState); mWalkToEndGoalState.AddTransition(walkToStation); // An avatar walking to center can be redirected to a station mWalkToCenterState.AddTransition(walkToStation); mWalkToStationStates.Add(station, walkToStation); } // Make it so that avatars can be interrupted from walking to // one station by sending them to another station they need foreach (WalkToStationState stateA in mWalkToStationStates.Values) { foreach (WalkToStationState stateB in mWalkToStationStates.Values) { stateA.AddTransition(stateB); } } mWalkToCenterState.AddTransition(mWalkToEndGoalState); mModel.Clickable = mInactiveState.Clickable; this.EnterInitialState(mInactiveState); }