Allow map slots to disallow bots

This commit is contained in:
Paul Chote
2010-10-15 18:21:26 +13:00
parent bba9c4b976
commit aa2aba1250
4 changed files with 11 additions and 34 deletions

View File

@@ -20,7 +20,7 @@ namespace OpenRA.FileFormats
public readonly IFolder Package;
// Yaml map data
public readonly string Uid;
public string Uid { get; protected set; }
[FieldLoader.Load] public bool Selectable;
[FieldLoader.Load] public string Title;
@@ -38,6 +38,7 @@ namespace OpenRA.FileFormats
public int Width { get { return BottomRight.X - TopLeft.X; } }
public int Height { get { return BottomRight.Y - TopLeft.Y; } }
public MapStub() {} // Hack for the editor - not used for anything important
public MapStub(IFolder package)
{
Package = package;

View File

@@ -21,6 +21,7 @@ namespace OpenRA.FileFormats
public bool NonCombatant = false;
public bool Playable = false;
public bool DefaultStartingUnits = false;
public bool AllowBots = true;
public Color Color = Color.FromArgb(238,238,238);
public Color Color2 = Color.FromArgb(44,28,24);

View File

@@ -19,24 +19,14 @@ using OpenRA.FileFormats;
namespace OpenRA
{
public class Map
public class Map : MapStub
{
public IFolder Package;
public string Uid;
// Yaml map data
[FieldLoader.Load] public bool Selectable = true;
[FieldLoader.Load] public int MapFormat;
[FieldLoader.Load] public string Title;
[FieldLoader.Load] public string Description;
[FieldLoader.Load] public string Author;
[FieldLoader.Load] public int PlayerCount;
[FieldLoader.Load] public string Tileset;
public Dictionary<string, PlayerReference> Players = new Dictionary<string, PlayerReference>();
public Dictionary<string, ActorReference> Actors = new Dictionary<string, ActorReference>();
public List<SmudgeReference> Smudges = new List<SmudgeReference>();
public Dictionary<string, int2> Waypoints = new Dictionary<string, int2>();
// Rules overrides
public List<MiniYamlNode> Rules = new List<MiniYamlNode>();
@@ -45,8 +35,6 @@ namespace OpenRA
public byte TileFormat = 1;
[FieldLoader.Load] public int2 MapSize;
[FieldLoader.Load] public int2 TopLeft;
[FieldLoader.Load] public int2 BottomRight;
public TileReference<ushort, byte>[,] MapTiles;
public TileReference<byte, byte>[,] MapResources;
@@ -55,10 +43,7 @@ namespace OpenRA
// Temporary compat hacks
public int XOffset { get { return TopLeft.X; } }
public int YOffset { get { return TopLeft.Y; } }
public int Width { get { return BottomRight.X - TopLeft.X; } }
public int Height { get { return BottomRight.Y - TopLeft.Y; } }
public string Theater { get { return Tileset; } }
public IEnumerable<int2> SpawnPoints { get { return Waypoints.Select(kv => kv.Value); } }
public Rectangle Bounds { get { return Rectangle.FromLTRB(TopLeft.X, TopLeft.Y, BottomRight.X, BottomRight.Y); } }
public Map()
@@ -97,19 +82,13 @@ namespace OpenRA
}
public Map(IFolder package)
: base(package)
{
Package = package;
var yaml = new MiniYaml( null, MiniYaml.FromStream( Package.GetContent( "map.yaml" ) ) );
// 'Simple' metadata
FieldLoader.Load( this, yaml );
// Waypoints
foreach (var wp in yaml.NodesDict["Waypoints"].NodesDict)
{
string[] loc = wp.Value.Value.Split(',');
Waypoints.Add(wp.Key, new int2(int.Parse(loc[0]), int.Parse(loc[1])));
}
// Players & Actors -- this has changed several times.
// - Be backwards compatible wherever possible.
@@ -199,7 +178,6 @@ namespace OpenRA
Rules = yaml.NodesDict["Rules"].Nodes;
CustomTerrain = new string[MapSize.X, MapSize.Y];
LoadUid();
LoadBinaryData();
}
@@ -314,11 +292,6 @@ namespace OpenRA
File.Move(filepath + ".tmp", filepath);
}
public void LoadUid()
{
Uid = Package.GetContent("map.uid").ReadAllText();
}
public void SaveUid(string filename)
{
// UID is calculated by taking an SHA1 of the yaml and binary data

View File

@@ -23,7 +23,7 @@ namespace OpenRA.Widgets.Delegates
Dictionary<string, string> CountryNames;
string MapUid;
MapStub Map;
Map Map;
public static Color CurrentColorPreview1;
public static Color CurrentColorPreview2;
@@ -109,6 +109,8 @@ namespace OpenRA.Widgets.Delegates
orderManager.IssueOrder(Order.Command("startgame"));
return true;
};
// Todo: Only show if the map requirements are met for player slots
startGameButton.IsVisible = () => Game.IsHost;
Game.LobbyInfoChanged += JoinedServer;
@@ -179,7 +181,7 @@ namespace OpenRA.Widgets.Delegates
{
if (MapUid == orderManager.LobbyInfo.GlobalSettings.Map) return;
MapUid = orderManager.LobbyInfo.GlobalSettings.Map;
Map = Game.modData.AvailableMaps[MapUid];
Map = new Map(Game.modData.AvailableMaps[MapUid].Package);
var title = Widget.RootWidget.GetWidget<LabelWidget>("LOBBY_TITLE");
title.Text = "OpenRA Multiplayer Lobby - " + orderManager.LobbyInfo.GlobalSettings.ServerName;
@@ -242,7 +244,7 @@ namespace OpenRA.Widgets.Delegates
}
else
{
if (s.Bot == null)
if (s.Bot == null && Map.Players[s.MapPlayer].AllowBots)
orderManager.IssueOrder(Order.Command("slot_bot {0} HackyAI".F(s.Index)));
else
orderManager.IssueOrder(Order.Command("slot_close " + s.Index));