Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/MapEditorLibrary/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,16 @@ public static class Constants
public const string VeinholeMonsterTypeName = "VEINHOLE";
public const string VeinholeDummyTypeName = "VEINHOLEDUMMY";

public const int MultiplayerMaxPlayers = 8;
/// <summary>
/// The number of starting waypoints the original games support.
/// </summary>
public const int OriginalMultiplayerMaxPlayers = 8;

/// <summary>
/// The most players the target game supports on one map.
/// Above 8, a map can set [Basic] MaxPlayers= to use more starting waypoints.
/// </summary>
public static int MultiplayerMaxPlayers = OriginalMultiplayerMaxPlayers;

public const int TS_WAYPT_SPECIAL = 100;

Expand Down Expand Up @@ -175,6 +184,8 @@ public static void Init()
IntegerVariables = constantsIni.GetBooleanValue(ConstantsSectionName, nameof(IntegerVariables), IntegerVariables);

MaxWaypoint = constantsIni.GetIntValue(ConstantsSectionName, nameof(MaxWaypoint), MaxWaypoint);
MultiplayerMaxPlayers = Math.Clamp(constantsIni.GetIntValue(ConstantsSectionName, nameof(MultiplayerMaxPlayers), MultiplayerMaxPlayers),
OriginalMultiplayerMaxPlayers, MaxWaypoint);

MapPreviewMaxWidth = constantsIni.GetIntValue(ConstantsSectionName, nameof(MapPreviewMaxWidth), MapPreviewMaxWidth);
MapPreviewMaxHeight = constantsIni.GetIntValue(ConstantsSectionName, nameof(MapPreviewMaxHeight), MapPreviewMaxHeight);
Expand Down
3 changes: 2 additions & 1 deletion src/MapEditorLibrary/Initialization/MapWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public static void WriteBasicSection(IMap map, IniFile mapIni)

if (string.IsNullOrWhiteSpace(map.Basic.Player))
{
map.Basic.MaxPlayer = map.Waypoints.Count(wp => wp.Identifier < Constants.MultiplayerMaxPlayers);
int startCount = map.Basic.GetMultiplayerStartCount();
map.Basic.MaxPlayer = map.Waypoints.Count(wp => wp.Identifier < startCount);
}

map.Basic.WritePropertiesToIniSection(section);
Expand Down
24 changes: 24 additions & 0 deletions src/MapEditorLibrary/Misc/MapIssueChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,30 @@ public static List<string> CheckForIssues(Map map)
Constants.TS_WAYPT_SPECIAL));
}

// A map for more than 8 players needs a starting waypoint for every player.
// Waypoints that were ordinary waypoints on an 8-player map become starting waypoints.
int startCount = map.Basic.GetMultiplayerStartCount();
if (startCount > Constants.OriginalMultiplayerMaxPlayers)
{
var missingStarts = Enumerable.Range(0, startCount).Where(i => !map.Waypoints.Exists(wp => wp.Identifier == i)).ToList();
if (missingStarts.Count > 0)
{
issueList.Add(string.Format(Translate(map, "CheckForIssues.MissingStartingWaypoints",
"The map sets MaxPlayers to {0}, but starting waypoints {1} are missing. Every player needs a starting waypoint from #0 to #{2}, or the game treats the map as a map for up to 8 players."),
startCount, string.Join(", ", missingStarts.Select(i => "#" + i)), startCount - 1));
}

foreach (var waypoint in map.Waypoints.Where(wp => wp.Identifier >= Constants.OriginalMultiplayerMaxPlayers && wp.Identifier < startCount))
{
if (map.IsWaypointInUse(waypoint))
{
issueList.Add(string.Format(Translate(map, "CheckForIssues.TriggerWaypointIsStartingWaypoint",
"Waypoint #{0} is used by triggers, scripts or TeamTypes, and it is also a starting waypoint because MaxPlayers is {1}. If it is meant as an ordinary waypoint, move it to #{1} or higher."),
waypoint.Identifier, startCount));
}
}
}

// Check for scripts that have more than 50 Script Actions. This is unsupported by the game.
const int maxScriptActionCount = 50;
foreach (var script in map.Scripts)
Expand Down
14 changes: 14 additions & 0 deletions src/MapEditorLibrary/Models/BasicSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class BasicSection : INIDefineable
public bool EndOfGame { get; set; }
public bool FreeRadar { get; set; }
public int MaxPlayer { get; set; } = 8;
public int? MaxPlayers { get; set; }
public int MinPlayer { get; set; } = 2;
public bool SkipScore { get; set; }
public bool TrainCrate { get; set; }
Expand All @@ -37,4 +38,17 @@ public class BasicSection : INIDefineable
public bool TiberiumGrowthEnabled { get; set; } = true;
public bool IgnoreGlobalAITriggers { get; set; }
public bool TiberiumDeathToVisceroid { get; set; }

/// <summary>
/// Returns how many waypoints, counting from 0, are multiplayer starting waypoints.
/// That is 8, unless the target game supports more players
/// and the map asks for more with MaxPlayers.
/// </summary>
public int GetMultiplayerStartCount()
{
if (MaxPlayers > Constants.OriginalMultiplayerMaxPlayers && MaxPlayers <= Constants.MultiplayerMaxPlayers)
return MaxPlayers.Value;

return Constants.OriginalMultiplayerMaxPlayers;
}
}
6 changes: 3 additions & 3 deletions src/MapEditorMCP/Infos/CellInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static CellInfo FromMapCell(Map map, MapTile mapTile)
var vehicleInfos = mapTile.Vehicles.Select(v => (MapFootInfo)FromTechno(map, v));
var infantryInfos = mapTile.Infantry.Where(i => i != null).Select(i => (MapFootInfo)FromTechno(map, i));
var aircraftInfos = mapTile.Aircraft.Select(a => (MapFootInfo)FromTechno(map, a));
var waypointInfos = mapTile.Waypoints.OrderBy(waypoint => waypoint.Identifier).Select(FromWaypoint).ToList();
var waypointInfos = mapTile.Waypoints.OrderBy(waypoint => waypoint.Identifier).Select(waypoint => FromWaypoint(map, waypoint)).ToList();

var tileInfo = theater.GetTile(mapTile.TileIndex);
var subTileInfo = tileInfo.GetSubTile(mapTile.SubTileIndex);
Expand All @@ -80,14 +80,14 @@ public static CellInfo FromMapCell(Map map, MapTile mapTile)
vehicleInfos.Concat(infantryInfos).Concat(aircraftInfos).ToList(), waypointInfos);
}

public static MapWaypointInfo FromWaypoint(Waypoint waypoint)
public static MapWaypointInfo FromWaypoint(Map map, Waypoint waypoint)
{
return new MapWaypointInfo(
waypoint.Identifier,
waypoint.Position.X,
waypoint.Position.Y,
waypoint.EditorColor,
waypoint.Identifier >= 0 && waypoint.Identifier < Constants.MultiplayerMaxPlayers);
waypoint.Identifier >= 0 && waypoint.Identifier < map.Basic.GetMultiplayerStartCount());
}

public static MapTechnoInfo FromTechno(Map map, TechnoBase techno)
Expand Down
2 changes: 1 addition & 1 deletion src/MapEditorMCP/MapFacade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ public List<MapWaypointInfo> GetWaypoints(int? identifier = null)
return map.Waypoints
.Where(waypoint => !identifier.HasValue || waypoint.Identifier == identifier.Value)
.OrderBy(waypoint => waypoint.Identifier)
.Select(CellInfo.FromWaypoint)
.Select(waypoint => CellInfo.FromWaypoint(map, waypoint))
.ToList();
}

Expand Down
5 changes: 5 additions & 0 deletions src/TSMapEditor/Config/Default/Constants.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ TileColorBufferSize=576
; 100 in vanilla TS.
MaxWaypoint=702

; The most players the target game supports on one map. 8 in the original games.
; When above 8, the Basic options let a map set MaxPlayers= to that many players,
; and waypoints 0 to MaxPlayers - 1 are treated as multiplayer starting waypoints.
MultiplayerMaxPlayers=8

; Determines how many pixels should the editor looks outside of the screen for objects to be drawn.
; Some padding is necessary so large objects whose origin cell is just outside of the screen
; are rendered, for example so that huge trees don't disappear instantly when their origin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ $CC25=chkGrowingIce:XNACheckBox
$CC26=chkTiberiumDeathToVisceroid:XNACheckBox
$CC27=chkFreeRadar:XNACheckBox
$CC28=chkRequiredAddOn:XNACheckBox
$CC29=btnApply:EditorButton
$CC29=tbMaxPlayers:EditorNumberTextBox
$CC30=lblMaxPlayers:XNALabel
$CC31=btnApply:EditorButton
$Height=getBottom(btnApply) + EMPTY_SPACE_BOTTOM
HasCloseButton=true

Expand Down Expand Up @@ -191,11 +193,22 @@ $Y=getBottom(chkFreeRadar) + VERTICAL_SPACING
$Text=translate(Enhanced Mode)
$Enabled=1 - IS_RA2YR

; Shown only when the game's Constants.ini sets MultiplayerMaxPlayers above 8
[tbMaxPlayers]
$X=getX(chkIgnoreGlobalAITriggers) + 150
$Width=150
$Y=getBottom(chkRequiredAddOn) + VERTICAL_SPACING

[lblMaxPlayers]
$X=getX(chkIgnoreGlobalAITriggers)
$Y=getY(tbMaxPlayers) + 1
$Text=translate(Max Players:)

; Apply button

[btnApply]
$Width=120
$X=(getWidth(BasicSectionConfigWindow) - getWidth(btnApply)) / 2
$Y=getBottom(chkSkipMapSelect) + EMPTY_SPACE_TOP
$Y=max(getBottom(chkSkipMapSelect), getBottom(tbMaxPlayers)) + EMPTY_SPACE_TOP
$Text=translate(Apply)

3 changes: 3 additions & 0 deletions src/TSMapEditor/Config/Translations/en/Translation_en.ini
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ Map.CheckForIssues.InvalidTriggerActionTeamType=Trigger '{0}' has a nonexistent
Map.CheckForIssues.InvalidTriggerActionHouse=Trigger '{0}' has a nonexistent HouseType specified as a parameter for one or more of its actions.
Map.CheckForIssues.InvalidTriggerOwner=Trigger '{0}' has a nonexistent HouseType specified as its owner.
Map.CheckForIssues.TriggerTooManyActions=Trigger '{0}' has more than {1} actions! This can cause the game to crash! Consider splitting it up to multiple triggers.
Map.CheckForIssues.MissingStartingWaypoints=The map sets MaxPlayers to {0}, but starting waypoints {1} are missing. Every player needs a starting waypoint from #0 to #{2}, or the game treats the map as a map for up to 8 players.
Map.CheckForIssues.TriggerWaypointIsStartingWaypoint=Waypoint #{0} is used by triggers, scripts or TeamTypes, and it is also a starting waypoint because MaxPlayers is {1}. If it is meant as an ordinary waypoint, move it to #{1} or higher.
Map.CheckForIssues.SpecialWaypointUsed=The map makes use of waypoint #{0}. In Tiberian Sun, this waypoint is reserved for special use cases (WAYPT_SPECIAL). Using it as a normal waypoint may cause issues as it may be dynamically moved by game events.
Map.CheckForAITriggerTeamWithMaxZeroIssue.TeamTypeMax=Team '{0}', linked to AITrigger '{1}', has Max=0. This prevents the AI from building the team.
Map.CheckForIssues.MismatchedDifficultyForEnableTrigger=The trigger "{0}" has "{1}" as its difficulty level, but it enables a trigger "{2}" which has "{3}" as its difficulty.
Expand Down Expand Up @@ -643,6 +645,7 @@ BasicSectionConfigWindow.chkGrowingIce.Text=Growing Ice
BasicSectionConfigWindow.chkTiberiumDeathToVisceroid.Text=Visceroid From Death In Tiberium
BasicSectionConfigWindow.chkFreeRadar.Text=Free Radar
BasicSectionConfigWindow.chkRequiredAddOn.Text=Enhanced Mode
BasicSectionConfigWindow.lblMaxPlayers.Text=Max Players:
BasicSectionConfigWindow.btnApply.Text=Apply

ChangeHeightWindow.lblDescription.Text=$$$TextBlockBegin$$$
Expand Down
4 changes: 3 additions & 1 deletion src/TSMapEditor/Rendering/MapView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2280,7 +2280,9 @@ private void InstantRenderMegamap(MegamapRenderOptions megamapRenderOptions)
{
Renderer.PushRenderTarget(compositeRenderTarget);

for (int i = 0; i < Constants.MultiplayerMaxPlayers; i++)
int startCount = Map.Basic.GetMultiplayerStartCount();

for (int i = 0; i < startCount; i++)
{
var wp = Map.Waypoints.Find(wp => wp.Identifier == i);
if (wp != null)
Expand Down
17 changes: 17 additions & 0 deletions src/TSMapEditor/UI/Windows/BasicSectionConfigWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public BasicSectionConfigWindow(WindowManager windowManager, Map map) : base(win
private XNACheckBox chkTiberiumDeathToVisceroid;
private XNACheckBox chkFreeRadar;
private XNACheckBox chkRequiredAddOn;
private EditorNumberTextBox tbMaxPlayers;

private SelectThemeWindow selectThemeWindow;

Expand Down Expand Up @@ -76,6 +77,13 @@ public override void Initialize()
chkFreeRadar = FindChild<XNACheckBox>(nameof(chkFreeRadar));
chkRequiredAddOn = FindChild<XNACheckBox>(nameof(chkRequiredAddOn));

// Only games that support more than 8 players need the player count set by hand
tbMaxPlayers = FindChild<EditorNumberTextBox>(nameof(tbMaxPlayers));
tbMaxPlayers.MaximumTextLength = Constants.MultiplayerMaxPlayers.ToString(CultureInfo.InvariantCulture).Length;
bool supportsMorePlayers = Constants.MultiplayerMaxPlayers > Constants.OriginalMultiplayerMaxPlayers;
tbMaxPlayers.Visible = supportsMorePlayers;
FindChild<XNALabel>("lblMaxPlayers").Visible = supportsMorePlayers;

selectThemeWindow = new SelectThemeWindow(WindowManager, map, true);
var themeDarkeningPanel = DarkeningPanel.InitializeAndAddToParentControlWithChild(WindowManager, Parent, selectThemeWindow);
themeDarkeningPanel.Hidden += ThemeDarkeningPanel_Hidden;
Expand Down Expand Up @@ -114,6 +122,7 @@ public void Open()
chkTiberiumDeathToVisceroid.Checked = map.Basic.TiberiumDeathToVisceroid;
chkFreeRadar.Checked = map.Basic.FreeRadar;
chkRequiredAddOn.Checked = map.Basic.RequiredAddOn > 0;
tbMaxPlayers.Text = map.Basic.MaxPlayers?.ToString(CultureInfo.InvariantCulture) ?? string.Empty;
}

private void BtnApply_LeftClick(object sender, System.EventArgs e)
Expand Down Expand Up @@ -145,6 +154,14 @@ private void BtnApply_LeftClick(object sender, System.EventArgs e)
{
map.Basic.RequiredAddOn = chkRequiredAddOn.Checked ? 1 : 0;
}

if (tbMaxPlayers.Visible)
{
if (string.IsNullOrWhiteSpace(tbMaxPlayers.Text))
map.Basic.MaxPlayers = null;
else
map.Basic.MaxPlayers = Math.Clamp(tbMaxPlayers.Value, 0, Constants.MultiplayerMaxPlayers);
}
}

private void ThemeDarkeningPanel_Hidden(object sender, EventArgs e)
Expand Down
2 changes: 1 addition & 1 deletion src/TSMapEditor/UI/Windows/PlaceWaypointWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public int GetAvailableWaypointNumber()
return -1;
}

for (int i = chkDoNotSuggestMPStartingWaypoints.Checked ? Constants.MultiplayerMaxPlayers : 0; i < Constants.MaxWaypoint; i++)
for (int i = chkDoNotSuggestMPStartingWaypoints.Checked ? map.Basic.GetMultiplayerStartCount() : 0; i < Constants.MaxWaypoint; i++)
{
if (!map.Waypoints.Exists(w => w.Identifier == i) && (Constants.IsRA2YR || i != Constants.TS_WAYPT_SPECIAL))
{
Expand Down