示例#1
0
        /// <summary>
        /// Enters the given state information for the named state of the unit into the state table
        /// </summary>
        /// <param name="unit">ID of unit</param>
        /// <param name="stateName">Name of state</param>
        /// <param name="stateBody">Information about state</param>
        public static void AddStateOf(string unit, string stateName, StateBody stateBody)
        {

            if (!stateTable.ContainsKey(unit))
            {
                stateTable[unit] = new Dictionary<string, StateBody>();
            }
            stateTable[unit][stateName] = stateBody;
        }
示例#2
0
        public void Start()
        {
            _pet      = new Pet();
            StateBody = StateBody.Alive;

            timer.Interval = 1000;
            timer.Elapsed += ReduceLivingParameters;
            timer.Enabled  = true;
        }
示例#3
0
        internal static void RevealDocked(string parentID, int time)
        {
            List <string> children = SubplatformRecords.GetDocked(parentID);

            for (int i = 0; i < children.Count; i++)
            {
                string oneChild = children[i];
                //need initaiState and genus (!=kind)
                Reveal_EventType re = new Reveal_EventType(oneChild);



                re.InitialState    = "FullyFunctional";
                re.InitialLocation = null;
                re.Genus           = Genealogy.GetGenus(oneChild);
                re.IsWeapon        = SpeciesType.GetSpecies(UnitFacts.Data[oneChild].Species).IsWeapon;
                re.DockedToParent  = true;

                StateBody thisStartState = StatesForUnits.StateTable[Genealogy.GetBase(re.UnitID)][re.InitialState];
                re.Parameters = thisStartState.Parameters.DeepCopy();
                re.Parameters["ParentObjectID"] = parentID;

                if (time > 1)
                {
                    TimerQueueClass.Add(time, re);
                }
                else
                {
                    TimerQueueClass.SecondarySendBeforeStartup(re);
                }
                Coordinator.debugLogger.Writeline("ScenarioToQueues", "revealEvent for " + re.UnitID, "test");
                if (!re.IsWeapon)
                {
                    RevealDocked(re.UnitID, time);
                }
            }
        }
示例#4
0
        /// <summary>
        /// Determines the attributes of a state following inheritance rules
        /// </summary>
        /// <param name="name">Name of state</param>
        /// <param name="basedOn">Name of immediate predecessor in species hierarchy</param>
        /// <remarks>
        /// In collapsing we assume that the immediate predecessor has already been collapsed
        /// thereby avoiding all kinds of ugly recursion
        /// </remarks>
        static public Dictionary<string, StateBody> CollapseStates(string name, string basedOn)
        {
            List<string> excludedAttributes = new List<string>();
            excludedAttributes.Add("InitialFuelLoad");
            excludedAttributes.Add("Location");
            //"name" is the name of the thing being defined
            if (Genealogy.GetGenus(name) != basedOn)
            {
                //FullyFunctional inherits from previous FullyFunctional
                StateBody newFully = StatesForUnits.StateTable[basedOn]["FullyFunctional"].DeepCopy();
                List<string> KeyList = fullyFunctional.Parameters.GetKeys();
                foreach (string k in KeyList)
                {
                    try
                    {
                        // copy the parameters name by name
                        if (fullyFunctional.Parameters[k] == null)
                            continue;
                        String type = fullyFunctional.Parameters[k].GetType().ToString();
                        switch (type)
                        {

                            case "System.Double":
                            case "System.String":
                            case "System.Int32":
                            case "System.Boolean":
                                newFully.Parameters[k] = fullyFunctional.Parameters[k];
                                break;
                            case "Aptima.Asim.DDD.ScenarioController.LocationType":
                                newFully.Parameters[k] = ((LocationType)fullyFunctional.Parameters[k]).DeepCopy();
                                break;
                            case "Aptima.Asim.DDD.ScenarioController.VelocityType":
                                newFully.Parameters[k] = ((VelocityType)fullyFunctional.Parameters[k]).DeepCopy();
                                break;
                            case "Aptima.Asim.DDD.CommonComponents.DataTypeTools.ClassificationDisplayRulesValue":
                                newFully.Parameters[k] = fullyFunctional.Parameters[k]; //Don't need a deep copy because these won't change
                                break;

                        }

                    }
                    catch (System.Exception e)
                    {
                        throw new ApplicationException("Could not DeepCopy Parameter in StateBody", e);

                    }


                }
                /* If no sensors are defined for a unit, then it inherits
                 * Otherwise it totally overrides
                 */
                if (fullyFunctional.Sensors.Count > 0)
                {
                    newFully.Sensors.Clear();
                    for (int i = 0; i < fullyFunctional.Sensors.Count; i++)
                    {
                        newFully.Sensors.Add(fullyFunctional.Sensors[i]);
                    }
                }

                foreach (string k in fullyFunctional.Capabilities.Keys)
                {
                    newFully.Capabilities[k] = fullyFunctional.Capabilities[k].DeepCopy();
                }

                foreach (string k in fullyFunctional.Vulnerabilities.Keys)
                {
                    newFully.Vulnerabilities[k] = fullyFunctional.Vulnerabilities[k].DeepCopy();
                }
                for (int i = 0; i < fullyFunctional.Combinations.Count; i++)
                {
                    newFully.Combinations.Add(fullyFunctional.Combinations[i].DeepCopy());
                }

                /// with emitters there is strict, attribute-by-attribute, inheritance
                foreach (string attribute in fullyFunctional.Emitters.Keys)
                {
                    newFully.Emitters[attribute] = fullyFunctional.Emitters[attribute].DeepCopy();
                }
                fullyFunctional = newFully;
                // Add in states of base that are not in this species
                Dictionary<string, StateBody> parent = StatesForUnits.GetExpandedStatesOf(basedOn);
                // Other states inherit from base species
                // First, states in base that are not in this species
                foreach (string k in parent.Keys)
                {
                    if (("FullyFunctional" != k) && (!allOtherStates.ContainsKey(k)))
                    {
                        WorkStates.Add(k, parent[k]);
                    }
                }
                string[] ikeys = new string[allOtherStates.Keys.Count];
                allOtherStates.Keys.CopyTo(ikeys, 0);
                foreach (string s in ikeys) // for each state name
                {
                    StateBody tempState = fullyFunctional.DeepCopy();

                    //Do not inherit capabilities or vulnerabilities of any kind from FF
                    tempState.Vulnerabilities.Clear();
                    tempState.Combinations.Clear();
                    tempState.Capabilities.Clear();
                    // But do inherit from previous state with same name
                    if (parent.ContainsKey(s))
                    {
                        tempState.Vulnerabilities = parent[s].DeepCopyVulnerabilities();
                        tempState.Combinations = parent[s].DeepCopyCombos();
                        tempState.Capabilities = parent[s].DeepCopyCapabilities();
                    }

                    // If current state has any sensors, Current state's sensors replace all previous
                    if (allOtherStates[s].Sensors.Count > 0)
                    {
                        tempState.Sensors.Clear();
                        for (int i = 0; i < allOtherStates[s].Sensors.Count; i++)
                        {
                            tempState.Sensors.Add(allOtherStates[s].Sensors[i]);
                        }
                    }
                    List<string> allStatesKeyList = allOtherStates[s].Parameters.GetKeys();

                    foreach (string p in allStatesKeyList)
                    {
                        if (allOtherStates[s].Parameters[p] == null)
                            continue;
                        switch (allOtherStates[s].Parameters[p].GetType().ToString())
                        {
                            case "System.Double":
                            case "System.String":
                            case "System.Int32":
                            case "System.Boolean":
                                tempState.Parameters[p] = allOtherStates[s].Parameters[p];
                                break;
                            case "Aptima.Asim.DDD.ScenarioController.LocationType":
                                tempState.Parameters[p] = ((LocationType)allOtherStates[s].Parameters[p]).DeepCopy();
                                break;
                            case "Aptima.Asim.DDD.ScenarioController.VelocityType":
                                tempState.Parameters[p] = ((VelocityType)allOtherStates[s].Parameters[p]).DeepCopy();
                                break;
                            case "Aptima.Asim.DDD.CommonComponents.DataTypeTools.ClassificationDisplayRulesValue":
                                tempState.Parameters[p] = allOtherStates[s].Parameters[p];
                                break;
                        }
                    }
                    foreach (string k in allOtherStates[s].Capabilities.Keys)
                    {
                        tempState.Capabilities[k] = allOtherStates[s].Capabilities[k].DeepCopy();
                    }
                    //Do allow inheritance of vulnerabilities from previous state with same name

                    foreach (string k in allOtherStates[s].Vulnerabilities.Keys)
                    {
                        tempState.Vulnerabilities[k] = allOtherStates[s].Vulnerabilities[k].DeepCopy();
                    }
                    for (int i = 0; i < allOtherStates[s].Combinations.Count; i++)
                    {
                        tempState.Combinations.Add(allOtherStates[s].Combinations[i].DeepCopy());
                    }
                    foreach (string a in allOtherStates[s].Emitters.Keys)
                    {
                        tempState.Emitters[a] = allOtherStates[s].Emitters[a].DeepCopy();
                    }

                    allOtherStates[s] = tempState.DeepCopy();
                }
            }
            if ("" != basedOn) /// I THINK IT NEVER HAPPENS  that basedOn is ""
            {
                if ((!fullyFunctional.Parameters.ContainsKey("Icon"))
                ||
                ("" == (string)fullyFunctional.Parameters["Icon"]))
                {
                    throw new ApplicationException("Icon is required for FullyFunctional state " +
                        "in definition of " + name + " -- based on " + basedOn);
                }
            }
            Dictionary<string, StateBody> returnStates = new Dictionary<string, StateBody>();
            returnStates["FullyFunctional"] = fullyFunctional.DeepCopy();
            // Now make sure all parameters are defined for each non-dead state

            string[] keyList = new string[allOtherStates.Keys.Count];
            allOtherStates.Keys.CopyTo(keyList, 0);
            foreach (string stateName in keyList)
            {
                if ("FullyFunctional" == stateName)
                {
                    continue;
                }
                returnStates.Add(stateName, allOtherStates[stateName].DeepCopy());

                // Inherit from fully functional these things if not already defined:
                if (0 == returnStates[stateName].Capabilities.Count)
                    returnStates[stateName].Capabilities = returnStates["FullyFunctional"].Capabilities;
                if (0 == returnStates[stateName].Sensors.Count)
                    returnStates[stateName].Sensors = returnStates["FullyFunctional"].Sensors;
                if (0 == returnStates[stateName].Combinations.Count)
                    returnStates[stateName].Combinations = returnStates["FullyFunctional"].Combinations;

                /* inheriting vulnerabilities and emitters case-by-case. That means 
                First do a copy from allOtherstates and the add from FF if not defined
              */

                foreach (string vul in returnStates["FullyFunctional"].Vulnerabilities.Keys)
                    if (!(returnStates[stateName].Vulnerabilities.ContainsKey(vul)))
                        returnStates[stateName].Vulnerabilities.Add(vul, returnStates["FullyFunctional"].Vulnerabilities[vul]);
                foreach (string emit in returnStates["FullyFunctional"].Emitters.Keys)
                    if (!(returnStates[stateName].Emitters.ContainsKey(emit)))
                        returnStates[stateName].Emitters.Add(emit, returnStates["FullyFunctional"].Emitters[emit]);




                // first copy the whole state, though don't want the Parameters part
                //so replace the Parameters with the full set from FullyFunctional
                returnStates[stateName].Parameters = fullyFunctional.Parameters.DeepCopy(excludedAttributes);
                List<string> paramList = allOtherStates[stateName].Parameters.GetKeys();
                foreach (string param in paramList)
                {
                    if (allOtherStates[stateName].Parameters[param] == null)
                        continue;
                    switch (allOtherStates[stateName].Parameters[param].GetType().ToString())
                    {
                        case "System.Double":
                        case "System.String":
                        case "System.Int32":
                        case "System.Boolean":
                            returnStates[stateName].Parameters[param] = allOtherStates[stateName].Parameters[param];
                            break;
                        case "Aptima.Asim.DDD.ScenarioController.LocationType":
                            returnStates[stateName].Parameters[param] = ((LocationType)allOtherStates[stateName].Parameters[param]).DeepCopy();
                            break;
                        case "Aptima.Asim.DDD.ScenarioController.VelocityType":
                            returnStates[stateName].Parameters[param] = ((VelocityType)allOtherStates[stateName].Parameters[param]).DeepCopy();
                            break;
                        case "System.Collections.Generic.List`1[System.String]":
                            returnStates[stateName].Parameters[param] = new List<string>(((List<string>)allOtherStates[stateName].Parameters[param]).ToArray());
                            break;
                        case "Aptima.Asim.DDD.CommonComponents.DataTypeTools.ClassificationDisplayRulesValue":
                            returnStates[stateName].Parameters[param] = allOtherStates[stateName].Parameters[param];
                            break;
                        default:
                            break;
                    }
                }

            }
            return returnStates;
        }
示例#5
0
 /// <summary>
 /// Clears static tables
 /// </summary>
 static public void Clear()
 {
     allOtherStates = new Dictionary<string, StateBody>();
     fullyFunctional = new StateBody();
 }
示例#6
0
 /// <summary>
 /// Adds information about a collection of states to the working tables
 /// </summary>
 /// <param name="states">Collection of names and associated information</param>
 static public void Add(Dictionary<string, StateBody> states)
 {
     foreach (string k in states.Keys)
     {
         Add(k, states[k]);
     }
     if (!states.ContainsKey("Dead"))
     {
         StateBody deadState = new StateBody();
         Add("Dead", deadState);
     }
     allOtherStates["Dead"].Parameters["MaximumSpeed"] = 0;
 }
示例#7
0
        /// <summary>
        /// Adds theinformation about a state to the working tables
        /// </summary>
        /// <param name="state">Name of state</param>
        /// <param name="body">Information about state</param>
        static public void Add(string state, StateBody body)
        {
            if ("FullyFunctional" == state)
            {
                fullyFunctional = body;
                // Check for cases where defined defaults may be needed

            }
            else
            {
                allOtherStates[state] = body;
            }
        }