Merge pull request #11638 from reaperrr/deprecate-IsWater-p1
Deprecate terrain IsWater check - Part 1
This commit is contained in:
@@ -134,6 +134,9 @@ namespace OpenRA.Mods.Common.AI
|
|||||||
"Should match maximum adjacency of naval structures.")]
|
"Should match maximum adjacency of naval structures.")]
|
||||||
public readonly int CheckForWaterRadius = 8;
|
public readonly int CheckForWaterRadius = 8;
|
||||||
|
|
||||||
|
[Desc("Terrain types which are considered water for base building purposes.")]
|
||||||
|
public readonly HashSet<string> WaterTerrainTypes = new HashSet<string> { "Water" };
|
||||||
|
|
||||||
[Desc("Avoid enemy actors nearby when searching for a new resource patch. Should be somewhere near the max weapon range.")]
|
[Desc("Avoid enemy actors nearby when searching for a new resource patch. Should be somewhere near the max weapon range.")]
|
||||||
public readonly WDist HarvesterEnemyAvoidanceRadius = WDist.FromCells(8);
|
public readonly WDist HarvesterEnemyAvoidanceRadius = WDist.FromCells(8);
|
||||||
|
|
||||||
@@ -323,14 +326,13 @@ namespace OpenRA.Mods.Common.AI
|
|||||||
|
|
||||||
foreach (var b in baseProviders)
|
foreach (var b in baseProviders)
|
||||||
{
|
{
|
||||||
// TODO: Unhardcode terrain type
|
// TODO: Properly check building foundation rather than 3x3 area
|
||||||
// TODO2: Properly check building foundation rather than 3x3 area
|
|
||||||
var playerWorld = Player.World;
|
var playerWorld = Player.World;
|
||||||
var countWaterCells = Map.FindTilesInCircle(b.Location, Info.MaxBaseRadius)
|
var countWaterCells = Map.FindTilesInCircle(b.Location, Info.MaxBaseRadius)
|
||||||
.Where(c => playerWorld.Map.Contains(c)
|
.Where(c => playerWorld.Map.Contains(c)
|
||||||
&& playerWorld.Map.GetTerrainInfo(c).IsWater
|
&& Info.WaterTerrainTypes.Contains(playerWorld.Map.GetTerrainInfo(c).Type)
|
||||||
&& Util.AdjacentCells(playerWorld, Target.FromCell(playerWorld, c))
|
&& Util.AdjacentCells(playerWorld, Target.FromCell(playerWorld, c))
|
||||||
.All(a => playerWorld.Map.GetTerrainInfo(a).IsWater))
|
.All(a => Info.WaterTerrainTypes.Contains(playerWorld.Map.GetTerrainInfo(a).Type)))
|
||||||
.Count();
|
.Count();
|
||||||
|
|
||||||
if (countWaterCells > 0)
|
if (countWaterCells > 0)
|
||||||
@@ -348,14 +350,13 @@ namespace OpenRA.Mods.Common.AI
|
|||||||
|
|
||||||
foreach (var a in areaProviders)
|
foreach (var a in areaProviders)
|
||||||
{
|
{
|
||||||
// TODO: Unhardcode terrain type
|
// TODO: Properly check building foundation rather than 3x3 area
|
||||||
// TODO2: Properly check building foundation rather than 3x3 area
|
|
||||||
var playerWorld = Player.World;
|
var playerWorld = Player.World;
|
||||||
var adjacentWater = Map.FindTilesInCircle(a.Location, Info.CheckForWaterRadius)
|
var adjacentWater = Map.FindTilesInCircle(a.Location, Info.CheckForWaterRadius)
|
||||||
.Where(c => playerWorld.Map.Contains(c)
|
.Where(c => playerWorld.Map.Contains(c)
|
||||||
&& playerWorld.Map.GetTerrainInfo(c).IsWater
|
&& Info.WaterTerrainTypes.Contains(playerWorld.Map.GetTerrainInfo(c).Type)
|
||||||
&& Util.AdjacentCells(playerWorld, Target.FromCell(playerWorld, c))
|
&& Util.AdjacentCells(playerWorld, Target.FromCell(playerWorld, c))
|
||||||
.All(b => playerWorld.Map.GetTerrainInfo(b).IsWater))
|
.All(ac => Info.WaterTerrainTypes.Contains(playerWorld.Map.GetTerrainInfo(ac).Type)))
|
||||||
.Count();
|
.Count();
|
||||||
|
|
||||||
if (adjacentWater > 0)
|
if (adjacentWater > 0)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Mods.Common.Effects;
|
using OpenRA.Mods.Common.Effects;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
@@ -32,6 +33,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
[SequenceReference("Image")] public readonly string WaterCorpseSequence = null;
|
[SequenceReference("Image")] public readonly string WaterCorpseSequence = null;
|
||||||
[PaletteReference] public readonly string WaterCorpsePalette = "effect";
|
[PaletteReference] public readonly string WaterCorpsePalette = "effect";
|
||||||
|
|
||||||
|
[Desc("Terrain types on which to display WaterCorpseSequence.")]
|
||||||
|
public readonly HashSet<string> WaterTerrainTypes = new HashSet<string> { "Water" };
|
||||||
|
|
||||||
public readonly int FallRate = 13;
|
public readonly int FallRate = 13;
|
||||||
|
|
||||||
[UpgradeGrantedReference]
|
[UpgradeGrantedReference]
|
||||||
@@ -59,19 +63,23 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (!info.KilledOnImpassableTerrain)
|
if (!info.KilledOnImpassableTerrain)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (positionable.CanEnterCell(self.Location, self))
|
var cell = self.Location;
|
||||||
|
if (self.World.Map.Contains(cell))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (ignore != null && self.World.ActorMap.GetActorsAt(self.Location).Any(a => a != ignore))
|
if (positionable.CanEnterCell(cell, self))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var terrain = self.World.Map.GetTerrainInfo(self.Location);
|
if (ignore != null && self.World.ActorMap.GetActorsAt(cell).Any(a => a != ignore))
|
||||||
|
return;
|
||||||
|
|
||||||
var sound = terrain.IsWater ? info.WaterImpactSound : info.GroundImpactSound;
|
var onWater = info.WaterTerrainTypes.Contains(self.World.Map.GetTerrainInfo(cell).Type);
|
||||||
|
|
||||||
|
var sound = onWater ? info.WaterImpactSound : info.GroundImpactSound;
|
||||||
Game.Sound.Play(sound, self.CenterPosition);
|
Game.Sound.Play(sound, self.CenterPosition);
|
||||||
|
|
||||||
var sequence = terrain.IsWater ? info.WaterCorpseSequence : info.GroundCorpseSequence;
|
var sequence = onWater ? info.WaterCorpseSequence : info.GroundCorpseSequence;
|
||||||
var palette = terrain.IsWater ? info.WaterCorpsePalette : info.GroundCorpsePalette;
|
var palette = onWater ? info.WaterCorpsePalette : info.GroundCorpsePalette;
|
||||||
if (sequence != null && palette != null)
|
if (sequence != null && palette != null)
|
||||||
self.World.AddFrameEndTask(w => w.Add(new SpriteEffect(self.OccupiesSpace.CenterPosition, w, info.Image, sequence, palette)));
|
self.World.AddFrameEndTask(w => w.Add(new SpriteEffect(self.OccupiesSpace.CenterPosition, w, info.Image, sequence, palette)));
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
[Desc("Easteregg sequences to use in December.")]
|
[Desc("Easteregg sequences to use in December.")]
|
||||||
public readonly string[] XmasImages = { };
|
public readonly string[] XmasImages = { };
|
||||||
|
|
||||||
|
[Desc("Terrain types on which to display WaterSequence.")]
|
||||||
|
public readonly HashSet<string> WaterTerrainTypes = new HashSet<string> { "Water" };
|
||||||
|
|
||||||
[SequenceReference] public readonly string IdleSequence = "idle";
|
[SequenceReference] public readonly string IdleSequence = "idle";
|
||||||
[SequenceReference] public readonly string WaterSequence = null;
|
[SequenceReference] public readonly string WaterSequence = null;
|
||||||
[SequenceReference] public readonly string LandSequence = null;
|
[SequenceReference] public readonly string LandSequence = null;
|
||||||
@@ -74,7 +77,8 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
|
|
||||||
void PlaySequence()
|
void PlaySequence()
|
||||||
{
|
{
|
||||||
var sequence = self.World.Map.GetTerrainInfo(self.Location).IsWater ? info.WaterSequence : info.LandSequence;
|
var onWater = info.WaterTerrainTypes.Contains(self.World.Map.GetTerrainInfo(self.Location).Type);
|
||||||
|
var sequence = onWater ? info.WaterSequence : info.LandSequence;
|
||||||
if (!string.IsNullOrEmpty(sequence))
|
if (!string.IsNullOrEmpty(sequence))
|
||||||
anim.PlayRepeating(sequence);
|
anim.PlayRepeating(sequence);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user