Merge tag '14.0-beta3' into jgrpp

# Conflicts:
#	regression/regression/result.txt
#	src/industrytype.h
#	src/network/core/config.h
#	src/network/core/network_game_info.cpp
#	src/network/core/network_game_info.h
#	src/network/core/packet.cpp
#	src/network/core/packet.h
#	src/network/core/tcp.cpp
#	src/network/core/tcp.h
#	src/network/core/tcp_admin.cpp
#	src/network/core/tcp_content.cpp
#	src/network/core/tcp_coordinator.cpp
#	src/network/core/tcp_game.cpp
#	src/network/core/tcp_game.h
#	src/network/core/tcp_turn.cpp
#	src/network/core/udp.cpp
#	src/network/core/udp.h
#	src/network/network_admin.cpp
#	src/network/network_client.cpp
#	src/network/network_client.h
#	src/network/network_command.cpp
#	src/network/network_content.cpp
#	src/network/network_internal.h
#	src/network/network_query.cpp
#	src/network/network_query.h
#	src/network/network_server.cpp
#	src/network/network_server.h
#	src/network/network_turn.cpp
#	src/network/network_udp.cpp
#	src/rail_gui.cpp
#	src/road_gui.cpp
This commit is contained in:
Jonathan G Rennison
2024-02-19 17:57:05 +00:00
67 changed files with 1463 additions and 1297 deletions

View File

@@ -2426,7 +2426,7 @@ static ChangeInfoResult TownHouseChangeInfo(uint hid, int numinfo, int prop, con
* in the temperate climate. */
CargoID cid = housespec->accepts_cargo[2];
if (!IsValidCargoID(cid)) cid = GetCargoIDByLabel(housespec->accepts_cargo_label[2]);
if (!IsValidCargoID(cid) || !CargoSpec::Get(cid)->IsValid()) {
if (!IsValidCargoID(cid)) {
housespec->cargo_acceptance[2] = 0;
}
}
@@ -2466,7 +2466,7 @@ static ChangeInfoResult TownHouseChangeInfo(uint hid, int numinfo, int prop, con
((_settings_game.game_creation.landscape == LT_TOYLAND) ? GetCargoIDByLabel(CT_FIZZY_DRINKS) : GetCargoIDByLabel(CT_FOOD));
/* Make sure the cargo type is valid in this climate. */
if (!CargoSpec::Get(cid)->IsValid()) goods = 0;
if (!IsValidCargoID(cid)) goods = 0;
housespec->accepts_cargo[2] = cid;
housespec->accepts_cargo_label[2] = CT_INVALID;
@@ -10613,6 +10613,38 @@ GRFFile::~GRFFile()
delete[] this->language_map;
}
/**
* Find first cargo label that exists and is active from a list of cargo labels.
* @param labels List of cargo labels.
* @returns First cargo label in list that exists, or CT_INVALID if none exist.
*/
static CargoLabel GetActiveCargoLabel(const std::initializer_list<CargoLabel> &labels)
{
for (const CargoLabel &label : labels) {
CargoID cid = GetCargoIDByLabel(label);
if (cid != INVALID_CARGO) return label;
}
return CT_INVALID;
}
/**
* Get active cargo label from either a cargo label or climate-dependent mixed cargo type.
* @param label Cargo label or climate-dependent mixed cargo type.
* @returns Active cargo label, or CT_INVALID if cargo label is not active.
*/
static CargoLabel GetActiveCargoLabel(const std::variant<CargoLabel, MixedCargoType> &label)
{
if (std::holds_alternative<CargoLabel>(label)) return std::get<CargoLabel>(label);
if (std::holds_alternative<MixedCargoType>(label)) {
switch (std::get<MixedCargoType>(label)) {
case MCT_LIVESTOCK_FRUIT: return GetActiveCargoLabel({CT_LIVESTOCK, CT_FRUIT});
case MCT_GRAIN_WHEAT_MAIZE: return GetActiveCargoLabel({CT_GRAIN, CT_WHEAT, CT_MAIZE});
case MCT_VALUABLES_GOLD_DIAMONDS: return GetActiveCargoLabel({CT_VALUABLES, CT_GOLD, CT_DIAMONDS});
default: NOT_REACHED();
}
}
NOT_REACHED();
}
/**
* Precalculate refit masks from cargo classes for all vehicles.
@@ -10631,7 +10663,7 @@ static void CalculateRefitMasks()
/* Apply default cargo translation map if cargo type hasn't been set, either explicitly or by aircraft cargo handling. */
if (!IsValidCargoID(e->info.cargo_type)) {
e->info.cargo_type = GetCargoIDByLabel(e->info.cargo_label);
e->info.cargo_type = GetCargoIDByLabel(GetActiveCargoLabel(e->info.cargo_label));
}
/* If the NewGRF did not set any cargo properties, we apply default values. */
@@ -10668,7 +10700,8 @@ static void CalculateRefitMasks()
_gted[engine].cargo_allowed = CC_PASSENGERS | CC_MAIL | CC_ARMOURED | CC_EXPRESS;
_gted[engine].cargo_disallowed = CC_LIQUID;
} else if (e->type == VEH_SHIP) {
switch (ei->cargo_label.base()) {
CargoLabel label = GetActiveCargoLabel(ei->cargo_label);
switch (label.base()) {
case CT_PASSENGERS.base():
/* Ferries */
_gted[engine].cargo_allowed = CC_PASSENGERS;
@@ -10699,9 +10732,10 @@ static void CalculateRefitMasks()
_gted[engine].cargo_disallowed = 0;
} else {
/* Train wagons and road vehicles are classified by their default cargo type */
CargoLabel label = GetActiveCargoLabel(ei->cargo_label);
for (const auto &drm : _default_refit_masks) {
if (!HasBit(drm.climate, _settings_game.game_creation.landscape)) continue;
if (drm.cargo_label != ei->cargo_label) continue;
if (drm.cargo_label != label) continue;
_gted[engine].cargo_allowed = drm.cargo_allowed;
_gted[engine].cargo_disallowed = drm.cargo_disallowed;
@@ -11097,17 +11131,17 @@ static void FinaliseIndustriesArray()
/* Apply default cargo translation map for unset cargo slots */
for (uint i = 0; i < lengthof(indsp.produced_cargo); ++i) {
if (!IsValidCargoID(indsp.produced_cargo[i])) indsp.produced_cargo[i] = GetCargoIDByLabel(indsp.produced_cargo_label[i]);
if (!IsValidCargoID(indsp.produced_cargo[i])) indsp.produced_cargo[i] = GetCargoIDByLabel(GetActiveCargoLabel(indsp.produced_cargo_label[i]));
}
for (uint i = 0; i < lengthof(indsp.accepts_cargo); ++i) {
if (!IsValidCargoID(indsp.accepts_cargo[i])) indsp.accepts_cargo[i] = GetCargoIDByLabel(indsp.accepts_cargo_label[i]);
if (!IsValidCargoID(indsp.accepts_cargo[i])) indsp.accepts_cargo[i] = GetCargoIDByLabel(GetActiveCargoLabel(indsp.accepts_cargo_label[i]));
}
}
for (auto &indtsp : _industry_tile_specs) {
/* Apply default cargo translation map for unset cargo slots */
for (uint i = 0; i < lengthof(indtsp.accepts_cargo); ++i) {
if (!IsValidCargoID(indtsp.accepts_cargo[i])) indtsp.accepts_cargo[i] = GetCargoIDByLabel(indtsp.accepts_cargo_label[i]);
if (!IsValidCargoID(indtsp.accepts_cargo[i])) indtsp.accepts_cargo[i] = GetCargoIDByLabel(GetActiveCargoLabel(indtsp.accepts_cargo_label[i]));
}
}
}