From bc47fdfa78ea86ee93ae7356a41aacf7e9213c29 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 2 Jan 2019 11:53:53 +0100 Subject: [PATCH] - scriptified useflechette CCMD's item finding code. --- src/d_player.h | 5 ++- src/g_game.cpp | 39 ++++--------------- wadsrc/static/zscript/shared/player.txt | 2 +- .../zscript/shared/player_inventory.txt | 35 +++++++++++++++++ 4 files changed, 47 insertions(+), 34 deletions(-) diff --git a/src/d_player.h b/src/d_player.h index 4acae8ac8..3d1a95bff 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -137,8 +137,6 @@ public: double AttackZOffset; // attack height, relative to player center double UseRange; // [NS] Distance at which player can +use double AirCapacity; // Multiplier for air supply underwater. - PClassActor *FlechetteType; - // [CW] Fades for when you are being damaged. PalEntry DamageFade; @@ -156,6 +154,9 @@ public: uint8_t ColorRangeStart; // Skin color range uint8_t ColorRangeEnd; + // Everything below this point is only used by scripted code. + PClassActor *FlechetteType; + }; // diff --git a/src/g_game.cpp b/src/g_game.cpp index a1c6f8304..70e5a517d 100644 --- a/src/g_game.cpp +++ b/src/g_game.cpp @@ -467,40 +467,17 @@ CCMD (drop) } } -PClassActor *GetFlechetteType(AActor *other); - CCMD (useflechette) -{ // Select from one of arti_poisonbag1-3, whichever the player has - static const ENamedName bagnames[3] = +{ + if (who == nullptr) return; + IFVIRTUALPTR(who, APlayerPawn, GetFlechetteItem) { - NAME_ArtiPoisonBag3, // use type 3 first because that's the default when the player has none specified. - NAME_ArtiPoisonBag1, - NAME_ArtiPoisonBag2 - }; + VMValue params[] = { who }; + AActor *cls; + VMReturn ret((void**)&cls); + VMCall(func, params, 1, &ret, 1); - if (who == NULL) - return; - - PClassActor *type = who->FlechetteType; - if (type != NULL) - { - AActor *item; - if ( (item = who->FindInventory (type) )) - { - SendItemUse = item; - return; - } - } - - // The default flechette could not be found, or the player had no default. Try all 3 types then. - for (int j = 0; j < 3; ++j) - { - AActor *item; - if ( (item = who->FindInventory (bagnames[j])) ) - { - SendItemUse = item; - break; - } + if (cls != nullptr) SendItemUse = cls; } } diff --git a/wadsrc/static/zscript/shared/player.txt b/wadsrc/static/zscript/shared/player.txt index 4a69e6b36..3bf0487ce 100644 --- a/wadsrc/static/zscript/shared/player.txt +++ b/wadsrc/static/zscript/shared/player.txt @@ -45,7 +45,7 @@ class PlayerPawn : Actor native native double AttackZOffset; // attack height, relative to player center native double UseRange; // [NS] Distance at which player can +use native double AirCapacity; // Multiplier for air supply underwater. - native Class FlechetteType; + native Class FlechetteType; native color DamageFade; // [CW] Fades for when you are being damaged. native double ViewBob; // [SP] ViewBob Multiplier native double FullHeight; diff --git a/wadsrc/static/zscript/shared/player_inventory.txt b/wadsrc/static/zscript/shared/player_inventory.txt index c71c1f3d8..bcaa31be1 100644 --- a/wadsrc/static/zscript/shared/player_inventory.txt +++ b/wadsrc/static/zscript/shared/player_inventory.txt @@ -320,5 +320,40 @@ extend class PlayerPawn } } + //============================================================================ + // + // Helper for 'useflechette' CCMD. + // + //============================================================================ + + protected virtual Inventory GetFlechetteItem() + { + // Select from one of arti_poisonbag1-3, whichever the player has + static const Class bagtypes[] = { + "ArtiPoisonBag3", // use type 3 first because that's the default when the player has none specified. + "ArtiPoisonBag1", + "ArtiPoisonBag2" + }; + + if (FlechetteType != NULL) + { + let item = FindInventory(FlechetteType); + if (item != null) + { + return item; + } + } + + // The default flechette could not be found, or the player had no default. Try all 3 types then. + for (int j = 0; j < 3; ++j) + { + let item = FindInventory(bagtypes[j]); + if (item != null) + { + return item; + } + } + return null; + } } \ No newline at end of file