* Create a new subsidy. * @param flags type of operation * @param cargo_type CargoType of subsidy. * @param src Source. * @param dst Destination. * @return the cost of this operation or an error */
| 194 | * @return the cost of this operation or an error |
| 195 | */ |
| 196 | CommandCost CmdCreateSubsidy(DoCommandFlags flags, CargoType cargo_type, Source src, Source dst) |
| 197 | { |
| 198 | if (!Subsidy::CanAllocateItem()) return CMD_ERROR; |
| 199 | |
| 200 | if (_current_company != OWNER_DEITY) return CMD_ERROR; |
| 201 | |
| 202 | if (cargo_type >= NUM_CARGO || !::CargoSpec::Get(cargo_type)->IsValid()) return CMD_ERROR; |
| 203 | |
| 204 | switch (src.type) { |
| 205 | case SourceType::Town: |
| 206 | if (!Town::IsValidID(src.ToTownID())) return CMD_ERROR; |
| 207 | break; |
| 208 | case SourceType::Industry: |
| 209 | if (!Industry::IsValidID(src.ToIndustryID())) return CMD_ERROR; |
| 210 | break; |
| 211 | default: |
| 212 | return CMD_ERROR; |
| 213 | } |
| 214 | switch (dst.type) { |
| 215 | case SourceType::Town: |
| 216 | if (!Town::IsValidID(dst.ToTownID())) return CMD_ERROR; |
| 217 | break; |
| 218 | case SourceType::Industry: |
| 219 | if (!Industry::IsValidID(dst.ToIndustryID())) return CMD_ERROR; |
| 220 | break; |
| 221 | default: |
| 222 | return CMD_ERROR; |
| 223 | } |
| 224 | |
| 225 | if (flags.Test(DoCommandFlag::Execute)) { |
| 226 | CreateSubsidy(cargo_type, src, dst); |
| 227 | } |
| 228 | |
| 229 | return CommandCost(); |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * Tries to create a passenger subsidy between two towns. |
nothing calls this directly
no test coverage detected