src/newgrf_industries.cpp
changeset 8932 989fe2280933
parent 8923 7bc318982e2c
child 9130 4c439f6c8ba4
equal deleted inserted replaced
8931:d84c34673a0f 8932:989fe2280933
    22 #include "player_func.h"
    22 #include "player_func.h"
    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 
       
    28 static Randomizer _industry_creation_randomizer;
    27 
    29 
    28 /* 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
    29  * 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
    30  * translated when the idustry spec is set. */
    32  * translated when the idustry spec is set. */
    31 IndustryOverrideManager _industry_mngr(NEW_INDUSTRYOFFSET, NUM_INDUSTRYTYPES, INVALID_INDUSTRYTYPE);
    33 IndustryOverrideManager _industry_mngr(NEW_INDUSTRYOFFSET, NUM_INDUSTRYTYPES, INVALID_INDUSTRYTYPE);
   464 		case 0x8B: return GetClosestWaterDistance(tile, (GetIndustrySpec(industry->type)->behaviour & INDUSTRYBEH_BUILT_ONWATER) == 0);
   466 		case 0x8B: return GetClosestWaterDistance(tile, (GetIndustrySpec(industry->type)->behaviour & INDUSTRYBEH_BUILT_ONWATER) == 0);
   465 
   467 
   466 		/* Square of Euclidian distance from town */
   468 		/* Square of Euclidian distance from town */
   467 		case 0x8D: return min(DistanceSquare(industry->town->xy, tile), 65535);
   469 		case 0x8D: return min(DistanceSquare(industry->town->xy, tile), 65535);
   468 
   470 
   469 		/* 32 random bits TODO! Wait for a better scheme that will not cause problems, MP desyncs and asserts */
   471 		/* 32 random bits */
   470 		// case 0x8F: return Random();
   472 		case 0x8F: return _industry_creation_randomizer.Next();
   471 	}
   473 	}
   472 
   474 
   473 	/* None of the special ones, so try the general ones */
   475 	/* None of the special ones, so try the general ones */
   474 	return IndustryGetVariable(object, variable, parameter, available);
   476 	return IndustryGetVariable(object, variable, parameter, available);
   475 }
   477 }
   476 
   478 
   477 bool CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, uint itspec_index)
   479 bool CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, uint itspec_index, uint32 seed)
   478 {
   480 {
   479 	const IndustrySpec *indspec = GetIndustrySpec(type);
   481 	const IndustrySpec *indspec = GetIndustrySpec(type);
   480 
   482 
   481 	ResolverObject object;
   483 	ResolverObject object;
   482 	const SpriteGroup *group;
   484 	const SpriteGroup *group;
   490 	ind.town = ClosestTownFromTile(tile, (uint)-1);
   492 	ind.town = ClosestTownFromTile(tile, (uint)-1);
   491 
   493 
   492 	NewIndustryResolver(&object, tile, &ind, type);
   494 	NewIndustryResolver(&object, tile, &ind, type);
   493 	object.GetVariable = IndustryLocationGetVariable;
   495 	object.GetVariable = IndustryLocationGetVariable;
   494 	object.callback = CBID_INDUSTRY_LOCATION;
   496 	object.callback = CBID_INDUSTRY_LOCATION;
       
   497 	_industry_creation_randomizer.SetSeed(seed);
   495 
   498 
   496 	group = Resolve(GetIndustrySpec(type)->grf_prop.spritegroup, &object);
   499 	group = Resolve(GetIndustrySpec(type)->grf_prop.spritegroup, &object);
   497 
   500 
   498 	/* Unlike the "normal" cases, not having a valid result means we allow
   501 	/* Unlike the "normal" cases, not having a valid result means we allow
   499 	 * the building of the industry, as that's how it's done in TTDP. */
   502 	 * the building of the industry, as that's how it's done in TTDP. */