diff options
-rw-r--r-- | docs/landscape.html | 10 | ||||
-rw-r--r-- | docs/landscape_grid.html | 28 | ||||
-rw-r--r-- | src/industry_map.h | 22 | ||||
-rw-r--r-- | src/newgrf_industries.cpp | 30 | ||||
-rw-r--r-- | src/newgrf_industries.h | 14 | ||||
-rw-r--r-- | 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 @@ </ul> </li> <li>m2: index into the array of industries</li> - <li>m5: type:<br> + <li>m5: type (plus m6 bit 2):<br> <small>(note: this is not the same as the industry type, which is stored in the array of industries)</small> <table> @@ -1272,9 +1272,17 @@ </table> </td> </tr> + <tr> + <td nowrap valign=top><tt>AF</tt>..<tt>1FF</tt> </td> + <td align=left>NewGRF industries industry</td> + </tr> </table> </li> <li>m6 bits 1..0 : <a href="#tropic_zone">Tropic zone definition</a></li> + <li>m3: animation state</li> + <li>m4: animation loop</li> + <li>m6 bits 3..5: random triggers (NewGRF)</li> + <li>m7: random bits (NewGRF)</li> </ul> </td> </tr> 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. <td class="bits"><span class="free">OOOO OOOO</span></td> </tr> <tr> - <td rowspan=3>8</td> + <td>8</td> <td class="caption">industry</td> <td class="bits">XXXX XXXX</td> <td class="bits"><span class="abuse">X</span><span class="free">OO</span><span class="abuse">X XXXX</span></td> <td class="bits">XXXX XXXX XXXX XXXX</td> - <td class="bits"><span class="free">OOOO OOOO</span></td> - <td class="bits"><span class="free">OOOO OOOO</span></td> <td class="bits">XXXX XXXX</td> - <td class="bits"><span class="free">OOOO OO</span>XX</td> - <td class="bits"><span class="free">OOOO OOOO</span></td> - </tr> - <tr> - <td>bubble/sugar/toffee,<BR> - gold/copper/coal,<BR> - oil wells, power station</td> - <td class="bits">-inherit-</td> - <td class="bits"><span class="abuse">X</span><span class="free">OOO OOOO</span></td> - <td class="bits">-inherit-</td> <td class="bits">XXXX XXXX</td> - <td class="bits"><span class="free">OOOO OOOO</span></td> - <td class="bits">-inherit-</td> - <td class="bits">-inherit-</td> - <td class="bits"><span class="free">OOOO OOOO</span></td> - </tr> - <tr> - <td>toy factory</td> - <td class="bits">-inherit-</td> - <td class="bits"><span class="abuse">X</span><span class="free">OOO OOOO</span></td> - <td class="bits">-inherit-</td> <td class="bits">XXXX XXXX</td> + <td class="bits"><span class="free">OO</span>XX XXXX</td> <td class="bits">XXXX XXXX</td> - <td class="bits">-inherit-</td> - <td class="bits">-inherit-</td> - <td class="bits"><span class="free">OOOO OOOO</span></td> </tr> <tr> <td rowspan=2>9</td> 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) |