Changeset - r12107:e2e26c8ef3e7
[Not reviewed]
master
0 4 0
frosch - 15 years ago 2009-06-06 14:46:50
frosch@openttd.org
(svn r16525) -Codechange: Notify small ufos on deletion of road vehicles, so they can head for somewhere else instead of stumbling over a ghost.
4 files changed with 38 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/disaster_cmd.cpp
Show inline comments
 
@@ -311,16 +311,13 @@ static bool DisasterTick_Ufo(DisasterVeh
 

	
 
		delete v;
 
		return false;
 
	} 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);
 

	
 
		if (dist < TILE_SIZE && !(u->vehstatus & VS_HIDDEN) && u->breakdown_ctr == 0) {
 
			u->breakdown_ctr = 3;
 
@@ -945,12 +942,32 @@ void ReleaseDisastersTargetingIndustry(I
 
			/* if it has chosen target, and it is this industry (yes, dest_tile is IndustryID here), set order to "leaving map peacefully" */
 
			if (v->current_order.GetDestination() > 0 && v->dest_tile == i) v->current_order.SetDestination(3);
 
		}
 
	}
 
}
 

	
 
/** 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;
 
	this->y_offs        = -1;
 
	this->x_extent      =  2;
 
	this->y_extent      =  2;
src/saveload/afterload.cpp
Show inline comments
 
@@ -1838,12 +1838,25 @@ bool AfterLoadGame()
 
		Company *c;
 
		FOR_ALL_COMPANIES(c) {
 
			c->settings.vehicle = _old_vds;
 
		}
 
	}
 

	
 
	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);
 

	
 
	bool ret = InitializeWindowsAndCaches();
 
	/* Restore the signals */
src/vehicle.cpp
Show inline comments
 
@@ -551,12 +551,14 @@ void Vehicle::PreDestructor()
 
	this->cargo.Truncate(0);
 
	DeleteVehicleOrders(this);
 
	DeleteDepotHighlightOfVehicle(this);
 

	
 
	extern void StopGlobalFollowVehicle(const Vehicle *v);
 
	StopGlobalFollowVehicle(this);
 

	
 
	ReleaseDisastersTargetingVehicle(this->index);
 
}
 

	
 
Vehicle::~Vehicle()
 
{
 
	free(this->name);
 

	
src/vehicle_func.h
Show inline comments
 
@@ -165,7 +165,9 @@ extern const Vehicle *_place_clicked_veh
 
extern VehicleID _new_vehicle_id;
 
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 */
0 comments (0 inline, 0 general)