Skip to content

Commit

Permalink
Post rebase stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
MustaphaTR committed Aug 7, 2024
1 parent 039bb31 commit a706cbe
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 61 deletions.
4 changes: 2 additions & 2 deletions OpenRA.Mods.AS/Activities/UnloadGarrison.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public UnloadGarrison(Actor self, Target destination, WDist unloadRange, bool un
{
var pos = passenger.Trait<IPositionable>();

return garrison.CurrentAdjacentCells
return garrison.CurrentAdjacentCells()
.Shuffle(self.World.SharedRandom)
.Select(c => (c, pos.GetAvailableSubCell(c)))
.Cast<(CPos, SubCell SubCell)?>()
Expand All @@ -67,7 +67,7 @@ IEnumerable<CPos> BlockedExitCells(Actor passenger)
var pos = passenger.Trait<IPositionable>();

// Find the cells that are blocked by transient actors
return garrison.CurrentAdjacentCells
return garrison.CurrentAdjacentCells()
.Where(c => pos.CanEnterCell(c, null, BlockedByActor.All) != pos.CanEnterCell(c, null, BlockedByActor.None));
}

Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.AS/Activities/UnloadSharedCargo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public UnloadSharedCargo(Actor self, in Target destination, WDist unloadRange, b
{
var pos = passenger.Trait<IPositionable>();

return cargo.CurrentAdjacentCells
return cargo.CurrentAdjacentCells()
.Shuffle(self.World.SharedRandom)
.Select(c => (c, pos.GetAvailableSubCell(c)))
.Cast<(CPos, SubCell SubCell)?>()
Expand All @@ -71,7 +71,7 @@ IEnumerable<CPos> BlockedExitCells(Actor passenger)
var pos = passenger.Trait<IPositionable>();

// Find the cells that are blocked by transient actors
return cargo.CurrentAdjacentCells
return cargo.CurrentAdjacentCells()
.Where(c => pos.CanEnterCell(c, null, BlockedByActor.All) != pos.CanEnterCell(c, null, BlockedByActor.None));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,16 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{
public enum ObserverStatsRVPanel { None, Minimal, Basic, Economy, Production, SupportPowers, Combat, Army, Upgrades, Graph, ArmyGraph }

[ChromeLogicArgsHotkeys("StatisticsMinimalKey", "StatisticsBasicKey", "StatisticsEconomyKey", "StatisticsProductionKey", "StatisticsSupportPowersKey", "StatisticsCombatKey", "StatisticsArmyKey", "StatisticsUpgradesKey", "StatisticsGraphKey",
[ChromeLogicArgsHotkeys(
"StatisticsMinimalKey",
"StatisticsBasicKey",
"StatisticsEconomyKey",
"StatisticsProductionKey",
"StatisticsSupportPowersKey",
"StatisticsCombatKey",
"StatisticsArmyKey",
"StatisticsUpgradesKey",
"StatisticsGraphKey",
"StatisticsArmyGraphKey")]
public class ObserverStatsRVLogic : ChromeLogic
{
Expand Down Expand Up @@ -491,7 +500,8 @@ ScrollItemWidget EconomyStats(Player player)
template.Get<LabelWidget>("ASSETS").GetText = () => assetsText.Update(stats.AssetsValue);

var harvesters = template.Get<LabelWidget>("HARVESTERS");
harvesters.GetText = () => world.ActorsWithTrait<Harvester>().Count(a => a.Actor.Owner == player && !a.Actor.IsDead && !a.Trait.IsTraitDisabled).ToString(NumberFormatInfo.CurrentInfo);
harvesters.GetText = () => world.ActorsWithTrait<Harvester>()
.Count(a => a.Actor.Owner == player && !a.Actor.IsDead && !a.Trait.IsTraitDisabled).ToString(NumberFormatInfo.CurrentInfo);

var derricks = template.GetOrNull<LabelWidget>("DERRICKS");
if (derricks != null)
Expand Down Expand Up @@ -529,7 +539,8 @@ ScrollItemWidget MinimalStats(Player player)
}

var harvesters = template.Get<LabelWidget>("HARVESTERS");
harvesters.GetText = () => world.ActorsWithTrait<Harvester>().Count(a => a.Actor.Owner == player && !a.Actor.IsDead && !a.Trait.IsTraitDisabled).ToString(NumberFormatInfo.CurrentInfo);
harvesters.GetText = () => world.ActorsWithTrait<Harvester>()
.Count(a => a.Actor.Owner == player && !a.Actor.IsDead && !a.Trait.IsTraitDisabled).ToString(NumberFormatInfo.CurrentInfo);

return template;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{
public enum ObserverStatsSPPanel { None, Minimal, Basic, Economy, Production, SupportPowers, Combat, Army, Graph, ArmyGraph }

[ChromeLogicArgsHotkeys("StatisticsMinimalKey", "StatisticsBasicKey", "StatisticsEconomyKey", "StatisticsProductionKey", "StatisticsSupportPowersKey", "StatisticsCombatKey", "StatisticsArmyKey", "StatisticsGraphKey",
[ChromeLogicArgsHotkeys(
"StatisticsMinimalKey",
"StatisticsBasicKey",
"StatisticsEconomyKey",
"StatisticsProductionKey",
"StatisticsSupportPowersKey",
"StatisticsCombatKey",
"StatisticsArmyKey",
"StatisticsGraphKey",
"StatisticsArmyGraphKey")]
public class ObserverStatsSPLogic : ChromeLogic
{
Expand Down Expand Up @@ -460,7 +468,8 @@ ScrollItemWidget EconomyStats(Player player)
template.Get<LabelWidget>("ASSETS").GetText = () => assetsText.Update(stats.AssetsValue);

var harvesters = template.Get<LabelWidget>("HARVESTERS");
harvesters.GetText = () => world.ActorsWithTrait<Harvester>().Count(a => a.Actor.Owner == player && !a.Actor.IsDead && !a.Trait.IsTraitDisabled).ToString(NumberFormatInfo.CurrentInfo);
harvesters.GetText = () => world.ActorsWithTrait<Harvester>()
.Count(a => a.Actor.Owner == player && !a.Actor.IsDead && !a.Trait.IsTraitDisabled).ToString(NumberFormatInfo.CurrentInfo);

var derricks = template.GetOrNull<LabelWidget>("DERRICKS");
if (derricks != null)
Expand Down Expand Up @@ -498,7 +507,8 @@ ScrollItemWidget MinimalStats(Player player)
}

var harvesters = template.Get<LabelWidget>("HARVESTERS");
harvesters.GetText = () => world.ActorsWithTrait<Harvester>().Count(a => a.Actor.Owner == player && !a.Actor.IsDead && !a.Trait.IsTraitDisabled).ToString(NumberFormatInfo.CurrentInfo);
harvesters.GetText = () => world.ActorsWithTrait<Harvester>()
.Count(a => a.Actor.Owner == player && !a.Actor.IsDead && !a.Trait.IsTraitDisabled).ToString(NumberFormatInfo.CurrentInfo);

return template;
}
Expand Down
30 changes: 6 additions & 24 deletions OpenRA.Mods.AS/Traits/Garrisonable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public class GarrisonableInfo : PausableConditionalTraitInfo, Requires<IOccupySp
public override object Create(ActorInitializer init) { return new Garrisonable(init, this); }
}

public class Garrisonable : PausableConditionalTrait<GarrisonableInfo>, IIssueOrder, IResolveOrder, IOrderVoice, INotifyCreated, INotifyKilled,
INotifyOwnerChanged, INotifyAddedToWorld, ITick, INotifySold, INotifyActorDisposing, IIssueDeployOrder,
public class Garrisonable : PausableConditionalTrait<GarrisonableInfo>, IIssueOrder, IResolveOrder, IOrderVoice,
INotifyKilled, INotifyOwnerChanged, INotifySold, INotifyActorDisposing, IIssueDeployOrder,
ITransformActorInitModifier, INotifyPassengersDamage
{
readonly Actor self;
Expand All @@ -108,8 +108,6 @@ public class Garrisonable : PausableConditionalTrait<GarrisonableInfo>, IIssueOr
bool takeOffAfterLoad;
bool initialised;

CPos currentCell;
public IEnumerable<CPos> CurrentAdjacentCells { get; private set; }
public IEnumerable<Actor> Garrisoners { get { return garrisonable; } }
public int GarrisonerCount { get { return garrisonable.Count; } }

Expand Down Expand Up @@ -230,7 +228,7 @@ public void ResolveOrder(Actor self, Order order)
}
}

IEnumerable<CPos> GetAdjacentCells()
public IEnumerable<CPos> CurrentAdjacentCells()
{
return Util.AdjacentCells(self.World, Target.FromActor(self)).Where(c => self.Location != c);
}
Expand All @@ -247,7 +245,7 @@ public bool CanUnload(BlockedByActor check = BlockedByActor.None)
}

return !IsEmpty() && (aircraft == null || aircraft.CanLand(self.Location, blockedByMobile: false))
&& CurrentAdjacentCells != null && CurrentAdjacentCells.Any(c => Garrisoners.Any(p => !p.IsDead && p.Trait<IPositionable>().CanEnterCell(c, null, check)));
&& CurrentAdjacentCells().Any(c => Garrisoners.Any(p => !p.IsDead && p.Trait<IPositionable>().CanEnterCell(c, null, check)));
}

public bool CanLoad(Actor a)
Expand Down Expand Up @@ -472,23 +470,6 @@ void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newO
p.ChangeOwner(newOwner);
}

void INotifyAddedToWorld.AddedToWorld(Actor self)
{
// Force location update to avoid issues when initial spawn is outside map
currentCell = self.Location;
CurrentAdjacentCells = GetAdjacentCells();
}

void ITick.Tick(Actor self)
{
var cell = self.World.Map.CellContaining(self.CenterPosition);
if (currentCell != cell)
{
currentCell = cell;
CurrentAdjacentCells = GetAdjacentCells();
}
}

void ITransformActorInitModifier.ModifyTransformActorInit(Actor self, TypeDictionary init)
{
init.Add(new RuntimeGarrisonInit(Info, Garrisoners.ToArray()));
Expand Down Expand Up @@ -516,7 +497,8 @@ public int DamageVersus(Actor victim, Dictionary<string, int> versus)
return Util.ApplyPercentageModifiers(100, armor);
}

void INotifyPassengersDamage.DamagePassengers(int damage, Actor attacker, int amount, Dictionary<string, int> versus, BitSet<DamageType> damageTypes, IEnumerable<int> damageModifiers)
void INotifyPassengersDamage.DamagePassengers(
int damage, Actor attacker, int amount, Dictionary<string, int> versus, BitSet<DamageType> damageTypes, IEnumerable<int> damageModifiers)
{
var passengersToDamage = amount > 0 && amount < garrisonable.Count ? garrisonable.Shuffle(self.World.SharedRandom).Take(amount) : garrisonable;
foreach (var passenger in passengersToDamage)
Expand Down
32 changes: 9 additions & 23 deletions OpenRA.Mods.AS/Traits/SharedCargo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public class SharedCargoInfo : PausableConditionalTraitInfo, Requires<IOccupySpa
}

public class SharedCargo : PausableConditionalTrait<SharedCargoInfo>, IIssueOrder, IResolveOrder, IOrderVoice, INotifyCreated,
INotifyAddedToWorld, ITick, IIssueDeployOrder, INotifyKilled, INotifyActorDisposing, INotifyPassengersDamage
ITick, IIssueDeployOrder, INotifyKilled, INotifyActorDisposing, INotifyPassengersDamage
{
readonly Actor self;
public readonly SharedCargoManager Manager;
Expand All @@ -96,9 +96,6 @@ public class SharedCargo : PausableConditionalTrait<SharedCargoInfo>, IIssueOrde
bool takeOffAfterLoad;
bool initialized;

CPos currentCell;
public IEnumerable<CPos> CurrentAdjacentCells { get; private set; }

enum State { Free, Locked }
State state = State.Free;

Expand Down Expand Up @@ -156,7 +153,7 @@ public void ResolveOrder(Actor self, Order order)
}
}

IEnumerable<CPos> GetAdjacentCells()
public IEnumerable<CPos> CurrentAdjacentCells()
{
return Util.AdjacentCells(self.World, Target.FromActor(self)).Where(c => self.Location != c);
}
Expand All @@ -172,8 +169,8 @@ public bool CanUnload(BlockedByActor check = BlockedByActor.None)
return false;
}

return !Manager.IsEmpty() && (aircraft == null || aircraft.CanLand(self.Location)) && !IsTraitPaused
&& CurrentAdjacentCells != null && CurrentAdjacentCells.Any(c => Manager.Passengers.Any(p => p.Trait<IPositionable>().CanEnterCell(c, null, check)));
return !Manager.IsEmpty() && (aircraft == null || aircraft.CanLand(self.Location, blockedByMobile: false)) && !IsTraitPaused
&& CurrentAdjacentCells().Any(c => Manager.Passengers.Any(p => p.Trait<IPositionable>().CanEnterCell(c, null, check)));
}

public bool CanLoad(Actor self, Actor a)
Expand Down Expand Up @@ -337,13 +334,6 @@ public void Load(Actor self, Actor a)
loadedTokens.Push(self.GrantCondition(Info.LoadedCondition));
}

void INotifyAddedToWorld.AddedToWorld(Actor self)
{
// Force location update to avoid issues when initial spawn is outside map
currentCell = self.Location;
CurrentAdjacentCells = GetAdjacentCells();
}

void INotifyKilled.Killed(Actor self, AttackInfo e)
{
if (!self.World.ActorsWithTrait<SharedCargo>().Any(a => a.Trait.Info.ShareType == Info.ShareType && a.Actor.Owner == self.Owner && a.Actor != self))
Expand Down Expand Up @@ -374,13 +364,6 @@ void ITick.Tick(Actor self)

initialized = true;
}

var cell = self.World.Map.CellContaining(self.CenterPosition);
if (currentCell != cell)
{
currentCell = cell;
CurrentAdjacentCells = GetAdjacentCells();
}
}

static int DamageVersus(Actor victim, Dictionary<string, int> versus)
Expand All @@ -396,9 +379,12 @@ static int DamageVersus(Actor victim, Dictionary<string, int> versus)
return Util.ApplyPercentageModifiers(100, armor);
}

void INotifyPassengersDamage.DamagePassengers(int damage, Actor attacker, int amount, Dictionary<string, int> versus, BitSet<DamageType> damageTypes, IEnumerable<int> damageModifiers)
void INotifyPassengersDamage.DamagePassengers(
int damage, Actor attacker, int amount, Dictionary<string, int> versus, BitSet<DamageType> damageTypes, IEnumerable<int> damageModifiers)
{
var passengersToDamage = amount > 0 && amount < Manager.Cargo.ToArray().Length ? Manager.Cargo.Shuffle(self.World.SharedRandom).Take(amount).ToArray() : Manager.Cargo.ToArray();
var passengersToDamage = amount > 0 && amount < Manager.Cargo.ToArray().Length
? Manager.Cargo.Shuffle(self.World.SharedRandom).Take(amount).ToArray()
: Manager.Cargo.ToArray();
foreach (var passenger in passengersToDamage)
{
var d = Util.ApplyPercentageModifiers(damage, damageModifiers.Append(DamageVersus(passenger, versus)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ bool IsRallyPointValid(CPos producerLocation, CPos rallyPointLocation, Locomotor
locomotors.All(l => pathFinder.PathMightExistForLocomotorBlockedByImmovable(l, producerLocation, rallyPointLocation)))
&&
(buildingInfo == null ||
world.IsCellBuildable(rallyPointLocation, null, buildingInfo));
world.IsCellBuildable(rallyPointLocation, rallyPointLocation, null, buildingInfo));
}

// Require at least one refinery, unless we can't build it.
Expand Down
8 changes: 5 additions & 3 deletions OpenRA.Mods.Common/Traits/Cargo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public class CargoInfo : PausableConditionalTraitInfo, Requires<IOccupySpaceInfo
}

public class Cargo : PausableConditionalTrait<CargoInfo>, IIssueOrder, IResolveOrder, IOrderVoice,
INotifyOwnerChanged, INotifySold, INotifyActorDisposing, IIssueDeployOrder
INotifyOwnerChanged, INotifySold, INotifyActorDisposing, IIssueDeployOrder,
INotifyCreated, INotifyKilled, ITransformActorInitModifier, INotifyPassengersDamage
{
readonly Actor self;
Expand Down Expand Up @@ -449,7 +449,8 @@ public void Load(Actor self, Actor a)
void INotifyKilled.Killed(Actor self, AttackInfo e)
{
// IsAtGroundLevel contains Map.Contains(self.Location) check.
if (Info.EjectOnDeathDamage < 100 && self.IsAtGroundLevel() && (!checkTerrainType || Info.UnloadTerrainTypes.Contains(self.World.Map.GetTerrainInfo(self.Location).Type)))
if (Info.EjectOnDeathDamage < 100 && self.IsAtGroundLevel()
&& (!checkTerrainType || Info.UnloadTerrainTypes.Contains(self.World.Map.GetTerrainInfo(self.Location).Type)))
{
while (!IsEmpty())
{
Expand Down Expand Up @@ -548,7 +549,8 @@ static int DamageVersus(Actor victim, Dictionary<string, int> versus)
return Util.ApplyPercentageModifiers(100, armor);
}

void INotifyPassengersDamage.DamagePassengers(int damage, Actor attacker, int amount, Dictionary<string, int> versus, BitSet<DamageType> damageTypes, IEnumerable<int> damageModifiers)
void INotifyPassengersDamage.DamagePassengers(
int damage, Actor attacker, int amount, Dictionary<string, int> versus, BitSet<DamageType> damageTypes, IEnumerable<int> damageModifiers)
{
var passengersToDamage = amount > 0 && amount < cargo.Count ? cargo.Shuffle(self.World.SharedRandom).Take(amount).ToArray() : cargo.ToArray();
foreach (var passenger in passengersToDamage)
Expand Down

0 comments on commit a706cbe

Please sign in to comment.