mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-07 06:39:08 +00:00
(svn r10984) -Codechange: unify the way one can get the current speed in the same forwat so we can display it.
This commit is contained in:
parent
a83ccad6bd
commit
a5b32d8d72
@ -137,6 +137,7 @@ struct Aircraft : public Vehicle {
|
|||||||
WindowClass GetVehicleListWindowClass() const { return WC_AIRCRAFT_LIST; }
|
WindowClass GetVehicleListWindowClass() const { return WC_AIRCRAFT_LIST; }
|
||||||
bool IsPrimaryVehicle() const { return IsNormalAircraft(this); }
|
bool IsPrimaryVehicle() const { return IsNormalAircraft(this); }
|
||||||
int GetImage(Direction direction) const;
|
int GetImage(Direction direction) const;
|
||||||
|
int GetDisplaySpeed() const { return this->cur_speed * 10 / 16; }
|
||||||
void Tick();
|
void Tick();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -283,14 +283,14 @@ static void AircraftViewWndProc(Window *w, WindowEvent *e)
|
|||||||
switch (v->current_order.type) {
|
switch (v->current_order.type) {
|
||||||
case OT_GOTO_STATION: {
|
case OT_GOTO_STATION: {
|
||||||
SetDParam(0, v->current_order.dest);
|
SetDParam(0, v->current_order.dest);
|
||||||
SetDParam(1, v->cur_speed * 10 / 16);
|
SetDParam(1, v->GetDisplaySpeed());
|
||||||
str = STR_HEADING_FOR_STATION + _patches.vehicle_speed;
|
str = STR_HEADING_FOR_STATION + _patches.vehicle_speed;
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case OT_GOTO_DEPOT: {
|
case OT_GOTO_DEPOT: {
|
||||||
/* Aircrafts always go to a station, even if you say depot */
|
/* Aircrafts always go to a station, even if you say depot */
|
||||||
SetDParam(0, v->current_order.dest);
|
SetDParam(0, v->current_order.dest);
|
||||||
SetDParam(1, v->cur_speed * 10 / 16);
|
SetDParam(1, v->GetDisplaySpeed());
|
||||||
if (HASBIT(v->current_order.flags, OFB_HALT_IN_DEPOT) && !HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS)) {
|
if (HASBIT(v->current_order.flags, OFB_HALT_IN_DEPOT) && !HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS)) {
|
||||||
str = STR_HEADING_FOR_HANGAR + _patches.vehicle_speed;
|
str = STR_HEADING_FOR_HANGAR + _patches.vehicle_speed;
|
||||||
} else {
|
} else {
|
||||||
@ -305,7 +305,7 @@ static void AircraftViewWndProc(Window *w, WindowEvent *e)
|
|||||||
default:
|
default:
|
||||||
if (v->num_orders == 0) {
|
if (v->num_orders == 0) {
|
||||||
str = STR_NO_ORDERS + _patches.vehicle_speed;
|
str = STR_NO_ORDERS + _patches.vehicle_speed;
|
||||||
SetDParam(0, v->cur_speed * 10 / 16);
|
SetDParam(0, v->GetDisplaySpeed());
|
||||||
} else {
|
} else {
|
||||||
str = STR_EMPTY;
|
str = STR_EMPTY;
|
||||||
}
|
}
|
||||||
|
@ -82,6 +82,7 @@ struct RoadVehicle : public Vehicle {
|
|||||||
bool IsPrimaryVehicle() const { return IsRoadVehFront(this); }
|
bool IsPrimaryVehicle() const { return IsRoadVehFront(this); }
|
||||||
bool HasFront() const { return true; }
|
bool HasFront() const { return true; }
|
||||||
int GetImage(Direction direction) const;
|
int GetImage(Direction direction) const;
|
||||||
|
int GetDisplaySpeed() const { return this->cur_speed * 10 / 32; }
|
||||||
void Tick();
|
void Tick();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -297,14 +297,14 @@ static void RoadVehViewWndProc(Window *w, WindowEvent *e)
|
|||||||
switch (v->current_order.type) {
|
switch (v->current_order.type) {
|
||||||
case OT_GOTO_STATION: {
|
case OT_GOTO_STATION: {
|
||||||
SetDParam(0, v->current_order.dest);
|
SetDParam(0, v->current_order.dest);
|
||||||
SetDParam(1, v->cur_speed * 10 / 32);
|
SetDParam(1, v->GetDisplaySpeed());
|
||||||
str = STR_HEADING_FOR_STATION + _patches.vehicle_speed;
|
str = STR_HEADING_FOR_STATION + _patches.vehicle_speed;
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case OT_GOTO_DEPOT: {
|
case OT_GOTO_DEPOT: {
|
||||||
Depot *depot = GetDepot(v->current_order.dest);
|
Depot *depot = GetDepot(v->current_order.dest);
|
||||||
SetDParam(0, depot->town_index);
|
SetDParam(0, depot->town_index);
|
||||||
SetDParam(1, v->cur_speed * 10 / 32);
|
SetDParam(1, v->GetDisplaySpeed());
|
||||||
if (HASBIT(v->current_order.flags, OFB_HALT_IN_DEPOT) && !HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS)) {
|
if (HASBIT(v->current_order.flags, OFB_HALT_IN_DEPOT) && !HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS)) {
|
||||||
str = STR_HEADING_FOR_ROAD_DEPOT + _patches.vehicle_speed;
|
str = STR_HEADING_FOR_ROAD_DEPOT + _patches.vehicle_speed;
|
||||||
} else {
|
} else {
|
||||||
@ -320,7 +320,7 @@ static void RoadVehViewWndProc(Window *w, WindowEvent *e)
|
|||||||
default:
|
default:
|
||||||
if (v->num_orders == 0) {
|
if (v->num_orders == 0) {
|
||||||
str = STR_NO_ORDERS + _patches.vehicle_speed;
|
str = STR_NO_ORDERS + _patches.vehicle_speed;
|
||||||
SetDParam(0, v->cur_speed * 10 / 32);
|
SetDParam(0, v->GetDisplaySpeed());
|
||||||
} else {
|
} else {
|
||||||
str = STR_EMPTY;
|
str = STR_EMPTY;
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,7 @@ struct Ship: public Vehicle {
|
|||||||
void PlayLeaveStationSound() const;
|
void PlayLeaveStationSound() const;
|
||||||
bool IsPrimaryVehicle() const { return true; }
|
bool IsPrimaryVehicle() const { return true; }
|
||||||
int GetImage(Direction direction) const;
|
int GetImage(Direction direction) const;
|
||||||
|
int GetDisplaySpeed() const { return this->cur_speed * 10 / 32; }
|
||||||
void Tick();
|
void Tick();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -219,14 +219,14 @@ static void ShipViewWndProc(Window *w, WindowEvent *e)
|
|||||||
switch (v->current_order.type) {
|
switch (v->current_order.type) {
|
||||||
case OT_GOTO_STATION: {
|
case OT_GOTO_STATION: {
|
||||||
SetDParam(0, v->current_order.dest);
|
SetDParam(0, v->current_order.dest);
|
||||||
SetDParam(1, v->cur_speed * 10 / 32);
|
SetDParam(1, v->GetDisplaySpeed());
|
||||||
str = STR_HEADING_FOR_STATION + _patches.vehicle_speed;
|
str = STR_HEADING_FOR_STATION + _patches.vehicle_speed;
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case OT_GOTO_DEPOT: {
|
case OT_GOTO_DEPOT: {
|
||||||
Depot *depot = GetDepot(v->current_order.dest);
|
Depot *depot = GetDepot(v->current_order.dest);
|
||||||
SetDParam(0, depot->town_index);
|
SetDParam(0, depot->town_index);
|
||||||
SetDParam(1, v->cur_speed * 10 / 32);
|
SetDParam(1, v->GetDisplaySpeed());
|
||||||
if (HASBIT(v->current_order.flags, OFB_HALT_IN_DEPOT) && !HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS)) {
|
if (HASBIT(v->current_order.flags, OFB_HALT_IN_DEPOT) && !HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS)) {
|
||||||
str = STR_HEADING_FOR_SHIP_DEPOT + _patches.vehicle_speed;
|
str = STR_HEADING_FOR_SHIP_DEPOT + _patches.vehicle_speed;
|
||||||
} else {
|
} else {
|
||||||
@ -242,7 +242,7 @@ static void ShipViewWndProc(Window *w, WindowEvent *e)
|
|||||||
default:
|
default:
|
||||||
if (v->num_orders == 0) {
|
if (v->num_orders == 0) {
|
||||||
str = STR_NO_ORDERS + _patches.vehicle_speed;
|
str = STR_NO_ORDERS + _patches.vehicle_speed;
|
||||||
SetDParam(0, v->cur_speed * 10 / 32);
|
SetDParam(0, v->GetDisplaySpeed());
|
||||||
} else {
|
} else {
|
||||||
str = STR_EMPTY;
|
str = STR_EMPTY;
|
||||||
}
|
}
|
||||||
|
@ -273,6 +273,7 @@ struct Train : public Vehicle {
|
|||||||
bool IsPrimaryVehicle() const { return IsFrontEngine(this); }
|
bool IsPrimaryVehicle() const { return IsFrontEngine(this); }
|
||||||
bool HasFront() const { return true; }
|
bool HasFront() const { return true; }
|
||||||
int GetImage(Direction direction) const;
|
int GetImage(Direction direction) const;
|
||||||
|
int GetDisplaySpeed() const { return this->cur_speed * 10 / 16; }
|
||||||
void Tick();
|
void Tick();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -301,7 +301,7 @@ static bool TrainShouldStop(const Vehicle* v, TileIndex tile)
|
|||||||
static int GetTrainAcceleration(Vehicle *v, bool mode)
|
static int GetTrainAcceleration(Vehicle *v, bool mode)
|
||||||
{
|
{
|
||||||
int max_speed = 2000;
|
int max_speed = 2000;
|
||||||
int speed = v->cur_speed * 10 / 16; //[mph]
|
int speed = v->GetDisplaySpeed(); //[mph]
|
||||||
int curvecount[2] = {0, 0};
|
int curvecount[2] = {0, 0};
|
||||||
|
|
||||||
/*first find the curve speed limit */
|
/*first find the curve speed limit */
|
||||||
|
@ -179,14 +179,14 @@ static void TrainViewWndProc(Window *w, WindowEvent *e)
|
|||||||
} else if (v->breakdown_ctr == 1) {
|
} else if (v->breakdown_ctr == 1) {
|
||||||
str = STR_885C_BROKEN_DOWN;
|
str = STR_885C_BROKEN_DOWN;
|
||||||
} else if (v->vehstatus & VS_STOPPED) {
|
} else if (v->vehstatus & VS_STOPPED) {
|
||||||
if (v->u.rail.last_speed == 0) {
|
if (v->cur_speed == 0) {
|
||||||
if (v->u.rail.cached_power == 0) {
|
if (v->u.rail.cached_power == 0) {
|
||||||
str = STR_TRAIN_NO_POWER;
|
str = STR_TRAIN_NO_POWER;
|
||||||
} else {
|
} else {
|
||||||
str = STR_8861_STOPPED;
|
str = STR_8861_STOPPED;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
SetDParam(0, v->u.rail.last_speed * 10 / 16);
|
SetDParam(0, v->GetDisplaySpeed());
|
||||||
str = STR_TRAIN_STOPPING + _patches.vehicle_speed;
|
str = STR_TRAIN_STOPPING + _patches.vehicle_speed;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -194,7 +194,7 @@ static void TrainViewWndProc(Window *w, WindowEvent *e)
|
|||||||
case OT_GOTO_STATION: {
|
case OT_GOTO_STATION: {
|
||||||
str = STR_HEADING_FOR_STATION + _patches.vehicle_speed;
|
str = STR_HEADING_FOR_STATION + _patches.vehicle_speed;
|
||||||
SetDParam(0, v->current_order.dest);
|
SetDParam(0, v->current_order.dest);
|
||||||
SetDParam(1, v->u.rail.last_speed * 10 / 16);
|
SetDParam(1, v->GetDisplaySpeed());
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case OT_GOTO_DEPOT: {
|
case OT_GOTO_DEPOT: {
|
||||||
@ -205,7 +205,7 @@ static void TrainViewWndProc(Window *w, WindowEvent *e)
|
|||||||
} else {
|
} else {
|
||||||
str = STR_HEADING_FOR_TRAIN_DEPOT_SERVICE + _patches.vehicle_speed;
|
str = STR_HEADING_FOR_TRAIN_DEPOT_SERVICE + _patches.vehicle_speed;
|
||||||
}
|
}
|
||||||
SetDParam(1, v->u.rail.last_speed * 10 / 16);
|
SetDParam(1, v->GetDisplaySpeed());
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case OT_LOADING:
|
case OT_LOADING:
|
||||||
@ -216,14 +216,14 @@ static void TrainViewWndProc(Window *w, WindowEvent *e)
|
|||||||
case OT_GOTO_WAYPOINT: {
|
case OT_GOTO_WAYPOINT: {
|
||||||
SetDParam(0, v->current_order.dest);
|
SetDParam(0, v->current_order.dest);
|
||||||
str = STR_HEADING_FOR_WAYPOINT + _patches.vehicle_speed;
|
str = STR_HEADING_FOR_WAYPOINT + _patches.vehicle_speed;
|
||||||
SetDParam(1, v->u.rail.last_speed * 10 / 16);
|
SetDParam(1, v->GetDisplaySpeed());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (v->num_orders == 0) {
|
if (v->num_orders == 0) {
|
||||||
str = STR_NO_ORDERS + _patches.vehicle_speed;
|
str = STR_NO_ORDERS + _patches.vehicle_speed;
|
||||||
SetDParam(0, v->u.rail.last_speed * 10 / 16);
|
SetDParam(0, v->GetDisplaySpeed());
|
||||||
} else {
|
} else {
|
||||||
str = STR_EMPTY;
|
str = STR_EMPTY;
|
||||||
}
|
}
|
||||||
|
@ -414,6 +414,12 @@ struct Vehicle : PoolItem<Vehicle, VehicleID, &_Vehicle_pool> {
|
|||||||
*/
|
*/
|
||||||
virtual int GetImage(Direction direction) const { return 0; }
|
virtual int GetImage(Direction direction) const { return 0; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the speed in mph that can be sent into SetDParam for string processing.
|
||||||
|
* @return the vehicle's speed
|
||||||
|
*/
|
||||||
|
virtual int GetDisplaySpeed() const { return 0; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls the tick handler of the vehicle
|
* Calls the tick handler of the vehicle
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user