(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.

This commit is contained in:
rubidium
2007-09-23 19:27:35 +00:00
parent f4792f29cb
commit 4dca543135
6 changed files with 78 additions and 50 deletions

View File

@@ -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 */

View File

@@ -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;

View File

@@ -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 */

View File

@@ -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)