| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497 |
- /*
- ** Command & Conquer Renegade(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 O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
- ***********************************************************************************************
- * *
- * Project Name : Combat *
- * *
- * $Archive:: /Commando/Code/Combat/specialeffectsgameobj.cpp $*
- * *
- * Author:: Patrick Smith *
- * *
- * $Modtime:: 1/15/02 2:33p $*
- * *
- * $Revision:: 6 $*
- * *
- *---------------------------------------------------------------------------------------------*
- * Functions: *
- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
- #include "specialeffectsgameobj.h"
- #include "combatchunkid.h"
- #include "wwaudio.h"
- #include "hanim.h"
- #include "assetmgr.h"
- #include "wwhack.h"
- #include "persistfactory.h"
- #include "simpledefinitionfactory.h"
- #include "chunkio.h"
- #include "rendobj.h"
- #include "timemgr.h"
- #include "debug.h"
- #include "phys.h"
- #include "combat.h"
- #include "wwprofile.h"
- DECLARE_FORCE_LINK (SpecialEffects)
- ///////////////////////////////////////////////////////////////////////////
- // Persist and Editable framework support
- ///////////////////////////////////////////////////////////////////////////
- SimplePersistFactoryClass <SpecialEffectsGameObj, CHUNKID_GAME_OBJECT_SPECIAL_EFFECTS> _SpecialEffectsGameObjPersistFactory;
- SimplePersistFactoryClass <SpecialEffectsGameObjDef, CHUNKID_GAME_OBJECT_DEF_SPECIAL_EFFECTS> _SpecialEffectsGameObjDefPersistFactory;
- DECLARE_DEFINITION_FACTORY (SpecialEffectsGameObjDef, CLASSID_GAME_OBJECT_DEF_SPECIAL_EFFECTS, "Special Effects") _SpecialEffectsGameObjDefDefFactory;
- ///////////////////////////////////////////////////////////////////////////
- // Constants
- ///////////////////////////////////////////////////////////////////////////
- enum
- {
- CHUNKID_DEF_PARENT = 0x09010212,
- CHUNKID_DEF_VARIABLES,
- VARID_DEF_ANIMATION_NAME = 1,
- VARID_DEF_SOUNDID,
- };
- enum
- {
- CHUNKID_PARENT = 0x09010236,
- CHUNKID_VARIABLES,
- VARID_LIFE_REMAINING = 1,
- VARID_IS_INITIALIZED
- };
- ///////////////////////////////////////////////////////////////////////////
- //
- // SpecialEffectsGameObjDef
- //
- ///////////////////////////////////////////////////////////////////////////
- SpecialEffectsGameObjDef::SpecialEffectsGameObjDef (void) :
- SoundDefID (0)
- {
- MODEL_DEF_PARAM(SpecialEffectsGameObjDef, PhysDefID, "TimedDecorationPhysDef");
- EDITABLE_PARAM (SpecialEffectsGameObjDef, ParameterClass::TYPE_STRING, AnimationName);
- EDITABLE_PARAM (SpecialEffectsGameObjDef, ParameterClass::TYPE_SOUNDDEFINITIONID, SoundDefID);
- return ;
- }
- ///////////////////////////////////////////////////////////////////////////
- //
- // ~SpecialEffectsGameObjDef
- //
- ///////////////////////////////////////////////////////////////////////////
- SpecialEffectsGameObjDef::~SpecialEffectsGameObjDef (void)
- {
- return ;
- }
- ///////////////////////////////////////////////////////////////////////////
- //
- // Get_Class_ID
- //
- ///////////////////////////////////////////////////////////////////////////
- uint32
- SpecialEffectsGameObjDef::Get_Class_ID (void) const
- {
- return CLASSID_GAME_OBJECT_DEF_SPECIAL_EFFECTS;
- }
- ///////////////////////////////////////////////////////////////////////////
- //
- // Create
- //
- ///////////////////////////////////////////////////////////////////////////
- PersistClass *
- SpecialEffectsGameObjDef::Create (void) const
- {
- SpecialEffectsGameObj *obj = new SpecialEffectsGameObj;
- obj->Init (*this);
- return obj;
- }
- ///////////////////////////////////////////////////////////////////////////
- //
- // Save
- //
- ///////////////////////////////////////////////////////////////////////////
- bool
- SpecialEffectsGameObjDef::Save (ChunkSaveClass &csave)
- {
- csave.Begin_Chunk (CHUNKID_DEF_PARENT);
- PhysicalGameObjDef::Save (csave);
- csave.End_Chunk ();
- csave.Begin_Chunk (CHUNKID_DEF_VARIABLES);
- Save_Variables (csave);
- csave.End_Chunk ();
- return true;
- }
- ///////////////////////////////////////////////////////////////////////////
- //
- // Load
- //
- ///////////////////////////////////////////////////////////////////////////
- bool
- SpecialEffectsGameObjDef::Load (ChunkLoadClass &cload)
- {
- while (cload.Open_Chunk ()) {
- switch(cload.Cur_Chunk_ID ()) {
- case CHUNKID_DEF_PARENT:
- PhysicalGameObjDef::Load (cload);
- break;
- case CHUNKID_DEF_VARIABLES:
- Load_Variables (cload);
- break;
-
- default:
- Debug_Say (("Unrecognized SpecialEffectsGameObjDef chunk ID\n"));
- break;
- }
- cload.Close_Chunk ();
- }
- return true;
- }
- ///////////////////////////////////////////////////////////////////////////
- //
- // Save_Variables
- //
- ///////////////////////////////////////////////////////////////////////////
- void
- SpecialEffectsGameObjDef::Save_Variables (ChunkSaveClass &csave)
- {
- WRITE_MICRO_CHUNK_WWSTRING (csave, VARID_DEF_ANIMATION_NAME, AnimationName);
- WRITE_MICRO_CHUNK (csave, VARID_DEF_SOUNDID, SoundDefID);
- return ;
- }
- ///////////////////////////////////////////////////////////////////////////
- //
- // Load_Variables
- //
- ///////////////////////////////////////////////////////////////////////////
- void
- SpecialEffectsGameObjDef::Load_Variables (ChunkLoadClass &cload)
- {
- while (cload.Open_Micro_Chunk()) {
- switch (cload.Cur_Micro_Chunk_ID()) {
- READ_MICRO_CHUNK_WWSTRING (cload, VARID_DEF_ANIMATION_NAME, AnimationName);
- READ_MICRO_CHUNK (cload, VARID_DEF_SOUNDID, SoundDefID);
-
- default:
- Debug_Say (("Unrecognized SpecialEffectsGameObjDef Variable chunkID %d\n", cload.Cur_Micro_Chunk_ID ()));
- break;
- }
- cload.Close_Micro_Chunk ();
- }
- return ;
- }
- ///////////////////////////////////////////////////////////////////////////
- //
- // Get_Factory
- //
- ///////////////////////////////////////////////////////////////////////////
- const PersistFactoryClass &
- SpecialEffectsGameObjDef::Get_Factory (void) const
- {
- return _SpecialEffectsGameObjDefPersistFactory;
- }
- /*
- **
- ** Start of SpecialEffectsGameObj
- **
- */
- ///////////////////////////////////////////////////////////////////////////
- //
- // SpecialEffectsGameObj
- //
- ///////////////////////////////////////////////////////////////////////////
- SpecialEffectsGameObj::SpecialEffectsGameObj (void) :
- LifeRemaining (-1.0F),
- IsInitialized (false)
- {
- return ;
- }
- ///////////////////////////////////////////////////////////////////////////
- //
- // ~SpecialEffectsGameObj
- //
- ///////////////////////////////////////////////////////////////////////////
- SpecialEffectsGameObj::~SpecialEffectsGameObj (void)
- {
- return ;
- }
- ///////////////////////////////////////////////////////////////////////////
- //
- // Get_Factory
- //
- ///////////////////////////////////////////////////////////////////////////
- const PersistFactoryClass &
- SpecialEffectsGameObj::Get_Factory (void) const
- {
- return _SpecialEffectsGameObjPersistFactory;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Init
- //
- ////////////////////////////////////////////////////////////////
- void SpecialEffectsGameObj::Init( void )
- {
- Init( Get_Definition() );
- }
- ///////////////////////////////////////////////////////////////////////////
- //
- // Init
- //
- ///////////////////////////////////////////////////////////////////////////
- void
- SpecialEffectsGameObj::Init (const SpecialEffectsGameObjDef &definition)
- {
- PhysicalGameObj::Init (definition);
- //
- // Make sure collisions are turned off on this effect
- //
- PhysClass *phys_obj = Peek_Physical_Object();
- if (phys_obj != NULL) {
- phys_obj->Set_Collision_Group( UNCOLLIDEABLE_GROUP );
- }
-
- return ;
- }
- ///////////////////////////////////////////////////////////////////////////
- //
- // Get_Definition
- //
- ///////////////////////////////////////////////////////////////////////////
- const SpecialEffectsGameObjDef &
- SpecialEffectsGameObj::Get_Definition (void) const
- {
- return (const SpecialEffectsGameObjDef &)BaseGameObj::Get_Definition();
- }
- ///////////////////////////////////////////////////////////////////////////
- //
- // Save
- //
- ///////////////////////////////////////////////////////////////////////////
- bool
- SpecialEffectsGameObj::Save (ChunkSaveClass & csave)
- {
- csave.Begin_Chunk (CHUNKID_PARENT);
- PhysicalGameObj::Save (csave);
- csave.End_Chunk ();
- csave.Begin_Chunk (CHUNKID_VARIABLES);
- Save_Variables (csave);
- csave.End_Chunk ();
- return true;
- }
- ///////////////////////////////////////////////////////////////////////////
- //
- // Load
- //
- ///////////////////////////////////////////////////////////////////////////
- bool
- SpecialEffectsGameObj::Load (ChunkLoadClass &cload)
- {
- while (cload.Open_Chunk ()) {
- switch(cload.Cur_Chunk_ID ()) {
- case CHUNKID_PARENT:
- PhysicalGameObj::Load (cload);
- break;
- case CHUNKID_VARIABLES:
- Load_Variables (cload);
- break;
- default:
- Debug_Say (("Unrecognized SpecialEffectsGameObj chunk ID\n"));
- break;
- }
- cload.Close_Chunk ();
- }
- return true;
- }
- ///////////////////////////////////////////////////////////////////////////
- //
- // Do_Effect
- //
- ///////////////////////////////////////////////////////////////////////////
- void
- SpecialEffectsGameObj::Do_Effect (void)
- {
- //
- // Make sure we have a render object
- //
- RenderObjClass *model = Peek_Model ();
- WWASSERT (model != NULL);
- if (model != NULL) {
- //
- // Should we play an animation?
- //
- const StringClass &anim_name = Get_Definition ().AnimationName;
- if (anim_name.Get_Length () > 0) {
-
- //
- // Load the animation
- //
- HAnimClass *animation = WW3DAssetManager::Get_Instance ()->Get_HAnim (anim_name);
- if (animation != NULL) {
- LifeRemaining = animation->Get_Total_Time ();
- model->Set_Animation (animation, 0, RenderObjClass::ANIM_MODE_ONCE);
- REF_PTR_RELEASE(animation);
- }
- }
- //
- // Should we play a sound?
- //
- if (Get_Definition ().SoundDefID > 0) {
- WWAudioClass::Get_Instance()->Create_Instant_Sound (Get_Definition ().SoundDefID, Get_Transform ());
- }
- }
- return ;
- }
- ///////////////////////////////////////////////////////////////////////////
- //
- // Save_Variables
- //
- ///////////////////////////////////////////////////////////////////////////
- void
- SpecialEffectsGameObj::Save_Variables (ChunkSaveClass &csave)
- {
- WRITE_MICRO_CHUNK (csave, VARID_LIFE_REMAINING, LifeRemaining);
- WRITE_MICRO_CHUNK (csave, VARID_IS_INITIALIZED, IsInitialized);
- return ;
- }
- ///////////////////////////////////////////////////////////////////////////
- //
- // Load_Variables
- //
- ///////////////////////////////////////////////////////////////////////////
- void
- SpecialEffectsGameObj::Load_Variables (ChunkLoadClass &cload)
- {
- while (cload.Open_Micro_Chunk()) {
- switch (cload.Cur_Micro_Chunk_ID()) {
- READ_MICRO_CHUNK (cload, VARID_LIFE_REMAINING, LifeRemaining);
- READ_MICRO_CHUNK (cload, VARID_IS_INITIALIZED, IsInitialized);
-
- default:
- Debug_Say (("Unrecognized SpecialEffectsGameObj Variable chunkID %d\n", cload.Cur_Micro_Chunk_ID ()));
- break;
- }
- cload.Close_Micro_Chunk ();
- }
- return ;
- }
- ///////////////////////////////////////////////////////////////////////////
- //
- // Think
- //
- ///////////////////////////////////////////////////////////////////////////
- void
- SpecialEffectsGameObj::Think (void)
- {
- WWPROFILE( "SpecialEffects Think" );
- //
- // Kick off the special effect
- //
- if (IsInitialized == false) {
- Do_Effect ();
- IsInitialized = true;
- }
- //
- // Check to see if we should make ourselves go away
- //
- if (LifeRemaining >= 0) {
- LifeRemaining -= TimeManager::Get_Frame_Seconds ();
- if (LifeRemaining <= 0) {
- Set_Delete_Pending ();
- }
- }
-
- return ;
- }
|