summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2009-06-06 14:46:50 +0000
committerfrosch <frosch@openttd.org>2009-06-06 14:46:50 +0000
commit5b497d6b4963303ea77259c5c471ae06fb15c6ca (patch)
treee1ab3e86398ba2801ad55c202a3f6b3708e14639 /src
parentec3ef70adb40d9ff371082a7360652d58e425284 (diff)
downloadopenttd-5b497d6b4963303ea77259c5c471ae06fb15c6ca.tar.xz
(svn r16525) -Codechange: Notify small ufos on deletion of road vehicles, so they can head for somewhere else instead of stumbling over a ghost.
Diffstat (limited to 'src')
-rw-r--r--src/disaster_cmd.cpp25
-rw-r--r--src/saveload/afterload.cpp13
-rw-r--r--src/vehicle.cpp2
-rw-r--r--src/vehicle_func.h2
4 files changed, 38 insertions, 4 deletions
diff --git a/src/disaster_cmd.cpp b/src/disaster_cmd.cpp
index 91208520b..a32ee6b80 100644
--- a/src/disaster_cmd.cpp
+++ b/src/disaster_cmd.cpp
@@ -314,10 +314,7 @@ static bool DisasterTick_Ufo(DisasterVehicle *v)
} else {
/* Target a vehicle */
Vehicle *u_tmp = Vehicle::Get(v->dest_tile);
- if (u_tmp == NULL || u_tmp->type != VEH_ROAD || !IsRoadVehFront(u_tmp)) {
- delete v;
- return false;
- }
+ assert(u_tmp != NULL && u_tmp->type == VEH_ROAD && IsRoadVehFront(u_tmp));
RoadVehicle *u = (RoadVehicle *)u_tmp;
uint dist = Delta(v->x_pos, u->x_pos) + Delta(v->y_pos, u->y_pos);
@@ -948,6 +945,26 @@ void ReleaseDisastersTargetingIndustry(IndustryID i)
}
}
+/** Notify disasters that we are about to delete a vehicle. So make them head elsewhere.
+ * @param vehicle deleted vehicle
+ */
+void ReleaseDisastersTargetingVehicle(VehicleID vehicle)
+{
+ DisasterVehicle *v;
+ FOR_ALL_DISASTERVEHICLES(v) {
+ /* primary disaster vehicles that have chosen target */
+ if (v->subtype == ST_SMALL_UFO) {
+ if (v->current_order.GetDestination() != 0 && v->dest_tile == vehicle) {
+ /* Revert to target-searching */
+ v->current_order.SetDestination(0);
+ v->dest_tile = RandomTile();
+ v->z_pos = 135;
+ v->age = 0;
+ }
+ }
+ }
+}
+
void DisasterVehicle::UpdateDeltaXY(Direction direction)
{
this->x_offs = -1;
diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp
index 36dca96bc..911e687dd 100644
--- a/src/saveload/afterload.cpp
+++ b/src/saveload/afterload.cpp
@@ -1841,6 +1841,19 @@ bool AfterLoadGame()
}
}
+ if (CheckSavegameVersion(121)) {
+ /* Delete small ufos heading for non-existing vehicles */
+ Vehicle *v;
+ FOR_ALL_DISASTERVEHICLES(v) {
+ if (v->subtype == 2/*ST_SMALL_UFO*/ && v->current_order.GetDestination() != 0) {
+ const Vehicle *u = Vehicle::GetIfValid(v->dest_tile);
+ if (u == NULL || u->type != VEH_ROAD || !IsRoadVehFront(u)) {
+ delete v;
+ }
+ }
+ }
+ }
+
AfterLoadLabelMaps();
GamelogPrintDebug(1);
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 19cd6021a..92248b95c 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -554,6 +554,8 @@ void Vehicle::PreDestructor()
extern void StopGlobalFollowVehicle(const Vehicle *v);
StopGlobalFollowVehicle(this);
+
+ ReleaseDisastersTargetingVehicle(this->index);
}
Vehicle::~Vehicle()
diff --git a/src/vehicle_func.h b/src/vehicle_func.h
index f7827112e..fa3fbc1b9 100644
--- a/src/vehicle_func.h
+++ b/src/vehicle_func.h
@@ -168,4 +168,6 @@ extern uint16 _returned_refit_capacity;
bool CanVehicleUseStation(EngineID engine_type, const struct Station *st);
bool CanVehicleUseStation(const Vehicle *v, const struct Station *st);
+void ReleaseDisastersTargetingVehicle(VehicleID vehicle);
+
#endif /* VEHICLE_FUNC_H */