OpenArena Message Boards

OpenArena Contributions => Development => Topic started by: hc on September 24, 2007, 03:50:38 AM



Title: [SOLVED]: placing bots dynamically
Post by: hc on September 24, 2007, 03:50:38 AM
Hello at all!

First of all: I'm new to the topic "editing games" and google was already my friend ;-)

I'm searching for hints / links to the question how to place bots dynamically in a level. As an example:
The player frags a bot which was in the (fictive) north direction. Now the bot should be respawn in the eastern direction (90 degrees away from the kill position).

Is it possible?
Until now I'm not familiar to the source code at all. Is the code/botlib/botlib.h the right place to look for such an option?

Thank you for your suggestion!

Best regards!

Steeve


Title: Re: placing bots dynamically
Post by: sago007 on September 24, 2007, 04:10:21 AM
The spawn functions are located in code/game/g_client.c.

Even if you think that you are working with a bot issue it is ultimately a gameplay change just only affecting the bots.

You might need to get the attackers position from another place. And you need some mathematical knowledge to find the spawnpoint that best describes your needs.


Title: Re: placing bots dynamically
Post by: De@thByBl@st on September 26, 2007, 01:55:15 PM
I thought DM spawns were already somewhat random in nature, what am I missing here?


Title: Re: placing bots dynamically
Post by: sago007 on September 26, 2007, 04:01:40 PM
I thought DM spawns were already somewhat random in nature, what am I missing here?
It sounds like he want them not to be random. I don't know why but it should be possible.


Title: Re: placing bots dynamically
Post by: hc on September 27, 2007, 01:31:58 AM
Hi sago007,
hi De@thByBl@st!

That's right, I don't want it to be random.
The goal of my "task" is to spawn the bots at the boarder of the (visible) screen. That's the area of the peripheral vision especially for people with a special kind of blindness. (That's the short version ;-) )

I've found the method "CG_Viewpos_f()" in cgame\cg_consolecmds.c and I hope that's the right methode or better the right syntax to get the viewing position.
I guess I should try the following method of resolution:
  • First I would like to get the position of the bot which the player fragged. I'm not quite sure how to get the position but I hope it will be possible like showing the name of the bot when the crosshair is aiming the bot.
  • After I've got the position I would like to alter the respawn position to "respawn position = frag position + new offset (maybe 90 degrees or whatever)".

I guess it's a little bit like a shooting gallery on a fair. (You do know a shooting gallery, don't you? Or is it only a german invention which you can find at the "Oktoberfest" in Munich?!)

As I mentioned before, I'm not very familiar with the source code and C(++) is not "my" language (JAVA is).

Thank you! :-)


Title: Re: placing bots dynamically
Post by: iLeft.bye on September 27, 2007, 01:54:29 AM
afaik you can only change what you see if you modify cgame
on the other hand if you modify game code, you can change the game logic
in your case where the bots spawn


Title: Re: placing bots dynamically
Post by: hc on September 27, 2007, 02:04:29 AM
Alright fork,
but I guess it should be possible to get the frag-position of the bot to recalculate this position and use it somewhere else, or am I wrong?

Thanks for your reply!



Title: Re: placing bots dynamically
Post by: hc on September 27, 2007, 05:16:46 AM
Ok the first part is done :-)

I get the position of the bot when I aim at him. I've done the following:
cgame\cg_draw.c - CG_DrawCrosshairNames()
Code:
x = cg_entities[cg.crosshairClientNum].lerpOrigin[0];
y = cg_entities[cg.crosshairClientNum].lerpOrigin[1];
z = cg_entities[cg.crosshairClientNum].lerpOrigin[2];
x, y, z are floats.

The next step will be to do some math.... :-/



Title: Re: placing bots dynamically
Post by: sago007 on September 27, 2007, 10:01:21 AM
cgame\cg_draw.c - CG_DrawCrosshairNames()

It will not work. cg_draw is in 'cgame' not 'game'. Spawn functions is in 'game'. You cannot easily move data between 'game' and 'cgame'.

You need to look in 'player_die' in 'game/g_combat.c'. There you can get the coordinates of the bot (self), human (attacker) and do math with that. And if you save the data in a data structure from 'g_local.h' you can access the coordinates in the pick spawn spot functions.


Title: Re: placing bots dynamically
Post by: hc on October 02, 2007, 03:48:05 AM
Ok, thanks sago007!
That works fine. I've got the position :-)

I've got a new question now:
How can I notice if the human player is "self" or is "attacker"? I suppose there is a flag somewhere in "self" or in "attacker" but I've not found it yet.
I've seen "self->classname" or "attacker->classname" but it's the hole time "player".

I'm afraid that there's no division in this way between human player and bot in openarena?!

Thanks for all your help, guys!



Title: Re: placing bots dynamically
Post by: hc on October 05, 2007, 04:14:55 AM
Hi guys!

And again... I've got a problem :-(

I've put the position into a temp variable to get it in g_client.c.

g_combat.c :
Code:
VectorCopy(self->r.currentOrigin, client->pers.positionOfDeath);

The copy works but then OA crashes to the windows error notification service (the phone-home software).
I've no idea why this happens. The ClientSpawn(gentity_t *ent) method in g_client.c isn't called. The system crashes before that.

Any ideas?

I'm desperate :-( I don't know how to go on.



Title: Re: placing bots dynamically
Post by: next_ghost on October 05, 2007, 12:15:00 PM
...

One line of code is not enough.


Title: Re: placing bots dynamically
Post by: iLeft.bye on October 05, 2007, 09:44:09 PM
...

One line of code is not enough.
search the forum maybe :D


you may check the class_f command in tremulous
afaict it removes player places it again in the same location as a different class
(checks if there is available space etc) src/g_cmds.c I believe

but you may first want to familiarize yourself with the q3 code
read some tutorials etc


Title: [SOLVED]: placing bots dynamically
Post by: hc on October 09, 2007, 07:22:45 AM
Hi guys!

It's done :-)

In g_combat.c I've created a new method:
Code:
/*
===================
GetPositionOfDeath
===================
Get the position where the bot has died and put it to the g_local.h to use it for the respawn.
*/
void GetPositionOfDeath (gentity_t *self, gentity_t *attacker)
{
// Did a teammate kill us or did we kill ourselves?
if ( (OnSameTeam( self, attacker ) && self != attacker )|| self == attacker )
{
return;
}

// Copy Vector to g_local.h to use it there for the respawn.
VectorCopy(self->r.currentOrigin, self->client->pers.positionOfDeath);
VectorCopy(self->r.currentAngles, self->client->pers.angleOfDeath);

}

This method is called by player_die():
Code:
if ( client->sess.spectatorClient == self->s.number ) {
Cmd_Score_f( g_entities + i );
}
}

// Here is it
        GetPositionOfDeath (self, attacker);

self->takedamage = qtrue; // can still be gibbed

self->s.weapon = WP_NONE;
self->s.powerups = 0;
self->r.contents = CONTENTS_CORPSE;

OK, also you need the following extention of the clientPersistant_t in g_local.h:
Code:
// Position of Death
vec3_t positionOfDeath;
vec3_t angleOfDeath;

And finally you have to alter ClientSpawn() in g_client.c like this:
Code:
       // health will count down towards max_health
ent->health = client->ps.stats[STAT_HEALTH] = client->ps.stats[STAT_MAX_HEALTH] + 25;

        // If you want to do it also with the angles, then you have to do it the same way
if ( client->pers.positionOfDeath[0] != 0 && client->pers.positionOfDeath[1] != 0 && client->pers.positionOfDeath[2] != 0 )
{
// Copy the new position to the spawn-origin to use spawn-origin for the other functions.
VectorCopy(client->pers.positionOfDeath, spawn_origin);

G_SetOrigin( ent, spawn_origin);
VectorCopy( spawn_origin, client->ps.origin );
}
else
{
G_SetOrigin( ent, spawn_origin );
VectorCopy( spawn_origin, client->ps.origin );
}


// the respawned flag will be cleared after the attack and jump keys come up
client->ps.pm_flags |= PMF_RESPAWNED;

It works! :-)
I don't know if it's the best solution and I just have done a short gameplay test, but so far it works.

Some problems are still there (dividing player and bot etc.) but I'm glad it's done so far.

Thanks to all of you for your help!

hc


Title: Re: [SOLVED]: placing bots dynamically
Post by: pulchr on October 09, 2007, 09:07:52 AM
just a question - what's it for? :)


Title: Re: [SOLVED]: placing bots dynamically
Post by: hc on October 10, 2007, 01:23:59 AM
Hi pulchr!

As I mentioned before (see above), it should become a training for the peripheral vision of handicaped persons.
It's still a lot to do (vector math etc) but the first problem is solved now :-)


Title: Re: [SOLVED]: placing bots dynamically
Post by: pulchr on October 10, 2007, 04:38:22 AM
sounds interesting :) good luck


Title: Re: [SOLVED]: placing bots dynamically
Post by: hc on October 10, 2007, 08:42:53 AM
Thank you, pulchr! (http://openarena.ws/board/Smileys/default/smiley.gif)