Advertisement
Guest User

mand1nga

a guest
Nov 20th, 2008
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.53 KB | None | 0 0
  1. Index: havocbot.qc
  2. ===================================================================
  3. --- havocbot.qc (revision 5065)
  4. +++ havocbot.qc (working copy)
  5. @@ -320,6 +320,7 @@
  6. self.havocbot_stickenemy = 1;
  7. };
  8.  
  9. +.float bot_chooseweapontime;
  10. float(entity e) w_getbestweapon;
  11. void havocbot_chooseweapon()
  12. {
  13. @@ -350,6 +351,62 @@
  14. local float distancefromfloor;
  15. traceline(self.enemy.origin,self.enemy.origin-'0 0 1000',TRUE,world);
  16. distancefromfloor = self.enemy.origin_z - trace_endpos_z;
  17. +
  18. + // Custom weapon list based on distance to the enemy
  19. + local float i; i = 0;
  20. + if(bot_custom_weapon){
  21. +
  22. + // Choose weapons for far distance
  23. + if ( distance > bot_distance_far ) {
  24. + for(i=0; i < WEP_LAST && bot_weapons_far[i] != -1 ; ++i){
  25. + w = bot_weapons_far[i];
  26. + if ( client_hasweapon(self, w, TRUE, FALSE) ){
  27. + if ( self.weapon == w){
  28. + if( cvar("bot_ai_weapon_combo") &&
  29. + ATTACK_FINISHED(self) > time + cvar("bot_ai_weapon_combo_threshold"))
  30. + continue;
  31. + } else {
  32. + self.switchweapon = w;
  33. + }
  34. + return;
  35. + }
  36. + }
  37. + }
  38. +
  39. + // Choose weapons for mid distance
  40. + if ( distance > bot_distance_close ) {
  41. + for(i=0; i < WEP_LAST && bot_weapons_mid[i] != -1 ; ++i){
  42. + w = bot_weapons_mid[i];
  43. + if ( client_hasweapon(self, w, TRUE, FALSE) ){
  44. + if ( self.weapon == w){
  45. + if( cvar("bot_ai_weapon_combo") &&
  46. + ATTACK_FINISHED(self) > time + cvar("bot_ai_weapon_combo_threshold"))
  47. + continue;
  48. + } else {
  49. + self.switchweapon = w;
  50. + }
  51. + return;
  52. + }
  53. + }
  54. + }
  55. +
  56. + // Choose weapons for close distance
  57. + for(i=0; i < WEP_LAST && bot_weapons_close[i] != -1 ; ++i){
  58. + w = bot_weapons_close[i];
  59. + if ( client_hasweapon(self, w, TRUE, FALSE) ){
  60. + if ( self.weapon == w){
  61. + if( cvar("bot_ai_weapon_combo") &&
  62. + ATTACK_FINISHED(self) > time + cvar("bot_ai_weapon_combo_threshold"))
  63. + continue;
  64. + } else {
  65. + self.switchweapon = w;
  66. + }
  67. + return;
  68. + }
  69. + }
  70. + // If now weapon was chosen by this system fall back to the previous one
  71. + }
  72. +
  73. // Formula:
  74. // (Damage/Sec * Weapon spefic change to get that damage)
  75. // *(Time to get to target * weapon specfic hitchange bonus) / (in a time of maxdelaytime)
  76. @@ -359,33 +416,71 @@
  77. if (client_hasweapon(self, WEP_MINSTANEX, TRUE, FALSE))
  78. minstanex = (1000/cvar("g_balance_minstanex_refire")*1.0)
  79. * (0.5);
  80. - if (client_hasweapon(self, WEP_ROCKET_LAUNCHER, TRUE, FALSE))
  81. +
  82. + if (client_hasweapon(self, WEP_ROCKET_LAUNCHER, TRUE, FALSE) &&
  83. + !( cvar("bot_ai_weapon_combo") && self.weapon == WEP_ROCKET_LAUNCHER &&
  84. + ATTACK_FINISHED(self) > time + cvar("bot_ai_weapon_combo_threshold")
  85. + )
  86. + )
  87. rocket = (cvar("g_balance_rocketlauncher_damage")/cvar("g_balance_rocketlauncher_refire")*0.75)
  88. * bound(0,(cvar("g_balance_rocketlauncher_speed")/distance*maxdelaytime),1)*1.5;
  89. - if (client_hasweapon(self, WEP_NEX, TRUE, FALSE))
  90. +
  91. + if (client_hasweapon(self, WEP_NEX, TRUE, FALSE) &&
  92. + !( cvar("bot_ai_weapon_combo") && self.weapon == WEP_NEX &&
  93. + ATTACK_FINISHED(self) > time + cvar("bot_ai_weapon_combo_threshold")
  94. + )
  95. + )
  96. nex = (cvar("g_balance_nex_damage")/cvar("g_balance_nex_refire")*1.0)
  97. * (0.5);
  98. - if (client_hasweapon(self, WEP_HAGAR, TRUE, FALSE))
  99. +
  100. + if (client_hasweapon(self, WEP_HAGAR, TRUE, FALSE) ) // &&
  101. + // !( cvar("bot_ai_weapon_combo") && self.weapon == WEP_HAGAR && time < self.bot_lastshot + cvar("g_balance_hagar_primary_refire") ))
  102. hagar = (cvar("g_balance_hagar_primary_damage")/cvar("g_balance_hagar_primary_refire")*1.0)
  103. * bound(0,(cvar("g_balance_hagar_primary_speed")/distance*maxdelaytime),1)*0.2;
  104. - if (client_hasweapon(self, WEP_GRENADE_LAUNCHER, TRUE, FALSE))
  105. +
  106. + if (client_hasweapon(self, WEP_GRENADE_LAUNCHER, TRUE, FALSE) &&
  107. + !(
  108. + cvar("bot_ai_weapon_combo") && self.weapon == WEP_GRENADE_LAUNCHER &&
  109. + ATTACK_FINISHED(self) > time + cvar("bot_ai_weapon_combo_threshold")
  110. + )
  111. + )
  112. grenade = (cvar("g_balance_grenadelauncher_primary_damage")/cvar("g_balance_grenadelauncher_primary_refire")*1.0)
  113. * bound(0,(cvar("g_balance_grenadelauncher_primary_speed")/distance*maxdelaytime),1)*1.1;
  114. - if (client_hasweapon(self, WEP_ELECTRO, TRUE, FALSE))
  115. +
  116. + if (client_hasweapon(self, WEP_ELECTRO, TRUE, FALSE) &&
  117. + !( cvar("bot_ai_weapon_combo") && self.weapon == WEP_ELECTRO &&
  118. + ATTACK_FINISHED(self) > time + cvar("bot_ai_weapon_combo_threshold")
  119. + )
  120. + )
  121. electro = (cvar("g_balance_electro_primary_damage")/cvar("g_balance_electro_primary_refire")*0.75)
  122. * bound(0,(cvar("g_balance_electro_primary_speed")/distance*maxdelaytime),1)*1.0;
  123. - if (client_hasweapon(self, WEP_CRYLINK, TRUE, FALSE))
  124. +
  125. + if (client_hasweapon(self, WEP_CRYLINK, TRUE, FALSE) ) // &&
  126. + // !( self.weapon == WEP_CRYLINK && time < self.bot_lastshot + cvar("g_balance_crylink_primary_refire") ))
  127. crylink = (cvar("g_balance_crylink_primary_damage")/cvar("g_balance_crylink_primary_refire")*1.0)
  128. * bound(0,(cvar("g_balance_crylink_primary_speed")/distance*maxdelaytime),1)*(64/(32+cvar("g_balance_crylink_primary_spread")*distance))*1.0;
  129. - if (client_hasweapon(self, WEP_UZI, TRUE, FALSE))
  130. +
  131. + if (client_hasweapon(self, WEP_UZI, TRUE, FALSE) ) // &&
  132. + // !( self.weapon == WEP_UZI && time < self.bot_lastshot + cvar("g_balance_uzi_sustained_refire") ))
  133. uzi = (cvar("g_balance_uzi_sustained_damage")/cvar("g_balance_uzi_sustained_refire")*1.0)
  134. * bound(0,32/(32+cvar("g_balance_uzi_sustained_spread")*distance),1);
  135. - if (client_hasweapon(self, WEP_SHOTGUN, TRUE, FALSE))
  136. +
  137. + if (client_hasweapon(self, WEP_SHOTGUN, TRUE, FALSE) &&
  138. + !( cvar("bot_ai_weapon_combo") && self.weapon == WEP_SHOTGUN &&
  139. + ATTACK_FINISHED(self) > time + cvar("bot_ai_weapon_combo_threshold")
  140. + )
  141. + )
  142. shotgun = (cvar("g_balance_shotgun_primary_damage")*cvar("g_balance_shotgun_primary_bullets")/cvar("g_balance_shotgun_primary_refire")*1.0)
  143. * bound(0,32/(32+cvar("g_balance_shotgun_primary_spread")*distance),1);
  144. - if (client_hasweapon(self, WEP_LASER, FALSE, FALSE))
  145. +
  146. + if (client_hasweapon(self, WEP_LASER, FALSE, FALSE) &&
  147. + !( cvar("bot_ai_weapon_combo") && self.weapon == WEP_LASER &&
  148. + ATTACK_FINISHED(self) > time + cvar("bot_ai_weapon_combo_threshold")
  149. + )
  150. + )
  151. laser = (cvar("g_balance_laser_primary_damage")/cvar("g_balance_laser_primary_refire")*1.0)
  152. * bound(0,cvar("g_balance_laser_primary_speed")/distance*maxdelaytime,1);
  153. +
  154. if((self.enemy.flags & FL_ONGROUND)==FALSE){
  155. rocket = rocket * (1.5-bound(0, distancefromfloor/cvar("g_balance_rocketlauncher_radius" ),0.9)); //slight bigger change
  156. grenade = grenade * (1.5-bound(0,distancefromfloor/cvar("g_balance_grenadelauncher_primary_radius"),0.95));
  157. @@ -417,8 +512,13 @@
  158. w = WEP_LASER ;s = laser ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
  159.  
  160. // switch if the best weapon would provide a significant damage increase
  161. - if (bestscore > currentscore*1.5)
  162. + if (bestscore > currentscore*1.5){
  163. self.switchweapon = bestweapon;
  164. +
  165. + // buys time for detonating the rocket. not tested yet
  166. + if ( cvar("bot_ai_weapon_combo") && bestweapon == WEP_ROCKET_LAUNCHER )
  167. + self.bot_chooseweapontime += (distance / cvar("g_balance_rocketlauncher_speed"));
  168. + }
  169. };
  170.  
  171. .float nextaim;
  172. @@ -442,7 +542,6 @@
  173. lag_additem(time + self.ping, 0, 0, world, self.origin, selfvel, self.goalcurrent.origin, '0 0 0');
  174. };
  175.  
  176. -.float bot_chooseweapontime;
  177. void havocbot_ai()
  178. {
  179. if (bot_strategytoken == self)
  180. @@ -453,7 +552,7 @@
  181. bot_strategytoken_taken = TRUE;
  182. }
  183. havocbot_chooseenemy();
  184. - if (self.bot_chooseweapontime < time)
  185. + if (self.bot_chooseweapontime < time )
  186. {
  187. self.bot_chooseweapontime = time + cvar("bot_ai_chooseweaponinterval");
  188. havocbot_chooseweapon();
  189. Index: bots.qc
  190. ===================================================================
  191. --- bots.qc (revision 5065)
  192. +++ bots.qc (working copy)
  193. @@ -1499,6 +1499,89 @@
  194. self.netname = name;
  195. };
  196.  
  197. +float bot_custom_weapon;
  198. +float bot_distance_far;
  199. +float bot_distance_close;
  200. +
  201. +float bot_weapons_far[WEP_LAST];
  202. +float bot_weapons_mid[WEP_LAST];
  203. +float bot_weapons_close[WEP_LAST];
  204. +
  205. +void bot_custom_weapon_priority_setup()
  206. +{
  207. + local float tokens, i, c, w;
  208. +
  209. + bot_custom_weapon = FALSE;
  210. +
  211. + if( cvar_string("bot_ai_custom_weapon_priority_far") == "" ||
  212. + cvar_string("bot_ai_custom_weapon_priority_mid") == "" ||
  213. + cvar_string("bot_ai_custom_weapon_priority_close") == "" ||
  214. + cvar_string("bot_ai_custom_weapon_priority_distances") == ""
  215. + )
  216. + return;
  217. +
  218. + // Parse distances
  219. + tokens = tokenizebyseparator(cvar_string("bot_ai_custom_weapon_priority_distances")," ");
  220. +
  221. + if (tokens!=2)
  222. + return;
  223. +
  224. + bot_distance_far = stof(argv(0));
  225. + bot_distance_close = stof(argv(1));
  226. +
  227. + if(bot_distance_far < bot_distance_close){
  228. + bot_distance_far = stof(argv(1));
  229. + bot_distance_close = stof(argv(0));
  230. + }
  231. +
  232. + // Initialize list of weapons
  233. + bot_weapons_far[0] = -1;
  234. + bot_weapons_mid[0] = -1;
  235. + bot_weapons_close[0] = -1;
  236. +
  237. + // Parse far distance weapon priorities
  238. + tokens = tokenizebyseparator(cvar_string("bot_ai_custom_weapon_priority_far")," ");
  239. +
  240. + c = 0;
  241. + for(i=0; i < tokens && i < WEP_LAST; ++i){
  242. + w = stof(argv(i));
  243. + if ( w >= WEP_FIRST && w <= WEP_LAST) {
  244. + bot_weapons_far[c] = w;
  245. + ++c;
  246. + }
  247. + }
  248. + bot_weapons_far[c] = -1;
  249. +
  250. + // Parse mid distance weapon priorities
  251. + tokens = tokenizebyseparator(cvar_string("bot_ai_custom_weapon_priority_mid")," ");
  252. +
  253. + c = 0;
  254. + for(i=0; i < tokens && i < WEP_LAST; ++i){
  255. + w = stof(argv(i));
  256. + if ( w >= WEP_FIRST && w <= WEP_LAST) {
  257. + bot_weapons_mid[c] = w;
  258. + ++c;
  259. + }
  260. + }
  261. + bot_weapons_mid[c] = -1;
  262. +
  263. + // Parse close distance weapon priorities
  264. + tokens = tokenizebyseparator(cvar_string("bot_ai_custom_weapon_priority_close")," ");
  265. +
  266. + c = 0;
  267. + for(i=0; i < tokens && i < WEP_LAST; ++i){
  268. + w = stof(argv(i));
  269. + if ( w >= WEP_FIRST && w <= WEP_LAST) {
  270. + bot_weapons_close[c] = w;
  271. + ++c;
  272. + }
  273. + }
  274. + bot_weapons_close[c] = -1;
  275. +
  276. + bot_custom_weapon = TRUE;
  277. +};
  278. +
  279. +
  280. void bot_endgame()
  281. {
  282. local entity e;
  283. @@ -2169,6 +2252,7 @@
  284. head.totalfrags_lastcheck = head.totalfrags;
  285. }
  286.  
  287. +float bot_cvar_nextthink;
  288. void bot_serverframe()
  289. {
  290. float realplayers, bots, activerealplayers;
  291. @@ -2288,4 +2372,11 @@
  292.  
  293. if (cvar("g_waypointeditor"))
  294. botframe_showwaypointlinks();
  295. +
  296. + if(time > bot_cvar_nextthink)
  297. + {
  298. + if(currentbots>1)
  299. + bot_custom_weapon_priority_setup();
  300. + bot_cvar_nextthink = time + 5;
  301. + }
  302. };
  303.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement