|
@@ -84,25 +84,25 @@ static WindowClass GetWCForVT(VehicleTyp
|
|
|
case VEH_SHIP: return WC_SHIPS_LIST;
|
|
|
case VEH_AIRCRAFT: return WC_AIRCRAFT_LIST;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* Add a vehicle to a group
|
|
|
* @param tile unused
|
|
|
* @param p1 vehicle type
|
|
|
* @param p2 unused
|
|
|
*/
|
|
|
int32 CmdCreateGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|
|
CommandCost CmdCreateGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|
|
{
|
|
|
VehicleType vt = (VehicleType)p1;
|
|
|
if (!IsPlayerBuildableVehicleType(vt)) return CMD_ERROR;
|
|
|
|
|
|
Group *g = AllocateGroup();
|
|
|
if (g == NULL) return CMD_ERROR;
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
g->owner = _current_player;
|
|
|
g->string_id = STR_SV_GROUP_NAME;
|
|
|
g->replace_protection = false;
|
|
|
g->vehicle_type = vt;
|
|
@@ -112,25 +112,25 @@ int32 CmdCreateGroup(TileIndex tile, uin
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* Add a vehicle to a group
|
|
|
* @param tile unused
|
|
|
* @param p1 index of array group
|
|
|
* - p1 bit 0-15 : GroupID
|
|
|
* @param p2 unused
|
|
|
*/
|
|
|
int32 CmdDeleteGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|
|
CommandCost CmdDeleteGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|
|
{
|
|
|
if (!IsValidGroupID(p1)) return CMD_ERROR;
|
|
|
|
|
|
Group *g = GetGroup(p1);
|
|
|
if (g->owner != _current_player) return CMD_ERROR;
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
Vehicle *v;
|
|
|
|
|
|
/* Add all vehicles belong to the group to the default group */
|
|
|
FOR_ALL_VEHICLES(v) {
|
|
|
if (v->group_id == g->index && v->type == g->vehicle_type) v->group_id = DEFAULT_GROUP;
|
|
@@ -158,25 +158,25 @@ int32 CmdDeleteGroup(TileIndex tile, uin
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* Rename a group
|
|
|
* @param tile unused
|
|
|
* @param p1 index of array group
|
|
|
* - p1 bit 0-15 : GroupID
|
|
|
* @param p2 unused
|
|
|
*/
|
|
|
int32 CmdRenameGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|
|
CommandCost CmdRenameGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|
|
{
|
|
|
if (!IsValidGroupID(p1) || StrEmpty(_cmd_text)) return CMD_ERROR;
|
|
|
|
|
|
Group *g = GetGroup(p1);
|
|
|
if (g->owner != _current_player) return CMD_ERROR;
|
|
|
|
|
|
/* Create the name */
|
|
|
StringID str = AllocateName(_cmd_text, 0);
|
|
|
if (str == STR_NULL) return CMD_ERROR;
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
/* Delete the old name */
|
|
@@ -190,25 +190,25 @@ int32 CmdRenameGroup(TileIndex tile, uin
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* Add a vehicle to a group
|
|
|
* @param tile unused
|
|
|
* @param p1 index of array group
|
|
|
* - p1 bit 0-15 : GroupID
|
|
|
* @param p2 vehicle to add to a group
|
|
|
* - p2 bit 0-15 : VehicleID
|
|
|
*/
|
|
|
int32 CmdAddVehicleGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|
|
CommandCost CmdAddVehicleGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|
|
{
|
|
|
GroupID new_g = p1;
|
|
|
|
|
|
if (!IsValidVehicleID(p2) || (!IsValidGroupID(new_g) && !IsDefaultGroupID(new_g))) return CMD_ERROR;
|
|
|
|
|
|
if (IsValidGroupID(new_g)) {
|
|
|
Group *g = GetGroup(new_g);
|
|
|
if (g->owner != _current_player) return CMD_ERROR;
|
|
|
}
|
|
|
|
|
|
Vehicle *v = GetVehicle(p2);
|
|
|
if (v->owner != _current_player || !v->IsPrimaryVehicle()) return CMD_ERROR;
|
|
@@ -236,25 +236,25 @@ int32 CmdAddVehicleGroup(TileIndex tile,
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 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
|
|
|
*/
|
|
|
int32 CmdAddSharedVehicleGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|
|
CommandCost CmdAddSharedVehicleGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|
|
{
|
|
|
VehicleType type = (VehicleType)p2;
|
|
|
if (!IsValidGroupID(p1) || !IsPlayerBuildableVehicleType(type)) return CMD_ERROR;
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
Vehicle *v;
|
|
|
VehicleType type = (VehicleType)p2;
|
|
|
GroupID id_g = p1;
|
|
|
|
|
|
/* Find the first front engine which belong to the group id_g
|
|
|
* then add all shared vehicles of this front engine to the group id_g */
|
|
|
FOR_ALL_VEHICLES(v) {
|
|
@@ -273,25 +273,25 @@ int32 CmdAddSharedVehicleGroup(TileIndex
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* Remove all vehicles from a group
|
|
|
* @param tile unused
|
|
|
* @param p1 index of group array
|
|
|
* - p1 bit 0-15 : GroupID
|
|
|
* @param p2 type of vehicles
|
|
|
*/
|
|
|
int32 CmdRemoveAllVehiclesGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|
|
CommandCost CmdRemoveAllVehiclesGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|
|
{
|
|
|
VehicleType type = (VehicleType)p2;
|
|
|
if (!IsValidGroupID(p1) || !IsPlayerBuildableVehicleType(type)) return CMD_ERROR;
|
|
|
|
|
|
Group *g = GetGroup(p1);
|
|
|
if (g->owner != _current_player) return CMD_ERROR;
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
GroupID old_g = p1;
|
|
|
Vehicle *v;
|
|
|
|
|
|
/* Find each Vehicle that belongs to the group old_g and add it to the default group */
|
|
@@ -310,25 +310,25 @@ int32 CmdRemoveAllVehiclesGroup(TileInde
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* (Un)set global replace protection from a group
|
|
|
* @param tile unused
|
|
|
* @param p1 index of group array
|
|
|
* - p1 bit 0-15 : GroupID
|
|
|
* @param p2
|
|
|
* - p2 bit 0 : 1 to set or 0 to clear protection.
|
|
|
*/
|
|
|
int32 CmdSetGroupReplaceProtection(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|
|
CommandCost CmdSetGroupReplaceProtection(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|
|
{
|
|
|
if (!IsValidGroupID(p1)) return CMD_ERROR;
|
|
|
|
|
|
Group *g = GetGroup(p1);
|
|
|
if (g->owner != _current_player) return CMD_ERROR;
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
g->replace_protection = HASBIT(p2, 0);
|
|
|
|
|
|
InvalidateWindowData(GetWCForVT(g->vehicle_type), (g->vehicle_type << 11) | VLW_GROUP_LIST | _current_player);
|
|
|
}
|
|
|
|