| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410 |
- /*
- ** 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 : LevelEdit *
- * *
- * $Archive:: /Commando/Code/Combat/dialogue.cpp $*
- * *
- * Author:: Patrick Smith *
- * *
- * $Modtime:: 9/14/01 12:10p $*
- * *
- * $Revision:: 6 $*
- * *
- *---------------------------------------------------------------------------------------------*
- * Functions: *
- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
- #include "dialogue.h"
- #include "chunkio.h"
- #include "wwmath.h"
- ////////////////////////////////////////////////////////////////
- // Constants
- ////////////////////////////////////////////////////////////////
- enum
- {
- CHUNKID_OPTION_VARIABLES = 0x08040528,
- CHUNKID_DIALOGUE_VARIABLES = 0x08040529,
- CHUNKID_DIALOGUE_OPTION
- };
- enum
- {
- VARID_WEIGHT = 0,
- XXX_VARID_REMARK_TEXT_ID,
- VARID_CONVERSATION_ID,
- VARID_DIALOGUE_SILENCE = 0,
- };
- const char * const DIALOG_EVENT_NAMES[DIALOG_MAX] =
- {
- "TAKE_DAMAGE_FROM_FRIEND",
- "TAKE_DAMAGE_FROM_ENEMY",
- "DAMAGE_FRIEND",
- "DAMAGE_ENEMY",
- "KILLED_FRIEND",
- "KILLED_ENEMY",
- "SAW_FRIEND",
- "SAW_ENEMY",
- "OBSOLETE_01",
- "OBSOLETE_02",
- "DIE",
- "POKE_IDLE",
- "POKE_SEARCH",
- "POKE_COMBAT",
- "IDLE_TO_COMBAT",
- "IDLE_TO_SEARCH",
- "SEARCH_TO_COMBAT",
- "SEARCH_TO_IDLE",
- "COMBAT_TO_SEARCH",
- "COMBAT_TO_IDLE"
- };
- ////////////////////////////////////////////////////////////////
- //
- // DialogueOptionClass
- //
- ////////////////////////////////////////////////////////////////
- DialogueOptionClass::DialogueOptionClass (void)
- : Weight (1),
- ConversationID (0)
- {
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // DialogueOptionClass
- //
- ////////////////////////////////////////////////////////////////
- DialogueOptionClass::DialogueOptionClass (const DialogueOptionClass &src)
- : Weight (1),
- ConversationID (0)
- {
- (*this) = src;
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // ~DialogueOptionClass
- //
- ////////////////////////////////////////////////////////////////
- DialogueOptionClass::~DialogueOptionClass (void)
- {
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // operator=
- //
- ////////////////////////////////////////////////////////////////
- const DialogueOptionClass &
- DialogueOptionClass::operator= (const DialogueOptionClass &src)
- {
- Weight = src.Weight;
- ConversationID = src.ConversationID;
- return (*this);
- }
- ////////////////////////////////////////////////////////////////
- //
- // Save
- //
- ////////////////////////////////////////////////////////////////
- void
- DialogueOptionClass::Save (ChunkSaveClass &csave)
- {
- csave.Begin_Chunk (CHUNKID_OPTION_VARIABLES);
- WRITE_MICRO_CHUNK (csave, VARID_WEIGHT, Weight);
- WRITE_MICRO_CHUNK (csave, VARID_CONVERSATION_ID, ConversationID);
- csave.End_Chunk ();
-
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Load
- //
- ////////////////////////////////////////////////////////////////
- void
- DialogueOptionClass::Load (ChunkLoadClass &cload)
- {
- while (cload.Open_Chunk ()) {
- switch (cload.Cur_Chunk_ID ()) {
- case CHUNKID_OPTION_VARIABLES:
- Load_Variables (cload);
- break;
- }
- cload.Close_Chunk ();
- }
- return ;
- }
- ///////////////////////////////////////////////////////////////////////
- //
- // Load_Variables
- //
- ///////////////////////////////////////////////////////////////////////
- void
- DialogueOptionClass::Load_Variables (ChunkLoadClass &cload)
- {
- //
- // Loop through all the microchunks that define the variables
- //
- while (cload.Open_Micro_Chunk ()) {
- switch (cload.Cur_Micro_Chunk_ID ()) {
- READ_MICRO_CHUNK (cload, VARID_WEIGHT, Weight);
- READ_MICRO_CHUNK (cload, VARID_CONVERSATION_ID, ConversationID);
- }
- cload.Close_Micro_Chunk ();
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // DialogueClass
- //
- ////////////////////////////////////////////////////////////////
- DialogueClass::DialogueClass (void)
- : SilenceWeight (1)
- {
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // DialogueClass
- //
- ////////////////////////////////////////////////////////////////
- DialogueClass::DialogueClass (const DialogueClass &src)
- : SilenceWeight (1)
- {
- (*this) = src;
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // ~DialogueClass
- //
- ////////////////////////////////////////////////////////////////
- DialogueClass::~DialogueClass (void)
- {
- Free_Options ();
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // operator=
- //
- ////////////////////////////////////////////////////////////////
- const DialogueClass &
- DialogueClass::operator= (const DialogueClass &src)
- {
- SilenceWeight = src.SilenceWeight;
-
- //
- // Free any option objects we may contain
- //
- Free_Options ();
- //
- // Copy all the option objects from the src object
- //
- for (int index = 0; index < src.OptionList.Count (); index ++) {
- DialogueOptionClass *option = src.OptionList[index];
- if (option != NULL) {
- OptionList.Add (new DialogueOptionClass (*option));
- }
- }
- return (*this);
- }
- ////////////////////////////////////////////////////////////////
- //
- // Save
- //
- ////////////////////////////////////////////////////////////////
- void
- DialogueClass::Save (ChunkSaveClass &csave)
- {
- csave.Begin_Chunk (CHUNKID_DIALOGUE_VARIABLES);
- WRITE_MICRO_CHUNK (csave, VARID_DIALOGUE_SILENCE, SilenceWeight);
- csave.End_Chunk ();
- //
- // Save the options
- //
- for (int index = 0; index < OptionList.Count (); index ++) {
- csave.Begin_Chunk (CHUNKID_DIALOGUE_OPTION);
- OptionList[index]->Save (csave);
- csave.End_Chunk ();
- }
-
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Load
- //
- ////////////////////////////////////////////////////////////////
- void
- DialogueClass::Load (ChunkLoadClass &cload)
- {
- Free_Options ();
- while (cload.Open_Chunk ()) {
- switch (cload.Cur_Chunk_ID ()) {
- case CHUNKID_DIALOGUE_VARIABLES:
- Load_Variables (cload);
- break;
- case CHUNKID_DIALOGUE_OPTION:
- {
- //
- // Create a new option object and add it to the list
- //
- DialogueOptionClass *option = new DialogueOptionClass;
- option->Load (cload);
- OptionList.Add (option);
- }
- break;
- }
- cload.Close_Chunk ();
- }
- return ;
- }
- ///////////////////////////////////////////////////////////////////////
- //
- // Load_Variables
- //
- ///////////////////////////////////////////////////////////////////////
- void
- DialogueClass::Load_Variables (ChunkLoadClass &cload)
- {
- //
- // Loop through all the microchunks that define the variables
- //
- while (cload.Open_Micro_Chunk ()) {
- switch (cload.Cur_Micro_Chunk_ID ()) {
- READ_MICRO_CHUNK (cload, VARID_DIALOGUE_SILENCE, SilenceWeight);
- }
- cload.Close_Micro_Chunk ();
- }
- return ;
- }
- ///////////////////////////////////////////////////////////////////////
- //
- // Free_Options
- //
- ///////////////////////////////////////////////////////////////////////
- void
- DialogueClass::Free_Options (void)
- {
- for (int index = 0; index < OptionList.Count (); index ++) {
- DialogueOptionClass *option = OptionList[index];
- if (option != NULL) {
- delete option;
- }
- }
- OptionList.Delete_All ();
- return ;
- }
- ///////////////////////////////////////////////////////////////////////
- //
- // Get_Conversation
- //
- ///////////////////////////////////////////////////////////////////////
- int
- DialogueClass::Get_Conversation (void)
- {
- int conv_id = 0;
- //
- // Make a number we can use to index linearly into the option list
- // to determine which one to use.
- //
- float total = SilenceWeight;
- for (int index = 0; index < OptionList.Count (); index ++) {
- total += OptionList[index]->Get_Weight ();
- }
- //
- // Choose a random value in this linear range
- //
- float value = WWMath::Random_Float (0, total);
- //
- // Now find the object this value corresponds to
- //
- float count = SilenceWeight;
- for (index = 0; value > count && index < OptionList.Count (); index ++) {
- conv_id = OptionList[index]->Get_Conversation_ID ();
- count += OptionList[index]->Get_Weight ();
- }
- return conv_id;
- }
|