Skip to content

Commit

Permalink
Merge pull request OpenRA#8674 from reaperrr/rem-initact
Browse files Browse the repository at this point in the history
Removed InitialActivity from FreeActor and Buildable
  • Loading branch information
obrakmann committed Jul 9, 2015
2 parents 0835504 + a295166 commit 4792ff3
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 31 deletions.
3 changes: 0 additions & 3 deletions OpenRA.Mods.Common/Traits/Buildable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ public class BuildableInfo : TraitInfo<Buildable>
[Desc("Disable production when there are more than this many of this actor on the battlefield. Set to 0 to disable.")]
public readonly int BuildLimit = 0;

[Desc("What the unit should start doing. Warning: If this is not a harvester", "it will break if you use FindResources.")]
public readonly string InitialActivity = null;

[Desc("Force a specific race variant, overriding the race of the producing actor.")]
public readonly string ForceRace = null;

Expand Down
11 changes: 2 additions & 9 deletions OpenRA.Mods.Common/Traits/Buildings/FreeActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,19 @@
*/
#endregion

using OpenRA.Activities;
using OpenRA.Primitives;
using OpenRA.Traits;

namespace OpenRA.Mods.Common.Traits
{
[Desc("Player recives a unit for free once the building is placed. This also works for structures.",
[Desc("Player receives a unit for free once the building is placed. This also works for structures.",
"If you want more than one unit to appear copy this section and assign IDs like FreeActor@2, ...")]
public class FreeActorInfo : ITraitInfo
{
[ActorReference]
[Desc("Name of the actor.")]
public readonly string Actor = null;

[Desc("What the unit should start doing. Warning: If this is not a harvester", "it will break if you use FindResources.")]
public readonly string InitialActivity = null;

[Desc("Offset relative to the top-left cell of the building.")]
public readonly CVec SpawnOffset = CVec.Zero;

Expand All @@ -43,16 +39,13 @@ public FreeActor(ActorInitializer init, FreeActorInfo info)

init.Self.World.AddFrameEndTask(w =>
{
var a = w.CreateActor(info.Actor, new TypeDictionary
w.CreateActor(info.Actor, new TypeDictionary
{
new ParentActorInit(init.Self),
new LocationInit(init.Self.Location + info.SpawnOffset),
new OwnerInit(init.Self.Owner),
new FacingInit(info.Facing),
});

if (info.InitialActivity != null)
a.QueueActivity(Game.CreateObject<Activity>(info.InitialActivity));
});
}
}
Expand Down
19 changes: 17 additions & 2 deletions OpenRA.Mods.Common/Traits/Harvester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public class HarvesterInfo : ITraitInfo
[Desc("Percentage of maximum speed when fully loaded.")]
public readonly int FullyLoadedSpeed = 85;

[Desc("Automatically scan for resources when created.")]
public readonly bool SearchOnCreation = true;

[Desc("Initial search radius (in cells) from the refinery that created us.")]
public readonly int SearchFromProcRadius = 24;

Expand All @@ -55,8 +58,8 @@ public class HarvesterInfo : ITraitInfo
}

public class Harvester : IIssueOrder, IResolveOrder, IPips,
IExplodeModifier, IOrderVoice, ISpeedModifier, ISync,
INotifyResourceClaimLost, INotifyIdle, INotifyBlockingMove
IExplodeModifier, IOrderVoice, ISpeedModifier, ISync, INotifyCreated,
INotifyResourceClaimLost, INotifyIdle, INotifyBlockingMove, INotifyBuildComplete
{
readonly HarvesterInfo info;
Dictionary<ResourceTypeInfo, int> contents = new Dictionary<ResourceTypeInfo, int>();
Expand All @@ -76,6 +79,18 @@ public Harvester(Actor self, HarvesterInfo info)
self.QueueActivity(new CallFunc(() => ChooseNewProc(self, null)));
}

public void Created(Actor self)
{
if (info.SearchOnCreation)
self.QueueActivity(new FindResources());
}

public void BuildingComplete(Actor self)
{
if (info.SearchOnCreation)
self.QueueActivity(new FindResources());
}

public void SetProcLines(Actor proc)
{
if (proc == null) return;
Expand Down
3 changes: 0 additions & 3 deletions OpenRA.Mods.Common/Traits/Production.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ public void DoProduction(Actor self, ActorInfo producee, ExitInfo exitinfo, stri
foreach (var notify in notifyOthers)
notify.Trait.UnitProducedByOther(notify.Actor, self, newUnit);

if (bi != null && bi.InitialActivity != null)
newUnit.QueueActivity(Game.CreateObject<Activity>(bi.InitialActivity));

foreach (var t in newUnit.TraitsImplementing<INotifyBuildComplete>())
t.BuildingComplete(newUnit);
});
Expand Down
7 changes: 7 additions & 0 deletions OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,13 @@ internal static void UpgradeActorRules(int engineVersion, ref List<MiniYamlNode>
node.Key = "FlashPaletteEffect";
}

// InitialActivity on FreeActor and Buildable was removed (due to being too hacky)
if (engineVersion < 20150707)
{
if (depth == 1)
node.Value.Nodes.RemoveAll(n => n.Key == "InitialActivity");
}

UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1);
}
}
Expand Down
7 changes: 2 additions & 5 deletions OpenRA.Mods.D2k/Traits/Buildings/FreeActorWithDelivery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,16 @@ public FreeActorWithDelivery(ActorInitializer init, FreeActorWithDeliveryInfo in
self = init.Self;
Info = info;

DoDelivery(self.Location + info.DeliveryOffset, info.Actor, info.DeliveringActor, info.InitialActivity);
DoDelivery(self.Location + info.DeliveryOffset, info.Actor, info.DeliveringActor);
}

public void DoDelivery(CPos location, string actorName, string carrierActorName, string clientInitialActivity)
public void DoDelivery(CPos location, string actorName, string carrierActorName)
{
Actor cargo;
Actor carrier;

CreateActors(actorName, carrierActorName, out cargo, out carrier);

if (clientInitialActivity != null)
cargo.QueueActivity(Game.CreateObject<Activity>(clientInitialActivity));

var carryable = cargo.Trait<Carryable>();
carryable.Destination = location;
carryable.Reserve(carrier);
Expand Down
4 changes: 0 additions & 4 deletions OpenRA.Mods.D2k/Traits/Buildings/ProductionFromMapEdge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ public override bool Produce(Actor self, ActorInfo producee, string raceVariant)
foreach (var notify in notifyOthers)
notify.Trait.UnitProducedByOther(notify.Actor, self, newUnit);

var bi = newUnit.Info.Traits.GetOrDefault<BuildableInfo>();
if (bi != null && bi.InitialActivity != null)
newUnit.QueueActivity(Game.CreateObject<Activity>(bi.InitialActivity));

foreach (var t in newUnit.TraitsImplementing<INotifyBuildComplete>())
t.BuildingComplete(newUnit);
});
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.D2k/Traits/Player/HarvesterInsurance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void TryActivate()
var refinery = refineries.First().Actor;
var delivery = refinery.Trait<FreeActorWithDelivery>();
delivery.DoDelivery(refinery.Location + delivery.Info.DeliveryOffset, delivery.Info.Actor,
delivery.Info.DeliveringActor, delivery.Info.InitialActivity);
delivery.Info.DeliveringActor);
}
}
}
1 change: 0 additions & 1 deletion mods/cnc/rules/structures.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ PROC:
Value: 500
FreeActor:
Actor: HARV
InitialActivity: FindResources
SpawnOffset: 1,2
Facing: 64
WithResources:
Expand Down
1 change: 0 additions & 1 deletion mods/d2k/rules/structures.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ refinery:
Value: 500
FreeActorWithDelivery:
Actor: harvester
InitialActivity: FindResources
DeliveryOffset: 2,2
DeliveringActor: carryall.reinforce
Facing: 160
Expand Down
1 change: 0 additions & 1 deletion mods/ra/rules/structures.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,6 @@ PROC:
Value: 600
FreeActor:
Actor: HARV
InitialActivity: FindResources
SpawnOffset: 1,2
Facing: 64
InfiltrateForCash:
Expand Down
1 change: 0 additions & 1 deletion mods/ts/rules/shared-structures.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ PROC:
Value: 600
FreeActor:
Actor: HARV
InitialActivity: FindResources
SpawnOffset: 3,1
Facing: 160
WithIdleOverlay@REDLIGHTS:
Expand Down

0 comments on commit 4792ff3

Please sign in to comment.