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

@@ -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,
@@ -68,9 +68,9 @@ namespace OpenRA.Mods.RA.AI
// Place the building
var type = BuildingType.Building;
if (Rules.Info[currentBuilding.Item].Traits.Contains<AttackBaseInfo>())
if (ai.Map.Rules.Actors[currentBuilding.Item].Traits.Contains<AttackBaseInfo>())
type = BuildingType.Defense;
else if (Rules.Info[currentBuilding.Item].Traits.Contains<OreRefineryInfo>())
else if (ai.Map.Rules.Actors[currentBuilding.Item].Traits.Contains<OreRefineryInfo>())
type = BuildingType.Refinery;
var location = ai.ChooseBuildLocation(currentBuilding.Item, type);

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,
@@ -83,7 +83,7 @@ namespace OpenRA.Mods.RA.AI
static object LoadBuildingLimits(MiniYaml y) { return LoadList<int>(y, "BuildingLimits"); }
public object Create(ActorInitializer init) { return new HackyAI(this); }
public object Create(ActorInitializer init) { return new HackyAI(this, init); }
}
public class Enemy { public int Aggro; }
@@ -119,15 +119,18 @@ namespace OpenRA.Mods.RA.AI
const int MaxBaseDistance = 40;
public const int feedbackTime = 30; // ticks; = a bit over 1s. must be >= netlag.
public World world { get { return p.PlayerActor.World; } }
//public World world { get { return p.PlayerActor.World; } }
public readonly World world;
public Map Map { get { return world.Map; } }
IBotInfo IBot.Info { get { return this.Info; } }
public HackyAI(HackyAIInfo info)
public HackyAI(HackyAIInfo info, ActorInitializer init)
{
Info = info;
world = init.world;
// Temporary hack.
rallypointTestBuilding = Rules.Info[Info.RallypointTestBuilding].Traits.Get<BuildingInfo>();
rallypointTestBuilding = Map.Rules.Actors[Info.RallypointTestBuilding].Traits.Get<BuildingInfo>();
}
public static void BotDebug(string s, params object[] args)
@@ -151,7 +154,7 @@ namespace OpenRA.Mods.RA.AI
random = new XRandom((int)p.PlayerActor.ActorID);
resourceTypes = Rules.Info["world"].Traits.WithInterface<ResourceTypeInfo>()
resourceTypes = Map.Rules.Actors["world"].Traits.WithInterface<ResourceTypeInfo>()
.Select(t => t.TerrainType).ToArray();
}
@@ -185,8 +188,8 @@ namespace OpenRA.Mods.RA.AI
foreach (var unit in Info.UnitsToBuild)
if (buildableThings.Any(b => b.Name == unit.Key))
if (myUnits.Count(a => a == unit.Key) < unit.Value * myUnits.Length)
if (HasAdequateAirUnits(Rules.Info[unit.Key]))
return Rules.Info[unit.Key];
if (HasAdequateAirUnits(Map.Rules.Actors[unit.Key]))
return Map.Rules.Actors[unit.Key];
return null;
}
@@ -215,7 +218,7 @@ namespace OpenRA.Mods.RA.AI
ActorInfo GetBuildingInfoByCommonName(string commonName, Player owner)
{
if (commonName == "ConstructionYard")
return Rules.Info.Where(k => Info.BuildingCommonNames[commonName].Contains(k.Key)).Random(random).Value;
return Map.Rules.Actors.Where(k => Info.BuildingCommonNames[commonName].Contains(k.Key)).Random(random).Value;
return GetInfoByCommonName(Info.BuildingCommonNames, commonName, owner);
}
@@ -230,7 +233,7 @@ namespace OpenRA.Mods.RA.AI
if (!names.Any() || !names.ContainsKey(commonName))
return null;
return Rules.Info.Where(k => names[commonName].Contains(k.Key) &&
return Map.Rules.Actors.Where(k => names[commonName].Contains(k.Key) &&
k.Value.Traits.Get<BuildableInfo>().Owner.Contains(owner.Country.Race)).Random(random).Value;
}
@@ -314,8 +317,8 @@ namespace OpenRA.Mods.RA.AI
foreach (var frac in Info.BuildingFractions)
if (buildableThings.Any(b => b.Name == frac.Key))
if (myBuildings.Count(a => a == frac.Key) < frac.Value * myBuildings.Length && HasAdequateNumber(frac.Key, p) &&
playerPower.ExcessPower >= Rules.Info[frac.Key].Traits.Get<BuildingInfo>().Power)
return Rules.Info[frac.Key];
playerPower.ExcessPower >= Map.Rules.Actors[frac.Key].Traits.Get<BuildingInfo>().Power)
return Map.Rules.Actors[frac.Key];
return null;
}
@@ -334,7 +337,7 @@ namespace OpenRA.Mods.RA.AI
public CPos? ChooseBuildLocation(string actorType, bool distanceToBaseIsImportant, int maxBaseDistance, BuildingType type)
{
var bi = Rules.Info[actorType].Traits.GetOrDefault<BuildingInfo>();
var bi = Map.Rules.Actors[actorType].Traits.GetOrDefault<BuildingInfo>();
if (bi == null)
return null;
@@ -348,7 +351,7 @@ namespace OpenRA.Mods.RA.AI
foreach (var t in tlist)
if (world.CanPlaceBuilding(actorType, bi, t, null))
if (bi.IsCloseEnoughToBase(world, p, actorType, t))
if (NoBuildingsUnder(Util.ExpandFootprint(FootprintUtils.Tiles(actorType, bi, t), false)))
if (NoBuildingsUnder(Util.ExpandFootprint(FootprintUtils.Tiles(Map.Rules, actorType, bi, t), false)))
return t;
}
@@ -377,7 +380,7 @@ namespace OpenRA.Mods.RA.AI
if (distanceToBaseIsImportant && !bi.IsCloseEnoughToBase(world, p, actorType, t))
continue;
if (NoBuildingsUnder(Util.ExpandFootprint(FootprintUtils.Tiles(actorType, bi, t), false)))
if (NoBuildingsUnder(Util.ExpandFootprint(FootprintUtils.Tiles(Map.Rules, actorType, bi, t), false)))
return t;
}
}
@@ -850,7 +853,7 @@ namespace OpenRA.Mods.RA.AI
if (queue == null)
return;
if (Rules.Info[name] != null)
if (Map.Rules.Actors[name] != null)
world.IssueOrder(Order.StartProduction(queue.self, name, 1));
}

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.RA
public void Killed(Actor self, AttackInfo e)
{
var player = (info.NotifyAll) ? self.World.LocalPlayer : self.Owner;
Sound.PlayNotification(player, "Speech", info.Notification, self.Owner.Country.Race);
Sound.PlayNotification(self.World.Map.Rules, player, "Speech", info.Notification, self.Owner.Country.Race);
}
}
}

View File

@@ -82,7 +82,7 @@ namespace OpenRA.Mods.RA
Coords = Exts.Lazy(() => self.Trait<IBodyOrientation>());
limitedAmmo = Exts.Lazy(() => self.TraitOrDefault<LimitedAmmo>());
Weapon = Rules.Weapons[info.Weapon.ToLowerInvariant()];
Weapon = self.World.Map.Rules.Weapons[info.Weapon.ToLowerInvariant()];
Burst = Weapon.Burst;
if (info.LocalOffset.Length % 3 != 0)

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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,
@@ -44,7 +44,7 @@ namespace OpenRA.Mods.RA
// Build a list of templates that should be overlayed with bridges
foreach(var bridge in Info.Bridges)
{
var bi = Rules.Info[bridge].Traits.Get<BridgeInfo>();
var bi = w.Map.Rules.Actors[bridge].Traits.Get<BridgeInfo>();
foreach (var template in bi.Templates)
BridgeTypes.Add(template.First, Pair.New(bridge, template.Second));
}

6
OpenRA.Mods.RA/Buildings/Building.cs Executable file → Normal file
View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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,
@@ -65,7 +65,7 @@ namespace OpenRA.Mods.RA.Buildings
return false;
var buildingMaxBounds = (CVec)Dimensions;
var buildingTraits = Rules.Info[buildingName].Traits;
var buildingTraits = world.Map.Rules.Actors[buildingName].Traits;
if (buildingTraits.Contains<BibInfo>() && !(buildingTraits.Get<BibInfo>().HasMinibib))
buildingMaxBounds += new CVec(0, 1);
@@ -91,7 +91,7 @@ namespace OpenRA.Mods.RA.Buildings
}
}
var buildingTiles = FootprintUtils.Tiles(buildingName, this, topLeft).ToList();
var buildingTiles = FootprintUtils.Tiles(world.Map.Rules, buildingName, this, topLeft).ToList();
return nearnessCandidates
.Any(a => buildingTiles
.Any(b => Math.Abs(a.X - b.X) <= Adjacent

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA.Buildings
if (b == null)
return;
foreach (var u in FootprintUtils.Tiles(a.Info.Name, b.Info, a.Location))
foreach (var u in FootprintUtils.Tiles(map.Rules, a.Info.Name, b.Info, a.Location))
if (map.IsInMap(u) && influence[u.X, u.Y] == null)
influence[u.X, u.Y] = a;
};
@@ -45,7 +45,7 @@ namespace OpenRA.Mods.RA.Buildings
if (b == null)
return;
foreach (var u in FootprintUtils.Tiles(a.Info.Name, b.Info, a.Location))
foreach (var u in FootprintUtils.Tiles(map.Rules, a.Info.Name, b.Info, a.Location))
if (map.IsInMap(u) && influence[u.X, u.Y] == a)
influence[u.X, u.Y] = null;
};

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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,
@@ -37,7 +37,7 @@ namespace OpenRA.Mods.RA.Buildings
if (order.OrderString == "PowerDown")
{
disabled = !disabled;
Sound.PlayNotification(self.Owner, "Sounds", (disabled ? "EnablePower" : "DisablePower"), self.Owner.Country.Race);
Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Sounds", (disabled ? "EnablePower" : "DisablePower"), self.Owner.Country.Race);
PowerManager.UpdateActor(self, disabled ? 0 : normalPower);
if (disabled)

8
OpenRA.Mods.RA/Buildings/FootprintUtils.cs Executable file → Normal file
View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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,
@@ -16,13 +16,13 @@ namespace OpenRA.Mods.RA.Buildings
{
public static class FootprintUtils
{
public static IEnumerable<CPos> Tiles(string name, BuildingInfo buildingInfo, CPos topLeft)
public static IEnumerable<CPos> Tiles(MapRuleset rules, string name, BuildingInfo buildingInfo, CPos topLeft)
{
var dim = (CVec)buildingInfo.Dimensions;
var footprint = buildingInfo.Footprint.Where(x => !char.IsWhiteSpace(x));
var buildingTraits = Rules.Info[name].Traits;
var buildingTraits = rules.Actors[name].Traits;
if (buildingTraits.Contains<BibInfo>() && !(buildingTraits.Get<BibInfo>().HasMinibib))
{
dim += new CVec(0, 1);
@@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA.Buildings
public static IEnumerable<CPos> Tiles(Actor a)
{
return Tiles( a.Info.Name, a.Info.Traits.Get<BuildingInfo>(), a.Location );
return Tiles(a.World.Map.Rules, a.Info.Name, a.Info.Traits.Get<BuildingInfo>(), a.Location);
}
public static IEnumerable<CPos> UnpathableTiles(string name, BuildingInfo buildingInfo, CPos position)

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2012 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,
@@ -108,7 +108,7 @@ namespace OpenRA.Mods.RA.Buildings
if (--nextPowerAdviceTime <= 0)
{
if (lowPower)
Sound.PlayNotification(self.Owner, "Speech", "LowPower", self.Owner.Country.Race);
Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", "LowPower", self.Owner.Country.Race);
nextPowerAdviceTime = Info.AdviceInterval;
}
}

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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,
@@ -51,7 +51,7 @@ namespace OpenRA.Mods.RA.Buildings
else
{
Repairer = p;
Sound.PlayNotification(Repairer, "Speech", "Repairing", self.Owner.Country.Race);
Sound.PlayNotification(self.World.Map.Rules, Repairer, "Speech", "Repairing", self.Owner.Country.Race);
self.World.AddFrameEndTask(
w => w.Add(new RepairIndicator(self, Info.IndicatorPalettePrefix, p)));

6
OpenRA.Mods.RA/Buildings/Util.cs Executable file → Normal file
View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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,
@@ -35,14 +35,14 @@ namespace OpenRA.Mods.RA.Buildings
return true;
var res = world.WorldActor.Trait<ResourceLayer>();
return FootprintUtils.Tiles(name, building, topLeft).All(
return FootprintUtils.Tiles(world.Map.Rules, name, building, topLeft).All(
t => world.Map.IsInMap(t.X, t.Y) && res.GetResource(t) == null &&
world.IsCellBuildable(t, building, toIgnore));
}
public static IEnumerable<CPos> GetLineBuildCells(World world, CPos location, string name, BuildingInfo bi)
{
var lbi = Rules.Info[name].Traits.Get<LineBuildInfo>();
var lbi = world.Map.Rules.Actors[name].Traits.Get<LineBuildInfo>();
var topLeft = location; // 1x1 assumption!
if (world.IsCellBuildable(topLeft, bi))

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,
@@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA
return;
var race = info.NewOwnerVoice ? newOwner.Country.Race : oldOwner.Country.Race;
Sound.PlayNotification(captor.World.LocalPlayer, "Speech", info.Notification, race);
Sound.PlayNotification(self.World.Map.Rules, captor.World.LocalPlayer, "Speech", info.Notification, race);
}
}
}

View File

@@ -158,7 +158,7 @@ namespace OpenRA.Mods.RA
public static void DoExplosion(Actor attacker, string weapontype, WPos pos)
{
var weapon = Rules.Weapons[weapontype.ToLowerInvariant()];
var weapon = attacker.World.Map.Rules.Weapons[weapontype.ToLowerInvariant()];
if (weapon.Report != null && weapon.Report.Any())
Sound.Play(weapon.Report.Random(attacker.World.SharedRandom), pos);

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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,
@@ -70,7 +70,7 @@ namespace OpenRA.Mods.RA
Game.RunAfterDelay(Info.NotificationDelay, () =>
{
if (Game.IsCurrentWorld(self.World))
Sound.PlayNotification(self.Owner, "Speech", "Lose", self.Owner.Country.Race);
Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", "Lose", self.Owner.Country.Race);
});
}
@@ -81,7 +81,7 @@ namespace OpenRA.Mods.RA
Game.Debug("{0} is victorious.".F(self.Owner.PlayerName));
if (self.Owner == self.World.LocalPlayer)
Game.RunAfterDelay(Info.NotificationDelay, () => Sound.PlayNotification(self.Owner, "Speech", "Win", self.Owner.Country.Race));
Game.RunAfterDelay(Info.NotificationDelay, () => Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", "Win", self.Owner.Country.Race));
}
}

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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,
@@ -90,7 +90,7 @@ namespace OpenRA.Mods.RA
{
var crate = w.CreateActor(false, crateActor, new TypeDictionary { new OwnerInit(w.WorldActor.Owner) });
var startPos = w.ChooseRandomEdgeCell();
var altitude = Rules.Info[info.DeliveryAircraft].Traits.Get<PlaneInfo>().CruiseAltitude;
var altitude = self.World.Map.Rules.Actors[info.DeliveryAircraft].Traits.Get<PlaneInfo>().CruiseAltitude;
var plane = w.CreateActor(info.DeliveryAircraft, new TypeDictionary
{
new CenterPositionInit(startPos.CenterPosition + new WVec(WRange.Zero, WRange.Zero, altitude)),

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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,
@@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA.Crates
public bool CanGiveTo(Actor collector)
{
var bi = Rules.Info[Info.Unit].Traits.GetOrDefault<BuildableInfo>();
var bi = self.World.Map.Rules.Actors[Info.Unit].Traits.GetOrDefault<BuildableInfo>();
// this unit is not buildable by the collector's country, so
// don't give them free ones either.
@@ -68,7 +68,7 @@ namespace OpenRA.Mods.RA.Crates
IEnumerable<CPos> GetSuitableCells(CPos near)
{
var mi = Rules.Info[Info.Unit].Traits.Get<MobileInfo>();
var mi = self.World.Map.Rules.Actors[Info.Unit].Traits.Get<MobileInfo>();
for (var i = -1; i < 2; i++)
for (var j = -1; j < 2; j++)

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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,
@@ -49,7 +49,7 @@ namespace OpenRA.Mods.RA.Effects
anim.PlayRepeating("up");
pos = launchPos;
var weaponRules = Rules.Weapons[weapon.ToLowerInvariant()];
var weaponRules = firedBy.World.Map.Rules.Weapons[weapon.ToLowerInvariant()];
if (weaponRules.Report != null && weaponRules.Report.Any())
Sound.Play(weaponRules.Report.Random(firedBy.World.SharedRandom), pos);

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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,
@@ -42,7 +42,7 @@ namespace OpenRA.Mods.RA
dudesValue /= 100;
var eligibleLocations = FootprintUtils.Tiles(self).ToList();
var actorTypes = info.ActorTypes.Select(a => new { Name = a, Cost = Rules.Info[a].Traits.Get<ValuedInfo>().Cost }).ToArray();
var actorTypes = info.ActorTypes.Select(a => new { Name = a, Cost = self.World.Map.Rules.Actors[a].Traits.Get<ValuedInfo>().Cost }).ToArray();
while (eligibleLocations.Count > 0 && actorTypes.Any(a => a.Cost <= dudesValue))
{

View File

@@ -70,7 +70,7 @@ namespace OpenRA.Mods.RA
{
Level++;
Sound.PlayNotification(self.Owner, "Sounds", "LevelUp", self.Owner.Country.Race);
Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Sounds", "LevelUp", self.Owner.Country.Race);
self.World.AddFrameEndTask(w => w.Add(new CrateEffect(self, "levelup", info.ChevronPalette)));
if (Level == 1)
self.World.AddFrameEndTask(w =>

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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,
@@ -11,6 +11,7 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using OpenRA;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
@@ -23,22 +24,22 @@ namespace OpenRA.Mods.RA
{
EmitError = emitError;
foreach (var actorInfo in Rules.Info)
foreach (var actorInfo in map.Rules.Actors)
foreach (var traitInfo in actorInfo.Value.Traits.WithInterface<ITraitInfo>())
CheckTrait(actorInfo.Value, traitInfo);
CheckTrait(actorInfo.Value, traitInfo, map);
}
void CheckTrait(ActorInfo actorInfo, ITraitInfo traitInfo)
void CheckTrait(ActorInfo actorInfo, ITraitInfo traitInfo, Map map)
{
var actualType = traitInfo.GetType();
foreach (var field in actualType.GetFields())
{
if (field.HasAttribute<ActorReferenceAttribute>())
CheckReference(actorInfo, traitInfo, field, Rules.Info, "actor");
CheckReference(actorInfo, traitInfo, field, map.Rules.Actors, "actor");
if (field.HasAttribute<WeaponReferenceAttribute>())
CheckReference(actorInfo, traitInfo, field, Rules.Weapons, "weapon");
CheckReference(actorInfo, traitInfo, field, map.Rules.Weapons, "weapon");
if (field.HasAttribute<VoiceReferenceAttribute>())
CheckReference(actorInfo, traitInfo, field, Rules.Voices, "voice");
CheckReference(actorInfo, traitInfo, field, map.Rules.Voices, "voice");
}
}
@@ -57,7 +58,7 @@ namespace OpenRA.Mods.RA
}
void CheckReference<T>(ActorInfo actorInfo, ITraitInfo traitInfo, FieldInfo fieldInfo,
Dictionary<string, T> dict, string type)
IReadOnlyDictionary<string, T> dict, string type)
{
var values = GetFieldValues(traitInfo, fieldInfo);
foreach (var v in values)

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,
@@ -19,11 +19,11 @@ namespace OpenRA.Mods.RA
{
public void Run(Action<string> emitError, Action<string> emitWarning, Map map)
{
var sequences = MiniYaml.MergeLiberal(map.Sequences,
var sequences = MiniYaml.MergeLiberal(map.SequenceDefinitions,
Game.modData.Manifest.Sequences.Select(s => MiniYaml.FromFile(s))
.Aggregate(MiniYaml.MergeLiberal));
foreach (var actorInfo in Rules.Info)
foreach (var actorInfo in map.Rules.Actors)
foreach (var renderInfo in actorInfo.Value.Traits.WithInterface<RenderSimpleInfo>())
{
var image = renderInfo.Image ?? actorInfo.Value.Name;

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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,
@@ -18,7 +18,7 @@ namespace OpenRA.Mods.RA
{
public void Run(Action<string> emitError, Action<string> emitWarning, Map map)
{
foreach (var actorInfo in Rules.Info.Where(a => !a.Key.StartsWith("^")))
foreach (var actorInfo in map.Rules.Actors.Where(a => !a.Key.StartsWith("^")))
try
{
var traits = actorInfo.Value.TraitsInConstructOrder().ToArray();

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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,
@@ -18,13 +18,13 @@ namespace OpenRA.Mods.RA
{
public void Run(Action<string> emitError, Action<string> emitWarning, Map map)
{
var providedPrereqs = Rules.Info.Keys.Concat(
Rules.Info.SelectMany(a => a.Value.Traits
var providedPrereqs = map.Rules.Actors.Keys.Concat(
map.Rules.Actors.SelectMany(a => a.Value.Traits
.WithInterface<ProvidesCustomPrerequisiteInfo>()
.Select(p => p.Prerequisite))).ToArray();
// TODO: this check is case insensitive while the real check in-game is not
foreach (var i in Rules.Info)
foreach (var i in map.Rules.Actors)
{
var bi = i.Value.Traits.GetOrDefault<BuildableInfo>();
if (bi != null)

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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,
@@ -40,7 +40,7 @@ namespace OpenRA.Mods.RA
this.self = self;
var tileset = self.World.TileSet.Id.ToLower();
tile = SequenceProvider.GetSequence("overlay", "build-valid-{0}".F(tileset)).GetSprite(0);
tile = self.World.Map.SequenceProvider.GetSequence("overlay", "build-valid-{0}".F(tileset)).GetSprite(0);
}
public IEnumerable<IOrderTargeter> Orders
@@ -120,8 +120,8 @@ namespace OpenRA.Mods.RA
minefieldStart = xy;
var tileset = self.World.TileSet.Id.ToLower();
tileOk = SequenceProvider.GetSequence("overlay", "build-valid-{0}".F(tileset)).GetSprite(0);
tileBlocked = SequenceProvider.GetSequence("overlay", "build-invalid").GetSprite(0);
tileOk = self.World.Map.SequenceProvider.GetSequence("overlay", "build-valid-{0}".F(tileset)).GetSprite(0);
tileBlocked = self.World.Map.SequenceProvider.GetSequence("overlay", "build-invalid").GetSprite(0);
}
public IEnumerable<Order> Order(World world, CPos xy, MouseInput mi)

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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,
@@ -31,10 +31,10 @@ namespace OpenRA.Mods.RA.Orders
Producer = producer;
Building = name;
var tileset = producer.World.TileSet.Id.ToLower();
BuildingInfo = Rules.Info[Building].Traits.Get<BuildingInfo>();
BuildingInfo = producer.World.Map.Rules.Actors[Building].Traits.Get<BuildingInfo>();
buildOk = SequenceProvider.GetSequence("overlay", "build-valid-{0}".F(tileset)).GetSprite(0);
buildBlocked = SequenceProvider.GetSequence("overlay", "build-invalid").GetSprite(0);
buildOk = producer.World.Map.SequenceProvider.GetSequence("overlay", "build-valid-{0}".F(tileset)).GetSprite(0);
buildBlocked = producer.World.Map.SequenceProvider.GetSequence("overlay", "build-invalid").GetSprite(0);
}
public IEnumerable<Order> Order(World world, CPos xy, MouseInput mi)
@@ -57,11 +57,11 @@ namespace OpenRA.Mods.RA.Orders
if (!world.CanPlaceBuilding(Building, BuildingInfo, topLeft, null)
|| !BuildingInfo.IsCloseEnoughToBase(world, Producer.Owner, Building, topLeft))
{
Sound.PlayNotification(Producer.Owner, "Speech", "BuildingCannotPlaceAudio", Producer.Owner.Country.Race);
Sound.PlayNotification(world.Map.Rules, Producer.Owner, "Speech", "BuildingCannotPlaceAudio", Producer.Owner.Country.Race);
yield break;
}
var isLineBuild = Rules.Info[Building].Traits.Contains<LineBuildInfo>();
var isLineBuild = world.Map.Rules.Actors[Building].Traits.Contains<LineBuildInfo>();
yield return new Order(isLineBuild ? "LineBuild" : "PlaceBuilding",
Producer.Owner.PlayerActor, false) { TargetLocation = topLeft, TargetString = Building };
}
@@ -74,14 +74,16 @@ namespace OpenRA.Mods.RA.Orders
var position = wr.Position(wr.Viewport.ViewToWorldPx(Viewport.LastMousePos)).ToCPos();
var topLeft = position - FootprintUtils.AdjustForBuildingSize(BuildingInfo);
var actorInfo = Rules.Info[Building];
var rules = world.Map.Rules;
var actorInfo = rules.Actors[Building];
foreach (var dec in actorInfo.Traits.WithInterface<IPlaceBuildingDecoration>())
dec.Render(wr, world, actorInfo, position.CenterPosition); /* hack hack */
var cells = new Dictionary<CPos, bool>();
// Linebuild for walls.
// Assumes a 1x1 footprint; weird things will happen for other footprints
if (Rules.Info[Building].Traits.Contains<LineBuildInfo>())
if (rules.Actors[Building].Traits.Contains<LineBuildInfo>())
{
foreach (var t in BuildingUtils.GetLineBuildCells(world, topLeft, Building, BuildingInfo))
cells.Add(t, BuildingInfo.IsCloseEnoughToBase(world, world.LocalPlayer, Building, t));
@@ -90,7 +92,7 @@ namespace OpenRA.Mods.RA.Orders
{
if (!initialized)
{
var rbi = Rules.Info[Building].Traits.GetOrDefault<RenderBuildingInfo>();
var rbi = rules.Actors[Building].Traits.GetOrDefault<RenderBuildingInfo>();
if (rbi == null)
preview = new IRenderable[0];
else
@@ -98,7 +100,7 @@ namespace OpenRA.Mods.RA.Orders
var palette = rbi.Palette ?? (Producer.Owner != null ?
rbi.PlayerPalette + Producer.Owner.InternalName : null);
preview = rbi.RenderPreview(Rules.Info[Building], wr.Palette(palette));
preview = rbi.RenderPreview(rules.Actors[Building], wr.Palette(palette));
}
initialized = true;
@@ -110,7 +112,7 @@ namespace OpenRA.Mods.RA.Orders
var res = world.WorldActor.Trait<ResourceLayer>();
var isCloseEnough = BuildingInfo.IsCloseEnoughToBase(world, world.LocalPlayer, Building, topLeft);
foreach (var t in FootprintUtils.Tiles(Building, BuildingInfo, topLeft))
foreach (var t in FootprintUtils.Tiles(rules, Building, BuildingInfo, topLeft))
cells.Add(t, isCloseEnough && world.IsCellBuildable(t, BuildingInfo) && res.GetResource(t) == null);
}

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2012 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,
@@ -57,7 +57,7 @@ namespace OpenRA.Mods.RA
if (self.World.WorldTick - lastAttackTime > info.NotifyInterval * 25)
{
Sound.PlayNotification(self.Owner, "Speech", "BaseAttack", self.Owner.Country.Race);
Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", "BaseAttack", self.Owner.Country.Race);
if (radarPings != null)
radarPings.Add(() => self.Owner == self.World.LocalPlayer, self.CenterPosition, info.RadarPingColor, info.RadarPingDuration);

6
OpenRA.Mods.RA/Player/ClassicProductionQueue.cs Executable file → Normal file
View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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,
@@ -81,7 +81,7 @@ namespace OpenRA.Mods.RA
foreach (var p in producers.Where(p => !p.Actor.IsDisabled()))
{
if (p.Trait.Produce(p.Actor, Rules.Info[name]))
if (p.Trait.Produce(p.Actor, self.World.Map.Rules.Actors[name]))
{
FinishProduction();
return true;
@@ -92,7 +92,7 @@ namespace OpenRA.Mods.RA
public override int GetBuildTime(String unitString)
{
var unit = Rules.Info[unitString];
var unit = self.World.Map.Rules.Actors[unitString];
if (unit == null || !unit.Traits.Contains<BuildableInfo>())
return 0;

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2012 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,
@@ -48,7 +48,7 @@ namespace OpenRA.Mods.RA
if (self.World.WorldTick - lastAttackTime > info.NotifyInterval * 25)
{
Sound.PlayNotification(self.Owner, "Speech", "HarvesterAttack", self.Owner.Country.Race);
Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", "HarvesterAttack", self.Owner.Country.Race);
if (radarPings != null)
radarPings.Add(() => self.Owner == self.World.LocalPlayer, self.CenterPosition, info.RadarPingColor, info.RadarPingDuration);

View File

@@ -53,7 +53,7 @@ namespace OpenRA.Mods.RA
self.World.Add(playerBeacon);
if (self.Owner.IsAlliedWith(self.World.RenderPlayer))
Sound.PlayNotification(null, info.NotificationType, info.Notification,
Sound.PlayNotification(self.World.Map.Rules, null, info.NotificationType, info.Notification,
self.World.RenderPlayer != null ? self.World.RenderPlayer.Country.Race : null);
if (radarPings != null)

6
OpenRA.Mods.RA/Player/PlaceBuilding.cs Executable file → Normal file
View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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,
@@ -40,7 +40,7 @@ namespace OpenRA.Mods.RA
if (queue == null)
return;
var unit = Rules.Info[order.TargetString];
var unit = self.World.Map.Rules.Actors[order.TargetString];
var buildingInfo = unit.Traits.Get<BuildingInfo>();
if (order.OrderString == "LineBuild")
@@ -92,7 +92,7 @@ namespace OpenRA.Mods.RA
if (GetNumBuildables(self.Owner) > prevItems)
w.Add(new DelayedAction(10,
() => Sound.PlayNotification(order.Player, "Speech", "NewOptions", order.Player.Country.Race)));
() => Sound.PlayNotification(self.World.Map.Rules, order.Player, "Speech", "NewOptions", order.Player.Country.Race)));
});
}
}

20
OpenRA.Mods.RA/Player/ProductionQueue.cs Executable file → Normal file
View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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,
@@ -135,7 +135,7 @@ namespace OpenRA.Mods.RA
IEnumerable<ActorInfo> AllBuildables(string category)
{
return Rules.Info.Values
return self.World.Map.Rules.Actors.Values
.Where( x => x.Name[ 0 ] != '^' )
.Where( x => x.Traits.Contains<BuildableInfo>() )
.Where( x => x.Traits.Get<BuildableInfo>().Queue == category );
@@ -149,14 +149,14 @@ namespace OpenRA.Mods.RA
public void PrerequisitesAvailable(string key)
{
var ps = Produceable[ Rules.Info[key] ];
var ps = Produceable[ self.World.Map.Rules.Actors[key] ];
if (!ps.Sticky)
ps.Buildable = true;
}
public void PrerequisitesUnavailable(string key)
{
var ps = Produceable[ Rules.Info[key] ];
var ps = Produceable[ self.World.Map.Rules.Actors[key] ];
if (!ps.Sticky)
ps.Buildable = false;
}
@@ -209,7 +209,7 @@ namespace OpenRA.Mods.RA
{
case "StartProduction":
{
var unit = Rules.Info[order.TargetString];
var unit = self.World.Map.Rules.Actors[order.TargetString];
var bi = unit.Traits.Get<BuildableInfo>();
if (bi.Queue != Info.Type)
return; /* Not built by this queue */
@@ -243,15 +243,15 @@ namespace OpenRA.Mods.RA
var isBuilding = unit.Traits.Contains<BuildingInfo>();
if (isBuilding && !hasPlayedSound)
{
hasPlayedSound = Sound.PlayNotification(self.Owner, "Speech", Info.ReadyAudio, self.Owner.Country.Race);
hasPlayedSound = Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", Info.ReadyAudio, self.Owner.Country.Race);
}
else if (!isBuilding)
{
if (BuildUnit(order.TargetString))
Sound.PlayNotification(self.Owner, "Speech", Info.ReadyAudio, self.Owner.Country.Race);
Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", Info.ReadyAudio, self.Owner.Country.Race);
else if (!hasPlayedSound && time > 0)
{
hasPlayedSound = Sound.PlayNotification(self.Owner, "Speech", Info.BlockedAudio, self.Owner.Country.Race);
hasPlayedSound = Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", Info.BlockedAudio, self.Owner.Country.Race);
}
}
})));
@@ -274,7 +274,7 @@ namespace OpenRA.Mods.RA
virtual public int GetBuildTime(String unitString)
{
var unit = Rules.Info[unitString];
var unit = self.World.Map.Rules.Actors[unitString];
if (unit == null || ! unit.Traits.Contains<BuildableInfo>())
return 0;
@@ -329,7 +329,7 @@ namespace OpenRA.Mods.RA
}
var sp = self.TraitsImplementing<Production>().FirstOrDefault(p => p.Info.Produces.Contains(Info.Type));
if (sp != null && !self.IsDisabled() && sp.Produce(self, Rules.Info[name]))
if (sp != null && !self.IsDisabled() && sp.Produce(self, self.World.Map.Rules.Actors[name]))
{
FinishProduction();
return true;

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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,
@@ -77,7 +77,7 @@ namespace OpenRA.Mods.RA
isPrimary = true;
Sound.PlayNotification(self.Owner, "Speech", "PrimaryBuildingSelected", self.Owner.Country.Race);
Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", "PrimaryBuildingSelected", self.Owner.Country.Race);
}
}
}

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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,
@@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA
var range = FallbackRange;
if (armaments.Any())
range = armaments.Select(a => Rules.Weapons[a.Weapon.ToLowerInvariant()].Range).Max();
range = armaments.Select(a => w.Map.Rules.Weapons[a.Weapon.ToLowerInvariant()].Range).Max();
if (range == WRange.Zero)
return;

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)));

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,
@@ -76,7 +76,7 @@ namespace OpenRA.Mods.RA
variantStride = info.Index.Length;
for (var j = 0; j < info.Variants.Length; j++)
{
var seq = SequenceProvider.GetSequence(info.Sequence, info.Variants[j]);
var seq = map.SequenceProvider.GetSequence(info.Sequence, info.Variants[j]);
for (var i = 0; i < info.Index.Length; i++)
sprites[j * variantStride + i] = seq.GetSprite(i);
}
@@ -95,7 +95,7 @@ namespace OpenRA.Mods.RA
{
var ts = Game.modData.Manifest.TileSize;
var data = Exts.MakeArray<byte>(ts.Width * ts.Height, _ => (byte)info.ShroudColor);
var s = Game.modData.SheetBuilder.Add(data, ts);
var s = map.Rules.TileSets[map.Tileset].Data.SpriteLoader.SheetBuilder.Add(data, ts);
unexploredTile = new Sprite(s.sheet, s.bounds, s.offset, s.channel, info.ShroudBlend);
}
else

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,
@@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA
void SpawnUnitsForPlayer(World w, Player p, CPos sp)
{
var spawnClass = p.PlayerReference.StartingUnitsClass ?? w.LobbyInfo.GlobalSettings.StartingUnitsClass;
var unitGroup = Rules.Info["world"].Traits.WithInterface<MPStartUnitsInfo>()
var unitGroup = w.Map.Rules.Actors["world"].Traits.WithInterface<MPStartUnitsInfo>()
.Where(g => g.Class == spawnClass && g.Races != null && g.Races.Contains(p.Country.Race))
.RandomOrDefault(w.SharedRandom);
@@ -57,7 +57,7 @@ namespace OpenRA.Mods.RA
foreach (var s in unitGroup.SupportActors)
{
var mi = Rules.Info[s.ToLowerInvariant()].Traits.Get<MobileInfo>();
var mi = w.Map.Rules.Actors[s.ToLowerInvariant()].Traits.Get<MobileInfo>();
var validCells = supportSpawnCells.Where(c => mi.CanEnterCell(w, c));
if (!validCells.Any())
throw new InvalidOperationException("No cells available to spawn starting unit {0}".F(s));

View File

@@ -28,9 +28,9 @@ namespace OpenRA.Mods.RA
this.info = info;
}
public void WorldLoaded(World w, WorldRenderer wr)
public void WorldLoaded(World world, WorldRenderer wr)
{
Sound.PlayNotification(null, "Speech", info.Notification, null);
Sound.PlayNotification(world.Map.Rules, null, "Speech", info.Notification, null);
}
}
}

2
OpenRA.Mods.RA/SupportPowers/AirstrikePower.cs Executable file → Normal file
View File

@@ -59,7 +59,7 @@ namespace OpenRA.Mods.RA
var attackRotation = WRot.FromFacing(attackFacing);
var delta = new WVec(0, -1024, 0).Rotate(attackRotation);
var altitude = Rules.Info[info.UnitType].Traits.Get<PlaneInfo>().CruiseAltitude.Range;
var altitude = self.World.Map.Rules.Actors[info.UnitType].Traits.Get<PlaneInfo>().CruiseAltitude.Range;
var target = order.TargetLocation.CenterPosition + new WVec(0, 0, altitude);
var startEdge = target - (self.World.DistanceToMapEdge(target, -delta) + info.Cordon).Range * delta / 1024;
var finishEdge = target + (self.World.DistanceToMapEdge(target, delta) + info.Cordon).Range * delta / 1024;

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA
public override IOrderGenerator OrderGenerator(string order, SupportPowerManager manager)
{
Sound.PlayToPlayer(manager.self.Owner, Info.SelectTargetSound);
return new SelectTarget(order, manager, this);
return new SelectTarget(self.World, order, manager, this);
}
public override void Activate(Actor self, Order order, SupportPowerManager manager)
@@ -115,20 +115,20 @@ namespace OpenRA.Mods.RA
readonly SupportPowerManager manager;
readonly string order;
public SelectTarget(string order, SupportPowerManager manager, ChronoshiftPower power)
public SelectTarget(World world, string order, SupportPowerManager manager, ChronoshiftPower power)
{
this.manager = manager;
this.order = order;
this.power = power;
this.range = (power.Info as ChronoshiftPowerInfo).Range;
tile = SequenceProvider.GetSequence("overlay", "target-select").GetSprite(0);
tile = world.Map.SequenceProvider.GetSequence("overlay", "target-select").GetSprite(0);
}
public IEnumerable<Order> Order(World world, CPos xy, MouseInput mi)
{
world.CancelInputMode();
if (mi.Button == MouseButton.Left)
world.OrderGenerator = new SelectDestination(order, manager, power, xy);
world.OrderGenerator = new SelectDestination(world, order, manager, power, xy);
yield break;
}
@@ -173,7 +173,7 @@ namespace OpenRA.Mods.RA
readonly SupportPowerManager manager;
readonly string order;
public SelectDestination(string order, SupportPowerManager manager, ChronoshiftPower power, CPos sourceLocation)
public SelectDestination(World world, string order, SupportPowerManager manager, ChronoshiftPower power, CPos sourceLocation)
{
this.manager = manager;
this.order = order;
@@ -182,9 +182,9 @@ namespace OpenRA.Mods.RA
this.range = (power.Info as ChronoshiftPowerInfo).Range;
var tileset = manager.self.World.TileSet.Id.ToLower();
validTile = SequenceProvider.GetSequence("overlay", "target-valid-{0}".F(tileset)).GetSprite(0);
invalidTile = SequenceProvider.GetSequence("overlay", "target-invalid").GetSprite(0);
sourceTile = SequenceProvider.GetSequence("overlay", "target-select").GetSprite(0);
validTile = world.Map.SequenceProvider.GetSequence("overlay", "target-valid-{0}".F(tileset)).GetSprite(0);
invalidTile = world.Map.SequenceProvider.GetSequence("overlay", "target-invalid").GetSprite(0);
sourceTile = world.Map.SequenceProvider.GetSequence("overlay", "target-select").GetSprite(0);
}
public IEnumerable<Order> Order(World world, CPos xy, MouseInput mi)

View File

@@ -41,7 +41,7 @@ namespace OpenRA.Mods.RA
public override IOrderGenerator OrderGenerator(string order, SupportPowerManager manager)
{
Sound.PlayToPlayer(manager.self.Owner, Info.SelectTargetSound);
return new SelectTarget(order, manager, this);
return new SelectTarget(self.World, order, manager, this);
}
public override void Activate(Actor self, Order order, SupportPowerManager manager)
@@ -76,13 +76,13 @@ namespace OpenRA.Mods.RA
readonly SupportPowerManager manager;
readonly string order;
public SelectTarget(string order, SupportPowerManager manager, IronCurtainPower power)
public SelectTarget(World world, string order, SupportPowerManager manager, IronCurtainPower power)
{
this.manager = manager;
this.order = order;
this.power = power;
this.range = (power.Info as IronCurtainPowerInfo).Range;
tile = SequenceProvider.GetSequence("overlay", "target-select").GetSprite(0);
tile = world.Map.SequenceProvider.GetSequence("overlay", "target-select").GetSprite(0);
}
public IEnumerable<Order> Order(World world, CPos xy, MouseInput mi)

4
OpenRA.Mods.RA/SupportPowers/ParatroopersPower.cs Executable file → Normal file
View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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,
@@ -55,7 +55,7 @@ namespace OpenRA.Mods.RA
flare.QueueActivity(new RemoveSelf());
}
var altitude = Rules.Info[info.UnitType].Traits.Get<PlaneInfo>().CruiseAltitude;
var altitude = self.World.Map.Rules.Actors[info.UnitType].Traits.Get<PlaneInfo>().CruiseAltitude;
var a = w.CreateActor(info.UnitType, new TypeDictionary
{
new CenterPositionInit(startPos.CenterPosition + new WVec(WRange.Zero, WRange.Zero, altitude)),

4
OpenRA.Mods.RA/SupportPowers/SpyPlanePower.cs Executable file → Normal file
View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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,
@@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA
base.Activate(self, order, manager);
var enterCell = self.World.ChooseRandomEdgeCell();
var altitude = Rules.Info["u2"].Traits.Get<PlaneInfo>().CruiseAltitude;
var altitude = self.World.Map.Rules.Actors["u2"].Traits.Get<PlaneInfo>().CruiseAltitude;
var plane = self.World.CreateActor("u2", new TypeDictionary
{

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,
@@ -79,8 +79,8 @@ namespace OpenRA.Mods.RA
public IEnumerable<IRenderable> GenerateRenderables(WorldRenderer wr)
{
var bright = SequenceProvider.GetSequence(image, "bright");
var dim = SequenceProvider.GetSequence(image, "dim");
var bright = wr.world.Map.SequenceProvider.GetSequence(image, "bright");
var dim = wr.world.Map.SequenceProvider.GetSequence(image, "dim");
var source = wr.ScreenPosition(pos);
var target = wr.ScreenPosition(pos + length);

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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,
@@ -38,7 +38,7 @@ namespace OpenRA.Mods.RA
{
this.self = self;
Info = info;
bi = Rules.Info[info.IntoActor].Traits.GetOrDefault<BuildingInfo>();
bi = self.World.Map.Rules.Actors[info.IntoActor].Traits.GetOrDefault<BuildingInfo>();
}
public string VoicePhraseForOrder(Actor self, Order order)

32
OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs Executable file → Normal file
View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2012 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,
@@ -124,11 +124,11 @@ namespace OpenRA.Mods.RA.Widgets
// Play palette-open sound at the start of the activate anim (open)
if (paletteAnimationFrame == 1 && paletteOpen)
Sound.PlayNotification(null, "Sounds", "BuildPaletteOpen", null);
Sound.PlayNotification(world.Map.Rules, null, "Sounds", "BuildPaletteOpen", null);
// Play palette-close sound at the start of the activate anim (close)
if (paletteAnimationFrame == paletteAnimationLength + -1 && !paletteOpen)
Sound.PlayNotification(null, "Sounds", "BuildPaletteClose", null);
Sound.PlayNotification(world.Map.Rules, null, "Sounds", "BuildPaletteClose", null);
// Animation is complete
if ((paletteAnimationFrame == 0 && !paletteOpen)
@@ -314,7 +314,7 @@ namespace OpenRA.Mods.RA.Widgets
{
return mi =>
{
Sound.PlayNotification(null, "Sounds", "TabClick", null);
Sound.PlayNotification(world.Map.Rules, null, "Sounds", "TabClick", null);
if (name != null)
HandleBuildPalette(world, name, (mi.Button == MouseButton.Left));
@@ -328,7 +328,7 @@ namespace OpenRA.Mods.RA.Widgets
if (mi.Button != MouseButton.Left)
return;
Sound.PlayNotification(null, "Sounds", "TabClick", null);
Sound.PlayNotification(world.Map.Rules, null, "Sounds", "TabClick", null);
var wasOpen = paletteOpen;
paletteOpen = CurrentQueue != queue || !wasOpen;
CurrentQueue = queue;
@@ -337,10 +337,10 @@ namespace OpenRA.Mods.RA.Widgets
};
}
static string Description(string a)
static string Description(MapRuleset rules, string a)
{
ActorInfo ai;
Rules.Info.TryGetValue(a.ToLowerInvariant(), out ai);
rules.Actors.TryGetValue(a.ToLowerInvariant(), out ai);
if (ai != null && ai.Traits.Contains<TooltipInfo>())
return ai.Traits.Get<TooltipInfo>().Name;
@@ -349,7 +349,7 @@ namespace OpenRA.Mods.RA.Widgets
void HandleBuildPalette(World world, string item, bool isLmb)
{
var unit = Rules.Info[item];
var unit = world.Map.Rules.Actors[item];
var producing = CurrentQueue.AllQueued().FirstOrDefault(a => a.Item == item);
if (isLmb)
@@ -379,9 +379,9 @@ namespace OpenRA.Mods.RA.Widgets
var buildLimit = unit.Traits.Get<BuildableInfo>().BuildLimit;
if (!((buildLimit != 0) && (inWorld + queued >= buildLimit)))
Sound.PlayNotification(world.LocalPlayer, "Speech", CurrentQueue.Info.QueuedAudio, world.LocalPlayer.Country.Race);
Sound.PlayNotification(world.Map.Rules, world.LocalPlayer, "Speech", CurrentQueue.Info.QueuedAudio, world.LocalPlayer.Country.Race);
else
Sound.PlayNotification(world.LocalPlayer, "Speech", CurrentQueue.Info.BlockedAudio, world.LocalPlayer.Country.Race);
Sound.PlayNotification(world.Map.Rules, world.LocalPlayer, "Speech", CurrentQueue.Info.BlockedAudio, world.LocalPlayer.Country.Race);
}
StartProduction(world, item);
@@ -393,14 +393,14 @@ namespace OpenRA.Mods.RA.Widgets
// instant cancel of things we havent really started yet, and things that are finished
if (producing.Paused || producing.Done || producing.TotalCost == producing.RemainingCost)
{
Sound.PlayNotification(world.LocalPlayer, "Speech", CurrentQueue.Info.CancelledAudio, world.LocalPlayer.Country.Race);
Sound.PlayNotification(world.Map.Rules, world.LocalPlayer, "Speech", CurrentQueue.Info.CancelledAudio, world.LocalPlayer.Country.Race);
int numberToCancel = Game.GetModifierKeys().HasModifier(Modifiers.Shift) ? 5 : 1;
world.IssueOrder(Order.CancelProduction(CurrentQueue.self, item, numberToCancel));
}
else
{
Sound.PlayNotification(world.LocalPlayer, "Speech", CurrentQueue.Info.OnHoldAudio, world.LocalPlayer.Country.Race);
Sound.PlayNotification(world.Map.Rules, world.LocalPlayer, "Speech", CurrentQueue.Info.OnHoldAudio, world.LocalPlayer.Country.Race);
world.IssueOrder(Order.PauseProduction(CurrentQueue.self, item, true));
}
}
@@ -463,7 +463,7 @@ namespace OpenRA.Mods.RA.Widgets
var pl = world.LocalPlayer;
var p = pos.ToFloat2() - new float2(297, -3);
var info = Rules.Info[unit];
var info = world.Map.Rules.Actors[unit];
var tooltip = info.Traits.Get<TooltipInfo>();
var buildable = info.Traits.Get<BuildableInfo>();
var cost = info.Traits.Get<ValuedInfo>().Cost;
@@ -497,7 +497,7 @@ namespace OpenRA.Mods.RA.Widgets
p += new int2(5, 35);
if (!canBuildThis)
{
var prereqs = buildable.Prerequisites.Select(Description);
var prereqs = buildable.Prerequisites.Select(s => Description(world.Map.Rules, s));
if (prereqs.Any())
{
Game.Renderer.Fonts["Regular"].DrawText(RequiresText.F(prereqs.JoinWith(", ")), p.ToInt2(), Color.White);
@@ -520,7 +520,7 @@ namespace OpenRA.Mods.RA.Widgets
if (toBuild != null)
{
Sound.PlayNotification(null, "Sounds", "TabClick", null);
Sound.PlayNotification(world.Map.Rules, null, "Sounds", "TabClick", null);
HandleBuildPalette(world, toBuild.Name, true);
return true;
}
@@ -531,7 +531,7 @@ namespace OpenRA.Mods.RA.Widgets
// NOTE: Always return true here to prevent mouse events from passing through the sidebar and interacting with the world behind it.
bool ChangeTab(bool reverse)
{
Sound.PlayNotification(null, "Sounds", "TabClick", null);
Sound.PlayNotification(world.Map.Rules, null, "Sounds", "TabClick", null);
var queues = VisibleQueues.Concat(VisibleQueues);
if (reverse)
queues = queues.Reverse();

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,
@@ -38,11 +38,15 @@ namespace OpenRA.Mods.RA.Widgets.Logic
Sprite[] currentSprites;
int currentFrame;
readonly World world;
static readonly string[] AllowedExtensions = { ".shp", ".r8", "tmp", ".tem", ".des", ".sno", ".int" };
[ObjectCreator.UseCtor]
public AssetBrowserLogic(Widget widget, Action onExit, World world)
{
this.world = world;
panel = widget;
assetSource = GlobalFileSystem.MountedFolders.First();
@@ -192,7 +196,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
return false;
currentFilename = filename;
currentSprites = Game.modData.SpriteLoader.LoadAllSprites(filename);
currentSprites = world.Map.Rules.TileSets[world.Map.Tileset].Data.SpriteLoader.LoadAllSprites(filename);
currentFrame = 0;
frameSlider.MaximumValue = (float)currentSprites.Length - 1;
frameSlider.Ticks = currentSprites.Length;

View File

@@ -20,6 +20,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{
public class IngameChatLogic
{
readonly World world;
readonly ContainerWidget chatOverlay;
readonly ChatDisplayWidget chatOverlayDisplay;
@@ -35,6 +37,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
[ObjectCreator.UseCtor]
public IngameChatLogic(Widget widget, OrderManager orderManager, World world)
{
this.world = world;
chatTraits = world.WorldActor.TraitsImplementing<INotifyChat>().ToList();
var players = world.Players.Where(p => p != world.LocalPlayer && !p.NonCombatant && !p.IsBot);
@@ -161,7 +165,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
if (scrolledToBottom)
chatScrollPanel.ScrollToBottom();
Sound.PlayNotification(null, "Sounds", "ChatLine", null);
Sound.PlayNotification(world.Map.Rules, null, "Sounds", "ChatLine", null);
}
}
}
}

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,
@@ -18,9 +18,9 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{
public class IngameChromeLogic
{
Widget gameRoot;
Widget playerRoot;
World world;
readonly Widget gameRoot;
readonly Widget playerRoot;
readonly World world;
[ObjectCreator.UseCtor]
public IngameChromeLogic(World world)
@@ -149,7 +149,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
.Any(a => a.Actor.Owner == world.LocalPlayer && a.Trait.IsActive);
if (radarActive != cachedRadarActive)
Sound.PlayNotification(null, "Sounds", (radarActive ? "RadarUp" : "RadarDown"), null);
Sound.PlayNotification(world.Map.Rules, null, "Sounds", (radarActive ? "RadarUp" : "RadarDown"), null);
cachedRadarActive = radarActive;
// Switch to observer mode after win/loss

View File

@@ -63,7 +63,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
widget.Get<ButtonWidget>("MUSIC").OnClick = () =>
{
widget.Visible = false;
Ui.OpenWindow("MUSIC_PANEL", new WidgetArgs { { "onExit", () => { widget.Visible = true; } } });
MusicPlayerLogic.OpenWindow(world, () => { widget.Visible = true; });
};
widget.Get<ButtonWidget>("RESUME").OnClick = () => onExit();
@@ -82,7 +82,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
void LeaveGame(World world)
{
Sound.PlayNotification(null, "Speech", "Leave", world.LocalPlayer == null ? null : world.LocalPlayer.Country.Race);
Sound.PlayNotification(world.Map.Rules, null, "Speech", "Leave", world.LocalPlayer == null ? null : world.LocalPlayer.Country.Race);
Game.Disconnect();
Ui.CloseWindow();
Game.LoadShellMap();

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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,
@@ -29,6 +29,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
readonly Action onExit;
readonly OrderManager orderManager;
readonly bool skirmishMode;
readonly World world;
enum PanelType { Players, Options, Kick, ForceStart }
PanelType panel = PanelType.Players;
@@ -98,6 +99,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
this.onStart = onStart;
this.onExit = onExit;
this.skirmishMode = skirmishMode;
this.world = world;
Game.LobbyInfoChanged += UpdateCurrentMap;
Game.LobbyInfoChanged += UpdatePlayerList;
@@ -132,7 +134,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
colorPreview = lobby.Get<ColorPreviewManagerWidget>("COLOR_MANAGER");
colorPreview.Color = Game.Settings.Player.Color;
countryNames = Rules.Info["world"].Traits.WithInterface<CountryInfo>()
countryNames = world.Map.Rules.Actors["world"].Traits.WithInterface<CountryInfo>()
.Where(c => c.Selectable)
.ToDictionary(a => a.Race, a => a.Name);
countryNames.Add("random", "Any");
@@ -170,7 +172,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
slotsButton.IsDisabled = () => configurationDisabled() || panel != PanelType.Players ||
!orderManager.LobbyInfo.Slots.Values.Any(s => s.AllowBots || !s.LockTeam);
var botNames = Rules.Info["player"].Traits.WithInterface<IBotInfo>().Select(t => t.Name);
var botNames = world.Map.Rules.Actors["player"].Traits.WithInterface<IBotInfo>().Select(t => t.Name);
slotsButton.OnMouseDown = _ =>
{
var options = new Dictionary<string, IEnumerable<DropDownOption>>();
@@ -375,7 +377,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
};
Func<string, string> className = c => classNames.ContainsKey(c) ? classNames[c] : c;
var classes = Rules.Info["world"].Traits.WithInterface<MPStartUnitsInfo>()
var classes = world.Map.Rules.Actors["world"].Traits.WithInterface<MPStartUnitsInfo>()
.Select(a => a.Class).Distinct();
startingUnits.IsDisabled = () => Map.Status != MapStatus.Available || !Map.Map.Options.ConfigurableStartingUnits || configurationDisabled();
@@ -409,7 +411,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
startingCash.GetText = () => Map.Status != MapStatus.Available || Map.Map.Options.StartingCash.HasValue ? "Not Available" : "${0}".F(orderManager.LobbyInfo.GlobalSettings.StartingCash);
startingCash.OnMouseDown = _ =>
{
var options = Rules.Info["player"].Traits.Get<PlayerResourcesInfo>().SelectableCash.Select(c => new DropDownOption
var options = world.Map.Rules.Actors["player"].Traits.Get<PlayerResourcesInfo>().SelectableCash.Select(c => new DropDownOption
{
Title = "${0}".F(c),
IsSelected = () => orderManager.LobbyInfo.GlobalSettings.StartingCash == c,
@@ -481,7 +483,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var musicButton = lobby.GetOrNull<ButtonWidget>("MUSIC_BUTTON");
if (musicButton != null)
musicButton.OnClick = () => Ui.OpenWindow("MUSIC_PANEL", new WidgetArgs { { "onExit", DoNothing } });
musicButton.OnClick = () => MusicPlayerLogic.OpenWindow(world);
var settingsButton = lobby.GetOrNull<ButtonWidget>("SETTINGS_BUTTON");
if (settingsButton != null)
@@ -499,7 +501,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
Game.LobbyInfoChanged += WidgetUtils.Once(() =>
{
var slot = orderManager.LobbyInfo.FirstEmptyBotSlot();
var bot = Rules.Info["player"].Traits.WithInterface<IBotInfo>().Select(t => t.Name).FirstOrDefault();
var bot = world.Map.Rules.Actors["player"].Traits.WithInterface<IBotInfo>().Select(t => t.Name).FirstOrDefault();
var botController = orderManager.LobbyInfo.Clients.FirstOrDefault(c => c.IsAdmin);
if (slot != null && bot != null)
orderManager.IssueOrder(Order.Command("slot_bot {0} {1} {2}".F(slot, botController.Index, bot)));
@@ -542,7 +544,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
if (scrolledToBottom)
chatPanel.ScrollToBottom();
Sound.PlayNotification(null, "Sounds", "ChatLine", null);
Sound.PlayNotification(world.Map.Rules, null, "Sounds", "ChatLine", null);
}
void UpdateCurrentMap()
@@ -559,7 +561,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
orderManager.IssueOrder(Order.Command("state {0}".F(Session.ClientState.NotReady)));
// Restore default starting cash if the last map set it to something invalid
var pri = Rules.Info["player"].Traits.Get<PlayerResourcesInfo>();
var pri = world.Map.Rules.Actors["player"].Traits.Get<PlayerResourcesInfo>();
if (!Map.Map.Options.StartingCash.HasValue && !pri.SelectableCash.Contains(orderManager.LobbyInfo.GlobalSettings.StartingCash))
orderManager.IssueOrder(Order.Command("startingcash {0}".F(pri.DefaultCash)));
}
@@ -588,7 +590,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
template = emptySlotTemplate.Clone();
if (Game.IsHost)
LobbyUtils.SetupEditableSlotWidget(template, slot, client, orderManager);
LobbyUtils.SetupEditableSlotWidget(template, slot, client, orderManager, world.Map.Rules);
else
LobbyUtils.SetupSlotWidget(template, slot, client);
@@ -607,7 +609,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
LobbyUtils.SetupClientWidget(template, slot, client, orderManager, client.Bot == null);
if (client.Bot != null)
LobbyUtils.SetupEditableSlotWidget(template, slot, client, orderManager);
LobbyUtils.SetupEditableSlotWidget(template, slot, client, orderManager, world.Map.Rules);
else
LobbyUtils.SetupEditableNameWidget(template, slot, client, orderManager);

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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,
@@ -37,7 +37,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
}
}
public static void ShowSlotDropDown(DropDownButtonWidget dropdown, Session.Slot slot,
public static void ShowSlotDropDown(MapRuleset rules, DropDownButtonWidget dropdown, Session.Slot slot,
Session.Client client, OrderManager orderManager)
{
var options = new Dictionary<string, IEnumerable<SlotDropDownOption>>() {{"Slot", new List<SlotDropDownOption>()
@@ -49,7 +49,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var bots = new List<SlotDropDownOption>();
if (slot.AllowBots)
{
foreach (var b in Rules.Info["player"].Traits.WithInterface<IBotInfo>().Select(t => t.Name))
foreach (var b in rules.Actors["player"].Traits.WithInterface<IBotInfo>().Select(t => t.Name))
{
var bot = b;
var botController = orderManager.LobbyInfo.Clients.FirstOrDefault(c => c.IsAdmin);
@@ -280,13 +280,13 @@ namespace OpenRA.Mods.RA.Widgets.Logic
name.GetText = () => c.Name;
}
public static void SetupEditableSlotWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager)
public static void SetupEditableSlotWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, MapRuleset rules)
{
var slot = parent.Get<DropDownButtonWidget>("SLOT_OPTIONS");
slot.IsVisible = () => true;
slot.IsDisabled = () => orderManager.LocalClient.IsReady;
slot.GetText = () => c != null ? c.Name : s.Closed ? "Closed" : "Open";
slot.OnMouseDown = _ => ShowSlotDropDown(slot, s, c, orderManager);
slot.OnMouseDown = _ => ShowSlotDropDown(rules, slot, s, c, orderManager);
// Ensure Name selector (if present) is hidden
var name = parent.GetOrNull("NAME");

View File

@@ -110,10 +110,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
extrasMenu.Get<ButtonWidget>("MUSIC_BUTTON").OnClick = () =>
{
menuType = MenuType.None;
Ui.OpenWindow("MUSIC_PANEL", new WidgetArgs
{
{ "onExit", () => menuType = MenuType.Extras },
});
MusicPlayerLogic.OpenWindow(world, () => menuType = MenuType.Extras);
};
var assetBrowserButton = extrasMenu.GetOrNull<ButtonWidget>("ASSETBROWSER_BUTTON");

View File

@@ -23,8 +23,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{
Widget modList;
ButtonWidget modTemplate;
Mod[] allMods;
Mod selectedMod;
ModInformation[] allMods;
ModInformation selectedMod;
string selectedAuthor;
string selectedDescription;
int modOffset = 0;
@@ -67,7 +67,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var sheetBuilder = new SheetBuilder(SheetType.BGRA);
previews = new Dictionary<string, Sprite>();
logos = new Dictionary<string, Sprite>();
allMods = Mod.AllMods.Values.Where(m => m.Id != "modchooser")
allMods = ModInformation.AllMods.Values.Where(m => m.Id != "modchooser")
.OrderBy(m => m.Title)
.ToArray();
@@ -96,9 +96,9 @@ namespace OpenRA.Mods.RA.Widgets.Logic
}
Mod initialMod = null;
Mod.AllMods.TryGetValue(Game.Settings.Game.PreviousMod, out initialMod);
SelectMod(initialMod ?? Mod.AllMods["ra"]);
ModInformation initialMod = null;
ModInformation.AllMods.TryGetValue(Game.Settings.Game.PreviousMod, out initialMod);
SelectMod(initialMod ?? ModInformation.AllMods["ra"]);
RebuildModList();
}
@@ -147,7 +147,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
}
}
void SelectMod(Mod mod)
void SelectMod(ModInformation mod)
{
selectedMod = mod;
selectedAuthor = "By " + mod.Author ?? "unknown author";
@@ -157,7 +157,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
modOffset = selectedIndex - 4;
}
void LoadMod(Mod mod)
void LoadMod(ModInformation mod)
{
Game.RunAfterTick(() =>
{

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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,
@@ -18,6 +18,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{
public class MusicPlayerLogic
{
readonly World world;
bool installed;
MusicInfo currentSong = null;
MusicInfo[] music;
@@ -26,9 +28,22 @@ namespace OpenRA.Mods.RA.Widgets.Logic
ScrollItemWidget itemTemplate;
[ObjectCreator.UseCtor]
public MusicPlayerLogic(Widget widget, Action onExit)
public static Widget OpenWindow(World world, Action onExit = null)
{
return Ui.OpenWindow(
"MUSIC_PANEL",
new WidgetArgs
{
{ "onExit", onExit != null ? onExit : (() => {}) }
}
);
}
[ObjectCreator.UseCtor]
public MusicPlayerLogic(Widget widget, World world, Action onExit)
{
this.world = world;
var panel = widget.Get("MUSIC_PANEL");
musicList = panel.Get<ScrollPanelWidget>("MUSIC_LIST");
@@ -82,7 +97,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
public void BuildMusicTable()
{
music = Rules.InstalledMusic.Select(a => a.Value).ToArray();
music = world.Map.Rules.InstalledMusic.Select(a => a.Value).ToArray();
random = music.Shuffle(Game.CosmeticRandom).ToArray();
currentSong = Sound.CurrentMusic;
if (currentSong == null && music.Any())
@@ -105,7 +120,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
if (currentSong != null)
musicList.ScrollToItem(currentSong.Filename);
installed = Rules.InstalledMusic.Any();
installed = world.Map.Rules.InstalledMusic.Any();
}
void Play()

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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,
@@ -315,10 +315,10 @@ namespace OpenRA.Mods.RA.Widgets.Logic
public static string GenerateModLabel(GameServer s)
{
Mod mod;
ModInformation mod;
var modVersion = s.Mods.Split('@');
if (modVersion.Length == 2 && Mod.AllMods.TryGetValue(modVersion[0], out mod))
if (modVersion.Length == 2 && ModInformation.AllMods.TryGetValue(modVersion[0], out mod))
return "{0} ({1})".F(mod.Title, modVersion[1]);
return "Unknown mod: {0}".F(s.Mods);

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2012 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,
@@ -21,8 +21,8 @@ namespace OpenRA.Mods.RA.Widgets
public class ObserverProductionIconsWidget : Widget
{
public Func<Player> GetPlayer;
World world;
WorldRenderer worldRenderer;
readonly World world;
readonly WorldRenderer worldRenderer;
Dictionary<ProductionQueue, Animation> clocks;
public int IconWidth = 32;

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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,
@@ -68,7 +68,7 @@ namespace OpenRA.Mods.RA.Widgets
mapRect = new Rectangle(previewOrigin.X, previewOrigin.Y, (int)(previewScale * width), (int)(previewScale * height));
// Only needs to be done once
var terrainBitmap = Minimap.TerrainBitmap(world.Map);
var terrainBitmap = Minimap.TerrainBitmap(world.Map.Rules.TileSets[world.Map.Tileset], world.Map);
var r = new Rectangle(0, 0, width, height);
var s = new Size(terrainBitmap.Width, terrainBitmap.Height);
terrainSprite = new Sprite(new Sheet(s), r, TextureChannel.Alpha);
@@ -99,7 +99,7 @@ namespace OpenRA.Mods.RA.Widgets
if (cursor == null)
return "default";
return CursorProvider.HasCursorSequence(cursor + "-minimap") ? cursor + "-minimap" : cursor;
return Game.modData.CursorProvider.HasCursorSequence(cursor + "-minimap") ? cursor + "-minimap" : cursor;
}
public override bool HandleMouseInput(MouseInput mi)

View File

@@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA
{
domainIndexes = new Dictionary<uint, MovementClassDomainIndex>();
var movementClasses = new HashSet<uint>(
Rules.Info.Where(ai => ai.Value.Traits.Contains<MobileInfo>())
world.Map.Rules.Actors.Where(ai => ai.Value.Traits.Contains<MobileInfo>())
.Select(ai => (uint)ai.Value.Traits.Get<MobileInfo>().GetMovementClass(world.TileSet)));
foreach (var mc in movementClasses)

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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,
@@ -24,19 +24,28 @@ namespace OpenRA.Mods.RA
class PlayMusicOnMapLoad : IWorldLoaded
{
PlayMusicOnMapLoadInfo Info;
readonly PlayMusicOnMapLoadInfo info;
World world;
public PlayMusicOnMapLoad(PlayMusicOnMapLoadInfo info) { Info = info; }
public PlayMusicOnMapLoad(PlayMusicOnMapLoadInfo info)
{
this.info = info;
}
public void WorldLoaded(World w, WorldRenderer wr) { PlayMusic(); }
public void WorldLoaded(World world, WorldRenderer wr)
{
this.world = world;
PlayMusic();
}
void PlayMusic()
{
var onComplete = Info.Loop ? (Action)PlayMusic : () => {};
var onComplete = info.Loop ? (Action)PlayMusic : () => {};
if (Game.Settings.Sound.MapMusic &&
Rules.Music.ContainsKey(Info.Music))
Sound.PlayMusicThen(Rules.Music[Info.Music], onComplete);
world.Map.Rules.Music.ContainsKey(info.Music))
Sound.PlayMusicThen(world.Map.Rules.Music[info.Music], onComplete);
}
}
}

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,
@@ -56,10 +56,10 @@ namespace OpenRA.Mods.RA
dirty = new Dictionary<CPos, Smudge>();
smudges = new Dictionary<string, Sprite[]>();
var types = SequenceProvider.Sequences(Info.Sequence);
var types = world.Map.SequenceProvider.Sequences(Info.Sequence);
foreach (var t in types)
{
var seq = SequenceProvider.GetSequence(Info.Sequence, t);
var seq = world.Map.SequenceProvider.GetSequence(Info.Sequence, t);
var sprites = Exts.MakeArray(seq.Length, x => seq.GetSprite(x));
smudges.Add(t, sprites);
}