Add a DamagesConcreteWarhead to remove buildable concrete.
This commit is contained in:
committed by
abcdefg30
parent
7438af8266
commit
399e451ada
@@ -83,6 +83,7 @@
|
||||
<Compile Include="Traits\World\D2kEditorResourceLayer.cs" />
|
||||
<Compile Include="Lint\CheckImportActors.cs" />
|
||||
<Compile Include="PackageLoaders\D2kSoundResources.cs" />
|
||||
<Compile Include="Warheads\DamagesConcreteWarhead.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.Game\OpenRA.Game.csproj">
|
||||
|
||||
@@ -21,6 +21,9 @@ namespace OpenRA.Mods.D2k.Traits
|
||||
[Desc("Palette to render the layer sprites in.")]
|
||||
public readonly string Palette = TileSet.TerrainPaletteInternalName;
|
||||
|
||||
[Desc("The hitpoints, which can be reduced by the DamagesConcreteWarhead.")]
|
||||
public readonly int MaxStrength = 9000;
|
||||
|
||||
public object Create(ActorInitializer init) { return new BuildableTerrainLayer(init.Self, this); }
|
||||
}
|
||||
|
||||
@@ -29,6 +32,7 @@ namespace OpenRA.Mods.D2k.Traits
|
||||
readonly BuildableTerrainLayerInfo info;
|
||||
readonly Dictionary<CPos, Sprite> dirty = new Dictionary<CPos, Sprite>();
|
||||
readonly Map map;
|
||||
readonly CellLayer<int> strength;
|
||||
|
||||
TerrainSpriteLayer render;
|
||||
Theater theater;
|
||||
@@ -38,6 +42,7 @@ namespace OpenRA.Mods.D2k.Traits
|
||||
{
|
||||
this.info = info;
|
||||
map = self.World.Map;
|
||||
strength = new CellLayer<int>(self.World.Map);
|
||||
}
|
||||
|
||||
public void WorldLoaded(World w, WorldRenderer wr)
|
||||
@@ -49,12 +54,30 @@ namespace OpenRA.Mods.D2k.Traits
|
||||
public void AddTile(CPos cell, TerrainTile tile)
|
||||
{
|
||||
map.CustomTerrain[cell] = map.Rules.TileSet.GetTerrainIndex(tile);
|
||||
strength[cell] = info.MaxStrength;
|
||||
|
||||
// Terrain tiles define their origin at the topleft
|
||||
var s = theater.TileSprite(tile);
|
||||
dirty[cell] = new Sprite(s.Sheet, s.Bounds, s.ZRamp, float2.Zero, s.Channel, s.BlendMode);
|
||||
}
|
||||
|
||||
public void HitTile(CPos cell, int damage)
|
||||
{
|
||||
if (strength[cell] == 0)
|
||||
return;
|
||||
|
||||
strength[cell] = strength[cell] - damage;
|
||||
if (strength[cell] < 1)
|
||||
RemoveTile(cell);
|
||||
}
|
||||
|
||||
public void RemoveTile(CPos cell)
|
||||
{
|
||||
map.CustomTerrain[cell] = byte.MaxValue;
|
||||
strength[cell] = 0;
|
||||
dirty[cell] = null;
|
||||
}
|
||||
|
||||
void ITickRender.TickRender(WorldRenderer wr, Actor self)
|
||||
{
|
||||
var remove = new List<CPos>();
|
||||
|
||||
34
OpenRA.Mods.D2k/Warheads/DamagesConcreteWarhead.cs
Normal file
34
OpenRA.Mods.D2k/Warheads/DamagesConcreteWarhead.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2018 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Mods.Common.Warheads;
|
||||
using OpenRA.Mods.D2k.Traits;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.D2k.Warheads
|
||||
{
|
||||
[Desc("Interacts with the BuildableTerrainLayer trait.")]
|
||||
public class DamagesConcreteWarhead : Warhead
|
||||
{
|
||||
[Desc("How much damage to deal.")]
|
||||
[FieldLoader.Require]
|
||||
public readonly int Damage = 0;
|
||||
|
||||
public override void DoImpact(Target target, Actor firedBy, IEnumerable<int> damageModifiers)
|
||||
{
|
||||
var world = firedBy.World;
|
||||
var layer = world.WorldActor.Trait<BuildableTerrainLayer>();
|
||||
var cell = world.Map.CellContaining(target.CenterPosition);
|
||||
layer.HitTile(cell, Damage);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user