diff options
author | Niels Martin Hansen <nielsm@indvikleren.dk> | 2018-07-26 19:29:54 +0200 |
---|---|---|
committer | Niels Martin Hansen <nielsm@indvikleren.dk> | 2018-11-03 21:43:54 +0100 |
commit | e66cec8f86357918c58b20bd3cc67330f277a5e1 (patch) | |
tree | 1d34c8882bdc3fa2150ebcd06ea5e9ce247cd68a /src/newgrf_industries.cpp | |
parent | 8859381d301a60169e167431c97cb084b7730ead (diff) | |
download | openttd-e66cec8f86357918c58b20bd3cc67330f277a5e1.tar.xz |
Add: NewGRF support for 16-in-16-out industries
Diffstat (limited to 'src/newgrf_industries.cpp')
-rw-r--r-- | src/newgrf_industries.cpp | 66 |
1 files changed, 53 insertions, 13 deletions
diff --git a/src/newgrf_industries.cpp b/src/newgrf_industries.cpp index c3ddda79a..de388c023 100644 --- a/src/newgrf_industries.cpp +++ b/src/newgrf_industries.cpp @@ -304,6 +304,33 @@ static uint32 GetCountAndDistanceOfClosestInstance(byte param_setID, byte layout return GetCountAndDistanceOfClosestInstance(parameter, layout_filter, town_filter, this->industry); } + case 0x69: + case 0x6A: + case 0x6B: + case 0x6C: + case 0x6D: { + CargoID cargo = GetCargoTranslation(parameter, this->ro.grffile); + int index = this->industry->GetCargoProducedIndex(cargo); + if (index < 0) return 0; // invalid cargo + if (variable == 0x69) return this->industry->produced_cargo_waiting[index]; + if (variable == 0x6A) return this->industry->this_month_production[index]; + if (variable == 0x6B) return this->industry->this_month_transported[index]; + if (variable == 0x6C) return this->industry->last_month_production[index]; + if (variable == 0x6D) return this->industry->last_month_transported[index]; + NOT_REACHED(); + } + + + case 0x6E: + case 0x6F: { + CargoID cargo = GetCargoTranslation(parameter, this->ro.grffile); + int index = this->industry->GetCargoAcceptedIndex(cargo); + if (index < 0) return 0; // invalid cargo + if (variable == 0x6E) return this->industry->last_cargo_accepted_at[index]; + if (variable == 0x6F) return this->industry->incoming_cargo_waiting[index]; + NOT_REACHED(); + } + /* Get a variable from the persistent storage */ case 0x7C: return (this->industry->psa != NULL) ? this->industry->psa->GetValue(parameter) : 0; @@ -364,7 +391,10 @@ static uint32 GetCountAndDistanceOfClosestInstance(byte param_setID, byte layout case 0xB0: return Clamp(this->industry->construction_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535); // Date when built since 1920 (in days) case 0xB3: return this->industry->construction_type; // Construction type - case 0xB4: return Clamp(this->industry->last_cargo_accepted_at - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535); // Date last cargo accepted since 1920 (in days) + case 0xB4: { + Date *latest = std::max_element(this->industry->last_cargo_accepted_at, endof(this->industry->last_cargo_accepted_at)); + return Clamp((*latest) - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535); // Date last cargo accepted since 1920 (in days) + } } DEBUG(grf, 1, "Unhandled industry variable 0x%X", variable); @@ -575,13 +605,28 @@ void IndustryProductionCallback(Industry *ind, int reason) if (tgroup == NULL || tgroup->type != SGT_INDUSTRY_PRODUCTION) break; const IndustryProductionSpriteGroup *group = (const IndustryProductionSpriteGroup *)tgroup; - bool deref = (group->version == 1); + bool deref = (group->version >= 1); - for (uint i = 0; i < 3; i++) { - ind->incoming_cargo_waiting[i] = Clamp(ind->incoming_cargo_waiting[i] - DerefIndProd(group->subtract_input[i], deref) * multiplier, 0, 0xFFFF); - } - for (uint i = 0; i < 2; i++) { - ind->produced_cargo_waiting[i] = Clamp(ind->produced_cargo_waiting[i] + max(DerefIndProd(group->add_output[i], deref), 0) * multiplier, 0, 0xFFFF); + if (group->version < 2) { + /* Callback parameters map directly to industry cargo slot indices */ + for (uint i = 0; i < group->num_input; i++) { + ind->incoming_cargo_waiting[i] = Clamp(ind->incoming_cargo_waiting[i] - DerefIndProd(group->subtract_input[i], deref) * multiplier, 0, 0xFFFF); + } + for (uint i = 0; i < group->num_output; i++) { + ind->produced_cargo_waiting[i] = Clamp(ind->produced_cargo_waiting[i] + max(DerefIndProd(group->add_output[i], deref), 0) * multiplier, 0, 0xFFFF); + } + } else { + /* Callback receives list of cargos to apply for, which need to have their cargo slots in industry looked up */ + for (uint i = 0; i < group->num_input; i++) { + int cargo_index = ind->GetCargoAcceptedIndex(group->cargo_input[i]); + if (cargo_index < 0) continue; + ind->incoming_cargo_waiting[cargo_index] = Clamp(ind->incoming_cargo_waiting[cargo_index] - DerefIndProd(group->subtract_input[i], deref) * multiplier, 0, 0xFFFF); + } + for (uint i = 0; i < group->num_output; i++) { + int cargo_index = ind->GetCargoProducedIndex(group->cargo_output[i]); + if (cargo_index < 0) continue; + ind->produced_cargo_waiting[cargo_index] = Clamp(ind->produced_cargo_waiting[cargo_index] + max(DerefIndProd(group->add_output[i], deref), 0) * multiplier, 0, 0xFFFF); + } } int32 again = DerefIndProd(group->again, deref); @@ -602,12 +647,7 @@ void IndustryProductionCallback(Industry *ind, int reason) */ bool IndustryTemporarilyRefusesCargo(Industry *ind, CargoID cargo_type) { - assert( - cargo_type == ind->accepts_cargo[0] || cargo_type == ind->accepts_cargo[1] || cargo_type == ind->accepts_cargo[2] || cargo_type == ind->accepts_cargo[3] || - cargo_type == ind->accepts_cargo[4] || cargo_type == ind->accepts_cargo[5] || cargo_type == ind->accepts_cargo[6] || cargo_type == ind->accepts_cargo[7] || - cargo_type == ind->accepts_cargo[8] || cargo_type == ind->accepts_cargo[9] || cargo_type == ind->accepts_cargo[10] || cargo_type == ind->accepts_cargo[11] || - cargo_type == ind->accepts_cargo[12] || cargo_type == ind->accepts_cargo[13] || cargo_type == ind->accepts_cargo[14] || cargo_type == ind->accepts_cargo[15] - ); + assert(std::find(ind->accepts_cargo, endof(ind->accepts_cargo), cargo_type) != endof(ind->accepts_cargo)); const IndustrySpec *indspec = GetIndustrySpec(ind->type); if (HasBit(indspec->callback_mask, CBM_IND_REFUSE_CARGO)) { |