Changeset - r26910:1221e1e8594f
[Not reviewed]
master
0 2 0
Rubidium - 21 months ago 2023-02-25 16:08:43
rubidium@openttd.org
Codechange: split large function into smaller functions with self-explanatory names
2 files changed with 227 insertions and 198 deletions:
0 comments (0 inline, 0 general)
src/industry_cmd.cpp
Show inline comments
 
@@ -554,6 +554,145 @@ static bool TransportIndustryGoods(TileI
 
	return moved_cargo;
 
}
 

	
 
static void AnimateSugarSieve(TileIndex tile)
 
{
 
	byte m = GetAnimationFrame(tile) + 1;
 

	
 
	if (_settings_client.sound.ambient) {
 
		switch (m & 7) {
 
			case 2: SndPlayTileFx(SND_2D_SUGAR_MINE_1, tile); break;
 
			case 6: SndPlayTileFx(SND_29_SUGAR_MINE_2, tile); break;
 
		}
 
	}
 

	
 
	if (m >= 96) {
 
		m = 0;
 
		DeleteAnimatedTile(tile);
 
	}
 
	SetAnimationFrame(tile, m);
 

	
 
	MarkTileDirtyByTile(tile);
 
}
 

	
 
static void AnimateToffeeQuarry(TileIndex tile)
 
{
 
	byte m = GetAnimationFrame(tile);
 

	
 
	if (_industry_anim_offs_toffee[m] == 0xFF && _settings_client.sound.ambient) {
 
		SndPlayTileFx(SND_30_TOFFEE_QUARRY, tile);
 
	}
 

	
 
	if (++m >= 70) {
 
		m = 0;
 
		DeleteAnimatedTile(tile);
 
	}
 
	SetAnimationFrame(tile, m);
 

	
 
	MarkTileDirtyByTile(tile);
 
}
 

	
 
static void AnimateBubbleCatcher(TileIndex tile)
 
{
 
	byte m = GetAnimationFrame(tile);
 

	
 
	if (++m >= 40) {
 
		m = 0;
 
		DeleteAnimatedTile(tile);
 
	}
 
	SetAnimationFrame(tile, m);
 

	
 
	MarkTileDirtyByTile(tile);
 
}
 

	
 
static void AnimatePowerPlantSparks(TileIndex tile)
 
{
 
	byte m = GetAnimationFrame(tile);
 
	if (m == 6) {
 
		SetAnimationFrame(tile, 0);
 
		DeleteAnimatedTile(tile);
 
	} else {
 
		SetAnimationFrame(tile, m + 1);
 
		MarkTileDirtyByTile(tile);
 
	}
 
}
 

	
 
static void AnimateToyFactory(TileIndex tile)
 
{
 
	byte m = GetAnimationFrame(tile) + 1;
 

	
 
	switch (m) {
 
		case  1: if (_settings_client.sound.ambient) SndPlayTileFx(SND_2C_TOY_FACTORY_1, tile); break;
 
		case 23: if (_settings_client.sound.ambient) SndPlayTileFx(SND_2B_TOY_FACTORY_2, tile); break;
 
		case 28: if (_settings_client.sound.ambient) SndPlayTileFx(SND_2A_TOY_FACTORY_3, tile); break;
 
		default:
 
			if (m >= 50) {
 
				int n = GetIndustryAnimationLoop(tile) + 1;
 
				m = 0;
 
				if (n >= 8) {
 
					n = 0;
 
					DeleteAnimatedTile(tile);
 
				}
 
				SetIndustryAnimationLoop(tile, n);
 
			}
 
	}
 

	
 
	SetAnimationFrame(tile, m);
 
	MarkTileDirtyByTile(tile);
 
}
 

	
 
static void AnimatePlasticFountain(TileIndex tile, IndustryGfx gfx)
 
{
 
	gfx = (gfx < GFX_PLASTIC_FOUNTAIN_ANIMATED_8) ? gfx + 1 : GFX_PLASTIC_FOUNTAIN_ANIMATED_1;
 
	SetIndustryGfx(tile, gfx);
 
	MarkTileDirtyByTile(tile);
 
}
 

	
 
static void AnimateOilWell(TileIndex tile, IndustryGfx gfx)
 
{
 
	bool b = Chance16(1, 7);
 
	byte m = GetAnimationFrame(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);
 
		DeleteAnimatedTile(tile);
 
	} else {
 
		SetAnimationFrame(tile, m);
 
		SetIndustryGfx(tile, gfx);
 
		MarkTileDirtyByTile(tile);
 
	}
 
}
 

	
 
static void AnimateMineTower(TileIndex tile)
 
{
 
	int state = _tick_counter & 0x7FF;
 

	
 
	if ((state -= 0x400) < 0) return;
 

	
 
	if (state < 0x1A0) {
 
		if (state < 0x20 || state >= 0x180) {
 
			byte m = GetAnimationFrame(tile);
 
			if (!(m & 0x40)) {
 
				SetAnimationFrame(tile, m | 0x40);
 
				if (_settings_client.sound.ambient) SndPlayTileFx(SND_0B_MINE, tile);
 
			}
 
			if (state & 7) return;
 
		} else {
 
			if (state & 3) return;
 
		}
 
		byte m = (GetAnimationFrame(tile) + 1) | 0x40;
 
		if (m > 0xC2) m = 0xC0;
 
		SetAnimationFrame(tile, m);
 
		MarkTileDirtyByTile(tile);
 
	} else if (state >= 0x200 && state < 0x3A0) {
 
		int i = (state < 0x220 || state >= 0x380) ? 7 : 3;
 
		if (state & i) return;
 

	
 
		byte m = (GetAnimationFrame(tile) & 0xBF) - 1;
 
		if (m < 0x80) m = 0x82;
 
		SetAnimationFrame(tile, m);
 
		MarkTileDirtyByTile(tile);
 
	}
 
}
 

	
 
static void AnimateTile_Industry(TileIndex tile)
 
{
 
@@ -566,159 +705,43 @@ static void AnimateTile_Industry(TileInd
 

	
 
	switch (gfx) {
 
	case GFX_SUGAR_MINE_SIEVE:
 
		if ((_tick_counter & 1) == 0) {
 
			byte m = GetAnimationFrame(tile) + 1;
 

	
 
			if (_settings_client.sound.ambient) {
 
				switch (m & 7) {
 
					case 2: SndPlayTileFx(SND_2D_SUGAR_MINE_1, tile); break;
 
					case 6: SndPlayTileFx(SND_29_SUGAR_MINE_2, tile); break;
 
				}
 
			}
 

	
 
			if (m >= 96) {
 
				m = 0;
 
				DeleteAnimatedTile(tile);
 
			}
 
			SetAnimationFrame(tile, m);
 

	
 
			MarkTileDirtyByTile(tile);
 
		}
 
		if ((_tick_counter & 1) == 0) AnimateSugarSieve(tile);
 
		break;
 

	
 
	case GFX_TOFFEE_QUARY:
 
		if ((_tick_counter & 3) == 0) {
 
			byte m = GetAnimationFrame(tile);
 

	
 
			if (_industry_anim_offs_toffee[m] == 0xFF && _settings_client.sound.ambient) {
 
				SndPlayTileFx(SND_30_TOFFEE_QUARRY, tile);
 
			}
 

	
 
			if (++m >= 70) {
 
				m = 0;
 
				DeleteAnimatedTile(tile);
 
			}
 
			SetAnimationFrame(tile, m);
 

	
 
			MarkTileDirtyByTile(tile);
 
		}
 
		if ((_tick_counter & 3) == 0) AnimateToffeeQuarry(tile);
 
		break;
 

	
 
	case GFX_BUBBLE_CATCHER:
 
		if ((_tick_counter & 1) == 0) {
 
			byte m = GetAnimationFrame(tile);
 

	
 
			if (++m >= 40) {
 
				m = 0;
 
				DeleteAnimatedTile(tile);
 
			}
 
			SetAnimationFrame(tile, m);
 

	
 
			MarkTileDirtyByTile(tile);
 
		}
 
		if ((_tick_counter & 1) == 0) AnimateBubbleCatcher(tile);
 
		break;
 

	
 
	/* Sparks on a coal plant */
 
	case GFX_POWERPLANT_SPARKS:
 
		if ((_tick_counter & 3) == 0) {
 
			byte m = GetAnimationFrame(tile);
 
			if (m == 6) {
 
				SetAnimationFrame(tile, 0);
 
				DeleteAnimatedTile(tile);
 
			} else {
 
				SetAnimationFrame(tile, m + 1);
 
				MarkTileDirtyByTile(tile);
 
			}
 
		}
 
		if ((_tick_counter & 3) == 0) AnimatePowerPlantSparks(tile);
 
		break;
 

	
 
	case GFX_TOY_FACTORY:
 
		if ((_tick_counter & 1) == 0) {
 
			byte m = GetAnimationFrame(tile) + 1;
 

	
 
			switch (m) {
 
				case  1: if (_settings_client.sound.ambient) SndPlayTileFx(SND_2C_TOY_FACTORY_1, tile); break;
 
				case 23: if (_settings_client.sound.ambient) SndPlayTileFx(SND_2B_TOY_FACTORY_2, tile); break;
 
				case 28: if (_settings_client.sound.ambient) SndPlayTileFx(SND_2A_TOY_FACTORY_3, tile); break;
 
				default:
 
					if (m >= 50) {
 
						int n = GetIndustryAnimationLoop(tile) + 1;
 
						m = 0;
 
						if (n >= 8) {
 
							n = 0;
 
							DeleteAnimatedTile(tile);
 
						}
 
						SetIndustryAnimationLoop(tile, n);
 
					}
 
			}
 

	
 
			SetAnimationFrame(tile, m);
 
			MarkTileDirtyByTile(tile);
 
		}
 
		if ((_tick_counter & 1) == 0) AnimateToyFactory(tile);
 
		break;
 

	
 
	case GFX_PLASTIC_FOUNTAIN_ANIMATED_1: case GFX_PLASTIC_FOUNTAIN_ANIMATED_2:
 
	case GFX_PLASTIC_FOUNTAIN_ANIMATED_3: case GFX_PLASTIC_FOUNTAIN_ANIMATED_4:
 
	case GFX_PLASTIC_FOUNTAIN_ANIMATED_5: case GFX_PLASTIC_FOUNTAIN_ANIMATED_6:
 
	case GFX_PLASTIC_FOUNTAIN_ANIMATED_7: case GFX_PLASTIC_FOUNTAIN_ANIMATED_8:
 
		if ((_tick_counter & 3) == 0) {
 
			gfx = (gfx < 155) ? gfx + 1 : 148;
 
			SetIndustryGfx(tile, gfx);
 
			MarkTileDirtyByTile(tile);
 
		}
 
		if ((_tick_counter & 3) == 0) AnimatePlasticFountain(tile, gfx);
 
		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);
 
			byte m = GetAnimationFrame(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);
 
				DeleteAnimatedTile(tile);
 
			} else {
 
				SetAnimationFrame(tile, m);
 
				SetIndustryGfx(tile, gfx);
 
				MarkTileDirtyByTile(tile);
 
			}
 
		}
 
		if ((_tick_counter & 7) == 0) AnimateOilWell(tile, gfx);
 
		break;
 

	
 
	case GFX_COAL_MINE_TOWER_ANIMATED:
 
	case GFX_COPPER_MINE_TOWER_ANIMATED:
 
	case GFX_GOLD_MINE_TOWER_ANIMATED: {
 
			int state = _tick_counter & 0x7FF;
 

	
 
			if ((state -= 0x400) < 0) return;
 

	
 
			if (state < 0x1A0) {
 
				if (state < 0x20 || state >= 0x180) {
 
					byte m = GetAnimationFrame(tile);
 
					if (!(m & 0x40)) {
 
						SetAnimationFrame(tile, m | 0x40);
 
						if (_settings_client.sound.ambient) SndPlayTileFx(SND_0B_MINE, tile);
 
					}
 
					if (state & 7) return;
 
				} else {
 
					if (state & 3) return;
 
				}
 
				byte m = (GetAnimationFrame(tile) + 1) | 0x40;
 
				if (m > 0xC2) m = 0xC0;
 
				SetAnimationFrame(tile, m);
 
				MarkTileDirtyByTile(tile);
 
			} else if (state >= 0x200 && state < 0x3A0) {
 
				int i = (state < 0x220 || state >= 0x380) ? 7 : 3;
 
				if (state & i) return;
 

	
 
				byte m = (GetAnimationFrame(tile) & 0xBF) - 1;
 
				if (m < 0x80) m = 0x82;
 
				SetAnimationFrame(tile, m);
 
				MarkTileDirtyByTile(tile);
 
			}
 
			break;
 
		}
 
	case GFX_GOLD_MINE_TOWER_ANIMATED:
 
		AnimateMineTower(tile);
 
		break;
 
	}
 
}
 

	
src/station_cmd.cpp
Show inline comments
 
@@ -3091,83 +3091,89 @@ static Foundation GetFoundation_Station(
 
	return FlatteningFoundation(tileh);
 
}
 

	
 
static void FillTileDescRoadStop(TileIndex tile, TileDesc *td)
 
{
 
	RoadType road_rt = GetRoadTypeRoad(tile);
 
	RoadType tram_rt = GetRoadTypeTram(tile);
 
	Owner road_owner = INVALID_OWNER;
 
	Owner tram_owner = INVALID_OWNER;
 
	if (road_rt != INVALID_ROADTYPE) {
 
		const RoadTypeInfo *rti = GetRoadTypeInfo(road_rt);
 
		td->roadtype = rti->strings.name;
 
		td->road_speed = rti->max_speed / 2;
 
		road_owner = GetRoadOwner(tile, RTT_ROAD);
 
	}
 

	
 
	if (tram_rt != INVALID_ROADTYPE) {
 
		const RoadTypeInfo *rti = GetRoadTypeInfo(tram_rt);
 
		td->tramtype = rti->strings.name;
 
		td->tram_speed = rti->max_speed / 2;
 
		tram_owner = GetRoadOwner(tile, RTT_TRAM);
 
	}
 

	
 
	if (IsDriveThroughStopTile(tile)) {
 
		/* Is there a mix of owners? */
 
		if ((tram_owner != INVALID_OWNER && tram_owner != td->owner[0]) ||
 
				(road_owner != INVALID_OWNER && road_owner != td->owner[0])) {
 
			uint i = 1;
 
			if (road_owner != INVALID_OWNER) {
 
				td->owner_type[i] = STR_LAND_AREA_INFORMATION_ROAD_OWNER;
 
				td->owner[i] = road_owner;
 
				i++;
 
			}
 
			if (tram_owner != INVALID_OWNER) {
 
				td->owner_type[i] = STR_LAND_AREA_INFORMATION_TRAM_OWNER;
 
				td->owner[i] = tram_owner;
 
			}
 
		}
 
	}
 
}
 

	
 
void FillTileDescRailStation(TileIndex tile, TileDesc *td)
 
{
 
	const StationSpec *spec = GetStationSpec(tile);
 

	
 
	if (spec != nullptr) {
 
		td->station_class = StationClass::Get(spec->cls_id)->name;
 
		td->station_name  = spec->name;
 

	
 
		if (spec->grf_prop.grffile != nullptr) {
 
			const GRFConfig *gc = GetGRFConfig(spec->grf_prop.grffile->grfid);
 
			td->grf = gc->GetName();
 
		}
 
	}
 

	
 
	const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(tile));
 
	td->rail_speed = rti->max_speed;
 
	td->railtype = rti->strings.name;
 
}
 

	
 
void FillTileDescAirport(TileIndex tile, TileDesc *td)
 
{
 
	const AirportSpec *as = Station::GetByTile(tile)->airport.GetSpec();
 
	td->airport_class = AirportClass::Get(as->cls_id)->name;
 
	td->airport_name = as->name;
 

	
 
	const AirportTileSpec *ats = AirportTileSpec::GetByTile(tile);
 
	td->airport_tile_name = ats->name;
 

	
 
	if (as->grf_prop.grffile != nullptr) {
 
		const GRFConfig *gc = GetGRFConfig(as->grf_prop.grffile->grfid);
 
		td->grf = gc->GetName();
 
	} else if (ats->grf_prop.grffile != nullptr) {
 
		const GRFConfig *gc = GetGRFConfig(ats->grf_prop.grffile->grfid);
 
		td->grf = gc->GetName();
 
	}
 
}
 

	
 
static void GetTileDesc_Station(TileIndex tile, TileDesc *td)
 
{
 
	td->owner[0] = GetTileOwner(tile);
 

	
 
	if (IsRoadStopTile(tile)) {
 
		RoadType road_rt = GetRoadTypeRoad(tile);
 
		RoadType tram_rt = GetRoadTypeTram(tile);
 
		Owner road_owner = INVALID_OWNER;
 
		Owner tram_owner = INVALID_OWNER;
 
		if (road_rt != INVALID_ROADTYPE) {
 
			const RoadTypeInfo *rti = GetRoadTypeInfo(road_rt);
 
			td->roadtype = rti->strings.name;
 
			td->road_speed = rti->max_speed / 2;
 
			road_owner = GetRoadOwner(tile, RTT_ROAD);
 
		}
 

	
 
		if (tram_rt != INVALID_ROADTYPE) {
 
			const RoadTypeInfo *rti = GetRoadTypeInfo(tram_rt);
 
			td->tramtype = rti->strings.name;
 
			td->tram_speed = rti->max_speed / 2;
 
			tram_owner = GetRoadOwner(tile, RTT_TRAM);
 
		}
 

	
 
		if (IsDriveThroughStopTile(tile)) {
 
			/* Is there a mix of owners? */
 
			if ((tram_owner != INVALID_OWNER && tram_owner != td->owner[0]) ||
 
					(road_owner != INVALID_OWNER && road_owner != td->owner[0])) {
 
				uint i = 1;
 
				if (road_owner != INVALID_OWNER) {
 
					td->owner_type[i] = STR_LAND_AREA_INFORMATION_ROAD_OWNER;
 
					td->owner[i] = road_owner;
 
					i++;
 
				}
 
				if (tram_owner != INVALID_OWNER) {
 
					td->owner_type[i] = STR_LAND_AREA_INFORMATION_TRAM_OWNER;
 
					td->owner[i] = tram_owner;
 
				}
 
			}
 
		}
 
	}
 

	
 
	td->build_date = BaseStation::GetByTile(tile)->build_date;
 

	
 
	if (HasStationTileRail(tile)) {
 
		const StationSpec *spec = GetStationSpec(tile);
 

	
 
		if (spec != nullptr) {
 
			td->station_class = StationClass::Get(spec->cls_id)->name;
 
			td->station_name  = spec->name;
 

	
 
			if (spec->grf_prop.grffile != nullptr) {
 
				const GRFConfig *gc = GetGRFConfig(spec->grf_prop.grffile->grfid);
 
				td->grf = gc->GetName();
 
			}
 
		}
 

	
 
		const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(tile));
 
		td->rail_speed = rti->max_speed;
 
		td->railtype = rti->strings.name;
 
	}
 

	
 
	if (IsAirport(tile)) {
 
		const AirportSpec *as = Station::GetByTile(tile)->airport.GetSpec();
 
		td->airport_class = AirportClass::Get(as->cls_id)->name;
 
		td->airport_name = as->name;
 

	
 
		const AirportTileSpec *ats = AirportTileSpec::GetByTile(tile);
 
		td->airport_tile_name = ats->name;
 

	
 
		if (as->grf_prop.grffile != nullptr) {
 
			const GRFConfig *gc = GetGRFConfig(as->grf_prop.grffile->grfid);
 
			td->grf = gc->GetName();
 
		} else if (ats->grf_prop.grffile != nullptr) {
 
			const GRFConfig *gc = GetGRFConfig(ats->grf_prop.grffile->grfid);
 
			td->grf = gc->GetName();
 
		}
 
	}
 
	if (IsRoadStop(tile)) FillTileDescRoadStop(tile, td);
 
	if (HasStationRail(tile)) FillTileDescRailStation(tile, td);
 
	if (IsAirport(tile)) FillTileDescAirport(tile, td);
 

	
 
	StringID str;
 
	switch (GetStationType(tile)) {
0 comments (0 inline, 0 general)