forked from mirror/OpenTTD
(svn r24690) -Codechange: Add resolver classes for industry tiles.
This commit is contained in:
@@ -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) {
|
||||
|
Reference in New Issue
Block a user