Added bot source files (oops)
Removed old project file
This commit is contained in:
parent
4ca5223c51
commit
6b3504c560
5 changed files with 757 additions and 121 deletions
|
@ -1,121 +0,0 @@
|
|||
<project version="Crimson Editor 3.60">
|
||||
<category name="Client" expanded="yes">
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Client\Defs.h" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Client\Draw.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Client\Entities.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Client\Event.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Client\HUD.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Client\HUDCrosshair.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Client\HUDOrbituaries.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Client\HUDScope.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Client\HUDWeaponSelect.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Client\Init.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Client\Nightvision.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Client\Overview.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Client\Player.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Client\progs.src" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Client\Sound.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Client\VGUI.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Client\VGUI.h" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Client\VGUIBuyMenu.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Client\VGUIMOTD.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Client\VGUIObjects.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Client\VGUIRadio.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Client\VGUIScoreboard.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Client\VGUISpectator.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Client\VGUITeamSelect.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Client\View.c" />
|
||||
</category>
|
||||
<category name="Server" expanded="yes">
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Server\AmbientSound.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Server\Ammo.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Server\ArmouryEntity.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Server\Client.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Server\Damage.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Server\Defs.h" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Server\EntHostage.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Server\Entities.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Server\EnvObjects.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Server\Footsteps.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Server\FuncBombTarget.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Server\FuncBreakable.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Server\FuncButton.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Server\FuncBuyZone.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Server\FuncDoor.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Server\FuncDoorRotating.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Server\FuncEscapeZone.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Server\FuncHostageRescue.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Server\FuncLadder.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Server\FuncPushable.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Server\FuncVehicle.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Server\FuncVIPSafetyZone.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Server\Input.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Server\Light.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Server\Main.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Server\Money.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Server\PhysicsMove.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Server\Player.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Server\progs.src" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Server\Rules.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Server\Spawn.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Server\Timer.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Server\TraceAttack.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Server\Triggers.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Server\Vox.c" />
|
||||
</category>
|
||||
<category name="Menu" expanded="no">
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Menu\Defs.h" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Menu\Draw.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Menu\Header.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Menu\Init.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Menu\Input.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Menu\MenuConfiguration.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Menu\MenuMain.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Menu\MenuMultiplayer.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Menu\Objects.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Menu\progs.src" />
|
||||
</category>
|
||||
<category name="Shared" expanded="yes">
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Shared\Animations.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Shared\BaseGun.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Shared\BaseMelee.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Shared\Effects.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Shared\Equipment.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Shared\Radio.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Shared\WeaponAK47.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Shared\WeaponAUG.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Shared\WeaponAWP.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Shared\WeaponC4Bomb.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Shared\WeaponDeagle.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Shared\WeaponElites.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Shared\WeaponFiveSeven.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Shared\WeaponFlashbang.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Shared\WeaponG3SG1.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Shared\WeaponGlock18.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Shared\WeaponHEGrenade.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Shared\WeaponKnife.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Shared\WeaponM3.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Shared\WeaponM4A1.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Shared\WeaponMac10.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Shared\WeaponMP5.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Shared\WeaponP228.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Shared\WeaponP90.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Shared\WeaponPara.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Shared\Weapons.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Shared\WeaponScout.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Shared\WeaponSG550.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Shared\WeaponSG552.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Shared\WeaponSmokeGrenade.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Shared\WeaponTMP.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Shared\WeaponUMP45.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Shared\WeaponUSP45.c" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Shared\WeaponXM1014.c" />
|
||||
</category>
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Builtins.h" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Globals.h" />
|
||||
<localfile path="C:\cygwin\home\User\FreeCS\Source\Math.h" />
|
||||
</project>
|
||||
|
||||
<workspace version="Crimson Editor 3.60">
|
||||
</workspace>
|
||||
|
327
Source/Server/Bot/Bot.c
Normal file
327
Source/Server/Bot/Bot.c
Normal file
|
@ -0,0 +1,327 @@
|
|||
/*
|
||||
* Copyright (c) 2015-2018
|
||||
* Marco Hladik All rights reserved.
|
||||
*
|
||||
* This file is part of The Wastes's Source-Code.
|
||||
*
|
||||
* The Wastes's Source-Code is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* The Wastes's Source-Code is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with The Wastes's Source-Code. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
float bot_skill[] = {
|
||||
2.0f,
|
||||
1.75f,
|
||||
1.5f,
|
||||
1.0f,
|
||||
0.5,
|
||||
0.25f,
|
||||
0.0f
|
||||
};
|
||||
|
||||
/*
|
||||
=================
|
||||
Bot_AutoAdd
|
||||
=================
|
||||
*/
|
||||
void Bot_AutoAdd( void ) {
|
||||
if ( self.delay == TRUE ) {
|
||||
CBot bot;
|
||||
bot = (CBot)spawnclient();
|
||||
if ( bot ) {
|
||||
bot.CreateRandom();
|
||||
self.health--;
|
||||
if ( self.health ) {
|
||||
self.nextthink = time + 0.25f;
|
||||
} else {
|
||||
remove( self );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Let's kill the bots that were here before, before they have not been initialized.
|
||||
for ( entity eFind = world; ( eFind = find( eFind, classname, "player" ) ); ) {
|
||||
if ( clienttype( eFind ) == CLIENTTYPE_BOT ) {
|
||||
dropclient( eFind );
|
||||
}
|
||||
}
|
||||
|
||||
// Let's add new bots.
|
||||
float bots = autocvar_bot_autoadd;
|
||||
if ( bots >= cvar( "sv_playerslots" ) ) {
|
||||
bots = cvar( "sv_playerslots" ) - 1;
|
||||
}
|
||||
|
||||
if ( !bots ) {
|
||||
remove( self );
|
||||
return;
|
||||
}
|
||||
|
||||
self.delay = TRUE;
|
||||
self.health = bots;
|
||||
self.nextthink = time + 0.25f;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
Bot_Init
|
||||
=================
|
||||
*/
|
||||
void Bot_Init( void )
|
||||
{
|
||||
entity eBotAdder = spawn();
|
||||
eBotAdder.think = Bot_AutoAdd;
|
||||
eBotAdder.nextthink = time + 0.25f;
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
CBot::PickEnemy
|
||||
=================
|
||||
*/
|
||||
void CBot::PickEnemy( void )
|
||||
{
|
||||
if ( huntenemy && huntenemy.health > 0 ){
|
||||
return;
|
||||
}
|
||||
|
||||
huntenemy = world;
|
||||
float bestdist = 99999999;
|
||||
|
||||
for (entity e = world; (e = find(e, ::classname, "player")); ) {
|
||||
if ( e.team == self.team ) {
|
||||
continue;
|
||||
}
|
||||
if ( e.flags & FL_NOTARGET ) {
|
||||
continue; //cheat.
|
||||
}
|
||||
if ( e == this ) {
|
||||
continue; //no self-harm
|
||||
}
|
||||
if ( e.health > 0 ) {
|
||||
float dist = vlen(e.origin - origin);
|
||||
if ( dist < bestdist ) {
|
||||
traceline(origin+view_ofs, e.origin, TRUE, this);
|
||||
if (trace_ent == e || trace_fraction == 1) {
|
||||
bestdist = dist;
|
||||
huntenemy = e;
|
||||
reflextime = time;
|
||||
reflextime += bot_skill[ bound( 0, autocvar_bot_skill, bot_skill.length - 1 ) ];
|
||||
reflextime += ( random() * 0.25f );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void Bot_RouteCB(entity ent, vector dest, int numnodes, nodeslist_t *nodelist)
|
||||
{
|
||||
CBot player = (CBot)ent;
|
||||
player.nodes = numnodes;
|
||||
player.cur_node = numnodes - 1;
|
||||
player.route = nodelist;
|
||||
|
||||
dprint( "Bot: Route calculated.\n" );
|
||||
dprint( sprintf( "Bot: # of nodes: %i\n", numnodes ) );
|
||||
dprint( sprintf( "Bot: # current node: %i\n", player.cur_node ) );
|
||||
dprint( sprintf( "Bot: # endpos: %v\n", dest ) );
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
CBot::RunAI
|
||||
=================
|
||||
*/
|
||||
void CBot::RunAI( void )
|
||||
{
|
||||
if ( team <= 0 ) {
|
||||
bprint( "Selecting team\n" );
|
||||
CSEv_GamePlayerSpawn_f( floor( random( 1, 8 ) ));
|
||||
|
||||
// If we couldn't spawn, don't even try doing stuff
|
||||
if ( health <= 0 ) {
|
||||
return;
|
||||
} else {
|
||||
if ( route ) {
|
||||
nodes = 0;
|
||||
memfree( route );
|
||||
huntenemy = __NULL__;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( autocvar_bot_ai == FALSE ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( nodes ) {
|
||||
PickEnemy();
|
||||
}
|
||||
|
||||
input_buttons = 0;
|
||||
|
||||
if ( !nodes ) {
|
||||
route_calculate( this, Route_SelectDestination(this), 0, Bot_RouteCB );
|
||||
bprint( "Route: Calculating first bot route\n" );
|
||||
}
|
||||
|
||||
// Route might have been not been processed
|
||||
if ( !nodes ) {
|
||||
bprint( "Route: NO NODES\n" );
|
||||
return;
|
||||
}
|
||||
|
||||
float dist = floor( vlen( route[cur_node].dest - origin ) );
|
||||
|
||||
if ( dist < 64 ) {
|
||||
bprint( "Route: Reached node.\n" );
|
||||
cur_node--;
|
||||
}
|
||||
|
||||
// We haven't gotten anywhere, start
|
||||
if ( dist == lastdist ) {
|
||||
node_giveup += frametime;
|
||||
}
|
||||
|
||||
if ( node_giveup > 2.5f ) {
|
||||
bprint( "Route: Giving up route\n" );
|
||||
cur_node = -1;
|
||||
node_giveup = 0.0f;
|
||||
} else if ( node_giveup > 1.0f ) {
|
||||
makevectors( angles );
|
||||
tracebox( origin + '0 0 18', mins, maxs, origin + '0 0 18' + ( v_forward * 32 ), FALSE, this );
|
||||
if ( trace_fraction < 1.0f && flags & FL_ONGROUND ) {
|
||||
tracebox( origin + '0 0 64', mins, maxs, origin + '0 0 64' + ( v_forward * 32 ), FALSE, this );
|
||||
if ( trace_fraction == 1.0f ) {
|
||||
input_movevalues_z = 200;
|
||||
} else {
|
||||
tracebox(origin-'0 0 18', VEC_CHULL_MIN, VEC_CHULL_MAX, origin-'0 0 18'+(v_forward * 16), FALSE, this);
|
||||
if ( trace_fraction == 1.0f ) {
|
||||
input_movevalues_z = -200;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( distcache < time ) {
|
||||
lastdist = dist;
|
||||
distcache = time + 2.0f;
|
||||
}
|
||||
// We haven't gotten anywhere, end
|
||||
|
||||
if ( cur_node < 0 ) {
|
||||
bprint( "Route: Calculating new bot route\n" );
|
||||
nodes = 0;
|
||||
memfree( route );
|
||||
route_calculate( this, Route_SelectDestination(this), 0, Bot_RouteCB );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( huntenemy != __NULL__ ) {
|
||||
int enemyvisible;
|
||||
traceline( origin + view_ofs, huntenemy.origin, TRUE, this);
|
||||
enemyvisible = ( trace_ent == huntenemy || trace_fraction == 1.0f );
|
||||
|
||||
if ( enemyvisible ) {
|
||||
angles = vectoangles( huntenemy.origin - origin );
|
||||
input_angles = angles;
|
||||
input_movevalues_x = 80;
|
||||
|
||||
if ( !iAttackMode ) {
|
||||
input_buttons |= INPUT_BUTTON0; // Attack
|
||||
}
|
||||
iAttackMode = 1 - iAttackMode;
|
||||
} else {
|
||||
nodes = 0;
|
||||
memfree( route );
|
||||
route_calculate( this, huntenemy.origin, 0, Bot_RouteCB );
|
||||
huntenemy = __NULL__;
|
||||
}
|
||||
} else if ( nodes ) {
|
||||
/*
|
||||
if ( route[cur_node].linkflags & WP_JUMP && pmove_flags & PM_ONGROUND ) {
|
||||
dprint( "Bot: JUMP!\n" );
|
||||
input_movevalues_z = 200;
|
||||
}*/
|
||||
angles = vectoangles( route[cur_node].dest - origin );
|
||||
input_angles = angles;
|
||||
input_movevalues_x = 250;
|
||||
}
|
||||
|
||||
tracebox( origin + '0 0 18', mins, maxs, origin + '0 0 18' + ( v_forward * 32 ), FALSE, this );
|
||||
if ( trace_fraction < 1.0f && flags & FL_ONGROUND ) {
|
||||
tracebox( origin + '0 0 18', mins, maxs, origin + '0 0 18' + ( v_forward * 32 ) + v_right * 16, FALSE, this );
|
||||
if ( trace_fraction == 1.0f ) {
|
||||
input_movevalues_y = 200;
|
||||
} else {
|
||||
tracebox( origin + '0 0 18', mins, maxs, origin + '0 0 18' + ( v_forward * 32 ) + v_right * -16, FALSE, this );
|
||||
if ( trace_fraction == 1.0f ) {
|
||||
input_movevalues_y = -200;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if 1
|
||||
vector vNForward;
|
||||
float fLerpy = bound( 0.0f, 1.0f - ( frametime * 16 ), 1.0f );
|
||||
makevectors( input_angles );
|
||||
|
||||
vNForward = v_forward;
|
||||
makevectors( v_angle );
|
||||
vNForward_x = Math_Lerp( vNForward_x, v_forward_x, fLerpy );
|
||||
vNForward_y = Math_Lerp( vNForward_y, v_forward_y, fLerpy );
|
||||
vNForward_z = Math_Lerp( vNForward_z, v_forward_z, fLerpy );
|
||||
input_angles = vectoangles( vNForward );
|
||||
v_angle = input_angles;
|
||||
angles = input_angles;
|
||||
#else
|
||||
v_angle = input_angles;
|
||||
#endif
|
||||
button0 = input_buttons & INPUT_BUTTON0; //attack
|
||||
//.button1 was meant to be +use, but the bit was never assigned and mods used button1 as a free field. there still is no button 1.
|
||||
button2 = input_buttons & INPUT_BUTTON2; //jump
|
||||
button3 = input_buttons & INPUT_BUTTON3; //tertiary
|
||||
button4 = input_buttons & INPUT_BUTTON4; //reload
|
||||
button5 = input_buttons & INPUT_BUTTON5; //secondary
|
||||
button6 = input_buttons & INPUT_BUTTON6; //unused
|
||||
//button7 = input_buttons & INPUT_BUTTON7; //sprint
|
||||
movement = input_movevalues;
|
||||
|
||||
//runplayerphysics();
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
CBot::CreateRandom
|
||||
=================
|
||||
*/
|
||||
void CBot::CreateRandom( void ) {
|
||||
Create( iBots );
|
||||
iBots++;
|
||||
if ( iBots >= iBotTotal ) {
|
||||
iBots = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
CBot::Create
|
||||
=================
|
||||
*/
|
||||
void CBot::Create( int iBotID )
|
||||
{
|
||||
forceinfokey( self, "name", "Bot" );
|
||||
|
||||
iInGame = TRUE;
|
||||
|
||||
ClientConnect();
|
||||
PutClientInServer();
|
||||
}
|
56
Source/Server/Bot/Bot.h
Normal file
56
Source/Server/Bot/Bot.h
Normal file
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright (c) 2015-2018
|
||||
* Marco Hladik All rights reserved.
|
||||
*
|
||||
* This file is part of The Wastes's Source-Code.
|
||||
*
|
||||
* The Wastes's Source-Code is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* The Wastes's Source-Code is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with The Wastes's Source-Code. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
class CBot {
|
||||
entity huntenemy; //who we're trying to hunt
|
||||
float wiggletime;
|
||||
float wiggleside;
|
||||
int iAttackMode;
|
||||
float flSwitchDelay;
|
||||
float flRouteDelay;
|
||||
string chat_next;
|
||||
float chat_nexttime;
|
||||
float flJumpNext;
|
||||
|
||||
float reflextime;
|
||||
|
||||
int teamrole; //attack, defend, assist
|
||||
int iInGame; // so we can drop them in case they rejoin
|
||||
|
||||
int nodes;
|
||||
int cur_node;
|
||||
nodeslist_t *route;
|
||||
|
||||
// unstuckyness
|
||||
float node_giveup;
|
||||
float lastdist;
|
||||
float distcache;
|
||||
nonvirtual void( void ) RunAI;
|
||||
nonvirtual void( void ) CreateRandom;
|
||||
nonvirtual void( int iBotID ) Create;
|
||||
};
|
||||
|
||||
var int autocvar_bot_ai = TRUE;
|
||||
var float autocvar_bot_autoadd = 0;
|
||||
var int autocvar_bot_skill = 3;
|
||||
|
||||
int iBots, iBotTotal;
|
||||
void Bot_Init( void );
|
||||
|
81
Source/Server/Bot/Route.c
Normal file
81
Source/Server/Bot/Route.c
Normal file
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* Copyright (c) 2015-2018
|
||||
* Marco Hladik All rights reserved.
|
||||
*
|
||||
* This file is part of The Wastes's Source-Code.
|
||||
*
|
||||
* The Wastes's Source-Code is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* The Wastes's Source-Code is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with The Wastes's Source-Code. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Begin calculating a route.
|
||||
* The callback function will be called once the route has finished being calculated.
|
||||
* The route must be memfreed once it is no longer needed.
|
||||
* The route must be followed in reverse order (ie: the first node that must be reached
|
||||
* is at index numnodes-1). If no route is available then the callback will be called with no nodes.
|
||||
*/
|
||||
|
||||
vector Route_SelectDestination( CBot target )
|
||||
{
|
||||
entity dest = world;
|
||||
|
||||
// Need health!
|
||||
/* if ( target.health < 50 ) {
|
||||
entity temp;
|
||||
int bestrange = 999999;
|
||||
int range;
|
||||
for ( temp = world; ( temp = find( temp, classname, "ItemHealth" ) ); ) {
|
||||
range = vlen( temp.origin - target.origin );
|
||||
if ( ( range < bestrange ) && ( temp.solid = SOLID_TRIGGER ) ) {
|
||||
bestrange = range;
|
||||
dest = temp;
|
||||
}
|
||||
}
|
||||
|
||||
if ( dest ) {
|
||||
dprint( "Route: Going for health!" );
|
||||
return dest.origin + '0 0 32';
|
||||
}
|
||||
}
|
||||
|
||||
// Handle the whole flag situation
|
||||
if ( iGame == MODE_CTF ) {
|
||||
if ( target.flags & FL_HASFLAG ) {
|
||||
if ( target.team == world.team1 ) {
|
||||
dest = find( world, classname, "CTFFlag1" );
|
||||
} else {
|
||||
dest = find( world, classname, "CTFFlag2" );
|
||||
}
|
||||
return dest.origin + '0 0 32';
|
||||
} else {
|
||||
if ( target.team == world.team1 ) {
|
||||
dest = find( world, classname, "CTFFlag2" );
|
||||
} else {
|
||||
dest = find( world, classname, "CTFFlag1" );
|
||||
}
|
||||
|
||||
if ( dest.solid == SOLID_TRIGGER ) {
|
||||
return dest.origin + '0 0 32';
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
if ( target.team == TEAM_T ) {
|
||||
dest = Spawn_FindSpawnPoint( TEAM_CT );
|
||||
} else {
|
||||
dest = Spawn_FindSpawnPoint( TEAM_T );
|
||||
}
|
||||
|
||||
return dest.origin;
|
||||
}
|
293
Source/Server/Bot/Way.c
Normal file
293
Source/Server/Bot/Way.c
Normal file
|
@ -0,0 +1,293 @@
|
|||
|
||||
#define COST_INFINITE 999999999999
|
||||
|
||||
enumflags {
|
||||
WP_JUMP, //also implies that the bot must first go behind the wp...
|
||||
WP_CLIMB,
|
||||
WP_CROUCH,
|
||||
WP_USE
|
||||
};
|
||||
|
||||
typedef struct waypoint_s {
|
||||
vector org;
|
||||
float flRadius; //used for picking the closest waypoint. aka proximity weight. also relaxes routes inside the area.
|
||||
struct wpneighbour_s
|
||||
{
|
||||
int node;
|
||||
float linkcost;
|
||||
int iFlags;
|
||||
} *neighbour;
|
||||
int iNeighbours;
|
||||
} waypoint_t;
|
||||
|
||||
static waypoint_t *waypoints;
|
||||
static int iWaypoints;
|
||||
static int bWaypointsLoaded;
|
||||
|
||||
static void() Way_WipeWaypoints=
|
||||
{
|
||||
for (int i = 0; i < iWaypoints; i++)
|
||||
memfree(waypoints[i].neighbour);
|
||||
memfree(waypoints);
|
||||
iWaypoints = 0;
|
||||
}
|
||||
|
||||
void Way_DumpWaypoints( string filename )
|
||||
{
|
||||
float file = fopen(filename, FILE_WRITE);
|
||||
if (file < 0)
|
||||
{
|
||||
print("RT_DumpWaypoints: unable to open ", filename, "\n");
|
||||
return;
|
||||
}
|
||||
fputs(file, sprintf("%i\n", iWaypoints));
|
||||
for(int i = 0i; i < iWaypoints; i++)
|
||||
{
|
||||
fputs(file, sprintf("%v %f %i\n", waypoints[i].org, waypoints[i].flRadius, waypoints[i].iNeighbours));
|
||||
for(int j = 0i; j < waypoints[i].iNeighbours; j++)
|
||||
fputs(file, sprintf(" %i %f %#x\n", waypoints[i].neighbour[j].node, waypoints[i].neighbour[j].linkcost, waypoints[i].neighbour[j].iFlags));
|
||||
}
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
void Way_ReadWaypoints( string filename )
|
||||
{
|
||||
float file = fopen(filename, FILE_READ);
|
||||
bWaypointsLoaded = TRUE;
|
||||
if (file < 0)
|
||||
{
|
||||
print("Way_DumpWaypoints: unable to open ", filename, "\n");
|
||||
return;
|
||||
}
|
||||
Way_WipeWaypoints();
|
||||
|
||||
tokenize(fgets(file));
|
||||
iWaypoints = stoi(argv(0));
|
||||
|
||||
waypoints = memalloc(sizeof(*waypoints)*iWaypoints);
|
||||
for(int i = 0i; i < iWaypoints; i++)
|
||||
{
|
||||
tokenize(fgets(file));
|
||||
waypoints[i].org[0] = stof(argv(0));
|
||||
waypoints[i].org[1] = stof(argv(1));
|
||||
waypoints[i].org[2] = stof(argv(2));
|
||||
waypoints[i].flRadius = stof(argv(3));
|
||||
waypoints[i].iNeighbours = stoi(argv(4));
|
||||
waypoints[i].neighbour = memalloc(sizeof(*waypoints[i].neighbour)*waypoints[i].iNeighbours);
|
||||
for(int j = 0i; j < waypoints[i].iNeighbours; j++)
|
||||
{
|
||||
tokenize(fgets(file));
|
||||
waypoints[i].neighbour[j].node = stoi(argv(0));
|
||||
waypoints[i].neighbour[j].linkcost = stof(argv(1));
|
||||
waypoints[i].neighbour[j].iFlags = stoh(argv(2));
|
||||
}
|
||||
}
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
static void* memrealloc( __variant *oldptr, int elementsize, int oldelements, int newelements )
|
||||
{
|
||||
void *n = memalloc(elementsize*newelements);
|
||||
memcpy(n, oldptr, elementsize*min(oldelements,newelements));
|
||||
memfree(oldptr);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
static void Way_LinkWaypoints( waypoint_t *wp, waypoint_t *w2 )
|
||||
{
|
||||
int w2n = w2-waypoints;
|
||||
for (int i = 0i; i < wp->iNeighbours; i++)
|
||||
{
|
||||
if (wp->neighbour[i].node == w2n)
|
||||
return;
|
||||
}
|
||||
|
||||
int idx = wp->iNeighbours++;
|
||||
wp->neighbour = memrealloc(wp->neighbour, sizeof(*wp->neighbour), idx, wp->iNeighbours);
|
||||
local struct wpneighbour_s *n = wp->neighbour+idx;
|
||||
n->node = w2n;
|
||||
n->linkcost = vlen(w2->org - wp->org);
|
||||
n->iFlags = 0;
|
||||
}
|
||||
|
||||
static void Way_AutoLink( waypoint_t *wp )
|
||||
{
|
||||
int wpidx = wp-waypoints;
|
||||
for (int i = 0i; i < iWaypoints; i++)
|
||||
{
|
||||
if (i == wpidx)
|
||||
continue; //don't link to ourself...
|
||||
|
||||
if (vlen(wp->org - waypoints[i].org) > autocvar( nav_linksize, 256, "Cuttoff distance between links" ) )
|
||||
continue; //autolink distance cutoff.
|
||||
|
||||
//not going to use the full player size because that makes steps really messy.
|
||||
//however, we do need a little size, for sanity's sake
|
||||
tracebox(wp->org, '-16 -16 0', '16 16 32', waypoints[i].org, TRUE, world);
|
||||
if (trace_fraction < 1)
|
||||
continue; //light of sight blocked, don't try autolinking.
|
||||
|
||||
Way_LinkWaypoints(wp, &waypoints[i]);
|
||||
Way_LinkWaypoints(&waypoints[i], wp);
|
||||
}
|
||||
}
|
||||
|
||||
void Way_Waypoint_Create( entity pl, float autolink )
|
||||
{
|
||||
vector pos = pl.origin;
|
||||
int idx = iWaypoints++;
|
||||
waypoints = memrealloc( waypoints, sizeof(waypoint_t), idx, iWaypoints );
|
||||
waypoint_t *n = waypoints + idx;
|
||||
n->org = pos;
|
||||
n->neighbour = __NULL__;
|
||||
n->iNeighbours = 0;
|
||||
|
||||
if (autolink)
|
||||
Way_AutoLink(n);
|
||||
}
|
||||
|
||||
void Way_Waypoint_Delete( int idx )
|
||||
{
|
||||
if (idx < 0i || idx >= iWaypoints)
|
||||
{
|
||||
print("RT_DeleteWaypoint: invalid waypoint\n");
|
||||
return;
|
||||
}
|
||||
|
||||
//wipe the waypoint
|
||||
memfree(waypoints[idx].neighbour);
|
||||
memcpy(waypoints+idx, waypoints+idx+1, (iWaypoints-(idx+1))*sizeof(*waypoints));
|
||||
iWaypoints--;
|
||||
|
||||
//clean up any links to it.
|
||||
for (int i = 0; i < iWaypoints; i++)
|
||||
{
|
||||
for (int j = 0; j < waypoints[i].iNeighbours; )
|
||||
{
|
||||
int l = waypoints[i].neighbour[j].node;
|
||||
if (l == idx)
|
||||
{
|
||||
memcpy(waypoints[i].neighbour+j, waypoints[i].neighbour+j+1, (waypoints[i].iNeighbours-(j+1))*sizeof(*waypoints[i].neighbour));
|
||||
waypoints[i].iNeighbours--;
|
||||
continue;
|
||||
}
|
||||
else if (l > idx)
|
||||
waypoints[i].neighbour[j].node = l-1;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Way_Waypoint_SetRadius( int idx, float radius )
|
||||
{
|
||||
if (idx < 0i || idx >= iWaypoints)
|
||||
{
|
||||
print("RT_Waypoint_SetRadius: invalid waypoint\n");
|
||||
return;
|
||||
}
|
||||
waypoints[idx].flRadius = radius;
|
||||
}
|
||||
|
||||
void Way_Waypoint_MakeJump(int idx)
|
||||
{
|
||||
if (idx < 0i || idx >= iWaypoints)
|
||||
{
|
||||
print("RT_Waypoint_SetRadius: invalid waypoint\n");
|
||||
return;
|
||||
}
|
||||
|
||||
for(int j = 0i; j < waypoints[idx].iNeighbours; j++) {
|
||||
int target = waypoints[idx].neighbour[j].node;
|
||||
|
||||
for(int b = 0i; b < waypoints[target].iNeighbours; b++) {
|
||||
if ( waypoints[target].neighbour[b].node == idx ) {
|
||||
waypoints[target].neighbour[b].iFlags = WP_JUMP;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-1 for no nodes anywhere...
|
||||
int Way_FindClosestWaypoint( vector org )
|
||||
{
|
||||
int r = -1i;
|
||||
float bestdist = COST_INFINITE;
|
||||
for (int i = 0i; i < iWaypoints; i++)
|
||||
{
|
||||
float dist = vlen(waypoints[i].org - org) - waypoints[i].flRadius;
|
||||
if (dist < bestdist)
|
||||
{
|
||||
if (dist < 0)
|
||||
{ //within the waypoint's radius
|
||||
bestdist = dist;
|
||||
r = i;
|
||||
}
|
||||
else
|
||||
{ //outside the waypoint, make sure its valid.
|
||||
traceline(org, waypoints[i].org, TRUE, world);
|
||||
if (trace_fraction == 1)
|
||||
{ //FIXME: sort them frst, to avoid traces?
|
||||
bestdist = dist;
|
||||
r = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
//Lame visualisation stuff - this is only visible on listen servers.
|
||||
void SV_AddDebugPolygons( void ) {
|
||||
if ( !autocvar( way_display, 0, "Display current waypoints" ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !iWaypoints ) {
|
||||
return;
|
||||
}
|
||||
|
||||
int nearest = Way_FindClosestWaypoint( self.origin );
|
||||
makevectors(self.v_angle);
|
||||
R_BeginPolygon( "waypoint", 0, 0 );
|
||||
|
||||
for ( int i = 0i; i < iWaypoints; i++ ) {
|
||||
waypoint_t *w = waypoints+i;
|
||||
vector org = w->org;
|
||||
vector rgb = '1 1 1';
|
||||
if (nearest == i)
|
||||
rgb = '0 1 0';
|
||||
R_PolygonVertex(org + v_right*16 - v_up*16, '1 1', rgb, 1);
|
||||
R_PolygonVertex(org - v_right*16 - v_up*16, '0 1', rgb, 1);
|
||||
R_PolygonVertex(org - v_right*16 + v_up*16, '0 0', rgb, 1);
|
||||
R_PolygonVertex(org + v_right*16 + v_up*16, '1 0', rgb, 1);
|
||||
R_EndPolygon();
|
||||
}
|
||||
|
||||
R_BeginPolygon("", 0, 0);
|
||||
for ( int i = 0i; i < iWaypoints; i++ ) {
|
||||
waypoint_t *w = waypoints+i;
|
||||
vector org = w->org;
|
||||
|
||||
for (float j = 0; j < 2*M_PI; j += 2*M_PI/4)
|
||||
R_PolygonVertex(org + [sin(j), cos(j)]*w->flRadius, '1 1', '0 0.25 0', 1);
|
||||
R_EndPolygon();
|
||||
}
|
||||
|
||||
R_BeginPolygon("", 1, 0);
|
||||
for ( int i = 0i; i < iWaypoints; i++ ) {
|
||||
waypoint_t *w = waypoints+i;
|
||||
vector org = w->org;
|
||||
vector rgb = '1 1 1';
|
||||
for ( int j = 0i; j < w->iNeighbours; j++ ) {
|
||||
int k = w->neighbour[j].node;
|
||||
if ( k < 0i || k >= iWaypoints ) {
|
||||
break;
|
||||
}
|
||||
waypoint_t *w2 = &waypoints[k];
|
||||
R_PolygonVertex(org, '0 1', '1 0 1', 1);
|
||||
R_PolygonVertex(w2->org, '1 1', '0 1 0', 1);
|
||||
R_EndPolygon();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue