From 4dca543135cac8034a5391e797711207ecf446b5 Mon Sep 17 00:00:00 2001 From: rubidium Date: Sun, 23 Sep 2007 19:27:35 +0000 Subject: (svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries. --- docs/landscape.html | 10 +++++++++- docs/landscape_grid.html | 28 ++-------------------------- src/industry_map.h | 22 +++++++++++++++++----- src/newgrf_industries.cpp | 30 ++++++++++++++++++++++++------ src/newgrf_industries.h | 14 ++++++++++---- src/newgrf_industrytiles.cpp | 20 ++++++++++++++------ 6 files changed, 76 insertions(+), 48 deletions(-) diff --git a/docs/landscape.html b/docs/landscape.html index 804ac1a26..9f09a4be1 100644 --- a/docs/landscape.html +++ b/docs/landscape.html @@ -973,7 +973,7 @@
  • m2: index into the array of industries
  • -
  • m5: type:
    +
  • m5: type (plus m6 bit 2):
    (note: this is not the same as the industry type, which is stored in the array of industries) @@ -1272,9 +1272,17 @@
    + + AF..1FF  + NewGRF industries industry +
  • m6 bits 1..0 : Tropic zone definition
  • +
  • m3: animation state
  • +
  • m4: animation loop
  • +
  • m6 bits 3..5: random triggers (NewGRF)
  • +
  • m7: random bits (NewGRF)
  • diff --git a/docs/landscape_grid.html b/docs/landscape_grid.html index 9f9e3e3ca..a02177926 100644 --- a/docs/landscape_grid.html +++ b/docs/landscape_grid.html @@ -200,41 +200,17 @@ the array so you can quickly see what is used and what is not. OOOO OOOO - 8 + 8 industry XXXX XXXX XOOX XXXX XXXX XXXX XXXX XXXX - OOOO OOOO - OOOO OOOO XXXX XXXX - OOOO OOXX - OOOO OOOO - - - bubble/sugar/toffee,
    - gold/copper/coal,
    - oil wells, power station - -inherit- - XOOO OOOO - -inherit- XXXX XXXX - OOOO OOOO - -inherit- - -inherit- - OOOO OOOO - - - toy factory - -inherit- - XOOO OOOO - -inherit- XXXX XXXX + OOXX XXXX XXXX XXXX - -inherit- - -inherit- - OOOO OOOO 9 diff --git a/src/industry_map.h b/src/industry_map.h index 888f8f7a6..7cf93af5a 100644 --- a/src/industry_map.h +++ b/src/industry_map.h @@ -253,12 +253,24 @@ static inline void SetIndustryAnimationState(TileIndex tile, byte state) * @param tile TileIndex of the tile to query * @pre IsTileType(tile, MP_INDUSTRY) * @return requested bits - * @todo implement the storage in map array */ static inline byte GetIndustryRandomBits(TileIndex tile) { assert(IsTileType(tile, MP_INDUSTRY)); - return 0; + return _me[tile].m7; +} + +/** + * Set the random bits for this tile. + * Used for grf callbacks + * @param tile TileIndex of the tile to query + * @param bits the random bits + * @pre IsTileType(tile, MP_INDUSTRY) + */ +static inline byte GetIndustryRandomBits(TileIndex tile, byte bits) +{ + assert(IsTileType(tile, MP_INDUSTRY)); + _me[tile].m7 = bits; } /** @@ -267,12 +279,11 @@ static inline byte GetIndustryRandomBits(TileIndex tile) * @param tile TileIndex of the tile to query * @pre IsTileType(tile, MP_INDUSTRY) * @return requested triggers - * @todo implement the storage in map array */ static inline byte GetIndustryTriggers(TileIndex tile) { assert(IsTileType(tile, MP_INDUSTRY)); - return 0; + return GB(_m[tile].m6, 3, 3); } @@ -280,12 +291,13 @@ static inline byte GetIndustryTriggers(TileIndex tile) * Set the activated triggers bits for this industry tile * Used for grf callbacks * @param tile TileIndex of the tile to query + * @param triggers the triggers to set * @pre IsTileType(tile, MP_INDUSTRY) - * @todo implement the storage in map array */ static inline void SetIndustryTriggers(TileIndex tile, byte triggers) { assert(IsTileType(tile, MP_INDUSTRY)); + SB(_m[tile].m6, 3, 3, triggers); } #endif /* INDUSTRY_MAP_H */ diff --git a/src/newgrf_industries.cpp b/src/newgrf_industries.cpp index 811f76a6d..1c33f4b2e 100644 --- a/src/newgrf_industries.cpp +++ b/src/newgrf_industries.cpp @@ -217,19 +217,21 @@ uint32 IndustryGetVariable(const ResolverObject *object, byte variable, byte par /* Get industry ID at offset param */ case 0x60: return GetIndustryIDAtOffset(GetNearbyTile(parameter, industry->xy), tile, industry); - case 0x61: return 0; // Get random tile bits at offset param + /* Get random tile bits at offset param */ + case 0x61: + tile = GetNearbyTile(parameter, tile); + return (IsTileType(tile, MP_INDUSTRY) && GetIndustryByTile(tile) == industry) ? GetIndustryRandomBits(tile) : 0; /* Land info of nearby tiles */ case 0x62: return GetNearbyIndustryTileInformation(parameter, tile, INVALID_INDUSTRY); /* Animation stage of nearby tiles */ - case 0x63: { + case 0x63: tile = GetNearbyTile(parameter, tile); if (IsTileType(tile, MP_INDUSTRY) && GetIndustryByTile(tile) == industry) { return GetIndustryAnimationState(tile); } return 0xFFFFFFFF; - } /* Distance of nearest industry of given type */ case 0x64: return GetClosestIndustry(tile, MapNewGRFIndustryType(parameter, indspec->grf_prop.grffile->grfid), industry); @@ -318,11 +320,27 @@ static const SpriteGroup *IndustryResolveReal(const ResolverObject *object, cons return NULL; } +static uint32 IndustryGetRandomBits(const ResolverObject *object) +{ + return object->u.industry.ind == NULL ? 0 : 0; //object->u.industry.ind->random_bits; +} + +static uint32 IndustryGetTriggers(const ResolverObject *object) +{ + return object->u.industry.ind == NULL ? 0 : 0; //object->u.industry.ind->triggers; +} + +static void IndustrySetTriggers(const ResolverObject *object, int triggers) +{ + if (object->u.industry.ind == NULL) return; + //object->u.industry.ind->triggers = triggers; +} + static void NewIndustryResolver(ResolverObject *res, TileIndex tile, Industry *indus) { - res->GetRandomBits = IndustryTileGetRandomBits; - res->GetTriggers = IndustryTileGetTriggers; - res->SetTriggers = IndustryTileSetTriggers; + res->GetRandomBits = IndustryGetRandomBits; + res->GetTriggers = IndustryGetTriggers; + res->SetTriggers = IndustrySetTriggers; res->GetVariable = IndustryGetVariable; res->ResolveReal = IndustryResolveReal; diff --git a/src/newgrf_industries.h b/src/newgrf_industries.h index 779050b33..3fda464dd 100644 --- a/src/newgrf_industries.h +++ b/src/newgrf_industries.h @@ -8,6 +8,16 @@ #include "industry.h" #include "newgrf_spritegroup.h" +/** When should the industry(tile) be triggered for random bits? */ +enum IndustryTrigger { + /** Triggered each tile loop */ + INDUSTRY_TRIGGER_TILELOOP_PROCESS = 1, + /** Triggered (whole industry) each 256 ticks */ + INDUSTRY_TRIGGER_256_TICKS = 2, + /** Triggered on cargo delivery */ + INDUSTRY_TRIGGER_CARGO_DELIVERY = 4, +}; + /* in newgrf_industry.cpp */ uint32 IndustryGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available); uint16 GetIndustryCallback(CallbackID callback, uint32 param1, uint32 param2, Industry *industry, IndustryType type, TileIndex tile); @@ -19,10 +29,6 @@ bool CheckIfCallBackAllowsAvailability(IndustryType type, IndustryAvailabilityCa IndustryType MapNewGRFIndustryType(IndustryType grf_type, uint32 grf_id); /* in newgrf_industrytiles.cpp*/ -uint32 IndustryTileGetRandomBits(const ResolverObject *object); -uint32 IndustryTileGetTriggers(const ResolverObject *object); -void IndustryTileSetTriggers(const ResolverObject *object, int triggers); - uint32 GetNearbyIndustryTileInformation(byte parameter, TileIndex tile, IndustryID index); #endif /* NEWGRF_INDUSTRIES_H */ diff --git a/src/newgrf_industrytiles.cpp b/src/newgrf_industrytiles.cpp index 7de635808..e59788a13 100644 --- a/src/newgrf_industrytiles.cpp +++ b/src/newgrf_industrytiles.cpp @@ -114,22 +114,30 @@ static const SpriteGroup *IndustryTileResolveReal(const ResolverObject *object, return NULL; } -uint32 IndustryTileGetRandomBits(const ResolverObject *object) +static uint32 IndustryTileGetRandomBits(const ResolverObject *object) { const TileIndex tile = object->u.industry.tile; - return (tile == INVALID_TILE || !IsTileType(tile, MP_INDUSTRY)) ? 0 : GetIndustryRandomBits(tile); + if (tile == INVALID_TILE || !IsTileType(tile, MP_INDUSTRY)) return 0; + return (object->scope == VSG_SCOPE_SELF) ? GetIndustryRandomBits(tile) : 0; //GetIndustryByTile(tile)->random_bits; } -uint32 IndustryTileGetTriggers(const ResolverObject *object) +static uint32 IndustryTileGetTriggers(const ResolverObject *object) { const TileIndex tile = object->u.industry.tile; - return (tile == INVALID_TILE || !IsTileType(tile, MP_INDUSTRY)) ? 0 : GetIndustryTriggers(tile); + if (tile == INVALID_TILE || !IsTileType(tile, MP_INDUSTRY)) return 0; + return (object->scope == VSG_SCOPE_SELF) ? GetIndustryTriggers(tile) : 0; //GetIndustryByTile(tile)->triggers; } -void IndustryTileSetTriggers(const ResolverObject *object, int triggers) +static void IndustryTileSetTriggers(const ResolverObject *object, int triggers) { const TileIndex tile = object->u.industry.tile; - if (IsTileType(tile, MP_INDUSTRY)) SetIndustryTriggers(tile, triggers); + if (tile == INVALID_TILE || !IsTileType(tile, MP_INDUSTRY)) return; + + if (object->scope != VSG_SCOPE_SELF) { + SetIndustryTriggers(tile, triggers); + } else { + //GetIndustryByTile(tile)->triggers = triggers; + } } static void NewIndustryTileResolver(ResolverObject *res, IndustryGfx gfx, TileIndex tile, Industry *indus) -- cgit v1.2.3-70-g09d2