mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r12870) -Codechange: remove some magic numbers from u.ship.state handling
This commit is contained in:
parent
5ac07a2c34
commit
345f160978
|
@ -167,6 +167,22 @@ static inline DiagDirection AxisToDiagDir(Axis a)
|
||||||
return (DiagDirection)(2 - a);
|
return (DiagDirection)(2 - a);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts an Axis to a Direction
|
||||||
|
*
|
||||||
|
* This function returns the Direction which
|
||||||
|
* belongs to the axis. As 2 directions are mapped to an axis
|
||||||
|
* this function returns the one which points to south,
|
||||||
|
* either south-west (on X axis) or south-east (on Y axis)
|
||||||
|
*
|
||||||
|
* @param a The axis
|
||||||
|
* @return The direction pointed to south
|
||||||
|
*/
|
||||||
|
static inline Direction AxisToDirection(Axis a)
|
||||||
|
{
|
||||||
|
return (Direction)(5 - 2 * a);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert an axis and a flag for north/south into a DiagDirection
|
* Convert an axis and a flag for north/south into a DiagDirection
|
||||||
* @param xy axis to convert
|
* @param xy axis to convert
|
||||||
|
|
|
@ -38,7 +38,7 @@ struct Ship: public Vehicle {
|
||||||
int GetDisplaySpeed() const { return this->cur_speed * 10 / 32; }
|
int GetDisplaySpeed() const { return this->cur_speed * 10 / 32; }
|
||||||
int GetDisplayMaxSpeed() const { return this->max_speed * 10 / 32; }
|
int GetDisplayMaxSpeed() const { return this->max_speed * 10 / 32; }
|
||||||
Money GetRunningCost() const { return ShipVehInfo(this->engine_type)->running_cost * _price.ship_running; }
|
Money GetRunningCost() const { return ShipVehInfo(this->engine_type)->running_cost * _price.ship_running; }
|
||||||
bool IsInDepot() const { return this->u.ship.state == 0x80; }
|
bool IsInDepot() const { return this->u.ship.state == TRACK_BIT_DEPOT; }
|
||||||
void Tick();
|
void Tick();
|
||||||
void OnNewDay();
|
void OnNewDay();
|
||||||
TileIndex GetOrderStationLocation(StationID station);
|
TileIndex GetOrderStationLocation(StationID station);
|
||||||
|
|
|
@ -282,26 +282,22 @@ static const TileIndexDiffC _ship_leave_depot_offs[] = {
|
||||||
|
|
||||||
static void CheckShipLeaveDepot(Vehicle *v)
|
static void CheckShipLeaveDepot(Vehicle *v)
|
||||||
{
|
{
|
||||||
TileIndex tile;
|
|
||||||
Axis axis;
|
|
||||||
uint m;
|
|
||||||
|
|
||||||
if (!v->IsInDepot()) return;
|
if (!v->IsInDepot()) return;
|
||||||
|
|
||||||
tile = v->tile;
|
TileIndex tile = v->tile;
|
||||||
axis = GetShipDepotAxis(tile);
|
Axis axis = GetShipDepotAxis(tile);
|
||||||
|
|
||||||
/* Check first side */
|
/* Check first (north) side */
|
||||||
if (_ship_sometracks[axis] & GetTileShipTrackStatus(TILE_ADD(tile, ToTileIndexDiff(_ship_leave_depot_offs[axis])))) {
|
if (_ship_sometracks[axis] & GetTileShipTrackStatus(TILE_ADD(tile, ToTileIndexDiff(_ship_leave_depot_offs[axis])))) {
|
||||||
m = (axis == AXIS_X) ? 0x101 : 0x207;
|
v->direction = ReverseDir(AxisToDirection(axis));
|
||||||
/* Check second side */
|
/* Check second (south) side */
|
||||||
} else if (_ship_sometracks[axis + 2] & GetTileShipTrackStatus(TILE_ADD(tile, -2 * ToTileIndexDiff(_ship_leave_depot_offs[axis])))) {
|
} else if (_ship_sometracks[axis + 2] & GetTileShipTrackStatus(TILE_ADD(tile, -2 * ToTileIndexDiff(_ship_leave_depot_offs[axis])))) {
|
||||||
m = (axis == AXIS_X) ? 0x105 : 0x203;
|
v->direction = AxisToDirection(axis);
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
v->direction = (Direction)GB(m, 0, 8);
|
|
||||||
v->u.ship.state = (TrackBits)GB(m, 8, 8);
|
v->u.ship.state = AxisToTrackBits(axis);
|
||||||
v->vehstatus &= ~VS_HIDDEN;
|
v->vehstatus &= ~VS_HIDDEN;
|
||||||
|
|
||||||
v->cur_speed = 0;
|
v->cur_speed = 0;
|
||||||
|
|
Loading…
Reference in New Issue