mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-02-06 22:37:22 +00:00
(svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
This commit is contained in:
parent
653290c76a
commit
147ca22060
@ -50,7 +50,7 @@ Station::Station(TileIndex tile)
|
|||||||
|
|
||||||
last_vehicle_type = VEH_Invalid;
|
last_vehicle_type = VEH_Invalid;
|
||||||
|
|
||||||
random_bits = Random();
|
random_bits = 0; // Random() must be called when station is really built (DC_EXEC)
|
||||||
waiting_triggers = 0;
|
waiting_triggers = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,6 +105,19 @@ void Station::operator delete(void *p, int st_idx)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Called when new facility is built on the station. If it is the first facility
|
||||||
|
* it initializes also 'xy' and 'random_bits' members */
|
||||||
|
void Station::AddFacility(byte new_facility_bit, TileIndex facil_xy)
|
||||||
|
{
|
||||||
|
if (facilities == 0) {
|
||||||
|
xy = facil_xy;
|
||||||
|
random_bits = Random();
|
||||||
|
}
|
||||||
|
facilities |= new_facility_bit;
|
||||||
|
owner = _current_player;
|
||||||
|
build_date = _date;
|
||||||
|
}
|
||||||
|
|
||||||
void Station::MarkDirty() const
|
void Station::MarkDirty() const
|
||||||
{
|
{
|
||||||
if (sign.width_1 != 0) {
|
if (sign.width_1 != 0) {
|
||||||
|
@ -159,6 +159,7 @@ struct Station {
|
|||||||
void* operator new (size_t size, int st_idx);
|
void* operator new (size_t size, int st_idx);
|
||||||
void operator delete(void *p, int st_idx);
|
void operator delete(void *p, int st_idx);
|
||||||
|
|
||||||
|
void AddFacility(byte new_facility_bit, TileIndex facil_xy);
|
||||||
void MarkDirty() const;
|
void MarkDirty() const;
|
||||||
void MarkTilesDirty() const;
|
void MarkTilesDirty() const;
|
||||||
bool TileBelongsToRailStation(TileIndex tile) const;
|
bool TileBelongsToRailStation(TileIndex tile) const;
|
||||||
|
@ -1000,15 +1000,11 @@ int32 CmdBuildRailroadStation(TileIndex tile_org, uint32 flags, uint32 p1, uint3
|
|||||||
if (CmdFailed(ret)) return ret;
|
if (CmdFailed(ret)) return ret;
|
||||||
|
|
||||||
st->train_tile = finalvalues[0];
|
st->train_tile = finalvalues[0];
|
||||||
if (!st->facilities) st->xy = finalvalues[0];
|
st->AddFacility(FACIL_TRAIN, finalvalues[0]);
|
||||||
st->facilities |= FACIL_TRAIN;
|
|
||||||
st->owner = _current_player;
|
|
||||||
|
|
||||||
st->trainst_w = finalvalues[1];
|
st->trainst_w = finalvalues[1];
|
||||||
st->trainst_h = finalvalues[2];
|
st->trainst_h = finalvalues[2];
|
||||||
|
|
||||||
st->build_date = _date;
|
|
||||||
|
|
||||||
st->rect.BeforeAddRect(tile_org, w_org, h_org, StationRect::ADD_TRY);
|
st->rect.BeforeAddRect(tile_org, w_org, h_org, StationRect::ADD_TRY);
|
||||||
|
|
||||||
tile_delta = (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
|
tile_delta = (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
|
||||||
@ -1415,11 +1411,7 @@ int32 CmdBuildRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||||||
|
|
||||||
//initialize an empty station
|
//initialize an empty station
|
||||||
road_stop->prev = prev;
|
road_stop->prev = prev;
|
||||||
if (!st->facilities) st->xy = tile;
|
st->AddFacility((type) ? FACIL_TRUCK_STOP : FACIL_BUS_STOP, tile);
|
||||||
st->facilities |= (type) ? FACIL_TRUCK_STOP : FACIL_BUS_STOP;
|
|
||||||
st->owner = _current_player;
|
|
||||||
|
|
||||||
st->build_date = _date;
|
|
||||||
|
|
||||||
st->rect.BeforeAddTile(tile, StationRect::ADD_TRY);
|
st->rect.BeforeAddTile(tile, StationRect::ADD_TRY);
|
||||||
|
|
||||||
@ -1674,15 +1666,11 @@ int32 CmdBuildAirport(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||||||
cost += _price.build_airport * w * h;
|
cost += _price.build_airport * w * h;
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
st->owner = _current_player;
|
|
||||||
st->airport_tile = tile;
|
st->airport_tile = tile;
|
||||||
if (!st->facilities) st->xy = tile;
|
st->AddFacility(FACIL_AIRPORT, tile);
|
||||||
st->facilities |= FACIL_AIRPORT;
|
|
||||||
st->airport_type = (byte)p1;
|
st->airport_type = (byte)p1;
|
||||||
st->airport_flags = 0;
|
st->airport_flags = 0;
|
||||||
|
|
||||||
st->build_date = _date;
|
|
||||||
|
|
||||||
st->rect.BeforeAddRect(tile, w, h, StationRect::ADD_TRY);
|
st->rect.BeforeAddRect(tile, w, h, StationRect::ADD_TRY);
|
||||||
|
|
||||||
/* if airport was demolished while planes were en-route to it, the
|
/* if airport was demolished while planes were en-route to it, the
|
||||||
@ -1953,11 +1941,7 @@ int32 CmdBuildDock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
st->dock_tile = tile;
|
st->dock_tile = tile;
|
||||||
if (!st->facilities) st->xy = tile;
|
st->AddFacility(FACIL_DOCK, tile);
|
||||||
st->facilities |= FACIL_DOCK;
|
|
||||||
st->owner = _current_player;
|
|
||||||
|
|
||||||
st->build_date = _date;
|
|
||||||
|
|
||||||
st->rect.BeforeAddRect(tile, _dock_w_chk[direction], _dock_h_chk[direction], StationRect::ADD_TRY);
|
st->rect.BeforeAddRect(tile, _dock_w_chk[direction], _dock_h_chk[direction], StationRect::ADD_TRY);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user