private static void AddResource(int x, int z, int multiplier, ref int pollution, ref int burned, ref int destroyed) { try { x = Mathf.Clamp(x, 0, 511); z = Mathf.Clamp(z, 0, 511); NaturalResourceManager.ResourceCell resourceCell = Singleton <NaturalResourceManager> .instance.m_naturalResources[z * 512 + x]; pollution += resourceCell.m_pollution * multiplier; burned += resourceCell.m_burned * multiplier; destroyed += resourceCell.m_destroyed * multiplier; } catch (Exception e) { Debug.Log("[Hide It!] NaturalResourceManagerUpdateTextureBPatch:AddResource -> Exception: " + e.Message); } }
public void DeclineTest() { ResourceIndustryDistrict.DistrictResource.getResource = () => { Random r = new Random(); NaturalResourceManager.ResourceCell[] resourcesFromMap = new NaturalResourceManager.ResourceCell[512 * 512]; for (int i = 0; i < resourcesFromMap.Length; i++) { resourcesFromMap[i].m_fertility = (byte)r.Next(0, 255); resourcesFromMap[i].m_forest = (byte)r.Next(0, 255); resourcesFromMap[i].m_oil = (byte)r.Next(0, 255); resourcesFromMap[i].m_ore = (byte)r.Next(0, 255); } return(resourcesFromMap); }; ResourceIndustryDistrict.DistrictResource.getDistricts = () => { DistrictManager.Cell[] districts = generateDistricts(); return(districts); }; ResourceIndustryDistrict.DistrictResource.getDistrictNames = () => { Array8 <District> districtNames = new Array8 <District>(128); return(districtNames); }; ResourceIndustryDistrict.DistrictResource.getDistrictNameFromId = (districtId) => { return(districtId.ToString()); }; ResourceIndustryDistrict.DistrictResource.Calculate2(); ResourceIndustryDistrict.DistrictResource.getResource = () => { Random r = new Random(); NaturalResourceManager.ResourceCell[] resourcesFromMap = new NaturalResourceManager.ResourceCell[512 * 512]; for (int i = 0; i < resourcesFromMap.Length; i++) { resourcesFromMap[i].m_fertility = (byte)r.Next(0, 2); resourcesFromMap[i].m_forest = (byte)r.Next(0, 2); resourcesFromMap[i].m_oil = (byte)r.Next(0, 2); resourcesFromMap[i].m_ore = (byte)r.Next(0, 2); } return(resourcesFromMap); }; ResourceIndustryDistrict.DistrictResource.Calculate2(); }
private void ApplyBrushResource(bool negate) { float[] brushData = this.m_toolController.BrushData; float num = this.m_brushSize * 0.5f; float num2 = 33.75f; int num3 = 512; NaturalResourceManager.ResourceCell[] naturalResources = Singleton <NaturalResourceManager> .instance.m_naturalResources; float strength = this.m_strength; Vector3 mousePosition = this.m_mousePosition; int num4 = Mathf.Max((int)((mousePosition.x - num) / num2 + (float)num3 * 0.5f), 0); int num5 = Mathf.Max((int)((mousePosition.z - num) / num2 + (float)num3 * 0.5f), 0); int num6 = Mathf.Min((int)((mousePosition.x + num) / num2 + (float)num3 * 0.5f), num3 - 1); int num7 = Mathf.Min((int)((mousePosition.z + num) / num2 + (float)num3 * 0.5f), num3 - 1); for (int i = num5; i <= num7; i++) { float num8 = (((float)i - (float)num3 * 0.5f + 0.5f) * num2 - mousePosition.z + num) / this.m_brushSize * 64f - 0.5f; int num9 = Mathf.Clamp(Mathf.FloorToInt(num8), 0, 63); int num10 = Mathf.Clamp(Mathf.CeilToInt(num8), 0, 63); for (int j = num4; j <= num6; j++) { float num11 = (((float)j - (float)num3 * 0.5f + 0.5f) * num2 - mousePosition.x + num) / this.m_brushSize * 64f - 0.5f; int num12 = Mathf.Clamp(Mathf.FloorToInt(num11), 0, 63); int num13 = Mathf.Clamp(Mathf.CeilToInt(num11), 0, 63); float num14 = brushData[num9 * 64 + num12]; float num15 = brushData[num9 * 64 + num13]; float num16 = brushData[num10 * 64 + num12]; float num17 = brushData[num10 * 64 + num13]; float num18 = num14 + (num15 - num14) * (num11 - (float)num12); float num19 = num16 + (num17 - num16) * (num11 - (float)num12); float num20 = num18 + (num19 - num18) * (num8 - (float)num9); NaturalResourceManager.ResourceCell resourceCell = naturalResources[i * num3 + j]; int num21 = (int)(255f * strength * num20); if (negate) { num21 = -num21; } this.ChangeMaterial(ref resourceCell.m_sand, ref resourceCell.m_fertility, num21); naturalResources[i * num3 + j] = resourceCell; } } Singleton <NaturalResourceManager> .instance.AreaModified(num4, num5, num6, num7); }
private static void AddResource(int x, int z, int multiplier, ref int ore, ref int oil, ref int sand, ref int fertility, ref int forest, ref int shore) { try { x = Mathf.Clamp(x, 0, 511); z = Mathf.Clamp(z, 0, 511); NaturalResourceManager.ResourceCell resourceCell = Singleton <NaturalResourceManager> .instance.m_naturalResources[z * 512 + x]; ore += resourceCell.m_ore * multiplier; oil += resourceCell.m_oil * multiplier; sand += resourceCell.m_sand * multiplier; fertility += resourceCell.m_fertility * multiplier; forest += resourceCell.m_forest * multiplier; shore += resourceCell.m_shore * multiplier; } catch (Exception e) { Debug.Log("[Hide It!] NaturalResourceManagerUpdateTexturePatch:AddResource -> Exception: " + e.Message); } }
public void PassingTest() { Assert.Equal(4, Add(2, 2)); ResourceIndustryDistrict.DistrictResource.getResource = () => { Random r = new Random(); NaturalResourceManager.ResourceCell[] resourcesFromMap = new NaturalResourceManager.ResourceCell[512 * 512]; for (int i = 0; i < resourcesFromMap.Length; i++) { resourcesFromMap[i].m_fertility = (byte)r.Next(0, 255); resourcesFromMap[i].m_forest = (byte)r.Next(0, 255); resourcesFromMap[i].m_oil = (byte)r.Next(0, 255); resourcesFromMap[i].m_ore = (byte)r.Next(0, 255); } return(resourcesFromMap); }; ResourceIndustryDistrict.DistrictResource.getDistricts = () => { DistrictManager.Cell[] districts = generateDistricts(); return(districts); }; ResourceIndustryDistrict.DistrictResource.getDistrictNames = () => { Array8 <District> districtNames = new Array8 <District>(128); return(districtNames); }; ResourceIndustryDistrict.DistrictResource.getDistrictNameFromId = (districtId) => { return(districtId.ToString()); }; ResourceIndustryDistrict.DistrictResource.Calculate2(); ResourceIndustryDistrict.DistrictResource.Calculate2(); ResourceIndustryDistrict.DistrictResource.Calculate2(); ResourceIndustryDistrict.DistrictResource.districtResourceList.Sort(new LineComparer("Size", true, false)); }
public override void OnLevelLoaded(LoadMode mode) { if (mode != LoadMode.LoadGame && mode != LoadMode.NewGame && mode != LoadMode.NewMap && mode != LoadMode.LoadMap) { return; } _mode = mode; buildingWindowGameObject = new GameObject("buildingWindowObject"); var view = UIView.GetAView(); this.buildingWindow = buildingWindowGameObject.AddComponent <ResourceIndustryDistrictWindow>(); this.buildingWindow.transform.parent = view.transform; this.buildingWindow.position = new Vector3(300, 122); this.buildingWindow.Hide(); UITabstrip strip = null; if (mode == LoadMode.NewGame || mode == LoadMode.LoadGame) { strip = ToolsModifierControl.mainToolbar.component as UITabstrip; } else { strip = UIView.Find <UITabstrip>("MainToolstrip"); } buttonObject = UITemplateManager.GetAsGameObject("MainToolbarButtonTemplate"); buttonObject2 = UITemplateManager.GetAsGameObject("ScrollablePanelTemplate"); menuButton = strip.AddTab("ResourceIndustryDistrict", buttonObject, buttonObject2, new Type[] { }) as UIButton; string sprite = "ToolbarIconDistrictPressed"; menuButton.normalFgSprite = sprite; menuButton.focusedFgSprite = sprite; menuButton.hoveredFgSprite = sprite; menuButton.pressedFgSprite = sprite; menuButton.disabledFgSprite = sprite; menuButton.tooltip = "RDI"; menuButton.eventClick += uiButton_eventClick; DistrictResource.getResource = () => { NaturalResourceManager.ResourceCell[] resourcesFromMap = new NaturalResourceManager.ResourceCell[NaturalResourceManager.instance.m_naturalResources.Length]; Array.Copy(NaturalResourceManager.instance.m_naturalResources, resourcesFromMap, resourcesFromMap.Length); return(resourcesFromMap); }; DistrictResource.getDistricts = () => { DistrictManager.Cell[] districts = DistrictManager.instance.m_districtGrid; return(districts); }; DistrictResource.getDistrictNames = () => { Array8 <District> districtNames = DistrictManager.instance.m_districts; return(districtNames); }; DistrictResource.getDistrictNameFromId = (districtId) => { return(DistrictManager.instance.GetDistrictName(districtId)); }; }
private int CountResource(NaturalResourceManager.Resource resource, Vector3 position, float radius, int cellDelta, out int numCells, out int totalCells, out int resultDelta, bool refresh) { float num1 = 33.75f; int num2 = 512; radius += num1 * 0.51f; int minX = Mathf.Max((int)(((double)position.x - (double)radius) / (double)num1 + (double)num2 * 0.5), 0); int minZ = Mathf.Max((int)(((double)position.z - (double)radius) / (double)num1 + (double)num2 * 0.5), 0); int maxX = Mathf.Min((int)(((double)position.x + (double)radius) / (double)num1 + (double)num2 * 0.5), num2 - 1); int maxZ = Mathf.Min((int)(((double)position.z + (double)radius) / (double)num1 + (double)num2 * 0.5), num2 - 1); int num3 = 0; numCells = 0; totalCells = 0; resultDelta = 0; int deltaBuffer = Singleton <SimulationManager> .instance.m_randomizer.Bits32(20); if (cellDelta < 0) { deltaBuffer = -deltaBuffer; } byte num4 = 0; if (cellDelta != 0) { num4 = resource < NaturalResourceManager.Resource.Pollution ? (byte)1 : (byte)2; } for (int index1 = minZ; index1 <= maxZ; ++index1) { float num5 = (float)((double)index1 - (double)num2 * 0.5 + 0.5) * num1 - position.z; for (int index2 = minX; index2 <= maxX; ++index2) { float num6 = (float)((double)index2 - (double)num2 * 0.5 + 0.5) * num1 - position.x; if ((double)num5 * (double)num5 + (double)num6 * (double)num6 < (double)radius * (double)radius || (double)radius == 0.0) { NaturalResourceManager.ResourceCell resourceCell = this.m_naturalResources[index1 * num2 + index2]; totalCells = totalCells + 1; int num7 = 0; switch (resource) { case NaturalResourceManager.Resource.Ore: //begin mod num7 = CountAndKeep(ref resourceCell.m_ore, ref deltaBuffer, ref resultDelta, cellDelta); //end mod break; case NaturalResourceManager.Resource.Sand: num7 = CountAndModify(ref resourceCell.m_sand, ref deltaBuffer, ref resultDelta, cellDelta); break; case NaturalResourceManager.Resource.Oil: //begin mod num7 = CountAndKeep(ref resourceCell.m_oil, ref deltaBuffer, ref resultDelta, cellDelta); //end mod break; case NaturalResourceManager.Resource.Fertility: num7 = CountAndKeep(ref resourceCell.m_fertility, ref deltaBuffer, ref resultDelta, cellDelta); break; case NaturalResourceManager.Resource.Forest: num7 = CountAndKeep(ref resourceCell.m_forest, ref deltaBuffer, ref resultDelta, cellDelta); break; case NaturalResourceManager.Resource.Pollution: num7 = CountAndModify(ref resourceCell.m_pollution, ref deltaBuffer, ref resultDelta, cellDelta); break; case NaturalResourceManager.Resource.Burned: num7 = CountAndModify(ref resourceCell.m_burned, ref deltaBuffer, ref resultDelta, cellDelta); break; case NaturalResourceManager.Resource.Destroyed: num7 = CountAndModify(ref resourceCell.m_destroyed, ref deltaBuffer, ref resultDelta, cellDelta); break; } if (num7 != 0) { numCells = numCells + 1; num3 += num7; } if (cellDelta != 0) { if (!refresh) { resourceCell.m_modified |= num4; } this.m_naturalResources[index1 * num2 + index2] = resourceCell; } } } } if (refresh && cellDelta != 0) { if (resource >= NaturalResourceManager.Resource.Pollution) { this.AreaModifiedB(minX, minZ, maxX, maxZ); } else { this.AreaModified(minX, minZ, maxX, maxZ); } } return(num3); }
private static void TreesModified(NaturalResourceManager nrm, Vector3 position) { unsafe { int num = Mathf.Clamp((int)((double)position.x / 33.75 + 256), 0, 511); int num1 = Mathf.Clamp((int)((double)position.z / 33.75 + 256), 0, 511); float single = (float)((double)(num - 256) * 33.75); float single1 = (float)((double)(num1 - 256) * 33.75); float single2 = (float)((double)(num + 1 - 256) * 33.75); float single3 = (float)((double)(num1 + 1 - 256) * 33.75); int num2 = Mathf.Max((int)(single / 32f + 270f), 0); int num3 = Mathf.Max((int)(single1 / 32f + 270f), 0); int num4 = Mathf.Min((int)(single2 / 32f + 270f), 539); int num5 = Mathf.Min((int)(single3 / 32f + 270f), 539); TreeManager treeManager = Singleton <TreeManager> .instance; int num6 = 0; int growState = 0; for (int i = num3; i <= num5; i++) { for (int j = num2; j <= num4; j++) { uint mTreeGrid = treeManager.m_treeGrid[i * 540 + j]; int num7 = 0; while (mTreeGrid != 0) { if ((treeManager.m_trees.m_buffer[mTreeGrid].m_flags & 3) == 1) { Vector3 vector3 = treeManager.m_trees.m_buffer[mTreeGrid].Position; if (vector3.x >= single && vector3.z >= single1 && vector3.x <= single2 && vector3.z <= single3) { num6 = num6 + 15; growState = growState + treeManager.m_trees.m_buffer[mTreeGrid].GrowState; } } mTreeGrid = treeManager.m_trees.m_buffer[mTreeGrid].m_nextGridTree; int num8 = num7 + 1; num7 = num8; if (num8 < LimitTreeManager.Helper.TreeLimit) { continue; } CODebugBase <LogChannel> .Error(LogChannel.Core, string.Concat("Invalid list detected!\n", Environment.StackTrace)); break; } } } byte num9 = (byte)Mathf.Min(num6 * 4, 255); byte num10 = (byte)Mathf.Min(growState * 4, 255); NaturalResourceManager.ResourceCell mNaturalResources = nrm.m_naturalResources[num1 * 512 + num]; if (num9 != mNaturalResources.m_forest || num10 != mNaturalResources.m_tree) { bool mForest = num9 != mNaturalResources.m_forest; mNaturalResources.m_forest = num9; mNaturalResources.m_tree = num10; nrm.m_naturalResources[num1 * 512 + num] = mNaturalResources; if (mForest) { nrm.AreaModified(num, num1, num, num1); } } } }