Skip to content

Commit

Permalink
move CYard trait and UndeployMCV activity into mod
Browse files Browse the repository at this point in the history
  • Loading branch information
ytinasni committed Jul 8, 2010
1 parent 1eedae2 commit 7a738ed
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 34 deletions.
3 changes: 1 addition & 2 deletions OpenRA.Game/OpenRA.Game.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
<Compile Include="GameRules\WeaponInfo.cs" />
<Compile Include="Group.cs" />
<Compile Include="Orders\GenericSelectTarget.cs" />
<Compile Include="Traits\Activities\UndeployMcv.cs" />
<Compile Include="Traits\BaseBuilding.cs" />
<Compile Include="Traits\DetectCloaked.cs" />
<Compile Include="Traits\LintAttributes.cs" />
<Compile Include="Traits\Modifiers\FrozenUnderFog.cs" />
Expand Down Expand Up @@ -184,7 +184,6 @@
<Compile Include="Traits\Buildable.cs" />
<Compile Include="Traits\Building.cs" />
<Compile Include="Traits\World\BuildingInfluence.cs" />
<Compile Include="Traits\ConstructionYard.cs" />
<Compile Include="Traits\LimitedAmmo.cs" />
<Compile Include="Traits\Player\PlaceBuilding.cs" />
<Compile Include="Traits\World\PlayerColorPalette.cs" />
Expand Down
11 changes: 11 additions & 0 deletions OpenRA.Game/Traits/BaseBuilding.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OpenRA.Traits
{
/* tag trait for "bases": mcv/fact */
class BaseBuildingInfo : TraitInfo<BaseBuilding> { }
class BaseBuilding { }
}
26 changes: 16 additions & 10 deletions OpenRA.Game/Traits/Player/PlaceBuilding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

using System.Linq;
using OpenRA.Effects;
using OpenRA.GameRules;

namespace OpenRA.Traits
{
Expand Down Expand Up @@ -63,16 +64,7 @@ public void ResolveOrder(Actor self, Order order)
Sound.PlayToPlayer(order.Player, s, building.CenterLocation);
}
/* todo: reimpl this properly */
var facts = w.Queries.OwnedBy[self.Owner]
.WithTrait<ConstructionYard>().Select(x => x.Actor);
var primaryFact = facts.Where(y => y.traits.Get<Production>().IsPrimary);
var fact = (primaryFact.Count() > 0) ? primaryFact.FirstOrDefault() : facts.FirstOrDefault();
if (fact != null)
fact.traits.Get<RenderBuilding>().PlayCustomAnim(fact, "build");
PlayBuildAnim( self, unit );
queue.FinishProduction(unit.Category);
Expand All @@ -84,6 +76,20 @@ public void ResolveOrder(Actor self, Order order)
}
}

// finds a construction yard (or equivalent) and runs its "build" animation.
static void PlayBuildAnim( Actor self, ActorInfo unit )
{
var producers = self.World.Queries.OwnedBy[ self.Owner ].WithTrait<Production>()
.Where( x => x.Actor.Info.Traits.Get<ProductionInfo>().Produces.Contains( unit.Category ) )
.ToList();
var producer = producers.Where( x => x.Trait.IsPrimary ).Concat( producers )
.Select( x => x.Actor )
.FirstOrDefault();

if( producer != null )
producer.traits.Get<RenderBuilding>().PlayCustomAnim( producer, "build" );
}

static int GetNumBuildables(Player p)
{
if (p != p.World.LocalPlayer) return 0; // this only matters for local players.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
*/
#endregion

namespace OpenRA.Traits.Activities
using OpenRA.Traits;

namespace OpenRA.Mods.RA.Activities
{
class UndeployMcv : IActivity
public class UndeployMcv : IActivity
{
public IActivity NextActivity { get; set; }
bool started;
Expand Down
5 changes: 2 additions & 3 deletions OpenRA.Mods.RA/Chrome/PowerDownButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ public bool Enabled
{
get
{
return !info.RequiresConstructionYard ||
Game.world.Queries.OwnedBy[Game.world.LocalPlayer]
.WithTrait<ConstructionYard>().Any();
// WTF: why are these buttons even traits?
return RepairOrderGenerator.PlayerIsAllowedToRepair( Game.world );
}
}

Expand Down
10 changes: 3 additions & 7 deletions OpenRA.Game/Traits/ConstructionYard.cs → OpenRA.Mods.RA/ConstructionYard.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
*/
#endregion

using OpenRA.Traits.Activities;
using OpenRA.Mods.RA.Activities;
using OpenRA.Traits;

namespace OpenRA.Traits
namespace OpenRA.Mods.RA
{
class ConstructionYardInfo : TraitInfo<ConstructionYard> { }

Expand All @@ -45,9 +46,4 @@ public void ResolveOrder(Actor self, Order order)
}
}
}

/* tag trait for "bases": mcv/fact */

class BaseBuildingInfo : TraitInfo<BaseBuilding> { }
class BaseBuilding { }
}
2 changes: 2 additions & 0 deletions OpenRA.Mods.RA/OpenRA.Mods.RA.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@
<Compile Include="Activities\Repair.cs" />
<Compile Include="Activities\ReturnToBase.cs" />
<Compile Include="Activities\Teleport.cs" />
<Compile Include="Activities\UndeployMcv.cs" />
<Compile Include="Activities\UnloadCargo.cs" />
<Compile Include="Activities\Wait.cs" />
<Compile Include="ConstructionYard.cs" />
<Compile Include="Player\ActorGroupProxy.cs" />
<Compile Include="Aircraft.cs" />
<Compile Include="SupportPowers\AirstrikePower.cs" />
Expand Down
16 changes: 11 additions & 5 deletions OpenRA.Mods.RA/Orders/RepairOrderGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,20 @@ IEnumerable<Order> OrderInner(World world, int2 xy, MouseInput mi)

public void Tick( World world )
{
var hasFact = world.Queries.OwnedBy[world.LocalPlayer]
.WithTrait<ConstructionYard>()
.Any();

if (!hasFact)
if( PlayerIsAllowedToRepair( world ) )
Game.controller.CancelInputMode();
}

public static bool PlayerIsAllowedToRepair( World world )
{
if( !world.WorldActor.Info.Traits.Get<RepairButtonInfo>().RequiresConstructionYard )
return true;

return Game.world.Queries.OwnedBy[ Game.world.LocalPlayer ]
.WithTrait<Production>().Where( x => x.Actor.Info.Traits.Get<ProductionInfo>().Produces.Contains( "Building" ) )
.Any();
}

public void Render( World world ) {}

public string GetCursor(World world, int2 xy, MouseInput mi)
Expand Down
8 changes: 3 additions & 5 deletions OpenRA.Mods.RA/Player/ActorGroupProxy.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq;
using OpenRA.Traits;

namespace OpenRA.Traits
namespace OpenRA.Mods.RA
{
class ActorGroupProxyInfo : TraitInfo<ActorGroupProxy> { }

Expand Down

0 comments on commit 7a738ed

Please sign in to comment.