Changeset - r28203:306a9b1774fe
[Not reviewed]
master
0 2 0
Peter Nelson - 12 months ago 2023-11-26 21:38:49
peter1138@openttd.org
Codechange: Use max_element to find highest cargo amount.
2 files changed with 6 insertions and 18 deletions:
0 comments (0 inline, 0 general)
src/script/api/script_engine.cpp
Show inline comments
 
@@ -55,16 +55,10 @@
 

	
 
	CargoArray cap = ::GetCapacityOfArticulatedParts(engine_id);
 

	
 
	CargoID most_cargo = CT_INVALID;
 
	uint amount = 0;
 
	for (CargoID cid = 0; cid < NUM_CARGO; cid++) {
 
		if (cap[cid] > amount) {
 
			amount = cap[cid];
 
			most_cargo = cid;
 
		}
 
	}
 
	auto it = std::max_element(std::cbegin(cap), std::cend(cap));
 
	if (*it == 0) return CT_INVALID;
 

	
 
	return most_cargo;
 
	return CargoID(std::distance(std::cbegin(cap), it));
 
}
 

	
 
/* static */ bool ScriptEngine::CanRefitCargo(EngineID engine_id, CargoID cargo_id)
src/script/api/script_event_types.cpp
Show inline comments
 
@@ -42,16 +42,10 @@ CargoID ScriptEventEnginePreview::GetCar
 
	if (!this->IsEngineValid()) return CT_INVALID;
 
	CargoArray cap = ::GetCapacityOfArticulatedParts(this->engine);
 

	
 
	CargoID most_cargo = CT_INVALID;
 
	uint amount = 0;
 
	for (CargoID cid = 0; cid < NUM_CARGO; cid++) {
 
		if (cap[cid] > amount) {
 
			amount = cap[cid];
 
			most_cargo = cid;
 
		}
 
	}
 
	auto it = std::max_element(std::cbegin(cap), std::cend(cap));
 
	if (*it == 0) return CT_INVALID;
 

	
 
	return most_cargo;
 
	return CargoID(std::distance(std::cbegin(cap), it));
 
}
 

	
 
int32_t ScriptEventEnginePreview::GetCapacity()
0 comments (0 inline, 0 general)