25 #include "table/strings.h"
43 if (grf_type == IT_INVALID)
return IT_INVALID;
44 if (!
HasBit(grf_type, 7))
return GB(grf_type, 0, 7);
46 return _industry_mngr.
GetID(
GB(grf_type, 0, 7), grf_id);
70 return 0xFF << 8 | gfx;
90 return 0xFF << 8 | indtsp->
grf_prop.subst_id;
93 static uint32 GetClosestIndustry(
TileIndex tile, IndustryType type,
const Industry *current)
95 uint32 best_dist = UINT32_MAX;
97 FOR_ALL_INDUSTRIES(i) {
98 if (i->
type != type || i == current)
continue;
119 IndustryType ind_index;
120 uint32 closest_dist = UINT32_MAX;
126 ind_index = param_setID;
142 if (layout_filter == 0 && !town_filter) {
145 closest_dist = GetClosestIndustry(current->
location.
tile, ind_index, current);
151 FOR_ALL_INDUSTRIES(i) {
152 if (i->
type == ind_index && i != current && (i->
selected_layout == layout_filter || layout_filter == 0) && (!town_filter || i->
town == current->
town)) {
159 return count << 16 |
GB(closest_dist, 0, 16);
168 case 0x80:
return this->
tile;
169 case 0x81:
return GB(this->tile, 8, 8);
175 case 0x85:
DEBUG(grf, 0,
"NewGRFs shouldn't be doing pointer magic");
break;
206 DEBUG(grf, 1,
"Unhandled variable 0x%X (no available industry) in callback 0x%x", variable, this->
ro.
callback);
244 const Livery *l = &c->livery[LS_DEFAULT];
250 return this->
industry->
founder | (is_ai ? 0x10000 : 0) | (colours << 24);
297 byte layout_filter = 0;
298 bool town_filter =
false;
299 if (variable == 0x68) {
301 layout_filter =
GB(reg, 0, 8);
302 town_filter =
HasBit(reg, 8);
317 case 0x85:
DEBUG(grf, 0,
"NewGRFs shouldn't be doing pointer magic");
break;
370 DEBUG(grf, 1,
"Unhandled industry variable 0x%X", variable);
398 if (value == 0)
return;
432 CallbackID callback, uint32 callback_param1, uint32 callback_param2)
434 industries_scope(*this, tile, indus, type, random_bits),
440 IndustriesResolverObject::~IndustriesResolverObject()
453 bool readonly =
true;
460 if (t == NULL)
return NULL;
496 return object.ResolveCallback();
515 ind.
index = INVALID_INDUSTRY;
521 ind.
random = initial_random_bits;
526 uint16 result =
object.ResolveCallback();
550 if (res != 0) default_prob = 0;
555 }
else if (res > 0x100) {
564 static int32 DerefIndProd(
int field,
bool use_register)
566 return use_register ? (int32)
GetRegister(field) : field;
581 object.callback_param2 = reason;
583 for (uint loop = 0;; loop++) {
586 if (loop >= 0x10000) {
596 SB(
object.callback_param2, 8, 16, loop);
598 if (tgroup == NULL || tgroup->type != SGT_INDUSTRY_PRODUCTION)
break;
601 bool deref = (group->version == 1);
603 for (uint i = 0; i < 3; i++) {
606 for (uint i = 0; i < 2; i++) {
610 int32 again = DerefIndProd(group->again, deref);
611 if (again == 0)
break;
613 SB(
object.callback_param2, 24, 8, again);