physicalgameobj.cpp 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418
  1. /*
  2. ** Command & Conquer Renegade(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. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Commando *
  23. * *
  24. * $Archive:: /Commando/Code/Combat/physicalgameobj.cpp $*
  25. * *
  26. * $Author:: Greg_h $*
  27. * *
  28. * $Modtime:: 6/14/02 5:58p $*
  29. * *
  30. * $Revision:: 223 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "physicalgameobj.h"
  36. #include "damage.h"
  37. #include "scripts.h"
  38. #include "debug.h"
  39. #include "explosion.h"
  40. #include "assets.h"
  41. #include "combatsound.h"
  42. #include "matrix3d.h"
  43. #include "phys.h"
  44. #include "smartgameobj.h"
  45. #include "soldier.h"
  46. #include "animcontrol.h"
  47. #include "chunkio.h"
  48. #include "saveload.h"
  49. #include "combat.h"
  50. #include "persistfactory.h"
  51. #include "combatchunkid.h"
  52. #include "parameter.h"
  53. #include "radar.h"
  54. #include "playertype.h"
  55. #include "matinfo.h"
  56. #include "gameobjmanager.h"
  57. #include "pscene.h"
  58. #include "wwprofile.h"
  59. #include "rbody.h"
  60. #include "bitpackids.h"
  61. #include "activeconversation.h"
  62. #include "oratortypes.h"
  63. #include "vistable.h"
  64. #include "encyclopediamgr.h"
  65. #include "combatmaterialeffectmanager.h"
  66. #include "phys.h"
  67. #include "transitioneffect.h"
  68. #include "phys3.h"
  69. #include "surfaceeffects.h"
  70. // Hibernate after 30 seconds
  71. #define HIBERNATION_DELAY 30
  72. bool _DisplayHibernating = false;
  73. /*
  74. ** PhysicalGameObjDef
  75. */
  76. PhysicalGameObjDef::PhysicalGameObjDef( void ) :
  77. Type( 0 ),
  78. BullseyeOffsetZ( 0.0f ),
  79. RadarBlipType( 0 ),
  80. PhysDefID( 0 ),
  81. KilledExplosion( 0 ),
  82. OratorType( ORATOR_TYPE_START - 1 ),
  83. DefaultHibernationEnable( true ),
  84. AllowInnateConversations( false ),
  85. UseCreationEffect( false )
  86. {
  87. #ifdef PARAM_EDITING_ON
  88. int i;
  89. EnumParameterClass *param;
  90. EDITABLE_PARAM( PhysicalGameObjDef, ParameterClass::TYPE_FLOAT, BullseyeOffsetZ );
  91. param = new EnumParameterClass( &RadarBlipType );
  92. param->Set_Name("Radar Blip Type");
  93. for ( i = 0; i < RadarManager::Get_Num_Blip_Shape_Types(); i++ ) {
  94. param->Add_Value ( RadarManager::Get_Blip_Shape_Type_Name( i ), i );
  95. }
  96. GENERIC_EDITABLE_PARAM(PhysicalGameObjDef,param)
  97. EDITABLE_PARAM( PhysicalGameObjDef, ParameterClass::TYPE_STRING, Animation );
  98. EDITABLE_PARAM( PhysicalGameObjDef, ParameterClass::TYPE_EXPLOSIONDEFINITIONID, KilledExplosion);
  99. EDITABLE_PARAM( PhysicalGameObjDef, ParameterClass::TYPE_BOOL, DefaultHibernationEnable );
  100. EDITABLE_PARAM( PhysicalGameObjDef, ParameterClass::TYPE_BOOL, AllowInnateConversations );
  101. EDITABLE_PARAM( PhysicalGameObjDef, ParameterClass::TYPE_BOOL, UseCreationEffect );
  102. //
  103. // Configure the orator types parameter
  104. //
  105. EnumParameterClass *orator_type_param = new EnumParameterClass (&OratorType);
  106. orator_type_param->Set_Name ("Orator Type");
  107. //
  108. // Add all the orator types to the list
  109. //
  110. int count = OratorTypeClass::Get_Count ();
  111. for (int index = 0; index < count; index ++) {
  112. orator_type_param->Add_Value (OratorTypeClass::Get_Description (index),
  113. OratorTypeClass::Get_ID (index));
  114. }
  115. GENERIC_EDITABLE_PARAM( PhysicalGameObjDef, orator_type_param );
  116. #endif
  117. }
  118. enum {
  119. CHUNKID_DEF_VARIABLES = 909991657,
  120. LEGACY_CHUNKID_DEF_PARENT_OLD,
  121. XXXCHUNKID_DEF_PARENT_OLD_OLD,
  122. LEGACY_CHUNKID_DEF_DEFENSEOBJECTDEF,
  123. CHUNKID_DEF_PARENT,
  124. MICROCHUNKID_DEF_TYPE = 1,
  125. MICROCHUNKID_DEF_BULLSEYE_OFFSET_Z,
  126. XXXMICROCHUNKID_DEF_DEFAULT_GANG,
  127. MICROCHUNKID_DEF_BLIP_TYPE,
  128. XXXMICROCHUNKID_DEF_MODEL_NAME,
  129. XXXMICROCHUNKID_DEF_HEALTH,
  130. XXXMICROCHUNKID_DEF_HEALTH_MAX,
  131. XXXMICROCHUNKID_DEF_SKIN,
  132. XXXMICROCHUNKID_DEF_SHIELD_STRENGTH,
  133. XXXMICROCHUNKID_DEF_SHIELD_STRENGTH_MAX,
  134. XXXMICROCHUNKID_DEF_SHIELD_TYPE,
  135. XXXMICROCHUNKID_DEF_LISTEN_RANGE,
  136. XXX_MICROCHUNKID_DEF_SCRIPT_NAME,
  137. XXX_MICROCHUNKID_DEF_SCRIPT_PARAMETERS,
  138. XXXMICROCHUNKID_DEF_POSITION, // ???
  139. MICROCHUNKID_DEF_FACING,
  140. MICROCHUNKID_DEF_ANIMATION,
  141. MICROCHUNKID_DEF_PHYS_ID,
  142. LEGACY_MICROCHUNKID_DEF_DEFAULT_PLAYER_TYPE,
  143. MICROCHUNKID_DEF_KILLED_EXPLOSION,
  144. LEGACY_MICROCHUNKID_DEF_TRANSLATED_NAME_ID,
  145. MICROCHUNKID_DEF_DEFAULT_HIBERNATION_ENABLE,
  146. MICROCHUNKID_DEF_ALLOW_INNATE_CONVERSATIONS,
  147. MICROCHUNKID_DEF_ORATOR_TYPE,
  148. MICROCHUNKID_DEF_USE_CREATION_EFFECT,
  149. };
  150. bool PhysicalGameObjDef::Save( ChunkSaveClass & csave )
  151. {
  152. csave.Begin_Chunk( CHUNKID_DEF_PARENT );
  153. DamageableGameObjDef::Save( csave );
  154. csave.End_Chunk();
  155. csave.Begin_Chunk( CHUNKID_DEF_VARIABLES );
  156. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_DEF_TYPE, Type );
  157. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_DEF_BULLSEYE_OFFSET_Z, BullseyeOffsetZ );
  158. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_DEF_BLIP_TYPE, RadarBlipType );
  159. WRITE_MICRO_CHUNK_WWSTRING( csave, MICROCHUNKID_DEF_ANIMATION, Animation );
  160. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_DEF_PHYS_ID, PhysDefID );
  161. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_DEF_KILLED_EXPLOSION, KilledExplosion );
  162. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_DEF_DEFAULT_HIBERNATION_ENABLE, DefaultHibernationEnable );
  163. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_DEF_ALLOW_INNATE_CONVERSATIONS, AllowInnateConversations );
  164. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_DEF_ORATOR_TYPE, OratorType );
  165. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_DEF_USE_CREATION_EFFECT, UseCreationEffect );
  166. csave.End_Chunk();
  167. return true;
  168. }
  169. bool PhysicalGameObjDef::Load( ChunkLoadClass &cload )
  170. {
  171. while (cload.Open_Chunk()) {
  172. switch(cload.Cur_Chunk_ID()) {
  173. case LEGACY_CHUNKID_DEF_PARENT_OLD:
  174. ScriptableGameObjDef::Load( cload );
  175. break;
  176. case CHUNKID_DEF_PARENT:
  177. DamageableGameObjDef::Load( cload );
  178. break;
  179. case CHUNKID_DEF_VARIABLES:
  180. while (cload.Open_Micro_Chunk()) {
  181. switch(cload.Cur_Micro_Chunk_ID()) {
  182. READ_MICRO_CHUNK( cload, MICROCHUNKID_DEF_TYPE, Type );
  183. READ_MICRO_CHUNK( cload, MICROCHUNKID_DEF_BULLSEYE_OFFSET_Z, BullseyeOffsetZ );
  184. READ_MICRO_CHUNK( cload, MICROCHUNKID_DEF_BLIP_TYPE, RadarBlipType );
  185. READ_MICRO_CHUNK_WWSTRING( cload, MICROCHUNKID_DEF_ANIMATION, Animation );
  186. READ_MICRO_CHUNK( cload, MICROCHUNKID_DEF_PHYS_ID, PhysDefID );
  187. READ_MICRO_CHUNK( cload, LEGACY_MICROCHUNKID_DEF_DEFAULT_PLAYER_TYPE, DefaultPlayerType );
  188. READ_MICRO_CHUNK( cload, MICROCHUNKID_DEF_KILLED_EXPLOSION, KilledExplosion );
  189. READ_MICRO_CHUNK( cload, LEGACY_MICROCHUNKID_DEF_TRANSLATED_NAME_ID, TranslatedNameID );
  190. READ_MICRO_CHUNK( cload, MICROCHUNKID_DEF_DEFAULT_HIBERNATION_ENABLE, DefaultHibernationEnable );
  191. READ_MICRO_CHUNK( cload, MICROCHUNKID_DEF_ALLOW_INNATE_CONVERSATIONS, AllowInnateConversations );
  192. READ_MICRO_CHUNK( cload, MICROCHUNKID_DEF_ORATOR_TYPE, OratorType );
  193. READ_MICRO_CHUNK( cload, MICROCHUNKID_DEF_USE_CREATION_EFFECT, UseCreationEffect );
  194. default:
  195. Debug_Say(( "Unrecognized PhysicalDef Variable chunkID %d\n", cload.Cur_Micro_Chunk_ID() ));
  196. break;
  197. }
  198. cload.Close_Micro_Chunk();
  199. }
  200. break;
  201. case LEGACY_CHUNKID_DEF_DEFENSEOBJECTDEF:
  202. DefenseObjectDef.Load(cload);
  203. break;
  204. default:
  205. Debug_Say(( "Unrecognized PhysicalGameObjDef chunkID %d\n", cload.Cur_Chunk_ID() ));
  206. break;
  207. }
  208. cload.Close_Chunk();
  209. }
  210. return true;
  211. }
  212. bool PhysicalGameObjDef::Is_Valid_Config (StringClass &message)
  213. {
  214. bool retval = false;
  215. DefinitionClass *phys_def = DefinitionMgrClass::Find_Definition (PhysDefID);
  216. if (phys_def != NULL) {
  217. retval = phys_def->Is_Valid_Config (message);
  218. } else {
  219. message += "Can't find physics object definition.\n";
  220. }
  221. return retval;
  222. }
  223. /*
  224. ** PhysicalGameObj
  225. */
  226. PhysicalGameObj::PhysicalGameObj( void ) :
  227. PhysObj( NULL ),
  228. AnimControl( NULL ),
  229. //TintColor(1, 1, 1),
  230. HibernationTimer( 0 ), // Start alseep
  231. HibernationEnable( true ),
  232. HostGameObjBone( 0 ),
  233. RadarBlipShapeType( 0 ),
  234. RadarBlipColorType( 0 ),
  235. RadarBlipIntensity( 0 ),
  236. ActiveConversation( NULL ),
  237. PendingHostObjID( 0 ),
  238. HUDPokableIndicatorEnabled( false ),
  239. IsInnateConversationsEnabled( true )
  240. {
  241. Reset_Server_Skips(255);
  242. return ;
  243. }
  244. PhysicalGameObj::~PhysicalGameObj( void )
  245. {
  246. if ( AnimControl != NULL ) {
  247. delete AnimControl;
  248. AnimControl = NULL;
  249. }
  250. if ( PhysObj != NULL ) {
  251. COMBAT_SCENE->Remove_Object( PhysObj );
  252. PhysObj->Release_Ref();
  253. PhysObj = NULL;
  254. }
  255. REF_PTR_RELEASE( ActiveConversation );
  256. }
  257. /*
  258. **
  259. */
  260. void PhysicalGameObj::Init( const PhysicalGameObjDef & definition )
  261. {
  262. DamageableGameObj::Init( definition );
  263. Copy_Settings( definition );
  264. Hide_Muzzle_Flashes();
  265. /*
  266. ** If the definition calls for it, add a material effect to the object
  267. */
  268. if ( definition.UseCreationEffect ) {
  269. PhysClass * physobj = Peek_Physical_Object();
  270. if (physobj != NULL) {
  271. TransitionEffectClass * effect = CombatMaterialEffectManager::Get_Spawn_Effect();
  272. physobj->Add_Effect_To_Me(effect);
  273. REF_PTR_RELEASE(effect);
  274. }
  275. }
  276. return ;
  277. }
  278. /*
  279. **
  280. */
  281. void PhysicalGameObj::Copy_Settings( const PhysicalGameObjDef & definition )
  282. {
  283. //
  284. // Release our hold on the physics object
  285. //
  286. if ( PhysObj != NULL ) {
  287. COMBAT_SCENE->Remove_Object( PhysObj );
  288. PhysObj->Release_Ref();
  289. PhysObj = NULL;
  290. }
  291. // Set the Physical Object
  292. WWASSERT( PhysObj == NULL );
  293. DefinitionClass * podef = DefinitionMgrClass::Find_Definition( definition.PhysDefID );
  294. WWASSERT( SuperClassID_From_ClassID( podef->Get_Class_ID() ) == CLASSID_PHYSICS );
  295. PhysObj = (PhysClass *)podef->Create();
  296. WWASSERT( PhysObj != NULL );
  297. PhysObj->Set_Collision_Group( DEFAULT_COLLISION_GROUP );
  298. PhysObj->Set_Observer( this );
  299. COMBAT_SCENE->Add_Dynamic_Object( PhysObj );
  300. // Do we still use this?????
  301. if ( !definition.Animation.Is_Empty() ) {
  302. Set_Animation( definition.Animation );
  303. }
  304. Enable_Hibernation( definition.DefaultHibernationEnable );
  305. Reset_Radar_Blip_Shape_Type();
  306. return ;
  307. }
  308. /*
  309. **
  310. */
  311. void PhysicalGameObj::Re_Init( const PhysicalGameObjDef & definition )
  312. {
  313. Matrix3D tm = Get_Transform ();
  314. //
  315. // Re-initialize the base class
  316. //
  317. DamageableGameObj::Re_Init( definition );
  318. //
  319. // Copy any internal settings from the definition
  320. //
  321. Copy_Settings( definition );
  322. //
  323. // Restore the necessary settings
  324. //
  325. Set_Transform( tm );
  326. return ;
  327. }
  328. const PhysicalGameObjDef & PhysicalGameObj::Get_Definition( void ) const
  329. {
  330. return (const PhysicalGameObjDef &)BaseGameObj::Get_Definition();
  331. }
  332. /*
  333. ** PhysicalGameObj Save and Load
  334. */
  335. enum {
  336. XXXCHUNKID_PARENT_OLD_OLD = 910991145,
  337. CHUNKID_VARIABLES,
  338. XXX_CHUNKID_SCRIPTS,
  339. LEGACY_CHUNKID_DEFENSE,
  340. XXXCHUNKID_LISTENER,
  341. XXXCHUNKID_REFERENCEABLE,
  342. XXXCHUNKID_OBSER_XXX_VER,
  343. LEGACY_CHUNKID_PARENT_OLD,
  344. CHUNKID_ANIM_CONTROL,
  345. CHUNKID_HOST_GAME_OBJ,
  346. CHUNKID_PARENT,
  347. XXXMICROCHUNKID_ID = 1,
  348. XXXMICROCHUNKID_GANG,
  349. MICROCHUNKID_PHYS_OBSERVER_PTR,
  350. XXXMICROCHUNKID_REFERENCEABLE_PTR,
  351. XXXMICROCHUNKID_DISTANCE_PRIORITY,
  352. XXXMICROCHUNKID_TIME_PRIORITY,
  353. XXXMICROCHUNKID_PRIORITY,
  354. XXXMICROCHUNKID_GAME_OBJ_OBSERVER_PTR,
  355. LEGACY_MICROCHUNKID_PLAYER_TYPE,
  356. MICROCHUNKID_PHYSICAL_OBJECT,
  357. MICROCHUNKID_HIBERNATION_TIMER,
  358. MICROCHUNKID_HIBERNATION_ENABLE,
  359. MICROCHUNKID_HOST_GAME_OBJ_BONE,
  360. MICROCHUNKID_RADAR_BLIP_SHAPE_TYPE,
  361. MICROCHUNKID_RADAR_BLIP_COLOR_TYPE,
  362. MICROCHUNKID_RADAR_BLIP_INTENSITY,
  363. MICROCHUNKID_ACTIVE_CONVERSATION,
  364. MICROCHUNKID_HUD_POKABLE_INDICATOR,
  365. MICROCHUNKID_IS_INNATE_CONVERSATIONS_ENABLED,
  366. };
  367. bool PhysicalGameObj::Save( ChunkSaveClass & csave )
  368. {
  369. csave.Begin_Chunk( CHUNKID_PARENT );
  370. DamageableGameObj::Save( csave );
  371. csave.End_Chunk();
  372. csave.Begin_Chunk( CHUNKID_VARIABLES );
  373. CombatPhysObserverClass * phys_observer_ptr = (CombatPhysObserverClass *)this;
  374. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_PHYS_OBSERVER_PTR, phys_observer_ptr );
  375. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_PHYSICAL_OBJECT, PhysObj );
  376. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_HIBERNATION_TIMER, HibernationTimer );
  377. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_HIBERNATION_ENABLE, HibernationEnable );
  378. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_HOST_GAME_OBJ_BONE, HostGameObjBone );
  379. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_RADAR_BLIP_SHAPE_TYPE, RadarBlipShapeType );
  380. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_RADAR_BLIP_COLOR_TYPE, RadarBlipColorType );
  381. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_RADAR_BLIP_INTENSITY, RadarBlipIntensity );
  382. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_ACTIVE_CONVERSATION, ActiveConversation );
  383. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_HUD_POKABLE_INDICATOR, HUDPokableIndicatorEnabled );
  384. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_IS_INNATE_CONVERSATIONS_ENABLED, IsInnateConversationsEnabled );
  385. csave.End_Chunk();
  386. if ( AnimControl ) {
  387. csave.Begin_Chunk( CHUNKID_ANIM_CONTROL );
  388. AnimControl->Save( csave );
  389. csave.End_Chunk();
  390. }
  391. if ( HostGameObj.Get_Ptr() != NULL ) {
  392. csave.Begin_Chunk( CHUNKID_HOST_GAME_OBJ );
  393. HostGameObj.Save( csave );
  394. csave.End_Chunk();
  395. }
  396. /*
  397. #pragma message( "Tom, do these need to be saved?" )
  398. int ImportStateCount;
  399. float DistancePriority;
  400. float TimePriority;
  401. float VolatilityPriority;
  402. float Priority;
  403. BYTE ClientUpdateSkips[255];
  404. BYTE ServerUpdateSkips;
  405. cPacket StatePacket;
  406. int StatePacketUnchangedCount;
  407. Vector3 TintColor;
  408. */
  409. return true;
  410. }
  411. bool PhysicalGameObj::Load( ChunkLoadClass &cload )
  412. {
  413. WWASSERT( PhysObj == NULL ); // May need to change to release???
  414. CombatPhysObserverClass * phys_observer_ptr = NULL;
  415. while (cload.Open_Chunk()) {
  416. switch(cload.Cur_Chunk_ID()) {
  417. case LEGACY_CHUNKID_PARENT_OLD:
  418. ScriptableGameObj::Load( cload );
  419. break;
  420. case CHUNKID_PARENT:
  421. DamageableGameObj::Load( cload );
  422. break;
  423. case CHUNKID_VARIABLES:
  424. while (cload.Open_Micro_Chunk()) {
  425. switch(cload.Cur_Micro_Chunk_ID()) {
  426. READ_MICRO_CHUNK( cload, MICROCHUNKID_PHYS_OBSERVER_PTR, phys_observer_ptr );
  427. READ_MICRO_CHUNK( cload, LEGACY_MICROCHUNKID_PLAYER_TYPE, PlayerType );
  428. READ_MICRO_CHUNK( cload, MICROCHUNKID_PHYSICAL_OBJECT, PhysObj );
  429. READ_MICRO_CHUNK( cload, MICROCHUNKID_HIBERNATION_TIMER, HibernationTimer );
  430. READ_MICRO_CHUNK( cload, MICROCHUNKID_HIBERNATION_ENABLE, HibernationEnable );
  431. READ_MICRO_CHUNK( cload, MICROCHUNKID_HOST_GAME_OBJ_BONE, HostGameObjBone );
  432. READ_MICRO_CHUNK( cload, MICROCHUNKID_RADAR_BLIP_SHAPE_TYPE, RadarBlipShapeType );
  433. READ_MICRO_CHUNK( cload, MICROCHUNKID_RADAR_BLIP_COLOR_TYPE, RadarBlipColorType );
  434. READ_MICRO_CHUNK( cload, MICROCHUNKID_RADAR_BLIP_INTENSITY, RadarBlipIntensity );
  435. READ_MICRO_CHUNK( cload, MICROCHUNKID_ACTIVE_CONVERSATION, ActiveConversation );
  436. READ_MICRO_CHUNK( cload, MICROCHUNKID_HUD_POKABLE_INDICATOR, HUDPokableIndicatorEnabled );
  437. READ_MICRO_CHUNK( cload, MICROCHUNKID_IS_INNATE_CONVERSATIONS_ENABLED, IsInnateConversationsEnabled );
  438. default:
  439. Debug_Say(( "Unrecognized PhysicalGameObj Variable chunkID\n" ));
  440. break;
  441. }
  442. cload.Close_Micro_Chunk();
  443. }
  444. break;
  445. case LEGACY_CHUNKID_DEFENSE:
  446. DefenseObject.Load( cload );
  447. break;
  448. case CHUNKID_ANIM_CONTROL:
  449. Set_Animation( NULL ); // Build AnimControl
  450. AnimControl->Load( cload );
  451. break;
  452. case CHUNKID_HOST_GAME_OBJ:
  453. HostGameObj.Load( cload );
  454. break;
  455. default:
  456. Debug_Say(( "Unrecognized PhysicalGameObj chunkID\n" ));
  457. break;
  458. }
  459. cload.Close_Chunk();
  460. }
  461. WWASSERT( PhysObj != NULL );
  462. REQUEST_REF_COUNTED_POINTER_REMAP( (RefCountClass **)&PhysObj );
  463. if ( ActiveConversation != NULL ) {
  464. REQUEST_REF_COUNTED_POINTER_REMAP( (RefCountClass **)&ActiveConversation );
  465. }
  466. // Register the multiple-inheritance versions of our this pointer.
  467. WWASSERT(phys_observer_ptr != NULL);
  468. if (phys_observer_ptr != NULL) {
  469. SaveLoadSystemClass::Register_Pointer(phys_observer_ptr, (CombatPhysObserverClass *)this);
  470. }
  471. SaveLoadSystemClass::Register_Post_Load_Callback(this);
  472. return true;
  473. }
  474. void PhysicalGameObj::On_Post_Load (void)
  475. {
  476. // Plug ourselves back into the physics object as an observer
  477. WWASSERT(PhysObj != NULL);
  478. PhysObj->Set_Observer(this);
  479. Hide_Muzzle_Flashes();
  480. DamageableGameObj::On_Post_Load ();
  481. }
  482. AnimControlClass * PhysicalGameObj::Get_Anim_Control( void )
  483. {
  484. return AnimControl;
  485. }
  486. void PhysicalGameObj::Set_Anim_Control( AnimControlClass * anim_control )
  487. {
  488. WWASSERT( AnimControl == NULL );
  489. AnimControl = anim_control;
  490. WWASSERT( AnimControl != NULL );
  491. }
  492. bool PhysicalGameObj::Is_Soft( void )
  493. {
  494. return DefenseObject.Is_Soft();
  495. }
  496. Vector3 PhysicalGameObj::Get_Bullseye_Position( void )
  497. {
  498. Vector3 pos;
  499. Get_Position(&pos);
  500. // pos.Z += Get_Bullseye_Offset_Z();
  501. return pos;
  502. }
  503. void PhysicalGameObj::Apply_Damage( const OffenseObjectClass & damager, float scale, int alternate_skin )
  504. {
  505. // If this damage is allowed
  506. if ( !CombatManager::Can_Damage( damager.Get_Owner(), this)) {
  507. return;
  508. }
  509. #ifdef WWDEBUG
  510. //
  511. // Tone it down for VIP's
  512. //
  513. scale *= CombatManager::Get_Damage_Factor(damager.Get_Owner(), this);
  514. #endif // WWDEBUG
  515. DamageableGameObj::Apply_Damage( damager, scale );
  516. }
  517. void PhysicalGameObj::Apply_Damage_Extended( const OffenseObjectClass & damager, float scale,
  518. const Vector3 & direction, const char * collision_box_name )
  519. {
  520. // if ( CombatManager::I_Am_Server() ) Clients can apply damage now
  521. {
  522. Apply_Damage( damager, scale );
  523. }
  524. }
  525. void PhysicalGameObj::Completely_Damaged( const OffenseObjectClass & damager )
  526. {
  527. if ( Get_Definition().KilledExplosion != 0 ) {
  528. Vector3 pos;
  529. Get_Position(&pos);
  530. WWASSERT(pos.Is_Valid());// most likely candidate for explosion damage bug....?
  531. // Build a transform with the same heading as the object
  532. float z_rot = Get_Transform().Get_Z_Rotation();
  533. Matrix3D tm(pos);
  534. tm.Rotate_Z(z_rot);
  535. // Create the explosion
  536. ExplosionManager::Create_Explosion_At( Get_Definition().KilledExplosion, tm/*pos*/, damager.Get_Owner() ); // no one gets credit for this
  537. //
  538. // Reveal this object to the player's encyclopedia
  539. //
  540. if ( damager.Get_Owner () == COMBAT_STAR ) {
  541. EncyclopediaMgrClass::Reveal_Object( this );
  542. }
  543. }
  544. Set_Delete_Pending();
  545. }
  546. void PhysicalGameObj::Teleport_To_Host_Bone( void )
  547. {
  548. // Debug_Say(( "Teleporting %d to host\n", Get_ID() ));
  549. if ( HostGameObj.Get_Ptr() ) {
  550. RenderObjClass * model = ((PhysicalGameObj * )(HostGameObj.Get_Ptr()))->Peek_Model();
  551. if ( model != NULL ) {
  552. /*
  553. ** Calculate the bone's transform and try to go there
  554. */
  555. bool ok = false;
  556. Matrix3D new_transform = model->Get_Bone_Transform( HostGameObjBone );
  557. /*
  558. ** If we are some kind of moveable object see if we can teleport to the desired position.
  559. ** Also, clear our velocity whenever being controlled by an animation.
  560. */
  561. if (Peek_Physical_Object()->As_MoveablePhysClass()) {
  562. /*
  563. ** Don't collide with our host
  564. */
  565. PhysClass * host_phys = ((PhysicalGameObj * )HostGameObj.Get_Ptr())->Peek_Physical_Object();
  566. if (host_phys != NULL) {
  567. host_phys->Inc_Ignore_Counter();
  568. }
  569. /*
  570. ** Try to teleport to the new location while pushing any blocking dynamic
  571. ** objects out of the way
  572. */
  573. MoveablePhysClass * movephys = Peek_Physical_Object()->As_MoveablePhysClass();
  574. movephys->Set_Velocity(Vector3(0,0,0));
  575. movephys->Cinematic_Move_To(new_transform);
  576. /*
  577. ** Re-enable collision for our host object
  578. */
  579. if (host_phys != NULL) {
  580. host_phys->Dec_Ignore_Counter();
  581. }
  582. }
  583. /*
  584. ** If we are not a moveable object, just set the transform.
  585. */
  586. if (Peek_Physical_Object()->As_MoveablePhysClass() == NULL) {
  587. Set_Transform(new_transform);
  588. ok = true;
  589. }
  590. /*
  591. ** Always reset the hibernation state
  592. */
  593. Reset_Hibernating();
  594. }
  595. }
  596. }
  597. void PhysicalGameObj::Post_Think( void )
  598. {
  599. if ( AnimControl != NULL ) {
  600. if ( AnimControl->Peek_Model() != Peek_Model() ) {
  601. Debug_Say(( "Anim control doesn't match Model\n" ));
  602. // For some reason??? some vehicles come in with an anim control, but no model in the anim control.
  603. if ( Get_Anim_Control() != NULL && Get_Anim_Control()->Peek_Model() == NULL ) {
  604. Get_Anim_Control()->Set_Model( Peek_Model() );
  605. }
  606. }
  607. // WWASSERT( AnimControl->Peek_Model() == Peek_Model() );
  608. }
  609. // Handle Pending Host
  610. if ( PendingHostObjID != 0 ) {
  611. Reset_Hibernating();
  612. HostGameObj = GameObjManager::Find_PhysicalGameObj( PendingHostObjID );
  613. Set_Object_Dirty_Bit( NetworkObjectClass::BIT_RARE, true );
  614. if ( HostGameObj.Get_Ptr() != NULL ) {
  615. // Debug_Say(( "Found Pending Host\n" ));
  616. PendingHostObjID = 0; // Fond em
  617. }
  618. }
  619. // If host bone controlled
  620. if ( HostGameObj.Get_Ptr() ) {
  621. Teleport_To_Host_Bone();
  622. }
  623. DamageableGameObj::Post_Think();
  624. WWPROFILE( "Physical PostThink" );
  625. if ( HibernationEnable && HibernationTimer > 0 ) {
  626. HibernationTimer -= TimeManager::Get_Frame_Seconds();
  627. if ( HibernationTimer <= 0 ) {
  628. Begin_Hibernation();
  629. // Debug_Say(( "Hibernate!!!\n" ));
  630. }
  631. }
  632. if ( AnimControl != NULL ) {
  633. bool anim_complete = AnimControl->Is_Complete();
  634. AnimControl->Update( TimeManager::Get_Frame_Seconds() ); // update the animation control
  635. if ( !anim_complete && AnimControl->Is_Complete() ) {
  636. // we just completed. Return Animation_Complete IF this is not a smart obj with animation action
  637. if ( As_SmartGameObj() == NULL || !As_SmartGameObj()->Get_Action()->Is_Animating() ) {
  638. const GameObjObserverList & observer_list = Get_Observers();
  639. for( int index = 0; index < observer_list.Count(); index++ ) {
  640. observer_list[ index ]->Animation_Complete( this, AnimControl->Get_Animation_Name() );
  641. }
  642. }
  643. }
  644. }
  645. #pragma message ("Going to hell on a client is problematic.")
  646. #ifndef PARAM_EDITING_ON //(gth) don't go to hell in the editor cause it will cause a crash!
  647. if (CombatManager::I_Am_Only_Client () == false && COMBAT_SCENE != NULL) {
  648. Vector3 pos;
  649. Get_Position(&pos);
  650. Vector3 min;
  651. Vector3 max;
  652. COMBAT_SCENE->Get_Level_Extents(min, max);
  653. if ( pos.Z < min.Z - 20.0f ) {
  654. Debug_Say(( "Object %d is going to hell at (%1.1f, %1.1f, %1.1f). Die!\n", Get_ID(), pos.X, pos.Y, pos.Z ));
  655. Set_Delete_Pending();
  656. }
  657. }
  658. #endif
  659. }
  660. void PhysicalGameObj::Set_Collision_Group( int group )
  661. {
  662. Peek_Physical_Object()->Set_Collision_Group( group );
  663. }
  664. void PhysicalGameObj::Attach_To_Object_Bone( PhysicalGameObj * host, const char * bone_name )
  665. {
  666. // Make sure we get teleported immeadiately!
  667. Teleport_To_Host_Bone();
  668. //
  669. // Zero the velocity of the object if we are detaching it from
  670. // the bone... (This makes physics behave better)
  671. //
  672. if (HostGameObj != host && host == NULL) {
  673. RigidBodyClass *rigid_body = Peek_Physical_Object()->As_RigidBodyClass();
  674. if (rigid_body != NULL) {
  675. Vector3 velocity;
  676. rigid_body->Get_Velocity (&velocity);
  677. Matrix3D curr_tm = rigid_body->Get_Transform ();
  678. float heading = curr_tm.Get_Z_Rotation ();
  679. Matrix3D new_tm (1);
  680. new_tm.Rotate_Z (heading);
  681. new_tm.Set_Translation (curr_tm.Get_Translation ());
  682. rigid_body->Set_Transform (new_tm);
  683. velocity.X = 0;
  684. velocity.Y = 0;
  685. velocity.Z = 0;
  686. rigid_body->Set_Velocity (velocity);
  687. rigid_body->Set_Angular_Velocity(velocity);
  688. }
  689. }
  690. HostGameObj = host;
  691. if ( host != NULL ) {
  692. WWASSERT( host->Peek_Model() );
  693. HostGameObjBone = host->Peek_Model()->Get_Bone_Index( bone_name );
  694. // Make sure we get teleported immeadiately!
  695. Teleport_To_Host_Bone();
  696. }
  697. //
  698. // "Dirty" the object for networking
  699. //
  700. Set_Object_Dirty_Bit( NetworkObjectClass::BIT_RARE, true );
  701. return ;
  702. }
  703. void PhysicalGameObj::Reset_Server_Skips(BYTE value)
  704. {
  705. ServerUpdateSkips = value;
  706. }
  707. void PhysicalGameObj::Increment_Server_Skips(void)
  708. {
  709. if (ServerUpdateSkips < 254) {
  710. ServerUpdateSkips++;
  711. }
  712. }
  713. //-----------------------------------------------------------------------------
  714. void PhysicalGameObj::Reset_Radar_Blip_Color_Type( void )
  715. {
  716. switch( Get_Player_Type() ) {
  717. case PLAYERTYPE_NOD: RadarBlipColorType = RadarManager::BLIP_COLOR_TYPE_NOD; break;
  718. case PLAYERTYPE_GDI: RadarBlipColorType = RadarManager::BLIP_COLOR_TYPE_GDI; break;
  719. case PLAYERTYPE_MUTANT: RadarBlipColorType = RadarManager::BLIP_COLOR_TYPE_MUTANT; break;
  720. case PLAYERTYPE_RENEGADE:RadarBlipColorType = RadarManager::BLIP_COLOR_TYPE_RENEGADE; break;
  721. default: RadarBlipColorType = RadarManager::BLIP_COLOR_TYPE_NEUTRAL; break;
  722. }
  723. }
  724. //-----------------------------------------------------------------------------
  725. /*
  726. **
  727. */
  728. void PhysicalGameObj::Set_Animation( const char *animation_name, bool looping, float frame_offset )
  729. {
  730. if ( AnimControl == NULL ) {
  731. Set_Anim_Control( new SimpleAnimControlClass ); // be sure we have a anim control
  732. }
  733. StringClass anim_name(animation_name,true);
  734. if ( !anim_name.Is_Empty() ) {
  735. // make sure it lead with model name
  736. if ( ::strchr( anim_name, '.' ) == NULL ) {
  737. Create_Animation_Name( anim_name, animation_name, Peek_Model()->Get_Name() );
  738. }
  739. AnimControl->Set_Model( Peek_Model() );
  740. AnimControl->Set_Animation( anim_name, 0, frame_offset );
  741. AnimControl->Set_Mode( looping ? ANIM_MODE_LOOP : ANIM_MODE_ONCE );
  742. // Force the object to start using the anim
  743. AnimControl->Update( 0 );
  744. //
  745. // "Dirty" the object for networking
  746. //
  747. Set_Object_Dirty_Bit( NetworkObjectClass::BIT_RARE, true );
  748. }
  749. }
  750. /*
  751. **
  752. */
  753. void PhysicalGameObj::Set_Animation_Frame ( const char *animation_name, int frame )
  754. {
  755. if ( AnimControl == NULL ) {
  756. Set_Anim_Control( new SimpleAnimControlClass ); // be sure we have a anim control
  757. }
  758. StringClass anim_name(animation_name,true);
  759. if ( !anim_name.Is_Empty() ) {
  760. // make sure it lead with model name
  761. if ( ::strchr( anim_name, '.' ) == NULL ) {
  762. Create_Animation_Name( anim_name, animation_name, Peek_Model()->Get_Name() );
  763. }
  764. AnimControl->Set_Model( Peek_Model() );
  765. AnimControl->Set_Animation( anim_name, 0 );
  766. AnimControl->Set_Mode( ANIM_MODE_STOP, frame );
  767. //
  768. // "Dirty" the object for networking
  769. //
  770. Set_Object_Dirty_Bit( NetworkObjectClass::BIT_RARE, true );
  771. }
  772. }
  773. /*
  774. **
  775. */
  776. void PhysicalGameObj::Set_Transform(const Matrix3D & tm)
  777. {
  778. WWASSERT(Peek_Physical_Object() != NULL);
  779. Peek_Physical_Object()->Set_Transform(tm);
  780. }
  781. const Matrix3D & PhysicalGameObj::Get_Transform(void) const
  782. {
  783. WWASSERT(Peek_Physical_Object() != NULL);
  784. return Peek_Physical_Object()->Get_Transform();
  785. }
  786. void PhysicalGameObj::Get_Position(Vector3 * set_pos) const
  787. {
  788. WWASSERT(Peek_Physical_Object() != NULL);
  789. Peek_Physical_Object()->Get_Position(set_pos);
  790. }
  791. void PhysicalGameObj::Set_Position(const Vector3 & pos)
  792. {
  793. WWASSERT(Peek_Physical_Object() != NULL);
  794. Peek_Physical_Object()->Set_Position(pos);
  795. }
  796. float PhysicalGameObj::Get_Facing(void) const
  797. {
  798. WWASSERT(Peek_Physical_Object() != NULL);
  799. return Peek_Physical_Object()->Get_Facing();
  800. }
  801. void PhysicalGameObj::Reset_Hibernating( void )
  802. {
  803. //
  804. // Notify the object that is has just finished hiibernating
  805. //
  806. if (Is_Hibernating ()) {
  807. End_Hibernation ();
  808. }
  809. HibernationTimer = MIN( HIBERNATION_DELAY, HibernationTimer + TimeManager::Get_Frame_Seconds() * 2 );
  810. }
  811. void PhysicalGameObj::Begin_Hibernation( void )
  812. {
  813. if (_DisplayHibernating) {
  814. Debug_Say(( "Object %d Hibernating\n", Get_ID() ));
  815. }
  816. }
  817. void PhysicalGameObj::End_Hibernation( void )
  818. {
  819. if (_DisplayHibernating) {
  820. Debug_Say(( "Object %d De-Hibernating\n", Get_ID() ));
  821. }
  822. }
  823. void PhysicalGameObj::Get_Information( StringClass & string )
  824. {
  825. StringClass temp;
  826. temp.Format( "%s\n", Get_Definition().Get_Name() );
  827. string += temp;
  828. temp.Format( "ID: %d\n", Get_ID() );
  829. string += temp;
  830. temp.Format( "Health: %d\n", (int)DefenseObject.Get_Health() );
  831. string += temp;
  832. if ( Is_Hibernating() ) {
  833. string += "HIBERNATING\n";
  834. }
  835. DamageableGameObj::Get_Information( string );
  836. }
  837. void PhysicalGameObj::Export_Creation( BitStreamClass &packet )
  838. {
  839. DamageableGameObj::Export_Creation( packet );
  840. //
  841. // Get the object's position and facing
  842. //
  843. Vector3 position (0, 0, 0);
  844. float facing = 0;
  845. Get_Position (&position);
  846. facing = Get_Facing ();
  847. //
  848. // Send the object's position
  849. //
  850. packet.Add( position.X, BITPACK_WORLD_POSITION_X );
  851. packet.Add( position.Y, BITPACK_WORLD_POSITION_Y );
  852. packet.Add( position.Z, BITPACK_WORLD_POSITION_Z );
  853. //
  854. // Send the object's facing
  855. //
  856. packet.Add( facing );
  857. /*
  858. //
  859. // Send the player type
  860. //
  861. int player_type = Get_Player_Type();
  862. packet.Add( player_type );
  863. */
  864. return ;
  865. }
  866. void PhysicalGameObj::Import_Creation( BitStreamClass &packet )
  867. {
  868. DamageableGameObj::Import_Creation( packet );
  869. //
  870. // Read the object's position
  871. //
  872. Vector3 position (0, 0, 0);
  873. packet.Get( position.X, BITPACK_WORLD_POSITION_X );
  874. packet.Get( position.Y, BITPACK_WORLD_POSITION_Y );
  875. packet.Get( position.Z, BITPACK_WORLD_POSITION_Z );
  876. //
  877. // Read the object's facing
  878. //
  879. float facing = 0;
  880. packet.Get( facing );
  881. //
  882. // Build a matrix from the position and facing, then set it
  883. //
  884. Matrix3D tm (1);
  885. tm.Translate (position);
  886. tm.Rotate_Z (facing);
  887. Set_Transform (tm);
  888. /*
  889. //
  890. // Get the player type from the packet
  891. //
  892. int player_type = 0;
  893. packet.Get( player_type );
  894. Set_Player_Type( player_type );
  895. */
  896. return ;
  897. }
  898. void PhysicalGameObj::Export_Rare( BitStreamClass &packet )
  899. {
  900. DamageableGameObj::Export_Rare( packet );
  901. //
  902. // Pass the model name across
  903. //
  904. WWASSERT(Peek_Physical_Object() != NULL);
  905. WWASSERT(Peek_Physical_Object()->Peek_Model() != NULL);
  906. //WWASSERT(Peek_Physical_Object()->Peek_Model()->Get_Name());
  907. const char *model_name = Peek_Physical_Object()->Peek_Model()->Get_Name();
  908. WWASSERT(model_name != NULL);
  909. WWASSERT(::strlen(model_name) < 256);
  910. packet.Add_Terminated_String( model_name, true );
  911. //
  912. // Get information about the animation
  913. //
  914. StringClass animation_name;
  915. int target_frame = 0;
  916. int curr_frame = 0;
  917. AnimMode anim_mode = ANIM_MODE_TARGET;
  918. if (AnimControl != NULL) {
  919. animation_name = AnimControl->Get_Animation_Name();
  920. target_frame = AnimControl->Get_Target_Frame ();
  921. curr_frame = AnimControl->Get_Current_Frame ();
  922. anim_mode = AnimControl->Get_Mode ();
  923. }
  924. //
  925. // Send the information to the client
  926. //
  927. packet.Add_Terminated_String( (const char *)animation_name, true );
  928. packet.Add( curr_frame );
  929. packet.Add( target_frame );
  930. packet.Add( anim_mode );
  931. //
  932. // Lookup the id of the host object
  933. //
  934. int host_model_id = 0;
  935. if (HostGameObj != NULL) {
  936. host_model_id = HostGameObj.Get_Ptr ()->Get_ID ();
  937. }
  938. //
  939. // Pass the host information across
  940. //
  941. packet.Add( host_model_id );
  942. packet.Add( HostGameObjBone );
  943. //
  944. // Send the player type
  945. //
  946. int player_type = Get_Player_Type();
  947. packet.Add( player_type );
  948. packet.Add( HUDPokableIndicatorEnabled );
  949. // We want to copy the hidden status for cinematics, (specefically, airstrip drops of vehicles)
  950. // but, we only want to change vehicles visibility
  951. if ( As_VehicleGameObj() != NULL ) {
  952. // Send hidden
  953. bool hidden = false;
  954. if ( Peek_Model() ) {
  955. hidden = !!(Peek_Model()->Is_Hidden());
  956. }
  957. packet.Add( hidden );
  958. }
  959. return ;
  960. }
  961. void PhysicalGameObj::Import_Rare( BitStreamClass &packet )
  962. {
  963. DamageableGameObj::Import_Rare( packet );
  964. //
  965. // Get the model name
  966. //
  967. StringClass model_name;
  968. packet.Get_Terminated_String( model_name.Get_Buffer( 256 ), 256, true );
  969. //
  970. // Set the new model (if necessary)
  971. //
  972. const char *old_model_name = Peek_Physical_Object()->Peek_Model()->Get_Name();
  973. if ( model_name.Compare_No_Case (old_model_name) != 0 ) {
  974. Peek_Physical_Object()->Set_Model_By_Name( model_name );
  975. }
  976. //
  977. // Get information about the animation
  978. //
  979. StringClass animation_name;
  980. int target_frame = 0;
  981. int curr_frame = 0;
  982. int anim_mode = ANIM_MODE_TARGET;
  983. packet.Get_Terminated_String( animation_name.Get_Buffer( 256 ), 256, true );
  984. packet.Get( curr_frame );
  985. packet.Get( target_frame );
  986. packet.Get( anim_mode );
  987. //
  988. // Pass the animation information onto the controller
  989. //
  990. if (AnimControl != NULL) {
  991. AnimControl->Set_Animation( animation_name, 0, curr_frame );
  992. AnimControl->Set_Target_Frame( target_frame );
  993. AnimControl->Set_Mode( (AnimMode)anim_mode );
  994. }
  995. //
  996. // Get the host information
  997. //
  998. int host_model_id = 0;
  999. packet.Get( host_model_id );
  1000. packet.Get( HostGameObjBone );
  1001. //
  1002. // Change the host object
  1003. //
  1004. PendingHostObjID = 0; // Assume no pending
  1005. if ( host_model_id != 0 ) {
  1006. HostGameObj = GameObjManager::Find_PhysicalGameObj( host_model_id );
  1007. if ( HostGameObj.Get_Ptr() == NULL ) {
  1008. PendingHostObjID = host_model_id; // Pending Host
  1009. Reset_Hibernating();
  1010. }
  1011. } else {
  1012. HostGameObj = NULL;
  1013. }
  1014. //
  1015. // Get the player type from the packet
  1016. //
  1017. int player_type = packet.Get( player_type );
  1018. Set_Player_Type( player_type );
  1019. HUDPokableIndicatorEnabled = packet.Get( HUDPokableIndicatorEnabled );
  1020. if ( As_VehicleGameObj() != NULL ) {
  1021. // Get Hidden
  1022. bool hidden = packet.Get( hidden );
  1023. if ( Peek_Model() ) {
  1024. Peek_Model()->Set_Hidden( hidden );
  1025. }
  1026. }
  1027. return ;
  1028. }
  1029. void PhysicalGameObj::Export_Frequent( BitStreamClass &packet )
  1030. {
  1031. bool on_host_bone = false;
  1032. if ( HostGameObj.Get_Ptr() ) {
  1033. RenderObjClass * model = ((PhysicalGameObj * )(HostGameObj.Get_Ptr()))->Peek_Model();
  1034. on_host_bone = ( model != NULL );
  1035. }
  1036. packet.Add(on_host_bone);
  1037. }
  1038. void PhysicalGameObj::Import_Frequent( BitStreamClass &packet )
  1039. {
  1040. bool on_host_bone;
  1041. packet.Get(on_host_bone);
  1042. if ( (on_host_bone) &&
  1043. (Peek_Physical_Object()) &&
  1044. (Peek_Physical_Object()->As_MoveablePhysClass()) )
  1045. {
  1046. MoveablePhysClass * movephys = Peek_Physical_Object()->As_MoveablePhysClass();
  1047. movephys->Set_Velocity(Vector3(0,0,0));
  1048. }
  1049. }
  1050. /*
  1051. **
  1052. */
  1053. void PhysicalGameObj::Set_Conversation( ActiveConversationClass *conversation )
  1054. {
  1055. REF_PTR_SET (ActiveConversation, conversation);
  1056. return ;
  1057. }
  1058. /*
  1059. **
  1060. */
  1061. void PhysicalGameObj::Hide_Muzzle_Flashes( bool hide )
  1062. {
  1063. RenderObjClass * model = Peek_Model();
  1064. if ( model ) {
  1065. for (int i=0; i<model->Get_Num_Sub_Objects(); i++) {
  1066. RenderObjClass * robj = model->Get_Sub_Object(i);
  1067. if (strstr(robj->Get_Name(),"MUZZLEFLASH") || strstr(robj->Get_Name(),"MZ")) {
  1068. robj->Set_Hidden( hide );
  1069. }
  1070. robj->Release_Ref();
  1071. }
  1072. }
  1073. }
  1074. /*
  1075. ** Get_Vis_ID - return the vis id for this object
  1076. */
  1077. int PhysicalGameObj::Get_Vis_ID ()
  1078. {
  1079. PhysClass *phys_obj = Peek_Physical_Object ();
  1080. //
  1081. // Do we have a physics object we can use?
  1082. //
  1083. if (phys_obj != NULL) {
  1084. return phys_obj->Get_Vis_Object_ID();
  1085. }
  1086. return -1;
  1087. }
  1088. void PhysicalGameObj::Set_Player_Type(int id)
  1089. {
  1090. DamageableGameObj::Set_Player_Type(id);
  1091. Reset_Radar_Blip_Color_Type();
  1092. }
  1093. /*
  1094. if (Is_Team_Player()) {
  1095. //
  1096. // Handle tinting for soldiers, pedestals, flags
  1097. //
  1098. if ( stricmp( Get_Definition().Get_Name(), "CtfFlag" ) == 0 ||
  1099. stricmp( Get_Definition().Get_Name(), "CtfPedestal" ) == 0)
  1100. {
  1101. Set_Tint( Get_Team_Color() );
  1102. }
  1103. }
  1104. */
  1105. //-----------------------------------------------------------------------------
  1106. /*
  1107. void Tint(RenderObjClass *robj, const Vector3 & color)
  1108. {
  1109. // Debug_Say(( "%s has %d sub objs\n", robj->Get_Name(), robj->Get_Num_Sub_Objects() ));
  1110. for( int so = 0; so < robj->Get_Num_Sub_Objects(); so++ ) {
  1111. RenderObjClass *child = robj->Get_Sub_Object( so );
  1112. Tint(child, color);
  1113. child->Release_Ref();
  1114. }
  1115. // Tint the commando body
  1116. MaterialInfoClass * matinfo = robj->Get_Material_Info();
  1117. if ( matinfo ) {
  1118. for ( int vm = 0; vm < matinfo->Vertex_Material_Count(); vm++ ) {
  1119. VertexMaterialClass *vertmat = matinfo->Peek_Vertex_Material(vm);
  1120. // Debug_Say(( "VM %p %s\n", vertmat, vertmat->Get_Name() ));
  1121. // if (1) {// !strnicmp( vertmat->Get_Name(), "tintt", 5 ) ) {
  1122. vertmat->Set_Diffuse( color[0], color[1], color[2] );
  1123. vertmat->Set_Ambient( color[0], color[1], color[2] );
  1124. // }
  1125. }
  1126. matinfo->Release_Ref();
  1127. }
  1128. }
  1129. //-----------------------------------------------------------------------------
  1130. void PhysicalGameObj::Set_Tint(Vector3 color)
  1131. {
  1132. if (TintColor != color && Peek_Model() != NULL) {
  1133. Tint(Peek_Model(), color);
  1134. TintColor = color;
  1135. }
  1136. }
  1137. */
  1138. void PhysicalGameObj::Enable_HUD_Pokable_Indicator( bool enable )
  1139. {
  1140. HUDPokableIndicatorEnabled = enable;
  1141. Set_Object_Dirty_Bit( NetworkObjectClass::BIT_RARE, true );
  1142. }
  1143. void PhysicalGameObj::Object_Shattered_Something
  1144. (
  1145. PhysClass * observed_obj,
  1146. PhysClass * shattered_obj,
  1147. int surface_type
  1148. )
  1149. {
  1150. const Matrix3D & tm = observed_obj->Get_Transform();
  1151. SurfaceEffectsManager::Apply_Effect( surface_type,
  1152. SurfaceEffectsManager::HITTER_TYPE_BULLET,
  1153. tm,
  1154. NULL,
  1155. NULL,
  1156. false, // no decals
  1157. false // no emitter
  1158. );
  1159. }