private int CountResource(NaturalResourceManager.Resource resource, Vector3 position, float radius, int cellDelta, out int numCells, out int totalCells, out int resultDelta, bool refresh) { UnityEngine.Debug.LogError("failed to detour CountResource()"); numCells = 0; totalCells = 0; resultDelta = 0; return(0); }
public void CreateResource(Vector2 Point, NaturalResourceManager.Resource resource) { // Recalculated resource grid var y = (int)((Point.x + 8608) / 33.625); // pixel y; 8608=(17280-32*2)/2; 33.625=17216/512 var x = (int)((Point.y + 8608) / 33.625); // pixel x; 8608=(17280-32*2)/2; 33.625=17216/512 if (x < 512 && y < 512 && x >= 0 && y >= 0) { var cellpos = x * 512 + y; switch (resource) { case NaturalResourceManager.Resource.Fertility: _naturalRM.m_naturalResources[cellpos].m_fertility = 255; _naturalRM.m_naturalResources[cellpos].m_modified = 0xff; break; case NaturalResourceManager.Resource.Sand: _naturalRM.m_naturalResources[cellpos].m_sand = 255; _naturalRM.m_naturalResources[cellpos].m_modified = 0xff; break; case NaturalResourceManager.Resource.Oil: _naturalRM.m_naturalResources[cellpos].m_oil = 255; _naturalRM.m_naturalResources[cellpos].m_modified = 0xff; break; case NaturalResourceManager.Resource.Ore: _naturalRM.m_naturalResources[cellpos].m_ore = 255; _naturalRM.m_naturalResources[cellpos].m_modified = 0xff; break; default: _naturalRM.m_naturalResources[cellpos].m_oil = 0; _naturalRM.m_naturalResources[cellpos].m_ore = 0; _naturalRM.m_naturalResources[cellpos].m_fertility = 0; _naturalRM.m_naturalResources[cellpos].m_forest = 0; _naturalRM.m_naturalResources[cellpos].m_tree = 0; _naturalRM.m_naturalResources[cellpos].m_sand = 0; _naturalRM.m_naturalResources[cellpos].m_shore = 0; break; } Temp++; } }
public int TryDumpResource(NaturalResourceManager.Resource resource, int rate, int max, Vector3 position, float radius, bool refresh) { //begin mod if (resource == Resource.Pollution) { if (Math.Abs(radius - 60.0) < 0.1) { radius = LoadingExtension.OriginalFactor * radius; } var rateFactor = LoadingExtension.OriginalFactor /** LoadingExtension.OriginalFactor*/; rate = rate * rateFactor; max = max * rateFactor; } else { radius = Mathf.Max(33.75f, (float)Singleton <SimulationManager> .instance.m_randomizer.Int32(200, 1000) * (radius * (1f / 1000f))); } //end mod int numCells; int totalCells; int resultDelta; this.CountResource(resource, position, radius, 0, out numCells, out totalCells, out resultDelta, false); rate = Mathf.Min(rate, max); //begin mod if (resource == Resource.Pollution && DEBUG_OUTPUT) { UnityEngine.Debug.Log($"#1: position={position}, radius={radius}, numCells={numCells}, totalCells={totalCells}, resultDelta={resultDelta}, rate={rate}"); } //end mod if (totalCells == 0 || rate == 0) { return(0); } int cellDelta = (int)(((long)rate << 20) / (long)totalCells); this.CountResource(resource, position, radius, cellDelta, out numCells, out totalCells, out resultDelta, refresh); //begin mod if (resource == Resource.Pollution && DEBUG_OUTPUT) { UnityEngine.Debug.Log($"#2: position={position}, cellDelta={cellDelta}, numCells={numCells}, totalCells={totalCells}, resultDelta={resultDelta}"); } //end mod return(rate); }
public override void GetNaturalResourceRadius(ushort buildingID, ref Building data, out NaturalResourceManager.Resource resource1, out Vector3 position1, out float radius1, out NaturalResourceManager.Resource resource2, out Vector3 position2, out float radius2) { resource1 = NaturalResourceManager.Resource.Water; position1 = data.CalculatePosition(this.m_waterLocationOffset); radius1 = this.m_maxWaterDistance; resource2 = NaturalResourceManager.Resource.None; position2 = data.m_position; radius2 = 0f; }
private void SelectFactory(string line, NetFactory netFactory, BuildingFactory buildingFactory, PropFactory propFactory, ResourceFactory resourceFactory, TreeFactory treeFactory, WaterFactory waterFactory) { if (!line.IsNullOrWhiteSpace()) { List <string> arguments = line.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList(); float[] points; float angle; switch (arguments[0]) { case "Resource": points = ReturnFloatsFromArg(arguments); NaturalResourceManager.Resource resource = (NaturalResourceManager.Resource)Enum .Parse(typeof(NaturalResourceManager.Resource), arguments[1], true); resourceFactory.CreateResource(new Vector2(points[0], points[1]), resource); timesResourceUsed++; break; case "Water": points = ReturnFloatsFromArg(arguments); var flowInOut = arguments[3].Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .Select(x => uint.Parse(x, CultureInfo.InvariantCulture)) .ToArray(); waterFactory.NewWaterSource(new Vector2(points[0], points[1]), flowInOut[0], flowInOut[1], flowInOut[2]); timesWaterUsed++; break; case "Net": points = ReturnFloatsFromArg(arguments); netFactory.Create(new Vector2(points[0], points[1]), new Vector2(points[2], points[3]), arguments[1]); timesNetUsed++; break; case "Building": points = ReturnFloatsFromArg(arguments); angle = float.Parse(arguments[3], CultureInfo.InvariantCulture); buildingFactory.Create(new Vector2(points[0], points[1]), angle, arguments[1]); timesBuildingUsed++; break; case "Tree": points = ReturnFloatsFromArg(arguments); treeFactory.Create(new Vector2(points[0], points[1]), arguments[1]); timesTreeUsed++; break; case "Prop": points = ReturnFloatsFromArg(arguments); angle = float.Parse(arguments[3], CultureInfo.InvariantCulture); propFactory.Create(new Vector2(points[0], points[1]), angle, arguments[1]); timesPropUsed++; break; case "Error": UnityEngine.Debug.Log(arguments[1]); break; default: UnityEngine.Debug.Log(arguments[0]); break; } } }
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); }