Ditto Player, Shroud, and Smudge

This commit is contained in:
Bob
2010-01-21 13:41:22 +13:00
parent 6ac384669b
commit bb5f7dac6b
4 changed files with 19 additions and 16 deletions

View File

@@ -29,7 +29,7 @@ namespace OpenRa
impactSound = warhead.WaterImpactSound; impactSound = warhead.WaterImpactSound;
if (impactSound != null) Sound.Play(impactSound + ".aud"); if (impactSound != null) Sound.Play(impactSound + ".aud");
if (!isWater) Smudge.AddSmudge(targetTile, warhead); if (!isWater) world.Map.AddSmudge(targetTile, warhead);
if (warhead.Ore) world.Map.DestroyOre(targetTile.X, targetTile.Y); if (warhead.Ore) world.Map.DestroyOre(targetTile.X, targetTile.Y);
var maxSpread = GetMaximumSpread(weapon, warhead); var maxSpread = GetMaximumSpread(weapon, warhead);

View File

@@ -26,6 +26,8 @@ namespace OpenRa
public int PowerProvided = 0; public int PowerProvided = 0;
public int PowerDrained = 0; public int PowerDrained = 0;
public World World { get { return PlayerActor.World; } }
public Shroud Shroud; public Shroud Shroud;
public Dictionary<string, SupportPower> SupportPowers; public Dictionary<string, SupportPower> SupportPowers;
@@ -52,7 +54,7 @@ namespace OpenRa
PowerProvided = 0; PowerProvided = 0;
PowerDrained = 0; PowerDrained = 0;
var myBuildings = Game.world.Actors var myBuildings = World.Actors
.Where(a => a.Owner == this && a.traits.Contains<Building>()); .Where(a => a.Owner == this && a.traits.Contains<Building>());
foreach (var a in myBuildings) foreach (var a in myBuildings)
@@ -83,7 +85,7 @@ namespace OpenRa
void UpdateOreCapacity() void UpdateOreCapacity()
{ {
OreCapacity = Game.world.Actors OreCapacity = World.Actors
.Where(a => a.Owner == this && a.traits.Contains<StoresOre>()) .Where(a => a.Owner == this && a.traits.Contains<StoresOre>())
.Select(a => a.Info.Traits.Get<StoresOreInfo>()) .Select(a => a.Info.Traits.Get<StoresOreInfo>())
.Sum(b => b.Capacity); .Sum(b => b.Capacity);
@@ -91,7 +93,7 @@ namespace OpenRa
void GiveAdvice(string advice) void GiveAdvice(string advice)
{ {
if (this != Game.world.LocalPlayer) return; if (this != World.LocalPlayer) return;
// todo: store the condition or something. // todo: store the condition or something.
// repeat after Rules.General.SpeakDelay, as long as the condition holds. // repeat after Rules.General.SpeakDelay, as long as the condition holds.
Sound.Play(advice); Sound.Play(advice);
@@ -130,12 +132,12 @@ namespace OpenRa
{ {
UpdatePower(); UpdatePower();
UpdateOreCapacity(); UpdateOreCapacity();
Shroud.Tick(); Shroud.Tick( World );
foreach (var sp in SupportPowers.Values) foreach (var sp in SupportPowers.Values)
sp.Tick(); sp.Tick();
if (this == Game.world.LocalPlayer) if (this == World.LocalPlayer)
{ {
var totalMoney = Cash + Ore; var totalMoney = Cash + Ore;

View File

@@ -29,11 +29,11 @@ namespace OpenRa
set { hasGPS = value; dirty = true;} set { hasGPS = value; dirty = true;}
} }
public void Tick() public void Tick( World world )
{ {
// Clear active flags // Clear active flags
gapActive = new bool[128, 128]; gapActive = new bool[128, 128];
foreach (var a in Game.world.Actors.Where(a => a.traits.Contains<GeneratesGap>() && owner != a.Owner)) foreach (var a in world.Actors.Where(a => a.traits.Contains<GeneratesGap>() && owner != a.Owner))
{ {
foreach (var t in a.traits.Get<GeneratesGap>().GetShroudedTiles()) foreach (var t in a.traits.Get<GeneratesGap>().GetShroudedTiles())
gapActive[t.X, t.Y] = true; gapActive[t.X, t.Y] = true;
@@ -81,7 +81,7 @@ namespace OpenRa
public void Explore(Actor a) public void Explore(Actor a)
{ {
foreach (var t in Game.world.FindTilesInCircle( foreach (var t in a.World.FindTilesInCircle(
(1f / Game.CellSize * a.CenterLocation).ToInt2(), (1f / Game.CellSize * a.CenterLocation).ToInt2(),
a.Info.Traits.Get<OwnedActorInfo>().Sight)) a.Info.Traits.Get<OwnedActorInfo>().Sight))
{ {

View File

@@ -1,4 +1,5 @@
using OpenRa.GameRules; using OpenRa.GameRules;
using OpenRa.FileFormats;
namespace OpenRa namespace OpenRa
{ {
@@ -8,11 +9,11 @@ namespace OpenRa
const int firstCrater = 17; const int firstCrater = 17;
const int framesPerCrater = 5; const int framesPerCrater = 5;
public static void AddSmudge(bool isCrater, int x, int y) public static void AddSmudge(this Map map, bool isCrater, int x, int y)
{ {
var smudge = Game.world.Map.MapTiles[x, y].smudge; var smudge = map.MapTiles[x, y].smudge;
if (smudge == 0) if (smudge == 0)
Game.world.Map.MapTiles[x, y].smudge = (byte) (isCrater map.MapTiles[x, y].smudge = (byte) (isCrater
? (firstCrater + framesPerCrater * ChooseSmudge()) ? (firstCrater + framesPerCrater * ChooseSmudge())
: (firstScorch + ChooseSmudge())); : (firstScorch + ChooseSmudge()));
@@ -21,21 +22,21 @@ namespace OpenRa
/* deepen the crater */ /* deepen the crater */
var amount = (smudge - firstCrater) % framesPerCrater; var amount = (smudge - firstCrater) % framesPerCrater;
if (amount < framesPerCrater - 1) if (amount < framesPerCrater - 1)
Game.world.Map.MapTiles[x, y].smudge++; map.MapTiles[x, y].smudge++;
} }
public static void AddSmudge(int2 targetTile, WarheadInfo warhead) public static void AddSmudge(this Map map, int2 targetTile, WarheadInfo warhead)
{ {
switch (warhead.Explosion) /* todo: push the scorch/crater behavior into data */ switch (warhead.Explosion) /* todo: push the scorch/crater behavior into data */
{ {
case 4: case 4:
case 5: case 5:
Smudge.AddSmudge(true, targetTile.X, targetTile.Y); map.AddSmudge(true, targetTile.X, targetTile.Y);
break; break;
case 3: case 3:
case 6: case 6:
Smudge.AddSmudge(false, targetTile.X, targetTile.Y); map.AddSmudge(false, targetTile.X, targetTile.Y);
break; break;
} }
} }