Changeset - r21720:231348c28655
[Not reviewed]
master
0 11 0
rubidium - 10 years ago 2014-09-20 15:31:26
rubidium@openttd.org
(svn r26863) -Codechange: move a number of Vehicle* functions into the Vehicle class
11 files changed with 82 insertions and 88 deletions:
0 comments (0 inline, 0 general)
src/aircraft_cmd.cpp
Show inline comments
 
@@ -334,14 +334,14 @@ CommandCost CmdBuildAircraft(TileIndex t
 
		v->cargo_cap = e->DetermineCapacity(v, &u->cargo_cap);
 

	
 
		v->InvalidateNewGRFCacheOfChain();
 

	
 
		UpdateAircraftCache(v, true);
 

	
 
		VehicleUpdatePosition(v);
 
		VehicleUpdatePosition(u);
 
		v->UpdatePosition();
 
		u->UpdatePosition();
 

	
 
		/* Aircraft with 3 vehicles (chopper)? */
 
		if (v->subtype == AIR_HELICOPTER) {
 
			Aircraft *w = new Aircraft();
 
			w->engine_type = e->index;
 
			w->direction = DIR_N;
 
@@ -356,13 +356,13 @@ CommandCost CmdBuildAircraft(TileIndex t
 
			w->random_bits = VehicleRandomBits();
 
			/* Use rotor's air.state to store the rotor animation frame */
 
			w->state = HRS_ROTOR_STOPPED;
 
			w->UpdateDeltaXY(INVALID_DIR);
 

	
 
			u->SetNext(w);
 
			VehicleUpdatePosition(w);
 
			w->UpdatePosition();
 
		}
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
@@ -484,13 +484,13 @@ static void HelicopterTickHandler(Aircra
 
	} else {
 
		return;
 
	}
 

	
 
	u->cur_image = img;
 

	
 
	VehicleUpdatePositionAndViewport(u);
 
	u->UpdatePositionAndViewport();
 
}
 

	
 
/**
 
 * Set aircraft position.
 
 * @param v Aircraft to position.
 
 * @param x New X position.
 
@@ -500,13 +500,13 @@ static void HelicopterTickHandler(Aircra
 
void SetAircraftPosition(Aircraft *v, int x, int y, int z)
 
{
 
	v->x_pos = x;
 
	v->y_pos = y;
 
	v->z_pos = z;
 

	
 
	VehicleUpdatePosition(v);
 
	v->UpdatePosition();
 
	v->UpdateViewport(true, false);
 
	if (v->subtype == AIR_HELICOPTER) v->Next()->Next()->cur_image = GetRotorImage(v, EIT_ON_MAP);
 

	
 
	Aircraft *u = v->Next();
 

	
 
	int safe_x = Clamp(x, 0, MapMaxX() * TILE_SIZE);
 
@@ -515,21 +515,21 @@ void SetAircraftPosition(Aircraft *v, in
 
	u->y_pos = y - ((v->z_pos - GetSlopePixelZ(safe_x, safe_y)) >> 3);
 

	
 
	safe_y = Clamp(u->y_pos, 0, MapMaxY() * TILE_SIZE);
 
	u->z_pos = GetSlopePixelZ(safe_x, safe_y);
 
	u->cur_image = v->cur_image;
 

	
 
	VehicleUpdatePositionAndViewport(u);
 
	u->UpdatePositionAndViewport();
 

	
 
	u = u->Next();
 
	if (u != NULL) {
 
		u->x_pos = x;
 
		u->y_pos = y;
 
		u->z_pos = z + ROTOR_Z_OFFSET;
 

	
 
		VehicleUpdatePositionAndViewport(u);
 
		u->UpdatePositionAndViewport();
 
	}
 
}
 

	
 
/**
 
 * Handle Aircraft specific tasks when an Aircraft enters a hangar
 
 * @param *v Vehicle that enters the hangar
src/articulated_vehicles.cpp
Show inline comments
 
@@ -442,9 +442,9 @@ void AddArticulatedParts(Vehicle *first)
 
		v->value = 0;
 
		v->cur_image = SPR_IMG_QUERY;
 
		v->random_bits = VehicleRandomBits();
 

	
 
		if (flip_image) v->spritenum++;
 

	
 
		VehicleUpdatePosition(v);
 
		v->UpdatePosition();
 
	}
 
}
src/disaster_cmd.cpp
Show inline comments
 
@@ -148,24 +148,24 @@ static void InitializeDisasterVehicle(Di
 
	v->owner = OWNER_NONE;
 
	v->vehstatus = VS_UNCLICKABLE;
 
	v->image_override = 0;
 
	v->current_order.Free();
 

	
 
	DisasterVehicleUpdateImage(v);
 
	VehicleUpdatePositionAndViewport(v);
 
	v->UpdatePositionAndViewport();
 
}
 

	
 
static void SetDisasterVehiclePos(DisasterVehicle *v, int x, int y, int z)
 
{
 
	v->x_pos = x;
 
	v->y_pos = y;
 
	v->z_pos = z;
 
	v->tile = TileVirtXY(x, y);
 

	
 
	DisasterVehicleUpdateImage(v);
 
	VehicleUpdatePositionAndViewport(v);
 
	v->UpdatePositionAndViewport();
 

	
 
	DisasterVehicle *u = v->Next();
 
	if (u != NULL) {
 
		int safe_x = Clamp(x, 0, MapMaxX() * TILE_SIZE);
 
		int safe_y = Clamp(y - 1, 0, MapMaxY() * TILE_SIZE);
 

	
 
@@ -173,19 +173,19 @@ static void SetDisasterVehiclePos(Disast
 
		u->y_pos = y - 1 - (max(z - GetSlopePixelZ(safe_x, safe_y), 0) >> 3);
 
		safe_y = Clamp(u->y_pos, 0, MapMaxY() * TILE_SIZE);
 
		u->z_pos = GetSlopePixelZ(safe_x, safe_y);
 
		u->direction = v->direction;
 

	
 
		DisasterVehicleUpdateImage(u);
 
		VehicleUpdatePositionAndViewport(u);
 
		u->UpdatePositionAndViewport();
 

	
 
		if ((u = u->Next()) != NULL) {
 
			u->x_pos = x;
 
			u->y_pos = y;
 
			u->z_pos = z + 5;
 
			VehicleUpdatePositionAndViewport(u);
 
			u->UpdatePositionAndViewport();
 
		}
 
	}
 
}
 

	
 
/**
 
 * Zeppeliner handling, v->current_order.dest states:
 
@@ -473,13 +473,13 @@ static bool DisasterTick_Helicopter_Roto
 
{
 
	v->tick_counter++;
 
	if (HasBit(v->tick_counter, 0)) return true;
 

	
 
	if (++v->cur_image > SPR_ROTOR_MOVING_3) v->cur_image = SPR_ROTOR_MOVING_1;
 

	
 
	VehicleUpdatePositionAndViewport(v);
 
	v->UpdatePositionAndViewport();
 

	
 
	return true;
 
}
 

	
 
/**
 
 * (Big) Ufo handling, v->current_order.dest states:
src/effectvehicle.cpp
Show inline comments
 
@@ -43,13 +43,13 @@ static bool ChimneySmokeTick(EffectVehic
 
		if (v->cur_image != SPR_CHIMNEY_SMOKE_7) {
 
			v->cur_image++;
 
		} else {
 
			v->cur_image = SPR_CHIMNEY_SMOKE_0;
 
		}
 
		v->progress = 7;
 
		VehicleUpdatePositionAndViewport(v);
 
		v->UpdatePositionAndViewport();
 
	}
 

	
 
	return true;
 
}
 

	
 
static void SteamSmokeInit(EffectVehicle *v)
 
@@ -76,13 +76,13 @@ static bool SteamSmokeTick(EffectVehicle
 
			delete v;
 
			return false;
 
		}
 
		moved = true;
 
	}
 

	
 
	if (moved) VehicleUpdatePositionAndViewport(v);
 
	if (moved) v->UpdatePositionAndViewport();
 

	
 
	return true;
 
}
 

	
 
static void DieselSmokeInit(EffectVehicle *v)
 
{
 
@@ -93,17 +93,17 @@ static void DieselSmokeInit(EffectVehicl
 
static bool DieselSmokeTick(EffectVehicle *v)
 
{
 
	v->progress++;
 

	
 
	if ((v->progress & 3) == 0) {
 
		v->z_pos++;
 
		VehicleUpdatePositionAndViewport(v);
 
		v->UpdatePositionAndViewport();
 
	} else if ((v->progress & 7) == 1) {
 
		if (v->cur_image != SPR_DIESEL_SMOKE_5) {
 
			v->cur_image++;
 
			VehicleUpdatePositionAndViewport(v);
 
			v->UpdatePositionAndViewport();
 
		} else {
 
			delete v;
 
			return false;
 
		}
 
	}
 

	
 
@@ -121,13 +121,13 @@ static bool ElectricSparkTick(EffectVehi
 
	if (v->progress < 2) {
 
		v->progress++;
 
	} else {
 
		v->progress = 0;
 
		if (v->cur_image != SPR_ELECTRIC_SPARK_5) {
 
			v->cur_image++;
 
			VehicleUpdatePositionAndViewport(v);
 
			v->UpdatePositionAndViewport();
 
		} else {
 
			delete v;
 
			return false;
 
		}
 
	}
 

	
 
@@ -158,13 +158,13 @@ static bool SmokeTick(EffectVehicle *v)
 
			delete v;
 
			return false;
 
		}
 
		moved = true;
 
	}
 

	
 
	if (moved) VehicleUpdatePositionAndViewport(v);
 
	if (moved) v->UpdatePositionAndViewport();
 

	
 
	return true;
 
}
 

	
 
static void ExplosionLargeInit(EffectVehicle *v)
 
{
 
@@ -175,13 +175,13 @@ static void ExplosionLargeInit(EffectVeh
 
static bool ExplosionLargeTick(EffectVehicle *v)
 
{
 
	v->progress++;
 
	if ((v->progress & 3) == 0) {
 
		if (v->cur_image != SPR_EXPLOSION_LARGE_F) {
 
			v->cur_image++;
 
			VehicleUpdatePositionAndViewport(v);
 
			v->UpdatePositionAndViewport();
 
		} else {
 
			delete v;
 
			return false;
 
		}
 
	}
 

	
 
@@ -200,13 +200,13 @@ static bool BreakdownSmokeTick(EffectVeh
 
	if ((v->progress & 7) == 0) {
 
		if (v->cur_image != SPR_BREAKDOWN_SMOKE_3) {
 
			v->cur_image++;
 
		} else {
 
			v->cur_image = SPR_BREAKDOWN_SMOKE_0;
 
		}
 
		VehicleUpdatePositionAndViewport(v);
 
		v->UpdatePositionAndViewport();
 
	}
 

	
 
	v->animation_state--;
 
	if (v->animation_state == 0) {
 
		delete v;
 
		return false;
 
@@ -224,13 +224,13 @@ static void ExplosionSmallInit(EffectVeh
 
static bool ExplosionSmallTick(EffectVehicle *v)
 
{
 
	v->progress++;
 
	if ((v->progress & 3) == 0) {
 
		if (v->cur_image != SPR_EXPLOSION_SMALL_B) {
 
			v->cur_image++;
 
			VehicleUpdatePositionAndViewport(v);
 
			v->UpdatePositionAndViewport();
 
		} else {
 
			delete v;
 
			return false;
 
		}
 
	}
 

	
 
@@ -301,13 +301,13 @@ static bool BulldozerTick(EffectVehicle 
 
			v->animation_state++;
 
			if (v->animation_state == lengthof(_bulldozer_movement)) {
 
				delete v;
 
				return false;
 
			}
 
		}
 
		VehicleUpdatePositionAndViewport(v);
 
		v->UpdatePositionAndViewport();
 
	}
 

	
 
	return true;
 
}
 

	
 
static void BubbleInit(EffectVehicle *v)
 
@@ -474,13 +474,13 @@ static bool BubbleTick(EffectVehicle *v)
 
	v->progress++;
 
	if ((v->progress & 3) != 0) return true;
 

	
 
	if (v->spritenum == 0) {
 
		v->cur_image++;
 
		if (v->cur_image < SPR_BUBBLE_GENERATE_3) {
 
			VehicleUpdatePositionAndViewport(v);
 
			v->UpdatePositionAndViewport();
 
			return true;
 
		}
 
		if (v->animation_substate != 0) {
 
			v->spritenum = GB(Random(), 0, 2) + 1;
 
		} else {
 
			v->spritenum = 6;
 
@@ -520,13 +520,13 @@ static bool BubbleTick(EffectVehicle *v)
 

	
 
	v->x_pos += b->x;
 
	v->y_pos += b->y;
 
	v->z_pos += b->z;
 
	v->cur_image = SPR_BUBBLE_0 + b->image;
 

	
 
	VehicleUpdatePositionAndViewport(v);
 
	v->UpdatePositionAndViewport();
 

	
 
	return true;
 
}
 

	
 

	
 
typedef void EffectInitProc(EffectVehicle *v);
 
@@ -604,13 +604,13 @@ EffectVehicle *CreateEffectVehicle(int x
 
	v->tile = 0;
 
	v->UpdateDeltaXY(INVALID_DIR);
 
	v->vehstatus = VS_UNCLICKABLE;
 

	
 
	_effect_init_procs[type](v);
 

	
 
	VehicleUpdatePositionAndViewport(v);
 
	v->UpdatePositionAndViewport();
 

	
 
	return v;
 
}
 

	
 
/**
 
 * Create an effect vehicle above a particular location.
src/roadveh_cmd.cpp
Show inline comments
 
@@ -326,13 +326,13 @@ CommandCost CmdBuildRoadVehicle(TileInde
 
			u->InvalidateNewGRFCache();
 
		}
 
		RoadVehUpdateCache(v);
 
		/* Initialize cached values for realistic acceleration. */
 
		if (_settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL) v->CargoChanged();
 

	
 
		VehicleUpdatePosition(v);
 
		v->UpdatePosition();
 

	
 
		CheckConsistencyOfArticulatedVehicle(v);
 
	}
 

	
 
	return CommandCost();
 
}
 
@@ -1014,13 +1014,13 @@ static bool RoadVehLeaveDepot(RoadVehicl
 
	v->vehstatus &= ~VS_HIDDEN;
 
	v->state = tdir;
 
	v->frame = RVC_DEPOT_START_FRAME;
 

	
 
	v->x_pos = x;
 
	v->y_pos = y;
 
	VehicleUpdatePosition(v);
 
	v->UpdatePosition();
 
	v->UpdateInclination(true, true);
 

	
 
	InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
 

	
 
	return true;
 
}
 
@@ -1143,21 +1143,21 @@ bool IndividualRoadVehicleController(Roa
 
		}
 

	
 
		if (IsTileType(gp.new_tile, MP_TUNNELBRIDGE) && HasBit(VehicleEnterTile(v, gp.new_tile, gp.x, gp.y), VETS_ENTERED_WORMHOLE)) {
 
			/* Vehicle has just entered a bridge or tunnel */
 
			v->x_pos = gp.x;
 
			v->y_pos = gp.y;
 
			VehicleUpdatePosition(v);
 
			v->UpdatePosition();
 
			v->UpdateInclination(true, true);
 
			return true;
 
		}
 

	
 
		v->x_pos = gp.x;
 
		v->y_pos = gp.y;
 
		VehicleUpdatePosition(v);
 
		if ((v->vehstatus & VS_HIDDEN) == 0) VehicleUpdateViewport(v, true);
 
		v->UpdatePosition();
 
		if ((v->vehstatus & VS_HIDDEN) == 0) v->Vehicle::UpdateViewport(true);
 
		return true;
 
	}
 

	
 
	/* Get move position data for next frame.
 
	 * For a drive-through road stop use 'straight road' move data.
 
	 * In this case v->state is masked to give the road stop entry direction. */
 
@@ -1300,13 +1300,13 @@ again:
 
		if (new_dir != v->direction) {
 
			v->direction = new_dir;
 
			if (_settings_game.vehicle.roadveh_acceleration_model == AM_ORIGINAL) v->cur_speed -= v->cur_speed >> 2;
 
		}
 
		v->x_pos = x;
 
		v->y_pos = y;
 
		VehicleUpdatePosition(v);
 
		v->UpdatePosition();
 
		RoadZPosAffectSpeed(v, v->UpdateInclination(true, true));
 
		return true;
 
	}
 

	
 
	if (rd.x & RDE_TURNED) {
 
		/* Vehicle has finished turning around, it will now head back onto the same tile */
 
@@ -1366,13 +1366,13 @@ again:
 
			v->direction = new_dir;
 
			if (_settings_game.vehicle.roadveh_acceleration_model == AM_ORIGINAL) v->cur_speed -= v->cur_speed >> 2;
 
		}
 

	
 
		v->x_pos = x;
 
		v->y_pos = y;
 
		VehicleUpdatePosition(v);
 
		v->UpdatePosition();
 
		RoadZPosAffectSpeed(v, v->UpdateInclination(true, true));
 
		return true;
 
	}
 

	
 
	/* This vehicle is not in a wormhole and it hasn't entered a new tile. If
 
	 * it's on a depot tile, check if it's time to activate the next vehicle in
 
@@ -1454,13 +1454,13 @@ again:
 

	
 
				/* Check if next inline bay is free and has compatible road. */
 
				if (RoadStop::IsDriveThroughRoadStopContinuation(v->tile, next_tile) && (GetRoadTypes(next_tile) & v->compatible_roadtypes) != 0) {
 
					v->frame++;
 
					v->x_pos = x;
 
					v->y_pos = y;
 
					VehicleUpdatePosition(v);
 
					v->UpdatePosition();
 
					RoadZPosAffectSpeed(v, v->UpdateInclination(true, false));
 
					return true;
 
				}
 
			}
 

	
 
			rs->SetEntranceBusy(false);
 
@@ -1503,13 +1503,13 @@ again:
 

	
 
	/* Move to next frame unless vehicle arrived at a stop position
 
	 * in a depot or entered a tunnel/bridge */
 
	if (!HasBit(r, VETS_ENTERED_WORMHOLE)) v->frame++;
 
	v->x_pos = x;
 
	v->y_pos = y;
 
	VehicleUpdatePosition(v);
 
	v->UpdatePosition();
 
	RoadZPosAffectSpeed(v, v->UpdateInclination(false, true));
 
	return true;
 
}
 

	
 
static bool RoadVehController(RoadVehicle *v)
 
{
src/saveload/vehicle_sl.cpp
Show inline comments
 
@@ -456,14 +456,14 @@ void AfterLoadVehicles(bool part_of_load
 
				break;
 
			default: break;
 
		}
 

	
 
		v->UpdateDeltaXY(v->direction);
 
		v->coord.left = INVALID_COORD;
 
		VehicleUpdatePosition(v);
 
		VehicleUpdateViewport(v, false);
 
		v->UpdatePosition();
 
		v->UpdateViewport(false);
 
	}
 
}
 

	
 
bool TrainController(Train *v, Vehicle *nomove, bool reverse = true); // From train_cmd.cpp
 
void ReverseTrainDirection(Train *v);
 
void ReverseTrainSwapVeh(Train *v, int l, int r);
src/ship_cmd.cpp
Show inline comments
 
@@ -622,26 +622,26 @@ static void ShipController(Ship *v)
 
		}
 
	} else {
 
		/* On a bridge */
 
		if (!IsTileType(gp.new_tile, MP_TUNNELBRIDGE) || !HasBit(VehicleEnterTile(v, gp.new_tile, gp.x, gp.y), VETS_ENTERED_WORMHOLE)) {
 
			v->x_pos = gp.x;
 
			v->y_pos = gp.y;
 
			VehicleUpdatePosition(v);
 
			if ((v->vehstatus & VS_HIDDEN) == 0) VehicleUpdateViewport(v, true);
 
			v->UpdatePosition();
 
			if ((v->vehstatus & VS_HIDDEN) == 0) v->Vehicle::UpdateViewport(true);
 
			return;
 
		}
 
	}
 

	
 
	/* update image of ship, as well as delta XY */
 
	dir = ShipGetNewDirection(v, gp.x, gp.y);
 
	v->x_pos = gp.x;
 
	v->y_pos = gp.y;
 
	v->z_pos = GetSlopePixelZ(gp.x, gp.y);
 

	
 
getout:
 
	VehicleUpdatePosition(v);
 
	v->UpdatePosition();
 
	v->UpdateViewport(true, true);
 
	return;
 

	
 
reverse_direction:
 
	dir = ReverseDir(v->direction);
 
	v->direction = dir;
 
@@ -719,13 +719,13 @@ CommandCost CmdBuildShip(TileIndex tile,
 
		v->InvalidateNewGRFCacheOfChain();
 

	
 
		v->cargo_cap = e->DetermineCapacity(v);
 

	
 
		v->InvalidateNewGRFCacheOfChain();
 

	
 
		VehicleUpdatePosition(v);
 
		v->UpdatePosition();
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
bool Ship::FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse)
src/train_cmd.cpp
Show inline comments
 
@@ -639,13 +639,13 @@ static CommandCost CmdBuildRailWagon(Til
 
		v->group_id = DEFAULT_GROUP;
 

	
 
		AddArticulatedParts(v);
 

	
 
		_new_vehicle_id = v->index;
 

	
 
		VehicleUpdatePosition(v);
 
		v->UpdatePosition();
 
		v->First()->ConsistChanged(CCF_ARRANGE);
 
		UpdateTrainGroupID(v->First());
 

	
 
		CheckConsistencyOfArticulatedVehicle(v);
 

	
 
		/* Try to connect the vehicle to one of free chains of wagons. */
 
@@ -702,13 +702,13 @@ static void AddRearEngineToMultiheadedTr
 
	u->build_year = v->build_year;
 
	u->cur_image = SPR_IMG_QUERY;
 
	u->random_bits = VehicleRandomBits();
 
	v->SetMultiheaded();
 
	u->SetMultiheaded();
 
	v->SetNext(u);
 
	VehicleUpdatePosition(u);
 
	u->UpdatePosition();
 

	
 
	/* Now we need to link the front and rear engines together */
 
	v->other_multiheaded_part = u;
 
	u->other_multiheaded_part = v;
 
}
 

	
 
@@ -774,13 +774,13 @@ CommandCost CmdBuildRailVehicle(TileInde
 

	
 
		v->group_id = DEFAULT_GROUP;
 

	
 
		v->SetFrontEngine();
 
		v->SetEngine();
 

	
 
		VehicleUpdatePosition(v);
 
		v->UpdatePosition();
 

	
 
		if (rvi->railveh_type == RAILVEH_MULTIHEAD) {
 
			AddRearEngineToMultiheadedTrain(v);
 
		} else {
 
			AddArticulatedParts(v);
 
		}
 
@@ -1562,20 +1562,20 @@ static void UpdateStatusAfterSwap(Train 
 
		if (IsTileType(vt, MP_TUNNELBRIDGE)) {
 
			VehicleEnterTile(v, vt, v->x_pos, v->y_pos);
 
			if (v->track != TRACK_BIT_WORMHOLE && IsBridgeTile(v->tile)) {
 
				/* We have just left the wormhole, possibly set the
 
				 * "goingdown" bit. UpdateInclination() can be used
 
				 * because we are at the border of the tile. */
 
				VehicleUpdatePosition(v);
 
				v->UpdatePosition();
 
				v->UpdateInclination(true, true);
 
				return;
 
			}
 
		}
 
	}
 

	
 
	VehicleUpdatePosition(v);
 
	v->UpdatePosition();
 
	v->UpdateViewport(true, true);
 
}
 

	
 
/**
 
 * Swap vehicles \a l and \a r in consist \a v, and reverse their direction.
 
 * @param v Consist to change.
 
@@ -2180,13 +2180,13 @@ static bool CheckTrainStayInDepot(Train 
 
	if (v->direction & 2) v->track = TRACK_BIT_Y;
 

	
 
	v->vehstatus &= ~VS_HIDDEN;
 
	v->cur_speed = 0;
 

	
 
	v->UpdateViewport(true, true);
 
	VehicleUpdatePosition(v);
 
	v->UpdatePosition();
 
	UpdateSignalsOnSegment(v->tile, INVALID_DIAGDIR, v->owner);
 
	v->UpdateAcceleration();
 
	InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
 

	
 
	return false;
 
}
 
@@ -3331,24 +3331,24 @@ bool TrainController(Train *v, Vehicle *
 
				if (gp.old_tile == gp.new_tile) {
 
					gp.old_tile = GetOtherTunnelBridgeEnd(gp.old_tile);
 
				}
 
			} else {
 
				v->x_pos = gp.x;
 
				v->y_pos = gp.y;
 
				VehicleUpdatePosition(v);
 
				if ((v->vehstatus & VS_HIDDEN) == 0) VehicleUpdateViewport(v, true);
 
				v->UpdatePosition();
 
				if ((v->vehstatus & VS_HIDDEN) == 0) v->Vehicle::UpdateViewport(true);
 
				continue;
 
			}
 
		}
 

	
 
		/* update image of train, as well as delta XY */
 
		v->UpdateDeltaXY(v->direction);
 

	
 
		v->x_pos = gp.x;
 
		v->y_pos = gp.y;
 
		VehicleUpdatePosition(v);
 
		v->UpdatePosition();
 

	
 
		/* update the Z position of the vehicle */
 
		int old_z = v->UpdateInclination(gp.new_tile != gp.old_tile, false);
 

	
 
		if (prev == NULL) {
 
			/* This is the first vehicle in the train */
 
@@ -3512,13 +3512,13 @@ static void ChangeTrainDirRandomly(Train
 
			v->UpdateDeltaXY(v->direction);
 
			v->cur_image = v->GetImage(v->direction, EIT_ON_MAP);
 
			/* Refrain from updating the z position of the vehicle when on
 
			 * a bridge, because UpdateInclination() will put the vehicle under
 
			 * the bridge in that case */
 
			if (v->track != TRACK_BIT_WORMHOLE) {
 
				VehicleUpdatePosition(v);
 
				v->UpdatePosition();
 
				v->UpdateInclination(false, false);
 
			}
 
		}
 
	} while ((v = v->Next()) != NULL);
 
}
 

	
src/vehicle.cpp
Show inline comments
 
@@ -203,13 +203,13 @@ uint Vehicle::Crash(bool flooded)
 
	if (this->IsPrimaryVehicle()) this->vehstatus |= VS_STOPPED;
 
	/* crash all wagons, and count passengers */
 
	for (Vehicle *v = this; v != NULL; v = v->Next()) {
 
		/* We do not transfer reserver cargo back, so TotalCount() instead of StoredCount() */
 
		if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) pass += v->cargo.TotalCount();
 
		v->vehstatus |= VS_CRASHED;
 
		MarkSingleVehicleDirty(v);
 
		v->MarkAllViewportsDirty();
 
	}
 

	
 
	/* Dirty some windows */
 
	InvalidateWindowClassesData(GetWindowClassForVehicleType(this->type), 0);
 
	SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, WID_VV_START_STOP);
 
	SetWindowDirty(WC_VEHICLE_DETAILS, this->index);
 
@@ -806,13 +806,13 @@ Vehicle::~Vehicle()
 
		this->cargo.OnCleanPool();
 
		return;
 
	}
 

	
 
	/* sometimes, eg. for disaster vehicles, when company bankrupts, when removing crashed/flooded vehicles,
 
	 * it may happen that vehicle chain is deleted when visible */
 
	if (!(this->vehstatus & VS_HIDDEN)) MarkSingleVehicleDirty(this);
 
	if (!(this->vehstatus & VS_HIDDEN)) this->MarkAllViewportsDirty();
 

	
 
	Vehicle *v = this->Next();
 
	this->SetNext(NULL);
 

	
 
	delete v;
 

	
 
@@ -1461,73 +1461,69 @@ void VehicleEnterDepot(Vehicle *v)
 
}
 

	
 

	
 
/**
 
 * Update the position of the vehicle. This will update the hash that tells
 
 *  which vehicles are on a tile.
 
 * @param v The vehicle to update.
 
 */
 
void VehicleUpdatePosition(Vehicle *v)
 
void Vehicle::UpdatePosition()
 
{
 
	UpdateVehicleTileHash(v, false);
 
	UpdateVehicleTileHash(this, false);
 
}
 

	
 
/**
 
 * Update the vehicle on the viewport, updating the right hash and setting the
 
 *  new coordinates.
 
 * @param v The vehicle to update.
 
 * @param dirty Mark the (new and old) coordinates of the vehicle as dirty.
 
 */
 
void VehicleUpdateViewport(Vehicle *v, bool dirty)
 
void Vehicle::UpdateViewport(bool dirty)
 
{
 
	int img = v->cur_image;
 
	Point pt = RemapCoords(v->x_pos + v->x_offs, v->y_pos + v->y_offs, v->z_pos);
 
	int img = this->cur_image;
 
	Point pt = RemapCoords(this->x_pos + this->x_offs, this->y_pos + this->y_offs, this->z_pos);
 
	const Sprite *spr = GetSprite(img, ST_NORMAL);
 

	
 
	pt.x += spr->x_offs;
 
	pt.y += spr->y_offs;
 

	
 
	UpdateVehicleViewportHash(v, pt.x, pt.y);
 

	
 
	Rect old_coord = v->coord;
 
	v->coord.left   = pt.x;
 
	v->coord.top    = pt.y;
 
	v->coord.right  = pt.x + spr->width + 2 * ZOOM_LVL_BASE;
 
	v->coord.bottom = pt.y + spr->height + 2 * ZOOM_LVL_BASE;
 
	UpdateVehicleViewportHash(this, pt.x, pt.y);
 

	
 
	Rect old_coord = this->coord;
 
	this->coord.left   = pt.x;
 
	this->coord.top    = pt.y;
 
	this->coord.right  = pt.x + spr->width + 2 * ZOOM_LVL_BASE;
 
	this->coord.bottom = pt.y + spr->height + 2 * ZOOM_LVL_BASE;
 

	
 
	if (dirty) {
 
		if (old_coord.left == INVALID_COORD) {
 
			MarkSingleVehicleDirty(v);
 
			this->MarkAllViewportsDirty();
 
		} else {
 
			MarkAllViewportsDirty(
 
				min(old_coord.left,   v->coord.left),
 
				min(old_coord.top,    v->coord.top),
 
				max(old_coord.right,  v->coord.right) + 1 * ZOOM_LVL_BASE,
 
				max(old_coord.bottom, v->coord.bottom) + 1 * ZOOM_LVL_BASE
 
			::MarkAllViewportsDirty(
 
				min(old_coord.left,   this->coord.left),
 
				min(old_coord.top,    this->coord.top),
 
				max(old_coord.right,  this->coord.right) + 1 * ZOOM_LVL_BASE,
 
				max(old_coord.bottom, this->coord.bottom) + 1 * ZOOM_LVL_BASE
 
			);
 
		}
 
	}
 
}
 

	
 
/**
 
 * Update the position of the vehicle, and update the viewport.
 
 * @param v The vehicle to update.
 
 */
 
void VehicleUpdatePositionAndViewport(Vehicle *v)
 
void Vehicle::UpdatePositionAndViewport()
 
{
 
	VehicleUpdatePosition(v);
 
	VehicleUpdateViewport(v, true);
 
	this->UpdatePosition();
 
	this->UpdateViewport(true);
 
}
 

	
 
/**
 
 * Marks viewports dirty where the vehicle's image is.
 
 * @param v vehicle to mark dirty
 
 */
 
void MarkSingleVehicleDirty(const Vehicle *v)
 
void Vehicle::MarkAllViewportsDirty() const
 
{
 
	MarkAllViewportsDirty(v->coord.left, v->coord.top, v->coord.right + 1 * ZOOM_LVL_BASE, v->coord.bottom + 1 * ZOOM_LVL_BASE);
 
	::MarkAllViewportsDirty(this->coord.left, this->coord.top, this->coord.right + 1 * ZOOM_LVL_BASE, this->coord.bottom + 1 * ZOOM_LVL_BASE);
 
}
 

	
 
/**
 
 * Get position information of a vehicle when moving one pixel in the direction it is facing
 
 * @param v Vehicle to move
 
 * @return Position information after the move
src/vehicle_base.h
Show inline comments
 
@@ -693,12 +693,17 @@ public:
 

	
 
	CommandCost SendToDepot(DoCommandFlag flags, DepotCommand command);
 

	
 
	void UpdateVisualEffect(bool allow_power_change = true);
 
	void ShowVisualEffect() const;
 

	
 
	void UpdatePosition();
 
	void UpdateViewport(bool dirty);
 
	void UpdatePositionAndViewport();
 
	void MarkAllViewportsDirty() const;
 

	
 
	inline uint16 GetServiceInterval() const { return this->service_interval; }
 

	
 
	inline void SetServiceInterval(uint16 interval) { this->service_interval = interval; }
 

	
 
	inline bool ServiceIntervalIsCustom() const { return HasBit(this->vehicle_flags, VF_SERVINT_IS_CUSTOM); }
 

	
 
@@ -1064,20 +1069,18 @@ struct SpecializedVehicle : public Vehic
 
	 * Update vehicle sprite- and position caches
 
	 * @param force_update Force updating the vehicle on the viewport.
 
	 * @param update_delta Also update the delta?
 
	 */
 
	inline void UpdateViewport(bool force_update, bool update_delta)
 
	{
 
		extern void VehicleUpdateViewport(Vehicle *v, bool dirty);
 

	
 
		/* Explicitly choose method to call to prevent vtable dereference -
 
		 * it gives ~3% runtime improvements in games with many vehicles */
 
		if (update_delta) ((T *)this)->T::UpdateDeltaXY(this->direction);
 
		SpriteID old_image = this->cur_image;
 
		this->cur_image = ((T *)this)->T::GetImage(this->direction, EIT_ON_MAP);
 
		if (force_update || this->cur_image != old_image) VehicleUpdateViewport(this, true);
 
		if (force_update || this->cur_image != old_image) this->Vehicle::UpdateViewport(true);
 
	}
 
};
 

	
 
/**
 
 * Iterate over all vehicles of a particular type.
 
 * @param name The type of vehicle to iterate over.
src/vehicle_func.h
Show inline comments
 
@@ -64,17 +64,12 @@ CommandCost TunnelBridgeIsFree(TileIndex
 

	
 
void DecreaseVehicleValue(Vehicle *v);
 
void CheckVehicleBreakdown(Vehicle *v);
 
void AgeVehicle(Vehicle *v);
 
void VehicleEnteredDepotThisTick(Vehicle *v);
 

	
 
void VehicleUpdatePosition(Vehicle *v);
 
void VehicleUpdateViewport(Vehicle *v, bool dirty);
 
void VehicleUpdatePositionAndViewport(Vehicle *v);
 
void MarkSingleVehicleDirty(const Vehicle *v);
 

	
 
UnitID GetFreeUnitNumber(VehicleType type);
 

	
 
void VehicleEnterDepot(Vehicle *v);
 

	
 
bool CanBuildVehicleInfrastructure(VehicleType type);
 

	
0 comments (0 inline, 0 general)