export health, cost and damage per section into a CSV file

closes #3855
This commit is contained in:
Matthias Mailänder
2014-06-15 20:10:51 +02:00
parent 60d973aab4
commit 8249012e4b
4 changed files with 57 additions and 2 deletions

View File

@@ -20,6 +20,7 @@ using System.Text;
using OpenRA.FileFormats;
using OpenRA.FileSystem;
using OpenRA.Graphics;
using OpenRA.Mods.RA;
using OpenRA.Scripting;
using OpenRA.Traits;
@@ -544,5 +545,53 @@ namespace OpenRA.Utility
map.Save(dest);
Console.WriteLine(dest + " saved.");
}
[Desc("MOD", "Export the game rules into a CSV file to inspect in a spreadheet.")]
public static void ExportCharacterSeparatedRules(string[] args)
{
var mod = args[1];
Game.modData = new ModData(mod);
var rules = Game.modData.RulesetCache.LoadDefaultRules();
var dump = new StringBuilder();
dump.AppendLine("Name;Faction;Health;Cost;Damage per Second");
foreach (var actorInfo in rules.Actors.Values)
{
if (actorInfo.Name.StartsWith("^"))
continue;
var buildable = actorInfo.Traits.GetOrDefault<BuildableInfo>();
if (buildable == null)
continue;
var faction = FieldSaver.FormatValue(buildable.Owner, buildable.Owner.GetType());
var damagePerSecond = 0f;
var armaments = actorInfo.Traits.WithInterface<ArmamentInfo>();
if (armaments.Any())
{
var weapons = armaments.Select(a => a.Weapon).Select(w => rules.Weapons[w.ToLowerInvariant()]);
if (weapons.Any())
{
var damage = weapons.Select(w => new { ROF = w.ROF > 0 ? w.ROF : 1, Damage = w.Burst * w.Warheads.Sum(z => z.Damage) });
damagePerSecond = damage.Sum(d => (float)d.Damage / d.ROF * 25);
}
}
var tooltip = actorInfo.Traits.GetOrDefault<TooltipInfo>();
var name = tooltip != null ? tooltip.Name : actorInfo.Name;
var health = actorInfo.Traits.GetOrDefault<HealthInfo>();
var hp = health != null ? health.HP : 0;
var value = actorInfo.Traits.GetOrDefault<ValuedInfo>();
var cost = value != null ? value.Cost : 0;
dump.AppendLine("{0};{1};{2};{3};{4}".F(name, faction, hp, cost, damagePerSecond));
}
var filename = "{0}-mod-rules.csv".F(mod);
using (StreamWriter outfile = new StreamWriter(filename))
outfile.Write(dump.ToString());
Console.WriteLine("{0} has been saved.\nOpen in a spreadsheet application as values separated by semicolon.".F(filename));
}
}
}

View File

@@ -87,6 +87,10 @@
<Project>{0DFB103F-2962-400F-8C6D-E2C28CCBA633}</Project>
<Name>OpenRA.Game</Name>
</ProjectReference>
<ProjectReference Include="..\OpenRA.Mods.RA\OpenRA.Mods.RA.csproj">
<Project>{4A8A43B5-A9EF-4ED0-99DD-4BAB10A0DB6E}</Project>
<Name>OpenRA.Mods.RA</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">

View File

@@ -34,7 +34,8 @@ namespace OpenRA.Utility
{ "--upgrade-map", UpgradeRules.UpgradeMap },
{ "--upgrade-mod", UpgradeRules.UpgradeMod },
{ "--map-import", Command.ImportLegacyMap },
{ "--extract-language-strings", ExtractLanguageStrings.FromMod }
{ "--extract-language-strings", ExtractLanguageStrings.FromMod },
{ "--csv", Command.ExportCharacterSeparatedRules }
};
static void Main(string[] args)