Skip to content

Commit

Permalink
Enforce required owner in map editor
Browse files Browse the repository at this point in the history
It can easily happen that mappers forget to set the current player to Neutral before placing more trees, for example, so we force the editor to set a valid owner in such cases.
  • Loading branch information
reaperrr committed Aug 22, 2018
1 parent b6df05a commit 51053c3
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions OpenRA.Mods.Common/EditorBrushes/EditorActorBrush.cs
Expand Up @@ -41,6 +41,7 @@ public EditorActorBrush(EditorViewportControllerWidget editorWidget, ActorInfo a

Actor = actor;
this.owner = owner;
var ownerName = owner.Name;

preview = editorWidget.Get<ActorPreviewWidget>("DRAG_ACTOR_PREVIEW");
preview.GetScale = () => worldRenderer.Viewport.Zoom;
Expand All @@ -50,10 +51,15 @@ public EditorActorBrush(EditorViewportControllerWidget editorWidget, ActorInfo a
if (buildingInfo != null)
centerOffset = buildingInfo.CenterOffset(world);

// Enforce Neutral or Creeps owner if the actor has RequiresSpecificOwner
var specificOwnerInfo = actor.TraitInfoOrDefault<RequiresSpecificOwnerInfo>();
if (specificOwnerInfo != null && !specificOwnerInfo.ValidOwnerTypes.Contains(ownerName))
ownerName = specificOwnerInfo.ValidOwnerTypes.First();

var td = new TypeDictionary();
td.Add(new FacingInit(facing));
td.Add(new TurretFacingInit(facing));
td.Add(new OwnerInit(owner.Name));
td.Add(new OwnerInit(ownerName));
td.Add(new FactionInit(owner.Faction));
preview.SetPreview(actor, td);

Expand Down Expand Up @@ -94,8 +100,14 @@ public bool HandleMouseInput(MouseInput mi)
if (!footprint.All(c => world.Map.Tiles.Contains(cell + c)))
return true;

// Enforce Neutral or Creeps owner if the actor has RequiresSpecificOwner
var ownerName = owner.Name;
var specificOwnerInfo = Actor.TraitInfoOrDefault<RequiresSpecificOwnerInfo>();
if (specificOwnerInfo != null && !specificOwnerInfo.ValidOwnerTypes.Contains(ownerName))
ownerName = specificOwnerInfo.ValidOwnerTypes.First();

var newActorReference = new ActorReference(Actor.Name);
newActorReference.Add(new OwnerInit(owner.Name));
newActorReference.Add(new OwnerInit(ownerName));

newActorReference.Add(new LocationInit(cell));

Expand Down

0 comments on commit 51053c3

Please sign in to comment.