summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-04-29 22:33:51 +0000
committerrubidium <rubidium@openttd.org>2007-04-29 22:33:51 +0000
commitdf59f5cd15266db4d29d59b591d739d3e025b206 (patch)
tree81c46786f55f9842ddb4b237507c86df8fd72924 /src
parent0def47a3b00b74157483ff73090e57d62e9f913d (diff)
downloadopenttd-df59f5cd15266db4d29d59b591d739d3e025b206.tar.xz
(svn r9755) -Codechange: refactor some more of the begin loading stuff.
Diffstat (limited to 'src')
-rw-r--r--src/aircraft.h1
-rw-r--r--src/aircraft_cmd.cpp21
-rw-r--r--src/roadveh.h1
-rw-r--r--src/roadveh_cmd.cpp15
-rw-r--r--src/ship.h1
-rw-r--r--src/ship_cmd.cpp19
-rw-r--r--src/train.h1
-rw-r--r--src/train_cmd.cpp22
-rw-r--r--src/vehicle.cpp11
-rw-r--r--src/vehicle.h6
10 files changed, 44 insertions, 54 deletions
diff --git a/src/aircraft.h b/src/aircraft.h
index 0876fee7f..1baad94c7 100644
--- a/src/aircraft.h
+++ b/src/aircraft.h
@@ -131,6 +131,7 @@ struct Aircraft : public Vehicle {
virtual ~Aircraft() {}
const char *GetTypeString() { return "aircraft"; }
+ void MarkDirty();
};
#endif /* AIRCRAFT_H */
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp
index 4993b6d4a..88716c829 100644
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -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)
diff --git a/src/roadveh.h b/src/roadveh.h
index 1e9ec8180..ec1e0354f 100644
--- a/src/roadveh.h
+++ b/src/roadveh.h
@@ -39,6 +39,7 @@ struct RoadVehicle : public Vehicle {
virtual ~RoadVehicle() {}
const char *GetTypeString() { return "road vehicle"; }
+ void MarkDirty();
};
#endif /* ROADVEH_H */
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index 012233164..c6ca01265 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -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;
}
diff --git a/src/ship.h b/src/ship.h
index 6c64e4a7a..6e696f088 100644
--- a/src/ship.h
+++ b/src/ship.h
@@ -40,6 +40,7 @@ struct Ship: public Vehicle {
virtual ~Ship() {}
const char *GetTypeString() { return "ship"; }
+ void MarkDirty();
};
#endif /* SHIP_H */
diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp
index 10c93d97f..6ce767649 100644
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -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++;
diff --git a/src/train.h b/src/train.h
index 33ffc1632..8d67c4a18 100644
--- a/src/train.h
+++ b/src/train.h
@@ -244,6 +244,7 @@ struct Train : public Vehicle {
virtual ~Train() {}
const char *GetTypeString() { return "train"; }
+ void MarkDirty();
};
#endif /* TRAIN_H */
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 936d13c61..e00c0bc29 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -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)
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 5338bd554..5ec8c1c5f 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -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()
diff --git a/src/vehicle.h b/src/vehicle.h
index df5daf1a4..2a1b75d25 100644
--- a/src/vehicle.h
+++ b/src/vehicle.h
@@ -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)