mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Rename storage of random triggers to include the term 'random'.
parent
39220a5feb
commit
264abfafe6
|
@ -74,7 +74,7 @@ struct BaseStation : StationPool::PoolItem<&_station_pool> {
|
||||||
TimerGameCalendar::Date build_date{}; ///< Date of construction
|
TimerGameCalendar::Date build_date{}; ///< Date of construction
|
||||||
|
|
||||||
uint16_t random_bits = 0; ///< Random bits assigned to this station
|
uint16_t random_bits = 0; ///< Random bits assigned to this station
|
||||||
uint8_t waiting_triggers = 0; ///< Waiting triggers (NewGRF) for this station
|
uint8_t waiting_random_triggers = 0; ///< Waiting triggers (NewGRF) for this station
|
||||||
uint8_t cached_anim_triggers = 0; ///< NOSAVE: Combined animation trigger bitmask, used to determine if trigger processing should happen.
|
uint8_t cached_anim_triggers = 0; ///< NOSAVE: Combined animation trigger bitmask, used to determine if trigger processing should happen.
|
||||||
uint8_t cached_roadstop_anim_triggers = 0; ///< NOSAVE: Combined animation trigger bitmask for road stops, used to determine if trigger processing should happen.
|
uint8_t cached_roadstop_anim_triggers = 0; ///< NOSAVE: Combined animation trigger bitmask for road stops, used to determine if trigger processing should happen.
|
||||||
CargoTypes cached_cargo_triggers{}; ///< NOSAVE: Combined cargo trigger bitmask
|
CargoTypes cached_cargo_triggers{}; ///< NOSAVE: Combined cargo trigger bitmask
|
||||||
|
|
|
@ -247,7 +247,7 @@ inline void SetIndustryRandomBits(Tile tile, uint8_t bits)
|
||||||
* @pre IsTileType(tile, MP_INDUSTRY)
|
* @pre IsTileType(tile, MP_INDUSTRY)
|
||||||
* @return requested triggers
|
* @return requested triggers
|
||||||
*/
|
*/
|
||||||
inline uint8_t GetIndustryTriggers(Tile tile)
|
inline uint8_t GetIndustryRandomTriggers(Tile tile)
|
||||||
{
|
{
|
||||||
assert(IsTileType(tile, MP_INDUSTRY));
|
assert(IsTileType(tile, MP_INDUSTRY));
|
||||||
return GB(tile.m6(), 3, 3);
|
return GB(tile.m6(), 3, 3);
|
||||||
|
@ -261,7 +261,7 @@ inline uint8_t GetIndustryTriggers(Tile tile)
|
||||||
* @param triggers the triggers to set
|
* @param triggers the triggers to set
|
||||||
* @pre IsTileType(tile, MP_INDUSTRY)
|
* @pre IsTileType(tile, MP_INDUSTRY)
|
||||||
*/
|
*/
|
||||||
inline void SetIndustryTriggers(Tile tile, uint8_t triggers)
|
inline void SetIndustryRandomTriggers(Tile tile, uint8_t triggers)
|
||||||
{
|
{
|
||||||
assert(IsTileType(tile, MP_INDUSTRY));
|
assert(IsTileType(tile, MP_INDUSTRY));
|
||||||
SB(tile.m6(), 3, 3, triggers);
|
SB(tile.m6(), 3, 3, triggers);
|
||||||
|
@ -283,7 +283,7 @@ inline void MakeIndustry(Tile t, IndustryID index, IndustryGfx gfx, uint8_t rand
|
||||||
SetIndustryRandomBits(t, random); // m3
|
SetIndustryRandomBits(t, random); // m3
|
||||||
t.m4() = 0;
|
t.m4() = 0;
|
||||||
SetIndustryGfx(t, gfx); // m5, part of m6
|
SetIndustryGfx(t, gfx); // m5, part of m6
|
||||||
SetIndustryTriggers(t, 0); // rest of m6
|
SetIndustryRandomTriggers(t, 0); // rest of m6
|
||||||
SetWaterClass(t, wc);
|
SetWaterClass(t, wc);
|
||||||
t.m7() = 0;
|
t.m7() = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -309,9 +309,9 @@ static uint8_t MapAircraftMovementAction(const Aircraft *v)
|
||||||
return this->v == nullptr ? 0 : this->v->random_bits;
|
return this->v == nullptr ? 0 : this->v->random_bits;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* virtual */ uint32_t VehicleScopeResolver::GetTriggers() const
|
/* virtual */ uint32_t VehicleScopeResolver::GetRandomTriggers() const
|
||||||
{
|
{
|
||||||
return this->v == nullptr ? 0 : this->v->waiting_triggers;
|
return this->v == nullptr ? 0 : this->v->waiting_random_triggers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -626,7 +626,7 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
|
||||||
|
|
||||||
if (parameter == 0x5F) {
|
if (parameter == 0x5F) {
|
||||||
/* This seems to be the only variable that makes sense to access via var 61, but is not handled by VehicleGetVariable */
|
/* This seems to be the only variable that makes sense to access via var 61, but is not handled by VehicleGetVariable */
|
||||||
return (u->random_bits << 8) | u->waiting_triggers;
|
return (u->random_bits << 8) | u->waiting_random_triggers;
|
||||||
} else {
|
} else {
|
||||||
return VehicleGetVariable(u, object, parameter, GetRegister(0x10E), available);
|
return VehicleGetVariable(u, object, parameter, GetRegister(0x10E), available);
|
||||||
}
|
}
|
||||||
|
@ -891,7 +891,7 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
|
||||||
case 0x78: break; // not implemented
|
case 0x78: break; // not implemented
|
||||||
case 0x79: break; // not implemented
|
case 0x79: break; // not implemented
|
||||||
case 0x7A: return v->random_bits;
|
case 0x7A: return v->random_bits;
|
||||||
case 0x7B: return v->waiting_triggers;
|
case 0x7B: return v->waiting_random_triggers;
|
||||||
case 0x7C: break; // vehicle specific, see below
|
case 0x7C: break; // vehicle specific, see below
|
||||||
case 0x7D: break; // vehicle specific, see below
|
case 0x7D: break; // vehicle specific, see below
|
||||||
case 0x7E: break; // not implemented
|
case 0x7E: break; // not implemented
|
||||||
|
@ -1253,14 +1253,14 @@ static void DoTriggerVehicleRandomisation(Vehicle *v, VehicleTrigger trigger, ui
|
||||||
assert(v != nullptr);
|
assert(v != nullptr);
|
||||||
|
|
||||||
VehicleResolverObject object(v->engine_type, v, VehicleResolverObject::WO_CACHED, false, CBID_RANDOM_TRIGGER);
|
VehicleResolverObject object(v->engine_type, v, VehicleResolverObject::WO_CACHED, false, CBID_RANDOM_TRIGGER);
|
||||||
object.waiting_triggers = v->waiting_triggers | trigger;
|
object.waiting_random_triggers = v->waiting_random_triggers | trigger;
|
||||||
v->waiting_triggers = object.waiting_triggers; // store now for var 5F
|
v->waiting_random_triggers = object.waiting_random_triggers; // store now for var 5F
|
||||||
|
|
||||||
const SpriteGroup *group = object.Resolve();
|
const SpriteGroup *group = object.Resolve();
|
||||||
if (group == nullptr) return;
|
if (group == nullptr) return;
|
||||||
|
|
||||||
/* Store remaining triggers. */
|
/* Store remaining triggers. */
|
||||||
v->waiting_triggers = object.GetRemainingTriggers();
|
v->waiting_random_triggers = object.GetRemainingRandomTriggers();
|
||||||
|
|
||||||
/* Rerandomise bits. Scopes other than SELF are invalid for rerandomisation. For bug-to-bug-compatibility with TTDP we ignore the scope. */
|
/* Rerandomise bits. Scopes other than SELF are invalid for rerandomisation. For bug-to-bug-compatibility with TTDP we ignore the scope. */
|
||||||
uint16_t new_random_bits = Random();
|
uint16_t new_random_bits = Random();
|
||||||
|
|
|
@ -40,7 +40,7 @@ struct VehicleScopeResolver : public ScopeResolver {
|
||||||
|
|
||||||
uint32_t GetRandomBits() const override;
|
uint32_t GetRandomBits() const override;
|
||||||
uint32_t GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const override;
|
uint32_t GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const override;
|
||||||
uint32_t GetTriggers() const override;
|
uint32_t GetRandomTriggers() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Resolver for a vehicle (chain) */
|
/** Resolver for a vehicle (chain) */
|
||||||
|
|
|
@ -226,10 +226,10 @@ void DecreaseBuildingCount(Town *t, HouseID house_id)
|
||||||
return this->not_yet_constructed ? this->initial_random_bits : GetHouseRandomBits(this->tile);
|
return this->not_yet_constructed ? this->initial_random_bits : GetHouseRandomBits(this->tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* virtual */ uint32_t HouseScopeResolver::GetTriggers() const
|
/* virtual */ uint32_t HouseScopeResolver::GetRandomTriggers() const
|
||||||
{
|
{
|
||||||
/* Note: Towns build houses over houses. So during construction checks 'tile' may be a valid but unrelated house. */
|
/* Note: Towns build houses over houses. So during construction checks 'tile' may be a valid but unrelated house. */
|
||||||
return this->not_yet_constructed ? 0 : GetHouseTriggers(this->tile);
|
return this->not_yet_constructed ? 0 : GetHouseRandomTriggers(this->tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t GetNumHouses(HouseID house_id, const Town *town)
|
static uint32_t GetNumHouses(HouseID house_id, const Town *town)
|
||||||
|
@ -631,14 +631,14 @@ static void DoTriggerHouseRandomisation(TileIndex tile, HouseTrigger trigger, ui
|
||||||
if (hs->grf_prop.GetSpriteGroup() == nullptr) return;
|
if (hs->grf_prop.GetSpriteGroup() == nullptr) return;
|
||||||
|
|
||||||
HouseResolverObject object(hid, tile, Town::GetByTile(tile), CBID_RANDOM_TRIGGER);
|
HouseResolverObject object(hid, tile, Town::GetByTile(tile), CBID_RANDOM_TRIGGER);
|
||||||
object.waiting_triggers = GetHouseTriggers(tile) | trigger;
|
object.waiting_random_triggers = GetHouseRandomTriggers(tile) | trigger;
|
||||||
SetHouseTriggers(tile, object.waiting_triggers); // store now for var 5F
|
SetHouseRandomTriggers(tile, object.waiting_random_triggers); // store now for var 5F
|
||||||
|
|
||||||
const SpriteGroup *group = object.Resolve();
|
const SpriteGroup *group = object.Resolve();
|
||||||
if (group == nullptr) return;
|
if (group == nullptr) return;
|
||||||
|
|
||||||
/* Store remaining triggers. */
|
/* Store remaining triggers. */
|
||||||
SetHouseTriggers(tile, object.GetRemainingTriggers());
|
SetHouseRandomTriggers(tile, object.GetRemainingRandomTriggers());
|
||||||
|
|
||||||
/* Rerandomise bits. Scopes other than SELF are invalid for houses. For bug-to-bug-compatibility with TTDP we ignore the scope. */
|
/* Rerandomise bits. Scopes other than SELF are invalid for houses. For bug-to-bug-compatibility with TTDP we ignore the scope. */
|
||||||
uint8_t new_random_bits = Random();
|
uint8_t new_random_bits = Random();
|
||||||
|
|
|
@ -45,7 +45,7 @@ struct HouseScopeResolver : public ScopeResolver {
|
||||||
|
|
||||||
uint32_t GetRandomBits() const override;
|
uint32_t GetRandomBits() const override;
|
||||||
uint32_t GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const override;
|
uint32_t GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const override;
|
||||||
uint32_t GetTriggers() const override;
|
uint32_t GetRandomTriggers() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Resolver object to be used for houses (feature 07 spritegroups). */
|
/** Resolver object to be used for houses (feature 07 spritegroups). */
|
||||||
|
|
|
@ -433,7 +433,7 @@ static uint32_t GetCountAndDistanceOfClosestInstance(uint8_t param_set_id, uint8
|
||||||
return this->industry != nullptr ? this->industry->random : 0;
|
return this->industry != nullptr ? this->industry->random : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* virtual */ uint32_t IndustriesScopeResolver::GetTriggers() const
|
/* virtual */ uint32_t IndustriesScopeResolver::GetRandomTriggers() const
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ struct IndustriesScopeResolver : public ScopeResolver {
|
||||||
|
|
||||||
uint32_t GetRandomBits() const override;
|
uint32_t GetRandomBits() const override;
|
||||||
uint32_t GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const override;
|
uint32_t GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const override;
|
||||||
uint32_t GetTriggers() const override;
|
uint32_t GetRandomTriggers() const override;
|
||||||
void StorePSA(uint pos, int32_t value) override;
|
void StorePSA(uint pos, int32_t value) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -110,12 +110,12 @@ uint32_t GetRelativePosition(TileIndex tile, TileIndex ind_tile)
|
||||||
return (this->industry->index != IndustryID::Invalid()) ? GetIndustryRandomBits(this->tile) : 0;
|
return (this->industry->index != IndustryID::Invalid()) ? GetIndustryRandomBits(this->tile) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* virtual */ uint32_t IndustryTileScopeResolver::GetTriggers() const
|
/* virtual */ uint32_t IndustryTileScopeResolver::GetRandomTriggers() const
|
||||||
{
|
{
|
||||||
assert(this->industry != nullptr && IsValidTile(this->tile));
|
assert(this->industry != nullptr && IsValidTile(this->tile));
|
||||||
assert(this->industry->index == IndustryID::Invalid() || IsTileType(this->tile, MP_INDUSTRY));
|
assert(this->industry->index == IndustryID::Invalid() || IsTileType(this->tile, MP_INDUSTRY));
|
||||||
if (this->industry->index == IndustryID::Invalid()) return 0;
|
if (this->industry->index == IndustryID::Invalid()) return 0;
|
||||||
return GetIndustryTriggers(this->tile);
|
return GetIndustryRandomTriggers(this->tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -320,14 +320,14 @@ static void DoTriggerIndustryTileRandomisation(TileIndex tile, IndustryTileTrigg
|
||||||
if (itspec->grf_prop.GetSpriteGroup() == nullptr) return;
|
if (itspec->grf_prop.GetSpriteGroup() == nullptr) return;
|
||||||
|
|
||||||
IndustryTileResolverObject object(gfx, tile, ind, CBID_RANDOM_TRIGGER);
|
IndustryTileResolverObject object(gfx, tile, ind, CBID_RANDOM_TRIGGER);
|
||||||
object.waiting_triggers = GetIndustryTriggers(tile) | trigger;
|
object.waiting_random_triggers = GetIndustryRandomTriggers(tile) | trigger;
|
||||||
SetIndustryTriggers(tile, object.waiting_triggers); // store now for var 5F
|
SetIndustryRandomTriggers(tile, object.waiting_random_triggers); // store now for var 5F
|
||||||
|
|
||||||
const SpriteGroup *group = object.Resolve();
|
const SpriteGroup *group = object.Resolve();
|
||||||
if (group == nullptr) return;
|
if (group == nullptr) return;
|
||||||
|
|
||||||
/* Store remaining triggers. */
|
/* Store remaining triggers. */
|
||||||
SetIndustryTriggers(tile, object.GetRemainingTriggers());
|
SetIndustryRandomTriggers(tile, object.GetRemainingRandomTriggers());
|
||||||
|
|
||||||
/* Rerandomise tile bits */
|
/* Rerandomise tile bits */
|
||||||
uint8_t new_random_bits = Random();
|
uint8_t new_random_bits = Random();
|
||||||
|
|
|
@ -32,7 +32,7 @@ struct IndustryTileScopeResolver : public ScopeResolver {
|
||||||
|
|
||||||
uint32_t GetRandomBits() const override;
|
uint32_t GetRandomBits() const override;
|
||||||
uint32_t GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const override;
|
uint32_t GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const override;
|
||||||
uint32_t GetTriggers() const override;
|
uint32_t GetRandomTriggers() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Resolver for industry tiles. */
|
/** Resolver for industry tiles. */
|
||||||
|
|
|
@ -63,9 +63,9 @@ uint32_t RoadStopScopeResolver::GetRandomBits() const
|
||||||
return bits;
|
return bits;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t RoadStopScopeResolver::GetTriggers() const
|
uint32_t RoadStopScopeResolver::GetRandomTriggers() const
|
||||||
{
|
{
|
||||||
return this->st == nullptr ? 0 : this->st->waiting_triggers;
|
return this->st == nullptr ? 0 : this->st->waiting_random_triggers;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t RoadStopScopeResolver::GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const
|
uint32_t RoadStopScopeResolver::GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const
|
||||||
|
@ -426,14 +426,14 @@ void TriggerRoadStopRandomisation(Station *st, TileIndex tile, RoadStopRandomTri
|
||||||
if (st->cached_roadstop_cargo_triggers == 0) return;
|
if (st->cached_roadstop_cargo_triggers == 0) return;
|
||||||
if (IsValidCargoType(cargo_type) && !HasBit(st->cached_roadstop_cargo_triggers, cargo_type)) return;
|
if (IsValidCargoType(cargo_type) && !HasBit(st->cached_roadstop_cargo_triggers, cargo_type)) return;
|
||||||
|
|
||||||
SetBit(st->waiting_triggers, trigger);
|
SetBit(st->waiting_random_triggers, trigger);
|
||||||
|
|
||||||
uint32_t whole_reseed = 0;
|
uint32_t whole_reseed = 0;
|
||||||
|
|
||||||
/* Bitmask of completely empty cargo types to be matched. */
|
/* Bitmask of completely empty cargo types to be matched. */
|
||||||
CargoTypes empty_mask = (trigger == RSRT_CARGO_TAKEN) ? GetEmptyMask(st) : 0;
|
CargoTypes empty_mask = (trigger == RSRT_CARGO_TAKEN) ? GetEmptyMask(st) : 0;
|
||||||
|
|
||||||
uint32_t used_triggers = 0;
|
uint32_t used_random_triggers = 0;
|
||||||
auto process_tile = [&](TileIndex cur_tile) {
|
auto process_tile = [&](TileIndex cur_tile) {
|
||||||
const RoadStopSpec *ss = GetRoadStopSpec(cur_tile);
|
const RoadStopSpec *ss = GetRoadStopSpec(cur_tile);
|
||||||
if (ss == nullptr) return;
|
if (ss == nullptr) return;
|
||||||
|
@ -446,12 +446,12 @@ void TriggerRoadStopRandomisation(Station *st, TileIndex tile, RoadStopRandomTri
|
||||||
|
|
||||||
if (!IsValidCargoType(cargo_type) || HasBit(ss->cargo_triggers, cargo_type)) {
|
if (!IsValidCargoType(cargo_type) || HasBit(ss->cargo_triggers, cargo_type)) {
|
||||||
RoadStopResolverObject object(ss, st, cur_tile, INVALID_ROADTYPE, GetStationType(cur_tile), GetStationGfx(cur_tile));
|
RoadStopResolverObject object(ss, st, cur_tile, INVALID_ROADTYPE, GetStationType(cur_tile), GetStationGfx(cur_tile));
|
||||||
object.waiting_triggers = st->waiting_triggers;
|
object.waiting_random_triggers = st->waiting_random_triggers;
|
||||||
|
|
||||||
const SpriteGroup *group = object.Resolve();
|
const SpriteGroup *group = object.Resolve();
|
||||||
if (group == nullptr) return;
|
if (group == nullptr) return;
|
||||||
|
|
||||||
used_triggers |= object.used_triggers;
|
used_random_triggers |= object.used_random_triggers;
|
||||||
|
|
||||||
uint32_t reseed = object.GetReseedSum();
|
uint32_t reseed = object.GetReseedSum();
|
||||||
if (reseed != 0) {
|
if (reseed != 0) {
|
||||||
|
@ -477,7 +477,7 @@ void TriggerRoadStopRandomisation(Station *st, TileIndex tile, RoadStopRandomTri
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update whole station random bits */
|
/* Update whole station random bits */
|
||||||
st->waiting_triggers &= ~used_triggers;
|
st->waiting_random_triggers &= ~used_random_triggers;
|
||||||
if ((whole_reseed & 0xFFFF) != 0) {
|
if ((whole_reseed & 0xFFFF) != 0) {
|
||||||
st->random_bits &= ~whole_reseed;
|
st->random_bits &= ~whole_reseed;
|
||||||
st->random_bits |= Random() & whole_reseed;
|
st->random_bits |= Random() & whole_reseed;
|
||||||
|
|
|
@ -103,7 +103,7 @@ struct RoadStopScopeResolver : public ScopeResolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t GetRandomBits() const override;
|
uint32_t GetRandomBits() const override;
|
||||||
uint32_t GetTriggers() const override;
|
uint32_t GetRandomTriggers() const override;
|
||||||
|
|
||||||
uint32_t GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const override;
|
uint32_t GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const override;
|
||||||
};
|
};
|
||||||
|
|
|
@ -62,7 +62,7 @@ static inline uint32_t GetVariable(const ResolverObject &object, ScopeResolver *
|
||||||
case 0x18: return object.callback_param2;
|
case 0x18: return object.callback_param2;
|
||||||
case 0x1C: return object.last_value;
|
case 0x1C: return object.last_value;
|
||||||
|
|
||||||
case 0x5F: return (scope->GetRandomBits() << 8) | scope->GetTriggers();
|
case 0x5F: return (scope->GetRandomBits() << 8) | scope->GetRandomTriggers();
|
||||||
|
|
||||||
case 0x7D: return _temp_store.GetValue(parameter);
|
case 0x7D: return _temp_store.GetValue(parameter);
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ static inline uint32_t GetVariable(const ResolverObject &object, ScopeResolver *
|
||||||
* Get the triggers. Base class returns \c 0 to prevent trouble.
|
* Get the triggers. Base class returns \c 0 to prevent trouble.
|
||||||
* @return The triggers.
|
* @return The triggers.
|
||||||
*/
|
*/
|
||||||
/* virtual */ uint32_t ScopeResolver::GetTriggers() const
|
/* virtual */ uint32_t ScopeResolver::GetRandomTriggers() const
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -258,11 +258,11 @@ const SpriteGroup *RandomizedSpriteGroup::Resolve(ResolverObject &object) const
|
||||||
ScopeResolver *scope = object.GetScope(this->var_scope, this->count);
|
ScopeResolver *scope = object.GetScope(this->var_scope, this->count);
|
||||||
if (object.callback == CBID_RANDOM_TRIGGER) {
|
if (object.callback == CBID_RANDOM_TRIGGER) {
|
||||||
/* Handle triggers */
|
/* Handle triggers */
|
||||||
uint8_t match = this->triggers & object.waiting_triggers;
|
uint8_t match = this->triggers & object.waiting_random_triggers;
|
||||||
bool res = (this->cmp_mode == RSG_CMP_ANY) ? (match != 0) : (match == this->triggers);
|
bool res = (this->cmp_mode == RSG_CMP_ANY) ? (match != 0) : (match == this->triggers);
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
object.used_triggers |= match;
|
object.used_random_triggers |= match;
|
||||||
object.reseed[this->var_scope] |= (this->groups.size() - 1) << this->lowest_randbit;
|
object.reseed[this->var_scope] |= (this->groups.size() - 1) << this->lowest_randbit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -282,7 +282,7 @@ struct ScopeResolver {
|
||||||
virtual ~ScopeResolver() = default;
|
virtual ~ScopeResolver() = default;
|
||||||
|
|
||||||
virtual uint32_t GetRandomBits() const;
|
virtual uint32_t GetRandomBits() const;
|
||||||
virtual uint32_t GetTriggers() const;
|
virtual uint32_t GetRandomTriggers() const;
|
||||||
|
|
||||||
virtual uint32_t GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const;
|
virtual uint32_t GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const;
|
||||||
virtual void StorePSA(uint reg, int32_t value);
|
virtual void StorePSA(uint reg, int32_t value);
|
||||||
|
@ -318,8 +318,8 @@ struct ResolverObject {
|
||||||
|
|
||||||
uint32_t last_value = 0; ///< Result of most recent DeterministicSpriteGroup (including procedure calls)
|
uint32_t last_value = 0; ///< Result of most recent DeterministicSpriteGroup (including procedure calls)
|
||||||
|
|
||||||
uint32_t waiting_triggers = 0; ///< Waiting triggers to be used by any rerandomisation. (scope independent)
|
uint32_t waiting_random_triggers = 0; ///< Waiting triggers to be used by any rerandomisation. (scope independent)
|
||||||
uint32_t used_triggers = 0; ///< Subset of cur_triggers, which actually triggered some rerandomisation. (scope independent)
|
uint32_t used_random_triggers = 0; ///< Subset of cur_triggers, which actually triggered some rerandomisation. (scope independent)
|
||||||
std::array<uint32_t, VSG_END> reseed; ///< Collects bits to rerandomise while triggering triggers.
|
std::array<uint32_t, VSG_END> reseed; ///< Collects bits to rerandomise while triggering triggers.
|
||||||
|
|
||||||
const GRFFile *grffile = nullptr; ///< GRFFile the resolved SpriteGroup belongs to
|
const GRFFile *grffile = nullptr; ///< GRFFile the resolved SpriteGroup belongs to
|
||||||
|
@ -351,9 +351,9 @@ struct ResolverObject {
|
||||||
/**
|
/**
|
||||||
* Returns the waiting triggers that did not trigger any rerandomisation.
|
* Returns the waiting triggers that did not trigger any rerandomisation.
|
||||||
*/
|
*/
|
||||||
uint32_t GetRemainingTriggers() const
|
uint32_t GetRemainingRandomTriggers() const
|
||||||
{
|
{
|
||||||
return this->waiting_triggers & ~this->used_triggers;
|
return this->waiting_random_triggers & ~this->used_random_triggers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -377,8 +377,8 @@ struct ResolverObject {
|
||||||
void ResetState()
|
void ResetState()
|
||||||
{
|
{
|
||||||
this->last_value = 0;
|
this->last_value = 0;
|
||||||
this->waiting_triggers = 0;
|
this->waiting_random_triggers = 0;
|
||||||
this->used_triggers = 0;
|
this->used_random_triggers = 0;
|
||||||
this->reseed.fill(0);
|
this->reseed.fill(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -244,9 +244,9 @@ static uint32_t GetRailContinuationInfo(TileIndex tile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* virtual */ uint32_t StationScopeResolver::GetTriggers() const
|
/* virtual */ uint32_t StationScopeResolver::GetRandomTriggers() const
|
||||||
{
|
{
|
||||||
return this->st == nullptr ? 0 : this->st->waiting_triggers;
|
return this->st == nullptr ? 0 : this->st->waiting_random_triggers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -965,8 +965,8 @@ void TriggerStationRandomisation(Station *st, TileIndex trigger_tile, StationRan
|
||||||
CargoTypes empty_mask = (trigger == SRT_CARGO_TAKEN) ? GetEmptyMask(st) : 0;
|
CargoTypes empty_mask = (trigger == SRT_CARGO_TAKEN) ? GetEmptyMask(st) : 0;
|
||||||
|
|
||||||
/* Store triggers now for var 5F */
|
/* Store triggers now for var 5F */
|
||||||
SetBit(st->waiting_triggers, trigger);
|
SetBit(st->waiting_random_triggers, trigger);
|
||||||
uint32_t used_triggers = 0;
|
uint32_t used_random_triggers = 0;
|
||||||
|
|
||||||
/* Check all tiles over the station to check if the specindex is still in use */
|
/* Check all tiles over the station to check if the specindex is still in use */
|
||||||
for (TileIndex tile : area) {
|
for (TileIndex tile : area) {
|
||||||
|
@ -982,12 +982,12 @@ void TriggerStationRandomisation(Station *st, TileIndex trigger_tile, StationRan
|
||||||
|
|
||||||
if (!IsValidCargoType(cargo_type) || HasBit(ss->cargo_triggers, cargo_type)) {
|
if (!IsValidCargoType(cargo_type) || HasBit(ss->cargo_triggers, cargo_type)) {
|
||||||
StationResolverObject object(ss, st, tile, CBID_RANDOM_TRIGGER, 0);
|
StationResolverObject object(ss, st, tile, CBID_RANDOM_TRIGGER, 0);
|
||||||
object.waiting_triggers = st->waiting_triggers;
|
object.waiting_random_triggers = st->waiting_random_triggers;
|
||||||
|
|
||||||
const SpriteGroup *group = object.Resolve();
|
const SpriteGroup *group = object.Resolve();
|
||||||
if (group == nullptr) continue;
|
if (group == nullptr) continue;
|
||||||
|
|
||||||
used_triggers |= object.used_triggers;
|
used_random_triggers |= object.used_random_triggers;
|
||||||
|
|
||||||
uint32_t reseed = object.GetReseedSum();
|
uint32_t reseed = object.GetReseedSum();
|
||||||
if (reseed != 0) {
|
if (reseed != 0) {
|
||||||
|
@ -1007,7 +1007,7 @@ void TriggerStationRandomisation(Station *st, TileIndex trigger_tile, StationRan
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update whole station random bits */
|
/* Update whole station random bits */
|
||||||
st->waiting_triggers &= ~used_triggers;
|
st->waiting_random_triggers &= ~used_random_triggers;
|
||||||
if ((whole_reseed & 0xFFFF) != 0) {
|
if ((whole_reseed & 0xFFFF) != 0) {
|
||||||
st->random_bits &= ~whole_reseed;
|
st->random_bits &= ~whole_reseed;
|
||||||
st->random_bits |= Random() & whole_reseed;
|
st->random_bits |= Random() & whole_reseed;
|
||||||
|
|
|
@ -43,7 +43,7 @@ struct StationScopeResolver : public ScopeResolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t GetRandomBits() const override;
|
uint32_t GetRandomBits() const override;
|
||||||
uint32_t GetTriggers() const override;
|
uint32_t GetRandomTriggers() const override;
|
||||||
|
|
||||||
uint32_t GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const override;
|
uint32_t GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const override;
|
||||||
};
|
};
|
||||||
|
|
|
@ -490,7 +490,7 @@ static const SaveLoad _old_station_desc[] = {
|
||||||
|
|
||||||
/* Used by newstations for graphic variations */
|
/* Used by newstations for graphic variations */
|
||||||
SLE_CONDVAR(Station, random_bits, SLE_UINT16, SLV_27, SL_MAX_VERSION),
|
SLE_CONDVAR(Station, random_bits, SLE_UINT16, SLV_27, SL_MAX_VERSION),
|
||||||
SLE_CONDVAR(Station, waiting_triggers, SLE_UINT8, SLV_27, SL_MAX_VERSION),
|
SLE_CONDVARNAME(Station, waiting_random_triggers, "waiting_triggers", SLE_UINT8, SLV_27, SL_MAX_VERSION),
|
||||||
SLEG_CONDVAR("num_specs", SlStationSpecList<StationSpec>::last_num_specs, SLE_UINT8, SLV_27, SL_MAX_VERSION),
|
SLEG_CONDVAR("num_specs", SlStationSpecList<StationSpec>::last_num_specs, SLE_UINT8, SLV_27, SL_MAX_VERSION),
|
||||||
|
|
||||||
SLE_CONDREFLIST(Station, loading_vehicles, REF_VEHICLE, SLV_57, SL_MAX_VERSION),
|
SLE_CONDREFLIST(Station, loading_vehicles, REF_VEHICLE, SLV_57, SL_MAX_VERSION),
|
||||||
|
@ -562,7 +562,7 @@ public:
|
||||||
|
|
||||||
/* Used by newstations for graphic variations */
|
/* Used by newstations for graphic variations */
|
||||||
SLE_VAR(BaseStation, random_bits, SLE_UINT16),
|
SLE_VAR(BaseStation, random_bits, SLE_UINT16),
|
||||||
SLE_VAR(BaseStation, waiting_triggers, SLE_UINT8),
|
SLE_VARNAME(BaseStation, waiting_random_triggers, "waiting_triggers", SLE_UINT8),
|
||||||
SLEG_CONDVAR("num_specs", SlStationSpecList<StationSpec>::last_num_specs, SLE_UINT8, SL_MIN_VERSION, SLV_SAVELOAD_LIST_LENGTH),
|
SLEG_CONDVAR("num_specs", SlStationSpecList<StationSpec>::last_num_specs, SLE_UINT8, SL_MIN_VERSION, SLV_SAVELOAD_LIST_LENGTH),
|
||||||
};
|
};
|
||||||
inline const static SaveLoadCompatTable compat_description = _station_base_sl_compat;
|
inline const static SaveLoadCompatTable compat_description = _station_base_sl_compat;
|
||||||
|
|
|
@ -754,7 +754,7 @@ public:
|
||||||
|
|
||||||
SLE_CONDVAR(Vehicle, random_bits, SLE_FILE_U8 | SLE_VAR_U16, SLV_2, SLV_EXTEND_VEHICLE_RANDOM),
|
SLE_CONDVAR(Vehicle, random_bits, SLE_FILE_U8 | SLE_VAR_U16, SLV_2, SLV_EXTEND_VEHICLE_RANDOM),
|
||||||
SLE_CONDVAR(Vehicle, random_bits, SLE_UINT16, SLV_EXTEND_VEHICLE_RANDOM, SL_MAX_VERSION),
|
SLE_CONDVAR(Vehicle, random_bits, SLE_UINT16, SLV_EXTEND_VEHICLE_RANDOM, SL_MAX_VERSION),
|
||||||
SLE_CONDVAR(Vehicle, waiting_triggers, SLE_UINT8, SLV_2, SL_MAX_VERSION),
|
SLE_CONDVARNAME(Vehicle, waiting_random_triggers, "waiting_triggers", SLE_UINT8, SLV_2, SL_MAX_VERSION),
|
||||||
|
|
||||||
SLE_CONDREF(Vehicle, next_shared, REF_VEHICLE, SLV_2, SL_MAX_VERSION),
|
SLE_CONDREF(Vehicle, next_shared, REF_VEHICLE, SLV_2, SL_MAX_VERSION),
|
||||||
SLE_CONDVAR(Vehicle, group_id, SLE_UINT16, SLV_60, SL_MAX_VERSION),
|
SLE_CONDVAR(Vehicle, group_id, SLE_UINT16, SLV_60, SL_MAX_VERSION),
|
||||||
|
|
|
@ -307,7 +307,7 @@ inline uint8_t GetHouseRandomBits(Tile t)
|
||||||
* @param triggers the activated triggers
|
* @param triggers the activated triggers
|
||||||
* @pre IsTileType(t, MP_HOUSE)
|
* @pre IsTileType(t, MP_HOUSE)
|
||||||
*/
|
*/
|
||||||
inline void SetHouseTriggers(Tile t, uint8_t triggers)
|
inline void SetHouseRandomTriggers(Tile t, uint8_t triggers)
|
||||||
{
|
{
|
||||||
assert(IsTileType(t, MP_HOUSE));
|
assert(IsTileType(t, MP_HOUSE));
|
||||||
SB(t.m3(), 0, 5, triggers);
|
SB(t.m3(), 0, 5, triggers);
|
||||||
|
@ -320,7 +320,7 @@ inline void SetHouseTriggers(Tile t, uint8_t triggers)
|
||||||
* @pre IsTileType(t, MP_HOUSE)
|
* @pre IsTileType(t, MP_HOUSE)
|
||||||
* @return triggers
|
* @return triggers
|
||||||
*/
|
*/
|
||||||
inline uint8_t GetHouseTriggers(Tile t)
|
inline uint8_t GetHouseRandomTriggers(Tile t)
|
||||||
{
|
{
|
||||||
assert(IsTileType(t, MP_HOUSE));
|
assert(IsTileType(t, MP_HOUSE));
|
||||||
return GB(t.m3(), 0, 5);
|
return GB(t.m3(), 0, 5);
|
||||||
|
|
|
@ -311,7 +311,7 @@ public:
|
||||||
uint32_t motion_counter = 0; ///< counter to occasionally play a vehicle sound.
|
uint32_t motion_counter = 0; ///< counter to occasionally play a vehicle sound.
|
||||||
uint8_t progress = 0; ///< The percentage (if divided by 256) this vehicle already crossed the tile unit.
|
uint8_t progress = 0; ///< The percentage (if divided by 256) this vehicle already crossed the tile unit.
|
||||||
|
|
||||||
uint8_t waiting_triggers = 0; ///< Triggers to be yet matched before rerandomizing the random bits.
|
uint8_t waiting_random_triggers = 0; ///< Triggers to be yet matched before rerandomizing the random bits.
|
||||||
uint16_t random_bits = 0; ///< Bits used for randomized variational spritegroups.
|
uint16_t random_bits = 0; ///< Bits used for randomized variational spritegroups.
|
||||||
|
|
||||||
StationID last_station_visited = StationID::Invalid(); ///< The last station we stopped at.
|
StationID last_station_visited = StationID::Invalid(); ///< The last station we stopped at.
|
||||||
|
|
Loading…
Reference in New Issue