much simpler rules loader

This commit is contained in:
Chris Forbes
2010-04-01 21:31:15 +13:00
parent c5fdda9141
commit 38605faecf
16 changed files with 110 additions and 120 deletions

View File

@@ -58,15 +58,10 @@ namespace OpenRA.FileFormats
public class Manifest
{
public readonly string[] Folders = { };
public readonly string[] Packages = { };
public readonly string[] LegacyRules = { };
public readonly string[] Rules = { };
public readonly string[] Sequences = { };
public readonly string[] Chrome = { };
public readonly string[] Assemblies = { };
public readonly string[] ChromeLayout = { };
public readonly string[] Weapons = { };
public readonly string[]
Folders, Packages, LegacyRules, Rules,
Sequences, Chrome, Assemblies, ChromeLayout,
Weapons, Voices;
public Manifest(string[] mods)
{
@@ -83,6 +78,7 @@ namespace OpenRA.FileFormats
Assemblies = YamlList(yaml, "Assemblies");
ChromeLayout = YamlList(yaml, "ChromeLayout");
Weapons = YamlList(yaml, "Weapons");
Voices = YamlList(yaml, "Voices");
}
static string[] YamlList(Dictionary<string, MiniYaml> ys, string key) { return ys[key].Nodes.Keys.ToArray(); }

View File

@@ -27,7 +27,7 @@ using OpenRA.FileFormats;
namespace OpenRA
{
static class Combat /* some utility bits that are shared between various things */
public static class Combat /* some utility bits that are shared between various things */
{
static string GetImpactSound(WarheadInfo warhead, bool isWater)
{
@@ -82,6 +82,23 @@ namespace OpenRA
}
}
public static void DoExplosion(Actor attacker, string weapontype, int2 location, int altitude)
{
var args = new ProjectileArgs
{
src = location,
dest = location,
srcAltitude = altitude,
destAltitude = altitude,
firedBy = attacker,
target = null,
weapon = Rules.Weapons[ weapontype.ToLowerInvariant() ],
facing = 0
};
DoImpacts(args, location);
}
static float GetDamageToInflict(Actor target, ProjectileArgs args, WarheadInfo warhead, float modifier)
{
var distance = (target.CenterLocation - args.dest).Length;

View File

@@ -1,51 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using System;
using System.Collections;
using System.Collections.Generic;
using OpenRA.FileFormats;
namespace OpenRA.GameRules
{
public class InfoLoader<T> : IEnumerable<KeyValuePair<string, T>>
{
readonly Dictionary<string, T> infos = new Dictionary<string, T>();
public InfoLoader(params Pair<string, Func<string,T>>[] srcs)
{
foreach (var src in srcs)
foreach (var name in Rules.Categories[src.First])
{
var t = src.Second(name);
FieldLoader.Load(t, Rules.AllRules.GetSection(name));
infos[name] = t;
}
}
public T this[string name]
{
get { return infos[name.ToLowerInvariant()]; }
}
public IEnumerator<KeyValuePair<string, T>> GetEnumerator() { return infos.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() { return infos.GetEnumerator(); }
}
}

View File

@@ -29,13 +29,11 @@ namespace OpenRA
public static class Rules
{
public static IniFile AllRules;
public static Dictionary<string, List<string>> Categories = new Dictionary<string, List<string>>();
public static InfoLoader<WarheadInfo> WarheadInfo;
public static InfoLoader<VoiceInfo> VoiceInfo;
public static TechTree TechTree;
public static Dictionary<string, ActorInfo> Info;
public static Dictionary<string, WeaponInfo> Weapons;
public static Dictionary<string, VoiceInfo> Voices;
public static void LoadRules(string map, Manifest m)
{
@@ -43,38 +41,21 @@ namespace OpenRA
legacyRules.Insert(0, map);
AllRules = new IniFile(legacyRules.Select(a => FileSystem.Open(a)).ToArray());
LoadCategories(
"Weapon",
"Warhead",
"Projectile",
"Voice");
WarheadInfo = new InfoLoader<WarheadInfo>(
Pair.New<string, Func<string, WarheadInfo>>("Warhead", _ => new WarheadInfo()));
VoiceInfo = new InfoLoader<VoiceInfo>(
Pair.New<string, Func<string, VoiceInfo>>("Voice", _ => new VoiceInfo()));
Log.Write("Using rules files: ");
foreach (var y in m.Rules)
Log.Write(" -- {0}", y);
var yamlRules = m.Rules.Select(a => MiniYaml.FromFile(a)).Aggregate(MiniYaml.Merge);
Info = new Dictionary<string, ActorInfo>();
foreach( var kv in yamlRules )
Info.Add(kv.Key.ToLowerInvariant(), new ActorInfo(kv.Key.ToLowerInvariant(), kv.Value, yamlRules));
var weaponsYaml = m.Weapons.Select(a => MiniYaml.FromFile(a)).Aggregate(MiniYaml.Merge);
Weapons = new Dictionary<string, WeaponInfo>();
foreach (var kv in weaponsYaml)
Weapons.Add(kv.Key.ToLowerInvariant(), new WeaponInfo(kv.Key.ToLowerInvariant(), kv.Value));
Info = LoadYamlRules(m.Rules, (k, y) => new ActorInfo(k.Key.ToLowerInvariant(), k.Value, y));
Weapons = LoadYamlRules(m.Weapons, (k, _) => new WeaponInfo(k.Key.ToLowerInvariant(), k.Value));
Voices = LoadYamlRules(m.Voices, (k, _) => new VoiceInfo(k.Value));
TechTree = new TechTree();
}
static void LoadCategories(params string[] types)
static Dictionary<string, T> LoadYamlRules<T>(string[] files, Func<KeyValuePair<string, MiniYaml>, Dictionary<string, MiniYaml>, T> f)
{
foreach (var t in types)
Categories[t] = AllRules.GetSection(t + "Types").Select(x => x.Key.ToLowerInvariant()).ToList();
var y = files.Select(a => MiniYaml.FromFile(a)).Aggregate(MiniYaml.Merge);
return y.ToDictionary(kv => kv.Key.ToLowerInvariant(), kv => f(kv, y));
}
}
}

View File

@@ -34,8 +34,10 @@ namespace OpenRA.GameRules
public readonly Lazy<Dictionary<string, VoicePool>> Pools;
public VoiceInfo()
public VoiceInfo( MiniYaml y )
{
FieldLoader.Load(this, y);
Pools = Lazy.New(() =>
new Dictionary<string, VoicePool>
{

View File

@@ -153,7 +153,6 @@
<Compile Include="Cursor.cs" />
<Compile Include="Effects\Explosion.cs" />
<Compile Include="GameRules\Footprint.cs" />
<Compile Include="GameRules\InfoLoader.cs" />
<Compile Include="GameRules\Rules.cs" />
<Compile Include="Graphics\Animation.cs" />
<Compile Include="Game.cs" />

View File

@@ -102,16 +102,6 @@ namespace OpenRA
music.Volume = value;
}
}
//public static void SeekMusic(uint delta)
//{
// if (music != null)
// {
// music.PlayPosition += delta;
// if (music.PlayPosition < 0 || music.PlayPosition > music.PlayLength)
// music.PlayPosition = 0;
// }
//}
public static void PlayVoice(string phrase, Actor voicedUnit)
{
@@ -120,7 +110,7 @@ namespace OpenRA
var mi = voicedUnit.Info.Traits.GetOrDefault<SelectableInfo>();
if (mi == null) return;
var vi = Rules.VoiceInfo[mi.Voice];
var vi = Rules.Voices[mi.Voice.ToLowerInvariant()];
var clip = vi.Pools.Value[phrase].GetNext();
if (clip == null)

View File

@@ -44,7 +44,7 @@ namespace OpenRA.Traits
if (--ticks <= 0)
{
ticks = info.Ticks;
self.InflictDamage(self, -info.Step, Rules.WarheadInfo["Super"]);
self.InflictDamage(self, -info.Step, null);
}
}
}

View File

@@ -51,7 +51,7 @@ namespace OpenRA.Traits.Activities
return this;
}
self.InflictDamage(self, -hpToRepair, Rules.WarheadInfo["Super"]);
self.InflictDamage(self, -hpToRepair, null);
if (self.Health == hp)
return NextActivity;

View File

@@ -135,7 +135,7 @@ namespace OpenRA.Traits
}
self.World.AddFrameEndTask(w => w.Add(new RepairIndicator(self)));
self.InflictDamage(self, -hpToRepair, Rules.WarheadInfo["Super"]);
self.InflictDamage(self, -hpToRepair, null);
if (self.Health == maxHP)
{
isRepairing = false;

View File

@@ -35,7 +35,8 @@ namespace OpenRA.Traits
public void OnCrush(Actor crusher)
{
self.InflictDamage(crusher, self.Health, Rules.WarheadInfo["Crush"]);
// ... this wasnt working ANYWAY ...
// self.InflictDamage(crusher, self.Health, Rules.WarheadInfo["Crush"]);
}
public bool IsPathableCrush(UnitMovementType umt, Player player)

View File

@@ -35,23 +35,21 @@ namespace OpenRA.Mods.RA.Activities
{
if (target == null || target.IsDead) return NextActivity;
var warhead = Rules.WarheadInfo["Super"];
if (self.Owner.Stances[ target.Owner ] == Stance.Ally)
{
if (target.Health == target.Info.Traits.Get<OwnedActorInfo>().HP)
return NextActivity;
target.InflictDamage(self, -EngineerCapture.EngineerDamage, warhead);
target.InflictDamage(self, -EngineerCapture.EngineerDamage, null);
}
else
{
if (target.Health - EngineerCapture.EngineerDamage <= 0)
{
target.Owner = self.Owner;
target.InflictDamage(self, target.Health - EngineerCapture.EngineerDamage, warhead);
target.InflictDamage(self, target.Health - EngineerCapture.EngineerDamage, null);
}
else
target.InflictDamage(self, EngineerCapture.EngineerDamage, warhead);
target.InflictDamage(self, EngineerCapture.EngineerDamage, null);
}
// the engineer is sacrificed.

View File

@@ -36,8 +36,8 @@ namespace OpenRA.Mods.RA.Activities
public IActivity Tick(Actor self)
{
if (target == null || target.IsDead) return NextActivity;
self.World.AddFrameEndTask(w => w.Add(new DelayedAction(25*2,
() => target.InflictDamage(self, target.Health, Rules.WarheadInfo["DemolishWarhead"]))));
self.World.AddFrameEndTask(w => w.Add(new DelayedAction(25 * 2,
() => target.InflictDamage(self, target.Health, null))));
return NextActivity;
}

View File

@@ -22,6 +22,7 @@ using System.Collections.Generic;
using System.Linq;
using OpenRA.Effects;
using OpenRA.Traits;
using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA
{
@@ -50,14 +51,8 @@ namespace OpenRA.Mods.RA
return;
var info = self.Info.Traits.Get<MineInfo>();
var warhead = Rules.WarheadInfo[info.Warhead];
self.World.AddFrameEndTask(w =>
{
w.Remove(self);
w.Add(new Explosion(w, self.CenterLocation.ToInt2(), warhead.Explosion, false));
crusher.InflictDamage(crusher, info.Damage, warhead);
});
Combat.DoExplosion(self, info.Warhead, self.CenterLocation.ToInt2(), 0);
self.QueueActivity(new RemoveSelf());
}
public bool IsPathableCrush(UnitMovementType umt, Player player)

View File

@@ -40,4 +40,7 @@ ChromeLayout:
mods/ra/menus.yaml:
Weapons:
mods/ra/weapons.yaml
mods/ra/weapons.yaml
Voices:
mods/ra/voices.yaml

59
mods/ra/voices.yaml Normal file
View File

@@ -0,0 +1,59 @@
# Classic Red Alert Mod -- Package Manifest
GenericVoice:
SovietVariants: .r01,.r03
AlliedVariants: .v01,.v03
Select: await1,ready,report1,yessir1
Move: ackno,affirm1,noprob,overout,ritaway,roger,ugotit
Die: dedman1.aud,dedman2.aud,dedman3.aud,dedman4.aud,dedman5.aud,dedman6.aud,dedman7.aud,dedman8.aud,dedman10.aud
VehicleVoice:
SovietVariants: .r00,.r02
AlliedVariants: .v00,.v02
Select: vehic1,yessir1,report1,await1
Move: ackno,affirm1
EngineerVoice:
Select: eengin1,eyessir1
Move: eaffirm1,emovout1
Die: dedman1,dedman2,dedman3,dedman4,dedman5,dedman6,dedman7,dedman8,dedman10
MedicVoice:
Select: mrespon1,myessir1
Move: maffirm1,mmovout1
Die: dedman1,dedman2,dedman3,dedman4,dedman5,dedman6,dedman7,dedman8,dedman10
TanyaVoice:
Select: yo1,yes1,yeah1
Move: rokroll1,onit1,cmon1
Attack: tuffguy1,bombit1,gotit1
Die: tandeth1
DogVoice:
Select:
Move: dogy1
Attack: dogg5p,dogw3px
Die: dogw5,dogw6,dogw7
SpyVoice:
Select: syessir1,scomnd1
Move: sonway1,sindeed1
Attack: sking1
Die: dedman1,dedman2,dedman3,dedman4,dedman5,dedman6,dedman7,dedman8,dedman10
ThiefVoice:
Select: swhat1,syeah1
Move: saffirm1,smout1,sokay1
Die: dedman1,dedman2,dedman3,dedman4,dedman5,dedman6,dedman7,dedman8,dedman10
CivilianMaleVoice:
Select: guyyeah1
Move: guyokay1
CivilianFemaleVoice:
Select: girlyeah
Move: girlokay
EinsteinVoice:
Select: einah1,einok1,einyes1
Move: einah1,einok1,einyes1