Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New waypoints #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ sandbot_windows_exports.txt

linux_exports.txt
sandbot_linux_exports.txt
*.so
17 changes: 5 additions & 12 deletions dlls/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,13 @@

CPP = g++

# gcc preprocessor flags
BASEFLAGS =

# gcc compiler flags - thanks RoboCop
# gcc flags - thanks RoboCop
OPTFLAGS = \
-m32 -Wall -Wextra \
-O2 -march=core2 -mfpmath=sse \
-fomit-frame-pointer -finline-functions -falign-loops=2 -falign-jumps=2 -falign-functions=2 \
-Wno-write-strings \
-Wno-missing-field-initializers \
-Wno-unknown-pragmas \
-Wno-attributes
-fomit-frame-pointer -finline-functions -falign-loops=2 -falign-jumps=2 -falign-functions=2

CPPFLAGS = ${BASEFLAGS} ${OPTFLAGS} -lstdc++ -lm -I../dlls -I../engine -I../common -I../pm_shared -I../metamod
CPPFLAGS = ${OPTFLAGS} -lstdc++ -lm -I../dlls -I../engine -I../common -I../pm_shared -I../metamod

OBJ = \
bot.o \
Expand All @@ -35,19 +28,19 @@ OBJ = \
bot_hunger.o \
dll.o \
engine.o \
foolsgoldsource.o \
game.o \
h_export.o \
linkfunc.o \
meta_api.o \
pseudomod.o \
util.o \
waypoint.o

# by default build sandbot.so in release mode
.DEFAULT_GOAL := sandbot.so

# if debug is requested add debug flags and build sandbot.so
# could have debug: BASEFLAGS += -DDEBUG as well but that would
# could have debug: OPTFLAGS += -DDEBUG as well but that would
# mean the symbols are from a build that is different to release
debug: OPTFLAGS += -g
debug: sandbot.so
Expand Down
101 changes: 71 additions & 30 deletions dlls/bot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
#include "h_export.h"

bot_player_t *pBotData = nullptr;
bot_t **pBots = nullptr; // [MAX_PLAYERS];
bot_t **pBots = nullptr; // [Game::MAX_PLAYERS];

bool b_observer_mode = false;

bot_player_t g_valveBots[MAX_PLAYERS] =
bot_player_t g_valveBots[Game::MAX_PLAYERS] =
{
{"Kelly", "barney", false},
{"Ted", "gina", false},
Expand Down Expand Up @@ -60,7 +60,7 @@ bot_player_t g_valveBots[MAX_PLAYERS] =
{"Harry", "gina", false}
};

bot_player_t g_gearboxBots[MAX_PLAYERS] =
bot_player_t g_gearboxBots[Game::MAX_PLAYERS] =
{
{"Randy", "barney", false},
{"Brian", "beret", false},
Expand Down Expand Up @@ -96,13 +96,13 @@ bot_player_t g_gearboxBots[MAX_PLAYERS] =
{"RichardC", "otis", false}
};

bot_player_t g_cstrikeBots[MAX_PLAYERS] =
bot_player_t g_cstrikeBots[Game::MAX_PLAYERS] =
{
{"Minh", NULL, false},
{"Jesse", NULL, false}
};

bot_player_t g_dodBots[MAX_PLAYERS] =
bot_player_t g_dodBots[Game::MAX_PLAYERS] =
{
{"Matt", NULL, false}, // mugsy
{"John", NULL, false}, // pickitup
Expand Down Expand Up @@ -138,7 +138,7 @@ bot_player_t g_dodBots[MAX_PLAYERS] =
{"Unknown8", NULL, false}, // Kamikazi
};

bot_player_t g_gunmanBots[MAX_PLAYERS] =
bot_player_t g_gunmanBots[Game::MAX_PLAYERS] =
{
{"Herb", "bandit", false}, // BoneWolf
{"Steven", "general", false}, // Wipeoot
Expand Down Expand Up @@ -174,7 +174,7 @@ bot_player_t g_gunmanBots[MAX_PLAYERS] =
{"Robin", "general", false}
};

bot_player_t g_nsBots[MAX_PLAYERS] =
bot_player_t g_nsBots[Game::MAX_PLAYERS] =
{
{"Charlie", NULL, false},
{"Jon", NULL, false},
Expand Down Expand Up @@ -210,7 +210,7 @@ bot_player_t g_nsBots[MAX_PLAYERS] =
{"Nick", NULL, false}
};

bot_player_t g_hungerBots[MAX_PLAYERS] =
bot_player_t g_hungerBots[Game::MAX_PLAYERS] =
{
{"Bill", "civie", false},
{"Dave", "dave", false},
Expand Down Expand Up @@ -246,7 +246,7 @@ bot_player_t g_hungerBots[MAX_PLAYERS] =
{"Ben", "zork", false}
};

bot_player_t g_shipBots[MAX_PLAYERS] =
bot_player_t g_shipBots[Game::MAX_PLAYERS] =
{
{"Chris", NULL, false},
{"Ailsa", NULL, false},
Expand Down Expand Up @@ -288,8 +288,6 @@ float pause_frequency[5] = {4, 7, 10, 15, 20};
float pause_time[5][2] = {{0.2f, 0.5f}, {0.5f, 1.0f}, {0.7f, 1.3f}, {1.0f, 1.7f}, {1.2f, 2.0f}};

// TheFatal's method for calculating the msecval
extern int msecnum;
extern float msecdel;
extern float msecval;

int GetBotCount()
Expand Down Expand Up @@ -335,7 +333,7 @@ void KickBot( const int iIndex )

void KickAllBots()
{
for( unsigned int index = 0; index < MAX_PLAYERS; index++ )
for( unsigned int index = 0; index < Game::MAX_PLAYERS; index++ )
{
KickBot( index );
}
Expand All @@ -345,14 +343,14 @@ void CleanupGameAndBots()
{
if( pBotData )
{
for( int i = 0; i < MAX_PLAYERS; i++ )
for( int i = 0; i < Game::MAX_PLAYERS; i++ )
{
pBotData[i].bIsUsed = false;
}
}
if( pBots )
{
for( int i = 0; i < MAX_PLAYERS; i++ )
for( int i = 0; i < Game::MAX_PLAYERS; i++ )
{
delete pBots[i];
pBots[i] = nullptr;
Expand Down Expand Up @@ -493,7 +491,7 @@ void BotCreate( edict_t *pPlayer, const char *arg1, const char *arg2, const char
iIndex++;

// loop around
if( iIndex == MAX_PLAYERS )
if( iIndex == Game::MAX_PLAYERS )
{
iIndex = 0;
}
Expand Down Expand Up @@ -545,12 +543,12 @@ void BotCreate( edict_t *pPlayer, const char *arg1, const char *arg2, const char
pBotEdict->v.frags = 0;

index = 0;
while ((index < MAX_PLAYERS) && (pBots[index]->is_used))
while ((index < Game::MAX_PLAYERS) && (pBots[index]->is_used))
{
index++;
}

if (index == MAX_PLAYERS)
if (index == Game::MAX_PLAYERS)
{
ClientPrint( pPlayer, HUD_PRINTNOTIFY, "Can't create bot!\n");
return;
Expand Down Expand Up @@ -1283,20 +1281,21 @@ void BotThink( bot_t *pBot )
else
pitch_degrees = 0.0;

// turn towards ideal_yaw by yaw_speed degrees
yaw_degrees = BotChangeYaw( pBot, pEdict->v.yaw_speed );
// turn towards ideal_yaw by yaw_speed degrees
yaw_degrees = BotChangeYaw( pBot, pEdict->v.yaw_speed );

if ((pitch_degrees >= pEdict->v.pitch_speed) || (yaw_degrees >= pEdict->v.yaw_speed))
{
if ((pitch_degrees >= pEdict->v.pitch_speed) || (yaw_degrees >= pEdict->v.yaw_speed))
{
// don't move while turning a lot
pBot->SetSpeed( 0.0 );
}
else if ((pitch_degrees >= 10) || (yaw_degrees >= 10)) // turning more than 10 degrees?
{
pBot->SetSpeed( pBot->GetSpeed() / 4.0 ); // slow down while turning
}
else // else handle movement related actions...
{
}
else if ((pitch_degrees >= 10) || (yaw_degrees >= 10)) // turning more than 10 degrees?
{
// slow down while turning
pBot->SetSpeed( pBot->GetSpeed() / 4.0 );
}
else // else handle movement related actions...
{
if( pBot->CanShoot() && pBot->ShouldSeekEnemy() )
{
// if it's CTF, prioritise looking for the flag
Expand Down Expand Up @@ -1812,6 +1811,9 @@ bot_t::bot_t()
// TODO: needed? already set in BotThink - not BotCreate?
this->name[0] = '\0';
this->pEdict = nullptr;

this->iGoalIndex = 0;
this->bCapturing = false;
}

bot_t::~bot_t()
Expand All @@ -1820,6 +1822,8 @@ bot_t::~bot_t()

void bot_t::OnSpawn()
{
this->iGoalIndex = 0;
this->bCapturing = false;
}

void bot_t::Join()
Expand Down Expand Up @@ -1859,6 +1863,33 @@ void bot_t::Think()
{
// TODO: move all of BotThink into here eventually
this->PreThink();

// TODO: possibly this will trigger before the bot is touching the capture point? shouldn't
// though because bCapturing is only true when the bot is close enough to the waypoint
// if the bot is capturing, and is at a capture point, and it's a point that should be captured
if( this->IsCapturing() )
{
this->SetSpeed( 0.0 );

// TODO: this is very rough - probably something is set in pev if the bot is
// on or near a dod_control_point/trigger_ctfgeneric - should check if it's a brush entity...
if( DistanceToNearest( this->pEdict->v.origin, "dod_control_point" ) > 200.0 || DistanceToNearest( this->pEdict->v.origin, "trigger_ctfgeneric" ) > 200.0 )
{
UTIL_LogDPrintf( "too far from capture point while capturing; resetting\n" );
this->SetIsCapturing( false );
this->SetSpeed( this->GetMaxSpeed() );
}
}

// TODO: waypoint goal changes once it's capturing?
// if the current waypoint is a capture point and it is now captured
if( this->IsCapturing() && ShouldSkip( this->pEdict, this->iGoalIndex ) )
{
UTIL_LogDPrintf( "leaving waypoint\n" );
this->SetIsCapturing( false );
this->SetSpeed( this->GetMaxSpeed() );
}

this->PostThink();
}

Expand Down Expand Up @@ -2268,7 +2299,7 @@ bool bot_t::IsDead()
return this->pEdict->v.health < 1 || this->pEdict->v.deadflag != DEAD_NO;
}

bool bot_t::IsUnderWater()
bool bot_t::IsUnderWater() const
{
return this->pEdict->v.waterlevel == 3;
}
Expand All @@ -2278,6 +2309,11 @@ bool bot_t::IsSniper()
return false;
}

bool bot_t::IsCapturing() const
{
return this->bCapturing;
}

void bot_t::UpdateSounds()
{
edict_t *pPlayer;
Expand Down Expand Up @@ -2332,7 +2368,7 @@ float bot_t::GetWaypointRadius()
return fRadius;
}

bool bot_t::BaseCanUseWeapon()
bool bot_t::BaseCanUseWeapon() const
{
return this->HasEnemy();
}
Expand Down Expand Up @@ -2396,3 +2432,8 @@ bool bot_t::ShouldCapturePoint( edict_t * pControlPoint )
{
return false;
}

void bot_t::SetIsCapturing( const bool bIsCapturing )
{
this->bCapturing = bIsCapturing;
}
Loading