Clean up Buildable vs Tooltip vs Valued. cnc only.
This commit is contained in:
@@ -39,9 +39,9 @@ namespace OpenRA.GameRules
|
||||
foreach( var b in player.World.Queries.OwnedBy[player].Where( x=>x.Info.Traits.Contains<BuildingInfo>() ) )
|
||||
{
|
||||
ret[ b.Info.Name ].Add( b );
|
||||
var buildable = b.Info.Traits.GetOrDefault<BuildableInfo>();
|
||||
if( buildable != null )
|
||||
foreach( var alt in buildable.AlternateName )
|
||||
var tt = b.Info.Traits.GetOrDefault<TooltipInfo>();
|
||||
if( tt != null )
|
||||
foreach( var alt in tt.AlternateName )
|
||||
ret[ alt ].Add( b );
|
||||
}
|
||||
return ret;
|
||||
|
||||
@@ -13,26 +13,34 @@ namespace OpenRA.Traits
|
||||
public class ValuedInfo : ITraitInfo
|
||||
{
|
||||
public readonly int Cost = 0;
|
||||
public readonly string Description = "";
|
||||
public readonly string LongDesc = "";
|
||||
public readonly string[] Owner = { };
|
||||
|
||||
public virtual object Create(ActorInitializer init) { return new Valued(); }
|
||||
public object Create(ActorInitializer init) { return new Valued(); }
|
||||
}
|
||||
|
||||
public class BuildableInfo : ValuedInfo
|
||||
|
||||
public class TooltipInfo : ITraitInfo
|
||||
{
|
||||
public readonly string Description = "";
|
||||
public readonly string Name = "";
|
||||
public readonly string Icon = null;
|
||||
public readonly string[] AlternateName = { };
|
||||
public object Create(ActorInitializer init) { return new Tooltip(); }
|
||||
}
|
||||
|
||||
public class BuildableInfo : ITraitInfo
|
||||
{
|
||||
[ActorReference]public readonly string[] Prerequisites = { };
|
||||
[ActorReference] public readonly string[] BuiltAt = { };
|
||||
|
||||
public readonly string Icon = null;
|
||||
public readonly string[] AlternateName = { };
|
||||
[ActorReference]
|
||||
public readonly string[] Prerequisites = { };
|
||||
[ActorReference]
|
||||
public readonly string[] BuiltAt = { };
|
||||
|
||||
public readonly string[] Owner = { };
|
||||
|
||||
// todo: UI fluff; doesn't belong here
|
||||
public readonly int BuildPaletteOrder = 9999;
|
||||
public readonly string Hotkey = null;
|
||||
|
||||
public override object Create(ActorInitializer init) { return new Buildable(); }
|
||||
public object Create(ActorInitializer init) { return new Buildable(); }
|
||||
}
|
||||
|
||||
class Valued { } /* halfway to buildable */
|
||||
class Buildable { }
|
||||
class Valued { }
|
||||
class Buildable { }
|
||||
class Tooltip { }
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace OpenRA.Traits
|
||||
for (var n = 0; n < order.TargetLocation.X; n++) // repeat count
|
||||
{
|
||||
var unit = Rules.Info[order.TargetString];
|
||||
var ui = unit.Traits.Get<BuildableInfo>();
|
||||
var cost = unit.Traits.Contains<ValuedInfo>() ? unit.Traits.Get<ValuedInfo>().Cost : 0;
|
||||
var time = GetBuildTime(self, order.TargetString);
|
||||
|
||||
if (!Rules.TechTree.BuildableItems(order.Player, unit.Category).Contains(order.TargetString))
|
||||
@@ -63,7 +63,7 @@ namespace OpenRA.Traits
|
||||
bool hasPlayedSound = false;
|
||||
|
||||
BeginProduction(unit.Category,
|
||||
new ProductionItem(order.TargetString, (int)time, ui.Cost,
|
||||
new ProductionItem(order.TargetString, (int)time, cost,
|
||||
() => self.World.AddFrameEndTask(
|
||||
_ =>
|
||||
{
|
||||
@@ -102,8 +102,8 @@ namespace OpenRA.Traits
|
||||
return 0;
|
||||
|
||||
if (Game.LobbyInfo.GlobalSettings.AllowCheats && self.Trait<DeveloperMode>().FastBuild) return 0;
|
||||
var ui = unit.Traits.Get<BuildableInfo>();
|
||||
var time = ui.Cost
|
||||
var cost = unit.Traits.Contains<ValuedInfo>() ? unit.Traits.Get<ValuedInfo>().Cost : 0;
|
||||
var time = cost
|
||||
* self.Owner.PlayerActor.Info.Traits.Get<ProductionQueueInfo>().BuildSpeed /* todo: country-specific build speed bonus */
|
||||
* (25 * 60) /* frames per min */ /* todo: build acceleration, if we do that */
|
||||
/ 1000;
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace OpenRA.Traits
|
||||
if (owner.Country == null)
|
||||
return;
|
||||
|
||||
var effectivePrereq = prerequisites.Where( a => a.Traits.Get<BuildableInfo>().Owner.Contains( owner.Country.Race ) );
|
||||
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 ) );
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ namespace OpenRA.Traits
|
||||
var buildings = Rules.TechTree.GatherBuildings(Owner);
|
||||
var effectivePrereq = Info.Prerequisites
|
||||
.Select(a => a.ToLowerInvariant())
|
||||
.Where(a => Rules.Info[a].Traits.Get<ValuedInfo>().Owner.Contains(Owner.Country.Race));
|
||||
.Where(a => Rules.Info[a].Traits.Get<BuildableInfo>().Owner.Contains(Owner.Country.Race));
|
||||
|
||||
if (Info.Prerequisites.Count() == 0)
|
||||
return Owner.PlayerActor.Trait<PlayerResources>().GetPowerState() == PowerState.Normal;
|
||||
|
||||
@@ -47,8 +47,8 @@ namespace OpenRA.Widgets
|
||||
if (actor == null || !actor.IsVisible(world.LocalPlayer))
|
||||
return;
|
||||
|
||||
var text = actor.Info.Traits.Contains<ValuedInfo>()
|
||||
? actor.Info.Traits.Get<ValuedInfo>().Description
|
||||
var text = actor.Info.Traits.Contains<TooltipInfo>()
|
||||
? actor.Info.Traits.Get<TooltipInfo>().Name
|
||||
: actor.Info.Name;
|
||||
var text2 = (actor.Owner.NonCombatant)
|
||||
? "" : "{0}".F(actor.Owner.PlayerName);
|
||||
|
||||
Reference in New Issue
Block a user