From 9a55c79fd11e9075b937abe0a6a077fa77a72823 Mon Sep 17 00:00:00 2001 From: rubidium Date: Sat, 7 Jul 2007 08:53:19 +0000 Subject: (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries. --- src/economy.cpp | 2 ++ src/industry.h | 12 ++++++++++++ src/industry_cmd.cpp | 13 ++++++++++++- src/newgrf_industries.cpp | 20 ++++++++------------ src/openttd.cpp | 6 ++++++ 5 files changed, 40 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/economy.cpp b/src/economy.cpp index cd7f57a92..3eb8bdabc 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -1236,7 +1236,9 @@ static void DeliverGoodsToIndustry(TileIndex xy, CargoID cargo_type, int num_pie if (best != NULL) { indspec = GetIndustrySpec(best->type); uint16 callback = indspec->callback_flags; + best->was_cargo_delivered = true; + best->last_cargo_accepted_at = _date; if (HASBIT(callback, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HASBIT(callback, CBM_IND_PRODUCTION_256_TICKS)) { best->incoming_cargo_waiting[accepted_cargo_index] = min(num_pieces + best->incoming_cargo_waiting[accepted_cargo_index], 0xFFFF); diff --git a/src/industry.h b/src/industry.h index d8fea7356..d97185862 100644 --- a/src/industry.h +++ b/src/industry.h @@ -49,6 +49,13 @@ enum CheckProc { CHECK_END, }; +enum IndustryConstructionType { + ICT_UNKNOWN, + ICT_NORMAL_GAMEPLAY, + ICT_MAP_GENERATION, + ICT_SCENARIO_EDITOR +}; + enum IndustyBehaviour { INDUSTRYBEH_NONE = 0, INDUSTRYBEH_PLANT_FIELDS = 1 << 0, ///< periodically plants fileds around itself (temp and artic farms) @@ -96,6 +103,11 @@ struct Industry { byte was_cargo_delivered; ///< flag that indicate this has been the closest industry chosen for cargo delivery by a station. see DeliverGoodsToIndustry IndustryID index; ///< index of the industry in the pool of industries + + OwnerByte founder; ///< Founder of the industry + Date construction_date; ///< Date of the construction of the industry + uint8 construction_type; ///< Way the industry was constructed (@see IndustryConstructionType) + Date last_cargo_accepted_at; ///< Last day cargo was accepted by this industry }; struct IndustryTileTable { diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index 3deb5c673..0162f7ce5 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -792,7 +792,9 @@ static void GetProducedCargo_Industry(TileIndex tile, CargoID *b) static void ChangeTileOwner_Industry(TileIndex tile, PlayerID old_player, PlayerID new_player) { - /* not used */ + /* If the founder merges, the industry was created by the merged company */ + Industry *i = GetIndustryByTile(tile); + if (i->founder == old_player) i->founder = (new_player == PLAYER_SPECTATOR) ? OWNER_NONE : new_player; } static const byte _plantfarmfield_type[] = {1, 1, 1, 1, 1, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6}; @@ -1411,6 +1413,10 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const Ind i->last_prod_year = _cur_year; i->last_month_production[0] = i->production_rate[0] * 8; i->last_month_production[1] = i->production_rate[1] * 8; + i->founder = _current_player; + i->construction_date = _date; + i->construction_type = (_game_mode == GM_EDITOR) ? ICT_SCENARIO_EDITOR : + (_generating_world ? ICT_MAP_GENERATION : ICT_NORMAL_GAMEPLAY); if (!_generating_world) i->last_month_production[0] = i->last_month_production[1] = 0; @@ -1951,6 +1957,11 @@ static const SaveLoad _industry_desc[] = { SLE_CONDVAR(Industry, last_prod_year, SLE_INT32, 31, SL_MAX_VERSION), SLE_VAR(Industry, was_cargo_delivered, SLE_UINT8), + SLE_CONDVAR(Industry, owner, SLE_UINT8, 70, SL_MAX_VERSION), + SLE_CONDVAR(Industry, construction_date, SLE_INT32, 70, SL_MAX_VERSION), + SLE_CONDVAR(Industry, construction_type, SLE_UINT8, 70, SL_MAX_VERSION), + SLE_CONDVAR(Industry, last_cargo_accepted_at, SLE_INT32, 70, SL_MAX_VERSION), + /* reserve extra space in savegame here. (currently 32 bytes) */ SLE_CONDNULL(32, 2, SL_MAX_VERSION), diff --git a/src/newgrf_industries.cpp b/src/newgrf_industries.cpp index 7730d5531..e9d8a686c 100644 --- a/src/newgrf_industries.cpp +++ b/src/newgrf_industries.cpp @@ -14,6 +14,7 @@ #include "newgrf_spritegroup.h" #include "newgrf_industries.h" #include "newgrf_commons.h" +#include "date.h" /* Since the industry IDs defined by the GRF file don't necessarily correlate * to those used by the game, the IDs used for overriding old industries must be @@ -151,15 +152,6 @@ uint32 IndustryGetVariable(const ResolverObject *object, byte variable, byte par * let's just say it is a beginning ;) */ case 0x67: return GetIndustryTypeCount(industry->type) << 16 | 0; - /* Industry founder information. - * 0x10 if randomly created or from a map pre-newindustry. - * Else, the company who funded it */ - case 0xA7: return 0x10; - - case 0xB0: // Date when built since 1920 (in days) - case 0xB3: // Construction type - case 0xB4: break; // Date last cargo accepted since 1920 (in days) - /* Industry structure access*/ case 0x80: return industry->xy; case 0x81: return GB(industry->xy, 8, 8); @@ -167,7 +159,7 @@ uint32 IndustryGetVariable(const ResolverObject *object, byte variable, byte par case 0x82: case 0x83: case 0x84: - case 0x85: break; // not supported + case 0x85: DEBUG(grf, 0, "NewGRFs shouldn't be doing pointer magic"); break; // not supported case 0x86: return industry->width; case 0x87: return industry->height;// xy dimensions /* */ @@ -208,12 +200,16 @@ uint32 IndustryGetVariable(const ResolverObject *object, byte variable, byte par case 0xA5: return GB(industry->last_month_transported[0], 8, 8); case 0xA6: return industry->type; - + case 0xA7: return industry->founder; case 0xA8: return industry->random_color; - case 0xA9: return industry->last_prod_year; // capped? + case 0xA9: return clamp(0, industry->last_prod_year - 1920, 255); case 0xAA: return industry->counter; case 0xAB: return GB(industry->counter, 8, 8); case 0xAC: return industry->was_cargo_delivered; + + case 0xB0: return clamp(0, industry->construction_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 65535); // Date when built since 1920 (in days) + case 0xB3: return industry->construction_type; // Construction type + case 0xB4: return clamp(0, industry->last_cargo_accepted_at - DAYS_TILL_ORIGINAL_BASE_YEAR, 65535); // Date last cargo accepted since 1920 (in days) } DEBUG(grf, 1, "Unhandled industry property 0x%X", variable); diff --git a/src/openttd.cpp b/src/openttd.cpp index 7f88684e4..bdec37c94 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -2080,6 +2080,12 @@ bool AfterLoadGame() } } + if (CheckSavegameVersion(70)) { + /* Added variables to support newindustries */ + Industry *i; + FOR_ALL_INDUSTRIES(i) i->founder = OWNER_NONE; + } + /* Recalculate */ Group *g; FOR_ALL_GROUPS(g) { -- cgit v1.2.3-54-g00ecf