From 5d07ca2c90365a95c64be98ad7d3d56a84f6c07a Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Mon, 2 Nov 2009 23:15:29 +1300 Subject: [PATCH] oops. fixed growth and wired up. --- OpenRa.FileFormats/Map.cs | 17 +++++++++++------ OpenRa.Game/Game.cs | 7 +++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/OpenRa.FileFormats/Map.cs b/OpenRa.FileFormats/Map.cs index bb326e1863..49e996b95a 100644 --- a/OpenRa.FileFormats/Map.cs +++ b/OpenRa.FileFormats/Map.cs @@ -126,7 +126,10 @@ namespace OpenRa.FileFormats return HasOverlay(i, j) && overlayIsGems[MapTiles[i, j].overlay]; } - public void GrowOre( Func canSpreadIntoCell ) /* todo: deal with ore pits */ + const float oreRate = .02f; + const float gemRate = .01f; + + public void GrowOre( Func canSpreadIntoCell, Random r ) /* todo: deal with ore pits */ { /* phase 1: grow into neighboring regions */ var newOverlay = new byte[128, 128]; @@ -134,11 +137,13 @@ namespace OpenRa.FileFormats for (int i = 1; i < 127; i++) { newOverlay[i,j] = 0xff; - if (!HasOverlay(i, j) && GetOreDensity(i, j) > 0 && canSpreadIntoCell(new int2(i,j))) - newOverlay[i, j] = 5; /* todo: randomize [5..8] */ + if (!HasOverlay(i, j) && GetOreDensity(i, j) > 0 && canSpreadIntoCell(new int2(i,j)) + && r.NextDouble() < oreRate ) + newOverlay[i, j] = (byte)r.Next(5,9); - if (!HasOverlay(i, j) && GetGemDensity(i, j) > 0 && canSpreadIntoCell(new int2(i, j))) - newOverlay[i, j] = 9; /* todo: randomize [9..12] */ + if (!HasOverlay(i, j) && GetGemDensity(i, j) > 0 && canSpreadIntoCell(new int2(i, j)) + && r.NextDouble() < gemRate ) + newOverlay[i, j] = (byte)r.Next(9, 13); } for (int j = 1; j < 127; j++) @@ -158,7 +163,7 @@ namespace OpenRa.FileFormats for (int j = 1; j < 127; j++) for (int i = 1; i < 127; i++) if (MapTiles[i, j].density < newDensity[i, j]) - MapTiles[i, j].density = newDensity[i, j]; + ++MapTiles[i, j].density; } static MemoryStream ReadPackedSection(IniSection mapPackSection) diff --git a/OpenRa.Game/Game.cs b/OpenRa.Game/Game.cs index d0d9755fe1..466cd9ef12 100644 --- a/OpenRa.Game/Game.cs +++ b/OpenRa.Game/Game.cs @@ -136,6 +136,8 @@ namespace OpenRa.Game lastTime = Environment.TickCount; } + static int oreTicks = 20; + public static void Tick() { int t = Environment.TickCount; @@ -149,6 +151,11 @@ namespace OpenRa.Game if( controller.orderGenerator != null ) controller.orderGenerator.Tick(); + if (--oreTicks == 0) + { + map.GrowOre(p => IsCellBuildable(p, UnitMovementType.Wheel), SharedRandom); + oreTicks = 20; + } world.Tick(); UnitInfluence.Tick(); foreach( var player in players.Values )