From 8b4e35800828d8c5db5e61af7a7319737a53e57c Mon Sep 17 00:00:00 2001 From: terencehill Date: Sun, 16 Feb 2020 16:50:47 +0100 Subject: [PATCH] Use a shared macro to parse bot weapon priorities --- qcsrc/server/bot/default/bot.qc | 66 ++++++++++----------------------- 1 file changed, 20 insertions(+), 46 deletions(-) diff --git a/qcsrc/server/bot/default/bot.qc b/qcsrc/server/bot/default/bot.qc index bc9c0e18e..d768149e7 100644 --- a/qcsrc/server/bot/default/bot.qc +++ b/qcsrc/server/bot/default/bot.qc @@ -330,7 +330,7 @@ void bot_custom_weapon_priority_setup() if( autocvar_bot_ai_custom_weapon_priority_far == "" || autocvar_bot_ai_custom_weapon_priority_mid == "" || autocvar_bot_ai_custom_weapon_priority_close == "" || - autocvar_bot_ai_custom_weapon_priority_distances == "" + autocvar_bot_ai_custom_weapon_priority_distances == "" ) return; @@ -348,52 +348,26 @@ void bot_custom_weapon_priority_setup() bot_distance_close = stof(argv(0)); } - // Initialize list of weapons - bot_weapons_far[0] = -1; - bot_weapons_mid[0] = -1; - bot_weapons_close[0] = -1; - - // Parse far distance weapon priorities - tokens = tokenizebyseparator(W_NumberWeaponOrder(autocvar_bot_ai_custom_weapon_priority_far)," "); - - int c = 0; - for(i=0; i < tokens && c < Weapons_COUNT; ++i){ - w = stof(argv(i)); - if ( w >= WEP_FIRST && w <= WEP_LAST) { - bot_weapons_far[c] = w; - ++c; - } - } - if(c < Weapons_COUNT) - bot_weapons_far[c] = -1; - - // Parse mid distance weapon priorities - tokens = tokenizebyseparator(W_NumberWeaponOrder(autocvar_bot_ai_custom_weapon_priority_mid)," "); - - c = 0; - for(i=0; i < tokens && c < Weapons_COUNT; ++i){ - w = stof(argv(i)); - if ( w >= WEP_FIRST && w <= WEP_LAST) { - bot_weapons_mid[c] = w; - ++c; - } - } - if(c < Weapons_COUNT) - bot_weapons_mid[c] = -1; - - // Parse close distance weapon priorities - tokens = tokenizebyseparator(W_NumberWeaponOrder(autocvar_bot_ai_custom_weapon_priority_close)," "); + int c; + + #define PARSE_WEAPON_PRIORITIES(dist) MACRO_BEGIN \ + tokens = tokenizebyseparator(W_NumberWeaponOrder(autocvar_bot_ai_custom_weapon_priority_##dist)," "); \ + bot_weapons_##dist[0] = -1; \ + c = 0; \ + for(i = 0; i < tokens && c < Weapons_COUNT; ++i) { \ + w = stof(argv(i)); \ + if (w >= WEP_FIRST && w <= WEP_LAST) { \ + bot_weapons_##dist[c] = w; \ + ++c; \ + } \ + } \ + if (c < Weapons_COUNT) \ + bot_weapons_##dist[c] = -1; \ + MACRO_END - c = 0; - for(i=0; i < tokens && c < Weapons_COUNT; ++i){ - w = stof(argv(i)); - if ( w >= WEP_FIRST && w <= WEP_LAST) { - bot_weapons_close[c] = w; - ++c; - } - } - if(c < Weapons_COUNT) - bot_weapons_close[c] = -1; + PARSE_WEAPON_PRIORITIES(far); + PARSE_WEAPON_PRIORITIES(mid); + PARSE_WEAPON_PRIORITIES(close); bot_custom_weapon = true; } -- 2.39.2