mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-16 00:12:51 +00:00
Do name generation at client, fix localisation
Use existing group creation command
This commit is contained in:
parent
dee05f520f
commit
6c07758cc3
@ -223,7 +223,6 @@ CommandProc CmdDepotSellAllVehicles;
|
|||||||
CommandProc CmdDepotMassAutoReplace;
|
CommandProc CmdDepotMassAutoReplace;
|
||||||
|
|
||||||
CommandProc CmdCreateGroup;
|
CommandProc CmdCreateGroup;
|
||||||
CommandProc CmdCreateGroupAutoName;
|
|
||||||
CommandProc CmdAlterGroup;
|
CommandProc CmdAlterGroup;
|
||||||
CommandProc CmdDeleteGroup;
|
CommandProc CmdDeleteGroup;
|
||||||
CommandProc CmdCreateGroupFromList;
|
CommandProc CmdCreateGroupFromList;
|
||||||
@ -458,7 +457,6 @@ static const Command _command_proc_table[] = {
|
|||||||
DEF_CMD(CmdDepotSellAllVehicles, 0, CMDT_VEHICLE_CONSTRUCTION ), // CMD_DEPOT_SELL_ALL_VEHICLES
|
DEF_CMD(CmdDepotSellAllVehicles, 0, CMDT_VEHICLE_CONSTRUCTION ), // CMD_DEPOT_SELL_ALL_VEHICLES
|
||||||
DEF_CMD(CmdDepotMassAutoReplace, 0, CMDT_VEHICLE_CONSTRUCTION ), // CMD_DEPOT_MASS_AUTOREPLACE
|
DEF_CMD(CmdDepotMassAutoReplace, 0, CMDT_VEHICLE_CONSTRUCTION ), // CMD_DEPOT_MASS_AUTOREPLACE
|
||||||
DEF_CMD(CmdCreateGroup, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_CREATE_GROUP
|
DEF_CMD(CmdCreateGroup, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_CREATE_GROUP
|
||||||
DEF_CMD(CmdCreateGroupAutoName, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_CREATE_GROUP_AUTO_NAME
|
|
||||||
DEF_CMD(CmdDeleteGroup, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_DELETE_GROUP
|
DEF_CMD(CmdDeleteGroup, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_DELETE_GROUP
|
||||||
DEF_CMD(CmdAlterGroup, 0, CMDT_OTHER_MANAGEMENT ), // CMD_ALTER_GROUP
|
DEF_CMD(CmdAlterGroup, 0, CMDT_OTHER_MANAGEMENT ), // CMD_ALTER_GROUP
|
||||||
DEF_CMD(CmdCreateGroupFromList, 0, CMDT_OTHER_MANAGEMENT ), // CMD_CREATE_GROUP_FROM_LIST
|
DEF_CMD(CmdCreateGroupFromList, 0, CMDT_OTHER_MANAGEMENT ), // CMD_CREATE_GROUP_FROM_LIST
|
||||||
|
@ -404,7 +404,6 @@ enum Commands {
|
|||||||
CMD_DEPOT_MASS_AUTOREPLACE, ///< force the autoreplace to take action in a given depot
|
CMD_DEPOT_MASS_AUTOREPLACE, ///< force the autoreplace to take action in a given depot
|
||||||
|
|
||||||
CMD_CREATE_GROUP, ///< create a new group
|
CMD_CREATE_GROUP, ///< create a new group
|
||||||
CMD_CREATE_GROUP_AUTO_NAME, ///< create a new group with an automatically generated name
|
|
||||||
CMD_DELETE_GROUP, ///< delete a group
|
CMD_DELETE_GROUP, ///< delete a group
|
||||||
CMD_ALTER_GROUP, ///< alter a group
|
CMD_ALTER_GROUP, ///< alter a group
|
||||||
CMD_CREATE_GROUP_FROM_LIST, ///< create and rename a new group from a vehicle list
|
CMD_CREATE_GROUP_FROM_LIST, ///< create and rename a new group from a vehicle list
|
||||||
|
@ -117,6 +117,8 @@ void RemoveVehicleFromGroup(const Vehicle *v);
|
|||||||
void RemoveAllGroupsForCompany(const CompanyID company);
|
void RemoveAllGroupsForCompany(const CompanyID company);
|
||||||
bool GroupIsInGroup(GroupID search, GroupID group);
|
bool GroupIsInGroup(GroupID search, GroupID group);
|
||||||
|
|
||||||
|
std::string GenerateAutoNameForVehicleGroup(const Vehicle *v);
|
||||||
|
|
||||||
extern GroupID _new_group_id;
|
extern GroupID _new_group_id;
|
||||||
|
|
||||||
#endif /* GROUP_H */
|
#endif /* GROUP_H */
|
||||||
|
@ -649,119 +649,19 @@ CommandCost CmdAddVehicleGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, u
|
|||||||
return CommandCost();
|
return CommandCost();
|
||||||
}
|
}
|
||||||
|
|
||||||
Group* CreateAutoGroup(const VehicleType vt, const std::string& name, Group* parent)
|
static Town* GetTownFromDestination(const DestinationID destination)
|
||||||
{
|
|
||||||
Group *group = nullptr;
|
|
||||||
|
|
||||||
if (Group::CanAllocateItem())
|
|
||||||
{
|
|
||||||
const Company *company = Company::Get(_current_company);
|
|
||||||
group = new Group(_current_company);
|
|
||||||
group->vehicle_type = vt;
|
|
||||||
group->parent = parent != nullptr ? parent->index : INVALID_GROUP;
|
|
||||||
group->livery.colour1 = company->livery[LS_DEFAULT].colour1;
|
|
||||||
group->livery.colour2 = company->livery[LS_DEFAULT].colour2;
|
|
||||||
|
|
||||||
if (company->settings.renew_keep_length) {
|
|
||||||
SetBit(group->flags, GF_REPLACE_WAGON_REMOVAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
group->name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
return group;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string GetCargoList(const Vehicle *vehicle)
|
|
||||||
{
|
|
||||||
auto checked_vehicle = vehicle;
|
|
||||||
std::vector<StringID> cargoes;
|
|
||||||
|
|
||||||
do {
|
|
||||||
if (checked_vehicle->cargo_cap == 0) continue;
|
|
||||||
|
|
||||||
const StringID cargo_name = CargoSpec::Get(checked_vehicle->cargo_type)->name;
|
|
||||||
|
|
||||||
if(cargo_name == INVALID_STRING_ID) continue;
|
|
||||||
|
|
||||||
if (std::find(cargoes.begin(), cargoes.end(), cargo_name) == cargoes.end()) {
|
|
||||||
cargoes.push_back(cargo_name);
|
|
||||||
}
|
|
||||||
} while ((checked_vehicle = checked_vehicle->Next()) != nullptr);
|
|
||||||
|
|
||||||
std::string cargo_list;
|
|
||||||
|
|
||||||
if (!cargoes.empty()) {
|
|
||||||
for (auto cargo : cargoes) {
|
|
||||||
if (cargo_list.empty()) {
|
|
||||||
cargo_list += " (";
|
|
||||||
} else {
|
|
||||||
cargo_list += ", ";
|
|
||||||
}
|
|
||||||
|
|
||||||
char cargo_name_buffer[255];
|
|
||||||
SetDParam(0, cargo);
|
|
||||||
GetString(cargo_name_buffer, STR_JUST_STRING, lastof(cargo_name_buffer));
|
|
||||||
cargo_list += cargo_name_buffer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!cargo_list.empty()) {
|
|
||||||
cargo_list += ")";
|
|
||||||
}
|
|
||||||
|
|
||||||
return cargo_list;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a vehicle to an auto group.
|
|
||||||
* @param vehicle the vehicle
|
|
||||||
* @param from the first town in the orders list
|
|
||||||
* @param to the last town in the orders list
|
|
||||||
* @return the group to add the vehicle to.
|
|
||||||
*/
|
|
||||||
Group* CreateVehicleAutoGroup(const Vehicle *vehicle, const Town *from, const Town *to)
|
|
||||||
{
|
|
||||||
assert(from != nullptr);
|
|
||||||
Group *group;
|
|
||||||
|
|
||||||
if (from == to || to == nullptr)
|
|
||||||
{
|
|
||||||
char local_name[255];
|
|
||||||
GetString(local_name, STR_VEHICLE_GROUP_LOCAL_ROUTE, lastof(local_name));
|
|
||||||
std::string name;
|
|
||||||
name += from->GetCachedName();
|
|
||||||
name += " ";
|
|
||||||
name += local_name;
|
|
||||||
name += GetCargoList(vehicle);
|
|
||||||
group = CreateAutoGroup(vehicle->type, name, nullptr);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::string name;
|
|
||||||
name += from->GetCachedName();
|
|
||||||
name += " to ";
|
|
||||||
name += to->GetCachedName();
|
|
||||||
name += GetCargoList(vehicle);
|
|
||||||
group = CreateAutoGroup(vehicle->type, name, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
return group;
|
|
||||||
}
|
|
||||||
|
|
||||||
Town* GetTownFromDestination(const DestinationID destination)
|
|
||||||
{
|
{
|
||||||
Town* town = nullptr;
|
Town* town = nullptr;
|
||||||
|
|
||||||
if (BaseStation *st = BaseStation::GetIfValid(destination); st != nullptr)
|
BaseStation *st = BaseStation::GetIfValid(destination);
|
||||||
{
|
if (st != nullptr) {
|
||||||
town = st->town;
|
town = st->town;
|
||||||
}
|
}
|
||||||
|
|
||||||
return town;
|
return town;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetAutoGroupMostRelevantTowns(const Vehicle *vehicle, Town* &from, Town* &to)
|
static void GetAutoGroupMostRelevantTowns(const Vehicle *vehicle, Town* &from, Town* &to)
|
||||||
{
|
{
|
||||||
std::vector<Town*> unique_destinations;
|
std::vector<Town*> unique_destinations;
|
||||||
|
|
||||||
@ -791,62 +691,42 @@ void GetAutoGroupMostRelevantTowns(const Vehicle *vehicle, Town* &from, Town* &t
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
static CargoTypes GetVehicleCargoList(const Vehicle *vehicle)
|
||||||
* Create a new group, rename it with automatically generated name and add vehicle to this group
|
|
||||||
* @param tile unused
|
|
||||||
* @param flags type of operation
|
|
||||||
* @param p1 vehicle to add to a group
|
|
||||||
* - p1 bit 0-19 : VehicleID
|
|
||||||
* - p1 bit 31 : Add shared vehicles as well.
|
|
||||||
* @param p2 unused
|
|
||||||
* @param text unused
|
|
||||||
* @return the cost of this operation or an error
|
|
||||||
*/
|
|
||||||
CommandCost CmdCreateGroupAutoName(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
|
||||||
{
|
{
|
||||||
Vehicle *vehicle = Vehicle::GetIfValid(GB(p1, 0, 20));
|
CargoTypes cargoes = 0;
|
||||||
|
|
||||||
if (vehicle == nullptr) return CMD_ERROR;
|
for (const Vehicle *u = vehicle; u != nullptr; u = u->Next()) {
|
||||||
if (vehicle->owner != _current_company || !vehicle->IsPrimaryVehicle()) return CMD_ERROR;
|
if (u->cargo_cap == 0) continue;
|
||||||
if (!Group::CanAllocateItem()) return CMD_ERROR;
|
|
||||||
|
|
||||||
|
SetBit(cargoes, u->cargo_type);
|
||||||
|
}
|
||||||
|
return cargoes;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GenerateAutoNameForVehicleGroup(const Vehicle *v)
|
||||||
|
{
|
||||||
Town *town_from = nullptr;
|
Town *town_from = nullptr;
|
||||||
Town *town_to = nullptr;
|
Town *town_to = nullptr;
|
||||||
|
|
||||||
GetAutoGroupMostRelevantTowns(vehicle, town_from, town_to);
|
GetAutoGroupMostRelevantTowns(v, town_from, town_to);
|
||||||
|
if (town_from == nullptr) return "";
|
||||||
|
|
||||||
if (town_from == nullptr) return CMD_ERROR;
|
CargoTypes cargoes = GetVehicleCargoList(v);
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
char group_name[512];
|
||||||
const auto new_group = CreateVehicleAutoGroup(vehicle, town_from, town_to);
|
if (town_from == town_to || town_to == nullptr) {
|
||||||
|
SetDParam(0, town_from->index);
|
||||||
assert(new_group != nullptr);
|
SetDParam(1, (cargoes != 0) ? STR_VEHICLE_AUTO_GROUP_CARGO_LIST : STR_EMPTY);
|
||||||
|
SetDParam(2, cargoes);
|
||||||
AddVehicleToGroup(vehicle, new_group->index);
|
GetString(group_name, STR_VEHICLE_AUTO_GROUP_LOCAL_ROUTE, lastof(group_name));
|
||||||
|
} else {
|
||||||
if (HasBit(p1, 31)) {
|
SetDParam(0, town_from->index);
|
||||||
/* Add vehicles in the shared order list as well. */
|
SetDParam(1, town_to->index);
|
||||||
for (Vehicle *v2 = vehicle->FirstShared(); v2 != nullptr; v2 = v2->NextShared()) {
|
SetDParam(2, (cargoes != 0) ? STR_VEHICLE_AUTO_GROUP_CARGO_LIST : STR_EMPTY);
|
||||||
if (v2->group_id != new_group->index) {
|
SetDParam(3, cargoes);
|
||||||
AddVehicleToGroup(v2, new_group->index);
|
GetString(group_name, STR_VEHICLE_AUTO_GROUP_ROUTE, lastof(group_name));
|
||||||
}
|
}
|
||||||
}
|
return std::string(group_name);
|
||||||
}
|
|
||||||
|
|
||||||
GroupStatistics::UpdateAutoreplace(vehicle->owner);
|
|
||||||
|
|
||||||
/* Update the Replace Vehicle Windows */
|
|
||||||
SetWindowDirty(WC_REPLACE_VEHICLE, vehicle->type);
|
|
||||||
SetWindowDirty(WC_VEHICLE_DEPOT, vehicle->tile);
|
|
||||||
SetWindowDirty(WC_VEHICLE_VIEW, vehicle->index);
|
|
||||||
SetWindowDirty(WC_VEHICLE_DETAILS, vehicle->index);
|
|
||||||
InvalidateWindowData(WC_VEHICLE_VIEW, vehicle->index);
|
|
||||||
InvalidateWindowData(WC_VEHICLE_DETAILS, vehicle->index);
|
|
||||||
InvalidateWindowData(GetWindowClassForVehicleType(vehicle->type), VehicleListIdentifier(VL_GROUP_LIST, vehicle->type, _current_company).Pack());
|
|
||||||
InvalidateWindowClassesData(WC_TEMPLATEGUI_MAIN);
|
|
||||||
}
|
|
||||||
|
|
||||||
return CommandCost();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -999,13 +999,16 @@ public:
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case WID_GL_CREATE_GROUP: { // make new group with auto generated vehicle specific name and add vehicle
|
case WID_GL_CREATE_GROUP: { // make new group with auto generated vehicle specific name and add vehicle
|
||||||
const VehicleID vindex = this->vehicle_sel;
|
const Vehicle *v = Vehicle::Get(vehicle_sel);
|
||||||
this->vehicle_sel = INVALID_VEHICLE;
|
this->vehicle_sel = INVALID_VEHICLE;
|
||||||
this->group_over = INVALID_GROUP;
|
this->group_over = INVALID_GROUP;
|
||||||
this->SetDirty();
|
this->SetDirty();
|
||||||
|
|
||||||
DoCommandP(0, vindex | (_ctrl_pressed ? 1U << 31 : 0),0 , CMD_CREATE_GROUP_AUTO_NAME | CMD_MSG(STR_ERROR_GROUP_CAN_T_CREATE), nullptr, nullptr);
|
std::string name = GenerateAutoNameForVehicleGroup(v);
|
||||||
|
|
||||||
|
DoCommandP(0, VehicleListIdentifier(_ctrl_pressed ? VL_SHARED_ORDERS : VL_SINGLE_VEH, v->type, v->owner, v->index).Pack(), 0, CMD_CREATE_GROUP_FROM_LIST | CMD_MSG(STR_ERROR_GROUP_CAN_T_CREATE), nullptr, name.c_str());
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -4925,7 +4925,10 @@ STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR_LIFETIME :{STRING2} (life
|
|||||||
STR_VEHICLE_INFO_RELIABILITY_BREAKDOWNS :{BLACK}Reliability: {LTBLUE}{COMMA}% {BLACK}Breakdowns since last service: {LTBLUE}{COMMA}
|
STR_VEHICLE_INFO_RELIABILITY_BREAKDOWNS :{BLACK}Reliability: {LTBLUE}{COMMA}% {BLACK}Breakdowns since last service: {LTBLUE}{COMMA}
|
||||||
|
|
||||||
STR_VEHICLE_INFO_GROUP :{BLACK}Group: {LTBLUE}{GROUP}
|
STR_VEHICLE_INFO_GROUP :{BLACK}Group: {LTBLUE}{GROUP}
|
||||||
STR_VEHICLE_GROUP_LOCAL_ROUTE :Local
|
|
||||||
|
STR_VEHICLE_AUTO_GROUP_ROUTE :{TOWN} to {TOWN}{STRING1}
|
||||||
|
STR_VEHICLE_AUTO_GROUP_LOCAL_ROUTE :{TOWN} Local{STRING1}
|
||||||
|
STR_VEHICLE_AUTO_GROUP_CARGO_LIST : ({CARGO_LIST})
|
||||||
|
|
||||||
STR_VEHICLE_INFO_BUILT_VALUE :{LTBLUE}{ENGINE} {BLACK}Built: {LTBLUE}{NUM}{BLACK} Value: {LTBLUE}{CURRENCY_LONG}
|
STR_VEHICLE_INFO_BUILT_VALUE :{LTBLUE}{ENGINE} {BLACK}Built: {LTBLUE}{NUM}{BLACK} Value: {LTBLUE}{CURRENCY_LONG}
|
||||||
STR_VEHICLE_INFO_NO_CAPACITY :{BLACK}Capacity: {LTBLUE}None{STRING}
|
STR_VEHICLE_INFO_NO_CAPACITY :{BLACK}Capacity: {LTBLUE}None{STRING}
|
||||||
|
@ -4781,7 +4781,8 @@ STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR_LIFETIME :{STRING} (seit
|
|||||||
STR_VEHICLE_INFO_RELIABILITY_BREAKDOWNS :{BLACK}Zuverlässigkeit: {LTBLUE}{COMMA}% {BLACK}Pannen seit der letzten Wartung: {LTBLUE}{COMMA}
|
STR_VEHICLE_INFO_RELIABILITY_BREAKDOWNS :{BLACK}Zuverlässigkeit: {LTBLUE}{COMMA}% {BLACK}Pannen seit der letzten Wartung: {LTBLUE}{COMMA}
|
||||||
|
|
||||||
STR_VEHICLE_INFO_GROUP :{BLACK}Gruppe: {LTBLUE}{GROUP}
|
STR_VEHICLE_INFO_GROUP :{BLACK}Gruppe: {LTBLUE}{GROUP}
|
||||||
STR_VEHICLE_GROUP_LOCAL_ROUTE :Ortsbereich
|
|
||||||
|
STR_VEHICLE_AUTO_GROUP_LOCAL_ROUTE :{TOWN} Ortsbereich {CARGO_LIST}
|
||||||
|
|
||||||
STR_VEHICLE_INFO_BUILT_VALUE :{LTBLUE}{ENGINE} {BLACK}Gebaut: {LTBLUE}{NUM}{BLACK} Wert: {LTBLUE}{CURRENCY_LONG}
|
STR_VEHICLE_INFO_BUILT_VALUE :{LTBLUE}{ENGINE} {BLACK}Gebaut: {LTBLUE}{NUM}{BLACK} Wert: {LTBLUE}{CURRENCY_LONG}
|
||||||
STR_VEHICLE_INFO_NO_CAPACITY :{BLACK}Kapazität: {LTBLUE}Keine{STRING}
|
STR_VEHICLE_INFO_NO_CAPACITY :{BLACK}Kapazität: {LTBLUE}Keine{STRING}
|
||||||
|
Loading…
Reference in New Issue
Block a user