Skip to content

Commit b93edeb

Browse files
committed
Merge remote-tracking branch 'darkademic/dev'
2 parents a6eea3a + 4a84fc0 commit b93edeb

25 files changed

Lines changed: 366 additions & 66 deletions
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#region Copyright & License Information
2+
/*
3+
* Copyright (c) The OpenRA Developers and Contributors
4+
* This file is part of OpenRA, which is free software. It is made
5+
* available to you under the terms of the GNU General Public License
6+
* as published by the Free Software Foundation, either version 3 of
7+
* the License, or (at your option) any later version. For more
8+
* information, see COPYING.
9+
*/
10+
#endregion
11+
12+
using System;
13+
using System.Collections.Generic;
14+
using System.Linq;
15+
using OpenRA.Mods.Common.Traits;
16+
using OpenRA.Traits;
17+
18+
namespace OpenRA.Mods.CA.Traits
19+
{
20+
[Desc("Gradually converts resources within a given radius.")]
21+
sealed class ConvertsResourcesInfo : ConditionalTraitInfo
22+
{
23+
public readonly string[] ConvertFrom = { "Ore", "Tiberium", "Gems", "BlueTiberium" };
24+
public readonly int Interval = 75;
25+
public readonly string ConvertTo = "BlackTiberium";
26+
public readonly WDist Range = WDist.FromCells(5);
27+
public readonly int Amount = 1;
28+
29+
public override object Create(ActorInitializer init) { return new ConvertsResources(init.Self, this); }
30+
}
31+
32+
sealed class ConvertsResources : ConditionalTrait<ConvertsResourcesInfo>, ITick
33+
{
34+
readonly ConvertsResourcesInfo info;
35+
readonly IResourceLayer resourceLayer;
36+
readonly Dictionary<CPos, int> cellsToConvert;
37+
38+
public ConvertsResources(Actor self, ConvertsResourcesInfo info)
39+
: base(info)
40+
{
41+
this.info = info;
42+
resourceLayer = self.World.WorldActor.Trait<IResourceLayer>();
43+
cellsToConvert = new Dictionary<CPos, int>();
44+
ticks = info.Interval;
45+
}
46+
47+
int ticks;
48+
49+
void ITick.Tick(Actor self)
50+
{
51+
if (IsTraitDisabled)
52+
return;
53+
54+
if (--ticks <= 0)
55+
{
56+
Convert(self);
57+
ticks = info.Interval;
58+
}
59+
}
60+
61+
void Convert(Actor self)
62+
{
63+
// Find cells with convertible resources within range
64+
var cells = self.World.Map.FindTilesInCircle(self.Location, info.Range.Length / 1024)
65+
.Where(c =>
66+
{
67+
var resource = resourceLayer.GetResource(c);
68+
return resource.Type != null &&
69+
info.ConvertFrom.Contains(resource.Type) &&
70+
(resource.Density > 0 || cellsToConvert.ContainsKey(c));
71+
});
72+
73+
if (cells.Any())
74+
Remove(cells.Random(self.World.SharedRandom));
75+
76+
// Only try to add resources to cells that are ready for conversion
77+
var convertedCells = cellsToConvert
78+
.Where(kv => resourceLayer.GetResource(kv.Key).Type == null || resourceLayer.GetResource(kv.Key).Type == info.ConvertTo)
79+
.Select(kv => kv.Key)
80+
.ToList();
81+
82+
if (convertedCells.Count > 0)
83+
Add(convertedCells.Random(self.World.SharedRandom));
84+
}
85+
86+
void Remove(CPos cell)
87+
{
88+
var resource = resourceLayer.GetResource(cell);
89+
var amountRemoved = resourceLayer.RemoveResource(resource.Type, cell, info.Amount);
90+
91+
// Remove some of the original resource
92+
if (amountRemoved > 0)
93+
{
94+
// Track how much we've removed from this cell
95+
if (!cellsToConvert.ContainsKey(cell))
96+
cellsToConvert[cell] = 0;
97+
98+
cellsToConvert[cell] += amountRemoved;
99+
var updatedResource = resourceLayer.GetResource(cell);
100+
101+
// If none of the original resource is left, mark it as converted
102+
if (updatedResource.Density == 0)
103+
Add(cell);
104+
}
105+
}
106+
107+
void Add(CPos cell)
108+
{
109+
if (!resourceLayer.CanAddResource(info.ConvertTo, cell))
110+
return;
111+
112+
var toConvert = cellsToConvert[cell];
113+
var maxDensity = resourceLayer.GetMaxDensity(info.ConvertTo);
114+
var currentDensity = resourceLayer.GetResource(cell).Density;
115+
116+
// Only try to add info.Amount, limited by remaining space
117+
var amountToAdd = Math.Min(info.Amount, maxDensity - currentDensity);
118+
var amountAdded = resourceLayer.AddResource(info.ConvertTo, cell, amountToAdd);
119+
120+
if (amountAdded > 0)
121+
{
122+
var remaining = toConvert - amountAdded;
123+
if (remaining > 0)
124+
cellsToConvert[cell] = remaining;
125+
else
126+
cellsToConvert.Remove(cell);
127+
}
128+
else if (currentDensity >= maxDensity)
129+
cellsToConvert.Remove(cell);
130+
}
131+
}
132+
}

OpenRA.Mods.CA/Traits/Player/ProvidesPrerequisitesOnTimeline.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ public class ProvidesPrerequisitesOnTimelineInfo : TraitInfo, ITechTreePrerequis
3434
[Desc("List of factions that can affect this count. Leave blank for any faction.")]
3535
public readonly string[] Factions = { };
3636

37-
[NotificationReference("Speech")]
3837
[Desc("Speech notification to play when player reaches the required count.")]
39-
public readonly string PrerequisiteGrantedNotification = null;
38+
public readonly Dictionary<int, string> PrerequisiteGrantedNotifications = null;
4039

4140
[Desc("Text notification to display when player reaches the required count.")]
4241
public readonly string PrerequisiteGrantedTextNotification = null;
@@ -73,7 +72,7 @@ public class ProvidesPrerequisitesOnTimeline : ITechTreePrerequisite, INotifyCre
7372

7473
int ticksElapsed;
7574
HashSet<int> thresholdsPassed;
76-
bool notificationQueued;
75+
string notificationQueued;
7776
int ticksUntilNotification;
7877
bool dummyActorQueued;
7978
int ticksUntilSpawnDummyActor;
@@ -154,7 +153,9 @@ void HandlePrerequisiteThreshold(int percentage)
154153

155154
if (Info.DummyActor != null)
156155
{
157-
notificationQueued = true;
156+
if (Info.PrerequisiteGrantedNotifications != null && Info.PrerequisiteGrantedNotifications.ContainsKey(percentage))
157+
notificationQueued = Info.PrerequisiteGrantedNotifications[percentage];
158+
158159
dummyActorQueued = true;
159160
ticksUntilSpawnDummyActor = 1;
160161
}
@@ -178,15 +179,14 @@ void ITick.Tick(Actor self)
178179
HandlePrerequisiteThreshold(PercentageComplete);
179180
}
180181

181-
if (notificationQueued && --ticksUntilNotification <= 0)
182+
if (notificationQueued != null && --ticksUntilNotification <= 0)
182183
{
183-
if (Info.PrerequisiteGrantedNotification != null)
184-
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", Info.PrerequisiteGrantedNotification, self.Owner.Faction.InternalName);
184+
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", notificationQueued, self.Owner.Faction.InternalName);
185185

186186
if (Info.PrerequisiteGrantedTextNotification != null)
187187
TextNotificationsManager.AddTransientLine(Info.PrerequisiteGrantedTextNotification, self.Owner);
188188

189-
notificationQueued = false;
189+
notificationQueued = null;
190190
ticksUntilNotification = Info.NotificationDelay;
191191
}
192192

OpenRA.Mods.CA/Traits/SeedsResourceCA.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ public SeedsResourceCA(Actor self, SeedsResourceCAInfo info)
4444
protected override void Created(Actor self)
4545
{
4646
base.Created(self);
47-
48-
seedsResourceModifiers = self.TraitsImplementing<ISeedsResourceIntervalModifier>()
49-
.Concat(self.Owner.PlayerActor.TraitsImplementing<ISeedsResourceIntervalModifier>()).ToArray();
47+
seedsResourceModifiers = self.TraitsImplementing<ISeedsResourceIntervalModifier>().ToArray();
5048
}
5149

5250
void ITick.Tick(Actor self)

mods/ca/audio/notifications.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ Speech:
161161
ForceShieldCharging: forcechg1
162162
ForceShieldReady: forcedr1
163163

164+
DevLevel1: devlevel1
165+
DevLevel2: devlevel2
164166
VeilOfWarReady: vowrdy1
165167
ClusterMinesReady: cminesrdy1
166168
TemporalIncursionReady: tempincrdy1
@@ -225,6 +227,7 @@ Speech:
225227
ChemMissileReady: cmissrdy1
226228
ChemMissileWarning: cmisswarn1
227229

230+
VoidSpikeReady: voidspkrdy1
228231
IchorSeedReady: ichsdrdy
229232
ResourceScanReady: rscanrdy
230233
StormSpikeReady: strmspkrdy

mods/ca/bits/audio/r_devlevel1.aud

33.3 KB
Binary file not shown.

mods/ca/bits/audio/r_devlevel2.aud

38.8 KB
Binary file not shown.

mods/ca/bits/audio/timeskip.aud

13.9 KB
Binary file not shown.
16.2 KB
Binary file not shown.

mods/ca/bits/scrin/voidpulse.shp

27.7 KB
Binary file not shown.

mods/ca/bits/scrin/vspk.shp

14.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)