GetEffectiveSpeed() factored out; Mobile hacked to only allow Move orders if the speed is nonzero
This commit is contained in:
@@ -22,5 +22,10 @@ namespace OpenRa.Game
|
|||||||
// this is probably a shockingly-slow way to do this, but it's concise.
|
// this is probably a shockingly-slow way to do this, but it's concise.
|
||||||
return xs.Except(ys).Concat(ys.Except(xs));
|
return xs.Except(ys).Concat(ys.Except(xs));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static float Product(this IEnumerable<float> xs)
|
||||||
|
{
|
||||||
|
return xs.Aggregate((a, x) => a * x);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -168,11 +168,7 @@ namespace OpenRa.Game.Traits.Activities
|
|||||||
var oldFraction = moveFraction;
|
var oldFraction = moveFraction;
|
||||||
var oldTotal = moveFractionTotal;
|
var oldTotal = moveFractionTotal;
|
||||||
|
|
||||||
var actualSpeed = (int)self.traits.WithInterface<ISpeedModifier>().Aggregate(
|
moveFraction += (int)Util.GetEffectiveSpeed(self);
|
||||||
(float)(self.Info as MobileInfo).Speed,
|
|
||||||
(a, t) => t.GetSpeedModifier() * a);
|
|
||||||
|
|
||||||
moveFraction += actualSpeed;
|
|
||||||
UpdateCenterLocation( self, mobile );
|
UpdateCenterLocation( self, mobile );
|
||||||
if( moveFraction >= moveFractionTotal )
|
if( moveFraction >= moveFractionTotal )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -48,12 +48,7 @@ namespace OpenRa.Game.Traits
|
|||||||
Util.TickFacing(ref unit.Facing, desiredFacing,
|
Util.TickFacing(ref unit.Facing, desiredFacing,
|
||||||
self.Info.ROT);
|
self.Info.ROT);
|
||||||
|
|
||||||
var actualSpeed = self.traits.WithInterface<ISpeedModifier>().Aggregate(
|
var rawSpeed = .2f * Util.GetEffectiveSpeed(self);
|
||||||
(float)(self.Info as MobileInfo).Speed,
|
|
||||||
(a, t) => t.GetSpeedModifier() * a);
|
|
||||||
|
|
||||||
// .6f going the wrong way; .8f going sideways, 1f going forward.
|
|
||||||
var rawSpeed = .2f * actualSpeed;
|
|
||||||
var angle = (unit.Facing - desiredFacing) / 128f * Math.PI;
|
var angle = (unit.Facing - desiredFacing) / 128f * Math.PI;
|
||||||
var scale = .4f + .6f * (float)Math.Cos(angle);
|
var scale = .4f + .6f * (float)Math.Cos(angle);
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ namespace OpenRa.Game.Traits
|
|||||||
{
|
{
|
||||||
if (mi.Button == MouseButton.Left) return null;
|
if (mi.Button == MouseButton.Left) return null;
|
||||||
if (underCursor != null) return null;
|
if (underCursor != null) return null;
|
||||||
|
if (Util.GetEffectiveSpeed(self) == 0) return null; /* allow disabling move orders from modifiers */
|
||||||
if (xy == toCell) return null;
|
if (xy == toCell) return null;
|
||||||
return Order.Move(self, xy);
|
return Order.Move(self, xy);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRa.Game.Graphics;
|
using OpenRa.Game.Graphics;
|
||||||
|
using OpenRa.Game.GameRules;
|
||||||
|
|
||||||
namespace OpenRa.Game.Traits
|
namespace OpenRa.Game.Traits
|
||||||
{
|
{
|
||||||
@@ -124,5 +125,17 @@ namespace OpenRa.Game.Traits
|
|||||||
var loc = location - 0.5f * s.size;
|
var loc = location - 0.5f * s.size;
|
||||||
return Tuple.New(s, loc.Round(), 8);
|
return Tuple.New(s, loc.Round(), 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static float GetEffectiveSpeed(Actor self)
|
||||||
|
{
|
||||||
|
var mi = self.Info as MobileInfo;
|
||||||
|
if (mi == null) return 0f;
|
||||||
|
|
||||||
|
var modifier = self.traits
|
||||||
|
.WithInterface<ISpeedModifier>()
|
||||||
|
.Select(t => t.GetSpeedModifier())
|
||||||
|
.Product();
|
||||||
|
return mi.Speed * modifier;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user