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
 
@@ -328,47 +328,47 @@ CommandCost CmdBuildAircraft(TileIndex t
 
		v->vehicle_flags = 0;
 
		if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SetBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
 
		v->SetServiceIntervalIsPercent(Company::Get(_current_company)->settings.vehicle.servint_ispercent);
 

	
 
		v->InvalidateNewGRFCacheOfChain();
 

	
 
		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;
 
			w->owner = _current_company;
 
			w->x_pos = v->x_pos;
 
			w->y_pos = v->y_pos;
 
			w->z_pos = v->z_pos + ROTOR_Z_OFFSET;
 
			w->vehstatus = VS_HIDDEN | VS_UNCLICKABLE;
 
			w->spritenum = 0xFF;
 
			w->subtype = AIR_ROTOR;
 
			w->cur_image = SPR_ROTOR_STOPPED;
 
			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();
 
}
 

	
 

	
 
bool Aircraft::FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse)
 
{
 
	const Station *st = GetTargetAirportIfValid(this);
 
	/* If the station is not a valid airport or if it has no hangars */
 
	if (st == NULL || !st->airport.HasHangar()) {
 
@@ -478,64 +478,64 @@ static void HelicopterTickHandler(Aircra
 
		if (u->cur_image == img) return;
 
	} else if (tick >= spd) {
 
		u->tick_counter = 0;
 
		u->state++;
 
		if (u->state > HRS_ROTOR_MOVING_3) u->state = HRS_ROTOR_MOVING_1;
 
		img = GetRotorImage(v, EIT_ON_MAP);
 
	} else {
 
		return;
 
	}
 

	
 
	u->cur_image = img;
 

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

	
 
/**
 
 * Set aircraft position.
 
 * @param v Aircraft to position.
 
 * @param x New X position.
 
 * @param y New y position.
 
 * @param z New z position.
 
 */
 
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);
 
	int safe_y = Clamp(y - 1, 0, MapMaxY() * TILE_SIZE);
 
	u->x_pos = x;
 
	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
 
 */
 
void HandleAircraftEnterHangar(Aircraft *v)
 
{
 
	v->subspeed = 0;
 
	v->progress = 0;
 

	
src/articulated_vehicles.cpp
Show inline comments
 
@@ -436,15 +436,15 @@ void AddArticulatedParts(Vehicle *first)
 
		v->build_year = first->build_year;
 
		v->vehstatus = first->vehstatus & ~VS_STOPPED;
 

	
 
		v->cargo_subtype = 0;
 
		v->max_age = 0;
 
		v->engine_type = engine_type;
 
		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
 
@@ -142,56 +142,56 @@ static void InitializeDisasterVehicle(Di
 
	v->y_pos = y;
 
	v->z_pos = z;
 
	v->tile = TileVirtXY(x, y);
 
	v->direction = direction;
 
	v->subtype = subtype;
 
	v->UpdateDeltaXY(INVALID_DIR);
 
	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);
 

	
 
		u->x_pos = x;
 
		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:
 
 * 0: Zeppeliner initialization has found a small airport, go there and crash
 
 * 1: Create crash and animate falling down for extra dramatic effect
 
 * 2: Create more smoke and leave debris on ground
 
 * 2: Clear the runway after some time and remove crashed zeppeliner
 
 * If not airport was found, only state 0 is reached until zeppeliner leaves map
 
 */
 
@@ -467,25 +467,25 @@ static bool DisasterTick_Helicopter(Disa
 
{
 
	return DisasterTick_Aircraft(v, SPR_AH_64A_FIRING, false, STR_NEWS_DISASTER_HELICOPTER_FACTORY, INDUSTRYBEH_CHOPPER_ATTACKS);
 
}
 

	
 
/** Helicopter rotor blades; keep these spinning */
 
static bool DisasterTick_Helicopter_Rotors(DisasterVehicle *v)
 
{
 
	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:
 
 * 0: Fly around to the middle of the map, then randomly for a while and home in on a piece of rail
 
 * 1: Land there and breakdown all trains in a radius of 12 tiles; and now we wait...
 
 *    because as soon as the Ufo lands, a fighter jet, a Skyranger, is called to clear up the mess
 
 */
 
static bool DisasterTick_Big_Ufo(DisasterVehicle *v)
 
{
src/effectvehicle.cpp
Show inline comments
 
@@ -37,25 +37,25 @@ static bool ChimneySmokeTick(EffectVehic
 
		TileIndex tile = TileVirtXY(v->x_pos, v->y_pos);
 
		if (!IsTileType(tile, MP_INDUSTRY)) {
 
			delete v;
 
			return false;
 
		}
 

	
 
		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)
 
{
 
	v->cur_image = SPR_STEAM_SMOKE_0;
 
	v->progress = 12;
 
}
 

	
 
static bool SteamSmokeTick(EffectVehicle *v)
 
@@ -70,70 +70,70 @@ static bool SteamSmokeTick(EffectVehicle
 
	}
 

	
 
	if ((v->progress & 0xF) == 4) {
 
		if (v->cur_image != SPR_STEAM_SMOKE_4) {
 
			v->cur_image++;
 
		} else {
 
			delete v;
 
			return false;
 
		}
 
		moved = true;
 
	}
 

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

	
 
	return true;
 
}
 

	
 
static void DieselSmokeInit(EffectVehicle *v)
 
{
 
	v->cur_image = SPR_DIESEL_SMOKE_0;
 
	v->progress = 0;
 
}
 

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

	
 
	return true;
 
}
 

	
 
static void ElectricSparkInit(EffectVehicle *v)
 
{
 
	v->cur_image = SPR_ELECTRIC_SPARK_0;
 
	v->progress = 1;
 
}
 

	
 
static bool ElectricSparkTick(EffectVehicle *v)
 
{
 
	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;
 
		}
 
	}
 

	
 
	return true;
 
}
 

	
 
static void SmokeInit(EffectVehicle *v)
 
{
 
	v->cur_image = SPR_SMOKE_0;
 
@@ -152,91 +152,91 @@ static bool SmokeTick(EffectVehicle *v)
 
	}
 

	
 
	if ((v->progress & 0xF) == 4) {
 
		if (v->cur_image != SPR_SMOKE_4) {
 
			v->cur_image++;
 
		} else {
 
			delete v;
 
			return false;
 
		}
 
		moved = true;
 
	}
 

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

	
 
	return true;
 
}
 

	
 
static void ExplosionLargeInit(EffectVehicle *v)
 
{
 
	v->cur_image = SPR_EXPLOSION_LARGE_0;
 
	v->progress = 0;
 
}
 

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

	
 
	return true;
 
}
 

	
 
static void BreakdownSmokeInit(EffectVehicle *v)
 
{
 
	v->cur_image = SPR_BREAKDOWN_SMOKE_0;
 
	v->progress = 0;
 
}
 

	
 
static bool BreakdownSmokeTick(EffectVehicle *v)
 
{
 
	v->progress++;
 
	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;
 
	}
 

	
 
	return true;
 
}
 

	
 
static void ExplosionSmallInit(EffectVehicle *v)
 
{
 
	v->cur_image = SPR_EXPLOSION_SMALL_0;
 
	v->progress = 0;
 
}
 

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

	
 
	return true;
 
}
 

	
 
static void BulldozerInit(EffectVehicle *v)
 
{
 
	v->cur_image = SPR_BULLDOZER_NE;
 
@@ -295,25 +295,25 @@ static bool BulldozerTick(EffectVehicle 
 
		v->x_pos += _inc_by_dir[b->direction].x;
 
		v->y_pos += _inc_by_dir[b->direction].y;
 

	
 
		v->animation_substate++;
 
		if (v->animation_substate >= b->duration) {
 
			v->animation_substate = 0;
 
			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)
 
{
 
	v->cur_image = SPR_BUBBLE_GENERATE_0;
 
	v->spritenum = 0;
 
	v->progress = 0;
 
}
 

	
 
@@ -468,25 +468,25 @@ static const BubbleMovement * const _bub
 
};
 

	
 
static bool BubbleTick(EffectVehicle *v)
 
{
 
	uint anim_state;
 

	
 
	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;
 
		}
 
		anim_state = 0;
 
	} else {
 
		anim_state = v->animation_state + 1;
 
	}
 

	
 
@@ -514,25 +514,25 @@ static bool BubbleTick(EffectVehicle *v)
 
		tile = TileVirtXY(v->x_pos, v->y_pos);
 
		if (IsTileType(tile, MP_INDUSTRY) && GetIndustryGfx(tile) == GFX_BUBBLE_CATCHER) AddAnimatedTile(tile);
 
	}
 

	
 
	v->animation_state = anim_state;
 
	b = &_bubble_movement[v->spritenum - 1][anim_state];
 

	
 
	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);
 
typedef bool EffectTickProc(EffectVehicle *v);
 

	
 
/** Functions to initialise an effect vehicle after construction. */
 
static EffectInitProc * const _effect_init_procs[] = {
 
	ChimneySmokeInit,   // EV_CHIMNEY_SMOKE
 
	SteamSmokeInit,     // EV_STEAM_SMOKE
 
@@ -598,25 +598,25 @@ EffectVehicle *CreateEffectVehicle(int x
 

	
 
	EffectVehicle *v = new EffectVehicle();
 
	v->subtype = type;
 
	v->x_pos = x;
 
	v->y_pos = y;
 
	v->z_pos = z;
 
	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.
 
 * @param x The x location on the map.
 
 * @param y The y location on the map.
 
 * @param z The offset from the ground.
 
 * @param type The type of effect vehicle.
 
 * @return The effect vehicle.
 
 */
src/roadveh_cmd.cpp
Show inline comments
 
@@ -320,25 +320,25 @@ CommandCost CmdBuildRoadVehicle(TileInde
 

	
 
		/* Call various callbacks after the whole consist has been constructed */
 
		for (RoadVehicle *u = v; u != NULL; u = u->Next()) {
 
			u->cargo_cap = u->GetEngine()->DetermineCapacity(u);
 
			u->refit_cap = 0;
 
			v->InvalidateNewGRFCache();
 
			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();
 
}
 

	
 
static FindDepotData FindClosestRoadDepot(const RoadVehicle *v, int max_distance)
 
{
 
	if (IsRoadDepotTile(v->tile)) return FindDepotData(v->tile, 0);
 

	
 
	switch (_settings_game.pf.pathfinder_for_roadvehs) {
 
@@ -1008,25 +1008,25 @@ static bool RoadVehLeaveDepot(RoadVehicl
 
		StartRoadVehSound(v);
 

	
 
		/* Vehicle is about to leave a depot */
 
		v->cur_speed = 0;
 
	}
 

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

	
 
static Trackdir FollowPreviousRoadVehicle(const RoadVehicle *v, const RoadVehicle *prev, TileIndex tile, DiagDirection entry_dir, bool already_reversed)
 
{
 
	if (prev->tile == v->tile && !already_reversed) {
 
		/* If the previous vehicle is on the same tile as this vehicle is
 
		 * then it must have reversed. */
 
@@ -1137,33 +1137,33 @@ bool IndividualRoadVehicleController(Roa
 
		if (v->IsFrontEngine()) {
 
			const Vehicle *u = RoadVehFindCloseTo(v, gp.x, gp.y, v->direction);
 
			if (u != NULL) {
 
				v->cur_speed = u->First()->cur_speed;
 
				return false;
 
			}
 
		}
 

	
 
		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. */
 
	RoadDriveEntry rd = _road_drive_data[v->roadtype][(
 
		(HasBit(v->state, RVS_IN_DT_ROAD_STOP) ? v->state & RVSB_ROAD_STOP_TRACKDIR_MASK : v->state) +
 
		(_settings_game.vehicle.road_side << RVS_DRIVE_SIDE)) ^ v->overtaking][v->frame + 1];
 

	
 
	if (rd.x & RDE_NEXT_TILE) {
 
		TileIndex tile = v->tile + TileOffsByDiagDir((DiagDirection)(rd.x & 3));
 
@@ -1294,25 +1294,25 @@ again:
 

	
 
		if (!HasBit(r, VETS_ENTERED_WORMHOLE)) {
 
			v->tile = tile;
 
			v->state = (byte)dir;
 
			v->frame = start_frame;
 
		}
 
		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 */
 
		Trackdir dir;
 
		uint turn_around_start_frame = RVC_TURN_AROUND_START_FRAME;
 

	
 
		if (v->roadtype == ROADTYPE_TRAM && !IsRoadDepotTile(v->tile) && HasExactlyOneBit(GetAnyRoadBits(v->tile, ROADTYPE_TRAM, true))) {
 
			/*
 
			 * The tram is turning around with one tram 'roadbit'. This means that
 
@@ -1360,25 +1360,25 @@ again:
 
		}
 

	
 
		v->state = dir;
 
		v->frame = turn_around_start_frame;
 

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

	
 
	/* 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
 
	 * the chain yet. */
 
	if (v->Next() != NULL && IsRoadDepotTile(v->tile)) {
 
		if (v->frame == v->gcache.cached_veh_length + RVC_DEPOT_START_FRAME) {
 
			RoadVehLeaveDepot(v->Next(), false);
 
		}
 
	}
 
@@ -1448,25 +1448,25 @@ again:
 
		 * so if we get here the vehicle has just arrived or is just ready to leave. */
 
		if (!HasBit(v->state, RVS_ENTERED_STOP)) {
 
			/* Vehicle has arrived at a bay in a road stop */
 

	
 
			if (IsDriveThroughStopTile(v->tile)) {
 
				TileIndex next_tile = TILE_ADD(v->tile, TileOffsByDir(v->direction));
 

	
 
				/* 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);
 
			SetBit(v->state, RVS_ENTERED_STOP);
 

	
 
			v->last_station_visited = st->index;
 

	
 
			if (IsDriveThroughStopTile(v->tile) || (v->current_order.IsType(OT_GOTO_STATION) && v->current_order.GetDestination() == st->index)) {
 
				RoadVehArrivesAt(v, st);
 
@@ -1497,25 +1497,25 @@ again:
 
		return false;
 
	}
 

	
 
	if (v->current_order.IsType(OT_LEAVESTATION) && IsDriveThroughStopTile(v->tile)) {
 
		v->current_order.Free();
 
	}
 

	
 
	/* 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)
 
{
 
	/* decrease counters */
 
	v->current_order_time++;
 
	if (v->reverse_ctr != 0) v->reverse_ctr--;
 

	
 
	/* handle crashed */
 
	if (v->vehstatus & VS_CRASHED || RoadVehCheckTrainCrash(v)) {
src/saveload/vehicle_sl.cpp
Show inline comments
 
@@ -450,26 +450,26 @@ void AfterLoadVehicles(bool part_of_load
 
						Vehicle *rotor = shadow->Next();
 
						rotor->cur_image = GetRotorImage(Aircraft::From(v), EIT_ON_MAP);
 
					}
 

	
 
					UpdateAircraftCache(Aircraft::From(v), true);
 
				}
 
				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);
 

	
 
/** Fixup old train spacing. */
 
void FixupTrainLengths()
 
{
 
	/* Vehicle center was moved from 4 units behind the front to half the length
 
	 * behind the front. Move vehicles so they end up on the same spot. */
src/ship_cmd.cpp
Show inline comments
 
@@ -616,38 +616,38 @@ static void ShipController(Ship *v)
 
				WaterClass old_wc = GetEffectiveWaterClass(gp.old_tile);
 
				WaterClass new_wc = GetEffectiveWaterClass(gp.new_tile);
 
				if (old_wc != new_wc) v->UpdateCache();
 
			}
 

	
 
			v->direction = (Direction)b[2];
 
		}
 
	} 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;
 
	goto getout;
 
}
 

	
 
bool Ship::Tick()
 
{
 
	if (!(this->vehstatus & VS_STOPPED)) this->running_ticks++;
 
@@ -713,25 +713,25 @@ CommandCost CmdBuildShip(TileIndex tile,
 

	
 
		v->UpdateCache();
 

	
 
		if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SetBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
 
		v->SetServiceIntervalIsPercent(Company::Get(_current_company)->settings.vehicle.servint_ispercent);
 

	
 
		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)
 
{
 
	const Depot *depot = FindClosestShipDepot(this, 0);
 

	
 
	if (depot == NULL) return false;
 

	
 
	if (location    != NULL) *location    = depot->xy;
src/train_cmd.cpp
Show inline comments
 
@@ -633,25 +633,25 @@ static CommandCost CmdBuildRailWagon(Til
 
		v->railtype = rvi->railtype;
 

	
 
		v->build_year = _cur_year;
 
		v->cur_image = SPR_IMG_QUERY;
 
		v->random_bits = VehicleRandomBits();
 

	
 
		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. */
 
		Train *w;
 
		FOR_ALL_TRAINS(w) {
 
			if (w->tile == tile &&              ///< Same depot
 
					w->IsFreeWagon() &&             ///< A free wagon chain
 
					w->engine_type == e->index &&   ///< Same type
 
					w->First() != v &&              ///< Don't connect to ourself
 
@@ -696,25 +696,25 @@ static void AddRearEngineToMultiheadedTr
 
	u->cargo_type = v->cargo_type;
 
	u->cargo_subtype = v->cargo_subtype;
 
	u->cargo_cap = v->cargo_cap;
 
	u->refit_cap = v->refit_cap;
 
	u->railtype = v->railtype;
 
	u->engine_type = v->engine_type;
 
	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;
 
}
 

	
 
/**
 
 * Build a railroad vehicle.
 
 * @param tile     tile of the depot where rail-vehicle is built.
 
 * @param flags    type of operation.
 
 * @param e        the engine to build.
 
 * @param data     bit 0 prevents any free cars from being added to the train.
 
@@ -768,25 +768,25 @@ CommandCost CmdBuildRailVehicle(TileInde
 
		v->build_year = _cur_year;
 
		v->cur_image = SPR_IMG_QUERY;
 
		v->random_bits = VehicleRandomBits();
 

	
 
		if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SetBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
 
		v->SetServiceIntervalIsPercent(Company::Get(_current_company)->settings.vehicle.servint_ispercent);
 

	
 
		v->group_id = DEFAULT_GROUP;
 

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

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

	
 
		if (rvi->railveh_type == RAILVEH_MULTIHEAD) {
 
			AddRearEngineToMultiheadedTrain(v);
 
		} else {
 
			AddArticulatedParts(v);
 
		}
 

	
 
		v->ConsistChanged(CCF_ARRANGE);
 
		UpdateTrainGroupID(v);
 

	
 
		if (!HasBit(data, 0) && !(flags & DC_AUTOREPLACE)) { // check if the cars should be added to the new vehicle
 
			NormalizeTrainVehInDepot(v);
 
@@ -1556,32 +1556,32 @@ static void UpdateStatusAfterSwap(Train 
 
	} else {
 
		/* VehicleEnter_TunnelBridge() sets TRACK_BIT_WORMHOLE when the vehicle
 
		 * is on the last bit of the bridge head (frame == TILE_SIZE - 1).
 
		 * If we were swapped with such a vehicle, we have set TRACK_BIT_WORMHOLE,
 
		 * when we shouldn't have. Check if this is the case. */
 
		TileIndex vt = TileVirtXY(v->x_pos, v->y_pos);
 
		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.
 
 * @param l %Vehicle index in the consist of the first vehicle.
 
 * @param r %Vehicle index in the consist of the second vehicle.
 
 */
 
void ReverseTrainSwapVeh(Train *v, int l, int r)
 
{
 
	Train *a, *b;
 
@@ -2174,25 +2174,25 @@ static bool CheckTrainStayInDepot(Train 
 

	
 
	VehicleServiceInDepot(v);
 
	SetWindowClassesDirty(WC_TRAINS_LIST);
 
	v->PlayLeaveStationSound();
 

	
 
	v->track = TRACK_BIT_X;
 
	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;
 
}
 

	
 
/**
 
 * Clear the reservation of \a tile that was just left by a wagon on \a track_dir.
 
 * @param v %Train owning the reservation.
 
 * @param tile Tile with reservation to clear.
 
 * @param track_dir Track direction to clear.
 
@@ -3325,36 +3325,36 @@ bool TrainController(Train *v, Vehicle *
 
				if (v->IsFrontEngine()) {
 
					TryReserveRailTrack(gp.new_tile, DiagDirToDiagTrack(GetTunnelBridgeDirection(gp.new_tile)));
 
					CheckNextTrainTile(v);
 
				}
 
				/* Prevent v->UpdateInclination() being called with wrong parameters.
 
				 * This could happen if the train was reversed inside the tunnel/bridge. */
 
				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 */
 
			AffectSpeedByZChange(v, old_z);
 
		}
 

	
 
		if (update_signals_crossing) {
 
			if (v->IsFrontEngine()) {
 
				if (TrainMovedChangeSignals(gp.new_tile, enterdir)) {
 
@@ -3506,25 +3506,25 @@ static void ChangeTrainDirRandomly(Train
 
	};
 

	
 
	do {
 
		/* We don't need to twist around vehicles if they're not visible */
 
		if (!(v->vehstatus & VS_HIDDEN)) {
 
			v->direction = ChangeDir(v->direction, delta[GB(Random(), 0, 2)]);
 
			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);
 
}
 

	
 
/**
 
 * Handle a crashed train.
 
 * @param v First train vehicle.
 
 * @return %Vehicle chain still exists.
 
 */
 
static bool HandleCrashedTrain(Train *v)
src/vehicle.cpp
Show inline comments
 
@@ -197,25 +197,25 @@ uint Vehicle::Crash(bool flooded)
 
{
 
	assert((this->vehstatus & VS_CRASHED) == 0);
 
	assert(this->Previous() == NULL); // IsPrimaryVehicle fails for free-wagon-chains
 

	
 
	uint pass = 0;
 
	/* Stop the vehicle. */
 
	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);
 
	SetWindowDirty(WC_VEHICLE_DEPOT, this->tile);
 

	
 
	delete this->cargo_payment;
 
	this->cargo_payment = NULL;
 

	
 
	return RandomRange(pass + 1); // Randomise deceased passengers.
 
@@ -800,25 +800,25 @@ void Vehicle::PreDestructor()
 
	ReleaseDisastersTargetingVehicle(this->index);
 
}
 

	
 
Vehicle::~Vehicle()
 
{
 
	if (CleaningPool()) {
 
		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;
 

	
 
	UpdateVehicleTileHash(this, true);
 
	UpdateVehicleViewportHash(this, INVALID_COORD, 0);
 
	DeleteVehicleNews(this->index, INVALID_STRING_ID);
 
	DeleteNewGRFInspectWindow(GetGrfSpecFeature(this->type), this->index);
 
}
 

	
 
@@ -1455,85 +1455,81 @@ void VehicleEnterDepot(Vehicle *v)
 
				AddVehicleAdviceNewsItem(STR_NEWS_TRAIN_IS_WAITING + v->type, v->index);
 
			}
 
			AI::NewEvent(v->owner, new ScriptEventVehicleWaitingInDepot(v->index));
 
		}
 
		v->current_order.MakeDummy();
 
	}
 
}
 

	
 

	
 
/**
 
 * 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
 
 */
 
GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v)
 
{
 
	static const int8 _delta_coord[16] = {
 
		-1,-1,-1, 0, 1, 1, 1, 0, /* x */
 
		-1, 0, 1, 1, 1, 0,-1,-1, /* y */
src/vehicle_base.h
Show inline comments
 
@@ -687,24 +687,29 @@ public:
 
	 * @param location    where do we go to?
 
	 * @param destination what hangar do we go to?
 
	 * @param reverse     should the vehicle be reversed?
 
	 * @return true if a depot could be found.
 
	 */
 
	virtual bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse) { return false; }
 

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

	
 
	inline bool ServiceIntervalIsPercent() const { return HasBit(this->vehicle_flags, VF_SERVINT_IS_PERCENT); }
 

	
 
	inline void SetServiceIntervalIsCustom(bool on) { SB(this->vehicle_flags, VF_SERVINT_IS_CUSTOM, 1, on); }
 

	
 
	inline void SetServiceIntervalIsPercent(bool on) { SB(this->vehicle_flags, VF_SERVINT_IS_PERCENT, 1, on); }
 

	
 
@@ -1058,32 +1063,30 @@ struct SpecializedVehicle : public Vehic
 
	{
 
		assert(v->type == Type);
 
		return (const T *)v;
 
	}
 

	
 
	/**
 
	 * 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.
 
 * @param var  The variable used to iterate over.
 
 */
 
#define FOR_ALL_VEHICLES_OF_TYPE(name, var) FOR_ALL_ITEMS_FROM(name, vehicle_index, var, 0) if (var->type == name::EXPECTED_TYPE)
 

	
 
/**
 
 * Disasters, like submarines, skyrangers and their shadows, belong to this class.
src/vehicle_func.h
Show inline comments
 
@@ -58,29 +58,24 @@ void ResetVehicleColourMap();
 
byte GetBestFittingSubType(Vehicle *v_from, Vehicle *v_for, CargoID dest_cargo_type);
 

	
 
void ViewportAddVehicles(DrawPixelInfo *dpi);
 

	
 
void ShowNewGrfVehicleError(EngineID engine, StringID part1, StringID part2, GRFBugs bug_type, bool critical);
 
CommandCost TunnelBridgeIsFree(TileIndex tile, TileIndex endtile, const Vehicle *ignore = NULL);
 

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

	
 
/** Position information of a vehicle after it moved */
 
struct GetNewVehiclePosResult {
 
	int x, y;  ///< x and y position of the vehicle after moving
 
	TileIndex old_tile; ///< Current tile of the vehicle
 
	TileIndex new_tile; ///< Tile of the vehicle after moving
 
};
0 comments (0 inline, 0 general)