Skip to content

Commit

Permalink
Engine update.
Browse files Browse the repository at this point in the history
  • Loading branch information
MustaphaTR committed Aug 10, 2024
1 parent 689706a commit 6db3fbe
Show file tree
Hide file tree
Showing 51 changed files with 3,244 additions and 1,229 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"version": "0.2.0",
"configurations": [
{
"name": "Launch (Example)",
"name": "Launch (Generals Alpha)",
"type": "coreclr",
"request": "launch",
"program": "${workspaceRoot}/engine/bin/OpenRA.dll",
"args": [
"Game.Mod=example",
"Game.Mod=gen",
"Engine.EngineDir=${workspaceRoot}/engine",
"Engine.ModSearchPaths=${workspaceRoot}/mods, ${workspaceRoot}/engine/mods",
"Debug.DisplayDeveloperSettings=true",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class InitialBaseAndWorkerBotModuleInfo : ConditionalTraitInfo
public override object Create(ActorInitializer init) { return new InitialBaseAndWorkerBotModule(init.Self, this); }
}

public class InitialBaseAndWorkerBotModule : ConditionalTrait<InitialBaseAndWorkerBotModuleInfo>, IBotTick, IBotPositionsUpdated, IGameSaveTraitData
public class InitialBaseAndWorkerBotModule : ConditionalTrait<InitialBaseAndWorkerBotModuleInfo>, IBotTick, IBotPositionsUpdated, INotifyActorDisposing, IGameSaveTraitData
{
readonly World world;
readonly Player player;
Expand All @@ -50,11 +50,17 @@ public class InitialBaseAndWorkerBotModule : ConditionalTrait<InitialBaseAndWork
bool initialized;
int scanInterval;

readonly ActorIndex.OwnerAndNamesAndTrait<Mobile> dozers;
readonly ActorIndex.OwnerAndNamesAndTrait<Building> commandCenters;

public InitialBaseAndWorkerBotModule(Actor self, InitialBaseAndWorkerBotModuleInfo info)
: base(info)
{
world = self.World;
player = self.Owner;

dozers = new ActorIndex.OwnerAndNamesAndTrait<Mobile>(world, Info.DozerTypes, player);
commandCenters = new ActorIndex.OwnerAndNamesAndTrait<Building>(world, Info.CommandCenterTypes, player);
}

protected override void Created(Actor self)
Expand Down Expand Up @@ -108,21 +114,21 @@ void BuildDozer(IBot bot)
var unitBuilder = requestUnitProduction.FirstOrDefault(Exts.IsTraitEnabled);
if (unitBuilder != null)
{
var dozerInfo = AIUtils.GetInfoByCommonName(Info.DozerTypes, player);
if (unitBuilder.RequestedProductionCount(bot, dozerInfo.Name) == 0)
unitBuilder.RequestUnitProduction(bot, dozerInfo.Name);
var dozerType = Info.DozerTypes.Random(world.LocalRandom);
if (unitBuilder.RequestedProductionCount(bot, dozerType) == 0)
unitBuilder.RequestUnitProduction(bot, dozerType);
}
}

bool ShouldBuildDozer()
{
// Only build Dozer if we don't already have one in the field.
var allowedToBuildDozer = AIUtils.CountActorByCommonName(Info.DozerTypes, player) < Info.MinimumDozerCount;
var allowedToBuildDozer = AIUtils.CountActorByCommonName(dozers) < Info.MinimumDozerCount;
if (!allowedToBuildDozer)
return false;

// Build Dozer if we don't have the desired number of construction yards, unless we have no factory (can't build it).
return AIUtils.CountBuildingByCommonName(Info.CommandCenterTypes, player) > 0;
// Build Dozer if we don't have the desired number of them, unless we have no factory (can't build it).
return AIUtils.CountActorByCommonName(commandCenters) > 0;
}

void IBotPositionsUpdated.UpdatedBaseCenter(CPos newLocation)
Expand All @@ -139,7 +145,7 @@ List<MiniYamlNode> IGameSaveTraitData.IssueTraitData(Actor self)

return new List<MiniYamlNode>()
{
new MiniYamlNode("InitialBaseCenter", FieldSaver.FormatValue(initialBaseCenter))
new("InitialBaseCenter", FieldSaver.FormatValue(initialBaseCenter))
};
}

Expand All @@ -153,5 +159,11 @@ void IGameSaveTraitData.ResolveTraitData(Actor self, MiniYaml data)
if (nodes.TryGetValue("InitialBaseCenter", out var initialBaseCenterNode))
initialBaseCenter = FieldLoader.GetValue<CPos>("InitialBaseCenter", initialBaseCenterNode.Value);
}

void INotifyActorDisposing.Disposing(Actor self)
{
dozers.Dispose();
commandCenters.Dispose();
}
}
}
31 changes: 22 additions & 9 deletions OpenRA.Mods.GenSDK/Widgets/Logic/Ingame/ObserverStatsGenLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,16 @@ namespace OpenRA.Mods.GenSDK.Widgets.Logic
{
public enum ObserverStatsGenPanel { 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 ObserverStatsGenLogic : ChromeLogic
{
Expand Down Expand Up @@ -91,8 +100,8 @@ public class ObserverStatsGenLogic : ChromeLogic
readonly LineGraphWidget incomeGraph;
readonly LineGraphWidget armyValueGraph;
readonly ScrollItemWidget teamTemplate;
readonly IEnumerable<Player> players;
readonly IOrderedEnumerable<IGrouping<int, Player>> teams;
readonly Player[] players;
readonly IGrouping<int, Player>[] teams;
readonly bool hasTeams;
readonly World world;
readonly WorldRenderer worldRenderer;
Expand All @@ -112,9 +121,12 @@ public ObserverStatsGenLogic(World world, ModData modData, WorldRenderer worldRe
for (var i = 0; i < keyNames.Length; i++)
statsHotkeys[i] = logicArgs.TryGetValue("Statistics" + keyNames[i] + "Key", out yaml) ? modData.Hotkeys[yaml.Value] : new HotkeyReference();

players = world.Players.Where(p => !p.NonCombatant && p.Playable);
teams = players.GroupBy(p => (world.LobbyInfo.ClientWithIndex(p.ClientIndex) ?? new Session.Client()).Team).OrderBy(g => g.Key);
hasTeams = !(teams.Count() == 1 && teams.First().Key == 0);
players = world.Players.Where(p => !p.NonCombatant && p.Playable).ToArray();
teams = players
.GroupBy(p => (world.LobbyInfo.ClientWithIndex(p.ClientIndex) ?? new Session.Client()).Team)
.OrderBy(g => g.Key)
.ToArray();
hasTeams = !(teams.Length == 1 && teams[0].Key == 0);

minimalStatsHeaders = widget.Get<ContainerWidget>("MINIMAL_STATS_HEADERS");
basicStatsHeaders = widget.Get<ContainerWidget>("BASIC_STATS_HEADERS");
Expand Down Expand Up @@ -185,13 +197,14 @@ StatsDropDownOption CreateStatsOption(string title, ObserverStatsGenPanel panel,

var statsDropDownOptions = new StatsDropDownOption[]
{
new StatsDropDownOption
new()
{
Title = TranslationProvider.GetString(InformationNone),
IsSelected = () => activePanel == ObserverStatsGenPanel.None,
OnClick = () =>
{
var informationNone = TranslationProvider.GetString(InformationNone);
statsDropDown.GetText = () => informationNone;
playerStatsPanel.Visible = false;
ClearStats();
activePanel = ObserverStatsGenPanel.None;
Expand Down Expand Up @@ -585,7 +598,7 @@ ScrollItemWidget BasicStats(Player player)
return template;
}

void SetupPlayerColor(Player player, ScrollItemWidget template, ColorBlockWidget colorBlockWidget, GradientColorBlockWidget gradientColorBlockWidget)
static void SetupPlayerColor(Player player, ScrollItemWidget template, ColorBlockWidget colorBlockWidget, GradientColorBlockWidget gradientColorBlockWidget)
{
var color = Color.FromArgb(128, player.Color.R, player.Color.G, player.Color.B);
var hoverColor = Color.FromArgb(192, player.Color.R, player.Color.G, player.Color.B);
Expand Down Expand Up @@ -666,7 +679,7 @@ static Color GetPowerColor(PowerState state)
}

// HACK The height of the templates and the scrollpanel needs to be kept in synch
bool ShowScrollBar => players.Count() + (hasTeams ? teams.Count() : 0) > 10;
bool ShowScrollBar => players.Length + (hasTeams ? teams.Length : 0) > 10;

class StatsDropDownOption
{
Expand Down
2 changes: 1 addition & 1 deletion mod.config
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
MOD_ID="gen"

# The OpenRA engine version to use for this project.
ENGINE_VERSION="725f926b29e4b80b5572431c86c5a4e8f6c87a26"
ENGINE_VERSION="64c529d601001d4af12ef98f3fb21819af9082e9"

##############################################################################
# Packaging
Expand Down
1 change: 1 addition & 0 deletions mods/gen/chrome.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ lobby-bits:
admin-anonymous: 34, 51, 16, 16
player-registered: 17, 51, 16, 16
player-anonymous: 51, 51, 16, 16
bot: 170, 51, 16, 16

actor-stats-bits:
Image: staticons.png
Expand Down
12 changes: 6 additions & 6 deletions mods/gen/chrome/color-picker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ Background@COLOR_CHOOSER:
Width: 76
Height: 25
VisualHeight: 0
Text: Random
Text: button-color-chooser-random
Font: Bold
Button@STORE_BUTTON:
X: 245
Y: 124
Width: 76
Height: 25
VisualHeight: 0
Text: Store
Text: button-color-chooser-store
Font: Bold
ActorPreview@PREVIEW:
X: 245
Expand All @@ -35,15 +35,15 @@ Background@COLOR_CHOOSER:
Height: 25
Width: 80
VisualHeight: 0
Text: Mixer
Text: button-color-chooser-mixer-tab
Font: Bold
Button@PALETTE_TAB_BUTTON:
X: 85
Y: PARENT_BOTTOM - 30
Height: 25
Width: 80
VisualHeight: 0
Text: Palette
Text: button-color-chooser-palette-tab
Font: Bold
Container@MIXER_TAB:
X: 5
Expand Down Expand Up @@ -102,7 +102,7 @@ Background@COLOR_CHOOSER:
Width: PARENT_RIGHT
Height: 13
Align: Center
Text: Preset Colors
Text: label-preset-header
Container@PRESET_AREA:
Width: PARENT_RIGHT - 4
Height: 58
Expand All @@ -128,7 +128,7 @@ Background@COLOR_CHOOSER:
Width: PARENT_RIGHT
Height: 13
Align: Center
Text: Custom Colors
Text: label-custom-header
Container@CUSTOM_AREA:
Width: PARENT_RIGHT - 4
Height: 31
Expand Down
4 changes: 2 additions & 2 deletions mods/gen/chrome/gamesave-loading.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Container@GAMESAVE_LOADING_SCREEN:
Height: 25
Font: Bold
Align: Center
Text: Loading Saved Game
Text: label-gamesave-loading-screen-title
ProgressBar@PROGRESS:
X: (WINDOW_RIGHT - 500) / 2
Y: 3 * WINDOW_BOTTOM / 4
Expand All @@ -34,4 +34,4 @@ Container@GAMESAVE_LOADING_SCREEN:
Height: 25
Font: Regular
Align: Center
Text: Press Escape to cancel loading and return to the main menu
Text: label-gamesave-loading-screen-desc
14 changes: 6 additions & 8 deletions mods/gen/chrome/ingame-infostats.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Container@SKIRMISH_STATS:
Width: 482
Height: 25
Font: MediumBold
Text: Mission:
Text: label-objective-mission
Label@STATS_STATUS:
X: 100
Y: 22
Expand All @@ -25,7 +25,7 @@ Container@SKIRMISH_STATS:
Width: 482
Height: 20
Font: Bold
Text: Destroy all opposition!
Text: checkbox-objective-stats
Disabled: true
TextColorDisabled: FFFFFF
Container@STATS_HEADERS:
Expand All @@ -37,25 +37,25 @@ Container@SKIRMISH_STATS:
X: 10
Width: 210
Height: 25
Text: Player
Text: label-stats-player
Font: Bold
Label@FACTION:
X: 230
Width: 120
Height: 25
Text: Faction
Text: label-stats-faction
Font: Bold
Label@SCORE:
X: 397
Width: 60
Height: 25
Text: Score
Text: label-stats-score
Font: Bold
Label@ACTIONS:
X: 457
Width: 20
Height: 25
Text: Actions
Text: label-stats-actions
Font: Bold
ScrollPanel@PLAYER_LIST:
X: 20
Expand Down Expand Up @@ -137,7 +137,6 @@ Container@SKIRMISH_STATS:
VisualHeight: 0
Background: checkbox-toggle
TooltipContainer: TOOLTIP_CONTAINER
TooltipText: Kick this player
Children:
Image:
ImageCollection: lobby-bits
Expand Down Expand Up @@ -181,7 +180,6 @@ Container@SKIRMISH_STATS:
VisualHeight: 0
Background: checkbox-toggle
TooltipContainer: TOOLTIP_CONTAINER
TooltipText: Kick this player
Children:
Image:
ImageCollection: lobby-bits
Expand Down
Loading

0 comments on commit 6db3fbe

Please sign in to comment.