Remove dead TechTree code
This commit is contained in:
@@ -18,8 +18,6 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
public static class Rules
|
public static class Rules
|
||||||
{
|
{
|
||||||
public static TechTree TechTree;
|
|
||||||
|
|
||||||
public static Dictionary<string, ActorInfo> Info;
|
public static Dictionary<string, ActorInfo> Info;
|
||||||
public static Dictionary<string, WeaponInfo> Weapons;
|
public static Dictionary<string, WeaponInfo> Weapons;
|
||||||
public static Dictionary<string, VoiceInfo> Voices;
|
public static Dictionary<string, VoiceInfo> Voices;
|
||||||
@@ -41,8 +39,6 @@ namespace OpenRA
|
|||||||
var t = new TileSet(file);
|
var t = new TileSet(file);
|
||||||
TileSets.Add(t.Id,t);
|
TileSets.Add(t.Id,t);
|
||||||
}
|
}
|
||||||
|
|
||||||
TechTree = new TechTree();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Dictionary<string, T> LoadYamlRules<T>(string[] files, List<MiniYamlNode> dict, Func<MiniYamlNode, Dictionary<string, MiniYaml>, T> f)
|
static Dictionary<string, T> LoadYamlRules<T>(string[] files, List<MiniYamlNode> dict, Func<MiniYamlNode, Dictionary<string, MiniYaml>, T> f)
|
||||||
|
|||||||
@@ -1,100 +0,0 @@
|
|||||||
#region Copyright & License Information
|
|
||||||
/*
|
|
||||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
|
||||||
* This file is part of OpenRA, which is free software. It is made
|
|
||||||
* available to you under the terms of the GNU General Public License
|
|
||||||
* as published by the Free Software Foundation. For more information,
|
|
||||||
* see LICENSE.
|
|
||||||
*/
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using OpenRA.FileFormats;
|
|
||||||
using OpenRA.Traits;
|
|
||||||
|
|
||||||
namespace OpenRA.GameRules
|
|
||||||
{
|
|
||||||
public class TechTree
|
|
||||||
{
|
|
||||||
readonly Cache<string, List<ActorInfo>> producesIndex = new Cache<string, List<ActorInfo>>(x => new List<ActorInfo>());
|
|
||||||
|
|
||||||
public TechTree()
|
|
||||||
{
|
|
||||||
foreach( var info in Rules.Info.Values )
|
|
||||||
{
|
|
||||||
var pi = info.Traits.GetOrDefault<ProductionInfo>();
|
|
||||||
if (pi != null)
|
|
||||||
foreach( var p in pi.Produces )
|
|
||||||
producesIndex[ p ].Add( info );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Cache<string, List<Actor>> GatherBuildings( Player player )
|
|
||||||
{
|
|
||||||
var ret = new Cache<string, List<Actor>>( x => new List<Actor>() );
|
|
||||||
if (player == null)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
foreach( var b in player.World.Queries.OwnedBy[player].Where( x=>x.Info.Traits.Contains<BuildingInfo>() ) )
|
|
||||||
{
|
|
||||||
ret[ b.Info.Name ].Add( b );
|
|
||||||
var tt = b.Info.Traits.GetOrDefault<TooltipInfo>();
|
|
||||||
if( tt != null )
|
|
||||||
foreach( var alt in tt.AlternateName )
|
|
||||||
ret[ alt ].Add( b );
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool CanBuild( ActorInfo info, Player player, Cache<string, List<Actor>> playerBuildings )
|
|
||||||
{
|
|
||||||
if (player == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
var bi = info.Traits.GetOrDefault<BuildableInfo>();
|
|
||||||
if( bi == null ) return false;
|
|
||||||
|
|
||||||
if( !bi.Owner.Contains( player.Country.Race ) )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
foreach( var p in bi.Prerequisites )
|
|
||||||
if( playerBuildings[ p ].Count == 0 )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if( producesIndex[ bi.Queue ].All( x => playerBuildings[ x.Name ].Count == 0 ) )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerable<string> BuildableItems( Player player, params string[] categories )
|
|
||||||
{
|
|
||||||
if (player == null)
|
|
||||||
yield break;
|
|
||||||
|
|
||||||
var playerBuildings = GatherBuildings( player );
|
|
||||||
foreach (var unit in AllBuildables(categories))
|
|
||||||
if( CanBuild( unit, player, playerBuildings ) )
|
|
||||||
yield return unit.Name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerable<ActorInfo> AllBuildables(params string[] categories)
|
|
||||||
{
|
|
||||||
return Rules.Info.Values
|
|
||||||
.Where( x => x.Name[ 0 ] != '^' )
|
|
||||||
.Where( x => x.Traits.Contains<BuildableInfo>() )
|
|
||||||
.Where( x => categories.Contains(x.Traits.Get<BuildableInfo>().Queue) );
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerable<ActorInfo> UnitBuiltAt( ActorInfo info )
|
|
||||||
{
|
|
||||||
var bi = info.Traits.Get<BuildableInfo>();
|
|
||||||
var builtAt = bi.BuiltAt;
|
|
||||||
if( builtAt.Length != 0 )
|
|
||||||
return builtAt.Select( x => Rules.Info[ x.ToLowerInvariant() ] );
|
|
||||||
else
|
|
||||||
return producesIndex[ bi.Queue ];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -41,7 +41,8 @@ namespace OpenRA.Traits
|
|||||||
this.Info = info;
|
this.Info = info;
|
||||||
|
|
||||||
var ttc = playerActor.Trait<TechTreeCache>();
|
var ttc = playerActor.Trait<TechTreeCache>();
|
||||||
foreach (var a in Rules.TechTree.AllBuildables(Info.Type))
|
|
||||||
|
foreach (var a in AllBuildables(Info.Type))
|
||||||
{
|
{
|
||||||
var bi = a.Traits.Get<BuildableInfo>();
|
var bi = a.Traits.Get<BuildableInfo>();
|
||||||
// Can our race build this by satisfying normal prereqs?
|
// Can our race build this by satisfying normal prereqs?
|
||||||
@@ -52,6 +53,14 @@ namespace OpenRA.Traits
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IEnumerable<ActorInfo> AllBuildables(string category)
|
||||||
|
{
|
||||||
|
return Rules.Info.Values
|
||||||
|
.Where( x => x.Name[ 0 ] != '^' )
|
||||||
|
.Where( x => x.Traits.Contains<BuildableInfo>() )
|
||||||
|
.Where( x => x.Traits.Get<BuildableInfo>().Queue == category );
|
||||||
|
}
|
||||||
|
|
||||||
public void OverrideProduction(ActorInfo type, bool buildable)
|
public void OverrideProduction(ActorInfo type, bool buildable)
|
||||||
{
|
{
|
||||||
Produceable[type].Buildable = buildable;
|
Produceable[type].Buildable = buildable;
|
||||||
@@ -100,8 +109,7 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
public bool CanBuild(ActorInfo actor)
|
public bool CanBuild(ActorInfo actor)
|
||||||
{
|
{
|
||||||
var buildings = Rules.TechTree.GatherBuildings( self.Owner );
|
return Produceable.ContainsKey(actor) && Produceable[actor].Buildable;
|
||||||
return Rules.TechTree.CanBuild(actor, self.Owner, buildings);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Tick( Actor self )
|
public virtual void Tick( Actor self )
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
public void Update()
|
public void Update()
|
||||||
{
|
{
|
||||||
var buildings = Rules.TechTree.GatherBuildings(player);
|
var buildings = GatherBuildings(player);
|
||||||
foreach(var w in watchers)
|
foreach(var w in watchers)
|
||||||
w.Update(buildings);
|
w.Update(buildings);
|
||||||
}
|
}
|
||||||
@@ -54,6 +54,23 @@ namespace OpenRA.Traits
|
|||||||
watchers.RemoveAll(x => x.key == key);
|
watchers.RemoveAll(x => x.key == key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Cache<string, List<Actor>> GatherBuildings( Player player )
|
||||||
|
{
|
||||||
|
var ret = new Cache<string, List<Actor>>( x => new List<Actor>() );
|
||||||
|
if (player == null)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
foreach( var b in player.World.Queries.OwnedBy[player].Where( x=>x.Info.Traits.Contains<BuildingInfo>() ) )
|
||||||
|
{
|
||||||
|
ret[ b.Info.Name ].Add( b );
|
||||||
|
var tt = b.Info.Traits.GetOrDefault<TooltipInfo>();
|
||||||
|
if( tt != null )
|
||||||
|
foreach( var alt in tt.AlternateName )
|
||||||
|
ret[ alt ].Add( b );
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
class Watcher
|
class Watcher
|
||||||
{
|
{
|
||||||
public readonly string key;
|
public readonly string key;
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ namespace OpenRA.Traits
|
|||||||
return Owner.PlayerActor.Trait<PlayerResources>().GetPowerState() == PowerState.Normal;
|
return Owner.PlayerActor.Trait<PlayerResources>().GetPowerState() == PowerState.Normal;
|
||||||
|
|
||||||
// Takes 0.3ms on pchote's machine -- calling it every tick for every active special power is retarded
|
// Takes 0.3ms on pchote's machine -- calling it every tick for every active special power is retarded
|
||||||
var buildings = Rules.TechTree.GatherBuildings(Owner);
|
var buildings = TechTreeCache.GatherBuildings(Owner);
|
||||||
|
|
||||||
return effectivePrereq.All(a => buildings[a].Any(b => !b.Trait<Building>().Disabled));
|
return effectivePrereq.All(a => buildings[a].Any(b => !b.Trait<Building>().Disabled));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user