git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1131 993157c7-ee19-0410-b2c4-bb4e9862e678
This commit is contained in:
@@ -1,12 +1,16 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using OpenRa.FileFormats;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace OpenRa.TechTreeTest
|
namespace OpenRa.TechTreeTest
|
||||||
{
|
{
|
||||||
class Building
|
class Building
|
||||||
{
|
{
|
||||||
readonly string friendlyName;
|
readonly string friendlyName;
|
||||||
|
readonly string tag;
|
||||||
|
|
||||||
public string FriendlyName
|
public string FriendlyName
|
||||||
{
|
{
|
||||||
@@ -29,9 +33,10 @@ namespace OpenRa.TechTreeTest
|
|||||||
set { techLevel = value; }
|
set { techLevel = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public Building(string friendlyName)
|
public Building(string tag, string friendlyName)
|
||||||
{
|
{
|
||||||
this.friendlyName = friendlyName;
|
this.friendlyName = friendlyName;
|
||||||
|
this.tag = tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool ShouldMakeBuildable(IEnumerable<string> buildings)
|
public bool ShouldMakeBuildable(IEnumerable<string> buildings)
|
||||||
@@ -62,5 +67,30 @@ namespace OpenRa.TechTreeTest
|
|||||||
else if (!buildable && ShouldMakeBuildable(buildings))
|
else if (!buildable && ShouldMakeBuildable(buildings))
|
||||||
buildable = true;
|
buildable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Bitmap icon;
|
||||||
|
public Bitmap Icon
|
||||||
|
{
|
||||||
|
get { return icon ?? (icon = LoadIcon(tag)); }
|
||||||
|
}
|
||||||
|
|
||||||
|
static Package package = new Package("../../../hires.mix");
|
||||||
|
static Palette palette = new Palette( File.OpenRead("../../../temperat.pal"));
|
||||||
|
|
||||||
|
static Bitmap LoadIcon(string tag)
|
||||||
|
{
|
||||||
|
string filename = tag + "icon.shp";
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Stream s = package.GetContent(filename);
|
||||||
|
ShpReader reader = new ShpReader(s);
|
||||||
|
foreach (ImageHeader h in reader)
|
||||||
|
return BitmapBuilder.FromBytes(h.Image, reader.Width, reader.Height, palette);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
catch (FileNotFoundException) { return LoadIcon("dog"); }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ namespace OpenRa.TechTreeTest
|
|||||||
{
|
{
|
||||||
class TechTree
|
class TechTree
|
||||||
{
|
{
|
||||||
Dictionary<string, Building> buildings = new Dictionary<string,Building>();
|
Dictionary<string, Building> buildings = new Dictionary<string, Building>();
|
||||||
List<string> built;
|
public ICollection<string> built = new List<string>();
|
||||||
public TechTree()
|
public TechTree()
|
||||||
{
|
{
|
||||||
LoadBuildings();
|
LoadBuildings();
|
||||||
@@ -38,7 +38,7 @@ namespace OpenRa.TechTreeTest
|
|||||||
Regex pattern = new Regex(@"^(\w+),([\w ]+)$");
|
Regex pattern = new Regex(@"^(\w+),([\w ]+)$");
|
||||||
Match m = pattern.Match(line);
|
Match m = pattern.Match(line);
|
||||||
if (!m.Success) continue;
|
if (!m.Success) continue;
|
||||||
buildings.Add(m.Groups[0].Value, new Building(m.Groups[1].Value));
|
buildings.Add(m.Groups[1].Value, new Building(m.Groups[1].Value, m.Groups[2].Value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,9 +63,17 @@ namespace OpenRa.TechTreeTest
|
|||||||
void CheckAll()
|
void CheckAll()
|
||||||
{
|
{
|
||||||
foreach (Building building in buildings.Values)
|
foreach (Building building in buildings.Values)
|
||||||
{
|
|
||||||
building.CheckPrerequisites(built);
|
building.CheckPrerequisites(built);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IEnumerable<Building> BuildableItems
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
foreach (Building b in buildings.Values)
|
||||||
|
if (b.Buildable)
|
||||||
|
yield return b;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user