mirror of https://github.com/OpenTTD/OpenTTD
Change: Make ships stop and change direction slowly instead of instantly turning.
parent
479f13fc41
commit
225790892d
|
@ -273,8 +273,9 @@
|
||||||
* 201 #6885 Extend NewGRF persistant storages.
|
* 201 #6885 Extend NewGRF persistant storages.
|
||||||
* 202 #6867 Increase industry cargo slots to 16 in, 16 out
|
* 202 #6867 Increase industry cargo slots to 16 in, 16 out
|
||||||
* 203 #7072 Add path cache for ships
|
* 203 #7072 Add path cache for ships
|
||||||
|
* 204 #7065 Add extra rotation stages for ships.
|
||||||
*/
|
*/
|
||||||
extern const uint16 SAVEGAME_VERSION = 203; ///< Current savegame version of OpenTTD.
|
extern const uint16 SAVEGAME_VERSION = 204; ///< Current savegame version of OpenTTD.
|
||||||
|
|
||||||
SavegameType _savegame_type; ///< type of savegame we are loading
|
SavegameType _savegame_type; ///< type of savegame we are loading
|
||||||
FileToSaveLoad _file_to_saveload; ///< File to save or load in the openttd loop.
|
FileToSaveLoad _file_to_saveload; ///< File to save or load in the openttd loop.
|
||||||
|
|
|
@ -368,6 +368,14 @@ void AfterLoadVehicles(bool part_of_load)
|
||||||
v->SetServiceIntervalIsPercent(c->settings.vehicle.servint_ispercent);
|
v->SetServiceIntervalIsPercent(c->settings.vehicle.servint_ispercent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (IsSavegameVersionBefore(204)) {
|
||||||
|
/* Ship rotation added */
|
||||||
|
Ship *s;
|
||||||
|
FOR_ALL_SHIPS(s) {
|
||||||
|
s->rotation = s->direction;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckValidVehicles();
|
CheckValidVehicles();
|
||||||
|
@ -753,8 +761,9 @@ const SaveLoad *GetVehicleDescription(VehicleType vt)
|
||||||
static const SaveLoad _ship_desc[] = {
|
static const SaveLoad _ship_desc[] = {
|
||||||
SLE_WRITEBYTE(Vehicle, type, VEH_SHIP),
|
SLE_WRITEBYTE(Vehicle, type, VEH_SHIP),
|
||||||
SLE_VEH_INCLUDE(),
|
SLE_VEH_INCLUDE(),
|
||||||
SLE_VAR(Ship, state, SLE_UINT8),
|
SLE_VAR(Ship, state, SLE_UINT8),
|
||||||
SLE_CONDDEQUE(Ship, path, SLE_UINT8, 203, SL_MAX_VERSION),
|
SLE_CONDDEQUE(Ship, path, SLE_UINT8, 203, SL_MAX_VERSION),
|
||||||
|
SLE_CONDVAR(Ship, rotation, SLE_UINT8, 204, SL_MAX_VERSION),
|
||||||
|
|
||||||
SLE_CONDNULL(16, 2, 143), // old reserved space
|
SLE_CONDNULL(16, 2, 143), // old reserved space
|
||||||
|
|
||||||
|
|
|
@ -26,8 +26,9 @@ typedef std::deque<TrackdirByte> ShipPathCache;
|
||||||
* All ships have this type.
|
* All ships have this type.
|
||||||
*/
|
*/
|
||||||
struct Ship FINAL : public SpecializedVehicle<Ship, VEH_SHIP> {
|
struct Ship FINAL : public SpecializedVehicle<Ship, VEH_SHIP> {
|
||||||
TrackBitsByte state; ///< The "track" the ship is following.
|
TrackBitsByte state; ///< The "track" the ship is following.
|
||||||
ShipPathCache path; ///< Cached path.
|
ShipPathCache path; ///< Cached path.
|
||||||
|
DirectionByte rotation; ///< Visible direction.
|
||||||
|
|
||||||
/** 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! */
|
||||||
Ship() : SpecializedVehicleBase() {}
|
Ship() : SpecializedVehicleBase() {}
|
||||||
|
|
|
@ -129,6 +129,8 @@ void Ship::GetImage(Direction direction, EngineImageType image_type, VehicleSpri
|
||||||
{
|
{
|
||||||
uint8 spritenum = this->spritenum;
|
uint8 spritenum = this->spritenum;
|
||||||
|
|
||||||
|
if (image_type == EIT_ON_MAP) direction = this->rotation;
|
||||||
|
|
||||||
if (is_custom_sprite(spritenum)) {
|
if (is_custom_sprite(spritenum)) {
|
||||||
GetCustomVehicleSprite(this, direction, image_type, result);
|
GetCustomVehicleSprite(this, direction, image_type, result);
|
||||||
if (result->IsValid()) return;
|
if (result->IsValid()) return;
|
||||||
|
@ -311,7 +313,7 @@ void Ship::UpdateDeltaXY()
|
||||||
{32, 6, -16, -3}, // NW
|
{32, 6, -16, -3}, // NW
|
||||||
};
|
};
|
||||||
|
|
||||||
const int8 *bb = _delta_xy_table[this->direction];
|
const int8 *bb = _delta_xy_table[this->rotation];
|
||||||
this->x_offs = bb[3];
|
this->x_offs = bb[3];
|
||||||
this->y_offs = bb[2];
|
this->y_offs = bb[2];
|
||||||
this->x_extent = bb[1];
|
this->x_extent = bb[1];
|
||||||
|
@ -370,10 +372,10 @@ static bool CheckShipLeaveDepot(Ship *v)
|
||||||
|
|
||||||
if (north_tracks) {
|
if (north_tracks) {
|
||||||
/* Leave towards north */
|
/* Leave towards north */
|
||||||
v->direction = DiagDirToDir(north_dir);
|
v->rotation = v->direction = DiagDirToDir(north_dir);
|
||||||
} else if (south_tracks) {
|
} else if (south_tracks) {
|
||||||
/* Leave towards south */
|
/* Leave towards south */
|
||||||
v->direction = DiagDirToDir(south_dir);
|
v->rotation = v->direction = DiagDirToDir(south_dir);
|
||||||
} else {
|
} else {
|
||||||
/* Both ways blocked */
|
/* Both ways blocked */
|
||||||
return false;
|
return false;
|
||||||
|
@ -543,7 +545,6 @@ static void ShipController(Ship *v)
|
||||||
{
|
{
|
||||||
uint32 r;
|
uint32 r;
|
||||||
const byte *b;
|
const byte *b;
|
||||||
Direction dir;
|
|
||||||
Track track;
|
Track track;
|
||||||
TrackBits tracks;
|
TrackBits tracks;
|
||||||
|
|
||||||
|
@ -563,6 +564,16 @@ static void ShipController(Ship *v)
|
||||||
|
|
||||||
v->ShowVisualEffect();
|
v->ShowVisualEffect();
|
||||||
|
|
||||||
|
/* Rotating on spot */
|
||||||
|
if (v->direction != v->rotation) {
|
||||||
|
if ((v->tick_counter & 7) == 0) {
|
||||||
|
DirDiff diff = DirDifference(v->direction, v->rotation);
|
||||||
|
v->rotation = ChangeDir(v->rotation, diff > DIRDIFF_REVERSE ? DIRDIFF_45LEFT : DIRDIFF_45RIGHT);
|
||||||
|
v->UpdateViewport(true, true);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!ShipAccelerate(v)) return;
|
if (!ShipAccelerate(v)) return;
|
||||||
|
|
||||||
GetNewVehiclePosResult gp = GetNewVehiclePos(v);
|
GetNewVehiclePosResult gp = GetNewVehiclePos(v);
|
||||||
|
@ -653,7 +664,22 @@ static void ShipController(Ship *v)
|
||||||
if (old_wc != new_wc) v->UpdateCache();
|
if (old_wc != new_wc) v->UpdateCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
v->direction = (Direction)b[2];
|
Direction new_direction = (Direction)b[2];
|
||||||
|
DirDiff diff = DirDifference(new_direction, v->direction);
|
||||||
|
switch (diff) {
|
||||||
|
case DIRDIFF_SAME:
|
||||||
|
case DIRDIFF_45RIGHT:
|
||||||
|
case DIRDIFF_45LEFT:
|
||||||
|
/* Continue at speed */
|
||||||
|
v->rotation = v->direction = new_direction;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
/* Stop for rotation */
|
||||||
|
v->cur_speed = 0;
|
||||||
|
v->direction = new_direction;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* On a bridge */
|
/* On a bridge */
|
||||||
|
@ -677,8 +703,8 @@ getout:
|
||||||
return;
|
return;
|
||||||
|
|
||||||
reverse_direction:
|
reverse_direction:
|
||||||
dir = ReverseDir(v->direction);
|
v->direction = ReverseDir(v->direction);
|
||||||
v->direction = dir;
|
v->cur_speed = 0;
|
||||||
v->path.clear();
|
v->path.clear();
|
||||||
goto getout;
|
goto getout;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue