initial bridges hack
This commit is contained in:
@@ -8,8 +8,8 @@ namespace OpenRa.FileFormats
|
|||||||
{
|
{
|
||||||
public readonly Dictionary<ushort, Terrain> tiles = new Dictionary<ushort, Terrain>();
|
public readonly Dictionary<ushort, Terrain> tiles = new Dictionary<ushort, Terrain>();
|
||||||
|
|
||||||
readonly Dictionary<ushort, Dictionary<int, int>> walk =
|
public readonly Dictionary<ushort, TileTemplate> walk =
|
||||||
new Dictionary<ushort, Dictionary<int, int>>(); // cjf will fix
|
new Dictionary<ushort, TileTemplate>(); // cjf will fix
|
||||||
|
|
||||||
string NextLine( StreamReader reader )
|
string NextLine( StreamReader reader )
|
||||||
{
|
{
|
||||||
@@ -82,7 +82,7 @@ namespace OpenRa.FileFormats
|
|||||||
if (r.tile == 0xff || r.tile == 0xffff)
|
if (r.tile == 0xff || r.tile == 0xffff)
|
||||||
r.image = 0;
|
r.image = 0;
|
||||||
|
|
||||||
return walk[r.tile][r.image];
|
return walk[r.tile].TerrainType[r.image];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,35 +1,51 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace OpenRa.FileFormats
|
namespace OpenRa.FileFormats
|
||||||
{
|
{
|
||||||
public class Walkability
|
public class TileTemplate
|
||||||
{
|
{
|
||||||
Dictionary<string, Dictionary<int, int>> walkability =
|
public int Index;
|
||||||
new Dictionary<string, Dictionary<int, int>>();
|
public string Name;
|
||||||
|
public int2 Size;
|
||||||
|
public bool IsBridge;
|
||||||
|
public float HP;
|
||||||
|
public Dictionary<int, int> TerrainType = new Dictionary<int, int>();
|
||||||
|
}
|
||||||
|
|
||||||
|
class Walkability
|
||||||
|
{
|
||||||
|
public Dictionary<string, TileTemplate> walkability
|
||||||
|
= new Dictionary<string,TileTemplate>();
|
||||||
|
|
||||||
public Walkability()
|
public Walkability()
|
||||||
{
|
{
|
||||||
IniFile file = new IniFile( FileSystem.Open( "templates.ini" ) );
|
var file = new IniFile( FileSystem.Open( "templates.ini" ) );
|
||||||
Regex pattern = new Regex(@"tiletype(\d+)");
|
|
||||||
|
|
||||||
foreach (IniSection section in file.Sections)
|
foreach (var section in file.Sections)
|
||||||
{
|
{
|
||||||
string name = section.GetValue("Name", null).ToLowerInvariant();
|
var tile = new TileTemplate
|
||||||
|
|
||||||
Dictionary<int, int> tileWalkability = new Dictionary<int, int>();
|
|
||||||
foreach (KeyValuePair<string, string> p in section)
|
|
||||||
{
|
{
|
||||||
Match m = pattern.Match(p.Key);
|
Size = new int2(
|
||||||
if (m != null && m.Success)
|
int.Parse(section.GetValue("width", "0")),
|
||||||
tileWalkability.Add(int.Parse(m.Groups[1].Value), int.Parse(p.Value));
|
int.Parse(section.GetValue("height", "0"))),
|
||||||
}
|
TerrainType = section
|
||||||
|
.Where(p => p.Key.StartsWith("tiletype"))
|
||||||
|
.ToDictionary(
|
||||||
|
p => int.Parse(p.Key.Substring(8)),
|
||||||
|
p => int.Parse(p.Value)),
|
||||||
|
Name = section.GetValue("Name", null).ToLowerInvariant(),
|
||||||
|
Index = int.Parse(section.Name.Substring(3)),
|
||||||
|
IsBridge = section.GetValue("bridge", "no") != "no",
|
||||||
|
HP = float.Parse(section.GetValue("hp", "0"))
|
||||||
|
};
|
||||||
|
|
||||||
walkability[name] = tileWalkability;
|
walkability[tile.Name] = tile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Dictionary<int, int> GetWalkability(string terrainName)
|
public TileTemplate GetWalkability(string terrainName)
|
||||||
{
|
{
|
||||||
return walkability[terrainName];
|
return walkability[terrainName];
|
||||||
}
|
}
|
||||||
|
|||||||
63
OpenRa.Game/Bridges.cs
Normal file
63
OpenRa.Game/Bridges.cs
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using OpenRa.Traits;
|
||||||
|
|
||||||
|
namespace OpenRa
|
||||||
|
{
|
||||||
|
static class Bridges
|
||||||
|
{
|
||||||
|
public 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
// 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 = 0xff;
|
||||||
|
w.Map.MapTiles[x, y].image = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (replacedTiles.Any())
|
||||||
|
{
|
||||||
|
var a = w.CreateActor("Bridge", new int2(ni, nj), null);
|
||||||
|
var br = a.traits.Get<Bridge>();
|
||||||
|
br.SetTiles(template, replacedTiles);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool IsBridge(World w, ushort t)
|
||||||
|
{
|
||||||
|
return w.TileSet.walk[t].IsBridge;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -107,8 +107,6 @@ namespace OpenRa.Graphics
|
|||||||
|
|
||||||
public static Sprite GetImageFromCollection(Renderer renderer,string collection, string image)
|
public static Sprite GetImageFromCollection(Renderer renderer,string collection, string image)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
// Cached sprite
|
// Cached sprite
|
||||||
if (cachedSprites.ContainsKey(collection) && cachedSprites[collection].ContainsKey(image))
|
if (cachedSprites.ContainsKey(collection) && cachedSprites[collection].ContainsKey(image))
|
||||||
return cachedSprites[collection][image];
|
return cachedSprites[collection][image];
|
||||||
|
|||||||
@@ -77,6 +77,7 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Bridges.cs" />
|
||||||
<Compile Include="Chat.cs" />
|
<Compile Include="Chat.cs" />
|
||||||
<Compile Include="Chrome.cs" />
|
<Compile Include="Chrome.cs" />
|
||||||
<Compile Include="Combat.cs" />
|
<Compile Include="Combat.cs" />
|
||||||
@@ -210,6 +211,7 @@
|
|||||||
<Compile Include="Traits\AutoHeal.cs" />
|
<Compile Include="Traits\AutoHeal.cs" />
|
||||||
<Compile Include="Traits\AutoTarget.cs" />
|
<Compile Include="Traits\AutoTarget.cs" />
|
||||||
<Compile Include="Traits\BelowUnits.cs" />
|
<Compile Include="Traits\BelowUnits.cs" />
|
||||||
|
<Compile Include="Traits\Bridge.cs" />
|
||||||
<Compile Include="Traits\Buildable.cs" />
|
<Compile Include="Traits\Buildable.cs" />
|
||||||
<Compile Include="Traits\Building.cs" />
|
<Compile Include="Traits\Building.cs" />
|
||||||
<Compile Include="Traits\Cargo.cs" />
|
<Compile Include="Traits\Cargo.cs" />
|
||||||
|
|||||||
@@ -137,6 +137,8 @@ namespace OpenRa
|
|||||||
|
|
||||||
internal void Draw(SpriteRenderer r)
|
internal void Draw(SpriteRenderer r)
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
|
|
||||||
if (dirty)
|
if (dirty)
|
||||||
{
|
{
|
||||||
dirty = false;
|
dirty = false;
|
||||||
|
|||||||
43
OpenRa.Game/Traits/Bridge.cs
Normal file
43
OpenRa.Game/Traits/Bridge.cs
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using OpenRa.Graphics;
|
||||||
|
using OpenRa.FileFormats;
|
||||||
|
|
||||||
|
namespace OpenRa.Traits
|
||||||
|
{
|
||||||
|
class BridgeInfo : ITraitInfo
|
||||||
|
{
|
||||||
|
public object Create(Actor self) { return new Bridge(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
class Bridge : IRender, ITick
|
||||||
|
{
|
||||||
|
Animation anim;
|
||||||
|
|
||||||
|
public Bridge() {}
|
||||||
|
|
||||||
|
public IEnumerable<Renderable> Render(Actor self)
|
||||||
|
{
|
||||||
|
if (anim != null)
|
||||||
|
return new[] { Util.Centered(self, anim.Image, self.CenterLocation) };
|
||||||
|
else
|
||||||
|
return new Renderable[] { };
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Tick(Actor self)
|
||||||
|
{
|
||||||
|
if (anim == null)
|
||||||
|
{
|
||||||
|
anim = new Animation("3tnk");
|
||||||
|
anim.PlayRepeating("idle");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetTiles(TileTemplate template, Dictionary<int2, int> replacedTiles)
|
||||||
|
{
|
||||||
|
/* todo: stash these, etc */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -44,6 +44,8 @@ namespace OpenRa
|
|||||||
|
|
||||||
CreateActor("World", new int2(int.MaxValue, int.MaxValue), null);
|
CreateActor("World", new int2(int.MaxValue, int.MaxValue), null);
|
||||||
|
|
||||||
|
Bridges.MakeBridges(this);
|
||||||
|
|
||||||
WorldRenderer = new WorldRenderer(this, Game.renderer);
|
WorldRenderer = new WorldRenderer(this, Game.renderer);
|
||||||
Minimap = new Minimap(this, Game.renderer);
|
Minimap = new Minimap(this, Game.renderer);
|
||||||
}
|
}
|
||||||
|
|||||||
7
ra.yaml
7
ra.yaml
@@ -1435,6 +1435,13 @@ DOMF:
|
|||||||
Image: DOME
|
Image: DOME
|
||||||
Fake:
|
Fake:
|
||||||
|
|
||||||
|
BRIDGE:
|
||||||
|
Inherits: ^Building
|
||||||
|
Bridge:
|
||||||
|
BelowUnits:
|
||||||
|
-Selectable:
|
||||||
|
-Building:
|
||||||
|
|
||||||
T01:
|
T01:
|
||||||
Inherits: ^Building
|
Inherits: ^Building
|
||||||
Building:
|
Building:
|
||||||
|
|||||||
@@ -2491,6 +2491,8 @@ tiletype3=3
|
|||||||
Name=BR1A
|
Name=BR1A
|
||||||
width=4
|
width=4
|
||||||
height=3
|
height=3
|
||||||
|
bridge=yes
|
||||||
|
hp=1
|
||||||
tiletype1=3
|
tiletype1=3
|
||||||
tiletype2=2
|
tiletype2=2
|
||||||
tiletype4=3
|
tiletype4=3
|
||||||
@@ -2505,6 +2507,8 @@ tiletype11=3
|
|||||||
Name=BR1B
|
Name=BR1B
|
||||||
width=4
|
width=4
|
||||||
height=3
|
height=3
|
||||||
|
bridge=yes
|
||||||
|
hp=.5
|
||||||
tiletype1=3
|
tiletype1=3
|
||||||
tiletype2=6
|
tiletype2=6
|
||||||
tiletype4=3
|
tiletype4=3
|
||||||
@@ -2519,6 +2523,8 @@ tiletype11=3
|
|||||||
Name=BR1C
|
Name=BR1C
|
||||||
width=4
|
width=4
|
||||||
height=3
|
height=3
|
||||||
|
bridge=yes
|
||||||
|
hp=0
|
||||||
tiletype1=3
|
tiletype1=3
|
||||||
tiletype2=3
|
tiletype2=3
|
||||||
tiletype4=3
|
tiletype4=3
|
||||||
@@ -2533,6 +2539,8 @@ tiletype11=3
|
|||||||
Name=BR2A
|
Name=BR2A
|
||||||
width=5
|
width=5
|
||||||
height=3
|
height=3
|
||||||
|
bridge=yes
|
||||||
|
hp=1
|
||||||
tiletype1=3
|
tiletype1=3
|
||||||
tiletype2=2
|
tiletype2=2
|
||||||
tiletype5=3
|
tiletype5=3
|
||||||
@@ -2548,6 +2556,8 @@ tiletype13=3
|
|||||||
Name=BR2B
|
Name=BR2B
|
||||||
width=5
|
width=5
|
||||||
height=3
|
height=3
|
||||||
|
bridge=yes
|
||||||
|
hp=.5
|
||||||
tiletype1=3
|
tiletype1=3
|
||||||
tiletype2=6
|
tiletype2=6
|
||||||
tiletype5=3
|
tiletype5=3
|
||||||
@@ -2563,6 +2573,8 @@ tiletype13=3
|
|||||||
Name=BR2C
|
Name=BR2C
|
||||||
width=5
|
width=5
|
||||||
height=3
|
height=3
|
||||||
|
bridge=yes
|
||||||
|
hp=0
|
||||||
tiletype1=1
|
tiletype1=1
|
||||||
tiletype2=1
|
tiletype2=1
|
||||||
tiletype5=3
|
tiletype5=3
|
||||||
@@ -2578,6 +2590,8 @@ tiletype13=3
|
|||||||
Name=BR3A
|
Name=BR3A
|
||||||
width=4
|
width=4
|
||||||
height=2
|
height=2
|
||||||
|
bridge=yes
|
||||||
|
hp=1
|
||||||
tiletype0=3
|
tiletype0=3
|
||||||
tiletype1=2
|
tiletype1=2
|
||||||
tiletype5=2
|
tiletype5=2
|
||||||
@@ -2588,6 +2602,8 @@ tiletype7=3
|
|||||||
Name=BR3B
|
Name=BR3B
|
||||||
width=4
|
width=4
|
||||||
height=2
|
height=2
|
||||||
|
bridge=yes
|
||||||
|
hp=.5
|
||||||
tiletype0=3
|
tiletype0=3
|
||||||
tiletype1=2
|
tiletype1=2
|
||||||
tiletype5=2
|
tiletype5=2
|
||||||
@@ -2598,6 +2614,8 @@ tiletype7=3
|
|||||||
Name=BR3C
|
Name=BR3C
|
||||||
width=4
|
width=4
|
||||||
height=2
|
height=2
|
||||||
|
bridge=yes
|
||||||
|
hp=0
|
||||||
tiletype0=3
|
tiletype0=3
|
||||||
tiletype1=3
|
tiletype1=3
|
||||||
tiletype5=3
|
tiletype5=3
|
||||||
@@ -2608,6 +2626,8 @@ tiletype7=3
|
|||||||
Name=BR3D
|
Name=BR3D
|
||||||
width=4
|
width=4
|
||||||
height=2
|
height=2
|
||||||
|
bridge=yes
|
||||||
|
hp=0
|
||||||
tiletype0=5
|
tiletype0=5
|
||||||
tiletype1=3
|
tiletype1=3
|
||||||
tiletype5=5
|
tiletype5=5
|
||||||
@@ -2618,6 +2638,8 @@ tiletype7=5
|
|||||||
Name=BR3E
|
Name=BR3E
|
||||||
width=4
|
width=4
|
||||||
height=2
|
height=2
|
||||||
|
bridge=yes
|
||||||
|
hp=0
|
||||||
tiletype0=1
|
tiletype0=1
|
||||||
tiletype1=1
|
tiletype1=1
|
||||||
tiletype5=3
|
tiletype5=3
|
||||||
@@ -2628,6 +2650,8 @@ tiletype7=1
|
|||||||
Name=BR3F
|
Name=BR3F
|
||||||
width=4
|
width=4
|
||||||
height=2
|
height=2
|
||||||
|
bridge=yes
|
||||||
|
hp=0
|
||||||
tiletype0=1
|
tiletype0=1
|
||||||
tiletype1=1
|
tiletype1=1
|
||||||
tiletype5=1
|
tiletype5=1
|
||||||
|
|||||||
@@ -253,6 +253,7 @@ DOMF
|
|||||||
; pseudo-buildings
|
; pseudo-buildings
|
||||||
MINP
|
MINP
|
||||||
MINV
|
MINV
|
||||||
|
BRIDGE
|
||||||
|
|
||||||
|
|
||||||
; `Dimensions` is the size of a box that will include the whole building, excluding bib.
|
; `Dimensions` is the size of a box that will include the whole building, excluding bib.
|
||||||
@@ -533,6 +534,10 @@ Selectable=no
|
|||||||
Traits=Unit,RenderUnit,BelowUnits,InvisibleToOthers
|
Traits=Unit,RenderUnit,BelowUnits,InvisibleToOthers
|
||||||
Selectable=no
|
Selectable=no
|
||||||
|
|
||||||
|
[Bridge]
|
||||||
|
Traits=Bridge, BelowUnits
|
||||||
|
Selectable=no
|
||||||
|
|
||||||
[InfantryTypes]
|
[InfantryTypes]
|
||||||
DOG
|
DOG
|
||||||
E1
|
E1
|
||||||
|
|||||||
Reference in New Issue
Block a user