Merge pull request #4383 from cjshmyr/levelup

Initial support for unit upgrade crates
This commit is contained in:
Paul Chote
2013-12-30 19:22:40 -08:00
14 changed files with 152 additions and 1 deletions

View File

@@ -13,6 +13,8 @@ NEW:
Converted actor speed to world coordinates.
Added support for rectangular cells with forced perspective.
Added initial support for Tmp(TS) sprites.
Added GainsUnitUpgrades trait for leveling specific unit upgrades - firepower, armor, speed.
Added support for crates to level up specific unit upgrades.
Asset Browser:
Filenames are now listed in alphabetical order
Mod / Custom map compatibility:

View File

@@ -0,0 +1,51 @@
#region Copyright & License Information
/*
* Copyright 2007-2014 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. For more information,
* see COPYING.
*/
#endregion
using System.Linq;
namespace OpenRA.Mods.RA.Crates
{
public class UnitUpgradeCrateActionInfo : CrateActionInfo
{
public readonly UnitUpgrade? Upgrade = null;
public readonly int Levels = 1;
public override object Create(ActorInitializer init) { return new UnitUpgradeCrateAction(init.self, this); }
}
public class UnitUpgradeCrateAction : CrateAction
{
UnitUpgradeCrateActionInfo crateInfo;
public UnitUpgradeCrateAction(Actor self, UnitUpgradeCrateActionInfo info)
: base(self, info)
{
crateInfo = info;
}
public override int GetSelectionShares(Actor collector)
{
var up = collector.TraitOrDefault<GainsUnitUpgrades>();
return up != null && up.CanGainUnitUpgrade(crateInfo.Upgrade) ? info.SelectionShares : 0;
}
public override void Activate(Actor collector)
{
collector.World.AddFrameEndTask(w =>
{
var gainsStatBonuses = collector.TraitOrDefault<GainsUnitUpgrades>();
if (gainsStatBonuses != null)
gainsStatBonuses.GiveUnitUpgrade(crateInfo.Upgrade, crateInfo.Levels);
});
base.Activate(collector);
}
}
}

View File

@@ -0,0 +1,86 @@
#region Copyright & License Information
/*
* Copyright 2007-2014 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. For more information,
* see COPYING.
*/
#endregion
using System;
using OpenRA.Traits;
using OpenRA.GameRules;
namespace OpenRA.Mods.RA
{
public class GainsUnitUpgradesInfo : ITraitInfo
{
public readonly int FirepowerMaxLevel = 15;
public readonly float FirepowerModifier = .2f;
public readonly int ArmorMaxLevel = 15;
public readonly float ArmorModifier = .2f;
public readonly int SpeedMaxLevel = 15;
public readonly decimal SpeedModifier = .2m;
// TODO: weapon range, rate of fire modifiers. potentially a vision modifier.
public object Create(ActorInitializer init) { return new GainsUnitUpgrades(this); }
}
public class GainsUnitUpgrades : IFirepowerModifier, IDamageModifier, ISpeedModifier
{
GainsUnitUpgradesInfo info;
[Sync] public int FirepowerLevel = 0;
[Sync] public int SpeedLevel = 0;
[Sync] public int ArmorLevel = 0;
public GainsUnitUpgrades(GainsUnitUpgradesInfo info)
{
this.info = info;
}
public bool CanGainUnitUpgrade(UnitUpgrade? upgrade)
{
if (upgrade == UnitUpgrade.Firepower)
return FirepowerLevel < info.FirepowerMaxLevel;
if (upgrade == UnitUpgrade.Armor)
return ArmorLevel < info.ArmorMaxLevel;
if (upgrade == UnitUpgrade.Speed)
return SpeedLevel < info.SpeedMaxLevel;
return false;
}
public void GiveUnitUpgrade(UnitUpgrade? upgrade, int numLevels)
{
if (upgrade == UnitUpgrade.Firepower)
FirepowerLevel = Math.Min(FirepowerLevel + numLevels, info.FirepowerMaxLevel);
else if (upgrade == UnitUpgrade.Armor)
ArmorLevel = Math.Min(ArmorLevel + numLevels, info.ArmorMaxLevel);
else if (upgrade == UnitUpgrade.Speed)
SpeedLevel = Math.Min(SpeedLevel + numLevels, info.SpeedMaxLevel);
}
public float GetFirepowerModifier()
{
return FirepowerLevel > 0 ? (1 + FirepowerLevel * info.FirepowerModifier) : 1;
}
public float GetDamageModifier(Actor attacker, WarheadInfo warhead)
{
return ArmorLevel > 0 ? (1 / (1 + ArmorLevel * info.ArmorModifier)) : 1;
}
public decimal GetSpeedModifier()
{
return SpeedLevel > 0 ? (1m + SpeedLevel * info.SpeedModifier) : 1m;
}
}
public enum UnitUpgrade
{
Firepower = 0,
Armor = 1,
Speed = 2
}
}

View File

@@ -123,6 +123,7 @@
<Compile Include="Air\Aircraft.cs" />
<Compile Include="Air\AttackHeli.cs" />
<Compile Include="Air\AttackPlane.cs" />
<Compile Include="Crates\UnitUpgradeCrateAction.cs" />
<Compile Include="EjectOnDeath.cs" />
<Compile Include="Air\FallsToEarth.cs" />
<Compile Include="Air\Fly.cs" />
@@ -237,6 +238,7 @@
<Compile Include="Fake.cs" />
<Compile Include="FreeActor.cs" />
<Compile Include="GainsExperience.cs" />
<Compile Include="GainsUnitUpgrades.cs" />
<Compile Include="GivesBounty.cs" />
<Compile Include="GivesExperience.cs" />
<Compile Include="Guard.cs" />
@@ -538,4 +540,4 @@ copy "FuzzyLogicLibrary.dll" "$(SolutionDir)"
cd "$(SolutionDir)"</PostBuildEvent>
</PropertyGroup>
<ItemGroup />
</Project>
</Project>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -8,6 +8,7 @@ Folders:
.
./mods/cnc
./mods/cnc/bits
./mods/cnc/bits/ss
./mods/cnc/uibits
~^/Content/cnc

View File

@@ -234,6 +234,15 @@ crate-effects:
Start: 0
Length: *
Tick: 200
firepowerup: firepowercrate
Start: 0
Length: *
armorup: armorcrate
Start: 0
Length: *
speedup: speedcrate
Start: 0
Length: *
atomicup:
idle: