Changeset - r7967:9fd776876428
[Not reviewed]
master
0 13 0
skidd13 - 17 years ago 2007-11-25 15:35:25
skidd13@openttd.org
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
-Codechange: Convert the CHANCE macros to functions and rename them fitting to the naming style
13 files changed with 100 insertions and 90 deletions:
0 comments (0 inline, 0 general)
src/ai/default/default.cpp
Show inline comments
 
@@ -640,13 +640,13 @@ static bool AiCheckIfRouteIsGood(Player 
 

	
 
	/* Make sure distance to closest station is < min_distance tiles. */
 
	if (dist != 0xFFFF && dist > min_distance) return false;
 

	
 
	if (p->ai.route_type_mask != 0 &&
 
			!(p->ai.route_type_mask & bitmask) &&
 
			!CHANCE16(1, 5)) {
 
			!Chance16(1, 5)) {
 
		return false;
 
	}
 

	
 
	if (fr->cargo == CT_PASSENGERS || fr->cargo == CT_MAIL) {
 
		const Town* from = (const Town*)fr->from;
 
		const Town* to   = (const Town*)fr->to;
 
@@ -1449,13 +1449,13 @@ static void AiWantPassengerAircraftRoute
 
	 * rather than two way full 1 times.
 
	 * Practical experiments with AI show that the non-full-load aircrafts are usually
 
	 * those that survive
 
	 * Also, non-full load is more resistant against starving (by building better stations
 
	 * or using exclusive rights)
 
	 */
 
	p->ai.num_want_fullload = CHANCE16(1, 5); // 20% chance
 
	p->ai.num_want_fullload = Chance16(1, 5); // 20% chance
 
//	p->ai.loco_id = INVALID_VEHICLE;
 
	p->ai.order_list_blocks[0] = 0;
 
	p->ai.order_list_blocks[1] = 1;
 
	p->ai.order_list_blocks[2] = 255;
 

	
 
	p->ai.state = AIS_AIRPORT_STUFF;
src/aircraft_cmd.cpp
Show inline comments
 
@@ -1252,13 +1252,13 @@ static void HandleCrashedAircraft(Vehicl
 
			v->z_pos++;
 
		}
 
	}
 

	
 
	if (v->u.air.crashed_counter < 650) {
 
		uint32 r;
 
		if (CHANCE16R(1,32,r)) {
 
		if (Chance16R(1,32,r)) {
 
			static const DirDiff delta[] = {
 
				DIRDIFF_45LEFT, DIRDIFF_SAME, DIRDIFF_SAME, DIRDIFF_45RIGHT
 
			};
 

	
 
			v->direction = ChangeDir(v->direction, delta[GB(r, 16, 2)]);
 
			SetAircraftPosition(v, v->x_pos, v->y_pos, v->z_pos);
src/core/random_func.hpp
Show inline comments
 
@@ -33,7 +33,66 @@ void SetRandomSeed(uint32 seed);
 
	uint RandomRange(uint max);
 
#endif
 

	
 
uint32 InteractiveRandom(); // Used for random sequences that are not the same on the other end of the multiplayer link
 
uint InteractiveRandomRange(uint max);
 

	
 
/**
 
 * Checks if a given randomize-number is below a given probability.
 
 *
 
 * This function is used to check if the given probability by the fraction of (a/b)
 
 * is greater than low 16 bits of the given randomize-number v.
 
 *
 
 * Do not use this function twice on the same random 16 bits as it will yield
 
 * the same result. One can use a random number for two calls to Chance16I,
 
 * where one call sends the low 16 bits and the other the high 16 bits.
 
 *
 
 * @param a The numerator of the fraction
 
 * @param b The denominator of the fraction, must of course not be null
 
 * @param r The given randomize-number
 
 * @return True if v is less or equals (a/b)
 
 */
 
static inline bool Chance16I(const uint a, const uint b, const uint32 r)
 
{
 
	assert(b != 0);
 
	return (uint16)r < (uint16)((a << 16) / b);
 
}
 

	
 
/**
 
 * Flips a coin with a given probability.
 
 *
 
 * This macro can be used to get true or false randomized according to a
 
 * given probability. The parameter a and b create a percent value with
 
 * (a/b). The macro returns true in (a/b) percent.
 
 *
 
 * @see Chance16I()
 
 * @param a The numerator of the fraction
 
 * @param b The denominator of the fraction
 
 * @return True in (a/b) percent
 
 */
 
static inline bool Chance16(const uint a, const uint b)
 
{
 
	return Chance16I(a, b, Random());
 
}
 

	
 
/**
 
 * Flips a coin with a given probability and saves the randomize-number in a variable.
 
 *
 
 * This function uses the same parameters as Chance16. The third parameter
 
 * must be a variable the randomize-number from Random() is saved in.
 
 *
 
 * The low 16 bits of r will already be used and can therefor not be passed to
 
 * Chance16I. One can only send the high 16 bits to Chance16I.
 
 *
 
 * @see Chance16I()
 
 * @param a The numerator of the fraction
 
 * @param b The denominator of the fraction
 
 * @param r The variable to save the randomize-number from Random()
 
 * @return True in (a/b) percent
 
 */
 
static inline bool Chance16R(const uint a, const uint b, uint32 &r)
 
{
 
	r = Random();
 
	return Chance16I(a, b, r);
 
}
 

	
 
#endif /* RANDOM_FUNC_HPP */
src/disaster_cmd.cpp
Show inline comments
 
@@ -712,13 +712,13 @@ static void DisasterTick_Submarine(Vehic
 
	if (!HasBit(v->tick_counter, 0)) return;
 

	
 
	tile = v->tile + TileOffsByDiagDir(DirToDiagDir(v->direction));
 
	if (IsValidTile(tile)) {
 
		TrackdirBits r = (TrackdirBits)GetTileTrackStatus(tile, TRANSPORT_WATER, 0);
 

	
 
		if (TrackdirBitsToTrackBits(r) == TRACK_BIT_ALL && !CHANCE16(1, 90)) {
 
		if (TrackdirBitsToTrackBits(r) == TRACK_BIT_ALL && !Chance16(1, 90)) {
 
			GetNewVehiclePosResult gp = GetNewVehiclePos(v);
 
			SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
 
			return;
 
		}
 
	}
 

	
 
@@ -822,13 +822,13 @@ static void Disaster_Airplane_Init()
 
	int x, y;
 

	
 
	found = NULL;
 

	
 
	FOR_ALL_INDUSTRIES(i) {
 
		if ((GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_AIRPLANE_ATTACKS) &&
 
				(found == NULL || CHANCE16(1, 2))) {
 
				(found == NULL || Chance16(1, 2))) {
 
			found = i;
 
		}
 
	}
 

	
 
	if (found == NULL) return;
 

	
 
@@ -858,13 +858,13 @@ static void Disaster_Helicopter_Init()
 
	int x, y;
 

	
 
	found = NULL;
 

	
 
	FOR_ALL_INDUSTRIES(i) {
 
		if ((GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_CHOPPER_ATTACKS) &&
 
				(found == NULL || CHANCE16(1, 2))) {
 
				(found == NULL || Chance16(1, 2))) {
 
			found = i;
 
		}
 
	}
 

	
 
	if (found == NULL) return;
 

	
src/economy.cpp
Show inline comments
 
@@ -1099,13 +1099,13 @@ static void SubsidyMonthlyHandler()
 
		} else {
 
			s->age++;
 
		}
 
	}
 

	
 
	/* 25% chance to go on */
 
	if (CHANCE16(1,4)) {
 
	if (Chance16(1,4)) {
 
		/*  Find a free slot*/
 
		s = _subsidies;
 
		while (s->cargo_type != CT_INVALID) {
 
			if (++s == endof(_subsidies))
 
				goto no_add;
 
		}
src/industry_cmd.cpp
Show inline comments
 
@@ -555,13 +555,13 @@ static void AnimateTile_Industry(TileInd
 
		break;
 

	
 
	case GFX_OILWELL_ANIMATED_1:
 
	case GFX_OILWELL_ANIMATED_2:
 
	case GFX_OILWELL_ANIMATED_3:
 
		if ((_tick_counter & 7) == 0) {
 
			bool b = CHANCE16(1, 7);
 
			bool b = Chance16(1, 7);
 
			IndustryGfx gfx = GetIndustryGfx(tile);
 

	
 
			m = GetIndustryAnimationState(tile) + 1;
 
			if (m == 4 && (m = 0, ++gfx) == GFX_OILWELL_ANIMATED_3 + 1 && (gfx = GFX_OILWELL_ANIMATED_1, b)) {
 
				SetIndustryGfx(tile, GFX_OILWELL_NOT_ANIMATED);
 
				SetIndustryConstructionStage(tile, 3);
 
@@ -735,26 +735,26 @@ static void TileLoop_Industry(TileIndex 
 
		TileLoop_Water(tile);
 
		break;
 

	
 
	case GFX_COAL_MINE_TOWER_NOT_ANIMATED:
 
	case GFX_COPPER_MINE_TOWER_NOT_ANIMATED:
 
	case GFX_GOLD_MINE_TOWER_NOT_ANIMATED:
 
		if (!(_tick_counter & 0x400) && CHANCE16(1, 2)) {
 
		if (!(_tick_counter & 0x400) && Chance16(1, 2)) {
 
			switch (gfx) {
 
				case GFX_COAL_MINE_TOWER_NOT_ANIMATED:   gfx = GFX_COAL_MINE_TOWER_ANIMATED;   break;
 
				case GFX_COPPER_MINE_TOWER_NOT_ANIMATED: gfx = GFX_COPPER_MINE_TOWER_ANIMATED; break;
 
				case GFX_GOLD_MINE_TOWER_NOT_ANIMATED:   gfx = GFX_GOLD_MINE_TOWER_ANIMATED;   break;
 
			}
 
			SetIndustryGfx(tile, gfx);
 
			SetIndustryAnimationState(tile, 0x80);
 
			AddAnimatedTile(tile);
 
		}
 
		break;
 

	
 
	case GFX_OILWELL_NOT_ANIMATED:
 
		if (CHANCE16(1, 6)) {
 
		if (Chance16(1, 6)) {
 
			SetIndustryGfx(tile, GFX_OILWELL_ANIMATED_1);
 
			SetIndustryAnimationState(tile, 0);
 
			AddAnimatedTile(tile);
 
		}
 
		break;
 

	
 
@@ -772,13 +772,13 @@ static void TileLoop_Industry(TileIndex 
 
			SetIndustryConstructionStage(tile, 3);
 
			DeleteAnimatedTile(tile);
 
		}
 
		break;
 

	
 
	case GFX_POWERPLANT_SPARKS:
 
		if (CHANCE16(1, 3)) {
 
		if (Chance16(1, 3)) {
 
			SndPlayTileFx(SND_0C_ELECTRIC_SPARK, tile);
 
			AddAnimatedTile(tile);
 
		}
 
		break;
 

	
 
	case GFX_COPPER_MINE_CHIMNEY:
 
@@ -802,13 +802,13 @@ static void TileLoop_Industry(TileIndex 
 

	
 
	case GFX_TOFFEE_QUARY:
 
		AddAnimatedTile(tile);
 
		break;
 

	
 
	case GFX_SUGAR_MINE_SIEVE:
 
		if (CHANCE16(1, 3)) AddAnimatedTile(tile);
 
		if (Chance16(1, 3)) AddAnimatedTile(tile);
 
		break;
 
	}
 
}
 

	
 
static void ClickTile_Industry(TileIndex tile)
 
{
 
@@ -860,13 +860,13 @@ static void SetupFarmFieldFence(TileInde
 
	do {
 
		tile = TILE_MASK(tile);
 

	
 
		if (IsTileType(tile, MP_CLEAR) || IsTileType(tile, MP_TREES)) {
 
			byte or_ = type;
 

	
 
			if (or_ == 1 && CHANCE16(1, 7)) or_ = 2;
 
			if (or_ == 1 && Chance16(1, 7)) or_ = 2;
 

	
 
			if (direction == AXIS_X) {
 
				SetFenceSE(tile, or_);
 
			} else {
 
				SetFenceSW(tile, or_);
 
			}
 
@@ -987,13 +987,13 @@ static void ProduceIndustryGoods(Industr
 
	uint32 r;
 
	uint num;
 
	const IndustrySpec *indsp = GetIndustrySpec(i->type);
 

	
 
	/* play a sound? */
 
	if ((i->counter & 0x3F) == 0) {
 
		if (CHANCE16R(1, 14, r) && (num = indsp->number_of_sounds) != 0) {
 
		if (Chance16R(1, 14, r) && (num = indsp->number_of_sounds) != 0) {
 
			SndPlayTileFx(
 
				(SoundFx)(indsp->random_sounds[((r >> 16) * num) >> 16]),
 
				i->xy);
 
		}
 
	}
 

	
 
@@ -1009,13 +1009,13 @@ static void ProduceIndustryGoods(Industr
 

	
 
		if ((indbehav & INDUSTRYBEH_PLANT_FIELDS) != 0) {
 
			bool plant;
 
			if (HasBit(indsp->callback_flags, CBM_IND_SPECIAL_EFFECT)) {
 
				plant = (GetIndustryCallback(CBID_INDUSTRY_SPECIAL_EFFECT, Random(), 0, i, i->type, i->xy) != 0);
 
			} else {
 
				plant = CHANCE16(1, 8);
 
				plant = Chance16(1, 8);
 
			}
 

	
 
			if (plant) PlantRandomFarmField(i);
 
		}
 
		if ((indbehav & INDUSTRYBEH_CUT_TREES) != 0) {
 
			bool cut = ((i->counter & 0x1FF) == 0);
 
@@ -2049,15 +2049,15 @@ static void ChangeIndustryProduction(Ind
 
			for (byte j = 0; j < 2 && i->produced_cargo[j] != CT_INVALID; j++){
 
				int old_prod, new_prod, percent;
 
				int mult = (i->last_month_pct_transported[j] > PERCENT_TRANSPORTED_60) ? 1 : -1;
 

	
 
				new_prod = old_prod = i->production_rate[j];
 

	
 
				if (only_decrease || CHANCE16(1, 3)) mult *= -1;
 
				if (only_decrease || Chance16(1, 3)) mult *= -1;
 

	
 
				if (CHANCE16(1, 22)) {
 
				if (Chance16(1, 22)) {
 
					new_prod += mult * (max(((RandomRange(50) + 10) * old_prod) >> 8, 1U));
 
				}
 

	
 
				/* Prevent production to overflow or Oil Rig passengers to be over-"produced" */
 
				new_prod = Clamp(new_prod, 1, 255);
 

	
 
@@ -2078,25 +2078,25 @@ static void ChangeIndustryProduction(Ind
 

	
 
				if (abs(percent) >= 10) {
 
					ReportNewsProductionChangeIndustry(i, i->produced_cargo[j], percent);
 
				}
 
			}
 
		} else {
 
			if (only_decrease || CHANCE16(1, 3)) {
 
			if (only_decrease || Chance16(1, 3)) {
 
				/* If you transport > 60%, 66% chance we increase, else 33% chance we increase */
 
				if (!only_decrease && (i->last_month_pct_transported[0] > PERCENT_TRANSPORTED_60) != CHANCE16(1, 3)) {
 
				if (!only_decrease && (i->last_month_pct_transported[0] > PERCENT_TRANSPORTED_60) != Chance16(1, 3)) {
 
					mul = 1; // Increase production
 
				} else {
 
					div = 1; // Decrease production
 
				}
 
			}
 
		}
 
	}
 

	
 
	if (standard && indspec->life_type & INDUSTRYLIFE_PROCESSING) {
 
		if ( (byte)(_cur_year - i->last_prod_year) >= 5 && CHANCE16(1, smooth_economy ? 180 : 2)) {
 
		if ( (byte)(_cur_year - i->last_prod_year) >= 5 && Chance16(1, smooth_economy ? 180 : 2)) {
 
			closeit = true;
 
		}
 
	}
 

	
 
	/* Increase if needed */
 
	while (mul-- != 0 && i->prod_level < 0x80) {
 
@@ -2169,13 +2169,13 @@ void IndustryMonthlyLoop()
 
		} else {
 
			ChangeIndustryProduction(i, true);
 
		}
 
	}
 

	
 
	/* 3% chance that we start a new industry */
 
	if (CHANCE16(3, 100)) {
 
	if (Chance16(3, 100)) {
 
		MaybeNewIndustry();
 
	} else {
 
		i = GetRandomIndustry();
 
		if (i != NULL) ChangeIndustryProduction(i, false);
 
	}
 

	
src/macros.h
Show inline comments
 
@@ -258,61 +258,12 @@ template<typename T> static inline uint 
 
		value &= (T)(value - 1);
 
	}
 

	
 
	return num;
 
}
 

	
 
/**
 
 * Flips a coin with a given probability.
 
 *
 
 * This macro can be used to get true or false randomized according to a
 
 * given probability. The parameter a and b create a percent value with
 
 * (a/b). The macro returns true in (a/b) percent.
 
 *
 
 * @param a The numerator of the fraction
 
 * @param b The denominator of the fraction, must of course not be null
 
 * @return True in (a/b) percent
 
 */
 
#define CHANCE16(a, b) CHANCE16I(a, b, Random())
 

	
 
/**
 
 * Flips a coin with a given probability and saves the randomize-number in a variable.
 
 *
 
 * This macro uses the same parameters as the CHANCE16 marco. The third parameter
 
 * must be a variable the randomize-number from Random() is saved in.
 
 *
 
 * The low 16 bits of r will already be used and can therefor not be passed to
 
 * CHANCE16I. One can only send the high 16 bits to CHANCE16I.
 
 *
 
 * @param a The numerator of the fraction, see CHANCE16
 
 * @param b The denominator of the fraction, see CHANCE16
 
 * @param r The variable to save the randomize-number from Random()
 
 * @return True in (a/b) percent
 
 */
 
#define CHANCE16R(a, b, r) CHANCE16I(a, b, r = Random())
 

	
 
/**
 
 * Checks if a given randomize-number is below a given probability.
 
 *
 
 * This macro is used to check if the given probability by the fraction of (a/b)
 
 * is greater than low 16 bits of the given randomize-number v.
 
 *
 
 * Do not use this function twice on the same random 16 bits as it will yield
 
 * the same result. One can use a random number for two calls to CHANCE16I,
 
 * where one call sends the low 16 bits and the other the high 16 bits.
 
 *
 
 * @param a The numerator of the fraction, see CHANCE16
 
 * @param b The denominator of the fraction, see CHANCE16
 
 * @param r The given randomize-number
 
 * @return True if v is less or equals (a/b)
 
 */
 
static inline bool CHANCE16I(const uint a, const uint b, const uint32 r)
 
{
 
	return (uint16)r < (uint16)((65536 * a) / b);
 
}
 

	
 

	
 
#define for_each_bit(_i, _b)            \
 
	for (_i = 0; _b != 0; _i++, _b >>= 1) \
 
		if (_b & 1)
 

	
 

	
src/road_cmd.cpp
Show inline comments
 
@@ -1240,13 +1240,13 @@ static void TileLoop_Road(TileIndex tile
 
			grp = GetTownRadiusGroup(t, tile);
 

	
 
			/* Show an animation to indicate road work */
 
			if (t->road_build_months != 0 &&
 
					(DistanceManhattan(t->xy, tile) < 8 || grp != 0) &&
 
					GetRoadTileType(tile) == ROAD_TILE_NORMAL && CountBits(GetAllRoadBits(tile)) > 1 ) {
 
				if (GetTileSlope(tile, NULL) == SLOPE_FLAT && EnsureNoVehicleOnGround(tile) && CHANCE16(1, 40)) {
 
				if (GetTileSlope(tile, NULL) == SLOPE_FLAT && EnsureNoVehicleOnGround(tile) && Chance16(1, 40)) {
 
					StartRoadWorks(tile);
 

	
 
					SndPlayTileFx(SND_21_JACKHAMMER, tile);
 
					CreateEffectVehicleAbove(
 
						TileX(tile) * TILE_SIZE + 7,
 
						TileY(tile) * TILE_SIZE + 7,
src/roadveh_cmd.cpp
Show inline comments
 
@@ -1986,13 +1986,13 @@ static void CheckIfRoadVehNeedsService(V
 
		}
 
		return;
 
	}
 

	
 
	if (v->current_order.type == OT_GOTO_DEPOT &&
 
			v->current_order.flags & OF_NON_STOP &&
 
			!CHANCE16(1, 20)) {
 
			!Chance16(1, 20)) {
 
		return;
 
	}
 

	
 
	if (v->current_order.type == OT_LOADING) v->LeaveStation();
 
	ClearSlot(v);
 

	
src/town_cmd.cpp
Show inline comments
 
@@ -403,13 +403,13 @@ static void TileLoop_Town(TileIndex tile
 
	}
 

	
 
	/* If the lift has a destination, it is already an animated tile. */
 
	if ((hs->building_flags & BUILDING_IS_ANIMATED) &&
 
			house_id < NEW_HOUSE_OFFSET &&
 
			!LiftHasDestination(tile) &&
 
			CHANCE16(1, 2))
 
			Chance16(1, 2))
 
		AddAnimatedTile(tile);
 

	
 
	t = GetTownByTile(tile);
 

	
 
	r = Random();
 

	
 
@@ -728,20 +728,20 @@ no_slope:
 
		}
 

	
 
		/* If the tile is not a slope in the right direction, then
 
		 * maybe terraform some. */
 
		desired_slope = (dir == DIAGDIR_NW || dir == DIAGDIR_SE) ? SLOPE_NW : SLOPE_NE;
 
		if (desired_slope != cur_slope && ComplementSlope(desired_slope) != cur_slope) {
 
			if (CHANCE16(1, 8)) {
 
			if (Chance16(1, 8)) {
 
				CommandCost res = CMD_ERROR;
 
				if (!_generating_world && CHANCE16(1, 10)) {
 
				if (!_generating_world && Chance16(1, 10)) {
 
					/* Note: Do not replace " ^ 0xF" with ComplementSlope(). The slope might be steep. */
 
					res = DoCommand(tile, CHANCE16(1, 16) ? cur_slope : cur_slope ^ 0xF, 0,
 
					res = DoCommand(tile, Chance16(1, 16) ? cur_slope : cur_slope ^ 0xF, 0,
 
							DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND);
 
				}
 
				if (CmdFailed(res) && CHANCE16(1, 3)) {
 
				if (CmdFailed(res) && Chance16(1, 3)) {
 
					/* We can consider building on the slope, though. */
 
					goto no_slope;
 
				}
 
			}
 
			return false;
 
		}
 
@@ -999,13 +999,13 @@ static void GrowTownInTile(TileIndex *ti
 
			case TL_BETTER_ROADS:
 
			case TL_ORIGINAL:
 
				if (!IsRoadAllowedHere(tile, target_dir)) return;
 

	
 
				DiagDirection source_dir = ReverseDiagDir(target_dir);
 

	
 
				if (CHANCE16(1, 4)) {
 
				if (Chance16(1, 4)) {
 
					/* Randomize a new target dir */
 
					do target_dir = RandomDiagDir(); while (target_dir == source_dir);
 
				}
 

	
 
				if (!IsRoadAllowedHere(TileAddByDiagDir(tile, target_dir), target_dir)) {
 
					/* A road is not allowed to continue the randomized road,
 
@@ -1093,21 +1093,21 @@ static void GrowTownInTile(TileIndex *ti
 
				/* FALL THROUGH */
 

	
 
			case TL_ORIGINAL:
 
				 /* Allow a house at the edge. 60% chance or
 
				  * always ok if no road allowed. */
 
				rcmd = DiagDirToRoadBits(target_dir);
 
				allow_house = (!IsRoadAllowedHere(house_tile, target_dir) || CHANCE16(6, 10));
 
				allow_house = (!IsRoadAllowedHere(house_tile, target_dir) || Chance16(6, 10));
 
				break;
 
		}
 

	
 
		if (allow_house) {
 
			/* Build a house, but not if there already is a house there. */
 
			if (!IsTileType(house_tile, MP_HOUSE)) {
 
				/* Level the land if possible */
 
				if (CHANCE16(1, 6)) LevelTownLand(house_tile);
 
				if (Chance16(1, 6)) LevelTownLand(house_tile);
 

	
 
				/* And build a house.
 
				 * Set result to -1 if we managed to build it. */
 
				if (BuildTownHouse(t1, house_tile)) {
 
					_grow_town_result = GROWTH_SUCCEED;
 
				}
 
@@ -1775,13 +1775,13 @@ static void DoBuildTownHouse(Town *t, Ti
 
		byte construction_counter = 0, construction_stage = 0;
 

	
 
		if (_generating_world) {
 
			uint32 r = Random();
 

	
 
			construction_stage = TOWN_HOUSE_COMPLETED;
 
			if (CHANCE16(1, 7)) construction_stage = GB(r, 0, 2);
 
			if (Chance16(1, 7)) construction_stage = GB(r, 0, 2);
 

	
 
			if (construction_stage == TOWN_HOUSE_COMPLETED) {
 
				ChangePopulation(t, hs->population);
 
			} else {
 
				construction_counter = GB(r, 2, 2);
 
			}
 
@@ -2152,13 +2152,13 @@ static void UpdateTownGrowRate(Town *t)
 

	
 
	if (t->fund_buildings_months != 0) {
 
		m = _grow_count_values[0][min(n, 5)];
 
		t->fund_buildings_months--;
 
	} else {
 
		m = _grow_count_values[1][min(n, 5)];
 
		if (n == 0 && !CHANCE16(1, 12)) return;
 
		if (n == 0 && !Chance16(1, 12)) return;
 
	}
 

	
 
	if (_opt.landscape == LT_ARCTIC) {
 
		if (TilePixelHeight(t->xy) >= GetSnowLine() && t->act_food == 0 && t->population > 90)
 
			return;
 
	} else if (_opt.landscape == LT_TROPIC) {
src/train_cmd.cpp
Show inline comments
 
@@ -2012,21 +2012,21 @@ static void HandleLocomotiveSmokeCloud(c
 
				sound = true;
 
			}
 
			break;
 

	
 
		case 1:
 
			/* diesel smoke */
 
			if (u->cur_speed <= 40 && CHANCE16(15, 128)) {
 
			if (u->cur_speed <= 40 && Chance16(15, 128)) {
 
				CreateEffectVehicleRel(v, 0, 0, 10, EV_DIESEL_SMOKE);
 
				sound = true;
 
			}
 
			break;
 

	
 
		case 2:
 
			/* blue spark */
 
			if (GB(v->tick_counter, 0, 2) == 0 && CHANCE16(1, 45)) {
 
			if (GB(v->tick_counter, 0, 2) == 0 && Chance16(1, 45)) {
 
				CreateEffectVehicleRel(v, 0, 0, 10, EV_ELECTRIC_SPARK);
 
				sound = true;
 
			}
 
			break;
 
		}
 
	} while ((v = v->Next()) != NULL);
 
@@ -3111,13 +3111,13 @@ static void HandleCrashedTrain(Vehicle *
 

	
 
	if (state == 4 && !(v->vehstatus & VS_HIDDEN)) {
 
		CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE);
 
	}
 

	
 
	uint32 r;
 
	if (state <= 200 && CHANCE16R(1, 7, r)) {
 
	if (state <= 200 && Chance16R(1, 7, r)) {
 
		int index = (r * 10 >> 16);
 

	
 
		Vehicle *u = v;
 
		do {
 
			if (--index < 0) {
 
				r = Random();
 
@@ -3389,13 +3389,13 @@ static void CheckIfTrainNeedsService(Veh
 
	}
 

	
 
	const Depot* depot = GetDepotByTile(tfdd.tile);
 

	
 
	if (v->current_order.type == OT_GOTO_DEPOT &&
 
			v->current_order.dest != depot->index &&
 
			!CHANCE16(3, 16)) {
 
			!Chance16(3, 16)) {
 
		return;
 
	}
 

	
 
	v->current_order.type = OT_GOTO_DEPOT;
 
	v->current_order.flags = OF_NON_STOP;
 
	v->current_order.dest = depot->index;
src/tree_cmd.cpp
Show inline comments
 
@@ -540,13 +540,13 @@ static void TileLoopTreesDesert(TileInde
 
				SND_43_LION,
 
				SND_44_MONKEYS,
 
				SND_48_DISTANT_BIRD
 
			};
 
			uint32 r = Random();
 

	
 
			if (CHANCE16I(1, 200, r)) SndPlayTileFx(forest_sounds[GB(r, 16, 2)], tile);
 
			if (Chance16I(1, 200, r)) SndPlayTileFx(forest_sounds[GB(r, 16, 2)], tile);
 
			break;
 
		}
 

	
 
		default: break;
 
	}
 
}
 
@@ -564,13 +564,13 @@ static void TileLoopTreesAlps(TileIndex 
 
		if (GetTreeGround(tile) != TREE_GROUND_SNOW_DESERT ||
 
				GetTreeDensity(tile) != density) {
 
			SetTreeGroundDensity(tile, TREE_GROUND_SNOW_DESERT, density);
 
		} else {
 
			if (GetTreeDensity(tile) == 3) {
 
				uint32 r = Random();
 
				if (CHANCE16I(1, 200, r)) {
 
				if (Chance16I(1, 200, r)) {
 
					SndPlayTileFx((r & 0x80000000) ? SND_39_HEAVY_WIND : SND_34_WIND, tile);
 
				}
 
			}
 
			return;
 
		}
 
	}
src/vehicle.cpp
Show inline comments
 
@@ -1261,13 +1261,13 @@ static void BubbleTick(Vehicle *v)
 
		EndVehicleMove(v);
 
		delete v;
 
		return;
 
	}
 

	
 
	if (b->y == 4 && b->x == 1) {
 
		if (v->z_pos > 180 || CHANCE16I(1, 96, InteractiveRandom())) {
 
		if (v->z_pos > 180 || Chance16I(1, 96, InteractiveRandom())) {
 
			v->spritenum = 5;
 
			SndPlayVehicleFx(SND_2F_POP, v);
 
		}
 
		et = 0;
 
	}
 

	
 
@@ -1440,13 +1440,13 @@ void CheckVehicleBreakdown(Vehicle *v)
 
	}
 

	
 
	r = Random();
 

	
 
	/* increase chance of failure */
 
	chance = v->breakdown_chance + 1;
 
	if (CHANCE16I(1,25,r)) chance += 25;
 
	if (Chance16I(1,25,r)) chance += 25;
 
	v->breakdown_chance = min(255, chance);
 

	
 
	/* calculate reliability value to use in comparison */
 
	rel = v->reliability;
 
	if (v->type == VEH_SHIP) rel += 0x6666;
 

	
0 comments (0 inline, 0 general)