mirror of https://github.com/OpenTTD/OpenTTD
(svn r24690) -Codechange: Add resolver classes for industry tiles.
parent
f7352871fa
commit
e087503fd6
|
@ -34,6 +34,7 @@
|
|||
#include "newgrf_town.h"
|
||||
#include "newgrf_railtype.h"
|
||||
#include "newgrf_industries.h"
|
||||
#include "newgrf_industrytiles.h"
|
||||
|
||||
#include "widgets/newgrf_debug_widget.h"
|
||||
|
||||
|
|
|
@ -157,188 +157,6 @@ static uint32 GetCountAndDistanceOfClosestInstance(byte param_setID, byte layout
|
|||
return count << 16 | GB(closest_dist, 0, 16);
|
||||
}
|
||||
|
||||
/* XXX Temporarily kept for access by the industry tile resolver. */
|
||||
uint32 IndustryGetVariable(const ResolverObject *object, byte variable, uint32 parameter, bool *available)
|
||||
{
|
||||
const Industry *industry = object->u.industry.ind;
|
||||
TileIndex tile = object->u.industry.tile;
|
||||
IndustryType type = object->u.industry.type;
|
||||
const IndustrySpec *indspec = GetIndustrySpec(type);
|
||||
|
||||
/* Shall the variable get resolved in parent scope and are we not yet in parent scope? */
|
||||
if (object->u.industry.gfx == INVALID_INDUSTRYTILE && object->scope == VSG_SCOPE_PARENT) {
|
||||
/* Pass the request on to the town of the industry */
|
||||
Town *t;
|
||||
|
||||
if (industry != NULL) {
|
||||
t = industry->town;
|
||||
} else if (tile != INVALID_TILE) {
|
||||
t = ClosestTownFromTile(tile, UINT_MAX);
|
||||
} else {
|
||||
*available = false;
|
||||
return UINT_MAX;
|
||||
}
|
||||
|
||||
return TownGetVariable(variable, parameter, available, t, object->grffile);
|
||||
}
|
||||
|
||||
if (industry == NULL) {
|
||||
DEBUG(grf, 1, "Unhandled variable 0x%X (no available industry) in callback 0x%x", variable, object->callback);
|
||||
|
||||
*available = false;
|
||||
return UINT_MAX;
|
||||
}
|
||||
|
||||
switch (variable) {
|
||||
case 0x40:
|
||||
case 0x41:
|
||||
case 0x42: { // waiting cargo, but only if those two callback flags are set
|
||||
uint16 callback = indspec->callback_mask;
|
||||
if (HasBit(callback, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HasBit(callback, CBM_IND_PRODUCTION_256_TICKS)) {
|
||||
if ((indspec->behaviour & INDUSTRYBEH_PROD_MULTI_HNDLING) != 0) {
|
||||
if (industry->prod_level == 0) return 0;
|
||||
return min(industry->incoming_cargo_waiting[variable - 0x40] / industry->prod_level, (uint16)0xFFFF);
|
||||
} else {
|
||||
return min(industry->incoming_cargo_waiting[variable - 0x40], (uint16)0xFFFF);
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Manhattan distance of closes dry/water tile */
|
||||
case 0x43: return GetClosestWaterDistance(tile, (indspec->behaviour & INDUSTRYBEH_BUILT_ONWATER) == 0);
|
||||
|
||||
/* Layout number */
|
||||
case 0x44: return industry->selected_layout;
|
||||
|
||||
/* Company info */
|
||||
case 0x45: {
|
||||
byte colours = 0;
|
||||
bool is_ai = false;
|
||||
|
||||
const Company *c = Company::GetIfValid(industry->founder);
|
||||
if (c != NULL) {
|
||||
const Livery *l = &c->livery[LS_DEFAULT];
|
||||
|
||||
is_ai = c->is_ai;
|
||||
colours = l->colour1 + l->colour2 * 16;
|
||||
}
|
||||
|
||||
return industry->founder | (is_ai ? 0x10000 : 0) | (colours << 24);
|
||||
}
|
||||
|
||||
case 0x46: return industry->construction_date; // Date when built - long format - (in days)
|
||||
|
||||
/* Get industry ID at offset param */
|
||||
case 0x60: return GetIndustryIDAtOffset(GetNearbyTile(parameter, industry->location.tile, false), industry, object->grffile->grfid);
|
||||
|
||||
/* Get random tile bits at offset param */
|
||||
case 0x61:
|
||||
tile = GetNearbyTile(parameter, tile, false);
|
||||
return industry->TileBelongsToIndustry(tile) ? GetIndustryRandomBits(tile) : 0;
|
||||
|
||||
/* Land info of nearby tiles */
|
||||
case 0x62: return GetNearbyIndustryTileInformation(parameter, tile, INVALID_INDUSTRY, false, object->grffile->grf_version >= 8);
|
||||
|
||||
/* Animation stage of nearby tiles */
|
||||
case 0x63:
|
||||
tile = GetNearbyTile(parameter, tile, false);
|
||||
if (industry->TileBelongsToIndustry(tile)) {
|
||||
return GetAnimationFrame(tile);
|
||||
}
|
||||
return 0xFFFFFFFF;
|
||||
|
||||
/* Distance of nearest industry of given type */
|
||||
case 0x64: return GetClosestIndustry(tile, MapNewGRFIndustryType(parameter, indspec->grf_prop.grffile->grfid), industry);
|
||||
/* Get town zone and Manhattan distance of closest town */
|
||||
case 0x65: return GetTownRadiusGroup(industry->town, tile) << 16 | min(DistanceManhattan(tile, industry->town->xy), 0xFFFF);
|
||||
/* Get square of Euclidian distance of closes town */
|
||||
case 0x66: return GetTownRadiusGroup(industry->town, tile) << 16 | min(DistanceSquare(tile, industry->town->xy), 0xFFFF);
|
||||
|
||||
/* Count of industry, distance of closest instance
|
||||
* 68 is the same as 67, but with a filtering on selected layout */
|
||||
case 0x67:
|
||||
case 0x68: {
|
||||
byte layout_filter = 0;
|
||||
bool town_filter = false;
|
||||
if (variable == 0x68) {
|
||||
uint32 reg = GetRegister(0x101);
|
||||
layout_filter = GB(reg, 0, 8);
|
||||
town_filter = HasBit(reg, 8);
|
||||
}
|
||||
return GetCountAndDistanceOfClosestInstance(parameter, layout_filter, town_filter, industry);
|
||||
}
|
||||
|
||||
/* Get a variable from the persistent storage */
|
||||
case 0x7C: return (industry->psa != NULL) ? industry->psa->GetValue(parameter) : 0;
|
||||
|
||||
/* Industry structure access*/
|
||||
case 0x80: return industry->location.tile;
|
||||
case 0x81: return GB(industry->location.tile, 8, 8);
|
||||
/* Pointer to the town the industry is associated with */
|
||||
case 0x82: return industry->town->index;
|
||||
case 0x83:
|
||||
case 0x84:
|
||||
case 0x85: DEBUG(grf, 0, "NewGRFs shouldn't be doing pointer magic"); break; // not supported
|
||||
case 0x86: return industry->location.w;
|
||||
case 0x87: return industry->location.h;// xy dimensions
|
||||
|
||||
case 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];
|
||||
case 0x8D: return GB(industry->produced_cargo_waiting[1], 8, 8);
|
||||
case 0x8E:
|
||||
case 0x8F: return industry->production_rate[variable - 0x8E];
|
||||
case 0x90:
|
||||
case 0x91:
|
||||
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];
|
||||
case 0x95: return GB(industry->this_month_production[0], 8, 8);
|
||||
case 0x96: return industry->this_month_production[1];
|
||||
case 0x97: return GB(industry->this_month_production[1], 8, 8);
|
||||
/* amount of cargo transported so far THIS month. */
|
||||
case 0x98: return industry->this_month_transported[0];
|
||||
case 0x99: return GB(industry->this_month_transported[0], 8, 8);
|
||||
case 0x9A: return industry->this_month_transported[1];
|
||||
case 0x9B: return GB(industry->this_month_transported[1], 8, 8);
|
||||
/* fraction of cargo transported LAST month. */
|
||||
case 0x9C:
|
||||
case 0x9D: return industry->last_month_pct_transported[variable - 0x9C];
|
||||
/* amount of cargo produced LAST month. */
|
||||
case 0x9E: return industry->last_month_production[0];
|
||||
case 0x9F: return GB(industry->last_month_production[0], 8, 8);
|
||||
case 0xA0: return industry->last_month_production[1];
|
||||
case 0xA1: return GB(industry->last_month_production[1], 8, 8);
|
||||
/* amount of cargo transported last month. */
|
||||
case 0xA2: return industry->last_month_transported[0];
|
||||
case 0xA3: return GB(industry->last_month_transported[0], 8, 8);
|
||||
case 0xA4: return industry->last_month_transported[1];
|
||||
case 0xA5: return GB(industry->last_month_transported[1], 8, 8);
|
||||
|
||||
case 0xA6: return industry->type;
|
||||
case 0xA7: return industry->founder;
|
||||
case 0xA8: return industry->random_colour;
|
||||
case 0xA9: return Clamp(industry->last_prod_year - ORIGINAL_BASE_YEAR, 0, 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(industry->construction_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535); // Date when built since 1920 (in days)
|
||||
case 0xB3: return industry->construction_type; // Construction type
|
||||
case 0xB4: return Clamp(industry->last_cargo_accepted_at - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535); // Date last cargo accepted since 1920 (in days)
|
||||
}
|
||||
|
||||
DEBUG(grf, 1, "Unhandled industry variable 0x%X", variable);
|
||||
|
||||
*available = false;
|
||||
return UINT_MAX;
|
||||
}
|
||||
|
||||
/* virtual */ uint32 IndustriesScopeResolver::GetVariable(byte variable, uint32 parameter, bool *available) const
|
||||
{
|
||||
if (this->ro->callback == CBID_INDUSTRY_LOCATION) {
|
||||
|
|
|
@ -74,7 +74,6 @@ enum IndustryAvailabilityCallType {
|
|||
};
|
||||
|
||||
/* in newgrf_industry.cpp */
|
||||
uint32 IndustryGetVariable(const ResolverObject *object, byte variable, uint32 parameter, bool *available);
|
||||
uint16 GetIndustryCallback(CallbackID callback, uint32 param1, uint32 param2, Industry *industry, IndustryType type, TileIndex tile);
|
||||
uint32 GetIndustryIDAtOffset(TileIndex new_tile, const Industry *i, uint32 cur_grfid);
|
||||
void IndustryProductionCallback(Industry *ind, int reason);
|
||||
|
|
|
@ -58,44 +58,39 @@ uint32 GetRelativePosition(TileIndex tile, TileIndex ind_tile)
|
|||
return ((y & 0xF) << 20) | ((x & 0xF) << 16) | (y << 8) | x;
|
||||
}
|
||||
|
||||
static uint32 IndustryTileGetVariable(const ResolverObject *object, byte variable, uint32 parameter, bool *available)
|
||||
/* virtual */ uint32 IndustryTileScopeResolver::GetVariable(byte variable, uint32 parameter, bool *available) const
|
||||
{
|
||||
const Industry *inds = object->u.industry.ind;
|
||||
TileIndex tile = object->u.industry.tile;
|
||||
|
||||
if (object->scope == VSG_SCOPE_PARENT) {
|
||||
return IndustryGetVariable(object, variable, parameter, available);
|
||||
}
|
||||
|
||||
switch (variable) {
|
||||
/* Construction state of the tile: a value between 0 and 3 */
|
||||
case 0x40: return (IsTileType(tile, MP_INDUSTRY)) ? GetIndustryConstructionStage(tile) : 0;
|
||||
case 0x40: return (IsTileType(this->tile, MP_INDUSTRY)) ? GetIndustryConstructionStage(this->tile) : 0;
|
||||
|
||||
/* Terrain type */
|
||||
case 0x41: return GetTerrainType(tile);
|
||||
case 0x41: return GetTerrainType(this->tile);
|
||||
|
||||
/* Current town zone of the tile in the nearest town */
|
||||
case 0x42: return GetTownRadiusGroup(ClosestTownFromTile(tile, UINT_MAX), tile);
|
||||
case 0x42: return GetTownRadiusGroup(ClosestTownFromTile(this->tile, UINT_MAX), this->tile);
|
||||
|
||||
/* Relative position */
|
||||
case 0x43: return GetRelativePosition(tile, inds->location.tile);
|
||||
case 0x43: return GetRelativePosition(this->tile, this->industry->location.tile);
|
||||
|
||||
/* Animation frame. Like house variable 46 but can contain anything 0..FF. */
|
||||
case 0x44: return (IsTileType(tile, MP_INDUSTRY)) ? GetAnimationFrame(tile) : 0;
|
||||
case 0x44: return IsTileType(this->tile, MP_INDUSTRY) ? GetAnimationFrame(this->tile) : 0;
|
||||
|
||||
/* Land info of nearby tiles */
|
||||
case 0x60: return GetNearbyIndustryTileInformation(parameter, tile, inds == NULL ? (IndustryID)INVALID_INDUSTRY : inds->index, true, object->grffile->grf_version >= 8);
|
||||
case 0x60: return GetNearbyIndustryTileInformation(parameter, this->tile,
|
||||
this->industry == NULL ? (IndustryID)INVALID_INDUSTRY : this->industry->index, true, this->ro->grffile->grf_version >= 8);
|
||||
|
||||
/* Animation stage of nearby tiles */
|
||||
case 0x61:
|
||||
tile = GetNearbyTile(parameter, tile);
|
||||
if (IsTileType(tile, MP_INDUSTRY) && Industry::GetByTile(tile) == inds) {
|
||||
case 0x61: {
|
||||
TileIndex tile = GetNearbyTile(parameter, this->tile);
|
||||
if (IsTileType(tile, MP_INDUSTRY) && Industry::GetByTile(tile) == this->industry) {
|
||||
return GetAnimationFrame(tile);
|
||||
}
|
||||
return UINT_MAX;
|
||||
}
|
||||
|
||||
/* Get industry tile ID at offset */
|
||||
case 0x62: return GetIndustryIDAtOffset(GetNearbyTile(parameter, tile), inds, object->grffile->grfid);
|
||||
case 0x62: return GetIndustryIDAtOffset(GetNearbyTile(parameter, this->tile), this->industry, this->ro->grffile->grfid);
|
||||
}
|
||||
|
||||
DEBUG(grf, 1, "Unhandled industry tile variable 0x%X", variable);
|
||||
|
@ -104,93 +99,57 @@ static uint32 IndustryTileGetVariable(const ResolverObject *object, byte variabl
|
|||
return UINT_MAX;
|
||||
}
|
||||
|
||||
static const SpriteGroup *IndustryTileResolveReal(const ResolverObject *object, const RealSpriteGroup *group)
|
||||
/* virtual */ const SpriteGroup *IndustryTileResolverObject::ResolveReal(const RealSpriteGroup *group) const
|
||||
{
|
||||
/* IndustryTile do not have 'real' groups. Or do they?? */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static uint32 IndustryTileGetRandomBits(const ResolverObject *object)
|
||||
/* virtual */ uint32 IndustryTileScopeResolver::GetRandomBits() const
|
||||
{
|
||||
const TileIndex tile = object->u.industry.tile;
|
||||
const Industry *ind = object->u.industry.ind;
|
||||
assert(ind != NULL && IsValidTile(tile));
|
||||
assert(ind->index == INVALID_INDUSTRY || IsTileType(tile, MP_INDUSTRY));
|
||||
assert(this->industry != NULL && IsValidTile(this->tile));
|
||||
assert(this->industry->index == INVALID_INDUSTRY || IsTileType(this->tile, MP_INDUSTRY));
|
||||
|
||||
return (object->scope == VSG_SCOPE_SELF) ?
|
||||
(ind->index != INVALID_INDUSTRY ? GetIndustryRandomBits(tile) : 0) :
|
||||
ind->random;
|
||||
return (this->industry->index != INVALID_INDUSTRY) ? GetIndustryRandomBits(this->tile) : 0;
|
||||
}
|
||||
|
||||
static uint32 IndustryTileGetTriggers(const ResolverObject *object)
|
||||
/* virtual */ uint32 IndustryTileScopeResolver::GetTriggers() const
|
||||
{
|
||||
const TileIndex tile = object->u.industry.tile;
|
||||
const Industry *ind = object->u.industry.ind;
|
||||
assert(ind != NULL && IsValidTile(tile));
|
||||
assert(ind->index == INVALID_INDUSTRY || IsTileType(tile, MP_INDUSTRY));
|
||||
if (ind->index == INVALID_INDUSTRY) return 0;
|
||||
return (object->scope == VSG_SCOPE_SELF) ? GetIndustryTriggers(tile) : ind->random_triggers;
|
||||
assert(this->industry != NULL && IsValidTile(this->tile));
|
||||
assert(this->industry->index == INVALID_INDUSTRY || IsTileType(this->tile, MP_INDUSTRY));
|
||||
if (this->industry->index == INVALID_INDUSTRY) return 0;
|
||||
return GetIndustryTriggers(this->tile);
|
||||
}
|
||||
|
||||
static void IndustryTileSetTriggers(const ResolverObject *object, int triggers)
|
||||
/* virtual */ void IndustryTileScopeResolver::SetTriggers(int triggers) const
|
||||
{
|
||||
const TileIndex tile = object->u.industry.tile;
|
||||
Industry *ind = object->u.industry.ind;
|
||||
assert(ind != NULL && ind->index != INVALID_INDUSTRY && IsValidTile(tile) && IsTileType(tile, MP_INDUSTRY));
|
||||
|
||||
if (object->scope == VSG_SCOPE_SELF) {
|
||||
SetIndustryTriggers(tile, triggers);
|
||||
} else {
|
||||
ind->random_triggers = triggers;
|
||||
}
|
||||
assert(this->industry != NULL && this->industry->index != INVALID_INDUSTRY && IsValidTile(this->tile) && IsTileType(this->tile, MP_INDUSTRY));
|
||||
SetIndustryTriggers(this->tile, triggers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a value into the persistent storage of the object's parent.
|
||||
* @param object Object that we want to query.
|
||||
* @param pos Position in the persistent storage to use.
|
||||
* @param value Value to store.
|
||||
* Get the associated NewGRF file from the industry graphics.
|
||||
* @param gfx Graphics to query.
|
||||
* @return Grf file associated with the graphics, if any.
|
||||
*/
|
||||
void IndustryTileStorePSA(ResolverObject *object, uint pos, int32 value)
|
||||
static const GRFFile *GetIndTileGrffile(IndustryGfx gfx)
|
||||
{
|
||||
Industry *ind = object->u.industry.ind;
|
||||
if (object->scope != VSG_SCOPE_PARENT || ind->index == INVALID_INDUSTRY) return;
|
||||
|
||||
if (ind->psa == NULL) {
|
||||
/* There is no need to create a storage if the value is zero. */
|
||||
if (value == 0) return;
|
||||
|
||||
/* Create storage on first modification. */
|
||||
const IndustrySpec *indsp = GetIndustrySpec(ind->type);
|
||||
uint32 grfid = (indsp->grf_prop.grffile != NULL) ? indsp->grf_prop.grffile->grfid : 0;
|
||||
assert(PersistentStorage::CanAllocateItem());
|
||||
ind->psa = new PersistentStorage(grfid);
|
||||
}
|
||||
|
||||
ind->psa->StoreValue(pos, value);
|
||||
}
|
||||
|
||||
static void NewIndustryTileResolver(ResolverObject *res, IndustryGfx gfx, TileIndex tile, Industry *indus)
|
||||
{
|
||||
res->GetRandomBits = IndustryTileGetRandomBits;
|
||||
res->GetTriggers = IndustryTileGetTriggers;
|
||||
res->SetTriggers = IndustryTileSetTriggers;
|
||||
res->GetVariable = IndustryTileGetVariable;
|
||||
res->ResolveRealMethod = IndustryTileResolveReal;
|
||||
res->StorePSA = IndustryTileStorePSA;
|
||||
|
||||
res->u.industry.tile = tile;
|
||||
res->u.industry.ind = indus;
|
||||
res->u.industry.gfx = gfx;
|
||||
res->u.industry.type = indus->type;
|
||||
|
||||
res->callback = CBID_NO_CALLBACK;
|
||||
res->callback_param1 = 0;
|
||||
res->callback_param2 = 0;
|
||||
res->ResetState();
|
||||
|
||||
const IndustryTileSpec *its = GetIndustryTileSpec(gfx);
|
||||
res->grffile = (its != NULL ? its->grf_prop.grffile : NULL);
|
||||
return (its != NULL) ? its->grf_prop.grffile : NULL;
|
||||
}
|
||||
|
||||
IndustryTileResolverObject::IndustryTileResolverObject(IndustryGfx gfx, TileIndex tile, Industry *indus,
|
||||
CallbackID callback, uint32 callback_param1, uint32 callback_param2)
|
||||
: ResolverObject(GetIndTileGrffile(gfx), callback, callback_param1, callback_param2),
|
||||
indtile_scope(this, indus, tile),
|
||||
ind_scope(this, tile, indus, indus->type)
|
||||
{
|
||||
}
|
||||
|
||||
IndustryTileScopeResolver::IndustryTileScopeResolver(ResolverObject *ro, Industry *industry, TileIndex tile) : ScopeResolver(ro)
|
||||
{
|
||||
this->industry = industry;
|
||||
this->tile = tile;
|
||||
}
|
||||
|
||||
static void IndustryDrawTileLayout(const TileInfo *ti, const TileLayoutSpriteGroup *group, byte rnd_colour, byte stage, IndustryGfx gfx)
|
||||
|
@ -218,18 +177,11 @@ static void IndustryDrawTileLayout(const TileInfo *ti, const TileLayoutSpriteGro
|
|||
|
||||
uint16 GetIndustryTileCallback(CallbackID callback, uint32 param1, uint32 param2, IndustryGfx gfx_id, Industry *industry, TileIndex tile)
|
||||
{
|
||||
ResolverObject object;
|
||||
const SpriteGroup *group;
|
||||
|
||||
assert(industry != NULL && IsValidTile(tile));
|
||||
assert(industry->index == INVALID_INDUSTRY || IsTileType(tile, MP_INDUSTRY));
|
||||
|
||||
NewIndustryTileResolver(&object, gfx_id, tile, industry);
|
||||
object.callback = callback;
|
||||
object.callback_param1 = param1;
|
||||
object.callback_param2 = param2;
|
||||
|
||||
group = SpriteGroup::Resolve(GetIndustryTileSpec(gfx_id)->grf_prop.spritegroup[0], &object);
|
||||
IndustryTileResolverObject object(gfx_id, tile, industry, callback, param1, param2);
|
||||
const SpriteGroup *group = SpriteGroup::Resolve(GetIndustryTileSpec(gfx_id)->grf_prop.spritegroup[0], &object);
|
||||
if (group == NULL || group->type != SGT_CALLBACK) return CALLBACK_FAILED;
|
||||
|
||||
return group->GetCallbackResult();
|
||||
|
@ -237,9 +189,6 @@ uint16 GetIndustryTileCallback(CallbackID callback, uint32 param1, uint32 param2
|
|||
|
||||
bool DrawNewIndustryTile(TileInfo *ti, Industry *i, IndustryGfx gfx, const IndustryTileSpec *inds)
|
||||
{
|
||||
const SpriteGroup *group;
|
||||
ResolverObject object;
|
||||
|
||||
if (ti->tileh != SLOPE_FLAT) {
|
||||
bool draw_old_one = true;
|
||||
if (HasBit(inds->callback_mask, CBM_INDT_DRAW_FOUNDATIONS)) {
|
||||
|
@ -251,9 +200,9 @@ bool DrawNewIndustryTile(TileInfo *ti, Industry *i, IndustryGfx gfx, const Indus
|
|||
if (draw_old_one) DrawFoundation(ti, FOUNDATION_LEVELED);
|
||||
}
|
||||
|
||||
NewIndustryTileResolver(&object, gfx, ti->tile, i);
|
||||
IndustryTileResolverObject object(gfx, ti->tile, i);
|
||||
|
||||
group = SpriteGroup::Resolve(inds->grf_prop.spritegroup[0], &object);
|
||||
const SpriteGroup *group = SpriteGroup::Resolve(inds->grf_prop.spritegroup[0], &object);
|
||||
if (group == NULL || group->type != SGT_TILELAYOUT) {
|
||||
return false;
|
||||
} else {
|
||||
|
@ -362,8 +311,6 @@ bool StartStopIndustryTileAnimation(const Industry *ind, IndustryAnimationTrigge
|
|||
*/
|
||||
static void DoTriggerIndustryTile(TileIndex tile, IndustryTileTrigger trigger, Industry *ind, uint32 &reseed_industry)
|
||||
{
|
||||
ResolverObject object;
|
||||
|
||||
assert(IsValidTile(tile) && IsTileType(tile, MP_INDUSTRY));
|
||||
|
||||
IndustryGfx gfx = GetIndustryGfx(tile);
|
||||
|
@ -371,9 +318,7 @@ static void DoTriggerIndustryTile(TileIndex tile, IndustryTileTrigger trigger, I
|
|||
|
||||
if (itspec->grf_prop.spritegroup[0] == NULL) return;
|
||||
|
||||
NewIndustryTileResolver(&object, gfx, tile, ind);
|
||||
|
||||
object.callback = CBID_RANDOM_TRIGGER;
|
||||
IndustryTileResolverObject object(gfx, tile, ind, CBID_RANDOM_TRIGGER);
|
||||
object.trigger = trigger;
|
||||
|
||||
const SpriteGroup *group = SpriteGroup::Resolve(itspec->grf_prop.spritegroup[0], &object);
|
||||
|
@ -432,12 +377,3 @@ void TriggerIndustry(Industry *ind, IndustryTileTrigger trigger)
|
|||
DoReseedIndustry(ind, reseed_industry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a industry tile's spec and such so we can get a variable.
|
||||
* @param ro The resolver object to fill.
|
||||
* @param index The industry tile to get the data from.
|
||||
*/
|
||||
void GetIndustryTileResolver(ResolverObject *ro, uint index)
|
||||
{
|
||||
NewIndustryTileResolver(ro, GetIndustryGfx(index), index, Industry::GetByTile(index));
|
||||
}
|
||||
|
|
|
@ -16,6 +16,37 @@
|
|||
#include "newgrf_industries.h"
|
||||
#include "core/random_func.hpp"
|
||||
|
||||
struct IndustryTileScopeResolver : public ScopeResolver {
|
||||
Industry *industry;
|
||||
TileIndex tile;
|
||||
|
||||
IndustryTileScopeResolver(ResolverObject *ro, Industry *industry, TileIndex tile);
|
||||
|
||||
/* virtual */ uint32 GetRandomBits() const;
|
||||
/* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
|
||||
/* virtual */ uint32 GetTriggers() const;
|
||||
/* virtual */ void SetTriggers(int triggers) const;
|
||||
};
|
||||
|
||||
struct IndustryTileResolverObject : public ResolverObject {
|
||||
IndustryTileScopeResolver indtile_scope;
|
||||
IndustriesScopeResolver ind_scope;
|
||||
|
||||
IndustryTileResolverObject(IndustryGfx gfx, TileIndex tile, Industry *indus,
|
||||
CallbackID callback = CBID_NO_CALLBACK, uint32 callback_param1 = 0, uint32 callback_param2 = 0);
|
||||
|
||||
/* virtual */ ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0)
|
||||
{
|
||||
switch (scope) {
|
||||
case VSG_SCOPE_SELF: return &indtile_scope;
|
||||
case VSG_SCOPE_PARENT: return &ind_scope;
|
||||
default: return &this->default_scope; // XXX ResolverObject::GetScope(scope, relative);
|
||||
}
|
||||
}
|
||||
|
||||
/* virtual */ const SpriteGroup *ResolveReal(const RealSpriteGroup *group) const;
|
||||
};
|
||||
|
||||
bool DrawNewIndustryTile(TileInfo *ti, Industry *i, IndustryGfx gfx, const IndustryTileSpec *inds);
|
||||
uint16 GetIndustryTileCallback(CallbackID callback, uint32 param1, uint32 param2, IndustryGfx gfx_id, Industry *industry, TileIndex tile);
|
||||
CommandCost PerformIndustryTileSlopeCheck(TileIndex ind_base_tile, TileIndex ind_tile, const IndustryTileSpec *its, IndustryType type, IndustryGfx gfx, uint itspec_index, uint16 initial_random_bits, Owner founder, IndustryAvailabilityCallType creation_type);
|
||||
|
|
|
@ -357,12 +357,6 @@ struct ResolverObject {
|
|||
EngineID self_type;
|
||||
bool info_view; ///< Indicates if the item is being drawn in an info window
|
||||
} vehicle;
|
||||
struct {
|
||||
TileIndex tile;
|
||||
Industry *ind;
|
||||
IndustryGfx gfx;
|
||||
IndustryType type;
|
||||
} industry;
|
||||
} u;
|
||||
|
||||
uint32 (*GetRandomBits)(const struct ResolverObject*);
|
||||
|
|
|
@ -241,7 +241,12 @@ class NIHIndustryTile : public NIHelper {
|
|||
const void *GetSpec(uint index) const { return GetIndustryTileSpec(GetIndustryGfx(index)); }
|
||||
void SetStringParameters(uint index) const { this->SetObjectAtStringParameters(STR_INDUSTRY_NAME, GetIndustryIndex(index), index); }
|
||||
uint32 GetGRFID(uint index) const { return (this->IsInspectable(index)) ? GetIndustryTileSpec(GetIndustryGfx(index))->grf_prop.grffile->grfid : 0; }
|
||||
void Resolve(ResolverObject *ro, uint32 index) const { extern void GetIndustryTileResolver(ResolverObject *ro, uint index); GetIndustryTileResolver(ro, index); }
|
||||
|
||||
/* virtual */ uint Resolve(uint index, uint var, uint param, bool *avail) const
|
||||
{
|
||||
IndustryTileResolverObject ro(GetIndustryGfx(index), index, Industry::GetByTile(index));
|
||||
return ro.GetScope(ro.scope)->GetVariable(var, param, avail);
|
||||
}
|
||||
};
|
||||
|
||||
static const NIFeature _nif_industrytile = {
|
||||
|
|
Loading…
Reference in New Issue