private void BuildingProgressBarClick(UIComponent progressBar, UIMouseEventParameter eventParam) { ushort buildingID = this.getSelectedBuildingID(); Level buildingLockLevel = Buildings.getLockLevel(buildingID); Level progressBarLevel = this.getProgressBarLevel(progressBar); if (buildingLockLevel == Level.None) { Buildings.add(buildingID, progressBarLevel); this.updateBuildingView(buildingID, progressBarLevel); #if DEBUG Logger.Info("building lock level (" + buildingID + "): " + progressBarLevel); #endif } else { if (buildingLockLevel == progressBarLevel) { Buildings.remove(buildingID); this.updateBuildingView(buildingID, Level.None); #if DEBUG Logger.Info("building lock level (" + buildingID + "): none"); #endif } else { Buildings.update(buildingID, progressBarLevel); this.updateBuildingView(buildingID, progressBarLevel); #if DEBUG Logger.Info("building lock level (" + buildingID + "): " + progressBarLevel); #endif } } }
private void updateBuildingView() { ushort buildingID = this.getSelectedBuildingID(); Level buildingLockLevel = Buildings.getLockLevel(buildingID); this.updateBuildingView(buildingID, buildingLockLevel); }
public void OnSaveData() { #if DEBUG Logger.Info("Try to save mod data"); #endif try { if (this.sd != null) { byte[] building_data = Buildings.toByteArray(); if (building_data != null) { this.sd.SaveData(BUILDINGS_DATA_ID, building_data); } byte[] district_data = Districts.toByteArray(); if (district_data != null) { this.sd.SaveData(DISTRICT_DATA_ID, district_data); } #if DEBUG Logger.Info("Saving was successful"); #endif } else { Logger.Warning("Serializer is null, saving mod data not possible"); } } catch (Exception e) { Logger.Error("Error during save mod data :" + e.Message); } }
public static void update(ushort buildingID, Level level) { lock (lockBuilding) { buildings[buildingID] = level; } Buildings.ForceLevelBuilding(buildingID, level); }
public void OnLoadData() { #if DEBUG Logger.Info("Try to load mod data"); #endif try { if (this.sd != null) { byte[] building_data = this.sd.LoadData(BUILDINGS_DATA_ID); Buildings.fromByteArray(building_data); byte[] district_data = this.sd.LoadData(DISTRICT_DATA_ID); Districts.fromByteArray(district_data); #if DEBUG Logger.Info("Loading was successful"); Buildings.dump(); Districts.dump(); #endif } else { Logger.Warning("Serializer is null, loading mod data not possible"); } } catch (Exception e) { Logger.Error("Error during load mod data :" + e.Message); } }
public static void add(ushort buildingID, Level level) { lock (lockBuilding) { buildings.Add(buildingID, level); } Buildings.ForceLevelBuilding(buildingID, level); }
private Level determineLockLevel(ushort buildingID) { Level buildingLockLevel = Buildings.getLockLevel(buildingID); if (buildingLockLevel != Level.None) { return(buildingLockLevel); } else { Byte districtID = Buildings.getDistrictID(buildingID); int buildingType = Buildings.getBuildingType(buildingID); Level districtLockLevel = Districts.getLockLevels(districtID)[buildingType]; if (districtLockLevel != Level.None) { return(districtLockLevel); } else { return(Level.None); } } }
private void bulldozeBuilding(ushort buildingID) { try { BuildingManager buildingManager = Singleton <BuildingManager> .instance; Building building = buildingManager.m_buildings.m_buffer[buildingID]; BuildingInfo buildingInfo = building.Info; buildingManager.ReleaseBuilding(buildingID); Buildings.remove(buildingID); /* * EffectInfo effect = buildingManager.m_properties.m_bulldozeEffect; * if (effect != null) { * InstanceID instance = new InstanceID(); * Vector3 pos = building.m_position; * float angle = building.m_angle; * int length = building.Length; * * EffectInfo.SpawnArea spawnArea = new EffectInfo.SpawnArea( * Matrix4x4.TRS(Building.CalculateMeshPosition(buildingInfo, pos, angle, length), * Building.CalculateMeshRotation(angle), Vector3.one), buildingInfo.m_lodMeshData); * * AudioGroup nullAudioGroup = new AudioGroup(0, * new SavedFloat("NOTEXISTINGELEMENT", Settings.gameSettingsFile, 0, false)); * Singleton<EffectManager>.instance.DispatchEffect(effect, instance, spawnArea, * Vector3.zero, 0.0f, 1f, nullAudioGroup); * } */ } catch (Exception e) { Logger.Error("Error during bulldozing building :" + e.Message); } }
// Method based on UpgradeBuilding from BuildingManager public static bool ForceLevelBuilding(ushort buildingID, Level level) { BuildingManager instance = Singleton <BuildingManager> .instance; if (buildingID == 0 || (instance.m_buildings.m_buffer[(int)buildingID].m_flags & Building.Flags.Created) == Building.Flags.None) { return(false); } BuildingInfo info = instance.m_buildings.m_buffer[(int)buildingID].Info; if (info == null) { return(false); } if ((Level)info.m_class.m_level == level) { return(false); } BuildingInfo upgradeInfo = Buildings.GetInfoForLevel(buildingID, ref instance.m_buildings.m_buffer[(int)buildingID], (ItemClass.Level)level); if (upgradeInfo == null || upgradeInfo == info) { return(false); } instance.UpdateBuildingInfo(buildingID, upgradeInfo); upgradeInfo.m_buildingAI.BuildingUpgraded(buildingID, ref instance.m_buildings.m_buffer[(int)buildingID]); int constructionCost = upgradeInfo.m_buildingAI.GetConstructionCost(); Singleton <EconomyManager> .instance.FetchResource(EconomyManager.Resource.Construction, constructionCost, upgradeInfo.m_class); int num = 0; while (buildingID != 0) { BuildingInfo info2 = instance.m_buildings.m_buffer[(int)buildingID].Info; if (info2 != null) { Vector3 position = instance.m_buildings.m_buffer[(int)buildingID].m_position; float angle = instance.m_buildings.m_buffer[(int)buildingID].m_angle; BuildingTool.DispatchPlacementEffect(info2, 0, position, angle, info2.m_cellWidth, info2.m_cellLength, false, false); } buildingID = instance.m_buildings.m_buffer[(int)buildingID].m_subBuilding; if (++num > 49152) { CODebugBase <LogChannel> .Error(LogChannel.Core, "Invalid list detected!\n" + Environment.StackTrace); break; } } return(true); }
private Level controlLevelUp(Level targetLevel, Level currentLevel, ushort buildingID) { Level lockLevel = this.determineLockLevel(buildingID); if (lockLevel != Level.None) { #if DEBUG Logger.Info("OnCalculateResidentialLevelUp: building: " + buildingID + "\n lock level is: " + lockLevel + "\n current level is: " + currentLevel + "\n target level is: " + targetLevel); #endif if (lockLevel > targetLevel && Settings.preventLowLandValue && (Singleton <BuildingManager> .instance.m_buildings.m_buffer[(int)buildingID].m_problems & (Notification.Problem.LandValueLow | Notification.Problem.TooFewServices)) != (Notification.Problem) 0) { Buildings.LateClearProblemForBuilding(buildingID); } if (currentLevel > lockLevel) { #if DEBUG Logger.Info("Building level too high: " + buildingID); #endif if (Settings.allowDowngrade) { Buildings.ForceLevelBuilding(buildingID, lockLevel); } else { this.bulldozeBuilding(buildingID); } //TODO: b.m_flags = Building.Flags.Downgrading; ? } if (targetLevel > lockLevel && targetLevel > currentLevel) { #if DEBUG Logger.Info("Prevent building from leveling up: " + buildingID); #endif return(lockLevel); } } return(targetLevel); }
private void updateBuildingView(ushort buildingID, Level buildingLockLevel) { if (buildingLockLevel != Level.None) { this.updateProgressPanel(this.panelBuildingProgress, buildingLockLevel, false); } else { Byte districtID = Buildings.getDistrictID(buildingID); int buildingType = Buildings.getBuildingType(buildingID); Level districtLockLevel = Districts.getLockLevels(districtID)[buildingType]; if (districtLockLevel != Level.None) { this.updateProgressPanel(this.panelBuildingProgress, districtLockLevel, true); } else { this.updateProgressPanel(this.panelBuildingProgress, Level.None, false); } } }
public override void OnAfterSimulationFrame() { Buildings.ClearProblems(); }