Merge branch 'master' into jgrpp

# Conflicts:
#	.github/workflows/release-linux.yml
#	.github/workflows/release.yml
#	src/rail_cmd.cpp
#	src/rail_gui.cpp
#	src/script/api/script_rail.cpp
#	src/settings_gui.cpp
#	src/signal_type.h
#	src/video/sdl2_v.cpp
This commit is contained in:
Jonathan G Rennison
2024-01-16 00:38:56 +00:00
88 changed files with 417 additions and 131 deletions

View File

@@ -44,8 +44,6 @@ static bool _read_ttdpatch_flags; ///< Have we (tried to) read TTDPatch extra
static uint16_t _old_extra_chunk_nums; ///< Number of extra TTDPatch chunks
static byte _old_vehicle_multiplier; ///< TTDPatch vehicle multiplier
static uint8_t *_old_map3;
void FixOldMapArray()
{
/* TTO/TTD/TTDP savegames could have buoys at tile 0
@@ -55,12 +53,6 @@ void FixOldMapArray()
static void FixTTDMapArray()
{
/* _old_map3 is moved to _m::m3 and _m::m4 */
for (TileIndex t = 0; t < OLD_MAP_SIZE; t++) {
_m[t].m3 = _old_map3[t * 2];
_m[t].m4 = _old_map3[t * 2 + 1];
}
for (TileIndex t = 0; t < OLD_MAP_SIZE; t++) {
switch (GetTileType(t)) {
case MP_STATION:
@@ -495,6 +487,20 @@ static uint32_t _old_town_index;
static uint16_t _old_string_id;
static uint16_t _old_string_id_2;
static void ClearOldMap3(TileIndex t)
{
_m[t].m3 = 0;
_m[t].m4 = 0;
}
static Town *RemapTown(TileIndex fallback)
{
/* In some cases depots, industries and stations could refer to a missing town. */
Town *t = Town::GetIfValid(RemapTownIndex(_old_town_index));
if (t == nullptr) t = CalcClosestTownFromTile(fallback);
return t;
}
static void ReadTTDPatchFlags()
{
if (_read_ttdpatch_flags) return;
@@ -510,7 +516,7 @@ static void ReadTTDPatchFlags()
if (_savegame_type == SGT_TTO) return;
/* TTDPatch misuses _old_map3 for flags.. read them! */
_old_vehicle_multiplier = _old_map3[0];
_old_vehicle_multiplier = _m[0].m3;
/* Somehow.... there was an error in some savegames, so 0 becomes 1
* and 1 becomes 2. The rest of the values are okay */
if (_old_vehicle_multiplier < 2) _old_vehicle_multiplier++;
@@ -524,18 +530,25 @@ static void ReadTTDPatchFlags()
* 1 vehicle == 128 bytes */
_bump_assert_value = (_old_vehicle_multiplier - 1) * 850 * 128;
for (uint i = 0; i < 17; i++) { // check tile 0, too
if (_old_map3[i] != 0) _savegame_type = SGT_TTDP1;
/* The first 17 bytes are used by TTDP1, which translates to the first 9 m3s and first 8 m4s. */
for (TileIndex i = 0; i <= 8; i++) { // check tile 0, too
if (_m[i].m3 != 0 || (i != 8 && _m[i].m4 != 0)) _savegame_type = SGT_TTDP1;
}
/* Check if we have a modern TTDPatch savegame (has extra data all around) */
if (memcmp(&_old_map3[0x1FFFA], "TTDp", 4) == 0) _savegame_type = SGT_TTDP2;
TileIndex ttdp2_header_first = MapSize() - 3;
TileIndex ttdp2_header_second = MapSize() - 2;
if (_m[ttdp2_header_first].m3 == 'T' && _m[ttdp2_header_first].m4 == 'T' &&
_m[ttdp2_header_second].m3 == 'D' && _m[ttdp2_header_second].m4 == 'p') {
_savegame_type = SGT_TTDP2;
}
_old_extra_chunk_nums = _old_map3[_savegame_type == SGT_TTDP2 ? 0x1FFFE : 0x2];
TileIndex extra_chunk_tile = _savegame_type == SGT_TTDP2 ? MapSize() - 1 : 1;
_old_extra_chunk_nums = _m[extra_chunk_tile].m3 | (_m[extra_chunk_tile].m4 << 8);
/* Clean the misused places */
for (uint i = 0; i < 17; i++) _old_map3[i] = 0;
for (uint i = 0x1FE00; i < 0x20000; i++) _old_map3[i] = 0;
for (TileIndex i = 0; i < 9; i++) ClearOldMap3(i);
for (TileIndex i = TileXY(0, MapMaxY()); i < MapSize(); i++) ClearOldMap3(i);
if (_savegame_type == SGT_TTDP2) DEBUG(oldloader, 2, "Found TTDPatch game");
@@ -666,10 +679,7 @@ static bool LoadOldDepot(LoadgameState *ls, int num)
if (!LoadChunk(ls, d, depot_chunk)) return false;
if (d->xy != 0) {
/* In some cases, there could be depots referencing invalid town. */
Town *t = Town::GetIfValid(RemapTownIndex(_old_town_index));
if (t == nullptr) t = Town::GetRandom();
d->town = t;
d->town = RemapTown(d->xy);
} else {
delete d;
}
@@ -759,7 +769,7 @@ static bool LoadOldStation(LoadgameState *ls, int num)
if (!LoadChunk(ls, st, station_chunk)) return false;
if (st->xy != 0) {
st->town = Town::Get(RemapTownIndex(_old_town_index));
st->town = RemapTown(st->xy);
if (_savegame_type == SGT_TTO) {
if (IsInsideBS(_old_string_id, 0x180F, 32)) {
@@ -836,7 +846,7 @@ static bool LoadOldIndustry(LoadgameState *ls, int num)
if (!LoadChunk(ls, i, industry_chunk)) return false;
if (i->location.tile != 0) {
i->town = Town::Get(RemapTownIndex(_old_town_index));
i->town = RemapTown(i->location.tile);
if (_savegame_type == SGT_TTO) {
if (i->type > 0x06) i->type++; // Printing Works were added
@@ -1487,9 +1497,10 @@ static bool LoadOldMapPart1(LoadgameState *ls, int)
}
if (_savegame_type != SGT_TTO) {
/* old map3 is split into to m3 and m4 */
for (uint i = 0; i < OLD_MAP_SIZE; i++) {
_old_map3[i * 2] = ReadByte(ls);
_old_map3[i * 2 + 1] = ReadByte(ls);
_m[i].m3 = ReadByte(ls);
_m[i].m4 = ReadByte(ls);
}
for (uint i = 0; i < OLD_MAP_SIZE / 4; i++) {
byte b = ReadByte(ls);
@@ -1756,8 +1767,6 @@ bool LoadTTDMain(LoadgameState *ls)
_read_ttdpatch_flags = false;
/* Load the biggest chunk */
std::array<byte, OLD_MAP_SIZE * 2> map3;
_old_map3 = map3.data();
_old_vehicle_names = nullptr;
try {
if (!LoadChunk(ls, nullptr, main_chunk)) {