Example #1
0
        public HappeningCompletionType(pHappeningCompletionType h)
            : base(h.Unit)
        {
            object performer;
            this.isAction = false;
            this.isStateChange = false;
            this.Range = null;
            if (null != h.EngramRange)
            {
                this.Range = new EngramRange(h.EngramRange);
            }
            if ("" != h.Action)
            {
                this.isAction = true;
            }
            this.action = h.Action;
            if ("" != h.NewState)
            {
                this.isStateChange = true;
            }
            this.newState = h.NewState;
            for (int doThis = 0; doThis < h.DoThisList.Count; doThis++)
            {
                performer = h.DoThisList[doThis];
                switch (performer.GetType().Name.ToString())
                {
                    case "pReiterateType":
                        ReiterateType rt = new ReiterateType((pReiterateType)performer);
                        this.holdsReiteration = true;
                        this.Range = rt.Range;
                        this.Add(rt.ReiterateList);
                        /// when this is called the top element has already been shifted to the end
                        //this.UnitID = rt.ReiterateList[rt.ReiterateList.Count - 1].UnitID;
                        break;
                    case "pMoveType":
                        this.doThisList.Add(new Move_EventType((pMoveType)performer));
                        /*
                         * this is not needed because  in ScenarioEvent constructor(?)
                                              if (!this.AllUnits.Contains(((pMoveType)performer).UnitID))
                                              {
                                                  this.AllUnits.Add(((pMoveType)performer).UnitID);
                                              }
                                              */
                        break;

                    case "pRevealType":
                        Reveal_EventType r = new Reveal_EventType((pRevealType)performer);
                        r.Genus = Genealogy.GetGenus(r.UnitID);
                        this.doThisList.Add(r);
                        break;
                    case "pStateChangeType":
                        this.doThisList.Add(new StateChangeEvent((pStateChangeType)performer));
                        break;
                    case "pTransferType":
                        this.doThisList.Add(new TransferEvent((pTransferType)performer));
                        break;
                    case "pLaunchType":
                        this.doThisList.Add(new LaunchEventType((pLaunchType)performer));
                        if (!this.AllUnits.Contains(((pLaunchType)performer).Child))
                        {
                            this.AllUnits.Add(((pLaunchType)performer).Child);
                        }
                        break;
                    case "pWeaponLaunchType":
                        this.doThisList.Add(new WeaponLaunchEventType((pWeaponLaunchType)performer));
                        if (!this.AllUnits.Contains(((pWeaponLaunchType)performer).Child))
                        {
                            this.AllUnits.Add(((pWeaponLaunchType)performer).Child);
                        }
                        break;
                    case "pChangeEngramType":
                        this.doThisList.Add(new ChangeEngramType((pChangeEngramType)performer));
                        break;
                    case "pRemoveEngramType":
                        this.doThisList.Add(new RemoveEngramEvent((pRemoveEngramType)performer));
                        break;
                    case "pFlushEventType":
                        this.doThisList.Add(new FlushEvents((pFlushEventsType)performer));
                        break;
                    case "pHappeningCompletionType":
                        this.doThisList.Add(new HappeningCompletionType((pHappeningCompletionType)performer));
                        break;
                    default:
                        Coordinator.debugLogger.LogError("Senario reader", "Unknown happening event type for " + performer.ToString());
                        break;
                }
            }
        }
Example #2
0
        public override pHappeningCompletionType pGetHappeningCompletion()
        {
            string unitID = "Unknown object";
            string action = "", newState = "";
            pHappeningCompletionType returnValue;
            //object eventToPerform;

            try
            {
                reader.Read();
                unitID = pGetString();
                pEngramRange engramRange = null;
                if ("EngramRange" == reader.Name)
                {
                    engramRange = pGetEngramRange();
                }
                if ("Action" == reader.Name)
                {
                    action = pGetString();
                }
                else if ("NewState" == reader.Name)
                {
                    newState = pGetString();
                }
                returnValue = new pHappeningCompletionType(unitID, engramRange, action, newState);
                List<object> doThisList = pGetDoThisList();
                for (int i = 0; i < doThisList.Count; i++)
                    returnValue.AddAction(doThisList[i]);
                /*
                while ("DoThis" == reader.Name)
                {
                    reader.Read(); // bypass the DoThis tag
                    switch (reader.Name)
                    {
                        case "Move_Event":
                            eventToPerform = pGetMove();
                            break;
                        case "Reveal_Event":
                            eventToPerform = pGetReveal();
                            break;
                        case "StateChange_Event":
                            eventToPerform = pGetStateChange();
                            break;
                        case "Transfer_Event":
                            eventToPerform = pGetTransfer();
                            break;
                        case "Launch_Event":
                            eventToPerform = pGetLaunch();
                            break;
                        case "ChangeEngram":
                            eventToPerform = pGetChangeEngram();
                            break;
                        case "RemoveEngram":
                            eventToPerform = pGetRemoveEngram();
                            break;
                        case "FlushEvents":
                            eventToPerform = pGetFlushEventsType();
                            break;


                        default:
                            //                    Coordinator.debugLogger.WriteLine("Unknown Happening Complete Event: " + reader.Name);
                            eventToPerform = null;
                            break;
                    }
                    if (null != eventToPerform)
                    {
                        returnValue.AddAction(eventToPerform);
                    }
                
                    reader.ReadEndElement(); //Pass the </DoThis>
                } */
                reader.ReadEndElement(); // Pass the </Completion_Event>
            }
            catch (System.Exception e)
            {
                throw new ApplicationException("Error reading Happening command for unit named " +
                    unitID + ": ", e);
            }

            return returnValue;
        }