| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561 |
- /*
- ** 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/>.
- */
- /***********************************************************************************************
- *** Confidential - Westwood Studios ***
- ***********************************************************************************************
- * *
- * Project Name : Commando *
- * *
- * $Archive:: /Commando/Code/Combat/warfactorygameobj.cpp $Author:: Patrick $*
- * *
- * $Modtime:: 1/07/02 4:46p $*
- * *
- * $Revision:: 15 $*
- * *
- *---------------------------------------------------------------------------------------------*
- * Functions: *
- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
- #include "warfactorygameobj.h"
- #include "basecontroller.h"
- #include "vehicle.h"
- #include "wwhack.h"
- #include "simpledefinitionfactory.h"
- #include "persistfactory.h"
- #include "definitionmgr.h"
- #include "combatchunkid.h"
- #include "debug.h"
- #include "scriptzone.h"
- #include "wwprofile.h"
- #include "basecontroller.h"
- #include "combatchunkid.h"
- #include "hanim.h"
- #include "vehiclephys.h"
- ////////////////////////////////////////////////////////////////
- // Hacks
- ////////////////////////////////////////////////////////////////
- DECLARE_FORCE_LINK (WarFactory)
- ////////////////////////////////////////////////////////////////
- // Editable and persist factories
- ////////////////////////////////////////////////////////////////
- SimplePersistFactoryClass <WarFactoryGameObjDef, CHUNKID_GAME_OBJECT_DEF_WARFACTORY> _WarFactoryGameObjDefPersistFactory;
- SimplePersistFactoryClass <WarFactoryGameObj, CHUNKID_GAME_OBJECT_WARFACTORY> _WarFactoryGameObjPersistFactory;
- DECLARE_DEFINITION_FACTORY (WarFactoryGameObjDef, CLASSID_GAME_OBJECT_DEF_WARFACTORY, "WarFactory") _WarFactoryGameObjDefDefFactory;
- ////////////////////////////////////////////////////////////////
- // Constants
- ////////////////////////////////////////////////////////////////
- float UNITIALIZED_TIMER = -100.0F;
- const float WARFACTORY_LOCK_TIME = 26.0f;
- ////////////////////////////////////////////////////////////////
- // Save/Load constants
- ////////////////////////////////////////////////////////////////
- enum
- {
- CHUNKID_DEF_PARENT = 0x02200638,
- CHUNKID_DEF_VARIABLES,
- MICROCHUNKID_DEF_UNUSED = 1,
- };
- enum
- {
- CHUNKID_PARENT = 0x0219043,
- CHUNKID_VARIABLES,
- MICROCHUNKID_UNUSED = 1,
- };
- ////////////////////////////////////////////////////////////////
- //
- // WarFactoryGameObjDef
- //
- ////////////////////////////////////////////////////////////////
- WarFactoryGameObjDef::WarFactoryGameObjDef (void)
- {
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // ~WarFactoryGameObjDef
- //
- ////////////////////////////////////////////////////////////////
- WarFactoryGameObjDef::~WarFactoryGameObjDef (void)
- {
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Get_Class_ID
- //
- ////////////////////////////////////////////////////////////////
- uint32
- WarFactoryGameObjDef::Get_Class_ID (void) const
- {
- return CLASSID_GAME_OBJECT_DEF_WARFACTORY;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Create
- //
- ////////////////////////////////////////////////////////////////
- PersistClass *
- WarFactoryGameObjDef::Create (void) const
- {
- WarFactoryGameObj *building = new WarFactoryGameObj;
- building->Init (*this);
- return building;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Create
- //
- ////////////////////////////////////////////////////////////////
- bool
- WarFactoryGameObjDef::Save (ChunkSaveClass &csave)
- {
- csave.Begin_Chunk (CHUNKID_DEF_PARENT);
- VehicleFactoryGameObjDef::Save (csave);
- csave.End_Chunk ();
- csave.Begin_Chunk (CHUNKID_DEF_VARIABLES);
- csave.End_Chunk ();
- return true;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Load
- //
- ////////////////////////////////////////////////////////////////
- bool
- WarFactoryGameObjDef::Load (ChunkLoadClass &cload)
- {
- while (cload.Open_Chunk ())
- {
- switch (cload.Cur_Chunk_ID ())
- {
- case CHUNKID_DEF_PARENT:
- VehicleFactoryGameObjDef::Load (cload);
- break;
- case CHUNKID_DEF_VARIABLES:
- Load_Variables (cload);
- break;
-
- default:
- Debug_Say (("Unrecognized WarFactory Def chunkID\n"));
- break;
- }
- cload.Close_Chunk ();
- }
- return true;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Load_Variables
- //
- ////////////////////////////////////////////////////////////////
- void
- WarFactoryGameObjDef::Load_Variables (ChunkLoadClass &cload)
- {
- while (cload.Open_Micro_Chunk ()) {
- /*switch (cload.Cur_Micro_Chunk_ID ())
- {
- default:
- Debug_Say (("Unrecognized WarFactory Def Variable chunkID\n"));
- break;
- }*/
- cload.Close_Micro_Chunk();
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Get_Factory
- //
- ////////////////////////////////////////////////////////////////
- const PersistFactoryClass &
- WarFactoryGameObjDef::Get_Factory (void) const
- {
- return _WarFactoryGameObjDefPersistFactory;
- }
- ////////////////////////////////////////////////////////////////
- //
- // WarFactoryGameObj
- //
- ////////////////////////////////////////////////////////////////
- WarFactoryGameObj::WarFactoryGameObj (void) :
- CreationAnimationID (0),
- CreationFinishedTimer (UNITIALIZED_TIMER)
- {
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // ~WarFactoryGameObj
- //
- ////////////////////////////////////////////////////////////////
- WarFactoryGameObj::~WarFactoryGameObj (void)
- {
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Get_Factory
- //
- ////////////////////////////////////////////////////////////////
- const PersistFactoryClass &
- WarFactoryGameObj::Get_Factory (void) const
- {
- return _WarFactoryGameObjPersistFactory;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Init
- //
- ////////////////////////////////////////////////////////////////
- void WarFactoryGameObj::Init( void )
- {
- Init( Get_Definition() );
- }
- ////////////////////////////////////////////////////////////////
- //
- // Init
- //
- ////////////////////////////////////////////////////////////////
- void
- WarFactoryGameObj::Init (const WarFactoryGameObjDef &definition)
- {
- VehicleFactoryGameObj::Init (definition);
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Get_Definition
- //
- ////////////////////////////////////////////////////////////////
- const WarFactoryGameObjDef &
- WarFactoryGameObj::Get_Definition (void) const
- {
- return (const WarFactoryGameObjDef &)BaseGameObj::Get_Definition ();
- }
- ////////////////////////////////////////////////////////////////
- //
- // Save
- //
- ////////////////////////////////////////////////////////////////
- bool
- WarFactoryGameObj::Save (ChunkSaveClass &csave)
- {
- csave.Begin_Chunk (CHUNKID_PARENT);
- VehicleFactoryGameObj::Save (csave);
- csave.End_Chunk ();
- csave.Begin_Chunk (CHUNKID_VARIABLES);
- csave.End_Chunk ();
- return true;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Load
- //
- ////////////////////////////////////////////////////////////////
- bool
- WarFactoryGameObj::Load (ChunkLoadClass &cload)
- {
- while (cload.Open_Chunk ()) {
- switch (cload.Cur_Chunk_ID ()) {
- case CHUNKID_PARENT:
- VehicleFactoryGameObj::Load (cload);
- break;
-
- case CHUNKID_VARIABLES:
- Load_Variables (cload);
- break;
- default:
- Debug_Say (("Unrecognized WarFactory chunkID\n"));
- break;
- }
- cload.Close_Chunk();
- }
- return true;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Load_Variables
- //
- ////////////////////////////////////////////////////////////////
- void
- WarFactoryGameObj::Load_Variables (ChunkLoadClass &cload)
- {
- while (cload.Open_Micro_Chunk ()) {
-
- /*switch (cload.Cur_Micro_Chunk_ID ())
- {
- default:
- Debug_Say (("Unrecognized WarFactory Variable chunkID\n"));
- break;
- }*/
- cload.Close_Micro_Chunk();
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // CnC_Initialize
- //
- ////////////////////////////////////////////////////////////////
- void
- WarFactoryGameObj::CnC_Initialize (BaseControllerClass *base)
- {
- VehicleFactoryGameObj::CnC_Initialize (base);
- //
- // Get the building's "position"
- //
- Vector3 pos;
- Get_Position (&pos);
- //
- // Find the closest creation static anim phys
- //
- float closest2 = 99999.0F;
- RefPhysListIterator iterator = PhysicsSceneClass::Get_Instance()->Get_Static_Object_Iterator ();
- for (iterator.First (); !iterator.Is_Done (); iterator.Next ()) {
- StaticAnimPhysClass *anim_phys_obj = iterator.Peek_Obj ()->As_StaticAnimPhysClass ();
-
- //
- // Is this a vehicle creation static anim phys?
- //
- if (anim_phys_obj != NULL && anim_phys_obj->Peek_Model () != NULL) {
- StringClass name = anim_phys_obj->Peek_Model ()->Get_Name ();
- ::strupr (name.Peek_Buffer ());
- if (::strstr (name, "WEP#CONSTRUCT") != NULL) {
- //
- // Is this the closest one we've found so far?
- //
- Vector3 anim_pos;
- anim_phys_obj->Get_Position (&anim_pos);
- float dist2 = (anim_pos - pos).Length2 ();
- if (dist2 < closest2) {
- closest2 = dist2;
- CreationAnimationID = anim_phys_obj->Get_ID ();
- }
- }
- }
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Think
- //
- ////////////////////////////////////////////////////////////////
- void
- WarFactoryGameObj::Think (void)
- {
- WWPROFILE ("WarFactory Think");
- //
- // Are we currently building a vehicle?
- //
- if (IsDestroyed == false && GeneratingVehicleID != 0) {
- if (CreationFinishedTimer > UNITIALIZED_TIMER) {
- CreationFinishedTimer -= TimeManager::Get_Frame_Seconds ();
-
- if (CreationFinishedTimer <= 0) {
-
- CreationFinishedTimer = UNITIALIZED_TIMER;
-
- //
- // Generate the current vehicle
- //
- VehicleGameObj *vehicle = Create_Vehicle ();
- if (vehicle != NULL) {
-
- Matrix3D new_tm = CreationTM;
- //
- // Adjust the vehicle's transform to ensure its
- // not embedded in the ground
- //
- if (vehicle->Peek_Vehicle_Phys() != NULL) {
- float height = vehicle->Peek_Vehicle_Phys()->Compute_Approximate_Ride_Height();
- new_tm.Translate(0.0f,0.0f,height);
- vehicle->Set_Transform(new_tm);
- }
- //
- // Lock the vehicle to anyone but the purchaser
- //
- if (Purchaser != NULL) {
- vehicle->Lock_Vehicle(Purchaser,WARFACTORY_LOCK_TIME);
- }
- //
- // Destroy any game object that's in our way
- //
- Destroy_Blocking_Objects ();
- // Tell the vehicle to drive to one of the delivery points
- Deliver_Vehicle();
- }
- //
- // Now play the creation animation backwards to restore the
- // state of the factory
- //
- Play_Creation_Animation (false);
- }
- }
- }
- VehicleFactoryGameObj::Think ();
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Play_Creation_Animation
- //
- ////////////////////////////////////////////////////////////////
- void
- WarFactoryGameObj::Play_Creation_Animation (bool onoff)
- {
- //
- // Lookup the static animation object we need to play
- //
- StaticPhysClass *static_phys_obj = PhysicsSceneClass::Get_Instance ()->Find_Static_Object (CreationAnimationID);
- if (static_phys_obj != NULL) {
- StaticAnimPhysClass *anim_phys_obj = static_phys_obj->As_StaticAnimPhysClass ();
- if (anim_phys_obj != NULL) {
-
- //
- // Configure the animation
- //
- AnimCollisionManagerClass &anim_mgr = anim_phys_obj->Get_Animation_Manager ();
- anim_mgr.Set_Animation_Mode (AnimCollisionManagerClass::ANIMATE_TARGET);
-
- //
- // Either play the animation forward or backward
- //
- if (onoff) {
- anim_mgr.Set_Target_Frame_End ();
- } else {
- anim_mgr.Set_Target_Frame (0);
- }
- static_phys_obj->Enable_Is_State_Dirty(true);
- }
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Begin_Generation
- //
- ////////////////////////////////////////////////////////////////
- void
- WarFactoryGameObj::Begin_Generation (void)
- {
- Play_Creation_Animation (true);
- CreationFinishedTimer = 2.0F;
- //
- // Lookup the static animation object for the ending animation
- //
- StaticPhysClass *static_phys_obj = PhysicsSceneClass::Get_Instance ()->Find_Static_Object (CreationAnimationID);
- if (static_phys_obj != NULL) {
- StaticAnimPhysClass *anim_phys_obj = static_phys_obj->As_StaticAnimPhysClass ();
- if (anim_phys_obj != NULL) {
-
- //
- // Calculate how long to wait before we start playing the end animations
- //
- AnimCollisionManagerClass &anim_mgr = anim_phys_obj->Get_Animation_Manager ();
- CreationFinishedTimer = anim_mgr.Peek_Animation ()->Get_Total_Time () + 2.0f;
- }
- }
- return ;
- }
|