Fix #611 - prereqs handled by traits. Make both cnc power plants valid for prereqs.
This commit is contained in:
@@ -33,8 +33,8 @@ namespace OpenRA.Mods.RA.Buildings
|
||||
public object Create(ActorInitializer init) { return new Building(init, this); }
|
||||
|
||||
public bool IsCloseEnoughToBase(World world, Player p, string buildingName, int2 topLeft)
|
||||
{
|
||||
if (p.PlayerActor.Trait<DeveloperMode>().BuildAnywhere)
|
||||
{
|
||||
if (p.PlayerActor.Trait<DeveloperMode>().BuildAnywhere)
|
||||
return true;
|
||||
|
||||
var buildingMaxBounds = Dimensions;
|
||||
@@ -63,7 +63,7 @@ namespace OpenRA.Mods.RA.Buildings
|
||||
}
|
||||
}
|
||||
|
||||
public class Building : INotifyDamage, IOccupySpace, INotifyCapture, ISync
|
||||
public class Building : INotifyDamage, IOccupySpace, INotifyCapture, ISync, ITechTreePrerequisite
|
||||
{
|
||||
readonly Actor self;
|
||||
public readonly BuildingInfo Info;
|
||||
@@ -73,7 +73,9 @@ namespace OpenRA.Mods.RA.Buildings
|
||||
PowerManager PlayerPower;
|
||||
|
||||
public int2 PxPosition { get { return ( 2 * topLeft + Info.Dimensions ) * Game.CellSize / 2; } }
|
||||
|
||||
|
||||
public IEnumerable<string> ProvidesPrerequisites { get { yield return self.Info.Name; } }
|
||||
|
||||
public Building(ActorInitializer init, BuildingInfo info)
|
||||
{
|
||||
this.self = init.self;
|
||||
|
||||
@@ -23,12 +23,10 @@ namespace OpenRA.Mods.RA.Buildings
|
||||
bool disabled = false;
|
||||
int normalPower = 0;
|
||||
PowerManager PowerManager;
|
||||
TechTree TechTree;
|
||||
|
||||
public CanPowerDown(ActorInitializer init)
|
||||
{
|
||||
PowerManager = init.self.Owner.PlayerActor.Trait<PowerManager>();
|
||||
TechTree = init.self.Owner.PlayerActor.Trait<TechTree>();
|
||||
normalPower = init.self.Info.Traits.Get<BuildingInfo>().Power;
|
||||
}
|
||||
public bool Disabled { get { return disabled; } }
|
||||
@@ -42,16 +40,12 @@ namespace OpenRA.Mods.RA.Buildings
|
||||
Sound.PlayToPlayer(self.Owner, disabled ? eva.EnablePower : eva.DisablePower);
|
||||
|
||||
PowerManager.UpdateActor(self, disabled ? 0 : normalPower);
|
||||
|
||||
// Rebuild the tech tree; some support powers require active buildings
|
||||
TechTree.Update();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
|
||||
{
|
||||
PowerManager = newOwner.PlayerActor.Trait<PowerManager>();
|
||||
TechTree = newOwner.PlayerActor.Trait<TechTree>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace OpenRA.Mods.RA.Buildings
|
||||
|
||||
public void ActorChanged(Actor a)
|
||||
{
|
||||
if (a.Owner == player && a.HasTrait<Building>())
|
||||
if (a.Owner == player && a.HasTrait<ITechTreePrerequisite>())
|
||||
Update();
|
||||
}
|
||||
|
||||
@@ -58,18 +58,14 @@ namespace OpenRA.Mods.RA.Buildings
|
||||
{
|
||||
var ret = new Cache<string, List<Actor>>( x => new List<Actor>() );
|
||||
if (player == null)
|
||||
return ret;
|
||||
|
||||
foreach (var b in player.World.ActorsWithTrait<BuildingInfo>()
|
||||
.Where(a => a.Actor.Owner == player).Select(a => a.Actor))
|
||||
{
|
||||
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;
|
||||
|
||||
|
||||
foreach (var b in player.World.ActorsWithTrait<ITechTreePrerequisite>()
|
||||
.Where(a => a.Actor.IsInWorld && !a.Actor.IsDead() && a.Actor.Owner == player))
|
||||
foreach (var p in b.Trait.ProvidesPrerequisites)
|
||||
ret[ p ].Add( b.Actor );
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -115,4 +111,26 @@ namespace OpenRA.Mods.RA.Buildings
|
||||
void PrerequisitesAvailable(string key);
|
||||
void PrerequisitesUnavailable(string key);
|
||||
}
|
||||
|
||||
public interface ITechTreePrerequisite
|
||||
{
|
||||
IEnumerable<string> ProvidesPrerequisites {get;}
|
||||
}
|
||||
|
||||
public class ProvidesCustomPrerequisiteInfo : ITraitInfo
|
||||
{
|
||||
public string Prerequisite;
|
||||
public object Create(ActorInitializer init) { return new ProvidesCustomPrerequisite(this);}
|
||||
}
|
||||
|
||||
public class ProvidesCustomPrerequisite : ITechTreePrerequisite
|
||||
{
|
||||
ProvidesCustomPrerequisiteInfo Info;
|
||||
public IEnumerable<string> ProvidesPrerequisites { get { yield return Info.Prerequisite; } }
|
||||
|
||||
public ProvidesCustomPrerequisite(ProvidesCustomPrerequisiteInfo info)
|
||||
{
|
||||
Info = info;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ namespace OpenRA.Mods.RA
|
||||
public readonly string Description = "";
|
||||
public readonly string Name = "";
|
||||
public readonly string Icon = null;
|
||||
public readonly string[] AlternateName = { };
|
||||
|
||||
public virtual object Create (ActorInitializer init) { return new Tooltip(init.self, this); }
|
||||
}
|
||||
|
||||
@@ -324,10 +324,22 @@ namespace OpenRA.Mods.RA.Widgets
|
||||
|
||||
static string Description( string a )
|
||||
{
|
||||
if( a[ 0 ] == '@' )
|
||||
return "any " + a.Substring( 1 );
|
||||
else
|
||||
return Rules.Info[ a.ToLowerInvariant() ].Traits.Get<TooltipInfo>().Name;
|
||||
// hack hack hack - going to die soon anyway
|
||||
if (a == "barracks")
|
||||
return "Infantry production";
|
||||
if (a == "vehicleproduction")
|
||||
return "Vehicle production";
|
||||
if (a == "techcenter")
|
||||
return "Tech Center";
|
||||
if (a == "anypower")
|
||||
return "Power Plant";
|
||||
|
||||
ActorInfo ai;
|
||||
Rules.Info.TryGetValue(a.ToLowerInvariant(), out ai);
|
||||
if (ai != null && ai.Traits.Contains<TooltipInfo>())
|
||||
return ai.Traits.Get<TooltipInfo>().Name;
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
void HandleBuildPalette( World world, string item, bool isLmb )
|
||||
|
||||
@@ -51,6 +51,8 @@ NUKE:
|
||||
Name: Power Plant
|
||||
Icon: nukeicnh
|
||||
Description: Provides power for other structures
|
||||
ProvidesCustomPrerequisite:
|
||||
Prerequisite: anypower
|
||||
Buildable:
|
||||
BuildPaletteOrder: 10
|
||||
Owner: gdi,nod
|
||||
@@ -75,7 +77,7 @@ PROC:
|
||||
Description: Processes raw Tiberium into useable resources
|
||||
Buildable:
|
||||
BuildPaletteOrder: 30
|
||||
Prerequisites: nuke
|
||||
Prerequisites: anypower
|
||||
Owner: gdi,nod
|
||||
Building:
|
||||
Power: -30
|
||||
@@ -140,10 +142,11 @@ PYLE:
|
||||
Name: Barracks
|
||||
Icon: pyleicnh
|
||||
Description: Trains infantry
|
||||
AlternateName: @Barracks
|
||||
ProvidesCustomPrerequisite:
|
||||
Prerequisite: barracks
|
||||
Buildable:
|
||||
BuildPaletteOrder: 40
|
||||
Prerequisites: nuke
|
||||
Prerequisites: anypower
|
||||
Owner: gdi
|
||||
Building:
|
||||
Power: -20
|
||||
@@ -182,10 +185,11 @@ HAND:
|
||||
Name: Hand of Nod
|
||||
Icon: handicnh
|
||||
Description: Trains infantry
|
||||
AlternateName: @Barracks
|
||||
ProvidesCustomPrerequisite:
|
||||
Prerequisite: barracks
|
||||
Buildable:
|
||||
BuildPaletteOrder: 40
|
||||
Prerequisites: nuke
|
||||
Prerequisites: anypower
|
||||
Owner: nod
|
||||
Building:
|
||||
Power: -20
|
||||
@@ -220,8 +224,9 @@ AFLD:
|
||||
Tooltip:
|
||||
Name: Airstrip
|
||||
Icon: afldicnh
|
||||
AlternateName: @Vehicle Production
|
||||
Description: Provides a dropzone for vehicle reinforcements
|
||||
ProvidesCustomPrerequisite:
|
||||
Prerequisite: vehicleproduction
|
||||
Buildable:
|
||||
BuildPaletteOrder: 60
|
||||
Prerequisites: proc
|
||||
@@ -261,8 +266,9 @@ WEAP:
|
||||
Tooltip:
|
||||
Name: Weapons Factory
|
||||
Icon: weapicnh
|
||||
AlternateName: @Vehicle Production
|
||||
Description: Assembly point for vehicle reinforcements
|
||||
ProvidesCustomPrerequisite:
|
||||
Prerequisite: vehicleproduction
|
||||
Buildable:
|
||||
BuildPaletteOrder: 60
|
||||
Prerequisites: proc
|
||||
@@ -342,6 +348,8 @@ NUK2:
|
||||
Name: Advanced Power Plant
|
||||
Icon:nuk2icnh
|
||||
Description: Provides more power, cheaper than the \nstandard Power Plant
|
||||
ProvidesCustomPrerequisite:
|
||||
Prerequisite: anypower
|
||||
Buildable:
|
||||
BuildPaletteOrder: 90
|
||||
Prerequisites: hq
|
||||
@@ -367,7 +375,7 @@ FIX:
|
||||
Description: Repairs vehicles and allows the\nconstruction of additional bases.
|
||||
Buildable:
|
||||
BuildPaletteOrder: 70
|
||||
Prerequisites: @Vehicle Production
|
||||
Prerequisites: vehicleproduction
|
||||
Owner: gdi,nod
|
||||
Building:
|
||||
Power: -30
|
||||
@@ -394,7 +402,7 @@ HPAD:
|
||||
Description: Produces and reloads helicopters
|
||||
Buildable:
|
||||
BuildPaletteOrder: 50
|
||||
Prerequisites: @Barracks
|
||||
Prerequisites: barracks
|
||||
Owner: gdi,nod
|
||||
Building:
|
||||
Power: -10
|
||||
@@ -434,7 +442,6 @@ EYE:
|
||||
Name: Advanced Communications Center
|
||||
Icon: eyeicnh
|
||||
Description: Provides access to the Ion Cannon.\n Requires power to operate.
|
||||
AlternateName: @Superweapon
|
||||
Buildable:
|
||||
BuildPaletteOrder: 100
|
||||
Prerequisites: hq
|
||||
@@ -474,7 +481,6 @@ TMPL:
|
||||
Name: Temple of Nod
|
||||
Icon: tmplicnh
|
||||
Description: Place of worship and secret missile silo.\nRequires power to operate.
|
||||
AlternateName: @Superweapon
|
||||
Buildable:
|
||||
BuildPaletteOrder: 100
|
||||
Prerequisites: hq
|
||||
@@ -616,7 +622,7 @@ GUN:
|
||||
Buildable:
|
||||
Queue: Defense
|
||||
BuildPaletteOrder: 40
|
||||
Prerequisites: @Barracks
|
||||
Prerequisites: barracks
|
||||
Owner: gdi,nod
|
||||
Building:
|
||||
Power: -20
|
||||
@@ -684,7 +690,7 @@ GTWR:
|
||||
Buildable:
|
||||
Queue: Defense
|
||||
BuildPaletteOrder: 50
|
||||
Prerequisites: @Barracks
|
||||
Prerequisites: barracks
|
||||
Owner: gdi,nod
|
||||
Building:
|
||||
Power: -10
|
||||
|
||||
@@ -210,7 +210,7 @@ E7:
|
||||
Buildable:
|
||||
Queue: Infantry
|
||||
BuildPaletteOrder: 110
|
||||
Prerequisites: @Tech Center, @Barracks
|
||||
Prerequisites: techcenter, barracks
|
||||
Owner: allies,soviet
|
||||
BuiltAt: barr,tent
|
||||
Valued:
|
||||
|
||||
@@ -9,7 +9,7 @@ MSLO:
|
||||
Buildable:
|
||||
Queue: Defense
|
||||
BuildPaletteOrder: 130
|
||||
Prerequisites: @Tech Center
|
||||
Prerequisites: techcenter
|
||||
Owner: soviet,allies
|
||||
Building:
|
||||
Power: -100
|
||||
@@ -76,7 +76,7 @@ SPEN:
|
||||
Buildable:
|
||||
Queue: Building
|
||||
BuildPaletteOrder: 30
|
||||
Prerequisites: @Power Plant
|
||||
Prerequisites: anypower
|
||||
Owner: soviet
|
||||
Hotkey: y
|
||||
TargetableBuilding:
|
||||
@@ -127,7 +127,7 @@ SYRD:
|
||||
Buildable:
|
||||
Queue: Building
|
||||
BuildPaletteOrder: 40
|
||||
Prerequisites: @Power Plant
|
||||
Prerequisites: anypower
|
||||
Owner: allies
|
||||
Hotkey: y
|
||||
Valued:
|
||||
@@ -528,7 +528,8 @@ ATEK:
|
||||
Tooltip:
|
||||
Name: Allied Tech Center
|
||||
Description: Provides Allied advanced technologies.\n Special Ability: GPS Satellite
|
||||
AlternateName: @Tech Center
|
||||
ProvidesCustomPrerequisite:
|
||||
Prerequisite: techcenter
|
||||
Building:
|
||||
Power: -200
|
||||
Footprint: xx xx
|
||||
@@ -625,7 +626,7 @@ PROC:
|
||||
Buildable:
|
||||
Queue: Building
|
||||
BuildPaletteOrder: 10
|
||||
Prerequisites: @Power Plant
|
||||
Prerequisites: anypower
|
||||
Owner: allies,soviet
|
||||
Hotkey: e
|
||||
Valued:
|
||||
@@ -789,7 +790,8 @@ POWR:
|
||||
Tooltip:
|
||||
Name: Power Plant
|
||||
Description: Provides power for other structures
|
||||
AlternateName: @Power Plant
|
||||
ProvidesCustomPrerequisite:
|
||||
Prerequisite: anypower
|
||||
Building:
|
||||
Power: 100
|
||||
Footprint: xx xx
|
||||
@@ -817,7 +819,8 @@ APWR:
|
||||
Tooltip:
|
||||
Name: Advanced Power Plant
|
||||
Description: Provides more power, cheaper than the \nstandard Power Plant
|
||||
AlternateName: @Power Plant
|
||||
ProvidesCustomPrerequisite:
|
||||
Prerequisite: anypower
|
||||
Building:
|
||||
Power: 200
|
||||
Footprint: ___ xxx xxx
|
||||
@@ -845,7 +848,8 @@ STEK:
|
||||
Tooltip:
|
||||
Name: Soviet Tech Center
|
||||
Description: Provides Soviet advanced technologies
|
||||
AlternateName: @Tech Center
|
||||
ProvidesCustomPrerequisite:
|
||||
Prerequisite: techcenter
|
||||
Building:
|
||||
Power: -100
|
||||
Footprint: xxx xxx
|
||||
@@ -865,7 +869,7 @@ BARR:
|
||||
Buildable:
|
||||
Queue: Building
|
||||
BuildPaletteOrder: 30
|
||||
Prerequisites: @Power Plant
|
||||
Prerequisites: anypower
|
||||
Owner: soviet
|
||||
Hotkey: b
|
||||
Valued:
|
||||
@@ -873,7 +877,8 @@ BARR:
|
||||
Tooltip:
|
||||
Name: Soviet Barracks
|
||||
Description: Produces infantry
|
||||
AlternateName: @Barracks
|
||||
ProvidesCustomPrerequisite:
|
||||
Prerequisite: barracks
|
||||
Building:
|
||||
Power: -20
|
||||
Footprint: xx xx
|
||||
@@ -904,7 +909,7 @@ TENT:
|
||||
Buildable:
|
||||
Queue: Building
|
||||
BuildPaletteOrder: 30
|
||||
Prerequisites: @Power Plant
|
||||
Prerequisites: anypower
|
||||
Owner: allies
|
||||
Hotkey: b
|
||||
Valued:
|
||||
@@ -912,7 +917,8 @@ TENT:
|
||||
Tooltip:
|
||||
Name: Allied Barracks
|
||||
Description: Produces infantry
|
||||
AlternateName: @Barracks
|
||||
ProvidesCustomPrerequisite:
|
||||
Prerequisite: barracks
|
||||
Building:
|
||||
Power: -20
|
||||
Footprint: xx xx
|
||||
@@ -1031,7 +1037,7 @@ SYRF:
|
||||
Name: Fake Shipyard
|
||||
# Buildable:
|
||||
# BuildPaletteOrder: 900
|
||||
# Prerequisites: @Power Plant
|
||||
# Prerequisites: anypower
|
||||
# Owner: allies
|
||||
# Cost: 50
|
||||
# Description: Fake Shipyard
|
||||
|
||||
Reference in New Issue
Block a user