forked from electronicarts/CnC_Generals_Zero_Hour
-
Notifications
You must be signed in to change notification settings - Fork 180
Expand file tree
/
Copy pathTransportContain.cpp
More file actions
712 lines (586 loc) · 25.1 KB
/
TransportContain.cpp
File metadata and controls
712 lines (586 loc) · 25.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
/*
** Command & Conquer Generals Zero Hour(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
////////////////////////////////////////////////////////////////////////////////
// //
// (c) 2001-2003 Electronic Arts Inc. //
// //
////////////////////////////////////////////////////////////////////////////////
// FILE: TransportContain.cpp //////////////////////////////////////////////////////////////////////
// Author: Steven Johnson, March 2002
// Desc: Contain module for transport units.
///////////////////////////////////////////////////////////////////////////////////////////////////
// USER INCLUDES //////////////////////////////////////////////////////////////////////////////////
#include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine
#include "Common/Player.h"
#include "Common/ThingTemplate.h"
#include "Common/ThingFactory.h"
#include "Common/Xfer.h"
#include "GameClient/Drawable.h"
#include "GameLogic/AI.h"
#include "GameLogic/AIPathfind.h"
#include "GameLogic/Locomotor.h"
#include "GameLogic/Module/AIUpdate.h"
#include "GameLogic/Module/BodyModule.h"
#include "GameLogic/Module/PhysicsUpdate.h"
#include "GameLogic/Module/StealthUpdate.h"
#include "GameLogic/Module/TransportContain.h"
#include "GameLogic/Object.h"
#include "GameLogic/Weapon.h"
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
TransportContainModuleData::TransportContainModuleData()
{
m_slotCapacity = 0;
m_scatterNearbyOnExit = true;
m_orientLikeContainerOnExit = false;
m_keepContainerVelocityOnExit = false;
m_goAggressiveOnExit = FALSE;
m_armedRidersUpgradeWeaponSet = FALSE;
m_resetMoodCheckTimeOnExit = true;
m_destroyRidersWhoAreNotFreeToExit = false;
m_exitPitchRate = 0.0f;
m_initialPayload.count = 0;
m_healthRegen = 0.0f;
m_exitDelay = 0;
m_isDelayExitInAir = FALSE;
//
// by default we say that transports can have infantry inside them, this will be totally
// overwritten by any data provided from the INI entry tho
//
m_allowInsideKindOf = MAKE_KINDOF_MASK( KINDOF_INFANTRY );
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
void TransportContainModuleData::parseInitialPayload( INI* ini, void *instance, void *store, const void* /*userData*/ )
{
TransportContainModuleData* self = (TransportContainModuleData*)instance;
const char* name = ini->getNextToken();
const char* countStr = ini->getNextTokenOrNull();
Int count = countStr ? INI::scanInt(countStr) : 1;
self->m_initialPayload.name.set(name);
self->m_initialPayload.count = count;
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
void TransportContainModuleData::buildFieldParse(MultiIniFieldParse& p)
{
OpenContainModuleData::buildFieldParse(p);
static const FieldParse dataFieldParse[] =
{
{ "Slots", INI::parseInt, nullptr, offsetof( TransportContainModuleData, m_slotCapacity ) },
{ "ScatterNearbyOnExit", INI::parseBool, nullptr, offsetof( TransportContainModuleData, m_scatterNearbyOnExit ) },
{ "OrientLikeContainerOnExit", INI::parseBool, nullptr, offsetof( TransportContainModuleData, m_orientLikeContainerOnExit ) },
{ "KeepContainerVelocityOnExit", INI::parseBool, nullptr, offsetof( TransportContainModuleData, m_keepContainerVelocityOnExit ) },
{ "GoAggressiveOnExit", INI::parseBool, nullptr, offsetof( TransportContainModuleData, m_goAggressiveOnExit ) },
{ "ResetMoodCheckTimeOnExit", INI::parseBool, nullptr, offsetof( TransportContainModuleData, m_resetMoodCheckTimeOnExit ) },
{ "DestroyRidersWhoAreNotFreeToExit", INI::parseBool, nullptr, offsetof( TransportContainModuleData, m_destroyRidersWhoAreNotFreeToExit ) },
{ "ExitBone", INI::parseAsciiString, nullptr, offsetof( TransportContainModuleData, m_exitBone ) },
{ "ExitPitchRate", INI::parseAngularVelocityReal, nullptr, offsetof( TransportContainModuleData, m_exitPitchRate ) },
{ "InitialPayload", parseInitialPayload, nullptr, 0 },
{ "HealthRegen%PerSec", INI::parseReal, nullptr, offsetof( TransportContainModuleData, m_healthRegen ) },
{ "ExitDelay", INI::parseDurationUnsignedInt, nullptr, offsetof( TransportContainModuleData, m_exitDelay ) },
{ "ArmedRidersUpgradeMyWeaponSet", INI::parseBool, nullptr, offsetof( TransportContainModuleData, m_armedRidersUpgradeWeaponSet ) },
{ "DelayExitInAir", INI::parseBool, nullptr, offsetof( TransportContainModuleData, m_isDelayExitInAir ) },
{ nullptr, nullptr, nullptr, 0 }
};
p.add(dataFieldParse);
}
// PRIVATE ////////////////////////////////////////////////////////////////////////////////////////
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
Int TransportContain::getContainMax() const
{
if (getTransportContainModuleData())
return getTransportContainModuleData()->m_slotCapacity;
return 0;
}
// PUBLIC /////////////////////////////////////////////////////////////////////////////////////////
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
TransportContain::TransportContain( Thing *thing, const ModuleData *moduleData ) :
OpenContain( thing, moduleData )
{
m_extraSlotsInUse = 0;
m_frameExitNotBusy = 0;
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
TransportContain::~TransportContain()
{
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
/**
can this container contain this kind of object?
and, if checkCapacity is TRUE, does this container have enough space left to hold the given unit?
*/
Bool TransportContain::isValidContainerFor(const Object* rider, Bool checkCapacity) const
{
// sanity
if (!rider)
return false;
// The point of this new code is to determine when something is a "fake" container, to
// look at the object inside of it to use that as the valid check. There is a case, when a
// paratrooper (an infantry contained in a parachute). In this case, when we pass this object
// to contain in a transport plane, we want to check the infantry, not the parachute.
if (rider->getContain() && rider->getContain()->isSpecialZeroSlotContainer())
{
// Report the first thing inside it!
const ContainedItemsList *items = rider->getContain()->getContainedItemsList();
if (items && !items->empty())
{
if (items->front())
{
// Replace the object we are checking with the *first* object contained within it.
rider = items->front();
}
}
}
// extend functionality
if( OpenContain::isValidContainerFor( rider, checkCapacity ) == false )
return false;
// // only allied objects can be transported.
// // order matters: we want to know if I consider it to be an ally, not vice versa
// if (getObject()->getRelationship(rider) != ALLIES)
// return false;
// no... actually, only OUR OWN units can be transported.
if (rider->getControllingPlayer() != getObject()->getControllingPlayer())
return false;
Int transportSlotCount = rider->getTransportSlotCount();
// if 0, this object isn't transportable.
if (transportSlotCount == 0)
return false;
if (checkCapacity)
{
Int containMax = getContainMax();
Int containCount = getContainCount();
return (m_extraSlotsInUse + containCount + transportSlotCount <= containMax);
}
else
{
return true;
}
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
void TransportContain::letRidersUpgradeWeaponSet()
{
const TransportContainModuleData * d = getTransportContainModuleData();
if ( ! d->m_armedRidersUpgradeWeaponSet )
return;
Object *self = getObject();
if ( self == nullptr )
return;
Bool anyRiderHasViableWeapon = FALSE;
const ContainedItemsList* riderList = getContainedItemsList();
if( riderList )
{
ContainedItemsList::const_iterator it;
it = riderList->begin();
while( it != riderList->end() )
{
Object *rider = *it;
//Advance to the next iterator
it++;
if ( rider )
{
if(rider->isKindOf(KINDOF_INFANTRY) == false)
continue;
Weapon *weapon = nullptr;
for ( Int w = PRIMARY_WEAPON; w < WEAPONSLOT_COUNT; ++ w )
{
weapon = rider->getWeaponInWeaponSlot( (WeaponSlotType)w );
if ( weapon )
{
if ( weapon->getTemplate()->isContactWeapon() == FALSE && weapon->isDamageWeapon() == TRUE ) // THIS MAY NEED TO CHECK MORE WEAPON ATTRIBUTES TO WORK BEST
{
anyRiderHasViableWeapon = TRUE;
break;
}
}
}
}
}
}
if ( anyRiderHasViableWeapon )
self->setWeaponSetFlag( WEAPONSET_PLAYER_UPGRADE );
else
self->clearWeaponSetFlag( WEAPONSET_PLAYER_UPGRADE );
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
void TransportContain::onContaining( Object *rider, Bool wasSelected )
{
OpenContain::onContaining( rider, wasSelected );
// objects inside a transport are held
rider->setDisabled( DISABLED_HELD );
Int transportSlotCount = rider->getTransportSlotCount();
DEBUG_ASSERTCRASH(transportSlotCount > 0, ("Hmm, this object isnt transportable"));
m_extraSlotsInUse += transportSlotCount - 1;
DEBUG_ASSERTCRASH(m_extraSlotsInUse >= 0 && m_extraSlotsInUse + getContainCount() <= getContainMax(), ("Hmm, bad slot count"));
//
// when we go from holding nothing to holding something we have a model condition
// to visually show the change
//
if( getContainCount() == 1 )
{
Drawable *draw = getObject()->getDrawable();
if( draw )
draw->setModelConditionState( MODELCONDITION_LOADED );
}
if ( getTransportContainModuleData()->m_armedRidersUpgradeWeaponSet )
letRidersUpgradeWeaponSet();
//Kris: October 20, 2003 - Patch 1.01
//Force Jarmen Kell to transfer weapon timer for snipe to and from the combat bike.
if( getObject()->isKindOf( KINDOF_CLIFF_JUMPER ) && rider->isKindOf( KINDOF_HERO ) && rider->isKindOf( KINDOF_SALVAGER ) )
{
//Admittedly brutal hack, but considering the state of the game (post-ship), this is a particularly surgical fix.
Weapon *bikeWeapon = getObject()->getWeaponInWeaponSlot( SECONDARY_WEAPON );
Weapon *riderWeapon = rider->getWeaponInWeaponSlot( SECONDARY_WEAPON );
if( bikeWeapon && riderWeapon )
{
//Transfer the reload time from the rider to the bike
bikeWeapon->transferNextShotStatsFrom( *riderWeapon );
}
}
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
void TransportContain::onRemoving( Object *rider )
{
OpenContain::onRemoving(rider);
// object is no longer held inside a transport
rider->clearDisabled( DISABLED_HELD );
const TransportContainModuleData* d = getTransportContainModuleData();
if (!d->m_exitBone.isEmpty())
{
Drawable* draw = getObject()->getDrawable();
if (draw)
{
Coord3D bonePos, worldPos;
if (draw->getPristineBonePositions(d->m_exitBone.str(), 0, &bonePos, nullptr, 1) == 1)
{
getObject()->convertBonePosToWorldPos(&bonePos, nullptr, &worldPos, nullptr);
rider->setPosition(&worldPos);
}
}
}
if (d->m_orientLikeContainerOnExit)
{
rider->setOrientation(getObject()->getOrientation());
}
if (d->m_keepContainerVelocityOnExit)
{
PhysicsBehavior* parent = getObject()->getPhysics();
PhysicsBehavior* child = rider->getPhysics();
if (parent && child)
{
Coord3D startingForce = *parent->getVelocity();
Real mass = child->getMass();
startingForce.x *= mass;
startingForce.y *= mass;
startingForce.z *= mass;
child->applyMotiveForce( &startingForce );
Real pitchRate = child->getCenterOfMassOffset() * d->m_exitPitchRate;
child->setPitchRate( pitchRate );
}
}
Int transportSlotCount = rider->getTransportSlotCount();
DEBUG_ASSERTCRASH(transportSlotCount > 0, ("Hmm, this object isnt transportable"));
m_extraSlotsInUse -= transportSlotCount - 1;
DEBUG_ASSERTCRASH(m_extraSlotsInUse >= 0 && m_extraSlotsInUse + getContainCount() <= getContainMax(), ("Hmm, bad slot count"));
// when we are empty again, clear the model condition for loaded
if( getContainCount() == 0 )
{
Drawable *draw = getObject()->getDrawable();
if( draw )
draw->clearModelConditionState( MODELCONDITION_LOADED );
}
if (getObject()->isAboveTerrain())
{
// temporarily mark the guy as being allowed to fall
// (overriding his locomotor's stick-to-ground attribute).
// this will be reset (by PhysicsBehavior) when he touches the ground.
PhysicsBehavior* physics = rider->getPhysics();
if (physics)
physics->setAllowToFall(true);
}
// AI might need help using this transport in a good way. Make the passengers aggressive.
//There is no computer player check since Aggressive only means something for computer players anyway
if( d->m_goAggressiveOnExit && rider->getAI() )
{
rider->getAI()->setAttitude( ATTITUDE_AGGRESSIVE );
}
if (getObject()->isEffectivelyDead()) {
scatterToNearbyPosition(rider);
}
if( d->m_resetMoodCheckTimeOnExit && rider->getAI() )
{
rider->getAI()->wakeUpAndAttemptToTarget();
}
m_frameExitNotBusy = TheGameLogic->getFrame() + d->m_exitDelay;
if ( d->m_armedRidersUpgradeWeaponSet )
letRidersUpgradeWeaponSet();
//Kris: October 20, 2003 - Patch 1.01
//Force Jarmen Kell to transfer weapon timer for snipe to and from the combat bike.
if( getObject()->isKindOf( KINDOF_CLIFF_JUMPER ) && rider->isKindOf( KINDOF_HERO ) && rider->isKindOf( KINDOF_SALVAGER ) )
{
//Admittedly brutal hack, but considering the state of the game (post-ship), this is a particularly surgical fix.
Weapon *bikeWeapon = getObject()->getWeaponInWeaponSlot( SECONDARY_WEAPON );
Weapon *riderWeapon = rider->getWeaponInWeaponSlot( SECONDARY_WEAPON );
if( bikeWeapon && riderWeapon )
{
//Transfer the reload time from the bike to the rider
riderWeapon->transferNextShotStatsFrom( *bikeWeapon );
}
}
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
void TransportContain::createPayload()
{
TransportContainModuleData* self = (TransportContainModuleData*)getTransportContainModuleData();
Int count = self->m_initialPayload.count;
const ThingTemplate* payloadTemplate = TheThingFactory->findTemplate( self->m_initialPayload.name );
Object* object = getObject();
ContainModuleInterface *contain = object->getContain();
if( contain )
{
contain->enableLoadSounds( FALSE );
for( int i = 0; i < count; i++ )
{
//We are creating a transport that comes with a initial payload, so add it now!
Object* payload = TheThingFactory->newObject( payloadTemplate, object->getControllingPlayer()->getDefaultTeam() );
if( contain->isValidContainerFor( payload, true ) )
{
contain->addToContain( payload );
}
else
{
DEBUG_CRASH( ( "DeliverPayload: PutInContainer %s is full, or not valid for the payload %s!", object->getName().str(), self->m_initialPayload.name.str() ) );
}
}
contain->enableLoadSounds( TRUE );
}
m_payloadCreated = TRUE;
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
UpdateSleepTime TransportContain::update()
{
const TransportContainModuleData *moduleData = getTransportContainModuleData();
if( m_payloadCreated == FALSE )
createPayload();
if( moduleData && moduleData->m_healthRegen )
{
ContainModuleInterface *contain = getObject()->getContain();
if( contain )
{
//This transport has a health regeneration value, so go through and heal all inside.
const ContainedItemsList* items = contain->getContainedItemsList();
if( items )
{
ContainedItemsList::const_iterator it;
it = items->begin();
while( it != items->end() )
{
Object *object = *it;
//Advance to the next iterator
it++;
//Determine if we need healing or not.
BodyModuleInterface *body = object->getBodyModule();
if( body->getHealth() < body->getMaxHealth() )
{
//Calculate the health to be regenerated on each unit.
Real regen = body->getMaxHealth() * moduleData->m_healthRegen / 100.0f * SECONDS_PER_LOGICFRAME_REAL;
//Perform the actual healing for this frame.
// DamageInfo damageInfo;
// damageInfo.in.m_damageType = DAMAGE_HEALING;
// damageInfo.in.m_deathType = DEATH_NONE;
// damageInfo.in.m_sourceID = getObject()->getID();
// damageInfo.in.m_amount = regen;
// object->attemptDamage( &damageInfo );
object->attemptHealing( regen, getObject() );
}
}
}
}
}
return OpenContain::update(); //extend
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
void TransportContain::unreserveDoorForExit( ExitDoorType exitDoor )
{
/* nothing */
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
void TransportContain::killRidersWhoAreNotFreeToExit()
{
const TransportContainModuleData* d = getTransportContainModuleData();
ContainedItemsList::const_iterator it = getContainList().begin();
while( it != getContainList().end() )
{
// get the object
Object *obj = *it;
// increment the iterator, since death will pull this guy from the list somewhere else
++it;
if (!isSpecificRiderFreeToExit(obj)) // only TransportContain has a meaningful failure for isFreeToExit
{
// If we cannot exit this guy legally, kill the bastard before removeAllContained forces him out.
if (d->m_destroyRidersWhoAreNotFreeToExit)
TheGameLogic->destroyObject(obj);
else
#if RETAIL_COMPATIBLE_CRC
obj->kill();
#else
// TheSuperHackers @info Burned death prevents infantry corpses dropping out of the container.
obj->kill(DAMAGE_UNRESISTABLE, d->m_isBurnedDeathToUnits ? DEATH_BURNED : DEATH_NORMAL);
#endif
}
}
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
Bool TransportContain::isSpecificRiderFreeToExit(Object* specificObject)
{
if( specificObject == nullptr )
return TRUE; // I can, in general, exit people.
// This is a override, not an extend. I will check for game legality for
// okaying the call to exitObjectViaDoor.
const Object* me = getObject();
// this is present solely for some transports to override, so that they can land before
// allowing people to exit...
const AIUpdateInterface* ai = me->getAIUpdateInterface();
if (ai && ai->getAiFreeToExit(specificObject) != FREE_TO_EXIT)
return FALSE;
#if !RETAIL_COMPATIBLE_CRC
// TheSuperHackers @bugfix Stubbjax 02/03/2026 If our parent container is held, then we
// are not free to exit.
DEBUG_ASSERTCRASH(specificObject->getContainedBy(), ("rider must be contained"));
if (specificObject->getContainedBy() && specificObject->getContainedBy()->isDisabledByType(DISABLED_HELD))
return FALSE;
#endif
// I can always kick people out if I am in the air, I know what I'm doing
if (me->isUsingAirborneLocomotor())
return TRUE;
const Coord3D *myPosition = me->getPosition();
if (!specificObject->getAIUpdateInterface())
return FALSE;
const Locomotor *hisLocomotor = specificObject->getAIUpdateInterface()->getCurLocomotor();
if( hisLocomotor == FALSE )
return FALSE;
// He can't get to this spot naturally, so I can't force him there. (amphib transport)
if (!TheAI->pathfinder()->validMovementTerrain(me->getLayer(), hisLocomotor, myPosition))
return FALSE;
return TRUE;
}
Bool TransportContain::isPassengerAllowedToFire( ObjectID id ) const
{
Object *passenger = TheGameLogic->findObjectByID(id);
if( passenger != nullptr )
{
//only allow infantry, and turrets and such. no vehicles.
if( passenger->isKindOf(KINDOF_INFANTRY) == FALSE )
return FALSE;
}
if ( ! getObject() )
return FALSE;
// but wait! I may be riding on an Overlord
// This code detects the case of whether the contained passenger is in a bunker riding on an overlord, inside a helix!
// Oh my God.
const Object *heWhoContainsMe = getObject()->getContainedBy();
if ( heWhoContainsMe)
{
ContainModuleInterface *hisContain = heWhoContainsMe->getContain();
DEBUG_ASSERTCRASH( hisContain,("TransportContain::isPassengerAllowedToFire()... CONTAINER WITHOUT A CONTAIN! AARRGH!") );
if ( hisContain && hisContain->isSpecialOverlordStyleContainer() )
return hisContain->isPassengerAllowedToFire( id );
}
return OpenContain::isPassengerAllowedToFire();
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
ExitDoorType TransportContain::reserveDoorForExit( const ThingTemplate* objType, Object *specificObject )
{
return isSpecificRiderFreeToExit(specificObject) ? DOOR_1 : DOOR_NONE_AVAILABLE;
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
Bool TransportContain::isExitBusy() const ///< Contain style exiters are getting the ability to space out exits, so ask this before reserveDoor as a kind of no-commitment check.
{
const TransportContainModuleData *data = getTransportContainModuleData();
if( data->m_isDelayExitInAir && getObject()->isAboveTerrain() )
return TRUE;
return TheGameLogic->getFrame() < m_frameExitNotBusy;
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
void TransportContain::onCapture( Player *oldOwner, Player *newOwner )
{
if( oldOwner != newOwner )
{
if( getObject()->isDisabledByType( DISABLED_UNMANNED ) )
{
//If this vehicle was sniped, then instantly eject everyone (otherwise, the next guy to eject will recapture it).
removeAllContained();
}
else
{
//Use standard
orderAllPassengersToExit( CMD_FROM_AI, FALSE );
}
}
}
// ------------------------------------------------------------------------------------------------
/** CRC */
// ------------------------------------------------------------------------------------------------
void TransportContain::crc( Xfer *xfer )
{
// extend base class
OpenContain::crc( xfer );
}
// ------------------------------------------------------------------------------------------------
/** Xfer method
* Version Info:
* 1: Initial version */
// ------------------------------------------------------------------------------------------------
void TransportContain::xfer( Xfer *xfer )
{
// version
XferVersion currentVersion = 1;
XferVersion version = currentVersion;
xfer->xferVersion( &version, currentVersion );
// extend base class
OpenContain::xfer( xfer );
// payload created
xfer->xferBool( &m_payloadCreated );
// extra slots in use
xfer->xferInt( &m_extraSlotsInUse );
// frame exit not busy
xfer->xferUnsignedInt( &m_frameExitNotBusy );
}
// ------------------------------------------------------------------------------------------------
/** Load post process */
// ------------------------------------------------------------------------------------------------
void TransportContain::loadPostProcess()
{
// extend base class
OpenContain::loadPostProcess();
}