Add op_get_attack_type

This commit is contained in:
Alexander Batalov 2023-04-20 10:51:20 +03:00
parent 129361836f
commit 6ca1329720
3 changed files with 46 additions and 0 deletions

View File

@ -2616,4 +2616,37 @@ static void sidePanelsDraw(const char* path, int win, bool isLeading)
internal_free(image); internal_free(image);
} }
// NOTE: Follows Sfall implementation of `GetCurrentAttackMode`. It slightly
// differs from `interfaceGetCurrentHitMode` (can return one of `reload` hit
// modes, the default is `punch`).
//
// 0x45EF6C
bool interface_get_current_attack_mode(int* hit_mode)
{
if (gInterfaceBarWindow == -1) {
return false;
}
switch (gInterfaceItemStates[gInterfaceCurrentHand].action) {
case INTERFACE_ITEM_ACTION_PRIMARY_AIMING:
case INTERFACE_ITEM_ACTION_PRIMARY:
*hit_mode = gInterfaceItemStates[gInterfaceCurrentHand].primaryHitMode;
break;
case INTERFACE_ITEM_ACTION_SECONDARY_AIMING:
case INTERFACE_ITEM_ACTION_SECONDARY:
*hit_mode = gInterfaceItemStates[gInterfaceCurrentHand].secondaryHitMode;
break;
case INTERFACE_ITEM_ACTION_RELOAD:
*hit_mode = gInterfaceCurrentHand == HAND_LEFT
? HIT_MODE_LEFT_WEAPON_RELOAD
: HIT_MODE_RIGHT_WEAPON_RELOAD;
break;
default:
*hit_mode = HIT_MODE_PUNCH;
break;
}
return true;
}
} // namespace fallout } // namespace fallout

View File

@ -69,6 +69,7 @@ void interfaceBarEndButtonsRenderRedLights();
int indicatorBarRefresh(); int indicatorBarRefresh();
bool indicatorBarShow(); bool indicatorBarShow();
bool indicatorBarHide(); bool indicatorBarHide();
bool interface_get_current_attack_mode(int* hit_mode);
unsigned char* customInterfaceBarGetBackgroundImageData(); unsigned char* customInterfaceBarGetBackgroundImageData();

View File

@ -416,6 +416,17 @@ static void opGetScreenHeight(Program* program)
programStackPushInteger(program, screenGetHeight()); programStackPushInteger(program, screenGetHeight());
} }
// get_attack_type
static void op_get_attack_type(Program* program)
{
int hit_mode;
if (interface_get_current_attack_mode(&hit_mode)) {
programStackPushInteger(program, hit_mode);
} else {
programStackPushInteger(program, -1);
}
}
// atoi // atoi
static void opParseInt(Program* program) static void opParseInt(Program* program)
{ {
@ -551,6 +562,7 @@ void sfallOpcodesInit()
interpreterRegisterOpcode(0x821E, op_get_mouse_buttons); interpreterRegisterOpcode(0x821E, op_get_mouse_buttons);
interpreterRegisterOpcode(0x8220, opGetScreenWidth); interpreterRegisterOpcode(0x8220, opGetScreenWidth);
interpreterRegisterOpcode(0x8221, opGetScreenHeight); interpreterRegisterOpcode(0x8221, opGetScreenHeight);
interpreterRegisterOpcode(0x8228, op_get_attack_type);
interpreterRegisterOpcode(0x8237, opParseInt); interpreterRegisterOpcode(0x8237, opParseInt);
interpreterRegisterOpcode(0x8238, op_atof); interpreterRegisterOpcode(0x8238, op_atof);
interpreterRegisterOpcode(0x824B, op_tile_under_cursor); interpreterRegisterOpcode(0x824B, op_tile_under_cursor);