.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   Releases, Installers, Docs & Coding (http://forums.bots-united.com/forumdisplay.php?f=48)
-   -   bot_sounds.cpp (http://forums.bots-united.com/showthread.php?t=1810)

Huntkillaz 30-05-2004 04:50

bot_sounds.cpp
 
there's 3 distinctive lines that's being used over n over

i was wondering if u put it into a method that gets called instead

it would be neater code.. but will it slow\use more resources (ie memory\cpu)?

sPlOrYgOn 30-05-2004 05:39

Re: bot_sounds.cpp
 
yea but i think for 2 different if's it won't be called..
so i think he was trying to save cpu usage at the expense of the dll's size.

Pierre-Marie Baty 30-05-2004 15:07

Re: bot_sounds.cpp
 
...or he was just lazy and did a lot of CTRL-C CTRL-V :)

Huntkillaz 31-05-2004 05:07

Re: bot_sounds.cpp
 
so the bot_sounds.cpp can be reduced file size alot by adding a method similar to this:

Code:

  void SoundMethod(boolean a,float b, float c, boolean d)
  {
            if(a){
                    if ((iIndex < 0) || (iIndex >= gpGlobals->maxClients))
                          iIndex = UTIL_GetNearestPlayerIndex (VecBModelOrigin (pEdict));
            }
                    clients[iIndex].fHearingDistance = b * fVolume;
                    clients[iIndex].fTimeSoundLasting = gpGlobals->time + c;
                  if(d)
                          clients[iIndex].vecSoundPosition = pEdict->v.origin;
                    else
                            clients[iIndex].vecSoundPosition = vecPosition;
  }

and having 1 method call at each place instead of 3-5 lines?

but will it be efficient??

sPlOrYgOn 31-05-2004 05:19

Re: bot_sounds.cpp
 
actually it'll be very very very slightly less efficient but it'll save space in the dll...
at least thats what i think it'll do..

btw...
more descriptive names...
and I don't see iIndex or fVolume or pEdict or vecPosition defined anywhere in that scope...

Huntkillaz 31-05-2004 05:46

Re: bot_sounds.cpp
 
Quote:

Originally Posted by sPlOrYgOn
actually it'll be very very very slightly less efficient but it'll save space in the dll...
at least thats what i think it'll do..

btw...
more descriptive names...
and I don't see iIndex or fVolume or pEdict or vecPosition defined anywhere in that scope...

scope as in the paramaters of the method??...lol i wrote what the code would look like ..not the actual code :o... still learning whats whato_O

sPlOrYgOn 31-05-2004 05:54

Re: bot_sounds.cpp
 
hmm
I dunno of any way to teach you what a scope is but to show you...
Code:

#include <iostream>
using namespace std;

namespace blue
{
  int x = 3;
}

int x = 2;

int main ()
{
  int x = 0;
  {
      int x = 1;
      cout << "This is the value of x: " << x << endl;
      cout << "No.. this is.... " << blue::x << endl;
      cout << "Geez idiots this is.. " << ::x << endl;
  }
  cout << "You're all wrong.. this is.. " << x << endl;
  return (0);
}

well thats a little scope thingy...

Huntkillaz 31-05-2004 23:32

Re: bot_sounds.cpp
 
ahhhh...u mean class.......sorry as i said i've only learnt a little java...and c\c++ is like going to lower langs..

basically this is a method thats within the bot_sounds.cpp if u have a look u'll see that these 5 lines are often used...so to save space one can replace the 3-5 lines with just 1 method call...

i'll try do it and put it up....

sPlOrYgOn 01-06-2004 06:54

Re: bot_sounds.cpp
 
I say we go and add more hearable sounds...
it seems to be like it's missing some useful sounds..

Huntkillaz 05-06-2004 02:04

Re: bot_sounds.cpp
 
yep ur right ..knife hit's and stabs aint there... world spawn...

what other's do we need?

Huntkillaz 25-06-2004 06:30

Re: bot_sounds.cpp
 
will this work???
Code:

// ####################################
// # #

// # Ping of Death - Bot #

// # by #

// # Markus Klinge aka Count Floyd #

// # #

// ####################################

//

// Started from the HPB-Bot Alpha Source

// by Botman so Credits for a lot of the basic

// HL Server/Client Stuff goes to him

//

// bot_sounds.cpp

//

// Hooks to let Bots 'hear' otherwise unnoticed things. Base code & idea from killaruna/ParaBot

#include "bot_globals.h"

 

void SoundAttachToThreat (edict_t *pEdict, const char *pszSample, float fVolume)

{

// Called by the Sound Hooking Code (in EMIT_SOUND)

// Enters the played Sound into the Array associated with the Entity

Vector vecPosition;

int iIndex;

if (FNullEnt (pEdict))

return;

// Hit/Fall Sound ?

if ((strncmp ("player/bhit_flesh", pszSample, 17) == 0)

|| (strncmp ("player/headshot", pszSample, 15) == 0))

{

iIndex = ENTINDEX (pEdict) - 1;

// crash fix courtesy of Wei Mingzhi

if ((iIndex < 0) || (iIndex >= gpGlobals->maxClients))

iIndex = UTIL_GetNearestPlayerIndex (VecBModelOrigin (pEdict));

//clients[iIndex].fHearingDistance = 800.0 * fVolume;

//clients[iIndex].fTimeSoundLasting = gpGlobals->time + 0.5;

//clients[iIndex].vecSoundPosition = pEdict->v.origin;

SoundMethod(iIndex, false, 800.0, 0.5, false, true)

}

// Weapon Pickup ?

else if (strncmp ("items/gunpickup", pszSample, 15) == 0)

{

iIndex = ENTINDEX (pEdict) - 1;

// crash fix courtesy of Wei Mingzhi

if ((iIndex < 0) || (iIndex >= gpGlobals->maxClients))

iIndex = UTIL_GetNearestPlayerIndex (VecBModelOrigin (pEdict));

//clients[iIndex].fHearingDistance = 800.0 * fVolume;

//clients[iIndex].fTimeSoundLasting = gpGlobals->time + 0.5;

//clients[iIndex].vecSoundPosition = pEdict->v.origin;

SoundMethod(iIndex, false, 800.0, 0.5, false, true)

}

// Sniper zooming ?

else if (strncmp ("weapons/zoom", pszSample, 12) == 0)

{

iIndex = ENTINDEX (pEdict) - 1;

// crash fix courtesy of Wei Mingzhi

if ((iIndex < 0) || (iIndex >= gpGlobals->maxClients))

iIndex = UTIL_GetNearestPlayerIndex (VecBModelOrigin (pEdict));

//clients[iIndex].fHearingDistance = 500.0 * fVolume;

//clients[iIndex].fTimeSoundLasting = gpGlobals->time + 0.1;

//clients[iIndex].vecSoundPosition = pEdict->v.origin;

SoundMethod(iIndex, false, 500.0, 0.1, false, true)

}

// Reload ?

else if (strncmp ("weapons/reload", pszSample, 14) == 0)

{

iIndex = ENTINDEX (pEdict) - 1;

// crash fix courtesy of Wei Mingzhi

if ((iIndex < 0) || (iIndex >= gpGlobals->maxClients))

iIndex = UTIL_GetNearestPlayerIndex (VecBModelOrigin (pEdict));

//clients[iIndex].fHearingDistance = 500.0 * fVolume;

//clients[iIndex].fTimeSoundLasting = gpGlobals->time + 0.5;

//clients[iIndex].vecSoundPosition = pEdict->v.origin;

SoundMethod(iIndex, false, 1024.0, 3.0, false, true)

}

// The following Sounds don't have the Player Entity associated

// so we need to search the nearest Player

// Ammo Pickup ?

else if (strncmp ("items/9mmclip", pszSample, 13) == 0)

{

vecPosition = pEdict->v.origin;

iIndex = UTIL_GetNearestPlayerIndex (vecPosition);

//clients[iIndex].fHearingDistance = 500.0 * fVolume;

//clients[iIndex].fTimeSoundLasting = gpGlobals->time + 0.1;

//clients[iIndex].vecSoundPosition = pEdict->v.origin;

SoundMethod(iIndex, false, 500.0, 0.1, false, true)

}

// CT used Hostage ?

else if (strncmp ("hostage/hos", pszSample, 11) == 0)

{

vecPosition = VecBModelOrigin (pEdict);

iIndex = UTIL_GetNearestPlayerIndex (vecPosition);

//clients[iIndex].fHearingDistance = 1024.0 * fVolume;

//clients[iIndex].fTimeSoundLasting = gpGlobals->time + 5.0;

//clients[iIndex].vecSoundPosition = vecPosition;

SoundMethod(iIndex, false, 1024.0, 5.0, false, false)

}

// Broke something ?

else if ((strncmp ("debris/bustmetal", pszSample, 16) == 0)

|| (strncmp ("debris/bustglass", pszSample, 16) == 0))

{

vecPosition = VecBModelOrigin (pEdict);

iIndex = UTIL_GetNearestPlayerIndex (vecPosition);

//clients[iIndex].fHearingDistance = 1024.0 * fVolume;

//clients[iIndex].fTimeSoundLasting = gpGlobals->time + 2.0;

//clients[iIndex].vecSoundPosition = vecPosition;

SoundMethod(iIndex, false, 1024.0, 2.0, false, false)

}

// Someone opened a door

else if (strncmp ("doors/doormove", pszSample, 14) == 0)

{

vecPosition = VecBModelOrigin (pEdict);

iIndex = UTIL_GetNearestPlayerIndex (vecPosition);

//clients[iIndex].fHearingDistance = 1024.0 * fVolume;

//clients[iIndex].fTimeSoundLasting = gpGlobals->time + 3.0;

//clients[iIndex].vecSoundPosition = vecPosition;

SoundMethod(iIndex, false, 1024.0, 3.0, false, false)

}

}

void SoundSimulateUpdate (int iPlayerIndex)

{

// Tries to simulate playing of Sounds to let the Bots hear

// sounds which aren't captured through Server Sound hooking

edict_t *pPlayer = clients[iPlayerIndex].pEdict;

float fVelocity = pPlayer->v.velocity.Length2D ();

float fHearDistance = 0.0;

float fTimeSound;

// Pressed Attack Button ?

if (pPlayer->v.oldbuttons & IN_ATTACK)

{

fHearDistance = 4096.0;

fTimeSound = gpGlobals->time + 0.5;

}

// Pressed Used Button ?

else if (pPlayer->v.oldbuttons & IN_USE)

{

fHearDistance = 1024.0;

fTimeSound = gpGlobals->time + 0.5;

}

// Uses Ladder ?

else if (pPlayer->v.movetype == MOVETYPE_FLY)

{

if (fabs (pPlayer->v.velocity.z) > 50)

{

fHearDistance = 1024.0;

fTimeSound = gpGlobals->time + 0.3;

}

}

// Moves fast enough ?

else

{

static float fMaxSpeed = 0.0;

if (fMaxSpeed == 0.0)

fMaxSpeed = CVAR_GET_FLOAT ("sv_maxspeed");

fHearDistance = 1024.0 * (fVelocity / fMaxSpeed);

fTimeSound = gpGlobals->time + 0.3;

}

// Did issue Sound ?

if (fHearDistance > 0.0)

{

// Some sound already associated ?

if (clients[iPlayerIndex].fTimeSoundLasting > gpGlobals->time)

{

// New Sound louder (bigger range) than old sound ?

if (clients[iPlayerIndex].fHearingDistance <= fHearDistance)

{

// Override it with new

//clients[iPlayerIndex].fHearingDistance = fHearDistance;

//clients[iPlayerIndex].fTimeSoundLasting = fTimeSound;

//clients[iPlayerIndex].vecSoundPosition = pPlayer->v.origin;

SoundMethod(iPlayerIndex, true, 0, 0, true, true)

}

}

// New sound ?

else

{

// Just remember it

//clients[iPlayerIndex].fHearingDistance = fHearDistance;

//clients[iPlayerIndex].fTimeSoundLasting = fTimeSound;

//clients[iPlayerIndex].vecSoundPosition = pPlayer->v.origin;

SoundMethod(iPlayerIndex, true, 0, 0, true, true)

}

}

void SoundMethod(int i, boolean a,float b, float c, boolean d, boolean e)

{

if(a)

clients[i].fHearingDistance = fHearDistance;

else

clients[i].fHearingDistance = b * fVolume;

if(d){

clients[i].fTimeSoundLasting = fTimeSound;

else

clients[i].fTimeSoundLasting = gpGlobals->time + c;

if(e)

clients[i].vecSoundPosition = pEdict->v.origin;

else

clients[i].vecSoundPosition = vecPosition;

}

}




Pierre-Marie Baty 25-06-2004 10:09

Re: bot_sounds.cpp
 
I believe yes, but I'd have renamed that mysterious "SoundMethod" into something more explicit... :)

Huntkillaz 26-06-2004 00:21

Re: bot_sounds.cpp
 
Quote:

Originally Posted by Pierre-Marie Baty
I believe yes, but I'd have renamed that mysterious "SoundMethod" into something more explicit... :)

lol, okay ...therefore u can delete all the commented lines i made :)

and how would we be able to add more types of sounds that splorygon was talking about

Pierre-Marie Baty 26-06-2004 19:16

Re: bot_sounds.cpp
 
Constantly evaluating the players' actions each frame...

because currently, SoundAttachToThreat() is only called in pfnEmitSound and pfnEmitAmbientSound for SERVER-side sounds. You can't use this method for all the client-side sounds (gunshots, footsteps) that's why SoundSimulateUpdate() is used. All you need to do is to add more precise checks into this function to make the bot identify more sounds.


All times are GMT +2. The time now is 04:25.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.