Refactoring to remove static Rules & SequenceProvider

This commit is contained in:
Pavlos Touboulidis
2014-05-05 02:43:08 +03:00
parent c68427eaa6
commit 63ec6d60e7
114 changed files with 914 additions and 615 deletions

View File

@@ -67,7 +67,7 @@ namespace OpenRA.Scripting
public int BuildTime(string type)
{
ActorInfo ai;
if (!Rules.Info.TryGetValue(type, out ai))
if (!context.World.Map.Rules.Actors.TryGetValue(type, out ai))
throw new LuaException("Unknown actor type '{0}'".F(type));
return ai.GetBuildTime();
@@ -77,7 +77,7 @@ namespace OpenRA.Scripting
public int CruiseAltitude(string type)
{
ActorInfo ai;
if (!Rules.Info.TryGetValue(type, out ai))
if (!context.World.Map.Rules.Actors.TryGetValue(type, out ai))
throw new LuaException("Unknown actor type '{0}'".F(type));
var pi = ai.Traits.GetOrDefault<PlaneInfo>();

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2013 The OpenRA Developers (see AUTHORS)
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
@@ -171,10 +171,10 @@ namespace OpenRA.Mods.RA.Scripting
public object TraitInfoOrDefault(string actorType, string className)
{
var type = Game.modData.ObjectCreator.FindType(className);
if (type == null || !Rules.Info.ContainsKey(actorType))
if (type == null || !world.Map.Rules.Actors.ContainsKey(actorType))
return null;
return Rules.Info[actorType].Traits.GetOrDefault(type);
return world.Map.Rules.Actors[actorType].Traits.GetOrDefault(type);
}
[LuaGlobal]
@@ -202,13 +202,13 @@ namespace OpenRA.Mods.RA.Scripting
[LuaGlobal]
public void PlaySpeechNotification(Player player, string notification)
{
Sound.PlayNotification(player, "Speech", notification, player != null ? player.Country.Race : null);
Sound.PlayNotification(world.Map.Rules, player, "Speech", notification, player != null ? player.Country.Race : null);
}
[LuaGlobal]
public void PlaySoundNotification(Player player, string notification)
{
Sound.PlayNotification(player, "Sounds", notification, player != null ? player.Country.Race : null);
Sound.PlayNotification(world.Map.Rules, player, "Sounds", notification, player != null ? player.Country.Race : null);
}
[LuaGlobal]
@@ -248,7 +248,7 @@ namespace OpenRA.Mods.RA.Scripting
[LuaGlobal]
public void PlayRandomMusic()
{
if (!Rules.InstalledMusic.Any() || !Game.Settings.Sound.MapMusic)
if (!Game.Settings.Sound.MapMusic || !world.Map.Rules.InstalledMusic.Any())
return;
Game.ConnectionStateChanged += StopMusic;
PlayMusic();
@@ -256,7 +256,7 @@ namespace OpenRA.Mods.RA.Scripting
void PlayMusic()
{
var track = Rules.InstalledMusic.Random(Game.CosmeticRandom);
var track = world.Map.Rules.InstalledMusic.Random(Game.CosmeticRandom);
Sound.PlayMusicThen(track.Value, PlayMusic);
}
@@ -385,7 +385,7 @@ namespace OpenRA.Mods.RA.Scripting
ClassicProductionQueue GetSharedQueueForUnit(Player player, string unit)
{
var ri = Rules.Info[unit];
var ri = world.Map.Rules.Actors[unit];
var bi = ri.Traits.GetOrDefault<BuildableInfo>();
if (bi == null)
@@ -406,7 +406,7 @@ namespace OpenRA.Mods.RA.Scripting
[LuaGlobal]
public void BuildWithPerFactoryQueue(Actor factory, string unit, double amount)
{
var ri = Rules.Info[unit];
var ri = world.Map.Rules.Actors[unit];
var bi = ri.Traits.GetOrDefault<BuildableInfo>();
if (bi == null)

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA.Scripting
public void Produce(string actorType)
{
ActorInfo actorInfo;
if (!Rules.Info.TryGetValue(actorType, out actorInfo))
if (!self.World.Map.Rules.Actors.TryGetValue(actorType, out actorInfo))
throw new LuaException("Unknown actor type '{0}'".F(actorType));
self.QueueActivity(new WaitFor(() => p.Produce(self, actorInfo)));