]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Clean up some for() loops, also replace a few remaining cases of VHF_ISVEHICLE with...
authorMario <mario@smbclan.net>
Sat, 18 Jun 2016 23:36:13 +0000 (09:36 +1000)
committerMario <mario@smbclan.net>
Sat, 18 Jun 2016 23:36:13 +0000 (09:36 +1000)
qcsrc/common/vehicles/vehicle/bumblebee.qc
qcsrc/server/bot/havocbot/havocbot.qc
qcsrc/server/cl_client.qc
qcsrc/server/mutators/mutator/gamemode_assault.qc
qcsrc/server/mutators/mutator/gamemode_domination.qc
qcsrc/server/mutators/mutator/gamemode_invasion.qc
qcsrc/server/portals.qc
qcsrc/server/spawnpoints.qc
qcsrc/server/weapons/selection.qc
qcsrc/server/weapons/weaponsystem.qc

index 401483735ca409394d38a72173430a55262f8430..d65d061fbcc885572afdfa034b92c69636b1e432 100644 (file)
@@ -562,7 +562,7 @@ bool bumblebee_pilot_frame(entity this)
                                        if((teamplay && trace_ent.team == this.team) || !teamplay)
                                        {
 
-                                               if(trace_ent.vehicle_flags & VHF_ISVEHICLE)
+                                               if(IS_VEHICLE(trace_ent))
                                                {
                                                        if(autocvar_g_vehicle_bumblebee_healgun_sps && trace_ent.vehicle_health <= trace_ent.max_health)
                                                                trace_ent.vehicle_shield = min(trace_ent.vehicle_shield + autocvar_g_vehicle_bumblebee_healgun_sps * frametime, trace_ent.tur_head.max_health);
index f6c0348d28065517ff5865f0a5a21e8a3f27704a..c3603e9ff1bdc7390bde112b1e67d876d4fd0921 100644 (file)
@@ -1233,15 +1233,11 @@ float havocbot_moveto(entity this, vector pos)
        this.aistatus |= AI_STATUS_WAYPOINT_PERSONAL_LINKING;
 
        // if pos is inside a teleport, then let's mark it as teleport waypoint
-       entity head;
-       for(head = NULL; (head = find(head, classname, "trigger_teleport")); )
+       FOREACH_ENTITY_CLASS("trigger_teleport", WarpZoneLib_BoxTouchesBrush(pos, pos, it, NULL),
        {
-               if(WarpZoneLib_BoxTouchesBrush(pos, pos, head, NULL))
-               {
-                       wp.wpflags |= WAYPOINTFLAG_TELEPORT;
-                       this.lastteleporttime = 0;
-               }
-       }
+               wp.wpflags |= WAYPOINTFLAG_TELEPORT;
+               this.lastteleporttime = 0;
+       });
 
 /*
        if(wp.wpflags & WAYPOINTFLAG_TELEPORT)
index 0bdd2f19e78e83ca5bf410736ca97f73515c17b2..1298ae4fe675d107b1141d0b64b1c09e60582cdb 100644 (file)
@@ -853,7 +853,6 @@ void ClientKill_TeamChange (entity this, float targetteam) // 0 = don't change,
 {
        float killtime;
        float starttime;
-       entity e;
 
        if (gameover)
                return;
@@ -896,20 +895,20 @@ void ClientKill_TeamChange (entity this, float targetteam) // 0 = don't change,
                        this.killindicator.count = bound(0, ceil(killtime), 10);
                        //sprint(this, strcat("^1You'll be dead in ", ftos(this.killindicator.cnt), " seconds\n"));
 
-                       for(e = NULL; (e = find(e, classname, "body")) != NULL; )
+                       FOREACH_ENTITY_ENT(enemy, this,
                        {
-                               if(e.enemy != this)
+                               if(it.classname != "body")
                                        continue;
-                               e.killindicator = spawn();
-                               e.killindicator.owner = e;
-                               e.killindicator.scale = 0.5;
-                               setattachment(e.killindicator, e, "");
-                               setorigin(e.killindicator, '0 0 52');
-                               setthink(e.killindicator, KillIndicator_Think);
-                               e.killindicator.nextthink = starttime + (e.lip) * 0.05;
-                               clientkilltime = max(clientkilltime, e.killindicator.nextthink + 0.05);
-                               e.killindicator.cnt = ceil(killtime);
-                       }
+                               it.killindicator = spawn();
+                               it.killindicator.owner = it;
+                               it.killindicator.scale = 0.5;
+                               setattachment(it.killindicator, it, "");
+                               setorigin(it.killindicator, '0 0 52');
+                               setthink(it.killindicator, KillIndicator_Think);
+                               it.killindicator.nextthink = starttime + (it.lip) * 0.05;
+                               clientkilltime = max(clientkilltime, it.killindicator.nextthink + 0.05);
+                               it.killindicator.cnt = ceil(killtime);
+                       });
                        this.lip = 0;
                }
        }
@@ -2031,7 +2030,7 @@ void PlayerUseKey(entity this)
 
                        while(head) // find the closest acceptable target to enter
                        {
-                               if(head.vehicle_flags & VHF_ISVEHICLE)
+                               if(IS_VEHICLE(head))
                                if(!IS_DEAD(head))
                                if(!head.owner || ((head.vehicle_flags & VHF_MULTISLOT) && SAME_TEAM(head.owner, this)))
                                if(head.takedamage != DAMAGE_NO)
index 938cdd748bd60be5aebc661e36bd64fa868d7184..20b3b54c04bb5f4d106064c2cb6db090024ea674 100644 (file)
@@ -140,18 +140,17 @@ void assault_objective_decrease_use(entity this, entity actor, entity trigger)
 
 void assault_setenemytoobjective(entity this)
 {
-       entity objective;
-       for(objective = NULL; (objective = find(objective, targetname, this.target)); )
+       FOREACH_ENTITY_STRING(targetname, this.target,
        {
-               if(objective.classname == "target_objective")
+               if(it.classname == "target_objective")
                {
                        if(this.enemy == NULL)
-                               this.enemy = objective;
+                               this.enemy = it;
                        else
                                objerror(this, "more than one objective as target - fix the map!");
                        break;
                }
-       }
+       });
 
        if(this.enemy == NULL)
                objerror(this, "no objective as target - fix the map!");
@@ -167,32 +166,32 @@ bool assault_decreaser_sprite_visible(entity this, entity player, entity view)
 
 void target_objective_decrease_activate(entity this)
 {
-       entity ent, spr;
+       entity spr;
        this.owner = NULL;
-       for(ent = NULL; (ent = find(ent, target, this.targetname)); )
+       FOREACH_ENTITY_STRING(target, this.targetname,
        {
-               if(ent.assault_sprite != NULL)
+               if(it.assault_sprite != NULL)
                {
-                       WaypointSprite_Disown(ent.assault_sprite, waypointsprite_deadlifetime);
-                       if(ent.classname == "func_assault_destructible")
-                               ent.sprite = NULL; // TODO: just unsetting it?!
+                       WaypointSprite_Disown(it.assault_sprite, waypointsprite_deadlifetime);
+                       if(it.classname == "func_assault_destructible")
+                               it.sprite = NULL; // TODO: just unsetting it?!
                }
 
-               spr = WaypointSprite_SpawnFixed(WP_Assault, 0.5 * (ent.absmin + ent.absmax), ent, assault_sprite, RADARICON_OBJECTIVE);
+               spr = WaypointSprite_SpawnFixed(WP_Assault, 0.5 * (it.absmin + it.absmax), it, assault_sprite, RADARICON_OBJECTIVE);
                spr.assault_decreaser = this;
                spr.waypointsprite_visible_for_player = assault_decreaser_sprite_visible;
                spr.classname = "sprite_waypoint";
                WaypointSprite_UpdateRule(spr, assault_attacker_team, SPRITERULE_TEAMPLAY);
-               if(ent.classname == "func_assault_destructible")
+               if(it.classname == "func_assault_destructible")
                {
                        WaypointSprite_UpdateSprites(spr, WP_AssaultDefend, WP_AssaultDestroy, WP_AssaultDestroy);
-                       WaypointSprite_UpdateMaxHealth(spr, ent.max_health);
-                       WaypointSprite_UpdateHealth(spr, ent.health);
-                       ent.sprite = spr;
+                       WaypointSprite_UpdateMaxHealth(spr, it.max_health);
+                       WaypointSprite_UpdateHealth(spr, it.health);
+                       it.sprite = spr;
                }
                else
                        WaypointSprite_UpdateSprites(spr, WP_AssaultDefend, WP_AssaultPush, WP_AssaultPush);
-       }
+       });
 }
 
 void target_objective_decrease_findtarget(entity this)
@@ -426,8 +425,9 @@ spawnfunc(target_assault_roundstart)
 // legacy bot code
 void havocbot_goalrating_ast_targets(entity this, float ratingscale)
 {
-       entity ad, best, wp, tod;
-       float radius, found, bestvalue;
+       entity ad, best, wp;
+       float radius, bestvalue;
+       bool found;
        vector p;
 
        ad = findchain(classname, "func_assault_destructible");
@@ -441,18 +441,18 @@ void havocbot_goalrating_ast_targets(entity this, float ratingscale)
                        continue;
 
                found = false;
-               for(tod = NULL; (tod = find(tod, targetname, ad.target)); )
+               FOREACH_ENTITY_STRING(targetname, ad.target,
                {
-                       if(tod.classname == "target_objective_decrease")
+                       if(it.classname == "target_objective_decrease")
                        {
-                               if(tod.enemy.health > 0 && tod.enemy.health < ASSAULT_VALUE_INACTIVE)
+                               if(it.enemy.health > 0 && it.enemy.health < ASSAULT_VALUE_INACTIVE)
                                {
                                //      dprint(etos(ad),"\n");
                                        found = true;
                                        break;
                                }
                        }
-               }
+               });
 
                if(!found)
                {
index 6a217133a787f70ed859f872eed6af1bec91c25c..89740fbc430c5b5c6ee77d80f4a0a5d08912c410 100644 (file)
@@ -165,7 +165,6 @@ void dompoint_captured(entity this)
        WaypointSprite_UpdateSprites(this.sprite, msg, WP_Null, WP_Null);
 
        total_pps = 0, pps_red = 0, pps_blue = 0, pps_yellow = 0, pps_pink = 0;
-       for(head = NULL; (head = find(head, classname, "dom_controlpoint")) != NULL; )
        FOREACH_ENTITY_CLASS("dom_controlpoint", true, LAMBDA(
                if (autocvar_g_domination_point_amt)
                        points = autocvar_g_domination_point_amt;
@@ -362,16 +361,15 @@ void dom_controlpoint_setup(entity this)
 float total_controlpoints;
 void Domination_count_controlpoints()
 {
-       entity e;
        total_controlpoints = redowned = blueowned = yellowowned = pinkowned = 0;
-       for(e = NULL; (e = find(e, classname, "dom_controlpoint")) != NULL; )
+       FOREACH_ENTITY_CLASS("dom_controlpoint", true,
        {
                ++total_controlpoints;
-               redowned += (e.goalentity.team == NUM_TEAM_1);
-               blueowned += (e.goalentity.team == NUM_TEAM_2);
-               yellowowned += (e.goalentity.team == NUM_TEAM_3);
-               pinkowned += (e.goalentity.team == NUM_TEAM_4);
-       }
+               redowned += (it.goalentity.team == NUM_TEAM_1);
+               blueowned += (it.goalentity.team == NUM_TEAM_2);
+               yellowowned += (it.goalentity.team == NUM_TEAM_3);
+               pinkowned += (it.goalentity.team == NUM_TEAM_4);
+       });
 }
 
 float Domination_GetWinnerTeam()
index 7c949d8663625e207db2ece50ac03d993d999d2c..9d31506e6dfe77134f2dcf8fb225fa1e2a53f475 100644 (file)
@@ -112,15 +112,13 @@ float invasion_PickMonster(float supermonster_count)
 
 entity invasion_PickSpawn()
 {
-       entity e;
-
        RandomSelection_Init();
 
-       for(e = NULL;(e = find(e, classname, "invasion_spawnpoint")); )
+       FOREACH_ENTITY_CLASS("invasion_spawnpoint", true,
        {
-               RandomSelection_Add(e, 0, string_null, 1, ((time >= e.spawnshieldtime) ? 0.2 : 1)); // give recently used spawnpoints a very low rating
-               e.spawnshieldtime = time + autocvar_g_invasion_spawnpoint_spawn_delay;
-       }
+               RandomSelection_Add(it, 0, string_null, 1, ((time >= it.spawnshieldtime) ? 0.2 : 1)); // give recently used spawnpoints a very low rating
+               it.spawnshieldtime = time + autocvar_g_invasion_spawnpoint_spawn_delay;
+       });
 
        return RandomSelection_chosen_ent;
 }
index f6502dfd812335d794b6a43f79322a03f68a6402..7d85eec7eb06714b95d51bb170d1919789c01a1f 100644 (file)
@@ -269,7 +269,7 @@ void Portal_Touch(entity this)
                return; // handled by think
 
        if(!autocvar_g_vehicles_teleportable)
-       if(other.vehicle_flags & VHF_ISVEHICLE)
+       if(IS_VEHICLE(other))
                return; // no teleporting vehicles?
 
        if(!this.enemy)
index f55fb1122aee7e5686b4ee83aa43324da388633c..21112d93f3e55f1063723dcdc463b5b4c4f265b5 100644 (file)
@@ -249,21 +249,19 @@ vector Spawn_Score(entity this, entity spot, float mindist, float teamcheck)
        vector spawn_score = prio * '1 0 0' + shortest * '0 1 0';
 
        // filter out spots for assault
-       if(spot.target != "") {
-               entity ent;
-               float found;
-
-               found = 0;
-               for(ent = NULL; (ent = find(ent, targetname, spot.target)); )
+       if(spot.target != "")
+       {
+               int found = 0;
+               FOREACH_ENTITY_STRING(targetname, spot.target,
                {
                        ++found;
-                       if(ent.spawn_evalfunc)
+                       if(it.spawn_evalfunc)
                        {
-                               spawn_score = ent.spawn_evalfunc(ent, this, spot, spawn_score);
+                               spawn_score = it.spawn_evalfunc(it, this, spot, spawn_score);
                                if(spawn_score.x < 0)
                                        return spawn_score;
                        }
-               }
+               });
 
                if(!found)
                {
index 70284a8f4b421055768b2db0658199ab7d4bd83c..0288347ee1f1e61bdaa47cc70b93479c04f2f02f 100644 (file)
@@ -21,7 +21,7 @@ void Send_WeaponComplain(entity e, float wpn, float type)
 void Weapon_whereis(Weapon this, entity cl)
 {
        if (!autocvar_g_showweaponspawns) return;
-       for (entity it = NULL; (it = findfloat(it, weapon, this.m_id)); )
+       FOREACH_ENTITY_FLOAT(weapon, this.m_id,
        {
                if (it.classname == "droppedweapon" && autocvar_g_showweaponspawns < 2)
                        continue;
@@ -37,7 +37,7 @@ void Weapon_whereis(Weapon this, entity cl)
                        RADARICON_NONE
                );
                wp.wp_extra = this.m_id;
-       }
+       });
 }
 
 bool client_hasweapon(entity this, Weapon wpn, float andammo, bool complain)
index 21057e4a0b525a02a14c995b9294f78b64bee52d..77904aca5d0912713f3e1e57402d224f7473eb38 100644 (file)
@@ -214,8 +214,13 @@ bool weapon_prepareattack_checkammo(Weapon thiswep, entity actor, bool secondary
        if (ammo) return true;
        // always keep the Mine Layer if we placed mines, so that we can detonate them
        if (thiswep == WEP_MINE_LAYER)
-               for (entity mine; (mine = find(mine, classname, "mine")); )
-                       if (mine.owner == actor) return false;
+       {
+               FOREACH_ENTITY_ENT(owner, actor,
+               {
+                       if(it.classname != "mine") continue;
+                       if(it.owner == actor) return false;
+               });
+       }
 
        if (thiswep == WEP_SHOTGUN)
                if (!secondary && WEP_CVAR(shotgun, secondary) == 1) return false;           // no clicking, just allow