Merge pull request #8017 from pchote/map-definitions
Remove magic ActorReference/SmudgeReference parsing
This commit is contained in:
@@ -18,7 +18,7 @@ namespace OpenRA.Mods.Common.Lint
|
||||
{
|
||||
public void Run(Action<string> emitError, Action<string> emitWarning, Map map)
|
||||
{
|
||||
var actorTypes = map.Actors.Value.Values.Select(a => a.Type);
|
||||
var actorTypes = map.ActorDefinitions.Select(a => a.Value.Value);
|
||||
foreach (var actor in actorTypes)
|
||||
if (!map.Rules.Actors.Keys.Contains(actor.ToLowerInvariant()))
|
||||
emitError("Actor {0} is not defined by any rule.".F(actor));
|
||||
|
||||
@@ -789,7 +789,7 @@ namespace OpenRA.Mods.Common.Server
|
||||
|
||||
int spawnPoint;
|
||||
if (!Exts.TryParseIntegerInvariant(parts[1], out spawnPoint)
|
||||
|| spawnPoint < 0 || spawnPoint > server.Map.GetSpawnPoints().Length)
|
||||
|| spawnPoint < 0 || spawnPoint > server.Map.SpawnPoints.Value.Length)
|
||||
{
|
||||
Log.Write("server", "Invalid spawn point: {0}", parts[1]);
|
||||
return true;
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void WorldLoaded(World world, WorldRenderer wr)
|
||||
{
|
||||
var spawns = world.Map.GetSpawnPoints();
|
||||
var spawns = world.Map.SpawnPoints.Value;
|
||||
var taken = world.LobbyInfo.Clients.Where(c => c.SpawnPoint != 0 && c.Slot != null)
|
||||
.Select(c => spawns[c.SpawnPoint - 1]).ToList();
|
||||
var available = spawns.Except(taken).ToList();
|
||||
|
||||
@@ -72,16 +72,27 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
|
||||
// Add map smudges
|
||||
foreach (var s in w.Map.Smudges.Value.Where(s => smudges.ContainsKey(s.Type)))
|
||||
foreach (var s in w.Map.SmudgeDefinitions)
|
||||
{
|
||||
var name = s.Key;
|
||||
var vals = name.Split(' ');
|
||||
var type = vals[0];
|
||||
|
||||
if (!smudges.ContainsKey(type))
|
||||
continue;
|
||||
|
||||
var loc = vals[1].Split(',');
|
||||
var cell = new CPos(Exts.ParseIntegerInvariant(loc[0]), Exts.ParseIntegerInvariant(loc[1]));
|
||||
var depth = Exts.ParseIntegerInvariant(vals[2]);
|
||||
|
||||
var smudge = new Smudge
|
||||
{
|
||||
Type = s.Type,
|
||||
Depth = s.Depth,
|
||||
Sprite = smudges[s.Type][s.Depth]
|
||||
Type = type,
|
||||
Depth = depth,
|
||||
Sprite = smudges[type][depth]
|
||||
};
|
||||
|
||||
tiles.Add((CPos)s.Location, smudge);
|
||||
tiles.Add(cell, smudge);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,17 +25,19 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void WorldLoaded(World world, WorldRenderer wr)
|
||||
{
|
||||
foreach (var actorReference in world.Map.Actors.Value)
|
||||
foreach (var kv in world.Map.ActorDefinitions)
|
||||
{
|
||||
var actorReference = new ActorReference(kv.Value.Value, kv.Value.ToDictionary());
|
||||
|
||||
// if there is no real player associated, dont spawn it.
|
||||
var ownerName = actorReference.Value.InitDict.Get<OwnerInit>().PlayerName;
|
||||
var ownerName = actorReference.InitDict.Get<OwnerInit>().PlayerName;
|
||||
if (!world.Players.Any(p => p.InternalName == ownerName))
|
||||
continue;
|
||||
|
||||
var initDict = actorReference.Value.InitDict;
|
||||
var initDict = actorReference.InitDict;
|
||||
initDict.Add(new SkipMakeAnimsInit());
|
||||
var actor = world.CreateActor(actorReference.Value.Type, initDict);
|
||||
Actors[actorReference.Key] = actor;
|
||||
var actor = world.CreateActor(actorReference.Type, initDict);
|
||||
Actors[kv.Key] = actor;
|
||||
LastMapActorID = actor.ActorID;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,8 +150,6 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
map.MapSize = new int2(mapSize, mapSize);
|
||||
map.Bounds = Rectangle.FromLTRB(offsetX, offsetY, offsetX + width, offsetY + height);
|
||||
|
||||
map.Smudges = Exts.Lazy(() => new List<SmudgeReference>());
|
||||
map.Actors = Exts.Lazy(() => new Dictionary<string, ActorReference>());
|
||||
map.MapResources = Exts.Lazy(() => new CellLayer<ResourceTile>(TileShape.Rectangle, size));
|
||||
map.MapTiles = Exts.Lazy(() => new CellLayer<TerrainTile>(TileShape.Rectangle, size));
|
||||
|
||||
@@ -190,26 +188,28 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
{
|
||||
if (kv.First <= 7)
|
||||
{
|
||||
var a = new ActorReference("mpspawn")
|
||||
var ar = new ActorReference("mpspawn")
|
||||
{
|
||||
new LocationInit((CPos)kv.Second),
|
||||
new OwnerInit("Neutral")
|
||||
};
|
||||
map.Actors.Value.Add("Actor" + map.Actors.Value.Count.ToString(), a);
|
||||
|
||||
map.ActorDefinitions.Add(new MiniYamlNode("Actor" + actorCount++, ar.Save()));
|
||||
}
|
||||
else
|
||||
{
|
||||
var a = new ActorReference("waypoint")
|
||||
var ar = new ActorReference("waypoint")
|
||||
{
|
||||
new LocationInit((CPos)kv.Second),
|
||||
new OwnerInit("Neutral")
|
||||
};
|
||||
map.Actors.Value.Add("waypoint" + kv.First, a);
|
||||
|
||||
map.ActorDefinitions.Add(new MiniYamlNode("waypoint" + kv.First, ar.Save()));
|
||||
}
|
||||
}
|
||||
|
||||
// Create default player definitions only if there are no players to import
|
||||
mapPlayers = new MapPlayers(map.Rules, (players.Count == 0) ? map.GetSpawnPoints().Length : 0);
|
||||
mapPlayers = new MapPlayers(map.Rules, (players.Count == 0) ? map.SpawnPoints.Value.Length : 0);
|
||||
foreach (var p in players)
|
||||
LoadPlayer(file, p, legacyMapFormat == IniMapFormat.RedAlert);
|
||||
map.PlayerDefinitions = mapPlayers.ToMiniYaml();
|
||||
@@ -295,12 +295,13 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
|
||||
if (o != 255 && overlayActorMapping.ContainsKey(redAlertOverlayNames[o]))
|
||||
{
|
||||
map.Actors.Value.Add("Actor" + actorCount++,
|
||||
new ActorReference(overlayActorMapping[redAlertOverlayNames[o]])
|
||||
{
|
||||
new LocationInit(cell),
|
||||
new OwnerInit("Neutral")
|
||||
});
|
||||
var ar = new ActorReference(overlayActorMapping[redAlertOverlayNames[o]])
|
||||
{
|
||||
new LocationInit(cell),
|
||||
new OwnerInit("Neutral")
|
||||
};
|
||||
|
||||
map.ActorDefinitions.Add(new MiniYamlNode("Actor" + actorCount++, ar.Save()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -315,12 +316,13 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
foreach (var kv in terrain)
|
||||
{
|
||||
var loc = Exts.ParseIntegerInvariant(kv.Key);
|
||||
map.Actors.Value.Add("Actor" + actorCount++,
|
||||
new ActorReference(kv.Value.ToLowerInvariant())
|
||||
{
|
||||
new LocationInit(new CPos(loc % mapSize, loc / mapSize)),
|
||||
new OwnerInit("Neutral")
|
||||
});
|
||||
var ar = new ActorReference(kv.Value.ToLowerInvariant())
|
||||
{
|
||||
new LocationInit(new CPos(loc % mapSize, loc / mapSize)),
|
||||
new OwnerInit("Neutral")
|
||||
};
|
||||
|
||||
map.ActorDefinitions.Add(new MiniYamlNode("Actor" + actorCount++, ar.Save()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -355,12 +357,15 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
map.MapResources.Value[cell] = new ResourceTile(res.First, res.Second);
|
||||
|
||||
if (overlayActorMapping.ContainsKey(kv.Value.ToLower()))
|
||||
map.Actors.Value.Add("Actor" + actorCount++,
|
||||
new ActorReference(overlayActorMapping[kv.Value.ToLower()])
|
||||
{
|
||||
new LocationInit(cell),
|
||||
new OwnerInit("Neutral")
|
||||
});
|
||||
{
|
||||
var ar = new ActorReference(overlayActorMapping[kv.Value.ToLower()])
|
||||
{
|
||||
new LocationInit(cell),
|
||||
new OwnerInit("Neutral")
|
||||
};
|
||||
|
||||
map.ActorDefinitions.Add(new MiniYamlNode("Actor" + actorCount++, ar.Save()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -373,12 +378,13 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
foreach (var kv in terrain)
|
||||
{
|
||||
var loc = Exts.ParseIntegerInvariant(kv.Key);
|
||||
map.Actors.Value.Add("Actor" + actorCount++,
|
||||
new ActorReference(kv.Value.Split(',')[0].ToLowerInvariant())
|
||||
{
|
||||
new LocationInit(new CPos(loc % mapSize, loc / mapSize)),
|
||||
new OwnerInit("Neutral")
|
||||
});
|
||||
var ar = new ActorReference(kv.Value.Split(',')[0].ToLowerInvariant())
|
||||
{
|
||||
new LocationInit(new CPos(loc % mapSize, loc / mapSize)),
|
||||
new OwnerInit("Neutral")
|
||||
};
|
||||
|
||||
map.ActorDefinitions.Add(new MiniYamlNode("Actor" + actorCount++, ar.Save()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -420,7 +426,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
if (!rules.Actors.ContainsKey(parts[1].ToLowerInvariant()))
|
||||
errorHandler("Ignoring unknown actor type: `{0}`".F(parts[1].ToLowerInvariant()));
|
||||
else
|
||||
map.Actors.Value.Add("Actor" + actorCount++, actor);
|
||||
map.ActorDefinitions.Add(new MiniYamlNode("Actor" + actorCount++, actor.Save()));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
@@ -436,7 +442,8 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
// loc=type,loc,depth
|
||||
var parts = s.Value.Split(',');
|
||||
var loc = Exts.ParseIntegerInvariant(parts[1]);
|
||||
map.Smudges.Value.Add(new SmudgeReference(parts[0].ToLowerInvariant(), new int2(loc % mapSize, loc / mapSize), Exts.ParseIntegerInvariant(parts[2])));
|
||||
var key = "{0} {1},{2} {3}".F(parts[0].ToLowerInvariant(), loc % mapSize, loc / mapSize, Exts.ParseIntegerInvariant(parts[2]));
|
||||
map.SmudgeDefinitions.Add(new MiniYamlNode(key, ""));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
UpgradeRules.UpgradeWeaponRules(engineDate, ref map.WeaponDefinitions, null, 0);
|
||||
UpgradeRules.UpgradeActorRules(engineDate, ref map.RuleDefinitions, null, 0);
|
||||
UpgradeRules.UpgradePlayers(engineDate, ref map.PlayerDefinitions, null, 0);
|
||||
UpgradeRules.UpgradeActors(engineDate, ref map.ActorDefinitions, null, 0);
|
||||
map.Save(args[1]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,6 +84,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
UpgradeRules.UpgradeActorRules(engineDate, ref map.RuleDefinitions, null, 0);
|
||||
UpgradeRules.UpgradeWeaponRules(engineDate, ref map.WeaponDefinitions, null, 0);
|
||||
UpgradeRules.UpgradePlayers(engineDate, ref map.PlayerDefinitions, null, 0);
|
||||
UpgradeRules.UpgradeActors(engineDate, ref map.ActorDefinitions, null, 0);
|
||||
map.Save(map.Path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1365,5 +1365,11 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
foreach (var node in nodes)
|
||||
UpgradePlayers(engineVersion, ref node.Value.Nodes, node, depth + 1);
|
||||
}
|
||||
|
||||
internal static void UpgradeActors(int engineVersion, ref List<MiniYamlNode> nodes, MiniYamlNode parent, int depth)
|
||||
{
|
||||
foreach (var node in nodes)
|
||||
UpgradeActors(engineVersion, ref node.Value.Nodes, node, depth + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user