ore growth -> trait on world

This commit is contained in:
Chris Forbes
2010-02-07 18:09:41 +13:00
parent 1d964d9301
commit 853f9ae6d5
12 changed files with 101 additions and 78 deletions

View File

@@ -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 (; ; )

View File

@@ -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)

View File

@@ -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 */
}
}

View File

@@ -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)
{

View File

@@ -118,6 +118,7 @@
<Compile Include="Support\PerfHistory.cs" />
<Compile Include="Sync.cs" />
<Compile Include="Traits\CrateSpawner.cs" />
<Compile Include="Traits\OreGrowth.cs" />
<Compile Include="Traits\OreRefinery.cs" />
<Compile Include="Traits\Activities\Attack.cs" />
<Compile Include="Traits\Activities\CallFunc.cs" />

View File

@@ -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 )

View File

@@ -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<OreGrowthInfo>();
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);
}
}
}
}

View File

@@ -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<ITick>().Do( x => x.Trait.Tick( x.Actor ) );

View File

@@ -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

View File

@@ -104,4 +104,9 @@ World:
G: 0
B: 0
A: 180
ShroudPalette:
ShroudPalette:
OreGrowth:
Interval: .3
Chance: .02
Spreads: yes
Grows: yes

View File

@@ -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]

View File

@@ -158,6 +158,11 @@ World:
B: 0
A: 180
ShroudPalette:
OreGrowth:
Interval: .3
Chance: .02
Spreads: yes
Grows: yes
MGG:
GeneratesGap: