From 79a7bf75a0a1a7dcc04f019b3d44f7a8c012a652 Mon Sep 17 00:00:00 2001 From: rubidium Date: Fri, 22 Jun 2007 20:08:37 +0000 Subject: [PATCH] (svn r10279) [0.5] -Backport from trunk (r10139, r10153, r10154, r10155, r10165, r10187): - Fix: Do not make a 270 degree turn on the international airport when a 90 degree turn is enough (r10187) - Fix: Crash when trying to get the aircraft movement state of an aircraft going to a just deleted airport [FS#874] (r10165) - Fix: Airports did not flood when there are aircraft on the airport [FS#601] (r10155) - Fix: Some vehicles were not drawn when having a high resolution and a high zoom-out level [FS#870] (r10154) - Fix: Vehicles disappear when crossing certain tiles [FS#869] (r10153) - Fix: OpenTTD assumes that the resolution is at least 1 by 1, so force the resolution to be always at least 1 by 1 (r10139) --- airport_movement.h | 2 +- newgrf_engine.c | 2 ++ openttd.c | 5 +++++ vehicle.c | 28 ++++++++++++++++++++-------- water_cmd.c | 40 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 68 insertions(+), 9 deletions(-) diff --git a/airport_movement.h b/airport_movement.h index 32ed7c0ee4..44b3ab8139 100644 --- a/airport_movement.h +++ b/airport_movement.h @@ -180,7 +180,7 @@ static const AirportMovingData _airport_moving_data_international[51] = { { 193, 104, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 32 Fly to landing position in air { 105, 104, AMED_NOSPDCLAMP | AMED_LAND, 0 }, // 33 Going down for land { 3, 104, AMED_NOSPDCLAMP | AMED_BRAKE, 0 }, // 34 Just landed, brake until end of runway - { 12, 104, 0, 0 }, // 35 Just landed, turn around and taxi 1 square + { 12, 104, AMED_SLOWTURN, 0 }, // 35 Just landed, turn around and taxi 1 square { 7, 84, 0, 0 }, // 36 Taxi from runway to crossing { -31, 209, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 37 Fly around waiting for a landing spot (north-east) { 1, 6, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 38 Fly around waiting for a landing spot (north-west) diff --git a/newgrf_engine.c b/newgrf_engine.c index fe50259135..8604ed1e13 100644 --- a/newgrf_engine.c +++ b/newgrf_engine.c @@ -290,6 +290,8 @@ static byte MapAircraftMovementState(const Vehicle *v) const Station *st = GetStation(v->u.air.targetairport); byte amdflag = GetAirportMovingData(st->airport_type, v->u.air.pos)->flag; + if (st->airport_tile == 0) return AMS_TTDP_FLIGHT_TO_TOWER; + switch (v->u.air.state) { case HANGAR: /* The international airport is a special case as helicopters can land in diff --git a/openttd.c b/openttd.c index 9bb2ab9771..6d3dcfd849 100644 --- a/openttd.c +++ b/openttd.c @@ -419,6 +419,11 @@ int ttd_main(int argc, char *argv[]) if (startyear != INVALID_YEAR) _patches_newgame.starting_year = startyear; if (generation_seed != GENERATE_NEW_SEED) _patches_newgame.generation_seed = generation_seed; + /* The width and height must be at least 1 pixel, this + * way all internal drawing routines work correctly. */ + if (_cur_resolution[0] == 0) _cur_resolution[0] = 1; + if (_cur_resolution[1] == 0) _cur_resolution[1] = 1; + if (_dedicated_forks && !dedicated) _dedicated_forks = false; // enumerate language files diff --git a/vehicle.c b/vehicle.c index b5bac57c60..472e2d148a 100644 --- a/vehicle.c +++ b/vehicle.c @@ -36,7 +36,7 @@ #include "newgrf_engine.h" #include "newgrf_sound.h" -#define INVALID_COORD (-0x8000) +#define INVALID_COORD (0x7fffffff) #define GEN_HASH(x, y) ((GB((y), 6, 6) << 6) + GB((x), 7, 6)) /* @@ -823,17 +823,29 @@ void ViewportAddVehicles(DrawPixelInfo *dpi) const int b = dpi->top + dpi->height; // The hash area to scan - const int xl = GB(l - 70, 7, 6); - const int xu = GB(r, 7, 6); - const int yl = GB(t - 70, 6, 6) << 6; - const int yu = GB(b, 6, 6) << 6; + int xl, xu, yl, yu, x, y; - int x; - int y; + if (dpi->width + 70 < (1 << (7 + 6))) { + xl = GB(l - 70, 7, 6); + xu = GB(r, 7, 6); + } else { + /* scan whole hash row */ + xl = 0; + xu = 0x3F; + } + + if (dpi->height + 70 < (1 << (6 + 6))) { + yl = GB(t - 70, 6, 6) << 6; + yu = GB(b, 6, 6) << 6; + } else { + /* scan whole column */ + yl = 0; + yu = 0x3F << 6; + } for (y = yl;; y = (y + (1 << 6)) & (0x3F << 6)) { for (x = xl;; x = (x + 1) & 0x3F) { - VehicleID veh = _vehicle_position_hash[(x + y) & 0xFFFF]; + VehicleID veh = _vehicle_position_hash[x + y]; // already masked & 0xFFF while (veh != INVALID_VEHICLE) { const Vehicle* v = GetVehicle(veh); diff --git a/water_cmd.c b/water_cmd.c index 4314438f9d..9dad847a71 100644 --- a/water_cmd.c +++ b/water_cmd.c @@ -21,6 +21,7 @@ #include "water_map.h" #include "newgrf.h" #include "bridge.h" +#include "airport.h" const SpriteID _water_shore_sprites[15] = { 0, @@ -620,6 +621,26 @@ static Vehicle *FindFloodableVehicleOnTile(TileIndex tile) byte z; Vehicle *v; + if (IsTileType(tile, MP_STATION) && IsAirport(tile)) { + uint x, y; + const Station *st = GetStationByTile(tile); + const AirportFTAClass *airport = GetAirport(st->airport_type); + for (x = 0; x < airport->size_x; x++) { + for (y = 0; y < airport->size_y; y++) { + uint z = 1; + tile = TILE_ADDXY(st->airport_tile, x, y); + if (st->airport_type == AT_OILRIG) z += 54; + if (st->airport_type == AT_HELIPORT) z += 60; + + v = FindVehicleOnTileZ(tile, z); + if (v != NULL && (v->vehstatus & VS_CRASHED) == 0) return v; + } + } + + /* No vehicle could be flooded on this airport anymore */ + return NULL; + } + if (!IsBridgeTile(tile) || !IsBridgeRamp(tile)) return FindVehicleOnTileZ(tile, 0); end = GetOtherBridgeEnd(tile); @@ -668,6 +689,25 @@ static void FloodVehicle(Vehicle *v) v = u; v->u.rail.crash_anim_pos = 4000; // max 4440, disappear pretty fast RebuildVehicleLists(); + } else if (v->type == VEH_Aircraft) { + const Station *st; + const AirportFTAClass *airport; + uint z = 1; + + /* Crashing aircraft are always at z_pos == 1, never on z_pos == 0, + * because that's always the shadow. Except for the heliport, because + * that station has a big z_offset for the aircraft. */ + if (!IsTileType(v->tile, MP_STATION) || !IsAirport(v->tile) || GetTileMaxZ(v->tile) != 0) return; + st = GetStationByTile(v->tile); + airport = GetAirport(st->airport_type); + + if (st->airport_type == AT_OILRIG) z += 54; + if (st->airport_type == AT_HELIPORT) z += 60; + + if (v->z_pos != z) return; + + pass = 2; // driver + if (v->cargo_type == CT_PASSENGERS) pass += v->cargo_count; } else { return; }