1
0
mirror of https://github.com/OpenTTD/OpenTTD.git synced 2025-08-12 09:09:09 +00:00

(svn r27928) -Fix: [NewGRF] While executing random triggers, var 5F should include the new triggers.

-Fix: [NewGRF] Reset used random triggers only after all A123 chains have been resolved, so that all RA2 in all chains can test the shard triggers. This also includes multiple RA2 in the same A123 chain.
-Fix: [NewGRF] Industry random triggers are stored per tile, even when randomising the shared random bits of the parent industry.
This commit is contained in:
frosch
2017-10-25 15:38:14 +00:00
parent 146e4eddb6
commit 82ae414e8d
12 changed files with 43 additions and 72 deletions

View File

@@ -347,21 +347,6 @@ static byte MapAircraftMovementAction(const Aircraft *v)
return this->v == NULL ? 0 : this->v->waiting_triggers;
}
/* virtual */ void VehicleScopeResolver::SetTriggers(int triggers) const
{
/* Evil cast to get around const-ness. This used to be achieved by an
* innocent looking function pointer cast... Currently I cannot see a
* way of avoiding this without removing consts deep within gui code.
*/
Vehicle *v = const_cast<Vehicle *>(this->v);
/* This function must only be called when processing triggers -- any
* other time is an error. */
assert(this->ro.trigger != 0);
if (v != NULL) v->waiting_triggers = triggers;
}
/* virtual */ ScopeResolver *VehicleResolverObject::GetScope(VarSpriteGroupScope scope, byte relative)
{
@@ -1140,13 +1125,18 @@ static void DoTriggerVehicle(Vehicle *v, VehicleTrigger trigger, byte base_rando
assert(v != NULL);
VehicleResolverObject object(v->engine_type, v, VehicleResolverObject::WO_CACHED, false, CBID_RANDOM_TRIGGER);
object.trigger = trigger;
object.waiting_triggers = v->waiting_triggers | trigger;
v->waiting_triggers = object.waiting_triggers; // store now for var 5F
const SpriteGroup *group = object.Resolve();
if (group == NULL) return;
/* Store remaining triggers. */
v->waiting_triggers = object.GetRemainingTriggers();
/* Rerandomise bits. Scopes other than SELF are invalid for rerandomisation. For bug-to-bug-compatibility with TTDP we ignore the scope. */
byte new_random_bits = Random();
uint32 reseed = object.GetReseedSum(); // The scope only affects triggers, not the reseeding
uint32 reseed = object.GetReseedSum();
v->random_bits &= ~reseed;
v->random_bits |= (first ? new_random_bits : base_random_bits) & reseed;