Skip to content

Commit f0d1f4e

Browse files
committed
Merge remote-tracking branch 'darkademic/dev' into WIPUrban
2 parents 402cae3 + cea756c commit f0d1f4e

36 files changed

Lines changed: 685 additions & 164 deletions

OpenRA.Mods.CA/Projectiles/ArcLaserZap.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public class ArcLaserZap : IProjectile, ISync
7474
readonly Color color;
7575

7676
[Sync]
77-
readonly WPos source;
77+
WPos source;
7878

7979
int ticks = 0;
8080
bool doneDamage;
@@ -104,6 +104,8 @@ public ArcLaserZap(ArcLaserZapInfo info, ProjectileArgs args, Color color)
104104

105105
public void Tick(World world)
106106
{
107+
source = args.CurrentSource();
108+
107109
// Beam tracks target
108110
if (info.TrackTarget && args.GuidedTarget.IsValidFor(args.SourceActor))
109111
target = args.Weapon.TargetActorCenter ? args.GuidedTarget.CenterPosition : args.GuidedTarget.Positions.PositionClosestTo(source);
@@ -141,13 +143,13 @@ public void Tick(World world)
141143
public IEnumerable<IRenderable> Render(WorldRenderer wr)
142144
{
143145
if (wr.World.FogObscures(target) &&
144-
wr.World.FogObscures(args.Source))
146+
wr.World.FogObscures(source))
145147
yield break;
146148

147149
if (ticks < info.Duration)
148150
{
149151
var rc = Color.FromArgb((info.Duration - ticks) * color.A / info.Duration, color);
150-
yield return new ArcRenderable(args.Source, target, info.ZOffset, info.Angle, rc, info.Width, info.QuantizedSegments);
152+
yield return new ArcRenderable(source, target, info.ZOffset, info.Angle, rc, info.Width, info.QuantizedSegments);
151153
}
152154

153155
if (hitanim != null)

OpenRA.Mods.CA/Traits/MindControllable.cs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
*/
99
#endregion
1010

11-
using System.Collections.Generic;
1211
using System.Linq;
1312
using OpenRA.Mods.Common.Activities;
1413
using OpenRA.Mods.Common.Traits;
@@ -34,21 +33,15 @@ public class MindControllableInfo : PausableConditionalTraitInfo
3433
[Desc("What happens to cargo on being mind controlled, and when control is lost.")]
3534
public readonly CargoBehaviour CargoBehaviour = CargoBehaviour.DoNothing;
3635

37-
[ActorReference(dictionaryReference: LintDictionaryReference.Keys)]
36+
[GrantedConditionReference]
3837
[Desc("Condition to grant when under mindcontrol.",
3938
"A dictionary of [actor id]: [condition].")]
40-
public readonly Dictionary<string, string> ControlledConditions = new Dictionary<string, string>();
39+
public readonly string ControlledCondition = null;
4140

42-
[ActorReference(dictionaryReference: LintDictionaryReference.Keys)]
41+
[GrantedConditionReference]
4342
[Desc("Condition to grant when revoking mindcontrol.",
4443
"A dictionary of [actor id]: [condition].")]
45-
public readonly Dictionary<string, string> RevokingConditions = new Dictionary<string, string>();
46-
47-
[GrantedConditionReference]
48-
public IEnumerable<string> LinterControlledConditions { get { return ControlledConditions.Values; } }
49-
50-
[GrantedConditionReference]
51-
public IEnumerable<string> LinterRevokingConditions { get { return RevokingConditions.Values; } }
44+
public readonly string RevokingCondition = null;
5245

5346
public override object Create(ActorInitializer init) { return new MindControllable(init.Self, this); }
5447
}
@@ -90,8 +83,8 @@ public void LinkMaster(Actor self, Actor masterActor)
9083
var mindController = masterActor.TraitsImplementing<MindController>().Single(mc => mc.Info.ControlType == info.ControlType);
9184
Master = new TraitPair<MindController>(masterActor, mindController);
9285

93-
if (controlledToken == Actor.InvalidConditionToken && Info.ControlledConditions.ContainsKey(masterActor.Info.Name))
94-
controlledToken = self.GrantCondition(Info.ControlledConditions[masterActor.Info.Name]);
86+
if (controlledToken == Actor.InvalidConditionToken && Info.ControlledCondition != null)
87+
controlledToken = self.GrantCondition(Info.ControlledCondition);
9588

9689
if (masterActor.Owner == creatorOwner)
9790
UnlinkMaster(self);
@@ -136,8 +129,6 @@ public void RevokeMindControl(Actor self, int ticks)
136129
if (Master == null)
137130
return;
138131

139-
var masterActor = Master.Value.Actor;
140-
var masterName = masterActor.Info.Name;
141132
UnlinkMaster(self);
142133

143134
if (ticks == 0)
@@ -147,8 +138,8 @@ public void RevokeMindControl(Actor self, int ticks)
147138
revokeTicks = ticks;
148139
revoking = true;
149140

150-
if (revokingToken == Actor.InvalidConditionToken && Info.RevokingConditions.ContainsKey(masterName))
151-
revokingToken = self.GrantCondition(Info.RevokingConditions[masterName]);
141+
if (revokingToken == Actor.InvalidConditionToken && Info.RevokingCondition != null)
142+
revokingToken = self.GrantCondition(Info.RevokingCondition);
152143
}
153144
}
154145

OpenRA.Mods.CA/Traits/MindController.cs

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@ public void ResolveOrder(Actor self, Order order)
288288
if (order.Target.Type != TargetType.Actor)
289289
return;
290290

291-
slaves.First(s => s.Actor == order.Target.Actor).Trait.RevokeMindControl(order.Target.Actor, 0);
291+
var slave = slaves.SingleOrDefault(s => s.Actor == order.Target.Actor);
292+
slave.Trait?.RevokeMindControl(order.Target.Actor, 0);
292293

293294
if (Info.SlaveDeployEffect == SlaveDeployEffect.Kill)
294295
{
@@ -485,7 +486,7 @@ public void ReleaseSlaves(Actor self, int ticks)
485486
if (s.Actor.IsDead || s.Actor.Disposed)
486487
continue;
487488

488-
if (s.Trait.Master.Value.Actor != self)
489+
if (s.Trait.Master.HasValue && s.Trait.Master.Value.Actor != self)
489490
continue;
490491

491492
s.Trait.RevokeMindControl(s.Actor, ticks);
@@ -671,41 +672,35 @@ void INotifyEnteredCargo.OnEnteredCargo(Actor self, Actor cargo)
671672
{
672673
if (Info.TransferToTransport)
673674
{
674-
//self.World.AddFrameEndTask(w => {
675-
var transportMc = cargo.TraitsImplementing<MindController>().FirstOrDefault(mc => mc.Info.ControlType == info.ControlType);
676-
if (transportMc != null)
675+
var transportMc = cargo.TraitsImplementing<MindController>().FirstOrDefault(mc => mc.Info.ControlType == info.ControlType);
676+
if (transportMc != null)
677+
{
678+
foreach (var s in slaves)
677679
{
678-
foreach (var s in slaves)
679-
{
680-
if (s.Actor.IsDead || s.Actor.Disposed)
681-
continue;
682-
683-
TextNotificationsManager.Debug("transferring {0} to {1}", s.Actor, cargo);
684-
transportMc.AddSlave(cargo, s.Actor, true);
685-
}
680+
if (s.Actor.IsDead || s.Actor.Disposed)
681+
continue;
682+
683+
transportMc.AddSlave(cargo, s.Actor, true);
686684
}
687-
//});
685+
}
688686
}
689687
}
690688

691689
void INotifyExitedCargo.OnExitedCargo(Actor self, Actor cargo)
692690
{
693691
if (Info.TransferToTransport)
694692
{
695-
//self.World.AddFrameEndTask(w => {
696-
var transportMc = cargo.TraitsImplementing<MindController>().FirstOrDefault(mc => mc.Info.ControlType == info.ControlType);
697-
if (transportMc != null)
693+
var transportMc = cargo.TraitsImplementing<MindController>().FirstOrDefault(mc => mc.Info.ControlType == info.ControlType);
694+
if (transportMc != null)
695+
{
696+
foreach (var s in transportMc.Slaves)
698697
{
699-
foreach (var s in transportMc.Slaves)
700-
{
701-
if (s.Actor.IsDead || s.Actor.Disposed)
702-
continue;
703-
704-
TextNotificationsManager.Debug("transferring {0} to {1}", s.Actor, self);
705-
AddSlave(self, s.Actor, true);
706-
}
698+
if (s.Actor.IsDead || s.Actor.Disposed)
699+
continue;
700+
701+
AddSlave(self, s.Actor, true);
707702
}
708-
//});
703+
}
709704
}
710705
}
711706
}

OpenRA.Mods.CA/Traits/PeriodicExplosion.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ class PeriodicExplosion : ConditionalTrait<PeriodicExplosionInfo>, ITick, INotif
7272

7373
List<(int Tick, Action Action)> delayedActions = new List<(int, Action)>();
7474

75+
IFirepowerModifier[] firepowerModifiers;
76+
IReloadModifier[] reloadModifiers;
77+
7578
public PeriodicExplosion(Actor self, PeriodicExplosionInfo info)
7679
: base(info)
7780
{
@@ -87,6 +90,17 @@ protected override void Created(Actor self)
8790
{
8891
ammoPool = self.TraitsImplementing<AmmoPool>().FirstOrDefault(la => la.Info.Name == Info.AmmoPoolName);
8992

93+
if (info.ApplyModifiers)
94+
{
95+
firepowerModifiers = self.TraitsImplementing<IFirepowerModifier>().ToArray();
96+
reloadModifiers = self.TraitsImplementing<IReloadModifier>().ToArray();
97+
}
98+
else
99+
{
100+
firepowerModifiers = Array.Empty<IFirepowerModifier>();
101+
reloadModifiers = Array.Empty<IReloadModifier>();
102+
}
103+
90104
base.Created(self);
91105
}
92106

@@ -123,7 +137,7 @@ void ITick.Tick(Actor self)
123137
};
124138

125139
if (info.ApplyModifiers)
126-
args.DamageModifiers = self.TraitsImplementing<IFirepowerModifier>().Select(a => a.GetFirepowerModifier()).ToArray();
140+
args.DamageModifiers = firepowerModifiers.Select(a => a.GetFirepowerModifier()).ToArray();
127141

128142
weapon.Impact(Target.FromPos(self.CenterPosition + localoffset), args);
129143

@@ -144,7 +158,7 @@ void ITick.Tick(Actor self)
144158
{
145159
if (info.ApplyModifiers)
146160
{
147-
var modifiers = self.TraitsImplementing<IReloadModifier>().Select(m => m.GetReloadModifier());
161+
var modifiers = reloadModifiers.Select(m => m.GetReloadModifier());
148162
fireDelay = Util.ApplyPercentageModifiers(weapon.ReloadDelay, modifiers);
149163
}
150164
else

OpenRA.Mods.CA/Traits/Render/RenderLine.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#endregion
1010

1111
using System.Collections.Generic;
12-
using System.Linq;
1312
using OpenRA.Graphics;
1413
using OpenRA.Mods.Common.Graphics;
1514
using OpenRA.Mods.Common.Traits;
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#region Copyright & License Information
2+
/**
3+
* Copyright (c) The OpenRA Combined Arms Developers (see CREDITS).
4+
* This file is part of OpenRA Combined Arms, which is free software.
5+
* It is made available to you under the terms of the GNU General Public License
6+
* as published by the Free Software Foundation, either version 3 of the License,
7+
* or (at your option) any later version. For more information, see COPYING.
8+
*/
9+
#endregion
10+
11+
using OpenRA.Mods.Common.Effects;
12+
using OpenRA.Mods.Common.Traits;
13+
using OpenRA.Primitives;
14+
using OpenRA.Traits;
15+
16+
namespace OpenRA.Mods.CA.Traits.Render
17+
{
18+
[Desc("Flashes the target at a set interval.")]
19+
class WithFlashEffectInfo : ConditionalTraitInfo
20+
{
21+
[Desc("Interval in ticks between flashes.")]
22+
public readonly int Interval = 25;
23+
24+
[Desc("Flash color.")]
25+
public readonly Color Color = Color.FromArgb(80, Color.Red);
26+
27+
public override object Create(ActorInitializer init) { return new WithFlashEffect(this); }
28+
}
29+
30+
class WithFlashEffect : ConditionalTrait<WithFlashEffectInfo>, ITick
31+
{
32+
public new readonly WithFlashEffectInfo Info;
33+
int intervalTicks;
34+
35+
public WithFlashEffect(WithFlashEffectInfo info)
36+
: base(info)
37+
{
38+
Info = info;
39+
}
40+
41+
void ITick.Tick(Actor self)
42+
{
43+
if (IsTraitDisabled || !self.IsInWorld)
44+
return;
45+
46+
if (intervalTicks == 0)
47+
{
48+
self.World.AddFrameEndTask(w =>
49+
{
50+
w.Add(new FlashTarget(self, Info.Color, 0.5f, 1, 2, 0));
51+
});
52+
}
53+
54+
intervalTicks++;
55+
56+
if (intervalTicks >= Info.Interval)
57+
intervalTicks = 0;
58+
}
59+
60+
protected override void TraitEnabled(Actor self)
61+
{
62+
intervalTicks = 0;
63+
}
64+
65+
protected override void TraitDisabled(Actor self)
66+
{
67+
intervalTicks = 0;
68+
}
69+
}
70+
}

OpenRA.Mods.CA/Traits/Render/WithRadiatingCircle.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99
#endregion
1010

11-
using System;
11+
using System.Linq;
1212
using System.Collections.Generic;
1313
using OpenRA.Graphics;
1414
using OpenRA.Mods.Common.Graphics;
@@ -62,6 +62,7 @@ class WithRadiatingCircle : ConditionalTrait<WithRadiatingCircleInfo>, ITick, IR
6262
Queue<RadiatingCircle> activeCircles;
6363
int intervalTicks;
6464
bool flash;
65+
WDist radiusChangePerTick;
6566

6667
struct RadiatingCircle
6768
{
@@ -165,7 +166,6 @@ void ITick.Tick(Actor self)
165166
}
166167

167168
// Update all active circles
168-
var radiusChangePerTick = (Info.EndRadius - Info.StartRadius) / Info.Duration;
169169
var tempCircles = new Queue<RadiatingCircle>();
170170
var circleCompleted = false;
171171

@@ -195,7 +195,15 @@ void ITick.Tick(Actor self)
195195

196196
protected override void TraitEnabled(Actor self)
197197
{
198-
activeCircles.Enqueue(new RadiatingCircle(Info.StartRadius));
198+
if (Info.Duration > 0)
199+
radiusChangePerTick = (Info.EndRadius - Info.StartRadius) / Info.Duration;
200+
else
201+
radiusChangePerTick = WDist.Zero;
202+
203+
if (Info.Interval == 0 || !activeCircles.Any())
204+
activeCircles.Enqueue(new RadiatingCircle(Info.StartRadius));
205+
206+
intervalTicks = 0;
199207
}
200208

201209
protected override void TraitDisabled(Actor self)

0 commit comments

Comments
 (0)