Created
May 23, 2010 00:38
-
-
Save chrisforbes/410498 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// damage per second evaluation for OpenRA mods | |
using System; | |
using System.IO; | |
using System.Linq; | |
using OpenRA; | |
using OpenRA.FileFormats; | |
using OpenRA.GameRules; | |
using OpenRA.Traits; | |
namespace dpstool | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
AppDomain.CurrentDomain.AssemblyResolve += FileSystem.ResolveAssembly; | |
LocateGameRoot(); | |
var manifest = new Manifest(new[] { args.FirstOrDefault() ?? "ra" }); | |
Game.LoadModAssemblies(manifest); | |
FileSystem.UnmountAll(); | |
foreach (var folder in manifest.Folders) FileSystem.Mount(folder); | |
foreach (var pkg in manifest.Packages) FileSystem.Mount(pkg); | |
Rules.LoadRules(manifest, new Map()); | |
foreach (var actorType in Rules.Info.Values) | |
DumpActorReport(actorType); | |
} | |
static void DumpActorReport(ActorInfo a) | |
{ | |
var weapons = a.Traits.WithInterface<AttackBaseInfo>() | |
.SelectMany(x => new[] { x.PrimaryWeapon, x.SecondaryWeapon }).Where(w => w != null) | |
.Select(w => Rules.Weapons[w.ToLowerInvariant()]); | |
var damage = weapons.Select(w => new { ROF = w.ROF, Damage = w.Burst * w.Warheads.Sum(z => z.Damage) }); | |
var dps = damage.Sum(d => (float)d.Damage / d.ROF * 25); | |
if (weapons.Any()) | |
Console.WriteLine("{0}: {2:F1} ({1})".F( | |
a.Name, string.Join(",", damage.Select(d => "{0}@{1}".F(d.Damage, d.ROF)).ToArray()), | |
dps)); | |
} | |
static void LocateGameRoot() | |
{ | |
while (!Directory.Exists("mods")) | |
{ | |
var current = Directory.GetCurrentDirectory(); | |
if (Directory.GetDirectoryRoot(current) == current) | |
throw new InvalidOperationException("Unable to find game root."); | |
Directory.SetCurrentDirectory(".."); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment