.:: Bots United ::.  
filebase forums discord server github wiki web
cubebot epodbot fritzbot gravebot grogbot hpbbot ivpbot jkbotti joebot
meanmod podbotmm racc rcbot realbot sandbot shrikebot soulfathermaps yapb

Go Back   .:: Bots United ::. > Developer's Farm > SDK Programming discussions > Half-Life 2 SDK
Half-Life 2 SDK For developments focused around the Half-Life 2 engine Half-Life 2

Reply
 
Thread Tools
How to do correct movement
Old
  (#1)
SteveC
Member
 
Status: Offline
Posts: 37
Join Date: Jan 2005
Location: UK
Default How to do correct movement - 09-01-2005

To get the bots to move correctly in my plugin, http://forums.bots-united.com/showthread.php?t=3366 , I used the following function;

Quote:
void CBasePlayer:: ProcessUsercmds( CUserCmd *cmds, int numcmds, int totalcmds,
int dropped_packets, bool paused )
To get to this you need to get the CBasePlayer pointer, which I did with the following code;

Quote:
// entity index
iBotIndex=ENTINDEX(pEdict);
// base entity
pBaseEnt = CBaseEntity::Instance(pEdict);
// get the player entity
if ( pBaseEnt && pBaseEnt->IsPlayer() )
{
pPlayerEnt = static_cast< CBasePlayer * >( pBaseEnt );
}
if (!pPlayerEnt) return false;
Where pEdict is the bot edict_t, pBaseEnt is a CBaseEntity pointer, and pPlayer is the CBasePlayer pointer. I can't remember which files I needed to include to get this to work, but I think it was 'cbase.h' as it links to most things.

Last edited by SteveC; 09-01-2005 at 02:22..
  
Reply With Quote
Re: How to do correct movement
Old
  (#2)
SteveC
Member
 
Status: Offline
Posts: 37
Join Date: Jan 2005
Location: UK
Default Re: How to do correct movement - 09-01-2005

To build the CUserCmd I used the following code;

Quote:
// look
if (pClosestEnemy)
{
// look at enemy
Vector vAim=vClosestEnemy-pBaseEnt->EyePosition();
VectorAngles(vAim, mBotCmd.viewangles);
}
else if (tFront.fraction<0.5f)
{
mBotCmd.viewangles.y+=90.0f+((float)rand() / RAND_MAX) * 180.0f; // turn 180 (ish)
}
else if (tLeft.fraction<0.5f)
{
mBotCmd.viewangles.y+=22.5f+((float)rand() / RAND_MAX) * 45.0f; // turn +45 (ish)
}
else if (tRight.fraction<0.5f)
{
mBotCmd.viewangles.y-=22.5f+((float)rand() / RAND_MAX) * 45.0f; // turn -45 (ish)
}
// forward
if (pClosestEnemy)
{
mBotCmd.forwardmove=0.0f; // stop to shoot at enemy
}
else
{
mBotCmd.forwardmove=200.0f;
}
//shoot
if (((float)rand() / RAND_MAX)>0.97)
{
mBotCmd.buttons|=IN_ATTACK;
}
else
{
mBotCmd.buttons&=~IN_ATTACK;;
}
//jump
if (((float)rand() / RAND_MAX)>0.97)
{
mBotCmd.buttons|=IN_JUMP;
}
else
{
mBotCmd.buttons&=~IN_JUMP;
}
// issue the command
pPlayerEnt->ProcessUsercmds(&mBotCmd,1,1,0,false);
  
Reply With Quote
Re: How to do correct movement
Old
  (#3)
SteveC
Member
 
Status: Offline
Posts: 37
Join Date: Jan 2005
Location: UK
Default Re: How to do correct movement - 09-01-2005

The most critical part to get them to turn, and move the way they are facing is to use this line of code;
Quote:

// this changes the fixangle from absolute (which isn't coded for) to none
// note: has to be run here because it doesn't work in the addbot routine?!?!?
if (pPlayerEnt->PlayerData()->fixangle!=FIXANGLE_NONE) pPlayerEnt->PlayerData()->fixangle=FIXANGLE_NONE;

As the comment says the bots by default use FIXANGLE_ABS, but the HL2 movement code isn't coded to support that type, so I change it to FIXANGLE_NONE. However I haven't worked out exactly where it needs to be changed, so I check it each frame before issuing the movement command. A bit of a bodge I know .

I think that's everything to get the correct movement, with full animation, physics interaction, and possibly ladder use.

I'll post my full code sometime tomorrow probably, just incase I've missed something.
  
Reply With Quote
Re: How to do correct movement
Old
  (#4)
Cheeseh
[rcbot]
 
Cheeseh's Avatar
 
Status: Offline
Posts: 361
Join Date: Dec 2003
Location: China
Default Re: How to do correct movement - 09-01-2005

How did you manage to compile with CBasePlayer ? The server & plugin builds are different and don't allow having cbasePlayer/CBaseEntity defined because there are hundereds of compile errors when I try. When I also contacted Alfred (valve) he said you cannot access these in plugins and so did botman, so please share your 'secret'

(ps: I'm sure all of us would be intrigued to know)

Last edited by Cheeseh; 09-01-2005 at 03:34..
  
Reply With Quote
Re: How to do correct movement
Old
  (#5)
SteveC
Member
 
Status: Offline
Posts: 37
Join Date: Jan 2005
Location: UK
Default Re: How to do correct movement - 09-01-2005

I'm no C++ linker expert (if you know someone who is, let me know ), so I don't know what I did that is special. I think the main difference between my plugin and the sample one is that I included cbase.h.
I cannot access all the functions of the CBasePlayer, I get compile errors with many, and if include baseplayer.cpp in the project then all hell breaks loose as you say.
One thing I did find was that the class CBotManager is a friend class to CBasePlayer, I think that means you can then access private variables of CBasePlayer. However there is no CBotManager defined anywhere in the SDK, so I define one, but it doesn't seem to help much so I don't know if just defining a class of the right name is enough to become the friend. It could be useful in the future, but you don't need it to do what I'm doing now.

Also I found out how to use the Vector class routines (includes the pesky fast sqaure root), you just need to include the mathlib, but then I got exceptions because it wasn't initialised. Initialising it lets it all work, but surely it must be already initialised for the main engine? I just found it a bit strange.

Anyway attached is the source for the current build now it's been tidied up. There are still many problems to solve, like how to find enemies.
Attached Files
File Type: zip SCBot.zip (14.8 KB, 814 views)
  
Reply With Quote
Re: How to do correct movement
Old
  (#6)
stefanhendriks
RealBot Author
 
stefanhendriks's Avatar
 
Status: Offline
Posts: 3,088
Join Date: Nov 2003
Location: Netherlands
Default Re: How to do correct movement - 09-01-2005

very interesting. I already had my own way of 'moving to a direction'. I am particularry interested in the aiming part of the bot. I want to do it as much the 'less hacky' way as possible.

I'll see if i can access cBaseEntity without hacking to much around. The above code looks a lot less hacky then the one i saw before... unless i am mistaken of course.


Author of RealBot, "Arrakis" and "Dune 2 - The Maker" | co-Founder of Bots-United | Fundynamic | Blog | E-Mail me
  
Reply With Quote
Re: How to do correct movement
Old
  (#7)
SteveC
Member
 
Status: Offline
Posts: 37
Join Date: Jan 2005
Location: UK
Default Re: How to do correct movement - 09-01-2005

No hacking in the code, well not intentionally anyway. The worst thing is casting the CBaseEntity to the CBasePlayer, but that was copied directly out of valves code.

I hope it works for you too, otherwise I've no idea what I've done to get it to work. o_O
  
Reply With Quote
Re: How to do correct movement
Old
  (#8)
stefanhendriks
RealBot Author
 
stefanhendriks's Avatar
 
Status: Offline
Posts: 3,088
Join Date: Nov 2003
Location: Netherlands
Default Re: How to do correct movement - 09-01-2005

well, i wonder if it will still work after a change in CSS, or that you have to recompile or whatever. Because that is my main concern, the continuity of a project


Author of RealBot, "Arrakis" and "Dune 2 - The Maker" | co-Founder of Bots-United | Fundynamic | Blog | E-Mail me
  
Reply With Quote
Re: How to do correct movement
Old
  (#9)
@$3.1415rin
Council Member, Author of JoeBOT
 
@$3.1415rin's Avatar
 
Status: Offline
Posts: 1,381
Join Date: Nov 2003
Location: Germany
Default Re: How to do correct movement - 09-01-2005

looks like the only problem would be if a mod would change the CBasePlayer class, but as I already wondered in HL1, why shouldnt this be done by inheritance ? I mean, if nobody would change it, everything would be fine, but in HL1, almost everyone did ...


  
Reply With Quote
Re: How to do correct movement
Old
  (#10)
SteveC
Member
 
Status: Offline
Posts: 37
Join Date: Jan 2005
Location: UK
Default Re: How to do correct movement - 09-01-2005

Am I correct in assuming that it would only be a problem if they changed the number/definitions of the functions, they can change the content of the functions and it would be fine? Also you can still get to alot of stuff from the CBaseEntity, but I guess they could change that too, if they were really determined.
  
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles.com