.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   Half-Life 2 SDK (http://forums.bots-united.com/forumdisplay.php?f=62)
-   -   How to do correct movement (http://forums.bots-united.com/showthread.php?t=3369)

SteveC 09-01-2005 01:10

How to do correct movement
 
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.

SteveC 09-01-2005 01:13

Re: How to do correct movement
 
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);


SteveC 09-01-2005 01:21

Re: How to do correct movement
 
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.

Cheeseh 09-01-2005 02:23

Re: How to do correct movement
 
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' :P

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

SteveC 09-01-2005 11:09

Re: How to do correct movement
 
1 Attachment(s)
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.

stefanhendriks 09-01-2005 11:39

Re: How to do correct movement
 
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.

SteveC 09-01-2005 11:45

Re: How to do correct movement
 
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

stefanhendriks 09-01-2005 11:58

Re: How to do correct movement
 
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 ;)

@$3.1415rin 09-01-2005 11:58

Re: How to do correct movement
 
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 ...

SteveC 09-01-2005 12:13

Re: How to do correct movement
 
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.

stefanhendriks 09-01-2005 12:14

Re: How to do correct movement
 
yes, thats the problem. But since this bot seems to work with CS, there MUST be an enheritance at the CSS side! And since HL2DM will be released soon (its source i believe). It could mean that the bot should work on HL2DM as well..

stefanhendriks 09-01-2005 12:18

Re: How to do correct movement
 
hey i do notice your bot walks and looks the same way right? How about looking to direction A and walking to direction B?

SteveC 09-01-2005 12:25

Re: How to do correct movement
 
I was planning on doing that in the same way as you do when playing HL, using the sideways speed to simulate the strafe keys. A bot could also do it at any angle not just at 45degrees (like a player) by just using different ratios of forward speed and sidespeed.

SteveC 09-01-2005 12:26

Re: How to do correct movement
 
I think the animations should also work correctly when you do it that way.

stefanhendriks 09-01-2005 12:39

Re: How to do correct movement
 
this will be pretty complicated when you want to look into several directions and walk just a path. I do know strafing is a way for combat, but i also thought , as with HL1 bot coding you could just pass 2 different angles (one for body, one for head) to get the same result. Its up to the coder to smoothen this out, but this would be most ideal (and easy).

SteveC 09-01-2005 12:47

Re: How to do correct movement
 
I could add two vectors to the CBot class which contain the movement direction and the viewing direction, then it would be quite easy to 'say' "look there and walk here". I'll get on it right away infact.

stefanhendriks 09-01-2005 12:52

Re: How to do correct movement
 
great ;) i can't work on this right now, but i am quite anxious to see what you got working there! :D

Cheeseh 09-01-2005 13:52

Re: How to do correct movement
 
Whenever I compile your source, I get all the same compile errors I usually get when I try to include cbase.h,

see, whenever I just include cbase.h, I get "syntax error identifier: x... syntax error: identifier y... syntax..."

surely you must have linked something differently?

Sorry but I'd just like to know how to get CBasePlayer or CBaseEntity in a plugin as I'd like to do it by myself, and then I'll leave you alone :P

@$3.1415rin 09-01-2005 13:57

Re: How to do correct movement
 
same problem here ...

stefanhendriks 09-01-2005 14:03

Re: How to do correct movement
 
there is no workspace included in the project, perhaps you need to do that so we can see what you link differently...

@$3.1415rin 09-01-2005 14:07

Re: How to do correct movement
 
that are primarily compile errors, no linking errors

Cheeseh 09-01-2005 14:17

Re: How to do correct movement
 
There is a visual C++ .NET workspace, I guess you're still using VC 6 :) ?

edit: yeah I think there is just something missing to compile it properly.

SteveC 09-01-2005 14:18

Re: How to do correct movement
 
Yeah I just got a message from my brother having the same problem, so I'm starting from a blank SDK just incase I cahnged something in the main files. Hopefully I'll have a working solution shortly.

SteveC 09-01-2005 15:05

Re: How to do correct movement
 
1 Attachment(s)
doh, something so annoying is solved by something so easy;
just add
GAME_DLL
to your preprocessor defines, and (fingers crossed) it should be problem sorted.

@$3.1415rin 09-01-2005 15:15

Re: How to do correct movement
 
that wasnt the reason I guess ... still lots of errors

Cheeseh 09-01-2005 15:18

Re: How to do correct movement
 
It works for your SCBot source, but not with my bot, I get even more errors than I used to. (1761 errors to be exact!) (also seems a bit of a hack since it isn't the game dll we're building)

@$3.1415rin 09-01-2005 15:23

Re: How to do correct movement
 
that last zip file steve uploaded doesnt even work here ...

SteveC 09-01-2005 15:24

Re: How to do correct movement
 
It does work for me o_O . Just this second I just created a new Source SDK (under the name test2) and extracted the above file /|\ into the utils/SCbot dir and it compiled first time.
You will probably need to do a re-build though.
The problem was in the file public/networkvar.h, on line 421 they have a preprocessor if statement which only creates the CNetworkHandleBase class if you have defined CLIENT_DLL or GAME_DLL. I didn't define either (i had modified the file in earlier attempts) but defining GAME_DLL works perfectly.

SteveC 09-01-2005 15:30

Re: How to do correct movement
 
Quote:

Originally Posted by Cheeseh
It works for your SCBot source, but not with my bot, I get even more errors than I used to. (1761 errors to be exact!) (also seems a bit of a hack since it isn't the game dll we're building)

Yeah if you define GAME_DLL (or CLIENT_DLL) and include some other files then you can cause major problems. I don't think you need much more than cbase.h normally (apart from the interface headers).

And the only reason it's a 'hack' is because valve forces us to define one to get the Networkvar.h to compile properly. The first time I had commented the #if statement on line 421 of Networkvar.h, so I didn't need to define either DLL type.
I can see your point though that I'm missleading the engine a little tiny bit.

@$3.1415rin 09-01-2005 15:37

Re: How to do correct movement
 
works now, reisnatlleds the sdk again ... dunno what was the reason

stefanhendriks 09-01-2005 16:02

Re: How to do correct movement
 
the SDK had an update, perhaps you need to re-build the source from a new SDK as SteveC did ;)

Cheeseh 09-01-2005 17:32

Re: How to do correct movement
 
I'm compiling the SCBot source with the same SDK code as my bot, SCBot compiles fine with the CBasePlayer stuff, mine doesn't even with the GAME_DLL thing and stuff, it;s confusin me ???:(

SteveC 09-01-2005 17:42

Re: How to do correct movement
 
Some of the functions within CBasePlayer don't work, they create linking errors. I think it's related to what the function calls, e.g. if it calls stuff from within the base entity class.

stefanhendriks 09-01-2005 20:23

Re: How to do correct movement
 
I saw in your post you figured how to do walking to A , aiming at B

got any hints/source on that? :D

SteveC 09-01-2005 21:15

Re: How to do correct movement
 
I think the latest souce zip in this thread contains the code for moving one way and looking in the other. But I don't think it will be very tidy, so not too readable.

It's quite easy now the math utilities are working because you can do tricky stuff in one line. =)

stefanhendriks 09-01-2005 22:04

Re: How to do correct movement
 
i got this principle working already as well; thx for the code snippets. I don't think i need more ;)

http://johannes.lampel.net/pics/shit/de_cbble0005.jpg

thx for mr joe / asp for his screeny and testing,

man i have to reinstall MSVC! :(

Geesu 11-01-2005 14:57

Re: How to do correct movement
 
I could compile the second zip file he posted fine, but I was unable to find where you defined GAME_DLL, which file did you put that in if you mind me asking?

@$3.1415rin 11-01-2005 15:17

Re: How to do correct movement
 
you can define stuff in the properties of your project, so you don't need to write that defines directly to some file ( which you might forget to load here and there, and then you'd be fucked up )

Cheeseh 11-01-2005 18:57

Re: How to do correct movement
 
I'm having trouble getting bots to face something, they never turn to look at anything when I set the cmd.viewangles to the angles I want. Is there something I'm missing? I'm using SteveC's CBasePlayer way of issuing a command:

PHP Code:

void CBot :: runPlayerMove()
{
    static 
CUserCmd cmd;

    
//////////////////////////////////
    
memset(&cmd0sizeof(cmd));
    
//////////////////////////////////
    
cmd.forwardmove m_fForwardSpeed;
    
cmd.sidemove m_fSideSpeed;
    
cmd.upmove m_fUpSpeed;
    
cmd.buttons m_iButtons;
    
cmd.impulse m_iImpulse;
    
cmd.viewangles m_vViewAngles;
    
    
CBasePlayer *pPlayer = (CBasePlayer*)CBaseEntity::Instance(m_pEdict);
    
// SteveC : CBasePlayer user command
    
pPlayer->ProcessUsercmds(&cmd,1,1,0,false); // SteveC



the bots move okay though, they just won't turn at all ?

SteveC 11-01-2005 19:02

Re: How to do correct movement
 
Did you include the line of code to set the fixangle type to none?

It's in post 3 of this thread.


All times are GMT +2. The time now is 18:51.

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