add RemoveSmudge function and trait
This commit is contained in:
committed by
Evgeniy Sergeev
parent
31d822bcd2
commit
e83ffbec1c
@@ -34,6 +34,12 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public readonly CVec Dimensions = new CVec(1, 1);
|
||||
public readonly bool RequiresBaseProvider = 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[] UndeploySounds = { "cashturn.aud" };
|
||||
@@ -185,6 +191,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public virtual void AddedToWorld(Actor self)
|
||||
{
|
||||
if (Info.RemoveSmudgesOnBuild)
|
||||
RemoveSmudges();
|
||||
|
||||
self.World.ActorMap.AddInfluence(self, this);
|
||||
self.World.ActorMap.AddPosition(self, this);
|
||||
|
||||
@@ -215,6 +224,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void Selling(Actor self)
|
||||
{
|
||||
if (Info.RemoveSmudgesOnSell)
|
||||
RemoveSmudges();
|
||||
|
||||
BuildComplete = false;
|
||||
}
|
||||
|
||||
@@ -222,11 +234,23 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void BeforeTransform(Actor self)
|
||||
{
|
||||
if (Info.RemoveSmudgesOnTransform)
|
||||
RemoveSmudges();
|
||||
|
||||
foreach (var s in Info.UndeploySounds)
|
||||
Game.Sound.PlayToPlayer(self.Owner, s, self.CenterPosition);
|
||||
}
|
||||
|
||||
public void OnTransform(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
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)));
|
||||
|
||||
if (!dirty.ContainsKey(loc) && !tiles.ContainsKey(loc))
|
||||
if ((!dirty.ContainsKey(loc) || dirty[loc].Sprite == null) && !tiles.ContainsKey(loc))
|
||||
{
|
||||
// No smudge; create a new one
|
||||
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)
|
||||
{
|
||||
var remove = new List<CPos>();
|
||||
@@ -170,7 +186,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
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);
|
||||
|
||||
remove.Add(kv.Key);
|
||||
|
||||
@@ -19,6 +19,7 @@ Terrain:
|
||||
TerrainType@Concrete:
|
||||
Type: Concrete
|
||||
TargetTypes: Ground
|
||||
AcceptsSmudgeType: RockCrater
|
||||
Color: E8C498
|
||||
TerrainType@Dune:
|
||||
Type: Dune
|
||||
|
||||
Reference in New Issue
Block a user