* Change the service interval of a vehicle * @param flags type of operation * @param veh_id vehicle ID that is being service-interval-changed * @param serv_int new service interval * @param is_custom service interval is custom flag * @param is_percent service interval is percentage flag * @return the cost of this operation or an error */
| 1114 | * @return the cost of this operation or an error |
| 1115 | */ |
| 1116 | CommandCost CmdChangeServiceInt(DoCommandFlags flags, VehicleID veh_id, uint16_t serv_int, bool is_custom, bool is_percent) |
| 1117 | { |
| 1118 | Vehicle *v = Vehicle::GetIfValid(veh_id); |
| 1119 | if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR; |
| 1120 | |
| 1121 | CommandCost ret = CheckOwnership(v->owner); |
| 1122 | if (ret.Failed()) return ret; |
| 1123 | |
| 1124 | const Company *company = Company::Get(v->owner); |
| 1125 | is_percent = is_custom ? is_percent : company->settings.vehicle.servint_ispercent; |
| 1126 | |
| 1127 | if (is_custom) { |
| 1128 | if (serv_int != GetServiceIntervalClamped(serv_int, is_percent)) return CMD_ERROR; |
| 1129 | } else { |
| 1130 | serv_int = CompanyServiceInterval(company, v->type); |
| 1131 | } |
| 1132 | |
| 1133 | if (flags.Test(DoCommandFlag::Execute)) { |
| 1134 | v->SetServiceInterval(serv_int); |
| 1135 | v->SetServiceIntervalIsCustom(is_custom); |
| 1136 | v->SetServiceIntervalIsPercent(is_percent); |
| 1137 | SetWindowDirty(WC_VEHICLE_DETAILS, v->index); |
| 1138 | } |
| 1139 | |
| 1140 | return CommandCost(); |
| 1141 | } |
nothing calls this directly
no test coverage detected