diff --git a/source/duke3d/src/_functio.h b/source/duke3d/src/_functio.h index a4aeef36e..56c63901a 100644 --- a/source/duke3d/src/_functio.h +++ b/source/duke3d/src/_functio.h @@ -111,7 +111,7 @@ char gamefunctions[NUMGAMEFUNCTIONS][MAXGAMEFUNCLEN] = "Dpad_Select", "Dpad_Aiming", "Alternate_Weapon", - "Last_Used_Weapon" + "Last_Used_Weapon", }; #ifdef __SETUP__ diff --git a/source/duke3d/src/events_defs.h b/source/duke3d/src/events_defs.h index 4cbc232f0..c567ecb3d 100644 --- a/source/duke3d/src/events_defs.h +++ b/source/duke3d/src/events_defs.h @@ -149,6 +149,7 @@ enum GameEvent_t { EVENT_PLAYLEVELMUSICSLOT, EVENT_CONTINUELEVELMUSICSLOT, EVENT_DISPLAYPOINTER, + EVENT_LASTWEAPON, #ifdef LUNATIC EVENT_ANIMATEALLSPRITES, #endif diff --git a/source/duke3d/src/game.cpp b/source/duke3d/src/game.cpp index 12513768f..065567002 100644 --- a/source/duke3d/src/game.cpp +++ b/source/duke3d/src/game.cpp @@ -7157,5 +7157,5 @@ static void G_SetupGameButtons(void) CONTROL_DefineFlag(gamefunc_Next_Weapon,FALSE); CONTROL_DefineFlag(gamefunc_Previous_Weapon,FALSE); CONTROL_DefineFlag(gamefunc_Alt_Weapon,FALSE); - CONTROL_DefineFlag(gamefunc_Last_Weapon, FALSE); + CONTROL_DefineFlag(gamefunc_Last_Weapon,FALSE); } diff --git a/source/duke3d/src/gamedef.cpp b/source/duke3d/src/gamedef.cpp index 544f48c52..78d20dc90 100644 --- a/source/duke3d/src/gamedef.cpp +++ b/source/duke3d/src/gamedef.cpp @@ -756,6 +756,7 @@ const char *EventNames[MAXEVENTS] = "EVENT_PLAYLEVELMUSICSLOT", "EVENT_CONTINUELEVELMUSICSLOT", "EVENT_DISPLAYPOINTER", + "EVENT_LASTWEAPON", #ifdef LUNATIC "EVENT_ANIMATEALLSPRITES", #endif @@ -1090,6 +1091,7 @@ const memberlabel_t PlayerLabels[]= { "connected", PLAYER_CONNECTED, 0, 0 }, { "frags", PLAYER_FRAGS, LABEL_HASPARM2, MAXPLAYERS }, { "deaths", PLAYER_DEATHS, 0, 0 }, + { "last_used_weapon", PLAYER_LAST_USED_WEAPON, 0, 0 }, { NULL, -1, 0, 0 } // END OF LIST }; diff --git a/source/duke3d/src/gamedef.h b/source/duke3d/src/gamedef.h index a68994b2b..c6edaffe8 100644 --- a/source/duke3d/src/gamedef.h +++ b/source/duke3d/src/gamedef.h @@ -421,6 +421,7 @@ enum PlayerLabel_t PLAYER_CONNECTED, PLAYER_FRAGS, PLAYER_DEATHS, + PLAYER_LAST_USED_WEAPON, PLAYER_END }; diff --git a/source/duke3d/src/gamestructures.cpp b/source/duke3d/src/gamestructures.cpp index 274129252..43d799a4e 100644 --- a/source/duke3d/src/gamestructures.cpp +++ b/source/duke3d/src/gamestructures.cpp @@ -694,6 +694,7 @@ int32_t __fastcall VM_GetPlayer(int32_t const playerNum, int32_t labelNum, int32 labelNum = g_player[playerNum].frags[lParm2]; break; case PLAYER_DEATHS: labelNum = g_player[playerNum].frags[playerNum]; break; + case PLAYER_LAST_USED_WEAPON: labelNum = ps->last_used_weapon; break; default: labelNum = -1; break; } @@ -890,6 +891,7 @@ void __fastcall VM_SetPlayer(int32_t const playerNum, int32_t const labelNum, in g_player[playerNum].frags[lParm2] = iSet; break; case PLAYER_DEATHS: g_player[playerNum].frags[playerNum] = iSet; break; + case PLAYER_LAST_USED_WEAPON: ps->last_used_weapon = iSet; break; default: break; } } diff --git a/source/duke3d/src/player.cpp b/source/duke3d/src/player.cpp index 224616f51..83cc178e2 100644 --- a/source/duke3d/src/player.cpp +++ b/source/duke3d/src/player.cpp @@ -2811,7 +2811,6 @@ enddisplayweapon: int32_t g_myAimMode = 0, g_myAimStat = 0, g_oldAimStat = 0; int32_t mouseyaxismode = -1; int32_t g_emuJumpTics = 0; -int32_t g_lastWeapon = 0; void P_GetInput(int playerNum) { @@ -2975,7 +2974,7 @@ void P_GetInput(int playerNum) weaponSelection = 13; if (BUTTON(gamefunc_Last_Weapon)) - weaponSelection = g_lastWeapon + 1; + weaponSelection = 14; if (BUTTON(gamefunc_Jump) && pPlayer->on_ground) g_emuJumpTics = 4; @@ -3350,15 +3349,10 @@ static void P_ChangeWeapon(DukePlayer_t * const pPlayer, int const weaponNum) } if (currentWeapon != pPlayer->curr_weapon && -// p->last_weapon != -1 && !(PWEAPON(playerNum, currentWeapon, WorksLike) == HANDREMOTE_WEAPON && PWEAPON(playerNum, pPlayer->curr_weapon, WorksLike) == HANDBOMB_WEAPON) && !(PWEAPON(playerNum, currentWeapon, WorksLike) == HANDBOMB_WEAPON && PWEAPON(playerNum, pPlayer->curr_weapon, WorksLike) == HANDREMOTE_WEAPON)) { - g_lastWeapon = PWEAPON(playerNum, currentWeapon, WorksLike) == HANDREMOTE_WEAPON ? (int) HANDBOMB_WEAPON : currentWeapon; - if (g_lastWeapon == GROW_WEAPON) g_lastWeapon = SHRINKER_WEAPON; -#ifdef __ANDROID__ - CONTROL_Android_SetLastWeapon(g_lastWeapon); -#endif + pPlayer->last_used_weapon = currentWeapon; } pPlayer->kickback_pic = 0; diff --git a/source/duke3d/src/player.h b/source/duke3d/src/player.h index e1d77f942..004a5ddc3 100644 --- a/source/duke3d/src/player.h +++ b/source/duke3d/src/player.h @@ -201,6 +201,8 @@ typedef struct { uint8_t palette; palette_t pals; + int8_t last_used_weapon; + #ifdef LUNATIC int8_t palsfadespeed, palsfadenext, palsfadeprio, padding2_; @@ -208,7 +210,7 @@ typedef struct { // anywhere (like with spritetype_t): g_player[i].ps->wa.idx == i. struct { int32_t idx; } wa; #endif - int8_t padding_[1]; + // int8_t padding_[0]; } DukePlayer_t; // KEEPINSYNC lunatic/_defs_game.lua diff --git a/source/duke3d/src/premap.cpp b/source/duke3d/src/premap.cpp index 2b8768449..63f5450ec 100644 --- a/source/duke3d/src/premap.cpp +++ b/source/duke3d/src/premap.cpp @@ -870,6 +870,7 @@ void P_ResetWeapons(int playerNum) pPlayer->show_empty_weapon = 0; pPlayer->last_pissed_time = 0; pPlayer->holster_weapon = 0; + pPlayer->last_used_weapon = -1; VM_OnEvent(EVENT_RESETWEAPONS, pPlayer->i, playerNum); } diff --git a/source/duke3d/src/sector.cpp b/source/duke3d/src/sector.cpp index a395f72aa..8a2436279 100644 --- a/source/duke3d/src/sector.cpp +++ b/source/duke3d/src/sector.cpp @@ -2555,6 +2555,9 @@ CHECKINV1: case 12: weaponNum = VM_OnEventWithReturn(EVENT_ALTWEAPON,pPlayer->i,playerNum, weaponNum); break; + case 13: + weaponNum = VM_OnEventWithReturn(EVENT_LASTWEAPON,pPlayer->i,playerNum, weaponNum); + break; } // NOTE: it is assumed that the above events return either -1 or a @@ -2647,9 +2650,11 @@ CHECKINV1: pPlayer->subweapon |= (1<= 12) // alt weapon, last used weapon { - switch (pPlayer->curr_weapon) + uint32_t const weaponNumSwitch = weaponNum == 13 ? pPlayer->last_used_weapon : pPlayer->curr_weapon; + switch (weaponNumSwitch) { case HANDREMOTE_WEAPON: weaponNum = HANDBOMB_WEAPON; @@ -2658,7 +2663,7 @@ CHECKINV1: weaponNum = SHRINKER_WEAPON; break; default: - weaponNum = pPlayer->curr_weapon; + weaponNum = weaponNumSwitch; break; } }