r5332 - in trunk/data: . qcsrc/common qcsrc/server

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Sun Dec 28 14:31:37 EST 2008


Author: div0
Date: 2008-12-28 14:31:37 -0500 (Sun, 28 Dec 2008)
New Revision: 5332

Modified:
   trunk/data/defaultNexuiz.cfg
   trunk/data/qcsrc/common/items.qc
   trunk/data/qcsrc/common/items.qh
   trunk/data/qcsrc/server/havocbot_roles.qc
Log:
next bot patch by mand1nga


Modified: trunk/data/defaultNexuiz.cfg
===================================================================
--- trunk/data/defaultNexuiz.cfg	2008-12-28 18:54:12 UTC (rev 5331)
+++ trunk/data/defaultNexuiz.cfg	2008-12-28 19:31:37 UTC (rev 5332)
@@ -262,6 +262,7 @@
 set bot_ai_custom_weapon_priority_close "11 3 9 13 14 8 6 4 2 5 7 15 1" // same as previous
 set bot_ai_weapon_combo 1 // Enable weapon combos 
 set bot_ai_weapon_combo_threshold 0.3 // Try to make a combo N seconds after the last attack
+set bot_ai_friends_aware_pickup_radius "500"
 
 // waypoint editor enable
 set g_waypointeditor 0

Modified: trunk/data/qcsrc/common/items.qc
===================================================================
--- trunk/data/qcsrc/common/items.qc	2008-12-28 18:54:12 UTC (rev 5331)
+++ trunk/data/qcsrc/common/items.qc	2008-12-28 19:31:37 UTC (rev 5332)
@@ -98,21 +98,21 @@
 void RegisterWeapons()
 {
 	// %weaponaddpoint
-	register_weapon(WEP_LASER,            w_laser,     0,              1, 1, 1,     0, "laser",     "laser",           "Laser");
-	register_weapon(WEP_SHOTGUN,          w_shotgun,   IT_SHELLS,      2, 1, 0,  2500, "shotgun",   "shotgun",         "Shotgun");
-	register_weapon(WEP_UZI,              w_uzi,       IT_NAILS,       3, 1, 0,  5000, "uzi",       "uzi",             "Machine Gun");
-	register_weapon(WEP_GRENADE_LAUNCHER, w_glauncher, IT_ROCKETS,     4, 1, 1,  5000, "gl",        "grenadelauncher", "Mortar");
-	register_weapon(WEP_ELECTRO,          w_electro,   IT_CELLS,       5, 1, 0,  5000, "electro",   "electro",         "Electro");
-	register_weapon(WEP_CRYLINK,          w_crylink,   IT_CELLS,       6, 1, 0,  5000, "crylink",   "crylink",         "Crylink");
-	register_weapon(WEP_NEX,              w_nex,       IT_CELLS,       7, 1, 0, 10000, "nex",       "nex",             "Nex");
-	register_weapon(WEP_HAGAR,            w_hagar,     IT_ROCKETS,     8, 1, 1,  5000, "hagar",     "hagar",           "Hagar");
-	register_weapon(WEP_ROCKET_LAUNCHER,  w_rlauncher, IT_ROCKETS,     9, 1, 1, 10000, "rl",        "rocketlauncher",  "Rocket Launcher");
-	register_weapon(WEP_PORTO,            w_porto,     0,              0, 0, 0,     0, "porto" ,    "porto",           "Port-O-Launch");
-	register_weapon(WEP_MINSTANEX,        w_minstanex, IT_CELLS,       7, 0, 1, 10000, "minstanex", "minstanex",       "MinstaNex");
-	register_weapon(WEP_HOOK,             w_hook,      IT_CELLS,       0, 0, 1,     0, "hookgun",   "hook",            "Grappling Hook");
-	register_weapon(WEP_SEEKER,           w_seeker,    IT_ROCKETS,     8, 1, 0,     0, "seeker",    "seeker",          "T.A.G. Seeker");
-	register_weapon(WEP_HLAC,             w_hlac,      IT_CELLS,       6, 1, 0,     0, "hlac",      "hlac",            "Heavy Laser Assault Cannon");
-	register_weapon(WEP_CAMPINGRIFLE,              w_campingrifle,       IT_NAILS,       3, 1, 0,  5000, "campingrifle",       "campingrifle",             "Camping Rifle");
+	register_weapon(WEP_LASER,            w_laser,        0,          1, 1, 1, 0,                      "laser",        "laser",           "Laser");
+	register_weapon(WEP_SHOTGUN,          w_shotgun,      IT_SHELLS,  2, 1, 0, BOT_PICKUP_RATING_LOW,  "shotgun",      "shotgun",         "Shotgun");
+	register_weapon(WEP_UZI,              w_uzi,          IT_NAILS,   3, 1, 0, BOT_PICKUP_RATING_MID,  "uzi",          "uzi",             "Machine Gun");
+	register_weapon(WEP_GRENADE_LAUNCHER, w_glauncher,    IT_ROCKETS, 4, 1, 1, BOT_PICKUP_RATING_MID,  "gl",           "grenadelauncher", "Mortar");
+	register_weapon(WEP_ELECTRO,          w_electro,      IT_CELLS,   5, 1, 0, BOT_PICKUP_RATING_MID,  "electro",      "electro",         "Electro");
+	register_weapon(WEP_CRYLINK,          w_crylink,      IT_CELLS,   6, 1, 0, BOT_PICKUP_RATING_MID,  "crylink",      "crylink",         "Crylink");
+	register_weapon(WEP_NEX,              w_nex,          IT_CELLS,   7, 1, 0, BOT_PICKUP_RATING_HIGH, "nex",          "nex",             "Nex");
+	register_weapon(WEP_HAGAR,            w_hagar,        IT_ROCKETS, 8, 1, 1, BOT_PICKUP_RATING_MID,  "hagar",        "hagar",           "Hagar");
+	register_weapon(WEP_ROCKET_LAUNCHER,  w_rlauncher,    IT_ROCKETS, 9, 1, 1, BOT_PICKUP_RATING_HIGH, "rl",           "rocketlauncher",  "Rocket Launcher");
+	register_weapon(WEP_PORTO,            w_porto,        0,          0, 0, 0, 0,                      "porto" ,       "porto",           "Port-O-Launch");
+	register_weapon(WEP_MINSTANEX,        w_minstanex,    IT_CELLS,   7, 0, 1, BOT_PICKUP_RATING_HIGH, "minstanex",    "minstanex",       "MinstaNex");
+	register_weapon(WEP_HOOK,             w_hook,         IT_CELLS,   0, 0, 1, 0,                      "hookgun",      "hook",            "Grappling Hook");
+	register_weapon(WEP_SEEKER,           w_seeker,       IT_ROCKETS, 8, 1, 0, BOT_PICKUP_RATING_HIGH, "seeker",       "seeker",          "T.A.G. Seeker");
+	register_weapon(WEP_HLAC,             w_hlac,         IT_CELLS,   6, 1, 0, BOT_PICKUP_RATING_MID,  "hlac",         "hlac",            "Heavy Laser Assault Cannon");
+	register_weapon(WEP_CAMPINGRIFLE,     w_campingrifle, IT_NAILS,   3, 1, 0, BOT_PICKUP_RATING_MID,  "campingrifle", "campingrifle",    "Camping Rifle");
 
 	register_weapons_done();
 }

Modified: trunk/data/qcsrc/common/items.qh
===================================================================
--- trunk/data/qcsrc/common/items.qh	2008-12-28 18:54:12 UTC (rev 5331)
+++ trunk/data/qcsrc/common/items.qh	2008-12-28 19:31:37 UTC (rev 5332)
@@ -19,6 +19,10 @@
 float WEP_LAST				= 15; float WEPBIT_ALL              = 32767;
 float WEP_COUNT             = 16;
 
+float BOT_PICKUP_RATING_LOW	= 2500;
+float BOT_PICKUP_RATING_MID	= 5000;
+float BOT_PICKUP_RATING_HIGH	= 10000;
+
 float	IT_UNLIMITED_WEAPON_AMMO  = 1;
 // when this bit is set, using a weapon does not reduce ammo. Checkpoints can give this powerup.
 float	IT_UNLIMITED_SUPERWEAPONS = 2;

Modified: trunk/data/qcsrc/server/havocbot_roles.qc
===================================================================
--- trunk/data/qcsrc/server/havocbot_roles.qc	2008-12-28 18:54:12 UTC (rev 5331)
+++ trunk/data/qcsrc/server/havocbot_roles.qc	2008-12-28 19:31:37 UTC (rev 5332)
@@ -10,25 +10,178 @@
 	return vlen(self.origin - e.origin) < 1500;
 }
 
+.float max_armorvalue;
+float havocbot_pickupevalfunc(entity item)
+{
+	float i, j, rating, base, position, need_shells, need_nails, need_rockets, need_cells;
+	rating = 0;
+
+	base = item.bot_pickupbasevalue;
+
+	need_shells = self.weapons & WEPBIT_SHOTGUN;
+	need_nails = self.weapons & WEPBIT_UZI;
+	need_cells = self.weapons & ( WEPBIT_HOOK | WEPBIT_HLAC | WEPBIT_MINSTANEX | WEPBIT_NEX | WEPBIT_ELECTRO | WEPBIT_CRYLINK );
+	need_rockets = self.weapons & ( WEPBIT_ROCKET_LAUNCHER | WEPBIT_GRENADE_LAUNCHER | WEPBIT_HAGAR | WEPBIT_SEEKER );
+
+	if( item.weapons )
+	{
+		if( self.weapons & item.weapons == item.weapons )
+			rating = 0.5 + bound(0, skill / 20, 0.5);
+		else
+			rating = 1;
+		
+		if( bot_custom_weapon )
+		{
+			for(i = WEP_FIRST; i < WEP_LAST ; ++i){		
+				if( power2of(i-1) & item.weapons  != item.weapons )
+					continue;
+
+				position = -1;
+				for(j = 0; j < WEP_LAST ; ++j){
+					if(
+						bot_weapons_far[j] == i ||
+						bot_weapons_mid[j] == i ||
+						bot_weapons_close[j] == i
+					)
+					{
+						position = j;
+						break;
+					}
+				}
+
+				if (position >= 0 ) 
+				{
+					position = WEP_LAST - position;
+					// item.bot_pickupbasevalue is overwritten here
+					base = BOT_PICKUP_RATING_LOW + ( (BOT_PICKUP_RATING_HIGH - BOT_PICKUP_RATING_LOW) * (position / WEP_LAST ));
+					break;
+				}
+			}
+		}
+	}
+
+	if (item.ammo_shells)
+	if (self.ammo_shells < g_pickup_shells_max && need_cells )
+		rating = rating + max(0, 1 - self.ammo_shells / g_pickup_shells_max);
+
+	if (item.ammo_nails)
+	if (self.ammo_nails < g_pickup_nails_max && need_nails )
+		rating = rating + max(0, 1 - self.ammo_nails / g_pickup_nails_max);
+
+	if (item.ammo_rockets)
+	if (self.ammo_rockets < g_pickup_rockets_max && need_rockets)
+		rating = rating + max(0, 1 - self.ammo_rockets / g_pickup_rockets_max);
+
+	if (item.ammo_cells)
+	if (self.ammo_cells < g_pickup_cells_max && need_cells)
+		rating = rating + max(0, 1 - self.ammo_cells / g_pickup_cells_max);
+
+	if (item.armorvalue)
+	if (self.armorvalue < item.max_armorvalue)
+		rating = rating + max(0, 1 - self.armorvalue / item.max_armorvalue);
+
+	if (item.health)
+	if (self.health < item.max_health)
+		rating = rating + max(0, 1 - self.health / item.max_health);
+
+	// TODO: if the item is not recognized then default to item.bot_pickupevalfunc(self, item);
+		
+	return base * rating;
+};
+
 void havocbot_goalrating_items(float ratingscale, vector org, float sradius)
 {
 	local entity head;
-	local float t;
+	local entity player;	
+	local float rating, d, discard, distance, friend_distance, enemy_distance;
 	ratingscale = ratingscale * 0.0001; // items are rated around 10000 already
 	head = findchainfloat(bot_pickup, TRUE);
+	
 	while (head)
 	{
-		if (head.solid) // must be possible to pick up (respawning items don't count)
-		if (vlen(head.origin - org) < sradius)
+		distance = vlen(head.origin - org);
+		friend_distance = 10000; enemy_distance = 10000;
+		rating = 0;
+	
+		if(!head.solid || distance > sradius ){
+			head = head.chain;
+			continue;		
+		}
+
+		if(teamplay)
 		{
-			// debugging
-			//if (!head.bot_pickupevalfunc || head.model == "")
-			//	eprint(head);
-			// get the value of the item
-			t = head.bot_pickupevalfunc(self, head);
-			if (t > 0)
-				navigation_routerating(head, t * ratingscale, 2000);
+			discard = FALSE;
+			
+			FOR_EACH_PLAYER(player)
+			{
+
+				if ( self == player || player.deadflag != DEAD_NO)
+					continue;
+
+				d = vlen(player.origin - head.origin); // distance between player and item
+
+				if ( player.team == self.team )
+				{
+					if ( clienttype(player) != CLIENTTYPE_REAL || discard )
+						continue;
+
+					if( d > friend_distance)
+						continue;
+					
+					friend_distance = d;
+
+					discard = TRUE;
+					
+					if( head.health && player.health > self.health )
+						continue;
+
+					if( head.armorvalue && player.armorvalue > self.armorvalue)
+						continue;
+											
+					if( head.weapons )
+					if( (player.weapons & head.weapons) != head.weapons)
+						continue;
+
+					if (head.ammo_shells && player.ammo_shells > self.ammo_shells)
+						continue;
+
+					if (head.ammo_nails && player.ammo_nails > self.ammo_nails)
+						continue;
+
+					if (head.ammo_rockets && player.ammo_rockets > self.ammo_rockets)
+						continue;
+
+					if (head.ammo_cells && player.ammo_cells > self.ammo_cells )
+						continue;
+
+					discard = FALSE;
+				}
+				else
+				{
+					// If enemy only track distances
+					// TODO: track only if visible ?
+					if( d < enemy_distance )
+						enemy_distance = d;
+				}
+			}
+
+			// Rate the item only if no one needs it, or if an enemy is closer to it
+			if (	(enemy_distance < friend_distance && distance < enemy_distance) ||
+				(friend_distance > cvar("bot_ai_friends_aware_pickup_radius") ) || !discard )
+			{
+			//	rating = head.bot_pickupevalfunc(self, head);
+				rating = havocbot_pickupevalfunc(head);
+			}				
 		}
+		else
+		{
+		//	rating = head.bot_pickupevalfunc(self, head);
+			rating = havocbot_pickupevalfunc(head);
+		}
+
+		if(rating > 0)
+			navigation_routerating(head, rating * ratingscale, 2000);
+			
 		head = head.chain;
 	}
 };




More information about the nexuiz-commits mailing list