mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use iteration to copy cargo list into CFT_CARGO.
parent
4f8d06ff73
commit
106f29f761
|
@ -2041,16 +2041,15 @@ struct CargoesField {
|
||||||
void MakeCargo(const CargoID *cargoes, uint length, int count = -1, bool top_end = false, bool bottom_end = false)
|
void MakeCargo(const CargoID *cargoes, uint length, int count = -1, bool top_end = false, bool bottom_end = false)
|
||||||
{
|
{
|
||||||
this->type = CFT_CARGO;
|
this->type = CFT_CARGO;
|
||||||
uint i;
|
auto insert = std::begin(this->u.cargo.vertical_cargoes);
|
||||||
uint num = 0;
|
for (uint i = 0; insert != std::end(this->u.cargo.vertical_cargoes) && i < length; i++) {
|
||||||
for (i = 0; i < MAX_CARGOES && i < length; i++) {
|
|
||||||
if (IsValidCargoID(cargoes[i])) {
|
if (IsValidCargoID(cargoes[i])) {
|
||||||
this->u.cargo.vertical_cargoes[num] = cargoes[i];
|
*insert = cargoes[i];
|
||||||
num++;
|
++insert;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this->u.cargo.num_cargoes = (count < 0) ? num : count;
|
this->u.cargo.num_cargoes = (count < 0) ? static_cast<uint8_t>(insert - std::begin(this->u.cargo.vertical_cargoes)) : count;
|
||||||
for (; num < MAX_CARGOES; num++) this->u.cargo.vertical_cargoes[num] = CT_INVALID;
|
std::fill(insert, std::end(this->u.cargo.vertical_cargoes), CT_INVALID);
|
||||||
this->u.cargo.top_end = top_end;
|
this->u.cargo.top_end = top_end;
|
||||||
this->u.cargo.bottom_end = bottom_end;
|
this->u.cargo.bottom_end = bottom_end;
|
||||||
std::fill(std::begin(this->u.cargo.supp_cargoes), std::end(this->u.cargo.supp_cargoes), CT_INVALID);
|
std::fill(std::begin(this->u.cargo.supp_cargoes), std::end(this->u.cargo.supp_cargoes), CT_INVALID);
|
||||||
|
|
Loading…
Reference in New Issue