1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-28 06:34:33 +01:00

Codechange: Add constants for original input/output cargo counts. (#12548)

This replaces some magic 3s and 2s.
This commit is contained in:
Peter Nelson
2024-04-20 20:50:48 +01:00
committed by GitHub
parent b4e00fa738
commit 959ced71bb
7 changed files with 44 additions and 39 deletions

View File

@@ -2559,7 +2559,7 @@ static ChangeInfoResult TownHouseChangeInfo(uint hid, int numinfo, int prop, Byt
/* Check if the cargo types should not be changed */
if (cargotypes == 0xFFFFFFFF) break;
for (uint j = 0; j < 3; j++) {
for (uint j = 0; j < HOUSE_ORIGINAL_NUM_ACCEPTS; j++) {
/* Get the cargo number from the 'list' */
uint8_t cargo_part = GB(cargotypes, 8 * j, 8);
CargoID cargo = GetCargoTranslation(cargo_part, _cur.grffile);
@@ -3392,14 +3392,14 @@ static ChangeInfoResult IgnoreIndustryProperty(int prop, ByteReader *buf)
case 0x0C:
case 0x0D:
case 0x0E:
case 0x10:
case 0x10: // INDUSTRY_ORIGINAL_NUM_OUTPUTS bytes
case 0x1B:
case 0x1F:
case 0x24:
buf->ReadWord();
break;
case 0x11:
case 0x11: // INDUSTRY_ORIGINAL_NUM_INPUTS bytes + 1
case 0x1A:
case 0x1C:
case 0x1D:
@@ -3431,7 +3431,7 @@ static ChangeInfoResult IgnoreIndustryProperty(int prop, ByteReader *buf)
}
case 0x16:
for (uint8_t j = 0; j < 3; j++) buf->ReadByte();
for (uint8_t j = 0; j < INDUSTRY_ORIGINAL_NUM_INPUTS; j++) buf->ReadByte();
break;
case 0x15:
@@ -3679,14 +3679,14 @@ static ChangeInfoResult IndustriesChangeInfo(uint indid, int numinfo, int prop,
break;
case 0x10: // Production cargo types
for (uint8_t j = 0; j < 2; j++) {
for (uint8_t j = 0; j < INDUSTRY_ORIGINAL_NUM_OUTPUTS; j++) {
indsp->produced_cargo[j] = GetCargoTranslation(buf->ReadByte(), _cur.grffile);
indsp->produced_cargo_label[j] = CT_INVALID;
}
break;
case 0x11: // Acceptance cargo types
for (uint8_t j = 0; j < 3; j++) {
for (uint8_t j = 0; j < INDUSTRY_ORIGINAL_NUM_INPUTS; j++) {
indsp->accepts_cargo[j] = GetCargoTranslation(buf->ReadByte(), _cur.grffile);
indsp->accepts_cargo_label[j] = CT_INVALID;
}
@@ -5472,22 +5472,22 @@ static void NewSpriteGroup(ByteReader *buf)
act_group = group;
group->version = type;
if (type == 0) {
group->num_input = 3;
for (uint i = 0; i < 3; i++) {
group->num_input = INDUSTRY_ORIGINAL_NUM_INPUTS;
for (uint i = 0; i < INDUSTRY_ORIGINAL_NUM_INPUTS; i++) {
group->subtract_input[i] = (int16_t)buf->ReadWord(); // signed
}
group->num_output = 2;
for (uint i = 0; i < 2; i++) {
group->num_output = INDUSTRY_ORIGINAL_NUM_OUTPUTS;
for (uint i = 0; i < INDUSTRY_ORIGINAL_NUM_OUTPUTS; i++) {
group->add_output[i] = buf->ReadWord(); // unsigned
}
group->again = buf->ReadByte();
} else if (type == 1) {
group->num_input = 3;
for (uint i = 0; i < 3; i++) {
group->num_input = INDUSTRY_ORIGINAL_NUM_INPUTS;
for (uint i = 0; i < INDUSTRY_ORIGINAL_NUM_INPUTS; i++) {
group->subtract_input[i] = buf->ReadByte();
}
group->num_output = 2;
for (uint i = 0; i < 2; i++) {
group->num_output = INDUSTRY_ORIGINAL_NUM_OUTPUTS;
for (uint i = 0; i < INDUSTRY_ORIGINAL_NUM_OUTPUTS; i++) {
group->add_output[i] = buf->ReadByte();
}
group->again = buf->ReadByte();