mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r3101) -Codechange: added _new_vehicle_id
this var works like _new_train_id and the rest of that kind of vars, except it is set each time a vehicle is build, nomatter what type this is a nice tool to code vehicle independent code, which in turn can reduce code duplication Right now it's used in ReplaceVehicle() and CmdCloneVehicle()
This commit is contained in:
parent
76f4c5b6f9
commit
6d41c23cf2
|
@ -251,6 +251,7 @@ int32 CmdBuildAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
v->max_age = e->lifelength * 366;
|
v->max_age = e->lifelength * 366;
|
||||||
|
|
||||||
_new_aircraft_id = v->index;
|
_new_aircraft_id = v->index;
|
||||||
|
_new_vehicle_id = v->index;
|
||||||
|
|
||||||
v->u.air.pos = MAX_ELEMENTS;
|
v->u.air.pos = MAX_ELEMENTS;
|
||||||
|
|
||||||
|
|
|
@ -176,6 +176,7 @@ int32 CmdBuildRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
v->reliability_spd_dec = e->reliability_spd_dec;
|
v->reliability_spd_dec = e->reliability_spd_dec;
|
||||||
v->max_age = e->lifelength * 366;
|
v->max_age = e->lifelength * 366;
|
||||||
_new_roadveh_id = v->index;
|
_new_roadveh_id = v->index;
|
||||||
|
_new_vehicle_id = v->index;
|
||||||
|
|
||||||
v->string_id = STR_SV_ROADVEH_NAME;
|
v->string_id = STR_SV_ROADVEH_NAME;
|
||||||
|
|
||||||
|
|
|
@ -907,6 +907,7 @@ int32 CmdBuildShip(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
v->reliability_spd_dec = e->reliability_spd_dec;
|
v->reliability_spd_dec = e->reliability_spd_dec;
|
||||||
v->max_age = e->lifelength * 366;
|
v->max_age = e->lifelength * 366;
|
||||||
_new_ship_id = v->index;
|
_new_ship_id = v->index;
|
||||||
|
_new_vehicle_id = v->index;
|
||||||
|
|
||||||
v->string_id = STR_SV_SHIP_NAME;
|
v->string_id = STR_SV_SHIP_NAME;
|
||||||
v->u.ship.state = 0x80;
|
v->u.ship.state = 0x80;
|
||||||
|
|
|
@ -471,6 +471,7 @@ static int32 CmdBuildRailWagon(EngineID engine, TileIndex tile, uint32 flags)
|
||||||
v->cur_image = 0xAC2;
|
v->cur_image = 0xAC2;
|
||||||
|
|
||||||
_new_wagon_id = v->index;
|
_new_wagon_id = v->index;
|
||||||
|
_new_vehicle_id = v->index;
|
||||||
|
|
||||||
VehiclePositionChanged(v);
|
VehiclePositionChanged(v);
|
||||||
TrainConsistChanged(GetFirstVehicleInChain(v));
|
TrainConsistChanged(GetFirstVehicleInChain(v));
|
||||||
|
@ -632,6 +633,7 @@ int32 CmdBuildRailVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
v->string_id = STR_SV_TRAIN_NAME;
|
v->string_id = STR_SV_TRAIN_NAME;
|
||||||
v->u.rail.railtype = e->railtype;
|
v->u.rail.railtype = e->railtype;
|
||||||
_new_train_id = v->index;
|
_new_train_id = v->index;
|
||||||
|
_new_vehicle_id = v->index;
|
||||||
|
|
||||||
v->service_interval = _patches.servint_trains;
|
v->service_interval = _patches.servint_trains;
|
||||||
v->date_of_last_service = _date;
|
v->date_of_last_service = _date;
|
||||||
|
|
22
vehicle.c
22
vehicle.c
|
@ -1403,13 +1403,6 @@ void AgeVehicle(Vehicle *v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static VehicleID * _new_vehicle_id_proc_table[] = {
|
|
||||||
&_new_train_id,
|
|
||||||
&_new_roadveh_id,
|
|
||||||
&_new_ship_id,
|
|
||||||
&_new_aircraft_id,
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Clone a vehicle. If it is a train, it will clone all the cars too
|
/** Clone a vehicle. If it is a train, it will clone all the cars too
|
||||||
* @param x,y depot where the cloned vehicle is build
|
* @param x,y depot where the cloned vehicle is build
|
||||||
* @param p1 the original vehicle's index
|
* @param p1 the original vehicle's index
|
||||||
|
@ -1420,7 +1413,7 @@ int32 CmdCloneVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
Vehicle *v_front, *v;
|
Vehicle *v_front, *v;
|
||||||
Vehicle *w_front, *w, *w_rear;
|
Vehicle *w_front, *w, *w_rear;
|
||||||
int cost, total_cost = 0;
|
int cost, total_cost = 0;
|
||||||
VehicleID *new_id;
|
// VehicleID *new_id;
|
||||||
|
|
||||||
if (!IsVehicleIndex(p1))
|
if (!IsVehicleIndex(p1))
|
||||||
return CMD_ERROR;
|
return CMD_ERROR;
|
||||||
|
@ -1444,8 +1437,6 @@ int32 CmdCloneVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
|
|
||||||
if (v->type == VEH_Train && v->subtype != TS_Front_Engine) return CMD_ERROR;
|
if (v->type == VEH_Train && v->subtype != TS_Front_Engine) return CMD_ERROR;
|
||||||
|
|
||||||
new_id = _new_vehicle_id_proc_table[v->type - VEH_Train];
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
cost = DoCommand(x, y, v->engine_type, 3, flags, CMD_BUILD_VEH(v->type));
|
cost = DoCommand(x, y, v->engine_type, 3, flags, CMD_BUILD_VEH(v->type));
|
||||||
|
|
||||||
|
@ -1454,11 +1445,7 @@ int32 CmdCloneVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
total_cost += cost;
|
total_cost += cost;
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
if (v->type == VEH_Train && RailVehInfo(v->engine_type)->flags & RVI_WAGON) {
|
w= GetVehicle(_new_vehicle_id);
|
||||||
w = GetVehicle(_new_wagon_id);
|
|
||||||
} else {
|
|
||||||
w = GetVehicle(*new_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (v->type != VEH_Road) { // road vehicles can't be refitted
|
if (v->type != VEH_Road) { // road vehicles can't be refitted
|
||||||
if (v->cargo_type != w->cargo_type) {
|
if (v->cargo_type != w->cargo_type) {
|
||||||
|
@ -1468,7 +1455,6 @@ int32 CmdCloneVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
|
|
||||||
if (v->type == VEH_Train && v->subtype != TS_Front_Engine) {
|
if (v->type == VEH_Train && v->subtype != TS_Front_Engine) {
|
||||||
// this s a train car
|
// this s a train car
|
||||||
|
|
||||||
// add this unit to the end of the train
|
// add this unit to the end of the train
|
||||||
DoCommand(x, y, (w_rear->index << 16) | w->index, 1, flags, CMD_MOVE_RAIL_VEHICLE);
|
DoCommand(x, y, (w_rear->index << 16) | w->index, 1, flags, CMD_MOVE_RAIL_VEHICLE);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1521,8 +1507,8 @@ static int32 ReplaceVehicle(Vehicle **w, byte flags)
|
||||||
if (CmdFailed(cost)) return cost;
|
if (CmdFailed(cost)) return cost;
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
new_v = GetVehicle(*_new_vehicle_id_proc_table[old_v->type - VEH_Train]);
|
new_v = GetVehicle(_new_vehicle_id);
|
||||||
*w = new_v;
|
*w = new_v; //we changed the vehicle, so MaybeReplaceVehicle needs to work on the new one. Now we tell it what the new one is
|
||||||
|
|
||||||
/* refit if needed */
|
/* refit if needed */
|
||||||
if (new_v->type != VEH_Road) { // road vehicles can't be refitted
|
if (new_v->type != VEH_Road) { // road vehicles can't be refitted
|
||||||
|
|
|
@ -442,6 +442,7 @@ VARDEF VehicleID _new_wagon_id;
|
||||||
VARDEF VehicleID _new_aircraft_id;
|
VARDEF VehicleID _new_aircraft_id;
|
||||||
VARDEF VehicleID _new_ship_id;
|
VARDEF VehicleID _new_ship_id;
|
||||||
VARDEF VehicleID _new_roadveh_id;
|
VARDEF VehicleID _new_roadveh_id;
|
||||||
|
VARDEF VehicleID _new_vehicle_id;
|
||||||
VARDEF uint16 _aircraft_refit_capacity;
|
VARDEF uint16 _aircraft_refit_capacity;
|
||||||
VARDEF byte _cmd_build_rail_veh_score;
|
VARDEF byte _cmd_build_rail_veh_score;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue