public void SetPrefab(VehicleInfo prefab)
        {
            if ((UnityEngine.Object)prefab == (UnityEngine.Object)null)
            {
                return;
            }
            PrefabAI ai = prefab.GetAI();

            if ((UnityEngine.Object)ai == (UnityEngine.Object)null)
            {
                return;
            }
            FieldInfo field = ai.GetType().GetField("m_transportInfo");

            if (field == null)
            {
                return;
            }
            TransportInfo.TransportType transportType = (field.GetValue((object)ai) as TransportInfo).m_transportType;
            if (this._firstShow)
            {
                this.FirstShowInit(transportType, prefab);
            }
            else
            {
                this.SetTransportType(transportType, prefab);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Set up prop types of vehicle props generated by Elektrix's TVP mod. Need the TVP Patch mod
        /// </summary>
        public void SetVehiclePropType(Dictionary <PropInfo, VehicleInfo> propVehicleInfoTable, PropInfo info)
        {
            propType = Asset.PropType.PropsUnsortedVehicle;
            if (!propVehicleInfoTable.ContainsKey(info))
            {
                return;
            }
            PrefabAI ai = propVehicleInfoTable[info].GetAI();

            if (ai == null)
            {
                return;
            }
            Type aiType = ai.GetType();

            if (IsMotorVehicle(aiType))
            {
                propType = Asset.PropType.PropsMoterVehicle;
            }
            else if (IsRailwayVehicle(aiType))
            {
                propType = Asset.PropType.PropsRailwayVehicle;
            }
            else if (IsAircraft(aiType))
            {
                propType = Asset.PropType.PropsAircraft;
            }
            else if (IsWatercraft(aiType))
            {
                propType = Asset.PropType.PropsWaterCraft;
            }
        }
Ejemplo n.º 3
0
        public static IBasicBuildingAIOverrides getBuildingOverrideExtension(BuildingInfo info)
        {
            PrefabAI targetAi     = info.GetAI();
            Type     targetTypeAi = targetAi.GetType();

            if (subtypes == null)
            {
                subtypes = new Dictionary <Type, Type>();
                var subclasses = SVMUtils.GetSubtypesRecursive(typeof(BasicBuildingAIOverrides <,>), typeof(SVMBuildingAIOverrideUtils));
                SVMUtils.doLog("GetOverride pré - subclasses:\r\n\t{0}", string.Join("\r\n\t", subclasses?.Select(x => x.ToString())?.ToArray() ?? new string[0]));
                foreach (Type t in subclasses)
                {
                    try
                    {
                        subtypes[t.BaseType.GetGenericArguments()[1]] = t;
                    }
                    catch (Exception e)
                    {
                        SVMUtils.doErrorLog("ERROR ADDING SUBTYPE {0}!\r\n{1}", t, subclasses);
                    }
                }
                SVMUtils.doLog("GetOverride - Classes:\r\n\t{0}", string.Join("\r\n\t", subtypes?.Select(x => x.Key.ToString() + "=>" + x.Value.ToString())?.ToArray() ?? new string[0]));
            }
            Type targetClass = null;
            IBasicBuildingAIOverrides value = null;

            if (!subtypes.ContainsKey(targetTypeAi))
            {
                foreach (var clazz in subtypes.Keys)
                {
                    if (clazz.IsAssignableFrom(targetTypeAi))
                    {
                        value = (IBasicBuildingAIOverrides)SVMUtils.GetPrivateStaticField("instance", subtypes[clazz]);
                        //SVMUtils.doLog("GetOverride - clazz = {0}; value = {1}", clazz, value);
                        if (value.AcceptsAI(targetAi))
                        {
                            targetClass = subtypes[clazz];
                            break;
                        }
                    }
                }
                SVMUtils.doLog("GetOverride - targetClass = {0} ({1})", targetClass, targetTypeAi);
                if (targetClass == null)
                {
                    return(null);
                }
            }
            else
            {
                targetClass = subtypes[targetTypeAi];
                value       = (IBasicBuildingAIOverrides)SVMUtils.GetPrivateStaticField("instance", targetClass);
            }
            //SVMUtils.doLog("GetOverride - value = {0}", value);
            return((IBasicBuildingAIOverrides)value);
        }
Ejemplo n.º 4
0
        public static void TryCopyAttributes(PrefabAI src, PrefabAI dst, bool safe = true)
        {
            var oldAIFields = src.GetType()
                              .GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
            var newAIFields = dst.GetType()
                              .GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);

            var newAIFieldDic = new Dictionary <string, FieldInfo>(newAIFields.Length);

            foreach (var field in newAIFields)
            {
                newAIFieldDic.Add(field.Name, field);
            }

            foreach (var fieldInfo in oldAIFields)
            {
                // do not copy attributes marked NonSerialized
                bool copyField = !fieldInfo.IsDefined(typeof(NonSerializedAttribute), true);

                if (safe && !fieldInfo.IsDefined(typeof(CustomizablePropertyAttribute), true))
                {
                    copyField = false;
                }

                if (copyField)
                {
                    FieldInfo newAIField;
                    newAIFieldDic.TryGetValue(fieldInfo.Name, out newAIField);
                    try
                    {
                        if (newAIField != null && newAIField.GetType().Equals(fieldInfo.GetType()))
                        {
                            newAIField.SetValue(dst, fieldInfo.GetValue(src));
                        }
                    }
                    catch (NullReferenceException)
                    {
                    }
                }
            }
        }
 public override bool AcceptsAI(PrefabAI ai) => ai.GetType() == typeof(DepotAI);
Ejemplo n.º 6
0
        /// <summary>
        /// Copies all attributes that share the same name and type from one AI object to another
        /// </summary>
        /// <param name="oldAI">Source AI instance</param>
        /// <param name="newAI">Destination AI instance</param>
        private void TryCopyAttributes(PrefabAI oldAI, PrefabAI newAI)
        {
            var oldAIFields =
                oldAI.GetType()
                    .GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic |
                               BindingFlags.FlattenHierarchy);
            var newAIFields = newAI.GetType()
                .GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic |
                           BindingFlags.FlattenHierarchy);

            var newAIFieldDic = new Dictionary<String, FieldInfo>(newAIFields.Length);
            foreach (var field in newAIFields)
            {
                newAIFieldDic.Add(field.Name, field);
            }

            foreach (var fieldInfo in oldAIFields)
            {
                if (fieldInfo.IsDefined(typeof (CustomizablePropertyAttribute), true))
                {
                    FieldInfo newAIField;
                    newAIFieldDic.TryGetValue(fieldInfo.Name, out newAIField);

                    try
                    {
                        if (newAIField.GetType().Equals(fieldInfo.GetType()))
                        {
                            newAIField.SetValue(newAI, fieldInfo.GetValue(oldAI));
                        }
                    }
                    catch (NullReferenceException)
                    {
                    }
                }
            }
        }
Ejemplo n.º 7
0
 public override bool AcceptsAI(PrefabAI ai) => typeof(DepotAI).IsAssignableFrom(ai.GetType());