SquishCollide.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: SquishCollide.cpp //////////////////////////////////////////////////////////////////////////
  24. // Author:
  25. // Desc:
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  28. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  29. #include "Common/ThingFactory.h"
  30. #include "Common/Xfer.h"
  31. #include "GameLogic/Damage.h"
  32. #include "GameLogic/Object.h"
  33. #include "GameLogic/Module/SquishCollide.h"
  34. #include "GameLogic/Module/PhysicsUpdate.h"
  35. #include "GameLogic/Module/HijackerUpdate.h"
  36. #include "GameLogic/Module/SpecialAbilityUpdate.h"
  37. #include "GameLogic/Module/AIUpdate.h"
  38. #include "GameLogic/PartitionManager.h"
  39. #ifdef _INTERNAL
  40. // for occasional debugging...
  41. //#pragma optimize("", off)
  42. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  43. #endif
  44. //-------------------------------------------------------------------------------------------------
  45. //-------------------------------------------------------------------------------------------------
  46. SquishCollide::SquishCollide( Thing *thing, const ModuleData* moduleData ) : CollideModule( thing, moduleData )
  47. {
  48. }
  49. //-------------------------------------------------------------------------------------------------
  50. //-------------------------------------------------------------------------------------------------
  51. SquishCollide::~SquishCollide( void )
  52. {
  53. }
  54. //-------------------------------------------------------------------------------------------------
  55. /** Do the collision */
  56. //-------------------------------------------------------------------------------------------------
  57. void SquishCollide::onCollide( Object *other, const Coord3D *loc, const Coord3D *normal )
  58. {
  59. // Note that other == null means "collide with ground"
  60. if (other == NULL)
  61. return;
  62. Object *self = getObject();
  63. AIUpdateInterface *ai = self->getAI();
  64. if( ai && ai->getGoalObject() == other )
  65. {
  66. //We are actually targeting the other object to do something to! Don't allow them to crush us in the following
  67. //special circumstances:
  68. //Hijacking!
  69. static NameKeyType key_HijackerUpdate = NAMEKEY( "HijackerUpdate" );
  70. HijackerUpdate *hijackUpdate = (HijackerUpdate*)self->findUpdateModule( key_HijackerUpdate );
  71. if( hijackUpdate )
  72. {
  73. return;
  74. }
  75. //TNT hunter placing a charge!
  76. SpecialAbilityUpdate *saUpdate = self->findSpecialAbilityUpdate( SPECIAL_TANKHUNTER_TNT_ATTACK );
  77. if( saUpdate && saUpdate->isActive() )
  78. {
  79. return;
  80. }
  81. }
  82. // order matters: we want to know if IT considers ME to be an ally (a reversal of the usual situation)
  83. if( other->getCrusherLevel() > 0 && other->getRelationship(getObject()) != ALLIES)
  84. {
  85. PhysicsBehavior *otherPhysics = other->getPhysics();
  86. if (otherPhysics == NULL)
  87. return;
  88. // use a 1.0 crush radius so the tank has to actually hit the infantry.
  89. GeometryInfo myGeom = self->getGeometryInfo();
  90. myGeom.setMajorRadius(1.0f);
  91. myGeom.setMinorRadius(1.0f);
  92. if (!ThePartitionManager->geomCollidesWithGeom(other->getPosition(), other->getGeometryInfo(), other->getOrientation(),
  93. self->getPosition(), myGeom, self->getOrientation())) {
  94. return;
  95. }
  96. // only squish if tank is moving toward victim
  97. const Coord3D *vel = otherPhysics->getVelocity();
  98. const Coord3D *pos = other->getPosition();
  99. const Coord3D *myPos = getObject()->getPosition();
  100. Coord3D to;
  101. to.x = myPos->x - pos->x;
  102. to.y = myPos->y - pos->y;
  103. to.z = myPos->z - pos->z;
  104. if (to.x * vel->x + to.y * vel->y > 0.0f)
  105. {
  106. DamageInfo damageInfo;
  107. damageInfo.in.m_damageType = DAMAGE_CRUSH;
  108. damageInfo.in.m_deathType = DEATH_CRUSHED;
  109. damageInfo.in.m_sourceID = other->getID();
  110. damageInfo.in.m_amount = HUGE_DAMAGE_AMOUNT; // make sure they die
  111. getObject()->attemptDamage( &damageInfo );
  112. getObject()->friend_setUndetectedDefector( FALSE );// My secret is out
  113. }
  114. }
  115. }
  116. // ------------------------------------------------------------------------------------------------
  117. /** CRC */
  118. // ------------------------------------------------------------------------------------------------
  119. void SquishCollide::crc( Xfer *xfer )
  120. {
  121. // extend base class
  122. CollideModule::crc( xfer );
  123. } // end crc
  124. // ------------------------------------------------------------------------------------------------
  125. /** Xfer method
  126. * Version Info:
  127. * 1: Initial version */
  128. // ------------------------------------------------------------------------------------------------
  129. void SquishCollide::xfer( Xfer *xfer )
  130. {
  131. // version
  132. XferVersion currentVersion = 1;
  133. XferVersion version = currentVersion;
  134. xfer->xferVersion( &version, currentVersion );
  135. // extend base class
  136. CollideModule::xfer( xfer );
  137. } // end xfer
  138. // ------------------------------------------------------------------------------------------------
  139. /** Load post process */
  140. // ------------------------------------------------------------------------------------------------
  141. void SquishCollide::loadPostProcess( void )
  142. {
  143. // extend base class
  144. CollideModule::loadPostProcess();
  145. } // end loadPostProcess