add RemoveSmudge function and trait

This commit is contained in:
evgeniysergeev
2016-04-24 09:19:53 +03:00
committed by Evgeniy Sergeev
parent 31d822bcd2
commit e83ffbec1c
3 changed files with 46 additions and 2 deletions

View File

@@ -34,6 +34,12 @@ namespace OpenRA.Mods.Common.Traits
public readonly CVec Dimensions = new CVec(1, 1); public readonly CVec Dimensions = new CVec(1, 1);
public readonly bool RequiresBaseProvider = false; public readonly bool RequiresBaseProvider = false;
public readonly bool AllowInvalidPlacement = false; public readonly bool AllowInvalidPlacement = false;
[Desc("Clear smudges from underneath the building footprint.")]
public readonly bool RemoveSmudgesOnBuild = true;
[Desc("Clear smudges from underneath the building footprint on sell.")]
public readonly bool RemoveSmudgesOnSell = true;
[Desc("Clear smudges from underneath the building footprint on transform.")]
public readonly bool RemoveSmudgesOnTransform = true;
public readonly string[] BuildSounds = { "placbldg.aud", "build5.aud" }; public readonly string[] BuildSounds = { "placbldg.aud", "build5.aud" };
public readonly string[] UndeploySounds = { "cashturn.aud" }; public readonly string[] UndeploySounds = { "cashturn.aud" };
@@ -185,6 +191,9 @@ namespace OpenRA.Mods.Common.Traits
public virtual void AddedToWorld(Actor self) public virtual void AddedToWorld(Actor self)
{ {
if (Info.RemoveSmudgesOnBuild)
RemoveSmudges();
self.World.ActorMap.AddInfluence(self, this); self.World.ActorMap.AddInfluence(self, this);
self.World.ActorMap.AddPosition(self, this); self.World.ActorMap.AddPosition(self, this);
@@ -215,6 +224,9 @@ namespace OpenRA.Mods.Common.Traits
public void Selling(Actor self) public void Selling(Actor self)
{ {
if (Info.RemoveSmudgesOnSell)
RemoveSmudges();
BuildComplete = false; BuildComplete = false;
} }
@@ -222,11 +234,23 @@ namespace OpenRA.Mods.Common.Traits
public void BeforeTransform(Actor self) public void BeforeTransform(Actor self)
{ {
if (Info.RemoveSmudgesOnTransform)
RemoveSmudges();
foreach (var s in Info.UndeploySounds) foreach (var s in Info.UndeploySounds)
Game.Sound.PlayToPlayer(self.Owner, s, self.CenterPosition); Game.Sound.PlayToPlayer(self.Owner, s, self.CenterPosition);
} }
public void OnTransform(Actor self) { } public void OnTransform(Actor self) { }
public void AfterTransform(Actor self) { } public void AfterTransform(Actor self) { }
public void RemoveSmudges()
{
var smudgeLayers = self.World.WorldActor.TraitsImplementing<SmudgeLayer>();
foreach (var smudgeLayer in smudgeLayers)
foreach (var footprintTile in FootprintUtils.Tiles(self))
smudgeLayer.RemoveSmudge(footprintTile);
}
} }
} }

View File

@@ -142,7 +142,7 @@ namespace OpenRA.Mods.Common.Traits
if (Game.CosmeticRandom.Next(0, 100) <= Info.SmokePercentage) if (Game.CosmeticRandom.Next(0, 100) <= Info.SmokePercentage)
world.AddFrameEndTask(w => w.Add(new SpriteEffect(world.Map.CenterOfCell(loc), w, Info.SmokeType, Info.SmokeSequence, Info.SmokePalette))); world.AddFrameEndTask(w => w.Add(new SpriteEffect(world.Map.CenterOfCell(loc), w, Info.SmokeType, Info.SmokeSequence, Info.SmokePalette)));
if (!dirty.ContainsKey(loc) && !tiles.ContainsKey(loc)) if ((!dirty.ContainsKey(loc) || dirty[loc].Sprite == null) && !tiles.ContainsKey(loc))
{ {
// No smudge; create a new one // No smudge; create a new one
var st = smudges.Keys.Random(world.SharedRandom); var st = smudges.Keys.Random(world.SharedRandom);
@@ -163,6 +163,22 @@ namespace OpenRA.Mods.Common.Traits
} }
} }
public void RemoveSmudge(CPos loc)
{
if (dirty.ContainsKey(loc))
{
var tile = dirty[loc];
tile.Depth = 0;
tile.Sprite = null;
dirty[loc] = tile;
}
else
{
var st = smudges.Keys.Random(world.SharedRandom);
dirty[loc] = new Smudge { Type = st, Depth = 0, Sprite = null };
}
}
public void TickRender(WorldRenderer wr, Actor self) public void TickRender(WorldRenderer wr, Actor self)
{ {
var remove = new List<CPos>(); var remove = new List<CPos>();
@@ -170,7 +186,10 @@ namespace OpenRA.Mods.Common.Traits
{ {
if (!self.World.FogObscures(kv.Key)) if (!self.World.FogObscures(kv.Key))
{ {
tiles[kv.Key] = kv.Value; if (kv.Value.Sprite == null)
tiles.Remove(kv.Key);
else
tiles[kv.Key] = kv.Value;
render.Update(kv.Key, kv.Value.Sprite); render.Update(kv.Key, kv.Value.Sprite);
remove.Add(kv.Key); remove.Add(kv.Key);

View File

@@ -19,6 +19,7 @@ Terrain:
TerrainType@Concrete: TerrainType@Concrete:
Type: Concrete Type: Concrete
TargetTypes: Ground TargetTypes: Ground
AcceptsSmudgeType: RockCrater
Color: E8C498 Color: E8C498
TerrainType@Dune: TerrainType@Dune:
Type: Dune Type: Dune