2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file newgrf_industries.cpp Handling of NewGRF industries. */
|
2007-06-09 02:05:51 +00:00
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "debug.h"
|
2009-08-30 11:47:41 +00:00
|
|
|
#include "industry.h"
|
2007-06-09 02:05:51 +00:00
|
|
|
#include "newgrf_industries.h"
|
2007-07-09 13:21:49 +00:00
|
|
|
#include "newgrf_town.h"
|
2010-08-07 20:11:27 +00:00
|
|
|
#include "newgrf_cargo.h"
|
2007-12-25 11:26:07 +00:00
|
|
|
#include "window_func.h"
|
2008-01-07 14:02:26 +00:00
|
|
|
#include "town.h"
|
2008-09-30 20:51:04 +00:00
|
|
|
#include "company_base.h"
|
2011-12-10 13:54:10 +00:00
|
|
|
#include "error.h"
|
2009-04-05 12:17:36 +00:00
|
|
|
#include "strings_func.h"
|
2010-01-15 16:41:15 +00:00
|
|
|
#include "core/random_func.hpp"
|
2007-06-09 02:05:51 +00:00
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/strings.h"
|
|
|
|
|
2014-04-23 20:13:33 +00:00
|
|
|
#include "safeguards.h"
|
|
|
|
|
2007-06-09 02:05:51 +00:00
|
|
|
/* Since the industry IDs defined by the GRF file don't necessarily correlate
|
|
|
|
* to those used by the game, the IDs used for overriding old industries must be
|
|
|
|
* translated when the idustry spec is set. */
|
|
|
|
IndustryOverrideManager _industry_mngr(NEW_INDUSTRYOFFSET, NUM_INDUSTRYTYPES, INVALID_INDUSTRYTYPE);
|
2007-06-21 17:09:10 +00:00
|
|
|
IndustryTileOverrideManager _industile_mngr(NEW_INDUSTRYTILEOFFSET, NUM_INDUSTRYTILES, INVALID_INDUSTRYTILE);
|
2007-06-09 02:05:51 +00:00
|
|
|
|
2011-05-02 16:14:23 +00:00
|
|
|
/**
|
|
|
|
* Map the GRF local type to an industry type.
|
|
|
|
* @param grf_type The GRF local type.
|
|
|
|
* @param grf_id The GRF of the local type.
|
|
|
|
* @return The industry type in the global scope.
|
|
|
|
*/
|
2007-07-11 22:57:47 +00:00
|
|
|
IndustryType MapNewGRFIndustryType(IndustryType grf_type, uint32 grf_id)
|
|
|
|
{
|
|
|
|
if (grf_type == IT_INVALID) return IT_INVALID;
|
2015-05-09 10:21:55 +00:00
|
|
|
if (!HasBit(grf_type, 7)) return GB(grf_type, 0, 7);
|
2007-07-11 22:57:47 +00:00
|
|
|
|
2015-05-09 10:21:55 +00:00
|
|
|
return _industry_mngr.GetID(GB(grf_type, 0, 7), grf_id);
|
2007-07-11 22:57:47 +00:00
|
|
|
}
|
|
|
|
|
2010-01-21 18:32:44 +00:00
|
|
|
/**
|
|
|
|
* Make an analysis of a tile and check for its belonging to the same
|
2007-06-12 00:49:50 +00:00
|
|
|
* industry, and/or the same grf file
|
2007-09-23 19:55:42 +00:00
|
|
|
* @param tile TileIndex of the tile to query
|
|
|
|
* @param i Industry to which to compare the tile to
|
2010-01-21 18:32:44 +00:00
|
|
|
* @param cur_grfid GRFID of the current callback chain
|
|
|
|
* @return value encoded as per NFO specs
|
|
|
|
*/
|
|
|
|
uint32 GetIndustryIDAtOffset(TileIndex tile, const Industry *i, uint32 cur_grfid)
|
2007-06-12 00:49:50 +00:00
|
|
|
{
|
2013-10-13 11:04:20 +00:00
|
|
|
if (!i->TileBelongsToIndustry(tile)) {
|
2007-09-23 19:55:42 +00:00
|
|
|
/* No industry and/or the tile does not have the same industry as the one we match it with */
|
|
|
|
return 0xFFFF;
|
2007-06-12 00:49:50 +00:00
|
|
|
}
|
|
|
|
|
2007-09-23 19:55:42 +00:00
|
|
|
IndustryGfx gfx = GetCleanIndustryGfx(tile);
|
|
|
|
const IndustryTileSpec *indtsp = GetIndustryTileSpec(gfx);
|
|
|
|
|
2010-10-09 18:43:37 +00:00
|
|
|
if (gfx < NEW_INDUSTRYTILEOFFSET) { // Does it belongs to an old type?
|
2013-01-08 22:46:42 +00:00
|
|
|
/* It is an old tile. We have to see if it's been overridden */
|
2007-09-23 19:55:42 +00:00
|
|
|
if (indtsp->grf_prop.override == INVALID_INDUSTRYTILE) { // has it been overridden?
|
|
|
|
return 0xFF << 8 | gfx; // no. Tag FF + the gfx id of that tile
|
|
|
|
}
|
2013-01-08 22:46:42 +00:00
|
|
|
/* Overridden */
|
2007-09-23 19:55:42 +00:00
|
|
|
const IndustryTileSpec *tile_ovr = GetIndustryTileSpec(indtsp->grf_prop.override);
|
|
|
|
|
2010-01-21 18:32:44 +00:00
|
|
|
if (tile_ovr->grf_prop.grffile->grfid == cur_grfid) {
|
2007-09-23 19:55:42 +00:00
|
|
|
return tile_ovr->grf_prop.local_id; // same grf file
|
|
|
|
} else {
|
|
|
|
return 0xFFFE; // not the same grf file
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Not an 'old type' tile */
|
2019-04-10 21:07:06 +00:00
|
|
|
if (indtsp->grf_prop.spritegroup[0] != nullptr) { // tile has a spritegroup ?
|
2010-01-21 18:32:44 +00:00
|
|
|
if (indtsp->grf_prop.grffile->grfid == cur_grfid) { // same industry, same grf ?
|
2007-09-23 19:55:42 +00:00
|
|
|
return indtsp->grf_prop.local_id;
|
|
|
|
} else {
|
|
|
|
return 0xFFFE; // Defined in another grf file
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* The tile has no spritegroup */
|
|
|
|
return 0xFF << 8 | indtsp->grf_prop.subst_id; // so just give him the substitute
|
2007-06-12 00:49:50 +00:00
|
|
|
}
|
|
|
|
|
2007-07-11 22:57:47 +00:00
|
|
|
static uint32 GetClosestIndustry(TileIndex tile, IndustryType type, const Industry *current)
|
|
|
|
{
|
2008-06-27 17:46:43 +00:00
|
|
|
uint32 best_dist = UINT32_MAX;
|
2019-12-16 17:51:20 +00:00
|
|
|
for (const Industry *i : Industry::Iterate()) {
|
2007-07-11 22:57:47 +00:00
|
|
|
if (i->type != type || i == current) continue;
|
|
|
|
|
2010-01-04 18:21:07 +00:00
|
|
|
best_dist = min(best_dist, DistanceManhattan(tile, i->location.tile));
|
2007-07-11 22:57:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return best_dist;
|
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Implementation of both var 67 and 68
|
2007-08-17 00:23:33 +00:00
|
|
|
* since the mechanism is almost the same, it is easier to regroup them on the same
|
|
|
|
* function.
|
|
|
|
* @param param_setID parameter given to the callback, which is the set id, or the local id, in our terminology
|
|
|
|
* @param layout_filter on what layout do we filter?
|
2011-05-07 10:20:29 +00:00
|
|
|
* @param town_filter Do we filter on the same town as the current industry?
|
2007-08-17 00:23:33 +00:00
|
|
|
* @param current Industry for which the inquiry is made
|
|
|
|
* @return the formatted answer to the callback : rr(reserved) cc(count) dddd(manhattan distance of closest sister)
|
|
|
|
*/
|
2011-05-07 10:20:29 +00:00
|
|
|
static uint32 GetCountAndDistanceOfClosestInstance(byte param_setID, byte layout_filter, bool town_filter, const Industry *current)
|
2007-08-17 00:23:33 +00:00
|
|
|
{
|
|
|
|
uint32 GrfID = GetRegister(0x100); ///< Get the GRFID of the definition to look for in register 100h
|
|
|
|
IndustryType ind_index;
|
2008-06-27 17:46:43 +00:00
|
|
|
uint32 closest_dist = UINT32_MAX;
|
2007-08-17 00:23:33 +00:00
|
|
|
byte count = 0;
|
|
|
|
|
|
|
|
/* Determine what will be the industry type to look for */
|
|
|
|
switch (GrfID) {
|
|
|
|
case 0: // this is a default industry type
|
|
|
|
ind_index = param_setID;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0xFFFFFFFF: // current grf
|
2007-10-04 07:09:05 +00:00
|
|
|
GrfID = GetIndustrySpec(current->type)->grf_prop.grffile->grfid;
|
2017-08-13 18:38:42 +00:00
|
|
|
FALLTHROUGH;
|
2007-08-17 00:23:33 +00:00
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
default: // use the grfid specified in register 100h
|
2007-11-20 13:35:54 +00:00
|
|
|
SetBit(param_setID, 7); // bit 7 means it is not an old type
|
2007-08-17 00:23:33 +00:00
|
|
|
ind_index = MapNewGRFIndustryType(param_setID, GrfID);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-04-24 19:06:54 +00:00
|
|
|
/* If the industry type is invalid, there is none and the closest is far away. */
|
|
|
|
if (ind_index >= NUM_INDUSTRYTYPES) return 0 | 0xFFFF;
|
|
|
|
|
2011-05-07 10:20:29 +00:00
|
|
|
if (layout_filter == 0 && !town_filter) {
|
2007-08-17 00:23:33 +00:00
|
|
|
/* If the filter is 0, it could be because none was specified as well as being really a 0.
|
|
|
|
* In either case, just do the regular var67 */
|
2010-01-04 18:21:07 +00:00
|
|
|
closest_dist = GetClosestIndustry(current->location.tile, ind_index, current);
|
2010-03-20 14:30:16 +00:00
|
|
|
count = min(Industry::GetIndustryTypeCount(ind_index), UINT8_MAX); // clamp to 8 bit
|
2007-08-17 00:23:33 +00:00
|
|
|
} else {
|
|
|
|
/* Count only those who match the same industry type and layout filter
|
|
|
|
* Unfortunately, we have to do it manually */
|
2019-12-16 17:51:20 +00:00
|
|
|
for (const Industry *i : Industry::Iterate()) {
|
2011-05-07 10:20:29 +00:00
|
|
|
if (i->type == ind_index && i != current && (i->selected_layout == layout_filter || layout_filter == 0) && (!town_filter || i->town == current->town)) {
|
2010-01-04 18:21:07 +00:00
|
|
|
closest_dist = min(closest_dist, DistanceManhattan(current->location.tile, i->location.tile));
|
2007-08-17 00:23:33 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return count << 16 | GB(closest_dist, 0, 16);
|
|
|
|
}
|
|
|
|
|
2012-11-10 20:44:10 +00:00
|
|
|
/* virtual */ uint32 IndustriesScopeResolver::GetVariable(byte variable, uint32 parameter, bool *available) const
|
|
|
|
{
|
2013-11-24 14:41:19 +00:00
|
|
|
if (this->ro.callback == CBID_INDUSTRY_LOCATION) {
|
2012-11-10 20:44:10 +00:00
|
|
|
/* Variables available during construction check. */
|
|
|
|
|
|
|
|
switch (variable) {
|
|
|
|
case 0x80: return this->tile;
|
|
|
|
case 0x81: return GB(this->tile, 8, 8);
|
|
|
|
|
|
|
|
/* Pointer to the town the industry is associated with */
|
|
|
|
case 0x82: return this->industry->town->index;
|
|
|
|
case 0x83:
|
|
|
|
case 0x84:
|
|
|
|
case 0x85: DEBUG(grf, 0, "NewGRFs shouldn't be doing pointer magic"); break; // not supported
|
|
|
|
|
|
|
|
/* Number of the layout */
|
|
|
|
case 0x86: return this->industry->selected_layout;
|
|
|
|
|
|
|
|
/* Ground type */
|
|
|
|
case 0x87: return GetTerrainType(this->tile);
|
|
|
|
|
|
|
|
/* Town zone */
|
|
|
|
case 0x88: return GetTownRadiusGroup(this->industry->town, this->tile);
|
|
|
|
|
|
|
|
/* Manhattan distance of the closest town */
|
|
|
|
case 0x89: return min(DistanceManhattan(this->industry->town->xy, this->tile), 255);
|
|
|
|
|
|
|
|
/* Lowest height of the tile */
|
2013-11-24 14:41:19 +00:00
|
|
|
case 0x8A: return Clamp(GetTileZ(this->tile) * (this->ro.grffile->grf_version >= 8 ? 1 : TILE_HEIGHT), 0, 0xFF);
|
2012-11-10 20:44:10 +00:00
|
|
|
|
|
|
|
/* Distance to the nearest water/land tile */
|
|
|
|
case 0x8B: return GetClosestWaterDistance(this->tile, (GetIndustrySpec(this->industry->type)->behaviour & INDUSTRYBEH_BUILT_ONWATER) == 0);
|
|
|
|
|
|
|
|
/* Square of Euclidian distance from town */
|
|
|
|
case 0x8D: return min(DistanceSquare(this->industry->town->xy, this->tile), 65535);
|
|
|
|
|
|
|
|
/* 32 random bits */
|
|
|
|
case 0x8F: return this->random_bits;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const IndustrySpec *indspec = GetIndustrySpec(this->type);
|
|
|
|
|
2019-04-10 21:07:06 +00:00
|
|
|
if (this->industry == nullptr) {
|
2013-11-24 14:41:19 +00:00
|
|
|
DEBUG(grf, 1, "Unhandled variable 0x%X (no available industry) in callback 0x%x", variable, this->ro.callback);
|
2012-11-10 20:44:10 +00:00
|
|
|
|
|
|
|
*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 (this->industry->prod_level == 0) return 0;
|
|
|
|
return min(this->industry->incoming_cargo_waiting[variable - 0x40] / this->industry->prod_level, (uint16)0xFFFF);
|
|
|
|
} else {
|
|
|
|
return min(this->industry->incoming_cargo_waiting[variable - 0x40], (uint16)0xFFFF);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Manhattan distance of closes dry/water tile */
|
2013-02-05 21:38:38 +00:00
|
|
|
case 0x43:
|
|
|
|
if (this->tile == INVALID_TILE) break;
|
|
|
|
return GetClosestWaterDistance(this->tile, (indspec->behaviour & INDUSTRYBEH_BUILT_ONWATER) == 0);
|
2012-11-10 20:44:10 +00:00
|
|
|
|
|
|
|
/* Layout number */
|
|
|
|
case 0x44: return this->industry->selected_layout;
|
|
|
|
|
|
|
|
/* Company info */
|
|
|
|
case 0x45: {
|
|
|
|
byte colours = 0;
|
|
|
|
bool is_ai = false;
|
|
|
|
|
|
|
|
const Company *c = Company::GetIfValid(this->industry->founder);
|
2019-04-10 21:07:06 +00:00
|
|
|
if (c != nullptr) {
|
2012-11-10 20:44:10 +00:00
|
|
|
const Livery *l = &c->livery[LS_DEFAULT];
|
|
|
|
|
|
|
|
is_ai = c->is_ai;
|
|
|
|
colours = l->colour1 + l->colour2 * 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this->industry->founder | (is_ai ? 0x10000 : 0) | (colours << 24);
|
|
|
|
}
|
|
|
|
|
|
|
|
case 0x46: return this->industry->construction_date; // Date when built - long format - (in days)
|
|
|
|
|
|
|
|
/* Get industry ID at offset param */
|
2013-11-24 14:41:19 +00:00
|
|
|
case 0x60: return GetIndustryIDAtOffset(GetNearbyTile(parameter, this->industry->location.tile, false), this->industry, this->ro.grffile->grfid);
|
2012-11-10 20:44:10 +00:00
|
|
|
|
|
|
|
/* Get random tile bits at offset param */
|
|
|
|
case 0x61: {
|
2013-02-05 21:38:38 +00:00
|
|
|
if (this->tile == INVALID_TILE) break;
|
2012-11-10 20:44:10 +00:00
|
|
|
TileIndex tile = GetNearbyTile(parameter, this->tile, false);
|
|
|
|
return this->industry->TileBelongsToIndustry(tile) ? GetIndustryRandomBits(tile) : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Land info of nearby tiles */
|
2013-02-05 21:38:38 +00:00
|
|
|
case 0x62:
|
|
|
|
if (this->tile == INVALID_TILE) break;
|
2013-11-24 14:41:19 +00:00
|
|
|
return GetNearbyIndustryTileInformation(parameter, this->tile, INVALID_INDUSTRY, false, this->ro.grffile->grf_version >= 8);
|
2012-11-10 20:44:10 +00:00
|
|
|
|
|
|
|
/* Animation stage of nearby tiles */
|
|
|
|
case 0x63: {
|
2013-02-05 21:38:38 +00:00
|
|
|
if (this->tile == INVALID_TILE) break;
|
2012-11-10 20:44:10 +00:00
|
|
|
TileIndex tile = GetNearbyTile(parameter, this->tile, false);
|
|
|
|
if (this->industry->TileBelongsToIndustry(tile)) {
|
|
|
|
return GetAnimationFrame(tile);
|
|
|
|
}
|
|
|
|
return 0xFFFFFFFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Distance of nearest industry of given type */
|
2013-02-05 21:38:38 +00:00
|
|
|
case 0x64:
|
|
|
|
if (this->tile == INVALID_TILE) break;
|
|
|
|
return GetClosestIndustry(this->tile, MapNewGRFIndustryType(parameter, indspec->grf_prop.grffile->grfid), this->industry);
|
2012-11-10 20:44:10 +00:00
|
|
|
/* Get town zone and Manhattan distance of closest town */
|
2013-02-05 21:38:38 +00:00
|
|
|
case 0x65:
|
|
|
|
if (this->tile == INVALID_TILE) break;
|
|
|
|
return GetTownRadiusGroup(this->industry->town, this->tile) << 16 | min(DistanceManhattan(this->tile, this->industry->town->xy), 0xFFFF);
|
2012-11-10 20:44:10 +00:00
|
|
|
/* Get square of Euclidian distance of closes town */
|
2013-02-05 21:38:38 +00:00
|
|
|
case 0x66:
|
|
|
|
if (this->tile == INVALID_TILE) break;
|
|
|
|
return GetTownRadiusGroup(this->industry->town, this->tile) << 16 | min(DistanceSquare(this->tile, this->industry->town->xy), 0xFFFF);
|
2012-11-10 20:44:10 +00:00
|
|
|
|
|
|
|
/* 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, this->industry);
|
|
|
|
}
|
|
|
|
|
2018-07-26 17:29:54 +00:00
|
|
|
case 0x69:
|
|
|
|
case 0x6A:
|
|
|
|
case 0x6B:
|
|
|
|
case 0x6C:
|
2019-03-24 17:32:39 +00:00
|
|
|
case 0x6D:
|
|
|
|
case 0x70:
|
|
|
|
case 0x71: {
|
2018-07-26 17:29:54 +00:00
|
|
|
CargoID cargo = GetCargoTranslation(parameter, this->ro.grffile);
|
|
|
|
int index = this->industry->GetCargoProducedIndex(cargo);
|
|
|
|
if (index < 0) return 0; // invalid cargo
|
2019-03-24 17:03:18 +00:00
|
|
|
switch (variable) {
|
|
|
|
case 0x69: return this->industry->produced_cargo_waiting[index];
|
|
|
|
case 0x6A: return this->industry->this_month_production[index];
|
|
|
|
case 0x6B: return this->industry->this_month_transported[index];
|
|
|
|
case 0x6C: return this->industry->last_month_production[index];
|
|
|
|
case 0x6D: return this->industry->last_month_transported[index];
|
2019-03-24 17:32:39 +00:00
|
|
|
case 0x70: return this->industry->production_rate[index];
|
|
|
|
case 0x71: return this->industry->last_month_pct_transported[index];
|
2019-03-24 17:03:18 +00:00
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
2018-07-26 17:29:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case 0x6E:
|
|
|
|
case 0x6F: {
|
|
|
|
CargoID cargo = GetCargoTranslation(parameter, this->ro.grffile);
|
|
|
|
int index = this->industry->GetCargoAcceptedIndex(cargo);
|
|
|
|
if (index < 0) return 0; // invalid cargo
|
|
|
|
if (variable == 0x6E) return this->industry->last_cargo_accepted_at[index];
|
|
|
|
if (variable == 0x6F) return this->industry->incoming_cargo_waiting[index];
|
|
|
|
NOT_REACHED();
|
|
|
|
}
|
|
|
|
|
2012-11-10 20:44:10 +00:00
|
|
|
/* Get a variable from the persistent storage */
|
2019-04-10 21:07:06 +00:00
|
|
|
case 0x7C: return (this->industry->psa != nullptr) ? this->industry->psa->GetValue(parameter) : 0;
|
2012-11-10 20:44:10 +00:00
|
|
|
|
|
|
|
/* Industry structure access*/
|
|
|
|
case 0x80: return this->industry->location.tile;
|
|
|
|
case 0x81: return GB(this->industry->location.tile, 8, 8);
|
|
|
|
/* Pointer to the town the industry is associated with */
|
|
|
|
case 0x82: return this->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 this->industry->location.w;
|
|
|
|
case 0x87: return this->industry->location.h;// xy dimensions
|
|
|
|
|
|
|
|
case 0x88:
|
|
|
|
case 0x89: return this->industry->produced_cargo[variable - 0x88];
|
|
|
|
case 0x8A: return this->industry->produced_cargo_waiting[0];
|
|
|
|
case 0x8B: return GB(this->industry->produced_cargo_waiting[0], 8, 8);
|
|
|
|
case 0x8C: return this->industry->produced_cargo_waiting[1];
|
|
|
|
case 0x8D: return GB(this->industry->produced_cargo_waiting[1], 8, 8);
|
|
|
|
case 0x8E:
|
|
|
|
case 0x8F: return this->industry->production_rate[variable - 0x8E];
|
|
|
|
case 0x90:
|
|
|
|
case 0x91:
|
|
|
|
case 0x92: return this->industry->accepts_cargo[variable - 0x90];
|
|
|
|
case 0x93: return this->industry->prod_level;
|
|
|
|
/* amount of cargo produced so far THIS month. */
|
|
|
|
case 0x94: return this->industry->this_month_production[0];
|
|
|
|
case 0x95: return GB(this->industry->this_month_production[0], 8, 8);
|
|
|
|
case 0x96: return this->industry->this_month_production[1];
|
|
|
|
case 0x97: return GB(this->industry->this_month_production[1], 8, 8);
|
|
|
|
/* amount of cargo transported so far THIS month. */
|
|
|
|
case 0x98: return this->industry->this_month_transported[0];
|
|
|
|
case 0x99: return GB(this->industry->this_month_transported[0], 8, 8);
|
|
|
|
case 0x9A: return this->industry->this_month_transported[1];
|
|
|
|
case 0x9B: return GB(this->industry->this_month_transported[1], 8, 8);
|
|
|
|
/* fraction of cargo transported LAST month. */
|
|
|
|
case 0x9C:
|
|
|
|
case 0x9D: return this->industry->last_month_pct_transported[variable - 0x9C];
|
|
|
|
/* amount of cargo produced LAST month. */
|
|
|
|
case 0x9E: return this->industry->last_month_production[0];
|
|
|
|
case 0x9F: return GB(this->industry->last_month_production[0], 8, 8);
|
|
|
|
case 0xA0: return this->industry->last_month_production[1];
|
|
|
|
case 0xA1: return GB(this->industry->last_month_production[1], 8, 8);
|
|
|
|
/* amount of cargo transported last month. */
|
|
|
|
case 0xA2: return this->industry->last_month_transported[0];
|
|
|
|
case 0xA3: return GB(this->industry->last_month_transported[0], 8, 8);
|
|
|
|
case 0xA4: return this->industry->last_month_transported[1];
|
|
|
|
case 0xA5: return GB(this->industry->last_month_transported[1], 8, 8);
|
|
|
|
|
2015-05-03 10:33:26 +00:00
|
|
|
case 0xA6: return indspec->grf_prop.local_id;
|
2012-11-10 20:44:10 +00:00
|
|
|
case 0xA7: return this->industry->founder;
|
|
|
|
case 0xA8: return this->industry->random_colour;
|
|
|
|
case 0xA9: return Clamp(this->industry->last_prod_year - ORIGINAL_BASE_YEAR, 0, 255);
|
|
|
|
case 0xAA: return this->industry->counter;
|
|
|
|
case 0xAB: return GB(this->industry->counter, 8, 8);
|
|
|
|
case 0xAC: return this->industry->was_cargo_delivered;
|
|
|
|
|
|
|
|
case 0xB0: return Clamp(this->industry->construction_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535); // Date when built since 1920 (in days)
|
|
|
|
case 0xB3: return this->industry->construction_type; // Construction type
|
2018-07-26 17:29:54 +00:00
|
|
|
case 0xB4: {
|
|
|
|
Date *latest = std::max_element(this->industry->last_cargo_accepted_at, endof(this->industry->last_cargo_accepted_at));
|
|
|
|
return Clamp((*latest) - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535); // Date last cargo accepted since 1920 (in days)
|
|
|
|
}
|
2012-11-10 20:44:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG(grf, 1, "Unhandled industry variable 0x%X", variable);
|
|
|
|
|
|
|
|
*available = false;
|
|
|
|
return UINT_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ uint32 IndustriesScopeResolver::GetRandomBits() const
|
2007-09-23 19:27:35 +00:00
|
|
|
{
|
2019-04-10 21:07:06 +00:00
|
|
|
return this->industry != nullptr ? this->industry->random : 0;
|
2007-09-23 19:27:35 +00:00
|
|
|
}
|
|
|
|
|
2012-11-10 20:44:10 +00:00
|
|
|
/* virtual */ uint32 IndustriesScopeResolver::GetTriggers() const
|
2007-09-23 19:27:35 +00:00
|
|
|
{
|
2017-10-25 15:38:19 +00:00
|
|
|
return 0;
|
2007-09-23 19:27:35 +00:00
|
|
|
}
|
|
|
|
|
2012-11-10 20:44:10 +00:00
|
|
|
/* virtual */ void IndustriesScopeResolver::StorePSA(uint pos, int32 value)
|
2011-06-12 20:38:46 +00:00
|
|
|
{
|
2012-11-10 20:44:10 +00:00
|
|
|
if (this->industry->index == INVALID_INDUSTRY) return;
|
2011-06-12 20:50:03 +00:00
|
|
|
|
2019-04-10 21:07:06 +00:00
|
|
|
if (this->industry->psa == nullptr) {
|
2011-06-12 20:47:45 +00:00
|
|
|
/* There is no need to create a storage if the value is zero. */
|
|
|
|
if (value == 0) return;
|
|
|
|
|
|
|
|
/* Create storage on first modification. */
|
2012-11-10 20:44:10 +00:00
|
|
|
const IndustrySpec *indsp = GetIndustrySpec(this->industry->type);
|
2019-04-10 21:07:06 +00:00
|
|
|
uint32 grfid = (indsp->grf_prop.grffile != nullptr) ? indsp->grf_prop.grffile->grfid : 0;
|
2011-06-12 20:47:45 +00:00
|
|
|
assert(PersistentStorage::CanAllocateItem());
|
2013-12-23 18:09:29 +00:00
|
|
|
this->industry->psa = new PersistentStorage(grfid, GSF_INDUSTRIES, this->industry->location.tile);
|
2011-06-12 20:47:45 +00:00
|
|
|
}
|
|
|
|
|
2012-11-10 20:44:10 +00:00
|
|
|
this->industry->psa->StoreValue(pos, value);
|
2011-06-12 20:38:46 +00:00
|
|
|
}
|
|
|
|
|
2012-11-10 20:44:10 +00:00
|
|
|
/**
|
|
|
|
* Get the grf file associated with the given industry type.
|
|
|
|
* @param type Industry type to query.
|
|
|
|
* @return The associated GRF file, if any.
|
|
|
|
*/
|
|
|
|
static const GRFFile *GetGrffile(IndustryType type)
|
2007-06-09 02:05:51 +00:00
|
|
|
{
|
2008-07-30 18:23:12 +00:00
|
|
|
const IndustrySpec *indspec = GetIndustrySpec(type);
|
2019-04-10 21:07:06 +00:00
|
|
|
return (indspec != nullptr) ? indspec->grf_prop.grffile : nullptr;
|
2012-11-10 20:44:10 +00:00
|
|
|
}
|
|
|
|
|
2012-11-10 20:46:39 +00:00
|
|
|
/**
|
|
|
|
* Constructor of the industries resolver.
|
|
|
|
* @param tile %Tile owned by the industry.
|
2018-10-28 02:17:36 +00:00
|
|
|
* @param indus %Industry being resolved.
|
2012-11-10 20:46:39 +00:00
|
|
|
* @param type Type of the industry.
|
|
|
|
* @param random_bits Random bits of the new industry.
|
|
|
|
* @param callback Callback ID.
|
|
|
|
* @param callback_param1 First parameter (var 10) of the callback.
|
|
|
|
* @param callback_param2 Second parameter (var 18) of the callback.
|
|
|
|
*/
|
2012-11-10 20:44:10 +00:00
|
|
|
IndustriesResolverObject::IndustriesResolverObject(TileIndex tile, Industry *indus, IndustryType type, uint32 random_bits,
|
|
|
|
CallbackID callback, uint32 callback_param1, uint32 callback_param2)
|
|
|
|
: ResolverObject(GetGrffile(type), callback, callback_param1, callback_param2),
|
2013-11-24 14:41:19 +00:00
|
|
|
industries_scope(*this, tile, indus, type, random_bits),
|
2019-04-10 21:07:06 +00:00
|
|
|
town_scope(nullptr)
|
2012-11-10 20:44:10 +00:00
|
|
|
{
|
2014-03-03 20:02:31 +00:00
|
|
|
this->root_spritegroup = GetIndustrySpec(type)->grf_prop.spritegroup[0];
|
2012-11-10 20:44:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
IndustriesResolverObject::~IndustriesResolverObject()
|
|
|
|
{
|
|
|
|
delete this->town_scope;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get or create the town scope object associated with the industry.
|
|
|
|
* @return The associated town scope, if it exists.
|
|
|
|
*/
|
|
|
|
TownScopeResolver *IndustriesResolverObject::GetTown()
|
|
|
|
{
|
2019-04-10 21:07:06 +00:00
|
|
|
if (this->town_scope == nullptr) {
|
|
|
|
Town *t = nullptr;
|
2013-11-23 18:07:11 +00:00
|
|
|
bool readonly = true;
|
2019-04-10 21:07:06 +00:00
|
|
|
if (this->industries_scope.industry != nullptr) {
|
2012-11-10 20:44:10 +00:00
|
|
|
t = this->industries_scope.industry->town;
|
2013-11-23 18:07:11 +00:00
|
|
|
readonly = this->industries_scope.industry->index == INVALID_INDUSTRY;
|
2012-11-10 20:44:10 +00:00
|
|
|
} else if (this->industries_scope.tile != INVALID_TILE) {
|
|
|
|
t = ClosestTownFromTile(this->industries_scope.tile, UINT_MAX);
|
|
|
|
}
|
2019-04-10 21:07:06 +00:00
|
|
|
if (t == nullptr) return nullptr;
|
2013-11-24 14:41:19 +00:00
|
|
|
this->town_scope = new TownScopeResolver(*this, t, readonly);
|
2012-11-10 20:44:10 +00:00
|
|
|
}
|
|
|
|
return this->town_scope;
|
|
|
|
}
|
|
|
|
|
2020-01-26 12:45:51 +00:00
|
|
|
GrfSpecFeature IndustriesResolverObject::GetFeature() const
|
|
|
|
{
|
|
|
|
return GSF_INDUSTRIES;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32 IndustriesResolverObject::GetDebugID() const
|
|
|
|
{
|
|
|
|
return GetIndustrySpec(this->industries_scope.type)->grf_prop.local_id;
|
|
|
|
}
|
|
|
|
|
2011-05-02 16:14:23 +00:00
|
|
|
/**
|
|
|
|
* Perform an industry callback.
|
|
|
|
* @param callback The callback to perform.
|
|
|
|
* @param param1 The first parameter.
|
|
|
|
* @param param2 The second parameter.
|
|
|
|
* @param industry The industry to do the callback for.
|
|
|
|
* @param type The type of industry to do the callback for.
|
|
|
|
* @param tile The tile associated with the callback.
|
|
|
|
* @return The callback result.
|
|
|
|
*/
|
2007-07-25 19:06:29 +00:00
|
|
|
uint16 GetIndustryCallback(CallbackID callback, uint32 param1, uint32 param2, Industry *industry, IndustryType type, TileIndex tile)
|
2007-06-09 02:05:51 +00:00
|
|
|
{
|
2012-11-10 20:44:10 +00:00
|
|
|
IndustriesResolverObject object(tile, industry, type, 0, callback, param1, param2);
|
2014-03-03 20:02:31 +00:00
|
|
|
return object.ResolveCallback();
|
2007-06-09 02:05:51 +00:00
|
|
|
}
|
2007-07-05 05:41:56 +00:00
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Check that the industry callback allows creation of the industry.
|
2010-02-21 17:01:23 +00:00
|
|
|
* @param tile %Tile to build the industry.
|
|
|
|
* @param type Type of industry to build.
|
|
|
|
* @param layout Layout number.
|
|
|
|
* @param seed Seed for the random generator.
|
2010-05-01 13:09:49 +00:00
|
|
|
* @param initial_random_bits The random bits the industry is going to have after construction.
|
2010-05-29 13:08:50 +00:00
|
|
|
* @param founder Industry founder
|
2010-10-16 13:15:54 +00:00
|
|
|
* @param creation_type The circumstances the industry is created under.
|
2010-02-21 17:01:23 +00:00
|
|
|
* @return Succeeded or failed command.
|
|
|
|
*/
|
2019-10-04 19:26:44 +00:00
|
|
|
CommandCost CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, size_t layout, uint32 seed, uint16 initial_random_bits, Owner founder, IndustryAvailabilityCallType creation_type)
|
2007-07-09 13:21:49 +00:00
|
|
|
{
|
|
|
|
const IndustrySpec *indspec = GetIndustrySpec(type);
|
|
|
|
|
2007-10-04 07:09:05 +00:00
|
|
|
Industry ind;
|
|
|
|
ind.index = INVALID_INDUSTRY;
|
2010-01-04 18:21:07 +00:00
|
|
|
ind.location.tile = tile;
|
2010-03-20 14:30:16 +00:00
|
|
|
ind.location.w = 0; // important to mark the industry invalid
|
2007-10-04 07:09:05 +00:00
|
|
|
ind.type = type;
|
2019-10-04 19:26:44 +00:00
|
|
|
ind.selected_layout = (byte)layout;
|
2008-10-14 18:38:51 +00:00
|
|
|
ind.town = ClosestTownFromTile(tile, UINT_MAX);
|
2010-05-01 13:09:49 +00:00
|
|
|
ind.random = initial_random_bits;
|
2010-05-29 13:08:50 +00:00
|
|
|
ind.founder = founder;
|
2019-04-10 21:07:06 +00:00
|
|
|
ind.psa = nullptr;
|
2007-10-04 07:09:05 +00:00
|
|
|
|
2012-11-10 20:44:10 +00:00
|
|
|
IndustriesResolverObject object(tile, &ind, type, seed, CBID_INDUSTRY_LOCATION, 0, creation_type);
|
2014-03-03 20:02:31 +00:00
|
|
|
uint16 result = object.ResolveCallback();
|
2007-07-09 13:21:49 +00:00
|
|
|
|
2007-09-30 18:53:59 +00:00
|
|
|
/* Unlike the "normal" cases, not having a valid result means we allow
|
|
|
|
* the building of the industry, as that's how it's done in TTDP. */
|
2011-07-11 16:32:19 +00:00
|
|
|
if (result == CALLBACK_FAILED) return CommandCost();
|
2011-07-03 14:32:15 +00:00
|
|
|
|
2014-01-12 18:00:19 +00:00
|
|
|
return GetErrorMessageFromLocationCallbackResult(result, indspec->grf_prop.grffile, STR_ERROR_SITE_UNSUITABLE);
|
2007-07-09 13:21:49 +00:00
|
|
|
}
|
|
|
|
|
2010-11-20 14:15:02 +00:00
|
|
|
/**
|
2011-11-08 17:26:13 +00:00
|
|
|
* Check with callback #CBID_INDUSTRY_PROBABILITY whether the industry can be built.
|
2010-11-20 14:15:02 +00:00
|
|
|
* @param type Industry type to check.
|
|
|
|
* @param creation_type Reason to construct a new industry.
|
|
|
|
* @return If the industry has no callback or allows building, \c true is returned. Otherwise, \c false is returned.
|
|
|
|
*/
|
2011-11-08 17:26:13 +00:00
|
|
|
uint32 GetIndustryProbabilityCallback(IndustryType type, IndustryAvailabilityCallType creation_type, uint32 default_prob)
|
2007-07-15 00:19:40 +00:00
|
|
|
{
|
|
|
|
const IndustrySpec *indspec = GetIndustrySpec(type);
|
|
|
|
|
2011-11-08 17:26:13 +00:00
|
|
|
if (HasBit(indspec->callback_mask, CBM_IND_PROBABILITY)) {
|
2019-04-10 21:07:06 +00:00
|
|
|
uint16 res = GetIndustryCallback(CBID_INDUSTRY_PROBABILITY, 0, creation_type, nullptr, type, INVALID_TILE);
|
2007-07-15 00:19:40 +00:00
|
|
|
if (res != CALLBACK_FAILED) {
|
2011-11-08 17:26:13 +00:00
|
|
|
if (indspec->grf_prop.grffile->grf_version < 8) {
|
|
|
|
/* Disallow if result != 0 */
|
|
|
|
if (res != 0) default_prob = 0;
|
|
|
|
} else {
|
|
|
|
/* Use returned probability. 0x100 to use default */
|
|
|
|
if (res < 0x100) {
|
|
|
|
default_prob = res;
|
|
|
|
} else if (res > 0x100) {
|
|
|
|
ErrorUnknownCallbackResult(indspec->grf_prop.grffile->grfid, CBID_INDUSTRY_PROBABILITY, res);
|
|
|
|
}
|
|
|
|
}
|
2007-07-15 00:19:40 +00:00
|
|
|
}
|
|
|
|
}
|
2011-11-08 17:26:13 +00:00
|
|
|
return default_prob;
|
2007-07-15 00:19:40 +00:00
|
|
|
}
|
|
|
|
|
2009-10-24 18:51:21 +00:00
|
|
|
static int32 DerefIndProd(int field, bool use_register)
|
2007-07-05 05:41:56 +00:00
|
|
|
{
|
|
|
|
return use_register ? (int32)GetRegister(field) : field;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the industry production callback and apply it to the industry.
|
|
|
|
* @param ind the industry this callback has to be called for
|
|
|
|
* @param reason the reason it is called (0 = incoming cargo, 1 = periodic tick callback)
|
|
|
|
*/
|
|
|
|
void IndustryProductionCallback(Industry *ind, int reason)
|
|
|
|
{
|
2007-09-22 23:14:32 +00:00
|
|
|
const IndustrySpec *spec = GetIndustrySpec(ind->type);
|
2012-11-10 20:44:10 +00:00
|
|
|
IndustriesResolverObject object(ind->location.tile, ind, ind->type);
|
2007-09-22 23:14:32 +00:00
|
|
|
if ((spec->behaviour & INDUSTRYBEH_PRODCALLBACK_RANDOM) != 0) object.callback_param1 = Random();
|
2007-11-24 14:03:47 +00:00
|
|
|
int multiplier = 1;
|
|
|
|
if ((spec->behaviour & INDUSTRYBEH_PROD_MULTI_HNDLING) != 0) multiplier = ind->prod_level;
|
2007-07-05 05:41:56 +00:00
|
|
|
object.callback_param2 = reason;
|
|
|
|
|
|
|
|
for (uint loop = 0;; loop++) {
|
2009-04-05 12:17:36 +00:00
|
|
|
/* limit the number of calls to break infinite loops.
|
|
|
|
* 'loop' is provided as 16 bits to the newgrf, so abort when those are exceeded. */
|
|
|
|
if (loop >= 0x10000) {
|
|
|
|
/* display error message */
|
|
|
|
SetDParamStr(0, spec->grf_prop.grffile->filename);
|
|
|
|
SetDParam(1, spec->name);
|
2010-02-24 14:46:15 +00:00
|
|
|
ShowErrorMessage(STR_NEWGRF_BUGGY, STR_NEWGRF_BUGGY_ENDLESS_PRODUCTION_CALLBACK, WL_WARNING);
|
2009-04-05 12:17:36 +00:00
|
|
|
|
|
|
|
/* abort the function early, this error isn't critical and will allow the game to continue to run */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-07-05 05:41:56 +00:00
|
|
|
SB(object.callback_param2, 8, 16, loop);
|
2014-03-03 20:02:31 +00:00
|
|
|
const SpriteGroup *tgroup = object.Resolve();
|
2019-04-10 21:07:06 +00:00
|
|
|
if (tgroup == nullptr || tgroup->type != SGT_INDUSTRY_PRODUCTION) break;
|
2009-05-23 12:13:42 +00:00
|
|
|
const IndustryProductionSpriteGroup *group = (const IndustryProductionSpriteGroup *)tgroup;
|
2007-07-05 05:41:56 +00:00
|
|
|
|
2019-03-10 17:45:15 +00:00
|
|
|
if (group->version == 0xFF) {
|
|
|
|
/* Result was marked invalid on load, display error message */
|
|
|
|
SetDParamStr(0, spec->grf_prop.grffile->filename);
|
|
|
|
SetDParam(1, spec->name);
|
|
|
|
SetDParam(2, ind->location.tile);
|
|
|
|
ShowErrorMessage(STR_NEWGRF_BUGGY, STR_NEWGRF_BUGGY_INVALID_CARGO_PRODUCTION_CALLBACK, WL_WARNING);
|
|
|
|
|
|
|
|
/* abort the function early, this error isn't critical and will allow the game to continue to run */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-07-26 17:29:54 +00:00
|
|
|
bool deref = (group->version >= 1);
|
2007-07-05 05:41:56 +00:00
|
|
|
|
2018-07-26 17:29:54 +00:00
|
|
|
if (group->version < 2) {
|
|
|
|
/* Callback parameters map directly to industry cargo slot indices */
|
|
|
|
for (uint i = 0; i < group->num_input; i++) {
|
|
|
|
ind->incoming_cargo_waiting[i] = Clamp(ind->incoming_cargo_waiting[i] - DerefIndProd(group->subtract_input[i], deref) * multiplier, 0, 0xFFFF);
|
|
|
|
}
|
|
|
|
for (uint i = 0; i < group->num_output; i++) {
|
|
|
|
ind->produced_cargo_waiting[i] = Clamp(ind->produced_cargo_waiting[i] + max(DerefIndProd(group->add_output[i], deref), 0) * multiplier, 0, 0xFFFF);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Callback receives list of cargos to apply for, which need to have their cargo slots in industry looked up */
|
|
|
|
for (uint i = 0; i < group->num_input; i++) {
|
|
|
|
int cargo_index = ind->GetCargoAcceptedIndex(group->cargo_input[i]);
|
|
|
|
if (cargo_index < 0) continue;
|
|
|
|
ind->incoming_cargo_waiting[cargo_index] = Clamp(ind->incoming_cargo_waiting[cargo_index] - DerefIndProd(group->subtract_input[i], deref) * multiplier, 0, 0xFFFF);
|
|
|
|
}
|
|
|
|
for (uint i = 0; i < group->num_output; i++) {
|
|
|
|
int cargo_index = ind->GetCargoProducedIndex(group->cargo_output[i]);
|
|
|
|
if (cargo_index < 0) continue;
|
|
|
|
ind->produced_cargo_waiting[cargo_index] = Clamp(ind->produced_cargo_waiting[cargo_index] + max(DerefIndProd(group->add_output[i], deref), 0) * multiplier, 0, 0xFFFF);
|
|
|
|
}
|
2007-07-05 05:41:56 +00:00
|
|
|
}
|
|
|
|
|
2009-05-23 12:13:42 +00:00
|
|
|
int32 again = DerefIndProd(group->again, deref);
|
2007-07-05 05:41:56 +00:00
|
|
|
if (again == 0) break;
|
|
|
|
|
|
|
|
SB(object.callback_param2, 24, 8, again);
|
|
|
|
}
|
2007-07-08 00:25:05 +00:00
|
|
|
|
2009-09-13 19:15:59 +00:00
|
|
|
SetWindowDirty(WC_INDUSTRY_VIEW, ind->index);
|
2007-07-05 05:41:56 +00:00
|
|
|
}
|
2010-04-24 13:35:18 +00:00
|
|
|
|
2010-08-07 20:11:27 +00:00
|
|
|
/**
|
|
|
|
* Check whether an industry temporarily refuses to accept a certain cargo.
|
|
|
|
* @param ind The industry to query.
|
|
|
|
* @param cargo_type The cargo to get information about.
|
|
|
|
* @pre cargo_type is in ind->accepts_cargo.
|
|
|
|
* @return Whether the given industry refuses to accept this cargo type.
|
|
|
|
*/
|
|
|
|
bool IndustryTemporarilyRefusesCargo(Industry *ind, CargoID cargo_type)
|
|
|
|
{
|
2018-07-26 17:29:54 +00:00
|
|
|
assert(std::find(ind->accepts_cargo, endof(ind->accepts_cargo), cargo_type) != endof(ind->accepts_cargo));
|
2010-08-07 20:11:27 +00:00
|
|
|
|
|
|
|
const IndustrySpec *indspec = GetIndustrySpec(ind->type);
|
|
|
|
if (HasBit(indspec->callback_mask, CBM_IND_REFUSE_CARGO)) {
|
|
|
|
uint16 res = GetIndustryCallback(CBID_INDUSTRY_REFUSE_CARGO,
|
2012-05-25 17:23:19 +00:00
|
|
|
0, indspec->grf_prop.grffile->cargo_map[cargo_type],
|
2010-08-07 20:11:27 +00:00
|
|
|
ind, ind->type, ind->location.tile);
|
2011-11-08 17:26:49 +00:00
|
|
|
if (res != CALLBACK_FAILED) return !ConvertBooleanCallback(indspec->grf_prop.grffile, CBID_INDUSTRY_REFUSE_CARGO, res);
|
2010-08-07 20:11:27 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|