- Moved Strife conversation data into FLevelLocals.
This commit is contained in:
parent
0e5986769e
commit
0a6b6173de
10 changed files with 91 additions and 82 deletions
|
|
@ -96,28 +96,21 @@ struct TeaserSpeech
|
|||
|
||||
static FRandom pr_randomspeech("RandomSpeech");
|
||||
|
||||
TArray<FStrifeDialogueNode *> StrifeDialogues;
|
||||
|
||||
typedef TMap<int, int> FDialogueIDMap; // maps dialogue IDs to dialogue array index (for ACS)
|
||||
typedef TMap<FName, int> FDialogueMap; // maps actor class names to dialogue array index
|
||||
|
||||
FClassMap StrifeTypes;
|
||||
static FDialogueIDMap DialogueRoots;
|
||||
static FDialogueMap ClassRoots;
|
||||
static int ConversationMenuY;
|
||||
|
||||
static int ConversationPauseTic;
|
||||
// These two should be moved to player_t...
|
||||
static FStrifeDialogueNode *PrevNode;
|
||||
static int StaticLastReply;
|
||||
|
||||
static bool LoadScriptFile(int lumpnum, FileReader &lump, int numnodes, bool include, int type);
|
||||
static FStrifeDialogueNode *ReadRetailNode (FileReader &lump, uint32_t &prevSpeakerType);
|
||||
static FStrifeDialogueNode *ReadTeaserNode (FileReader &lump, uint32_t &prevSpeakerType);
|
||||
static bool LoadScriptFile(FLevelLocals *Level, int lumpnum, FileReader &lump, int numnodes, bool include, int type);
|
||||
static FStrifeDialogueNode *ReadRetailNode (FLevelLocals *Level, FileReader &lump, uint32_t &prevSpeakerType);
|
||||
static FStrifeDialogueNode *ReadTeaserNode (FLevelLocals *Level, FileReader &lump, uint32_t &prevSpeakerType);
|
||||
static void ParseReplies (FStrifeDialogueReply **replyptr, Response *responses);
|
||||
static bool DrawConversationMenu ();
|
||||
static void PickConversationReply (int replyindex);
|
||||
static void TerminalResponse (const char *str);
|
||||
|
||||
static FStrifeDialogueNode *PrevNode;
|
||||
|
||||
//============================================================================
|
||||
//
|
||||
|
|
@ -137,7 +130,7 @@ void ClearStrifeTypes()
|
|||
StrifeTypes.Clear();
|
||||
}
|
||||
|
||||
void SetConversation(int convid, PClassActor *Class, int dlgindex)
|
||||
void FLevelLocals::SetConversation(int convid, PClassActor *Class, int dlgindex)
|
||||
{
|
||||
if (convid != -1)
|
||||
{
|
||||
|
|
@ -156,14 +149,14 @@ PClassActor *GetStrifeType (int typenum)
|
|||
else return *ptype;
|
||||
}
|
||||
|
||||
int GetConversation(int conv_id)
|
||||
int FLevelLocals::GetConversation(int conv_id)
|
||||
{
|
||||
int *pindex = DialogueRoots.CheckKey(conv_id);
|
||||
if (pindex == NULL) return -1;
|
||||
else return *pindex;
|
||||
}
|
||||
|
||||
int GetConversation(FName classname)
|
||||
int FLevelLocals::GetConversation(FName classname)
|
||||
{
|
||||
int *pindex = ClassRoots.CheckKey(classname);
|
||||
if (pindex == NULL) return -1;
|
||||
|
|
@ -178,12 +171,11 @@ int GetConversation(FName classname)
|
|||
//
|
||||
//============================================================================
|
||||
|
||||
void P_LoadStrifeConversations (MapData *map, const char *mapname)
|
||||
void P_LoadStrifeConversations (FLevelLocals *Level, MapData *map, const char *mapname)
|
||||
{
|
||||
P_FreeStrifeConversations ();
|
||||
if (map->Size(ML_CONVERSATION) > 0)
|
||||
{
|
||||
LoadScriptFile (map->lumpnum, map->Reader(ML_CONVERSATION), map->Size(ML_CONVERSATION), false, 0);
|
||||
LoadScriptFile (Level, map->lumpnum, map->Reader(ML_CONVERSATION), map->Size(ML_CONVERSATION), false, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -192,8 +184,8 @@ void P_LoadStrifeConversations (MapData *map, const char *mapname)
|
|||
char scriptname_b[9] = { 'S','C','R','I','P','T',mapname[3],mapname[4],0 };
|
||||
char scriptname_t[9] = { 'D','I','A','L','O','G',mapname[3],mapname[4],0 };
|
||||
|
||||
if ( LoadScriptFile(scriptname_t, false, 2)
|
||||
|| LoadScriptFile(scriptname_b, false, 1))
|
||||
if ( LoadScriptFile(Level, scriptname_t, false, 2)
|
||||
|| LoadScriptFile(Level, scriptname_b, false, 1))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -201,13 +193,13 @@ void P_LoadStrifeConversations (MapData *map, const char *mapname)
|
|||
|
||||
if (gameinfo.Dialogue.IsNotEmpty())
|
||||
{
|
||||
if (LoadScriptFile(gameinfo.Dialogue, false, 0))
|
||||
if (LoadScriptFile(Level, gameinfo.Dialogue, false, 0))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
LoadScriptFile("SCRIPT00", false, 1);
|
||||
LoadScriptFile(Level, "SCRIPT00", false, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -219,7 +211,7 @@ void P_LoadStrifeConversations (MapData *map, const char *mapname)
|
|||
//
|
||||
//============================================================================
|
||||
|
||||
bool LoadScriptFile (const char *name, bool include, int type)
|
||||
bool LoadScriptFile (FLevelLocals *Level, const char *name, bool include, int type)
|
||||
{
|
||||
int lumpnum = Wads.CheckNumForName (name);
|
||||
const bool found = lumpnum >= 0
|
||||
|
|
@ -236,11 +228,11 @@ bool LoadScriptFile (const char *name, bool include, int type)
|
|||
}
|
||||
FileReader lump = Wads.ReopenLumpReader (lumpnum);
|
||||
|
||||
bool res = LoadScriptFile(lumpnum, lump, Wads.LumpLength(lumpnum), include, type);
|
||||
bool res = LoadScriptFile(Level, lumpnum, lump, Wads.LumpLength(lumpnum), include, type);
|
||||
return res;
|
||||
}
|
||||
|
||||
static bool LoadScriptFile(int lumpnum, FileReader &lump, int numnodes, bool include, int type)
|
||||
static bool LoadScriptFile(FLevelLocals *Level, int lumpnum, FileReader &lump, int numnodes, bool include, int type)
|
||||
{
|
||||
int i;
|
||||
uint32_t prevSpeakerType;
|
||||
|
|
@ -261,13 +253,13 @@ static bool LoadScriptFile(int lumpnum, FileReader &lump, int numnodes, bool inc
|
|||
|
||||
if (!isbinary)
|
||||
{
|
||||
P_ParseUSDF(lumpnum, lump, numnodes);
|
||||
P_ParseUSDF(Level, lumpnum, lump, numnodes);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!include)
|
||||
{
|
||||
LoadScriptFile("SCRIPT00", true, 1);
|
||||
LoadScriptFile(Level, "SCRIPT00", true, 1);
|
||||
}
|
||||
if (!(gameinfo.flags & GI_SHAREWARE))
|
||||
{
|
||||
|
|
@ -297,13 +289,13 @@ static bool LoadScriptFile(int lumpnum, FileReader &lump, int numnodes, bool inc
|
|||
{
|
||||
if (!(gameinfo.flags & GI_SHAREWARE))
|
||||
{
|
||||
node = ReadRetailNode (lump, prevSpeakerType);
|
||||
node = ReadRetailNode (Level, lump, prevSpeakerType);
|
||||
}
|
||||
else
|
||||
{
|
||||
node = ReadTeaserNode (lump, prevSpeakerType);
|
||||
node = ReadTeaserNode (Level, lump, prevSpeakerType);
|
||||
}
|
||||
node->ThisNodeNum = StrifeDialogues.Push(node);
|
||||
node->ThisNodeNum = Level->StrifeDialogues.Push(node);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
@ -317,7 +309,7 @@ static bool LoadScriptFile(int lumpnum, FileReader &lump, int numnodes, bool inc
|
|||
//
|
||||
//============================================================================
|
||||
|
||||
static FStrifeDialogueNode *ReadRetailNode (FileReader &lump, uint32_t &prevSpeakerType)
|
||||
static FStrifeDialogueNode *ReadRetailNode (FLevelLocals *Level, FileReader &lump, uint32_t &prevSpeakerType)
|
||||
{
|
||||
FStrifeDialogueNode *node;
|
||||
Speech speech;
|
||||
|
|
@ -343,9 +335,9 @@ static FStrifeDialogueNode *ReadRetailNode (FileReader &lump, uint32_t &prevSpea
|
|||
{
|
||||
if (type != NULL)
|
||||
{
|
||||
ClassRoots[type->TypeName] = StrifeDialogues.Size();
|
||||
Level->ClassRoots[type->TypeName] = Level->StrifeDialogues.Size();
|
||||
}
|
||||
DialogueRoots[speech.SpeakerType] = StrifeDialogues.Size();
|
||||
Level->DialogueRoots[speech.SpeakerType] = Level->StrifeDialogues.Size();
|
||||
prevSpeakerType = speech.SpeakerType;
|
||||
}
|
||||
|
||||
|
|
@ -393,7 +385,7 @@ static FStrifeDialogueNode *ReadRetailNode (FileReader &lump, uint32_t &prevSpea
|
|||
//
|
||||
//============================================================================
|
||||
|
||||
static FStrifeDialogueNode *ReadTeaserNode (FileReader &lump, uint32_t &prevSpeakerType)
|
||||
static FStrifeDialogueNode *ReadTeaserNode (FLevelLocals *Level, FileReader &lump, uint32_t &prevSpeakerType)
|
||||
{
|
||||
FStrifeDialogueNode *node;
|
||||
TeaserSpeech speech;
|
||||
|
|
@ -418,9 +410,9 @@ static FStrifeDialogueNode *ReadTeaserNode (FileReader &lump, uint32_t &prevSpea
|
|||
{
|
||||
if (type != NULL)
|
||||
{
|
||||
ClassRoots[type->TypeName] = StrifeDialogues.Size();
|
||||
Level->ClassRoots[type->TypeName] = Level->StrifeDialogues.Size();
|
||||
}
|
||||
DialogueRoots[speech.SpeakerType] = StrifeDialogues.Size();
|
||||
Level->DialogueRoots[speech.SpeakerType] = Level->StrifeDialogues.Size();
|
||||
prevSpeakerType = speech.SpeakerType;
|
||||
}
|
||||
|
||||
|
|
@ -581,7 +573,7 @@ FStrifeDialogueNode::~FStrifeDialogueNode ()
|
|||
//
|
||||
//============================================================================
|
||||
|
||||
static int FindNode (const FStrifeDialogueNode *node)
|
||||
int FLevelLocals::FindNode (const FStrifeDialogueNode *node)
|
||||
{
|
||||
int rootnode = 0;
|
||||
|
||||
|
|
@ -725,16 +717,6 @@ DEFINE_ACTION_FUNCTION(DConversationMenu, SendConversationReply)
|
|||
|
||||
void P_FreeStrifeConversations ()
|
||||
{
|
||||
FStrifeDialogueNode *node;
|
||||
|
||||
while (StrifeDialogues.Pop (node))
|
||||
{
|
||||
delete node;
|
||||
}
|
||||
|
||||
DialogueRoots.Clear();
|
||||
ClassRoots.Clear();
|
||||
|
||||
PrevNode = NULL;
|
||||
if (CurrentMenu != NULL && CurrentMenu->IsKindOf("ConversationMenu"))
|
||||
{
|
||||
|
|
@ -756,7 +738,8 @@ void P_StartConversation (AActor *npc, AActor *pc, bool facetalker, bool saveang
|
|||
int i;
|
||||
|
||||
// Make sure this is actually a player.
|
||||
if (pc->player == NULL) return;
|
||||
if (pc == nullptr || pc->player == nullptr || npc == nullptr) return;
|
||||
auto Level = &level;
|
||||
|
||||
// [CW] If an NPC is talking to a PC already, then don't let
|
||||
// anyone else talk to the NPC.
|
||||
|
|
@ -818,7 +801,7 @@ void P_StartConversation (AActor *npc, AActor *pc, bool facetalker, bool saveang
|
|||
if (jump && CurNode->ItemCheckNode > 0)
|
||||
{
|
||||
int root = pc->player->ConversationNPC->ConversationRoot;
|
||||
CurNode = StrifeDialogues[root + CurNode->ItemCheckNode - 1];
|
||||
CurNode = Level->StrifeDialogues[root + CurNode->ItemCheckNode - 1];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -904,14 +887,14 @@ static void HandleReply(player_t *player, bool isconsole, int nodenum, int reply
|
|||
AActor *npc;
|
||||
bool takestuff;
|
||||
int i;
|
||||
|
||||
if (player->ConversationNPC == NULL || (unsigned)nodenum >= StrifeDialogues.Size())
|
||||
auto Level = &level;
|
||||
if (player->ConversationNPC == nullptr || (unsigned)nodenum >= Level->StrifeDialogues.Size())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Find the reply.
|
||||
node = StrifeDialogues[nodenum];
|
||||
node = Level->StrifeDialogues[nodenum];
|
||||
for (i = 0, reply = node->Children; reply != NULL && i != replynum; ++i, reply = reply->Next)
|
||||
{ }
|
||||
npc = player->ConversationNPC;
|
||||
|
|
@ -1041,9 +1024,9 @@ static void HandleReply(player_t *player, bool isconsole, int nodenum, int reply
|
|||
const bool isNegative = reply->NextNode < 0;
|
||||
const unsigned next = (unsigned)(rootnode + (isNegative ? -1 : 1) * reply->NextNode - 1);
|
||||
|
||||
if (next < StrifeDialogues.Size())
|
||||
if (next < Level->StrifeDialogues.Size())
|
||||
{
|
||||
npc->Conversation = StrifeDialogues[next];
|
||||
npc->Conversation = Level->StrifeDialogues[next];
|
||||
|
||||
if (isNegative)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue