Added bot code.

This commit is contained in:
Justin Marshall
2026-05-19 18:34:55 -07:00
parent b97127f038
commit af56d4bfeb
166 changed files with 22251 additions and 297 deletions
+12 -12
View File
@@ -23,7 +23,7 @@ rvmBot::rvmBot()
{
//bs.action = NULL;
hasSpawned = false;
gameLocal.RegisterBot( this );
//gameLocal.RegisterBot( this );
}
/*
@@ -33,7 +33,7 @@ rvmBot::~rvmBot
*/
rvmBot::~rvmBot()
{
gameLocal.UnRegisterBot( this );
//gameLocal.UnRegisterBot( this );
}
/*
@@ -71,12 +71,12 @@ void rvmBot::BotUpdateInventory( void )
bs.inventory[INVENTORY_PLASMAGUN] = HasWeapon( weapon_plasmagun );
bs.inventory[INVENTORY_BFG10K] = 0;
bs.inventory[INVENTORY_GRAPPLINGHOOK] = 0;
bs.inventory[INVENTORY_SHELLS] = inventory.ammo[idWeapon::GetAmmoNumForName( "ammo_shells" )].Get();
bs.inventory[INVENTORY_BULLETS] = inventory.ammo[idWeapon::GetAmmoNumForName( "ammo_clip" )].Get();
bs.inventory[INVENTORY_SHELLS] = inventory.ammo[idWeapon::GetAmmoNumForName( "ammo_shells" )];
bs.inventory[INVENTORY_BULLETS] = inventory.ammo[idWeapon::GetAmmoNumForName( "ammo_clip" )];
bs.inventory[INVENTORY_GRENADES] = 0;
bs.inventory[INVENTORY_CELLS] = inventory.ammo[idWeapon::GetAmmoNumForName( "ammo_cells" )].Get();
bs.inventory[INVENTORY_CELLS] = inventory.ammo[idWeapon::GetAmmoNumForName( "ammo_cells" )];
bs.inventory[INVENTORY_LIGHTNINGAMMO] = 0;
bs.inventory[INVENTORY_ROCKETS] = inventory.ammo[idWeapon::GetAmmoNumForName( "ammo_rockets" )].Get();
bs.inventory[INVENTORY_ROCKETS] = inventory.ammo[idWeapon::GetAmmoNumForName( "ammo_rockets" )];
bs.inventory[INVENTORY_SLUGS] = 0;
bs.inventory[INVENTORY_BFGAMMO] = 0;
bs.inventory[INVENTORY_HEALTH] = health;
@@ -108,7 +108,7 @@ void rvmBot::Spawn( void )
idPlayer::Spawn();
if( common->IsServer() )
if( gameLocal.isServer )
{
weapon_machinegun = SlotForWeapon( "weapon_machinegun" );
weapon_shotgun = SlotForWeapon( "weapon_shotgun" );
@@ -120,7 +120,7 @@ void rvmBot::Spawn( void )
WP_PLASMAGUN = weapon_plasmagun;
WP_ROCKET_LAUNCHER = weapon_rocketlauncher;
botName = spawnArgs.GetString( "botname" );
botName = "dark";// spawnArgs.GetString("botname");
aas = gameLocal.GetBotAAS();
if( aas == NULL )
@@ -209,7 +209,7 @@ void rvmBot::SpawnToPoint( const idVec3& spawn_origin, const idAngles& spawn_ang
{
idPlayer::SpawnToPoint( spawn_origin, spawn_angles );
if( common->IsServer() )
if( gameLocal.isServer )
{
bs.ltg_time = 0;
stateThread.SetState("state_SeekLTG");
@@ -388,7 +388,7 @@ void rvmBot::Think( void )
return;
}
if( common->IsServer() )
if( gameLocal.isServer )
{
ServerThink();
@@ -400,10 +400,10 @@ void rvmBot::Think( void )
color = idVec4(1, 0, 0, 1);
idBounds bounds = idBounds( idVec3( -10, -10, -10 ), idVec3( 10, 10, 10 ) );
common->RW()->DebugBounds( color, bounds, GetOrigin() );
gameRenderWorld->DebugBounds( color, bounds, GetOrigin() );
idMat3 axis = viewAngles.ToMat3();
common->RW()->DrawTextA(stateThread.GetState()->state.c_str(), GetOrigin(), 1.0f, color, axis);
gameRenderWorld->DrawTextA(stateThread.GetState()->state.c_str(), GetOrigin(), 1.0f, color, axis);
}
}
+6 -1
View File
@@ -848,9 +848,14 @@ public:
virtual void InflictedDamageEvent(idEntity* target) override;
virtual void StateThreadChanged(void) override;
virtual bool IsBot(void) override
{
return true;
}
void SetEnemy( idPlayer* player, idVec3 origin );
void BotInputFrame( idUserCmdMgr& cmdMgr );
void BotInputFrame( void );
void Bot_ResetUcmd( usercmd_t& ucmd );
static void PresenceTypeBoundingBox( int presencetype, idVec3& mins, idVec3& maxs );
+37 -10
View File
@@ -1135,19 +1135,46 @@ int rvmBot::BotNearbyGoal( bot_state_t* bs, int tfl, bot_goal_t* ltg, float rang
rvmBot::BotGetRandomPointNearPosition
=======================
*/
void rvmBot::BotGetRandomPointNearPosition( idVec3 point, idVec3& randomPoint, float radius )
{
idAAS* aas = gameLocal.GetBotAAS();
idAASFile* file = aas->GetAASFile();
void rvmBot::BotGetRandomPointNearPosition(const idVec3 point, idVec3& randomPoint, float radius) {
randomPoint = point;
int areaNum = aas->PointAreaNum(point);
const aasArea_t& area = file->GetArea(areaNum);
int firstEdge = area.firstEdge;
int i = rvRandom::irand(0, area.numEdges);
idAAS* aas = this->aas;
if (!aas) {
return;
}
const aasEdge_t &edge = file->GetEdge(abs(file->GetEdgeIndex(firstEdge + i)));
const int areaNum = aas->PointAreaNum(point);
if (areaNum <= 0) {
return;
}
randomPoint = file->GetVertex(edge.vertexNum[0]);
if (radius <= 0.0f) {
randomPoint = aas->AreaCenter(areaNum);
aas->PushPointIntoAreaNum(areaNum, randomPoint);
return;
}
for (int i = 0; i < 16; i++) {
const float angle = gameLocal.random.RandomFloat() * idMath::TWO_PI;
const float dist = gameLocal.random.RandomFloat() * radius;
idVec3 testPoint = point;
testPoint.x += idMath::Cos(angle) * dist;
testPoint.y += idMath::Sin(angle) * dist;
const int testAreaNum = aas->PointAreaNum(testPoint);
if (testAreaNum <= 0) {
continue;
}
aas->PushPointIntoAreaNum(testAreaNum, testPoint);
randomPoint = testPoint;
return;
}
randomPoint = aas->AreaCenter(areaNum);
aas->PushPointIntoAreaNum(areaNum, randomPoint);
}
/*
+2 -2
View File
@@ -83,8 +83,8 @@ stateResult_t rvmBot::state_Chase(stateParms_t* parms)
// goal.areanum = bs.lastenemyareanum;
VectorCopy( bs.lastenemyorigin, goal.origin );
goal.mins = idMath::CreateVector( -8, -8, -8 );
goal.maxs = idMath::CreateVector( 8, 8, 8 );
goal.mins = idVec3( -8, -8, -8 );
goal.maxs = idVec3( 8, 8, 8 );
// jmarshall - goal origin is last visible position
{
+5 -4
View File
@@ -5,6 +5,7 @@
#pragma hdrstop
#include "../Game_local.h"
#include "../../../engine/framework/UsercmdGen.h"
/*
==============
@@ -110,8 +111,8 @@ void rvmBot::BotInputToUserCommand(bot_input_t* bi, usercmd_t* ucmd, int time)
}
//jump/moveup
if (bi->actionflags & ACTION_JUMP)
ucmd->buttons |= BUTTON_JUMP;
//if (bi->actionflags & ACTION_JUMP)
// ucmd->buttons |= BUTTON_JUMP;
// ucmd->upmove += 127;
//
@@ -149,12 +150,12 @@ void rvmBot::Bot_ResetUcmd( usercmd_t& ucmd )
rvmBot::BotInputFrame
========================
*/
void rvmBot::BotInputFrame( idUserCmdMgr& cmdMgr )
void rvmBot::BotInputFrame( void )
{
usercmd_t botcmd = { }; //(usercmd_t&)cmdMgr.GetUserCmdForPlayer(entityNumber); // gameLocal.usercmds[entityNumber];
Bot_ResetUcmd( botcmd );
BotInputToUserCommand( &bs.botinput, &botcmd, gameLocal.time );
cmdMgr.PutUserCmdForPlayer( entityNumber, botcmd );
networkSystem->ServerSetBotUserCommand(entityNumber, gameLocal.framenum, botcmd);
}