Merge commit 'bob/worlds'
This commit is contained in:
@@ -14,7 +14,10 @@ namespace OpenRa
|
|||||||
[Sync]
|
[Sync]
|
||||||
public readonly TypeDictionary traits = new TypeDictionary();
|
public readonly TypeDictionary traits = new TypeDictionary();
|
||||||
public readonly ActorInfo Info;
|
public readonly ActorInfo Info;
|
||||||
|
|
||||||
|
public readonly World World;
|
||||||
public readonly uint ActorID;
|
public readonly uint ActorID;
|
||||||
|
|
||||||
[Sync]
|
[Sync]
|
||||||
public int2 Location;
|
public int2 Location;
|
||||||
[Sync]
|
[Sync]
|
||||||
@@ -25,6 +28,7 @@ namespace OpenRa
|
|||||||
|
|
||||||
public Actor( World world, string name, int2 location, Player owner )
|
public Actor( World world, string name, int2 location, Player owner )
|
||||||
{
|
{
|
||||||
|
World = world;
|
||||||
ActorID = world.NextAID();
|
ActorID = world.NextAID();
|
||||||
Location = location;
|
Location = location;
|
||||||
CenterLocation = Traits.Util.CenterOfCell(Location);
|
CenterLocation = Traits.Util.CenterOfCell(Location);
|
||||||
@@ -82,14 +86,14 @@ namespace OpenRa
|
|||||||
|
|
||||||
public Order Order( int2 xy, MouseInput mi )
|
public Order Order( int2 xy, MouseInput mi )
|
||||||
{
|
{
|
||||||
if (Owner != Game.world.LocalPlayer)
|
if (Owner != World.LocalPlayer)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (!Game.world.Map.IsInMap(xy.X, xy.Y))
|
if (!World.Map.IsInMap(xy.X, xy.Y))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
var loc = mi.Location + Game.viewport.Location;
|
var loc = mi.Location + Game.viewport.Location;
|
||||||
var underCursor = Game.world.FindUnits(loc, loc).FirstOrDefault();
|
var underCursor = World.FindUnits(loc, loc).FirstOrDefault();
|
||||||
|
|
||||||
if (underCursor != null && !underCursor.traits.Contains<Selectable>())
|
if (underCursor != null && !underCursor.traits.Contains<Selectable>())
|
||||||
underCursor = null;
|
underCursor = null;
|
||||||
@@ -147,7 +151,7 @@ namespace OpenRa
|
|||||||
attacker.Owner.Kills++;
|
attacker.Owner.Kills++;
|
||||||
|
|
||||||
if (RemoveOnDeath)
|
if (RemoveOnDeath)
|
||||||
Game.world.AddFrameEndTask(w => w.Remove(this));
|
World.AddFrameEndTask(w => w.Remove(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
var maxHP = this.GetMaxHP();
|
var maxHP = this.GetMaxHP();
|
||||||
|
|||||||
@@ -144,14 +144,14 @@ namespace OpenRa
|
|||||||
TickRadarAnimation();
|
TickRadarAnimation();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Draw()
|
public void Draw( World world )
|
||||||
{
|
{
|
||||||
DrawDownloadBar();
|
DrawDownloadBar();
|
||||||
|
|
||||||
chromeCollection = (Game.world.LocalPlayer.Race == Race.Allies) ? "chrome-allies" : "chrome-soviet";
|
chromeCollection = (world.LocalPlayer.Race == Race.Allies) ? "chrome-allies" : "chrome-soviet";
|
||||||
radarCollection = (Game.world.LocalPlayer.Race == Race.Allies) ? "radar-allies" : "radar-soviet";
|
radarCollection = (world.LocalPlayer.Race == Race.Allies) ? "radar-allies" : "radar-soviet";
|
||||||
paletteCollection = (Game.world.LocalPlayer.Race == Race.Allies) ? "palette-allies" : "palette-soviet";
|
paletteCollection = (world.LocalPlayer.Race == Race.Allies) ? "palette-allies" : "palette-soviet";
|
||||||
digitCollection = (Game.world.LocalPlayer.Race == Race.Allies) ? "digits-allies" : "digits-soviet";
|
digitCollection = (world.LocalPlayer.Race == Race.Allies) ? "digits-allies" : "digits-soviet";
|
||||||
|
|
||||||
buttons.Clear();
|
buttons.Clear();
|
||||||
|
|
||||||
@@ -164,18 +164,18 @@ namespace OpenRa
|
|||||||
new int2(140, 15), Color.White);
|
new int2(140, 15), Color.White);
|
||||||
|
|
||||||
if (Game.Settings.PerfGraph)
|
if (Game.Settings.PerfGraph)
|
||||||
PerfHistory.Render(renderer, Game.world.WorldRenderer.lineRenderer);
|
PerfHistory.Render(renderer, world.WorldRenderer.lineRenderer);
|
||||||
|
|
||||||
DrawRadar();
|
DrawRadar( world );
|
||||||
DrawPower();
|
DrawPower( world );
|
||||||
rgbaRenderer.DrawSprite(ChromeProvider.GetImage(renderer, chromeCollection, "moneybin"), new float2(Game.viewport.Width - 320, 0), PaletteType.Chrome);
|
rgbaRenderer.DrawSprite(ChromeProvider.GetImage(renderer, chromeCollection, "moneybin"), new float2(Game.viewport.Width - 320, 0), PaletteType.Chrome);
|
||||||
DrawMoney();
|
DrawMoney( world );
|
||||||
rgbaRenderer.Flush();
|
rgbaRenderer.Flush();
|
||||||
DrawButtons();
|
DrawButtons( world );
|
||||||
|
|
||||||
int paletteHeight = DrawBuildPalette(currentTab);
|
int paletteHeight = DrawBuildPalette(world, currentTab);
|
||||||
DrawSupportPowers();
|
DrawSupportPowers( world );
|
||||||
DrawBuildTabs(paletteHeight);
|
DrawBuildTabs(world, paletteHeight);
|
||||||
DrawChat();
|
DrawChat();
|
||||||
DrawOptionsMenu();
|
DrawOptionsMenu();
|
||||||
}
|
}
|
||||||
@@ -222,7 +222,7 @@ namespace OpenRa
|
|||||||
AddButton(r, _ => { });
|
AddButton(r, _ => { });
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawLobby()
|
public void DrawLobby( World world )
|
||||||
{
|
{
|
||||||
DrawDownloadBar();
|
DrawDownloadBar();
|
||||||
|
|
||||||
@@ -238,8 +238,8 @@ namespace OpenRa
|
|||||||
DrawDialogBackground(new Rectangle(r.Right - 330, r.Top + 40, 310, r.Bottom - 273 - r.Top - 40),
|
DrawDialogBackground(new Rectangle(r.Right - 330, r.Top + 40, 310, r.Bottom - 273 - r.Top - 40),
|
||||||
panelSprites, false);
|
panelSprites, false);
|
||||||
|
|
||||||
Game.world.Minimap.Update();
|
world.Minimap.Update();
|
||||||
Game.world.Minimap.Draw(new Rectangle(r.Right - 325, r.Top + 45, 300, 277), true);
|
world.Minimap.Draw(new Rectangle(r.Right - 325, r.Top + 45, 300, 277), true);
|
||||||
|
|
||||||
renderer.DrawText2("Name", new int2(r.Left + 30, r.Top + 50), Color.White);
|
renderer.DrawText2("Name", new int2(r.Left + 30, 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 + 230, r.Top + 50), Color.White);
|
||||||
@@ -303,9 +303,9 @@ namespace OpenRa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawRadar()
|
void DrawRadar( World world )
|
||||||
{
|
{
|
||||||
var hasNewRadar = Game.world.Actors.Any(a => a.Owner == Game.world.LocalPlayer
|
var hasNewRadar = world.Actors.Any(a => a.Owner == world.LocalPlayer
|
||||||
&& a.traits.Contains<ProvidesRadar>()
|
&& a.traits.Contains<ProvidesRadar>()
|
||||||
&& a.traits.Get<ProvidesRadar>().IsActive(a));
|
&& a.traits.Get<ProvidesRadar>().IsActive(a));
|
||||||
|
|
||||||
@@ -328,36 +328,36 @@ namespace OpenRa
|
|||||||
if (radarAnimationFrame >= radarSlideAnimationLength)
|
if (radarAnimationFrame >= radarSlideAnimationLength)
|
||||||
{
|
{
|
||||||
RectangleF mapRect = new RectangleF(radarOrigin.X + 9, radarOrigin.Y+(192-radarMinimapHeight)/2, 192, radarMinimapHeight);
|
RectangleF mapRect = new RectangleF(radarOrigin.X + 9, radarOrigin.Y+(192-radarMinimapHeight)/2, 192, radarMinimapHeight);
|
||||||
Game.world.Minimap.Draw(mapRect, false);
|
world.Minimap.Draw(mapRect, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddButton(RectangleF r, Action<bool> b) { buttons.Add(Pair.New(r, b)); }
|
void AddButton(RectangleF r, Action<bool> b) { buttons.Add(Pair.New(r, b)); }
|
||||||
|
|
||||||
void DrawBuildTabs(int paletteHeight)
|
void DrawBuildTabs( World world, int paletteHeight)
|
||||||
{
|
{
|
||||||
const int tabWidth = 24;
|
const int tabWidth = 24;
|
||||||
const int tabHeight = 40;
|
const int tabHeight = 40;
|
||||||
var x = paletteOrigin.X - tabWidth;
|
var x = paletteOrigin.X - tabWidth;
|
||||||
var y = paletteOrigin.Y + 9;
|
var y = paletteOrigin.Y + 9;
|
||||||
|
|
||||||
if (currentTab == null || !Rules.TechTree.BuildableItems(Game.world.LocalPlayer, currentTab).Any())
|
if (currentTab == null || !Rules.TechTree.BuildableItems(world.LocalPlayer, currentTab).Any())
|
||||||
ChooseAvailableTab();
|
ChooseAvailableTab( world );
|
||||||
|
|
||||||
var queue = Game.world.LocalPlayer.PlayerActor.traits.Get<Traits.ProductionQueue>();
|
var queue = world.LocalPlayer.PlayerActor.traits.Get<Traits.ProductionQueue>();
|
||||||
|
|
||||||
foreach (var q in tabImageNames)
|
foreach (var q in tabImageNames)
|
||||||
{
|
{
|
||||||
var groupName = q.Key;
|
var groupName = q.Key;
|
||||||
if (!Rules.TechTree.BuildableItems(Game.world.LocalPlayer, groupName).Any())
|
if (!Rules.TechTree.BuildableItems(world.LocalPlayer, groupName).Any())
|
||||||
{
|
{
|
||||||
CheckDeadTab(groupName);
|
CheckDeadTab( world, groupName );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
string[] tabKeys = { "normal", "ready", "selected" };
|
string[] tabKeys = { "normal", "ready", "selected" };
|
||||||
var producing = queue.CurrentItem(groupName);
|
var producing = queue.CurrentItem(groupName);
|
||||||
var index = q.Key == currentTab ? 2 : (producing != null && producing.Done) ? 1 : 0;
|
var index = q.Key == currentTab ? 2 : (producing != null && producing.Done) ? 1 : 0;
|
||||||
var race = (Game.world.LocalPlayer.Race == Race.Allies) ? "allies" : "soviet";
|
var race = (world.LocalPlayer.Race == Race.Allies) ? "allies" : "soviet";
|
||||||
rgbaRenderer.DrawSprite(ChromeProvider.GetImage(renderer,"tabs-"+tabKeys[index], race+"-"+q.Key), new float2(x, y), PaletteType.Chrome);
|
rgbaRenderer.DrawSprite(ChromeProvider.GetImage(renderer,"tabs-"+tabKeys[index], race+"-"+q.Key), new float2(x, y), PaletteType.Chrome);
|
||||||
|
|
||||||
buttons.Add(Pair.New(new RectangleF(x, y, tabWidth, tabHeight),
|
buttons.Add(Pair.New(new RectangleF(x, y, tabWidth, tabHeight),
|
||||||
@@ -378,22 +378,22 @@ namespace OpenRa
|
|||||||
paletteAnimating = true;
|
paletteAnimating = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckDeadTab( string groupName )
|
void CheckDeadTab( World world, string groupName )
|
||||||
{
|
{
|
||||||
var queue = Game.world.LocalPlayer.PlayerActor.traits.Get<Traits.ProductionQueue>();
|
var queue = world.LocalPlayer.PlayerActor.traits.Get<Traits.ProductionQueue>();
|
||||||
foreach( var item in queue.AllItems( groupName ) )
|
foreach( var item in queue.AllItems( groupName ) )
|
||||||
Game.controller.AddOrder(Order.CancelProduction(Game.world.LocalPlayer, item.Item));
|
Game.controller.AddOrder(Order.CancelProduction(world.LocalPlayer, item.Item));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChooseAvailableTab()
|
void ChooseAvailableTab( World world )
|
||||||
{
|
{
|
||||||
currentTab = tabImageNames.Select(q => q.Key).FirstOrDefault(
|
currentTab = tabImageNames.Select(q => q.Key).FirstOrDefault(
|
||||||
t => Rules.TechTree.BuildableItems(Game.world.LocalPlayer, t).Any());
|
t => Rules.TechTree.BuildableItems(world.LocalPlayer, t).Any());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawMoney()
|
void DrawMoney( World world )
|
||||||
{
|
{
|
||||||
var moneyDigits = Game.world.LocalPlayer.DisplayCash.ToString();
|
var moneyDigits = world.LocalPlayer.DisplayCash.ToString();
|
||||||
var x = Game.viewport.Width - 65;
|
var x = Game.viewport.Width - 65;
|
||||||
foreach (var d in moneyDigits.Reverse())
|
foreach (var d in moneyDigits.Reverse())
|
||||||
{
|
{
|
||||||
@@ -405,10 +405,10 @@ namespace OpenRa
|
|||||||
float? lastPowerProvidedPos;
|
float? lastPowerProvidedPos;
|
||||||
float? lastPowerDrainedPos;
|
float? lastPowerDrainedPos;
|
||||||
|
|
||||||
void DrawPower()
|
void DrawPower( World world )
|
||||||
{
|
{
|
||||||
// Nothing to draw
|
// Nothing to draw
|
||||||
if (Game.world.LocalPlayer.PowerProvided == 0 && Game.world.LocalPlayer.PowerDrained == 0)
|
if (world.LocalPlayer.PowerProvided == 0 && world.LocalPlayer.PowerDrained == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Draw bar horizontally
|
// Draw bar horizontally
|
||||||
@@ -416,18 +416,18 @@ namespace OpenRa
|
|||||||
var barEnd = barStart + new float2(powerSize.Width, 0);
|
var barEnd = barStart + new float2(powerSize.Width, 0);
|
||||||
|
|
||||||
float powerScaleBy = 100;
|
float powerScaleBy = 100;
|
||||||
var maxPower = Math.Max(Game.world.LocalPlayer.PowerProvided, Game.world.LocalPlayer.PowerDrained);
|
var maxPower = Math.Max(world.LocalPlayer.PowerProvided, world.LocalPlayer.PowerDrained);
|
||||||
while (maxPower >= powerScaleBy) powerScaleBy *= 2;
|
while (maxPower >= powerScaleBy) powerScaleBy *= 2;
|
||||||
|
|
||||||
// Current power supply
|
// Current power supply
|
||||||
var powerLevelTemp = barStart.X + (barEnd.X - barStart.X) * (Game.world.LocalPlayer.PowerProvided / powerScaleBy);
|
var powerLevelTemp = barStart.X + (barEnd.X - barStart.X) * (world.LocalPlayer.PowerProvided / powerScaleBy);
|
||||||
lastPowerProvidedPos = float2.Lerp(lastPowerProvidedPos.GetValueOrDefault(powerLevelTemp), powerLevelTemp, .3f);
|
lastPowerProvidedPos = float2.Lerp(lastPowerProvidedPos.GetValueOrDefault(powerLevelTemp), powerLevelTemp, .3f);
|
||||||
float2 powerLevel = new float2(lastPowerProvidedPos.Value, barStart.Y);
|
float2 powerLevel = new float2(lastPowerProvidedPos.Value, barStart.Y);
|
||||||
|
|
||||||
var color = Color.LimeGreen;
|
var color = Color.LimeGreen;
|
||||||
if (Game.world.LocalPlayer.GetPowerState() == PowerState.Low)
|
if (world.LocalPlayer.GetPowerState() == PowerState.Low)
|
||||||
color = Color.Orange;
|
color = Color.Orange;
|
||||||
if (Game.world.LocalPlayer.GetPowerState() == PowerState.Critical)
|
if (world.LocalPlayer.GetPowerState() == PowerState.Critical)
|
||||||
color = Color.Red;
|
color = Color.Red;
|
||||||
|
|
||||||
var colorDark = Graphics.Util.Lerp(0.25f, color, Color.Black);
|
var colorDark = Graphics.Util.Lerp(0.25f, color, Color.Black);
|
||||||
@@ -448,7 +448,7 @@ namespace OpenRa
|
|||||||
|
|
||||||
// Power usage indicator
|
// Power usage indicator
|
||||||
var indicator = ChromeProvider.GetImage(renderer, radarCollection, "power-indicator");
|
var indicator = ChromeProvider.GetImage(renderer, radarCollection, "power-indicator");
|
||||||
var powerDrainedTemp = barStart.X + (barEnd.X - barStart.X) * (Game.world.LocalPlayer.PowerDrained / powerScaleBy);
|
var powerDrainedTemp = barStart.X + (barEnd.X - barStart.X) * (world.LocalPlayer.PowerDrained / powerScaleBy);
|
||||||
lastPowerDrainedPos = float2.Lerp(lastPowerDrainedPos.GetValueOrDefault(powerDrainedTemp), powerDrainedTemp, .3f);
|
lastPowerDrainedPos = float2.Lerp(lastPowerDrainedPos.GetValueOrDefault(powerDrainedTemp), powerDrainedTemp, .3f);
|
||||||
float2 powerDrainLevel = new float2(lastPowerDrainedPos.Value-indicator.size.X/2, barStart.Y-1);
|
float2 powerDrainLevel = new float2(lastPowerDrainedPos.Value-indicator.size.X/2, barStart.Y-1);
|
||||||
|
|
||||||
@@ -456,14 +456,14 @@ namespace OpenRa
|
|||||||
rgbaRenderer.Flush();
|
rgbaRenderer.Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawButtons()
|
void DrawButtons( World world )
|
||||||
{
|
{
|
||||||
int2 buttonOrigin = new int2(Game.viewport.Width - 320, 2);
|
int2 buttonOrigin = new int2(Game.viewport.Width - 320, 2);
|
||||||
// Repair
|
// Repair
|
||||||
Rectangle repairRect = new Rectangle(buttonOrigin.X, buttonOrigin.Y, repairButton.Image.bounds.Width, repairButton.Image.bounds.Height);
|
Rectangle repairRect = new Rectangle(buttonOrigin.X, buttonOrigin.Y, repairButton.Image.bounds.Width, repairButton.Image.bounds.Height);
|
||||||
var repairDrawPos = new float2(repairRect.Location);
|
var repairDrawPos = new float2(repairRect.Location);
|
||||||
|
|
||||||
var hasFact = Game.world.Actors.Any(a => a.Owner == Game.world.LocalPlayer && a.traits.Contains<ConstructionYard>());
|
var hasFact = world.Actors.Any(a => a.Owner == world.LocalPlayer && a.traits.Contains<ConstructionYard>());
|
||||||
|
|
||||||
if (Game.Settings.RepairRequiresConyard && !hasFact)
|
if (Game.Settings.RepairRequiresConyard && !hasFact)
|
||||||
repairButton.ReplaceAnim("disabled");
|
repairButton.ReplaceAnim("disabled");
|
||||||
@@ -630,7 +630,7 @@ namespace OpenRa
|
|||||||
|
|
||||||
|
|
||||||
// Return an int telling us the y coordinate at the bottom of the palette
|
// Return an int telling us the y coordinate at the bottom of the palette
|
||||||
int DrawBuildPalette(string queueName)
|
int DrawBuildPalette( World world, string queueName )
|
||||||
{
|
{
|
||||||
// Hack
|
// Hack
|
||||||
int columns = paletteColumns;
|
int columns = paletteColumns;
|
||||||
@@ -641,14 +641,14 @@ namespace OpenRa
|
|||||||
var x = 0;
|
var x = 0;
|
||||||
var y = 0;
|
var y = 0;
|
||||||
|
|
||||||
var buildableItems = Rules.TechTree.BuildableItems(Game.world.LocalPlayer, queueName).ToArray();
|
var buildableItems = Rules.TechTree.BuildableItems(world.LocalPlayer, queueName).ToArray();
|
||||||
|
|
||||||
var allBuildables = Rules.TechTree.AllBuildables(Game.world.LocalPlayer, queueName)
|
var allBuildables = Rules.TechTree.AllBuildables(world.LocalPlayer, queueName)
|
||||||
.Where(a => a.Traits.Contains<BuildableInfo>())
|
.Where(a => a.Traits.Contains<BuildableInfo>())
|
||||||
.Where(a => a.Traits.Get<BuildableInfo>().Owner.Contains(Game.world.LocalPlayer.Race))
|
.Where(a => a.Traits.Get<BuildableInfo>().Owner.Contains(world.LocalPlayer.Race))
|
||||||
.OrderBy(a => a.Traits.Get<BuildableInfo>().TechLevel);
|
.OrderBy(a => a.Traits.Get<BuildableInfo>().TechLevel);
|
||||||
|
|
||||||
var queue = Game.world.LocalPlayer.PlayerActor.traits.Get<Traits.ProductionQueue>();
|
var queue = world.LocalPlayer.PlayerActor.traits.Get<Traits.ProductionQueue>();
|
||||||
|
|
||||||
var overlayBits = new List<Pair<Sprite, float2>>();
|
var overlayBits = new List<Pair<Sprite, float2>>();
|
||||||
|
|
||||||
@@ -722,7 +722,7 @@ namespace OpenRa
|
|||||||
|
|
||||||
var closureItemName = item.Name;
|
var closureItemName = item.Name;
|
||||||
AddButton(rect, buildableItems.Contains(item.Name)
|
AddButton(rect, buildableItems.Contains(item.Name)
|
||||||
? isLmb => HandleBuildPalette(closureItemName, isLmb)
|
? isLmb => HandleBuildPalette(world, closureItemName, isLmb)
|
||||||
: (Action<bool>)(_ => Sound.Play("briefing.aud")));
|
: (Action<bool>)(_ => Sound.Play("briefing.aud")));
|
||||||
|
|
||||||
if (++x == columns) { x = 0; y++; }
|
if (++x == columns) { x = 0; y++; }
|
||||||
@@ -751,21 +751,21 @@ namespace OpenRa
|
|||||||
rgbaRenderer.Flush();
|
rgbaRenderer.Flush();
|
||||||
|
|
||||||
if (tooltipItem != null)
|
if (tooltipItem != null)
|
||||||
DrawProductionTooltip(tooltipItem, new float2(Game.viewport.Width, origin.Y + y * 48 + 9).ToInt2()/*tooltipPos*/);
|
DrawProductionTooltip(world, tooltipItem, new float2(Game.viewport.Width, origin.Y + y * 48 + 9).ToInt2()/*tooltipPos*/);
|
||||||
|
|
||||||
return y*48+9;
|
return y*48+9;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StartProduction( string item )
|
void StartProduction( World world, string item )
|
||||||
{
|
{
|
||||||
var unit = Rules.Info[item];
|
var unit = Rules.Info[item];
|
||||||
Sound.Play(unit.Traits.Contains<BuildingInfo>() ? "abldgin1.aud" : "train1.aud");
|
Sound.Play(unit.Traits.Contains<BuildingInfo>() ? "abldgin1.aud" : "train1.aud");
|
||||||
Game.controller.AddOrder(Order.StartProduction(Game.world.LocalPlayer, item));
|
Game.controller.AddOrder(Order.StartProduction(world.LocalPlayer, item));
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandleBuildPalette(string item, bool isLmb)
|
void HandleBuildPalette( World world, string item, bool isLmb )
|
||||||
{
|
{
|
||||||
var player = Game.world.LocalPlayer;
|
var player = world.LocalPlayer;
|
||||||
var unit = Rules.Info[item];
|
var unit = Rules.Info[item];
|
||||||
var queue = player.PlayerActor.traits.Get<Traits.ProductionQueue>();
|
var queue = player.PlayerActor.traits.Get<Traits.ProductionQueue>();
|
||||||
var producing = queue.AllItems(unit.Category).FirstOrDefault( a => a.Item == item );
|
var producing = queue.AllItems(unit.Category).FirstOrDefault( a => a.Item == item );
|
||||||
@@ -790,7 +790,7 @@ namespace OpenRa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StartProduction(item);
|
StartProduction(world, item);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -812,7 +812,7 @@ namespace OpenRa
|
|||||||
}
|
}
|
||||||
|
|
||||||
int2 lastMousePos;
|
int2 lastMousePos;
|
||||||
public bool HandleInput(MouseInput mi)
|
public bool HandleInput(World world, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Event == MouseInputEvent.Move)
|
if (mi.Event == MouseInputEvent.Move)
|
||||||
lastMousePos = mi.Location;
|
lastMousePos = mi.Location;
|
||||||
@@ -844,7 +844,7 @@ namespace OpenRa
|
|||||||
renderer.DrawText2(text, pos - new int2(renderer.MeasureText2(text).X/2, 0), c);
|
renderer.DrawText2(text, pos - new int2(renderer.MeasureText2(text).X/2, 0), c);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawProductionTooltip(string unit, int2 pos)
|
void DrawProductionTooltip(World world, string unit, int2 pos)
|
||||||
{
|
{
|
||||||
var tooltipSprite = ChromeProvider.GetImage(renderer, chromeCollection, "tooltip-bg");
|
var tooltipSprite = ChromeProvider.GetImage(renderer, chromeCollection, "tooltip-bg");
|
||||||
var p = pos.ToFloat2() - new float2(tooltipSprite.size.X, 0);
|
var p = pos.ToFloat2() - new float2(tooltipSprite.size.X, 0);
|
||||||
@@ -857,18 +857,18 @@ namespace OpenRa
|
|||||||
renderer.DrawText2(buildable.Description, p.ToInt2() + new int2(5,5), Color.White);
|
renderer.DrawText2(buildable.Description, p.ToInt2() + new int2(5,5), Color.White);
|
||||||
|
|
||||||
DrawRightAligned( "${0}".F(buildable.Cost), pos + new int2(-5,5),
|
DrawRightAligned( "${0}".F(buildable.Cost), pos + new int2(-5,5),
|
||||||
Game.world.LocalPlayer.Cash + Game.world.LocalPlayer.Ore >= buildable.Cost ? Color.White : Color.Red);
|
world.LocalPlayer.Cash + world.LocalPlayer.Ore >= buildable.Cost ? Color.White : Color.Red);
|
||||||
|
|
||||||
var bi = info.Traits.GetOrDefault<BuildingInfo>();
|
var bi = info.Traits.GetOrDefault<BuildingInfo>();
|
||||||
if (bi != null)
|
if (bi != null)
|
||||||
DrawRightAligned("ϟ{0}".F(bi.Power), pos + new int2(-5, 20),
|
DrawRightAligned("ϟ{0}".F(bi.Power), pos + new int2(-5, 20),
|
||||||
Game.world.LocalPlayer.PowerProvided - Game.world.LocalPlayer.PowerDrained + bi.Power >= 0
|
world.LocalPlayer.PowerProvided - world.LocalPlayer.PowerDrained + bi.Power >= 0
|
||||||
? Color.White : Color.Red);
|
? Color.White : Color.Red);
|
||||||
|
|
||||||
var buildings = Rules.TechTree.GatherBuildings( Game.world.LocalPlayer );
|
var buildings = Rules.TechTree.GatherBuildings( world.LocalPlayer );
|
||||||
p += new int2(5, 5);
|
p += new int2(5, 5);
|
||||||
p += new int2(0, 15);
|
p += new int2(0, 15);
|
||||||
if (!Rules.TechTree.CanBuild(info, Game.world.LocalPlayer, buildings))
|
if (!Rules.TechTree.CanBuild(info, world.LocalPlayer, buildings))
|
||||||
{
|
{
|
||||||
var prereqs = buildable.Prerequisites
|
var prereqs = buildable.Prerequisites
|
||||||
.Select( a => Description( a ) );
|
.Select( a => Description( a ) );
|
||||||
@@ -891,9 +891,9 @@ namespace OpenRa
|
|||||||
return Rules.Info[ a.ToLowerInvariant() ].Traits.Get<BuildableInfo>().Description;
|
return Rules.Info[ a.ToLowerInvariant() ].Traits.Get<BuildableInfo>().Description;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawSupportPowers()
|
void DrawSupportPowers( World world )
|
||||||
{
|
{
|
||||||
var numPowers = Game.world.LocalPlayer.SupportPowers.Values
|
var numPowers = world.LocalPlayer.SupportPowers.Values
|
||||||
.Where(a => a.IsAvailable).Count();
|
.Where(a => a.IsAvailable).Count();
|
||||||
|
|
||||||
if (numPowers == 0) return;
|
if (numPowers == 0) return;
|
||||||
@@ -910,7 +910,7 @@ namespace OpenRa
|
|||||||
string tooltipItem = null;
|
string tooltipItem = null;
|
||||||
int2 tooltipPos = int2.Zero;
|
int2 tooltipPos = int2.Zero;
|
||||||
|
|
||||||
foreach (var sp in Game.world.LocalPlayer.SupportPowers)
|
foreach (var sp in world.LocalPlayer.SupportPowers)
|
||||||
{
|
{
|
||||||
var image = spsprites[sp.Key];
|
var image = spsprites[sp.Key];
|
||||||
if (sp.Value.IsAvailable)
|
if (sp.Value.IsAvailable)
|
||||||
@@ -949,7 +949,7 @@ namespace OpenRa
|
|||||||
shpRenderer.Flush();
|
shpRenderer.Flush();
|
||||||
|
|
||||||
if (tooltipItem != null)
|
if (tooltipItem != null)
|
||||||
DrawSupportPowerTooltip(tooltipItem, tooltipPos);
|
DrawSupportPowerTooltip(world, tooltipItem, tooltipPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
Action<bool> HandleSupportPower(SupportPower sp)
|
Action<bool> HandleSupportPower(SupportPower sp)
|
||||||
@@ -965,7 +965,7 @@ namespace OpenRa
|
|||||||
return "{0:D2}:{1:D2}".F(minutes, seconds % 60);
|
return "{0:D2}:{1:D2}".F(minutes, seconds % 60);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawSupportPowerTooltip(string sp, int2 pos)
|
void DrawSupportPowerTooltip(World world, string sp, int2 pos)
|
||||||
{
|
{
|
||||||
var tooltipSprite = ChromeProvider.GetImage(renderer, chromeCollection, "tooltip-bg");
|
var tooltipSprite = ChromeProvider.GetImage(renderer, chromeCollection, "tooltip-bg");
|
||||||
rgbaRenderer.DrawSprite(tooltipSprite, pos, PaletteType.Chrome);
|
rgbaRenderer.DrawSprite(tooltipSprite, pos, PaletteType.Chrome);
|
||||||
@@ -977,7 +977,7 @@ namespace OpenRa
|
|||||||
|
|
||||||
renderer.DrawText2(info.Description, pos, Color.White);
|
renderer.DrawText2(info.Description, pos, Color.White);
|
||||||
|
|
||||||
var timer = "Charge Time: {0}".F(FormatTime(Game.world.LocalPlayer.SupportPowers[sp].RemainingTime));
|
var timer = "Charge Time: {0}".F(FormatTime(world.LocalPlayer.SupportPowers[sp].RemainingTime));
|
||||||
DrawRightAligned(timer, pos + new int2((int)tooltipSprite.size.X - 10, 0), Color.White);
|
DrawRightAligned(timer, pos + new int2((int)tooltipSprite.size.X - 10, 0), Color.White);
|
||||||
|
|
||||||
if (info.LongDesc != null)
|
if (info.LongDesc != null)
|
||||||
|
|||||||
@@ -13,25 +13,27 @@ namespace OpenRa
|
|||||||
public static void DoImpact(int2 loc, int2 visualLoc,
|
public static void DoImpact(int2 loc, int2 visualLoc,
|
||||||
WeaponInfo weapon, ProjectileInfo projectile, WarheadInfo warhead, Actor firedBy)
|
WeaponInfo weapon, ProjectileInfo projectile, WarheadInfo warhead, Actor firedBy)
|
||||||
{
|
{
|
||||||
|
var world = firedBy.World;
|
||||||
|
|
||||||
var targetTile = ((1f / Game.CellSize) * loc.ToFloat2()).ToInt2();
|
var targetTile = ((1f / Game.CellSize) * loc.ToFloat2()).ToInt2();
|
||||||
|
|
||||||
var isWater = Game.world.IsWater(targetTile);
|
var isWater = world.IsWater(targetTile);
|
||||||
var hitWater = Game.world.IsCellBuildable(targetTile, UnitMovementType.Float);
|
var hitWater = world.IsCellBuildable(targetTile, UnitMovementType.Float);
|
||||||
|
|
||||||
if (warhead.Explosion != 0)
|
if (warhead.Explosion != 0)
|
||||||
Game.world.AddFrameEndTask(
|
world.AddFrameEndTask(
|
||||||
w => w.Add(new Explosion(visualLoc, warhead.Explosion, hitWater)));
|
w => w.Add(new Explosion(w, visualLoc, warhead.Explosion, hitWater)));
|
||||||
|
|
||||||
var impactSound = warhead.ImpactSound;
|
var impactSound = warhead.ImpactSound;
|
||||||
if (hitWater && warhead.WaterImpactSound != null)
|
if (hitWater && warhead.WaterImpactSound != null)
|
||||||
impactSound = warhead.WaterImpactSound;
|
impactSound = warhead.WaterImpactSound;
|
||||||
if (impactSound != null) Sound.Play(impactSound + ".aud");
|
if (impactSound != null) Sound.Play(impactSound + ".aud");
|
||||||
|
|
||||||
if (!isWater) Smudge.AddSmudge(targetTile, warhead);
|
if (!isWater) world.Map.AddSmudge(targetTile, warhead);
|
||||||
if (warhead.Ore) Game.world.Map.DestroyOre(targetTile.X, targetTile.Y);
|
if (warhead.Ore) world.Map.DestroyOre(targetTile.X, targetTile.Y);
|
||||||
|
|
||||||
var maxSpread = GetMaximumSpread(weapon, warhead);
|
var maxSpread = GetMaximumSpread(weapon, warhead);
|
||||||
var hitActors = Game.world.FindUnitsInCircle(loc, maxSpread);
|
var hitActors = world.FindUnitsInCircle(loc, maxSpread);
|
||||||
|
|
||||||
foreach (var victim in hitActors)
|
foreach (var victim in hitActors)
|
||||||
victim.InflictDamage(firedBy, (int)GetDamageToInflict(victim, loc, weapon, warhead), warhead);
|
victim.InflictDamage(firedBy, (int)GetDamageToInflict(victim, loc, weapon, warhead), warhead);
|
||||||
|
|||||||
@@ -43,15 +43,15 @@ namespace OpenRa
|
|||||||
|
|
||||||
List<Order> recentOrders = new List<Order>();
|
List<Order> recentOrders = new List<Order>();
|
||||||
|
|
||||||
void ApplyOrders(float2 xy, MouseInput mi)
|
void ApplyOrders(World world, float2 xy, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (orderGenerator == null) return;
|
if (orderGenerator == null) return;
|
||||||
|
|
||||||
var orders = orderGenerator.Order(xy.ToInt2(), mi).ToArray();
|
var orders = orderGenerator.Order(world, xy.ToInt2(), mi).ToArray();
|
||||||
recentOrders.AddRange( orders );
|
recentOrders.AddRange( orders );
|
||||||
|
|
||||||
var voicedActor = orders.Select(o => o.Subject)
|
var voicedActor = orders.Select(o => o.Subject)
|
||||||
.FirstOrDefault(a => a.Owner == Game.world.LocalPlayer && a.traits.Contains<Unit>());
|
.FirstOrDefault(a => a.Owner == world.LocalPlayer && a.traits.Contains<Unit>());
|
||||||
|
|
||||||
var isMove = orders.Any(o => o.OrderString == "Move");
|
var isMove = orders.Any(o => o.OrderString == "Move");
|
||||||
var isAttack = orders.Any( o => o.OrderString == "Attack" );
|
var isAttack = orders.Any( o => o.OrderString == "Attack" );
|
||||||
@@ -61,7 +61,7 @@ namespace OpenRa
|
|||||||
Sound.PlayVoice(isAttack ? "Attack" : "Move", voicedActor);
|
Sound.PlayVoice(isAttack ? "Attack" : "Move", voicedActor);
|
||||||
|
|
||||||
if (isMove)
|
if (isMove)
|
||||||
Game.world.Add(new Effects.MoveFlash(Game.CellSize * xy));
|
world.Add(new Effects.MoveFlash(world, Game.CellSize * xy));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ namespace OpenRa
|
|||||||
}
|
}
|
||||||
|
|
||||||
float2 dragStart, dragEnd;
|
float2 dragStart, dragEnd;
|
||||||
public bool HandleInput(MouseInput mi)
|
public bool HandleInput(World world, MouseInput mi)
|
||||||
{
|
{
|
||||||
var xy = Game.viewport.ViewToWorld(mi);
|
var xy = Game.viewport.ViewToWorld(mi);
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ namespace OpenRa
|
|||||||
{
|
{
|
||||||
if (!(orderGenerator is PlaceBuildingOrderGenerator))
|
if (!(orderGenerator is PlaceBuildingOrderGenerator))
|
||||||
dragStart = dragEnd = xy;
|
dragStart = dragEnd = xy;
|
||||||
ApplyOrders(xy, mi);
|
ApplyOrders(world, xy, mi);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Move)
|
if (mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Move)
|
||||||
@@ -94,8 +94,8 @@ namespace OpenRa
|
|||||||
{
|
{
|
||||||
if (orderGenerator is UnitOrderGenerator)
|
if (orderGenerator is UnitOrderGenerator)
|
||||||
{
|
{
|
||||||
var newSelection = Game.world.SelectActorsInBox(Game.CellSize * dragStart, Game.CellSize * xy);
|
var newSelection = world.SelectActorsInBox(Game.CellSize * dragStart, Game.CellSize * xy);
|
||||||
CombineSelection(newSelection, mi.Modifiers.HasModifier(Modifiers.Shift), dragStart == xy);
|
CombineSelection(world, newSelection, mi.Modifiers.HasModifier(Modifiers.Shift), dragStart == xy);
|
||||||
}
|
}
|
||||||
|
|
||||||
dragStart = dragEnd = xy;
|
dragStart = dragEnd = xy;
|
||||||
@@ -105,12 +105,12 @@ namespace OpenRa
|
|||||||
dragStart = dragEnd = xy;
|
dragStart = dragEnd = xy;
|
||||||
|
|
||||||
if (mi.Button == MouseButton.Right && mi.Event == MouseInputEvent.Down)
|
if (mi.Button == MouseButton.Right && mi.Event == MouseInputEvent.Down)
|
||||||
ApplyOrders(xy, mi);
|
ApplyOrders(world, xy, mi);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CombineSelection(IEnumerable<Actor> newSelection, bool isCombine, bool isClick)
|
void CombineSelection(World world, IEnumerable<Actor> newSelection, bool isCombine, bool isClick)
|
||||||
{
|
{
|
||||||
var oldSelection = (orderGenerator is UnitOrderGenerator)
|
var oldSelection = (orderGenerator is UnitOrderGenerator)
|
||||||
? (orderGenerator as UnitOrderGenerator).selection : new Actor[] { }.AsEnumerable();
|
? (orderGenerator as UnitOrderGenerator).selection : new Actor[] { }.AsEnumerable();
|
||||||
@@ -127,7 +127,7 @@ namespace OpenRa
|
|||||||
|
|
||||||
var voicedUnit = ((UnitOrderGenerator)orderGenerator).selection
|
var voicedUnit = ((UnitOrderGenerator)orderGenerator).selection
|
||||||
.Where(a => a.traits.Contains<Unit>()
|
.Where(a => a.traits.Contains<Unit>()
|
||||||
&& a.Owner == Game.world.LocalPlayer)
|
&& a.Owner == world.LocalPlayer)
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
|
|
||||||
Sound.PlayVoice("Select", voicedUnit);
|
Sound.PlayVoice("Select", voicedUnit);
|
||||||
@@ -144,9 +144,9 @@ namespace OpenRa
|
|||||||
|
|
||||||
public float2 MousePosition { get { return dragEnd; } }
|
public float2 MousePosition { get { return dragEnd; } }
|
||||||
|
|
||||||
public Cursor ChooseCursor()
|
public Cursor ChooseCursor( World world )
|
||||||
{
|
{
|
||||||
int sync = Game.world.SyncHash();
|
int sync = world.SyncHash();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -157,18 +157,18 @@ namespace OpenRa
|
|||||||
Modifiers = GetModifierKeys(),
|
Modifiers = GetModifierKeys(),
|
||||||
};
|
};
|
||||||
|
|
||||||
return orderGenerator.GetCursor( MousePosition.ToInt2(), mi );
|
return orderGenerator.GetCursor( world, MousePosition.ToInt2(), mi );
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
if( sync != Game.world.SyncHash() )
|
if( sync != world.SyncHash() )
|
||||||
throw new InvalidOperationException( "Desync in Controller.ChooseCursor" );
|
throw new InvalidOperationException( "Desync in Controller.ChooseCursor" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Cache<int, List<Actor>> controlGroups = new Cache<int, List<Actor>>(_ => new List<Actor>());
|
Cache<int, List<Actor>> controlGroups = new Cache<int, List<Actor>>(_ => new List<Actor>());
|
||||||
|
|
||||||
public void DoControlGroup(int group, Modifiers mods)
|
public void DoControlGroup(World world, int group, Modifiers mods)
|
||||||
{
|
{
|
||||||
var uog = orderGenerator as UnitOrderGenerator;
|
var uog = orderGenerator as UnitOrderGenerator;
|
||||||
if (uog == null) return;
|
if (uog == null) return;
|
||||||
@@ -193,7 +193,7 @@ namespace OpenRa
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CombineSelection(controlGroups[group], mods.HasModifier(Modifiers.Shift), false);
|
CombineSelection(world, controlGroups[group], mods.HasModifier(Modifiers.Shift), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int? GetControlGroupForActor(Actor a)
|
public int? GetControlGroupForActor(Actor a)
|
||||||
|
|||||||
@@ -56,13 +56,13 @@ namespace OpenRa.Effects
|
|||||||
|
|
||||||
int TotalTime() { return (Dest - Src).Length * BaseBulletSpeed / Weapon.Speed; }
|
int TotalTime() { return (Dest - Src).Length * BaseBulletSpeed / Weapon.Speed; }
|
||||||
|
|
||||||
public void Tick()
|
public void Tick( World world )
|
||||||
{
|
{
|
||||||
t += 40;
|
t += 40;
|
||||||
|
|
||||||
if (t > TotalTime()) /* remove finished bullets */
|
if (t > TotalTime()) /* remove finished bullets */
|
||||||
{
|
{
|
||||||
Game.world.AddFrameEndTask(w => w.Remove(this));
|
world.AddFrameEndTask(w => w.Remove(this));
|
||||||
Combat.DoImpact(Dest, VisualDest - new int2( 0, DestAltitude ),
|
Combat.DoImpact(Dest, VisualDest - new int2( 0, DestAltitude ),
|
||||||
Weapon, Projectile, Warhead, FiredBy);
|
Weapon, Projectile, Warhead, FiredBy);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,13 +15,13 @@ namespace OpenRa.Effects
|
|||||||
{
|
{
|
||||||
anim = new Animation(fromActor.traits.GetOrDefault<RenderSimple>().GetImage(fromActor));
|
anim = new Animation(fromActor.traits.GetOrDefault<RenderSimple>().GetImage(fromActor));
|
||||||
anim.PlayThen("die{0}".F(death + 1),
|
anim.PlayThen("die{0}".F(death + 1),
|
||||||
() => Game.world.AddFrameEndTask(w => w.Remove(this)));
|
() => fromActor.World.AddFrameEndTask(w => w.Remove(this)));
|
||||||
|
|
||||||
pos = fromActor.CenterLocation;
|
pos = fromActor.CenterLocation;
|
||||||
owner = fromActor.Owner;
|
owner = fromActor.Owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick() { anim.Tick(); }
|
public void Tick( World world ) { anim.Tick(); }
|
||||||
|
|
||||||
public IEnumerable<Renderable> Render()
|
public IEnumerable<Renderable> Render()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,10 +15,10 @@ namespace OpenRa.Effects
|
|||||||
this.delay = delay;
|
this.delay = delay;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick()
|
public void Tick( World world )
|
||||||
{
|
{
|
||||||
if (--delay <= 0)
|
if (--delay <= 0)
|
||||||
Game.world.AddFrameEndTask(w => { w.Remove(this); a(); });
|
world.AddFrameEndTask(w => { w.Remove(this); a(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Renderable> Render() { yield break; }
|
public IEnumerable<Renderable> Render() { yield break; }
|
||||||
|
|||||||
@@ -9,16 +9,16 @@ namespace OpenRa.Effects
|
|||||||
Animation anim;
|
Animation anim;
|
||||||
int2 pos;
|
int2 pos;
|
||||||
|
|
||||||
public Explosion(int2 pixelPos, int style, bool isWater)
|
public Explosion( World world, int2 pixelPos, int style, bool isWater)
|
||||||
{
|
{
|
||||||
this.pos = pixelPos;
|
this.pos = pixelPos;
|
||||||
var variantSuffix = isWater ? "w" : "";
|
var variantSuffix = isWater ? "w" : "";
|
||||||
anim = new Animation("explosion");
|
anim = new Animation("explosion");
|
||||||
anim.PlayThen(style.ToString() + variantSuffix,
|
anim.PlayThen(style.ToString() + variantSuffix,
|
||||||
() => Game.world.AddFrameEndTask(w => w.Remove(this)));
|
() => world.AddFrameEndTask(w => w.Remove(this)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick() { anim.Tick(); }
|
public void Tick( World world ) { anim.Tick(); }
|
||||||
|
|
||||||
public IEnumerable<Renderable> Render()
|
public IEnumerable<Renderable> Render()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,14 +15,14 @@ namespace OpenRa.Effects
|
|||||||
public FlashTarget(Actor target)
|
public FlashTarget(Actor target)
|
||||||
{
|
{
|
||||||
this.target = target;
|
this.target = target;
|
||||||
foreach (var e in Game.world.Effects.OfType<FlashTarget>().Where(a => a.target == target).ToArray())
|
foreach (var e in target.World.Effects.OfType<FlashTarget>().Where(a => a.target == target).ToArray())
|
||||||
Game.world.Remove(e);
|
target.World.Remove(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick()
|
public void Tick( World world )
|
||||||
{
|
{
|
||||||
if (--remainingTicks == 0)
|
if (--remainingTicks == 0)
|
||||||
Game.world.AddFrameEndTask(w => w.Remove(this));
|
world.AddFrameEndTask(w => w.Remove(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Renderable> Render()
|
public IEnumerable<Renderable> Render()
|
||||||
|
|||||||
@@ -16,13 +16,13 @@ namespace OpenRa.Effects
|
|||||||
anim.PlayRepeating("idle");
|
anim.PlayRepeating("idle");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick()
|
public void Tick( World world )
|
||||||
{
|
{
|
||||||
anim.Tick();
|
anim.Tick();
|
||||||
offset.Y -= heightPerTick;
|
offset.Y -= heightPerTick;
|
||||||
|
|
||||||
if (offset.Y < 0)
|
if (offset.Y < 0)
|
||||||
Game.world.AddFrameEndTask(w => w.Remove(this));
|
world.AddFrameEndTask(w => w.Remove(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Renderable> Render()
|
public IEnumerable<Renderable> Render()
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ namespace OpenRa.Effects
|
|||||||
{
|
{
|
||||||
public interface IEffect
|
public interface IEffect
|
||||||
{
|
{
|
||||||
void Tick();
|
void Tick( World world );
|
||||||
IEnumerable<Renderable> Render();
|
IEnumerable<Renderable> Render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,10 +15,10 @@ namespace OpenRa.Effects
|
|||||||
this.b = a.traits.Get<IronCurtainable>();
|
this.b = a.traits.Get<IronCurtainable>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick()
|
public void Tick( World world )
|
||||||
{
|
{
|
||||||
if (a.IsDead || b.GetDamageModifier() > 0)
|
if (a.IsDead || b.GetDamageModifier() > 0)
|
||||||
Game.world.AddFrameEndTask(w => w.Remove(this));
|
world.AddFrameEndTask(w => w.Remove(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Renderable> Render()
|
public IEnumerable<Renderable> Render()
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ namespace OpenRa.Effects
|
|||||||
const int MissileCloseEnough = 7;
|
const int MissileCloseEnough = 7;
|
||||||
const float Scale = .2f;
|
const float Scale = .2f;
|
||||||
|
|
||||||
public void Tick()
|
public void Tick( World world )
|
||||||
{
|
{
|
||||||
t += 40;
|
t += 40;
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@ namespace OpenRa.Effects
|
|||||||
var dist = Target.CenterLocation - Pos;
|
var dist = Target.CenterLocation - Pos;
|
||||||
if (dist.LengthSquared < MissileCloseEnough * MissileCloseEnough || Target.IsDead)
|
if (dist.LengthSquared < MissileCloseEnough * MissileCloseEnough || Target.IsDead)
|
||||||
{
|
{
|
||||||
Game.world.AddFrameEndTask(w => w.Remove(this));
|
world.AddFrameEndTask(w => w.Remove(this));
|
||||||
|
|
||||||
if (t > Projectile.Arm * 40) /* don't blow up in our launcher's face! */
|
if (t > Projectile.Arm * 40) /* don't blow up in our launcher's face! */
|
||||||
Combat.DoImpact(Pos.ToInt2(), Pos.ToInt2(), Weapon, Projectile, Warhead, FiredBy);
|
Combat.DoImpact(Pos.ToInt2(), Pos.ToInt2(), Weapon, Projectile, Warhead, FiredBy);
|
||||||
@@ -78,7 +78,7 @@ namespace OpenRa.Effects
|
|||||||
Pos += move;
|
Pos += move;
|
||||||
|
|
||||||
if (Projectile.Animates)
|
if (Projectile.Animates)
|
||||||
Game.world.AddFrameEndTask(w => w.Add(new Smoke((Pos - 1.5f * move - new int2( 0, Altitude )).ToInt2())));
|
world.AddFrameEndTask(w => w.Add(new Smoke(w, (Pos - 1.5f * move - new int2( 0, Altitude )).ToInt2())));
|
||||||
|
|
||||||
// todo: running out of fuel
|
// todo: running out of fuel
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,15 +12,15 @@ namespace OpenRa.Effects
|
|||||||
Animation anim = new Animation("moveflsh");
|
Animation anim = new Animation("moveflsh");
|
||||||
float2 pos;
|
float2 pos;
|
||||||
|
|
||||||
public MoveFlash( float2 pos )
|
public MoveFlash( World world, float2 pos )
|
||||||
{
|
{
|
||||||
this.pos = pos;
|
this.pos = pos;
|
||||||
anim.PlayThen( "idle",
|
anim.PlayThen( "idle",
|
||||||
() => Game.world.AddFrameEndTask(
|
() => world.AddFrameEndTask(
|
||||||
w => w.Remove( this ) ) );
|
w => w.Remove( this ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick() { anim.Tick(); }
|
public void Tick( World world ) { anim.Tick(); }
|
||||||
|
|
||||||
public IEnumerable<Renderable> Render()
|
public IEnumerable<Renderable> Render()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ namespace OpenRa.Effects
|
|||||||
anim.PlayRepeating("disabled");
|
anim.PlayRepeating("disabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick()
|
public void Tick( World world )
|
||||||
{
|
{
|
||||||
if (removeNextFrame == true)
|
if (removeNextFrame == true)
|
||||||
Game.world.AddFrameEndTask(w => w.Remove(this));
|
world.AddFrameEndTask(w => w.Remove(this));
|
||||||
|
|
||||||
// Fix off-by one frame bug with undisabling causing low-power
|
// Fix off-by one frame bug with undisabling causing low-power
|
||||||
if (!b.Disabled || a.IsDead)
|
if (!b.Disabled || a.IsDead)
|
||||||
|
|||||||
@@ -12,10 +12,10 @@ namespace OpenRa.Effects
|
|||||||
|
|
||||||
public RepairIndicator(Actor a) { this.a = a; anim.PlayRepeating("repair"); }
|
public RepairIndicator(Actor a) { this.a = a; anim.PlayRepeating("repair"); }
|
||||||
|
|
||||||
public void Tick()
|
public void Tick( World world )
|
||||||
{
|
{
|
||||||
if (--framesLeft == 0 || a.IsDead)
|
if (--framesLeft == 0 || a.IsDead)
|
||||||
Game.world.AddFrameEndTask(w => w.Remove(this));
|
world.AddFrameEndTask(w => w.Remove(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Renderable> Render()
|
public IEnumerable<Renderable> Render()
|
||||||
|
|||||||
@@ -15,16 +15,16 @@ namespace OpenRa.Effects
|
|||||||
{
|
{
|
||||||
this.a = a;
|
this.a = a;
|
||||||
doors.PlayThen("active",
|
doors.PlayThen("active",
|
||||||
() => Game.world.AddFrameEndTask(w => w.Remove(this)));
|
() => a.World.AddFrameEndTask(w => w.Remove(this)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick()
|
public void Tick( World world )
|
||||||
{
|
{
|
||||||
doors.Tick();
|
doors.Tick();
|
||||||
|
|
||||||
if (++frame == 19)
|
if (++frame == 19)
|
||||||
{
|
{
|
||||||
Game.world.AddFrameEndTask(w => w.Add(new GpsSatellite(a.CenterLocation - .5f * doors.Image.size + doorOffset)));
|
world.AddFrameEndTask(w => w.Add(new GpsSatellite(a.CenterLocation - .5f * doors.Image.size + doorOffset)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,14 +9,14 @@ namespace OpenRa.Effects
|
|||||||
readonly int2 pos;
|
readonly int2 pos;
|
||||||
readonly Animation anim = new Animation("smokey");
|
readonly Animation anim = new Animation("smokey");
|
||||||
|
|
||||||
public Smoke(int2 pos)
|
public Smoke(World world, int2 pos)
|
||||||
{
|
{
|
||||||
this.pos = pos;
|
this.pos = pos;
|
||||||
anim.PlayThen("idle",
|
anim.PlayThen("idle",
|
||||||
() => Game.world.AddFrameEndTask(w => w.Remove(this)));
|
() => world.AddFrameEndTask(w => w.Remove(this)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick()
|
public void Tick( World world )
|
||||||
{
|
{
|
||||||
anim.Tick();
|
anim.Tick();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ namespace OpenRa.Effects
|
|||||||
this.tesla = SequenceProvider.GetSequence( "litning", "bright" );
|
this.tesla = SequenceProvider.GetSequence( "litning", "bright" );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick()
|
public void Tick( World world )
|
||||||
{
|
{
|
||||||
if( timeUntilRemove <= 0 )
|
if( timeUntilRemove <= 0 )
|
||||||
Game.world.AddFrameEndTask( w => w.Remove( this ) );
|
world.AddFrameEndTask( w => w.Remove( this ) );
|
||||||
--timeUntilRemove;
|
--timeUntilRemove;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ using OpenRa.Graphics;
|
|||||||
using OpenRa.Orders;
|
using OpenRa.Orders;
|
||||||
using OpenRa.Support;
|
using OpenRa.Support;
|
||||||
using OpenRa.Traits;
|
using OpenRa.Traits;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace OpenRa
|
namespace OpenRa
|
||||||
{
|
{
|
||||||
@@ -28,7 +29,6 @@ namespace OpenRa
|
|||||||
|
|
||||||
internal static Renderer renderer;
|
internal static Renderer renderer;
|
||||||
static int2 clientSize;
|
static int2 clientSize;
|
||||||
static HardwarePalette palette;
|
|
||||||
static string mapName;
|
static string mapName;
|
||||||
internal static Session LobbyInfo = new Session();
|
internal static Session LobbyInfo = new Session();
|
||||||
static bool changePending;
|
static bool changePending;
|
||||||
@@ -57,8 +57,6 @@ namespace OpenRa
|
|||||||
a.Owner.Shroud.Explore(a);
|
a.Owner.Shroud.Explore(a);
|
||||||
};
|
};
|
||||||
|
|
||||||
palette = new HardwarePalette(renderer, world.Map);
|
|
||||||
|
|
||||||
SequenceProvider.Initialize(manifest.Sequences);
|
SequenceProvider.Initialize(manifest.Sequences);
|
||||||
viewport = new Viewport(clientSize, Game.world.Map.Offset, Game.world.Map.Offset + Game.world.Map.Size, renderer);
|
viewport = new Viewport(clientSize, Game.world.Map.Offset, Game.world.Map.Offset + Game.world.Map.Size, renderer);
|
||||||
|
|
||||||
@@ -127,13 +125,13 @@ namespace OpenRa
|
|||||||
lastTime += Settings.Timestep;
|
lastTime += Settings.Timestep;
|
||||||
chrome.Tick();
|
chrome.Tick();
|
||||||
|
|
||||||
orderManager.TickImmediate();
|
orderManager.TickImmediate( world );
|
||||||
|
|
||||||
if (orderManager.IsReadyForNextFrame)
|
if (orderManager.IsReadyForNextFrame)
|
||||||
{
|
{
|
||||||
orderManager.Tick();
|
orderManager.Tick( world );
|
||||||
if (controller.orderGenerator != null)
|
if (controller.orderGenerator != null)
|
||||||
controller.orderGenerator.Tick();
|
controller.orderGenerator.Tick( world );
|
||||||
|
|
||||||
world.Tick();
|
world.Tick();
|
||||||
}
|
}
|
||||||
@@ -147,26 +145,14 @@ namespace OpenRa
|
|||||||
|
|
||||||
using (new PerfSample("render"))
|
using (new PerfSample("render"))
|
||||||
{
|
{
|
||||||
UpdatePalette(world.Actors.SelectMany(
|
|
||||||
a => a.traits.WithInterface<IPaletteModifier>()));
|
|
||||||
++RenderFrame;
|
++RenderFrame;
|
||||||
viewport.DrawRegions();
|
viewport.DrawRegions( world );
|
||||||
}
|
}
|
||||||
|
|
||||||
PerfHistory.items["render"].Tick();
|
PerfHistory.items["render"].Tick();
|
||||||
PerfHistory.items["batches"].Tick();
|
PerfHistory.items["batches"].Tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void UpdatePalette(IEnumerable<IPaletteModifier> paletteMods)
|
|
||||||
{
|
|
||||||
var b = new Bitmap(palette.Bitmap);
|
|
||||||
foreach (var mod in paletteMods)
|
|
||||||
mod.AdjustPalette(b);
|
|
||||||
|
|
||||||
palette.Texture.SetData(b);
|
|
||||||
renderer.PaletteTexture = palette.Texture;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Random SharedRandom = new Random(0); /* for things that require sync */
|
public static Random SharedRandom = new Random(0); /* for things that require sync */
|
||||||
public static Random CosmeticRandom = new Random(); /* for things that are just fluff */
|
public static Random CosmeticRandom = new Random(); /* for things that are just fluff */
|
||||||
|
|
||||||
@@ -224,7 +210,7 @@ namespace OpenRa
|
|||||||
world.CreateActor("mcv", sp, world.players[client.Index]);
|
world.CreateActor("mcv", sp, world.players[client.Index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Game.viewport.GoToStartLocation();
|
Game.viewport.GoToStartLocation( Game.world.LocalPlayer );
|
||||||
orderManager.StartGame();
|
orderManager.StartGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,5 +232,62 @@ namespace OpenRa
|
|||||||
taken.Add(sp);
|
taken.Add(sp);
|
||||||
return sp;
|
return sp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static void DispatchMouseInput(MouseInputEvent ev, MouseEventArgs e, Keys ModifierKeys)
|
||||||
|
{
|
||||||
|
int sync = Game.world.SyncHash();
|
||||||
|
|
||||||
|
Game.viewport.DispatchMouseInput( world,
|
||||||
|
new MouseInput
|
||||||
|
{
|
||||||
|
Button = (MouseButton)(int)e.Button,
|
||||||
|
Event = ev,
|
||||||
|
Location = new int2(e.Location),
|
||||||
|
Modifiers = (Modifiers)(int)ModifierKeys,
|
||||||
|
});
|
||||||
|
|
||||||
|
if( sync != Game.world.SyncHash() )
|
||||||
|
throw new InvalidOperationException( "Desync in DispatchMouseInput" );
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void HandleKeyDown( KeyEventArgs e )
|
||||||
|
{
|
||||||
|
int sync = Game.world.SyncHash();
|
||||||
|
|
||||||
|
/* hack hack hack */
|
||||||
|
if( e.KeyCode == Keys.F8 && !Game.orderManager.GameStarted )
|
||||||
|
{
|
||||||
|
Game.controller.AddOrder(
|
||||||
|
new Order( "ToggleReady", Game.world.LocalPlayer.PlayerActor, null, int2.Zero, "" ) { IsImmediate = true } );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* temporary hack: DO NOT LEAVE IN */
|
||||||
|
if( e.KeyCode == Keys.F2 )
|
||||||
|
Game.world.LocalPlayer = Game.world.players[ ( Game.world.LocalPlayer.Index + 1 ) % 4 ];
|
||||||
|
if( e.KeyCode == Keys.F3 )
|
||||||
|
Game.controller.orderGenerator = new SellOrderGenerator();
|
||||||
|
if( e.KeyCode == Keys.F4 )
|
||||||
|
Game.controller.orderGenerator = new RepairOrderGenerator();
|
||||||
|
|
||||||
|
if( !Game.chat.isChatting )
|
||||||
|
if( e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9 )
|
||||||
|
Game.controller.DoControlGroup( world, (int)e.KeyCode - (int)Keys.D0, (Modifiers)(int)e.Modifiers );
|
||||||
|
|
||||||
|
if( sync != Game.world.SyncHash() )
|
||||||
|
throw new InvalidOperationException( "Desync in OnKeyDown" );
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void HandleKeyPress( KeyPressEventArgs e )
|
||||||
|
{
|
||||||
|
int sync = Game.world.SyncHash();
|
||||||
|
|
||||||
|
if( e.KeyChar == '\r' )
|
||||||
|
Game.chat.Toggle();
|
||||||
|
else if( Game.chat.isChatting )
|
||||||
|
Game.chat.TypeChar( e.KeyChar );
|
||||||
|
|
||||||
|
if( sync != Game.world.SyncHash() )
|
||||||
|
throw new InvalidOperationException( "Desync in OnKeyPress" );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ namespace OpenRa.GameRules
|
|||||||
public Cache<string, List<Actor>> GatherBuildings( Player player )
|
public Cache<string, List<Actor>> GatherBuildings( Player player )
|
||||||
{
|
{
|
||||||
var ret = new Cache<string, List<Actor>>( x => new List<Actor>() );
|
var ret = new Cache<string, List<Actor>>( x => new List<Actor>() );
|
||||||
foreach( var b in Game.world.Actors.Where( x => x.Owner == player && x.Info.Traits.Contains<BuildingInfo>() ) )
|
foreach( var b in player.World.Actors.Where( x => x.Owner == player && x.Info.Traits.Contains<BuildingInfo>() ) )
|
||||||
{
|
{
|
||||||
ret[ b.Info.Name ].Add( b );
|
ret[ b.Info.Name ].Add( b );
|
||||||
var buildable = b.Info.Traits.GetOrDefault<BuildableInfo>();
|
var buildable = b.Info.Traits.GetOrDefault<BuildableInfo>();
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using OpenRa.FileFormats;
|
using OpenRa.FileFormats;
|
||||||
|
using OpenRa.Traits;
|
||||||
|
|
||||||
namespace OpenRa.Graphics
|
namespace OpenRa.Graphics
|
||||||
{
|
{
|
||||||
@@ -38,5 +40,15 @@ namespace OpenRa.Graphics
|
|||||||
|
|
||||||
return allocated++;
|
return allocated++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Update(IEnumerable<IPaletteModifier> paletteMods)
|
||||||
|
{
|
||||||
|
var b = new Bitmap(Bitmap);
|
||||||
|
foreach (var mod in paletteMods)
|
||||||
|
mod.AdjustPalette(b);
|
||||||
|
|
||||||
|
Texture.SetData(b);
|
||||||
|
Game.renderer.PaletteTexture = Texture;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ namespace OpenRa.Graphics
|
|||||||
|
|
||||||
mapOnlySheet.Texture.SetData(oreLayer);
|
mapOnlySheet.Texture.SetData(oreLayer);
|
||||||
|
|
||||||
if (!world.Actors.Any(a => a.Owner == Game.world.LocalPlayer && a.traits.Contains<ProvidesRadar>()))
|
if (!world.Actors.Any(a => a.Owner == world.LocalPlayer && a.traits.Contains<ProvidesRadar>()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var bitmap = new Bitmap(oreLayer);
|
var bitmap = new Bitmap(oreLayer);
|
||||||
@@ -109,7 +109,7 @@ namespace OpenRa.Graphics
|
|||||||
{
|
{
|
||||||
for (var y = 0; y < 128; y++)
|
for (var y = 0; y < 128; y++)
|
||||||
for (var x = 0; x < 128; x++)
|
for (var x = 0; x < 128; x++)
|
||||||
if (!Game.world.LocalPlayer.Shroud.DisplayOnRadar(x, y))
|
if (!world.LocalPlayer.Shroud.DisplayOnRadar(x, y))
|
||||||
*(c + (y * bitmapData.Stride >> 2) + x) = shroudColor.ToArgb();
|
*(c + (y * bitmapData.Stride >> 2) + x) = shroudColor.ToArgb();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace OpenRa.Graphics
|
|||||||
{
|
{
|
||||||
interface IHandleInput
|
interface IHandleInput
|
||||||
{
|
{
|
||||||
bool HandleInput(MouseInput mi);
|
bool HandleInput(World world, MouseInput mi);
|
||||||
}
|
}
|
||||||
|
|
||||||
class Viewport
|
class Viewport
|
||||||
@@ -42,8 +42,11 @@ namespace OpenRa.Graphics
|
|||||||
this.scrollPosition = Game.CellSize* mapStart;
|
this.scrollPosition = Game.CellSize* mapStart;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawRegions()
|
public void DrawRegions( World world )
|
||||||
{
|
{
|
||||||
|
world.WorldRenderer.palette.Update(world.Actors.SelectMany(
|
||||||
|
a => a.traits.WithInterface<IPaletteModifier>()));
|
||||||
|
|
||||||
float2 r1 = new float2(2, -2) / screenSize;
|
float2 r1 = new float2(2, -2) / screenSize;
|
||||||
float2 r2 = new float2(-1, 1);
|
float2 r2 = new float2(-1, 1);
|
||||||
|
|
||||||
@@ -51,8 +54,8 @@ namespace OpenRa.Graphics
|
|||||||
|
|
||||||
if( Game.orderManager.GameStarted )
|
if( Game.orderManager.GameStarted )
|
||||||
{
|
{
|
||||||
Game.world.WorldRenderer.Draw();
|
world.WorldRenderer.Draw();
|
||||||
Game.chrome.Draw();
|
Game.chrome.Draw( world );
|
||||||
|
|
||||||
if (Game.orderManager.IsNetplay &&
|
if (Game.orderManager.IsNetplay &&
|
||||||
Game.orderManager.Sources.OfType<NetworkOrderSource>().First().State == ConnectionState.NotConnected)
|
Game.orderManager.Sources.OfType<NetworkOrderSource>().First().State == ConnectionState.NotConnected)
|
||||||
@@ -74,15 +77,15 @@ namespace OpenRa.Graphics
|
|||||||
Game.chrome.DrawDialog("Connection failed.");
|
Game.chrome.DrawDialog("Connection failed.");
|
||||||
break;
|
break;
|
||||||
case ConnectionState.Connected:
|
case ConnectionState.Connected:
|
||||||
Game.chrome.DrawLobby();
|
Game.chrome.DrawLobby( world );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Game.chrome.DrawLobby();
|
Game.chrome.DrawLobby( world );
|
||||||
}
|
}
|
||||||
|
|
||||||
var c = Game.chrome.HitTest(mousePos) ? Cursor.Default : Game.controller.ChooseCursor();
|
var c = Game.chrome.HitTest(mousePos) ? Cursor.Default : Game.controller.ChooseCursor( world );
|
||||||
cursorRenderer.DrawSprite(c.GetSprite((int)cursorFrame), mousePos + Location - c.GetHotspot(), 0);
|
cursorRenderer.DrawSprite(c.GetSprite((int)cursorFrame), mousePos + Location - c.GetHotspot(), 0);
|
||||||
cursorRenderer.Flush();
|
cursorRenderer.Flush();
|
||||||
|
|
||||||
@@ -95,18 +98,18 @@ namespace OpenRa.Graphics
|
|||||||
}
|
}
|
||||||
|
|
||||||
IHandleInput dragRegion = null;
|
IHandleInput dragRegion = null;
|
||||||
public void DispatchMouseInput(MouseInput mi)
|
public void DispatchMouseInput(World world, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Event == MouseInputEvent.Move)
|
if (mi.Event == MouseInputEvent.Move)
|
||||||
mousePos = mi.Location;
|
mousePos = mi.Location;
|
||||||
|
|
||||||
if (dragRegion != null) {
|
if (dragRegion != null) {
|
||||||
dragRegion.HandleInput( mi );
|
dragRegion.HandleInput( world, mi );
|
||||||
if (mi.Event == MouseInputEvent.Up) dragRegion = null;
|
if (mi.Event == MouseInputEvent.Up) dragRegion = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dragRegion = regions.FirstOrDefault(r => r.HandleInput(mi));
|
dragRegion = regions.FirstOrDefault(r => r.HandleInput(world, mi));
|
||||||
if (mi.Event != MouseInputEvent.Down)
|
if (mi.Event != MouseInputEvent.Down)
|
||||||
dragRegion = null;
|
dragRegion = null;
|
||||||
}
|
}
|
||||||
@@ -127,9 +130,9 @@ namespace OpenRa.Graphics
|
|||||||
scrollPosition = (avgPos - .5f * new float2(Width, Height)).ToInt2();
|
scrollPosition = (avgPos - .5f * new float2(Width, Height)).ToInt2();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void GoToStartLocation()
|
public void GoToStartLocation( Player player )
|
||||||
{
|
{
|
||||||
Center(Game.world.Actors.Where(a => a.Owner == Game.world.LocalPlayer && a.traits.Contains<Selectable>()));
|
Center(player.World.Actors.Where(a => a.Owner == player && a.traits.Contains<Selectable>()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,22 +7,26 @@ namespace OpenRa.Graphics
|
|||||||
{
|
{
|
||||||
public class WorldRenderer
|
public class WorldRenderer
|
||||||
{
|
{
|
||||||
|
readonly World world;
|
||||||
internal readonly TerrainRenderer terrainRenderer;
|
internal readonly TerrainRenderer terrainRenderer;
|
||||||
internal readonly SpriteRenderer spriteRenderer;
|
internal readonly SpriteRenderer spriteRenderer;
|
||||||
internal readonly LineRenderer lineRenderer;
|
internal readonly LineRenderer lineRenderer;
|
||||||
internal readonly UiOverlay uiOverlay;
|
internal readonly UiOverlay uiOverlay;
|
||||||
internal readonly Renderer renderer;
|
internal readonly Renderer renderer;
|
||||||
|
internal readonly HardwarePalette palette;
|
||||||
|
|
||||||
public static bool ShowUnitPaths = false;
|
public static bool ShowUnitPaths = false;
|
||||||
|
|
||||||
internal WorldRenderer(World world, Renderer renderer)
|
internal WorldRenderer(World world, Renderer renderer)
|
||||||
{
|
{
|
||||||
terrainRenderer = new TerrainRenderer(world, renderer);
|
this.world = world;
|
||||||
|
|
||||||
this.renderer = renderer;
|
this.renderer = renderer;
|
||||||
|
|
||||||
|
terrainRenderer = new TerrainRenderer(world, renderer);
|
||||||
spriteRenderer = new SpriteRenderer(renderer, true);
|
spriteRenderer = new SpriteRenderer(renderer, true);
|
||||||
lineRenderer = new LineRenderer(renderer);
|
lineRenderer = new LineRenderer(renderer);
|
||||||
uiOverlay = new UiOverlay(spriteRenderer);
|
uiOverlay = new UiOverlay(spriteRenderer);
|
||||||
|
palette = new HardwarePalette(renderer, world.Map);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawSpriteList(RectangleF rect,
|
void DrawSpriteList(RectangleF rect,
|
||||||
@@ -64,25 +68,25 @@ namespace OpenRa.Graphics
|
|||||||
new SizeF( Game.viewport.Width, Game.viewport.Height ));
|
new SizeF( Game.viewport.Width, Game.viewport.Height ));
|
||||||
|
|
||||||
/* todo: cull to screen again */
|
/* todo: cull to screen again */
|
||||||
var renderables = Game.world.Actors.SelectMany(a => a.Render())
|
var renderables = world.Actors.SelectMany(a => a.Render())
|
||||||
.OrderBy(r => r, comparer);
|
.OrderBy(r => r, comparer);
|
||||||
|
|
||||||
foreach (var r in renderables)
|
foreach (var r in renderables)
|
||||||
spriteRenderer.DrawSprite(r.Sprite, r.Pos, r.Palette);
|
spriteRenderer.DrawSprite(r.Sprite, r.Pos, r.Palette);
|
||||||
|
|
||||||
foreach (var e in Game.world.Effects)
|
foreach (var e in world.Effects)
|
||||||
DrawSpriteList(rect, e.Render());
|
DrawSpriteList(rect, e.Render());
|
||||||
|
|
||||||
uiOverlay.Draw();
|
uiOverlay.Draw( world );
|
||||||
|
|
||||||
spriteRenderer.Flush();
|
spriteRenderer.Flush();
|
||||||
|
|
||||||
DrawBandBox();
|
DrawBandBox();
|
||||||
|
|
||||||
if (Game.controller.orderGenerator != null)
|
if (Game.controller.orderGenerator != null)
|
||||||
Game.controller.orderGenerator.Render();
|
Game.controller.orderGenerator.Render( world );
|
||||||
|
|
||||||
Game.world.LocalPlayer.Shroud.Draw(spriteRenderer);
|
world.LocalPlayer.Shroud.Draw(spriteRenderer);
|
||||||
|
|
||||||
lineRenderer.Flush();
|
lineRenderer.Flush();
|
||||||
spriteRenderer.Flush();
|
spriteRenderer.Flush();
|
||||||
@@ -102,7 +106,7 @@ namespace OpenRa.Graphics
|
|||||||
lineRenderer.DrawLine(a + b + c, a + c, Color.White, Color.White);
|
lineRenderer.DrawLine(a + b + c, a + c, Color.White, Color.White);
|
||||||
lineRenderer.DrawLine(a, a + c, Color.White, Color.White);
|
lineRenderer.DrawLine(a, a + c, Color.White, Color.White);
|
||||||
|
|
||||||
foreach (var u in Game.world.SelectActorsInBox(selbox.Value.First, selbox.Value.Second))
|
foreach (var u in world.SelectActorsInBox(selbox.Value.First, selbox.Value.Second))
|
||||||
DrawSelectionBox(u, Color.Yellow, false);
|
DrawSelectionBox(u, Color.Yellow, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,7 +135,7 @@ namespace OpenRa.Graphics
|
|||||||
DrawControlGroup(selectedUnit, xy);
|
DrawControlGroup(selectedUnit, xy);
|
||||||
|
|
||||||
// Only display pips and tags to the owner
|
// Only display pips and tags to the owner
|
||||||
if (selectedUnit.Owner == Game.world.LocalPlayer)
|
if (selectedUnit.Owner == world.LocalPlayer)
|
||||||
{
|
{
|
||||||
DrawPips(selectedUnit, xY);
|
DrawPips(selectedUnit, xY);
|
||||||
DrawTags(selectedUnit, new float2(.5f * (bounds.Left + bounds.Right ), xy.Y));
|
DrawTags(selectedUnit, new float2(.5f * (bounds.Left + bounds.Right ), xy.Y));
|
||||||
|
|||||||
@@ -90,28 +90,11 @@ namespace OpenRa
|
|||||||
|
|
||||||
int2 lastPos;
|
int2 lastPos;
|
||||||
|
|
||||||
void DispatchMouseInput(MouseInputEvent ev, MouseEventArgs e)
|
|
||||||
{
|
|
||||||
int sync = Game.world.SyncHash();
|
|
||||||
|
|
||||||
Game.viewport.DispatchMouseInput(
|
|
||||||
new MouseInput
|
|
||||||
{
|
|
||||||
Button = (MouseButton)(int)e.Button,
|
|
||||||
Event = ev,
|
|
||||||
Location = new int2(e.Location),
|
|
||||||
Modifiers = (Modifiers)(int)ModifierKeys,
|
|
||||||
});
|
|
||||||
|
|
||||||
if( sync != Game.world.SyncHash() )
|
|
||||||
throw new InvalidOperationException( "Desync in DispatchMouseInput" );
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnMouseDown(MouseEventArgs e)
|
protected override void OnMouseDown(MouseEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnMouseDown(e);
|
base.OnMouseDown(e);
|
||||||
lastPos = new int2(e.Location);
|
lastPos = new int2(e.Location);
|
||||||
DispatchMouseInput(MouseInputEvent.Down, e);
|
Game.DispatchMouseInput(MouseInputEvent.Down, e, ModifierKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnMouseMove(MouseEventArgs e)
|
protected override void OnMouseMove(MouseEventArgs e)
|
||||||
@@ -125,57 +108,27 @@ namespace OpenRa
|
|||||||
lastPos = p;
|
lastPos = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
DispatchMouseInput(MouseInputEvent.Move, e);
|
Game.DispatchMouseInput(MouseInputEvent.Move, e, ModifierKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnMouseUp(MouseEventArgs e)
|
protected override void OnMouseUp(MouseEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnMouseUp(e);
|
base.OnMouseUp(e);
|
||||||
DispatchMouseInput(MouseInputEvent.Up, e);
|
Game.DispatchMouseInput(MouseInputEvent.Up, e, ModifierKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnKeyDown(KeyEventArgs e)
|
protected override void OnKeyDown(KeyEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnKeyDown(e);
|
base.OnKeyDown(e);
|
||||||
|
|
||||||
int sync = Game.world.SyncHash();
|
Game.HandleKeyDown( e );
|
||||||
|
|
||||||
/* hack hack hack */
|
|
||||||
if (e.KeyCode == Keys.F8 && !Game.orderManager.GameStarted)
|
|
||||||
{
|
|
||||||
Game.controller.AddOrder(
|
|
||||||
new Order( "ToggleReady", Game.world.LocalPlayer.PlayerActor, null, int2.Zero, "") { IsImmediate = true });
|
|
||||||
}
|
|
||||||
|
|
||||||
/* temporary hack: DO NOT LEAVE IN */
|
|
||||||
if (e.KeyCode == Keys.F2)
|
|
||||||
Game.world.LocalPlayer = Game.world.players[(Game.world.LocalPlayer.Index + 1) % 4];
|
|
||||||
if (e.KeyCode == Keys.F3)
|
|
||||||
Game.controller.orderGenerator = new SellOrderGenerator();
|
|
||||||
if (e.KeyCode == Keys.F4)
|
|
||||||
Game.controller.orderGenerator = new RepairOrderGenerator();
|
|
||||||
|
|
||||||
if (!Game.chat.isChatting)
|
|
||||||
if (e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9)
|
|
||||||
Game.controller.DoControlGroup( (int)e.KeyCode - (int)Keys.D0, (Modifiers)(int)e.Modifiers );
|
|
||||||
|
|
||||||
if( sync != Game.world.SyncHash() )
|
|
||||||
throw new InvalidOperationException( "Desync in OnKeyDown" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnKeyPress(KeyPressEventArgs e)
|
protected override void OnKeyPress(KeyPressEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnKeyPress(e);
|
base.OnKeyPress(e);
|
||||||
|
|
||||||
int sync = Game.world.SyncHash();
|
Game.HandleKeyPress( e );
|
||||||
|
|
||||||
if (e.KeyChar == '\r')
|
|
||||||
Game.chat.Toggle();
|
|
||||||
else if (Game.chat.isChatting)
|
|
||||||
Game.chat.TypeChar(e.KeyChar);
|
|
||||||
|
|
||||||
if( sync != Game.world.SyncHash() )
|
|
||||||
throw new InvalidOperationException( "Desync in OnKeyPress" );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace OpenRa.Orders
|
|||||||
this.power = power;
|
this.power = power;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Order> Order(int2 xy, MouseInput mi)
|
public IEnumerable<Order> Order(World world, int2 xy, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Button == MouseButton.Left)
|
if (mi.Button == MouseButton.Left)
|
||||||
{
|
{
|
||||||
@@ -29,15 +29,15 @@ namespace OpenRa.Orders
|
|||||||
power != null ? power.Name : null);
|
power != null ? power.Name : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick() {}
|
public void Tick( World world ) {}
|
||||||
public void Render()
|
public void Render( World world )
|
||||||
{
|
{
|
||||||
Game.world.WorldRenderer.DrawSelectionBox(self, Color.White, true);
|
world.WorldRenderer.DrawSelectionBox(self, Color.White, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Cursor GetCursor(int2 xy, MouseInput mi)
|
public Cursor GetCursor(World world, int2 xy, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (!Game.world.LocalPlayer.Shroud.IsExplored(xy))
|
if (!world.LocalPlayer.Shroud.IsExplored(xy))
|
||||||
return Cursor.MoveBlocked;
|
return Cursor.MoveBlocked;
|
||||||
|
|
||||||
var movement = self.traits.GetOrDefault<IMovement>();
|
var movement = self.traits.GetOrDefault<IMovement>();
|
||||||
|
|||||||
@@ -15,21 +15,21 @@ namespace OpenRa.Orders
|
|||||||
this.power = power;
|
this.power = power;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Order> Order(int2 xy, MouseInput mi)
|
public IEnumerable<Order> Order(World world, int2 xy, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Button == MouseButton.Right)
|
if (mi.Button == MouseButton.Right)
|
||||||
Game.controller.CancelInputMode();
|
Game.controller.CancelInputMode();
|
||||||
|
|
||||||
return OrderInner(xy, mi);
|
return OrderInner(world, xy, mi);
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerable<Order> OrderInner(int2 xy, MouseInput mi)
|
IEnumerable<Order> OrderInner(World world, int2 xy, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Button == MouseButton.Left)
|
if (mi.Button == MouseButton.Left)
|
||||||
{
|
{
|
||||||
var loc = mi.Location + Game.viewport.Location;
|
var loc = mi.Location + Game.viewport.Location;
|
||||||
var underCursor = Game.world.FindUnits(loc, loc)
|
var underCursor = world.FindUnits(loc, loc)
|
||||||
.Where(a => a.Owner == Game.world.LocalPlayer
|
.Where(a => a.Owner == world.LocalPlayer
|
||||||
&& a.traits.Contains<Chronoshiftable>()
|
&& a.traits.Contains<Chronoshiftable>()
|
||||||
&& a.traits.Contains<Selectable>()).FirstOrDefault();
|
&& a.traits.Contains<Selectable>()).FirstOrDefault();
|
||||||
|
|
||||||
@@ -38,21 +38,21 @@ namespace OpenRa.Orders
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick()
|
public void Tick( World world )
|
||||||
{
|
{
|
||||||
var hasChronosphere = Game.world.Actors
|
var hasChronosphere = world.Actors
|
||||||
.Any(a => a.Owner == Game.world.LocalPlayer && a.traits.Contains<Chronosphere>());
|
.Any(a => a.Owner == world.LocalPlayer && a.traits.Contains<Chronosphere>());
|
||||||
|
|
||||||
if (!hasChronosphere)
|
if (!hasChronosphere)
|
||||||
Game.controller.CancelInputMode();
|
Game.controller.CancelInputMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Render() { }
|
public void Render( World world ) { }
|
||||||
|
|
||||||
public Cursor GetCursor(int2 xy, MouseInput mi)
|
public Cursor GetCursor(World world, int2 xy, MouseInput mi)
|
||||||
{
|
{
|
||||||
mi.Button = MouseButton.Left;
|
mi.Button = MouseButton.Left;
|
||||||
return OrderInner(xy, mi).Any()
|
return OrderInner(world, xy, mi).Any()
|
||||||
? Cursor.ChronoshiftSelect : Cursor.MoveBlocked;
|
? Cursor.ChronoshiftSelect : Cursor.MoveBlocked;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ namespace OpenRa
|
|||||||
{
|
{
|
||||||
public interface IOrderGenerator
|
public interface IOrderGenerator
|
||||||
{
|
{
|
||||||
IEnumerable<Order> Order( int2 xy, MouseInput mi );
|
IEnumerable<Order> Order( World world, int2 xy, MouseInput mi );
|
||||||
void Tick();
|
void Tick( World world );
|
||||||
void Render();
|
void Render( World world );
|
||||||
Cursor GetCursor(int2 xy, MouseInput mi);
|
Cursor GetCursor( World world, int2 xy, MouseInput mi );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,21 +15,21 @@ namespace OpenRa.Orders
|
|||||||
this.power = power;
|
this.power = power;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Order> Order(int2 xy, MouseInput mi)
|
public IEnumerable<Order> Order(World world, int2 xy, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Button == MouseButton.Right)
|
if (mi.Button == MouseButton.Right)
|
||||||
Game.controller.CancelInputMode();
|
Game.controller.CancelInputMode();
|
||||||
|
|
||||||
return OrderInner(xy, mi);
|
return OrderInner(world, xy, mi);
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerable<Order> OrderInner(int2 xy, MouseInput mi)
|
IEnumerable<Order> OrderInner(World world, int2 xy, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Button == MouseButton.Left)
|
if (mi.Button == MouseButton.Left)
|
||||||
{
|
{
|
||||||
var loc = mi.Location + Game.viewport.Location;
|
var loc = mi.Location + Game.viewport.Location;
|
||||||
var underCursor = Game.world.FindUnits(loc, loc)
|
var underCursor = world.FindUnits(loc, loc)
|
||||||
.Where(a => a.Owner == Game.world.LocalPlayer
|
.Where(a => a.Owner == world.LocalPlayer
|
||||||
&& a.traits.Contains<IronCurtainable>()
|
&& a.traits.Contains<IronCurtainable>()
|
||||||
&& a.traits.Contains<Selectable>()).FirstOrDefault();
|
&& a.traits.Contains<Selectable>()).FirstOrDefault();
|
||||||
|
|
||||||
@@ -38,21 +38,21 @@ namespace OpenRa.Orders
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick()
|
public void Tick( World world )
|
||||||
{
|
{
|
||||||
var hasStructure = Game.world.Actors
|
var hasStructure = world.Actors
|
||||||
.Any(a => a.Owner == Game.world.LocalPlayer && a.traits.Contains<IronCurtain>());
|
.Any(a => a.Owner == world.LocalPlayer && a.traits.Contains<IronCurtain>());
|
||||||
|
|
||||||
if (!hasStructure)
|
if (!hasStructure)
|
||||||
Game.controller.CancelInputMode();
|
Game.controller.CancelInputMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Render() { }
|
public void Render( World world ) { }
|
||||||
|
|
||||||
public Cursor GetCursor(int2 xy, MouseInput mi)
|
public Cursor GetCursor(World world, int2 xy, MouseInput mi)
|
||||||
{
|
{
|
||||||
mi.Button = MouseButton.Left;
|
mi.Button = MouseButton.Left;
|
||||||
return OrderInner(xy, mi).Any()
|
return OrderInner(world, xy, mi).Any()
|
||||||
? Cursor.Ability : Cursor.MoveBlocked;
|
? Cursor.Ability : Cursor.MoveBlocked;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,14 +64,14 @@ namespace OpenRa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Player LookupPlayer(uint index)
|
static Player LookupPlayer(World world, uint index)
|
||||||
{
|
{
|
||||||
return Game.world.players
|
return world.players
|
||||||
.Where(x => x.Value.Index == index)
|
.Where(x => x.Value.Index == index)
|
||||||
.First().Value;
|
.First().Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Order Deserialize(BinaryReader r)
|
public static Order Deserialize(World world, BinaryReader r)
|
||||||
{
|
{
|
||||||
switch (r.ReadByte())
|
switch (r.ReadByte())
|
||||||
{
|
{
|
||||||
@@ -87,7 +87,7 @@ namespace OpenRa
|
|||||||
targetString = r.ReadString();
|
targetString = r.ReadString();
|
||||||
|
|
||||||
Actor subject, targetActor;
|
Actor subject, targetActor;
|
||||||
if( !TryGetActorFromUInt( subjectId, out subject ) || !TryGetActorFromUInt( targetActorId, out targetActor ) )
|
if( !TryGetActorFromUInt( world, subjectId, out subject ) || !TryGetActorFromUInt( world, targetActorId, out targetActor ) )
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return new Order( order, subject, targetActor, targetLocation, targetString);
|
return new Order( order, subject, targetActor, targetLocation, targetString);
|
||||||
@@ -99,7 +99,7 @@ namespace OpenRa
|
|||||||
var name = r.ReadString();
|
var name = r.ReadString();
|
||||||
var data = r.ReadString();
|
var data = r.ReadString();
|
||||||
|
|
||||||
return new Order( name, LookupPlayer( playerID ).PlayerActor, null, int2.Zero, data ) { IsImmediate = true };
|
return new Order( name, LookupPlayer( world, playerID ).PlayerActor, null, int2.Zero, data ) { IsImmediate = true };
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -113,7 +113,7 @@ namespace OpenRa
|
|||||||
return a.ActorID;
|
return a.ActorID;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool TryGetActorFromUInt(uint aID, out Actor ret )
|
static bool TryGetActorFromUInt(World world, uint aID, out Actor ret )
|
||||||
{
|
{
|
||||||
if( aID == 0xFFFFFFFF )
|
if( aID == 0xFFFFFFFF )
|
||||||
{
|
{
|
||||||
@@ -122,7 +122,7 @@ namespace OpenRa
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
foreach( var a in Game.world.Actors.Where( x => x.ActorID == aID ) )
|
foreach( var a in world.Actors.Where( x => x.ActorID == aID ) )
|
||||||
{
|
{
|
||||||
ret = a;
|
ret = a;
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -22,14 +22,14 @@ namespace OpenRa.Orders
|
|||||||
ms.WriteTo(s);
|
ms.WriteTo(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Order> ToOrderList(this byte[] bytes)
|
public static List<Order> ToOrderList(this byte[] bytes, World world)
|
||||||
{
|
{
|
||||||
var ms = new MemoryStream(bytes);
|
var ms = new MemoryStream(bytes);
|
||||||
var reader = new BinaryReader(ms);
|
var reader = new BinaryReader(ms);
|
||||||
var ret = new List<Order>();
|
var ret = new List<Order>();
|
||||||
while( ms.Position < ms.Length )
|
while( ms.Position < ms.Length )
|
||||||
{
|
{
|
||||||
var o = Order.Deserialize( reader );
|
var o = Order.Deserialize( world, reader );
|
||||||
if( o != null )
|
if( o != null )
|
||||||
ret.Add( o );
|
ret.Add( o );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,11 +54,11 @@ namespace OpenRa.Orders
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessOrders(int frame, bool save)
|
void ProcessOrders(World world, int frame, bool save)
|
||||||
{
|
{
|
||||||
var orders = sources
|
var orders = sources
|
||||||
.SelectMany(s => s.OrdersForFrame(frame))
|
.SelectMany(s => s.OrdersForFrame(frame))
|
||||||
.SelectMany(x => x.ToOrderList())
|
.SelectMany(x => x.ToOrderList(world))
|
||||||
.OrderBy(o => o.Player.Index)
|
.OrderBy(o => o.Player.Index)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
@@ -69,24 +69,24 @@ namespace OpenRa.Orders
|
|||||||
savingReplay.WriteFrameData(orders, frame);
|
savingReplay.WriteFrameData(orders, frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void TickImmediate()
|
public void TickImmediate( World world )
|
||||||
{
|
{
|
||||||
var localOrders = Game.controller.GetRecentOrders(true);
|
var localOrders = Game.controller.GetRecentOrders(true);
|
||||||
if (localOrders.Count > 0)
|
if (localOrders.Count > 0)
|
||||||
foreach (var p in sources)
|
foreach (var p in sources)
|
||||||
p.SendLocalOrders(0, localOrders);
|
p.SendLocalOrders(0, localOrders);
|
||||||
|
|
||||||
ProcessOrders(0, false);
|
ProcessOrders(world, 0, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick()
|
public void Tick( World world )
|
||||||
{
|
{
|
||||||
var localOrders = Game.controller.GetRecentOrders(false);
|
var localOrders = Game.controller.GetRecentOrders(false);
|
||||||
|
|
||||||
foreach( var p in sources )
|
foreach( var p in sources )
|
||||||
p.SendLocalOrders( frameNumber + FramesAhead, localOrders );
|
p.SendLocalOrders( frameNumber + FramesAhead, localOrders );
|
||||||
|
|
||||||
ProcessOrders(frameNumber, true);
|
ProcessOrders(world, frameNumber, true);
|
||||||
|
|
||||||
++frameNumber;
|
++frameNumber;
|
||||||
|
|
||||||
|
|||||||
@@ -16,21 +16,21 @@ namespace OpenRa.Orders
|
|||||||
Building = name;
|
Building = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Order> Order(int2 xy, MouseInput mi)
|
public IEnumerable<Order> Order(World world, int2 xy, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Button == MouseButton.Right)
|
if (mi.Button == MouseButton.Right)
|
||||||
Game.controller.CancelInputMode();
|
Game.controller.CancelInputMode();
|
||||||
|
|
||||||
return InnerOrder(xy, mi);
|
return InnerOrder(world, xy, mi);
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerable<Order> InnerOrder(int2 xy, MouseInput mi)
|
IEnumerable<Order> InnerOrder(World world, int2 xy, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Button == MouseButton.Left)
|
if (mi.Button == MouseButton.Left)
|
||||||
{
|
{
|
||||||
var topLeft = xy - Footprint.AdjustForBuildingSize( BuildingInfo );
|
var topLeft = xy - Footprint.AdjustForBuildingSize( BuildingInfo );
|
||||||
if (!Game.world.CanPlaceBuilding( Building, BuildingInfo, topLeft, null)
|
if (!world.CanPlaceBuilding( Building, BuildingInfo, topLeft, null)
|
||||||
|| !Game.world.IsCloseEnoughToBase(Producer.Owner, Building, BuildingInfo, topLeft))
|
|| !world.IsCloseEnoughToBase(Producer.Owner, Building, BuildingInfo, topLeft))
|
||||||
{
|
{
|
||||||
Sound.Play("nodeply1.aud");
|
Sound.Play("nodeply1.aud");
|
||||||
yield break;
|
yield break;
|
||||||
@@ -40,19 +40,19 @@ namespace OpenRa.Orders
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick()
|
public void Tick( World world )
|
||||||
{
|
{
|
||||||
var producing = Producer.traits.Get<Traits.ProductionQueue>().CurrentItem( Rules.Info[ Building ].Category );
|
var producing = Producer.traits.Get<Traits.ProductionQueue>().CurrentItem( Rules.Info[ Building ].Category );
|
||||||
if (producing == null || producing.Item != Building || producing.RemainingTime != 0)
|
if (producing == null || producing.Item != Building || producing.RemainingTime != 0)
|
||||||
Game.controller.CancelInputMode();
|
Game.controller.CancelInputMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Render()
|
public void Render( World world )
|
||||||
{
|
{
|
||||||
Game.world.WorldRenderer.uiOverlay.DrawBuildingGrid( Building, BuildingInfo );
|
world.WorldRenderer.uiOverlay.DrawBuildingGrid( world, Building, BuildingInfo );
|
||||||
}
|
}
|
||||||
|
|
||||||
public Cursor GetCursor(int2 xy, MouseInput mi)
|
public Cursor GetCursor(World world, int2 xy, MouseInput mi)
|
||||||
{
|
{
|
||||||
return Cursor.Default;
|
return Cursor.Default;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,21 +9,21 @@ namespace OpenRa.Orders
|
|||||||
{
|
{
|
||||||
class PowerDownOrderGenerator : IOrderGenerator
|
class PowerDownOrderGenerator : IOrderGenerator
|
||||||
{
|
{
|
||||||
public IEnumerable<Order> Order(int2 xy, MouseInput mi)
|
public IEnumerable<Order> Order(World world, int2 xy, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Button == MouseButton.Right)
|
if (mi.Button == MouseButton.Right)
|
||||||
Game.controller.CancelInputMode();
|
Game.controller.CancelInputMode();
|
||||||
|
|
||||||
return OrderInner(xy, mi);
|
return OrderInner(world, xy, mi);
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerable<Order> OrderInner(int2 xy, MouseInput mi)
|
IEnumerable<Order> OrderInner(World world, int2 xy, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Button == MouseButton.Left)
|
if (mi.Button == MouseButton.Left)
|
||||||
{
|
{
|
||||||
var loc = mi.Location + Game.viewport.Location;
|
var loc = mi.Location + Game.viewport.Location;
|
||||||
var underCursor = Game.world.FindUnits(loc, loc)
|
var underCursor = world.FindUnits(loc, loc)
|
||||||
.Where(a => a.Owner == Game.world.LocalPlayer
|
.Where(a => a.Owner == world.LocalPlayer
|
||||||
&& a.traits.Contains<Building>()
|
&& a.traits.Contains<Building>()
|
||||||
&& a.traits.Contains<Selectable>()).FirstOrDefault();
|
&& a.traits.Contains<Selectable>()).FirstOrDefault();
|
||||||
|
|
||||||
@@ -32,13 +32,13 @@ namespace OpenRa.Orders
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick() { }
|
public void Tick( World world ) { }
|
||||||
public void Render() { }
|
public void Render( World world ) { }
|
||||||
|
|
||||||
public Cursor GetCursor(int2 xy, MouseInput mi)
|
public Cursor GetCursor(World world, int2 xy, MouseInput mi)
|
||||||
{
|
{
|
||||||
mi.Button = MouseButton.Left;
|
mi.Button = MouseButton.Left;
|
||||||
return OrderInner(xy, mi).Any()
|
return OrderInner(world, xy, mi).Any()
|
||||||
? Cursor.PowerDown : Cursor.PowerDown;
|
? Cursor.PowerDown : Cursor.PowerDown;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,21 +9,21 @@ namespace OpenRa.Orders
|
|||||||
{
|
{
|
||||||
class RepairOrderGenerator : IOrderGenerator
|
class RepairOrderGenerator : IOrderGenerator
|
||||||
{
|
{
|
||||||
public IEnumerable<Order> Order(int2 xy, MouseInput mi)
|
public IEnumerable<Order> Order(World world, int2 xy, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Button == MouseButton.Right)
|
if (mi.Button == MouseButton.Right)
|
||||||
Game.controller.CancelInputMode();
|
Game.controller.CancelInputMode();
|
||||||
|
|
||||||
return OrderInner(xy, mi);
|
return OrderInner(world, xy, mi);
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerable<Order> OrderInner(int2 xy, MouseInput mi)
|
IEnumerable<Order> OrderInner(World world, int2 xy, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Button == MouseButton.Left)
|
if (mi.Button == MouseButton.Left)
|
||||||
{
|
{
|
||||||
var loc = mi.Location + Game.viewport.Location;
|
var loc = mi.Location + Game.viewport.Location;
|
||||||
var underCursor = Game.world.FindUnits(loc, loc)
|
var underCursor = world.FindUnits(loc, loc)
|
||||||
.Where(a => a.Owner == Game.world.LocalPlayer
|
.Where(a => a.Owner == world.LocalPlayer
|
||||||
&& a.traits.Contains<Building>()
|
&& a.traits.Contains<Building>()
|
||||||
&& a.traits.Contains<Selectable>()).FirstOrDefault();
|
&& a.traits.Contains<Selectable>()).FirstOrDefault();
|
||||||
|
|
||||||
@@ -34,24 +34,24 @@ namespace OpenRa.Orders
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick()
|
public void Tick( World world )
|
||||||
{
|
{
|
||||||
if (!Game.Settings.RepairRequiresConyard)
|
if (!Game.Settings.RepairRequiresConyard)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var hasFact = Game.world.Actors
|
var hasFact = world.Actors
|
||||||
.Any(a => a.Owner == Game.world.LocalPlayer && a.traits.Contains<ConstructionYard>());
|
.Any(a => a.Owner == world.LocalPlayer && a.traits.Contains<ConstructionYard>());
|
||||||
|
|
||||||
if (!hasFact)
|
if (!hasFact)
|
||||||
Game.controller.CancelInputMode();
|
Game.controller.CancelInputMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Render() {}
|
public void Render( World world ) {}
|
||||||
|
|
||||||
public Cursor GetCursor(int2 xy, MouseInput mi)
|
public Cursor GetCursor(World world, int2 xy, MouseInput mi)
|
||||||
{
|
{
|
||||||
mi.Button = MouseButton.Left;
|
mi.Button = MouseButton.Left;
|
||||||
return OrderInner(xy, mi).Any()
|
return OrderInner(world, xy, mi).Any()
|
||||||
? Cursor.Repair : Cursor.RepairBlocked;
|
? Cursor.Repair : Cursor.RepairBlocked;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,21 +9,21 @@ namespace OpenRa.Orders
|
|||||||
{
|
{
|
||||||
class SellOrderGenerator : IOrderGenerator
|
class SellOrderGenerator : IOrderGenerator
|
||||||
{
|
{
|
||||||
public IEnumerable<Order> Order(int2 xy, MouseInput mi)
|
public IEnumerable<Order> Order(World world, int2 xy, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Button == MouseButton.Right)
|
if (mi.Button == MouseButton.Right)
|
||||||
Game.controller.CancelInputMode();
|
Game.controller.CancelInputMode();
|
||||||
|
|
||||||
return OrderInner(xy, mi);
|
return OrderInner(world, xy, mi);
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerable<Order> OrderInner(int2 xy, MouseInput mi)
|
IEnumerable<Order> OrderInner(World world, int2 xy, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Button == MouseButton.Left)
|
if (mi.Button == MouseButton.Left)
|
||||||
{
|
{
|
||||||
var loc = mi.Location + Game.viewport.Location;
|
var loc = mi.Location + Game.viewport.Location;
|
||||||
var underCursor = Game.world.FindUnits(loc, loc)
|
var underCursor = world.FindUnits(loc, loc)
|
||||||
.Where(a => a.Owner == Game.world.LocalPlayer
|
.Where(a => a.Owner == world.LocalPlayer
|
||||||
&& a.traits.Contains<Building>()
|
&& a.traits.Contains<Building>()
|
||||||
&& a.traits.Contains<Selectable>()).FirstOrDefault();
|
&& a.traits.Contains<Selectable>()).FirstOrDefault();
|
||||||
|
|
||||||
@@ -34,13 +34,13 @@ namespace OpenRa.Orders
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick() {}
|
public void Tick( World world ) {}
|
||||||
public void Render() {}
|
public void Render( World world ) {}
|
||||||
|
|
||||||
public Cursor GetCursor(int2 xy, MouseInput mi)
|
public Cursor GetCursor(World world, int2 xy, MouseInput mi)
|
||||||
{
|
{
|
||||||
mi.Button = MouseButton.Left;
|
mi.Button = MouseButton.Left;
|
||||||
return OrderInner(xy, mi).Any()
|
return OrderInner(world, xy, mi).Any()
|
||||||
? Cursor.Sell : Cursor.SellBlocked;
|
? Cursor.Sell : Cursor.SellBlocked;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace OpenRa.Orders
|
|||||||
selection = selected.ToList();
|
selection = selected.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Order> Order( int2 xy, MouseInput mi )
|
public IEnumerable<Order> Order( World world, int2 xy, MouseInput mi )
|
||||||
{
|
{
|
||||||
foreach( var unit in selection )
|
foreach( var unit in selection )
|
||||||
{
|
{
|
||||||
@@ -25,31 +25,31 @@ namespace OpenRa.Orders
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick()
|
public void Tick( World world )
|
||||||
{
|
{
|
||||||
selection.RemoveAll(a => !a.IsInWorld);
|
selection.RemoveAll(a => !a.IsInWorld);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Render()
|
public void Render( World world )
|
||||||
{
|
{
|
||||||
foreach( var a in selection )
|
foreach( var a in selection )
|
||||||
Game.world.WorldRenderer.DrawSelectionBox( a, Color.White, true );
|
world.WorldRenderer.DrawSelectionBox( a, Color.White, true );
|
||||||
}
|
}
|
||||||
|
|
||||||
public Cursor GetCursor(int2 xy, MouseInput mi)
|
public Cursor GetCursor( World world, int2 xy, MouseInput mi )
|
||||||
{
|
{
|
||||||
return ChooseCursor(mi);
|
return ChooseCursor(world, mi);
|
||||||
}
|
}
|
||||||
|
|
||||||
Cursor ChooseCursor( MouseInput mi )
|
Cursor ChooseCursor( World world, MouseInput mi )
|
||||||
{
|
{
|
||||||
var p = Game.controller.MousePosition;
|
var p = Game.controller.MousePosition;
|
||||||
var c = Order(p.ToInt2(), mi)
|
var c = Order(world, p.ToInt2(), mi)
|
||||||
.Select(o => CursorForOrderString(o.OrderString, o.Subject, o.TargetLocation))
|
.Select(o => CursorForOrderString(o.OrderString, o.Subject, o.TargetLocation))
|
||||||
.FirstOrDefault(a => a != null);
|
.FirstOrDefault(a => a != null);
|
||||||
|
|
||||||
return c ??
|
return c ??
|
||||||
(Game.world.SelectActorsInBox(Game.CellSize * p,
|
(world.SelectActorsInBox(Game.CellSize * p,
|
||||||
Game.CellSize * p).Any()
|
Game.CellSize * p).Any()
|
||||||
? Cursor.Select : Cursor.Default);
|
? Cursor.Select : Cursor.Default);
|
||||||
}
|
}
|
||||||
@@ -69,7 +69,7 @@ namespace OpenRa.Orders
|
|||||||
return Cursor.MoveBlocked;
|
return Cursor.MoveBlocked;
|
||||||
case "DeployMcv":
|
case "DeployMcv":
|
||||||
var factBuildingInfo = Rules.Info["fact"].Traits.Get<BuildingInfo>();
|
var factBuildingInfo = Rules.Info["fact"].Traits.Get<BuildingInfo>();
|
||||||
if (Game.world.CanPlaceBuilding("fact", factBuildingInfo, a.Location - new int2(1, 1), a))
|
if (a.World.CanPlaceBuilding("fact", factBuildingInfo, a.Location - new int2(1, 1), a))
|
||||||
return Cursor.Deploy;
|
return Cursor.Deploy;
|
||||||
else
|
else
|
||||||
return Cursor.DeployBlocked;
|
return Cursor.DeployBlocked;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace OpenRa.Orders
|
|||||||
}
|
}
|
||||||
case "AssignPlayer":
|
case "AssignPlayer":
|
||||||
{
|
{
|
||||||
Game.world.LocalPlayer = order.Player;
|
order.Player.World.LocalPlayer = order.Player;
|
||||||
Game.chat.AddLine(order.Player, "is now YOU.");
|
Game.chat.AddLine(order.Player, "is now YOU.");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,10 +10,12 @@ namespace OpenRa
|
|||||||
{
|
{
|
||||||
public class PathFinder
|
public class PathFinder
|
||||||
{
|
{
|
||||||
|
readonly World world;
|
||||||
float[][,] passableCost = new float[4][,];
|
float[][,] passableCost = new float[4][,];
|
||||||
|
|
||||||
public PathFinder( World world )
|
public PathFinder( World world )
|
||||||
{
|
{
|
||||||
|
this.world = world;
|
||||||
for (var umt = UnitMovementType.Foot; umt <= UnitMovementType.Float; umt++)
|
for (var umt = UnitMovementType.Foot; umt <= UnitMovementType.Float; umt++)
|
||||||
passableCost[(int)umt] = new float[128, 128];
|
passableCost[(int)umt] = new float[128, 128];
|
||||||
for( int x = 0 ; x < 128 ; x++ )
|
for( int x = 0 ; x < 128 ; x++ )
|
||||||
@@ -29,8 +31,8 @@ namespace OpenRa
|
|||||||
using (new PerfSample("find_unit_path"))
|
using (new PerfSample("find_unit_path"))
|
||||||
{
|
{
|
||||||
var pb = FindBidiPath(
|
var pb = FindBidiPath(
|
||||||
PathSearch.FromPoint(target, from, umt, false).WithCustomBlocker(AvoidUnitsNear(from, 4)),
|
PathSearch.FromPoint(world, target, from, umt, false).WithCustomBlocker(AvoidUnitsNear(from, 4)),
|
||||||
PathSearch.FromPoint(from, target, umt, false).WithCustomBlocker(AvoidUnitsNear(from, 4)));
|
PathSearch.FromPoint(world, from, target, umt, false).WithCustomBlocker(AvoidUnitsNear(from, 4)));
|
||||||
|
|
||||||
CheckSanePath2(pb, from, target);
|
CheckSanePath2(pb, from, target);
|
||||||
return pb;
|
return pb;
|
||||||
@@ -41,10 +43,10 @@ namespace OpenRa
|
|||||||
{
|
{
|
||||||
using( new PerfSample( "find_unit_path_multiple_src" ) )
|
using( new PerfSample( "find_unit_path_multiple_src" ) )
|
||||||
{
|
{
|
||||||
var tilesInRange = Game.world.FindTilesInCircle(target, range)
|
var tilesInRange = world.FindTilesInCircle(target, range)
|
||||||
.Where( t => Game.world.IsCellBuildable( t, umt ) );
|
.Where( t => world.IsCellBuildable( t, umt ) );
|
||||||
|
|
||||||
var path = FindPath( PathSearch.FromPoints( tilesInRange, src, umt, false ).WithCustomBlocker(AvoidUnitsNear(src, 4)));
|
var path = FindPath( PathSearch.FromPoints( world, tilesInRange, src, umt, false ).WithCustomBlocker(AvoidUnitsNear(src, 4)));
|
||||||
path.Reverse();
|
path.Reverse();
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
@@ -55,7 +57,7 @@ namespace OpenRa
|
|||||||
return q =>
|
return q =>
|
||||||
p != q &&
|
p != q &&
|
||||||
((p - q).LengthSquared < dist * dist) &&
|
((p - q).LengthSquared < dist * dist) &&
|
||||||
(Game.world.UnitInfluence.GetUnitsAt(q).Any());
|
(world.UnitInfluence.GetUnitsAt(q).Any());
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<int2> FindPath( PathSearch search )
|
public List<int2> FindPath( PathSearch search )
|
||||||
@@ -64,7 +66,7 @@ namespace OpenRa
|
|||||||
{
|
{
|
||||||
while (!search.queue.Empty)
|
while (!search.queue.Empty)
|
||||||
{
|
{
|
||||||
var p = search.Expand( passableCost );
|
var p = search.Expand( world, passableCost );
|
||||||
PerfHistory.Increment("nodes_expanded", .01);
|
PerfHistory.Increment("nodes_expanded", .01);
|
||||||
|
|
||||||
if (search.heuristic(p) == 0)
|
if (search.heuristic(p) == 0)
|
||||||
@@ -101,13 +103,13 @@ namespace OpenRa
|
|||||||
while (!fromSrc.queue.Empty && !fromDest.queue.Empty)
|
while (!fromSrc.queue.Empty && !fromDest.queue.Empty)
|
||||||
{
|
{
|
||||||
/* make some progress on the first search */
|
/* make some progress on the first search */
|
||||||
var p = fromSrc.Expand( passableCost );
|
var p = fromSrc.Expand( world, passableCost );
|
||||||
|
|
||||||
if (fromDest.cellInfo[p.X, p.Y].Seen && fromDest.cellInfo[p.X, p.Y].MinCost < float.PositiveInfinity)
|
if (fromDest.cellInfo[p.X, p.Y].Seen && fromDest.cellInfo[p.X, p.Y].MinCost < float.PositiveInfinity)
|
||||||
return MakeBidiPath(fromSrc, fromDest, p);
|
return MakeBidiPath(fromSrc, fromDest, p);
|
||||||
|
|
||||||
/* make some progress on the second search */
|
/* make some progress on the second search */
|
||||||
var q = fromDest.Expand( passableCost );
|
var q = fromDest.Expand( world, passableCost );
|
||||||
|
|
||||||
if (fromSrc.cellInfo[q.X, q.Y].Seen && fromSrc.cellInfo[q.X, q.Y].MinCost < float.PositiveInfinity)
|
if (fromSrc.cellInfo[q.X, q.Y].Seen && fromSrc.cellInfo[q.X, q.Y].MinCost < float.PositiveInfinity)
|
||||||
return MakeBidiPath(fromSrc, fromDest, q);
|
return MakeBidiPath(fromSrc, fromDest, q);
|
||||||
|
|||||||
@@ -34,12 +34,12 @@ namespace OpenRa
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int2 Expand( float[][ , ] passableCost )
|
public int2 Expand( World world, float[][ , ] passableCost )
|
||||||
{
|
{
|
||||||
var p = queue.Pop();
|
var p = queue.Pop();
|
||||||
cellInfo[ p.Location.X, p.Location.Y ].Seen = true;
|
cellInfo[ p.Location.X, p.Location.Y ].Seen = true;
|
||||||
|
|
||||||
var custom2 = Game.world.customTerrain[p.Location.X, p.Location.Y];
|
var custom2 = world.customTerrain[p.Location.X, p.Location.Y];
|
||||||
var thisCost = (custom2 != null)
|
var thisCost = (custom2 != null)
|
||||||
? custom2.GetCost(p.Location, umt)
|
? custom2.GetCost(p.Location, umt)
|
||||||
: passableCost[(int)umt][p.Location.X, p.Location.Y];
|
: passableCost[(int)umt][p.Location.X, p.Location.Y];
|
||||||
@@ -51,24 +51,24 @@ namespace OpenRa
|
|||||||
{
|
{
|
||||||
int2 newHere = p.Location + d;
|
int2 newHere = p.Location + d;
|
||||||
|
|
||||||
if (!Game.world.Map.IsInMap(newHere.X, newHere.Y)) continue;
|
if (!world.Map.IsInMap(newHere.X, newHere.Y)) continue;
|
||||||
if( cellInfo[ newHere.X, newHere.Y ].Seen )
|
if( cellInfo[ newHere.X, newHere.Y ].Seen )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var custom = Game.world.customTerrain[newHere.X, newHere.Y];
|
var custom = world.customTerrain[newHere.X, newHere.Y];
|
||||||
var costHere = (custom != null) ? custom.GetCost(newHere, umt) : passableCost[(int)umt][newHere.X, newHere.Y];
|
var costHere = (custom != null) ? custom.GetCost(newHere, umt) : passableCost[(int)umt][newHere.X, newHere.Y];
|
||||||
|
|
||||||
if (costHere == float.PositiveInfinity)
|
if (costHere == float.PositiveInfinity)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!Game.world.BuildingInfluence.CanMoveHere(newHere) &&
|
if (!world.BuildingInfluence.CanMoveHere(newHere) &&
|
||||||
Game.world.BuildingInfluence.GetBuildingAt(newHere) != ignoreBuilding)
|
world.BuildingInfluence.GetBuildingAt(newHere) != ignoreBuilding)
|
||||||
continue;
|
continue;
|
||||||
if (Game.world.Map.IsOverlaySolid(newHere))
|
if (world.Map.IsOverlaySolid(newHere))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Replicate real-ra behavior of not being able to enter a cell if there is a mixture of crushable and uncrushable units
|
// Replicate real-ra behavior of not being able to enter a cell if there is a mixture of crushable and uncrushable units
|
||||||
if (checkForBlocked && (Game.world.UnitInfluence.GetUnitsAt(newHere).Any(a => !Game.world.IsActorPathableToCrush(a, umt))))
|
if (checkForBlocked && (world.UnitInfluence.GetUnitsAt(newHere).Any(a => !world.IsActorPathableToCrush(a, umt))))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (customBlock != null && customBlock(newHere))
|
if (customBlock != null && customBlock(newHere))
|
||||||
@@ -93,27 +93,27 @@ namespace OpenRa
|
|||||||
return p.Location;
|
return p.Location;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddInitialCell( int2 location )
|
public void AddInitialCell( World world, int2 location )
|
||||||
{
|
{
|
||||||
if (!Game.world.Map.IsInMap(location.X, location.Y))
|
if (!world.Map.IsInMap(location.X, location.Y))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
cellInfo[ location.X, location.Y ] = new CellInfo( 0, location, false );
|
cellInfo[ location.X, location.Y ] = new CellInfo( 0, location, false );
|
||||||
queue.Add( new PathDistance( heuristic( location ), location ) );
|
queue.Add( new PathDistance( heuristic( location ), location ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PathSearch FromPoint( int2 from, int2 target, UnitMovementType umt, bool checkForBlocked )
|
public static PathSearch FromPoint( World world, int2 from, int2 target, UnitMovementType umt, bool checkForBlocked )
|
||||||
{
|
{
|
||||||
var search = new PathSearch {
|
var search = new PathSearch {
|
||||||
heuristic = DefaultEstimator( target ),
|
heuristic = DefaultEstimator( target ),
|
||||||
umt = umt,
|
umt = umt,
|
||||||
checkForBlocked = checkForBlocked };
|
checkForBlocked = checkForBlocked };
|
||||||
|
|
||||||
search.AddInitialCell( from );
|
search.AddInitialCell( world, from );
|
||||||
return search;
|
return search;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PathSearch FromPoints(IEnumerable<int2> froms, int2 target, UnitMovementType umt, bool checkForBlocked)
|
public static PathSearch FromPoints(World world, IEnumerable<int2> froms, int2 target, UnitMovementType umt, bool checkForBlocked)
|
||||||
{
|
{
|
||||||
var search = new PathSearch
|
var search = new PathSearch
|
||||||
{
|
{
|
||||||
@@ -123,7 +123,7 @@ namespace OpenRa
|
|||||||
};
|
};
|
||||||
|
|
||||||
foreach (var sl in froms)
|
foreach (var sl in froms)
|
||||||
search.AddInitialCell(sl);
|
search.AddInitialCell(world, sl);
|
||||||
|
|
||||||
return search;
|
return search;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ namespace OpenRa
|
|||||||
public int PowerProvided = 0;
|
public int PowerProvided = 0;
|
||||||
public int PowerDrained = 0;
|
public int PowerDrained = 0;
|
||||||
|
|
||||||
|
public World World { get { return PlayerActor.World; } }
|
||||||
|
|
||||||
public Shroud Shroud;
|
public Shroud Shroud;
|
||||||
public Dictionary<string, SupportPower> SupportPowers;
|
public Dictionary<string, SupportPower> SupportPowers;
|
||||||
|
|
||||||
@@ -52,7 +54,7 @@ namespace OpenRa
|
|||||||
PowerProvided = 0;
|
PowerProvided = 0;
|
||||||
PowerDrained = 0;
|
PowerDrained = 0;
|
||||||
|
|
||||||
var myBuildings = Game.world.Actors
|
var myBuildings = World.Actors
|
||||||
.Where(a => a.Owner == this && a.traits.Contains<Building>());
|
.Where(a => a.Owner == this && a.traits.Contains<Building>());
|
||||||
|
|
||||||
foreach (var a in myBuildings)
|
foreach (var a in myBuildings)
|
||||||
@@ -83,7 +85,7 @@ namespace OpenRa
|
|||||||
|
|
||||||
void UpdateOreCapacity()
|
void UpdateOreCapacity()
|
||||||
{
|
{
|
||||||
OreCapacity = Game.world.Actors
|
OreCapacity = World.Actors
|
||||||
.Where(a => a.Owner == this && a.traits.Contains<StoresOre>())
|
.Where(a => a.Owner == this && a.traits.Contains<StoresOre>())
|
||||||
.Select(a => a.Info.Traits.Get<StoresOreInfo>())
|
.Select(a => a.Info.Traits.Get<StoresOreInfo>())
|
||||||
.Sum(b => b.Capacity);
|
.Sum(b => b.Capacity);
|
||||||
@@ -91,7 +93,7 @@ namespace OpenRa
|
|||||||
|
|
||||||
void GiveAdvice(string advice)
|
void GiveAdvice(string advice)
|
||||||
{
|
{
|
||||||
if (this != Game.world.LocalPlayer) return;
|
if (this != World.LocalPlayer) return;
|
||||||
// todo: store the condition or something.
|
// todo: store the condition or something.
|
||||||
// repeat after Rules.General.SpeakDelay, as long as the condition holds.
|
// repeat after Rules.General.SpeakDelay, as long as the condition holds.
|
||||||
Sound.Play(advice);
|
Sound.Play(advice);
|
||||||
@@ -130,12 +132,12 @@ namespace OpenRa
|
|||||||
{
|
{
|
||||||
UpdatePower();
|
UpdatePower();
|
||||||
UpdateOreCapacity();
|
UpdateOreCapacity();
|
||||||
Shroud.Tick();
|
Shroud.Tick( World );
|
||||||
|
|
||||||
foreach (var sp in SupportPowers.Values)
|
foreach (var sp in SupportPowers.Values)
|
||||||
sp.Tick();
|
sp.Tick();
|
||||||
|
|
||||||
if (this == Game.world.LocalPlayer)
|
if (this == World.LocalPlayer)
|
||||||
{
|
{
|
||||||
var totalMoney = Cash + Ore;
|
var totalMoney = Cash + Ore;
|
||||||
|
|
||||||
|
|||||||
@@ -29,11 +29,11 @@ namespace OpenRa
|
|||||||
set { hasGPS = value; dirty = true;}
|
set { hasGPS = value; dirty = true;}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick()
|
public void Tick( World world )
|
||||||
{
|
{
|
||||||
// Clear active flags
|
// Clear active flags
|
||||||
gapActive = new bool[128, 128];
|
gapActive = new bool[128, 128];
|
||||||
foreach (var a in Game.world.Actors.Where(a => a.traits.Contains<GeneratesGap>() && owner != a.Owner))
|
foreach (var a in world.Actors.Where(a => a.traits.Contains<GeneratesGap>() && owner != a.Owner))
|
||||||
{
|
{
|
||||||
foreach (var t in a.traits.Get<GeneratesGap>().GetShroudedTiles())
|
foreach (var t in a.traits.Get<GeneratesGap>().GetShroudedTiles())
|
||||||
gapActive[t.X, t.Y] = true;
|
gapActive[t.X, t.Y] = true;
|
||||||
@@ -81,7 +81,7 @@ namespace OpenRa
|
|||||||
|
|
||||||
public void Explore(Actor a)
|
public void Explore(Actor a)
|
||||||
{
|
{
|
||||||
foreach (var t in Game.world.FindTilesInCircle(
|
foreach (var t in a.World.FindTilesInCircle(
|
||||||
(1f / Game.CellSize * a.CenterLocation).ToInt2(),
|
(1f / Game.CellSize * a.CenterLocation).ToInt2(),
|
||||||
a.Info.Traits.Get<OwnedActorInfo>().Sight))
|
a.Info.Traits.Get<OwnedActorInfo>().Sight))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using OpenRa.GameRules;
|
using OpenRa.GameRules;
|
||||||
|
using OpenRa.FileFormats;
|
||||||
|
|
||||||
namespace OpenRa
|
namespace OpenRa
|
||||||
{
|
{
|
||||||
@@ -8,11 +9,11 @@ namespace OpenRa
|
|||||||
const int firstCrater = 17;
|
const int firstCrater = 17;
|
||||||
const int framesPerCrater = 5;
|
const int framesPerCrater = 5;
|
||||||
|
|
||||||
public static void AddSmudge(bool isCrater, int x, int y)
|
public static void AddSmudge(this Map map, bool isCrater, int x, int y)
|
||||||
{
|
{
|
||||||
var smudge = Game.world.Map.MapTiles[x, y].smudge;
|
var smudge = map.MapTiles[x, y].smudge;
|
||||||
if (smudge == 0)
|
if (smudge == 0)
|
||||||
Game.world.Map.MapTiles[x, y].smudge = (byte) (isCrater
|
map.MapTiles[x, y].smudge = (byte) (isCrater
|
||||||
? (firstCrater + framesPerCrater * ChooseSmudge())
|
? (firstCrater + framesPerCrater * ChooseSmudge())
|
||||||
: (firstScorch + ChooseSmudge()));
|
: (firstScorch + ChooseSmudge()));
|
||||||
|
|
||||||
@@ -21,21 +22,21 @@ namespace OpenRa
|
|||||||
/* deepen the crater */
|
/* deepen the crater */
|
||||||
var amount = (smudge - firstCrater) % framesPerCrater;
|
var amount = (smudge - firstCrater) % framesPerCrater;
|
||||||
if (amount < framesPerCrater - 1)
|
if (amount < framesPerCrater - 1)
|
||||||
Game.world.Map.MapTiles[x, y].smudge++;
|
map.MapTiles[x, y].smudge++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AddSmudge(int2 targetTile, WarheadInfo warhead)
|
public static void AddSmudge(this Map map, int2 targetTile, WarheadInfo warhead)
|
||||||
{
|
{
|
||||||
switch (warhead.Explosion) /* todo: push the scorch/crater behavior into data */
|
switch (warhead.Explosion) /* todo: push the scorch/crater behavior into data */
|
||||||
{
|
{
|
||||||
case 4:
|
case 4:
|
||||||
case 5:
|
case 5:
|
||||||
Smudge.AddSmudge(true, targetTile.X, targetTile.Y);
|
map.AddSmudge(true, targetTile.X, targetTile.Y);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
case 6:
|
case 6:
|
||||||
Smudge.AddSmudge(false, targetTile.X, targetTile.Y);
|
map.AddSmudge(false, targetTile.X, targetTile.Y);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,12 +20,12 @@ namespace OpenRa.SupportPowers
|
|||||||
Sound.Play("chrono2.aud");
|
Sound.Play("chrono2.aud");
|
||||||
|
|
||||||
// Play chronosphere active anim
|
// Play chronosphere active anim
|
||||||
var chronosphere = Game.world.Actors.Where(a => a.Owner == p.Owner && a.traits.Contains<Chronosphere>()).FirstOrDefault();
|
var chronosphere = target.World.Actors.Where(a => a.Owner == p.Owner && a.traits.Contains<Chronosphere>()).FirstOrDefault();
|
||||||
if (chronosphere != null)
|
if (chronosphere != null)
|
||||||
Game.controller.AddOrder(Order.PlayAnimation(chronosphere, "active"));
|
Game.controller.AddOrder(Order.PlayAnimation(chronosphere, "active"));
|
||||||
|
|
||||||
// Trigger screen desaturate effect
|
// Trigger screen desaturate effect
|
||||||
foreach (var a in Game.world.Actors.Where(a => a.traits.Contains<ChronoshiftPaletteEffect>()))
|
foreach (var a in target.World.Actors.Where(a => a.traits.Contains<ChronoshiftPaletteEffect>()))
|
||||||
a.traits.Get<ChronoshiftPaletteEffect>().DoChronoshift();
|
a.traits.Get<ChronoshiftPaletteEffect>().DoChronoshift();
|
||||||
}
|
}
|
||||||
SupportPower p;
|
SupportPower p;
|
||||||
|
|||||||
@@ -12,13 +12,13 @@ namespace OpenRa.SupportPowers
|
|||||||
public void IsChargingNotification(SupportPower p) { }
|
public void IsChargingNotification(SupportPower p) { }
|
||||||
public void IsReadyNotification(SupportPower p)
|
public void IsReadyNotification(SupportPower p)
|
||||||
{
|
{
|
||||||
var launchSite = Game.world.Actors
|
var launchSite = p.Owner.World.Actors
|
||||||
.FirstOrDefault(a => a.Owner == p.Owner && a.traits.Contains<GpsLaunchSite>());
|
.FirstOrDefault(a => a.Owner == p.Owner && a.traits.Contains<GpsLaunchSite>());
|
||||||
|
|
||||||
if (launchSite == null)
|
if (launchSite == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Game.world.AddFrameEndTask(w =>
|
p.Owner.World.AddFrameEndTask(w =>
|
||||||
{
|
{
|
||||||
w.Add(new SatelliteLaunch(launchSite));
|
w.Add(new SatelliteLaunch(launchSite));
|
||||||
w.Add(new DelayedAction(revealDelay, () => p.Owner.Shroud.HasGPS = true));
|
w.Add(new DelayedAction(revealDelay, () => p.Owner.Shroud.HasGPS = true));
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ namespace OpenRa.SupportPowers
|
|||||||
Sound.Play("ironcur9.aud");
|
Sound.Play("ironcur9.aud");
|
||||||
|
|
||||||
// Play active anim
|
// Play active anim
|
||||||
var ironCurtain = Game.world.Actors
|
var ironCurtain = target.World.Actors
|
||||||
.Where(a => a.Owner == p.Owner && a.traits.Contains<IronCurtain>())
|
.Where(a => a.Owner == p.Owner && a.traits.Contains<IronCurtain>())
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
if (ironCurtain != null)
|
if (ironCurtain != null)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace OpenRa.Traits
|
|||||||
{
|
{
|
||||||
public AcceptsOre(Actor self)
|
public AcceptsOre(Actor self)
|
||||||
{
|
{
|
||||||
Game.world.AddFrameEndTask(
|
self.World.AddFrameEndTask(
|
||||||
w =>
|
w =>
|
||||||
{ /* create the free harvester! */
|
{ /* create the free harvester! */
|
||||||
var harvester = w.CreateActor("harv", self.Location + new int2(1, 2), self.Owner);
|
var harvester = w.CreateActor("harv", self.Location + new int2(1, 2), self.Owner);
|
||||||
|
|||||||
@@ -42,15 +42,15 @@ namespace OpenRa.Traits.Activities
|
|||||||
umt = mobile.GetMovementType(),
|
umt = mobile.GetMovementType(),
|
||||||
checkForBlocked = false,
|
checkForBlocked = false,
|
||||||
};
|
};
|
||||||
var refineries = Game.world.Actors.Where( x => x.traits.Contains<AcceptsOre>()
|
var refineries = self.World.Actors.Where( x => x.traits.Contains<AcceptsOre>()
|
||||||
&& x.Owner == self.Owner ).ToList();
|
&& x.Owner == self.Owner ).ToList();
|
||||||
if( refinery != null )
|
if( refinery != null )
|
||||||
search.AddInitialCell( refinery.Location + refineryDeliverOffset );
|
search.AddInitialCell( self.World, refinery.Location + refineryDeliverOffset );
|
||||||
else
|
else
|
||||||
foreach( var r in refineries )
|
foreach( var r in refineries )
|
||||||
search.AddInitialCell( r.Location + refineryDeliverOffset );
|
search.AddInitialCell( self.World, r.Location + refineryDeliverOffset );
|
||||||
|
|
||||||
var path = Game.world.PathFinder.FindPath( search );
|
var path = self.World.PathFinder.FindPath( search );
|
||||||
path.Reverse();
|
path.Reverse();
|
||||||
if( path.Count != 0 )
|
if( path.Count != 0 )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,16 +8,16 @@ namespace OpenRa.Traits.Activities
|
|||||||
|
|
||||||
public IActivity Tick( Actor self )
|
public IActivity Tick( Actor self )
|
||||||
{
|
{
|
||||||
Game.world.AddFrameEndTask( _ =>
|
self.World.AddFrameEndTask( _ =>
|
||||||
{
|
{
|
||||||
self.Health = 0;
|
self.Health = 0;
|
||||||
Game.world.Remove( self );
|
self.World.Remove( self );
|
||||||
if (self.Owner == Game.world.LocalPlayer)
|
if (self.Owner == self.World.LocalPlayer)
|
||||||
{
|
{
|
||||||
Sound.Play("placbldg.aud");
|
Sound.Play("placbldg.aud");
|
||||||
Sound.Play("build5.aud");
|
Sound.Play("build5.aud");
|
||||||
}
|
}
|
||||||
Game.world.CreateActor( "fact", self.Location - new int2( 1, 1 ), self.Owner );
|
self.World.CreateActor( "fact", self.Location - new int2( 1, 1 ), self.Owner );
|
||||||
} );
|
} );
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ namespace OpenRa.Traits.Activities
|
|||||||
return NextActivity;
|
return NextActivity;
|
||||||
|
|
||||||
cargo.Load(transport, self);
|
cargo.Load(transport, self);
|
||||||
Game.world.AddFrameEndTask(w => w.Remove(self));
|
self.World.AddFrameEndTask(w => w.Remove(self));
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ namespace OpenRa.Traits.Activities
|
|||||||
var renderUnit = self.traits.Get<RenderUnit>(); /* better have one of these! */
|
var renderUnit = self.traits.Get<RenderUnit>(); /* better have one of these! */
|
||||||
|
|
||||||
var isGem = false;
|
var isGem = false;
|
||||||
if (!Game.world.Map.ContainsResource(self.Location) ||
|
if (!self.World.Map.ContainsResource(self.Location) ||
|
||||||
!Game.world.Map.Harvest(self.Location, out isGem))
|
!self.World.Map.Harvest(self.Location, out isGem))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var harvestAnim = "harvest" + Util.QuantizeFacing(unit.Facing, 8);
|
var harvestAnim = "harvest" + Util.QuantizeFacing(unit.Facing, 8);
|
||||||
@@ -58,12 +58,12 @@ namespace OpenRa.Traits.Activities
|
|||||||
{
|
{
|
||||||
var search = new PathSearch
|
var search = new PathSearch
|
||||||
{
|
{
|
||||||
heuristic = loc => (Game.world.Map.ContainsResource(loc) ? 0 : 1),
|
heuristic = loc => (self.World.Map.ContainsResource(loc) ? 0 : 1),
|
||||||
umt = UnitMovementType.Wheel,
|
umt = UnitMovementType.Wheel,
|
||||||
checkForBlocked = true
|
checkForBlocked = true
|
||||||
};
|
};
|
||||||
search.AddInitialCell(self.Location);
|
search.AddInitialCell(self.World, self.Location);
|
||||||
return Game.world.PathFinder.FindPath(search);
|
return self.World.PathFinder.FindPath(search);
|
||||||
}));
|
}));
|
||||||
self.QueueActivity(new Harvest());
|
self.QueueActivity(new Harvest());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ namespace OpenRa.Traits.Activities
|
|||||||
if (unit.Altitude == 0)
|
if (unit.Altitude == 0)
|
||||||
return NextActivity;
|
return NextActivity;
|
||||||
|
|
||||||
if (requireSpace && !Game.world.IsCellBuildable(self.Location, UnitMovementType.Foot))
|
if (requireSpace && !self.World.IsCellBuildable(self.Location, UnitMovementType.Foot))
|
||||||
return this; // fail to land if no space
|
return this; // fail to land if no space
|
||||||
|
|
||||||
--unit.Altitude;
|
--unit.Altitude;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace OpenRa.Traits.Activities
|
|||||||
|
|
||||||
static Actor ChooseHelipad(Actor self)
|
static Actor ChooseHelipad(Actor self)
|
||||||
{
|
{
|
||||||
return Game.world.Actors.FirstOrDefault(
|
return self.World.Actors.FirstOrDefault(
|
||||||
a => a.Info.Name == "hpad" &&
|
a => a.Info.Name == "hpad" &&
|
||||||
a.Owner == self.Owner &&
|
a.Owner == self.Owner &&
|
||||||
!Reservable.IsReserved(a));
|
!Reservable.IsReserved(a));
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ namespace OpenRa.Traits.Activities
|
|||||||
|
|
||||||
public Move( int2 destination, int nearEnough )
|
public Move( int2 destination, int nearEnough )
|
||||||
{
|
{
|
||||||
this.getPath = ( self, mobile ) => Game.world.PathFinder.FindUnitPath(
|
this.getPath = ( self, mobile ) => self.World.PathFinder.FindUnitPath(
|
||||||
self.Location, destination,
|
self.Location, destination,
|
||||||
mobile.GetMovementType() );
|
mobile.GetMovementType() );
|
||||||
this.destination = destination;
|
this.destination = destination;
|
||||||
@@ -30,9 +30,9 @@ namespace OpenRa.Traits.Activities
|
|||||||
public Move(int2 destination, Actor ignoreBuilding)
|
public Move(int2 destination, Actor ignoreBuilding)
|
||||||
{
|
{
|
||||||
this.getPath = (self, mobile) =>
|
this.getPath = (self, mobile) =>
|
||||||
Game.world.PathFinder.FindPath(
|
self.World.PathFinder.FindPath(
|
||||||
PathSearch.FromPoint( self.Location, destination, mobile.GetMovementType(), false )
|
PathSearch.FromPoint( self.World, self.Location, destination, mobile.GetMovementType(), false )
|
||||||
.WithCustomBlocker( Game.world.PathFinder.AvoidUnitsNear( self.Location, 4 )).WithIgnoredBuilding( ignoreBuilding ));
|
.WithCustomBlocker( self.World.PathFinder.AvoidUnitsNear( self.Location, 4 )).WithIgnoredBuilding( ignoreBuilding ));
|
||||||
|
|
||||||
this.destination = destination;
|
this.destination = destination;
|
||||||
this.nearEnough = 0;
|
this.nearEnough = 0;
|
||||||
@@ -41,7 +41,7 @@ namespace OpenRa.Traits.Activities
|
|||||||
|
|
||||||
public Move( Actor target, int range )
|
public Move( Actor target, int range )
|
||||||
{
|
{
|
||||||
this.getPath = ( self, mobile ) => Game.world.PathFinder.FindUnitPathToRange(
|
this.getPath = ( self, mobile ) => self.World.PathFinder.FindUnitPathToRange(
|
||||||
self.Location, target.Location,
|
self.Location, target.Location,
|
||||||
mobile.GetMovementType(), range );
|
mobile.GetMovementType(), range );
|
||||||
this.destination = null;
|
this.destination = null;
|
||||||
@@ -57,13 +57,13 @@ namespace OpenRa.Traits.Activities
|
|||||||
|
|
||||||
bool CanEnterCell( int2 c, Actor self )
|
bool CanEnterCell( int2 c, Actor self )
|
||||||
{
|
{
|
||||||
if (!Game.world.BuildingInfluence.CanMoveHere(c)
|
if (!self.World.BuildingInfluence.CanMoveHere(c)
|
||||||
&& Game.world.BuildingInfluence.GetBuildingAt(c) != ignoreBuilding)
|
&& self.World.BuildingInfluence.GetBuildingAt(c) != ignoreBuilding)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Cannot enter a cell if any unit inside is uncrushable
|
// Cannot enter a cell if any unit inside is uncrushable
|
||||||
// This will need to be updated for multiple-infantry-in-a-cell
|
// This will need to be updated for multiple-infantry-in-a-cell
|
||||||
return (!Game.world.UnitInfluence.GetUnitsAt(c).Any(a => a != self && !Game.world.IsActorCrushableByActor(a, self)));
|
return (!self.World.UnitInfluence.GetUnitsAt(c).Any(a => a != self && !self.World.IsActorCrushableByActor(a, self)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public IActivity Tick( Actor self )
|
public IActivity Tick( Actor self )
|
||||||
@@ -144,10 +144,10 @@ namespace OpenRa.Traits.Activities
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Game.world.UnitInfluence.Remove( self, mobile );
|
self.World.UnitInfluence.Remove( self, mobile );
|
||||||
var newPath = getPath(self, mobile).TakeWhile(a => a != self.Location).ToList();
|
var newPath = getPath(self, mobile).TakeWhile(a => a != self.Location).ToList();
|
||||||
|
|
||||||
Game.world.UnitInfluence.Add( self, mobile );
|
self.World.UnitInfluence.Add( self, mobile );
|
||||||
if (newPath.Count != 0)
|
if (newPath.Count != 0)
|
||||||
path = newPath;
|
path = newPath;
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ namespace OpenRa.Traits.Activities
|
|||||||
{
|
{
|
||||||
if (!limitedAmmo.GiveAmmo()) return NextActivity;
|
if (!limitedAmmo.GiveAmmo()) return NextActivity;
|
||||||
|
|
||||||
var hostBuilding = Game.world.FindUnits(self.CenterLocation, self.CenterLocation)
|
var hostBuilding = self.World.FindUnits(self.CenterLocation, self.CenterLocation)
|
||||||
.FirstOrDefault(a => a.traits.Contains<RenderBuilding>());
|
.FirstOrDefault(a => a.traits.Contains<RenderBuilding>());
|
||||||
|
|
||||||
if (hostBuilding != null)
|
if (hostBuilding != null)
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ namespace OpenRa.Traits.Activities
|
|||||||
if (self.Health == hp)
|
if (self.Health == hp)
|
||||||
return NextActivity;
|
return NextActivity;
|
||||||
|
|
||||||
var hostBuilding = Game.world.FindUnits(self.CenterLocation, self.CenterLocation)
|
var hostBuilding = self.World.FindUnits(self.CenterLocation, self.CenterLocation)
|
||||||
.FirstOrDefault(a => a.traits.Contains<RenderBuilding>());
|
.FirstOrDefault(a => a.traits.Contains<RenderBuilding>());
|
||||||
|
|
||||||
if (hostBuilding != null)
|
if (hostBuilding != null)
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace OpenRa.Traits.Activities
|
|||||||
|
|
||||||
Actor ChooseAirfield(Actor self)
|
Actor ChooseAirfield(Actor self)
|
||||||
{
|
{
|
||||||
var airfield = Game.world.Actors
|
var airfield = self.World.Actors
|
||||||
.Where(a => a.Info.Name == "afld"
|
.Where(a => a.Info.Name == "afld"
|
||||||
&& a.Owner == self.Owner
|
&& a.Owner == self.Owner
|
||||||
&& !Reservable.IsReserved(a))
|
&& !Reservable.IsReserved(a))
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ namespace OpenRa.Traits.Activities
|
|||||||
self.Health = 0;
|
self.Health = 0;
|
||||||
foreach (var ns in self.traits.WithInterface<INotifySold>())
|
foreach (var ns in self.traits.WithInterface<INotifySold>())
|
||||||
ns.Sold(self);
|
ns.Sold(self);
|
||||||
Game.world.AddFrameEndTask( _ => Game.world.Remove( self ) );
|
self.World.AddFrameEndTask( _ => self.World.Remove( self ) );
|
||||||
|
|
||||||
// todo: give dudes
|
// todo: give dudes
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace OpenRa.Traits.Activities
|
|||||||
{
|
{
|
||||||
var rb = self.traits.Get<RenderBuilding>();
|
var rb = self.traits.Get<RenderBuilding>();
|
||||||
rb.PlayCustomAnimBackwards(self, "make",
|
rb.PlayCustomAnimBackwards(self, "make",
|
||||||
() => Game.world.AddFrameEndTask(w => DoUndeploy(w,self)));
|
() => self.World.AddFrameEndTask(w => DoUndeploy(w,self)));
|
||||||
|
|
||||||
Sound.Play("cashturn.aud");
|
Sound.Play("cashturn.aud");
|
||||||
started = true;
|
started = true;
|
||||||
|
|||||||
@@ -13,13 +13,13 @@ namespace OpenRa.Traits.Activities
|
|||||||
int2? ChooseExitTile(Actor self)
|
int2? ChooseExitTile(Actor self)
|
||||||
{
|
{
|
||||||
// is anyone still hogging this tile?
|
// is anyone still hogging this tile?
|
||||||
if (Game.world.UnitInfluence.GetUnitsAt(self.Location).Count() > 1)
|
if (self.World.UnitInfluence.GetUnitsAt(self.Location).Count() > 1)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
for (var i = -1; i < 2; i++)
|
for (var i = -1; i < 2; i++)
|
||||||
for (var j = -1; j < 2; j++)
|
for (var j = -1; j < 2; j++)
|
||||||
if ((i != 0 || j != 0) &&
|
if ((i != 0 || j != 0) &&
|
||||||
Game.world.IsCellBuildable(self.Location + new int2(i, j),
|
self.World.IsCellBuildable(self.Location + new int2(i, j),
|
||||||
UnitMovementType.Foot))
|
UnitMovementType.Foot))
|
||||||
return self.Location + new int2(i, j);
|
return self.Location + new int2(i, j);
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ namespace OpenRa.Traits.Activities
|
|||||||
|
|
||||||
var actor = cargo.Unload(self);
|
var actor = cargo.Unload(self);
|
||||||
|
|
||||||
Game.world.AddFrameEndTask(w =>
|
self.World.AddFrameEndTask(w =>
|
||||||
{
|
{
|
||||||
w.Add(actor);
|
w.Add(actor);
|
||||||
actor.traits.Get<Mobile>().TeleportTo(actor, self.Location);
|
actor.traits.Get<Mobile>().TeleportTo(actor, self.Location);
|
||||||
|
|||||||
@@ -150,18 +150,18 @@ namespace OpenRa.Traits
|
|||||||
var destAltitude = destUnit != null ? destUnit.Altitude : 0;
|
var destAltitude = destUnit != null ? destUnit.Altitude : 0;
|
||||||
|
|
||||||
if( weapon.RenderAsTesla )
|
if( weapon.RenderAsTesla )
|
||||||
Game.world.Add( new TeslaZap( firePos, thisTarget.CenterLocation.ToInt2() ) );
|
self.World.Add( new TeslaZap( firePos, thisTarget.CenterLocation.ToInt2() ) );
|
||||||
|
|
||||||
if (Rules.ProjectileInfo[weapon.Projectile].ROT != 0)
|
if (Rules.ProjectileInfo[weapon.Projectile].ROT != 0)
|
||||||
{
|
{
|
||||||
var fireFacing = thisLocalOffset.ElementAtOrDefault(2) +
|
var fireFacing = thisLocalOffset.ElementAtOrDefault(2) +
|
||||||
(self.traits.Contains<Turreted>() ? self.traits.Get<Turreted>().turretFacing : unit.Facing);
|
(self.traits.Contains<Turreted>() ? self.traits.Get<Turreted>().turretFacing : unit.Facing);
|
||||||
|
|
||||||
Game.world.Add(new Missile(weapon, self.Owner, self,
|
self.World.Add(new Missile(weapon, self.Owner, self,
|
||||||
firePos, thisTarget, srcAltitude, fireFacing));
|
firePos, thisTarget, srcAltitude, fireFacing));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Game.world.Add(new Bullet(weapon, self.Owner, self,
|
self.World.Add(new Bullet(weapon, self.Owner, self,
|
||||||
firePos, thisTarget.CenterLocation.ToInt2(), srcAltitude, destAltitude));
|
firePos, thisTarget.CenterLocation.ToInt2(), srcAltitude, destAltitude));
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(weapon.Report))
|
if (!string.IsNullOrEmpty(weapon.Report))
|
||||||
@@ -205,8 +205,8 @@ namespace OpenRa.Traits
|
|||||||
self.CancelActivity();
|
self.CancelActivity();
|
||||||
QueueAttack(self, order);
|
QueueAttack(self, order);
|
||||||
|
|
||||||
if (self.Owner == Game.world.LocalPlayer)
|
if (self.Owner == self.World.LocalPlayer)
|
||||||
Game.world.AddFrameEndTask(w => w.Add(new FlashTarget(order.TargetActor)));
|
self.World.AddFrameEndTask(w => w.Add(new FlashTarget(order.TargetActor)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
target = null;
|
target = null;
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ namespace OpenRa.Traits
|
|||||||
|
|
||||||
Actor ChooseTarget(Actor self, float range)
|
Actor ChooseTarget(Actor self, float range)
|
||||||
{
|
{
|
||||||
var inRange = Game.world.FindUnitsInCircle(self.CenterLocation, Game.CellSize * range);
|
var inRange = self.World.FindUnitsInCircle(self.CenterLocation, Game.CellSize * range);
|
||||||
|
|
||||||
return inRange
|
return inRange
|
||||||
.Where(a => a.Owner == self.Owner && a != self) /* todo: one day deal with friendly players */
|
.Where(a => a.Owner == self.Owner && a != self) /* todo: one day deal with friendly players */
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ namespace OpenRa.Traits
|
|||||||
|
|
||||||
Actor ChooseTarget(Actor self, float range)
|
Actor ChooseTarget(Actor self, float range)
|
||||||
{
|
{
|
||||||
var inRange = Game.world.FindUnitsInCircle(self.CenterLocation, Game.CellSize * range);
|
var inRange = self.World.FindUnitsInCircle(self.CenterLocation, Game.CellSize * range);
|
||||||
|
|
||||||
return inRange
|
return inRange
|
||||||
.Where(a => a.Owner != null && a.Owner != self.Owner) /* todo: one day deal with friendly players */
|
.Where(a => a.Owner != null && a.Owner != self.Owner) /* todo: one day deal with friendly players */
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ namespace OpenRa.Traits
|
|||||||
// If the disabled state has changed since the last frame
|
// If the disabled state has changed since the last frame
|
||||||
if (Disabled ^ wasDisabled
|
if (Disabled ^ wasDisabled
|
||||||
&& (wasDisabled = Disabled)) // Yes, I mean assignment
|
&& (wasDisabled = Disabled)) // Yes, I mean assignment
|
||||||
Game.world.AddFrameEndTask(w => w.Add(new PowerDownIndicator(self)));
|
self.World.AddFrameEndTask(w => w.Add(new PowerDownIndicator(self)));
|
||||||
|
|
||||||
if (!isRepairing) return;
|
if (!isRepairing) return;
|
||||||
|
|
||||||
@@ -113,7 +113,7 @@ namespace OpenRa.Traits
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Game.world.AddFrameEndTask(w => w.Add(new RepairIndicator(self)));
|
self.World.AddFrameEndTask(w => w.Add(new RepairIndicator(self)));
|
||||||
self.InflictDamage(self, -hpToRepair, Rules.WarheadInfo["Super"]);
|
self.InflictDamage(self, -hpToRepair, Rules.WarheadInfo["Super"]);
|
||||||
if (self.Health == maxHP)
|
if (self.Health == maxHP)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ namespace OpenRa.Traits
|
|||||||
if (remainingUncloakTime > 0)
|
if (remainingUncloakTime > 0)
|
||||||
return rs;
|
return rs;
|
||||||
|
|
||||||
if (self.Owner == Game.world.LocalPlayer)
|
if (self.Owner == self.World.LocalPlayer)
|
||||||
return rs.Select(a => a.WithPalette(PaletteType.Shadow));
|
return rs.Select(a => a.WithPalette(PaletteType.Shadow));
|
||||||
else
|
else
|
||||||
return new Renderable[] { };
|
return new Renderable[] { };
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ namespace OpenRa.Traits
|
|||||||
{
|
{
|
||||||
// force-move
|
// force-move
|
||||||
if (!mi.Modifiers.HasModifier(Modifiers.Alt)) return null;
|
if (!mi.Modifiers.HasModifier(Modifiers.Alt)) return null;
|
||||||
if (!Game.world.IsActorCrushableByActor(underCursor, self)) return null;
|
if (!self.World.IsActorCrushableByActor(underCursor, self)) return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Order("Move", self, null, xy, null);
|
return new Order("Move", self, null, xy, null);
|
||||||
@@ -50,14 +50,14 @@ namespace OpenRa.Traits
|
|||||||
|
|
||||||
public bool CanEnterCell(int2 a)
|
public bool CanEnterCell(int2 a)
|
||||||
{
|
{
|
||||||
if (!Game.world.BuildingInfluence.CanMoveHere(a)) return false;
|
if (!self.World.BuildingInfluence.CanMoveHere(a)) return false;
|
||||||
|
|
||||||
var crushable = true;
|
var crushable = true;
|
||||||
foreach (Actor actor in Game.world.UnitInfluence.GetUnitsAt(a))
|
foreach (Actor actor in self.World.UnitInfluence.GetUnitsAt(a))
|
||||||
{
|
{
|
||||||
if (actor == self) continue;
|
if (actor == self) continue;
|
||||||
|
|
||||||
if (!Game.world.IsActorCrushableByActor(actor, self))
|
if (!self.World.IsActorCrushableByActor(actor, self))
|
||||||
{
|
{
|
||||||
crushable = false;
|
crushable = false;
|
||||||
break;
|
break;
|
||||||
@@ -66,9 +66,9 @@ namespace OpenRa.Traits
|
|||||||
|
|
||||||
if (!crushable) return false;
|
if (!crushable) return false;
|
||||||
|
|
||||||
return Game.world.Map.IsInMap(a.X, a.Y) &&
|
return self.World.Map.IsInMap(a.X, a.Y) &&
|
||||||
TerrainCosts.Cost(GetMovementType(),
|
TerrainCosts.Cost(GetMovementType(),
|
||||||
Game.world.TileSet.GetWalkability(Game.world.Map.MapTiles[a.X, a.Y])) < double.PositiveInfinity;
|
self.World.TileSet.GetWalkability(self.World.Map.MapTiles[a.X, a.Y])) < double.PositiveInfinity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace OpenRa.Traits
|
|||||||
var unit = self.traits.GetOrDefault<Unit>();
|
var unit = self.traits.GetOrDefault<Unit>();
|
||||||
var altitude = unit != null ? unit.Altitude : 0;
|
var altitude = unit != null ? unit.Altitude : 0;
|
||||||
|
|
||||||
Game.world.AddFrameEndTask(
|
self.World.AddFrameEndTask(
|
||||||
w => w.Add(new Bullet("UnitExplode", e.Attacker.Owner, e.Attacker,
|
w => w.Add(new Bullet("UnitExplode", e.Attacker.Owner, e.Attacker,
|
||||||
self.CenterLocation.ToInt2(), self.CenterLocation.ToInt2(),
|
self.CenterLocation.ToInt2(), self.CenterLocation.ToInt2(),
|
||||||
altitude, altitude)));
|
altitude, altitude)));
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace OpenRa.Traits
|
|||||||
// Gap Generator building; powered down
|
// Gap Generator building; powered down
|
||||||
return (self.traits.Contains<Building>() && self.traits.Get<Building>().Disabled)
|
return (self.traits.Contains<Building>() && self.traits.Get<Building>().Disabled)
|
||||||
? new int2[] {}
|
? new int2[] {}
|
||||||
: Game.world.FindTilesInCircle(self.Location, range);
|
: self.World.FindTilesInCircle(self.Location, range);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ namespace OpenRa.Traits
|
|||||||
&& underCursor.traits.Contains<AcceptsOre>() && !IsEmpty)
|
&& underCursor.traits.Contains<AcceptsOre>() && !IsEmpty)
|
||||||
return new Order("Deliver", self, underCursor, int2.Zero, null);
|
return new Order("Deliver", self, underCursor, int2.Zero, null);
|
||||||
|
|
||||||
if (underCursor == null && Game.world.Map.ContainsResource(xy))
|
if (underCursor == null && self.World.Map.ContainsResource(xy))
|
||||||
return new Order("Harvest", self, null, xy, null);
|
return new Order("Harvest", self, null, xy, null);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace OpenRa.Traits
|
|||||||
{
|
{
|
||||||
public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r)
|
public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r)
|
||||||
{
|
{
|
||||||
return Game.world.LocalPlayer == self.Owner
|
return self.World.LocalPlayer == self.Owner
|
||||||
? r : new Renderable[] { };
|
? r : new Renderable[] { };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ namespace OpenRa.Traits
|
|||||||
{
|
{
|
||||||
var power = self.Owner.SupportPowers[order.TargetString].Impl;
|
var power = self.Owner.SupportPowers[order.TargetString].Impl;
|
||||||
power.OnFireNotification(self, self.Location);
|
power.OnFireNotification(self, self.Location);
|
||||||
Game.world.AddFrameEndTask(w => w.Add(new InvulnEffect(self)));
|
self.World.AddFrameEndTask(w => w.Add(new InvulnEffect(self)));
|
||||||
RemainingTicks = (int)(Rules.General.IronCurtain * 60 * 25);
|
RemainingTicks = (int)(Rules.General.IronCurtain * 60 * 25);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ namespace OpenRa.Traits
|
|||||||
if( order.OrderString == "DeployMcv" )
|
if( order.OrderString == "DeployMcv" )
|
||||||
{
|
{
|
||||||
var factBuildingInfo = Rules.Info[ "fact" ].Traits.Get<BuildingInfo>();
|
var factBuildingInfo = Rules.Info[ "fact" ].Traits.Get<BuildingInfo>();
|
||||||
if( Game.world.CanPlaceBuilding( "fact", factBuildingInfo, self.Location - new int2( 1, 1 ), self ) )
|
if( self.World.CanPlaceBuilding( "fact", factBuildingInfo, self.Location - new int2( 1, 1 ), self ) )
|
||||||
{
|
{
|
||||||
self.CancelActivity();
|
self.CancelActivity();
|
||||||
self.QueueActivity( new Turn( 96 ) );
|
self.QueueActivity( new Turn( 96 ) );
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ namespace OpenRa.Traits
|
|||||||
public int2 fromCell
|
public int2 fromCell
|
||||||
{
|
{
|
||||||
get { return __fromCell; }
|
get { return __fromCell; }
|
||||||
set { Game.world.UnitInfluence.Remove(self, this); __fromCell = value; Game.world.UnitInfluence.Add(self, this); }
|
set { self.World.UnitInfluence.Remove(self, this); __fromCell = value; self.World.UnitInfluence.Add(self, this); }
|
||||||
}
|
}
|
||||||
public int2 toCell
|
public int2 toCell
|
||||||
{
|
{
|
||||||
@@ -30,11 +30,11 @@ namespace OpenRa.Traits
|
|||||||
{
|
{
|
||||||
if (self.Location != value)
|
if (self.Location != value)
|
||||||
{
|
{
|
||||||
Game.world.UnitInfluence.Remove(self, this);
|
self.World.UnitInfluence.Remove(self, this);
|
||||||
self.Location = value;
|
self.Location = value;
|
||||||
self.Owner.Shroud.Explore(self);
|
self.Owner.Shroud.Explore(self);
|
||||||
}
|
}
|
||||||
Game.world.UnitInfluence.Add(self, this);
|
self.World.UnitInfluence.Add(self, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ namespace OpenRa.Traits
|
|||||||
{
|
{
|
||||||
this.self = self;
|
this.self = self;
|
||||||
__fromCell = toCell;
|
__fromCell = toCell;
|
||||||
Game.world.UnitInfluence.Add(self, this);
|
self.World.UnitInfluence.Add(self, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void TeleportTo(Actor self, int2 xy)
|
public void TeleportTo(Actor self, int2 xy)
|
||||||
@@ -62,7 +62,7 @@ namespace OpenRa.Traits
|
|||||||
{
|
{
|
||||||
// force-move
|
// force-move
|
||||||
if (!mi.Modifiers.HasModifier(Modifiers.Alt)) return null;
|
if (!mi.Modifiers.HasModifier(Modifiers.Alt)) return null;
|
||||||
if (!Game.world.IsActorCrushableByActor(underCursor, self)) return null;
|
if (!self.World.IsActorCrushableByActor(underCursor, self)) return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Util.GetEffectiveSpeed(self) == 0) return null; /* allow disabling move orders from modifiers */
|
if (Util.GetEffectiveSpeed(self) == 0) return null; /* allow disabling move orders from modifiers */
|
||||||
@@ -93,14 +93,14 @@ namespace OpenRa.Traits
|
|||||||
|
|
||||||
public bool CanEnterCell(int2 a)
|
public bool CanEnterCell(int2 a)
|
||||||
{
|
{
|
||||||
if (!Game.world.BuildingInfluence.CanMoveHere(a)) return false;
|
if (!self.World.BuildingInfluence.CanMoveHere(a)) return false;
|
||||||
|
|
||||||
var crushable = true;
|
var crushable = true;
|
||||||
foreach (Actor actor in Game.world.UnitInfluence.GetUnitsAt(a))
|
foreach (Actor actor in self.World.UnitInfluence.GetUnitsAt(a))
|
||||||
{
|
{
|
||||||
if (actor == self) continue;
|
if (actor == self) continue;
|
||||||
|
|
||||||
if (!Game.world.IsActorCrushableByActor(actor, self))
|
if (!self.World.IsActorCrushableByActor(actor, self))
|
||||||
{
|
{
|
||||||
crushable = false;
|
crushable = false;
|
||||||
break;
|
break;
|
||||||
@@ -109,9 +109,9 @@ namespace OpenRa.Traits
|
|||||||
|
|
||||||
if (!crushable) return false;
|
if (!crushable) return false;
|
||||||
|
|
||||||
return Game.world.Map.IsInMap(a.X, a.Y) &&
|
return self.World.Map.IsInMap(a.X, a.Y) &&
|
||||||
TerrainCosts.Cost(GetMovementType(),
|
TerrainCosts.Cost(GetMovementType(),
|
||||||
Game.world.TileSet.GetWalkability(Game.world.Map.MapTiles[a.X, a.Y])) < double.PositiveInfinity;
|
self.World.TileSet.GetWalkability(self.World.Map.MapTiles[a.X, a.Y])) < double.PositiveInfinity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<int2> GetCurrentPath()
|
public IEnumerable<int2> GetCurrentPath()
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace OpenRa.Traits
|
|||||||
{
|
{
|
||||||
if( order.OrderString == "PlaceBuilding" )
|
if( order.OrderString == "PlaceBuilding" )
|
||||||
{
|
{
|
||||||
Game.world.AddFrameEndTask( _ =>
|
self.World.AddFrameEndTask( _ =>
|
||||||
{
|
{
|
||||||
var queue = self.traits.Get<ProductionQueue>();
|
var queue = self.traits.Get<ProductionQueue>();
|
||||||
var unit = Rules.Info[ order.TargetString ];
|
var unit = Rules.Info[ order.TargetString ];
|
||||||
@@ -22,8 +22,8 @@ namespace OpenRa.Traits
|
|||||||
if( producing == null || producing.Item != order.TargetString || producing.RemainingTime != 0 )
|
if( producing == null || producing.Item != order.TargetString || producing.RemainingTime != 0 )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Game.world.CreateActor( order.TargetString, order.TargetLocation, order.Player );
|
self.World.CreateActor( order.TargetString, order.TargetLocation, order.Player );
|
||||||
if (order.Player == Game.world.LocalPlayer)
|
if (order.Player == self.World.LocalPlayer)
|
||||||
{
|
{
|
||||||
Sound.Play("placbldg.aud");
|
Sound.Play("placbldg.aud");
|
||||||
Sound.Play("build5.aud");
|
Sound.Play("build5.aud");
|
||||||
|
|||||||
@@ -32,10 +32,10 @@ namespace OpenRa.Traits
|
|||||||
public bool Produce( Actor self, ActorInfo producee )
|
public bool Produce( Actor self, ActorInfo producee )
|
||||||
{
|
{
|
||||||
var location = CreationLocation( self, producee );
|
var location = CreationLocation( self, producee );
|
||||||
if( location == null || Game.world.UnitInfluence.GetUnitsAt( location.Value ).Any() )
|
if( location == null || self.World.UnitInfluence.GetUnitsAt( location.Value ).Any() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var newUnit = Game.world.CreateActor( producee.Name, location.Value, self.Owner );
|
var newUnit = self.World.CreateActor( producee.Name, location.Value, self.Owner );
|
||||||
newUnit.traits.Get<Unit>().Facing = CreationFacing( self, newUnit ); ;
|
newUnit.traits.Get<Unit>().Facing = CreationFacing( self, newUnit ); ;
|
||||||
|
|
||||||
var rp = self.traits.GetOrDefault<RallyPoint>();
|
var rp = self.traits.GetOrDefault<RallyPoint>();
|
||||||
@@ -86,7 +86,7 @@ namespace OpenRa.Traits
|
|||||||
// Cancel existing primaries
|
// Cancel existing primaries
|
||||||
foreach (var p in self.Info.Traits.Get<ProductionInfo>().Produces)
|
foreach (var p in self.Info.Traits.Get<ProductionInfo>().Produces)
|
||||||
{
|
{
|
||||||
foreach (var b in Game.world.Actors.Where(x => x.traits.Contains<Production>()
|
foreach (var b in self.World.Actors.Where(x => x.traits.Contains<Production>()
|
||||||
&& x.Owner == self.Owner
|
&& x.Owner == self.Owner
|
||||||
&& x.traits.Get<Production>().IsPrimary == true
|
&& x.traits.Get<Production>().IsPrimary == true
|
||||||
&& (x.Info.Traits.Get<ProductionInfo>().Produces.Contains(p))))
|
&& (x.Info.Traits.Get<ProductionInfo>().Produces.Contains(p))))
|
||||||
|
|||||||
@@ -49,11 +49,11 @@ namespace OpenRa.Traits
|
|||||||
|
|
||||||
BeginProduction( unit.Category,
|
BeginProduction( unit.Category,
|
||||||
new ProductionItem( order.TargetString, (int)time, ui.Cost,
|
new ProductionItem( order.TargetString, (int)time, ui.Cost,
|
||||||
() => Game.world.AddFrameEndTask(
|
() => self.World.AddFrameEndTask(
|
||||||
_ =>
|
_ =>
|
||||||
{
|
{
|
||||||
var isBuilding = unit.Traits.Contains<BuildingInfo>();
|
var isBuilding = unit.Traits.Contains<BuildingInfo>();
|
||||||
if( !hasPlayedSound && order.Player == Game.world.LocalPlayer )
|
if( !hasPlayedSound && order.Player == self.World.LocalPlayer )
|
||||||
{
|
{
|
||||||
Sound.Play( isBuilding ? "conscmp1.aud" : "unitrdy1.aud" );
|
Sound.Play( isBuilding ? "conscmp1.aud" : "unitrdy1.aud" );
|
||||||
hasPlayedSound = true;
|
hasPlayedSound = true;
|
||||||
@@ -131,7 +131,7 @@ namespace OpenRa.Traits
|
|||||||
Actor producer = null;
|
Actor producer = null;
|
||||||
|
|
||||||
// Prioritise primary structure in build order
|
// Prioritise primary structure in build order
|
||||||
var primaryProducers = Game.world.Actors
|
var primaryProducers = self.World.Actors
|
||||||
.Where(x => x.traits.Contains<Production>()
|
.Where(x => x.traits.Contains<Production>()
|
||||||
&& producerTypes.Contains(x.Info)
|
&& producerTypes.Contains(x.Info)
|
||||||
&& x.Owner == self.Owner
|
&& x.Owner == self.Owner
|
||||||
@@ -152,7 +152,7 @@ namespace OpenRa.Traits
|
|||||||
// Pick the first available producer
|
// Pick the first available producer
|
||||||
if (producer == null)
|
if (producer == null)
|
||||||
{
|
{
|
||||||
producer = Game.world.Actors
|
producer = self.World.Actors
|
||||||
.Where( x => producerTypes.Contains( x.Info ) && x.Owner == self.Owner )
|
.Where( x => producerTypes.Contains( x.Info ) && x.Owner == self.Owner )
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,15 +12,15 @@ namespace OpenRa.Traits
|
|||||||
{
|
{
|
||||||
public ProductionSurround(Actor self) : base(self) { }
|
public ProductionSurround(Actor self) : base(self) { }
|
||||||
|
|
||||||
static int2? FindAdjacentTile(Actor a, UnitMovementType umt)
|
static int2? FindAdjacentTile(Actor self, UnitMovementType umt)
|
||||||
{
|
{
|
||||||
var tiles = Footprint.Tiles(a, a.traits.Get<Traits.Building>());
|
var tiles = Footprint.Tiles(self, self.traits.Get<Traits.Building>());
|
||||||
var min = tiles.Aggregate(int2.Min) - new int2(1, 1);
|
var min = tiles.Aggregate(int2.Min) - new int2(1, 1);
|
||||||
var max = tiles.Aggregate(int2.Max) + new int2(1, 1);
|
var max = tiles.Aggregate(int2.Max) + new int2(1, 1);
|
||||||
|
|
||||||
for (var j = min.Y; j <= max.Y; j++)
|
for (var j = min.Y; j <= max.Y; j++)
|
||||||
for (var i = min.X; i <= max.X; i++)
|
for (var i = min.X; i <= max.X; i++)
|
||||||
if (Game.world.IsCellBuildable(new int2(i, j), umt))
|
if (self.World.IsCellBuildable(new int2(i, j), umt))
|
||||||
return new int2(i, j);
|
return new int2(i, j);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace OpenRa.Traits
|
|||||||
public IEnumerable<Renderable> Render(Actor self)
|
public IEnumerable<Renderable> Render(Actor self)
|
||||||
{
|
{
|
||||||
var uog = Game.controller.orderGenerator as UnitOrderGenerator;
|
var uog = Game.controller.orderGenerator as UnitOrderGenerator;
|
||||||
if (uog != null && self.Owner == Game.world.LocalPlayer && uog.selection.Contains(self))
|
if (uog != null && self.Owner == self.World.LocalPlayer && uog.selection.Contains(self))
|
||||||
yield return Util.Centered(self,
|
yield return Util.Centered(self,
|
||||||
anim.Image, Util.CenterOfCell(rallyPoint));
|
anim.Image, Util.CenterOfCell(rallyPoint));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace OpenRa.Traits
|
|||||||
if( Game.skipMakeAnims )
|
if( Game.skipMakeAnims )
|
||||||
Complete( self );
|
Complete( self );
|
||||||
else
|
else
|
||||||
anim.PlayThen( "make", () => Game.world.AddFrameEndTask( _ => Complete( self ) ) );
|
anim.PlayThen( "make", () => self.World.AddFrameEndTask( _ => Complete( self ) ) );
|
||||||
|
|
||||||
DoBib(self, false);
|
DoBib(self, false);
|
||||||
}
|
}
|
||||||
@@ -45,11 +45,11 @@ namespace OpenRa.Traits
|
|||||||
var p = self.Location + new int2(i % size, i / size + bibOffset);
|
var p = self.Location + new int2(i % size, i / size + bibOffset);
|
||||||
if (isRemove)
|
if (isRemove)
|
||||||
{
|
{
|
||||||
if (Game.world.Map.MapTiles[p.X, p.Y].smudge == (byte)(i + startIndex))
|
if (self.World.Map.MapTiles[p.X, p.Y].smudge == (byte)(i + startIndex))
|
||||||
Game.world.Map.MapTiles[ p.X, p.Y ].smudge = 0;
|
self.World.Map.MapTiles[ p.X, p.Y ].smudge = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Game.world.Map.MapTiles[p.X, p.Y].smudge = (byte)(i + startIndex);
|
self.World.Map.MapTiles[p.X, p.Y].smudge = (byte)(i + startIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -87,7 +87,7 @@ namespace OpenRa.Traits
|
|||||||
break;
|
break;
|
||||||
case DamageState.Dead:
|
case DamageState.Dead:
|
||||||
DoBib(self, true);
|
DoBib(self, true);
|
||||||
Game.world.AddFrameEndTask(w => w.Add(new Explosion(self.CenterLocation.ToInt2(), 7, false)));
|
self.World.AddFrameEndTask(w => w.Add(new Explosion(w, self.CenterLocation.ToInt2(), 7, false)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace OpenRa.Traits
|
|||||||
public void Tick(Actor self)
|
public void Tick(Actor self)
|
||||||
{
|
{
|
||||||
var b = self.GetBounds(false);
|
var b = self.GetBounds(false);
|
||||||
if (isOpen && !Game.world.UnitInfluence.GetUnitsAt(((1/24f) * self.CenterLocation).ToInt2()).Any())
|
if (isOpen && !self.World.UnitInfluence.GetUnitsAt(((1/24f) * self.CenterLocation).ToInt2()).Any())
|
||||||
{
|
{
|
||||||
isOpen = false;
|
isOpen = false;
|
||||||
roof.PlayBackwardsThen(GetPrefix(self) + "build-top", () => roof.Play(GetPrefix(self) + "idle-top"));
|
roof.PlayBackwardsThen(GetPrefix(self) + "build-top", () => roof.Play(GetPrefix(self) + "idle-top"));
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ namespace OpenRa.Traits
|
|||||||
if (e.DamageState == DamageState.Dead)
|
if (e.DamageState == DamageState.Dead)
|
||||||
{
|
{
|
||||||
Sound.PlayVoice("Die", self);
|
Sound.PlayVoice("Die", self);
|
||||||
Game.world.AddFrameEndTask(w => w.Add(new Corpse(self, e.Warhead.InfDeath)));
|
self.World.AddFrameEndTask(w => w.Add(new Corpse(self, e.Warhead.InfDeath)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ namespace OpenRa.Traits
|
|||||||
for (var j = -1; j < 2; j++)
|
for (var j = -1; j < 2; j++)
|
||||||
for (var i = -1; i < 2; i++)
|
for (var i = -1; i < 2; i++)
|
||||||
if (Game.SharedRandom.NextDouble() < info.Chance)
|
if (Game.SharedRandom.NextDouble() < info.Chance)
|
||||||
if (Game.world.OreCanSpreadInto(self.Location.X + i, self.Location.Y + j))
|
if (self.World.OreCanSpreadInto(self.Location.X + i, self.Location.Y + j))
|
||||||
Game.world.Map.AddOre(self.Location.X + i, self.Location.Y + j);
|
self.World.Map.AddOre(self.Location.X + i, self.Location.Y + j);
|
||||||
|
|
||||||
ticks = info.Interval;
|
ticks = info.Interval;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ namespace OpenRa.Traits
|
|||||||
|
|
||||||
public bool IsCrushableBy(UnitMovementType umt, Player player)
|
public bool IsCrushableBy(UnitMovementType umt, Player player)
|
||||||
{
|
{
|
||||||
if (player == Game.world.LocalPlayer) return false;
|
if (player == self.World.LocalPlayer) return false;
|
||||||
switch (umt)
|
switch (umt)
|
||||||
{
|
{
|
||||||
case UnitMovementType.Track: return true;
|
case UnitMovementType.Track: return true;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace OpenRa.Traits
|
|||||||
self.Owner.TakeCash(toSteal);
|
self.Owner.TakeCash(toSteal);
|
||||||
thief.Owner.GiveCash(toSteal);
|
thief.Owner.GiveCash(toSteal);
|
||||||
|
|
||||||
if (Game.world.LocalPlayer == thief.Owner)
|
if (self.World.LocalPlayer == thief.Owner)
|
||||||
Sound.Play("credit1.aud");
|
Sound.Play("credit1.aud");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ namespace OpenRa.Traits
|
|||||||
var numPips = self.Info.Traits.Get<StoresOreInfo>().Pips;
|
var numPips = self.Info.Traits.Get<StoresOreInfo>().Pips;
|
||||||
|
|
||||||
return Graphics.Util.MakeArray( numPips,
|
return Graphics.Util.MakeArray( numPips,
|
||||||
i => (Game.world.LocalPlayer.GetSiloFullness() > i * 1.0f / numPips)
|
i => (self.World.LocalPlayer.GetSiloFullness() > i * 1.0f / numPips)
|
||||||
? PipType.Yellow : PipType.Transparent );
|
? PipType.Yellow : PipType.Transparent );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ namespace OpenRa.Traits
|
|||||||
if (remainingSurfaceTime > 0)
|
if (remainingSurfaceTime > 0)
|
||||||
return rs;
|
return rs;
|
||||||
|
|
||||||
if (self.Owner == Game.world.LocalPlayer)
|
if (self.Owner == self.World.LocalPlayer)
|
||||||
return rs.Select(a => a.WithPalette(PaletteType.Shadow));
|
return rs.Select(a => a.WithPalette(PaletteType.Shadow));
|
||||||
else
|
else
|
||||||
return new Renderable[] { };
|
return new Renderable[] { };
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ namespace OpenRa.Traits
|
|||||||
public void Damaged(Actor self, AttackInfo e)
|
public void Damaged(Actor self, AttackInfo e)
|
||||||
{
|
{
|
||||||
if (e.DamageState == DamageState.Dead)
|
if (e.DamageState == DamageState.Dead)
|
||||||
if (self.Owner == Game.world.LocalPlayer)
|
if (self.Owner == self.World.LocalPlayer)
|
||||||
Sound.Play(self.Info.Traits.Get<OwnedActorInfo>().WaterBound
|
Sound.Play(self.Info.Traits.Get<OwnedActorInfo>().WaterBound
|
||||||
? "navylst1.aud" : "unitlst1.aud");
|
? "navylst1.aud" : "unitlst1.aud");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,24 +34,24 @@ namespace OpenRa
|
|||||||
return SheetBuilder.Add( data, new Size(Game.CellSize,Game.CellSize) );
|
return SheetBuilder.Add( data, new Size(Game.CellSize,Game.CellSize) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Draw()
|
public void Draw( World world )
|
||||||
{
|
{
|
||||||
if (ShowUnitDebug)
|
if (ShowUnitDebug)
|
||||||
for (var j = 0; j < 128; j++)
|
for (var j = 0; j < 128; j++)
|
||||||
for (var i = 0; i < 128; i++)
|
for (var i = 0; i < 128; i++)
|
||||||
if (Game.world.UnitInfluence.GetUnitsAt(new int2(i, j)).Any())
|
if (world.UnitInfluence.GetUnitsAt(new int2(i, j)).Any())
|
||||||
spriteRenderer.DrawSprite(unitDebug, Game.CellSize * new float2(i, j), 0);
|
spriteRenderer.DrawSprite(unitDebug, Game.CellSize * new float2(i, j), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawBuildingGrid( string name, BuildingInfo bi )
|
public void DrawBuildingGrid( World world, string name, BuildingInfo bi )
|
||||||
{
|
{
|
||||||
var position = Game.controller.MousePosition.ToInt2();
|
var position = Game.controller.MousePosition.ToInt2();
|
||||||
var topLeft = position - Footprint.AdjustForBuildingSize( bi );
|
var topLeft = position - Footprint.AdjustForBuildingSize( bi );
|
||||||
var isCloseEnough = Game.world.IsCloseEnoughToBase(Game.world.LocalPlayer, name, bi, topLeft);
|
var isCloseEnough = world.IsCloseEnoughToBase(world.LocalPlayer, name, bi, topLeft);
|
||||||
|
|
||||||
foreach( var t in Footprint.Tiles( name, bi, topLeft ) )
|
foreach( var t in Footprint.Tiles( name, bi, topLeft ) )
|
||||||
spriteRenderer.DrawSprite( ( isCloseEnough && Game.world.IsCellBuildable( t, bi.WaterBound
|
spriteRenderer.DrawSprite( ( isCloseEnough && world.IsCellBuildable( t, bi.WaterBound
|
||||||
? UnitMovementType.Float : UnitMovementType.Wheel ) && !Game.world.Map.ContainsResource( t ) )
|
? UnitMovementType.Float : UnitMovementType.Wheel ) && !world.Map.ContainsResource( t ) )
|
||||||
? buildOk : buildBlocked, Game.CellSize * t, 0 );
|
? buildOk : buildBlocked, Game.CellSize * t, 0 );
|
||||||
|
|
||||||
spriteRenderer.Flush();
|
spriteRenderer.Flush();
|
||||||
|
|||||||
@@ -8,11 +8,13 @@ namespace OpenRa
|
|||||||
{
|
{
|
||||||
public class UnitInfluenceMap
|
public class UnitInfluenceMap
|
||||||
{
|
{
|
||||||
|
readonly World world;
|
||||||
List<Actor>[,] influence = new List<Actor>[128, 128];
|
List<Actor>[,] influence = new List<Actor>[128, 128];
|
||||||
readonly int2 searchDistance = new int2(2,2);
|
readonly int2 searchDistance = new int2(2,2);
|
||||||
|
|
||||||
public UnitInfluenceMap( World world )
|
public UnitInfluenceMap( World world )
|
||||||
{
|
{
|
||||||
|
this.world = world;
|
||||||
for (int i = 0; i < 128; i++)
|
for (int i = 0; i < 128; i++)
|
||||||
for (int j = 0; j < 128; j++)
|
for (int j = 0; j < 128; j++)
|
||||||
influence[ i, j ] = new List<Actor>();
|
influence[ i, j ] = new List<Actor>();
|
||||||
@@ -25,7 +27,7 @@ namespace OpenRa
|
|||||||
// Does this belong here? NO, but it's your mess.
|
// Does this belong here? NO, but it's your mess.
|
||||||
|
|
||||||
// Get the crushable actors
|
// Get the crushable actors
|
||||||
foreach (var a in Game.world.Actors.Where(b => b.traits.Contains<ICrushable>()))
|
foreach (var a in world.Actors.Where(b => b.traits.Contains<ICrushable>()))
|
||||||
{
|
{
|
||||||
// Are there any units in the same cell that can crush this?
|
// Are there any units in the same cell that can crush this?
|
||||||
foreach( var ios in a.traits.WithInterface<IOccupySpace>() )
|
foreach( var ios in a.traits.WithInterface<IOccupySpace>() )
|
||||||
@@ -33,7 +35,7 @@ namespace OpenRa
|
|||||||
{
|
{
|
||||||
// There should only be one (counterexample: An infantry and a tank try to pick up a crate at the same time.)
|
// There should only be one (counterexample: An infantry and a tank try to pick up a crate at the same time.)
|
||||||
// If there is more than one, do action on the first crusher
|
// If there is more than one, do action on the first crusher
|
||||||
var crusher = GetUnitsAt(cell).Where(b => a != b && Game.world.IsActorCrushableByActor(a, b)).FirstOrDefault();
|
var crusher = GetUnitsAt(cell).Where(b => a != b && world.IsActorCrushableByActor(a, b)).FirstOrDefault();
|
||||||
if (crusher != null)
|
if (crusher != null)
|
||||||
{
|
{
|
||||||
Log.Write("{0} crushes {1}", crusher.Info.Name, a.Info.Name);
|
Log.Write("{0} crushes {1}", crusher.Info.Name, a.Info.Name);
|
||||||
@@ -56,7 +58,7 @@ namespace OpenRa
|
|||||||
if (!a.traits.Get<IOccupySpace>().OccupiedCells().Contains( new int2( x, y ) ) )
|
if (!a.traits.Get<IOccupySpace>().OccupiedCells().Contains( new int2( x, y ) ) )
|
||||||
throw new InvalidOperationException( "UIM: Sanity check failed A" );
|
throw new InvalidOperationException( "UIM: Sanity check failed A" );
|
||||||
|
|
||||||
foreach( Actor a in Game.world.Actors )
|
foreach( Actor a in world.Actors )
|
||||||
foreach( var ios in a.traits.WithInterface<IOccupySpace>() )
|
foreach( var ios in a.traits.WithInterface<IOccupySpace>() )
|
||||||
foreach( var cell in ios.OccupiedCells() )
|
foreach( var cell in ios.OccupiedCells() )
|
||||||
if (!influence[cell.X, cell.Y].Contains(a))
|
if (!influence[cell.X, cell.Y].Contains(a))
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace OpenRa
|
|||||||
set
|
set
|
||||||
{
|
{
|
||||||
localPlayerIndex = value.Index;
|
localPlayerIndex = value.Index;
|
||||||
Game.viewport.GoToStartLocation();
|
Game.viewport.GoToStartLocation( value );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,7 +110,7 @@ namespace OpenRa
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach (var a in actors) a.Tick();
|
foreach (var a in actors) a.Tick();
|
||||||
foreach (var e in effects) e.Tick();
|
foreach (var e in effects) e.Tick( this );
|
||||||
|
|
||||||
Game.viewport.Tick();
|
Game.viewport.Tick();
|
||||||
|
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ namespace OpenRa
|
|||||||
{
|
{
|
||||||
return world.FindUnits(a, b)
|
return world.FindUnits(a, b)
|
||||||
.Where( x => x.traits.Contains<Selectable>() )
|
.Where( x => x.traits.Contains<Selectable>() )
|
||||||
.GroupBy(x => (x.Owner == Game.world.LocalPlayer) ? x.Info.Traits.Get<SelectableInfo>().Priority : 0)
|
.GroupBy(x => (x.Owner == world.LocalPlayer) ? x.Info.Traits.Get<SelectableInfo>().Priority : 0)
|
||||||
.OrderByDescending(g => g.Key)
|
.OrderByDescending(g => g.Key)
|
||||||
.Select( g => g.AsEnumerable() )
|
.Select( g => g.AsEnumerable() )
|
||||||
.DefaultIfEmpty( new Actor[] {} )
|
.DefaultIfEmpty( new Actor[] {} )
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ namespace OpenRa.Mods.Aftermath
|
|||||||
Sound.Play("chrotnk1.aud");
|
Sound.Play("chrotnk1.aud");
|
||||||
chargeTick = chargeLength;
|
chargeTick = chargeLength;
|
||||||
|
|
||||||
foreach (var a in Game.world.Actors.Where(a => a.traits.Contains<ChronoshiftPaletteEffect>()))
|
foreach (var a in self.World.Actors.Where(a => a.traits.Contains<ChronoshiftPaletteEffect>()))
|
||||||
a.traits.Get<ChronoshiftPaletteEffect>().DoChronoshift();
|
a.traits.Get<ChronoshiftPaletteEffect>().DoChronoshift();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ namespace OpenRa.Mods.Aftermath
|
|||||||
{
|
{
|
||||||
// Override chronoshifting action to detonate vehicle
|
// Override chronoshifting action to detonate vehicle
|
||||||
var movement = self.traits.GetOrDefault<IMovement>();
|
var movement = self.traits.GetOrDefault<IMovement>();
|
||||||
var chronosphere = Game.world.Actors.Where(a => a.Owner == order.Subject.Owner && a.traits.Contains<Chronosphere>()).FirstOrDefault();
|
var chronosphere = self.World.Actors.Where(a => a.Owner == order.Subject.Owner && a.traits.Contains<Chronosphere>()).FirstOrDefault();
|
||||||
if (order.OrderString == "Chronoshift" && movement.CanEnterCell(order.TargetLocation))
|
if (order.OrderString == "Chronoshift" && movement.CanEnterCell(order.TargetLocation))
|
||||||
{
|
{
|
||||||
self.InflictDamage(chronosphere, self.Health, Rules.WarheadInfo["Super"]);
|
self.InflictDamage(chronosphere, self.Health, Rules.WarheadInfo["Super"]);
|
||||||
@@ -44,7 +44,7 @@ namespace OpenRa.Mods.Aftermath
|
|||||||
var altitude = unit != null ? unit.Altitude : 0;
|
var altitude = unit != null ? unit.Altitude : 0;
|
||||||
int2 detonateLocation = self.CenterLocation.ToInt2();
|
int2 detonateLocation = self.CenterLocation.ToInt2();
|
||||||
|
|
||||||
Game.world.AddFrameEndTask(
|
self.World.AddFrameEndTask(
|
||||||
w => w.Add(new Bullet(self.Info.Traits.Get<AttackBaseInfo>().PrimaryWeapon, detonatedBy.Owner, detonatedBy,
|
w => w.Add(new Bullet(self.Info.Traits.Get<AttackBaseInfo>().PrimaryWeapon, detonatedBy.Owner, detonatedBy,
|
||||||
detonateLocation, detonateLocation, altitude, altitude)));
|
detonateLocation, detonateLocation, altitude, altitude)));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace OpenRa.Mods.Aftermath.Orders
|
|||||||
this.self = self;
|
this.self = self;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Order> Order(int2 xy, MouseInput mi)
|
public IEnumerable<Order> Order(World world, int2 xy, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Button == MouseButton.Left)
|
if (mi.Button == MouseButton.Left)
|
||||||
{
|
{
|
||||||
@@ -24,15 +24,15 @@ namespace OpenRa.Mods.Aftermath.Orders
|
|||||||
yield return new Order("ChronoshiftSelf", self, null, xy, null);
|
yield return new Order("ChronoshiftSelf", self, null, xy, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick() { }
|
public void Tick( World world ) { }
|
||||||
public void Render()
|
public void Render( World world )
|
||||||
{
|
{
|
||||||
Game.world.WorldRenderer.DrawSelectionBox(self, Color.White, true);
|
world.WorldRenderer.DrawSelectionBox(self, Color.White, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Cursor GetCursor(int2 xy, MouseInput mi)
|
public Cursor GetCursor(World world, int2 xy, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (!Game.world.LocalPlayer.Shroud.IsExplored(xy))
|
if (!world.LocalPlayer.Shroud.IsExplored(xy))
|
||||||
return Cursor.MoveBlocked;
|
return Cursor.MoveBlocked;
|
||||||
|
|
||||||
var movement = self.traits.GetOrDefault<IMovement>();
|
var movement = self.traits.GetOrDefault<IMovement>();
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ namespace OpenRa.Mods.RA.Activities
|
|||||||
}
|
}
|
||||||
|
|
||||||
// the engineer is sacrificed.
|
// the engineer is sacrificed.
|
||||||
Game.world.AddFrameEndTask(w => w.Remove(self));
|
self.World.AddFrameEndTask(w => w.Remove(self));
|
||||||
|
|
||||||
return NextActivity;
|
return NextActivity;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ namespace OpenRa.Mods.RA.Activities
|
|||||||
public IActivity Tick(Actor self)
|
public IActivity Tick(Actor self)
|
||||||
{
|
{
|
||||||
if (target == null || target.IsDead) return NextActivity;
|
if (target == null || target.IsDead) return NextActivity;
|
||||||
Game.world.AddFrameEndTask(w => w.Add(new DelayedAction(25*2,
|
self.World.AddFrameEndTask(w => w.Add(new DelayedAction(25*2,
|
||||||
() => target.InflictDamage(self, target.Health, Rules.WarheadInfo["DemolishWarhead"]))));
|
() => target.InflictDamage(self, target.Health, Rules.WarheadInfo["DemolishWarhead"]))));
|
||||||
return NextActivity;
|
return NextActivity;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace OpenRa.Mods.RA.Activities
|
|||||||
foreach (var t in target.traits.WithInterface<IAcceptSpy>())
|
foreach (var t in target.traits.WithInterface<IAcceptSpy>())
|
||||||
t.OnInfiltrate(target, self);
|
t.OnInfiltrate(target, self);
|
||||||
|
|
||||||
Game.world.AddFrameEndTask(w => w.Remove(self));
|
self.World.AddFrameEndTask(w => w.Remove(self));
|
||||||
|
|
||||||
return NextActivity;
|
return NextActivity;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ namespace OpenRa.Mods.RA.Activities
|
|||||||
foreach (var t in target.traits.WithInterface<IAcceptThief>())
|
foreach (var t in target.traits.WithInterface<IAcceptThief>())
|
||||||
t.OnSteal(target, self);
|
t.OnSteal(target, self);
|
||||||
|
|
||||||
Game.world.AddFrameEndTask(w => w.Remove(self));
|
self.World.AddFrameEndTask(w => w.Remove(self));
|
||||||
|
|
||||||
return NextActivity;
|
return NextActivity;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ namespace OpenRa.Mods.RA
|
|||||||
public Mine(Actor self)
|
public Mine(Actor self)
|
||||||
{
|
{
|
||||||
this.self = self;
|
this.self = self;
|
||||||
Game.world.UnitInfluence.Add(self, this);
|
self.World.UnitInfluence.Add(self, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnCrush(Actor crusher)
|
public void OnCrush(Actor crusher)
|
||||||
@@ -32,17 +32,17 @@ namespace OpenRa.Mods.RA
|
|||||||
var info = self.Info.Traits.Get<MineInfo>();
|
var info = self.Info.Traits.Get<MineInfo>();
|
||||||
var warhead = Rules.WarheadInfo[info.Warhead];
|
var warhead = Rules.WarheadInfo[info.Warhead];
|
||||||
|
|
||||||
Game.world.AddFrameEndTask(_ =>
|
self.World.AddFrameEndTask(w =>
|
||||||
{
|
{
|
||||||
Game.world.Remove(self);
|
w.Remove(self);
|
||||||
Game.world.Add(new Explosion(self.CenterLocation.ToInt2(), warhead.Explosion, false));
|
w.Add(new Explosion(w, self.CenterLocation.ToInt2(), warhead.Explosion, false));
|
||||||
crusher.InflictDamage(crusher, info.Damage, warhead);
|
crusher.InflictDamage(crusher, info.Damage, warhead);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsPathableCrush(UnitMovementType umt, Player player)
|
public bool IsPathableCrush(UnitMovementType umt, Player player)
|
||||||
{
|
{
|
||||||
return !self.Info.Traits.Get<MineInfo>().AvoidFriendly || (player != Game.world.LocalPlayer);
|
return !self.Info.Traits.Get<MineInfo>().AvoidFriendly || (player != self.World.LocalPlayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsCrushableBy(UnitMovementType umt, Player player)
|
public bool IsCrushableBy(UnitMovementType umt, Player player)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace OpenRa.Mods.RA
|
|||||||
return null;
|
return null;
|
||||||
|
|
||||||
// Ensure that the cell is empty except for the minelayer
|
// Ensure that the cell is empty except for the minelayer
|
||||||
if (Game.world.UnitInfluence.GetUnitsAt(xy).Any(a => a != self))
|
if (self.World.UnitInfluence.GetUnitsAt(xy).Any(a => a != self))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (mi.Button == MouseButton.Right && underCursor == self)
|
if (mi.Button == MouseButton.Right && underCursor == self)
|
||||||
@@ -36,7 +36,7 @@ namespace OpenRa.Mods.RA
|
|||||||
|
|
||||||
// todo: delay a bit? (req making deploy-mine an activity)
|
// todo: delay a bit? (req making deploy-mine an activity)
|
||||||
|
|
||||||
Game.world.AddFrameEndTask(
|
self.World.AddFrameEndTask(
|
||||||
w => w.CreateActor(self.Info.Traits.Get<MinelayerInfo>().Mine, self.Location, self.Owner));
|
w => w.CreateActor(self.Info.Traits.Get<MinelayerInfo>().Mine, self.Location, self.Owner));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user