From d021909224c97b151dfee3c38779d42d779a7ffe Mon Sep 17 00:00:00 2001 From: aurhat Date: Fri, 18 Jul 2014 11:25:20 +0200 Subject: [PATCH] Restore old working quicknadethrow code and fix bug in it This commit restores old working quicknadethrow code, which existed after commit: https://github.com/assaultcube/AC/commit/aaeca4ef323f09d252498bcc66eb90d51aef4586 and keeps later bug fixes (which thought needed to be fixed). It fixes https://github.com/assaultcube/AC/issues/25 It also fixes followed bug: after releasing right mouse button/G key and quickly pressing it again, weapon, to which quicknadethrow switched, starts to shoot. --- config/scripts.cfg | 8 -------- source/src/weapon.cpp | 22 +++++++++++----------- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/config/scripts.cfg b/config/scripts.cfg index 14e6ba07..12cf0604 100644 --- a/config/scripts.cfg +++ b/config/scripts.cfg @@ -170,14 +170,6 @@ const altaction [ (concatword altaction_ (curweapon)) ] const checkmag [ result (|| (magcontent $arg1) (magreserve $arg1)) ] const checkrange [ result (&& (>=f $arg1 $arg2) (<=f $arg1 $arg3)) ] -const quicknadethrow_old [ - if (> (magcontent $GRENADES) 0) [ - if (!= (curweapon) $CPISTOL) grenades - attack - ] - // onrelease [ sleep 1 [ if (= (curweapon) $CPISTOL) [ weapon (prevweapon) ] ] ] -] - loop i $NUM_WEAPONS [ (concatword altaction_ $i) = quicknadethrow ] // Quick nade throw is default // Use format to define altaction_N aliases from now on, makes for less edits in the future if weapon IDs change. - Bukz // (format altaction_%1 $KNIFE) = [ if (checkmag (currentprimary)) primary [ if (|| (checkmag $PISTOL) (checkmag $AKIMBO)) secondary [ if (checkmag $GRENADES) grenades ] ] ] // Knife // uncomment to switch to primary/secondary/grenades with MOUSE2 depending on ammo content for each. diff --git a/source/src/weapon.cpp b/source/src/weapon.cpp index eaf7e94d..b3238d80 100644 --- a/source/src/weapon.cpp +++ b/source/src/weapon.cpp @@ -109,8 +109,7 @@ void shiftweapon(int *s) else if(player1->isspectating()) updatefollowplayer(*s); } -bool quicknade = false, nadeattack = false; -VARP(quicknade_hold, 0, 0, 1); +bool quicknade = false; void quicknadethrow(bool on) { @@ -120,12 +119,15 @@ void quicknadethrow(bool on) if(player1->weapons[GUN_GRENADE]->mag > 0) { if(player1->weaponsel->type != GUN_GRENADE) selectweapon(player1->weapons[GUN_GRENADE]); - if(player1->weaponsel->type == GUN_GRENADE || quicknade_hold) { player1->attacking = true; nadeattack = true; } + if(player1->weaponsel->type == GUN_GRENADE || player1->nextweaponsel->type == GUN_GRENADE) + { + if(!(player1->weaponsel->type == GUN_GRENADE && player1->nextweaponsel->type != GUN_GRENADE)) attack(true); + } } } - else if (nadeattack) + else { - nadeattack = player1->attacking = false; + attack(false); if(player1->weaponsel->type == GUN_GRENADE) quicknade = true; } } @@ -1085,8 +1087,7 @@ bool grenades::attack(vec &targ) int attackmillis = lastmillis-owner->lastaction; vec &to = targ; - bool quickwait = attackmillis*3>=gunwait && !(m_arena && m_teammode && arenaintermission); - bool waitdone = attackmillis>=gunwait && quickwait; + bool waitdone = attackmillis>=gunwait && !(m_arena && m_teammode && arenaintermission); if(waitdone) gunwait = reloading = 0; switch(state) @@ -1100,7 +1101,7 @@ bool grenades::attack(vec &targ) break; case GST_INHAND: - if(waitdone || ( quicknade && quickwait ) ) + if(waitdone) { if(!owner->attacking || this!=owner->weaponsel) thrownade(); // throw else if(!inhandnade->isalive(lastmillis)) dropnade(); // drop & have fun @@ -1164,8 +1165,6 @@ void grenades::activatenade(const vec &to) void grenades::thrownade() { - if (quicknade && owner->weaponsel->type == GUN_GRENADE) selectweapon(owner->prevweaponsel); - quicknade = false; if(!inhandnade) return; const float speed = cosf(RAD*owner->pitch); vec vel(sinf(RAD*owner->yaw)*speed, -cosf(RAD*owner->yaw)*speed, sinf(RAD*owner->pitch)); @@ -1183,6 +1182,7 @@ void grenades::thrownade(const vec &vel) updatelastaction(owner); state = GST_THROWING; if(this==owner->weaponsel) owner->attacking = false; + if(quicknade && owner->weaponsel->type == GUN_GRENADE) selectweapon(owner->prevweaponsel); } void grenades::dropnade() @@ -1199,7 +1199,7 @@ void grenades::renderstats() } bool grenades::selectable() { return weapon::selectable() && state != GST_INHAND && mag; } -void grenades::reset() { throwmillis = 0; state = GST_NONE; } +void grenades::reset() { throwmillis = 0; quicknade = false; state = GST_NONE; } void grenades::onselecting() { reset(); audiomgr.playsound(S_GUNCHANGE); } void grenades::onownerdies()