float cvar_settemp(string tmp_cvar, string tmp_value)
{
float created_saved_value;
- entity e;
created_saved_value = 0;
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));
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)
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);
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)
enemydamage = enemydamage + d;
targ = targ.chain;
}
- missile = find(missile, classname, "rocket");
- }
+ });
float desirabledamage;
desirabledamage = enemydamage;
if(time > self.invincible_finished && time > self.spawnshieldtime)
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
{
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