diff options
author | glx <glx@openttd.org> | 2007-09-27 21:39:13 +0000 |
---|---|---|
committer | glx <glx@openttd.org> | 2007-09-27 21:39:13 +0000 |
commit | 5e45e730375743b5429215644b31d1bb1cfdcf3b (patch) | |
tree | dcfc4308edebdd200f9fae9daf09ec2601ae2212 /src | |
parent | 02d23c27764c9ff01c3f370c7638012e4520afa1 (diff) | |
download | openttd-5e45e730375743b5429215644b31d1bb1cfdcf3b.tar.xz |
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
Diffstat (limited to 'src')
-rw-r--r-- | src/ai/default/default.cpp | 25 | ||||
-rw-r--r-- | src/ai/trolly/trolly.cpp | 31 | ||||
-rw-r--r-- | src/economy.cpp | 27 | ||||
-rw-r--r-- | src/industry.h | 2 | ||||
-rw-r--r-- | src/industry_cmd.cpp | 24 | ||||
-rw-r--r-- | src/industry_gui.cpp | 72 | ||||
-rw-r--r-- | src/newgrf_industries.cpp | 4 | ||||
-rw-r--r-- | src/openttd.cpp | 13 | ||||
-rw-r--r-- | src/saveload.cpp | 2 | ||||
-rw-r--r-- | src/station_cmd.cpp | 16 |
10 files changed, 106 insertions, 110 deletions
diff --git a/src/ai/default/default.cpp b/src/ai/default/default.cpp index 87306b6bc..92b852e43 100644 --- a/src/ai/default/default.cpp +++ b/src/ai/default/default.cpp @@ -533,7 +533,6 @@ static void AiFindSubsidyPassengerRoute(FoundRoute *fr) static void AiFindRandomIndustryRoute(FoundRoute *fr) { Industry* i; - const IndustrySpec *indsp; uint32 r; CargoID cargo; @@ -547,9 +546,8 @@ static void AiFindRandomIndustryRoute(FoundRoute *fr) if (i == NULL) return; // pick a random produced cargo - indsp = GetIndustrySpec(i->type); - cargo = indsp->produced_cargo[0]; - if (r & 1 && indsp->produced_cargo[1] != CT_INVALID) cargo = indsp->produced_cargo[1]; + cargo = i->produced_cargo[0]; + if (r & 1 && i->produced_cargo[1] != CT_INVALID) cargo = i->produced_cargo[1]; fr->cargo = cargo; @@ -559,16 +557,10 @@ static void AiFindRandomIndustryRoute(FoundRoute *fr) if (cargo != CT_GOODS && cargo != CT_FOOD) { // pick a dest, and see if it can receive Industry* i2 = AiFindRandomIndustry(); - if (i2 == NULL) { - return; - } - - indsp = GetIndustrySpec(i2->type); - - if (i == i2 || - (indsp->accepts_cargo[0] != cargo && - indsp->accepts_cargo[1] != cargo && - indsp->accepts_cargo[2] != cargo)) { + if (i2 == NULL || i == i2 || + (i2->accepts_cargo[0] != cargo && + i2->accepts_cargo[1] != cargo && + i2->accepts_cargo[2] != cargo)) { return; } @@ -671,10 +663,9 @@ static bool AiCheckIfRouteIsGood(Player *p, FoundRoute *fr, byte bitmask) } } else { const Industry* i = (const Industry*)fr->from; - const IndustrySpec *indsp = GetIndustrySpec(i->type); - if (i->last_month_pct_transported[fr->cargo != indsp->produced_cargo[0]] > 0x99 || - i->last_month_production[fr->cargo != indsp->produced_cargo[0]] == 0) { + if (i->last_month_pct_transported[fr->cargo != i->produced_cargo[0]] > 0x99 || + i->last_month_production[fr->cargo != i->produced_cargo[0]] == 0) { return false; } } diff --git a/src/ai/trolly/trolly.cpp b/src/ai/trolly/trolly.cpp index eb79d6f5e..c2e4f577e 100644 --- a/src/ai/trolly/trolly.cpp +++ b/src/ai/trolly/trolly.cpp @@ -270,7 +270,6 @@ static bool AiNew_Check_City_or_Industry(Player *p, int ic, byte type) } if (type == AI_INDUSTRY) { const Industry* i = GetIndustry(ic); - const IndustrySpec *indsp = GetIndustrySpec(i->type); const Station* st; int count = 0; int j = 0; @@ -279,7 +278,7 @@ static bool AiNew_Check_City_or_Industry(Player *p, int ic, byte type) // No limits on delevering stations! // Or for industry that does not give anything yet - if (indsp->produced_cargo[0] == CT_INVALID || i->last_month_production[0] == 0) return true; + if (i->produced_cargo[0] == CT_INVALID || i->last_month_production[0] == 0) return true; if (i->last_month_production[0] - i->last_month_transported[0] < AI_CHECKCITY_NEEDED_CARGO) return false; @@ -302,13 +301,13 @@ static bool AiNew_Check_City_or_Industry(Player *p, int ic, byte type) // we want to know if this station gets the same good. If so, // we want to know its rating. If it is too high, we are not going // to build there - if (indsp->produced_cargo[0] == CT_INVALID) continue; + if (i->produced_cargo[0] == CT_INVALID) continue; // It does not take this cargo - if (!st->goods[indsp->produced_cargo[0]].last_speed) continue; + if (!st->goods[i->produced_cargo[0]].last_speed) continue; // Is it around our industry if (DistanceManhattan(st->xy, i->xy) > 5) continue; // It does take this cargo.. what is his rating? - if (st->goods[indsp->produced_cargo[0]].rating < AI_CHECKCITY_CARGO_RATING) continue; + if (st->goods[i->produced_cargo[0]].rating < AI_CHECKCITY_CARGO_RATING) continue; j++; // The rating is high.. a little chance that we still continue // But if there are 2 stations of this size, we never go on... @@ -458,19 +457,17 @@ static void AiNew_State_LocateRoute(Player *p) } } else if (p->ainew.tbt == AI_TRUCK) { const Industry* ind_from = GetIndustry(p->ainew.from_ic); - const IndustrySpec *indsp_from = GetIndustrySpec(ind_from->type); const Industry* ind_temp = GetIndustry(p->ainew.temp); - const IndustrySpec *indsp_temp = GetIndustrySpec(ind_temp->type); bool found = false; int max_cargo = 0; uint i; // TODO: in max_cargo, also check other cargo (beside [0]) // First we check if the from_ic produces cargo that this ic accepts - if (indsp_from->produced_cargo[0] != CT_INVALID && ind_from->last_month_production[0] != 0) { - for (i = 0; i < lengthof(indsp_temp->accepts_cargo); i++) { - if (indsp_temp->accepts_cargo[i] == CT_INVALID) break; - if (indsp_from->produced_cargo[0] == indsp_temp->accepts_cargo[i]) { + if (ind_from->produced_cargo[0] != CT_INVALID && ind_from->last_month_production[0] != 0) { + for (i = 0; i < lengthof(ind_temp->accepts_cargo); i++) { + if (ind_temp->accepts_cargo[i] == CT_INVALID) break; + if (ind_from->produced_cargo[0] == ind_temp->accepts_cargo[i]) { // Found a compatible industry max_cargo = ind_from->last_month_production[0] - ind_from->last_month_transported[0]; found = true; @@ -480,11 +477,11 @@ static void AiNew_State_LocateRoute(Player *p) } } } - if (!found && indsp_temp->produced_cargo[0] != CT_INVALID && ind_temp->last_month_production[0] != 0) { + if (!found && ind_temp->produced_cargo[0] != CT_INVALID && ind_temp->last_month_production[0] != 0) { // If not check if the current ic produces cargo that the from_ic accepts - for (i = 0; i < lengthof(indsp_from->accepts_cargo); i++) { - if (indsp_from->accepts_cargo[i] == CT_INVALID) break; - if (indsp_from->produced_cargo[0] == indsp_from->accepts_cargo[i]) { + for (i = 0; i < lengthof(ind_from->accepts_cargo); i++) { + if (ind_from->accepts_cargo[i] == CT_INVALID) break; + if (ind_from->produced_cargo[0] == ind_from->accepts_cargo[i]) { // Found a compatbiel industry found = true; max_cargo = ind_temp->last_month_production[0] - ind_temp->last_month_transported[0]; @@ -503,9 +500,9 @@ static void AiNew_State_LocateRoute(Player *p) distance <= max_cargo * AI_LOCATEROUTE_TRUCK_CARGO_DISTANCE) { p->ainew.to_ic = p->ainew.temp; if (p->ainew.from_deliver) { - p->ainew.cargo = indsp_from->produced_cargo[0]; + p->ainew.cargo = ind_from->produced_cargo[0]; } else { - p->ainew.cargo = indsp_temp->produced_cargo[0]; + p->ainew.cargo = ind_temp->produced_cargo[0]; } p->ainew.state = AI_STATE_FIND_STATION; diff --git a/src/economy.cpp b/src/economy.cpp index 19bf6346b..e4b9eb623 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -973,7 +973,6 @@ static void FindSubsidyPassengerRoute(FoundRoute *fr) static void FindSubsidyCargoRoute(FoundRoute *fr) { Industry *i; - const IndustrySpec *ind; int trans, total; CargoID cargo; @@ -981,15 +980,14 @@ static void FindSubsidyCargoRoute(FoundRoute *fr) fr->from = i = GetRandomIndustry(); if (i == NULL) return; - ind = GetIndustrySpec(i->type); /* Randomize cargo type */ - if (HASBIT(Random(), 0) && ind->produced_cargo[1] != CT_INVALID) { - cargo = ind->produced_cargo[1]; + if (HASBIT(Random(), 0) && i->produced_cargo[1] != CT_INVALID) { + cargo = i->produced_cargo[1]; trans = i->last_month_pct_transported[1]; total = i->last_month_production[1]; } else { - cargo = ind->produced_cargo[0]; + cargo = i->produced_cargo[0]; trans = i->last_month_pct_transported[0]; total = i->last_month_production[0]; } @@ -1016,17 +1014,12 @@ static void FindSubsidyCargoRoute(FoundRoute *fr) } else { /* The destination is an industry */ Industry *i2 = GetRandomIndustry(); - if (i2 == NULL) { - return; - } - - ind = GetIndustrySpec(i2->type); /* The industry must accept the cargo */ - if (i == i2 || - (cargo != ind->accepts_cargo[0] && - cargo != ind->accepts_cargo[1] && - cargo != ind->accepts_cargo[2])) { + if (i2 == NULL || i == i2 || + (cargo != i2->accepts_cargo[0] && + cargo != i2->accepts_cargo[1] && + cargo != i2->accepts_cargo[2])) { return; } fr->distance = DistanceManhattan(i->xy, i2->xy); @@ -1227,12 +1220,12 @@ static void DeliverGoodsToIndustry(TileIndex xy, CargoID cargo_type, int num_pie indspec = GetIndustrySpec(ind->type); uint i; - for (i = 0; i < lengthof(indspec->accepts_cargo); i++) { - if (cargo_type == indspec->accepts_cargo[i]) break; + for (i = 0; i < lengthof(ind->accepts_cargo); i++) { + if (cargo_type == ind->accepts_cargo[i]) break; } /* Check if matching cargo has been found */ - if (i == lengthof(indspec->accepts_cargo)) continue; + if (i == lengthof(ind->accepts_cargo)) continue; if (HASBIT(indspec->callback_flags, CBM_IND_REFUSE_CARGO)) { uint16 res = GetIndustryCallback(CBID_INDUSTRY_REFUSE_CARGO, 0, GetReverseCargoTranslation(cargo_type, indspec->grf_prop.grffile), ind, ind->type, ind->xy); diff --git a/src/industry.h b/src/industry.h index f3f0ca2ca..d1d71abce 100644 --- a/src/industry.h +++ b/src/industry.h @@ -105,10 +105,12 @@ struct Industry : PoolItem<Industry, IndustryID, &_Industry_pool> { byte width; byte height; const Town *town; ///< Nearest town + CargoID produced_cargo[2]; ///< 2 production cargo slots uint16 produced_cargo_waiting[2]; ///< amount of cargo produced per cargo uint16 incoming_cargo_waiting[3]; ///< incoming cargo waiting to be processed byte production_rate[2]; ///< production rate for each cargo byte prod_level; ///< general production level + CargoID accepts_cargo[3]; ///< 3 input cargo slots uint16 this_month_production[2]; ///< stats of this month's production per cargo uint16 this_month_transported[2]; ///< stats of this month's transport per cargo byte last_month_pct_transported[2]; ///< percentage transported per cargo in the last full month diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index 5f5cf3cf6..e30501beb 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -410,7 +410,7 @@ static void TransportIndustryGoods(TileIndex tile) i->this_month_production[0] += cw; - am = MoveGoodsToStation(i->xy, i->width, i->height, indspec->produced_cargo[0], cw); + am = MoveGoodsToStation(i->xy, i->width, i->height, i->produced_cargo[0], cw); i->this_month_transported[0] += am; if (am != 0 && !StartStopIndustryTileAnimation(i, IAT_INDUSTRY_DISTRIBUTES_CARGO)) { uint newgfx = GetIndustryTileSpec(GetIndustryGfx(tile))->anim_production; @@ -432,7 +432,7 @@ static void TransportIndustryGoods(TileIndex tile) i->this_month_production[1] += cw; - am = MoveGoodsToStation(i->xy, i->width, i->height, indspec->produced_cargo[1], cw); + am = MoveGoodsToStation(i->xy, i->width, i->height, i->produced_cargo[1], cw); i->this_month_transported[1] += am; } } @@ -820,7 +820,7 @@ static uint32 GetTileTrackStatus_Industry(TileIndex tile, TransportType mode, ui static void GetProducedCargo_Industry(TileIndex tile, CargoID *b) { - const IndustrySpec *i = GetIndustrySpec(GetIndustryByTile(tile)->type); + const Industry *i = GetIndustryByTile(tile); b[0] = i->produced_cargo[0]; b[1] = i->produced_cargo[1]; @@ -1391,7 +1391,7 @@ static bool CheckIfTooCloseToIndustry(TileIndex tile, int type) /* check if an industry that accepts the same goods is nearby */ if (DistanceMax(tile, i->xy) <= 14 && indspec->accepts_cargo[0] != CT_INVALID && - indspec->accepts_cargo[0] == GetIndustrySpec(i->type)->accepts_cargo[0] && ( + indspec->accepts_cargo[0] == i->accepts_cargo[0] && ( _game_mode != GM_EDITOR || !_patches.same_industry_close || !_patches.multiple_industry_per_town @@ -1421,6 +1421,11 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const Ind i->type = type; IncIndustryTypeCount(type); + i->produced_cargo[0] = indspec->produced_cargo[0]; + i->produced_cargo[1] = indspec->produced_cargo[1]; + i->accepts_cargo[0] = indspec->accepts_cargo[0]; + i->accepts_cargo[1] = indspec->accepts_cargo[1]; + i->accepts_cargo[2] = indspec->accepts_cargo[2]; i->production_rate[0] = indspec->production_rate[0]; i->production_rate[1] = indspec->production_rate[1]; @@ -1713,10 +1718,9 @@ static void UpdateIndustryStatistics(Industry *i) { byte pct; bool refresh = false; - const IndustrySpec *indsp = GetIndustrySpec(i->type); - for (byte j = 0; j < lengthof(indsp->produced_cargo); j++) { - if (indsp->produced_cargo[j] != CT_INVALID) { + for (byte j = 0; j < lengthof(i->produced_cargo); j++) { + if (i->produced_cargo[j] != CT_INVALID) { pct = 0; if (i->this_month_production[j] != 0) { i->last_prod_year = _cur_year; @@ -1859,7 +1863,7 @@ static void ChangeIndustryProduction(Industry *i, bool monthly) if (_patches.smooth_economy) { closeit = true; - for (byte j = 0; j < 2 && indspec->produced_cargo[j] != CT_INVALID; j++){ + for (byte j = 0; j < 2 && i->produced_cargo[j] != CT_INVALID; j++){ uint32 r = Random(); int old_prod, new_prod, percent; int mag; @@ -1888,7 +1892,7 @@ static void ChangeIndustryProduction(Industry *i, bool monthly) mag = abs(percent); if (mag >= 10) { SetDParam(2, mag); - SetDParam(0, GetCargo(indspec->produced_cargo[j])->name); + SetDParam(0, GetCargo(i->produced_cargo[j])->name); SetDParam(1, i->index); AddNewsItem( percent >= 0 ? STR_INDUSTRY_PROD_GOUP : STR_INDUSTRY_PROD_GODOWN, @@ -2059,10 +2063,12 @@ static const SaveLoad _industry_desc[] = { SLE_VAR(Industry, height, SLE_UINT8), SLE_REF(Industry, town, REF_TOWN), SLE_CONDNULL( 2, 2, 60), ///< used to be industry's produced_cargo + SLE_CONDARR(Industry, produced_cargo, SLE_UINT8, 2, 78, SL_MAX_VERSION), SLE_CONDARR(Industry, incoming_cargo_waiting, SLE_UINT16, 3, 70, SL_MAX_VERSION), SLE_ARR(Industry, produced_cargo_waiting, SLE_UINT16, 2), SLE_ARR(Industry, production_rate, SLE_UINT8, 2), SLE_CONDNULL( 3, 2, 60), ///< used to be industry's accepts_cargo + SLE_CONDARR(Industry, accepts_cargo, SLE_UINT8, 3, 78, SL_MAX_VERSION), SLE_VAR(Industry, prod_level, SLE_UINT8), SLE_ARR(Industry, this_month_production, SLE_UINT16, 2), SLE_ARR(Industry, this_month_transported, SLE_UINT16, 2), diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index 76b9a8fea..79b9e1e51 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -390,9 +390,8 @@ static inline bool isProductionMaximum(const Industry *i, int pt) static inline bool IsProductionAlterable(const Industry *i) { - const IndustrySpec *ind = GetIndustrySpec(i->type); return ((_game_mode == GM_EDITOR || _cheats.setup_prod.value) && - (ind->accepts_cargo[0] == CT_INVALID || ind->accepts_cargo[0] == CT_VALUABLES)); + (i->accepts_cargo[0] == CT_INVALID || i->accepts_cargo[0] == CT_VALUABLES)); } /** Information to store about the industry window */ @@ -410,21 +409,22 @@ static void IndustryViewWndProc(Window *w, WindowEvent *e) switch (e->event) { case WE_CREATE: { /* Count the number of lines that we need to resize the GUI with */ - const IndustrySpec *ind = GetIndustrySpec(GetIndustry(w->window_number)->type); + const Industry *i = GetIndustry(w->window_number); + const IndustrySpec *ind = GetIndustrySpec(i->type); int lines = -3; if (HASBIT(ind->callback_flags, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HASBIT(ind->callback_flags, CBM_IND_PRODUCTION_256_TICKS)) { - for (uint j = 0; j < 3 && ind->accepts_cargo[j] != CT_INVALID; j++) { + for (uint j = 0; j < lengthof(i->accepts_cargo) && i->accepts_cargo[j] != CT_INVALID; j++) { if (j == 0) lines++; lines++; } - } else if (ind->accepts_cargo[0] != CT_INVALID) { + } else if (i->accepts_cargo[0] != CT_INVALID) { lines++; } - for (uint j = 0; j < 2 && ind->produced_cargo[j] != CT_INVALID; j++) { + for (uint j = 0; j < lengthof(i->produced_cargo) && i->produced_cargo[j] != CT_INVALID; j++) { if (j == 0) { - if (ind->accepts_cargo[0] != CT_INVALID) lines++; + if (i->accepts_cargo[0] != CT_INVALID) lines++; lines++; } lines++; @@ -448,26 +448,26 @@ static void IndustryViewWndProc(Window *w, WindowEvent *e) DrawWindowWidgets(w); if (HASBIT(ind->callback_flags, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HASBIT(ind->callback_flags, CBM_IND_PRODUCTION_256_TICKS)) { - for (uint j = 0; j < 3 && ind->accepts_cargo[j] != CT_INVALID; j++) { + for (uint j = 0; j < lengthof(i->accepts_cargo) && i->accepts_cargo[j] != CT_INVALID; j++) { if (j == 0) { DrawString(2, y, STR_INDUSTRY_WINDOW_WAITING_FOR_PROCESSING, 0); y += 10; } - SetDParam(0, ind->accepts_cargo[j]); + SetDParam(0, i->accepts_cargo[j]); SetDParam(1, i->incoming_cargo_waiting[j]); DrawString(4, y, STR_INDUSTRY_WINDOW_WAITING_STOCKPILE_CARGO, 0); y += 10; } - } else if (ind->accepts_cargo[0] != CT_INVALID) { + } else if (i->accepts_cargo[0] != CT_INVALID) { StringID str; - SetDParam(0, GetCargo(ind->accepts_cargo[0])->name); + SetDParam(0, GetCargo(i->accepts_cargo[0])->name); str = STR_4827_REQUIRES; - if (ind->accepts_cargo[1] != CT_INVALID) { - SetDParam(1, GetCargo(ind->accepts_cargo[1])->name); + if (i->accepts_cargo[1] != CT_INVALID) { + SetDParam(1, GetCargo(i->accepts_cargo[1])->name); str = STR_4828_REQUIRES; - if (ind->accepts_cargo[2] != CT_INVALID) { - SetDParam(2, GetCargo(ind->accepts_cargo[2])->name); + if (i->accepts_cargo[2] != CT_INVALID) { + SetDParam(2, GetCargo(i->accepts_cargo[2])->name); str = STR_4829_REQUIRES; } } @@ -475,15 +475,15 @@ static void IndustryViewWndProc(Window *w, WindowEvent *e) y += 10; } - for (uint j = 0; j < 2 && ind->produced_cargo[j] != CT_INVALID; j++) { + for (uint j = 0; j < lengthof(i->produced_cargo) && i->produced_cargo[j] != CT_INVALID; j++) { if (j == 0) { - if (ind->accepts_cargo[0] != CT_INVALID) y += 10; + if (i->accepts_cargo[0] != CT_INVALID) y += 10; DrawString(2, y, STR_482A_PRODUCTION_LAST_MONTH, 0); y += 10; WP(w, indview_d).production_offset_y = y; } - SetDParam(0, ind->produced_cargo[j]); + SetDParam(0, i->produced_cargo[j]); SetDParam(1, i->last_month_production[j]); SetDParam(2, i->last_month_pct_transported[j] * 100 >> 8); @@ -527,8 +527,7 @@ static void IndustryViewWndProc(Window *w, WindowEvent *e) if (!IsProductionAlterable(i)) return; x = e->we.click.pt.x; line = (e->we.click.pt.y - WP(w, indview_d).production_offset_y) / 10; - if (e->we.click.pt.y >= WP(w, indview_d).production_offset_y && IS_INT_INSIDE(line, 0, 2) && - GetIndustrySpec(i->type)->produced_cargo[line] != CT_INVALID) { + if (e->we.click.pt.y >= WP(w, indview_d).production_offset_y && IS_INT_INSIDE(line, 0, 2) && i->produced_cargo[line] != CT_INVALID) { if (IS_INT_INSIDE(x, 5, 25) ) { /* Clicked buttons, decrease or increase production */ if (x < 15) { @@ -579,10 +578,8 @@ static void IndustryViewWndProc(Window *w, WindowEvent *e) static void UpdateIndustryProduction(Industry *i) { - const IndustrySpec *ind = GetIndustrySpec(i->type); - - for (byte j = 0; j < lengthof(ind->produced_cargo); j++) { - if (ind->produced_cargo[j] != CT_INVALID) { + for (byte j = 0; j < lengthof(i->produced_cargo); j++) { + if (i->produced_cargo[j] != CT_INVALID) { i->last_month_production[j] = 8 * i->production_rate[j]; } } @@ -655,8 +652,6 @@ static int CDECL GeneralIndustrySorter(const void *a, const void *b) { const Industry* i = *(const Industry**)a; const Industry* j = *(const Industry**)b; - const IndustrySpec *ind_i = GetIndustrySpec(i->type); - const IndustrySpec *ind_j = GetIndustrySpec(j->type); int r; switch (_industry_sort_order >> 1) { @@ -670,10 +665,10 @@ static int CDECL GeneralIndustrySorter(const void *a, const void *b) break; case 2: /* Sort by Production */ - if (ind_i->produced_cargo[0] == CT_INVALID) { - r = (ind_j->produced_cargo[0] == CT_INVALID ? 0 : -1); + if (i->produced_cargo[0] == CT_INVALID) { + r = (j->produced_cargo[0] == CT_INVALID ? 0 : -1); } else { - if (ind_j->produced_cargo[0] == CT_INVALID) { + if (j->produced_cargo[0] == CT_INVALID) { r = 1; } else { r = @@ -684,23 +679,23 @@ static int CDECL GeneralIndustrySorter(const void *a, const void *b) break; case 3: /* Sort by transported fraction */ - if (ind_i->produced_cargo[0] == CT_INVALID) { - r = (ind_j->produced_cargo[0] == CT_INVALID ? 0 : -1); + if (i->produced_cargo[0] == CT_INVALID) { + r = (j->produced_cargo[0] == CT_INVALID ? 0 : -1); } else { - if (ind_j->produced_cargo[0] == CT_INVALID) { + if (j->produced_cargo[0] == CT_INVALID) { r = 1; } else { int pi; int pj; pi = i->last_month_pct_transported[0] * 100 >> 8; - if (ind_i->produced_cargo[1] != CT_INVALID) { + if (i->produced_cargo[1] != CT_INVALID) { int p = i->last_month_pct_transported[1] * 100 >> 8; if (p < pi) pi = p; } pj = j->last_month_pct_transported[0] * 100 >> 8; - if (ind_j->produced_cargo[1] != CT_INVALID) { + if (j->produced_cargo[1] != CT_INVALID) { int p = j->last_month_pct_transported[1] * 100 >> 8; if (p < pj) pj = p; } @@ -781,15 +776,14 @@ static void IndustryDirectoryWndProc(Window *w, WindowEvent *e) while (p < _num_industry_sort) { const Industry* i = _industry_sort[p]; - const IndustrySpec *ind = GetIndustrySpec(i->type); SetDParam(0, i->index); - if (ind->produced_cargo[0] != CT_INVALID) { - SetDParam(1, ind->produced_cargo[0]); + if (i->produced_cargo[0] != CT_INVALID) { + SetDParam(1, i->produced_cargo[0]); SetDParam(2, i->last_month_production[0]); - if (ind->produced_cargo[1] != CT_INVALID) { - SetDParam(3, ind->produced_cargo[1]); + if (i->produced_cargo[1] != CT_INVALID) { + SetDParam(3, i->produced_cargo[1]); SetDParam(4, i->last_month_production[1]); SetDParam(5, i->last_month_pct_transported[0] * 100 >> 8); SetDParam(6, i->last_month_pct_transported[1] * 100 >> 8); diff --git a/src/newgrf_industries.cpp b/src/newgrf_industries.cpp index 06b18d70e..8703ab417 100644 --- a/src/newgrf_industries.cpp +++ b/src/newgrf_industries.cpp @@ -257,7 +257,7 @@ uint32 IndustryGetVariable(const ResolverObject *object, byte variable, byte par case 0x87: return industry->height;// xy dimensions /* */ case 0x88: - case 0x89: return indspec->produced_cargo[variable - 0x88]; + case 0x89: return industry->produced_cargo[variable - 0x88]; case 0x8A: return industry->produced_cargo_waiting[0]; case 0x8B: return GB(industry->produced_cargo_waiting[0], 8, 8); case 0x8C: return industry->produced_cargo_waiting[1]; @@ -266,7 +266,7 @@ uint32 IndustryGetVariable(const ResolverObject *object, byte variable, byte par case 0x8F: return industry->production_rate[variable - 0x8E]; case 0x90: case 0x91: - case 0x92: return indspec->accepts_cargo[variable - 0x90]; + case 0x92: return industry->accepts_cargo[variable - 0x90]; case 0x93: return industry->prod_level; /* amount of cargo produced so far THIS month. */ case 0x94: return industry->this_month_production[0]; diff --git a/src/openttd.cpp b/src/openttd.cpp index 4098c7547..aa55e788c 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -2182,6 +2182,19 @@ bool AfterLoadGame() } } + if (CheckSavegameVersion(78)) { + Industry *i; + uint j; + FOR_ALL_INDUSTRIES(i) { + const IndustrySpec *indsp = GetIndustrySpec(i->type); + for (j = 0; j < lengthof(i->produced_cargo); j++) { + i->produced_cargo[j] = indsp->produced_cargo[j]; + } + for (j = 0; j < lengthof(i->accepts_cargo); j++) { + i->accepts_cargo[j] = indsp->accepts_cargo[j]; + } + } + } return true; } diff --git a/src/saveload.cpp b/src/saveload.cpp index a02b16a2f..623f9a9c8 100644 --- a/src/saveload.cpp +++ b/src/saveload.cpp @@ -29,7 +29,7 @@ #include "strings.h" #include <list> -extern const uint16 SAVEGAME_VERSION = 77; +extern const uint16 SAVEGAME_VERSION = 78; uint16 _sl_version; ///< the major savegame version identifier byte _sl_minor_version; ///< the minor savegame version, DO NOT USE! diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index a964dc334..1507c73e2 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -165,14 +165,14 @@ static bool CMSAMine(TileIndex tile) /* No industry */ if (!IsTileType(tile, MP_INDUSTRY)) return false; - const IndustrySpec *indsp = GetIndustrySpec(GetIndustryByTile(tile)->type); + const Industry *ind = GetIndustryByTile(tile); /* No extractive industry */ - if ((indsp->life_type & INDUSTRYLIFE_EXTRACTIVE) == 0) return false; + if ((GetIndustrySpec(ind->type)->life_type & INDUSTRYLIFE_EXTRACTIVE) == 0) return false; - for (uint i = 0; i < lengthof(indsp->produced_cargo); i++) { + for (uint i = 0; i < lengthof(ind->produced_cargo); i++) { /* The industry extracts something non-liquid, i.e. no oil or plastic, so it is a mine */ - if (indsp->produced_cargo[i] != CT_INVALID && (GetCargo(indsp->produced_cargo[i])->classes & CC_LIQUID) == 0) return true; + if (ind->produced_cargo[i] != CT_INVALID && (GetCargo(ind->produced_cargo[i])->classes & CC_LIQUID) == 0) return true; } return false; @@ -208,14 +208,14 @@ static bool CMSAForest(TileIndex tile) /* No industry */ if (!IsTileType(tile, MP_INDUSTRY)) return false; - const IndustrySpec *indsp = GetIndustrySpec(GetIndustryByTile(tile)->type); + const Industry *ind = GetIndustryByTile(tile); /* No extractive industry */ - if ((indsp->life_type & INDUSTRYLIFE_ORGANIC) == 0) return false; + if ((GetIndustrySpec(ind->type)->life_type & INDUSTRYLIFE_ORGANIC) == 0) return false; - for (uint i = 0; i < lengthof(indsp->produced_cargo); i++) { + for (uint i = 0; i < lengthof(ind->produced_cargo); i++) { /* The industry produces wood. */ - if (indsp->produced_cargo[i] != CT_INVALID && GetCargo(indsp->produced_cargo[i])->label == 'WOOD') return true; + if (ind->produced_cargo[i] != CT_INVALID && GetCargo(ind->produced_cargo[i])->label == 'WOOD') return true; } return false; |