1
0
Fork 0

Codechange: Use reference for always_accepted output parameter of AddAcceptedCargo. (#12854)

This parameter should always present (see tile_cmd.h:186), so use a reference to ensure it is.
pull/12855/head
Peter Nelson 2024-07-10 12:30:14 +01:00 committed by GitHub
parent 60c3913a99
commit 93eb27d8df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 11 deletions

View File

@ -409,7 +409,7 @@ static Foundation GetFoundation_Industry(TileIndex tile, Slope tileh)
return FlatteningFoundation(tileh); return FlatteningFoundation(tileh);
} }
static void AddAcceptedCargo_Industry(TileIndex tile, CargoArray &acceptance, CargoTypes *always_accepted) static void AddAcceptedCargo_Industry(TileIndex tile, CargoArray &acceptance, CargoTypes &always_accepted)
{ {
IndustryGfx gfx = GetIndustryGfx(tile); IndustryGfx gfx = GetIndustryGfx(tile);
const IndustryTileSpec *itspec = GetIndustryTileSpec(gfx); const IndustryTileSpec *itspec = GetIndustryTileSpec(gfx);
@ -459,13 +459,13 @@ static void AddAcceptedCargo_Industry(TileIndex tile, CargoArray &acceptance, Ca
acceptance[a] += cargo_acceptance[i]; acceptance[a] += cargo_acceptance[i];
/* Maybe set 'always accepted' bit (if it's not set already) */ /* Maybe set 'always accepted' bit (if it's not set already) */
if (HasBit(*always_accepted, a)) continue; if (HasBit(always_accepted, a)) continue;
/* Test whether the industry itself accepts the cargo type */ /* Test whether the industry itself accepts the cargo type */
if (ind->IsCargoAccepted(a)) continue; if (ind->IsCargoAccepted(a)) continue;
/* If the industry itself doesn't accept this cargo, set 'always accepted' bit */ /* If the industry itself doesn't accept this cargo, set 'always accepted' bit */
SetBit(*always_accepted, a); SetBit(always_accepted, a);
} }
} }

View File

@ -617,7 +617,7 @@ static CommandCost ClearTile_Object(TileIndex tile, DoCommandFlag flags)
return cost; return cost;
} }
static void AddAcceptedCargo_Object(TileIndex tile, CargoArray &acceptance, CargoTypes *always_accepted) static void AddAcceptedCargo_Object(TileIndex tile, CargoArray &acceptance, CargoTypes &always_accepted)
{ {
if (!IsObjectType(tile, OBJECT_HQ)) return; if (!IsObjectType(tile, OBJECT_HQ)) return;
@ -632,7 +632,7 @@ static void AddAcceptedCargo_Object(TileIndex tile, CargoArray &acceptance, Carg
CargoID pass = GetCargoIDByLabel(CT_PASSENGERS); CargoID pass = GetCargoIDByLabel(CT_PASSENGERS);
if (IsValidCargoID(pass)) { if (IsValidCargoID(pass)) {
acceptance[pass] += std::max(1U, level); acceptance[pass] += std::max(1U, level);
SetBit(*always_accepted, pass); SetBit(always_accepted, pass);
} }
/* Top town building generates 4, HQ can make up to 8. The /* Top town building generates 4, HQ can make up to 8. The
@ -642,7 +642,7 @@ static void AddAcceptedCargo_Object(TileIndex tile, CargoArray &acceptance, Carg
CargoID mail = GetCargoIDByLabel(CT_MAIL); CargoID mail = GetCargoIDByLabel(CT_MAIL);
if (IsValidCargoID(mail)) { if (IsValidCargoID(mail)) {
acceptance[mail] += std::max(1U, level / 2); acceptance[mail] += std::max(1U, level / 2);
SetBit(*always_accepted, mail); SetBit(always_accepted, mail);
} }
} }

View File

@ -95,7 +95,7 @@ typedef CommandCost ClearTileProc(TileIndex tile, DoCommandFlag flags);
* @param acceptance Storage destination of the cargo acceptance in 1/8 * @param acceptance Storage destination of the cargo acceptance in 1/8
* @param always_accepted Bitmask of always accepted cargo types * @param always_accepted Bitmask of always accepted cargo types
*/ */
typedef void AddAcceptedCargoProc(TileIndex tile, CargoArray &acceptance, CargoTypes *always_accepted); typedef void AddAcceptedCargoProc(TileIndex tile, CargoArray &acceptance, CargoTypes &always_accepted);
/** /**
* Tile callback function signature for obtaining a tile description * Tile callback function signature for obtaining a tile description
@ -184,7 +184,7 @@ inline void AddAcceptedCargo(TileIndex tile, CargoArray &acceptance, CargoTypes
AddAcceptedCargoProc *proc = _tile_type_procs[GetTileType(tile)]->add_accepted_cargo_proc; AddAcceptedCargoProc *proc = _tile_type_procs[GetTileType(tile)]->add_accepted_cargo_proc;
if (proc == nullptr) return; if (proc == nullptr) return;
CargoTypes dummy = 0; // use dummy bitmask so there don't need to be several 'always_accepted != nullptr' checks CargoTypes dummy = 0; // use dummy bitmask so there don't need to be several 'always_accepted != nullptr' checks
proc(tile, acceptance, always_accepted == nullptr ? &dummy : always_accepted); proc(tile, acceptance, always_accepted == nullptr ? dummy : *always_accepted);
} }
inline void AddProducedCargo(TileIndex tile, CargoArray &produced) inline void AddProducedCargo(TileIndex tile, CargoArray &produced)

View File

@ -771,14 +771,21 @@ static void AddProducedCargo_Town(TileIndex tile, CargoArray &produced)
} }
} }
static inline void AddAcceptedCargoSetMask(CargoID cargo, uint amount, CargoArray &acceptance, CargoTypes *always_accepted) /**
* Fill cargo acceptance array and always_accepted mask, if cargo ID is valid.
* @param cargo Cargo type to add.
* @param amount Amount of cargo to add.
* @param[out] acceptance Output array containing amount of cargo accepted.
* @param[out] always_accepted Output mask of accepted cargo types.
*/
static void AddAcceptedCargoSetMask(CargoID cargo, uint amount, CargoArray &acceptance, CargoTypes &always_accepted)
{ {
if (!IsValidCargoID(cargo) || amount == 0) return; if (!IsValidCargoID(cargo) || amount == 0) return;
acceptance[cargo] += amount; acceptance[cargo] += amount;
SetBit(*always_accepted, cargo); SetBit(always_accepted, cargo);
} }
static void AddAcceptedCargo_Town(TileIndex tile, CargoArray &acceptance, CargoTypes *always_accepted) static void AddAcceptedCargo_Town(TileIndex tile, CargoArray &acceptance, CargoTypes &always_accepted)
{ {
const HouseSpec *hs = HouseSpec::Get(GetHouseType(tile)); const HouseSpec *hs = HouseSpec::Get(GetHouseType(tile));
CargoID accepts[lengthof(hs->accepts_cargo)]; CargoID accepts[lengthof(hs->accepts_cargo)];