spawn points! bugs: minimap lags by one, 1-8 always valid

This commit is contained in:
Alli
2010-02-06 20:07:26 +13:00
parent c0d51601a1
commit df00694c83
6 changed files with 96 additions and 20 deletions

View File

@@ -251,6 +251,32 @@ namespace OpenRA.Server
GetClient(conn).Race = 1 + race; GetClient(conn).Race = 1 + race;
SyncLobbyInfo(); SyncLobbyInfo();
return true; return true;
}},
{ "spawn",
s =>
{
if (GameStarted)
{
SendChatTo( conn, "You can't change your spawn point after the game has started" );
return true;
}
int spawnPoint;
if (!int.TryParse(s, out spawnPoint) || spawnPoint < 0 || spawnPoint > 8) //TODO: SET properly!
{
Console.WriteLine("Invalid spawn point: {0}", s);
return false;
}
if (lobbyInfo.Clients.Where( c => c != GetClient(conn) ).Any( c => c.SpawnPoint == spawnPoint )) //TODO: except 0
{
SendChatTo( conn, "You can't be at the same spawn point as another player" );
return true;
}
GetClient(conn).SpawnPoint = spawnPoint;
SyncLobbyInfo();
return true;
}}, }},
{ "pal", { "pal",
s => s =>

View File

@@ -22,7 +22,7 @@ namespace OpenRa.FileFormats
public int Index; public int Index;
public int PaletteIndex; public int PaletteIndex;
public int Race; public int Race;
// public int SpawnPoint; public int SpawnPoint;
public string Name; public string Name;
public ClientState State; public ClientState State;
} }

View File

@@ -346,6 +346,10 @@ namespace OpenRa
} }
bool PaletteAvailable(int index) { return Game.LobbyInfo.Clients.All(c => c.PaletteIndex != index); } bool PaletteAvailable(int index) { return Game.LobbyInfo.Clients.All(c => c.PaletteIndex != index); }
bool SpawnPointAvailable(int index) { return Game.LobbyInfo.Clients.All(c => c.SpawnPoint != index); }
void CyclePalette(bool left) void CyclePalette(bool left)
{ {
var d = left ? +1 : Player.PlayerColors.Count() - 1; var d = left ? +1 : Player.PlayerColors.Count() - 1;
@@ -354,9 +358,11 @@ namespace OpenRa
while (!PaletteAvailable(newIndex) && newIndex != (int)Game.world.LocalPlayer.PaletteIndex) while (!PaletteAvailable(newIndex) && newIndex != (int)Game.world.LocalPlayer.PaletteIndex)
newIndex = (newIndex + d) % Player.PlayerColors.Count(); newIndex = (newIndex + d) % Player.PlayerColors.Count();
Game.world.Minimap.InvalidateSpawnPoints();
Game.IssueOrder( Game.IssueOrder(
Order.Chat("/pal " + newIndex)); Order.Chat("/pal " + newIndex));
} }
void CycleRace(bool left) void CycleRace(bool left)
@@ -371,6 +377,21 @@ namespace OpenRa
new Order("ToggleReady", Game.world.LocalPlayer.PlayerActor, "") { IsImmediate = true }); new Order("ToggleReady", Game.world.LocalPlayer.PlayerActor, "") { IsImmediate = true });
} }
void CycleSpawnPoint(bool left)
{
var d = left ? +1 : Game.world.Map.SpawnPoints.Count() - 1;
var newIndex = (Game.world.LocalPlayer.SpawnPointIndex + d) % Game.world.Map.SpawnPoints.Count();
while (!SpawnPointAvailable(newIndex) && newIndex != (int)Game.world.LocalPlayer.SpawnPointIndex)
newIndex = (newIndex + d) % Game.world.Map.SpawnPoints.Count();
Game.world.Minimap.InvalidateSpawnPoints();
Game.IssueOrder(
Order.Chat("/spawn " + newIndex));
}
public void DrawLobby( World world ) public void DrawLobby( World world )
{ {
buttons.Clear(); buttons.Clear();
@@ -408,32 +429,37 @@ namespace OpenRa
} }
renderer.DrawText2("Name", new int2(r.Left + 40, r.Top + 50), Color.White); renderer.DrawText2("Name", new int2(r.Left + 40, r.Top + 50), Color.White);
renderer.DrawText2("Color", new int2(r.Left + 230, r.Top + 50), Color.White); renderer.DrawText2("Color", new int2(r.Left + 140, r.Top + 50), Color.White);
renderer.DrawText2("Faction", new int2(r.Left + 300, r.Top + 50), Color.White); renderer.DrawText2("Faction", new int2(r.Left + 220, r.Top + 50), Color.White);
renderer.DrawText2("Status", new int2(r.Left + 370, r.Top + 50), Color.White); renderer.DrawText2("Status", new int2(r.Left + 290, r.Top + 50), Color.White);
renderer.DrawText2("Spawn", new int2(r.Left + 390, r.Top + 50), Color.White);
var y = r.Top + 80; var y = r.Top + 80;
foreach (var client in Game.LobbyInfo.Clients) foreach (var client in Game.LobbyInfo.Clients)
{ {
var isLocalPlayer = client.Index == Game.orderManager.Connection.LocalClientId; var isLocalPlayer = client.Index == Game.orderManager.Connection.LocalClientId;
var paletteRect = new Rectangle(r.Left + 220, y - 2, 65, 22); var paletteRect = new Rectangle(r.Left + 130, y - 2, 65, 22);
if (isLocalPlayer) if (isLocalPlayer)
{ {
// todo: name editing // todo: name editing
var nameRect = new Rectangle(r.Left + 30, y - 2, 185, 22); var nameRect = new Rectangle(r.Left + 30, y - 2, 95, 22);
DrawDialogBackground(nameRect, "panel"); DrawDialogBackground(nameRect, "panel");
DrawDialogBackground(paletteRect, "panel"); DrawDialogBackground(paletteRect, "panel");
AddButton(paletteRect, CyclePalette); AddButton(paletteRect, CyclePalette);
var raceRect = new Rectangle(r.Left + 290, y - 2, 65, 22); var raceRect = new Rectangle(r.Left + 210, y - 2, 65, 22);
DrawDialogBackground(raceRect, "panel"); DrawDialogBackground(raceRect, "panel");
AddButton(raceRect, CycleRace); AddButton(raceRect, CycleRace);
var readyRect = new Rectangle(r.Left + 360, y - 2, 95, 22); var readyRect = new Rectangle(r.Left + 280, y - 2, 95, 22);
DrawDialogBackground(readyRect, "panel"); DrawDialogBackground(readyRect, "panel");
AddButton(readyRect, CycleReady); AddButton(readyRect, CycleReady);
var spawnPointRect = new Rectangle(r.Left + 380, y - 2, 70, 22);
DrawDialogBackground(spawnPointRect, "panel");
AddButton(spawnPointRect, CycleSpawnPoint);
} }
shpRenderer.Flush(); shpRenderer.Flush();
@@ -445,8 +471,9 @@ namespace OpenRa
paletteRect.Bottom+Game.viewport.Location.Y - 5), paletteRect.Bottom+Game.viewport.Location.Y - 5),
Player.PlayerColors[client.PaletteIndex].c); Player.PlayerColors[client.PaletteIndex].c);
lineRenderer.Flush(); lineRenderer.Flush();
renderer.DrawText(((Race)client.Race).ToString(), new int2(r.Left + 300, y), Color.White); renderer.DrawText(((Race)client.Race).ToString(), new int2(r.Left + 220, y), Color.White);
renderer.DrawText(client.State.ToString(), new int2(r.Left + 370, y), Color.White); renderer.DrawText(client.State.ToString(), new int2(r.Left + 290, y), Color.White);
renderer.DrawText((client.SpawnPoint == 0)? "-" : client.SpawnPoint.ToString(), new int2(r.Left + 410, y), Color.White);
y += 30; y += 30;
} }

View File

@@ -239,12 +239,16 @@ namespace OpenRa
foreach (var client in LobbyInfo.Clients) foreach (var client in LobbyInfo.Clients)
{ {
// todo: allow players to choose their own spawn points. int2 sp;
// only select a point for them if they didn't. if (client.SpawnPoint == 0)
sp = ChooseSpawnPoint(available, taken);
else
{
sp = world.Map.SpawnPoints.ElementAt(client.SpawnPoint - 1);
taken.Add(sp);
available.Remove(sp);
}
// todo: spawn more than one unit, in most cases! // todo: spawn more than one unit, in most cases!
var sp = ChooseSpawnPoint(available, taken);
world.CreateActor("mcv", sp, world.players[client.Index]); world.CreateActor("mcv", sp, world.players[client.Index]);
} }

View File

@@ -5,6 +5,7 @@ using OpenRa.Traits;
using OpenRa.FileFormats; using OpenRa.FileFormats;
using System.Drawing.Imaging; using System.Drawing.Imaging;
using IjwFramework.Collections; using IjwFramework.Collections;
using System.Collections.Generic;
namespace OpenRa.Graphics namespace OpenRa.Graphics
{ {
@@ -62,6 +63,7 @@ namespace OpenRa.Graphics
static Color shroudColor; static Color shroudColor;
public void InvalidateOre() { oreLayer = null; } public void InvalidateOre() { oreLayer = null; }
public void InvalidateSpawnPoints() { spawnPointsLayer = null; }
public static Bitmap RenderTerrainBitmap(Map map, TileSet tileset) public static Bitmap RenderTerrainBitmap(Map map, TileSet tileset)
{ {
@@ -78,8 +80,8 @@ namespace OpenRa.Graphics
public static Bitmap RenderTerrainBitmapWithSpawnPoints(Map map, TileSet tileset) public static Bitmap RenderTerrainBitmapWithSpawnPoints(Map map, TileSet tileset)
{ {
var terrain = RenderTerrainBitmap(map, tileset); var terrain = RenderTerrainBitmap(map, tileset);
foreach (var point in map.SpawnPoints) foreach (var sp in map.SpawnPoints)
terrain.SetPixel(point.X, point.Y, Color.White); terrain.SetPixel(sp.X, sp.Y, Color.White);
return terrain; return terrain;
} }
@@ -105,9 +107,19 @@ namespace OpenRa.Graphics
if (spawnPointsLayer == null) if (spawnPointsLayer == null)
{ {
spawnPointsLayer = new Bitmap(terrain); spawnPointsLayer = new Bitmap(terrain);
foreach (var point in world.Map.SpawnPoints){ var available = Game.world.Map.SpawnPoints.ToList();
spawnPointsLayer.SetPixel(point.X, point.Y, Color.White);
foreach (var player in Game.world.players.Values)
{
if (player.SpawnPointIndex != 0)
{
int2 sp = Game.world.Map.SpawnPoints.ElementAt(player.SpawnPointIndex - 1);
spawnPointsLayer.SetPixel(sp.X, sp.Y, player.Color);
available.Remove(sp);
}
} }
foreach (var sp in available)
spawnPointsLayer.SetPixel(sp.X, sp.Y, Color.White);
} }
mapSpawnPointSheet.Texture.SetData(spawnPointsLayer); mapSpawnPointSheet.Texture.SetData(spawnPointsLayer);

View File

@@ -26,6 +26,7 @@ namespace OpenRa
public int DisplayCash = 0; public int DisplayCash = 0;
public int PowerProvided = 0; public int PowerProvided = 0;
public int PowerDrained = 0; public int PowerDrained = 0;
public int SpawnPointIndex = 0;
public World World { get { return PlayerActor.World; } } public World World { get { return PlayerActor.World; } }
@@ -189,6 +190,12 @@ namespace OpenRa
PaletteIndex = client.PaletteIndex; PaletteIndex = client.PaletteIndex;
Game.chat.AddLine(this, "has changed color to {0}".F(PlayerColors[client.PaletteIndex].b)); Game.chat.AddLine(this, "has changed color to {0}".F(PlayerColors[client.PaletteIndex].b));
} }
if (SpawnPointIndex != client.SpawnPoint)
{
SpawnPointIndex = client.SpawnPoint;
Game.chat.AddLine(this, "has changed spawn point to {0}".F(client.SpawnPoint));
}
} }
} }
} }