openttd updated to 1.5.0-beta2

--HG--
branch : openttd
This commit is contained in:
Pavel Stupnikov
2015-03-01 00:30:53 +03:00
parent 0abb47ce90
commit d201932121
682 changed files with 26103 additions and 16553 deletions

View File

@@ -1,4 +1,4 @@
/* $Id: afterload.cpp 26317 2014-02-07 23:48:56Z frosch $ */
/* $Id: afterload.cpp 27020 2014-10-15 18:31:37Z rubidium $ */
/*
* This file is part of OpenTTD.
@@ -51,13 +51,17 @@
#include "../core/backup_type.hpp"
#include "../smallmap_gui.h"
#include "../news_func.h"
#include "../order_backup.h"
#include "../error.h"
#include "../disaster_vehicle.h"
#include "saveload_internal.h"
#include <signal.h>
#include "../safeguards.h"
extern Company *DoStartupNewCompany(bool is_ai, CompanyID company = INVALID_COMPANY);
/**
@@ -501,6 +505,18 @@ static uint FixVehicleInclination(Vehicle *v, Direction dir)
return 1U << GVF_GOINGUP_BIT;
}
/**
* Checks for the possibility that a bridge may be on this tile
* These are in fact all the tile types on which a bridge can be found
* @param t The tile to analyze
* @return True if a bridge might have been present prior to savegame 194.
*/
static inline bool MayHaveBridgeAbove(TileIndex t)
{
return IsTileType(t, MP_CLEAR) || IsTileType(t, MP_RAILWAY) || IsTileType(t, MP_ROAD) ||
IsTileType(t, MP_WATER) || IsTileType(t, MP_TUNNELBRIDGE) || IsTileType(t, MP_OBJECT);
}
/**
* Perform a (large) amount of savegame conversion *magic* in order to
* load older savegames and to fill the caches for various purposes.
@@ -566,6 +582,23 @@ bool AfterLoadGame()
}
}
if (IsSavegameVersionBefore(194)) {
_settings_game.construction.max_heightlevel = 15;
/* In old savegame versions, the heightlevel was coded in bits 0..3 of the type field */
for (TileIndex t = 0; t < map_size; t++) {
_m[t].height = GB(_m[t].type, 0, 4);
SB(_m[t].type, 0, 2, GB(_me[t].m6, 0, 2));
SB(_me[t].m6, 0, 2, 0);
if (MayHaveBridgeAbove(t)) {
SB(_m[t].type, 2, 2, GB(_me[t].m6, 6, 2));
SB(_me[t].m6, 6, 2, 0);
} else {
SB(_m[t].type, 2, 2, 0);
}
}
}
/* in version 2.1 of the savegame, town owner was unified. */
if (IsSavegameVersionBefore(2, 1)) ConvertTownOwner();
@@ -791,7 +824,7 @@ bool AfterLoadGame()
break;
case MP_STATION: {
if (HasBit(_m[t].m6, 3)) SetBit(_m[t].m6, 2);
if (HasBit(_me[t].m6, 3)) SetBit(_me[t].m6, 2);
StationGfx gfx = GetStationGfx(t);
StationType st;
if ( IsInsideMM(gfx, 0, 8)) { // Rail station
@@ -829,7 +862,7 @@ bool AfterLoadGame()
ResetSignalHandlers();
return false;
}
SB(_m[t].m6, 3, 3, st);
SB(_me[t].m6, 3, 3, st);
break;
}
}
@@ -1003,7 +1036,7 @@ bool AfterLoadGame()
case ROAD_TILE_NORMAL:
SB(_m[t].m4, 0, 4, GB(_m[t].m5, 0, 4));
SB(_m[t].m4, 4, 4, 0);
SB(_m[t].m6, 2, 4, 0);
SB(_me[t].m6, 2, 4, 0);
break;
case ROAD_TILE_CROSSING:
SB(_m[t].m4, 5, 2, GB(_m[t].m5, 2, 2));
@@ -1042,19 +1075,19 @@ bool AfterLoadGame()
switch (GetRoadTileType(t)) {
default: SlErrorCorrupt("Invalid road tile type");
case ROAD_TILE_NORMAL:
SB(_me[t].m7, 0, 4, GB(_m[t].m3, 0, 4)); // road works
SB(_m[t].m6, 3, 3, GB(_m[t].m3, 4, 3)); // ground
SB(_m[t].m3, 0, 4, GB(_m[t].m4, 4, 4)); // tram bits
SB(_m[t].m3, 4, 4, GB(_m[t].m5, 0, 4)); // tram owner
SB(_m[t].m5, 0, 4, GB(_m[t].m4, 0, 4)); // road bits
SB(_me[t].m7, 0, 4, GB(_m[t].m3, 0, 4)); // road works
SB(_me[t].m6, 3, 3, GB(_m[t].m3, 4, 3)); // ground
SB(_m[t].m3, 0, 4, GB(_m[t].m4, 4, 4)); // tram bits
SB(_m[t].m3, 4, 4, GB(_m[t].m5, 0, 4)); // tram owner
SB(_m[t].m5, 0, 4, GB(_m[t].m4, 0, 4)); // road bits
break;
case ROAD_TILE_CROSSING:
SB(_me[t].m7, 0, 5, GB(_m[t].m4, 0, 5)); // road owner
SB(_m[t].m6, 3, 3, GB(_m[t].m3, 4, 3)); // ground
SB(_m[t].m3, 4, 4, GB(_m[t].m5, 0, 4)); // tram owner
SB(_m[t].m5, 0, 1, GB(_m[t].m4, 6, 1)); // road axis
SB(_m[t].m5, 5, 1, GB(_m[t].m4, 5, 1)); // crossing state
SB(_me[t].m7, 0, 5, GB(_m[t].m4, 0, 5)); // road owner
SB(_me[t].m6, 3, 3, GB(_m[t].m3, 4, 3)); // ground
SB(_m[t].m3, 4, 4, GB(_m[t].m5, 0, 4)); // tram owner
SB(_m[t].m5, 0, 1, GB(_m[t].m4, 6, 1)); // road axis
SB(_m[t].m5, 5, 1, GB(_m[t].m4, 5, 1)); // crossing state
break;
case ROAD_TILE_DEPOT:
@@ -1071,7 +1104,7 @@ bool AfterLoadGame()
if (!IsRoadStop(t)) break;
if (fix_roadtypes) SetRoadTypes(t, (RoadTypes)GB(_m[t].m3, 0, 3));
SB(_me[t].m7, 0, 5, HasBit(_m[t].m6, 2) ? OWNER_TOWN : GetTileOwner(t));
SB(_me[t].m7, 0, 5, HasBit(_me[t].m6, 2) ? OWNER_TOWN : GetTileOwner(t));
SB(_m[t].m3, 4, 4, _m[t].m1);
_m[t].m4 = 0;
break;
@@ -1085,7 +1118,7 @@ bool AfterLoadGame()
SB(_me[t].m7, 0, 5, o); // road owner
SB(_m[t].m3, 4, 4, o == OWNER_NONE ? OWNER_TOWN : o); // tram owner
}
SB(_m[t].m6, 2, 4, GB(_m[t].m2, 4, 4)); // bridge type
SB(_me[t].m6, 2, 4, GB(_m[t].m2, 4, 4)); // bridge type
SB(_me[t].m7, 5, 1, GB(_m[t].m4, 7, 1)); // snow/desert
_m[t].m2 = 0;
@@ -1597,7 +1630,7 @@ bool AfterLoadGame()
FOR_ALL_STATIONS(st) {
for (CargoID c = 0; c < NUM_CARGO; c++) {
st->goods[c].last_speed = 0;
if (st->goods[c].cargo.AvailableCount() != 0) SetBit(st->goods[c].acceptance_pickup, GoodsEntry::GES_PICKUP);
if (st->goods[c].cargo.AvailableCount() != 0) SetBit(st->goods[c].status, GoodsEntry::GES_RATING);
}
}
}
@@ -1819,7 +1852,7 @@ bool AfterLoadGame()
/* Increase HouseAnimationFrame from 5 to 7 bits */
for (TileIndex t = 0; t < map_size; t++) {
if (IsTileType(t, MP_HOUSE) && GetHouseType(t) >= NEW_HOUSE_OFFSET) {
SB(_m[t].m6, 2, 6, GB(_m[t].m6, 3, 5));
SB(_me[t].m6, 2, 6, GB(_me[t].m6, 3, 5));
SB(_m[t].m3, 5, 1, 0);
}
}
@@ -1976,7 +2009,7 @@ bool AfterLoadGame()
/* Reordering/generalisation of the object bits. */
ObjectType type = _m[t].m5;
SB(_m[t].m6, 2, 4, type == OBJECT_HQ ? GB(_m[t].m3, 2, 3) : 0);
SB(_me[t].m6, 2, 4, type == OBJECT_HQ ? GB(_m[t].m3, 2, 3) : 0);
_m[t].m3 = type == OBJECT_HQ ? GB(_m[t].m3, 1, 1) | GB(_m[t].m3, 0, 1) << 4 : 0;
/* Make sure those bits are clear as well! */
@@ -1997,8 +2030,8 @@ bool AfterLoadGame()
uint offset = _m[t].m3;
/* Also move the animation state. */
_m[t].m3 = GB(_m[t].m6, 2, 4);
SB(_m[t].m6, 2, 4, 0);
_m[t].m3 = GB(_me[t].m6, 2, 4);
SB(_me[t].m6, 2, 4, 0);
if (offset == 0) {
/* No offset, so make the object. */
@@ -2089,7 +2122,7 @@ bool AfterLoadGame()
/* Delete small ufos heading for non-existing vehicles */
Vehicle *v;
FOR_ALL_DISASTERVEHICLES(v) {
if (v->subtype == 2/*ST_SMALL_UFO*/ && v->current_order.GetDestination() != 0) {
if (v->subtype == 2 /* ST_SMALL_UFO */ && v->current_order.GetDestination() != 0) {
const Vehicle *u = Vehicle::GetIfValid(v->dest_tile);
if (u == NULL || u->type != VEH_ROAD || !RoadVehicle::From(u)->IsFrontEngine()) {
delete v;
@@ -2370,7 +2403,10 @@ bool AfterLoadGame()
UpdateAircraftCache(v);
AircraftNextAirportPos_and_Order(v);
/* get aircraft back on running altitude */
if ((v->vehstatus & VS_CRASHED) == 0) SetAircraftPosition(v, v->x_pos, v->y_pos, GetAircraftFlyingAltitude(v));
if ((v->vehstatus & VS_CRASHED) == 0) {
GetAircraftFlightLevelBounds(v, &v->z_pos, NULL);
SetAircraftPosition(v, v->x_pos, v->y_pos, GetAircraftFlightLevel(v));
}
}
}
}
@@ -2382,9 +2418,9 @@ bool AfterLoadGame()
case MP_HOUSE:
if (GetHouseType(t) >= NEW_HOUSE_OFFSET) {
uint per_proc = _me[t].m7;
_me[t].m7 = GB(_m[t].m6, 2, 6) | (GB(_m[t].m3, 5, 1) << 6);
_me[t].m7 = GB(_me[t].m6, 2, 6) | (GB(_m[t].m3, 5, 1) << 6);
SB(_m[t].m3, 5, 1, 0);
SB(_m[t].m6, 2, 6, min(per_proc, 63));
SB(_me[t].m6, 2, 6, min(per_proc, 63));
}
break;
@@ -2914,6 +2950,21 @@ bool AfterLoadGame()
}
}
/*
* Only keep order-backups for network clients.
* If we are a network server or not networking, then we just loaded a previously
* saved-by-server savegame. There are no clients with a backup, so clear it.
* Furthermore before savegame version 192 the actual content was always corrupt.
*/
if (!_networking || _network_server || IsSavegameVersionBefore(192)) {
/* Note: We cannot use CleanPool since that skips part of the destructor
* and then leaks un-reachable Orders in the order pool. */
OrderBackup *ob;
FOR_ALL_ORDER_BACKUPS(ob) {
delete ob;
}
}
/* Station acceptance is some kind of cache */
if (IsSavegameVersionBefore(127)) {