Merge pull request #6218 from pchote/percentmods

Change attribute modifiers to use integers.
This commit is contained in:
Matthias Mailänder
2014-08-16 17:28:37 +02:00
19 changed files with 121 additions and 66 deletions

View File

@@ -50,16 +50,17 @@ namespace OpenRA.Mods.RA.Activities
if (target.Type != TargetType.Actor)
return;
// Invulnerable actors can't be demolished
var modifier = (float)target.Actor.TraitsImplementing<IDamageModifier>()
.Concat(self.Owner.PlayerActor.TraitsImplementing<IDamageModifier>())
.Select(t => t.GetDamageModifier(self, null)).Product();
var demolishable = target.Actor.TraitOrDefault<IDemolishable>();
if (demolishable == null || !demolishable.IsValidTarget(target.Actor, self))
return;
if (modifier > 0)
var modifiers = target.Actor.TraitsImplementing<IDamageModifier>()
.Concat(self.Owner.PlayerActor.TraitsImplementing<IDamageModifier>())
.Select(t => t.GetDamageModifier(self, null));
if (Util.ApplyPercentageModifiers(100, modifiers) > 0)
demolishable.Demolish(target.Actor, self);
}));
});

View File

@@ -203,10 +203,9 @@ namespace OpenRA.Mods.RA.Air
{
get
{
decimal ret = info.Speed;
foreach (var t in self.TraitsImplementing<ISpeedModifier>())
ret *= t.GetSpeedModifier();
return (int)ret;
var modifiers = self.TraitsImplementing<ISpeedModifier>()
.Select(m => m.GetSpeedModifier());
return Util.ApplyPercentageModifiers(info.Speed, modifiers);
}
}

View File

@@ -153,8 +153,10 @@ namespace OpenRA.Mods.RA
{
Weapon = Weapon,
Facing = legacyFacing,
// TODO: Convert to ints
FirepowerModifier = self.TraitsImplementing<IFirepowerModifier>()
.Select(a => a.GetFirepowerModifier())
.Select(a => a.GetFirepowerModifier() / 100f)
.Product(),
Source = muzzlePosition,

View File

@@ -23,8 +23,8 @@ namespace OpenRA.Mods.RA
public int CloseDelay = 125;
public int DefaultFacing = 0;
[Desc("The factor damage received is multiplied by while this actor is closed.")]
public float ClosedDamageMultiplier = 0.5f;
[Desc("The percentage of damage that is received while this actor is closed.")]
public int ClosedDamageMultiplier = 50;
public override object Create(ActorInitializer init) { return new AttackPopupTurreted(init, this); }
}
@@ -105,9 +105,9 @@ namespace OpenRA.Mods.RA
}
}
public float GetDamageModifier(Actor attacker, DamageWarhead warhead)
public int GetDamageModifier(Actor attacker, DamageWarhead warhead)
{
return state == PopupState.Closed ? info.ClosedDamageMultiplier : 1f;
return state == PopupState.Closed ? info.ClosedDamageMultiplier : 100;
}
}
}

View File

@@ -19,13 +19,13 @@ namespace OpenRA.Mods.RA
public class GainsStatUpgradesInfo : ITraitInfo
{
public readonly string FirepowerUpgrade = "firepower";
public readonly float[] FirepowerModifier = { 1.1f, 1.15f, 1.2f, 1.5f };
public readonly int[] FirepowerModifier = { 110, 115, 120, 150 };
public readonly string ArmorUpgrade = "armor";
public readonly float[] ArmorModifier = { 1.1f, 1.2f, 1.3f, 1.5f };
public readonly int[] ArmorModifier = { 110, 120, 130, 150 };
public readonly string SpeedUpgrade = "speed";
public readonly decimal[] SpeedModifier = { 1.1m, 1.15m, 1.2m, 1.5m };
public readonly int[] SpeedModifier = { 110, 115, 120, 150 };
public object Create(ActorInitializer init) { return new GainsStatUpgrades(this); }
}
@@ -60,19 +60,19 @@ namespace OpenRA.Mods.RA
speedLevel = (speedLevel + mod).Clamp(0, info.SpeedModifier.Length);
}
public float GetDamageModifier(Actor attacker, DamageWarhead warhead)
public int GetDamageModifier(Actor attacker, DamageWarhead warhead)
{
return armorLevel > 0 ? 1 / info.ArmorModifier[armorLevel - 1] : 1;
return armorLevel > 0 ? 1 / info.ArmorModifier[armorLevel - 1] : 100;
}
public float GetFirepowerModifier()
public int GetFirepowerModifier()
{
return firepowerLevel > 0 ? info.FirepowerModifier[firepowerLevel - 1] : 1;
return firepowerLevel > 0 ? info.FirepowerModifier[firepowerLevel - 1] : 100;
}
public decimal GetSpeedModifier()
public int GetSpeedModifier()
{
return speedLevel > 0 ? info.SpeedModifier[speedLevel - 1] : 1m;
return speedLevel > 0 ? info.SpeedModifier[speedLevel - 1] : 100;
}
}
}

View File

@@ -31,8 +31,8 @@ namespace OpenRA.Mods.RA
public readonly int HarvestFacings = 0;
[Desc("Which resources it can harvest.")]
public readonly string[] Resources = { };
[Desc("How much it is slowed down when returning to the refinery.")]
public readonly decimal FullyLoadedSpeed = .85m;
[Desc("Percentage of maximum speed when fully loaded.")]
public readonly int FullyLoadedSpeed = 85;
[Desc("Initial search radius (in cells) from the refinery that created us.")]
public readonly int SearchFromProcRadius = 24;
[Desc("Search radius (in cells) from the last harvest order location to find more resources.")]
@@ -418,9 +418,9 @@ namespace OpenRA.Mods.RA
public bool ShouldExplode(Actor self) { return !IsEmpty; }
public decimal GetSpeedModifier()
public int GetSpeedModifier()
{
return 1m - (1m - Info.FullyLoadedSpeed) * contents.Values.Sum() / Info.Capacity;
return 100 - (100 - Info.FullyLoadedSpeed) * contents.Values.Sum() / Info.Capacity;
}
class HarvestOrderTargeter : IOrderTargeter

View File

@@ -18,6 +18,6 @@ namespace OpenRA.Mods.RA
class Invulnerable : IDamageModifier
{
public float GetDamageModifier(Actor attacker, DamageWarhead warhead) { return 0.0f; }
public int GetDamageModifier(Actor attacker, DamageWarhead warhead) { return 0; }
}
}

View File

@@ -28,9 +28,9 @@ namespace OpenRA.Mods.RA
RemainingTicks--;
}
public float GetDamageModifier(Actor attacker, DamageWarhead warhead)
public int GetDamageModifier(Actor attacker, DamageWarhead warhead)
{
return (RemainingTicks > 0) ? 0.0f : 1.0f;
return RemainingTicks > 0 ? 0 : 100;
}
public void Activate(Actor self, int duration)

View File

@@ -487,13 +487,15 @@ namespace OpenRA.Mods.RA.Move
if (index == -1)
return 0;
// TODO: Convert to integers
var speed = Info.TilesetTerrainInfo[self.World.TileSet][index].Speed;
if (speed == decimal.Zero)
return 0;
speed *= Info.Speed;
foreach (var t in self.TraitsImplementing<ISpeedModifier>())
speed *= t.GetSpeedModifier();
speed *= t.GetSpeedModifier() / 100m;
return (int)(speed / 100);
}

View File

@@ -17,7 +17,7 @@ namespace OpenRA.Mods.RA
class ScaredyCatInfo : ITraitInfo
{
public readonly int PanicLength = 25 * 10;
public readonly decimal PanicSpeedModifier = 2;
public readonly int PanicSpeedModifier = 200;
public readonly int AttackPanicChance = 20;
public object Create(ActorInitializer init) { return new ScaredyCat(init.self, this); }
@@ -74,9 +74,9 @@ namespace OpenRA.Mods.RA
Panic();
}
public decimal GetSpeedModifier()
public int GetSpeedModifier()
{
return Panicking ? Info.PanicSpeedModifier : 1;
return Panicking ? Info.PanicSpeedModifier : 100;
}
}
}

View File

@@ -20,9 +20,9 @@ namespace OpenRA.Mods.RA
{
public bool Invulnerable = false;
public float GetDamageModifier(Actor attacker, DamageWarhead warhead)
public int GetDamageModifier(Actor attacker, DamageWarhead warhead)
{
return Invulnerable ? 0.0f : 1.0f;
return Invulnerable ? 0 : 100;
}
}
}

View File

@@ -21,8 +21,8 @@ namespace OpenRA.Mods.RA
"Measured in game ticks. Default is 4 seconds.")]
public readonly int ProneTime = 100;
[Desc("How quickly we should go from standing to prone.")]
public readonly decimal ProneSpeed = .5m;
[Desc("Prone movement speed as a percentage of the normal speed.")]
public readonly int SpeedModifier = 50;
public readonly WVec ProneOffset = new WVec(85, 0, -171);
@@ -61,14 +61,14 @@ namespace OpenRA.Mods.RA
LocalOffset = WVec.Zero;
}
public float GetDamageModifier(Actor attacker, DamageWarhead warhead)
public int GetDamageModifier(Actor attacker, DamageWarhead warhead)
{
return IsProne && warhead != null ? warhead.ProneModifier / 100f : 1f;
return IsProne && warhead != null ? warhead.ProneModifier : 100;
}
public decimal GetSpeedModifier()
public int GetSpeedModifier()
{
return IsProne ? Info.ProneSpeed : 1m;
return IsProne ? Info.SpeedModifier : 100;
}
}