Quake3World.com Forums
     Programming Discussion
        [GENERAL] What you don't know about the code


Post new topicReply to topic
Login | Profile | | FAQ | Search | IRC




Print view Previous topic | Next topic 
Topic Starter Topic: [GENERAL] What you don't know about the code

Warrior
Warrior
Joined: 13 May 2012
Posts: 90
PostPosted: 09-18-2013 02:37 PM           Profile Send private message  E-mail  Edit post Reply with quote


So, i'm here from some months, sometimes inactive sometimes more active.
By the way, i wanted to create this topic for all users, like me, who comes from a different program language and, most of all, doesn't know exactly how to understand completly the source code or else.

So i suggest this topic in order to put your questions about the "dark" side of the code that you aren't able to understand.

So i propose in order to start a piece of cpma source code about hitsounds:

Quote:
in cg_playerstate.c
in CG_CheckLocalSounds, change this

// hit changes
if ( ps->persistant[PERS_HITS] > ops->persistant[PERS_HITS] ) {
trap_S_StartLocalSound( cgs.media.hitSound[2], CHAN_LOCAL_SOUND );
} else if ( ps->persistant[PERS_HITS] < ops->persistant[PERS_HITS] ) {
trap_S_StartLocalSound( cgs.media.hitTeamSound, CHAN_LOCAL_SOUND );
}

to

// hit changes
// CPM: Hit tones
if (cpm_hittones)
{
int delta;

delta = ps->persistant[PERS_HITS] - ops->persistant[PERS_HITS];

if (delta > 75)
trap_S_StartLocalSound( cgs.media.hitSound[3], CHAN_LOCAL_SOUND );
else if (delta > 50)
trap_S_StartLocalSound( cgs.media.hitSound[2], CHAN_LOCAL_SOUND );
else if (delta > 25)
trap_S_StartLocalSound( cgs.media.hitSound[1], CHAN_LOCAL_SOUND );
else if (delta > 0)
trap_S_StartLocalSound( cgs.media.hitSound[0], CHAN_LOCAL_SOUND );
else if (delta < 0)
trap_S_StartLocalSound( cgs.media.hitTeamSound, CHAN_LOCAL_SOUND );
}
else
{
if ( ps->persistant[PERS_HITS] > ops->persistant[PERS_HITS] ) {
trap_S_StartLocalSound( cgs.media.hitSound[2], CHAN_LOCAL_SOUND );
} else if ( ps->persistant[PERS_HITS] < ops->persistant[PERS_HITS] ) {
trap_S_StartLocalSound( cgs.media.hitTeamSound, CHAN_LOCAL_SOUND );
}
}
// !CPM


the main function is CG_CheckLocalSounds and start with
Code:
void CG_CheckLocalSounds( playerState_t *ps, playerState_t *ops ) {
   int         highScore, health, armor, reward;
   sfxHandle_t sfx;


this is the code about cpma hitsounds, but what i don't understand is that:

Quote:
delta = ps->persistant[PERS_HITS] - ops->persistant[PERS_HITS];


delta is an integer and is equal to = ?????

i still not understand that ps->persistant and ops->persistant (aren't the same variable inside the playerState_t table?)

[USING THAT CODE]: i got ever the same hitsound....




Top
                 

Insane Quaker
Insane Quaker
Joined: 05 Mar 2010
Posts: 384
PostPosted: 09-18-2013 11:27 PM           Profile Send private message  E-mail  Edit post Reply with quote


ops = old playerstate, ie: playerstate from previous frame. That's how you check for changes in player state: by comparing old to current.

Those silly CPM guys! PERS_HITS adds/subtracts whenever you hit an opponent/teammate respectively. It doesn't factor in damage points at all so you can't consider changes in damage dealt with it (unless you modify how it is calculated, which - if you don't have some separate stats calculations of your own - is not recommended as it is used for the overall accuracy calculation). Hence delta will always be either 1, 0 or -1.

What you want to do is set delta to the ps-ops difference in PERS_DMG_GIVEN (that you added earlier on) but only consider it when the difference in PERS_HITS is positive (hit opponent).

Also: make sure that cpm_hittones is in fact not zero.




Top
                 

Warrior
Warrior
Joined: 13 May 2012
Posts: 90
PostPosted: 09-20-2013 12:13 AM           Profile Send private message  E-mail  Edit post Reply with quote


that's why the hitsound still sounds the ever the same!
instead of using the PERS_DMG_GIVEN isn't more easy setting delta = take +atake ?




Top
                 

Insane Quaker
Insane Quaker
Joined: 05 Mar 2010
Posts: 384
PostPosted: 09-20-2013 11:43 PM           Profile Send private message  E-mail  Edit post Reply with quote


Well then you'll need to add another two entries in persEnum_t to communicate G_Damage()'s take and atake. How is that easier?




Top
                 

Insane Quaker
Insane Quaker
Joined: 05 Mar 2010
Posts: 384
PostPosted: 09-20-2013 11:48 PM           Profile Send private message  E-mail  Edit post Reply with quote


You can also refer to how it was done in Q3TA where it counted only armor damage using PERS_ATTACKEE_ARMOR. Here's my (slightly) modified version of it:
Code:
// hit changes
   if ( ps->persistant[PERS_HITS] > ops->persistant[PERS_HITS] ) {
      armor  = ps->persistant[PERS_ATTACKEE_ARMOR] & 0xff;
      health = ps->persistant[PERS_ATTACKEE_ARMOR] >> 8;

      cg.targetTime = cg.time;
      cg.targetDmg = armor;
      if ( cg_hitBeep.integer == 1 ) {
         trap_S_StartLocalSound( cgs.media.hitSound, CHAN_LOCAL_SOUND );
      } else if ( cg_hitBeep.integer == 2 ) {
         if (armor <= 50 ) {
            trap_S_StartLocalSound( cgs.media.hitSoundHigh2, CHAN_LOCAL_SOUND );
         } else if (armor > 50 ) {
            trap_S_StartLocalSound( cgs.media.hitSoundHigh1, CHAN_LOCAL_SOUND );
         } else if (armor || health > 75) {
            trap_S_StartLocalSound( cgs.media.hitSoundLow1, CHAN_LOCAL_SOUND );
         } else if (armor || health > 100) {
            trap_S_StartLocalSound( cgs.media.hitSoundLow2, CHAN_LOCAL_SOUND );
         }
      } else if ( cg_hitBeep.integer == 3 ) {
         if (armor <= 50 ) {
            trap_S_StartLocalSound( cgs.media.hitSoundLow2, CHAN_LOCAL_SOUND );
         } else if (armor > 50 ) {
            trap_S_StartLocalSound( cgs.media.hitSoundLow1, CHAN_LOCAL_SOUND );
         } else if (armor || health > 75) {
            trap_S_StartLocalSound( cgs.media.hitSoundHigh1, CHAN_LOCAL_SOUND );
         } else if (armor || health > 100) {
            trap_S_StartLocalSound( cgs.media.hitSoundHigh2, CHAN_LOCAL_SOUND );
         }
      }
   }




Top
                 

Warrior
Warrior
Joined: 13 May 2012
Posts: 90
PostPosted: 09-21-2013 04:12 AM           Profile Send private message  E-mail  Edit post Reply with quote


Your version work with bip from high to low and reverse but it's based on enemy armor value.
There's a way probably with PERS_DMG_GIVEN but using it i will stuck myself like for CA scores (i wasn't able to complete it)
for example the first thing in my mind for hit sounds was to set:
delta = PERS_DMG_GIVEN - 100
if (delta <= 0 ) it will play a sound for 100 of damage
if (delta >= 25) the other one
if (delta >= 50) etc...
if (delta >= 75) the most low tone
BUT
PERS_DMG_GIVEN doesn't reset is value so probably it will ever increase > of 100 so after the first hit probably i will got ever the sound (delta>= 75)...
That's the same trouble i got with CA individual scores.
I need to reset PERS_DMG_GIVEN after every hit or create some kind of rule in order to check only the last added value on it




Top
                 

Insane Quaker
Insane Quaker
Joined: 05 Mar 2010
Posts: 384
PostPosted: 09-21-2013 04:58 AM           Profile Send private message  E-mail  Edit post Reply with quote


Yeah you can probably just ignore that code I posted, isn't that relevant here I suppose.

What did I tell you about checking for changes in values? You subtract ops from ps. So what you want is something along these lines:

Code:
   // hit changes
   if ( ps->persistant[PERS_HITS] > ops->persistant[PERS_HITS] ) {
      const int dmg = ps->persistant[PERS_DMG_GIVEN] - ops->persistant[PERS_DMG_GIVEN];

      cg.targetTime = cg.time;
      cg.targetDmg = dmg;
      if ( cg_hitBeep.integer == 1 ) {
         trap_S_StartLocalSound( cgs.media.hitSound, CHAN_LOCAL_SOUND );
      } else if ( cg_hitBeep.integer == 2 ) {
         if ( dmg > 75 ) {
            trap_S_StartLocalSound( cgs.media.hitSoundLow2, CHAN_LOCAL_SOUND );
         } else if ( dmg > 50 ) {
            trap_S_StartLocalSound( cgs.media.hitSoundLow1, CHAN_LOCAL_SOUND );
         } else if ( dmg > 25 ) {
            trap_S_StartLocalSound( cgs.media.hitSoundHigh1, CHAN_LOCAL_SOUND );
         } else if ( dmg > 0 ) {
            trap_S_StartLocalSound( cgs.media.hitSoundHigh2, CHAN_LOCAL_SOUND );
         }
      } else if ( cg_hitBeep.integer == 3 ) {
         if ( dmg > 75 ) {
            trap_S_StartLocalSound( cgs.media.hitSoundHigh2, CHAN_LOCAL_SOUND );
         } else if ( dmg > 50 ) {
            trap_S_StartLocalSound( cgs.media.hitSoundHigh1, CHAN_LOCAL_SOUND );
         } else if ( dmg > 25 ) {
            trap_S_StartLocalSound( cgs.media.hitSoundLow1, CHAN_LOCAL_SOUND );
         } else if ( dmg > 0 ) {
            trap_S_StartLocalSound( cgs.media.hitSoundLow2, CHAN_LOCAL_SOUND );
         }
      }
   }  else if ( ps->persistant[PERS_HITS] < ops->persistant[PERS_HITS] ) {
      trap_S_StartLocalSound( cgs.media.hitTeamSound, CHAN_LOCAL_SOUND );
   }


Then if your server side code isn't working, what you need is this in G_Damage() right after PERS_ATTACKEE_ARMOR is set:
Code:
attacker->client->ps.persistant[PERS_DMG_GIVEN] += damage;


You can also remove all references to PERS_ATTACKEE_ARMOR while you're at it.




Top
                 
Quake3World.com | Forum Index | Programming Discussion


Post new topic Reply to topic


cron
Quake3World.com
© ZeniMax. Zenimax, QUAKE III ARENA, Id Software and associated trademarks are trademarks of the ZeniMax group of companies. All rights reserved.
This is an unofficial fan website without any affiliation with or endorsement by ZeniMax.
All views and opinions expressed are those of the author.