Tech tree changes to support non-buildable prerequisites, capturable superweapons, "hidden tech" for tech buildings, scripted tech unlocks, "build everything" developer toggle.

This commit is contained in:
Paul Chote
2010-08-27 23:51:12 +12:00
parent 7f3e491ecc
commit 853e60f76e
9 changed files with 141 additions and 76 deletions

View File

@@ -35,6 +35,7 @@ namespace OpenRA.Traits
public readonly string[] Owner = { }; public readonly string[] Owner = { };
public readonly string Queue; public readonly string Queue;
public readonly bool Hidden = false;
// todo: UI fluff; doesn't belong here // todo: UI fluff; doesn't belong here
public readonly int BuildPaletteOrder = 9999; public readonly int BuildPaletteOrder = 9999;

View File

@@ -25,11 +25,11 @@ namespace OpenRA.Traits
public class DeveloperMode : IResolveOrder public class DeveloperMode : IResolveOrder
{ {
DeveloperModeInfo Info; DeveloperModeInfo Info;
[Sync] [Sync] public bool FastCharge;
public bool FastCharge; [Sync] public bool AllTech;
public bool FastBuild; [Sync] public bool FastBuild;
public bool DisableShroud; [Sync] public bool DisableShroud;
public bool PathDebug; [Sync] public bool PathDebug;
public DeveloperMode(DeveloperModeInfo info) public DeveloperMode(DeveloperModeInfo info)
{ {
@@ -46,6 +46,11 @@ namespace OpenRA.Traits
switch(order.OrderString) switch(order.OrderString)
{ {
case "DevEnableTech":
{
AllTech ^= true;
break;
}
case "DevFastCharge": case "DevFastCharge":
{ {
FastCharge ^= true; FastCharge ^= true;

View File

@@ -23,39 +23,79 @@ namespace OpenRA.Traits
public object Create(ActorInitializer init) { return new ProductionQueue(init.self, this); } public object Create(ActorInitializer init) { return new ProductionQueue(init.self, this); }
} }
public class ProductionQueue : IResolveOrder, ITick public class ProductionQueue : IResolveOrder, ITick, ITechTreeElement
{ {
public readonly Actor self; public readonly Actor self;
public ProductionQueueInfo Info; public ProductionQueueInfo Info;
// TODO: sync this
List<ProductionItem> Producing = new List<ProductionItem>(); // TODO: sync these
// A list of things we are currently building
List<ProductionItem> Queue = new List<ProductionItem>();
// A list of things we could possibly build, even if our race doesn't normally get it
Dictionary<ActorInfo, ProductionState> Produceable = new Dictionary<ActorInfo, ProductionState>();
public ProductionQueue( Actor self, ProductionQueueInfo info ) public ProductionQueue( Actor self, ProductionQueueInfo info )
{ {
this.self = self; this.self = self;
this.Info = info; this.Info = info;
var ttc = self.Owner.PlayerActor.Trait<TechTreeCache>();
foreach (var a in Rules.TechTree.AllBuildables(Info.Type))
{
var bi = a.Traits.Get<BuildableInfo>();
// Can our race build this by satisfying normal prereqs?
var buildable = bi.Owner.Contains(self.Owner.Country.Race);
Produceable.Add( a, new ProductionState(){ Visible = buildable && !bi.Hidden } );
if (buildable)
ttc.Add( a.Name, a.Traits.Get<BuildableInfo>().Prerequisites.ToList(), this );
}
}
public void OverrideProduction(ActorInfo type, bool buildable)
{
Produceable[type].Buildable = buildable;
Produceable[type].Sticky = true;
}
public void PrerequisitesAvailable(string key)
{
var ps = Produceable[ Rules.Info[key] ];
if (!ps.Sticky)
ps.Buildable = true;
}
public void PrerequisitesUnavailable(string key)
{
var ps = Produceable[ Rules.Info[key] ];
if (!ps.Sticky)
ps.Buildable = false;
} }
public ProductionItem CurrentItem() public ProductionItem CurrentItem()
{ {
return Producing.ElementAtOrDefault(0); return Queue.ElementAtOrDefault(0);
} }
public IEnumerable<ProductionItem> AllQueued() public IEnumerable<ProductionItem> AllQueued()
{ {
return Producing; return Queue;
} }
public IEnumerable<ActorInfo> AllItems() public IEnumerable<ActorInfo> AllItems()
{ {
return Rules.TechTree.AllBuildables(Info.Type) if (Game.LobbyInfo.GlobalSettings.AllowCheats && self.Owner.PlayerActor.Trait<DeveloperMode>().AllTech)
.Where(a => a.Traits.Get<BuildableInfo>().Owner.Contains(self.Owner.Country.Race)) return Produceable.Select(a => a.Key);
.OrderBy(a => a.Traits.Get<BuildableInfo>().BuildPaletteOrder);
return Produceable.Where(a => a.Value.Buildable || a.Value.Visible).Select(a => a.Key);
} }
public IEnumerable<ActorInfo> BuildableItems() public IEnumerable<ActorInfo> BuildableItems()
{ {
return Rules.TechTree.BuildableItems(self.Owner, Info.Type).Select(b => Rules.Info[b.ToLowerInvariant()]); if (Game.LobbyInfo.GlobalSettings.AllowCheats && self.Owner.PlayerActor.Trait<DeveloperMode>().AllTech)
return Produceable.Select(a => a.Key);
return Produceable.Where(a => a.Value.Buildable).Select(a => a.Key);
} }
public bool CanBuild(ActorInfo actor) public bool CanBuild(ActorInfo actor)
@@ -66,13 +106,13 @@ namespace OpenRA.Traits
public void Tick( Actor self ) public void Tick( Actor self )
{ {
while( Producing.Count > 0 && !BuildableItems().Any(b => b.Name == Producing[ 0 ].Item) ) while( Queue.Count > 0 && !BuildableItems().Any(b => b.Name == Queue[ 0 ].Item) )
{ {
self.Owner.PlayerActor.Trait<PlayerResources>().GiveCash(Producing[0].TotalCost - Producing[0].RemainingCost); // refund what's been paid so far. self.Owner.PlayerActor.Trait<PlayerResources>().GiveCash(Queue[0].TotalCost - Queue[0].RemainingCost); // refund what's been paid so far.
FinishProduction(); FinishProduction();
} }
if( Producing.Count > 0 ) if( Queue.Count > 0 )
Producing[ 0 ].Tick( self.Owner ); Queue[ 0 ].Tick( self.Owner );
} }
public void ResolveOrder( Actor self, Order order ) public void ResolveOrder( Actor self, Order order )
@@ -115,8 +155,8 @@ namespace OpenRA.Traits
} }
case "PauseProduction": case "PauseProduction":
{ {
if( Producing.Count > 0 && Producing[0].Item == order.TargetString ) if( Queue.Count > 0 && Queue[0].Item == order.TargetString )
Producing[0].Paused = ( order.TargetLocation.X != 0 ); Queue[0].Paused = ( order.TargetLocation.X != 0 );
break; break;
} }
case "CancelProduction": case "CancelProduction":
@@ -144,17 +184,15 @@ namespace OpenRA.Traits
void CancelProduction( string itemName ) void CancelProduction( string itemName )
{ {
if (Producing.Count == 0) if (Queue.Count == 0)
return; // Nothing to do here return; // Nothing to do here
var lastIndex = Producing.FindLastIndex( a => a.Item == itemName ); var lastIndex = Queue.FindLastIndex( a => a.Item == itemName );
if (lastIndex > 0) if (lastIndex > 0)
{ Queue.RemoveAt(lastIndex);
Producing.RemoveAt(lastIndex);
}
else if( lastIndex == 0 ) else if( lastIndex == 0 )
{ {
var item = Producing[0]; var item = Queue[0];
self.Owner.PlayerActor.Trait<PlayerResources>().GiveCash(item.TotalCost - item.RemainingCost); // refund what's been paid so far. self.Owner.PlayerActor.Trait<PlayerResources>().GiveCash(item.TotalCost - item.RemainingCost); // refund what's been paid so far.
FinishProduction(); FinishProduction();
} }
@@ -162,13 +200,13 @@ namespace OpenRA.Traits
public void FinishProduction() public void FinishProduction()
{ {
if (Producing.Count == 0) return; if (Queue.Count == 0) return;
Producing.RemoveAt(0); Queue.RemoveAt(0);
} }
void BeginProduction( ProductionItem item ) void BeginProduction( ProductionItem item )
{ {
Producing.Add(item); Queue.Add(item);
} }
static bool IsDisabledBuilding(Actor a) static bool IsDisabledBuilding(Actor a)
@@ -213,6 +251,13 @@ namespace OpenRA.Traits
} }
} }
public class ProductionState
{
public bool Visible = false;
public bool Buildable = false;
public bool Sticky = false;
}
public class ProductionItem public class ProductionItem
{ {
public readonly string Item; public readonly string Item;

View File

@@ -21,12 +21,15 @@ namespace OpenRA.Traits
{ {
class Watcher class Watcher
{ {
public readonly List<ActorInfo> prerequisites; public readonly string key;
// strings may be either actor type, or "alternate name" key
public readonly List<string> prerequisites;
public readonly ITechTreeElement watcher; public readonly ITechTreeElement watcher;
bool hasPrerequisites; bool hasPrerequisites;
public Watcher(List<ActorInfo> prerequisites, ITechTreeElement watcher) public Watcher(string key, List<string> prerequisites, ITechTreeElement watcher)
{ {
this.key = key;
this.prerequisites = prerequisites; this.prerequisites = prerequisites;
this.watcher = watcher; this.watcher = watcher;
this.hasPrerequisites = false; this.hasPrerequisites = false;
@@ -34,18 +37,13 @@ namespace OpenRA.Traits
public void Tick( Player owner, Cache<string, List<Actor>> buildings ) public void Tick( Player owner, Cache<string, List<Actor>> buildings )
{ {
if (owner.Country == null) var nowHasPrerequisites = prerequisites.All( a => buildings[ a ].Any( b => !b.Trait<Building>().Disabled ) );
return;
var effectivePrereq = prerequisites.Where( a => a.Traits.Contains<BuildableInfo>() && a.Traits.Get<BuildableInfo>().Owner.Contains( owner.Country.Race ) );
var nowHasPrerequisites = effectivePrereq.Any() &&
effectivePrereq.All( a => buildings[ a.Name ].Any( b => !b.Trait<Building>().Disabled ) );
if( nowHasPrerequisites && !hasPrerequisites ) if( nowHasPrerequisites && !hasPrerequisites )
watcher.Available(); watcher.PrerequisitesAvailable(key);
if( !nowHasPrerequisites && hasPrerequisites ) if( !nowHasPrerequisites && hasPrerequisites )
watcher.Unavailable(); watcher.PrerequisitesUnavailable(key);
hasPrerequisites = nowHasPrerequisites; hasPrerequisites = nowHasPrerequisites;
} }
@@ -61,20 +59,20 @@ namespace OpenRA.Traits
w.Tick( self.Owner, buildings ); w.Tick( self.Owner, buildings );
} }
public void Add( List<ActorInfo> prerequisites, ITechTreeElement tte ) public void Add( string key, List<string> prerequisites, ITechTreeElement tte )
{ {
watchers.Add( new Watcher( prerequisites, tte ) ); watchers.Add( new Watcher( key, prerequisites, tte ) );
} }
public void Remove( ITechTreeElement tte ) public void Remove( string key )
{ {
watchers.RemoveAll( x => x.watcher == tte ); watchers.RemoveAll( x => x.key == key );
} }
} }
interface ITechTreeElement interface ITechTreeElement
{ {
void Available(); void PrerequisitesAvailable(string key);
void Unavailable(); void PrerequisitesUnavailable(string key);
} }
} }

View File

@@ -59,7 +59,7 @@ namespace OpenRA.Traits
Self = self; Self = self;
Owner = self.Owner; Owner = self.Owner;
self.Trait<TechTreeCache>().Add( Info.Prerequisites.Select( a => Rules.Info[ a.ToLowerInvariant() ] ).ToList(), this ); self.Trait<TechTreeCache>().Add( Info.OrderName, Info.Prerequisites.Select( a => a.ToLowerInvariant() ).ToList(), this );
} }
public void Tick(Actor self) public void Tick(Actor self)
@@ -95,8 +95,7 @@ namespace OpenRA.Traits
{ {
var buildings = Rules.TechTree.GatherBuildings(Owner); var buildings = Rules.TechTree.GatherBuildings(Owner);
var effectivePrereq = Info.Prerequisites var effectivePrereq = Info.Prerequisites
.Select(a => a.ToLowerInvariant()) .Select(a => a.ToLowerInvariant());
.Where(a => Rules.Info[a].Traits.Get<BuildableInfo>().Owner.Contains(Owner.Country.Race));
if (Info.Prerequisites.Count() == 0) if (Info.Prerequisites.Count() == 0)
return Owner.PlayerActor.Trait<PlayerResources>().GetPowerState() == PowerState.Normal; return Owner.PlayerActor.Trait<PlayerResources>().GetPowerState() == PowerState.Normal;
@@ -146,12 +145,12 @@ namespace OpenRA.Traits
bool hasPrerequisites; bool hasPrerequisites;
public void Available() public void PrerequisitesAvailable(string key)
{ {
hasPrerequisites = true; hasPrerequisites = true;
} }
public void Unavailable() public void PrerequisitesUnavailable(string key)
{ {
hasPrerequisites = false; hasPrerequisites = false;
} }

View File

@@ -40,52 +40,60 @@ namespace OpenRA.Widgets.Delegates
return true; return true;
}; };
devmodeBG.GetWidget<CheckboxWidget>("SETTINGS_CHECKBOX_SHROUD").Checked = devmodeBG.GetWidget<CheckboxWidget>("CHECKBOX_SHROUD").Checked =
() => Game.world.LocalPlayer.PlayerActor.Trait<DeveloperMode>().DisableShroud; () => Game.world.LocalPlayer.PlayerActor.Trait<DeveloperMode>().DisableShroud;
devmodeBG.GetWidget<CheckboxWidget>("SETTINGS_CHECKBOX_SHROUD").OnMouseDown = mi => devmodeBG.GetWidget<CheckboxWidget>("CHECKBOX_SHROUD").OnMouseDown = mi =>
{ {
Game.IssueOrder(new Order("DevShroud", Game.world.LocalPlayer.PlayerActor)); Game.IssueOrder(new Order("DevShroud", Game.world.LocalPlayer.PlayerActor));
return true; return true;
}; };
devmodeBG.GetWidget<CheckboxWidget>("SETTINGS_CHECKBOX_UNITDEBUG").Checked = devmodeBG.GetWidget<CheckboxWidget>("CHECKBOX_UNITDEBUG").Checked =
() => Game.Settings.Debug.ShowCollisions; () => Game.Settings.Debug.ShowCollisions;
devmodeBG.GetWidget("SETTINGS_CHECKBOX_UNITDEBUG").OnMouseDown = mi => devmodeBG.GetWidget("CHECKBOX_UNITDEBUG").OnMouseDown = mi =>
{ {
Game.IssueOrder(new Order("DevUnitDebug", Game.world.LocalPlayer.PlayerActor)); Game.IssueOrder(new Order("DevUnitDebug", Game.world.LocalPlayer.PlayerActor));
return true; return true;
}; };
devmodeBG.GetWidget<CheckboxWidget>("SETTINGS_CHECKBOX_PATHDEBUG").Checked = devmodeBG.GetWidget<CheckboxWidget>("CHECKBOX_PATHDEBUG").Checked =
() => Game.world.LocalPlayer.PlayerActor.Trait<DeveloperMode>().PathDebug; () => Game.world.LocalPlayer.PlayerActor.Trait<DeveloperMode>().PathDebug;
devmodeBG.GetWidget("SETTINGS_CHECKBOX_PATHDEBUG").OnMouseDown = mi => devmodeBG.GetWidget("CHECKBOX_PATHDEBUG").OnMouseDown = mi =>
{ {
Game.IssueOrder(new Order("DevPathDebug", Game.world.LocalPlayer.PlayerActor)); Game.IssueOrder(new Order("DevPathDebug", Game.world.LocalPlayer.PlayerActor));
return true; return true;
}; };
devmodeBG.GetWidget<ButtonWidget>("SETTINGS_GIVE_CASH").OnMouseUp = mi => devmodeBG.GetWidget<ButtonWidget>("GIVE_CASH").OnMouseUp = mi =>
{ {
Game.IssueOrder(new Order("DevGiveCash", Game.world.LocalPlayer.PlayerActor)); Game.IssueOrder(new Order("DevGiveCash", Game.world.LocalPlayer.PlayerActor));
return true; return true;
}; };
devmodeBG.GetWidget<CheckboxWidget>("SETTINGS_BUILD_SPEED").Checked = devmodeBG.GetWidget<CheckboxWidget>("INSTANT_BUILD").Checked =
() => Game.world.LocalPlayer.PlayerActor.Trait<DeveloperMode>().FastBuild; () => Game.world.LocalPlayer.PlayerActor.Trait<DeveloperMode>().FastBuild;
devmodeBG.GetWidget<CheckboxWidget>("SETTINGS_BUILD_SPEED").OnMouseDown = mi => devmodeBG.GetWidget<CheckboxWidget>("INSTANT_BUILD").OnMouseDown = mi =>
{ {
Game.IssueOrder(new Order("DevFastBuild", Game.world.LocalPlayer.PlayerActor)); Game.IssueOrder(new Order("DevFastBuild", Game.world.LocalPlayer.PlayerActor));
return true; return true;
}; };
devmodeBG.GetWidget<CheckboxWidget>("SETTINGS_CHARGE_TIME").Checked = devmodeBG.GetWidget<CheckboxWidget>("INSTANT_CHARGE").Checked =
() => Game.world.LocalPlayer.PlayerActor.Trait<DeveloperMode>().FastCharge; () => Game.world.LocalPlayer.PlayerActor.Trait<DeveloperMode>().FastCharge;
devmodeBG.GetWidget<CheckboxWidget>("SETTINGS_CHARGE_TIME").OnMouseDown = mi => devmodeBG.GetWidget<CheckboxWidget>("INSTANT_CHARGE").OnMouseDown = mi =>
{ {
Game.IssueOrder(new Order("DevFastCharge", Game.world.LocalPlayer.PlayerActor)); Game.IssueOrder(new Order("DevFastCharge", Game.world.LocalPlayer.PlayerActor));
return true; return true;
}; };
devmodeBG.GetWidget<CheckboxWidget>("ENABLE_TECH").Checked =
() => Game.world.LocalPlayer.PlayerActor.Trait<DeveloperMode>().AllTech;
devmodeBG.GetWidget<CheckboxWidget>("ENABLE_TECH").OnMouseDown = mi =>
{
Game.IssueOrder(new Order("DevEnableTech", Game.world.LocalPlayer.PlayerActor));
return true;
};
devModeButton.IsVisible = () => { return Game.LobbyInfo.GlobalSettings.AllowCheats; }; devModeButton.IsVisible = () => { return Game.LobbyInfo.GlobalSettings.AllowCheats; };
} }
} }

View File

@@ -186,8 +186,8 @@ namespace OpenRA.Mods.RA.Widgets
// Collect info // Collect info
var x = 0; var x = 0;
var y = 0; var y = 0;
var buildableItems = queue.BuildableItems(); var buildableItems = queue.BuildableItems().OrderBy(a => a.Traits.Get<BuildableInfo>().BuildPaletteOrder);
var allBuildables = queue.AllItems(); var allBuildables = queue.AllItems().OrderBy(a => a.Traits.Get<BuildableInfo>().BuildPaletteOrder);
var overlayBits = new List<Pair<Sprite, float2>>(); var overlayBits = new List<Pair<Sprite, float2>>();
numActualRows = Math.Max((allBuildables.Count() + Columns - 1) / Columns, Rows); numActualRows = Math.Max((allBuildables.Count() + Columns - 1) / Columns, Rows);

View File

@@ -204,7 +204,7 @@ Container@ROOT:
X:(WINDOW_RIGHT - WIDTH)/2 X:(WINDOW_RIGHT - WIDTH)/2
Y:(WINDOW_BOTTOM - HEIGHT)/2 Y:(WINDOW_BOTTOM - HEIGHT)/2
Width:350 Width:350
Height:300 Height:330
Visible:false Visible:false
Children: Children:
Label@LABEL_TITLE: Label@LABEL_TITLE:
@@ -215,48 +215,55 @@ Container@ROOT:
Height:25 Height:25
Text:Developer Mode Text:Developer Mode
Align:Center Align:Center
Checkbox@SETTINGS_CHECKBOX_SHROUD Checkbox@CHECKBOX_SHROUD
Id:SETTINGS_CHECKBOX_SHROUD Id:CHECKBOX_SHROUD
X:30 X:30
Y:50 Y:50
Height:20 Height:20
Width:PARENT_RIGHT - 30 Width:PARENT_RIGHT - 30
Text:Disable Shroud Text:Disable Shroud
Checkbox@SETTINGS_CHECKBOX_UNITDEBUG: Checkbox@CHECKBOX_UNITDEBUG:
Id:SETTINGS_CHECKBOX_UNITDEBUG Id:CHECKBOX_UNITDEBUG
X:30 X:30
Y:80 Y:80
Width:PARENT_RIGHT - 30 Width:PARENT_RIGHT - 30
Height:20 Height:20
Text:Show Occupied Cells Text:Show Occupied Cells
Checkbox@SETTINGS_CHECKBOX_PATHDEBUG: Checkbox@CHECKBOX_PATHDEBUG:
Id:SETTINGS_CHECKBOX_PATHDEBUG Id:CHECKBOX_PATHDEBUG
X:30 X:30
Y:110 Y:110
Width:PARENT_RIGHT - 30 Width:PARENT_RIGHT - 30
Height:20 Height:20
Text:Show Unit Paths Text:Show Unit Paths
Button@SETTINGS_GIVE_CASH Button@GIVE_CASH
Id:SETTINGS_GIVE_CASH Id:GIVE_CASH
X:30 X:30
Y:140 Y:140
Width:200 Width:200
Height:20 Height:20
Text: Give Cash Text: Give Cash
Checkbox@SETTINGS_BUILD_SPEED Checkbox@INSTANT_BUILD
Id:SETTINGS_BUILD_SPEED Id:INSTANT_BUILD
X:30 X:30
Y:170 Y:170
Width:PARENT_RIGHT - 30 Width:PARENT_RIGHT - 30
Height:20 Height:20
Text:Instant Build Speed Text:Instant Build Speed
Checkbox@SETTINGS_CHARGE_TIME Checkbox@INSTANT_CHARGE
Id:SETTINGS_CHARGE_TIME Id:INSTANT_CHARGE
X:30 X:30
Y:200 Y:200
Width:PARENT_RIGHT - 30 Width:PARENT_RIGHT - 30
Height:20 Height:20
Text:Instant Charge Time (Special Powers) Text:Instant Charge Time (Special Powers)
Checkbox@ENABLE_TECH
Id:ENABLE_TECH
X:30
Y:230
Width:PARENT_RIGHT - 30
Height:20
Text:Build Everything
Background@FMVPLAYER: Background@FMVPLAYER:
Id:FMVPLAYER Id:FMVPLAYER
Width:WINDOW_RIGHT Width:WINDOW_RIGHT

View File

@@ -1,5 +1,6 @@
FACT: FACT:
Inherits: ^Building Inherits: ^Building
-Buildable:
Valued: Valued:
Cost: 2000 Cost: 2000
Tooltip: Tooltip:
@@ -83,6 +84,7 @@ PROC.proxy:
PROC: PROC:
Inherits: ^Building Inherits: ^Building
-Buildable:
Valued: Valued:
Cost: 1700 Cost: 1700
Tooltip: Tooltip: