merged pchote/master attack-omni bridge-setup-as-trait
This commit is contained in:
35
OpenRa.Game/Traits/AttackOmni.cs
Normal file
35
OpenRa.Game/Traits/AttackOmni.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenRa.Traits
|
||||
{
|
||||
class AttackOmniInfo : AttackBaseInfo
|
||||
{
|
||||
public override object Create(Actor self) { return new AttackOmni(self); }
|
||||
}
|
||||
|
||||
class AttackOmni : AttackBase, INotifyBuildComplete
|
||||
{
|
||||
bool buildComplete = false;
|
||||
public void BuildingComplete(Actor self) { buildComplete = true; }
|
||||
|
||||
public AttackOmni(Actor self) : base(self) { }
|
||||
|
||||
public override void Tick(Actor self)
|
||||
{
|
||||
base.Tick(self);
|
||||
|
||||
if (!CanAttack(self)) return;
|
||||
if (self.traits.Contains<Building>() && !buildComplete) return;
|
||||
|
||||
DoAttack(self);
|
||||
}
|
||||
|
||||
protected override void QueueAttack(Actor self, Order order)
|
||||
{
|
||||
target = order.TargetActor;
|
||||
}
|
||||
}
|
||||
}
|
||||
70
OpenRa.Game/Traits/BridgeLoadHook.cs
Normal file
70
OpenRa.Game/Traits/BridgeLoadHook.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenRa.Traits
|
||||
{
|
||||
class BridgeLoadHookInfo : StatelessTraitInfo<BridgeLoadHook> { }
|
||||
|
||||
class BridgeLoadHook : ILoadWorldHook
|
||||
{
|
||||
static void MakeBridges(World w)
|
||||
{
|
||||
var mini = w.Map.XOffset; var maxi = w.Map.XOffset + w.Map.Width;
|
||||
var minj = w.Map.YOffset; var maxj = w.Map.YOffset + w.Map.Height;
|
||||
|
||||
for (var j = minj; j < maxj; j++)
|
||||
for (var i = mini; i < maxi; i++)
|
||||
if (IsBridge(w, w.Map.MapTiles[i, j].tile))
|
||||
ConvertBridgeToActor(w, i, j);
|
||||
|
||||
foreach (var br in w.Queries.WithTraitMultiple<Bridge>())
|
||||
br.Trait.FinalizeBridges(w);
|
||||
}
|
||||
|
||||
static void ConvertBridgeToActor(World w, int i, int j)
|
||||
{
|
||||
var tile = w.Map.MapTiles[i, j].tile;
|
||||
var image = w.Map.MapTiles[i, j].image;
|
||||
var template = w.TileSet.walk[tile];
|
||||
|
||||
// base position of the tile
|
||||
var ni = i - image % template.Size.X;
|
||||
var nj = j - image / template.Size.X;
|
||||
|
||||
var replacedTiles = new Dictionary<int2, int>();
|
||||
for (var y = nj; y < nj + template.Size.Y; y++)
|
||||
for (var x = ni; x < ni + template.Size.X; x++)
|
||||
{
|
||||
var n = (x - ni) + template.Size.X * (y - nj);
|
||||
if (!template.TerrainType.ContainsKey(n)) continue;
|
||||
|
||||
if (w.Map.IsInMap(x, y))
|
||||
if (w.Map.MapTiles[x, y].tile == tile
|
||||
&& w.Map.MapTiles[x, y].image == n)
|
||||
{
|
||||
// stash it
|
||||
replacedTiles[new int2(x, y)] = w.Map.MapTiles[x, y].image;
|
||||
// remove the tile from the actual map
|
||||
w.Map.MapTiles[x, y].tile = 0xfffe;
|
||||
w.Map.MapTiles[x, y].image = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (replacedTiles.Any())
|
||||
{
|
||||
var a = w.CreateActor(template.Bridge, new int2(ni, nj), null);
|
||||
var br = a.traits.Get<Bridge>();
|
||||
br.SetTiles(w, template, replacedTiles);
|
||||
}
|
||||
}
|
||||
|
||||
static bool IsBridge(World w, ushort t)
|
||||
{
|
||||
return w.TileSet.walk[t].Bridge != null;
|
||||
}
|
||||
|
||||
public void WorldLoaded(World w) { MakeBridges(w); }
|
||||
}
|
||||
}
|
||||
27
OpenRa.Game/Traits/ChoosePaletteOnSelect.cs
Normal file
27
OpenRa.Game/Traits/ChoosePaletteOnSelect.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenRa.Traits
|
||||
{
|
||||
class ChoosePaletteOnSelectInfo : StatelessTraitInfo<ChoosePaletteOnSelect> { }
|
||||
|
||||
class ChoosePaletteOnSelect : INotifySelection
|
||||
{
|
||||
public void SelectionChanged()
|
||||
{
|
||||
var firstItem = Game.controller.selection.Actors.FirstOrDefault(
|
||||
a => a.World.LocalPlayer == a.Owner && a.traits.Contains<Production>());
|
||||
|
||||
if (firstItem == null)
|
||||
return;
|
||||
|
||||
var produces = firstItem.Info.Traits.Get<ProductionInfo>().Produces.FirstOrDefault();
|
||||
if (produces == null)
|
||||
return;
|
||||
|
||||
Game.chrome.SetCurrentTab(produces);
|
||||
}
|
||||
}
|
||||
}
|
||||
47
OpenRa.Game/Traits/OreGrowth.cs
Normal file
47
OpenRa.Game/Traits/OreGrowth.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using OpenRa.Graphics;
|
||||
|
||||
namespace OpenRa.Traits
|
||||
{
|
||||
class OreGrowthInfo : ITraitInfo
|
||||
{
|
||||
public readonly float Interval = 1f;
|
||||
public readonly float Chance = .02f;
|
||||
public readonly bool Spreads = true;
|
||||
public readonly bool Grows = true;
|
||||
|
||||
public object Create(Actor self) { return new OreGrowth(); }
|
||||
}
|
||||
|
||||
class OreGrowth : ITick, ILoadWorldHook
|
||||
{
|
||||
int remainingTicks;
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
if (--remainingTicks <= 0)
|
||||
{
|
||||
var info = self.Info.Traits.Get<OreGrowthInfo>();
|
||||
|
||||
if (info.Spreads)
|
||||
Ore.SpreadOre(self.World,
|
||||
Game.SharedRandom,
|
||||
info.Chance);
|
||||
|
||||
if (info.Grows)
|
||||
Ore.GrowOre(self.World, Game.SharedRandom);
|
||||
|
||||
self.World.Minimap.InvalidateOre();
|
||||
remainingTicks = (int)(info.Interval * 60 * 25);
|
||||
}
|
||||
}
|
||||
|
||||
public void WorldLoaded(World w)
|
||||
{
|
||||
Ore.InitOreDensity(w.Map);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRa.Graphics;
|
||||
using OpenRa.Orders;
|
||||
|
||||
@@ -27,8 +28,7 @@ namespace OpenRa.Traits
|
||||
|
||||
public IEnumerable<Renderable> Render(Actor self)
|
||||
{
|
||||
var uog = Game.controller.orderGenerator as UnitOrderGenerator;
|
||||
if (uog != null && self.Owner == self.World.LocalPlayer && uog.selection.Contains(self))
|
||||
if (self.Owner == self.World.LocalPlayer && Game.controller.selection.Actors.Contains(self))
|
||||
yield return Util.Centered(self,
|
||||
anim.Image, Util.CenterOfCell(rallyPoint));
|
||||
}
|
||||
|
||||
@@ -99,5 +99,8 @@ namespace OpenRa.Traits
|
||||
public object Create(Actor self) { return Instance.Value; }
|
||||
}
|
||||
|
||||
interface ITraitPrerequisite<T> { }
|
||||
public interface ITraitPrerequisite<T> { }
|
||||
|
||||
public interface INotifySelection { void SelectionChanged(); }
|
||||
public interface ILoadWorldHook { void WorldLoaded(World w); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user