.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   General Bot Coding (http://forums.bots-united.com/forumdisplay.php?f=24)
-   -   Detecting fall damage in a safe way? (http://forums.bots-united.com/showthread.php?t=338)

stefanhendriks 12-01-2004 17:09

Detecting fall damage in a safe way?
 
I am trying to figure out how to get a 100% solid method to know a bot recieved damage due falling. This is to let bots learn from their mistakes in some nodes.

I tried using the DMG_FALL and DMG_CRUSS bits, but they gave me no luck! I saw in the SDK only bits gets sent that require a HUD drawing on the client, this stinks!

My code:
Code:

// This message gets sent when the bots are getting damaged.
void BotClient_Valve_Damage(void *p, int bot_index)
{
 //DebugOut("bot_client: BotClient_Valve_Damage()\n");
  static int state = 0;  // current state machine state
  static int damage_armor;
  static int damage_taken;
  static int damage_bits;  // type of damage being done
  static Vector damage_origin;
  if (state == 0)
  {
          state++;
          damage_armor = *(int *)p;
  }
  else if (state == 1)
  {
          state++;
          damage_taken = *(int *)p;
  }
  else if (state == 2)
  {
          state++;
          damage_bits = *(int *)p;
  }
  else if (state == 3)
  {
          state++;
          damage_origin.x = *(float *)p;
  }
  else if (state == 4)
  {
          state++;
          damage_origin.y = *(float *)p;
  }
  else if (state == 5)
  {
          state = 0;
          damage_origin.z = *(float *)p;
          if ((damage_armor > 0) || (damage_taken > 0))
          {
                  // Damage recieved:
                  // - when the prev node was higher (so we are sure we do FIX the correct nodes!)
                  //  we fix it (only when dist > 90)
                  cBot *pBot = &bots[bot_index];
 
                  if ((damage_bits & (DMG_FALL | DMG_CRUSH))
                  {                                         
                          LOG_CONSOLE (PLID, "realbot - fixed connection with falling.");                         
                          LOG_MESSAGE (PLID, "realbot - fixed connection with falling.");
                          if (pBot->bot_pathid > 0)
                          {
                                  int iNode = NodeMachine.NodeFromPath(pBot->iIndex, (pBot->bot_pathid-1));
                                  float fDist = fabs(damage_origin.z - NodeMachine.node_vector(iNode).z);
                                  if (fDist > 90)
                                  {
                                          // we know where we came from, and we know where we went to
                                          int iNodeTo = NodeMachine.NodeFromPath(pBot->iIndex, pBot->bot_pathid);
                                          // remove connection
                                          NodeMachine.remove_neighbour_node(iNode, iNodeTo);
                                  }
                          }
                  }
                // ignore certain types of damage...
                if (damage_bits & IGNORE_DAMAGE)
                        return;
                // if the bot doesn't have an enemy and someone is shooting at it then
                // turn in the attacker's direction...
                if (bots[bot_index].pBotEnemy == NULL)
                {
                        // face the attacker... (yeah yeah, cheating for now ;) )
  // Face danger vector
          pBot->vHead = damage_origin;
                        pBot->vBody = damage_origin;
                       
                        // move to damage vector
                        pBot->f_camp_time = gpGlobals->time; // stop camping
                        pBot->iGoalNode = NodeMachine.close(damage_origin, 150, NULL);
                        pBot->bot_pathid = -1;
  ///////////// END STEFAN
                }
          }
  }
}

Code from sdk (player.cpp, function "UpdateClientdata"),
Code:

if (pev->dmg_take || pev->dmg_save || m_bitsHUDDamage != m_bitsDamageType)
 {
  // Comes from inside me if not set
  Vector damageOrigin = pev->origin;
  // send "damage" message
  // causes screen to flash, and pain compass to show direction of damage
  edict_t *other = pev->dmg_inflictor;
  if ( other )
  {
  CBaseEntity *pEntity = CBaseEntity::Instance(other);
  if ( pEntity )
        damageOrigin = pEntity->Center();
  }
  // only send down damage type that have hud art
  int visibleDamageBits = m_bitsDamageType & DMG_SHOWNHUD;
  MESSAGE_BEGIN( MSG_ONE, gmsgDamage, NULL, pev );
  WRITE_BYTE( pev->dmg_save );
  WRITE_BYTE( pev->dmg_take );
  WRITE_LONG( visibleDamageBits );
  WRITE_COORD( damageOrigin.x );
  WRITE_COORD( damageOrigin.y );
  WRITE_COORD( damageOrigin.z );
  MESSAGE_END();
 
  pev->dmg_take = 0;
  pev->dmg_save = 0;
  m_bitsHUDDamage = m_bitsDamageType;
 
  // Clear off non-time-based damage indicators
  m_bitsDamageType &= DMG_TIMEBASED;
 }


Pierre-Marie Baty 13-01-2004 00:40

Re: Detecting fall damage in a safe way?
 
The IGNORE_DAMAGE bits don't work in Counter-Strike.

Do this instead
Code:

// is this player falling fast enough to get some damage ?
if (pEdict->v.flFallVelocity > PLAYER_MAX_SAFE_FALL_SPEED)

look in the SDK's player.h:
Code:

#define PLAYER_FATAL_FALL_SPEED 1024// approx 60 feet
#define PLAYER_MAX_SAFE_FALL_SPEED 580// approx 20 feet


botmeister 13-01-2004 03:01

Re: Detecting fall damage in a safe way?
 
I have a similar problem. How to detect if a bot is getting damage from being attacked, and who the attacker is. I tried using the "Damage" message, but it does not indicate what the cause of the damage is, or who (or what) is the source. I ended up doing a traceline back to the source origin to see what it is, but the method is cpu intensive and inaccurate.

Pierre-Marie Baty 13-01-2004 03:10

Re: Detecting fall damage in a safe way?
 
lol, I feel like I'm your savior for each problem you have :D

botmeister: already checked: pEdict->v.dmg_inflictor ?

:)

botmeister 13-01-2004 05:23

Re: Detecting fall damage in a safe way?
 
Quote:

Originally Posted by Pierre-Marie Baty
lol, I feel like I'm your savior for each problem you have :D

botmeister: already checked: pEdict->v.dmg_inflictor ?

:)

THANKS! :D

How in the hell do you find this stuff anyway? ???:(

Pierre-Marie Baty 13-01-2004 05:59

Re: Detecting fall damage in a safe way?
 
the hell you're talking about is called "PMTools plugin", and it's available for download with source code on my site, hehe :P

strelok 13-01-2004 06:53

Re: Detecting fall damage in a safe way?
 
BTW: Whether function UpdateClientData in dll.cpp is necessary? Count Floyd spoke, that she is not necessary.

Pierre-Marie Baty 13-01-2004 07:34

Re: Detecting fall damage in a safe way?
 
It is not necessary. You can delete it.

This function is used by clients to ask the server to send a network message containing various data about the client, so that the client can update itself and synchronize with the server. It would be useful for a client-side bot. But since your bot is a server-side bot, all the data concerning your bots is available through pBot->pEdict, and you don't need to ask the server to send you anything because you use the same structures as the server.

Cheeseh 13-01-2004 18:08

Re: Detecting fall damage in a safe way?
 
UpdateClientData is only used in the bot code to find out if the bots weapons have been changed and it's weapons haven't been updated yet. You only need to use it if a bot drops its weapon, as it doesnt get removed from the bots weapons bitmask (but it does in the pev->weapons bitmask).

UpdateClientData uses some cpu I think, so I just replaced it by checking pev->weapons instead of cd.weapons that comes from UpdateClientData.

stefanhendriks 15-01-2004 20:04

Re: Detecting fall damage in a safe way?
 
thanks guys, i think i can work with this stuff! :D


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

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