(svn r17483) -Fix (r17405): when an aircraft starts flying in circles make it turn in the correct direction first before continuing

This commit is contained in:
yexo 2009-09-09 00:03:35 +00:00
parent 4924e4ffba
commit e2122dc7f0
3 changed files with 12 additions and 4 deletions

View File

@ -92,6 +92,7 @@ struct Aircraft : public SpecializedVehicle<Aircraft, VEH_AIRCRAFT> {
StationID targetairport; StationID targetairport;
byte state; byte state;
DirectionByte last_direction; DirectionByte last_direction;
byte number_consecutive_turns;
/** We don't want GCC to zero our struct! It already is zeroed and has an index! */ /** We don't want GCC to zero our struct! It already is zeroed and has an index! */
Aircraft() : SpecializedVehicle<Aircraft, VEH_AIRCRAFT>() {} Aircraft() : SpecializedVehicle<Aircraft, VEH_AIRCRAFT>() {}

View File

@ -1071,9 +1071,14 @@ static bool AircraftController(Aircraft *v)
/* Turn. Do it slowly if in the air. */ /* Turn. Do it slowly if in the air. */
Direction newdir = GetDirectionTowards(v, x + amd->x, y + amd->y); Direction newdir = GetDirectionTowards(v, x + amd->x, y + amd->y);
if (newdir != v->direction) { if (newdir != v->direction) {
if (amd->flag & AMED_SLOWTURN) { if (amd->flag & AMED_SLOWTURN && v->number_consecutive_turns < 8) {
if (v->load_unload_time_rem == 0 || newdir == v->last_direction) { if (v->load_unload_time_rem == 0 || newdir == v->last_direction) {
v->load_unload_time_rem = 1 << (_settings_game.vehicle.plane_speed - 1); if (newdir == v->last_direction) {
v->number_consecutive_turns = 0;
} else {
v->number_consecutive_turns++;
}
v->load_unload_time_rem = 2 * _settings_game.vehicle.plane_speed;
v->last_direction = v->direction; v->last_direction = v->direction;
v->direction = newdir; v->direction = newdir;
} }
@ -1094,6 +1099,7 @@ static bool AircraftController(Aircraft *v)
gp.new_tile = gp.old_tile = v->tile; gp.new_tile = gp.old_tile = v->tile;
} }
} else { } else {
v->number_consecutive_turns = 0;
/* Move vehicle. */ /* Move vehicle. */
gp = GetNewVehiclePos(v); gp = GetNewVehiclePos(v);
} }

View File

@ -592,9 +592,10 @@ const SaveLoad *GetVehicleDescription(VehicleType vt)
SLE_CONDVAR(Aircraft, previous_pos, SLE_UINT8, 2, SL_MAX_VERSION), SLE_CONDVAR(Aircraft, previous_pos, SLE_UINT8, 2, SL_MAX_VERSION),
SLE_CONDVAR(Aircraft, last_direction, SLE_UINT8, 2, SL_MAX_VERSION), SLE_CONDVAR(Aircraft, last_direction, SLE_UINT8, 2, SL_MAX_VERSION),
SLE_CONDVAR(Aircraft, number_consecutive_turns, SLE_UINT8, 2, SL_MAX_VERSION),
/* reserve extra space in savegame here. (currently 14 bytes) */ /* reserve extra space in savegame here. (currently 13 bytes) */
SLE_CONDNULL(14, 2, SL_MAX_VERSION), SLE_CONDNULL(13, 2, SL_MAX_VERSION),
SLE_END() SLE_END()
}; };