]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Parse one bot weapon priority list as soon as its relative cvar is changed rather...
authorterencehill <piuntn@gmail.com>
Sun, 16 Feb 2020 16:35:00 +0000 (17:35 +0100)
committerterencehill <piuntn@gmail.com>
Sun, 16 Feb 2020 16:43:39 +0000 (17:43 +0100)
qcsrc/server/bot/default/bot.qc
qcsrc/server/bot/default/bot.qh

index d768149e7d1eba2009c07c9e259a66cacdb16fe4..f367adab32c538c455a1a12ea8216897de1d2781 100644 (file)
@@ -323,6 +323,10 @@ void bot_setnameandstuff(entity this)
 
 void bot_custom_weapon_priority_setup()
 {
+       static string bot_priority_far_prev;
+       static string bot_priority_mid_prev;
+       static string bot_priority_close_prev;
+       static string bot_priority_distances_prev;
        float tokens, i, w;
 
        bot_custom_weapon = false;
@@ -334,35 +338,41 @@ void bot_custom_weapon_priority_setup()
        )
                return;
 
-       // Parse distances
-       tokens = tokenizebyseparator(autocvar_bot_ai_custom_weapon_priority_distances," ");
+       if (bot_priority_distances_prev != autocvar_bot_ai_custom_weapon_priority_distances)
+       {
+               strcpy(bot_priority_distances_prev, autocvar_bot_ai_custom_weapon_priority_distances);
+               tokens = tokenizebyseparator(autocvar_bot_ai_custom_weapon_priority_distances," ");
 
-       if (tokens!=2)
-               return;
+               if (tokens!=2)
+                       return;
 
-       bot_distance_far = stof(argv(0));
-       bot_distance_close = stof(argv(1));
+               bot_distance_far = stof(argv(0));
+               bot_distance_close = stof(argv(1));
 
-       if(bot_distance_far < bot_distance_close){
-               bot_distance_far = stof(argv(1));
-               bot_distance_close = stof(argv(0));
+               if(bot_distance_far < bot_distance_close){
+                       bot_distance_far = stof(argv(1));
+                       bot_distance_close = stof(argv(0));
+               }
        }
 
        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 (bot_priority_##dist##_prev != autocvar_bot_ai_custom_weapon_priority_##dist) { \
+                       strcpy(bot_priority_##dist##_prev, autocvar_bot_ai_custom_weapon_priority_##dist); \
+                       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; \
                } \
-               if (c < Weapons_COUNT) \
-                       bot_weapons_##dist[c] = -1; \
        MACRO_END
 
        PARSE_WEAPON_PRIORITIES(far);
@@ -834,10 +844,6 @@ void bot_serverframe()
        if (autocvar_g_waypointeditor_auto)
                botframe_autowaypoints();
 
-       if(time > bot_cvar_nextthink)
-       {
-               if(currentbots>0)
-                       bot_custom_weapon_priority_setup();
-               bot_cvar_nextthink = time + 5;
-       }
+       if (currentbots > 0)
+               bot_custom_weapon_priority_setup();
 }
index 98b2ae3df78fb4d970ffd60528d65339b834f687..2cc20e0d34d4b7e080fabae33738a7ce3ef3218f 100644 (file)
@@ -75,7 +75,6 @@ entity bot_strategytoken;
 float botframe_spawnedwaypoints;
 float botframe_nextthink;
 float botframe_nextdangertime;
-float bot_cvar_nextthink;
 
 int _content_type;
 #define IN_LAVA(pos) (_content_type = pointcontents(pos), (_content_type == CONTENT_LAVA || _content_type == CONTENT_SLIME))