|
@@ -219,25 +219,25 @@ CommandCost CmdAddVehicleGroup(TileIndex
|
|
|
case VEH_TRAIN:
|
|
|
SetTrainGroupID(Train::From(v), new_g);
|
|
|
break;
|
|
|
case VEH_ROAD:
|
|
|
case VEH_SHIP:
|
|
|
case VEH_AIRCRAFT:
|
|
|
if (v->IsEngineCountable()) UpdateNumEngineGroup(v->engine_type, v->group_id, new_g);
|
|
|
v->group_id = new_g;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
/* Update the Replace Vehicle Windows */
|
|
|
InvalidateWindow(WC_REPLACE_VEHICLE, v->type);
|
|
|
SetWindowDirty(WC_REPLACE_VEHICLE, v->type);
|
|
|
InvalidateWindowData(GetWindowClassForVehicleType(v->type), (v->type << 11) | VLW_GROUP_LIST | _current_company);
|
|
|
}
|
|
|
|
|
|
return CommandCost();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Add all shared vehicles of all vehicles from a group
|
|
|
* @param tile unused
|
|
|
* @param p1 index of group array
|
|
|
* - p1 bit 0-15 : GroupID
|
|
|
* @param p2 type of vehicles
|
|
@@ -353,48 +353,48 @@ void SetTrainGroupID(Train *v, GroupID n
|
|
|
{
|
|
|
if (!Group::IsValidID(new_g) && !IsDefaultGroupID(new_g)) return;
|
|
|
|
|
|
assert(v->IsFrontEngine());
|
|
|
|
|
|
for (Vehicle *u = v; u != NULL; u = u->Next()) {
|
|
|
if (u->IsEngineCountable()) UpdateNumEngineGroup(u->engine_type, u->group_id, new_g);
|
|
|
|
|
|
u->group_id = new_g;
|
|
|
}
|
|
|
|
|
|
/* Update the Replace Vehicle Windows */
|
|
|
InvalidateWindow(WC_REPLACE_VEHICLE, VEH_TRAIN);
|
|
|
SetWindowDirty(WC_REPLACE_VEHICLE, VEH_TRAIN);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* Recalculates the groupID of a train. Should be called each time a vehicle is added
|
|
|
* to/removed from the chain,.
|
|
|
* @note this needs to be called too for 'wagon chains' (in the depot, without an engine)
|
|
|
* @note Called in CmdBuildRailVehicle, CmdBuildRailWagon, CmdMoveRailVehicle, CmdSellRailWagon
|
|
|
* @param v First vehicle of the chain.
|
|
|
*/
|
|
|
void UpdateTrainGroupID(Train *v)
|
|
|
{
|
|
|
assert(v->IsFrontEngine() || v->IsFreeWagon());
|
|
|
|
|
|
GroupID new_g = v->IsFrontEngine() ? v->group_id : (GroupID)DEFAULT_GROUP;
|
|
|
for (Vehicle *u = v; u != NULL; u = u->Next()) {
|
|
|
if (u->IsEngineCountable()) UpdateNumEngineGroup(u->engine_type, u->group_id, new_g);
|
|
|
|
|
|
u->group_id = new_g;
|
|
|
}
|
|
|
|
|
|
/* Update the Replace Vehicle Windows */
|
|
|
InvalidateWindow(WC_REPLACE_VEHICLE, VEH_TRAIN);
|
|
|
SetWindowDirty(WC_REPLACE_VEHICLE, VEH_TRAIN);
|
|
|
}
|
|
|
|
|
|
uint GetGroupNumEngines(CompanyID company, GroupID id_g, EngineID id_e)
|
|
|
{
|
|
|
if (Group::IsValidID(id_g)) return Group::Get(id_g)->num_engines[id_e];
|
|
|
|
|
|
uint num = Company::Get(company)->num_engines[id_e];
|
|
|
if (!IsDefaultGroupID(id_g)) return num;
|
|
|
|
|
|
const Group *g;
|
|
|
FOR_ALL_GROUPS(g) {
|
|
|
if (g->owner == company) num -= g->num_engines[id_e];
|