]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
refactor RandomSelection, add a field for vector 373/head
authorMartin Taibr <taibr.martin@gmail.com>
Fri, 7 Oct 2016 19:19:37 +0000 (21:19 +0200)
committerMartin Taibr <taibr.martin@gmail.com>
Fri, 7 Oct 2016 19:19:37 +0000 (21:19 +0200)
23 files changed:
qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qc
qcsrc/common/minigames/minigame/snake.qc
qcsrc/common/minigames/minigame/ttt.qc
qcsrc/common/monsters/sv_spawn.qc
qcsrc/common/mutators/mutator/buffs/sv_buffs.qc
qcsrc/common/mutators/mutator/nades/nades.qc
qcsrc/common/mutators/mutator/nix/sv_nix.qc
qcsrc/common/mutators/mutator/spawn_near_teammate/sv_spawn_near_teammate.qc
qcsrc/common/t_items.qc
qcsrc/common/triggers/teleporters.qc
qcsrc/common/triggers/trigger/jumppads.qc
qcsrc/common/triggers/triggers.qc
qcsrc/common/weapons/all.qc
qcsrc/common/weapons/weapon/fireball.qc
qcsrc/lib/random.qc
qcsrc/lib/random.qh
qcsrc/server/bot/default/bot.qc
qcsrc/server/cheats.qc
qcsrc/server/g_world.qc
qcsrc/server/mapvoting.qc
qcsrc/server/mutators/mutator/gamemode_invasion.qc
qcsrc/server/spawnpoints.qc
qcsrc/server/teamplay.qc

index d6606a370b74e6cc08fdd9a898e2f6a5a12d5766..a18ce34c5d06e83ad98d95a2e606f0034b5bc333 100644 (file)
@@ -1685,7 +1685,7 @@ MUTATOR_HOOKFUNCTION(ons, PlayerSpawn)
                {
                        if(SAME_TEAM(tmp_entity, player))
                        if(random_target)
-                               RandomSelection_Add(tmp_entity, 0, string_null, 1, 1);
+                               RandomSelection_AddEnt(tmp_entity, 1, 1);
                        else if(vlen2(tmp_entity.origin - spawn_loc) <= vlen2(closest_target.origin - spawn_loc) || closest_target == NULL)
                                closest_target = tmp_entity;
                }
@@ -1732,7 +1732,7 @@ MUTATOR_HOOKFUNCTION(ons, PlayerSpawn)
                for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
                {
                        if(random_target)
-                               RandomSelection_Add(tmp_entity, 0, string_null, 1, 1);
+                               RandomSelection_AddEnt(tmp_entity, 1, 1);
                        else
                        {
                                if(SAME_TEAM(tmp_entity, player))
index c15ecd463b94f4e8da29e7e745fd5bc87fef3de7..7f0fdb2ff750aa61eb1ffd2b5d72c903cfd0d97a 100644 (file)
@@ -95,7 +95,7 @@ void snake_new_mouse(entity minigame)
        {
                string pos = minigame_tile_buildname(i, j);
                if(!snake_find_piece(minigame, pos))
-                       RandomSelection_Add(NULL, 0, pos, 1, 1);
+                       RandomSelection_AddString(pos, 1, 1);
        }
 
        entity piece = msle_spawn(minigame,"minigame_board_piece");
@@ -175,7 +175,7 @@ void minigame_setup_snake(entity minigame, int pteam)
        {
                string pos = minigame_tile_buildname(i, j);
                if(!snake_find_piece(minigame, pos))
-                       RandomSelection_Add(NULL, 0, pos, 1, 1);
+                       RandomSelection_AddString(pos, 1, 1);
        }
 
        entity piece = msle_spawn(minigame,"minigame_board_piece");
index e06bb46628c5366db60f07a129feaf0cc18358f7..c5a658054fe0d1e55192363b7e12cfd0abe9112b 100644 (file)
@@ -418,7 +418,7 @@ int ttt_ai_random(int piecemask)
        for ( int i = 0; i < 9; i++ )
        {
                if ( piecemask & f )
-                       RandomSelection_Add(NULL, f, string_null, 1, 1);
+                       RandomSelection_AddFloat(f, 1, 1);
                f <<= 1;
        }
 
index da924cf96b37ec7e8ba707f40f1e1a79c88d156a..9e87e488e624323d336ee9cfcedb36ec651b1ba9 100644 (file)
@@ -24,7 +24,7 @@ entity spawnmonster (string monster, int monster_id, entity spawnedby, entity ow
                RandomSelection_Init(); 
                FOREACH(Monsters, it != MON_Null,
                {
-                       RandomSelection_Add(it, 0, string_null, 1, 1);
+                       RandomSelection_AddEnt(it, 1, 1);
                });
 
                monster_id = RandomSelection_chosen_ent.monsterid;
index 82fa2d33cb8bd0e0a649619e7836f95eefdfd9d6..5587da593796e32e6e6afee3d91d84ec4ac14a18 100644 (file)
@@ -216,7 +216,7 @@ void buff_NewType(entity ent, float cb)
        FOREACH(Buffs, buff_Available(it), LAMBDA(
                it.buff_seencount += 1;
                // if it's already been chosen, give it a lower priority
-               RandomSelection_Add(NULL, it.m_itemid, string_null, 1, max(0.2, 1 / it.buff_seencount));
+               RandomSelection_AddFloat(it.m_itemid, 1, max(0.2, 1 / it.buff_seencount));
        ));
        ent.buffs = RandomSelection_chosen_float;
 }
index 02760045c3e89e68bd8f309ad80a3fba7fd7ca8c..b0c0e582aaa5aab136865d7805bc6a6001d0e1ec 100644 (file)
@@ -211,7 +211,7 @@ void napalm_damage(entity this, float dist, float damage, float edgedamage, floa
                        if(d < dist)
                        {
                                e.fireball_impactvec = p;
-                               RandomSelection_Add(e, 0, string_null, 1 / (1 + d), !Fire_IsBurning(e));
+                               RandomSelection_AddEnt(e, 1 / (1 + d), !Fire_IsBurning(e));
                        }
                }
        if(RandomSelection_chosen_ent)
index 97ed4361ba12c8e4da5d8701fbf7f7e3208faad7..39072cefc7d2ba0ab9697a9f3a104599b2a40dc9 100644 (file)
@@ -96,7 +96,7 @@ void NIX_ChooseNextWeapon()
        RandomSelection_Init();
        FOREACH(Weapons, it != WEP_Null, LAMBDA(
                if(NIX_CanChooseWeapon(it.m_id))
-                       RandomSelection_Add(NULL, it.m_id, string_null, 1, (it.m_id != nix_weapon));
+                       RandomSelection_AddFloat(it.m_id, 1, (it.m_id != nix_weapon));
        ));
        nix_nextweapon = RandomSelection_chosen_float;
 }
index fb14f27db8063cb22d96b1dd9baad197b2f545d2..123b8caa03fbd9876d16af1c140b0a59479504fe 100644 (file)
@@ -38,7 +38,7 @@ MUTATOR_HOOKFUNCTION(spawn_near_teammate, Spawn_Score)
                        continue;
                if(!checkpvs(spawn_spot.origin, it))
                        continue;
-               RandomSelection_Add(it, 0, string_null, 1, 1);
+               RandomSelection_AddEnt(it, 1, 1);
        ));
 
        if(RandomSelection_chosen_ent)
index f9f89a73fa6ec8a5da6bf70d62227079c8569d5d..7424d695aa041cf2eb557576d209df327ae60a77 100644 (file)
@@ -840,7 +840,7 @@ LABEL(pickup)
                                if(it.classname != "item_flag_team" && it.classname != "item_kh_key")
                                {
                                        Item_Show(it, -1);
-                                       RandomSelection_Add(it, 0, string_null, it.cnt, 0);
+                                       RandomSelection_AddEnt(it, it.cnt, 0);
                                }
                        });
                        e = RandomSelection_chosen_ent;
@@ -882,7 +882,7 @@ void Item_FindTeam(entity this)
                IL_EACH(g_items, it.team == this.team,
                {
                        if(it.classname != "item_flag_team" && it.classname != "item_kh_key")
-                               RandomSelection_Add(it, 0, string_null, it.cnt, 0);
+                               RandomSelection_AddEnt(it, it.cnt, 0);
                });
 
                e = RandomSelection_chosen_ent;
index b5e97b1fc7516f1a082a82d69c354a85f4b8594e..949f478fdd3c714e9ba3402416be4b182c348b7a 100644 (file)
@@ -92,7 +92,7 @@ void TeleportPlayer(entity teleporter, entity player, vector to, vector to_angle
                                        RandomSelection_Init();
                                        FOREACH_WORD(teleporter.noise, true,
                                        {
-                                               RandomSelection_Add(NULL, 0, it, 1, 1);
+                                               RandomSelection_AddString(it, 1, 1);
                                        });
                                        thesound = RandomSelection_chosen_string;
                                }
@@ -198,7 +198,7 @@ entity Simple_TeleportPlayer(entity teleporter, entity player)
                                if(check_tdeath(player, locout, '0 0 0', '0 0 0'))
                                        p = 0;
                        }
-                       RandomSelection_Add(it, 0, string_null, (it.cnt ? it.cnt : 1), p);
+                       RandomSelection_AddEnt(it, (it.cnt ? it.cnt : 1), p);
                });
                e = RandomSelection_chosen_ent;
        }
index ef13dd5bec0d95af57d2432ba25e83953335cfa5..498f0ff2dbbffb885c36a546ff7f4faba2bac378 100644 (file)
@@ -155,9 +155,9 @@ void trigger_push_touch(entity this, entity toucher)
                for(e = NULL; (e = find(e, targetname, this.target)); )
                {
                        if(e.cnt)
-                               RandomSelection_Add(e, 0, string_null, e.cnt, 1);
+                               RandomSelection_AddEnt(e, e.cnt, 1);
                        else
-                               RandomSelection_Add(e, 0, string_null, 1, 1);
+                               RandomSelection_AddEnt(e, 1, 1);
                }
                toucher.velocity = trigger_push_calculatevelocity(toucher.origin, RandomSelection_chosen_ent, this.height);
        }
index 54e1e09919f06666bb6ff1b22c379b5f7577bc0c..8a63e3b6836a428c2bdfcdf7e7e422d581f73821 100644 (file)
@@ -260,7 +260,7 @@ void SUB_UseTargets_Ex(entity this, entity actor, entity trigger, bool preventRe
                                {
                                        if(this.target_random)
                                        {
-                                               RandomSelection_Add(t, 0, string_null, 1, 0);
+                                               RandomSelection_AddEnt(t, 1, 0);
                                        }
                                        else
                                        {
index cf55aa65214b7a84673da155f3ffb0eece56eb36..763dd6e8de83646cefda1786d8f6b51d3ce1dbaf 100644 (file)
@@ -204,7 +204,7 @@ void W_RandomWeapons(entity e, float n)
                RandomSelection_Init();
                FOREACH(Weapons, it != WEP_Null, {
                        if (remaining & (it.m_wepset))
-                               RandomSelection_Add(it, 0, string_null, 1, 1);
+                               RandomSelection_AddEnt(it, 1, 1);
                });
                Weapon w = RandomSelection_chosen_ent;
                result |= WepSet_FromWeapon(w);
index c2b93747c8c4c14d7d9437f6c50e2cc2934b8d89..ae1e48bb2c3e7f511af59d27ba3235a2434f07f5 100644 (file)
@@ -150,7 +150,7 @@ void W_Fireball_LaserPlay(entity this, float dt, float dist, float damage, float
                if(d < dist)
                {
                        e.fireball_impactvec = p;
-                       RandomSelection_Add(e, 0, string_null, 1 / (1 + d), !Fire_IsBurning(e));
+                       RandomSelection_AddEnt(e, 1 / (1 + d), !Fire_IsBurning(e));
                }
        }
        if(RandomSelection_chosen_ent)
index 2287d869d0c455bdbf15c77950ac8a5671f20b64..627fec11a92e1293bec76db098230b0a5fafc7f0 100644 (file)
@@ -9,7 +9,7 @@ void RandomSelection_Init()
        RandomSelection_best_priority = -1;
 }
 
-void RandomSelection_Add(entity e, float f, string s, float weight, float priority)
+void RandomSelection_Add(entity e, float f, string s, vector v, float weight, float priority)
 {
        if (priority > RandomSelection_best_priority)
        {
@@ -17,6 +17,7 @@ void RandomSelection_Add(entity e, float f, string s, float weight, float priori
                RandomSelection_chosen_ent = e;
                RandomSelection_chosen_float = f;
                RandomSelection_chosen_string = s;
+               RandomSelection_chosen_vec = v;
                RandomSelection_totalweight = weight;
        }
        else if (priority == RandomSelection_best_priority)
@@ -27,6 +28,7 @@ void RandomSelection_Add(entity e, float f, string s, float weight, float priori
                        RandomSelection_chosen_ent = e;
                        RandomSelection_chosen_float = f;
                        RandomSelection_chosen_string = s;
+                       RandomSelection_chosen_vec = v;
                }
        }
 }
index 1834a97a331164086464ce6ecc87d0527971fb9a..b2fc53f0cac4edaaa3ef964c25b7b6093ac2ae2c 100644 (file)
@@ -5,9 +5,14 @@ float RandomSelection_best_priority;
 entity RandomSelection_chosen_ent;
 float RandomSelection_chosen_float;
 string RandomSelection_chosen_string;
+vector RandomSelection_chosen_vec;
 
 void RandomSelection_Init();
-void RandomSelection_Add(entity e, float f, string s, float weight, float priority);
+void RandomSelection_Add(entity e, float f, string s, vector v, float weight, float priority);
+#define RandomSelection_AddEnt(e, weight, priority) RandomSelection_Add(e, 0, string_null, '0 0 0', weight, priority)
+#define RandomSelection_AddFloat(f, weight, priority) RandomSelection_Add(NULL, f, string_null, '0 0 0', weight, priority)
+#define RandomSelection_AddString(s, weight, priority) RandomSelection_Add(NULL, 0, s, '0 0 0', weight, priority)
+#define RandomSelection_AddVec(v, weight, priority) RandomSelection_Add(NULL, 0, string_null, v, weight, priority)
 
 // prandom - PREDICTABLE random number generator
 
index ca12d0d651cf53e9caa39a6afa01bd3528a466f8..bdde55b9aa94683b7ffb0901229203fb1ff59116 100644 (file)
@@ -177,7 +177,7 @@ void bot_setnameandstuff(entity this)
                                        break;
                                }
                        ));
-                       RandomSelection_Add(NULL, 0, readfile, 1, prio);
+                       RandomSelection_AddString(readfile, 1, prio);
                }
                readfile = RandomSelection_chosen_string;
                fclose(file);
index 9f763a886d73217cd4490aa05fba9f75a2add448..543a3f98d2174346e3fd61b27ae320ea15fd3f78 100644 (file)
@@ -262,7 +262,7 @@ float CheatImpulse(entity this, int imp)
                case CHIMPULSE_R00T.impulse:
                        IS_CHEAT(this, imp, 0, 0);
                        RandomSelection_Init();
-                       FOREACH_CLIENT(IS_PLAYER(it) && !IS_DEAD(it) && DIFF_TEAM(it, this), LAMBDA(RandomSelection_Add(it, 0, string_null, 1, 1)));
+                       FOREACH_CLIENT(IS_PLAYER(it) && !IS_DEAD(it) && DIFF_TEAM(it, this), LAMBDA(RandomSelection_AddEnt(it, 1, 1)));
                        if(RandomSelection_chosen_ent)
                                e = RandomSelection_chosen_ent;
                        else
@@ -475,9 +475,9 @@ float CheatCommand(entity this, int argc)
                        RandomSelection_Init();
                        crosshair_trace(this);
                        for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
-                               RandomSelection_Add(e, 0, string_null, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
+                               RandomSelection_AddEnt(e, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
                        for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
-                               RandomSelection_Add(e, 0, string_null, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
+                               RandomSelection_AddEnt(e, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
                        if(RandomSelection_chosen_ent)
                        {
                                delete(RandomSelection_chosen_ent.killindicator.killindicator);
@@ -497,9 +497,9 @@ float CheatCommand(entity this, int argc)
                                RandomSelection_Init();
                                crosshair_trace(this);
                                for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
-                                       RandomSelection_Add(e, 0, string_null, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
+                                       RandomSelection_AddEnt(e, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
                                for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
-                                       RandomSelection_Add(e, 0, string_null, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
+                                       RandomSelection_AddEnt(e, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
                                if(RandomSelection_chosen_ent)
                                {
                                        if(substring(argv(1), 0, 1) == "*")
index fe7822bc161549c5ab9f45a93eb5b61d6df24aad..be21020d4dc5f71cf84fe6a3dd836851473edba4 100644 (file)
@@ -1503,7 +1503,7 @@ void FixIntermissionClient(entity e)
                        stuffcmd(e, "\nscr_printspeed 1000000\n");
                        RandomSelection_Init();
                        FOREACH_WORD(autocvar_sv_intermission_cdtrack, true, LAMBDA(
-                               RandomSelection_Add(NULL, 0, it, 1, 1);
+                               RandomSelection_AddString(it, 1, 1);
                        ));
                        if (RandomSelection_chosen_string != "")
                        {
index 29768893a727dc3730bb723dfdb38f25ee72fb5a..7c7c02018c2afb1f664cab59800734bdca75606b 100644 (file)
@@ -522,7 +522,7 @@ float MapVote_CheckRules_2()
        for(i = 0; i < mapvote_count_real; ++i)
                if ( mapvote_maps_flags[i] & GTV_AVAILABLE )
                {
-                       RandomSelection_Add(NULL, i, string_null, 1, mapvote_selections[i]);
+                       RandomSelection_AddFloat(i, 1, mapvote_selections[i]);
                        if ( gametypevote &&  mapvote_maps[i] == MapInfo_Type_ToString(MapInfo_CurrentGametype()) )
                        {
                                currentVotes = mapvote_selections[i];
@@ -542,7 +542,7 @@ float MapVote_CheckRules_2()
        for(i = 0; i < mapvote_count_real; ++i)
                if(i != firstPlace)
                if ( mapvote_maps_flags[i] & GTV_AVAILABLE )
-                       RandomSelection_Add(NULL, i, string_null, 1, mapvote_selections[i]);
+                       RandomSelection_AddFloat(i, 1, mapvote_selections[i]);
        secondPlace = RandomSelection_chosen_float;
        secondPlaceVotes = RandomSelection_best_priority;
        //dprint("Second place: ", ftos(secondPlace), "\n");
index 61fe75ea49fa6128066e5fb294a988f157e5deb1..a057408b965846b31c1c2bd7e2486b9d03b1fcee 100644 (file)
@@ -45,7 +45,7 @@ int invasion_PickMonster(int supermonster_count)
        {
                if((it.spawnflags & MONSTER_TYPE_FLY) || (it.spawnflags & MONSTER_TYPE_SWIM) || (it.spawnflags & MONSTER_SIZE_QUAKE) || ((it.spawnflags & MON_FLAG_SUPERMONSTER) && supermonster_count >= 1))
                        continue;
-        RandomSelection_Add(NULL, it.monsterid, string_null, 1, 1);
+        RandomSelection_AddFloat(it.monsterid, 1, 1);
        });
 
        return RandomSelection_chosen_float;
@@ -57,7 +57,7 @@ entity invasion_PickSpawn()
 
        IL_EACH(g_invasion_spawns, true,
        {
-               RandomSelection_Add(it, 0, string_null, 1, ((time >= it.spawnshieldtime) ? 0.2 : 1)); // give recently used spawnpoints a very low rating
+               RandomSelection_AddEnt(it, 1, ((time >= it.spawnshieldtime) ? 0.2 : 1)); // give recently used spawnpoints a very low rating
                it.spawnshieldtime = time + autocvar_g_invasion_spawnpoint_spawn_delay;
        });
 
@@ -96,10 +96,10 @@ void invasion_SpawnChosenMonster(int mon)
        else
        {
                RandomSelection_Init();
-               if(inv_monsters_perteam[NUM_TEAM_1] > 0) RandomSelection_Add(NULL, NUM_TEAM_1, string_null, 1, 1);
-               if(inv_monsters_perteam[NUM_TEAM_2] > 0) RandomSelection_Add(NULL, NUM_TEAM_2, string_null, 1, 1);
-               if(invasion_teams >= 3) if(inv_monsters_perteam[NUM_TEAM_3] > 0) { RandomSelection_Add(NULL, NUM_TEAM_3, string_null, 1, 1); }
-               if(invasion_teams >= 4) if(inv_monsters_perteam[NUM_TEAM_4] > 0) { RandomSelection_Add(NULL, NUM_TEAM_4, string_null, 1, 1); }
+               if(inv_monsters_perteam[NUM_TEAM_1] > 0) RandomSelection_AddFloat(NUM_TEAM_1, 1, 1);
+               if(inv_monsters_perteam[NUM_TEAM_2] > 0) RandomSelection_AddFloat(NUM_TEAM_2, 1, 1);
+               if(invasion_teams >= 3) if(inv_monsters_perteam[NUM_TEAM_3] > 0) { RandomSelection_AddFloat(NUM_TEAM_3, 1, 1); }
+               if(invasion_teams >= 4) if(inv_monsters_perteam[NUM_TEAM_4] > 0) { RandomSelection_AddFloat(NUM_TEAM_4, 1, 1); }
 
                monster.team = RandomSelection_chosen_float;
        }
index 59cc052af421942def992c27f5103fd3d08d00d8..18d32c2f06369b05dd5be39db868aca414a10d44 100644 (file)
@@ -317,7 +317,7 @@ entity Spawn_WeightedPoint(entity firstspot, float lower, float upper, float exp
 
        RandomSelection_Init();
        for(spot = firstspot; spot; spot = spot.chain)
-               RandomSelection_Add(spot, 0, string_null, pow(bound(lower, spot.spawnpoint_score.y, upper), exponent) * spot.cnt, (spot.spawnpoint_score.y >= lower) * 0.5 + spot.spawnpoint_score.x);
+               RandomSelection_AddEnt(spot, pow(bound(lower, spot.spawnpoint_score.y, upper), exponent) * spot.cnt, (spot.spawnpoint_score.y >= lower) * 0.5 + spot.spawnpoint_score.x);
 
        return RandomSelection_chosen_ent;
 }
index 6ccb7d408186a2c473c4860bd7a210860e9deea2..4632866b4886755e7657da57ca2cc95fa3039109 100644 (file)
@@ -508,13 +508,13 @@ float FindSmallestTeam(entity pl, float ignore_pl)
 
        // now t is the minimum, or A minimum!
        if(t == 1 || TeamSmallerEqThanTeam(1, t, pl))
-               RandomSelection_Add(NULL, 1, string_null, 1, 1);
+               RandomSelection_AddFloat(1, 1, 1);
        if(t == 2 || TeamSmallerEqThanTeam(2, t, pl))
-               RandomSelection_Add(NULL, 2, string_null, 1, 1);
+               RandomSelection_AddFloat(2, 1, 1);
        if(t == 3 || TeamSmallerEqThanTeam(3, t, pl))
-               RandomSelection_Add(NULL, 3, string_null, 1, 1);
+               RandomSelection_AddFloat(3, 1, 1);
        if(t == 4 || TeamSmallerEqThanTeam(4, t, pl))
-               RandomSelection_Add(NULL, 4, string_null, 1, 1);
+               RandomSelection_AddFloat(4, 1, 1);
 
        return RandomSelection_chosen_float;
 }