]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
More loops
authorMario <mario@smbclan.net>
Fri, 1 Jan 2016 11:05:01 +0000 (21:05 +1000)
committerMario <mario@smbclan.net>
Fri, 1 Jan 2016 11:05:01 +0000 (21:05 +1000)
qcsrc/common/t_items.qc
qcsrc/common/util.qc
qcsrc/common/weapons/weapon/devastator.qc

index 945abd531fc2eeeede79634613226758ff0d7da4..f78c8d1340cc3d166af3ba818eec5c3e9306ccd9 100644 (file)
@@ -1425,10 +1425,11 @@ void target_items_use()
                return;
        EXACTTRIGGER_TOUCH;
 
-       entity e;
-       for(e = world; (e = find(e, classname, "droppedweapon")); )
-               if(e.enemy == activator)
-                       remove(e);
+       FOREACH_ENTITY_ENT(enemy, activator,
+       {
+               if(it.classname == "droppedweapon")
+                       remove(it);
+       });
 
        if(GiveItems(activator, 0, tokenize_console(self.netname)))
                centerprint(activator, self.message);
index 55a5274f475e9ec9b3e7433d40f17191c774680b..427bdb84b4662b7d2347b1c190f84102589cb4b5 100644 (file)
@@ -584,7 +584,6 @@ void get_mi_min_max_texcoords(float mode)
 float cvar_settemp(string tmp_cvar, string tmp_value)
 {
        float created_saved_value;
-       entity e;
 
        created_saved_value = 0;
 
@@ -600,14 +599,16 @@ float cvar_settemp(string tmp_cvar, string tmp_value)
                return 0;
        }
 
-       for(e = world; (e = find(e, classname, "saved_cvar_value")); )
-               if(e.netname == tmp_cvar)
-                       created_saved_value = -1; // skip creation
+       FOREACH_ENTITY_CLASS("saved_cvar_value", it.netname == tmp_cvar,
+       {
+               created_saved_value = -1; // skip creation
+               break; // no need to continue
+       });
 
        if(created_saved_value != -1)
        {
                // creating a new entity to keep track of this cvar
-               e = new(saved_cvar_value);
+               entity e = new(saved_cvar_value);
                make_pure(e);
                e.netname = strzone(tmp_cvar);
                e.message = strzone(cvar_string(tmp_cvar));
@@ -620,25 +621,24 @@ float cvar_settemp(string tmp_cvar, string tmp_value)
        return created_saved_value;
 }
 
-float cvar_settemp_restore()
+int cvar_settemp_restore()
 {
-       float i = 0;
-       entity e = world;
-       while((e = find(e, classname, "saved_cvar_value")))
+       int j = 0;
+       FOREACH_ENTITY_CLASS("saved_cvar_value", true,
        {
-               if(cvar_type(e.netname))
+               if(cvar_type(it.netname))
                {
-                       cvar_set(e.netname, e.message);
-                       strunzone(e.netname);
-                       strunzone(e.message);
-                       remove(e);
-                       ++i;
+                       cvar_set(it.netname, it.message);
+                       strunzone(it.netname);
+                       strunzone(it.message);
+                       remove(it);
+                       ++j;
                }
                else
-                       LOG_INFOF("Error: cvar %s doesn't exist anymore! It can still be restored once it's manually recreated.\n", e.netname);
-       }
+                       LOG_INFOF("Error: cvar %s doesn't exist anymore! It can still be restored once it's manually recreated.\n", it.netname);
+       });
 
-       return i;
+       return j;
 }
 
 float textLengthUpToWidth(string theText, float maxWidth, vector theSize, textLengthUpToWidth_widthFunction_t w)
index d632d7776a87f7886a976f7811fc1b26b54aaaba..f334f2a2b5fb9c1afc5a0f830abc642e42868c02 100644 (file)
@@ -439,7 +439,7 @@ void W_Devastator_Attack(Weapon thiswep)
                        if(skill >= 2) // skill 0 and 1 bots won't detonate rockets!
                        {
                                // decide whether to detonate rockets
-                               entity missile, targetlist, targ;
+                               entity targetlist, targ;
                                float edgedamage, coredamage, edgeradius, recipricoledgeradius, d;
                                float selfdamage, teamdamage, enemydamage;
                                edgedamage = WEP_CVAR(devastator, edgedamage);
@@ -450,18 +450,14 @@ void W_Devastator_Attack(Weapon thiswep)
                                teamdamage = 0;
                                enemydamage = 0;
                                targetlist = findchainfloat(bot_attack, true);
-                               missile = find(world, classname, "rocket");
-                               while(missile)
+                               FOREACH_ENTITY_ENT(realowner, self,
                                {
-                                       if(missile.realowner != self)
-                                       {
-                                               missile = find(missile, classname, "rocket");
-                                               continue;
-                                       }
+                                       if(it.classname != "rocket") continue;
+
                                        targ = targetlist;
                                        while(targ)
                                        {
-                                               d = vlen(targ.origin + (targ.mins + targ.maxs) * 0.5 - missile.origin);
+                                               d = vlen(targ.origin + (targ.mins + targ.maxs) * 0.5 - it.origin);
                                                d = bound(0, edgedamage + (coredamage - edgedamage) * sqrt(1 - d * recipricoledgeradius), 10000);
                                                // count potential damage according to type of target
                                                if(targ == self)
@@ -472,8 +468,7 @@ void W_Devastator_Attack(Weapon thiswep)
                                                        enemydamage = enemydamage + d;
                                                targ = targ.chain;
                                        }
-                                       missile = find(missile, classname, "rocket");
-                               }
+                               });
                                float desirabledamage;
                                desirabledamage = enemydamage;
                                if(time > self.invincible_finished && time > self.spawnshieldtime)
@@ -481,15 +476,11 @@ void W_Devastator_Attack(Weapon thiswep)
                                if(teamplay && self.team)
                                        desirabledamage = desirabledamage - teamdamage;
 
-                               missile = find(world, classname, "rocket");
-                               while(missile)
+                               FOREACH_ENTITY_ENT(realowner, self,
                                {
-                                       if(missile.realowner != self)
-                                       {
-                                               missile = find(missile, classname, "rocket");
-                                               continue;
-                                       }
-                                       makevectors(missile.v_angle);
+                                       if(it.classname != "rocket") continue;
+
+                                       makevectors(it.v_angle);
                                        targ = targetlist;
                                        if(skill > 9) // normal players only do this for the target they are tracking
                                        {
@@ -497,25 +488,25 @@ void W_Devastator_Attack(Weapon thiswep)
                                                while(targ)
                                                {
                                                        if(
-                                                               (v_forward * normalize(missile.origin - targ.origin)< 0.1)
+                                                               (v_forward * normalize(it.origin - targ.origin)< 0.1)
                                                                && desirabledamage > 0.1*coredamage
                                                        )self.BUTTON_ATCK2 = true;
                                                        targ = targ.chain;
                                                }
-                                       }else{
+                                       }
+                                       else
+                                       {
                                                float distance; distance= bound(300,vlen(self.origin-self.enemy.origin),30000);
                                                //As the distance gets larger, a correct detonation gets near imposible
                                                //Bots are assumed to use the rocket spawnfunc_light to see if the rocket gets near a player
-                                               if(v_forward * normalize(missile.origin - self.enemy.origin)< 0.1)
+                                               if(v_forward * normalize(it.origin - self.enemy.origin)< 0.1)
                                                        if(IS_PLAYER(self.enemy))
                                                                if(desirabledamage >= 0.1*coredamage)
                                                                        if(random()/distance*300 > frametime*bound(0,(10-skill)*0.2,1))
                                                                                self.BUTTON_ATCK2 = true;
                                        //      dprint(ftos(random()/distance*300),">");dprint(ftos(frametime*bound(0,(10-skill)*0.2,1)),"\n");
                                        }
-
-                                       missile = find(missile, classname, "rocket");
-                               }
+                               });
                                // if we would be doing at X percent of the core damage, detonate it
                                // but don't fire a new shot at the same time!
                                if(desirabledamage >= 0.75 * coredamage) //this should do group damage in rare fortunate events