Skip to content

Added more landing pads to the Airforce Command Center #735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions OpenRA.Mods.RA2/Traits/SpawnNeighboringActors.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#region Copyright & License Information
/*
* Copyright 2007-2020 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion

using System.Collections.Generic;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;

namespace OpenRA.Mods.RA2.Traits
{
[Desc("This actor places other actors around itself, which keep connected as in they get removed when the parent is sold or destroyed.")]
public class SpawnNeighboringActorsInfo : ITraitInfo
{
[FieldLoader.Require]
[ActorReference]
[Desc("Types of actors to place. If multiple are defined, a random one will be selected for each actor spawned.")]
public readonly HashSet<string> ActorTypes = new HashSet<string>();

[FieldLoader.Require]
[Desc("Locations to spawn the actors relative to the origin (top-left for buildings) of this actor.")]
public readonly CVec[] Locations = { };

public object Create(ActorInitializer init) { return new SpawnNeighboringActors(this, init.Self); }
}

public class SpawnNeighboringActors : INotifyKilled, INotifyOwnerChanged, INotifyActorDisposing, INotifyAddedToWorld, INotifySold
{
readonly SpawnNeighboringActorsInfo info;
readonly List<Actor> actors = new List<Actor>();

public SpawnNeighboringActors(SpawnNeighboringActorsInfo info, Actor self)
{
this.info = info;
}

void INotifyAddedToWorld.AddedToWorld(Actor self)
{
SpawnActors(self);
}

public void SpawnActors(Actor self)
{
foreach (var offset in info.Locations)
{
self.World.AddFrameEndTask(w =>
{
var actorType = info.ActorTypes.Random(self.World.SharedRandom).ToLowerInvariant();
var cell = self.Location + offset;

var actor = w.CreateActor(true, actorType, new TypeDictionary
{
new OwnerInit(self.Owner),
new LocationInit(cell)
});

actors.Add(actor);
});
}
}

public void RemoveActors()
{
foreach (var actor in actors)
actor.Dispose();

actors.Clear();
}

void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this documented at all and this seems to be a very specific behavior unrelated to spawning nearby actors.
Regardless of whether this functionality remains, it should be documented IMO.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a note to the trait description.

Copy link
Member

@phrohdoh phrohdoh Dec 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that in reference to the "which keep connected?"
That makes me think this'd be used for (visually) connecting walls, not ownership of the spawned actors always being that of the actor that spawned them throughout the game.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Owner changing is still undocumented.

{
foreach (var actor in actors)
actor.ChangeOwnerSync(newOwner);
}

void INotifyKilled.Killed(Actor self, AttackInfo e)
{
RemoveActors();
}

void INotifyActorDisposing.Disposing(Actor self)
{
RemoveActors();
}

void INotifySold.Selling(Actor self) { }
void INotifySold.Sold(Actor self)
{
RemoveActors();
}
}
}
2 changes: 1 addition & 1 deletion mods/ra2/rules/aircraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ orca:
Actor: orcahusk
HitShape:
Rearmable:
RearmActors: gaairc, amradr
RearmActors: gaairc, amradr, gapad

orcahusk:
Inherits: ^PlaneHusk
Expand Down
24 changes: 19 additions & 5 deletions mods/ra2/rules/allied-structures.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ gaairc:
Factions: korea
ProvidesPrerequisite@default:
Building:
Footprint: xxx xxx
Footprint: x=x x==
Dimensions: 3,2
Selectable:
Bounds: 142, 150, -3, -42
Expand Down Expand Up @@ -320,17 +320,17 @@ gaairc:
Amount: -50
Reservable:
Exit@1:
SpawnOffset: -370,370,0
Facing: 224
SpawnOffset: 1024,512,0
Exit@2:
SpawnOffset: 370,-370,0
Facing: 224
SpawnOffset: 512,1024,0
Exit@3:
SpawnOffset: 1000,370,0
Facing: 224
SpawnOffset: -512,512,0
Exit@4:
SpawnOffset: 350,1000,0
Facing: 224
SpawnOffset: 512,-512,0
Production:
Produces: Aircraft
ProductionBar:
Expand All @@ -349,6 +349,20 @@ gaairc:
SpawnSurvivors:
DeathTypes: ExplosionDeath, BulletDeath
Actors: e1, e1
SpawnNeighboringActors:
ActorTypes: gapad
Locations: 1,0, 1,1, 2,1

gapad:
Interactable:
AlwaysVisible:
Reservable:
Building:
Footprint: x
Dimensions: 1,1
AllowInvalidPlacement: true
Production:
Produces: Aircraft

amradr:
Inherits: gaairc
Expand Down
1 change: 1 addition & 0 deletions mods/ra2/rules/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,7 @@
AltitudeVelocity: 120
TakeOffOnCreation: false
IdleBehavior: ReturnToBase
InitialFacing: 224
Hovers@CRUISING:
RequiresCondition: cruising
WithVoxelBody:
Expand Down