Pages: [1]
  Print  
Author Topic: [SOLVED]: placing bots dynamically  (Read 10492 times)
hc
Nub


Cakes 0
Posts: 10


« 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
« Last Edit: October 09, 2007, 07:24:57 am by hc » Logged
sago007
Posts a lot
*

Cakes 62
Posts: 1664


Open Arena Developer


WWW
« Reply #1 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.
Logged

There are nothing offending in my posts.
De@thByBl@st
Half-Nub


Cakes 0
Posts: 67


« Reply #2 on: September 26, 2007, 01:55:15 pm »

I thought DM spawns were already somewhat random in nature, what am I missing here?
Logged
sago007
Posts a lot
*

Cakes 62
Posts: 1664


Open Arena Developer


WWW
« Reply #3 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.
Logged

There are nothing offending in my posts.
hc
Nub


Cakes 0
Posts: 10


« Reply #4 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! :-)
Logged
iLeft.bye
Member


Cakes 1
Posts: 188



« Reply #5 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
Logged
hc
Nub


Cakes 0
Posts: 10


« Reply #6 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!

Logged
hc
Nub


Cakes 0
Posts: 10


« Reply #7 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.... :-/

Logged
sago007
Posts a lot
*

Cakes 62
Posts: 1664


Open Arena Developer


WWW
« Reply #8 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.
Logged

There are nothing offending in my posts.
hc
Nub


Cakes 0
Posts: 10


« Reply #9 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!

Logged
hc
Nub


Cakes 0
Posts: 10


« Reply #10 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.

Logged
next_ghost
Half-Nub


Cakes 0
Posts: 76


« Reply #11 on: October 05, 2007, 12:15:00 pm »

...

One line of code is not enough.
Logged
iLeft.bye
Member


Cakes 1
Posts: 188



« Reply #12 on: October 05, 2007, 09:44:09 pm »

...

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


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
« Last Edit: October 05, 2007, 09:49:16 pm by fork » Logged
hc
Nub


Cakes 0
Posts: 10


« Reply #13 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
« Last Edit: October 09, 2007, 07:24:35 am by hc » Logged
pulchr
Member


Cakes 34
Posts: 626



WWW
« Reply #14 on: October 09, 2007, 09:07:52 am »

just a question - what's it for? Smiley
Logged
hc
Nub


Cakes 0
Posts: 10


« Reply #15 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 :-)
Logged
pulchr
Member


Cakes 34
Posts: 626



WWW
« Reply #16 on: October 10, 2007, 04:38:22 am »

sounds interesting Smiley good luck
Logged
hc
Nub


Cakes 0
Posts: 10


« Reply #17 on: October 10, 2007, 08:42:53 am »

Thank you, pulchr!

Logged
Pages: [1]
  Print  
 
Jump to: