mirror of
https://github.com/ineedbots/iw3_bot_warfare.git
synced 2025-07-04 02:01:48 +00:00
Compare commits
13 Commits
v2.2.0
...
02761a1013
Author | SHA1 | Date | |
---|---|---|---|
02761a1013 | |||
093dc9cd8c | |||
a3266c6de3 | |||
0ea6672804 | |||
b3967606f4 | |||
fcd130a132 | |||
f39a4d008c | |||
cff61ab690 | |||
f044af8aea | |||
1d464fca49 | |||
538269517a | |||
9efda21175 | |||
f536f2b65d |
4
.github/workflows/main.yml
vendored
4
.github/workflows/main.yml
vendored
@ -13,7 +13,9 @@ jobs:
|
||||
|
||||
- name: Setup gsc-tool
|
||||
uses: xensik/setup-gsc-tool@v1
|
||||
with:
|
||||
version: '1.4.0'
|
||||
|
||||
- name: Compile test script
|
||||
run: |
|
||||
gsc-tool.exe parse iw5 pc .
|
||||
gsc-tool.exe -m parse -g iw5 -s pc .
|
||||
|
@ -8,7 +8,7 @@
|
||||
*/
|
||||
init()
|
||||
{
|
||||
level.bw_version = "2.1.0";
|
||||
level.bw_version = "2.2.0";
|
||||
|
||||
if ( getdvar( "bots_main" ) == "" )
|
||||
{
|
||||
@ -207,8 +207,11 @@ init()
|
||||
if ( !isdefined( game[ "botWarfare" ] ) )
|
||||
{
|
||||
game[ "botWarfare" ] = true;
|
||||
game[ "botWarfareInitTime" ] = gettime();
|
||||
}
|
||||
|
||||
level.bot_inittime = gettime();
|
||||
|
||||
level.defuseobject = undefined;
|
||||
level.bots_smokelist = List();
|
||||
level.tbl_perkdata[ 0 ][ "reference_full" ] = true;
|
||||
@ -262,6 +265,7 @@ init()
|
||||
|
||||
level thread onPlayerConnect();
|
||||
level thread handleBots();
|
||||
level thread onPlayerChat();
|
||||
}
|
||||
|
||||
/*
|
||||
@ -440,6 +444,23 @@ fixPerksAndScriptKick()
|
||||
self.pers[ "isBot" ] = true;
|
||||
}
|
||||
|
||||
/*
|
||||
When a bot disconnects.
|
||||
*/
|
||||
onDisconnectPlayer()
|
||||
{
|
||||
name = self.name;
|
||||
|
||||
self waittill( "disconnect" );
|
||||
waittillframeend;
|
||||
|
||||
for ( i = 0; i < level.bots.size; i++ )
|
||||
{
|
||||
bot = level.bots[ i ];
|
||||
bot BotNotifyBotEvent( "connection", "disconnected", self, name );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
When a bot disconnects.
|
||||
*/
|
||||
@ -457,6 +478,14 @@ connected()
|
||||
{
|
||||
self endon( "disconnect" );
|
||||
|
||||
for ( i = 0; i < level.bots.size; i++ )
|
||||
{
|
||||
bot = level.bots[ i ];
|
||||
bot BotNotifyBotEvent( "connection", "connected", self, self.name );
|
||||
}
|
||||
|
||||
self thread onDisconnectPlayer();
|
||||
|
||||
if ( !isdefined( self.pers[ "bot_host" ] ) )
|
||||
{
|
||||
self thread doHostCheck();
|
||||
@ -1247,3 +1276,21 @@ doFiringThread()
|
||||
wait 1;
|
||||
self.bots_firing = false;
|
||||
}
|
||||
|
||||
/*
|
||||
When a player chats
|
||||
*/
|
||||
onPlayerChat()
|
||||
{
|
||||
for ( ;; )
|
||||
{
|
||||
level waittill( "say", message, player, is_hidden );
|
||||
|
||||
for ( i = 0; i < level.bots.size; i++ )
|
||||
{
|
||||
bot = level.bots[ i ];
|
||||
|
||||
bot BotNotifyBotEvent( "chat", "chat", message, player, is_hidden );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -252,10 +252,43 @@ start_chat_watch()
|
||||
case "sd":
|
||||
self thread bot_chat_sd_watch( a, b, c, d, e, f, g );
|
||||
break;
|
||||
|
||||
case "connection":
|
||||
self thread bot_chat_connection_player_watch( a, b, c, d, e, f, g );
|
||||
break;
|
||||
|
||||
case "chat":
|
||||
self thread bot_chat_chat_player_watch( a, b, c, d, e, f, g );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
When another player chats
|
||||
*/
|
||||
bot_chat_chat_player_watch( chatstr, message, player, is_hidden, e, f, g )
|
||||
{
|
||||
self endon( "disconnect" );
|
||||
}
|
||||
|
||||
/*
|
||||
When a player connected
|
||||
*/
|
||||
bot_chat_connection_player_watch( conn, player, playername, d, e, f, g )
|
||||
{
|
||||
self endon( "disconnect" );
|
||||
|
||||
switch ( conn )
|
||||
{
|
||||
case "connected":
|
||||
break;
|
||||
|
||||
case "disconnected":
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
start_startgame_watch
|
||||
*/
|
||||
|
@ -485,7 +485,7 @@ IsWeapSniper( weap )
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( maps\mp\gametypes\_missions::getweaponclass( weap ) != "weapon_sniper" )
|
||||
if ( getweaponclass( weap ) != "weapon_sniper" )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -556,6 +556,12 @@ onWeaponChange()
|
||||
{
|
||||
first = false;
|
||||
newWeapon = self getcurrentweapon();
|
||||
|
||||
// hack fix for botstop overridding weapon
|
||||
if ( newWeapon != "none" )
|
||||
{
|
||||
self switchtoweapon( newWeapon );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -903,19 +909,22 @@ updateBones()
|
||||
self endon( "disconnect" );
|
||||
self endon( "death" );
|
||||
|
||||
bones = strtok( self.pers[ "bots" ][ "skill" ][ "bones" ], "," );
|
||||
waittime = self.pers[ "bots" ][ "skill" ][ "bone_update_interval" ];
|
||||
|
||||
for ( ;; )
|
||||
{
|
||||
self waittill_notify_or_timeout( "new_enemy", waittime );
|
||||
oldbones = self.pers[ "bots" ][ "skill" ][ "bones" ];
|
||||
bones = strtok( oldbones, "," );
|
||||
|
||||
if ( !isdefined( self.bot.target ) )
|
||||
while ( oldbones == self.pers[ "bots" ][ "skill" ][ "bones" ] )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
self waittill_notify_or_timeout( "new_enemy", self.pers[ "bots" ][ "skill" ][ "bone_update_interval" ] );
|
||||
|
||||
self.bot.target.bone = random( bones );
|
||||
if ( !isdefined( self.bot.target ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
self.bot.target.bone = random( bones );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1024,6 +1033,23 @@ targetObjUpdateNoTrace( obj )
|
||||
obj.didlook = false;
|
||||
}
|
||||
|
||||
/*
|
||||
Returns true if myEye can see the bone of self
|
||||
*/
|
||||
checkTraceForBone( myEye, bone )
|
||||
{
|
||||
boneLoc = self gettagorigin( bone );
|
||||
|
||||
if ( !isdefined( boneLoc ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
trace = bullettrace( myEye, boneLoc, false, undefined );
|
||||
|
||||
return ( sighttracepassed( myEye, boneLoc, false, undefined ) && ( trace[ "fraction" ] >= 1.0 || trace[ "surfacetype" ] == "glass" ) );
|
||||
}
|
||||
|
||||
/*
|
||||
The main target thread, will update the bot's main target. Will auto target enemy players and handle script targets.
|
||||
*/
|
||||
@ -1135,21 +1161,9 @@ target_loop()
|
||||
continue;
|
||||
}
|
||||
|
||||
targetHead = player gettagorigin( "j_head" );
|
||||
targetAnkleLeft = player gettagorigin( "j_ankle_le" );
|
||||
targetAnkleRight = player gettagorigin( "j_ankle_ri" );
|
||||
|
||||
traceHead = bullettrace( myEye, targetHead, false, undefined );
|
||||
traceAnkleLeft = bullettrace( myEye, targetAnkleLeft, false, undefined );
|
||||
traceAnkleRight = bullettrace( myEye, targetAnkleRight, false, undefined );
|
||||
|
||||
canTargetPlayer = ( ( sighttracepassed( myEye, targetHead, false, undefined ) ||
|
||||
sighttracepassed( myEye, targetAnkleLeft, false, undefined ) ||
|
||||
sighttracepassed( myEye, targetAnkleRight, false, undefined ) )
|
||||
|
||||
&& ( ( traceHead[ "fraction" ] >= 1.0 || traceHead[ "surfacetype" ] == "glass" ) ||
|
||||
( traceAnkleLeft[ "fraction" ] >= 1.0 || traceAnkleLeft[ "surfacetype" ] == "glass" ) ||
|
||||
( traceAnkleRight[ "fraction" ] >= 1.0 || traceAnkleRight[ "surfacetype" ] == "glass" ) )
|
||||
canTargetPlayer = ( ( player checkTraceForBone( myEye, "j_head" ) ||
|
||||
player checkTraceForBone( myEye, "j_ankle_le" ) ||
|
||||
player checkTraceForBone( myEye, "j_ankle_ri" ) )
|
||||
|
||||
&& ( SmokeTrace( myEye, player.origin, level.smokeradius ) ||
|
||||
daDist < level.bots_maxknifedistance * 4 )
|
||||
@ -1508,7 +1522,7 @@ aim_loop()
|
||||
}
|
||||
else if ( curweap != "none" && weaponclass( curweap ) == "grenade" )
|
||||
{
|
||||
if ( maps\mp\gametypes\_missions::getweaponclass( curweap ) == "weapon_projectile" )
|
||||
if ( getweaponclass( curweap ) == "weapon_projectile" )
|
||||
{
|
||||
nadeAimOffset = dist / 16000;
|
||||
}
|
||||
@ -1582,7 +1596,7 @@ aim_loop()
|
||||
|
||||
conedot = getConeDot( aimpos, eyePos, angles );
|
||||
|
||||
if ( isdefined( self.bot.knifing_target ) )
|
||||
if ( isdefined( self.bot.knifing_target ) && self.bot.knifing_target == target )
|
||||
{
|
||||
self thread bot_lookat( target gettagorigin( "j_spine4" ), 0.05 );
|
||||
}
|
||||
@ -1680,7 +1694,7 @@ aim_loop()
|
||||
}
|
||||
else if ( curweap != "none" && weaponclass( curweap ) == "grenade" )
|
||||
{
|
||||
if ( maps\mp\gametypes\_missions::getweaponclass( curweap ) == "weapon_projectile" )
|
||||
if ( getweaponclass( curweap ) == "weapon_projectile" )
|
||||
{
|
||||
nadeAimOffset = dist / 16000;
|
||||
}
|
||||
@ -1773,6 +1787,7 @@ aim()
|
||||
for ( ;; )
|
||||
{
|
||||
wait 0.05;
|
||||
waittillframeend;
|
||||
|
||||
if ( level.inprematchperiod || level.gameended || self.bot.isfrozen || self maps\mp\_flashgrenades::isflashbanged() )
|
||||
{
|
||||
@ -1954,9 +1969,9 @@ walk_loop()
|
||||
|
||||
dist = 16;
|
||||
|
||||
if ( level.waypointcount )
|
||||
if ( level.waypoints.size )
|
||||
{
|
||||
goal = level.waypoints[ randomint( level.waypointcount ) ].origin;
|
||||
goal = level.waypoints[ randomint( level.waypoints.size ) ].origin;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -347,6 +347,21 @@ classWatch()
|
||||
|
||||
if ( !maps\mp\gametypes\_globallogic::isvalidclass( self.class ) || !isdefined( self.bot_change_class ) )
|
||||
{
|
||||
// mod warfare shtuff
|
||||
if ( isdefined( level.serverdvars ) )
|
||||
{
|
||||
a = [];
|
||||
a[ a.size ] = "assault";
|
||||
a[ a.size ] = "specops";
|
||||
a[ a.size ] = "heavygunner";
|
||||
a[ a.size ] = "demolitions";
|
||||
a[ a.size ] = "sniper";
|
||||
|
||||
self notify( "menuresponse", game[ "menu_changeclass_" + self.pers[ "team" ] ], random( a ) );
|
||||
|
||||
wait 0.5;
|
||||
}
|
||||
|
||||
self notify( "menuresponse", game[ "menu_changeclass" ], self chooseRandomClass() );
|
||||
}
|
||||
|
||||
|
@ -426,12 +426,22 @@ BotStopMoving( what )
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Waits till frame end so that if two notifies happen in the same frame, the other will not be missed.
|
||||
*/
|
||||
BotNotifyBotEvent_( msg, a, b, c, d, e, f, g )
|
||||
{
|
||||
self endon( "disconnect" );
|
||||
waittillframeend; // wait for the waittills to setup again
|
||||
self notify( "bot_event", msg, a, b, c, d, e, f, g );
|
||||
}
|
||||
|
||||
/*
|
||||
Notify the bot chat message
|
||||
*/
|
||||
BotNotifyBotEvent( msg, a, b, c, d, e, f, g )
|
||||
{
|
||||
self notify( "bot_event", msg, a, b, c, d, e, f, g );
|
||||
self thread BotNotifyBotEvent_( msg, a, b, c, d, e, f, g );
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1029,6 +1039,22 @@ isItemUnlocked( what, lvl )
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
ModWarfare removes this func from _missions
|
||||
*/
|
||||
getweaponclass( weapon )
|
||||
{
|
||||
tokens = strtok( weapon, "_" );
|
||||
weaponClass = tablelookup( "mp/statstable.csv", 4, tokens[ 0 ], 2 );
|
||||
|
||||
if ( ismg( weapon ) )
|
||||
{
|
||||
weaponClass = "weapon_mg";
|
||||
}
|
||||
|
||||
return weaponClass;
|
||||
}
|
||||
|
||||
/*
|
||||
If the weapon is allowed to be dropped
|
||||
*/
|
||||
@ -1724,7 +1750,6 @@ load_waypoints()
|
||||
{
|
||||
mapname = getdvar( "mapname" );
|
||||
|
||||
level.waypointcount = 0;
|
||||
level.waypointusage = [];
|
||||
level.waypointusage[ "allies" ] = [];
|
||||
level.waypointusage[ "axis" ] = [];
|
||||
@ -1771,9 +1796,7 @@ load_waypoints()
|
||||
BotBuiltinPrintConsole( "No waypoints loaded!" );
|
||||
}
|
||||
|
||||
level.waypointcount = level.waypoints.size;
|
||||
|
||||
for ( i = 0; i < level.waypointcount; i++ )
|
||||
for ( i = level.waypoints.size - 1; i >= 0; i-- )
|
||||
{
|
||||
if ( !isdefined( level.waypoints[ i ].children ) || !isdefined( level.waypoints[ i ].children.size ) )
|
||||
{
|
||||
@ -1872,7 +1895,7 @@ getWaypointsOfType( type )
|
||||
{
|
||||
answer = [];
|
||||
|
||||
for ( i = 0; i < level.waypointcount; i++ )
|
||||
for ( i = level.waypoints.size - 1; i >= 0; i-- )
|
||||
{
|
||||
wp = level.waypoints[ i ];
|
||||
|
||||
@ -2679,16 +2702,18 @@ RemoveWaypointUsage( wp, team )
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !isdefined( level.waypointusage[ team ][ wp + "" ] ) )
|
||||
wpstr = wp + "";
|
||||
|
||||
if ( !isdefined( level.waypointusage[ team ][ wpstr ] ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
level.waypointusage[ team ][ wp + "" ]--;
|
||||
level.waypointusage[ team ][ wpstr ]--;
|
||||
|
||||
if ( level.waypointusage[ team ][ wp + "" ] <= 0 )
|
||||
if ( level.waypointusage[ team ][ wpstr ] <= 0 )
|
||||
{
|
||||
level.waypointusage[ team ][ wp + "" ] = undefined;
|
||||
level.waypointusage[ team ][ wpstr ] = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2700,7 +2725,7 @@ GetNearestWaypointWithSight( pos )
|
||||
candidate = undefined;
|
||||
dist = 2147483647;
|
||||
|
||||
for ( i = 0; i < level.waypointcount; i++ )
|
||||
for ( i = level.waypoints.size - 1; i >= 0; i-- )
|
||||
{
|
||||
if ( !bullettracepassed( pos + ( 0, 0, 15 ), level.waypoints[ i ].origin + ( 0, 0, 15 ), false, undefined ) )
|
||||
{
|
||||
@ -2729,7 +2754,7 @@ getNearestWaypoint( pos )
|
||||
candidate = undefined;
|
||||
dist = 2147483647;
|
||||
|
||||
for ( i = 0; i < level.waypointcount; i++ )
|
||||
for ( i = level.waypoints.size - 1; i >= 0; i-- )
|
||||
{
|
||||
curdis = distancesquared( level.waypoints[ i ].origin, pos );
|
||||
|
||||
@ -2814,7 +2839,8 @@ AStarSearch( start, goal, team, greedy_path )
|
||||
// pop bestnode from queue
|
||||
bestNode = open.data[ 0 ];
|
||||
open HeapRemove();
|
||||
openset[ bestNode.index + "" ] = undefined;
|
||||
bestNodeStr = bestNode.index + "";
|
||||
openset[ bestNodeStr ] = undefined;
|
||||
wp = level.waypoints[ bestNode.index ];
|
||||
|
||||
// check if we made it to the goal
|
||||
@ -2824,14 +2850,16 @@ AStarSearch( start, goal, team, greedy_path )
|
||||
|
||||
while ( isdefined( bestNode ) )
|
||||
{
|
||||
bestNodeStr = bestNode.index + "";
|
||||
|
||||
if ( isdefined( team ) && isdefined( level.waypointusage ) )
|
||||
{
|
||||
if ( !isdefined( level.waypointusage[ team ][ bestNode.index + "" ] ) )
|
||||
if ( !isdefined( level.waypointusage[ team ][ bestNodeStr ] ) )
|
||||
{
|
||||
level.waypointusage[ team ][ bestNode.index + "" ] = 0;
|
||||
level.waypointusage[ team ][ bestNodeStr ] = 0;
|
||||
}
|
||||
|
||||
level.waypointusage[ team ][ bestNode.index + "" ]++;
|
||||
level.waypointusage[ team ][ bestNodeStr ]++;
|
||||
}
|
||||
|
||||
// construct path
|
||||
@ -2847,6 +2875,7 @@ AStarSearch( start, goal, team, greedy_path )
|
||||
for ( i = wp.children.size - 1; i >= 0; i-- )
|
||||
{
|
||||
child = wp.children[ i ];
|
||||
childStr = child + "";
|
||||
childWp = level.waypoints[ child ];
|
||||
|
||||
penalty = 1;
|
||||
@ -2855,9 +2884,9 @@ AStarSearch( start, goal, team, greedy_path )
|
||||
{
|
||||
temppen = 1;
|
||||
|
||||
if ( isdefined( level.waypointusage[ team ][ child + "" ] ) )
|
||||
if ( isdefined( level.waypointusage[ team ][ childStr ] ) )
|
||||
{
|
||||
temppen = level.waypointusage[ team ][ child + "" ]; // consider how many bots are taking this path
|
||||
temppen = level.waypointusage[ team ][ childStr ]; // consider how many bots are taking this path
|
||||
}
|
||||
|
||||
if ( temppen > 1 )
|
||||
@ -2876,16 +2905,16 @@ AStarSearch( start, goal, team, greedy_path )
|
||||
newg = bestNode.g + distancesquared( wp.origin, childWp.origin ) * penalty; // bots on same team's path are more expensive
|
||||
|
||||
// check if this child is in open or close with a g value less than newg
|
||||
inopen = isdefined( openset[ child + "" ] );
|
||||
inopen = isdefined( openset[ childStr ] );
|
||||
|
||||
if ( inopen && openset[ child + "" ].g <= newg )
|
||||
if ( inopen && openset[ childStr ].g <= newg )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
inclosed = isdefined( closed[ child + "" ] );
|
||||
inclosed = isdefined( closed[ childStr ] );
|
||||
|
||||
if ( inclosed && closed[ child + "" ].g <= newg )
|
||||
if ( inclosed && closed[ childStr ].g <= newg )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@ -2894,11 +2923,11 @@ AStarSearch( start, goal, team, greedy_path )
|
||||
|
||||
if ( inopen )
|
||||
{
|
||||
node = openset[ child + "" ];
|
||||
node = openset[ childStr ];
|
||||
}
|
||||
else if ( inclosed )
|
||||
{
|
||||
node = closed[ child + "" ];
|
||||
node = closed[ childStr ];
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -2914,19 +2943,19 @@ AStarSearch( start, goal, team, greedy_path )
|
||||
// check if in closed, remove it
|
||||
if ( inclosed )
|
||||
{
|
||||
closed[ child + "" ] = undefined;
|
||||
closed[ childStr ] = undefined;
|
||||
}
|
||||
|
||||
// check if not in open, add it
|
||||
if ( !inopen )
|
||||
{
|
||||
open HeapInsert( node );
|
||||
openset[ child + "" ] = node;
|
||||
openset[ childStr ] = node;
|
||||
}
|
||||
}
|
||||
|
||||
// done with children, push onto closed
|
||||
closed[ bestNode.index + "" ] = bestNode;
|
||||
closed[ bestNodeStr ] = bestNode;
|
||||
}
|
||||
|
||||
return [];
|
||||
|
@ -461,6 +461,7 @@ LoadWaypoints()
|
||||
self deleteAllWaypoints();
|
||||
self iprintlnbold( "Loading WPS..." );
|
||||
load_waypoints();
|
||||
level.waypointcount = level.waypoints.size;
|
||||
|
||||
wait 1;
|
||||
|
||||
|
@ -17,11 +17,11 @@ CodeCallback_StartGameType()
|
||||
|
||||
level.gametypestarted = true; // so we know that the gametype has been started up
|
||||
|
||||
level thread scripts\bots_adapter_cod4x::init();
|
||||
level thread scripts\bots_chat::init();
|
||||
level thread scripts\bots_menu::init();
|
||||
level thread scripts\bots_wp_editor::init();
|
||||
level thread scripts\bots::init();
|
||||
level thread scripts\mp\bots_adapter_cod4x::init();
|
||||
level thread scripts\mp\bots_chat::init();
|
||||
level thread scripts\mp\bots_menu::init();
|
||||
level thread scripts\mp\bots_wp_editor::init();
|
||||
level thread scripts\mp\bots::init();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user