mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-11 18:10:14 +00:00
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
This commit is contained in:
parent
161786e222
commit
2efecd34c4
@ -1416,32 +1416,6 @@ void Aircraft::MarkDirty()
|
|||||||
MarkAllViewportsDirty(this->left_coord, this->top_coord, this->right_coord + 1, this->bottom_coord + 1);
|
MarkAllViewportsDirty(this->left_coord, this->top_coord, this->right_coord + 1, this->bottom_coord + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void HandleAircraftLoading(Vehicle *v, int mode)
|
|
||||||
{
|
|
||||||
switch (v->current_order.type) {
|
|
||||||
case OT_LOADING: {
|
|
||||||
if (mode != 0) return;
|
|
||||||
if (--v->load_unload_time_rem != 0) return;
|
|
||||||
|
|
||||||
if (LoadUnloadVehicle(v)) return;
|
|
||||||
|
|
||||||
Order b = v->current_order;
|
|
||||||
v->LeaveStation();
|
|
||||||
v->current_order.Free();
|
|
||||||
v->MarkDirty();
|
|
||||||
if (!(b.flags & OF_NON_STOP)) return;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case OT_DUMMY: break;
|
|
||||||
|
|
||||||
default: return;
|
|
||||||
}
|
|
||||||
|
|
||||||
v->cur_order_index++;
|
|
||||||
InvalidateVehicleOrder(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void CrashAirplane(Vehicle *v)
|
static void CrashAirplane(Vehicle *v)
|
||||||
{
|
{
|
||||||
v->vehstatus |= VS_CRASHED;
|
v->vehstatus |= VS_CRASHED;
|
||||||
@ -2130,7 +2104,7 @@ static void AircraftEventHandler(Vehicle *v, int loop)
|
|||||||
|
|
||||||
HandleAircraftSmoke(v);
|
HandleAircraftSmoke(v);
|
||||||
ProcessAircraftOrder(v);
|
ProcessAircraftOrder(v);
|
||||||
HandleAircraftLoading(v, loop);
|
v->HandleLoading(loop != 0);
|
||||||
|
|
||||||
if (v->current_order.type >= OT_LOADING) return;
|
if (v->current_order.type >= OT_LOADING) return;
|
||||||
|
|
||||||
|
@ -753,31 +753,6 @@ static void ProcessRoadVehOrder(Vehicle *v)
|
|||||||
InvalidateVehicleOrder(v);
|
InvalidateVehicleOrder(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void HandleRoadVehLoading(Vehicle *v)
|
|
||||||
{
|
|
||||||
switch (v->current_order.type) {
|
|
||||||
case OT_LOADING: {
|
|
||||||
Order b;
|
|
||||||
|
|
||||||
if (--v->load_unload_time_rem != 0) return;
|
|
||||||
|
|
||||||
if (LoadUnloadVehicle(v)) return;
|
|
||||||
|
|
||||||
b = v->current_order;
|
|
||||||
v->LeaveStation();
|
|
||||||
if (!(b.flags & OF_NON_STOP)) return;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case OT_DUMMY: break;
|
|
||||||
|
|
||||||
default: return;
|
|
||||||
}
|
|
||||||
|
|
||||||
v->cur_order_index++;
|
|
||||||
InvalidateVehicleOrder(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void StartRoadVehSound(const Vehicle* v)
|
static void StartRoadVehSound(const Vehicle* v)
|
||||||
{
|
{
|
||||||
if (!PlayVehicleSound(v, VSE_START)) {
|
if (!PlayVehicleSound(v, VSE_START)) {
|
||||||
@ -1304,7 +1279,7 @@ static void RoadVehController(Vehicle *v)
|
|||||||
if (v->vehstatus & VS_STOPPED) return;
|
if (v->vehstatus & VS_STOPPED) return;
|
||||||
|
|
||||||
ProcessRoadVehOrder(v);
|
ProcessRoadVehOrder(v);
|
||||||
HandleRoadVehLoading(v);
|
v->HandleLoading();
|
||||||
|
|
||||||
if (v->current_order.type == OT_LOADING) return;
|
if (v->current_order.type == OT_LOADING) return;
|
||||||
|
|
||||||
|
@ -305,31 +305,6 @@ static void ProcessShipOrder(Vehicle *v)
|
|||||||
InvalidateWindowClasses(WC_SHIPS_LIST);
|
InvalidateWindowClasses(WC_SHIPS_LIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void HandleShipLoading(Vehicle *v)
|
|
||||||
{
|
|
||||||
switch (v->current_order.type) {
|
|
||||||
case OT_LOADING: {
|
|
||||||
if (--v->load_unload_time_rem != 0) return;
|
|
||||||
|
|
||||||
if (LoadUnloadVehicle(v)) return;
|
|
||||||
|
|
||||||
v->PlayLeaveStationSound();
|
|
||||||
|
|
||||||
Order b = v->current_order;
|
|
||||||
v->LeaveStation();
|
|
||||||
if (!(b.flags & OF_NON_STOP)) return;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case OT_DUMMY: break;
|
|
||||||
|
|
||||||
default: return;
|
|
||||||
}
|
|
||||||
|
|
||||||
v->cur_order_index++;
|
|
||||||
InvalidateVehicleOrder(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Ship::UpdateDeltaXY(Direction direction)
|
void Ship::UpdateDeltaXY(Direction direction)
|
||||||
{
|
{
|
||||||
#define MKIT(a, b, c, d) ((a & 0xFF) << 24) | ((b & 0xFF) << 16) | ((c & 0xFF) << 8) | ((d & 0xFF) << 0)
|
#define MKIT(a, b, c, d) ((a & 0xFF) << 24) | ((b & 0xFF) << 16) | ((c & 0xFF) << 8) | ((d & 0xFF) << 0)
|
||||||
@ -681,7 +656,7 @@ static void ShipController(Vehicle *v)
|
|||||||
if (v->vehstatus & VS_STOPPED) return;
|
if (v->vehstatus & VS_STOPPED) return;
|
||||||
|
|
||||||
ProcessShipOrder(v);
|
ProcessShipOrder(v);
|
||||||
HandleShipLoading(v);
|
v->HandleLoading();
|
||||||
|
|
||||||
if (v->current_order.type == OT_LOADING) return;
|
if (v->current_order.type == OT_LOADING) return;
|
||||||
|
|
||||||
|
@ -2526,35 +2526,6 @@ void Train::MarkDirty()
|
|||||||
UpdateTrainAcceleration(this);
|
UpdateTrainAcceleration(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void HandleTrainLoading(Vehicle *v, bool mode)
|
|
||||||
{
|
|
||||||
switch (v->current_order.type) {
|
|
||||||
case OT_LOADING: {
|
|
||||||
if (mode) return;
|
|
||||||
|
|
||||||
if (--v->load_unload_time_rem) return;
|
|
||||||
|
|
||||||
if (LoadUnloadVehicle(v)) return;
|
|
||||||
|
|
||||||
v->PlayLeaveStationSound();
|
|
||||||
|
|
||||||
Order b = v->current_order;
|
|
||||||
v->LeaveStation();
|
|
||||||
|
|
||||||
/* If this was not the final order, don't remove it from the list. */
|
|
||||||
if (!(b.flags & OF_NON_STOP)) return;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case OT_DUMMY: break;
|
|
||||||
|
|
||||||
default: return;
|
|
||||||
}
|
|
||||||
|
|
||||||
v->cur_order_index++;
|
|
||||||
InvalidateVehicleOrder(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int UpdateTrainSpeed(Vehicle *v)
|
static int UpdateTrainSpeed(Vehicle *v)
|
||||||
{
|
{
|
||||||
uint accel;
|
uint accel;
|
||||||
@ -3333,7 +3304,7 @@ static void TrainLocoHandler(Vehicle *v, bool mode)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
HandleTrainLoading(v, mode);
|
v->HandleLoading(mode);
|
||||||
|
|
||||||
if (v->current_order.type == OT_LOADING) return;
|
if (v->current_order.type == OT_LOADING) return;
|
||||||
|
|
||||||
|
@ -2929,6 +2929,40 @@ void Vehicle::LeaveStation()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Vehicle::HandleLoading(bool mode)
|
||||||
|
{
|
||||||
|
switch (this->current_order.type) {
|
||||||
|
case OT_LOADING: {
|
||||||
|
/* Not the first call for this tick */
|
||||||
|
if (mode) return;
|
||||||
|
|
||||||
|
/* We have not waited enough time till the next round of loading/unloading */
|
||||||
|
if (--this->load_unload_time_rem) return;
|
||||||
|
|
||||||
|
/* Load/unload the vehicle; when it actually did something
|
||||||
|
* we do not leave the station. */
|
||||||
|
if (LoadUnloadVehicle(this)) return;
|
||||||
|
|
||||||
|
this->PlayLeaveStationSound();
|
||||||
|
|
||||||
|
Order b = this->current_order;
|
||||||
|
this->LeaveStation();
|
||||||
|
|
||||||
|
/* If this was not the final order, don't remove it from the list. */
|
||||||
|
if (!(b.flags & OF_NON_STOP)) return;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case OT_DUMMY: break;
|
||||||
|
|
||||||
|
default: return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->cur_order_index++;
|
||||||
|
InvalidateVehicleOrder(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SpecialVehicle::UpdateDeltaXY(Direction direction)
|
void SpecialVehicle::UpdateDeltaXY(Direction direction)
|
||||||
{
|
{
|
||||||
this->x_offs = 0;
|
this->x_offs = 0;
|
||||||
|
@ -316,6 +316,13 @@ struct Vehicle {
|
|||||||
void BeginLoading();
|
void BeginLoading();
|
||||||
void LeaveStation();
|
void LeaveStation();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the loading of the vehicle; when not it skips through dummy
|
||||||
|
* orders and does nothing in all other cases.
|
||||||
|
* @param mode is the non-first call for this vehicle in this tick?
|
||||||
|
*/
|
||||||
|
void HandleLoading(bool mode = false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An overriden version of new, so you can use the vehicle instance
|
* An overriden version of new, so you can use the vehicle instance
|
||||||
* instead of a newly allocated piece of memory.
|
* instead of a newly allocated piece of memory.
|
||||||
|
Loading…
Reference in New Issue
Block a user