public Reveal_EventType(pRevealType rEvent) : base(rEvent.UnitID, rEvent.Time) { if (!NameLists.unitNames.ContainsKey(rEvent.UnitID)) throw new ApplicationException("Cannot reveal unknown unit " + rEvent.UnitID); if (null != rEvent.EngramRange) { this.Range = new EngramRange(rEvent.EngramRange); } this.initialLocation = new LocationType(rEvent.InitialLocation.X, rEvent.InitialLocation.Y, rEvent.InitialLocation.Z); this.initialState = rEvent.InitialState; if ("" == this.initialState) { this.initialState = "FullyFunctional"; } else { if (!StatesForUnits.UnitHasState(rEvent.UnitID, rEvent.InitialState)) throw new ApplicationException("Cannot reveal " + rEvent.UnitID + " in initial state " + rEvent.InitialState + ", as state doesn't exist."); } // this.Parameters = new ObjectDictionary(rEvent.StartupParameters); StateBody thisStartState = StatesForUnits.StateTable[Genealogy.GetBase(this.UnitID)][this.initialState]; Parameters = thisStartState.Parameters.DeepCopy(); ObjectDictionary incomingParameters = new ObjectDictionary(rEvent.StartupParameters); List<string> KeyList = incomingParameters.GetKeys(); foreach (string k in KeyList) { Parameters[k] = incomingParameters[k]; } string initialTag = ""; if ((null != rEvent.InitialTag)) initialTag = rEvent.InitialTag; Parameters["InitialTag"] = initialTag; }
/// <summary> /// Retrieves a reveal command from the scenario /// </summary> public override pRevealType pGetReveal() { string unitID = "Unknown object"; string initialTag = ""; pRevealType rEvent; try { string initialState = ""; Dictionary<string, object> startupParameters; reader.Read();// pass the RevealEvent tag unitID = pGetString(); pEngramRange engramRange = null; if ("EngramRange" == reader.Name) { engramRange = pGetEngramRange(); } int time = pGetInt(); pLocationType initialLocation = pGetLocation(); if ("InitialState" == reader.Name) { initialState = pGetString(); } if ("InitialTag" == reader.Name) initialTag = pGetString(); if ("StartupParameters" == reader.Name) { startupParameters = pGetParameters(); } else { startupParameters = new Dictionary<string, object>(); } reader.ReadEndElement(); rEvent = new pRevealType(unitID, engramRange, time, initialLocation, initialState, startupParameters); rEvent.InitialTag = initialTag; } catch (System.Exception e) { throw new ApplicationException("Error reading Reveal command for " + unitID + ": ", e); } return rEvent; }