diff --git a/src/actor.h b/src/actor.h index 06deafdaa..c21270af6 100644 --- a/src/actor.h +++ b/src/actor.h @@ -380,6 +380,8 @@ enum ActorFlag7 MF7_LAXTELEFRAGDMG = 0x00100000, // [MC] Telefrag damage can be reduced. MF7_ICESHATTER = 0x00200000, // [MC] Shatters ice corpses regardless of damagetype. MF7_ALLOWTHRUFLAGS = 0x00400000, // [MC] Allow THRUACTORS and the likes on puffs to prevent mod breakage. + MF7_USEKILLSCRIPTS = 0x00800000, // [JM] Use "KILL" Script on death if not forced by GameInfo. + MF7_NOKILLSCRIPTS = 0x01000000, // [JM] No "KILL" Script on death whatsoever, even if forced by GameInfo. }; // --- mobj.renderflags --- diff --git a/src/g_shared/a_pickups.h b/src/g_shared/a_pickups.h index 26b27e202..0023cd271 100644 --- a/src/g_shared/a_pickups.h +++ b/src/g_shared/a_pickups.h @@ -378,6 +378,8 @@ enum WIF_MELEEWEAPON = 0x00008000, // melee weapon. Used by bots and monster AI. WIF_DEHAMMO = 0x00010000, // Uses Doom's original amount of ammo for the respective attack functions so that old DEHACKED patches work as intended. // AmmoUse1 will be set to the first attack's ammo use so that checking for empty weapons still works + WIF_NODEATHDESELECT = 0x00020000, // Don't jump to the Deselect state when the player dies + WIF_NODEATHINPUT = 0x00040000, // The weapon cannot be fired/reloaded/whatever when the player is dead WIF_CHEATNOTWEAPON = 0x08000000, // Give cheat considers this not a weapon (used by Sigil) // Flags used only by bot AI: diff --git a/src/g_shared/shared_hud.cpp b/src/g_shared/shared_hud.cpp index 46cf61d54..3a8dc388c 100644 --- a/src/g_shared/shared_hud.cpp +++ b/src/g_shared/shared_hud.cpp @@ -539,6 +539,38 @@ static void AddAmmoToList(AWeapon * weapdef) } } +static int GetDigitCount(int value) +{ + int digits = 0; + + do + { + value /= 10; + ++digits; + } + while (0 != value); + + return digits; +} + +static void GetAmmoTextLengths(player_t *CPlayer, int& ammocur, int& ammomax) +{ + for (auto type : orderedammos) + { + AAmmo * ammoitem = static_cast(CPlayer->mo->FindInventory(type)); + AAmmo * inv = nullptr == ammoitem + ? static_cast(GetDefaultByType(type)) + : ammoitem; + assert(nullptr != inv); + + ammocur = MAX(ammocur, nullptr == ammoitem ? 0 : ammoitem->Amount); + ammomax = MAX(ammomax, inv->MaxAmount); + } + + ammocur = GetDigitCount(ammocur); + ammomax = GetDigitCount(ammomax); +} + static int DrawAmmo(player_t *CPlayer, int x, int y) { @@ -586,7 +618,13 @@ static int DrawAmmo(player_t *CPlayer, int x, int y) // ok, we got all ammo types. Now draw the list back to front (bottom to top) - int def_width = ConFont->StringWidth("000/000"); + int ammocurlen = 0; + int ammomaxlen = 0; + GetAmmoTextLengths(CPlayer, ammocurlen, ammomaxlen); + + mysnprintf(buf, countof(buf), "%0*d/%0*d", ammocurlen, 0, ammomaxlen, 0); + + int def_width = ConFont->StringWidth(buf); int yadd = ConFont->GetHeight(); int xtext = x - def_width; @@ -618,7 +656,7 @@ static int DrawAmmo(player_t *CPlayer, int x, int y) int maxammo = inv->MaxAmount; int ammo = ammoitem? ammoitem->Amount : 0; - mysnprintf(buf, countof(buf), "%3d/%3d", ammo, maxammo); + mysnprintf(buf, countof(buf), "%*d/%*d", ammocurlen, ammo, ammomaxlen, maxammo); int tex_width= clamp(ConFont->StringWidth(buf)-def_width, 0, 1000); diff --git a/src/gi.cpp b/src/gi.cpp index 313df4f0b..9d45d2724 100644 --- a/src/gi.cpp +++ b/src/gi.cpp @@ -354,6 +354,7 @@ void FMapInfoParser::ParseGameInfo() GAMEINFOKEY_PATCH(mStatscreenFinishedFont, "statscreen_finishedpatch") GAMEINFOKEY_PATCH(mStatscreenEnteringFont, "statscreen_enteringpatch") GAMEINFOKEY_BOOL(norandomplayerclass, "norandomplayerclass") + GAMEINFOKEY_BOOL(forcekillscripts, "forcekillscripts") // [JM] Force kill scripts on thing death. (MF7_NOKILLSCRIPTS overrides.) else { diff --git a/src/gi.h b/src/gi.h index 2786b3425..c5b8f79cf 100644 --- a/src/gi.h +++ b/src/gi.h @@ -173,6 +173,7 @@ struct gameinfo_t FGIFont mStatscreenFinishedFont; FGIFont mStatscreenEnteringFont; bool norandomplayerclass; + bool forcekillscripts; const char *GetFinalePage(unsigned int num) const; }; diff --git a/src/menu/menu.h b/src/menu/menu.h index aa4058f87..04ae7e3f7 100644 --- a/src/menu/menu.h +++ b/src/menu/menu.h @@ -418,7 +418,7 @@ public: class FPlayerNameBox : public FListMenuItemSelectable { - const char *mText; + FString mText; FFont *mFont; EColorRange mFontColor; int mFrameSize; @@ -447,7 +447,7 @@ public: class FValueTextItem : public FListMenuItemSelectable { TArray mSelections; - const char *mText; + FString mText; int mSelection; FFont *mFont; EColorRange mFontColor; @@ -472,7 +472,7 @@ public: class FSliderItem : public FListMenuItemSelectable { - const char *mText; + FString mText; FFont *mFont; EColorRange mFontColor; int mMinrange, mMaxrange; @@ -539,7 +539,7 @@ public: class FOptionMenuItem : public FListMenuItem { protected: - char *mLabel; + FString mLabel; bool mCentered; void drawLabel(int indent, int y, EColorRange color, bool grayed = false); @@ -548,7 +548,7 @@ public: FOptionMenuItem(const char *text, FName action = NAME_None, bool center = false) : FListMenuItem(0, 0, action) { - mLabel = copystring(text); + mLabel = text; mCentered = center; } diff --git a/src/menu/menudef.cpp b/src/menu/menudef.cpp index 1948153e4..618189b4f 100644 --- a/src/menu/menudef.cpp +++ b/src/menu/menudef.cpp @@ -781,7 +781,15 @@ static void ParseOptionMenuBody(FScanner &sc, FOptionMenuDescriptor *desc) FString label = sc.String; sc.MustGetStringName(","); sc.MustGetString(); - FOptionMenuItem *it = new FOptionMenuItemSafeCommand(label, sc.String); + FString command = sc.String; + FString prompt; + // Check for optional custom prompt + if (sc.CheckString(",")) + { + sc.MustGetString(); + prompt = sc.String; + } + FOptionMenuItem *it = new FOptionMenuItemSafeCommand(label, command, prompt); desc->mItems.Push(it); } else if (sc.Compare("Control") || sc.Compare("MapControl")) diff --git a/src/menu/optionmenu.cpp b/src/menu/optionmenu.cpp index f6633c76a..efea7d910 100644 --- a/src/menu/optionmenu.cpp +++ b/src/menu/optionmenu.cpp @@ -479,7 +479,6 @@ void DOptionMenu::Drawer () FOptionMenuItem::~FOptionMenuItem() { - if (mLabel != NULL) delete [] mLabel; } int FOptionMenuItem::Draw(FOptionMenuDescriptor *desc, int y, int indent, bool selected) @@ -507,14 +506,14 @@ int FOptionMenuItem::GetIndent() { return 0; } - const char *label = mLabel; + const char *label = mLabel.GetChars(); if (*label == '$') label = GStrings(label+1); return SmallFont->StringWidth(label); } void FOptionMenuItem::drawLabel(int indent, int y, EColorRange color, bool grayed) { - const char *label = mLabel; + const char *label = mLabel.GetChars(); if (*label == '$') label = GStrings(label+1); int overlay = grayed? MAKEARGB(96,48,0,0) : 0; diff --git a/src/menu/optionmenuitems.h b/src/menu/optionmenuitems.h index 3131e35f7..76718809e 100644 --- a/src/menu/optionmenuitems.h +++ b/src/menu/optionmenuitems.h @@ -103,9 +103,13 @@ public: class FOptionMenuItemSafeCommand : public FOptionMenuItemCommand { // action is a CCMD +protected: + FString mPrompt; + public: - FOptionMenuItemSafeCommand(const char *label, const char *menu) + FOptionMenuItemSafeCommand(const char *label, const char *menu, const char *prompt) : FOptionMenuItemCommand(label, menu) + , mPrompt(prompt) { } @@ -121,9 +125,13 @@ public: bool Activate() { - const char *msg = GStrings("SAFEMESSAGE"); + const char *msg = mPrompt.IsNotEmpty() ? mPrompt.GetChars() : "$SAFEMESSAGE"; + if (*msg == '$') + { + msg = GStrings(msg + 1); + } - const char *actionLabel = mLabel; + const char *actionLabel = mLabel.GetChars(); if (actionLabel != NULL) { if (*actionLabel == '$') @@ -528,7 +536,7 @@ public: int Draw(FOptionMenuDescriptor *desc, int y, int indent, bool selected) { - const char *txt = mCurrent? mAltText.GetChars() : mLabel; + const char *txt = mCurrent? mAltText.GetChars() : mLabel.GetChars(); if (*txt == '$') txt = GStrings(txt + 1); int w = SmallFont->StringWidth(txt) * CleanXfac_1; int x = (screen->GetWidth() - w) / 2; diff --git a/src/menu/playermenu.cpp b/src/menu/playermenu.cpp index cf63283ba..ce542c2f2 100644 --- a/src/menu/playermenu.cpp +++ b/src/menu/playermenu.cpp @@ -64,7 +64,7 @@ EXTERN_CVAR (Bool, cl_run) FPlayerNameBox::FPlayerNameBox(int x, int y, int height, int frameofs, const char *text, FFont *font, EColorRange color, FName action) : FListMenuItemSelectable(x, y, height, action) { - mText = copystring(text); + mText = text; mFont = font; mFontColor = color; mFrameSize = frameofs; @@ -74,7 +74,6 @@ FPlayerNameBox::FPlayerNameBox(int x, int y, int height, int frameofs, const cha FPlayerNameBox::~FPlayerNameBox() { - if (mText != NULL) delete [] mText; } //============================================================================= @@ -220,7 +219,7 @@ bool FPlayerNameBox::MenuEvent(int mkey, bool fromcontroller) FValueTextItem::FValueTextItem(int x, int y, int height, const char *text, FFont *font, EColorRange color, EColorRange valuecolor, FName action, FName values) : FListMenuItemSelectable(x, y, height, action) { - mText = copystring(text); + mText = text; mFont = font; mFontColor = color; mFontColor2 = valuecolor; @@ -240,7 +239,6 @@ FValueTextItem::FValueTextItem(int x, int y, int height, const char *text, FFont FValueTextItem::~FValueTextItem() { - if (mText != NULL) delete [] mText; } //============================================================================= @@ -341,7 +339,7 @@ void FValueTextItem::Drawer(bool selected) FSliderItem::FSliderItem(int x, int y, int height, const char *text, FFont *font, EColorRange color, FName action, int min, int max, int step) : FListMenuItemSelectable(x, y, height, action) { - mText = copystring(text); + mText = text; mFont = font; mFontColor = color; mSelection = 0; @@ -352,7 +350,6 @@ FSliderItem::FSliderItem(int x, int y, int height, const char *text, FFont *font FSliderItem::~FSliderItem() { - if (mText != NULL) delete [] mText; } //============================================================================= diff --git a/src/p_acs.h b/src/p_acs.h index 13dad4651..243e2ccf3 100644 --- a/src/p_acs.h +++ b/src/p_acs.h @@ -270,6 +270,8 @@ enum SCRIPT_Unloading = 13, SCRIPT_Disconnect = 14, SCRIPT_Return = 15, + SCRIPT_Event = 16, // [BB] + SCRIPT_Kill = 17, // [JM] }; // Script flags diff --git a/src/p_interaction.cpp b/src/p_interaction.cpp index 8890d3592..9f50c9ab5 100644 --- a/src/p_interaction.cpp +++ b/src/p_interaction.cpp @@ -379,6 +379,12 @@ void AActor::Die (AActor *source, AActor *inflictor, int dmgflags) target = source; } + // [JM] Fire KILL type scripts for actor. Not needed for players, since they have the "DEATH" script type. + if (!player && !(flags7 & MF7_NOKILLSCRIPTS) && ((flags7 & MF7_USEKILLSCRIPTS) || gameinfo.forcekillscripts)) + { + FBehavior::StaticStartTypedScripts(SCRIPT_Kill, this, true, 0, true); + } + flags &= ~(MF_SHOOTABLE|MF_FLOAT|MF_SKULLFLY); if (!(flags4 & MF4_DONTFALL)) flags&=~MF_NOGRAVITY; flags |= MF_DROPOFF; diff --git a/src/p_pspr.cpp b/src/p_pspr.cpp index bad9c2d73..350acc3fd 100644 --- a/src/p_pspr.cpp +++ b/src/p_pspr.cpp @@ -510,7 +510,7 @@ void P_DropWeapon (player_t *player) } // Since the weapon is dropping, stop blocking switching. player->WeaponState &= ~WF_DISABLESWITCH; - if (player->ReadyWeapon != nullptr) + if ((player->ReadyWeapon != nullptr) && (player->health > 0 || !(player->ReadyWeapon->WeaponFlags & WIF_NODEATHDESELECT))) { P_SetPsprite(player, PSP_WEAPON, player->ReadyWeapon->GetDownState()); } @@ -1396,20 +1396,23 @@ void player_t::TickPSprites() pspr = pspr->Next; } - if (ReadyWeapon == nullptr && (health > 0 || mo->DamageType != NAME_Fire)) + if ((health > 0) || (ReadyWeapon != nullptr && !(ReadyWeapon->WeaponFlags & WIF_NODEATHINPUT))) { - if (PendingWeapon != WP_NOCHANGE) - P_BringUpWeapon(this); - } - else - { - P_CheckWeaponSwitch(this); - if (WeaponState & (WF_WEAPONREADY | WF_WEAPONREADYALT)) + if (ReadyWeapon == nullptr) { - P_CheckWeaponFire(this); + if (PendingWeapon != WP_NOCHANGE) + P_BringUpWeapon(this); + } + else + { + P_CheckWeaponSwitch(this); + if (WeaponState & (WF_WEAPONREADY | WF_WEAPONREADYALT)) + { + P_CheckWeaponFire(this); + } + // Check custom buttons + P_CheckWeaponButtons(this); } - // Check custom buttons - P_CheckWeaponButtons(this); } } diff --git a/src/thingdef/thingdef_codeptr.cpp b/src/thingdef/thingdef_codeptr.cpp index ef41faea2..d1933e142 100644 --- a/src/thingdef/thingdef_codeptr.cpp +++ b/src/thingdef/thingdef_codeptr.cpp @@ -7188,3 +7188,34 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_FaceMovementDirection) ACTION_RETURN_BOOL(true); } +//========================================================================== +// +// A_CopySpriteFrame(from, to, flags) +// +// Copies the sprite and/or frame from one pointer to another. +//========================================================================== +enum CPSFFlags +{ + CPSF_NOSPRITE = 1, + CPSF_NOFRAME = 1 << 1, +}; + +DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CopySpriteFrame) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_INT(from); + PARAM_INT(to); + PARAM_INT_OPT(flags) { flags = 0; } + + AActor *copyfrom = COPY_AAPTR(self, from); + AActor *copyto = COPY_AAPTR(self, to); + + if (copyfrom == copyto || copyfrom == nullptr || copyto == nullptr || ((flags & CPSF_NOSPRITE) && (flags & CPSF_NOFRAME))) + { + ACTION_RETURN_BOOL(false); + } + + if (!(flags & CPSF_NOSPRITE)) copyto->sprite = copyfrom->sprite; + if (!(flags & CPSF_NOFRAME)) copyto->frame = copyfrom->frame; + ACTION_RETURN_BOOL(true); +} diff --git a/src/thingdef/thingdef_data.cpp b/src/thingdef/thingdef_data.cpp index a86e98566..0768f80c8 100644 --- a/src/thingdef/thingdef_data.cpp +++ b/src/thingdef/thingdef_data.cpp @@ -257,6 +257,8 @@ static FFlagDef ActorFlagDefs[]= DEFINE_FLAG(MF7, LAXTELEFRAGDMG, AActor, flags7), DEFINE_FLAG(MF7, ICESHATTER, AActor, flags7), DEFINE_FLAG(MF7, ALLOWTHRUFLAGS, AActor, flags7), + DEFINE_FLAG(MF7, USEKILLSCRIPTS, AActor, flags7), + DEFINE_FLAG(MF7, NOKILLSCRIPTS, AActor, flags7), // Effect flags DEFINE_FLAG(FX, VISIBILITYPULSE, AActor, effects), @@ -362,6 +364,8 @@ static FFlagDef WeaponFlagDefs[] = DEFINE_FLAG(WIF, NO_AUTO_SWITCH, AWeapon, WeaponFlags), DEFINE_FLAG(WIF, AMMO_CHECKBOTH, AWeapon, WeaponFlags), DEFINE_FLAG(WIF, NOAUTOAIM, AWeapon, WeaponFlags), + DEFINE_FLAG(WIF, NODEATHDESELECT, AWeapon, WeaponFlags), + DEFINE_FLAG(WIF, NODEATHINPUT, AWeapon, WeaponFlags), DEFINE_DUMMY_FLAG(NOLMS), DEFINE_FLAG(WIF, ALT_USES_BOTH, AWeapon, WeaponFlags), diff --git a/wadsrc/static/actors/actor.txt b/wadsrc/static/actors/actor.txt index 8c35df21b..77250b3df 100644 --- a/wadsrc/static/actors/actor.txt +++ b/wadsrc/static/actors/actor.txt @@ -330,6 +330,7 @@ ACTOR Actor native //: Thinker native state A_CheckRange(float distance, state label, bool two_dimension = false); action native bool A_FaceMovementDirection(float offset = 0, float anglelimit = 0, float pitchlimit = 0, int flags = 0, int ptr = AAPTR_DEFAULT); action native int A_ClearOverlays(int sstart = 0, int sstop = 0, bool safety = true); + action native bool A_CopySpriteFrame(int from, int to, int flags = 0); native void A_RearrangePointers(int newtarget, int newmaster = AAPTR_DEFAULT, int newtracer = AAPTR_DEFAULT, int flags=0); native void A_TransferPointer(int ptr_source, int ptr_recepient, int sourcefield, int recepientfield=AAPTR_DEFAULT, int flags=0); diff --git a/wadsrc/static/actors/constants.txt b/wadsrc/static/actors/constants.txt index e11f3d0bb..76bdcf9eb 100644 --- a/wadsrc/static/actors/constants.txt +++ b/wadsrc/static/actors/constants.txt @@ -666,4 +666,11 @@ enum { GAF_RELATIVE = 1, GAF_SWITCH = 1 << 1, +}; + +//Flags for A_CopySpriteFrame +enum +{ + CPSF_NOSPRITE = 1, + CPSF_NOFRAME = 1 << 1, }; \ No newline at end of file