Permalink
Browse files

Moved Strife conversation data into FLevelLocals.

  • Loading branch information...
coelckers committed Jan 9, 2019
1 parent 0ed856f commit 0180bcb178cf6fd0c5abed6c237418a841ec64c6
Showing with 91 additions and 83 deletions.
  1. +4 −0 src/g_level.cpp
  2. +14 −1 src/g_levellocals.h
  3. +1 −1 src/maploader/maploader.cpp
  4. +37 −54 src/p_conversation.cpp
  5. +3 −8 src/p_conversation.h
  6. +2 −2 src/p_lnspec.cpp
  7. +4 −4 src/p_mobj.cpp
  8. +10 −1 src/p_setup.cpp
  9. +14 −10 src/p_usdf.cpp
  10. +2 −2 src/serializer.cpp
@@ -79,6 +79,7 @@
#include "events.h"
#include "i_music.h"
#include "a_dynlight.h"
#include "p_conversation.h"

#include "gi.h"

@@ -771,6 +772,9 @@ void G_DoCompleted (void)

if (automapactive)
AM_Stop ();

// Close the conversation menu if open.
P_FreeStrifeConversations ();

wminfo.finished_ep = level.cluster - 1;
wminfo.LName0 = TexMan.CheckForTexture(level.info->PName, ETextureType::MiscPatch);
@@ -52,6 +52,10 @@
class DACSThinker;
class DFraggleThinker;
class DSpotState;
struct FStrifeDialogueNode;

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

struct FLevelData
{
@@ -105,9 +109,15 @@ struct FLevelData

FTagManager tagManager;
AActor *TIDHash[128];

TArray<FStrifeDialogueNode *> StrifeDialogues;
FDialogueIDMap DialogueRoots;
FDialogueMap ClassRoots;


};


struct FLevelLocals : public FLevelData
{
void Tick();
@@ -125,7 +135,10 @@ struct FLevelLocals : public FLevelData
void InitLevelLocals();
bool IsTIDUsed(int tid);
int FindUniqueTID(int start_tid, int limit);

int GetConversation(int conv_id);
int GetConversation(FName classname);
void SetConversation(int convid, PClassActor *Class, int dlgindex);
int FindNode (const FStrifeDialogueNode *node);

//
// P_ClearTidHashes
@@ -2978,7 +2978,7 @@ void MapLoader::LoadLevel(MapData *map, const char *lumpname, int position)
LoadMapinfoACSLump();


P_LoadStrifeConversations(map, lumpname);
P_LoadStrifeConversations(Level, map, lumpname);

FMissingTextureTracker missingtex;

@@ -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,22 +184,22 @@ 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;
}
}

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 = pc->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 = player->mo->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)
{
@@ -57,19 +57,14 @@ struct FStrifeDialogueReply
bool NeedsGold = false;
};

extern TArray<FStrifeDialogueNode *> StrifeDialogues;

struct MapData;

void SetStrifeType(int convid, PClassActor *Class);
void SetConversation(int convid, PClassActor *Class, int dlgindex);
PClassActor *GetStrifeType (int typenum);
int GetConversation(int conv_id);
int GetConversation(FName classname);

bool LoadScriptFile (const char *name, bool include, int type = 0);
bool LoadScriptFile (FLevelLocals *Level, const char *name, bool include, int type = 0);

void P_LoadStrifeConversations (MapData *map, const char *mapname);
void P_LoadStrifeConversations (FLevelLocals *Level, MapData *map, const char *mapname);
void P_FreeStrifeConversations ();

void P_StartConversation (AActor *npc, AActor *pc, bool facetalker, bool saveangle);
@@ -78,7 +73,7 @@ void P_ResumeConversation ();
void P_ConversationCommand (int netcode, int player, uint8_t **stream);

class FileReader;
bool P_ParseUSDF(int lumpnum, FileReader &lump, int lumplen);
bool P_ParseUSDF(FLevelLocals *Level, int lumpnum, FileReader &lump, int lumplen);


#endif
@@ -3378,9 +3378,9 @@ FUNC(LS_Thing_SetConversation)

if (arg1 != 0)
{
dlg_index = GetConversation(arg1);
dlg_index = Level->GetConversation(arg1);
if (dlg_index == -1) return false;
node = StrifeDialogues[dlg_index];
node = Level->StrifeDialogues[dlg_index];
}

if (arg0 != 0)
Oops, something went wrong.

0 comments on commit 0180bcb

Please sign in to comment.