.:: Bots United ::.

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

bluebyte 03-06-2004 16:55

my reload fix
 
I thought that bots were reloading way too infrequently. They sometimes engage the enemy with nearly-empty clips. So i decided to try to fix this. I wrote a method in bot.cpp. here:

Code:


 
void BotCheckReload(bot_t *pBot, edict_t *pEdict)//bluebyte
{
if (!(pBot->bIsReloading) && FNullEnt (pBot->pBotEnemy)
&& (pBot->current_weapon.iAmmo1 > 0) && !(pBot->iStates & STATE_HEARINGENEMY)
&& !(pBot->iStates & STATE_SEEINGENEMY) )
{
int maxClip;//bluebyte
switch (pBot->current_weapon.iId)//bluebyte
{
 
        case CS_WEAPON_P228:        maxClip = 13 ; break;
        case CS_WEAPON_ELITE:        maxClip = 30 ; break;
        case CS_WEAPON_FIVESEVEN:        maxClip = 20; break;
        case CS_WEAPON_DEAGLE:        maxClip = 7 ; break;
        case CS_WEAPON_USP:        maxClip = 12 ; break;
        case CS_WEAPON_GLOCK18:        maxClip = 20 ; break;
 
        case CS_WEAPON_M3:        maxClip = 8 ; break;
        case CS_WEAPON_XM1014:        maxClip = 7 ; break;
 
        case CS_WEAPON_MP5NAVY:        maxClip = 30 ; break;
        case CS_WEAPON_MAC10:        maxClip = 30 ; break;
        case CS_WEAPON_P90:        maxClip = 50 ; break;
        case CS_WEAPON_UMP45:        maxClip = 25 ; break;
        case CS_WEAPON_TMP:        maxClip = 30 ; break;
 
        case CS_WEAPON_M4A1:        maxClip = 30 ; break;
        case CS_WEAPON_AK47:        maxClip = 30 ; break;
        case CS_WEAPON_SG552:        maxClip = 30 ; break;
        case CS_WEAPON_AUG:        maxClip = 30 ; break;
        case CS_WEAPON_G3SG1:        maxClip = 20 ; break;
        case CS_WEAPON_SG550:        maxClip = 30 ; break;
        case CS_WEAPON_SCOUT:        maxClip = 10 ; break;
        case CS_WEAPON_AWP:        maxClip = 10 ; break;
 
        case CS_WEAPON_M249:        maxClip = 100 ; break;
 
        case CS_WEAPON_SHIELDGUN:        maxClip = 0 ; break;
        case CS_WEAPON_GALIL:        maxClip = 35 ; break;
        case CS_WEAPON_FAMAS:        maxClip = 25 ; break;
 
        default:        maxClip = 0;//for knives & grenades
}//end switch
        //bluebyte: we should reload more frequently
if (pBot->current_weapon.iClip < (0.8*maxClip) )
{
pEdict->v.button |= IN_RELOAD;
pBot->bIsReloading = TRUE;
}
}//end if
}//end BotCheckReload

They reload if they don't have an enemy, if don't see an enemy, if don't hear an enemy, if aren't reloading already, and if they have enough ammo to reload ( > 0) .

If all these conditions are satisfied, i proceed and get the clip capacity of the current weapon that the bot is using. the switch-case block server this purpose. I do this because there is no variable in the code that keeps track of this already (or i missed it). After i got maxClip for current weapon, i check if current number of bullets in the clip is less than %80 of maxclip. (for instance, if the bot is using mp5navy and has 23 bullets, he reloads, but if it has, say, 24 bullets or more, it doesn't) If it is less, then the bot reloads. If not, they don't reload.

I call this method in bot think, at the beginning of these tasks: TASK_NORMAL, TASK_ENEMYHUNT, TASK_SEEKCOVER (but here not at the beginning of the task, but just after " // Enter look direction from previously calculated positions" code (after the else), TASK_PAUSE, TASK_CAMP, TASK_HIDE, TASK_MOVETOPOSITION and finally TASK_FOLLOWUSER.

I have tested my modifications for about 1 hour now, and it seems to work well. I already sent this code to SPlorYGon but i'm not sure if he will decide to include it or not, i just wrote this thread to get some feedback. If you guys request, i may prepare a binary for you. Also, it is likely that this will be my last coding about podbot, since i'll work on something else, anyway i always remain as a part of this "warm" community :)

>BKA< T Wrecks 03-06-2004 18:44

Re: my reload fix
 
Awwww, man! What a pity - you come, post 2-3 very useful things, and now you tell us this is probably the last thing you'll ever do with PODBot! :'(
Ok, in any case I think the stuff you coded here really makes sense; at least it's the way I'd prefer bots to behave. No reloading orgies whenever 1 or 2 bullets have been fired, yet no facing enemies with the final bullet left... thumbs up!
You only made some tiny mistakes concerning clip capacity:
M3 Shotgun is 8, not 7
XM1014 Auto-Shottie is 7, not 8
SG 550 is 30, not 20
...and why do your FAMAS and GALIL have 0? I can't check right now, cause my CS 1.6 is unavailable due to the last CS update... as usual... 9_9
Anyway, thanks for this contribution and good luck with whatever you're up to... ;) :) :| :( :'( !!

bluebyte 03-06-2004 22:21

Re: my reload fix
 
okay, thanks for your corrections Wrecks, I edited the code to reflect the right values now. Also, i forgot to mention, they are zero because i haven't played 1.6 therefore i don't know the values for galil and famas (have no clue about CS_WEAPON_SHIELDGUN also) . So if somebody can supply me with the correct maxclip values, i'll update them. C ya :)

Dark JP2 03-06-2004 22:24

Re: my reload fix
 
galil: 35 shots/clip
famas: 25 shots/clip

to the shieldgun <- what does that thing mean?

sPlOrYgOn 04-06-2004 01:23

Re: my reload fix
 
yea you already gave this to me..
and i cleaned it up and made it easier to read..
Code:

void BotCheckReload (bot_t *pBot)  // bluebyte
{
  if (!pBot->bIsReloading && FNullEnt (pBot->pBotEnemy) && (pBot->current_weapon.iAmmo1 > 0)
      && !(pBot->iStates & STATE_SEEINGENEMY) && !(pBot->iStates & STATE_SUSPECTENEMY)
      && !(pBot->iStates & STATE_HEARINGENEMY))
  {
      int iMaxClip;  // bluebyte

      switch (pBot->current_weapon.iId)  // bluebyte
      {
      case CS_WEAPON_M249:
        iMaxClip = 100;
        break;

      case CS_WEAPON_P90:
        iMaxClip = 50;
        break;

      case CS_WEAPON_GALIL:
        iMaxClip = 35;
        break;

      case CS_WEAPON_ELITE:
      case CS_WEAPON_MP5NAVY:
      case CS_WEAPON_TMP:
      case CS_WEAPON_MAC10:
      case CS_WEAPON_M4A1:
      case CS_WEAPON_AK47:
      case CS_WEAPON_SG552:
      case CS_WEAPON_AUG:
      case CS_WEAPON_SG550:
        iMaxClip = 30;
        break;

      case CS_WEAPON_UMP45:
      case CS_WEAPON_FAMAS:
        iMaxClip = 25;
        break;

      case CS_WEAPON_GLOCK18:
      case CS_WEAPON_FIVESEVEN:
      case CS_WEAPON_G3SG1:
        iMaxClip = 20;
        break;

      case CS_WEAPON_P228:
        iMaxClip = 13;
        break;

      case CS_WEAPON_USP:
        iMaxClip = 12;
        break;

      case CS_WEAPON_AWP:
      case CS_WEAPON_SCOUT:
        iMaxClip = 10;
        break;

      case CS_WEAPON_M3:
        iMaxClip = 8;
        break;

      case CS_WEAPON_DEAGLE:
      case CS_WEAPON_XM1014:
        iMaxClip = 7;
        break;

      default:  // for knives & grenades
        iMaxClip = 0;
      }

      // bluebyte: we should reload more frequently
      if (pBot->current_weapon.iClip < (0.8 * iMaxClip))
      {       
        pBot->pEdict->v.button |= IN_RELOAD;
        pBot->bIsReloading = TRUE;
      }
  }
}


>BKA< T Wrecks 04-06-2004 09:14

Re: my reload fix
 
Hmmm... smart guy! :D You're right... this IS less complicated.


All times are GMT +2. The time now is 16:08.

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