public static void Postfix(BuildingAI __instance, BuildingInfo.Prop[] __state)
 {
     if (__state != null)
     {
         __instance.m_info.m_props = __state;
     }
 }
Exemplo n.º 2
0
        private bool IsMatch(uint index, BuildingAI bld)
        {
            switch (Matcher)
            {
            case MatchPatternKind.Category:
                Type t = bld.GetType();
                while (true)
                {
                    if (string.CompareOrdinal(Pattern, t.FullName) == 0)
                    {
                        return(true);
                    }
                    if (string.CompareOrdinal(t.FullName, typeof(BuildingAI).FullName) == 0)
                    {
                        return(false);
                    }
                    t = t.BaseType;
                }

            case MatchPatternKind.Name:
                return(string.CompareOrdinal(Pattern, PrefabCollection <BuildingInfo> .PrefabName(index)) == 0);

            case MatchPatternKind.Regex:
                return(Regex.IsMatch(PrefabCollection <BuildingInfo> .PrefabName(index), Pattern));
            }

            return(false);
        }
Exemplo n.º 3
0
    private void Effect()
    {
        List <BuildingAI> affectedBuildings = new List <BuildingAI>();
        int distanceSqrt = this.Scope * this.Scope;

        Vector2      targetPosition = (Vector2)this.transform.position;
        TilePosition targetTile     = PositionConvertor.GetActorTileIndexFromWorldPosition(this.transform.position);
        int          radius         = Mathf.CeilToInt(this.Scope / (float)Mathf.Min(ClientSystemConstants.ACTOR_TILE_MAP_TILE_SIZE.width,
                                                                                    ClientSystemConstants.ACTOR_TILE_MAP_TILE_SIZE.height));

        List <TilePosition> affectedTiles = RoundHelper.FillCircle(targetTile.Column, targetTile.Row, radius);

        foreach (TilePosition tile in affectedTiles)
        {
            if (tile.IsValidActorTilePosition())
            {
                Vector2 p   = (Vector2)PositionConvertor.GetWorldPositionFromActorTileIndex(tile);
                Vector2 dis = p - targetPosition;
                if (dis.sqrMagnitude <= distanceSqrt)
                {
                    GameObject building = BattleMapData.Instance.GetBulidingObjectFromActorObstacleMap(tile.Row, tile.Column);
                    if (building != null)
                    {
                        BuildingAI ai = building.GetComponent <BuildingAI>();
                        if (ai != null && !affectedBuildings.Contains(ai))
                        {
                            affectedBuildings.Add(ai);
                            ai.SetTarget(this.gameObject, (Vector2)this.transform.position);
                        }
                    }
                }
            }
        }
    }
Exemplo n.º 4
0
 void buildingAISelection_eventSelectedIndexChanged(UIComponent component, int value)
 {
     if (ToolsModifierControl.toolController.m_editPrefabInfo is BuildingInfo)
     {
         BuildingInfo buildingInfo = (BuildingInfo)ToolsModifierControl.toolController.m_editPrefabInfo;
         if (buildingInfo.m_buildingAI.GetType() == buildingAITypes[value])
         {
             return; // nothing is changed.
         }
         BuildingAI backup            = buildingInfo.m_buildingAI;
         GameObject currentGameObject = buildingInfo.m_buildingAI.gameObject;
         currentGameObject.AddComponent(buildingAITypes[value]);
         buildingInfo.m_buildingAI        = (BuildingAI)currentGameObject.GetComponent(buildingAITypes[value]);
         buildingInfo.m_buildingAI.m_info = backup.m_info;
         buildingInfo.m_buildingAI.m_info.m_buildingAI = buildingInfo.m_buildingAI;
         if (buildingInfo.m_buildingAI == null)
         {
             buildingInfo.m_buildingAI = backup;
         }
         else
         {
             Destroy(backup);
         }
     }
 }
Exemplo n.º 5
0
 private void deleteAllAssets()
 {
     if (LoadingFunctions.Loaded == true)
     {
         try
         {
             BuildingManager _buildingManager = Singleton <BuildingManager> .instance;
             int             _capacity        = _buildingManager.m_buildings.m_buffer.Length;
             int             id;
             for (id = 0; id < _capacity; id++)
             {
                 if ((_buildingManager.m_buildings.m_buffer[id].m_flags & Building.Flags.Created) == Building.Flags.None || (_buildingManager.m_buildings.m_buffer[id].m_flags & Building.Flags.Untouchable) != Building.Flags.None || (_buildingManager.m_buildings.m_buffer[id].m_flags & Building.Flags.BurnedDown) != Building.Flags.None || (_buildingManager.m_buildings.m_buffer[id].m_flags & Building.Flags.Demolishing) != Building.Flags.None || (_buildingManager.m_buildings.m_buffer[id].m_flags & Building.Flags.Deleted) != Building.Flags.None)
                 {
                     // Debug.Log("[RF].Hydrology  Failed Flag Test: " + _buildingManager.m_buildings.m_buffer[id].m_flags.ToString());
                 }
                 else
                 {
                     BuildingAI ai = _buildingManager.m_buildings.m_buffer[id].Info.m_buildingAI;
                     if (ai is ParkingSpaceAssetAI)
                     {
                         // Debug.Log("[RF].Hydrology  Failed AI Test: " + ai.ToString());
                         _buildingManager.ReleaseBuilding((ushort)id);
                     }
                 }
             }
         }
         catch (Exception e)
         {
             Debug.Log("[PLS].deleteAllAssets Encountered Exception " + e);
         }
     }
 }
Exemplo n.º 6
0
        internal static bool hasSpareVehicles(ushort buildingID, ref Building data, BuildingAI buildingAI)
        {
            string stats = buildingAI.GetLocalizedStats(buildingID, ref data);

            if ((stats == null) || (stats == ""))
            {
                return(false);
            }

            stats = stats.Substring(stats.LastIndexOf(':') + 2);
            Match match = new Regex(@"(\d+)\D+(\d+)").Match(stats);

            if (match.Success)
            {
                int             vehiclesInUse     = int.Parse(match.Groups[1].Value);
                int             vehiclesAvailable = int.Parse(match.Groups[2].Value);
                BuildingManager buildingManager   = Singleton <BuildingManager> .instance;

                string buildingName = buildingManager.GetBuildingName(buildingID, InstanceID.Empty);
                Utils.LogBuilding(String.Format("   - {0} - Capacity check: {1}/{2}, result: {3}", buildingName, vehiclesInUse, vehiclesAvailable, (vehiclesInUse < vehiclesAvailable)));

                return(vehiclesInUse < vehiclesAvailable);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 7
0
 public static void Postfix(BuildingAI __instance, int layer, ref float maxInstanceDistance)
 {
     if (__instance.m_info.m_prefabDataLayer == layer)
     {
         maxInstanceDistance = Mathf.Max(maxInstanceDistance, TrueLodTogglerMod.ActiveConfig.BuildingLodDistance);
     }
 }
Exemplo n.º 8
0
    public void BuildStartClear()
    {
        MainUIHide(false);
        //TweenPosition.Begin(top, 0.5f, Vector3.zero);
        //TweenPosition.Begin(bottom, 0.5f, Vector3.zero);

        if (randState >= MainDataManager.instance.buildingAIList.Count)
        {
            GameObject obj        = new GameObject();
            BuildingAI buildingAI = obj.AddComponent <BuildingAI>();

            obj.transform.parent        = buildingAIPanel.transform;
            obj.transform.localPosition = new Vector3(randState * 1080, 0, 0);

            MainDataManager.instance.buildingAIList.Add(buildingAI);
        }

        List <BuildingLayer> buildingLayerDataList = buildReadyPopupController.buildLayerSelectPopup.buildingLayerDataList;
        string randName = buildReadyPopupController.buildStartOnPopup.gameObject.transform.FindChild("InputPanel/NameInput").GetComponent <UIInput>().value;

        MainDataManager.instance.buildingAIList[randState].SetData(buildingLayerDataList, randState, randName);

        int addMoneyValue = buildReadyPopupController.buildLayerSelectPopup.totalPriceValue;

        MainDataManager.instance.MoneyChange(-addMoneyValue);

        Destroy(buildReadyPopupController.gameObject);



        ArrowReset();
    }
Exemplo n.º 9
0
    public void BuildStartClear()
    {
        TweenPosition.Begin(top, 0.5f, Vector3.zero);
        TweenPosition.Begin(bottom, 0.5f, Vector3.zero);

        if (randState >= buildingAIList.Count)
        {
            GameObject obj        = new GameObject();
            BuildingAI buildingAI = obj.AddComponent <BuildingAI>();

            obj.transform.parent        = transform.FindChild("BuildingAIPanel");
            obj.transform.localPosition = new Vector3(randState * 1080, 0, 0);

            buildingAIList.Add(buildingAI);
        }

        List <BuildingLayer> buildingLayerDataList = buildLayerSelectPopup.GetComponent <BuildLayerSelectPopup>().buildingLayerDataList;
        string randName = buildStartOnPopup.transform.FindChild("InputPanel/NameInput").GetComponent <UIInput>().value;

        buildingAIList[randState].SetData(buildingLayerDataList, randState, randName);

        MainDataManager.instance.money -= buildLayerSelectPopup.GetComponent <BuildLayerSelectPopup>().totalPriceValue;
        MoneyChange();
        Destroy(buildLayerSelectPopup);
        Destroy(buildStartOnPopup);


        ArrowReset();
    }
Exemplo n.º 10
0
        public static void CopyFields(this BuildingInfo oldInfo, string newName)
        {
            BuildingInfo newInfo = PrefabCollection <BuildingInfo> .FindLoaded(newName);

            if (newInfo == null)
            {
                return;
            }

            BuildingAI oldAI = newInfo.GetComponent <BuildingAI>();
            BuildingAI newAI = newInfo.gameObject.AddComponent <BuildingAI>().GetCopyOf(oldAI);

            Destroy(oldAI);

            newInfo.m_props = new BuildingInfo.Prop[oldInfo.m_props.Length];
            oldInfo.m_props.CopyTo(newInfo.m_props, 0);

            foreach (FieldInfo fieldInfo in newInfo.GetType().GetFields(Flags))
            {
                string fieldName = fieldInfo.Name;
                if (fieldName == "m_prefabDataIndex" || fieldName == "WidthCount" || fieldName == "LengthCount")
                {
                    continue;
                }
                object newValue = oldInfo.GetType().GetField(fieldName, Flags).GetValue(oldInfo);
                if (fieldName == "m_buildingAI")
                {
                    newValue = newAI;
                }
                newInfo.GetType().GetField(fieldName, Flags).SetValue(newInfo, newValue);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Updates the household numbers of already existing (placed/grown) residential building instances to the current prefab value.
        /// Called after updating a residential prefab's household count in order to apply changes to existing buildings.
        /// </summary>
        /// <param name="prefabName">The (raw BuildingInfo) name of the prefab</param>
        private void UpdateHouseholds(string prefabName)
        {
            // Get building manager instance.
            var instance = Singleton <BuildingManager> .instance;

            // Iterate through each building in the scene.
            for (ushort i = 0; i < instance.m_buildings.m_buffer.Length; i++)
            {
                // Get current building instance.
                Building thisBuilding = instance.m_buildings.m_buffer[i];

                // Only interested in residential buildings.
                BuildingAI thisAI = thisBuilding.Info?.GetAI() as ResidentialBuildingAI;
                if (thisAI != null)
                {
                    // Residential building; check for name match.
                    if (thisBuilding.Info.name.Equals(prefabName))
                    {
                        // Got one!  Recalculate home and visit counts.
                        int homeCount  = ((ResidentialBuildingAI)thisAI).CalculateHomeCount((ItemClass.Level)thisBuilding.m_level, new Randomizer(i), thisBuilding.Width, thisBuilding.Length);
                        int visitCount = ((ResidentialBuildingAI)thisAI).CalculateVisitplaceCount((ItemClass.Level)thisBuilding.m_level, new Randomizer(i), thisBuilding.Width, thisBuilding.Length);

                        // Apply changes via direct call to EnsureCitizenUnits prefix patch from this mod.
                        RealisticCitizenUnits.Prefix(ref thisAI, i, ref thisBuilding, homeCount, 0, visitCount, 0);
                    }
                }
            }
        }
Exemplo n.º 12
0
        public static void CalculateUnspawnPositionPostfix(BuildingAI __instance, ushort buildingID, ref Building data, ref Randomizer randomizer, CitizenInfo info, ref Vector3 position, ref Vector3 target, ref CitizenInstance.Flags specialFlags)
        {
            if (UserModSettings.Settings.Enabled)
            {
                var simulationManager = SimulationManager.instance;
                var weatherManager    = WeatherManager.instance;
                var rainPercentage    = weatherManager.m_currentRain * 100f;

                if (data.m_eventIndex == 0)
                {
                    if (data.Enterable() && rainPercentage > 0.5 && UserModSettings.Settings.Citizens_ReactToWeather)
                    {
                        __instance.CalculateSpawnPosition(buildingID, ref data, ref randomizer, info, out var spawnPosition, out var spawnTarget);

                        position = spawnPosition;
                        target   = spawnTarget;

                        specialFlags &= ~(CitizenInstance.Flags.HangAround | CitizenInstance.Flags.SittingDown);
                    }
                    else if (!data.Enterable() && (specialFlags & (CitizenInstance.Flags.HangAround | CitizenInstance.Flags.SittingDown)) == CitizenInstance.Flags.None)
                    {
                        specialFlags &= (~CitizenInstance.Flags.InsideBuilding) | CitizenInstance.Flags.HangAround;
                    }
                }
            }
        }
Exemplo n.º 13
0
 public UniqueBuildingInfo(BuildingInfo oldInfo)
 {
     m_buildingAI     = oldInfo.m_buildingAI;
     m_props          = oldInfo.m_props;
     m_placementMode  = oldInfo.m_placementMode;
     m_flattenTerrain = oldInfo.m_flattenTerrain;
     m_fullGravel     = oldInfo.m_fullGravel;
     m_fullPavement   = oldInfo.m_fullPavement;
 }
Exemplo n.º 14
0
    void ItemUseOkClick()
    {
        int        randState = transform.parent.GetComponent <MainController>().randState;
        BuildingAI data      = MainDataManager.instance.buildingAIList[randState];

        data.skyloungeOn = true;

        data.SkyloungeCheck();

        transform.parent.GetComponent <MainController>().ItemUserClose();
        Destroy(gameObject);
    }
Exemplo n.º 15
0
        public static bool RenderInstanceBuildingAIPrefix(BuildingAI __instance, RenderManager.CameraInfo cameraInfo, ushort buildingID, ref Building data, int layerMask, ref RenderManager.Instance instance)
        {
#if UseTask
            var localData     = data;
            var localInstance = instance;
            Patcher.Dispatcher.Add(() => __instance.RenderMeshes(cameraInfo, buildingID, ref localData, layerMask, ref localInstance));
#else
            __instance.RenderMeshes(cameraInfo, buildingID, ref data, layerMask, ref instance);
#endif
            __instance.RenderProps(cameraInfo, buildingID, ref data, layerMask, ref instance, renderFixed: true, renderNonfixed: true);

            return(false);
        }
Exemplo n.º 16
0
 public void EnableBuildingAI()
 {
     foreach (GameObject building in m_AttackableBuildingList)
     {
         BuildingAI ai = building.GetComponent <BuildingAI>();
         ai.enabled = true;
     }
     foreach (GameObject defenseObject in this.m_DefenseObjectList)
     {
         DefenseObjectAI ai = defenseObject.GetComponent <DefenseObjectAI>();
         ai.enabled = true;
     }
 }
Exemplo n.º 17
0
        public static void PatchEveryBuildingAI()
        {
            prefabCount = PrefabCollection <BuildingInfo> .PrefabCount();

            for (int i = 0; i < prefabCount; ++i)
            {
                prefab = PrefabCollection <BuildingInfo> .GetPrefab((uint)i);

                if (prefab != null)
                {
                    component = prefab.GetComponent <BuildingAI>();

                    if (component != null)
                    {
                        Type currentAiType = component.GetType();
                        Type newAiType     = null;

                        if (currentAiType == typeof(ResidentialBuildingAI))
                        {
                            newAiType = typeof(MyResidentialBuildingAI);
                        }
                        else if (currentAiType == typeof(CommercialBuildingAI))
                        {
                            newAiType = typeof(MyCommercialBuildingAI);
                        }
                        else if (currentAiType == typeof(IndustrialBuildingAI))
                        {
                            newAiType = typeof(MyIndustrialBuildingAI);
                        }
                        else if (currentAiType == typeof(IndustrialExtractorAI))
                        {
                            newAiType = typeof(MyIndustrialExtractorAI);
                        }
                        else if (currentAiType == typeof(OfficeBuildingAI))
                        {
                            newAiType = typeof(MyOfficeBuildingAI);
                        }

                        if (newAiType != null)
                        {
                            BuildingAI buildingAI = (BuildingAI)prefab.gameObject.AddComponent(newAiType);

                            buildingAI.m_info   = prefab;
                            prefab.m_buildingAI = buildingAI;
                            buildingAI.InitializePrefab();
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Applies settings to a BuildingInfo prefab.
        /// </summary>
        /// <param name="prefab">The prefab to modify.</param>
        /// <param name="ai">The building AI to apply.</param>
        /// <param name="aiClass">The AI class string to apply.</param>
        /// <param name="growable">Whether the prefab should be growable.</param>
        private void InitializePrefab(BuildingInfo prefab, BuildingAI ai, String aiClass, bool growable)
        {
            // Non-zero construction time important for other mods (Real Time, Real Construction) - only for private building AIs.
            if (ai is PrivateBuildingAI)
            {
                ((PrivateBuildingAI)ai).m_constructionTime = 30;
            }

            prefab.m_buildingAI        = ai;
            prefab.m_buildingAI.m_info = prefab;
            prefab.m_class             = ItemClassCollection.FindClass(aiClass);
            prefab.m_placementStyle    = growable ? ItemClass.Placement.Automatic : ItemClass.Placement.Manual;
            prefab.m_autoRemove        = false;
        }
        public static void Prefix(BuildingAI __instance, ushort buildingID, ref Building data, out BuildingInfo.Prop[] __state)
        {
            var districtId = DistrictManager.instance.GetDistrict(data.m_position);

            if (districtId != 0 && __instance.m_info.name == "L1 3x4 Detached08")
            {
                __state = __instance.m_info.m_props;
                __instance.m_info.m_props = BuildingDecorationManager.instance.SampleProps;
            }
            else
            {
                __state = null;
            }
        }
        /// <summary>
        /// Applies settings to a BuildingInfo prefab.
        /// </summary>
        /// <param name="prefab">The prefab to modify.</param>
        /// <param name="ai">The building AI to apply.</param>
        /// <param name="aiClass">The AI class string to apply.</param>
        /// <param name="growable">Whether the prefab should be growable.</param>
        private void InitializePrefab(BuildingInfo prefab, BuildingAI ai, String aiClass, bool growable)
        {
            // Non-zero construction time important for other mods (Real Time, Real Construction) - only for private building AIs.
            if (ai is PrivateBuildingAI privateBuildingAI)
            {
                privateBuildingAI.m_constructionTime = 30;
            }

            // Assign required fields.
            prefab.m_buildingAI        = ai;
            prefab.m_buildingAI.m_info = prefab;
            prefab.m_class             = ItemClassCollection.FindClass(aiClass);
            prefab.m_placementStyle    = growable ? ItemClass.Placement.Automatic : ItemClass.Placement.Manual;
            prefab.m_autoRemove        = growable || !ModSettings.warnBulldoze;
        }
Exemplo n.º 21
0
 /// <summary>
 /// Gets the medium wealth tourist value.
 /// </summary>
 /// <param name="ai">The building ai.</param>
 /// <returns>The medium wealth tourist target number.</returns>
 public static int GetMediumWealthTourists(this BuildingAI ai)
 {
     if (ai is MonumentAI)
     {
         return(((MonumentAI)ai).m_visitPlaceCount1);
     }
     else if (ai is ParkAI)
     {
         return(((ParkAI)ai).m_visitPlaceCount1);
     }
     else
     {
         return(GetIntProperty(ai, "m_visitPlaceCount1", 0));
     }
 }
Exemplo n.º 22
0
        public static bool DisplayDistrictsButton(BuildingAI ai)
        {
            switch (ai)
            {
            case MaintenanceDepotAI _:
            case MedicalCenterAI _:
            case SnowDumpAI _:
            case PostOfficeAI _:
            case TaxiStandAI _:
                return(true);

            default:
                return(false);
            }
        }
Exemplo n.º 23
0
 /// <summary>
 /// Sets the low wealth tourist value.
 /// </summary>
 /// <param name="ai">The building ai.</param>
 /// <param name="value">The low wealth tourist target number.</param>
 public static void SetLowWealthTourists(this BuildingAI ai, int value)
 {
     if (ai is MonumentAI)
     {
         ((MonumentAI)ai).m_visitPlaceCount0 = value;
     }
     else if (ai is ParkAI)
     {
         ((ParkAI)ai).m_visitPlaceCount0 = value;
     }
     else
     {
         SetIntProperty(ai, "m_visitPlaceCount0", value);
     }
 }
Exemplo n.º 24
0
 static void SimulationStep(BuildingAI _this, ushort buildingID, ref Building data)
 {
     try
     {
         _this.SimulationStep(buildingID, ref data);
     }
     catch (Exception e)
     {
         string info = $"An exception occured during BuildingAI simulation step.\nAsset: {_this.m_info.name}" +
                       $"\nBuildingID: {buildingID}\nType: {_this.GetType().Name}\nSeverity: High";
         HealkitException e2 = new HealkitException(info, e);
         e2.m_uniqueData   = _this.m_info.name;
         e2.m_supperessMsg = "Suppress similar exceptions caused by this asset";
         UIView.ForwardException(e2);
     }
 }
Exemplo n.º 25
0
        public static List <ushort> GetAllDepotsFromCity()
        {
            var               saida     = new List <ushort>();
            BuildingManager   bm        = BuildingManager.instance;
            FastList <ushort> buildings = bm.GetServiceBuildings(ItemClass.Service.PublicTransport);

            foreach (ushort i in buildings)
            {
                BuildingAI buildingAi = bm.m_buildings.m_buffer[i].Info.m_buildingAI;
                if ((bm.m_buildings.m_buffer[i].m_flags & Building.Flags.Untouchable) != 0 && ((buildingAi is DepotAI depotAi && depotAi.m_maxVehicleCount > 0) || (buildingAi is ShelterAI)))
                {
                    saida.Add(i);
                }
            }
            return(saida);
        }
Exemplo n.º 26
0
        static bool CheckUnlocking(BuildingAI _this)
        {
            try
            {
                return(_this.CheckUnlocking());
            }
            catch (Exception e)
            {
                string info = $"An exception occured during BuildingAI CheckUnlocking() method.\nAsset: {_this.m_info.name}" +
                              $"\nBuildingID: ??\nType: {_this.GetType().Name}\nSeverity: High";
                HealkitException e2 = new HealkitException(info, e);
                e2.m_uniqueData   = _this.m_info.name;
                e2.m_supperessMsg = "Suppress similar exceptions caused by this asset";
                UIView.ForwardException(e2);
            }

            return(false);
        }
        public static void Prefix(BuildingInfo __instance)
        {
            if (!Mod.IsInGame && !Mod.IsInAssetEditor)
            {
                return;
            }

            if (__instance.editorCategory == "MovableBridge")
            {
                BuildingAI oldAI = __instance.gameObject.GetComponent <BuildingAI>();
                if (oldAI is MovableBridgeAI)
                {
                    UnityEngine.Debug.Log($"MovableBridgeAI already set for ${__instance.name}");
                    return;
                }

                UnityEngine.Debug.Log($"Adding MovableBridgeAI to ${__instance.name}");

                MovableBridgeAI newAI = __instance.gameObject.AddComponent <MovableBridgeAI>();
                newAI.m_electricityConsumption = 0;
                newAI.m_waterConsumption       = 0;
                newAI.m_sewageAccumulation     = 0;
                newAI.m_garbageAccumulation    = 0;
                newAI.CopyFrom(oldAI);

                UnityEngine.Object.DestroyImmediate(oldAI);

                // disable building LOD
                __instance.m_lodObject = null;

                foreach (BuildingInfo.PathInfo pathInfo in __instance.m_paths)
                {
                    if (pathInfo.m_netInfo.editorCategory == "MovableBridge_Movable" && pathInfo.m_nodes.Length > 1)
                    {
                        if (pathInfo.m_trafficLights == null)
                        {
                            pathInfo.m_trafficLights = new BuildingInfo.TrafficLights[pathInfo.m_nodes.Length];
                        }
                        pathInfo.m_trafficLights[0] = BuildingInfo.TrafficLights.ForceOn;
                        pathInfo.m_trafficLights[pathInfo.m_trafficLights.Length - 1] = BuildingInfo.TrafficLights.ForceOn;
                    }
                }
            }
        }
Exemplo n.º 28
0
        public bool replaceBuildingAi <T>(BuildingInfo building, BuildingInfo medicalBuilding) where T : BuildingAI
        {
            Logger.logInfo(LOG_AI_REPLACEMENT, "AiReplacementHelper.replaceBuildingAi -- Checking Building: {0}", building);
            if (building == null)
            {
                Logger.logInfo(LOG_AI_REPLACEMENT, "AiReplacementHelper.replaceBuildingAi -- Null Building");
                return(false);
            }

            if (this.replacedAIs.ContainsKey(building.name))
            {
                Logger.logInfo(LOG_AI_REPLACEMENT, "AiReplacementHelper.replaceBuildingAi -- Did not replace AI for {0}, building AI has already been replaced", building.name);
                return(true);
            }


            if (building.m_buildingAI is DormitoryAi)
            {
                Logger.logInfo(LOG_AI_REPLACEMENT, "AiReplacementHelper.replaceBuildingAi -- Did not replace AI for {0}, building already running the DormitoryAi", building.name);
                return(false);
            }


            // Replace the AI
            BuildingAI originalAi = building.GetComponent <BuildingAI>();
            BuildingAI medicalAi  = medicalBuilding.GetComponent <BuildingAI>();
            T          to         = building.gameObject.AddComponent <T>();

            this.copyBuildingAIAttributes(originalAi, to, medicalAi);
            this.replacedAIs[building.name] = originalAi;
            building.m_buildingAI           = to;
            to.m_info = building;

            // Set the class as a medical building
            building.m_class = medicalBuilding.m_class;

            // Set the placement style as manual
            building.m_placementStyle = ItemClass.Placement.Manual;

            Logger.logInfo(LOG_AI_REPLACEMENT, "AiReplacementHelper.replaceBuildingAi -- Successfully replaced {0}'s AI", building.name);
            return(true);
        }
Exemplo n.º 29
0
        private void copyBuildingAIAttributes <T>(BuildingAI from, T to, BuildingAI fallback)
        {
            var baseType = typeof(T).BaseType;

            if (baseType != null)
            {
                FieldInfo[] fieldInfos = baseType.GetFields();
                if (fieldInfos == null)
                {
                    return;
                }

                foreach (FieldInfo fieldInfo in fieldInfos)
                {
                    try {
                        fieldInfo.SetValue(to, fieldInfo.GetValue(@from));
                    } catch (ArgumentException e) {
                        fieldInfo.SetValue(to, fieldInfo.GetValue(@fallback));
                    }
                }
            }
        }
Exemplo n.º 30
0
 public static bool Prefix(BuildingAI __instance, RenderManager.CameraInfo cameraInfo, ushort buildingID, ref Building data, int layerMask, ref RenderManager.Instance instance)
 {
     __instance.m_info.m_rendered = true;
     if (__instance.m_info.m_mesh != null)
     {
         BuildingAI.RenderMesh(cameraInfo, buildingID, ref data, __instance.m_info, ref instance);
     }
     if (__instance.m_info.m_subMeshes != null)
     {
         for (int i = 0; i < __instance.m_info.m_subMeshes.Length; i++)
         {
             BuildingInfo.MeshInfo meshInfo = __instance.m_info.m_subMeshes[i];
             if (((meshInfo.m_flagsRequired | meshInfo.m_flagsForbidden) & data.m_flags) == meshInfo.m_flagsRequired)
             {
                 BuildingInfoSub buildingInfoSub = meshInfo.m_subInfo as BuildingInfoSub;
                 buildingInfoSub.m_rendered = true;
                 if (buildingInfoSub.m_subMeshes != null && buildingInfoSub.m_subMeshes.Length != 0)
                 {
                     for (int j = 0; j < buildingInfoSub.m_subMeshes.Length; j++)
                     {
                         BuildingInfo.MeshInfo meshInfo2 = buildingInfoSub.m_subMeshes[j];
                         if (((meshInfo2.m_flagsRequired | meshInfo2.m_flagsForbidden) & data.m_flags) == meshInfo2.m_flagsRequired)
                         {
                             BuildingInfoSub buildingInfoSub2 = meshInfo2.m_subInfo as BuildingInfoSub;
                             buildingInfoSub2.m_rendered = true;
                             BuildingAI.RenderMesh(cameraInfo, __instance.m_info, buildingInfoSub2, meshInfo.m_matrix, ref instance);
                         }
                     }
                 }
                 else
                 {
                     BuildingAI.RenderMesh(cameraInfo, __instance.m_info, buildingInfoSub, meshInfo.m_matrix, ref instance);
                 }
             }
         }
     }
     return(false);
 }
 private void BuildingAIRenderInstance(BuildingAI buildingAI, RenderManager.CameraInfo cameraInfo, ushort buildingID, ref Building data, int layerMask, ref RenderManager.Instance instance)
 {
     BuildingAIRenderMeshes(buildingAI, cameraInfo, buildingID, ref data, layerMask, ref instance);
 }
 //
 private void BuildingAIRenderMeshes(BuildingAI buildingAI, RenderManager.CameraInfo cameraInfo, ushort buildingID, ref Building data, int layerMask, ref RenderManager.Instance instance)
 {
     if (buildingAI.m_info.m_mesh != null)
     {
         BuildingAIRenderMesh(cameraInfo, buildingID, ref data, buildingAI.m_info, ref instance);
     }
     if (buildingAI.m_info.m_subMeshes != null)
     {
         for (int i = 0; i < buildingAI.m_info.m_subMeshes.Length; i++)
         {
             BuildingInfo.MeshInfo meshInfo = buildingAI.m_info.m_subMeshes[i];
             if (((meshInfo.m_flagsRequired | meshInfo.m_flagsForbidden) & data.m_flags) == meshInfo.m_flagsRequired)
             {
                 BuildingInfoBase subInfo = meshInfo.m_subInfo;
                 BuildingAIRenderMesh(cameraInfo, buildingAI.m_info, subInfo, meshInfo.m_matrix, ref instance);
             }
         }
     }
 }