Changeset - r27935:8fbfc030e7be
[Not reviewed]
master
0 3 0
PeterN - 15 months ago 2023-09-18 21:43:03
peter1138@openttd.org
Fix: Don't produce invalid cargo. (#11314)

Production for secondary industries did not always check that the produced cargo type isn't valid.
3 files changed with 8 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/economy.cpp
Show inline comments
 
@@ -1169,9 +1169,10 @@ static void TriggerIndustryProduction(In
 
		}
 
	} else {
 
		for (auto ita = std::begin(i->accepted); ita != std::end(i->accepted); ++ita) {
 
			if (ita->waiting == 0) continue;
 
			if (ita->waiting == 0 || !IsValidCargoID(ita->cargo)) continue;
 

	
 
			for (auto itp = std::begin(i->produced); itp != std::end(i->produced); ++itp) {
 
				if (!IsValidCargoID(itp->cargo)) continue;
 
				itp->waiting = ClampTo<uint16_t>(itp->waiting + (ita->waiting * indspec->input_cargo_multiplier[ita - std::begin(i->accepted)][itp - std::begin(i->produced)] / 256));
 
			}
 

	
src/industry_cmd.cpp
Show inline comments
 
@@ -1122,6 +1122,9 @@ static bool SearchLumberMillTrees(TileIn
 
 */
 
static void ChopLumberMillTrees(Industry *i)
 
{
 
	/* Skip production if cargo slot is invalid. */
 
	if (!IsValidCargoID(i->produced[0].cargo)) return;
 

	
 
	/* We only want to cut trees if all tiles are completed. */
 
	for (TileIndex tile_cur : i->location) {
 
		if (i->TileBelongsToIndustry(tile_cur)) {
 
@@ -1160,6 +1163,7 @@ static void ProduceIndustryGoods(Industr
 

	
 
		IndustryBehaviour indbehav = indsp->behaviour;
 
		for (auto &p : i->produced) {
 
			if (!IsValidCargoID(p.cargo)) continue;
 
			p.waiting = ClampTo<uint16_t>(p.waiting + p.rate);
 
		}
 

	
src/newgrf_industries.cpp
Show inline comments
 
@@ -643,9 +643,11 @@ void IndustryProductionCallback(Industry
 
		if (group->version < 2) {
 
			/* Callback parameters map directly to industry cargo slot indices */
 
			for (uint i = 0; i < group->num_input; i++) {
 
				if (!IsValidCargoID(ind->accepted[i].cargo)) continue;
 
				ind->accepted[i].waiting = ClampTo<uint16_t>(ind->accepted[i].waiting - DerefIndProd(group->subtract_input[i], deref) * multiplier);
 
			}
 
			for (uint i = 0; i < group->num_output; i++) {
 
				if (!IsValidCargoID(ind->produced[i].cargo)) continue;
 
				ind->produced[i].waiting = ClampTo<uint16_t>(ind->produced[i].waiting + std::max(DerefIndProd(group->add_output[i], deref), 0) * multiplier);
 
			}
 
		} else {
0 comments (0 inline, 0 general)