Terrain speed modifiers
This commit is contained in:
@@ -41,7 +41,7 @@ namespace OpenRA.GameRules
|
|||||||
|
|
||||||
public TerrainCost(MiniYaml y) { FieldLoader.Load(this, y); }
|
public TerrainCost(MiniYaml y) { FieldLoader.Load(this, y); }
|
||||||
|
|
||||||
public float GetSpeedMultiplier(UnitMovementType umt)
|
public float GetSpeedModifier(UnitMovementType umt)
|
||||||
{
|
{
|
||||||
switch (umt) /* todo: make this nice */
|
switch (umt) /* todo: make this nice */
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#region Copyright & License Information
|
#region Copyright & License Information
|
||||||
/*
|
/*
|
||||||
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
||||||
* This file is part of OpenRA.
|
* This file is part of OpenRA.
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using OpenRA.GameRules;
|
||||||
|
|
||||||
namespace OpenRA.Traits.Activities
|
namespace OpenRA.Traits.Activities
|
||||||
{
|
{
|
||||||
@@ -64,7 +65,7 @@ namespace OpenRA.Traits.Activities
|
|||||||
public static void Fly(Actor self, int desiredAltitude )
|
public static void Fly(Actor self, int desiredAltitude )
|
||||||
{
|
{
|
||||||
var unit = self.traits.Get<Unit>();
|
var unit = self.traits.Get<Unit>();
|
||||||
var speed = .2f * Util.GetEffectiveSpeed(self);
|
var speed = .2f * Util.GetEffectiveSpeed(self, UnitMovementType.Fly);
|
||||||
var angle = unit.Facing / 128f * Math.PI;
|
var angle = unit.Facing / 128f * Math.PI;
|
||||||
|
|
||||||
self.CenterLocation += speed * -float2.FromAngle((float)angle);
|
self.CenterLocation += speed * -float2.FromAngle((float)angle);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#region Copyright & License Information
|
#region Copyright & License Information
|
||||||
/*
|
/*
|
||||||
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
||||||
* This file is part of OpenRA.
|
* This file is part of OpenRA.
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using OpenRA.GameRules;
|
||||||
|
|
||||||
namespace OpenRA.Traits.Activities
|
namespace OpenRA.Traits.Activities
|
||||||
{
|
{
|
||||||
@@ -55,7 +56,7 @@ namespace OpenRA.Traits.Activities
|
|||||||
|
|
||||||
if (!float2.WithinEpsilon(float2.Zero, dist, range * Game.CellSize))
|
if (!float2.WithinEpsilon(float2.Zero, dist, range * Game.CellSize))
|
||||||
{
|
{
|
||||||
var rawSpeed = .2f * Util.GetEffectiveSpeed(self);
|
var rawSpeed = .2f * Util.GetEffectiveSpeed(self, UnitMovementType.Fly);
|
||||||
self.CenterLocation += (rawSpeed / dist.Length) * dist;
|
self.CenterLocation += (rawSpeed / dist.Length) * dist;
|
||||||
self.Location = ((1 / 24f) * self.CenterLocation).ToInt2();
|
self.Location = ((1 / 24f) * self.CenterLocation).ToInt2();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#region Copyright & License Information
|
#region Copyright & License Information
|
||||||
/*
|
/*
|
||||||
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
||||||
* This file is part of OpenRA.
|
* This file is part of OpenRA.
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using OpenRA.GameRules;
|
||||||
|
|
||||||
namespace OpenRA.Traits.Activities
|
namespace OpenRA.Traits.Activities
|
||||||
{
|
{
|
||||||
@@ -59,7 +60,7 @@ namespace OpenRA.Traits.Activities
|
|||||||
Util.TickFacing(ref unit.Facing, desiredFacing,
|
Util.TickFacing(ref unit.Facing, desiredFacing,
|
||||||
self.Info.Traits.Get<UnitInfo>().ROT);
|
self.Info.Traits.Get<UnitInfo>().ROT);
|
||||||
|
|
||||||
var rawSpeed = .2f * Util.GetEffectiveSpeed(self);
|
var rawSpeed = .2f * Util.GetEffectiveSpeed(self, UnitMovementType.Fly);
|
||||||
self.CenterLocation += (rawSpeed / dist.Length) * dist;
|
self.CenterLocation += (rawSpeed / dist.Length) * dist;
|
||||||
self.Location = ((1 / 24f) * self.CenterLocation).ToInt2();
|
self.Location = ((1 / 24f) * self.CenterLocation).ToInt2();
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#region Copyright & License Information
|
#region Copyright & License Information
|
||||||
/*
|
/*
|
||||||
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
||||||
* This file is part of OpenRA.
|
* This file is part of OpenRA.
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using OpenRA.GameRules;
|
||||||
|
|
||||||
namespace OpenRA.Traits.Activities
|
namespace OpenRA.Traits.Activities
|
||||||
{
|
{
|
||||||
@@ -54,7 +55,7 @@ namespace OpenRA.Traits.Activities
|
|||||||
|
|
||||||
var desiredFacing = Util.GetFacing(d, unit.Facing);
|
var desiredFacing = Util.GetFacing(d, unit.Facing);
|
||||||
Util.TickFacing(ref unit.Facing, desiredFacing, self.Info.Traits.Get<UnitInfo>().ROT);
|
Util.TickFacing(ref unit.Facing, desiredFacing, self.Info.Traits.Get<UnitInfo>().ROT);
|
||||||
var speed = .2f * Util.GetEffectiveSpeed(self);
|
var speed = .2f * Util.GetEffectiveSpeed(self, UnitMovementType.Fly);
|
||||||
var angle = unit.Facing / 128f * Math.PI;
|
var angle = unit.Facing / 128f * Math.PI;
|
||||||
|
|
||||||
self.CenterLocation += speed * -float2.FromAngle((float)angle);
|
self.CenterLocation += speed * -float2.FromAngle((float)angle);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#region Copyright & License Information
|
#region Copyright & License Information
|
||||||
/*
|
/*
|
||||||
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
||||||
* This file is part of OpenRA.
|
* This file is part of OpenRA.
|
||||||
@@ -23,6 +23,7 @@ using System.Collections.Generic;
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using OpenRA.GameRules;
|
||||||
|
|
||||||
namespace OpenRA.Traits.Activities
|
namespace OpenRA.Traits.Activities
|
||||||
{
|
{
|
||||||
@@ -237,7 +238,8 @@ namespace OpenRA.Traits.Activities
|
|||||||
|
|
||||||
public void TickMove( Actor self, Mobile mobile, Move parent )
|
public void TickMove( Actor self, Mobile mobile, Move parent )
|
||||||
{
|
{
|
||||||
moveFraction += (int)Util.GetEffectiveSpeed(self);
|
var umt = self.Info.Traits.Get<MobileInfo>().MovementType;
|
||||||
|
moveFraction += (int)Util.GetEffectiveSpeed(self, umt);
|
||||||
if( moveFraction >= moveFractionTotal )
|
if( moveFraction >= moveFractionTotal )
|
||||||
moveFraction = moveFractionTotal;
|
moveFraction = moveFractionTotal;
|
||||||
UpdateCenterLocation( self, mobile );
|
UpdateCenterLocation( self, mobile );
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#region Copyright & License Information
|
#region Copyright & License Information
|
||||||
/*
|
/*
|
||||||
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
||||||
* This file is part of OpenRA.
|
* This file is part of OpenRA.
|
||||||
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using OpenRA.GameRules;
|
||||||
|
|
||||||
namespace OpenRA.Traits.Activities
|
namespace OpenRA.Traits.Activities
|
||||||
{
|
{
|
||||||
@@ -51,7 +52,7 @@ namespace OpenRA.Traits.Activities
|
|||||||
|
|
||||||
var landPos = dest.CenterLocation;
|
var landPos = dest.CenterLocation;
|
||||||
var unit = self.traits.Get<Unit>();
|
var unit = self.traits.Get<Unit>();
|
||||||
var speed = .2f * Util.GetEffectiveSpeed(self);
|
var speed = .2f * Util.GetEffectiveSpeed(self, UnitMovementType.Fly);
|
||||||
var approachStart = landPos - new float2(unit.Altitude * speed, 0);
|
var approachStart = landPos - new float2(unit.Altitude * speed, 0);
|
||||||
var turnRadius = (128f / self.Info.Traits.Get<UnitInfo>().ROT) * speed / (float)Math.PI;
|
var turnRadius = (128f / self.Info.Traits.Get<UnitInfo>().ROT) * speed / (float)Math.PI;
|
||||||
|
|
||||||
|
|||||||
@@ -128,7 +128,12 @@ namespace OpenRA.Traits
|
|||||||
{
|
{
|
||||||
return Rules.TerrainTypes[Templates[state].TerrainType[Tiles[p]]].GetCost(umt);
|
return Rules.TerrainTypes[Templates[state].TerrainType[Tiles[p]]].GetCost(umt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float GetSpeedModifier(int2 p, UnitMovementType umt)
|
||||||
|
{
|
||||||
|
return Rules.TerrainTypes[Templates[state].TerrainType[Tiles[p]]].GetSpeedModifier(umt);
|
||||||
|
}
|
||||||
|
|
||||||
static bool IsIntact(Bridge b)
|
static bool IsIntact(Bridge b)
|
||||||
{
|
{
|
||||||
return b != null && b.self.IsInWorld && b.self.Health > 0;
|
return b != null && b.self.IsInWorld && b.self.Health > 0;
|
||||||
|
|||||||
@@ -85,8 +85,8 @@ namespace OpenRA.Traits
|
|||||||
if (!mi.Modifiers.HasModifier(Modifiers.Alt)) return null;
|
if (!mi.Modifiers.HasModifier(Modifiers.Alt)) return null;
|
||||||
if (!self.World.IsActorCrushableByActor(underCursor, self)) return null;
|
if (!self.World.IsActorCrushableByActor(underCursor, self)) return null;
|
||||||
}
|
}
|
||||||
|
var umt = self.Info.Traits.Get<MobileInfo>().MovementType;
|
||||||
if (Util.GetEffectiveSpeed(self) == 0) return null; /* allow disabling move orders from modifiers */
|
if (Util.GetEffectiveSpeed(self,umt) == 0) return null; /* allow disabling move orders from modifiers */
|
||||||
if (xy == toCell) return null;
|
if (xy == toCell) return null;
|
||||||
return new Order("Move", self, xy);
|
return new Order("Move", self, xy);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,11 @@ namespace OpenRA.Traits
|
|||||||
public interface IAcceptThief { void OnSteal(Actor self, Actor thief); }
|
public interface IAcceptThief { void OnSteal(Actor self, Actor thief); }
|
||||||
public interface IAcceptSpy { void OnInfiltrate(Actor self, Actor spy); }
|
public interface IAcceptSpy { void OnInfiltrate(Actor self, Actor spy); }
|
||||||
|
|
||||||
public interface ICustomTerrain { float GetCost(int2 p, UnitMovementType umt); }
|
public interface ICustomTerrain
|
||||||
|
{
|
||||||
|
float GetCost(int2 p, UnitMovementType umt);
|
||||||
|
float GetSpeedModifier(int2 p, UnitMovementType umt);
|
||||||
|
}
|
||||||
|
|
||||||
public interface IDisable { bool Disabled { get; set; } }
|
public interface IDisable { bool Disabled { get; set; } }
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ using System;
|
|||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
|
using OpenRA.GameRules;
|
||||||
|
|
||||||
namespace OpenRA.Traits
|
namespace OpenRA.Traits
|
||||||
{
|
{
|
||||||
@@ -138,16 +139,25 @@ namespace OpenRA.Traits
|
|||||||
return new Renderable(s, loc.Round(), pal);
|
return new Renderable(s, loc.Round(), pal);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float GetEffectiveSpeed(Actor self)
|
public static float GetEffectiveSpeed(Actor self, UnitMovementType umt)
|
||||||
{
|
{
|
||||||
var unitInfo = self.Info.Traits.GetOrDefault<UnitInfo>();
|
var unitInfo = self.Info.Traits.GetOrDefault<UnitInfo>();
|
||||||
if( unitInfo == null ) return 0f;
|
if( unitInfo == null ) return 0f;
|
||||||
|
|
||||||
|
var terrain = 1f;
|
||||||
|
if (umt != UnitMovementType.Fly)
|
||||||
|
{
|
||||||
|
var tt = self.World.GetTerrainType(self.Location);
|
||||||
|
terrain = Rules.TerrainTypes[tt].GetSpeedModifier(umt)*self.World.WorldActor.traits
|
||||||
|
.WithInterface<ICustomTerrain>()
|
||||||
|
.Select(t => t.GetSpeedModifier(self.Location, umt))
|
||||||
|
.Product();
|
||||||
|
}
|
||||||
var modifier = self.traits
|
var modifier = self.traits
|
||||||
.WithInterface<ISpeedModifier>()
|
.WithInterface<ISpeedModifier>()
|
||||||
.Select(t => t.GetSpeedModifier())
|
.Select(t => t.GetSpeedModifier())
|
||||||
.Product();
|
.Product();
|
||||||
return unitInfo.Speed * modifier;
|
return unitInfo.Speed * terrain * modifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IActivity SequenceActivities(params IActivity[] acts)
|
public static IActivity SequenceActivities(params IActivity[] acts)
|
||||||
|
|||||||
@@ -95,7 +95,13 @@ namespace OpenRA.Traits
|
|||||||
return customTerrain[p.X,p.Y].GetCost(p,umt);
|
return customTerrain[p.X,p.Y].GetCost(p,umt);
|
||||||
return 1f;
|
return 1f;
|
||||||
}
|
}
|
||||||
|
public float GetSpeedModifier(int2 p, UnitMovementType umt)
|
||||||
|
{
|
||||||
|
if (customTerrain[p.X, p.Y] != null)
|
||||||
|
return customTerrain[p.X,p.Y].GetSpeedModifier(p,umt);
|
||||||
|
return 1f;
|
||||||
|
}
|
||||||
|
|
||||||
static bool IsBridge(World w, ushort t)
|
static bool IsBridge(World w, ushort t)
|
||||||
{
|
{
|
||||||
return w.TileSet.walk[t].Bridge != null;
|
return w.TileSet.walk[t].Bridge != null;
|
||||||
|
|||||||
@@ -88,11 +88,11 @@ namespace OpenRA.Traits
|
|||||||
content[x, y].density = GetIdealDensity(x, y);
|
content[x, y].density = GetIdealDensity(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public float GetSpeedMultiplier(UnitMovementType umt, int2 p)
|
public float GetSpeedModifier(int2 p, UnitMovementType umt)
|
||||||
{
|
{
|
||||||
if (content[p.X,p.Y].type == null)
|
if (content[p.X,p.Y].type == null)
|
||||||
return 1.0f;
|
return 1.0f;
|
||||||
return content[p.X,p.Y].type.GetSpeedMultiplier(umt);
|
return content[p.X,p.Y].type.GetSpeedModifier(umt);
|
||||||
}
|
}
|
||||||
|
|
||||||
public float GetCost(int2 p,UnitMovementType umt)
|
public float GetCost(int2 p,UnitMovementType umt)
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ namespace OpenRA.Traits
|
|||||||
for (var umt = UnitMovementType.Foot; umt <= UnitMovementType.Float; umt++ )
|
for (var umt = UnitMovementType.Foot; umt <= UnitMovementType.Float; umt++ )
|
||||||
{
|
{
|
||||||
// HACK: hardcode "ore" terraintype for now
|
// HACK: hardcode "ore" terraintype for now
|
||||||
movementSpeed[(int)umt] = (info.MovementTerrainType != null) ? (float)Rules.TerrainTypes[TerrainType.Ore].GetSpeedMultiplier(umt) : 1.0f;
|
movementSpeed[(int)umt] = (info.MovementTerrainType != null) ? (float)Rules.TerrainTypes[TerrainType.Ore].GetSpeedModifier(umt) : 1.0f;
|
||||||
pathCost[(int)umt] = (info.PathingTerrainType != null) ? (float)Rules.TerrainTypes[TerrainType.Ore].GetCost(umt)
|
pathCost[(int)umt] = (info.PathingTerrainType != null) ? (float)Rules.TerrainTypes[TerrainType.Ore].GetCost(umt)
|
||||||
: (info.MovementTerrainType != null) ? (float)Rules.TerrainTypes[TerrainType.Ore].GetCost(umt) : 1.0f;
|
: (info.MovementTerrainType != null) ? (float)Rules.TerrainTypes[TerrainType.Ore].GetCost(umt) : 1.0f;
|
||||||
}
|
}
|
||||||
@@ -64,7 +64,7 @@ namespace OpenRA.Traits
|
|||||||
this.info = info;
|
this.info = info;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float GetSpeedMultiplier(UnitMovementType umt)
|
public float GetSpeedModifier(UnitMovementType umt)
|
||||||
{
|
{
|
||||||
return movementSpeed[(int)umt];
|
return movementSpeed[(int)umt];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user