Merge pull request #9611 from obrakmann/fix3285_default-stance-defend

Change the default stance to Defend for human players
This commit is contained in:
abcdefg30
2015-10-27 21:21:43 +01:00
13 changed files with 64 additions and 19 deletions

View File

@@ -16,7 +16,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("The actor will automatically engage the enemy when it is in range.")] [Desc("The actor will automatically engage the enemy when it is in range.")]
public class AutoTargetInfo : ITraitInfo, Requires<AttackBaseInfo> public class AutoTargetInfo : ITraitInfo, Requires<AttackBaseInfo>, UsesInit<StanceInit>
{ {
[Desc("It will try to hunt down the enemy if it is not set to defend.")] [Desc("It will try to hunt down the enemy if it is not set to defend.")]
public readonly bool AllowMovement = true; public readonly bool AllowMovement = true;
@@ -24,8 +24,12 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Set to a value >1 to override weapons maximum range for this.")] [Desc("Set to a value >1 to override weapons maximum range for this.")]
public readonly int ScanRadius = -1; public readonly int ScanRadius = -1;
[Desc("Possible values are HoldFire, ReturnFire, Defend and AttackAnything.")] [Desc("Possible values are HoldFire, ReturnFire, Defend and AttackAnything.",
public readonly UnitStance InitialStance = UnitStance.AttackAnything; "Used for computer-controlled players, both Lua-scripted and regular Skirmish AI alike.")]
public readonly UnitStance InitialStanceAI = UnitStance.AttackAnything;
[Desc("Possible values are HoldFire, ReturnFire, Defend and AttackAnything. Used for human players.")]
public readonly UnitStance InitialStance = UnitStance.Defend;
[Desc("Allow the player to change the unit stance.")] [Desc("Allow the player to change the unit stance.")]
public readonly bool EnableStances = true; public readonly bool EnableStances = true;
@@ -40,7 +44,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly bool TargetWhenDamaged = true; public readonly bool TargetWhenDamaged = true;
public object Create(ActorInitializer init) { return new AutoTarget(init.Self, this); } public object Create(ActorInitializer init) { return new AutoTarget(init, this); }
} }
public enum UnitStance { HoldFire, ReturnFire, Defend, AttackAnything } public enum UnitStance { HoldFire, ReturnFire, Defend, AttackAnything }
@@ -59,11 +63,17 @@ namespace OpenRA.Mods.Common.Traits
// NOT SYNCED: do not refer to this anywhere other than UI code // NOT SYNCED: do not refer to this anywhere other than UI code
public UnitStance PredictedStance; public UnitStance PredictedStance;
public AutoTarget(Actor self, AutoTargetInfo info) public AutoTarget(ActorInitializer init, AutoTargetInfo info)
{ {
var self = init.Self;
this.info = info; this.info = info;
attack = self.Trait<AttackBase>(); attack = self.Trait<AttackBase>();
Stance = info.InitialStance;
if (init.Contains<StanceInit>())
Stance = init.Get<StanceInit, UnitStance>();
else
Stance = self.Owner.IsBot || !self.Owner.Playable ? info.InitialStanceAI : info.InitialStance;
PredictedStance = Stance; PredictedStance = Stance;
at = self.TraitOrDefault<AttackFollow>(); at = self.TraitOrDefault<AttackFollow>();
} }
@@ -198,4 +208,12 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Will not get automatically targeted by enemy (like walls)")] [Desc("Will not get automatically targeted by enemy (like walls)")]
class AutoTargetIgnoreInfo : TraitInfo<AutoTargetIgnore> { } class AutoTargetIgnoreInfo : TraitInfo<AutoTargetIgnore> { }
class AutoTargetIgnore { } class AutoTargetIgnore { }
public class StanceInit : IActorInit<UnitStance>
{
[FieldFromYamlKey] readonly UnitStance value = UnitStance.AttackAnything;
public StanceInit() { }
public StanceInit(UnitStance init) { value = init; }
public UnitStance Value(World world) { return value; }
}
} }

View File

@@ -2266,6 +2266,17 @@ namespace OpenRA.Mods.Common.UtilityCommands
} }
} }
// Add InitialStance for bots
if (engineVersion < 20151025)
{
if (depth == 1 && node.Key == "AutoTarget")
{
var stance = node.Value.Nodes.FirstOrDefault(n => n.Key == "InitialStance");
if (stance != null)
node.Value.Nodes.Add(new MiniYamlNode("InitialStanceAI", stance.Value.Value));
}
}
UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1); UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1);
} }
} }

View File

@@ -150,7 +150,7 @@ ARTY:
AttackFrontal: AttackFrontal:
WithMuzzleOverlay: WithMuzzleOverlay:
AutoTarget: AutoTarget:
InitialStance: Defend InitialStanceAI: Defend
SpawnActorOnDeath: SpawnActorOnDeath:
Actor: ARTY.Husk Actor: ARTY.Husk
Explodes: Explodes:
@@ -488,7 +488,7 @@ MLRS:
WithReloadingTurret: WithReloadingTurret:
AmmoPoolName: primary AmmoPoolName: primary
AutoTarget: AutoTarget:
InitialStance: Defend InitialStanceAI: Defend
RenderRangeCircle: RenderRangeCircle:
SpawnActorOnDeath: SpawnActorOnDeath:
Actor: MLRS.Husk Actor: MLRS.Husk
@@ -526,6 +526,7 @@ STNK:
AttackFrontal: AttackFrontal:
AutoTarget: AutoTarget:
InitialStance: HoldFire InitialStance: HoldFire
InitialStanceAI: ReturnFire
Targetable: Targetable:
SpawnActorOnDeath: SpawnActorOnDeath:
Actor: STNK.Husk Actor: STNK.Husk

View File

@@ -126,6 +126,8 @@ fremen:
Range: 4c768 Range: 4c768
AutoTarget: AutoTarget:
ScanRadius: 7 ScanRadius: 7
InitialStance: HoldFire
InitialStanceAI: ReturnFire
Armament@PRIMARY: Armament@PRIMARY:
Weapon: Fremen_S Weapon: Fremen_S
Armament@SECONDARY: Armament@SECONDARY:

View File

@@ -210,7 +210,7 @@ siege_tank:
Weapon: UnitExplodeMed Weapon: UnitExplodeMed
EmptyWeapon: UnitExplodeMed EmptyWeapon: UnitExplodeMed
AutoTarget: AutoTarget:
InitialStance: Defend InitialStanceAI: Defend
Selectable: Selectable:
Class: siegetank Class: siegetank
SpawnActorOnDeath: SpawnActorOnDeath:
@@ -245,7 +245,7 @@ missile_tank:
LocalOffset: -128,128,171, -128,-128,171 LocalOffset: -128,128,171, -128,-128,171
AttackFrontal: AttackFrontal:
AutoTarget: AutoTarget:
InitialStance: Defend InitialStanceAI: Defend
Explodes: Explodes:
Weapon: UnitExplodeMed Weapon: UnitExplodeMed
EmptyWeapon: UnitExplodeMed EmptyWeapon: UnitExplodeMed
@@ -394,6 +394,7 @@ stealth_raider:
IsPlayerPalette: true IsPlayerPalette: true
AutoTarget: AutoTarget:
InitialStance: HoldFire InitialStance: HoldFire
InitialStanceAI: ReturnFire
-MustBeDestroyed: -MustBeDestroyed:
deviator: deviator:
@@ -423,7 +424,7 @@ deviator:
LocalOffset: -299,0,85 LocalOffset: -299,0,85
AttackFrontal: AttackFrontal:
AutoTarget: AutoTarget:
InitialStance: Defend InitialStanceAI: Defend
Explodes: Explodes:
Weapon: UnitExplodeLarge Weapon: UnitExplodeLarge
EmptyWeapon: UnitExplodeLarge EmptyWeapon: UnitExplodeLarge

View File

@@ -654,7 +654,7 @@ Rules:
Health: Health:
HP: 200 HP: 200
AutoTarget: AutoTarget:
InitialStance: Defend InitialStanceAI: Defend
SNIPER.soviets: SNIPER.soviets:
Inherits: SNIPER Inherits: SNIPER
Buildable: Buildable:

View File

@@ -40,7 +40,6 @@ BaseRearAttackWpts = { GroundAttackWpt1.Location, BaseRearAttackWpt1.Location, B
SovietHarvesters = { Harvester1, Harvester2, Harvester3 } SovietHarvesters = { Harvester1, Harvester2, Harvester3 }
HarvesterGuard = { HarvGuard1, HarvGuard2, HarvGuard3 } HarvesterGuard = { HarvGuard1, HarvGuard2, HarvGuard3 }
UBoats = { Uboat1, Uboat2, Uboat3, Uboat4, Uboat5, Uboat6 }
UboatPatrolWpts1 = { UboatPatrolWpt1.Location, UboatPatrolWpt2.Location, UboatPatrolWpt3.Location, UboatPatrolWpt4.Location } UboatPatrolWpts1 = { UboatPatrolWpt1.Location, UboatPatrolWpt2.Location, UboatPatrolWpt3.Location, UboatPatrolWpt4.Location }
UboatPatrolWpts2 = { UboatPatrolWpt4.Location, UboatPatrolWpt2.Location, UboatPatrolWpt1.Location } UboatPatrolWpts2 = { UboatPatrolWpt4.Location, UboatPatrolWpt2.Location, UboatPatrolWpt1.Location }
UBoatPatrolUnits = { "ss" } UBoatPatrolUnits = { "ss" }
@@ -183,8 +182,6 @@ SetupWorld = function()
end) end)
end) end)
Utils.Do(UBoats, function(a) a.Stance = "Defend" end)
Utils.Do(Map.NamedActors, function(actor) Utils.Do(Map.NamedActors, function(actor)
if actor.Owner == soviets and actor.HasProperty("StartBuildingRepairs") then if actor.Owner == soviets and actor.HasProperty("StartBuildingRepairs") then
Trigger.OnDamaged(actor, function(building) Trigger.OnDamaged(actor, function(building)

View File

@@ -2053,26 +2053,32 @@ Actors:
Location: 17,92 Location: 17,92
Owner: Soviets Owner: Soviets
Facing: 128 Facing: 128
Stance: Defend
Uboat2: ss Uboat2: ss
Location: 20,91 Location: 20,91
Owner: Soviets Owner: Soviets
Facing: 128 Facing: 128
Stance: Defend
Uboat3: ss Uboat3: ss
Location: 17,112 Location: 17,112
Owner: Soviets Owner: Soviets
Facing: 192 Facing: 192
Stance: Defend
Uboat4: ss Uboat4: ss
Location: 34,120 Location: 34,120
Owner: Soviets Owner: Soviets
Facing: 160 Facing: 160
Stance: Defend
Uboat5: ss Uboat5: ss
Location: 24,126 Location: 24,126
Owner: Soviets Owner: Soviets
Facing: 160 Facing: 160
Stance: Defend
Uboat6: ss Uboat6: ss
Location: 29,131 Location: 29,131
Owner: Soviets Owner: Soviets
Facing: 192 Facing: 192
Stance: Defend
WarFactory: weap WarFactory: weap
Location: 70,72 Location: 70,72
Owner: Soviets Owner: Soviets

View File

@@ -273,6 +273,7 @@ HELI:
CanHover: True CanHover: True
AutoTarget: AutoTarget:
InitialStance: HoldFire InitialStance: HoldFire
InitialStanceAI: HoldFire
WithSpriteRotorOverlay: WithSpriteRotorOverlay:
Offset: 0,0,85 Offset: 0,0,85
AmmoPool: AmmoPool:
@@ -326,6 +327,7 @@ HIND:
CanHover: True CanHover: True
AutoTarget: AutoTarget:
InitialStance: HoldFire InitialStance: HoldFire
InitialStanceAI: HoldFire
WithSpriteRotorOverlay: WithSpriteRotorOverlay:
AmmoPool: AmmoPool:
Ammo: 24 Ammo: 24

View File

@@ -32,6 +32,8 @@ DOG:
Voice: Attack Voice: Attack
AttackMove: AttackMove:
Voice: Move Voice: Move
AutoTarget:
InitialStance: AttackAnything
Targetable: Targetable:
TargetTypes: Ground, Infantry TargetTypes: Ground, Infantry
WithInfantryBody: WithInfantryBody:
@@ -517,7 +519,8 @@ SNIPER:
RevealsShroud: RevealsShroud:
Range: 6c0 Range: 6c0
AutoTarget: AutoTarget:
InitialStance: ReturnFire InitialStance: HoldFire
InitialStanceAI: ReturnFire
Armament@PRIMARY: Armament@PRIMARY:
Weapon: Sniper Weapon: Sniper
Armament@GARRISONED: Armament@GARRISONED:

View File

@@ -43,7 +43,8 @@ SS:
SelectionDecorations: SelectionDecorations:
VisualBounds: 38,38 VisualBounds: 38,38
AutoTarget: AutoTarget:
InitialStance: ReturnFire InitialStance: HoldFire
InitialStanceAI: ReturnFire
DetectCloaked: DetectCloaked:
CloakTypes: Underwater CloakTypes: Underwater
Range: 4c0 Range: 4c0
@@ -98,7 +99,8 @@ MSUB:
SelectionDecorations: SelectionDecorations:
VisualBounds: 44,44 VisualBounds: 44,44
AutoTarget: AutoTarget:
InitialStance: ReturnFire InitialStance: HoldFire
InitialStanceAI: ReturnFire
DetectCloaked: DetectCloaked:
CloakTypes: Underwater CloakTypes: Underwater
Range: 4c0 Range: 4c0

View File

@@ -723,7 +723,8 @@ STNK:
RevealsShroud: RevealsShroud:
Range: 6c0 Range: 6c0
AutoTarget: AutoTarget:
InitialStance: ReturnFire InitialStance: HoldFire
InitialStanceAI: ReturnFire
Armament: Armament:
Weapon: APTusk Weapon: APTusk
LocalOffset: 400,0,0 LocalOffset: 400,0,0

View File

@@ -272,5 +272,6 @@ STNK:
Voice: Attack Voice: Attack
AutoTarget: AutoTarget:
InitialStance: HoldFire InitialStance: HoldFire
InitialStanceAI: ReturnFire
-MustBeDestroyed: -MustBeDestroyed: