Skip to content

Commit

Permalink
Merge remote-tracking branch 'darkademic/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Inq8 committed Aug 28, 2024
2 parents 42bde88 + d7074d1 commit 4799e8e
Show file tree
Hide file tree
Showing 57 changed files with 2,025 additions and 222 deletions.
2 changes: 1 addition & 1 deletion OpenRA.Mods.CA/Traits/CloneProducer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void INotifyRemovedFromWorld.RemovedFromWorld(Actor self)

public void UnitProduced(Actor unit)
{
if (Info.InvalidActors.Contains(unit.Info.Name))
if (self.IsDead || Info.InvalidActors.Contains(unit.Info.Name))
return;

var sp = self.TraitsImplementing<Production>()
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.CA/Traits/MindController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public void ResolveOrder(Actor self, Order order)
}

// For all other orders, if target has changed, reset progress
if (order.Target.Actor != currentTarget.Actor)
if (order.Target.Actor != currentTarget.Actor && !order.Queued)
{
if (Info.AutoUndeploy && deployTrait != null && deployTrait.DeployState == DeployState.Deployed && currentTarget.Actor != null && order.OrderString != "GrantConditionOnDeploy")
deployTrait.Undeploy();
Expand Down
48 changes: 48 additions & 0 deletions OpenRA.Mods.CA/Traits/Player/BuildOrderTracker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#region Copyright & License Information
/**
* Copyright (c) The OpenRA Combined Arms Developers (see CREDITS).
* This file is part of OpenRA Combined Arms, which is free software.
* It is made available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version. For more information, see COPYING.
*/
#endregion

using System.Collections.Generic;
using OpenRA.Traits;

namespace OpenRA.Mods.CA.Traits
{
[Desc("Keeps track of player's initial build order for observer stats.")]
public class BuildOrderTrackerInfo : TraitInfo
{
[Desc("Maximum number of items to track.")]
public readonly int MaxItems = 12;

public override object Create(ActorInitializer init) { return new BuildOrderTracker(init.Self, this); }
}

public class BuildOrderTracker
{
readonly BuildOrderTrackerInfo info;
List<string> buildOrder;
public int Count { get; private set; }
public List<string> BuildOrder => buildOrder;

public BuildOrderTracker(Actor self, BuildOrderTrackerInfo info)
{
this.info = info;
buildOrder = new List<string>();
Count = 0;
}

public void BuildingCreated(string type)
{
if (Count >= info.MaxItems)
return;

Count++;
buildOrder.Add(type);
}
}
}
2 changes: 2 additions & 0 deletions OpenRA.Mods.CA/Traits/Player/UpgradesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class UpgradesManager

public int Hash { get; private set; }

public HashSet<string> UnlockedUpgradeTypes => unlockedUpgradeTypes;

public UpgradesManager(Actor self, UpgradesManagerInfo info)
{
this.self = self;
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.CA/Traits/Render/WithEnabledAnimation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace OpenRA.Mods.CA.Traits.Render
{
[Desc("Plays an animation when trait is enabled or re-enabled, replacing the default body animation (plays once, unlike WithEnabledAnimation).")]
[Desc("Plays an animation when trait is enabled or re-enabled, replacing the default body animation (plays once, unlike WithIdleAnimation).")]
public class WithEnabledAnimationInfo : ConditionalTraitInfo, Requires<WithSpriteBodyInfo>
{
[SequenceReference]
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.CA/Traits/Sound/AmbientSoundCA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void ITick.Tick(Actor self)
if (IsTraitDisabled)
return;

if (self.World.IsGameOver)
if (self.World.IsGameOver || self.World.Paused)
StopSounds(self, false);

if (Info.InitialSound != null && !initialSoundComplete)
Expand Down
35 changes: 21 additions & 14 deletions OpenRA.Mods.CA/Traits/UnitConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public class UnitConverter : ConditionalTrait<UnitConverterInfo>, ITick, INotify
protected PlayerResources playerResources;
int conditionToken = Actor.InvalidConditionToken;
bool eject = false;
bool blocked = false;

public UnitConverter(ActorInitializer init, UnitConverterInfo info)
: base(info)
Expand Down Expand Up @@ -147,26 +148,31 @@ void ITick.Tick(Actor self)
var outputActor = eject ? nextItem.InputActor : nextItem.OutputActor;
var exitSound = info.ReadyAudio;

if (!eject)
if (!blocked)
{
var expectedRemainingCost = nextItem.BuildDurationRemaining == 1 ? 0 : nextItem.ConversionCost * nextItem.BuildDurationRemaining / Math.Max(1, nextItem.BuildDuration);
var costThisFrame = nextItem.ConversionCostRemaining - expectedRemainingCost;
if (!eject)
{
var expectedRemainingCost = nextItem.BuildDurationRemaining == 1 ? 0 : nextItem.ConversionCost * nextItem.BuildDurationRemaining / Math.Max(1, nextItem.BuildDuration);
var costThisFrame = nextItem.ConversionCostRemaining - expectedRemainingCost;

if (costThisFrame != 0 && !playerResources.TakeCash(costThisFrame, true))
return;
if (costThisFrame != 0 && !playerResources.TakeCash(costThisFrame, true))
return;

nextItem.ConversionCostRemaining -= costThisFrame;
nextItem.BuildDurationRemaining -= 1;
if (nextItem.BuildDurationRemaining > 0)
return;
}
else
{
playerResources.GiveCash(nextItem.ConversionCost - nextItem.ConversionCostRemaining);
nextItem.ConversionCostRemaining -= costThisFrame;
nextItem.BuildDurationRemaining -= 1;
if (nextItem.BuildDurationRemaining > 0)
return;
}
else
{
playerResources.GiveCash(nextItem.ConversionCost - nextItem.ConversionCostRemaining);
}
}

if (nextItem.Producer.Produce(nextItem.Actor, outputActor, nextItem.ProductionType, nextItem.Inits, 0))
{
blocked = false;

if (!eject)
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", exitSound, self.Owner.Faction.InternalName);

Expand All @@ -178,9 +184,10 @@ void ITick.Tick(Actor self)
RevokeCondition(self);
}
}
else if (!eject)
else if (!eject && !blocked)
{
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", Info.BlockedAudio, self.Owner.Faction.InternalName);
blocked = true;
}
}

Expand Down
37 changes: 37 additions & 0 deletions OpenRA.Mods.CA/Traits/UpdatesBuildOrder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#region Copyright & License Information
/**
* Copyright (c) The OpenRA Combined Arms Developers (see CREDITS).
* This file is part of OpenRA Combined Arms, which is free software.
* It is made available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version. For more information, see COPYING.
*/
#endregion

using OpenRA.Traits;

namespace OpenRA.Mods.CA.Traits
{
[Desc("Added to build order when the actor is created.")]
public class UpdatesBuildOrderInfo : TraitInfo
{
public override object Create(ActorInitializer init) { return new UpdatesBuildOrder(init, this); }
}

public class UpdatesBuildOrder : INotifyCreated
{
public readonly UpdatesBuildOrderInfo Info;
readonly BuildOrderTracker buildOrderTracker;

public UpdatesBuildOrder(ActorInitializer init, UpdatesBuildOrderInfo info)
{
Info = info;
buildOrderTracker = init.Self.Owner.PlayerActor.Trait<BuildOrderTracker>();
}

void INotifyCreated.Created(Actor self)
{
buildOrderTracker.BuildingCreated(self.Info.Name);
}
}
}
Loading

0 comments on commit 4799e8e

Please sign in to comment.