mirror of https://github.com/OpenTTD/OpenTTD
(svn r3179) - RandomRange() and RandomTile() instead of home brewed versions
- CHANCE*() instead of mumbling strange numbersrelease/0.4.5
parent
6124ee0974
commit
5fa6b7eb06
|
@ -977,7 +977,7 @@ static void DoDisaster(void)
|
||||||
if (j == 0)
|
if (j == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_disaster_initprocs[buf[GB(Random(), 0, 16) * j >> 16]]();
|
_disaster_initprocs[buf[RandomRange(j)]]();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -937,7 +937,7 @@ static void SetupFarmFieldFence(TileIndex tile, int size, byte type, int directi
|
||||||
if (IsTileType(tile, MP_CLEAR) || IsTileType(tile, MP_TREES)) {
|
if (IsTileType(tile, MP_CLEAR) || IsTileType(tile, MP_TREES)) {
|
||||||
|
|
||||||
or = type;
|
or = type;
|
||||||
if (or == 1 && GB(Random(), 0, 16) <= 9362) or = 2;
|
if (or == 1 && CHANCE16(1, 7)) or = 2;
|
||||||
|
|
||||||
or <<= 2;
|
or <<= 2;
|
||||||
and = (byte)~0x1C;
|
and = (byte)~0x1C;
|
||||||
|
@ -1620,7 +1620,7 @@ Industry *CreateNewIndustry(TileIndex tile, int type)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* pick a random layout */
|
/* pick a random layout */
|
||||||
it = spec->table[(spec->num_table * GB(Random(), 0, 16)) >> 16];
|
it = spec->table[RandomRange(spec->num_table)];;
|
||||||
|
|
||||||
if (!CheckIfIndustryTilesAreFree(tile, it, type, t))
|
if (!CheckIfIndustryTilesAreFree(tile, it, type, t))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -1810,7 +1810,7 @@ static void MaybeNewIndustry(uint32 r)
|
||||||
|
|
||||||
j = 2000;
|
j = 2000;
|
||||||
for(;;) {
|
for(;;) {
|
||||||
i = CreateNewIndustry(TILE_MASK(Random()), type);
|
i = CreateNewIndustry(RandomTile(), type);
|
||||||
if (i != NULL)
|
if (i != NULL)
|
||||||
break;
|
break;
|
||||||
if (--j == 0)
|
if (--j == 0)
|
||||||
|
|
|
@ -990,7 +990,7 @@ static int PickRandomBit(uint bits)
|
||||||
num++;
|
num++;
|
||||||
} while (b >>= 1);
|
} while (b >>= 1);
|
||||||
|
|
||||||
num = GB(Random(), 0, 16) * num >> 16;
|
num = RandomRange(num);
|
||||||
|
|
||||||
for(i=0; !((bits & 1) && ((int)--num) < 0); bits>>=1,i++);
|
for(i=0; !((bits & 1) && ((int)--num) < 0); bits>>=1,i++);
|
||||||
return i;
|
return i;
|
||||||
|
|
10
town_cmd.c
10
town_cmd.c
|
@ -569,7 +569,6 @@ static void LevelTownLand(TileIndex tile)
|
||||||
|
|
||||||
static void GrowTownInTile(TileIndex *tile_ptr, uint mask, int block, Town *t1)
|
static void GrowTownInTile(TileIndex *tile_ptr, uint mask, int block, Town *t1)
|
||||||
{
|
{
|
||||||
uint16 r;
|
|
||||||
int a,b,rcmd;
|
int a,b,rcmd;
|
||||||
TileIndex tmptile;
|
TileIndex tmptile;
|
||||||
TileInfo ti;
|
TileInfo ti;
|
||||||
|
@ -594,10 +593,11 @@ static void GrowTownInTile(TileIndex *tile_ptr, uint mask, int block, Town *t1)
|
||||||
// Randomize new road block numbers
|
// Randomize new road block numbers
|
||||||
a = block;
|
a = block;
|
||||||
b = block ^ 2;
|
b = block ^ 2;
|
||||||
r = GB(Random(), 0, 16);
|
if (CHANCE16(1, 4)) {
|
||||||
if (r <= 0x4000) do {
|
do {
|
||||||
a = GB(Random(), 0, 2);
|
a = GB(Random(), 0, 2);
|
||||||
} while(a == b);
|
} while(a == b);
|
||||||
|
}
|
||||||
|
|
||||||
if (!IsRoadAllowedHere(TILE_ADD(tile, ToTileIndexDiff(_roadblock_tileadd[a])), a)) {
|
if (!IsRoadAllowedHere(TILE_ADD(tile, ToTileIndexDiff(_roadblock_tileadd[a])), a)) {
|
||||||
// A road is not allowed to continue the randomized road,
|
// A road is not allowed to continue the randomized road,
|
||||||
|
|
|
@ -1907,20 +1907,19 @@ static void HandleLocomotiveSmokeCloud(const Vehicle* v)
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
// diesel smoke
|
// diesel smoke
|
||||||
if (u->cur_speed <= 40 && GB(Random(), 0, 16) <= 0x1E00) {
|
if (u->cur_speed <= 40 && CHANCE16(15, 128)) {
|
||||||
CreateEffectVehicleRel(v, 0, 0, 10, EV_DIESEL_SMOKE);
|
CreateEffectVehicleRel(v, 0, 0, 10, EV_DIESEL_SMOKE);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
// blue spark
|
// blue spark
|
||||||
if (GB(v->tick_counter, 0, 2) == 0 && GB(Random(), 0, 16) <= 0x5B0) {
|
if (GB(v->tick_counter, 0, 2) == 0 && CHANCE16(1, 45)) {
|
||||||
CreateEffectVehicleRel(v, 0, 0, 10, EV_ELECTRIC_SPARK);
|
CreateEffectVehicleRel(v, 0, 0, 10, EV_ELECTRIC_SPARK);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while ( (v = v->next) != NULL );
|
} while ((v = v->next) != NULL);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void TrainPlayLeaveStationSound(const Vehicle* v)
|
static void TrainPlayLeaveStationSound(const Vehicle* v)
|
||||||
|
@ -3193,7 +3192,7 @@ static void HandleCrashedTrain(Vehicle *v)
|
||||||
CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE);
|
CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state <= 200 && GB(r = Random(), 0, 16) <= 0x2492) {
|
if (state <= 200 && CHANCE16R(1, 7, r)) {
|
||||||
index = (r * 10 >> 16);
|
index = (r * 10 >> 16);
|
||||||
|
|
||||||
u = v;
|
u = v;
|
||||||
|
|
Loading…
Reference in New Issue