diff --git a/OpenRA.Server/Server.cs b/OpenRA.Server/Server.cs index c0adf90611..cbf8cf2d9f 100644 --- a/OpenRA.Server/Server.cs +++ b/OpenRA.Server/Server.cs @@ -24,7 +24,7 @@ namespace OpenRA.Server const int DownloadChunkInterval = 20000; const int DownloadChunkSize = 16384; - public static void Main(string[] args) + public static int Main(string[] args) { if (args.Length > 0) defaultMods = args; lobbyInfo = new Session(); @@ -39,10 +39,10 @@ namespace OpenRA.Server listener.Start(); Console.WriteLine("Server started."); } - catch (Exception e) + catch (Exception) { Console.WriteLine("Server failed to start."); - Environment.Exit(1); + return 1; } for (; ; ) diff --git a/OpenRa.Game/Chrome.cs b/OpenRa.Game/Chrome.cs index 018cc82eef..fee25e94b0 100644 --- a/OpenRa.Game/Chrome.cs +++ b/OpenRa.Game/Chrome.cs @@ -356,10 +356,8 @@ namespace OpenRa while (!PaletteAvailable(newIndex) && newIndex != (int)Game.world.LocalPlayer.PaletteIndex) newIndex = (newIndex + d) % Player.PlayerColors.Count(); - Game.world.Minimap.InvalidateSpawnPoints(); Game.IssueOrder( Order.Chat("/pal " + newIndex)); - } void CycleRace(bool left) diff --git a/OpenRa.Game/GameRules/GeneralInfo.cs b/OpenRa.Game/GameRules/GeneralInfo.cs index ea8fa66894..2f0207d545 100644 --- a/OpenRa.Game/GameRules/GeneralInfo.cs +++ b/OpenRa.Game/GameRules/GeneralInfo.cs @@ -46,9 +46,6 @@ namespace OpenRa.GameRules public readonly float BuildupTime = 0; public readonly int GemValue = 0; public readonly int GoldValue = 0; - public readonly float GrowthRate = 0; - public readonly bool OreGrows = true; - public readonly bool OreSpreads = true; public readonly float OreTruckRate = 0; public readonly bool SeparateAircraft = true; public readonly float SurvivorRate = 0; @@ -90,7 +87,6 @@ namespace OpenRa.GameRules public readonly bool FineDiffControl = false; /* OpenRA-specific */ - public readonly float OreChance = 0; /* chance of spreading to a particular eligible cell */ public readonly int LowPowerSlowdown = 3; /* build time multiplier */ } } diff --git a/OpenRa.Game/Graphics/Minimap.cs b/OpenRa.Game/Graphics/Minimap.cs index a2f3cbe934..5067dc13f3 100644 --- a/OpenRa.Game/Graphics/Minimap.cs +++ b/OpenRa.Game/Graphics/Minimap.cs @@ -17,7 +17,7 @@ namespace OpenRa.Graphics SpriteRenderer rgbaRenderer; LineRenderer lineRenderer; Sprite sprite, mapOnlySprite, mapSpawnPointSprite; - Bitmap terrain, oreLayer, spawnPointsLayer; + Bitmap terrain, oreLayer; Rectangle bounds; Sprite ownedSpawnPoint; @@ -74,7 +74,6 @@ namespace OpenRa.Graphics static Color shroudColor; public void InvalidateOre() { oreLayer = null; } - public void InvalidateSpawnPoints() { spawnPointsLayer = null; } public static Bitmap RenderTerrainBitmap(Map map, TileSet tileset) { diff --git a/OpenRa.Game/OpenRa.Game.csproj b/OpenRa.Game/OpenRa.Game.csproj index bb1abf8cb2..646de1c6ea 100644 --- a/OpenRa.Game/OpenRa.Game.csproj +++ b/OpenRa.Game/OpenRa.Game.csproj @@ -118,6 +118,7 @@ + diff --git a/OpenRa.Game/Ore.cs b/OpenRa.Game/Ore.cs index 34318cd38b..c671ed7330 100644 --- a/OpenRa.Game/Ore.cs +++ b/OpenRa.Game/Ore.cs @@ -8,14 +8,13 @@ namespace OpenRa { public static void AddOre(this Map map, int i, int j) { - if (Rules.General.OreSpreads) - if (map.ContainsOre(i, j) && map.MapTiles[i, j].density < 12) - map.MapTiles[i, j].density++; - else if (map.MapTiles[i, j].overlay == 0xff) - { - map.MapTiles[i, j].overlay = ChooseOre(); - map.MapTiles[i, j].density = 1; - } + if (map.ContainsOre(i, j) && map.MapTiles[i, j].density < 12) + map.MapTiles[i, j].density++; + else if (map.MapTiles[i, j].overlay == 0xff) + { + map.MapTiles[i, j].overlay = ChooseOre(); + map.MapTiles[i, j].density = 1; + } } public static void DestroyOre(this Map map, int i, int j) @@ -37,48 +36,49 @@ namespace OpenRa < double.PositiveInfinity; } + public static void SpreadOre(this World world, Random r, float chance) + { + var map = world.Map; + + var mini = map.XOffset; var maxi = map.XOffset + map.Width; + var minj = map.YOffset; var maxj = map.YOffset + map.Height; + + /* phase 1: grow into neighboring regions */ + var newOverlay = new byte[128, 128]; + for (int j = minj; j < maxj; j++) + for (int i = mini; i < maxi; i++) + { + newOverlay[i, j] = 0xff; + if (!map.HasOverlay(i, j) + && r.NextDouble() < chance + && map.GetOreDensity(i, j) > 0 + && world.OreCanSpreadInto(i, j)) + newOverlay[i, j] = ChooseOre(); + } + + for (int j = minj; j < maxj; j++) + for (int i = mini; i < maxi; i++) + if (newOverlay[i, j] != 0xff) + map.MapTiles[i, j].overlay = newOverlay[i, j]; + } + public static void GrowOre(this World world, Random r) { var map = world.Map; var mini = map.XOffset; var maxi = map.XOffset + map.Width; var minj = map.YOffset; var maxj = map.YOffset + map.Height; - var chance = Rules.General.OreChance; - - /* phase 1: grow into neighboring regions */ - if (Rules.General.OreSpreads) - { - var newOverlay = new byte[128, 128]; - for (int j = minj; j < maxj; j++) - for (int i = mini; i < maxi; i++) - { - newOverlay[i, j] = 0xff; - if (!map.HasOverlay(i, j) - && r.NextDouble() < chance - && map.GetOreDensity(i, j) > 0 - && world.OreCanSpreadInto(i,j)) - newOverlay[i, j] = ChooseOre(); - } - - for (int j = minj; j < maxj; j++) - for (int i = mini; i < maxi; i++) - if (newOverlay[i, j] != 0xff) - map.MapTiles[i, j].overlay = newOverlay[i, j]; - } /* phase 2: increase density of existing areas */ - if (Rules.General.OreGrows) - { - var newDensity = new byte[128, 128]; - for (int j = minj; j < maxj; j++) - for (int i = mini; i < maxi; i++) - if (map.ContainsOre(i, j)) newDensity[i, j] = map.GetOreDensity(i, j); + var newDensity = new byte[128, 128]; + for (int j = minj; j < maxj; j++) + for (int i = mini; i < maxi; i++) + if (map.ContainsOre(i, j)) newDensity[i, j] = map.GetOreDensity(i, j); - for (int j = minj; j < maxj; j++) - for (int i = mini; i < maxi; i++) - if (map.MapTiles[i, j].density < newDensity[i, j]) - ++map.MapTiles[i, j].density; - } + for (int j = minj; j < maxj; j++) + for (int i = mini; i < maxi; i++) + if (map.MapTiles[i, j].density < newDensity[i, j]) + ++map.MapTiles[i, j].density; } public static void InitOreDensity( this Map map ) diff --git a/OpenRa.Game/Traits/OreGrowth.cs b/OpenRa.Game/Traits/OreGrowth.cs new file mode 100644 index 0000000000..3fbf09b061 --- /dev/null +++ b/OpenRa.Game/Traits/OreGrowth.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using OpenRa.Graphics; + +namespace OpenRa.Traits +{ + class OreGrowthInfo : ITraitInfo + { + public readonly float Interval = 1f; + public readonly float Chance = .02f; + public readonly bool Spreads = true; + public readonly bool Grows = true; + + public object Create(Actor self) { return new OreGrowth(); } + } + + class OreGrowth : ITick + { + int remainingTicks; + + public void Tick(Actor self) + { + if (--remainingTicks <= 0) + { + var info = self.Info.Traits.Get(); + + if (info.Spreads) + Ore.SpreadOre(self.World, + Game.SharedRandom, + info.Chance); + + if (info.Grows) + Ore.GrowOre(self.World, Game.SharedRandom); + + self.World.Minimap.InvalidateOre(); + remainingTicks = (int)(info.Interval * 60 * 25); + } + } + } +} diff --git a/OpenRa.Game/World.cs b/OpenRa.Game/World.cs index 7b1f3730b6..0691f62c39 100644 --- a/OpenRa.Game/World.cs +++ b/OpenRa.Game/World.cs @@ -50,9 +50,6 @@ namespace OpenRa public readonly WorldRenderer WorldRenderer; internal readonly Minimap Minimap; - readonly int oreFrequency; - int oreTicks; - public World() { Timer.Time( "----World.ctor" ); @@ -66,9 +63,6 @@ namespace OpenRa WorldRenderer = new WorldRenderer(this, Game.renderer); Timer.Time("renderer: {0}"); - - oreFrequency = (int)(Rules.General.GrowthRate * 60 * 25); - oreTicks = oreFrequency; Map.InitOreDensity(); Timer.Time( "Ore: {0}" ); @@ -124,14 +118,6 @@ namespace OpenRa public void Tick() { - if (--oreTicks == 0) - using( new PerfSample( "ore" ) ) - { - this.GrowOre( Game.SharedRandom ); - Minimap.InvalidateOre(); - oreTicks = oreFrequency; - } - foreach (var a in actors) a.Tick(); Queries.WithTraitMultiple().Do( x => x.Trait.Tick( x.Actor ) ); diff --git a/mods/cnc/minimal.ini b/mods/cnc/minimal.ini index a6d3813237..5b45ded674 100644 --- a/mods/cnc/minimal.ini +++ b/mods/cnc/minimal.ini @@ -10,14 +10,11 @@ URepairPercent=20% ; [units only] percent cost to fully repair as ratio of URepairStep=10 ; [units only] hit points to heal per repair 'tick' for units BuildSpeed=.1 ; general build speed [time (in minutes) to produce a 1000 credit cost item] -OreGrows=yes ; Does ore grow denser over time? -OreSpreads=yes ; Does ore spread into adjacent areas GemValue=50 ; gem credits per 'bail' carried by a harvester GoldValue=25 ; gold credits per 'bail' carried by a harvester GrowthRate=.3 ; minutes between ore (Tiberium) growth BailCount=28 ; number of 'bails' carried by a harvester -;; OreChance is missing from rules.ini but referenced -;; LowPowerSlowdown is missing from rules.ini but referenced +LowPowerSlowdown=3 ; slowdown factor for low power GapRegenInterval=.1 ; gap generators will regenerate their shroud at this time interval SubmergeDelay=.02 ; forced delay that subs will remain on surface before allowing to submerge diff --git a/mods/cnc/system.yaml b/mods/cnc/system.yaml index 1778a8f392..04bc7f83be 100644 --- a/mods/cnc/system.yaml +++ b/mods/cnc/system.yaml @@ -104,4 +104,9 @@ World: G: 0 B: 0 A: 180 - ShroudPalette: \ No newline at end of file + ShroudPalette: + OreGrowth: + Interval: .3 + Chance: .02 + Spreads: yes + Grows: yes \ No newline at end of file diff --git a/mods/ra/rules.ini b/mods/ra/rules.ini index fa457dbbfb..1937a50348 100644 --- a/mods/ra/rules.ini +++ b/mods/ra/rules.ini @@ -69,9 +69,6 @@ BuildSpeed=.8 ; general build speed [time (in minutes) to produce a 10 BuildupTime=.06 ; average minutes that building build-up animation runs GemValue=50 ; gem credits per 'bail' carried by a harvester GoldValue=25 ; gold credits per 'bail' carried by a harvester -GrowthRate=.3 ; minutes between ore (Tiberium) growth -OreGrows=yes ; Does ore grow denser over time? -OreSpreads=yes ; Does ore spread into adjacent areas? OreTruckRate=1 ; speed that harvester truck manages ore [larger means slower] SeparateAircraft=no ; Is first helicopter to be purchased separately from helipad? SurvivorRate=.4 ; fraction of building cost to be converted to survivors when sold @@ -110,6 +107,7 @@ TeamDelay=.6 ; interval between checking for and creating teams ; misc FineDiffControl=no ; Allow 5 difficulty settings instead of only 3 settings? +LowPowerSlowdown=3 ; ******* Weapon Statistics ******* @@ -1011,10 +1009,6 @@ Verses=100%,100%,100%,100%,100% ImpactSound=kaboom25 Explosion=7 -[General] -OreChance=.02 -LowPowerSlowdown=3 - [VoiceTypes] diff --git a/mods/ra/rules.yaml b/mods/ra/rules.yaml index 11f089cb56..854f8bf9b4 100644 --- a/mods/ra/rules.yaml +++ b/mods/ra/rules.yaml @@ -158,6 +158,11 @@ World: B: 0 A: 180 ShroudPalette: + OreGrowth: + Interval: .3 + Chance: .02 + Spreads: yes + Grows: yes MGG: GeneratesGap: