crude map change support; quite a few things aren't right

This commit is contained in:
Chris Forbes
2009-12-22 21:49:04 +13:00
parent ff90bd7b21
commit f57865bd32
7 changed files with 81 additions and 35 deletions

View File

@@ -301,6 +301,29 @@ namespace OpenRA.Server
new ServerOrder(conn.PlayerIndex, "SetPalette", pal.ToString()).Serialize()); new ServerOrder(conn.PlayerIndex, "SetPalette", pal.ToString()).Serialize());
return true; return true;
}}, }},
{ "map",
s =>
{
if (conn.PlayerIndex != 0)
{
DispatchOrdersToClient(conn, 0,
new ServerOrder( conn.PlayerIndex, "Chat",
"Only the host can change the map" ).Serialize() );
return true;
}
if (conn.IsReady)
{
DispatchOrdersToClient(conn, 0,
new ServerOrder( conn.PlayerIndex, "Chat",
"You can't change the map after the game has started" ).Serialize() );
return true;
}
DispatchOrders( null, 0,
new ServerOrder(0, "ChangeMap", s).Serialize());
return true;
}},
}; };
var cmdName = cmd.Split(' ').First(); var cmdName = cmd.Split(' ').First();

View File

@@ -48,45 +48,68 @@ namespace OpenRa.Game
public static bool skipMakeAnims = true; public static bool skipMakeAnims = true;
public static void Initialize(string mapName, Renderer renderer, int2 clientSize, static Renderer renderer;
int localPlayer, bool useAftermath, Controller controller) static bool usingAftermath;
static int2 clientSize;
public static void ChangeMap(string mapName)
{ {
Rules.LoadRules(mapName, useAftermath); SheetBuilder.Initialize(renderer);
Rules.LoadRules(mapName, usingAftermath);
world = new World(); world = new World();
for( int i = 0 ; i < 8 ; i++ ) for (int i = 0; i < 8; i++)
{ {
var a = new Actor( null, new int2( int.MaxValue, int.MaxValue ), null ); var a = new Actor(null, new int2(int.MaxValue, int.MaxValue), null);
players[ i ] = new Player( a, i, i, "Multi{0}".F( i ), Race.Allies ); players[i] = new Player(a, i, i, "Multi{0}".F(i), Race.Allies);
a.Owner = players[ i ]; a.Owner = players[i];
a.traits.Add( new Traits.ProductionQueue( a ) ); a.traits.Add(new Traits.ProductionQueue(a));
Game.world.Add( a ); Game.world.Add(a);
} }
localPlayerIndex = localPlayer;
Rules.Map.InitOreDensity(); Rules.Map.InitOreDensity();
worldRenderer = new WorldRenderer(renderer);
Game.controller = controller; SequenceProvider.Initialize(usingAftermath);
worldRenderer = new WorldRenderer( renderer ); viewport = new Viewport(clientSize, Rules.Map.Offset, Rules.Map.Offset + Rules.Map.Size, renderer);
SequenceProvider.Initialize(useAftermath);
viewport = new Viewport( clientSize, Rules.Map.Offset, Rules.Map.Offset + Rules.Map.Size, renderer );
Sound.Initialize();
BuildingInfluence = new BuildingInfluenceMap(); BuildingInfluence = new BuildingInfluenceMap();
UnitInfluence = new UnitInfluenceMap(); UnitInfluence = new UnitInfluenceMap();
skipMakeAnims = true;
foreach (var treeReference in Rules.Map.Trees) foreach (var treeReference in Rules.Map.Trees)
world.Add(new Actor(Rules.UnitInfo[treeReference.Image], world.Add(new Actor(Rules.UnitInfo[treeReference.Image],
new int2(treeReference.Location), new int2(treeReference.Location),
null)); null));
LoadMapActors(Rules.AllRules); LoadMapActors(Rules.AllRules);
skipMakeAnims = false;
PathFinder = new PathFinder(); PathFinder = new PathFinder();
chrome = new Chrome(renderer);
oreFrequency = (int)(Rules.General.GrowthRate * 60 * 1000);
oreTicks = oreFrequency;
}
public static void Initialize(string mapName, Renderer renderer, int2 clientSize,
int localPlayer, bool useAftermath, Controller controller)
{
localPlayerIndex = localPlayer;
usingAftermath = useAftermath;
Game.renderer = renderer;
Game.clientSize = clientSize;
// todo
Sound.Initialize();
PerfHistory.items["render"].hasNormalTick = false;
PerfHistory.items["batches"].hasNormalTick = false;
Game.controller = controller;
ChangeMap(mapName);
if (Replay != "") if (Replay != "")
orderManager = new OrderManager(new IOrderSource[] { new ReplayOrderSource(Replay) }); orderManager = new OrderManager(new IOrderSource[] { new ReplayOrderSource(Replay) });
else else
@@ -96,15 +119,6 @@ namespace OpenRa.Game
: new IOrderSource[] { new LocalOrderSource(), new NetworkOrderSource(new TcpClient(NetworkHost, NetworkPort)) }; : new IOrderSource[] { new LocalOrderSource(), new NetworkOrderSource(new TcpClient(NetworkHost, NetworkPort)) };
orderManager = new OrderManager(orderSources, "replay.rep"); orderManager = new OrderManager(orderSources, "replay.rep");
} }
skipMakeAnims = false;
PerfHistory.items["render"].hasNormalTick = false;
PerfHistory.items["batches"].hasNormalTick = false;
chrome = new Chrome(renderer);
oreFrequency = (int)(Rules.General.GrowthRate * 60 * 1000);
oreTicks = oreFrequency;
} }
static void LoadMapActors(IniFile mapfile) static void LoadMapActors(IniFile mapfile)

View File

@@ -8,13 +8,14 @@ namespace OpenRa.Game.Graphics
{ {
static class SequenceProvider static class SequenceProvider
{ {
static Dictionary<string, Dictionary<string, Sequence>> units = static Dictionary<string, Dictionary<string, Sequence>> units;
new Dictionary<string, Dictionary<string, Sequence>>(); static Dictionary<string, CursorSequence> cursors;
static Dictionary<string, CursorSequence> cursors = new Dictionary<string, CursorSequence>();
public static void Initialize( bool useAftermath ) public static void Initialize( bool useAftermath )
{ {
units = new Dictionary<string, Dictionary<string, Sequence>>();
cursors = new Dictionary<string, CursorSequence>();
LoadSequenceSource("sequences.xml"); LoadSequenceSource("sequences.xml");
if (useAftermath) if (useAftermath)
LoadSequenceSource("sequences-aftermath.xml"); LoadSequenceSource("sequences-aftermath.xml");

View File

@@ -7,6 +7,9 @@ namespace OpenRa.Game.Graphics
public static void Initialize(Renderer r) public static void Initialize(Renderer r)
{ {
renderer = r; renderer = r;
current = null;
rowHeight = 0;
channel = null;
} }
public static Sprite Add(byte[] src, Size size) public static Sprite Add(byte[] src, Size size)

View File

@@ -16,7 +16,7 @@ namespace OpenRa.Game.Graphics
public readonly SpriteRenderer spriteRenderer; public readonly SpriteRenderer spriteRenderer;
public readonly LineRenderer lineRenderer; public readonly LineRenderer lineRenderer;
public readonly UiOverlay uiOverlay; public readonly UiOverlay uiOverlay;
readonly Renderer renderer; public readonly Renderer renderer;
public static bool ShowUnitPaths = false; public static bool ShowUnitPaths = false;

View File

@@ -56,7 +56,6 @@ namespace OpenRa.Game
bool windowed = !settings.GetValue( "fullscreen", false ); bool windowed = !settings.GetValue( "fullscreen", false );
renderer = new Renderer( this, GetResolution( settings ), windowed ); renderer = new Renderer( this, GetResolution( settings ), windowed );
SheetBuilder.Initialize( renderer );
var controller = new Controller( () => (Modifiers)(int)ModifierKeys ); /* a bit of insane input routing */ var controller = new Controller( () => (Modifiers)(int)ModifierKeys ); /* a bit of insane input routing */

View File

@@ -105,6 +105,12 @@ namespace OpenRa.Game
Game.orderManager.StartGame(); Game.orderManager.StartGame();
break; break;
} }
case "ChangeMap":
{
Game.chat.AddLine(Color.White, "Server", "Changing map to {0}".F(order.TargetString));
Game.ChangeMap(order.TargetString);
break;
}
default: default:
throw new NotImplementedException(); throw new NotImplementedException();