From 670c8b140830174e052242b75f4962f84425365f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 9 Dec 2019 18:40:07 +0100 Subject: [PATCH] - use the quote array to store the key, door and fortune cookie messages in Shadow Warrior. This is infinitely better than leaking char pointers. --- source/sw/src/game.h | 16 +++-- source/sw/src/rotator.cpp | 3 +- source/sw/src/scrip2.cpp | 13 ++-- source/sw/src/slidor.cpp | 3 +- source/sw/src/sprite.cpp | 47 ++------------ source/sw/src/text.cpp | 12 ---- source/sw/src/vator.cpp | 5 +- wadsrc/static/demolition/language.csv | 35 +++++++++- .../shadowwarrior/demolition/SWCustom.txt | 64 +++++++++---------- 9 files changed, 94 insertions(+), 104 deletions(-) diff --git a/source/sw/src/game.h b/source/sw/src/game.h index 17cbc12ef..508da6686 100644 --- a/source/sw/src/game.h +++ b/source/sw/src/game.h @@ -961,12 +961,18 @@ extern const char *ThemeSongs[6]; // extern char EpisodeNames[3][MAX_EPISODE_NAME_LEN+2]; -#define MAX_FORTUNES 16 -extern const char *ReadFortune[MAX_FORTUNES]; -#define MAX_KEYS 8 -extern const char *KeyMsg[MAX_KEYS]; -extern const char *KeyDoorMessage[MAX_KEYS]; + +enum +{ + MAX_KEYS = 8, + MAX_FORTUNES = 16, + + QUOTE_KEYMSG = 1, + QUOTE_DOORMSG = QUOTE_KEYMSG + MAX_KEYS, + // 23+24 are reserved. + QUOTE_COOKIE = 25, +}; typedef struct { diff --git a/source/sw/src/rotator.cpp b/source/sw/src/rotator.cpp index 97cd46f1d..029656b6f 100644 --- a/source/sw/src/rotator.cpp +++ b/source/sw/src/rotator.cpp @@ -35,6 +35,7 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms #include "text.h" #include "interp.h" #include "sprite.h" +#include "quotemgr.h" BEGIN_SW_NS @@ -217,7 +218,7 @@ DoRotatorMatch(PLAYERp pp, short match, SWBOOL manual) else #endif { - PutStringInfo(pp, KeyDoorMessage[key_num - 1]); + PutStringInfo(pp, quoteMgr.GetExQuote(QUOTE_DOORMSG + key_num - 1)); return -1; } } diff --git a/source/sw/src/scrip2.cpp b/source/sw/src/scrip2.cpp index f9598e064..0c4d6dde5 100644 --- a/source/sw/src/scrip2.cpp +++ b/source/sw/src/scrip2.cpp @@ -40,6 +40,7 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms #include "parent.h" #include "scriptfile.h" #include "menu/menu.h" +#include "quotemgr.h" BEGIN_SW_NS @@ -538,9 +539,6 @@ static int cm_transtok(const char *tok, const struct _tokset *set, const unsigne // quit "PRESS (Y) TO QUIT, (N) TO FIGHT ON." static LEVEL_INFO custommaps[MAX_LEVELS_REG]; -static char *customfortune[MAX_FORTUNES]; -static char *customkeymsg[MAX_KEYS]; -static char *customkeydoormsg[MAX_KEYS]; static char *custominventoryname[InvDecl_TOTAL]; static char *customweaponname[2][MAX_WEAPONS]; // weapon, ammo @@ -798,8 +796,7 @@ void LoadCustomInfoFromScript(const char *filename) if (fc == MAX_FORTUNES) continue; - customfortune[fc] = strdup(t); - if (customfortune[fc]) ReadFortune[fc] = customfortune[fc]; + quoteMgr.InitializeQuote(QUOTE_COOKIE + fc, t); fc++; } break; @@ -817,8 +814,7 @@ void LoadCustomInfoFromScript(const char *filename) if (fc == MAX_KEYS) continue; - customkeymsg[fc] = strdup(t); - if (customkeymsg[fc]) KeyMsg[fc] = customkeymsg[fc]; + quoteMgr.InitializeQuote(QUOTE_KEYMSG + fc, t); fc++; } break; @@ -836,8 +832,7 @@ void LoadCustomInfoFromScript(const char *filename) if (fc == MAX_KEYS) continue; - customkeydoormsg[fc] = strdup(t); - if (customkeydoormsg[fc]) KeyDoorMessage[fc] = customkeydoormsg[fc]; + quoteMgr.InitializeQuote(QUOTE_DOORMSG + fc, t); fc++; } break; diff --git a/source/sw/src/slidor.cpp b/source/sw/src/slidor.cpp index 697513cab..f13de4bf7 100644 --- a/source/sw/src/slidor.cpp +++ b/source/sw/src/slidor.cpp @@ -36,6 +36,7 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms #include "interp.h" #include "text.h" #include "sprite.h" +#include "quotemgr.h" BEGIN_SW_NS @@ -213,7 +214,7 @@ DoSlidorMatch(PLAYERp pp, short match, SWBOOL manual) else #endif { - PutStringInfo(pp, KeyDoorMessage[key_num - 1]); + PutStringInfo(pp, quoteMgr.GetExQuote(QUOTE_DOORMSG + key_num - 1)); return -1; } } diff --git a/source/sw/src/sprite.cpp b/source/sw/src/sprite.cpp index 60c131847..b3e409c2a 100644 --- a/source/sw/src/sprite.cpp +++ b/source/sw/src/sprite.cpp @@ -48,6 +48,8 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms #include "slidor.h" #include "player.h" #include "swcvar.h" +#include "quotemgr.h" +#include "v_text.h" BEGIN_SW_NS @@ -5505,29 +5507,6 @@ void ChoosePlayerGetSound(PLAYERp pp) PlayerSound(PlayerGetItemVocs[choose_snd],&pp->posx,&pp->posy,&pp->posz,v3df_follow|v3df_dontpan,pp); } -//#define MAX_FORTUNES 16 -// With PLOCK on, max = 11 -const char *ReadFortune[MAX_FORTUNES] = -{ - "You never going to score.", - "26-31-43-82-16-29", - "Sorry, you no win this time, try again.", - "You try harder get along. Be a nice man.", - "No man is island, except Lo Wang.", - "There is much death in future.", - "You should kill all business associates.", - "(c)1997,3DRealms fortune cookie company.", - "Your chi attracts many chicks.", - "Don't you know you the scum of society!?", - "You should not scratch yourself there.", - "Man who stand on toilet, high on pot.", - "Man who fart in church sit in own pew.", - "Man trapped in pantry has ass in jam.", - "Baseball wrong. Man with 4 balls cannot walk.", - "Man who buy drowned cat pay for wet pussy.", -}; - - SWBOOL CanGetWeapon(PLAYERp pp, short SpriteNum, int WPN) { USERp u = User[SpriteNum], pu; @@ -5563,18 +5542,6 @@ SWBOOL CanGetWeapon(PLAYERp pp, short SpriteNum, int WPN) return TRUE; } -const char *KeyMsg[MAX_KEYS] = -{ - "Got the RED key!", - "Got the BLUE key!", - "Got the GREEN key!", - "Got the YELLOW key!", - "Got the GOLD master key!", - "Got the SILVER master key!", - "Got the BRONZE master key!", - "Got the RED master key!" -}; - struct InventoryDecl_t InventoryDecls[InvDecl_TOTAL] = { { "Armor Vest +50", 50 }, @@ -5702,7 +5669,7 @@ KeyMain: if (pp->HasKey[key_num]) break; - PutStringInfo(Player+pnum, KeyMsg[key_num]); + PutStringInfo(Player+pnum, quoteMgr.GetQuote(QUOTE_KEYMSG + key_num)); pp->HasKey[key_num] = TRUE; SetFadeAmt(pp,ITEMFLASHAMT,ITEMFLASHCLR); // Flash blue on item pickup @@ -5795,11 +5762,9 @@ KeyMain: // Say something witty if (pp == Player+myconnectindex && hud_messages) { - if (adult_lockout || Global_PLock) - sprintf(ds,"Fortune Say: %s\n",ReadFortune[STD_RANDOM_RANGE(10)]); - else - sprintf(ds,"Fortune Say: %s\n",ReadFortune[STD_RANDOM_RANGE(MAX_FORTUNES)]); - OSD_Printf("%s", ds); + int cookie = (adult_lockout || Global_PLock)? STD_RANDOM_RANGE(10) : STD_RANDOM_RANGE(MAX_FORTUNES); + // print to the console, and if active to the generic notify display. + Printf(PRINT_NOTIFY, TEXTCOLOR_SAPPHIRE "%s: %s\n", GStrings("TXTS_FORTUNE"), quoteMgr.GetQuote(QUOTE_COOKIE + cookie)); } SetFadeAmt(pp,ITEMFLASHAMT,ITEMFLASHCLR); // Flash blue on item pickup diff --git a/source/sw/src/text.cpp b/source/sw/src/text.cpp index 11fb643c3..090e79437 100644 --- a/source/sw/src/text.cpp +++ b/source/sw/src/text.cpp @@ -49,18 +49,6 @@ BEGIN_SW_NS #define PANEL_SM_FONT_Y 3613 #define PANEL_SM_FONT_R 3625 -const char *KeyDoorMessage[MAX_KEYS] = -{ - "You need a RED key for this door.", - "You need a BLUE key for this door.", - "You need a GREEN key for this door.", - "You need a YELLOW key for this door.", - "You need a GOLD key for this door.", - "You need a SILVER key for this door.", - "You need a BRONZE key for this door.", - "You need a RED key for this door." -}; - void DisplaySummaryString(PLAYERp pp, short xs, short ys, short color, short shade, const char *buffer) { short size,x; diff --git a/source/sw/src/vator.cpp b/source/sw/src/vator.cpp index ecba7c777..bb3f013ea 100644 --- a/source/sw/src/vator.cpp +++ b/source/sw/src/vator.cpp @@ -36,6 +36,7 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms #include "text.h" #include "sprite.h" #include "weapon.h" +#include "quotemgr.h" BEGIN_SW_NS @@ -199,7 +200,7 @@ short DoVatorOperate(PLAYERp pp, short sectnum) else #endif { - PutStringInfo(pp, KeyDoorMessage[key_num - 1]); + PutStringInfo(pp, quoteMgr.GetExQuote(QUOTE_DOORMSG + key_num - 1)); return FALSE; } } @@ -267,7 +268,7 @@ DoVatorMatch(PLAYERp pp, short match) else #endif { - PutStringInfo(pp, KeyDoorMessage[key_num - 1]); + PutStringInfo(pp, quoteMgr.GetExQuote(QUOTE_DOORMSG + key_num - 1)); return -1; } } diff --git a/wadsrc/static/demolition/language.csv b/wadsrc/static/demolition/language.csv index 6b814cc19..45083934c 100644 --- a/wadsrc/static/demolition/language.csv +++ b/wadsrc/static/demolition/language.csv @@ -1775,4 +1775,37 @@ TXTS_EPD2,Eighteen levels (Full Version Only),,,,,,,,,,,,,,,,,,,,,, TXTS_SK1,Tiny grasshopper,,,,,,,,,,,,,,,,,,,,,, TXTS_SK2,I Have No Fear,,,,,,,,,,,,,,,,,,,,,, TXTS_SK3,Who Wants Wang,,,,,,,,,,,,,,,,,,,,,, -TXTS_SK4,"No Pain, No Gain",,,,,,,,,,,,,,,,,,,,,, \ No newline at end of file +TXTS_SK4,"No Pain, No Gain",,,,,,,,,,,,,,,,,,,,,, +Got the RED key!,TXTS_KEY1,,,,,,,,,,,,,,,,,,,,,, +Got the BLUE key!,TXTS_KEY2,,,,,,,,,,,,,,,,,,,,,, +Got the GREEN key!,TXTS_KEY3,,,,,,,,,,,,,,,,,,,,,, +Got the YELLOW key!,TXTS_KEY4,,,,,,,,,,,,,,,,,,,,,, +Got the GOLD master key!,TXTS_KEY5,,,,,,,,,,,,,,,,,,,,,, +Got the SILVER master key!,TXTS_KEY6,,,,,,,,,,,,,,,,,,,,,, +Got the BRONZE master key!,TXTS_KEY7,,,,,,,,,,,,,,,,,,,,,, +Got the RED master key!,TXTS_KEY8,,,,,,,,,,,,,,,,,,,,,, +You need a RED key for this door.,TXTS_DOOR1,,,,,,,,,,,,,,,,,,,,,, +You need a BLUE key for this door.,TXTS_DOOR2,,,,,,,,,,,,,,,,,,,,,, +You need a GREEN key for this door.,TXTS_DOOR3,,,,,,,,,,,,,,,,,,,,,, +You need a YELLOW key for this door.,TXTS_DOOR4,,,,,,,,,,,,,,,,,,,,,, +You need a GOLD key for this door.,TXTS_DOOR5,,,,,,,,,,,,,,,,,,,,,, +You need a SILVER key for this door.,TXTS_DOOR6,,,,,,,,,,,,,,,,,,,,,, +You need a BRONZE key for this door.,TXTS_DOOR7,,,,,,,,,,,,,,,,,,,,,, +You need a RED key for this door.,TXTS_DOOR8,,,,,,,,,,,,,,,,,,,,,, +You never going to score.,TXTS_COOKIE1,,,,,,,,,,,,,,,,,,,,,, +26-31-43-82-16-29,TXTS_COOKIE2,,,,,,,,,,,,,,,,,,,,,, +"Sorry, you no win this time, try again.",TXTS_COOKIE3,,,,,,,,,,,,,,,,,,,,,, +You try harder get along. Be a nice man.,TXTS_COOKIE4,,,,,,,,,,,,,,,,,,,,,, +"No man is island, except Lo Wang.",TXTS_COOKIE5,,,,,,,,,,,,,,,,,,,,,, +There is much death in future.,TXTS_COOKIE6,,,,,,,,,,,,,,,,,,,,,, +You should kill all business associates.,TXTS_COOKIE7,,,,,,,,,,,,,,,,,,,,,, +"(c)1997,3DRealms fortune cookie company.",TXTS_COOKIE8,,,,,,,,,,,,,,,,,,,,,, +Your chi attracts many chicks.,TXTS_COOKIE9,,,,,,,,,,,,,,,,,,,,,, +Don't you know you the scum of society!?,TXTS_COOKIE10,,,,,,,,,,,,,,,,,,,,,, +You should not scratch yourself there.,TXTS_COOKIE11,,,,,,,,,,,,,,,,,,,,,, +"Man who stand on toilet, high on pot.",TXTS_COOKIE12,,,,,,,,,,,,,,,,,,,,,, +Man who fart in church sit in own pew.,TXTS_COOKIE13,,,,,,,,,,,,,,,,,,,,,, +Man trapped in pantry has ass in jam.,TXTS_COOKIE14,,,,,,,,,,,,,,,,,,,,,, +Baseball wrong. Man with 4 balls cannot walk.,TXTS_COOKIE15,,,,,,,,,,,,,,,,,,,,,, +Man who buy drowned cat pay for wet pussy.,TXTS_COOKIE16,,,,,,,,,,,,,,,,,,,,,, +Fortune Say:,TXTS_FORTUNE,,,,,,,,,,,,,,,,,,,,,, \ No newline at end of file diff --git a/wadsrc/static/filter/shadowwarrior/demolition/SWCustom.txt b/wadsrc/static/filter/shadowwarrior/demolition/SWCustom.txt index 62b54e600..7ffcf34f8 100644 --- a/wadsrc/static/filter/shadowwarrior/demolition/SWCustom.txt +++ b/wadsrc/static/filter/shadowwarrior/demolition/SWCustom.txt @@ -446,44 +446,44 @@ weapon 12 } fortune { - "You never going to score." - "26-31-43-82-16-29" - "Sorry, you no win this time, try again." - "You try harder get along. Be a nice man." - "No man is island, except Lo Wang." - "There is much death in future." - "You should kill all business associates." - "(c)1997,3DRealms fortune cookie company." - "Your chi attracts many chicks." - "Don't you know you the scum of society!?" - "You should not scratch yourself there." - "Man who stand on toilet, high on pot." - "Man who fart in church sit in own pew." - "Man trapped in pantry has ass in jam." - "Baseball wrong. Man with 4 balls cannot walk." - "Man who buy drowned cat pay for wet pussy." + "$TXTS_COOKIE1" + "$TXTS_COOKIE2" + "$TXTS_COOKIE3" + "$TXTS_COOKIE4" + "$TXTS_COOKIE5" + "$TXTS_COOKIE6" + "$TXTS_COOKIE7" + "$TXTS_COOKIE8" + "$TXTS_COOKIE9" + "$TXTS_COOKIE10" + "$TXTS_COOKIE11" + "$TXTS_COOKIE12" + "$TXTS_COOKIE13" + "$TXTS_COOKIE14" + "$TXTS_COOKIE15" + "$TXTS_COOKIE16" } gotkey { - "Got the RED key!" - "Got the BLUE key!" - "Got the GREEN key!" - "Got the YELLOW key!" - "Got the GOLD master key!" - "Got the SILVER master key!" - "Got the BRONZE master key!" - "Got the RED master key!" + "$TXTS_KEY1" + "$TXTS_KEY2" + "$TXTS_KEY3" + "$TXTS_KEY4" + "$TXTS_KEY5" + "$TXTS_KEY6" + "$TXTS_KEY7" + "$TXTS_KEY8" } needkey { - "You need a RED key for this door." - "You need a BLUE key for this door." - "You need a GREEN key for this door." - "You need a YELLOW key for this door." - "You need a GOLD key for this door." - "You need a SILVER key for this door." - "You need a BRONZE key for this door." - "You need a RED key for this door." + "$TXTS_DOOR1" + "$TXTS_DOOR2" + "$TXTS_DOOR3" + "$TXTS_DOOR4" + "$TXTS_DOOR5" + "$TXTS_DOOR6" + "$TXTS_DOOR7" + "$TXTS_DOOR8" } theme 1 // game startup menu {