Enforce required owner in map editor

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.
This commit is contained in:
reaperrr
2018-08-04 01:22:30 +02:00
committed by Paul Chote
parent fcb09d069b
commit 1eb573bcbc

View File

@@ -41,6 +41,7 @@ namespace OpenRA.Mods.Common.Widgets
Actor = actor; Actor = actor;
this.owner = owner; this.owner = owner;
var ownerName = owner.Name;
preview = editorWidget.Get<ActorPreviewWidget>("DRAG_ACTOR_PREVIEW"); preview = editorWidget.Get<ActorPreviewWidget>("DRAG_ACTOR_PREVIEW");
preview.GetScale = () => worldRenderer.Viewport.Zoom; preview.GetScale = () => worldRenderer.Viewport.Zoom;
@@ -50,10 +51,15 @@ namespace OpenRA.Mods.Common.Widgets
if (buildingInfo != null) if (buildingInfo != null)
centerOffset = buildingInfo.CenterOffset(world); centerOffset = buildingInfo.CenterOffset(world);
// Enforce first entry of ValidOwnerNames as owner if the actor has RequiresSpecificOwners
var specificOwnerInfo = actor.TraitInfoOrDefault<RequiresSpecificOwnersInfo>();
if (specificOwnerInfo != null && !specificOwnerInfo.ValidOwnerNames.Contains(ownerName))
ownerName = specificOwnerInfo.ValidOwnerNames.First();
var td = new TypeDictionary(); var td = new TypeDictionary();
td.Add(new FacingInit(facing)); td.Add(new FacingInit(facing));
td.Add(new TurretFacingInit(facing)); td.Add(new TurretFacingInit(facing));
td.Add(new OwnerInit(owner.Name)); td.Add(new OwnerInit(ownerName));
td.Add(new FactionInit(owner.Faction)); td.Add(new FactionInit(owner.Faction));
preview.SetPreview(actor, td); preview.SetPreview(actor, td);
@@ -94,8 +100,14 @@ namespace OpenRA.Mods.Common.Widgets
if (!footprint.All(c => world.Map.Tiles.Contains(cell + c))) if (!footprint.All(c => world.Map.Tiles.Contains(cell + c)))
return true; return true;
// Enforce first entry of ValidOwnerNames as owner if the actor has RequiresSpecificOwners
var ownerName = owner.Name;
var specificOwnerInfo = Actor.TraitInfoOrDefault<RequiresSpecificOwnersInfo>();
if (specificOwnerInfo != null && !specificOwnerInfo.ValidOwnerNames.Contains(ownerName))
ownerName = specificOwnerInfo.ValidOwnerNames.First();
var newActorReference = new ActorReference(Actor.Name); var newActorReference = new ActorReference(Actor.Name);
newActorReference.Add(new OwnerInit(owner.Name)); newActorReference.Add(new OwnerInit(ownerName));
newActorReference.Add(new LocationInit(cell)); newActorReference.Add(new LocationInit(cell));