3 /** @file oldloader.cpp */ |
3 /** @file oldloader.cpp */ |
4 |
4 |
5 #include "stdafx.h" |
5 #include "stdafx.h" |
6 #include "openttd.h" |
6 #include "openttd.h" |
7 #include "station_map.h" |
7 #include "station_map.h" |
8 #include "table/strings.h" |
|
9 #include "functions.h" |
|
10 #include "map.h" |
|
11 #include "town.h" |
8 #include "town.h" |
12 #include "industry.h" |
9 #include "industry.h" |
13 #include "station.h" |
10 #include "station.h" |
14 #include "economy.h" |
11 #include "player_func.h" |
15 #include "player.h" |
12 #include "player_base.h" |
16 #include "engine.h" |
13 #include "engine.h" |
17 #include "vehicle.h" |
|
18 #include "aircraft.h" |
14 #include "aircraft.h" |
19 #include "roadveh.h" |
15 #include "roadveh.h" |
20 #include "ship.h" |
16 #include "ship.h" |
21 #include "train.h" |
17 #include "train.h" |
22 #include "signs.h" |
18 #include "signs.h" |
23 #include "debug.h" |
19 #include "debug.h" |
24 #include "depot.h" |
20 #include "depot.h" |
25 #include "newgrf_config.h" |
21 #include "newgrf_config.h" |
26 #include "ai/ai.h" |
22 #include "ai/ai.h" |
27 #include "date.h" |
23 #include "ai/default/default.h" |
|
24 #include "zoom_func.h" |
|
25 #include "functions.h" |
|
26 #include "date_func.h" |
|
27 #include "vehicle_func.h" |
|
28 #include "variables.h" |
|
29 |
|
30 #include "table/strings.h" |
28 |
31 |
29 enum { |
32 enum { |
30 HEADER_SIZE = 49, |
33 HEADER_SIZE = 49, |
31 BUFFER_SIZE = 4096, |
34 BUFFER_SIZE = 4096, |
32 |
35 |
809 static bool OldLoadAIBuildRec(LoadgameState *ls, int num) |
812 static bool OldLoadAIBuildRec(LoadgameState *ls, int num) |
810 { |
813 { |
811 Player *p = GetPlayer(_current_player_id); |
814 Player *p = GetPlayer(_current_player_id); |
812 |
815 |
813 switch (num) { |
816 switch (num) { |
814 case 0: return LoadChunk(ls, &p->ai.src, player_ai_build_rec_chunk); |
817 case 0: return LoadChunk(ls, &_players_ai[p->index].src, player_ai_build_rec_chunk); |
815 case 1: return LoadChunk(ls, &p->ai.dst, player_ai_build_rec_chunk); |
818 case 1: return LoadChunk(ls, &_players_ai[p->index].dst, player_ai_build_rec_chunk); |
816 case 2: return LoadChunk(ls, &p->ai.mid1, player_ai_build_rec_chunk); |
819 case 2: return LoadChunk(ls, &_players_ai[p->index].mid1, player_ai_build_rec_chunk); |
817 case 3: return LoadChunk(ls, &p->ai.mid2, player_ai_build_rec_chunk); |
820 case 3: return LoadChunk(ls, &_players_ai[p->index].mid2, player_ai_build_rec_chunk); |
818 } |
821 } |
819 |
822 |
820 return false; |
823 return false; |
821 } |
824 } |
822 static const OldChunks player_ai_chunk[] = { |
825 static const OldChunks player_ai_chunk[] = { |
922 OCL_END() |
925 OCL_END() |
923 }; |
926 }; |
924 |
927 |
925 static bool OldPlayerAI(LoadgameState *ls, int num) |
928 static bool OldPlayerAI(LoadgameState *ls, int num) |
926 { |
929 { |
927 Player *p = GetPlayer(_current_player_id); |
930 return LoadChunk(ls, &_players_ai[_current_player_id], player_ai_chunk); |
928 |
931 } |
929 return LoadChunk(ls, &p->ai, player_ai_chunk); |
932 |
930 } |
933 uint8 ai_tick; |
931 |
|
932 static const OldChunks player_chunk[] = { |
934 static const OldChunks player_chunk[] = { |
933 OCL_VAR ( OC_UINT16, 1, &_old_string_id ), |
935 OCL_VAR ( OC_UINT16, 1, &_old_string_id ), |
934 OCL_SVAR( OC_UINT32, Player, name_2 ), |
936 OCL_SVAR( OC_UINT32, Player, name_2 ), |
935 OCL_SVAR( OC_UINT32, Player, face ), |
937 OCL_SVAR( OC_UINT32, Player, face ), |
936 OCL_VAR ( OC_UINT16, 1, &_old_string_id_2 ), |
938 OCL_VAR ( OC_UINT16, 1, &_old_string_id_2 ), |
956 OCL_SVAR( OC_UINT8, Player, num_valid_stat_ent ), |
958 OCL_SVAR( OC_UINT8, Player, num_valid_stat_ent ), |
957 |
959 |
958 OCL_CHUNK( 1, OldPlayerAI ), |
960 OCL_CHUNK( 1, OldPlayerAI ), |
959 |
961 |
960 OCL_SVAR( OC_UINT8, Player, block_preview ), |
962 OCL_SVAR( OC_UINT8, Player, block_preview ), |
961 OCL_SVAR( OC_UINT8, Player, ai.tick ), |
963 OCL_VAR( OC_UINT8, 1, &ai_tick ), |
962 OCL_SVAR( OC_UINT8, Player, avail_railtypes ), |
964 OCL_SVAR( OC_UINT8, Player, avail_railtypes ), |
963 OCL_SVAR( OC_TILE, Player, location_of_house ), |
965 OCL_SVAR( OC_TILE, Player, location_of_house ), |
964 OCL_SVAR( OC_UINT8, Player, share_owners[0] ), |
966 OCL_SVAR( OC_UINT8, Player, share_owners[0] ), |
965 OCL_SVAR( OC_UINT8, Player, share_owners[1] ), |
967 OCL_SVAR( OC_UINT8, Player, share_owners[1] ), |
966 OCL_SVAR( OC_UINT8, Player, share_owners[2] ), |
968 OCL_SVAR( OC_UINT8, Player, share_owners[2] ), |
980 if (!LoadChunk(ls, p, player_chunk)) return false; |
982 if (!LoadChunk(ls, p, player_chunk)) return false; |
981 |
983 |
982 p->name_1 = RemapOldStringID(_old_string_id); |
984 p->name_1 = RemapOldStringID(_old_string_id); |
983 p->president_name_1 = RemapOldStringID(_old_string_id_2); |
985 p->president_name_1 = RemapOldStringID(_old_string_id_2); |
984 p->player_money = p->player_money; |
986 p->player_money = p->player_money; |
|
987 _players_ai[_current_player_id].tick = ai_tick; |
985 |
988 |
986 if (num == 0) { |
989 if (num == 0) { |
987 /* If the first player has no name, make sure we call it UNNAMED */ |
990 /* If the first player has no name, make sure we call it UNNAMED */ |
988 if (p->name_1 == 0) |
991 if (p->name_1 == 0) |
989 p->name_1 = STR_SV_UNNAMED; |
992 p->name_1 = STR_SV_UNNAMED; |
1005 p->inaugurated_year -= ORIGINAL_BASE_YEAR; |
1008 p->inaugurated_year -= ORIGINAL_BASE_YEAR; |
1006 if (p->location_of_house == 0xFFFF) |
1009 if (p->location_of_house == 0xFFFF) |
1007 p->location_of_house = 0; |
1010 p->location_of_house = 0; |
1008 |
1011 |
1009 /* State 20 for AI players is sell vehicle. Since the AI struct is not |
1012 /* State 20 for AI players is sell vehicle. Since the AI struct is not |
1010 * really figured out as of now, p->ai.cur_veh; needed for 'sell vehicle' |
1013 * really figured out as of now, _players_ai[p->index].cur_veh; needed for 'sell vehicle' |
1011 * is NULL and the function will crash. To fix this, just change the state |
1014 * is NULL and the function will crash. To fix this, just change the state |
1012 * to some harmless state, like 'loop vehicle'; 1 */ |
1015 * to some harmless state, like 'loop vehicle'; 1 */ |
1013 if (!IsHumanPlayer((PlayerID)num) && p->ai.state == 20) p->ai.state = 1; |
1016 if (!IsHumanPlayer((PlayerID)num) && _players_ai[p->index].state == 20) _players_ai[p->index].state = 1; |
1014 |
1017 |
1015 if (p->is_ai && (!_networking || _network_server) && _ai.enabled) |
1018 if (p->is_ai && (!_networking || _network_server) && _ai.enabled) |
1016 AI_StartNewAI(p->index); |
1019 AI_StartNewAI(p->index); |
1017 |
1020 |
1018 return true; |
1021 return true; |
1231 default: v->spritenum >>= 1; break; |
1234 default: v->spritenum >>= 1; break; |
1232 } |
1235 } |
1233 |
1236 |
1234 if (_old_next_ptr != 0xFFFF) v->next = GetVehiclePoolSize() <= _old_next_ptr ? new (_old_next_ptr) InvalidVehicle() : GetVehicle(_old_next_ptr); |
1237 if (_old_next_ptr != 0xFFFF) v->next = GetVehiclePoolSize() <= _old_next_ptr ? new (_old_next_ptr) InvalidVehicle() : GetVehicle(_old_next_ptr); |
1235 |
1238 |
1236 v->string_id = RemapOldStringID(_old_string_id); |
1239 _old_string_id = RemapOldStringID(_old_string_id); |
|
1240 v->name = CopyFromOldName(_old_string_id); |
1237 |
1241 |
1238 /* Vehicle-subtype is different in TTD(Patch) */ |
1242 /* Vehicle-subtype is different in TTD(Patch) */ |
1239 if (v->type == VEH_SPECIAL) v->subtype = v->subtype >> 1; |
1243 if (v->type == VEH_SPECIAL) v->subtype = v->subtype >> 1; |
1240 |
1244 |
1241 if (_cargo_count != 0) { |
1245 if (_cargo_count != 0) { |
1247 |
1251 |
1248 return true; |
1252 return true; |
1249 } |
1253 } |
1250 |
1254 |
1251 static const OldChunks sign_chunk[] = { |
1255 static const OldChunks sign_chunk[] = { |
1252 OCL_SVAR( OC_UINT16, Sign, str ), |
1256 OCL_VAR ( OC_UINT16, 1, &_old_string_id ), |
1253 OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, Sign, x ), |
1257 OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, Sign, x ), |
1254 OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, Sign, y ), |
1258 OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, Sign, y ), |
1255 OCL_SVAR( OC_FILE_U16 | OC_VAR_I8, Sign, z ), |
1259 OCL_SVAR( OC_FILE_U16 | OC_VAR_I8, Sign, z ), |
1256 |
1260 |
1257 OCL_NULL( 6 ), ///< Width of sign, no longer in use |
1261 OCL_NULL( 6 ), ///< Width of sign, no longer in use |
1259 OCL_END() |
1263 OCL_END() |
1260 }; |
1264 }; |
1261 |
1265 |
1262 static bool LoadOldSign(LoadgameState *ls, int num) |
1266 static bool LoadOldSign(LoadgameState *ls, int num) |
1263 { |
1267 { |
1264 return LoadChunk(ls, new (num) Sign(), sign_chunk); |
1268 Sign *si = new (num) Sign(); |
|
1269 if (!LoadChunk(ls, si, sign_chunk)) return false; |
|
1270 |
|
1271 _old_string_id = RemapOldStringID(_old_string_id); |
|
1272 si->name = CopyFromOldName(_old_string_id); |
|
1273 |
|
1274 return true; |
1265 } |
1275 } |
1266 |
1276 |
1267 static const OldChunks engine_chunk[] = { |
1277 static const OldChunks engine_chunk[] = { |
1268 OCL_SVAR( OC_UINT16, Engine, player_avail ), |
1278 OCL_SVAR( OC_UINT16, Engine, player_avail ), |
1269 OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Engine, intro_date ), |
1279 OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Engine, intro_date ), |
1293 |
1303 |
1294 /* Make sure wagons are marked as do-not-age */ |
1304 /* Make sure wagons are marked as do-not-age */ |
1295 if ((num >= 27 && num < 54) || (num >= 57 && num < 84) || (num >= 89 && num < 116)) |
1305 if ((num >= 27 && num < 54) || (num >= 57 && num < 84) || (num >= 89 && num < 116)) |
1296 GetEngine(num)->age = 0xFFFF; |
1306 GetEngine(num)->age = 0xFFFF; |
1297 |
1307 |
|
1308 return true; |
|
1309 } |
|
1310 |
|
1311 static bool LoadOldEngineName(LoadgameState *ls, int num) |
|
1312 { |
|
1313 Engine *e = GetEngine(num); |
|
1314 e->name = CopyFromOldName(RemapOldStringID(ReadUint16(ls))); |
1298 return true; |
1315 return true; |
1299 } |
1316 } |
1300 |
1317 |
1301 static const OldChunks subsidy_chunk[] = { |
1318 static const OldChunks subsidy_chunk[] = { |
1302 OCL_SVAR( OC_UINT8, Subsidy, cargo_type ), |
1319 OCL_SVAR( OC_UINT8, Subsidy, cargo_type ), |
1502 |
1519 |
1503 OCL_VAR ( OC_UINT16, 1, &_disaster_delay ), |
1520 OCL_VAR ( OC_UINT16, 1, &_disaster_delay ), |
1504 |
1521 |
1505 OCL_NULL( 144 ), ///< cargo-stuff, calculated in InitializeLandscapeVariables |
1522 OCL_NULL( 144 ), ///< cargo-stuff, calculated in InitializeLandscapeVariables |
1506 |
1523 |
1507 OCL_VAR ( OC_UINT16, 256, &_engine_name_strings[0] ), |
1524 OCL_CHUNK(256, LoadOldEngineName ), |
1508 |
1525 |
1509 OCL_NULL( 144 ), ///< AI cargo-stuff, calculated in InitializeLandscapeVariables |
1526 OCL_NULL( 144 ), ///< AI cargo-stuff, calculated in InitializeLandscapeVariables |
1510 OCL_NULL( 2 ), ///< Company indexes of players, no longer in use |
1527 OCL_NULL( 2 ), ///< Company indexes of players, no longer in use |
1511 |
1528 |
1512 OCL_VAR ( OC_FILE_U8 | OC_VAR_U16, 1, &_station_tick_ctr ), |
1529 OCL_VAR ( OC_FILE_U8 | OC_VAR_U16, 1, &_station_tick_ctr ), |
1620 /* Make sure the available engines are really available, otherwise |
1637 /* Make sure the available engines are really available, otherwise |
1621 * we will get a "new vehicle"-spree. */ |
1638 * we will get a "new vehicle"-spree. */ |
1622 for (Engine *e = _engines; e != endof(_engines); e++) { |
1639 for (Engine *e = _engines; e != endof(_engines); e++) { |
1623 if (_date >= (e->intro_date + 365)) { |
1640 if (_date >= (e->intro_date + 365)) { |
1624 e->flags = (e->flags & ~ENGINE_EXCLUSIVE_PREVIEW) | ENGINE_AVAILABLE; |
1641 e->flags = (e->flags & ~ENGINE_EXCLUSIVE_PREVIEW) | ENGINE_AVAILABLE; |
1625 AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type); |
|
1626 e->player_avail = (byte)-1; |
1642 e->player_avail = (byte)-1; |
1627 } |
1643 } |
1628 } |
1644 } |
1629 |
1645 |
1630 /* Fix the game to be compatible with OpenTTD */ |
1646 /* Fix the game to be compatible with OpenTTD */ |
1631 FixOldTowns(); |
1647 FixOldTowns(); |
1632 FixOldStations(); |
1648 FixOldStations(); |
1633 FixOldVehicles(); |
1649 FixOldVehicles(); |
1634 |
1650 |
1635 AddTypeToEngines(); |
|
1636 |
|
1637 /* We have a new difficulty setting */ |
1651 /* We have a new difficulty setting */ |
1638 _opt.diff.town_council_tolerance = Clamp(_opt.diff_level, 0, 2); |
1652 _opt.diff.town_council_tolerance = Clamp(_opt.diff_level, 0, 2); |
1639 |
1653 |
1640 DEBUG(oldloader, 3, "Finished converting game data"); |
1654 DEBUG(oldloader, 3, "Finished converting game data"); |
1641 DEBUG(oldloader, 1, "TTD(Patch) savegame successfully converted"); |
1655 DEBUG(oldloader, 1, "TTD(Patch) savegame successfully converted"); |