Implement jumpjets.
This commit is contained in:
@@ -43,6 +43,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public const byte Tunnel = 1;
|
||||
public const byte Subterranean = 2;
|
||||
public const byte Jumpjet = 3;
|
||||
}
|
||||
|
||||
[Desc("Unit is able to move.")]
|
||||
@@ -115,6 +116,22 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public readonly string SubterraneanTransitionSound = null;
|
||||
|
||||
[Desc("Can this unit fly over obsticals?")]
|
||||
public readonly bool Jumpjet = false;
|
||||
|
||||
[GrantedConditionReference]
|
||||
[Desc("The condition to grant to self while flying.")]
|
||||
public readonly string JumpjetCondition = null;
|
||||
|
||||
[Desc("Pathfinding cost for taking off or landing.")]
|
||||
public readonly int JumpjetTransitionCost = 0;
|
||||
|
||||
[Desc("The terrain types that this actor can transition on. Leave empty to allow any.")]
|
||||
public readonly HashSet<string> JumpjetTransitionTerrainTypes = new HashSet<string>();
|
||||
|
||||
[Desc("Can this actor transition on slopes?")]
|
||||
public readonly bool JumpjetTransitionOnRamps = true;
|
||||
|
||||
public override object Create(ActorInitializer init) { return new Mobile(init, this); }
|
||||
|
||||
static object LoadSpeeds(MiniYaml y)
|
||||
@@ -378,6 +395,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public SubCell FromSubCell, ToSubCell;
|
||||
int tunnelToken = ConditionManager.InvalidConditionToken;
|
||||
int subterraneanToken = ConditionManager.InvalidConditionToken;
|
||||
int jumpjetToken = ConditionManager.InvalidConditionToken;
|
||||
ConditionManager conditionManager;
|
||||
|
||||
[Sync] public int Facing
|
||||
@@ -424,6 +442,12 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!string.IsNullOrEmpty(Info.SubterraneanTransitionSound))
|
||||
Game.Sound.Play(SoundType.World, Info.SubterraneanTransitionSound);
|
||||
}
|
||||
|
||||
// Grant the jumpjet condition as soon as the actor starts leaving the ground layer
|
||||
// The condition is revoked from FinishedMoving
|
||||
if (toCell.Layer == CustomMovementLayerType.Jumpjet && conditionManager != null &&
|
||||
!string.IsNullOrEmpty(Info.JumpjetCondition) && jumpjetToken == ConditionManager.InvalidConditionToken)
|
||||
jumpjetToken = conditionManager.GrantCondition(self, Info.JumpjetCondition);
|
||||
}
|
||||
|
||||
public Mobile(ActorInitializer init, MobileInfo info)
|
||||
@@ -699,6 +723,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void FinishedMoving(Actor self)
|
||||
{
|
||||
// Need to check both fromCell and toCell because FinishedMoving is called multiple times during the move
|
||||
// and that condition guarantees that this only runs when the unit has finished landing.
|
||||
if (fromCell.Layer != CustomMovementLayerType.Jumpjet && toCell.Layer != CustomMovementLayerType.Jumpjet && jumpjetToken != ConditionManager.InvalidConditionToken)
|
||||
jumpjetToken = conditionManager.RevokeCondition(self, jumpjetToken);
|
||||
|
||||
// Only make actor crush if it is on the ground
|
||||
if (!self.IsAtGroundLevel())
|
||||
return;
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return true;
|
||||
|
||||
// HACK: Workaround until we can generalize movement classes
|
||||
if (mi.Subterranean)
|
||||
if (mi.Subterranean || mi.Jumpjet)
|
||||
return true;
|
||||
|
||||
return domainIndexes[movementClass].IsPassable(p1, p2);
|
||||
|
||||
103
OpenRA.Mods.Common/Traits/World/JumpjetActorLayer.cs
Normal file
103
OpenRA.Mods.Common/Traits/World/JumpjetActorLayer.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2017 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.Linq;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public class JumpjetActorLayerInfo : ITraitInfo
|
||||
{
|
||||
[Desc("Terrain type of the airborne layer.")]
|
||||
public readonly string TerrainType = "Jumpjet";
|
||||
|
||||
[Desc("Height offset relative to the smoothed terrain for movement.")]
|
||||
public readonly WDist HeightOffset = new WDist(2304);
|
||||
|
||||
[Desc("Cell radius for smoothing adjacent cell heights.")]
|
||||
public readonly int SmoothingRadius = 2;
|
||||
|
||||
public object Create(ActorInitializer init) { return new JumpjetActorLayer(init.Self, this); }
|
||||
}
|
||||
|
||||
public class JumpjetActorLayer : ICustomMovementLayer
|
||||
{
|
||||
readonly Map map;
|
||||
|
||||
readonly byte terrainIndex;
|
||||
readonly CellLayer<int> height;
|
||||
|
||||
public JumpjetActorLayer(Actor self, JumpjetActorLayerInfo info)
|
||||
{
|
||||
map = self.World.Map;
|
||||
terrainIndex = self.World.Map.Rules.TileSet.GetTerrainIndex(info.TerrainType);
|
||||
height = new CellLayer<int>(map);
|
||||
foreach (var c in map.AllCells)
|
||||
{
|
||||
var neighbourCount = 0;
|
||||
var neighbourHeight = 0;
|
||||
for (var dy = -info.SmoothingRadius; dy <= info.SmoothingRadius; dy++)
|
||||
{
|
||||
for (var dx = -info.SmoothingRadius; dx <= info.SmoothingRadius; dx++)
|
||||
{
|
||||
var neighbour = c + new CVec(dx, dy);
|
||||
if (!map.AllCells.Contains(neighbour))
|
||||
continue;
|
||||
|
||||
neighbourCount++;
|
||||
neighbourHeight += map.Height[neighbour];
|
||||
}
|
||||
}
|
||||
|
||||
height[c] = info.HeightOffset.Length + neighbourHeight * 512 / neighbourCount;
|
||||
}
|
||||
}
|
||||
|
||||
bool ICustomMovementLayer.EnabledForActor(ActorInfo a, MobileInfo mi) { return mi.Jumpjet; }
|
||||
byte ICustomMovementLayer.Index { get { return CustomMovementLayerType.Jumpjet; } }
|
||||
bool ICustomMovementLayer.InteractsWithDefaultLayer { get { return true; } }
|
||||
|
||||
WPos ICustomMovementLayer.CenterOfCell(CPos cell)
|
||||
{
|
||||
var pos = map.CenterOfCell(cell);
|
||||
return pos + new WVec(0, 0, height[cell] - pos.Z);
|
||||
}
|
||||
|
||||
bool ValidTransitionCell(CPos cell, MobileInfo mi)
|
||||
{
|
||||
var terrainType = map.GetTerrainInfo(cell).Type;
|
||||
if (!mi.JumpjetTransitionTerrainTypes.Contains(terrainType) && mi.JumpjetTransitionTerrainTypes.Any())
|
||||
return false;
|
||||
|
||||
if (mi.JumpjetTransitionOnRamps)
|
||||
return true;
|
||||
|
||||
var tile = map.Tiles[cell];
|
||||
var ti = map.Rules.TileSet.GetTileInfo(tile);
|
||||
return ti == null || ti.RampType == 0;
|
||||
}
|
||||
|
||||
int ICustomMovementLayer.EntryMovementCost(ActorInfo a, MobileInfo mi, CPos cell)
|
||||
{
|
||||
return ValidTransitionCell(cell, mi) ? mi.JumpjetTransitionCost : int.MaxValue;
|
||||
}
|
||||
|
||||
int ICustomMovementLayer.ExitMovementCost(ActorInfo a, MobileInfo mi, CPos cell)
|
||||
{
|
||||
return ValidTransitionCell(cell, mi) ? mi.JumpjetTransitionCost : int.MaxValue;
|
||||
}
|
||||
|
||||
byte ICustomMovementLayer.GetTerrainIndex(CPos cell)
|
||||
{
|
||||
return terrainIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user