Changeset - r6608:f2d13a751f0b
[Not reviewed]
master
0 4 0
peter1138 - 17 years ago 2007-05-12 07:05:34
peter1138@openttd.org
(svn r9828) -Codechange: [NewGRF] Add support for changing cargo capacity with callback 36. This is set on construction for ships and roadvehicles, and whenever carriages are attached for trains.
4 files changed with 14 insertions and 7 deletions:
0 comments (0 inline, 0 general)
src/build_vehicle_gui.cpp
Show inline comments
 
@@ -377,25 +377,25 @@ static const StringID _sort_listing[][10
 

	
 
/* Draw rail wagon specific details */
 
static int DrawRailWagonPurchaseInfo(int x, int y, EngineID engine_number, const RailVehicleInfo *rvi)
 
{
 
	/* Purchase cost */
 
	SetDParam(0, (GetEngineProperty(engine_number, 0x17, rvi->base_cost) * _price.build_railwagon) >> 8);
 
	DrawString(x, y, STR_PURCHASE_INFO_COST, 0);
 
	y += 10;
 

	
 
	/* Wagon weight - (including cargo) */
 
	uint weight = GetEngineProperty(engine_number, 0x16, rvi->weight);
 
	SetDParam(0, weight);
 
	SetDParam(1, (GetCargo(rvi->cargo_type)->weight * rvi->capacity >> 4) + weight);
 
	SetDParam(1, (GetCargo(rvi->cargo_type)->weight * GetEngineProperty(engine_number, 0x14, rvi->capacity) >> 4) + weight);
 
	DrawString(x, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT, 0);
 
	y += 10;
 

	
 
	/* Wagon speed limit, displayed if above zero */
 
	if (_patches.wagon_speed_limits) {
 
		uint max_speed = GetEngineProperty(engine_number, 0x09, rvi->max_speed);
 
		if (max_speed > 0) {
 
			SetDParam(0, max_speed * 10 / 16);
 
			DrawString(x, y, STR_PURCHASE_INFO_SPEED, 0);
 
			y += 10;
 
		}
 
	}
 
@@ -452,44 +452,44 @@ static int DrawRoadVehPurchaseInfo(int x
 
	SetDParam(0, GetEngineProperty(engine_number, 0x11, rvi->base_cost) * (_price.roadveh_base >> 3) >> 5);
 
	SetDParam(1, rvi->max_speed * 10 / 32);
 
	DrawString(x, y, STR_PURCHASE_INFO_COST_SPEED, 0);
 
	y += 10;
 

	
 
	/* Running cost */
 
	SetDParam(0, rvi->running_cost * _price.roadveh_running >> 8);
 
	DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
 
	y += 10;
 

	
 
	/* Cargo type + capacity */
 
	SetDParam(0, rvi->cargo_type);
 
	SetDParam(1, rvi->capacity);
 
	SetDParam(1, GetEngineProperty(engine_number, 0x0F, rvi->capacity));
 
	SetDParam(2, refittable ? STR_9842_REFITTABLE : STR_EMPTY);
 
	DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 0);
 
	y += 10;
 

	
 
	return y;
 
}
 

	
 
/* Draw ship specific details */
 
static int DrawShipPurchaseInfo(int x, int y, EngineID engine_number, const ShipVehicleInfo *svi)
 
{
 
	/* Purchase cost - Max speed */
 
	SetDParam(0, GetEngineProperty(engine_number, 0x0A, svi->base_cost) * (_price.ship_base >> 3) >> 5);
 
	SetDParam(1, GetEngineProperty(engine_number, 0x0B, svi->max_speed) * 10 / 32);
 
	DrawString(x, y, STR_PURCHASE_INFO_COST_SPEED, 0);
 
	y += 10;
 

	
 
	/* Cargo type + capacity */
 
	SetDParam(0, svi->cargo_type);
 
	SetDParam(1, svi->capacity);
 
	SetDParam(1, GetEngineProperty(engine_number, 0x0D, svi->capacity));
 
	SetDParam(2, svi->refittable ? STR_9842_REFITTABLE : STR_EMPTY);
 
	DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 0);
 
	y += 10;
 

	
 
	/* Running cost */
 
	SetDParam(0, GetEngineProperty(engine_number, 0x0F, svi->running_cost) * _price.ship_running >> 8);
 
	DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
 
	y += 10;
 

	
 
	return y;
 
}
 

	
 
@@ -536,42 +536,43 @@ static int DrawAircraftPurchaseInfo(int 
 
 * @return y after drawing all the text
 
 */
 
int DrawVehiclePurchaseInfo(int x, int y, uint w, EngineID engine_number)
 
{
 
	const Engine *e = GetEngine(engine_number);
 
	YearMonthDay ymd;
 
	ConvertDateToYMD(e->intro_date, &ymd);
 
	bool refitable = false;
 

	
 
	switch (e->type) {
 
		case VEH_TRAIN: {
 
			const RailVehicleInfo *rvi = RailVehInfo(engine_number);
 
			uint capacity = GetEngineProperty(engine_number, 0x14, rvi->capacity);
 

	
 
			refitable = (EngInfo(engine_number)->refit_mask != 0) && (rvi->capacity > 0);
 
			refitable = (EngInfo(engine_number)->refit_mask != 0) && (capacity > 0);
 

	
 
			if (rvi->railveh_type == RAILVEH_WAGON) {
 
				y = DrawRailWagonPurchaseInfo(x, y, engine_number, rvi);
 
			} else {
 
				y = DrawRailEnginePurchaseInfo(x, y, engine_number, rvi);
 
			}
 

	
 
			/* Cargo type + capacity, or N/A */
 
			if (rvi->capacity == 0) {
 
				SetDParam(0, CT_INVALID);
 
				SetDParam(2, STR_EMPTY);
 
			} else {
 
				int multihead = (rvi->railveh_type == RAILVEH_MULTIHEAD ? 1 : 0);
 

	
 
				SetDParam(0, rvi->cargo_type);
 
				SetDParam(1, (rvi->capacity * (CountArticulatedParts(engine_number) + 1)) << multihead);
 
				SetDParam(1, (capacity * (CountArticulatedParts(engine_number) + 1)) << multihead);
 
				SetDParam(2, refitable ? STR_9842_REFITTABLE : STR_EMPTY);
 
			}
 
			DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 0);
 
			y += 10;
 
		}
 
			break;
 
		case VEH_ROAD:
 
			y = DrawRoadVehPurchaseInfo(x, y, engine_number, RoadVehInfo(engine_number));
 
			refitable = true;
 
			break;
 
		case VEH_SHIP: {
 
			const ShipVehicleInfo *svi = ShipVehInfo(engine_number);
src/roadveh_cmd.cpp
Show inline comments
 
@@ -202,24 +202,26 @@ int32 CmdBuildRoadVeh(TileIndex tile, ui
 
		v->service_interval = _patches.servint_roadveh;
 

	
 
		v->date_of_last_service = _date;
 
		v->build_year = _cur_year;
 

	
 
		v = new (v) RoadVehicle();
 
		v->cur_image = 0xC15;
 
		v->random_bits = VehicleRandomBits();
 

	
 
		v->vehicle_flags = 0;
 
		if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SETBIT(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
 

	
 
		v->cargo_cap = GetVehicleProperty(v, 0x0F, rvi->capacity);
 

	
 
		VehiclePositionChanged(v);
 

	
 
		InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
 
		RebuildVehicleLists();
 
		InvalidateWindow(WC_COMPANY, v->owner);
 
		if (IsLocalPlayer())
 
			InvalidateAutoreplaceWindow(VEH_ROAD); // updates the replace Road window
 

	
 
		GetPlayer(_current_player)->num_engines[p1]++;
 
	}
 

	
 
	return cost;
 
@@ -1840,25 +1842,25 @@ int32 CmdRefitRoadVeh(TileIndex tile, ui
 
		v->cargo_subtype = temp_subtype;
 
	}
 

	
 
	if (capacity == CALLBACK_FAILED) {
 
		/* callback failed or not used, use default capacity */
 
		const RoadVehicleInfo *rvi = RoadVehInfo(v->engine_type);
 

	
 
		CargoID old_cid = rvi->cargo_type;
 
		/* normally, the capacity depends on the cargo type, a vehicle can
 
		 * carry twice as much mail/goods as normal cargo, and four times as
 
		 * many passengers
 
		 */
 
		capacity = rvi->capacity;
 
		capacity = GetVehicleProperty(v, 0x0F, rvi->capacity);
 
		switch (old_cid) {
 
			case CT_PASSENGERS: break;
 
			case CT_MAIL:
 
			case CT_GOODS: capacity *= 2; break;
 
			default:       capacity *= 4; break;
 
		}
 
		switch (new_cid) {
 
			case CT_PASSENGERS: break;
 
			case CT_MAIL:
 
			case CT_GOODS: capacity /= 2; break;
 
			default:       capacity /= 4; break;
 
		}
src/ship_cmd.cpp
Show inline comments
 
@@ -869,24 +869,26 @@ int32 CmdBuildShip(TileIndex tile, uint3
 
		v->u.ship.state = TRACK_BIT_DEPOT;
 

	
 
		v->service_interval = _patches.servint_ships;
 
		v->date_of_last_service = _date;
 
		v->build_year = _cur_year;
 
		v->cur_image = 0x0E5E;
 
		v = new (v) Ship();
 
		v->random_bits = VehicleRandomBits();
 

	
 
		v->vehicle_flags = 0;
 
		if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SETBIT(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
 

	
 
		v->cargo_cap = GetVehicleProperty(v, 0x0D, svi->capacity);
 

	
 
		VehiclePositionChanged(v);
 

	
 
		InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
 
		RebuildVehicleLists();
 
		InvalidateWindow(WC_COMPANY, v->owner);
 
		if (IsLocalPlayer())
 
			InvalidateAutoreplaceWindow(VEH_SHIP); // updates the replace Ship window
 

	
 
		GetPlayer(_current_player)->num_engines[p1]++;
 
	}
 

	
 
	return value;
 
@@ -1081,25 +1083,25 @@ int32 CmdRefitShip(TileIndex tile, uint3
 
		byte temp_subtype = v->cargo_subtype;
 
		v->cargo_type = new_cid;
 
		v->cargo_subtype = new_subtype;
 

	
 
		capacity = GetVehicleCallback(CBID_VEHICLE_REFIT_CAPACITY, 0, 0, v->engine_type, v);
 

	
 
		/* Restore the cargo type */
 
		v->cargo_type = temp_cid;
 
		v->cargo_subtype = temp_subtype;
 
	}
 

	
 
	if (capacity == CALLBACK_FAILED) {
 
		capacity = ShipVehInfo(v->engine_type)->capacity;
 
		capacity = GetVehicleProperty(v, 0x0D, ShipVehInfo(v->engine_type)->capacity);
 
	}
 
	_returned_refit_capacity = capacity;
 

	
 
	cost = 0;
 
	if (IsHumanPlayer(v->owner) && new_cid != v->cargo_type) {
 
		cost = GetRefitCost(v->engine_type);
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		v->cargo_cap = capacity;
 
		v->cargo_count = (v->cargo_type == new_cid) ? min(v->cargo_cap, v->cargo_count) : 0;
 
		v->cargo_type = new_cid;
src/train_cmd.cpp
Show inline comments
 
@@ -211,24 +211,26 @@ void TrainConsistChanged(Vehicle* v)
 
			if (HASBIT(u->u.rail.flags, VRF_EL_ENGINE_ALLOWED_NORMAL_RAIL)) {
 
				u->u.rail.railtype = RAILTYPE_RAIL;
 
				u->u.rail.compatible_railtypes |= (1 << RAILTYPE_RAIL);
 
			}
 

	
 
			/* max speed is the minimum of the speed limits of all vehicles in the consist */
 
			if ((rvi_u->railveh_type != RAILVEH_WAGON || _patches.wagon_speed_limits) && !UsesWagonOverride(u)) {
 
				uint16 speed = GetVehicleProperty(u, 0x09, rvi_u->max_speed);
 
				if (speed != 0) max_speed = min(speed, max_speed);
 
			}
 
		}
 

	
 
		u->cargo_cap = GetVehicleProperty(u, 0x14, rvi_u->capacity);
 

	
 
		/* check the vehicle length (callback) */
 
		uint16 veh_len = CALLBACK_FAILED;
 
		if (HASBIT(EngInfo(u->engine_type)->callbackmask, CBM_VEHICLE_LENGTH)) {
 
			veh_len = GetVehicleCallback(CBID_TRAIN_VEHICLE_LENGTH, 0, 0, u->engine_type, u);
 
		}
 
		if (veh_len == CALLBACK_FAILED) veh_len = rvi_u->shorten_factor;
 
		veh_len = clamp(veh_len, 0, u->next == NULL ? 7 : 5); // the clamp on vehicles not the last in chain is stricter, as too short wagons can break the 'follow next vehicle' code
 
		u->u.rail.cached_veh_length = 8 - veh_len;
 
		v->u.rail.cached_total_length += u->u.rail.cached_veh_length;
 
	}
 

	
 
	/* store consist weight/max speed in cache */
0 comments (0 inline, 0 general)