MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / CmdCreateSubsidy

Function CmdCreateSubsidy

src/subsidy.cpp:196–230  ·  view source on GitHub ↗

* 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 */

Source from the content-addressed store, hash-verified

194 * @return the cost of this operation or an error
195 */
196CommandCost 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.

Callers

nothing calls this directly

Calls 6

CreateSubsidyFunction · 0.85
CommandCostClass · 0.85
ToTownIDMethod · 0.80
ToIndustryIDMethod · 0.80
TestMethod · 0.80
IsValidMethod · 0.45

Tested by

no test coverage detected