From bef7cd3a2b0217e63ef0b3b6832b22abbfe05bd1 Mon Sep 17 00:00:00 2001 From: Alexander Monakov Date: Mon, 27 Dec 2010 02:22:53 +0300 Subject: [PATCH] Bonus Score deduplication --- Source/Awards.cpp | 15 ++++ Source/Awards.h | 6 +- Source/Bonuses.def | 54 ++++++------ Source/GameTick.cpp | 20 +---- Source/Person.cpp | 201 ++++++++------------------------------------ Source/Weapons.cpp | 14 +-- 6 files changed, 89 insertions(+), 221 deletions(-) diff --git a/Source/Awards.cpp b/Source/Awards.cpp index be967c5..cbfe381 100644 --- a/Source/Awards.cpp +++ b/Source/Awards.cpp @@ -30,6 +30,21 @@ float startbonustotal; float bonustime; float bonusnum[100]; +static const int bonus_values[bonus_count] = { +#define DECLARE_BONUS(id, name, value, ...) value, +#include "Bonuses.def" +#undef DECLARE_BONUS +}; + +void +award_bonus(int playerid, int bonusid, int alt_value) +{ + if (playerid != 0) + return; + bonus = bonusid; + bonustime = 0; + bonusvalue = alt_value ? alt_value : bonus_values[bonusid]; +} // FIXME: make these per-player float damagetaken; diff --git a/Source/Awards.h b/Source/Awards.h index 9168f1c..83b61c0 100644 --- a/Source/Awards.h +++ b/Source/Awards.h @@ -23,14 +23,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define AWARDS_H enum bonus_types { -#define DECLARE_BONUS(id, name) id, +#define DECLARE_BONUS(id, ...) id, #include "Bonuses.def" #undef DECLARE_BONUS bonus_count }; static const char *bonus_names[bonus_count] = { -#define DECLARE_BONUS(id, name) name, +#define DECLARE_BONUS(id, name, ...) name, #include "Bonuses.def" #undef DECLARE_BONUS }; @@ -42,6 +42,8 @@ extern float bonustime; extern float startbonustotal; extern float bonusnum[100]; +extern void award_bonus(int playerid, int bonusid, int alt_value = 0); + enum award_types { #define DECLARE_AWARD(id, name) id, #include "Awards.def" diff --git a/Source/Bonuses.def b/Source/Bonuses.def index 00e0226..91b2b5c 100644 --- a/Source/Bonuses.def +++ b/Source/Bonuses.def @@ -19,30 +19,30 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -DECLARE_BONUS(nobonus, "") -DECLARE_BONUS(tracheotomy, "Tracheotomy!") -DECLARE_BONUS(backstab, "Backstabber!") -DECLARE_BONUS(spinecrusher, "Spinecrusher!") -DECLARE_BONUS(ninja, "Ninja Bonus!") -DECLARE_BONUS(style, "Style Bonus!") -DECLARE_BONUS(cannon, "Leg Cannon!") -DECLARE_BONUS(aimbonus, "Nice Aim!") -DECLARE_BONUS(deepimpact, "Heavy Impact!") -DECLARE_BONUS(touchofdeath, "Touch of Death!") -DECLARE_BONUS(swordreversebonus, "Sword Disarm!") -DECLARE_BONUS(staffreversebonus, "Staff Disarm!") -DECLARE_BONUS(reverseko, "Reversal KO!") -DECLARE_BONUS(solidhit, "Solid Hit!") -DECLARE_BONUS(twoxcombo, "2X Combo!") -DECLARE_BONUS(threexcombo, "3X Combo!") -DECLARE_BONUS(fourxcombo, "4X COMBO!") -DECLARE_BONUS(megacombo, "MEGA COMBO!") -DECLARE_BONUS(Reversal, "Reversal!") -DECLARE_BONUS(Stabbonus, "Punctured!") -DECLARE_BONUS(Slicebonus, "Sliced!") -DECLARE_BONUS(Bullseyebonus, "Bullseye!") -DECLARE_BONUS(Slashbonus, "Slashed!") -DECLARE_BONUS(Wolfbonus, "WOLF SLAYER!") -DECLARE_BONUS(FinishedBonus, "SLAIN!") -DECLARE_BONUS(TackleBonus, "Tackle!") -DECLARE_BONUS(AboveBonus, "Death from Above!") +DECLARE_BONUS(nobonus, "", 0) +DECLARE_BONUS(tracheotomy, "Tracheotomy!", 100) +DECLARE_BONUS(backstab, "Backstabber!", 100) +DECLARE_BONUS(spinecrusher, "Spinecrusher!", 100) +DECLARE_BONUS(ninja, "Ninja Bonus!", 60) +DECLARE_BONUS(style, "Style Bonus!", 150) +DECLARE_BONUS(cannon, "Leg Cannon!", 100) +DECLARE_BONUS(aimbonus, "Nice Aim!", 150) +DECLARE_BONUS(deepimpact, "Heavy Impact!", 50) +DECLARE_BONUS(touchofdeath, "Touch of Death!", 150) +DECLARE_BONUS(swordreversebonus, "Sword Disarm!", 100) +DECLARE_BONUS(staffreversebonus, "Staff Disarm!", 100) +DECLARE_BONUS(reverseko, "Reversal KO!", 100) +DECLARE_BONUS(solidhit, "Solid Hit!", 10) +DECLARE_BONUS(twoxcombo, "2X Combo!", 20) +DECLARE_BONUS(threexcombo, "3X Combo!", 40) +DECLARE_BONUS(fourxcombo, "4X COMBO!", 80) +DECLARE_BONUS(megacombo, "MEGA COMBO!", 160) +DECLARE_BONUS(Reversal, "Reversal!", 60) +DECLARE_BONUS(Stabbonus, "Punctured!", 40) +DECLARE_BONUS(Slicebonus, "Sliced!", 10) +DECLARE_BONUS(Bullseyebonus, "Bullseye!", 30) +DECLARE_BONUS(Slashbonus, "Slashed!", 40) +DECLARE_BONUS(Wolfbonus, "WOLF SLAYER!", 300) +DECLARE_BONUS(FinishedBonus, "SLAIN!", 200) +DECLARE_BONUS(TackleBonus, "Tackle!", 5) +DECLARE_BONUS(AboveBonus, "Death from Above!", 50) diff --git a/Source/GameTick.cpp b/Source/GameTick.cpp index 5c292f7..05e9fd8 100644 --- a/Source/GameTick.cpp +++ b/Source/GameTick.cpp @@ -5715,16 +5715,12 @@ void Game::Tick() player[i].RagDoll(0); if(player[i].damage>player[i].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[i].dead){ - bonus=aimbonus; - bonustime=0; - bonusvalue=150; + award_bonus(0, aimbonus); } player[i].DoDamage(findLengthfast(&rotatetarget)/4); player[k].RagDoll(0); if(player[k].damage>player[k].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[k].dead){ - bonus=aimbonus; - bonustime=0; - bonusvalue=150; + award_bonus(0, aimbonus); // Huh, again? } player[k].DoDamage(findLengthfast(&rotatetarget)/4); @@ -5790,11 +5786,7 @@ void Game::Tick() player[i].DoDamage(20); player[i].RagDoll(0); player[k].lastcollide=1; - if(k==0){ - bonus=AboveBonus; - bonustime=0; - bonusvalue=50; - } + award_bonus(k, AboveBonus); } if(i==0&&k!=0&&player[i].targetanimation==jumpdownanim&&!player[k].isCrouch()&&player[k].targetanimation!=rollanim&&!player[i].skeleton.oldfree&&!player[i].skeleton.free&&player[i].lastcollide<=0&&player[i].velocity.y<-10){ player[k].velocity=player[i].velocity; @@ -5804,11 +5796,7 @@ void Game::Tick() player[k].DoDamage(20); player[k].RagDoll(0); player[i].lastcollide=1; - if(i==0){ - bonus=AboveBonus; - bonustime=0; - bonusvalue=50; - } + award_bonus(i, AboveBonus); } } } diff --git a/Source/Person.cpp b/Source/Person.cpp index ca2c51d..4d7f9df 100644 --- a/Source/Person.cpp +++ b/Source/Person.cpp @@ -141,13 +141,7 @@ void Person::CheckKick(){ skeleton.free=0; if(id==0)OPENAL_SetPaused(channels[whooshsound], false); - //if(victim->damage>victim->damagetolerance){ - if(id==0){ - bonus=cannon; - bonustime=0; - bonusvalue=100; - } - //} + award_bonus(id, cannon); } else if (victim->isCrouch()){ targetanimation=rabbitkickreversedanim; @@ -363,32 +357,21 @@ bool Person::isWallJump(){ else return 0; } -void SolidHitBonus(); void SolidHitBonus(){ if(bonustime<1.5&&(bonus==fourxcombo||bonus==megacombo)){ - bonus=megacombo; - bonustime=0; - bonusvalue=160; + award_bonus(0, megacombo); } else if(bonustime<1.5&&bonus==threexcombo){ - bonus=fourxcombo; - bonustime=0; - bonusvalue=80; + award_bonus(0, fourxcombo); } else if(bonustime<1.5&&bonus==twoxcombo){ - bonus=threexcombo; - bonustime=0; - bonusvalue=40; + award_bonus(0, threexcombo); } else if(bonustime<1.5&&bonus==solidhit){ - bonus=twoxcombo; - bonustime=0; - bonusvalue=20; + award_bonus(0, twoxcombo); } else { - bonus=solidhit; - bonustime=0; - bonusvalue=10; + award_bonus(0, solidhit); } } @@ -1384,9 +1367,7 @@ void Person::DoDamage(float howmuch){ slomodelay=.2; }*/ if(!dead&&creature==wolftype){ - bonus=Wolfbonus; - bonustime=0; - bonusvalue=300; + award_bonus(0, Wolfbonus); } dead=2; coords=20; @@ -1838,10 +1819,8 @@ void Person::DoAnimations(){ victim->spurt=1; victim->DoBloodBig(1/victim->armorhead,210); } + award_bonus(id, TackleBonus); if(id==0){ - bonus=TackleBonus; - bonustime=0; - bonusvalue=5; if(victim->aitype==gethelptype)bonusvalue=50; } } @@ -2413,11 +2392,7 @@ void Person::DoAnimations(){ victim->DoDamage(damagemult*150/victim->protectionhead); if(victim->damage>victim->damagetolerance){ - if(id==0){ - bonus=style; - bonustime=0; - bonusvalue=150; - } + award_bonus(id, style); } else if(id==0){ SolidHitBonus(); @@ -2468,11 +2443,7 @@ void Person::DoAnimations(){ victim->DoDamage(damagemult*150/victim->protectionhead); if(victim->damage>victim->damagetolerance){ - if(id==0){ - bonus=style; - bonustime=0; - bonusvalue=150; - } + award_bonus(id, style); } else if(id==0){ SolidHitBonus(); @@ -2716,11 +2687,8 @@ void Person::DoAnimations(){ if(whichtri!=-1){ if(victim->dead!=2){ victim->DoDamage(abs((victim->damagetolerance-victim->permanentdamage)*2)); - if(id==0&&!victim->dead){ - bonus=FinishedBonus; - bonustime=0; - bonusvalue=200; - } + if (!victim->dead) + award_bonus(id, FinishedBonus); } if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2; @@ -3080,11 +3048,7 @@ void Person::DoAnimations(){ if(tutoriallevel!=1)victim->DoBloodBig(1.5/victim->armorhigh,225); //} - if(id==0){ - bonus=Slicebonus; - bonustime=0; - bonusvalue=10; - } + award_bonus(id, Slicebonus); if(tutoriallevel!=1){ float gLoc[3]; float vel[3]; @@ -3141,11 +3105,7 @@ void Person::DoAnimations(){ if(targetanimation==swordslashanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){ if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim){ if(victim->weaponactive==-1||normaldotproduct(victim->facing,victim->coords-coords)>0||(Random()%2==0)){ - if(id==0){ - bonus=Slashbonus; - bonustime=0; - bonusvalue=40; - } + award_bonus(id, Slashbonus); escapednum=0; if(tutoriallevel!=1){ if(normaldotproduct(victim->facing,victim->coords-coords)<0)victim->DoBloodBig(2/victim->armorhigh,190); @@ -3309,11 +3269,7 @@ void Person::DoAnimations(){ if(tutoriallevel!=1){ victim->DoDamage(damagemult*120/victim->protectionhigh); - if(id==0){ - bonus=solidhit; - bonustime=0; - bonusvalue=30; - } + award_bonus(id, solidhit, 30); } } } @@ -3355,11 +3311,7 @@ void Person::DoAnimations(){ victim->Puff(head); if(tutoriallevel!=1){victim->DoDamage(damagemult*350/victim->protectionhead); - if(id==0){ - bonus=solidhit; - bonustime=0; - bonusvalue=60; - } + award_bonus(id, solidhit, 60); } } } @@ -3423,11 +3375,7 @@ void Person::DoAnimations(){ if(tutoriallevel!=1){victim->DoDamage(damagemult*100/victim->protectionhigh); if(!victim->dead){ - if(id==0){ - bonus=solidhit; - bonustime=0; - bonusvalue=40; - } + award_bonus(id, solidhit, 40); } } } @@ -3628,11 +3576,7 @@ void Person::DoAnimations(){ victim->Puff(abdomen); victim->DoDamage(damagemult*150/victim->protectionhigh); - if(id==0){ - bonus=Reversal; - bonustime=0; - bonusvalue=60; - } + award_bonus(id, Reversal); } if((targetanimation==swordslashreversalanim||targetanimation==knifeslashreversalanim||targetanimation==staffhitreversalanim||targetanimation==staffspinhitreversalanim)&&animation[targetanimation].label[currentframe]==5){ @@ -3705,11 +3649,7 @@ void Person::DoAnimations(){ vel[1]=velocity.y; vel[2]=velocity.z; - if(id==0){ - bonus=staffreversebonus; - bonustime=0; - bonusvalue=100; - } + award_bonus(id, staffreversebonus); if(tutoriallevel!=1){ PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, true); @@ -3718,11 +3658,7 @@ void Person::DoAnimations(){ OPENAL_SetPaused(channels[heavyimpactsound], false); } victim->RagDoll(0); - if(id==0){ - bonus=staffreversebonus; - bonustime=0; - bonusvalue=100; - } + award_bonus(id, staffreversebonus); // Huh, again? XYZ relative; relative=victim->coords-oldcoords; @@ -3762,11 +3698,7 @@ void Person::DoAnimations(){ victim->Puff(abdomen); victim->DoDamage(damagemult*90/victim->protectionhigh); - if(id==0){ - bonus=Reversal; - bonustime=0; - bonusvalue=60; - } + award_bonus(id, Reversal); bool doslice; doslice=0; @@ -3824,30 +3756,7 @@ void Person::DoAnimations(){ victim->skeleton.joints[victim->skeleton.jointlabels[rightelbow]].velocity*=.5-1; victim->skeleton.joints[victim->skeleton.jointlabels[rightshoulder]].velocity*=.7-1; - if(id==0){ - bonus=swordreversebonus; - bonustime=0; - bonusvalue=100; - } - //victim->DoDamage(90); - - /*if(weaponactive!=-1){ - float gLoc[3]; - float vel[3]; - gLoc[0]=victim->coords.x; - gLoc[1]=victim->coords.y; - gLoc[2]=victim->coords.z; - vel[0]=velocity.x; - vel[1]=velocity.y; - vel[2]=velocity.z; - victim->DoBloodBig(2,225); - PlaySoundEx( knifeslicesound, samp[knifeslicesound], NULL, true); - OPENAL_3D_SetAttributes(channels[knifeslicesound], gLoc, vel); - OPENAL_SetVolume(channels[knifeslicesound], 512); - OPENAL_SetPaused(channels[knifeslicesound], false); - if(bloodtoggle&&!weapons.bloody[weaponids[weaponactive]])weapons.bloody[weaponids[weaponactive]]=1; - weapons.blooddrip[weaponids[weaponactive]]+=3; - }*/ + award_bonus(id, swordreversebonus); } if(hasvictim&&targetanimation==knifeslashreversalanim&&animation[targetanimation].label[currentframe]==7){ @@ -3885,11 +3794,7 @@ void Person::DoAnimations(){ victim->Puff(abdomen); victim->DoDamage(damagemult*30/victim->protectionhigh); - if(id==0){ - bonus=Reversal; - bonustime=0; - bonusvalue=60; - } + award_bonus(id, Reversal); } if(hasvictim&&targetanimation==sneakattackanim&&animation[targetanimation].label[currentframe]==7){ @@ -3939,11 +3844,7 @@ void Person::DoAnimations(){ victim->DoBloodBig(2,175); } } - if(id==0){ - bonus=spinecrusher; - bonustime=0; - bonusvalue=100; - } + award_bonus(id, spinecrusher); } if(hasvictim&&(targetanimation==knifefollowanim||targetanimation==knifesneakattackanim)&&animation[targetanimation].label[currentframe]==5){ @@ -3969,20 +3870,10 @@ void Person::DoAnimations(){ Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1); Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1); victim->DoBloodBig(200,195); - if(id==0){ - bonus=tracheotomy; - bonustime=0; - bonusvalue=100; - } - - //victim->neckspurtamount=5; + award_bonus(id, tracheotomy); } if(targetanimation==knifefollowanim){ - if(id==0){ - bonus=Stabbonus; - bonustime=0; - bonusvalue=40; - } + award_bonus(id, Stabbonus); XYZ footvel,footpoint; footvel=0; footpoint=weapons.tippoint[weaponids[0]]; @@ -4055,11 +3946,7 @@ void Person::DoAnimations(){ if(hasvictim&&(targetanimation==swordsneakattackanim)&&animation[targetanimation].label[currentframe]==5){ if(weaponactive!=-1&&victim->bloodlossdamagetolerance){ - if(id==0){ - bonus=backstab; - bonustime=0; - bonusvalue=100; - } + award_bonus(id, backstab); escapednum=0; @@ -4174,11 +4061,7 @@ void Person::DoAnimations(){ } } - if(id==0){ - bonus=Reversal; - bonustime=0; - bonusvalue=60; - } + award_bonus(id, Reversal); victim->Puff(neck); @@ -4218,11 +4101,7 @@ void Person::DoAnimations(){ if(hasvictim&&(targetanimation==spinkickreversalanim||targetanimation==sweepreversalanim||targetanimation==rabbitkickreversalanim||targetanimation==upunchreversalanim||targetanimation==jumpreversalanim||targetanimation==swordslashreversalanim||targetanimation==knifeslashreversalanim||targetanimation==rabbittacklereversal||targetanimation==wolftacklereversal||targetanimation==staffhitreversalanim||targetanimation==staffspinhitreversalanim)) if(victim->damage>victim->damagetolerance&&bonus!=reverseko){ - if(id==0){ - bonus=reverseko; - bonustime=0; - bonusvalue=100; - } + award_bonus(id, reverseko); } } @@ -4991,9 +4870,7 @@ void Person::DoStuff(){ } if(!dead&&creature==wolftype){ - bonus=Wolfbonus; - bonustime=0; - bonusvalue=300; + award_bonus(0, Wolfbonus); } dead=2; if(targetanimation==knifefollowedanim&&!skeleton.free){ @@ -5368,9 +5245,7 @@ void Person::DoStuff(){ unconscioustime=0; if(creature==wolftype){ - bonus=Wolfbonus; - bonustime=0; - bonusvalue=300; + award_bonus(0, Wolfbonus); } RagDoll(0); @@ -5463,11 +5338,8 @@ void Person::DoStuff(){ bonusvalue=300; } - if(id!=0&&unconscioustime<.1&&(bonus!=spinecrusher||bonustime>1)&&(bonus!=FinishedBonus||bonustime>1)&&bloodloss1)&&(bonus!=FinishedBonus||bonustime>1)&&bloodloss.1){ numafterkill++; } @@ -5517,11 +5389,8 @@ void Person::DoStuff(){ skeleton.DoGravity(&scale); float damageamount; damageamount=skeleton.DoConstraints(&coords,&scale)*5; - if(id!=0&&damage>damagetolerance-damageamount&&!dead&&(bonus!=spinecrusher||bonustime>1)&&(bonus!=style||bonustime>1)&&(bonus!=cannon||bonustime>1)){ - bonus=deepimpact; - bonustime=0; - bonusvalue=50; - } + if(damage>damagetolerance-damageamount&&!dead&&(bonus!=spinecrusher||bonustime>1)&&(bonus!=style||bonustime>1)&&(bonus!=cannon||bonustime>1)) + award_bonus(id, deepimpact); DoDamage(damageamount/((protectionhigh+protectionhead+protectionlow)/3)); average=0; diff --git a/Source/Weapons.cpp b/Source/Weapons.cpp index 212bdb4..ff41d8b 100644 --- a/Source/Weapons.cpp +++ b/Source/Weapons.cpp @@ -275,16 +275,10 @@ void Weapons::DoStuff(){ OPENAL_SetVolume(channels[fleshstabsound], 128); OPENAL_SetPaused(channels[fleshstabsound], false); - if(animation[player[0].targetanimation].height==highheight){ - bonus=ninja; - bonustime=0; - bonusvalue=60; - } - else{ - bonus=Bullseyebonus; - bonustime=0; - bonusvalue=30; - } + if(animation[player[0].targetanimation].height==highheight) + award_bonus(0, ninja); + else + award_bonus(0, Bullseyebonus); } } else missed[i]=1; -- 2.39.5