From 22f00dee87cbca43de8cf802108b4681877cc4ec Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 1 Jan 2016 21:05:01 +1000 Subject: [PATCH] More loops --- qcsrc/common/t_items.qc | 9 ++--- qcsrc/common/util.qc | 36 ++++++++++---------- qcsrc/common/weapons/weapon/devastator.qc | 41 +++++++++-------------- 3 files changed, 39 insertions(+), 47 deletions(-) diff --git a/qcsrc/common/t_items.qc b/qcsrc/common/t_items.qc index 945abd531..f78c8d134 100644 --- a/qcsrc/common/t_items.qc +++ b/qcsrc/common/t_items.qc @@ -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); diff --git a/qcsrc/common/util.qc b/qcsrc/common/util.qc index 55a5274f4..427bdb84b 100644 --- a/qcsrc/common/util.qc +++ b/qcsrc/common/util.qc @@ -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) diff --git a/qcsrc/common/weapons/weapon/devastator.qc b/qcsrc/common/weapons/weapon/devastator.qc index d632d7776..f334f2a2b 100644 --- a/qcsrc/common/weapons/weapon/devastator.qc +++ b/qcsrc/common/weapons/weapon/devastator.qc @@ -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 -- 2.39.2