mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r9755) -Codechange: refactor some more of the begin loading stuff.
This commit is contained in:
parent
202009522c
commit
ec9ac99d01
|
@ -131,6 +131,7 @@ struct Aircraft : public Vehicle {
|
|||
virtual ~Aircraft() {}
|
||||
|
||||
const char *GetTypeString() { return "aircraft"; }
|
||||
void MarkDirty();
|
||||
};
|
||||
|
||||
#endif /* AIRCRAFT_H */
|
||||
|
|
|
@ -1385,14 +1385,11 @@ static void ProcessAircraftOrder(Vehicle *v)
|
|||
InvalidateWindowClasses(WC_AIRCRAFT_LIST);
|
||||
}
|
||||
|
||||
/** Mark all views dirty for an aircraft.
|
||||
* @param v vehicle to be redrawn.
|
||||
*/
|
||||
static void MarkAircraftDirty(Vehicle *v)
|
||||
void Aircraft::MarkDirty()
|
||||
{
|
||||
v->cur_image = GetAircraftImage(v, v->direction);
|
||||
if (v->subtype == AIR_HELICOPTER) v->next->next->cur_image = GetRotorImage(v);
|
||||
MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1);
|
||||
this->cur_image = GetAircraftImage(this, this->direction);
|
||||
if (this->subtype == AIR_HELICOPTER) this->next->next->cur_image = GetRotorImage(this);
|
||||
MarkAllViewportsDirty(this->left_coord, this->top_coord, this->right_coord + 1, this->bottom_coord + 1);
|
||||
}
|
||||
|
||||
static void HandleAircraftLoading(Vehicle *v, int mode)
|
||||
|
@ -1409,7 +1406,7 @@ static void HandleAircraftLoading(Vehicle *v, int mode)
|
|||
SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_INC);
|
||||
if (LoadUnloadVehicle(v, false)) {
|
||||
InvalidateWindow(WC_AIRCRAFT_LIST, v->owner);
|
||||
MarkAircraftDirty(v);
|
||||
v->MarkDirty();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -1417,7 +1414,7 @@ static void HandleAircraftLoading(Vehicle *v, int mode)
|
|||
Order b = v->current_order;
|
||||
v->LeaveStation();
|
||||
v->current_order.Free();
|
||||
MarkAircraftDirty(v);
|
||||
v->MarkDirty();
|
||||
if (!(b.flags & OF_NON_STOP)) return;
|
||||
break;
|
||||
}
|
||||
|
@ -1511,12 +1508,6 @@ static void AircraftEntersTerminal(Vehicle *v)
|
|||
}
|
||||
|
||||
v->BeginLoading();
|
||||
|
||||
SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_INC);
|
||||
LoadUnloadVehicle(v, true);
|
||||
MarkAircraftDirty(v);
|
||||
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
|
||||
InvalidateWindowClasses(WC_AIRCRAFT_LIST);
|
||||
}
|
||||
|
||||
static void AircraftLand(Vehicle *v)
|
||||
|
|
|
@ -39,6 +39,7 @@ struct RoadVehicle : public Vehicle {
|
|||
virtual ~RoadVehicle() {}
|
||||
|
||||
const char *GetTypeString() { return "road vehicle"; }
|
||||
void MarkDirty();
|
||||
};
|
||||
|
||||
#endif /* ROADVEH_H */
|
||||
|
|
|
@ -486,10 +486,10 @@ int32 CmdTurnRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||
}
|
||||
|
||||
|
||||
static void MarkRoadVehDirty(Vehicle *v)
|
||||
void RoadVehicle::MarkDirty()
|
||||
{
|
||||
v->cur_image = GetRoadVehImage(v, v->direction);
|
||||
MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1);
|
||||
this->cur_image = GetRoadVehImage(this, this->direction);
|
||||
MarkAllViewportsDirty(this->left_coord, this->top_coord, this->right_coord + 1, this->bottom_coord + 1);
|
||||
}
|
||||
|
||||
static void UpdateRoadVehDeltaXY(Vehicle *v)
|
||||
|
@ -765,7 +765,7 @@ static void HandleRoadVehLoading(Vehicle *v)
|
|||
SET_EXPENSES_TYPE(EXPENSES_ROADVEH_INC);
|
||||
if (LoadUnloadVehicle(v, false)) {
|
||||
InvalidateWindow(WC_ROADVEH_LIST, v->owner);
|
||||
MarkRoadVehDirty(v);
|
||||
v->MarkDirty();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -1598,15 +1598,8 @@ again:
|
|||
v->last_station_visited = GetStationIndex(v->tile);
|
||||
|
||||
RoadVehArrivesAt(v, st);
|
||||
|
||||
v->BeginLoading();
|
||||
|
||||
SET_EXPENSES_TYPE(EXPENSES_ROADVEH_INC);
|
||||
if (LoadUnloadVehicle(v, true)) {
|
||||
InvalidateWindow(WC_ROADVEH_LIST, v->owner);
|
||||
MarkRoadVehDirty(v);
|
||||
}
|
||||
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ struct Ship: public Vehicle {
|
|||
virtual ~Ship() {}
|
||||
|
||||
const char *GetTypeString() { return "ship"; }
|
||||
void MarkDirty();
|
||||
};
|
||||
|
||||
#endif /* SHIP_H */
|
||||
|
|
|
@ -229,10 +229,10 @@ static void HandleBrokenShip(Vehicle *v)
|
|||
}
|
||||
}
|
||||
|
||||
static void MarkShipDirty(Vehicle *v)
|
||||
void Ship::MarkDirty()
|
||||
{
|
||||
v->cur_image = GetShipImage(v, v->direction);
|
||||
MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1);
|
||||
this->cur_image = GetShipImage(this, this->direction);
|
||||
MarkAllViewportsDirty(this->left_coord, this->top_coord, this->right_coord + 1, this->bottom_coord + 1);
|
||||
}
|
||||
|
||||
static void PlayShipSound(Vehicle *v)
|
||||
|
@ -313,7 +313,7 @@ static void HandleShipLoading(Vehicle *v)
|
|||
SET_EXPENSES_TYPE(EXPENSES_SHIP_INC);
|
||||
if (LoadUnloadVehicle(v, false)) {
|
||||
InvalidateWindow(WC_SHIPS_LIST, v->owner);
|
||||
MarkShipDirty(v);
|
||||
v->MarkDirty();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -359,7 +359,7 @@ void RecalcShipStuff(Vehicle *v)
|
|||
{
|
||||
UpdateShipDeltaXY(v, v->direction);
|
||||
v->cur_image = GetShipImage(v, v->direction);
|
||||
MarkShipDirty(v);
|
||||
v->MarkDirty();
|
||||
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
|
||||
}
|
||||
|
||||
|
@ -735,15 +735,8 @@ static void ShipController(Vehicle *v)
|
|||
/* Process station in the orderlist. */
|
||||
st = GetStation(v->current_order.dest);
|
||||
if (st->facilities & FACIL_DOCK) { // ugly, ugly workaround for problem with ships able to drop off cargo at wrong stations
|
||||
v->BeginLoading();
|
||||
ShipArrivesAt(v, st);
|
||||
|
||||
SET_EXPENSES_TYPE(EXPENSES_SHIP_INC);
|
||||
if (LoadUnloadVehicle(v, true)) {
|
||||
InvalidateWindow(WC_SHIPS_LIST, v->owner);
|
||||
MarkShipDirty(v);
|
||||
}
|
||||
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
|
||||
v->BeginLoading();
|
||||
} else { // leave stations without docks right aways
|
||||
v->current_order.type = OT_LEAVESTATION;
|
||||
v->cur_order_index++;
|
||||
|
|
|
@ -244,6 +244,7 @@ struct Train : public Vehicle {
|
|||
virtual ~Train() {}
|
||||
|
||||
const char *GetTypeString() { return "train"; }
|
||||
void MarkDirty();
|
||||
};
|
||||
|
||||
#endif /* TRAIN_H */
|
||||
|
|
|
@ -2522,12 +2522,17 @@ static bool ProcessTrainOrder(Vehicle *v)
|
|||
return !at_waypoint && CheckReverseTrain(v);
|
||||
}
|
||||
|
||||
static void MarkTrainDirty(Vehicle *v)
|
||||
void Train::MarkDirty()
|
||||
{
|
||||
Vehicle *v = this;
|
||||
do {
|
||||
v->cur_image = GetTrainImage(v, v->direction);
|
||||
MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1);
|
||||
} while ((v = v->next) != NULL);
|
||||
|
||||
/* need to update acceleration and cached values since the goods on the train changed. */
|
||||
TrainCargoChanged(this);
|
||||
UpdateTrainAcceleration(this);
|
||||
}
|
||||
|
||||
static void HandleTrainLoading(Vehicle *v, bool mode)
|
||||
|
@ -2551,11 +2556,7 @@ static void HandleTrainLoading(Vehicle *v, bool mode)
|
|||
SET_EXPENSES_TYPE(EXPENSES_TRAIN_INC);
|
||||
if (LoadUnloadVehicle(v, false)) {
|
||||
InvalidateWindow(WC_TRAINS_LIST, v->owner);
|
||||
MarkTrainDirty(v);
|
||||
|
||||
/* need to update acceleration and cached values since the goods on the train changed. */
|
||||
TrainCargoChanged(v);
|
||||
UpdateTrainAcceleration(v);
|
||||
v->MarkDirty();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -2636,15 +2637,6 @@ static void TrainEnterStation(Vehicle *v, StationID station)
|
|||
|
||||
v->BeginLoading();
|
||||
v->current_order.dest = 0;
|
||||
|
||||
SET_EXPENSES_TYPE(EXPENSES_TRAIN_INC);
|
||||
if (LoadUnloadVehicle(v, true) != 0) {
|
||||
InvalidateWindow(WC_TRAINS_LIST, v->owner);
|
||||
TrainCargoChanged(v);
|
||||
UpdateTrainAcceleration(v);
|
||||
}
|
||||
MarkTrainDirty(v);
|
||||
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
|
||||
}
|
||||
|
||||
static byte AfterSetTrainPos(Vehicle *v, bool new_tile)
|
||||
|
|
|
@ -2980,6 +2980,17 @@ void Vehicle::BeginLoading()
|
|||
|
||||
current_order.type = OT_LOADING;
|
||||
GetStation(this->last_station_visited)->loading_vehicles.push_back(this);
|
||||
|
||||
static const int expense_type[] = { EXPENSES_TRAIN_INC, EXPENSES_ROADVEH_INC, EXPENSES_SHIP_INC, EXPENSES_AIRCRAFT_INC };
|
||||
SET_EXPENSES_TYPE(expense_type[this->type]);
|
||||
|
||||
if (LoadUnloadVehicle(this, true) != 0) {
|
||||
static const WindowClass invalidate_windows[] = { WC_TRAINS_LIST, WC_ROADVEH_LIST, WC_SHIPS_LIST, WC_AIRCRAFT_LIST };
|
||||
InvalidateWindow(invalidate_windows[this->type], this->owner);
|
||||
|
||||
this->MarkDirty();
|
||||
}
|
||||
InvalidateWindowWidget(WC_VEHICLE_VIEW, this->index, STATUS_BAR);
|
||||
}
|
||||
|
||||
void Vehicle::LeaveStation()
|
||||
|
|
|
@ -353,6 +353,11 @@ struct Vehicle {
|
|||
* @return the string representation.
|
||||
*/
|
||||
virtual const char* GetTypeString() = 0;
|
||||
|
||||
/**
|
||||
* Marks the vehicles to be redrawn and updates cached variables
|
||||
*/
|
||||
virtual void MarkDirty() {}
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -417,6 +422,7 @@ struct InvalidVehicle : public Vehicle {
|
|||
virtual ~InvalidVehicle() {}
|
||||
|
||||
const char *GetTypeString() { return "invalid vehicle"; }
|
||||
void MarkDirty() { NOT_REACHED(); }
|
||||
};
|
||||
|
||||
#define is_custom_sprite(x) (x >= 0xFD)
|
||||
|
|
Loading…
Reference in New Issue