equal
deleted
inserted
replaced
23 #include "player_base.h" |
23 #include "player_base.h" |
24 #include "command_func.h" |
24 #include "command_func.h" |
25 |
25 |
26 #include "table/strings.h" |
26 #include "table/strings.h" |
27 |
27 |
28 static Randomizer _industry_creation_randomizer; |
28 static uint32 _industry_creation_random_bits; |
29 |
29 |
30 /* Since the industry IDs defined by the GRF file don't necessarily correlate |
30 /* Since the industry IDs defined by the GRF file don't necessarily correlate |
31 * to those used by the game, the IDs used for overriding old industries must be |
31 * to those used by the game, the IDs used for overriding old industries must be |
32 * translated when the idustry spec is set. */ |
32 * translated when the idustry spec is set. */ |
33 IndustryOverrideManager _industry_mngr(NEW_INDUSTRYOFFSET, NUM_INDUSTRYTYPES, INVALID_INDUSTRYTYPE); |
33 IndustryOverrideManager _industry_mngr(NEW_INDUSTRYOFFSET, NUM_INDUSTRYTYPES, INVALID_INDUSTRYTYPE); |
408 res->callback_param1 = 0; |
408 res->callback_param1 = 0; |
409 res->callback_param2 = 0; |
409 res->callback_param2 = 0; |
410 res->last_value = 0; |
410 res->last_value = 0; |
411 res->trigger = 0; |
411 res->trigger = 0; |
412 res->reseed = 0; |
412 res->reseed = 0; |
|
413 res->count = 0; |
413 } |
414 } |
414 |
415 |
415 uint16 GetIndustryCallback(CallbackID callback, uint32 param1, uint32 param2, Industry *industry, IndustryType type, TileIndex tile) |
416 uint16 GetIndustryCallback(CallbackID callback, uint32 param1, uint32 param2, Industry *industry, IndustryType type, TileIndex tile) |
416 { |
417 { |
417 ResolverObject object; |
418 ResolverObject object; |
467 |
468 |
468 /* Square of Euclidian distance from town */ |
469 /* Square of Euclidian distance from town */ |
469 case 0x8D: return min(DistanceSquare(industry->town->xy, tile), 65535); |
470 case 0x8D: return min(DistanceSquare(industry->town->xy, tile), 65535); |
470 |
471 |
471 /* 32 random bits */ |
472 /* 32 random bits */ |
472 case 0x8F: return _industry_creation_randomizer.Next(); |
473 case 0x8F: return _industry_creation_random_bits; |
473 } |
474 } |
474 |
475 |
475 /* None of the special ones, so try the general ones */ |
476 /* None of the special ones, so try the general ones */ |
476 return IndustryGetVariable(object, variable, parameter, available); |
477 return IndustryGetVariable(object, variable, parameter, available); |
477 } |
478 } |
492 ind.town = ClosestTownFromTile(tile, (uint)-1); |
493 ind.town = ClosestTownFromTile(tile, (uint)-1); |
493 |
494 |
494 NewIndustryResolver(&object, tile, &ind, type); |
495 NewIndustryResolver(&object, tile, &ind, type); |
495 object.GetVariable = IndustryLocationGetVariable; |
496 object.GetVariable = IndustryLocationGetVariable; |
496 object.callback = CBID_INDUSTRY_LOCATION; |
497 object.callback = CBID_INDUSTRY_LOCATION; |
497 _industry_creation_randomizer.SetSeed(seed); |
498 _industry_creation_random_bits = seed; |
498 |
499 |
499 group = Resolve(GetIndustrySpec(type)->grf_prop.spritegroup, &object); |
500 group = Resolve(GetIndustrySpec(type)->grf_prop.spritegroup, &object); |
500 |
501 |
501 /* Unlike the "normal" cases, not having a valid result means we allow |
502 /* Unlike the "normal" cases, not having a valid result means we allow |
502 * the building of the industry, as that's how it's done in TTDP. */ |
503 * the building of the industry, as that's how it's done in TTDP. */ |