moved the rest of the mine crap into mod dll

This commit is contained in:
Chris Forbes
2010-01-17 09:35:51 +13:00
parent 59c0791d93
commit 47f95ff596
16 changed files with 105 additions and 96 deletions

View File

@@ -4,7 +4,7 @@ using OpenRa.Traits;
namespace OpenRa.Effects
{
class Explosion : IEffect
public class Explosion : IEffect
{
Animation anim;
int2 pos;

View File

@@ -1,7 +1,7 @@

namespace OpenRa.GameRules
{
class AftermathInfo
public class AftermathInfo
{
public readonly int MTankDistance = 0;
public readonly float QuakeUnitDamage = 0f;

View File

@@ -2,7 +2,7 @@
using System;
namespace OpenRa.GameRules
{
class GeneralInfo
public class GeneralInfo
{
/* Crates */
public readonly int CrateMinimum = 0;

View File

@@ -9,7 +9,7 @@ using System.Collections;
namespace OpenRa.GameRules
{
class InfoLoader<T> : IEnumerable<KeyValuePair<string, T>>
public class InfoLoader<T> : IEnumerable<KeyValuePair<string, T>>
{
readonly Dictionary<string, T> infos = new Dictionary<string, T>();

View File

@@ -1,7 +1,7 @@

namespace OpenRa.GameRules
{
class ProjectileInfo
public class ProjectileInfo
{
public readonly bool AA = false;
public readonly bool AG = true;

View File

@@ -7,7 +7,7 @@ using OpenRa.GameRules;
namespace OpenRa
{
static class Rules
public static class Rules
{
public static IniFile AllRules;
public static Dictionary<string, List<string>> Categories = new Dictionary<string, List<string>>();

View File

@@ -5,7 +5,7 @@ using OpenRa.Traits;
namespace OpenRa.GameRules
{
class TechTree
public class TechTree
{
readonly Cache<string, List<NewUnitInfo>> producesIndex = new Cache<string, List<NewUnitInfo>>(x => new List<NewUnitInfo>());

View File

@@ -7,7 +7,7 @@ using IjwFramework.Collections;
namespace OpenRa.GameRules
{
class VoiceInfo
public class VoiceInfo
{
public readonly string[] SovietVariants = { ".aud" };
public readonly string[] AlliedVariants = { ".aud" };
@@ -30,4 +30,29 @@ namespace OpenRa.GameRules
});
}
}
public class VoicePool
{
readonly string[] clips;
readonly List<string> liveclips = new List<string>();
public VoicePool(params string[] clips)
{
this.clips = clips;
}
public string GetNext()
{
if (liveclips.Count == 0)
liveclips.AddRange(clips);
if (liveclips.Count == 0)
return null; /* avoid crashing if there's no clips at all */
var i = Game.CosmeticRandom.Next(liveclips.Count);
var s = liveclips[i];
liveclips.RemoveAt(i);
return s;
}
}
}

View File

@@ -1,7 +1,7 @@

namespace OpenRa.GameRules
{
class WeaponInfo
public class WeaponInfo
{
public readonly string Anim = null;
public readonly int Burst = 1;

View File

@@ -288,7 +288,6 @@
<Compile Include="Graphics\Viewport.cs" />
<Compile Include="UnitInfluenceMap.cs" />
<Compile Include="Orders\UnitOrderGenerator.cs" />
<Compile Include="VoicePool.cs" />
<Compile Include="World.cs" />
</ItemGroup>
<ItemGroup>

View File

@@ -4,51 +4,5 @@ using OpenRa.Effects;
namespace OpenRa.Traits
{
class MineInfo : ITraitInfo
{
public readonly int Damage = 0;
public readonly UnitMovementType[] TriggeredBy = { };
public readonly string Warhead = "ATMine";
public readonly bool AvoidFriendly = true;
public object Create(Actor self) { return new Mine(self); }
}
class Mine : ICrushable, IOccupySpace
{
readonly Actor self;
public Mine(Actor self)
{
this.self = self;
Game.UnitInfluence.Add(self, this);
}
public void OnCrush(Actor crusher)
{
if (crusher.traits.Contains<MineImmune>() && crusher.Owner == self.Owner)
return;
var info = self.Info.Traits.Get<MineInfo>();
var warhead = Rules.WarheadInfo[info.Warhead];
Game.world.AddFrameEndTask(_ =>
{
Game.world.Remove(self);
Game.world.Add(new Explosion(self.CenterLocation.ToInt2(), warhead.Explosion, false));
crusher.InflictDamage(crusher, info.Damage, warhead);
});
}
public bool IsPathableCrush(UnitMovementType umt, Player player)
{
return !self.Info.Traits.Get<MineInfo>().AvoidFriendly || (player != Game.LocalPlayer);
}
public bool IsCrushableBy(UnitMovementType umt, Player player)
{
return self.Info.Traits.Get<MineInfo>().TriggeredBy.Contains(umt);
}
public IEnumerable<int2> OccupiedCells() { yield return self.Location; }
}
}

View File

@@ -1,6 +1,5 @@

namespace OpenRa.Traits
{
class MineImmuneInfo : StatelessTraitInfo<MineImmune> { }
class MineImmune { }
}

View File

@@ -32,19 +32,19 @@ namespace OpenRa.Traits
}
public interface IOccupySpace { IEnumerable<int2> OccupiedCells(); }
interface INotifyAttack { void Attacking(Actor self); }
interface IRenderModifier { IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r); }
interface IDamageModifier { float GetDamageModifier(); }
interface ISpeedModifier { float GetSpeedModifier(); }
interface IPaletteModifier { void AdjustPalette(Bitmap b); }
interface IPips { IEnumerable<PipType> GetPips(Actor self); }
interface ITags { IEnumerable<TagType> GetTags(); }
interface IMovement
public interface IRenderModifier { IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r); }
public interface IDamageModifier { float GetDamageModifier(); }
public interface ISpeedModifier { float GetSpeedModifier(); }
public interface IPaletteModifier { void AdjustPalette(Bitmap b); }
public interface IPips { IEnumerable<PipType> GetPips(Actor self); }
public interface ITags { IEnumerable<TagType> GetTags(); }
public interface IMovement
{
UnitMovementType GetMovementType();
bool CanEnterCell(int2 location);
}
interface ICrushable
public interface ICrushable
{
void OnCrush(Actor crusher);
bool IsCrushableBy(UnitMovementType umt, Player player);
@@ -75,7 +75,7 @@ namespace OpenRa.Traits
public interface ITraitInfo { object Create(Actor self); }
class StatelessTraitInfo<T> : ITraitInfo
public class StatelessTraitInfo<T> : ITraitInfo
where T : new()
{
static Lazy<T> Instance = Lazy.New(() => new T());

View File

@@ -1,29 +0,0 @@
using System.Collections.Generic;
namespace OpenRa
{
class VoicePool
{
readonly string[] clips;
readonly List<string> liveclips = new List<string>();
public VoicePool(params string[] clips)
{
this.clips = clips;
}
public string GetNext()
{
if (liveclips.Count == 0)
liveclips.AddRange(clips);
if (liveclips.Count == 0)
return null; /* avoid crashing if there's no clips at all */
var i = Game.CosmeticRandom.Next(liveclips.Count);
var s = liveclips[i];
liveclips.RemoveAt(i);
return s;
}
}
}

60
OpenRa.Mods.RA/Mine.cs Normal file
View File

@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenRa.Traits;
using OpenRa.Effects;
namespace OpenRa.Mods.RA
{
class MineInfo : ITraitInfo
{
public readonly int Damage = 0;
public readonly UnitMovementType[] TriggeredBy = { };
public readonly string Warhead = "ATMine";
public readonly bool AvoidFriendly = true;
public object Create(Actor self) { return new Mine(self); }
}
class Mine : ICrushable, IOccupySpace
{
readonly Actor self;
public Mine(Actor self)
{
this.self = self;
Game.UnitInfluence.Add(self, this);
}
public void OnCrush(Actor crusher)
{
if (crusher.traits.Contains<MineImmune>() && crusher.Owner == self.Owner)
return;
var info = self.Info.Traits.Get<MineInfo>();
var warhead = Rules.WarheadInfo[info.Warhead];
Game.world.AddFrameEndTask(_ =>
{
Game.world.Remove(self);
Game.world.Add(new Explosion(self.CenterLocation.ToInt2(), warhead.Explosion, false));
crusher.InflictDamage(crusher, info.Damage, warhead);
});
}
public bool IsPathableCrush(UnitMovementType umt, Player player)
{
return !self.Info.Traits.Get<MineInfo>().AvoidFriendly || (player != Game.LocalPlayer);
}
public bool IsCrushableBy(UnitMovementType umt, Player player)
{
return self.Info.Traits.Get<MineInfo>().TriggeredBy.Contains(umt);
}
public IEnumerable<int2> OccupiedCells() { yield return self.Location; }
}
class MineImmuneInfo : StatelessTraitInfo<MineImmune> { }
class MineImmune { }
}

View File

@@ -45,6 +45,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Mine.cs" />
<Compile Include="Minelayer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>