summaryrefslogtreecommitdiff
path: root/src/strife/p_dialog.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/strife/p_dialog.c')
-rw-r--r--src/strife/p_dialog.c88
1 files changed, 80 insertions, 8 deletions
diff --git a/src/strife/p_dialog.c b/src/strife/p_dialog.c
index d22e217b..2b20f55d 100644
--- a/src/strife/p_dialog.c
+++ b/src/strife/p_dialog.c
@@ -53,11 +53,13 @@ static boolean script0loaded;
// Number of dialogs defined in the current level's script.
static int numleveldialogs;
-// Pointer to level dialog script data
-static byte *leveldialogptr;
+// The actual level dialogs. This didn't exist in Strife, but is new to account
+// for structure alignment/packing concerns, given that Chocolate Doom is
+// multiplatform.
+static mapdialog_t *leveldialogs;
-// Pointer to SCRIPT0 data
-static byte *script0ptr;
+// The actual script00 dialogs. As above.
+static mapdialog_t *script0dialogs;
// Number of dialogs defined in the SCRIPT00 lump.
static int numscript0dialogs;
@@ -66,6 +68,68 @@ static int numscript0dialogs;
// Routines
//
+#define DIALOG_INT(field, ptr) \
+ field = ((int)ptr[0] | \
+ ((int)ptr[1] << 8) | \
+ ((int)ptr[2] << 16) | \
+ ((int)ptr[3] << 24)); \
+ ptr += 4;
+
+#define DIALOG_STR(field, ptr, len) \
+ memcpy(field, ptr, len); \
+ ptr += len;
+
+//
+// P_ParseDialogLump
+//
+// haleyjd 09/02/10: This is a new function added to parse out the dialogs
+// from the dialog lump rather than reading them raw from the lump pointer.
+// This avoids problems with structure packing.
+//
+static void P_ParseDialogLump(byte *lump, mapdialog_t **dialogs,
+ int numdialogs, int tag)
+{
+ int i;
+ byte *rover = lump;
+
+ *dialogs = Z_Malloc(numdialogs * sizeof(mapdialog_t), tag, NULL);
+
+ for(i = 0; i < numdialogs; i++)
+ {
+ int j;
+ mapdialog_t *curdialog = &((*dialogs)[i]);
+
+ DIALOG_INT(curdialog->speakerid, rover);
+ DIALOG_INT(curdialog->dropitem, rover);
+ DIALOG_INT(curdialog->checkitem1, rover);
+ DIALOG_INT(curdialog->checkitem2, rover);
+ DIALOG_INT(curdialog->checkitem3, rover);
+ DIALOG_INT(curdialog->jumptoconv, rover);
+ DIALOG_STR(curdialog->name, rover, MDLG_NAMELEN);
+ DIALOG_STR(curdialog->voice, rover, MDLG_LUMPLEN);
+ DIALOG_STR(curdialog->backpic, rover, MDLG_LUMPLEN);
+ DIALOG_STR(curdialog->text, rover, MDLG_TEXTLEN);
+
+ // copy choices
+ for(j = 0; j < 5; j++)
+ {
+ mapdlgchoice_t *curchoice = &(curdialog->choices[j]);
+ DIALOG_INT(curchoice->giveitem, rover);
+ DIALOG_INT(curchoice->needitem1, rover);
+ DIALOG_INT(curchoice->needitem2, rover);
+ DIALOG_INT(curchoice->needitem3, rover);
+ DIALOG_INT(curchoice->needamount1, rover);
+ DIALOG_INT(curchoice->needamount2, rover);
+ DIALOG_INT(curchoice->needamount3, rover);
+ DIALOG_STR(curchoice->text, rover, MDLG_CHOICELEN);
+ DIALOG_STR(curchoice->textok, rover, MDLG_MSGLEN);
+ DIALOG_INT(curchoice->next, rover);
+ DIALOG_INT(curchoice->objective, rover);
+ DIALOG_STR(curchoice->textno, rover, MDLG_MSGLEN);
+ }
+ }
+}
+
//
// P_DialogLoad
//
@@ -84,18 +148,26 @@ void P_DialogLoad(int eax0, int a2, int a3, int a4)
numleveldialogs = 0;
else
{
- leveldialogptr = W_CacheLumpNum(lumpnum, PU_LEVEL);
+ byte *leveldialogptr = W_CacheLumpNum(lumpnum, PU_STATIC);
numleveldialogs = W_LumpLength(lumpnum) / ORIG_MAPDIALOG_SIZE;
+ P_ParseDialogLump(leveldialogptr, &leveldialogs, numleveldialogs,
+ PU_LEVEL);
+ Z_Free(leveldialogptr); // haleyjd: free the original lump
}
// also load SCRIPT00 if it has not been loaded yet
if(!script0loaded)
{
+ byte *script0ptr;
+
script0loaded = true;
// BUG: Rogue should have used W_GetNumForName here...
lumpnum = W_CheckNumForName(DEH_String("script00"));
script0ptr = W_CacheLumpNum(lumpnum, PU_STATIC);
numscript0dialogs = W_LumpLength(lumpnum) / ORIG_MAPDIALOG_SIZE;
+ P_ParseDialogLump(script0ptr, &script0dialogs, numscript0dialogs,
+ PU_STATIC);
+ Z_Free(script0ptr); // haleyjd: free the original lump
}
}
@@ -114,15 +186,15 @@ int P_PlayerHasItem(player_t *player, mobjtype_t type)
{
// check keys
if(type >= MT_KEY_BASE && type < MT_INV_SHADOWARMOR)
- return 1; // STRIFE-FIXME: wtf is it doing here??? Should be player->cards...
+ return (player->cards[type - MT_KEY_BASE]);
// check sigil pieces
if(type >= MT_SIGIL_A && type <= MT_SIGIL_E)
- return type - MT_SIGIL_A <= player->sigiltype;
+ return (type - MT_SIGIL_A <= player->sigiltype);
// check quest tokens
if(type >= MT_TOKEN_QUEST1 && type <= MT_TOKEN_QUEST31)
- return player->questflags & (1 << (type - MT_TOKEN_QUEST1));
+ return (player->questflags & (1 << (type - MT_TOKEN_QUEST1)));
// check inventory
for(i = 0; i < 32; i++)