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

Function CmdIndustrySetProduction

src/industry_cmd.cpp:2178–2222  ·  view source on GitHub ↗

* Set industry production. * @param flags Type of operation. * @param ind_id IndustryID * @param prod_level Production level. * @param show_news Show a news message on production change. * @param custom_news Custom news message text. * @return Empty cost or an error. */

Source from the content-addressed store, hash-verified

2176 * @return Empty cost or an error.
2177 */
2178CommandCost CmdIndustrySetProduction(DoCommandFlags flags, IndustryID ind_id, uint8_t prod_level, bool show_news, const EncodedString &custom_news)
2179{
2180 if (_current_company != OWNER_DEITY) return CMD_ERROR;
2181 if (prod_level < PRODLEVEL_MINIMUM || prod_level > PRODLEVEL_MAXIMUM) return CMD_ERROR;
2182
2183 Industry *ind = Industry::GetIfValid(ind_id);
2184 if (ind == nullptr) return CMD_ERROR;
2185
2186 if (flags.Test(DoCommandFlag::Execute)) {
2187 ind->ctlflags.Set(IndustryControlFlag::ExternalProdLevel);
2188 ind->prod_level = prod_level;
2189 ind->RecomputeProductionMultipliers();
2190
2191 /* Show news message if requested. */
2192 if (show_news && prod_level != ind->prod_level) {
2193 NewsType nt;
2194 switch (WhoCanServiceIndustry(ind)) {
2195 case 0: nt = NewsType::IndustryNobody; break;
2196 case 1: nt = NewsType::IndustryOther; break;
2197 case 2: nt = NewsType::IndustryCompany; break;
2198 default: NOT_REACHED();
2199 }
2200
2201 /* Set parameters of news string */
2202 EncodedString headline;
2203 if (!custom_news.empty()) {
2204 headline = custom_news;
2205 } else {
2206 StringID str = (prod_level > ind->prod_level)
2207 ? GetIndustrySpec(ind->type)->production_up_text
2208 : GetIndustrySpec(ind->type)->production_down_text;
2209
2210 if (str > STR_LAST_STRINGID) {
2211 headline = GetEncodedString(str, STR_TOWN_NAME, ind->town->index, GetIndustrySpec(ind->type)->name);
2212 } else {
2213 headline = GetEncodedString(str, ind->index);
2214 }
2215 }
2216
2217 AddIndustryNewsItem(std::move(headline), nt, ind->index);
2218 }
2219 }
2220
2221 return CommandCost();
2222}
2223
2224/**
2225 * Change exclusive consumer or supplier for the industry.

Callers

nothing calls this directly

Calls 10

WhoCanServiceIndustryFunction · 0.85
NOT_REACHEDFunction · 0.85
GetIndustrySpecFunction · 0.85
AddIndustryNewsItemFunction · 0.85
CommandCostClass · 0.85
TestMethod · 0.80
GetEncodedStringFunction · 0.70
SetMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected