2007-06-09 02:05:51 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
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.h"
|
|
|
|
#include "newgrf_industries.h"
|
2007-07-09 13:21:49 +00:00
|
|
|
#include "newgrf_text.h"
|
|
|
|
#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"
|
2008-01-13 21:41:24 +00:00
|
|
|
#include "command_func.h"
|
2009-04-05 12:17:36 +00:00
|
|
|
#include "gui.h"
|
|
|
|
#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"
|
|
|
|
|
2008-03-12 15:56:56 +00:00
|
|
|
static uint32 _industry_creation_random_bits;
|
2008-01-29 00:36:55 +00:00
|
|
|
|
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;
|
2007-11-19 21:02:30 +00:00
|
|
|
if (!HasBit(grf_type, 7)) return GB(grf_type, 0, 6);
|
2007-07-11 22:57:47 +00:00
|
|
|
|
|
|
|
return _industry_mngr.GetID(GB(grf_type, 0, 6), grf_id);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2007-10-10 00:01:41 +00:00
|
|
|
if (!IsTileType(tile, MP_INDUSTRY) || GetIndustryIndex(tile) != i->index) {
|
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?
|
2007-09-23 19:55:42 +00:00
|
|
|
/* It is an old tile. We have to see if it's been overriden */
|
|
|
|
if (indtsp->grf_prop.override == INVALID_INDUSTRYTILE) { // has it been overridden?
|
|
|
|
return 0xFF << 8 | gfx; // no. Tag FF + the gfx id of that tile
|
|
|
|
}
|
2010-01-21 18:32:44 +00:00
|
|
|
/* Overriden */
|
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 */
|
2010-10-28 11:10:12 +00:00
|
|
|
if (indtsp->grf_prop.spritegroup[0] != NULL) { // 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;
|
2007-07-11 22:57:47 +00:00
|
|
|
const Industry *i;
|
|
|
|
FOR_ALL_INDUSTRIES(i) {
|
|
|
|
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;
|
2010-07-29 14:26:28 +00:00
|
|
|
/* FALL THROUGH */
|
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 */
|
|
|
|
const Industry *i;
|
|
|
|
FOR_ALL_INDUSTRIES(i) {
|
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);
|
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* This function implements the industries variables that newGRF defines.
|
2009-09-19 09:51:14 +00:00
|
|
|
* @param object the object that we want to query
|
2007-06-09 02:05:51 +00:00
|
|
|
* @param variable that is queried
|
|
|
|
* @param parameter unused
|
|
|
|
* @param available will return false if ever the variable asked for does not exist
|
2010-08-01 19:44:49 +00:00
|
|
|
* @return the value stored in the corresponding variable
|
|
|
|
*/
|
2011-11-08 17:23:30 +00:00
|
|
|
uint32 IndustryGetVariable(const ResolverObject *object, byte variable, uint32 parameter, bool *available)
|
2007-06-09 02:05:51 +00:00
|
|
|
{
|
|
|
|
const Industry *industry = object->u.industry.ind;
|
2007-07-09 13:21:49 +00:00
|
|
|
TileIndex tile = object->u.industry.tile;
|
2008-01-09 18:14:29 +00:00
|
|
|
IndustryType type = object->u.industry.type;
|
|
|
|
const IndustrySpec *indspec = GetIndustrySpec(type);
|
|
|
|
|
2008-07-29 19:51:30 +00:00
|
|
|
/* 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 */
|
2011-06-12 20:37:26 +00:00
|
|
|
Town *t;
|
2008-07-29 19:51:30 +00:00
|
|
|
|
|
|
|
if (industry != NULL) {
|
|
|
|
t = industry->town;
|
|
|
|
} else if (tile != INVALID_TILE) {
|
|
|
|
t = ClosestTownFromTile(tile, UINT_MAX);
|
|
|
|
} else {
|
|
|
|
*available = false;
|
|
|
|
return UINT_MAX;
|
|
|
|
}
|
|
|
|
|
2011-06-12 20:50:03 +00:00
|
|
|
return TownGetVariable(variable, parameter, available, t, object->grffile);
|
2008-07-29 19:51:30 +00:00
|
|
|
}
|
|
|
|
|
2008-01-09 18:14:29 +00:00
|
|
|
if (industry == NULL) {
|
2010-11-15 16:43:46 +00:00
|
|
|
DEBUG(grf, 1, "Unhandled variable 0x%X (no available industry) in callback 0x%x", variable, object->callback);
|
2008-01-09 18:14:29 +00:00
|
|
|
|
|
|
|
*available = false;
|
|
|
|
return UINT_MAX;
|
|
|
|
}
|
2007-06-09 02:05:51 +00:00
|
|
|
|
|
|
|
switch (variable) {
|
|
|
|
case 0x40:
|
|
|
|
case 0x41:
|
|
|
|
case 0x42: { // waiting cargo, but only if those two callback flags are set
|
2009-09-14 12:22:57 +00:00
|
|
|
uint16 callback = indspec->callback_mask;
|
2007-11-19 21:02:30 +00:00
|
|
|
if (HasBit(callback, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HasBit(callback, CBM_IND_PRODUCTION_256_TICKS)) {
|
2007-11-24 14:03:47 +00:00
|
|
|
if ((indspec->behaviour & INDUSTRYBEH_PROD_MULTI_HNDLING) != 0) {
|
2010-05-01 18:58:50 +00:00
|
|
|
if (industry->prod_level == 0) return 0;
|
2007-11-24 14:03:47 +00:00
|
|
|
return min(industry->incoming_cargo_waiting[variable - 0x40] / industry->prod_level, (uint16)0xFFFF);
|
|
|
|
} else {
|
|
|
|
return min(industry->incoming_cargo_waiting[variable - 0x40], (uint16)0xFFFF);
|
|
|
|
}
|
2007-06-09 02:05:51 +00:00
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2007-07-09 13:21:49 +00:00
|
|
|
|
|
|
|
/* Manhattan distance of closes dry/water tile */
|
2007-10-04 07:09:05 +00:00
|
|
|
case 0x43: return GetClosestWaterDistance(tile, (indspec->behaviour & INDUSTRYBEH_BUILT_ONWATER) == 0);
|
2007-06-09 02:05:51 +00:00
|
|
|
|
2007-08-15 00:49:34 +00:00
|
|
|
/* Layout number */
|
|
|
|
case 0x44: return industry->selected_layout;
|
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
/* Company info */
|
2007-10-05 01:46:49 +00:00
|
|
|
case 0x45: {
|
2010-04-05 21:18:32 +00:00
|
|
|
byte colours = 0;
|
2007-10-05 01:46:49 +00:00
|
|
|
bool is_ai = false;
|
2007-10-06 00:23:30 +00:00
|
|
|
|
2009-05-18 16:21:28 +00:00
|
|
|
const Company *c = Company::GetIfValid(industry->founder);
|
|
|
|
if (c != NULL) {
|
2008-09-30 20:39:50 +00:00
|
|
|
const Livery *l = &c->livery[LS_DEFAULT];
|
2007-10-06 00:23:30 +00:00
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
is_ai = c->is_ai;
|
2007-10-06 00:23:30 +00:00
|
|
|
colours = l->colour1 + l->colour2 * 16;
|
2007-10-05 01:46:49 +00:00
|
|
|
}
|
2007-10-06 00:23:30 +00:00
|
|
|
|
|
|
|
return industry->founder | (is_ai ? 0x10000 : 0) | (colours << 24);
|
2007-10-05 01:46:49 +00:00
|
|
|
}
|
|
|
|
|
2008-06-10 17:47:55 +00:00
|
|
|
case 0x46: return industry->construction_date; // Date when built - long format - (in days)
|
|
|
|
|
2007-06-12 00:49:50 +00:00
|
|
|
/* Get industry ID at offset param */
|
2010-10-19 21:00:45 +00:00
|
|
|
case 0x60: return GetIndustryIDAtOffset(GetNearbyTile(parameter, industry->location.tile, false), industry, object->grffile->grfid);
|
2007-06-09 02:05:51 +00:00
|
|
|
|
2007-09-23 19:27:35 +00:00
|
|
|
/* Get random tile bits at offset param */
|
|
|
|
case 0x61:
|
2010-10-19 21:00:45 +00:00
|
|
|
tile = GetNearbyTile(parameter, tile, false);
|
2009-08-30 11:47:41 +00:00
|
|
|
return (IsTileType(tile, MP_INDUSTRY) && Industry::GetByTile(tile) == industry) ? GetIndustryRandomBits(tile) : 0;
|
2007-06-09 02:05:51 +00:00
|
|
|
|
2007-07-11 23:10:22 +00:00
|
|
|
/* Land info of nearby tiles */
|
2010-10-19 21:00:45 +00:00
|
|
|
case 0x62: return GetNearbyIndustryTileInformation(parameter, tile, INVALID_INDUSTRY, false);
|
2007-07-11 23:10:22 +00:00
|
|
|
|
|
|
|
/* Animation stage of nearby tiles */
|
2007-09-23 19:27:35 +00:00
|
|
|
case 0x63:
|
2010-10-19 21:00:45 +00:00
|
|
|
tile = GetNearbyTile(parameter, tile, false);
|
2009-08-30 11:47:41 +00:00
|
|
|
if (IsTileType(tile, MP_INDUSTRY) && Industry::GetByTile(tile) == industry) {
|
2010-08-26 14:45:45 +00:00
|
|
|
return GetAnimationFrame(tile);
|
2007-07-11 23:10:22 +00:00
|
|
|
}
|
|
|
|
return 0xFFFFFFFF;
|
|
|
|
|
|
|
|
/* Distance of nearest industry of given type */
|
2007-07-24 01:26:57 +00:00
|
|
|
case 0x64: return GetClosestIndustry(tile, MapNewGRFIndustryType(parameter, indspec->grf_prop.grffile->grfid), industry);
|
2007-06-09 02:05:51 +00:00
|
|
|
/* Get town zone and Manhattan distance of closest town */
|
2008-04-18 04:54:09 +00:00
|
|
|
case 0x65: return GetTownRadiusGroup(industry->town, tile) << 16 | min(DistanceManhattan(tile, industry->town->xy), 0xFFFF);
|
2007-06-09 02:05:51 +00:00
|
|
|
/* 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
|
2007-08-17 00:23:33 +00:00
|
|
|
* 68 is the same as 67, but with a filtering on selected layout */
|
|
|
|
case 0x67:
|
2011-05-07 10:20:29 +00:00
|
|
|
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);
|
|
|
|
}
|
2007-06-09 02:05:51 +00:00
|
|
|
|
2007-09-22 13:56:38 +00:00
|
|
|
/* Get a variable from the persistent storage */
|
2011-06-12 20:47:45 +00:00
|
|
|
case 0x7C: return (industry->psa != NULL) ? industry->psa->GetValue(parameter) : 0;
|
2007-09-22 13:56:38 +00:00
|
|
|
|
2007-06-09 02:05:51 +00:00
|
|
|
/* Industry structure access*/
|
2010-01-04 18:21:07 +00:00
|
|
|
case 0x80: return industry->location.tile;
|
|
|
|
case 0x81: return GB(industry->location.tile, 8, 8);
|
2007-06-09 02:05:51 +00:00
|
|
|
/* Pointer to the town the industry is associated with */
|
2007-07-07 17:36:01 +00:00
|
|
|
case 0x82: return industry->town->index;
|
2007-06-09 02:05:51 +00:00
|
|
|
case 0x83:
|
|
|
|
case 0x84:
|
2007-07-07 08:53:19 +00:00
|
|
|
case 0x85: DEBUG(grf, 0, "NewGRFs shouldn't be doing pointer magic"); break; // not supported
|
2010-01-04 18:21:07 +00:00
|
|
|
case 0x86: return industry->location.w;
|
|
|
|
case 0x87: return industry->location.h;// xy dimensions
|
2009-03-15 00:32:18 +00:00
|
|
|
|
2007-06-09 02:05:51 +00:00
|
|
|
case 0x88:
|
2007-09-27 21:39:13 +00:00
|
|
|
case 0x89: return industry->produced_cargo[variable - 0x88];
|
2007-07-04 18:27:21 +00:00
|
|
|
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);
|
2007-06-09 02:05:51 +00:00
|
|
|
case 0x8E:
|
|
|
|
case 0x8F: return industry->production_rate[variable - 0x8E];
|
|
|
|
case 0x90:
|
|
|
|
case 0x91:
|
2007-09-27 21:39:13 +00:00
|
|
|
case 0x92: return industry->accepts_cargo[variable - 0x90];
|
2007-06-09 02:05:51 +00:00
|
|
|
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];
|
2010-02-02 23:11:10 +00:00
|
|
|
case 0x9B: return GB(industry->this_month_transported[1], 8, 8);
|
2007-06-09 02:05:51 +00:00
|
|
|
/* 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];
|
2010-02-02 23:11:10 +00:00
|
|
|
case 0xA5: return GB(industry->last_month_transported[1], 8, 8);
|
2007-06-09 02:05:51 +00:00
|
|
|
|
|
|
|
case 0xA6: return industry->type;
|
2007-07-07 08:53:19 +00:00
|
|
|
case 0xA7: return industry->founder;
|
2009-02-09 02:57:15 +00:00
|
|
|
case 0xA8: return industry->random_colour;
|
2008-02-25 13:38:11 +00:00
|
|
|
case 0xA9: return Clamp(industry->last_prod_year - ORIGINAL_BASE_YEAR, 0, 255);
|
2007-06-09 02:05:51 +00:00
|
|
|
case 0xAA: return industry->counter;
|
|
|
|
case 0xAB: return GB(industry->counter, 8, 8);
|
|
|
|
case 0xAC: return industry->was_cargo_delivered;
|
2007-07-07 08:53:19 +00:00
|
|
|
|
2008-02-25 13:38:11 +00:00
|
|
|
case 0xB0: return Clamp(industry->construction_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535); // Date when built since 1920 (in days)
|
2007-07-07 08:53:19 +00:00
|
|
|
case 0xB3: return industry->construction_type; // Construction type
|
2008-02-25 13:38:11 +00:00
|
|
|
case 0xB4: return Clamp(industry->last_cargo_accepted_at - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535); // Date last cargo accepted since 1920 (in days)
|
2007-06-09 02:05:51 +00:00
|
|
|
}
|
|
|
|
|
2010-11-15 16:43:46 +00:00
|
|
|
DEBUG(grf, 1, "Unhandled industry variable 0x%X", variable);
|
2007-06-09 02:05:51 +00:00
|
|
|
|
|
|
|
*available = false;
|
2009-02-18 09:14:41 +00:00
|
|
|
return UINT_MAX;
|
2007-06-09 02:05:51 +00:00
|
|
|
}
|
|
|
|
|
2009-05-23 12:13:42 +00:00
|
|
|
static const SpriteGroup *IndustryResolveReal(const ResolverObject *object, const RealSpriteGroup *group)
|
2007-06-09 02:05:51 +00:00
|
|
|
{
|
|
|
|
/* IndustryTile do not have 'real' groups */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-09-23 19:27:35 +00:00
|
|
|
static uint32 IndustryGetRandomBits(const ResolverObject *object)
|
|
|
|
{
|
2010-05-01 13:01:21 +00:00
|
|
|
const Industry *ind = object->u.industry.ind;
|
2010-05-01 17:53:25 +00:00
|
|
|
return ind != NULL ? ind->random: 0;
|
2007-09-23 19:27:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static uint32 IndustryGetTriggers(const ResolverObject *object)
|
|
|
|
{
|
2010-05-01 13:01:21 +00:00
|
|
|
const Industry *ind = object->u.industry.ind;
|
2010-05-01 17:53:25 +00:00
|
|
|
return ind != NULL ? ind->random_triggers : 0;
|
2007-09-23 19:27:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void IndustrySetTriggers(const ResolverObject *object, int triggers)
|
|
|
|
{
|
2010-05-01 13:01:21 +00:00
|
|
|
Industry *ind = object->u.industry.ind;
|
|
|
|
assert(ind != NULL && ind->index != INVALID_INDUSTRY);
|
|
|
|
ind->random_triggers = triggers;
|
2007-09-23 19:27:35 +00:00
|
|
|
}
|
|
|
|
|
2011-06-12 20:38:46 +00:00
|
|
|
/**
|
|
|
|
* Store a value into the object's persistent storage.
|
|
|
|
* @param object Object that we want to query.
|
|
|
|
* @param pos Position in the persistent storage to use.
|
|
|
|
* @param value Value to store.
|
|
|
|
*/
|
|
|
|
void IndustryStorePSA(ResolverObject *object, uint pos, int32 value)
|
|
|
|
{
|
|
|
|
Industry *ind = object->u.industry.ind;
|
2011-06-12 20:50:03 +00:00
|
|
|
if (ind->index == INVALID_INDUSTRY) return;
|
|
|
|
|
|
|
|
if (object->scope != VSG_SCOPE_SELF) {
|
|
|
|
/* Pass the request on to the town of the industry. */
|
|
|
|
TownStorePSA(ind->town, object->grffile, pos, value);
|
|
|
|
return;
|
|
|
|
}
|
2011-06-12 20:47:45 +00:00
|
|
|
|
|
|
|
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);
|
2011-06-12 20:38:46 +00:00
|
|
|
}
|
|
|
|
|
2008-01-09 18:14:29 +00:00
|
|
|
static void NewIndustryResolver(ResolverObject *res, TileIndex tile, Industry *indus, IndustryType type)
|
2007-06-09 02:05:51 +00:00
|
|
|
{
|
2007-09-23 19:27:35 +00:00
|
|
|
res->GetRandomBits = IndustryGetRandomBits;
|
|
|
|
res->GetTriggers = IndustryGetTriggers;
|
|
|
|
res->SetTriggers = IndustrySetTriggers;
|
2007-06-09 02:05:51 +00:00
|
|
|
res->GetVariable = IndustryGetVariable;
|
|
|
|
res->ResolveReal = IndustryResolveReal;
|
2011-06-12 20:38:46 +00:00
|
|
|
res->StorePSA = IndustryStorePSA;
|
2007-06-09 02:05:51 +00:00
|
|
|
|
|
|
|
res->u.industry.tile = tile;
|
|
|
|
res->u.industry.ind = indus;
|
2007-06-13 02:29:08 +00:00
|
|
|
res->u.industry.gfx = INVALID_INDUSTRYTILE;
|
2008-01-09 18:14:29 +00:00
|
|
|
res->u.industry.type = type;
|
2007-06-09 02:05:51 +00:00
|
|
|
|
2007-07-25 19:06:29 +00:00
|
|
|
res->callback = CBID_NO_CALLBACK;
|
2007-06-09 02:05:51 +00:00
|
|
|
res->callback_param1 = 0;
|
|
|
|
res->callback_param2 = 0;
|
2011-07-04 20:31:57 +00:00
|
|
|
res->ResetState();
|
2008-07-30 18:23:12 +00:00
|
|
|
|
|
|
|
const IndustrySpec *indspec = GetIndustrySpec(type);
|
|
|
|
res->grffile = (indspec != NULL ? indspec->grf_prop.grffile : NULL);
|
2007-06-09 02:05:51 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
ResolverObject object;
|
|
|
|
const SpriteGroup *group;
|
|
|
|
|
2008-01-09 18:14:29 +00:00
|
|
|
NewIndustryResolver(&object, tile, industry, type);
|
2007-06-09 02:05:51 +00:00
|
|
|
object.callback = callback;
|
|
|
|
object.callback_param1 = param1;
|
|
|
|
object.callback_param2 = param2;
|
|
|
|
|
2010-08-10 15:49:35 +00:00
|
|
|
group = SpriteGroup::Resolve(GetIndustrySpec(type)->grf_prop.spritegroup[0], &object);
|
2009-05-23 12:13:42 +00:00
|
|
|
if (group == NULL) return CALLBACK_FAILED;
|
2007-06-09 02:05:51 +00:00
|
|
|
|
2009-05-23 12:13:42 +00:00
|
|
|
return group->GetCallbackResult();
|
2007-06-09 02:05:51 +00:00
|
|
|
}
|
2007-07-05 05:41:56 +00:00
|
|
|
|
2011-11-08 17:23:30 +00:00
|
|
|
uint32 IndustryLocationGetVariable(const ResolverObject *object, byte variable, uint32 parameter, bool *available)
|
2007-07-09 13:21:49 +00:00
|
|
|
{
|
2007-10-04 07:09:05 +00:00
|
|
|
const Industry *industry = object->u.industry.ind;
|
|
|
|
TileIndex tile = object->u.industry.tile;
|
2007-07-09 13:21:49 +00:00
|
|
|
|
|
|
|
if (object->scope == VSG_SCOPE_PARENT) {
|
2011-06-12 20:50:03 +00:00
|
|
|
return TownGetVariable(variable, parameter, available, industry->town, object->grffile);
|
2007-07-09 13:21:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (variable) {
|
|
|
|
case 0x80: return tile;
|
|
|
|
case 0x81: return GB(tile, 8, 8);
|
2007-07-11 23:10:22 +00:00
|
|
|
|
2007-07-09 13:21:49 +00:00
|
|
|
/* Pointer to the town the industry is associated with */
|
2007-10-04 07:09:05 +00:00
|
|
|
case 0x82: return industry->town->index;
|
2007-07-09 13:21:49 +00:00
|
|
|
case 0x83:
|
|
|
|
case 0x84:
|
|
|
|
case 0x85: DEBUG(grf, 0, "NewGRFs shouldn't be doing pointer magic"); break; // not supported
|
|
|
|
|
|
|
|
/* Number of the layout */
|
2007-10-04 07:09:05 +00:00
|
|
|
case 0x86: return industry->selected_layout;
|
2007-07-09 13:21:49 +00:00
|
|
|
|
|
|
|
/* Ground type */
|
|
|
|
case 0x87: return GetTerrainType(tile);
|
|
|
|
|
|
|
|
/* Town zone */
|
2007-10-04 07:09:05 +00:00
|
|
|
case 0x88: return GetTownRadiusGroup(industry->town, tile);
|
2007-07-09 13:21:49 +00:00
|
|
|
|
|
|
|
/* Manhattan distance of the closest town */
|
2007-10-04 07:09:05 +00:00
|
|
|
case 0x89: return min(DistanceManhattan(industry->town->xy, tile), 255);
|
2007-07-09 13:21:49 +00:00
|
|
|
|
|
|
|
/* Lowest height of the tile */
|
2011-11-04 10:18:13 +00:00
|
|
|
case 0x8A: return GetTilePixelZ(tile);
|
2007-07-09 13:21:49 +00:00
|
|
|
|
|
|
|
/* Distance to the nearest water/land tile */
|
2007-10-04 07:09:05 +00:00
|
|
|
case 0x8B: return GetClosestWaterDistance(tile, (GetIndustrySpec(industry->type)->behaviour & INDUSTRYBEH_BUILT_ONWATER) == 0);
|
2007-07-09 13:21:49 +00:00
|
|
|
|
|
|
|
/* Square of Euclidian distance from town */
|
2007-10-04 07:09:05 +00:00
|
|
|
case 0x8D: return min(DistanceSquare(industry->town->xy, tile), 65535);
|
2008-01-25 18:13:04 +00:00
|
|
|
|
2008-01-29 00:36:55 +00:00
|
|
|
/* 32 random bits */
|
2008-03-12 15:56:56 +00:00
|
|
|
case 0x8F: return _industry_creation_random_bits;
|
2007-07-09 13:21:49 +00:00
|
|
|
}
|
|
|
|
|
2007-10-04 07:09:05 +00:00
|
|
|
/* None of the special ones, so try the general ones */
|
|
|
|
return IndustryGetVariable(object, variable, parameter, available);
|
2007-07-09 13:21:49 +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.
|
|
|
|
*/
|
2010-10-16 13:15:54 +00:00
|
|
|
CommandCost CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, uint 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);
|
|
|
|
|
|
|
|
ResolverObject object;
|
|
|
|
const SpriteGroup *group;
|
|
|
|
|
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;
|
2010-02-21 17:01:23 +00:00
|
|
|
ind.selected_layout = 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;
|
2007-10-04 07:09:05 +00:00
|
|
|
|
2008-01-09 18:14:29 +00:00
|
|
|
NewIndustryResolver(&object, tile, &ind, type);
|
2007-07-09 13:21:49 +00:00
|
|
|
object.GetVariable = IndustryLocationGetVariable;
|
|
|
|
object.callback = CBID_INDUSTRY_LOCATION;
|
2010-10-16 13:15:54 +00:00
|
|
|
object.callback_param2 = creation_type;
|
2008-03-12 15:56:56 +00:00
|
|
|
_industry_creation_random_bits = seed;
|
2007-07-09 13:21:49 +00:00
|
|
|
|
2010-08-10 15:49:35 +00:00
|
|
|
group = SpriteGroup::Resolve(GetIndustrySpec(type)->grf_prop.spritegroup[0], &object);
|
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. */
|
2010-02-21 17:01:23 +00:00
|
|
|
if (group == NULL) return CommandCost();
|
2009-05-23 12:13:42 +00:00
|
|
|
uint16 result = group->GetCallbackResult();
|
2011-07-11 16:32:19 +00:00
|
|
|
if (result == CALLBACK_FAILED) return CommandCost();
|
2011-07-03 14:32:15 +00:00
|
|
|
|
2011-07-11 16:32:19 +00:00
|
|
|
return GetErrorMessageFromLocationCallbackResult(result, indspec->grf_prop.grffile->grfid, 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)) {
|
|
|
|
uint16 res = GetIndustryCallback(CBID_INDUSTRY_PROBABILITY, 0, creation_type, NULL, 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);
|
2007-07-05 05:41:56 +00:00
|
|
|
ResolverObject object;
|
2010-01-04 18:21:07 +00:00
|
|
|
NewIndustryResolver(&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);
|
2010-08-10 15:49:35 +00:00
|
|
|
const SpriteGroup *tgroup = SpriteGroup::Resolve(spec->grf_prop.spritegroup[0], &object);
|
2009-05-23 12:13:42 +00:00
|
|
|
if (tgroup == NULL || tgroup->type != SGT_INDUSTRY_PRODUCTION) break;
|
|
|
|
const IndustryProductionSpriteGroup *group = (const IndustryProductionSpriteGroup *)tgroup;
|
2007-07-05 05:41:56 +00:00
|
|
|
|
2009-05-23 12:13:42 +00:00
|
|
|
bool deref = (group->version == 1);
|
2007-07-05 05:41:56 +00:00
|
|
|
|
|
|
|
for (uint i = 0; i < 3; i++) {
|
2009-10-24 18:51:21 +00:00
|
|
|
ind->incoming_cargo_waiting[i] = Clamp(ind->incoming_cargo_waiting[i] - DerefIndProd(group->subtract_input[i], deref) * multiplier, 0, 0xFFFF);
|
2007-07-05 05:41:56 +00:00
|
|
|
}
|
|
|
|
for (uint i = 0; i < 2; i++) {
|
2009-05-23 12:13:42 +00:00
|
|
|
ind->produced_cargo_waiting[i] = Clamp(ind->produced_cargo_waiting[i] + 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
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolve a industry's spec and such so we can get a variable.
|
|
|
|
* @param ro The resolver object to fill.
|
|
|
|
* @param index The industry ID to get the data from.
|
|
|
|
*/
|
|
|
|
void GetIndustryResolver(ResolverObject *ro, uint index)
|
|
|
|
{
|
|
|
|
Industry *i = Industry::Get(index);
|
|
|
|
NewIndustryResolver(ro, i->location.tile, i, i->type);
|
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
assert(cargo_type == ind->accepts_cargo[0] || cargo_type == ind->accepts_cargo[1] || cargo_type == ind->accepts_cargo[2]);
|
|
|
|
|
|
|
|
const IndustrySpec *indspec = GetIndustrySpec(ind->type);
|
|
|
|
if (HasBit(indspec->callback_mask, CBM_IND_REFUSE_CARGO)) {
|
|
|
|
uint16 res = GetIndustryCallback(CBID_INDUSTRY_REFUSE_CARGO,
|
|
|
|
0, GetReverseCargoTranslation(cargo_type, indspec->grf_prop.grffile),
|
|
|
|
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;
|
|
|
|
}
|