| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209 |
- /*
- ** 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/conversationmgr.cpp $*
- * *
- * Author:: Patrick Smith *
- * *
- * $Modtime:: 1/15/02 9:37p $*
- * *
- * $Revision:: 24 $*
- * *
- *---------------------------------------------------------------------------------------------*
- * Functions: *
- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
- #include "conversationmgr.h"
- #include "combatchunkid.h"
- #include "chunkio.h"
- #include "vector3.h"
- #include "pscene.h"
- #include "physicalgameobj.h"
- #include "aabox.h"
- #include "conversation.h"
- #include "wwmath.h"
- #include "soldierobserver.h"
- #include "playertype.h"
- #include "activeconversation.h"
- #include "phys.h"
- #include "string_ids.h"
- #include "oratortypes.h"
- ////////////////////////////////////////////////////////////////
- // Constants
- ////////////////////////////////////////////////////////////////
- enum
- {
- CHUNKID_VARIABLES = 0x08090315,
- CHUNKID_OLD_CONVERSATION,
- CHUNKID_ACTIVE_CONVERSATION,
- CHUNKID_CONVERSATION_CATEGORY,
- CHUNKID_CONVERSATION
- };
- enum
- {
- VARID_NEXT_ACTIVE_CONVERSATION_ID = 0,
- XXX_VARID_NEXT_GLOBAL_CONVERSATION_ID,
- VARID_NEXT_LEVEL_CONVERSATION_ID,
- VARID_NEXT_GLOBAL_CONVERSATION_ID,
- };
- static const float BUDDY_LOCATE_CX = 7;
- static const float BUDDY_LOCATE_CY = 7;
- static const float BUDDY_LOCATE_CZ = 3;
- static const int ACTIVE_CONVERSATION_START_ID = 1000;
- static const int LEVEL_CONVERSATION_START_ID = 1;
- static const int GLOBAL_CONVERSATION_START_ID = 100000;
- ////////////////////////////////////////////////////////////////
- // Static member initialization
- ////////////////////////////////////////////////////////////////
- CONVERSATION_LIST ConversationMgrClass::ConversationList[CATEGORY_MAX];
- ACTIVE_CONVERSATION_LIST ConversationMgrClass::ActiveConversationList;
- int ConversationMgrClass::NextActiveConversationID = ACTIVE_CONVERSATION_START_ID;
- int ConversationMgrClass::NextGlobalConversationID = GLOBAL_CONVERSATION_START_ID;
- int ConversationMgrClass::NextLevelConversationID = LEVEL_CONVERSATION_START_ID;
- ConversationMgrClass::CATEGORY ConversationMgrClass::SaveCategoryID = CATEGORY_GLOBAL;
- bool ConversationMgrClass::DisplayEmotIcons = false;
- ////////////////////////////////////////////////////////////////
- // Singleton instance
- ////////////////////////////////////////////////////////////////
- ConversationMgrClass _ConversationMgrSaveLoad;
- ////////////////////////////////////////////////////////////////
- //
- // ConversationMgrClass
- //
- ////////////////////////////////////////////////////////////////
- ConversationMgrClass::ConversationMgrClass (void)
- {
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // ~ConversationMgrClass
- //
- ////////////////////////////////////////////////////////////////
- ConversationMgrClass::~ConversationMgrClass (void)
- {
- Reset ();
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Reset_Conversations
- //
- ////////////////////////////////////////////////////////////////
- void
- ConversationMgrClass::Reset_Conversations (int category_index, bool reset_start_id)
- {
- if (reset_start_id && category_index == CATEGORY_LEVEL) {
- NextLevelConversationID = LEVEL_CONVERSATION_START_ID;
- }
- int count = ConversationList[category_index].Count ();
- //
- // Release our hold on all the conversations in this category
- //
- for (int index = 0; index < count; index ++) {
- ConversationClass *conversation = ConversationList[category_index][index];
- REF_PTR_RELEASE (conversation);
- }
- ConversationList[category_index].Delete_All ();
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Reset_All_Other_Conversations
- //
- ////////////////////////////////////////////////////////////////
- void
- ConversationMgrClass::Reset_All_Other_Conversations (ActiveConversationClass *active_conversation)
- {
- NextActiveConversationID = active_conversation->Get_ID () + 1;
- //
- // Release our hold on all the other conversations
- //
- int count = ActiveConversationList.Count ();
- for (int index = 0; index < count; index ++) {
- ActiveConversationClass *conversation = ActiveConversationList[index];
- if (conversation != NULL && conversation != active_conversation) {
- conversation->Stop_Conversation (ACTION_COMPLETE_CONVERSATION_INTERRUPTED);
- REF_PTR_RELEASE (conversation);
- }
- }
-
- ActiveConversationList.Delete_All ();
- //
- // Add this conversation back into the list
- //
- ActiveConversationList.Add (active_conversation);
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Reset_Active_Conversations
- //
- ////////////////////////////////////////////////////////////////
- void
- ConversationMgrClass::Reset_Active_Conversations (void)
- {
- NextActiveConversationID = ACTIVE_CONVERSATION_START_ID;
- //
- // Release our hold on all the active conversations
- //
- while (ActiveConversationList.Count () > 0) {
- ActiveConversationClass *active_conversation = ActiveConversationList[0];
- ActiveConversationList.Delete (0);
- if (active_conversation != NULL) {
- active_conversation->Stop_Conversation (ACTION_COMPLETE_CONVERSATION_INTERRUPTED);
- }
- REF_PTR_RELEASE (active_conversation);
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Reset
- //
- ////////////////////////////////////////////////////////////////
- void
- ConversationMgrClass::Reset (void)
- {
- //
- // Release our hold on all the active conversations
- //
- Reset_Active_Conversations ();
- //
- // Release our hold on all the conversations
- //
- for (int cat_index = 0; cat_index < CATEGORY_MAX; cat_index ++) {
- Reset_Conversations (cat_index);
- }
-
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Chunk_ID
- //
- ////////////////////////////////////////////////////////////////
- uint32
- ConversationMgrClass::Chunk_ID (void) const
- {
- return CHUNKID_CONVERSATION_MGR;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Save
- //
- ////////////////////////////////////////////////////////////////
- bool
- ConversationMgrClass::Save (ChunkSaveClass &csave)
- {
- csave.Begin_Chunk (CHUNKID_VARIABLES);
- WRITE_MICRO_CHUNK (csave, VARID_NEXT_ACTIVE_CONVERSATION_ID, NextActiveConversationID);
-
- if (SaveCategoryID == CATEGORY_GLOBAL) {
- WRITE_MICRO_CHUNK (csave, VARID_NEXT_GLOBAL_CONVERSATION_ID, NextGlobalConversationID);
- } else {
- WRITE_MICRO_CHUNK (csave, VARID_NEXT_LEVEL_CONVERSATION_ID, NextLevelConversationID);
- }
- csave.End_Chunk ();
- //
- // Save the conversations in the current category
- //
- csave.Begin_Chunk (CHUNKID_CONVERSATION_CATEGORY);
- //
- // Save the category ID
- //
- csave.Write (&SaveCategoryID, sizeof (SaveCategoryID));
-
- //
- // Save each conversation in this category
- //
- int count = ConversationList[SaveCategoryID].Count ();
- for (int index = 0; index < count; index ++) {
- ConversationClass *conversation = ConversationList[SaveCategoryID][index];
- if (conversation != NULL) {
- csave.Begin_Chunk (CHUNKID_CONVERSATION);
- conversation->Save (csave);
- csave.End_Chunk ();
- }
- }
- csave.End_Chunk ();
- //
- // Save each active conversation to its own chunk
- //
- count = ActiveConversationList.Count ();
- for (index = 0; index < count; index ++) {
- ActiveConversationClass *active_conversation = ActiveConversationList[index];
- if (active_conversation != NULL) {
- csave.Begin_Chunk (CHUNKID_ACTIVE_CONVERSATION);
- active_conversation->Save (csave);
- csave.End_Chunk ();
- }
- }
- return true;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Load_Conversations
- //
- ////////////////////////////////////////////////////////////////
- bool
- ConversationMgrClass::Load_Conversations (ChunkLoadClass &cload, int category_id)
- {
- while (cload.Open_Chunk ()) {
- switch (cload.Cur_Chunk_ID ()) {
- case CHUNKID_CONVERSATION:
- {
- //
- // Create a new object and its state from the chunk
- //
- ConversationClass *conversation = new ConversationClass;
- SET_REF_OWNER( conversation );
- conversation->Load (cload);
-
- //
- // Debug check to ensure we've got the correct cateogry
- //
- WWASSERT (conversation->Get_Category_ID () == category_id);
-
- //
- // Add this conversation to our list
- //
- Add_Conversation (conversation);
- REF_PTR_RELEASE (conversation);
- }
- break;
- }
- cload.Close_Chunk ();
- }
- return true;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Load
- //
- ////////////////////////////////////////////////////////////////
- bool
- ConversationMgrClass::Load (ChunkLoadClass &cload)
- {
- int old_style_conv_count = 0;
- //
- // Remove all currently active conversations
- //
- Reset_Active_Conversations ();
- while (cload.Open_Chunk ()) {
- switch (cload.Cur_Chunk_ID ()) {
- case CHUNKID_ACTIVE_CONVERSATION:
- {
- //
- // Create a new object and its state from the chunk
- //
- ActiveConversationClass *active_conversation = new ActiveConversationClass;
- active_conversation->Load (cload);
-
- //
- // Add this new active conversation to our list
- //
- ActiveConversationList.Add (active_conversation);
- }
- break;
- case CHUNKID_CONVERSATION_CATEGORY:
- {
- int category_id = 0;
- cload.Read (&category_id, sizeof (category_id));
- //
- // Remove all conversations in this category
- //
- Reset_Conversations (category_id);
- //
- // Load all the conversations in this category
- //
- Load_Conversations (cload, category_id);
- }
- break;
- case CHUNKID_OLD_CONVERSATION:
- {
- //
- // Reset the list of level conversations if this
- // the first one loaded
- //
- if (old_style_conv_count == 0) {
- Reset_Conversations (CATEGORY_LEVEL);
- }
- old_style_conv_count ++;
- //
- // Create a new object and its state from the chunk
- //
- ConversationClass *conversation = new ConversationClass;
- conversation->Load (cload);
- conversation->Set_Category_ID (CATEGORY_LEVEL);
-
- //
- // Add this conversation to our list
- //
- Add_Conversation (conversation);
- REF_PTR_RELEASE (conversation);
- }
- break;
- case CHUNKID_VARIABLES:
- Load_Variables (cload);
- break;
- }
- cload.Close_Chunk ();
- }
- return true;
- }
- ///////////////////////////////////////////////////////////////////////
- //
- // Load_Variables
- //
- ///////////////////////////////////////////////////////////////////////
- void
- ConversationMgrClass::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_NEXT_ACTIVE_CONVERSATION_ID, NextActiveConversationID);
- READ_MICRO_CHUNK (cload, VARID_NEXT_GLOBAL_CONVERSATION_ID, NextGlobalConversationID);
- READ_MICRO_CHUNK (cload, VARID_NEXT_LEVEL_CONVERSATION_ID, NextLevelConversationID);
- }
- cload.Close_Micro_Chunk ();
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Build_Buddy_List
- //
- ////////////////////////////////////////////////////////////////
- void
- ConversationMgrClass::Build_Buddy_List
- (
- PhysicalGameObj * orator,
- DynamicVectorClass<PhysicalGameObj *> & buddy_list,
- bool include_orator
- )
- {
- //
- // Build a box, centered around the orator, that we can use to
- // collect other 'friendly' orators in the area
- //
- Vector3 orator_pos (0, 0, 0);
- orator->Get_Position (&orator_pos);
- orator_pos.Z += BUDDY_LOCATE_CZ / 3.0F;
- AABoxClass box (orator_pos, Vector3 (BUDDY_LOCATE_CX, BUDDY_LOCATE_CY, BUDDY_LOCATE_CZ));
- //
- // Collect all the dynamic objects in this box
- //
- NonRefPhysListClass obj_list;
- PhysicsSceneClass::Get_Instance ()->Collect_Objects (box, false, true, &obj_list);
-
- //
- // Loop over all the collected objects
- //
- NonRefPhysListIterator it (&obj_list);
- for (it.First(); !it.Is_Done(); it.Next()) {
- PhysClass *phys_obj = it.Peek_Obj ();
-
- //
- // Check to ensure this game object is a orator
- //
- CombatPhysObserverClass *phys_observer = reinterpret_cast<CombatPhysObserverClass *>(phys_obj->Get_Observer ());
- if (phys_observer != NULL) {
- PhysicalGameObj *game_obj = phys_observer->As_PhysicalGameObj();
- if (game_obj != NULL) {
-
- //
- // Check to make sure we found a orator who can participate
- // in this conversation
- //
- PhysicalGameObj *other_orator = game_obj->As_PhysicalGameObj ();
- if (other_orator != NULL && (include_orator || other_orator != orator)) {
- //
- // Can this orator hold a conversation?
- //
- if ( other_orator->Is_In_Conversation () == false &&
- other_orator->Are_Innate_Conversations_Enabled ())
- {
- buddy_list.Add (other_orator);
- }
- }
- }
- }
- }
-
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Find_Active_Conversation
- //
- ////////////////////////////////////////////////////////////////
- ActiveConversationClass *
- ConversationMgrClass::Find_Active_Conversation (int id)
- {
- ActiveConversationClass *conversation = NULL;
- //
- // Loop over each entry in the active conversation list, looking for one with
- // the supplied identifier.
- //
- for (int index = 0; index < ActiveConversationList.Count (); index ++) {
- ActiveConversationClass *curr_conversation = ActiveConversationList[index];
-
- //
- // Is this the conversation we were looking for?
- //
- if (curr_conversation != NULL && curr_conversation->Get_ID () == id) {
- conversation = curr_conversation;
- conversation->Add_Ref ();
- break;
- }
- }
- return conversation;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Find_Conversation
- //
- ////////////////////////////////////////////////////////////////
- ConversationClass *
- ConversationMgrClass::Find_Conversation (const char *conversation_name)
- {
- ConversationClass *conversation = NULL;
- //
- // Loop over all the conversation categories
- //
- for (int cat_index = 0; cat_index < CATEGORY_MAX; cat_index ++) {
-
- //
- // Loop over each conversation in this category, looking for one with
- // the requested name.
- //
- int count = ConversationList[cat_index].Count ();
- for (int index = 0; index < count; index ++) {
- ConversationClass *curr_conversation = ConversationList[cat_index][index];
-
- //
- // Is this the conversation we were looking for?
- //
- if ( curr_conversation != NULL &&
- ::strcmpi (curr_conversation->Get_Name (), conversation_name) == 0)
- {
- conversation = curr_conversation;
- conversation->Add_Ref ();
- break;
- }
- }
- }
- return conversation;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Find_Conversation
- //
- ////////////////////////////////////////////////////////////////
- ConversationClass *
- ConversationMgrClass::Find_Conversation (int conversation_id)
- {
- ConversationClass *conversation = NULL;
- //
- // Loop over all the conversation categories
- //
- for (int cat_index = 0; cat_index < CATEGORY_MAX; cat_index ++) {
-
- //
- // Loop over each conversation in this category, looking for one with
- // the requested name.
- //
- int count = ConversationList[cat_index].Count ();
- for (int index = 0; index < count; index ++) {
- ConversationClass *curr_conversation = ConversationList[cat_index][index];
-
- //
- // Is this the conversation we were looking for?
- //
- if ( (curr_conversation != NULL) &&
- (curr_conversation->Get_ID () == conversation_id))
- {
- conversation = curr_conversation;
- conversation->Add_Ref ();
- break;
- }
- }
- }
- return conversation;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Start_Conversation
- //
- ////////////////////////////////////////////////////////////////
- ActiveConversationClass *
- ConversationMgrClass::Start_Conversation (PhysicalGameObj *orator, int conversation_id, bool force)
- {
- ActiveConversationClass *active_conversation = NULL;
- //
- // Try to find the requested conversation
- //
- ConversationClass *conversation = Find_Conversation (conversation_id);
- if (conversation != NULL) {
- //
- // Start the conversation
- //
- active_conversation = Start_Conversation (orator, conversation, force);
- REF_PTR_RELEASE (conversation);
- }
- //
- // Return a pointer to the conversation. Note: This object has
- // an extra ref count on it, its the caller's responsibility to release
- // this ref count when they are finished with it.
- //
- return active_conversation;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Start_Conversation
- //
- ////////////////////////////////////////////////////////////////
- ActiveConversationClass *
- ConversationMgrClass::Start_Conversation (PhysicalGameObj *orator, const char *conversation_name, bool force)
- {
- ActiveConversationClass *active_conversation = NULL;
- //
- // Try to find the requested conversation
- //
- ConversationClass *conversation = Find_Conversation (conversation_name);
- if (conversation != NULL) {
- //
- // Start the conversation
- //
- active_conversation = Start_Conversation (orator, conversation, force);
- REF_PTR_RELEASE (conversation);
- }
- //
- // Return a pointer to the conversation. Note: This object has
- // an extra ref count on it, its the caller's responsibility to release
- // this ref count when they are finished with it.
- //
- return active_conversation;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Start_Conversation
- //
- ////////////////////////////////////////////////////////////////
- ActiveConversationClass *
- ConversationMgrClass::Start_Conversation (PhysicalGameObj *orator, ConversationClass *conversation, bool force)
- {
- //
- // Build a list of potential participants in the conversation
- //
- DynamicVectorClass<PhysicalGameObj *> buddy_list;
- Build_Buddy_List (orator, buddy_list, false);
-
- //
- // If we have enough people to hold this conversation, then activate
- // the new conversation.
- //
- ActiveConversationClass *active_conversation = NULL;
- if (Test_Conversation (orator, conversation, buddy_list, force)) {
- active_conversation = Create_New_Conversation (conversation, buddy_list);
- }
- //
- // Return a pointer to the conversation. Note: This object has
- // an extra ref count on it, its the caller's responsibility to release
- // this ref count when they are finished with it.
- //
- return active_conversation;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Create_New_Conversation
- //
- ////////////////////////////////////////////////////////////////
- ActiveConversationClass *
- ConversationMgrClass::Create_New_Conversation
- (
- ConversationClass * conversation,
- DynamicVectorClass<PhysicalGameObj *> & buddy_list
- )
- {
- ActiveConversationClass *active_conversation = new ActiveConversationClass;
- active_conversation->Set_Conversation (conversation);
- //
- // Add the participants to the active conversation.
- // Note: Its assumed that the buddy_list is in the correct
- // order for this conversation.
- //
- int count = conversation->Get_Orator_Count ();
- for (int index = 0; index < count; index ++) {
- active_conversation->Add_Orator (buddy_list[index]);
- }
- //
- // Add it to our active conversation list
- //
- active_conversation->Set_ID (NextActiveConversationID ++);
- ActiveConversationList.Add (active_conversation);
- //
- // Initialize the conversation
- //
- active_conversation->Start_Conversation ();
- //
- // Increment the reference count on the conversation and
- // return it to the caller.
- //
- active_conversation->Add_Ref ();
- return active_conversation;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Start_Conversation
- //
- ////////////////////////////////////////////////////////////////
- void
- ConversationMgrClass::Start_Conversation (PhysicalGameObj *orator)
- {
- //
- // Build a list of potential participants in the conversation
- //
- DynamicVectorClass<PhysicalGameObj *> available_buddy_list;
- Build_Buddy_List (orator, available_buddy_list, false);
-
- //
- // Try to find a conversation that this list of orators can have
- //
- DynamicVectorClass<PhysicalGameObj *> orator_list;
- ConversationClass *conversation = Pick_Conversation (orator, available_buddy_list, orator_list);
- if (conversation != NULL) {
- ActiveConversationClass *active_conversation = Create_New_Conversation (conversation, orator_list);
- REF_PTR_RELEASE (active_conversation);
- }
-
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Test_Conversation
- //
- ////////////////////////////////////////////////////////////////
- bool
- ConversationMgrClass::Test_Conversation
- (
- PhysicalGameObj * initiator,
- ConversationClass * conversation,
- DynamicVectorClass<PhysicalGameObj *> & buddy_list,
- bool force
- )
- {
- int orator_count = conversation->Get_Orator_Count ();
- bool retval = (orator_count > 0);
- bool initiator_included = false;
- DynamicVectorClass<PhysicalGameObj *> available_buddy_list = buddy_list;
- buddy_list.Reset_Active ();
- //
- // Loop over all the orator requirements for this conversation and
- // see if they are in the buddy list
- //
- for (int orator_index = 0; orator_index < orator_count; orator_index ++) {
- OratorClass *orator = conversation->Get_Orator (orator_index);
-
- //
- // If the orator is invisible, it automatically passes the test (we
- // don't need a physical object to take the part).
- //
- bool found = false;
- if (orator->Is_Invisible ()) {
- buddy_list.Add (NULL);
- found = true;
- } else {
- //
- // Test the initiator
- //
- if (initiator_included == false) {
- if (force || Test_Orator (conversation, orator, initiator)) {
- buddy_list.Add (initiator);
- initiator_included = true;
- found = true;
- }
- }
- //
- // Try to find an entry in our buddy list that matches the orator
- // requirements
- //
- for (int index = 0; index < available_buddy_list.Count (); index ++) {
- PhysicalGameObj *game_obj = available_buddy_list[index];
-
- //
- // Does this game object fit the orator description?
- //
- if (Test_Orator (conversation, orator, game_obj)) {
- buddy_list.Add (game_obj);
- //
- // Remove this orator from the buddy list
- //
- available_buddy_list.Delete (index);
- found = true;
- break;
- }
- }
- }
-
- //
- // If we can't match up even ONE of the orators, then the
- // conversation can't be executed
- //
- if (found == false) {
- retval = false;
- break;
- }
- }
- //
- // We can't pass the conversation if the initiator isn't
- // included in the conversation.
- //
- if (initiator_included == false) {
- retval = false;
- }
- return retval;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Test_Orator
- //
- ////////////////////////////////////////////////////////////////
- bool
- ConversationMgrClass::Test_Orator
- (
- ConversationClass * conversation,
- OratorClass * orator,
- PhysicalGameObj * game_obj
- )
- {
- bool retval = false;
- //
- // Check to ensure the orator types match
- //
- if (orator->Get_Orator_Type () == game_obj->Get_Definition ().Get_Orator_Type ()) {
- //
- // Check to see (if its a soldier) if this orator is in the correct state
- //
- SoldierGameObj *soldier = game_obj->As_SoldierGameObj ();
- if ( soldier == NULL ||
- soldier->Is_Human_Controlled () ||
- soldier->Get_AI_State () == conversation->Get_AI_State ())
- {
- retval = true;
- }
- }
- return retval;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Pick_Conversation
- //
- ////////////////////////////////////////////////////////////////
- ConversationClass *
- ConversationMgrClass::Pick_Conversation
- (
- PhysicalGameObj * initiator,
- const DynamicVectorClass<PhysicalGameObj *> & available_orator_list,
- DynamicVectorClass<PhysicalGameObj *> & orator_list
- )
- {
- ConversationClass *conversation = NULL;
-
- //
- // Try to find a conversation that matches the criteria
- //
- float best_match = 0;
- //
- // Loop over all the conversation categories
- //
- for (int cat_index = 0; cat_index < CATEGORY_MAX; cat_index ++) {
-
- //
- // Loop over all the conversations in this category
- //
- int count = ConversationList[cat_index].Count ();
- for (int index = 0; index < count; index ++) {
- ConversationClass *curr_conversation = ConversationList[cat_index][index];
- //
- // Can this conversation be used innately?
- //
- if ( curr_conversation != NULL &&
- curr_conversation->Is_Innate ())
- {
- //
- // Test this conversation to ensure all requirements are met
- //
- DynamicVectorClass<PhysicalGameObj *> curr_orator_list = available_orator_list;
- if (Test_Conversation (initiator, curr_conversation, curr_orator_list)) {
-
- //
- // Randomize the selection process
- //
- float match_percent = WWMath::Random_Float (0.9F, 1.1F);
- match_percent *= curr_conversation->Get_Probability ();
- if (match_percent > best_match) {
-
- //
- // This is our best bet so far, so save this conversation
- //
- best_match = match_percent;
- conversation = curr_conversation;
- orator_list = curr_orator_list;
- }
- }
- }
- }
- }
- //
- // If we've found a conversation, decrease its probability so
- // it will be less likely to be picked next time.
- //
- if (conversation != NULL) {
- float probability = conversation->Get_Probability ();
- probability = probability * 0.75F;
- conversation->Set_Probability (probability);
- }
- return conversation;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Is_Key_Conversation_Playing
- //
- ////////////////////////////////////////////////////////////////
- bool
- ConversationMgrClass::Is_Key_Conversation_Playing (void)
- {
- bool retval = false;
- //
- // Check for any "key" conversations
- //
- int index = ActiveConversationList.Count ();
- while (index --) {
- ActiveConversationClass *active_conversation = ActiveConversationList[index];
- //
- // Is this a "key" conversation?
- //
- if (active_conversation->Peek_Conversation ()->Is_Key ()) {
- retval = true;
- break;
- }
- }
- return retval;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Think
- //
- ////////////////////////////////////////////////////////////////
- void
- ConversationMgrClass::Think (void)
- {
- bool is_key = Is_Key_Conversation_Playing ();
- //
- // Stop any non-key conversations that are playing (if there is a key conversation playing)
- //
- if (is_key) {
- bool release_key_conv = false;
- int index = ActiveConversationList.Count ();
- while (index --) {
- ActiveConversationClass *active_conversation = ActiveConversationList[index];
- if (active_conversation->Peek_Conversation ()->Is_Key () == false || release_key_conv) {
- //
- // Stop any non-key conversation
- //
- active_conversation->Stop_Conversation ();
-
- //
- // Remove the conversation from the list
- //
- ActiveConversationList.Delete (index);
- REF_PTR_RELEASE (active_conversation);
- } else {
- release_key_conv = true;
- }
- }
- }
- //
- // Loop over all the remaining active conversations
- //
- int count = ActiveConversationList.Count ();
- for (int index = 0; index < count; index ++) {
- ActiveConversationClass *active_conversation = ActiveConversationList[index];
-
- //
- // Let this conversation process
- //
- bool remove_from_list = true;
- if (active_conversation != NULL) {
- active_conversation->Think ();
- remove_from_list = active_conversation->Is_Finished ();
- }
- //
- // Remove this conversation from our control (if necessary)
- //
- if (remove_from_list) {
- ActiveConversationList.Delete (index);
- REF_PTR_RELEASE (active_conversation);
- index --;
- count --;
- }
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Add_Conversation
- //
- ////////////////////////////////////////////////////////////////
- void
- ConversationMgrClass::Add_Conversation (ConversationClass *conversation)
- {
- WWASSERT (conversation != NULL);
- if (conversation == NULL) {
- return ;
- }
- //
- // Assign this conversation an ID (if necessary)
- //
- if (conversation->Get_ID () == 0) {
-
- if (conversation->Get_Category_ID () == CATEGORY_LEVEL) {
- conversation->Set_ID (NextLevelConversationID ++);
- } else {
- conversation->Set_ID (NextGlobalConversationID ++);
- }
- }
- //
- // Add a reference to the converation, then add it to our list
- //
- conversation->Add_Ref ();
- ConversationList[conversation->Get_Category_ID ()].Add (conversation);
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Create_New_Conversation
- //
- ////////////////////////////////////////////////////////////////
- ActiveConversationClass *
- ConversationMgrClass::Create_New_Conversation (ConversationClass *conversation)
- {
- ActiveConversationClass *active_conversation = NULL;
- if (conversation != NULL) {
- //
- // Allocate the new conversation
- //
- active_conversation = new ActiveConversationClass;
- active_conversation->Set_Conversation (conversation);
- //
- // Add it to our active conversation list
- //
- active_conversation->Set_ID (NextActiveConversationID ++);
- ActiveConversationList.Add (active_conversation);
- active_conversation->Add_Ref ();
- }
- //
- // Return a pointer to the conversation. Note: This object has
- // an extra ref count on it, its the caller's responsibility to release
- // this ref count when they are finished with it.
- //
- return active_conversation;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Remove_Conversation
- //
- ////////////////////////////////////////////////////////////////
- void
- ConversationMgrClass::Remove_Conversation (ConversationClass *conversation)
- {
- int cat_index = conversation->Get_Category_ID ();
- int count = ConversationList[cat_index].Count ();
- //
- // Loop over all the conversations in this category
- //
- for (int index = 0; index < count; index ++) {
- ConversationClass *curr_conversation = ConversationList[cat_index][index];
- if (conversation == curr_conversation) {
-
- //
- // Remove this conversation from the list
- //
- ConversationList[cat_index].Delete (index);
- conversation->Set_ID (0);
- REF_PTR_RELEASE (conversation);
- break;
- }
- }
- return ;
- }
|