Terrain speed modifiers

This commit is contained in:
Paul Chote
2010-04-17 20:42:42 +12:00
committed by Chris Forbes
parent 4a6c32bd9c
commit fcf8eb2726
14 changed files with 58 additions and 26 deletions

View File

@@ -41,7 +41,7 @@ namespace OpenRA.GameRules
public TerrainCost(MiniYaml y) { FieldLoader.Load(this, y); }
public float GetSpeedMultiplier(UnitMovementType umt)
public float GetSpeedModifier(UnitMovementType umt)
{
switch (umt) /* todo: make this nice */
{

View File

@@ -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.
* This file is part of OpenRA.
@@ -19,6 +19,7 @@
#endregion
using System;
using OpenRA.GameRules;
namespace OpenRA.Traits.Activities
{
@@ -64,7 +65,7 @@ namespace OpenRA.Traits.Activities
public static void Fly(Actor self, int desiredAltitude )
{
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;
self.CenterLocation += speed * -float2.FromAngle((float)angle);

View File

@@ -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.
* This file is part of OpenRA.
@@ -19,6 +19,7 @@
#endregion
using System;
using OpenRA.GameRules;
namespace OpenRA.Traits.Activities
{
@@ -55,7 +56,7 @@ namespace OpenRA.Traits.Activities
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.Location = ((1 / 24f) * self.CenterLocation).ToInt2();
}

View File

@@ -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.
* This file is part of OpenRA.
@@ -19,6 +19,7 @@
#endregion
using System;
using OpenRA.GameRules;
namespace OpenRA.Traits.Activities
{
@@ -59,7 +60,7 @@ namespace OpenRA.Traits.Activities
Util.TickFacing(ref unit.Facing, desiredFacing,
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.Location = ((1 / 24f) * self.CenterLocation).ToInt2();

View File

@@ -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.
* This file is part of OpenRA.
@@ -19,6 +19,7 @@
#endregion
using System;
using OpenRA.GameRules;
namespace OpenRA.Traits.Activities
{
@@ -54,7 +55,7 @@ namespace OpenRA.Traits.Activities
var desiredFacing = Util.GetFacing(d, unit.Facing);
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;
self.CenterLocation += speed * -float2.FromAngle((float)angle);

View File

@@ -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.
* This file is part of OpenRA.
@@ -23,6 +23,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Drawing;
using OpenRA.GameRules;
namespace OpenRA.Traits.Activities
{
@@ -237,7 +238,8 @@ namespace OpenRA.Traits.Activities
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 )
moveFraction = moveFractionTotal;
UpdateCenterLocation( self, mobile );

View File

@@ -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.
* This file is part of OpenRA.
@@ -20,6 +20,7 @@
using System;
using System.Linq;
using OpenRA.GameRules;
namespace OpenRA.Traits.Activities
{
@@ -51,7 +52,7 @@ namespace OpenRA.Traits.Activities
var landPos = dest.CenterLocation;
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 turnRadius = (128f / self.Info.Traits.Get<UnitInfo>().ROT) * speed / (float)Math.PI;

View File

@@ -129,6 +129,11 @@ namespace OpenRA.Traits
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)
{
return b != null && b.self.IsInWorld && b.self.Health > 0;

View File

@@ -85,8 +85,8 @@ namespace OpenRA.Traits
if (!mi.Modifiers.HasModifier(Modifiers.Alt)) return null;
if (!self.World.IsActorCrushableByActor(underCursor, self)) return null;
}
if (Util.GetEffectiveSpeed(self) == 0) return null; /* allow disabling move orders from modifiers */
var umt = self.Info.Traits.Get<MobileInfo>().MovementType;
if (Util.GetEffectiveSpeed(self,umt) == 0) return null; /* allow disabling move orders from modifiers */
if (xy == toCell) return null;
return new Order("Move", self, xy);
}

View File

@@ -45,7 +45,11 @@ namespace OpenRA.Traits
public interface IAcceptThief { void OnSteal(Actor self, Actor thief); }
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; } }

View File

@@ -22,6 +22,7 @@ using System;
using System.Drawing;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.GameRules;
namespace OpenRA.Traits
{
@@ -138,16 +139,25 @@ namespace OpenRA.Traits
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>();
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
.WithInterface<ISpeedModifier>()
.Select(t => t.GetSpeedModifier())
.Product();
return unitInfo.Speed * modifier;
return unitInfo.Speed * terrain * modifier;
}
public static IActivity SequenceActivities(params IActivity[] acts)

View File

@@ -95,6 +95,12 @@ namespace OpenRA.Traits
return customTerrain[p.X,p.Y].GetCost(p,umt);
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)
{

View File

@@ -88,11 +88,11 @@ namespace OpenRA.Traits
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)
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)

View File

@@ -56,7 +56,7 @@ namespace OpenRA.Traits
for (var umt = UnitMovementType.Foot; umt <= UnitMovementType.Float; umt++ )
{
// 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)
: (info.MovementTerrainType != null) ? (float)Rules.TerrainTypes[TerrainType.Ore].GetCost(umt) : 1.0f;
}
@@ -64,7 +64,7 @@ namespace OpenRA.Traits
this.info = info;
}
public float GetSpeedMultiplier(UnitMovementType umt)
public float GetSpeedModifier(UnitMovementType umt)
{
return movementSpeed[(int)umt];
}