Assembly resolving, fixes to crate dropping.

This commit is contained in:
Matthew Bowra-Dean
2010-03-19 17:50:27 +13:00
parent c2e9f41051
commit d471c602c7
4 changed files with 45 additions and 4 deletions

View File

@@ -21,6 +21,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
namespace OpenRA.FileFormats
{
@@ -134,5 +135,34 @@ namespace OpenRA.FileFormats
return false;
}
static Dictionary<string, Assembly> assemblyCache = new Dictionary<string, Assembly>();
public static Assembly ResolveAssembly(object sender, ResolveEventArgs e)
{
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
{
if (assembly.FullName == e.Name)
return assembly;
}
string[] frags = e.Name.Split(',');
var filename = frags[0] + ".dll";
Assembly a;
if (assemblyCache.TryGetValue(filename, out a))
return a;
if (FileSystem.Exists(filename))
using (Stream s = FileSystem.Open(filename))
{
byte[] buf = new byte[s.Length];
s.Read(buf, 0, buf.Length);
a = Assembly.Load(buf);
assemblyCache.Add(filename, a);
return a;
}
return null;
}
}
}

View File

@@ -348,6 +348,7 @@ namespace OpenRA
public static void PreInit(Settings settings)
{
AppDomain.CurrentDomain.AssemblyResolve += FileSystem.ResolveAssembly;
while (!Directory.Exists("mods"))
{
var current = Directory.GetCurrentDirectory();

View File

@@ -22,6 +22,7 @@ using System;
using System.Collections.Generic;
using OpenRA.Mods.RA;
using OpenRA.Traits;
using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA_NG
{
@@ -72,9 +73,11 @@ namespace OpenRA.Mods.RA_NG
{
self.World.AddFrameEndTask(w =>
{
var crate = new Actor(w, "crate", new int2(0, 0), self.Owner);
var crate = new Actor(w, "crate", new int2(0, 0), w.NeutralPlayer);
crates.Add(crate);
var plane = w.CreateActor("BADR", w.ChooseRandomEdgeCell(), self.Owner);
var plane = w.CreateActor("BADR", w.ChooseRandomEdgeCell(), w.NeutralPlayer);
plane.CancelActivity();
plane.QueueActivity(new FlyCircle(p));
plane.traits.Get<ParaDrop>().SetLZ(p);
plane.traits.Get<Cargo>().Load(plane, crate);
});

View File

@@ -65,9 +65,16 @@ namespace OpenRA.Mods.RA.Effects
world.AddFrameEndTask(w =>
{
w.Remove(this);
w.Add(cargo);
int2 loc = ((1 / 24f) * location).ToInt2();
cargo.CancelActivity();
cargo.traits.Get<Mobile>().TeleportTo(cargo, ((1 / 24f) * location).ToInt2());
if (cargo.traits.Contains<Mobile>())
cargo.traits.Get<Mobile>().TeleportTo(cargo, loc);
else
{
cargo.Location = loc;
cargo.CenterLocation = Util.CenterOfCell(loc);
}
w.Add(cargo);
});
}