Skip to content

Commit db3416b

Browse files
authored
tweak(behavior): Make aircraft takeoff order deterministic (#1297)
1 parent 9e4d4a2 commit db3416b

File tree

4 files changed

+90
-24
lines changed

4 files changed

+90
-24
lines changed

Generals/Code/GameEngine/Include/GameLogic/Module/ParkingPlaceBehavior.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class ParkingPlaceBehavior : public UpdateModule,
130130
Bool reserveSpace(ObjectID id, Real parkingOffset, PPInfo* info);
131131
void releaseSpace(ObjectID id);
132132
Bool reserveRunway(ObjectID id, Bool forLanding);
133+
Bool postponeRunwayReservation(UnsignedInt spaceIndex, Bool forLanding);
133134
void releaseRunway(ObjectID id);
134135
Int getRunwayCount() const { return m_runways.size(); }
135136
ObjectID getRunwayReservation(Int r);
@@ -143,15 +144,16 @@ class ParkingPlaceBehavior : public UpdateModule,
143144

144145
struct ParkingPlaceInfo
145146
{
146-
Coord3D m_hangarStart;
147-
Real m_hangarStartOrient;
148-
Coord3D m_location;
149-
Coord3D m_prep;
150-
Real m_orientation;
151-
Int m_runway;
152-
ExitDoorType m_door;
153-
ObjectID m_objectInSpace;
154-
Bool m_reservedForExit;
147+
Coord3D m_hangarStart;
148+
Real m_hangarStartOrient;
149+
Coord3D m_location;
150+
Coord3D m_prep;
151+
Real m_orientation;
152+
Int m_runway;
153+
ExitDoorType m_door;
154+
ObjectID m_objectInSpace;
155+
Bool m_reservedForExit;
156+
Bool m_postponedRunwayReservationForTakeoff;
155157

156158
ParkingPlaceInfo()
157159
{
@@ -164,6 +166,7 @@ class ParkingPlaceBehavior : public UpdateModule,
164166
m_door = DOOR_NONE_AVAILABLE;
165167
m_objectInSpace = INVALID_ID;
166168
m_reservedForExit = false;
169+
m_postponedRunwayReservationForTakeoff = false;
167170
}
168171
};
169172

Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/ParkingPlaceBehavior.cpp

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ void ParkingPlaceBehavior::purgeDead()
159159
{
160160
it->m_objectInSpace = INVALID_ID;
161161
it->m_reservedForExit = false;
162+
it->m_postponedRunwayReservationForTakeoff = false;
162163
if (pu)
163164
pu->setHoldDoorOpen(it->m_door, false);
164165
}
@@ -379,6 +380,7 @@ void ParkingPlaceBehavior::releaseSpace(ObjectID id)
379380
{
380381
it->m_objectInSpace = INVALID_ID;
381382
it->m_reservedForExit = false;
383+
it->m_postponedRunwayReservationForTakeoff = false;
382384
if (pu)
383385
pu->setHoldDoorOpen(it->m_door, false);
384386
}
@@ -409,18 +411,46 @@ void ParkingPlaceBehavior::transferRunwayReservationToNextInLineForTakeoff(Objec
409411
}
410412
}
411413

414+
//-------------------------------------------------------------------------------------------------
415+
Bool ParkingPlaceBehavior::postponeRunwayReservation(UnsignedInt spaceIndex, Bool forLanding)
416+
{
417+
// TheSuperHackers @tweak Block the first attempt to reserve a runway for 'upper' space indices.
418+
// This allows 'lower' space indices to reserve a runway first to ensure deterministic takeoff ordering.
419+
420+
if (m_spaces.size() > m_runways.size() && spaceIndex >= m_runways.size())
421+
{
422+
Bool& postponed = m_spaces[spaceIndex].m_postponedRunwayReservationForTakeoff;
423+
if (forLanding)
424+
{
425+
postponed = false;
426+
}
427+
else if (!postponed)
428+
{
429+
postponed = true;
430+
return true;
431+
}
432+
}
433+
434+
return false;
435+
}
436+
412437
//-------------------------------------------------------------------------------------------------
413438
Bool ParkingPlaceBehavior::reserveRunway(ObjectID id, Bool forLanding)
414439
{
415440
buildInfo();
416441
purgeDead();
417442

418443
Int runway = -1;
419-
for (std::vector<ParkingPlaceInfo>::iterator it = m_spaces.begin(); it != m_spaces.end(); ++it)
444+
for (UnsignedInt i = 0; i < m_spaces.size(); ++i)
420445
{
421-
if (it->m_objectInSpace == id)
446+
if (m_spaces[i].m_objectInSpace == id)
422447
{
423-
runway = it->m_runway;
448+
#if !RETAIL_COMPATIBLE_CRC
449+
if (postponeRunwayReservation(i, forLanding))
450+
return false;
451+
#endif
452+
453+
runway = m_spaces[i].m_runway;
424454
break;
425455
}
426456
}

GeneralsMD/Code/GameEngine/Include/GameLogic/Module/ParkingPlaceBehavior.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ class ParkingPlaceBehavior : public UpdateModule,
140140
virtual Bool reserveSpace(ObjectID id, Real parkingOffset, PPInfo* info);
141141
virtual void releaseSpace(ObjectID id);
142142
virtual Bool reserveRunway(ObjectID id, Bool forLanding);
143+
Bool postponeRunwayReservation(UnsignedInt spaceIndex, Bool forLanding);
143144
virtual void releaseRunway(ObjectID id);
144145
virtual void calcPPInfo( ObjectID id, PPInfo *info );
145146
virtual Int getRunwayCount() const { return m_runways.size(); }
@@ -158,15 +159,16 @@ class ParkingPlaceBehavior : public UpdateModule,
158159

159160
struct ParkingPlaceInfo
160161
{
161-
Coord3D m_hangarStart;
162-
Real m_hangarStartOrient;
163-
Coord3D m_location;
164-
Coord3D m_prep;
165-
Real m_orientation;
166-
Int m_runway;
167-
ExitDoorType m_door;
168-
ObjectID m_objectInSpace;
169-
Bool m_reservedForExit;
162+
Coord3D m_hangarStart;
163+
Real m_hangarStartOrient;
164+
Coord3D m_location;
165+
Coord3D m_prep;
166+
Real m_orientation;
167+
Int m_runway;
168+
ExitDoorType m_door;
169+
ObjectID m_objectInSpace;
170+
Bool m_reservedForExit;
171+
Bool m_postponedRunwayReservationForTakeoff;
170172

171173
ParkingPlaceInfo()
172174
{
@@ -179,6 +181,7 @@ class ParkingPlaceBehavior : public UpdateModule,
179181
m_door = DOOR_NONE_AVAILABLE;
180182
m_objectInSpace = INVALID_ID;
181183
m_reservedForExit = false;
184+
m_postponedRunwayReservationForTakeoff = false;
182185
}
183186
};
184187

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/ParkingPlaceBehavior.cpp

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ void ParkingPlaceBehavior::purgeDead()
159159
{
160160
it->m_objectInSpace = INVALID_ID;
161161
it->m_reservedForExit = false;
162+
it->m_postponedRunwayReservationForTakeoff = false;
162163
if (pu)
163164
pu->setHoldDoorOpen(it->m_door, false);
164165
}
@@ -430,6 +431,7 @@ void ParkingPlaceBehavior::releaseSpace(ObjectID id)
430431
{
431432
it->m_objectInSpace = INVALID_ID;
432433
it->m_reservedForExit = false;
434+
it->m_postponedRunwayReservationForTakeoff = false;
433435
if (pu)
434436
pu->setHoldDoorOpen(it->m_door, false);
435437
}
@@ -468,18 +470,46 @@ void ParkingPlaceBehavior::transferRunwayReservationToNextInLineForTakeoff(Objec
468470
}
469471
}
470472

473+
//-------------------------------------------------------------------------------------------------
474+
Bool ParkingPlaceBehavior::postponeRunwayReservation(UnsignedInt spaceIndex, Bool forLanding)
475+
{
476+
// TheSuperHackers @tweak Block the first attempt to reserve a runway for 'upper' space indices.
477+
// This allows 'lower' space indices to reserve a runway first to ensure deterministic takeoff ordering.
478+
479+
if (m_spaces.size() > m_runways.size() && spaceIndex >= m_runways.size())
480+
{
481+
Bool& postponed = m_spaces[spaceIndex].m_postponedRunwayReservationForTakeoff;
482+
if (forLanding)
483+
{
484+
postponed = false;
485+
}
486+
else if (!postponed)
487+
{
488+
postponed = true;
489+
return true;
490+
}
491+
}
492+
493+
return false;
494+
}
495+
471496
//-------------------------------------------------------------------------------------------------
472497
Bool ParkingPlaceBehavior::reserveRunway(ObjectID id, Bool forLanding)
473498
{
474499
buildInfo();
475500
purgeDead();
476501

477502
Int runway = -1;
478-
for (std::vector<ParkingPlaceInfo>::iterator it = m_spaces.begin(); it != m_spaces.end(); ++it)
503+
for (UnsignedInt i = 0; i < m_spaces.size(); ++i)
479504
{
480-
if (it->m_objectInSpace == id)
505+
if (m_spaces[i].m_objectInSpace == id)
481506
{
482-
runway = it->m_runway;
507+
#if !RETAIL_COMPATIBLE_CRC
508+
if (postponeRunwayReservation(i, forLanding))
509+
return false;
510+
#endif
511+
512+
runway = m_spaces[i].m_runway;
483513
break;
484514
}
485515
}

0 commit comments

Comments
 (0)