From 54feab66e07c654c7865ef62aba3ca558c88edf0 Mon Sep 17 00:00:00 2001 From: Scott_NZ Date: Sun, 16 Dec 2012 13:30:20 +1300 Subject: [PATCH] Add hijackable truck to Allies 04 --- OpenRA.Mods.RA/Activities/Infiltrate.cs | 15 ++++- OpenRA.Mods.RA/Missions/Allies04Script.cs | 67 +++++++++++++++++++++++ OpenRA.Mods.RA/Spy.cs | 5 +- mods/ra/maps/allies-04/map.yaml | 42 ++++++++++++-- 4 files changed, 121 insertions(+), 8 deletions(-) diff --git a/OpenRA.Mods.RA/Activities/Infiltrate.cs b/OpenRA.Mods.RA/Activities/Infiltrate.cs index a5519fecdb..a6da250746 100644 --- a/OpenRA.Mods.RA/Activities/Infiltrate.cs +++ b/OpenRA.Mods.RA/Activities/Infiltrate.cs @@ -1,4 +1,4 @@ -#region Copyright & License Information +#region Copyright & License Information /* * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) * This file is part of OpenRA, which is free software. It is made @@ -9,6 +9,7 @@ #endregion using System.Linq; +using OpenRA.Mods.RA.Buildings; using OpenRA.Traits; namespace OpenRA.Mods.RA.Activities @@ -30,9 +31,17 @@ namespace OpenRA.Mods.RA.Activities foreach (var t in target.TraitsImplementing()) t.OnInfiltrate(target, self); - self.Destroy(); + if (self.HasTrait()) + self.World.AddFrameEndTask(w => + { + if (self.Destroyed) return; + w.Remove(self); + }); + else + self.Destroy(); - Sound.PlayToPlayer(self.Owner, "bldginf1.aud"); + if (target.HasTrait()) + Sound.PlayToPlayer(self.Owner, "bldginf1.aud"); return this; } diff --git a/OpenRA.Mods.RA/Missions/Allies04Script.cs b/OpenRA.Mods.RA/Missions/Allies04Script.cs index 9b644f13b2..e513b9a327 100644 --- a/OpenRA.Mods.RA/Missions/Allies04Script.cs +++ b/OpenRA.Mods.RA/Missions/Allies04Script.cs @@ -12,6 +12,7 @@ using System.Collections.Generic; using System.Linq; using OpenRA.FileFormats; using OpenRA.Mods.RA.Activities; +using OpenRA.Mods.RA.Render; using OpenRA.Network; using OpenRA.Traits; @@ -36,6 +37,8 @@ namespace OpenRA.Mods.RA.Missions Actor lstEntryPoint; Actor lstUnloadPoint; Actor lstExitPoint; + Actor hijackTruck; + Actor hijackTruckGuard; Actor allies1Spy; Actor allies2Spy; @@ -76,6 +79,14 @@ namespace OpenRA.Mods.RA.Missions PatrolTick(ref patrol3, ref currentPatrolPoint3, soviets, DogPatrol, patrolPoints3); PatrolTick(ref patrol4, ref currentPatrolPoint4, soviets, DogPatrol, patrolPoints4); PatrolTick(ref patrol5, ref currentPatrolPoint5, soviets, DogPatrol, patrolPoints5); + ManageSovietOre(); + } + + void ManageSovietOre() + { + var res = soviets.PlayerActor.Trait(); + res.TakeOre(res.Ore); + res.TakeCash(res.Cash); } void PatrolTick(ref Actor[] patrolActors, ref int currentPoint, Player owner, string[] actorNames, CPos[] points) @@ -151,6 +162,8 @@ namespace OpenRA.Mods.RA.Missions lstEntryPoint = actors["LstEntryPoint"]; lstUnloadPoint = actors["LstUnloadPoint"]; lstExitPoint = actors["LstExitPoint"]; + hijackTruck = actors["HijackTruck"]; + hijackTruckGuard = actors["HijackTruckGuard"]; patrolPoints1 = new[] { actors["PatrolPoint11"].Location, @@ -208,4 +221,58 @@ namespace OpenRA.Mods.RA.Missions } } } + + class Allies04HijackableInfo : ITraitInfo + { + public object Create(ActorInitializer init) { return new Allies04Hijackable(init.self); } + } + + class Allies04Hijackable : IAcceptSpy, INotifyPassengerExited + { + public Player OldOwner; + + public Allies04Hijackable(Actor self) + { + OldOwner = self.Owner; + } + + public void OnInfiltrate(Actor self, Actor spy) + { + if (self.Trait().IsEmpty(self)) + { + self.ChangeOwner(spy.Owner); + } + self.Trait().Load(self, spy); + } + + public void PassengerExited(Actor self, Actor passenger) + { + if (self.Trait().IsEmpty(self)) + { + self.CancelActivity(); + self.ChangeOwner(OldOwner); + } + } + } + + class Allies04RenderHijackedInfo : RenderUnitInfo + { + public override object Create(ActorInitializer init) { return new Allies04RenderHijacked(init.self, this); } + } + + class Allies04RenderHijacked : RenderUnit, IRenderModifier + { + Allies04Hijackable hijackable; + + public Allies04RenderHijacked(Actor self, Allies04RenderHijackedInfo info) + : base(self) + { + hijackable = self.Trait(); + } + + public IEnumerable ModifyRender(Actor self, IEnumerable r) + { + return r.Select(a => a.WithPalette(Palette(hijackable.OldOwner))); + } + } } diff --git a/OpenRA.Mods.RA/Spy.cs b/OpenRA.Mods.RA/Spy.cs index 407685eb3f..7d74fdee5c 100644 --- a/OpenRA.Mods.RA/Spy.cs +++ b/OpenRA.Mods.RA/Spy.cs @@ -1,4 +1,4 @@ -#region Copyright & License Information +#region Copyright & License Information /* * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) * This file is part of OpenRA, which is free software. It is made @@ -155,4 +155,7 @@ namespace OpenRA.Mods.RA class IgnoresDisguiseInfo : TraitInfo {} class IgnoresDisguise {} + + class DontDestroyWhenInfiltratingInfo : TraitInfo { } + class DontDestroyWhenInfiltrating { } } diff --git a/mods/ra/maps/allies-04/map.yaml b/mods/ra/maps/allies-04/map.yaml index 8a69fe11d9..1841940fa6 100644 --- a/mods/ra/maps/allies-04/map.yaml +++ b/mods/ra/maps/allies-04/map.yaml @@ -468,7 +468,7 @@ Actors: Actor136: dome Location: 107,25 Owner: Soviets - Actor137: weap + HijackFactory: weap Location: 98,32 Owner: Soviets Actor138: sam @@ -768,7 +768,7 @@ Actors: Actor229: v2rl Location: 96,19 Owner: Soviets - Actor230: e1 + HijackTruckGuard: e1 Location: 65,34 Owner: Soviets Actor50: fenc @@ -852,6 +852,7 @@ Actors: Actor264: v2rl Location: 50,36 Owner: Soviets + Facing: 192 Actor266: 3tnk Location: 88,70 Owner: Soviets @@ -1263,6 +1264,7 @@ Actors: Actor328: v2rl Location: 27,37 Owner: Soviets + Facing: 64 Actor366: powr Location: 35,54 Owner: Soviets @@ -1413,6 +1415,10 @@ Actors: Actor427: dog Location: 104,24 Owner: Soviets + HijackTruck: truk.hijackable + Location: 99,34 + Owner: Soviets + Facing: 160 Smudges: @@ -1433,13 +1439,13 @@ Rules: Range: 10 Health: HP: 100 + DontDestroyWhenInfiltrating: DOG.Patrol: Inherits: ^Infantry Valued: Cost: 200 Tooltip: Name: Attack Dog - Description: Anti-infantry unit. Not fooled by the \nSpy's disguise.\n Strong vs Infantry\n Weak vs Vehicles Selectable: Voice: DogVoice Bounds: 12,17,-1,-4 @@ -1457,9 +1463,37 @@ Rules: Image: dog IdleAnimations: idle1,idle2 IgnoresDisguise: + TRUK.Hijackable: + Inherits: ^Vehicle + Cargo: + MaxWeight: 2 + PipCount: 2 + AutoTargetIgnore: + Allies04Hijackable: + Allies04RenderHijacked: + Image: TRUK + Selectable: + Voice: SpyVoice + Valued: + Cost: 500 + Tooltip: + Name: Supply Truck + Health: + HP: 110 + Armor: + Type: Light + Mobile: + Speed: 9 + RevealsShroud: + Range: 10 + AttackMove: + JustMove: yes Sequences: - + truk: + unload: + Start: 0 + Facings: 32 Weapons: Voices: