35 #include "table/strings.h"
40 const uint32 _veh_build_proc_table[] = {
47 const uint32 _veh_sell_proc_table[] = {
54 const uint32 _veh_refit_proc_table[] = {
61 const uint32 _send_to_depot_proc_table[] = {
107 case VEH_SHIP: num_vehicles = 1;
break;
109 default: NOT_REACHED();
117 if (unit_num == UINT16_MAX)
return_cmd_error(STR_ERROR_TOO_MANY_VEHICLES_IN_GAME);
125 default: NOT_REACHED();
128 if (value.Succeeded() && flags &
DC_EXEC) {
130 v->
value = value.GetCost();
173 if (ret.
Failed())
return ret;
218 if (e->
GetGRF() != NULL) {
224 *auto_refit_allowed =
HasBit(cb_res, 14);
225 int factor =
GB(cb_res, 0, 14);
226 if (factor >= 0x2000) factor -= 0x4000;
231 *auto_refit_allowed = e->info.refit_cost == 0;
232 return (v == NULL || v->
cargo_type != new_cid) ? e->info.refit_cost : 0;
249 int cost_factor =
GetRefitCostFactor(v, engine_type, new_cid, new_subtype, auto_refit_allowed);
252 base_price = PR_BUILD_VEHICLE_SHIP;
257 base_price = PR_BUILD_VEHICLE_ROAD;
262 base_price = PR_BUILD_VEHICLE_AIRCRAFT;
267 base_price = (e->u.rail.railveh_type ==
RAILVEH_WAGON) ? PR_BUILD_VEHICLE_WAGON : PR_BUILD_VEHICLE_TRAIN;
272 default: NOT_REACHED();
274 if (cost_factor < 0) {
304 uint total_capacity = 0;
305 uint total_mail_capacity = 0;
306 num_vehicles = num_vehicles == 0 ? UINT8_MAX : num_vehicles;
316 refit_result.
Clear();
319 byte actual_subtype = new_subtype;
320 for (; v != NULL; v = (only_this ? NULL : v->
Next())) {
332 if (!refittable && v->
cargo_type != new_cid)
continue;
335 if (actual_subtype == 0xFF) {
347 uint16 mail_capacity = 0;
349 total_capacity += amount;
351 total_mail_capacity += mail_capacity;
353 if (!refittable)
continue;
359 bool auto_refit_allowed;
361 if (auto_refit && !auto_refit_allowed) {
363 total_capacity -= amount;
364 total_mail_capacity -= mail_capacity;
373 cost.AddCost(refit_cost);
388 result->
subtype = actual_subtype;
409 refit_result.
Clear();
442 if (ret.
Failed())
return ret;
444 bool auto_refit =
HasBit(p2, 6);
455 byte new_subtype =
GB(p2, 8, 8);
460 uint8 num_vehicles =
GB(p2, 16, 8);
485 default: NOT_REACHED();
520 if (ret.
Failed())
return ret;
548 if (v->
GetGRF()->grf_version < 8) {
552 if (callback < 0x400) {
560 error = STR_ERROR_INCOMPATIBLE_RAIL_TYPES;
596 bool do_start =
HasBit(p1, 0);
597 bool vehicle_list_window =
HasBit(p1, 1);
603 if (vehicle_list_window) {
610 for (uint i = 0; i < list.
Length(); i++) {
638 VehicleType vehicle_type = Extract<VehicleType, 0, 3>(p1);
642 uint sell_command = GetCmdSellVeh(vehicle_type);
648 bool had_success =
false;
649 for (uint i = 0; i < list.
Length(); i++) {
659 return had_success ? cost : last_error;
675 VehicleType vehicle_type = Extract<VehicleType, 0, 3>(p1);
683 for (uint i = 0; i < list.
Length(); i++) {
706 if (v->
name != NULL && strcmp(v->
name, name) == 0)
return false;
722 size_t number_position;
723 for (number_position = strlen(src->
name); number_position > 0; number_position--) {
726 if (src->
name[number_position - 1] <
'0' || src->
name[number_position - 1] >
'9')
break;
732 if (number_position == strlen(src->
name)) {
736 number_position = strlen(buf);
741 buf[number_position] =
'\0';
743 num = strtol(&src->
name[number_position], &endptr, 10) + 1;
744 padding = endptr - &src->
name[number_position];
748 for (
int max_iterations = 1000; max_iterations > 0; max_iterations--, num++) {
750 seprintf(&buf[number_position],
lastof(buf),
"%0*d", padding, num);
791 if (ret.
Failed())
return ret;
800 }
while ((v = v->
Next()) != NULL);
828 if (w_front != NULL)
DoCommand(w_front->
tile, w_front->
index | (1 << 20), 0, flags, GetCmdSellVeh(w_front));
834 if (flags & DC_EXEC) {
856 w->SetServiceIntervalIsCustom(v->ServiceIntervalIsCustom());
857 w->SetServiceIntervalIsPercent(v->ServiceIntervalIsPercent());
865 _new_vehicle_id = w_front->
index;
868 if (flags & DC_EXEC) {
886 if (flags & DC_EXEC) {
921 if (flags & DC_EXEC) {
936 if (flags & DC_EXEC) {
960 bool had_success =
false;
961 for (uint i = 0; i < list.
Length(); i++) {
1021 if (ret.
Failed())
return ret;
1059 if (ret.
Failed())
return ret;
1062 bool iscustom =
HasBit(p2, 16);
1067 serv_int =
GB(p2, 0, 16);
1074 v->SetServiceInterval(serv_int);
1075 v->SetServiceIntervalIsCustom(iscustom);
1076 v->SetServiceIntervalIsPercent(ispercent);