]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/gamemodes/gamemode/onslaught/onslaught.qc
Merge branch 'master' into terencehill/scoreboard_panel_2
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / gamemodes / gamemode / onslaught / onslaught.qc
index 6242414ae0b275e8b1ded5dcf01880e6c4a32bee..713c5d7de06e3abf40c19b27f211d0759aef5a1e 100644 (file)
@@ -120,8 +120,6 @@ void havocbot_goalrating_enemyplayers(entity this, float ratingscale, vector org
 
 // score rule declarations
 const int ST_ONS_CAPS = 1;
-const int SP_ONS_CAPS = 4;
-const int SP_ONS_TAKES = 6;
 
 #endif
 #endif
@@ -238,14 +236,14 @@ void onslaught_updatelinks()
 {
        entity l;
        // first check if the game has ended
-       LOG_DEBUG("--- updatelinks ---\n");
+       LOG_DEBUG("--- updatelinks ---");
        // mark generators as being shielded and networked
        for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
        {
                if (l.iscaptured)
-                       LOG_DEBUG(strcat(etos(l), " (generator) belongs to team ", ftos(l.team), "\n"));
+                       LOG_DEBUG(etos(l), " (generator) belongs to team ", ftos(l.team));
                else
-                       LOG_DEBUG(strcat(etos(l), " (generator) is destroyed\n"));
+                       LOG_DEBUG(etos(l), " (generator) is destroyed");
                l.islinked = l.iscaptured;
                l.isshielded = l.iscaptured;
                l.sprite.SendFlags |= 16;
@@ -257,7 +255,7 @@ void onslaught_updatelinks()
                l.isshielded = true;
                int i;
                for(i = 0; i < 17; ++i) { l.isgenneighbor[i] = false; l.iscpneighbor[i] = false; }
-               LOG_DEBUG(strcat(etos(l), " (point) belongs to team ", ftos(l.team), "\n"));
+               LOG_DEBUG(etos(l), " (point) belongs to team ", ftos(l.team));
                l.sprite.SendFlags |= 16;
        }
        // flow power outward from the generators through the network
@@ -277,13 +275,13 @@ void onslaught_updatelinks()
                                                {
                                                        stop = false;
                                                        l.goalentity.islinked = true;
-                                                       LOG_DEBUG(strcat(etos(l), " (link) is marking ", etos(l.goalentity), " (point) because its team matches ", etos(l.enemy), " (point)\n"));
+                                                       LOG_DEBUG(etos(l), " (link) is marking ", etos(l.goalentity), " (point) because its team matches ", etos(l.enemy), " (point)");
                                                }
                                                else if (!l.enemy.islinked)
                                                {
                                                        stop = false;
                                                        l.enemy.islinked = true;
-                                                       LOG_DEBUG(strcat(etos(l), " (link) is marking ", etos(l.enemy), " (point) because its team matches ", etos(l.goalentity), " (point)\n"));
+                                                       LOG_DEBUG(etos(l), " (link) is marking ", etos(l.enemy), " (point) because its team matches ", etos(l.goalentity), " (point)");
                                                }
                                        }
                }
@@ -296,7 +294,7 @@ void onslaught_updatelinks()
                {
                        if(DIFF_TEAM(l.goalentity, l.enemy))
                        {
-                               LOG_DEBUG(strcat(etos(l), " (link) is unshielding ", etos(l.enemy), " (point) because its team does not match ", etos(l.goalentity), " (point)\n"));
+                               LOG_DEBUG(etos(l), " (link) is unshielding ", etos(l.enemy), " (point) because its team does not match ", etos(l.goalentity), " (point)");
                                l.enemy.isshielded = false;
                        }
                        if(l.goalentity.classname == "onslaught_generator")
@@ -308,7 +306,7 @@ void onslaught_updatelinks()
                {
                        if(DIFF_TEAM(l.goalentity, l.enemy))
                        {
-                               LOG_DEBUG(strcat(etos(l), " (link) is unshielding ", etos(l.goalentity), " (point) because its team does not match ", etos(l.enemy), " (point)\n"));
+                               LOG_DEBUG(etos(l), " (link) is unshielding ", etos(l.goalentity), " (point) because its team does not match ", etos(l.enemy), " (point)");
                                l.goalentity.isshielded = false;
                        }
                        if(l.enemy.classname == "onslaught_generator")
@@ -322,13 +320,13 @@ void onslaught_updatelinks()
        {
                if (l.isshielded)
                {
-                       LOG_DEBUG(strcat(etos(l), " (generator) is shielded\n"));
+                       LOG_DEBUG(etos(l), " (generator) is shielded");
                        l.takedamage = DAMAGE_NO;
                        l.bot_attack = false;
                }
                else
                {
-                       LOG_DEBUG(strcat(etos(l), " (generator) is not shielded\n"));
+                       LOG_DEBUG(etos(l), " (generator) is not shielded");
                        l.takedamage = DAMAGE_AIM;
                        l.bot_attack = true;
                }
@@ -340,7 +338,7 @@ void onslaught_updatelinks()
        {
                if (l.isshielded)
                {
-                       LOG_DEBUG(strcat(etos(l), " (point) is shielded\n"));
+                       LOG_DEBUG(etos(l), " (point) is shielded");
                        if (l.goalentity)
                        {
                                l.goalentity.takedamage = DAMAGE_NO;
@@ -349,7 +347,7 @@ void onslaught_updatelinks()
                }
                else
                {
-                       LOG_DEBUG(strcat(etos(l), " (point) is not shielded\n"));
+                       LOG_DEBUG(etos(l), " (point) is not shielded");
                        if (l.goalentity)
                        {
                                l.goalentity.takedamage = DAMAGE_AIM;
@@ -358,13 +356,11 @@ void onslaught_updatelinks()
                }
                ons_ControlPoint_UpdateSprite(l);
        }
-       l = findchain(classname, "ons_captureshield");
-       while(l)
+       FOREACH_ENTITY_CLASS("ons_captureshield", true,
        {
-               l.team = l.enemy.team;
-               l.colormap = l.enemy.colormap;
-               l = l.chain;
-       }
+               it.team = it.enemy.team;
+               it.colormap = it.enemy.colormap;
+       });
 }
 
 
@@ -421,7 +417,7 @@ void ons_DelayedLinkSetup(entity this)
        if(!this.goalentity) { objerror(this, "can not find target\n"); }
        if(!this.enemy) { objerror(this, "can not find target2\n"); }
 
-       LOG_DEBUG(strcat(etos(this.goalentity), " linked with ", etos(this.enemy), "\n"));
+       LOG_DEBUG(etos(this.goalentity), " linked with ", etos(this.enemy));
        this.SendFlags |= 3;
        setthink(this, ons_Link_CheckUpdate);
        this.nextthink = time;
@@ -553,7 +549,7 @@ void ons_ControlPoint_Icon_Damage(entity this, entity inflictor, entity attacker
                        setmodel_fixsize(this.owner, MDL_ONS_CP_PAD1);
                //setsize(this, '-32 -32 0', '32 32 8');
 
-               remove(this);
+               delete(this);
        }
 
        this.SendFlags |= CPSF_STATUS;
@@ -821,7 +817,7 @@ void ons_ControlPoint_Think(entity this)
 void ons_ControlPoint_Reset(entity this)
 {
        if(this.goalentity)
-               remove(this.goalentity);
+               delete(this.goalentity);
 
        this.goalentity = NULL;
        this.team = 0;
@@ -1289,8 +1285,6 @@ void Onslaught_RoundStart()
 
 void havocbot_goalrating_ons_offenseitems(entity this, float ratingscale, vector org, float sradius)
 {
-       entity head;
-       float t, c;
        bool needarmor = false, needweapons = false;
 
        // Needs armor/health?
@@ -1298,7 +1292,7 @@ void havocbot_goalrating_ons_offenseitems(entity this, float ratingscale, vector
                needarmor = true;
 
        // Needs weapons?
-       c = 0;
+       int c = 0;
        FOREACH(Weapons, it != WEP_Null, {
                if(this.weapons & (it.m_wepset))
                if(++c >= 4)
@@ -1311,29 +1305,27 @@ void havocbot_goalrating_ons_offenseitems(entity this, float ratingscale, vector
        if(!needweapons && !needarmor)
                return;
 
-       LOG_DEBUG(strcat(this.netname, " needs weapons ", ftos(needweapons) , "\n"));
-       LOG_DEBUG(strcat(this.netname, " needs armor ", ftos(needarmor) , "\n"));
+       LOG_DEBUG(this.netname, " needs weapons ", ftos(needweapons));
+       LOG_DEBUG(this.netname, " needs armor ", ftos(needarmor));
 
        // See what is around
-       head = findchainfloat(bot_pickup, true);
-       while (head)
+       FOREACH_ENTITY_FLOAT(bot_pickup, true,
        {
                // gather health and armor only
-               if (head.solid)
-               if ( ((head.health || head.armorvalue) && needarmor) || (head.weapons && needweapons ) )
-               if (vdist(head.origin - org, <, sradius))
+               if (it.solid)
+               if ( ((it.health || it.armorvalue) && needarmor) || (it.weapons && needweapons ) )
+               if (vdist(it.origin - org, <, sradius))
                {
-                       t = head.bot_pickupevalfunc(this, head);
+                       int t = it.bot_pickupevalfunc(this, it);
                        if (t > 0)
-                               navigation_routerating(this, head, t * ratingscale, 500);
+                               navigation_routerating(this, it, t * ratingscale, 500);
                }
-               head = head.chain;
-       }
+       });
 }
 
 void havocbot_role_ons_setrole(entity this, int role)
 {
-       LOG_DEBUG(strcat(this.netname," switched to "));
+       LOG_DEBUG(this.netname," switched to ");
        switch(role)
        {
                case HAVOCBOT_ONS_ROLE_DEFENSE:
@@ -1355,7 +1347,7 @@ void havocbot_role_ons_setrole(entity this, int role)
                        this.havocbot_role_timeout = 0;
                        break;
        }
-       LOG_DEBUG("\n");
+       LOG_DEBUG("");
 }
 
 void havocbot_goalrating_ons_controlpoints_attack(entity this, float ratingscale)
@@ -1411,7 +1403,7 @@ void havocbot_goalrating_ons_controlpoints_attack(entity this, float ratingscale
        if (!cp)
                return;
 
-       LOG_DEBUG(strcat(this.netname, " chose cp ranked ", ftos(bestvalue), "\n"));
+       LOG_DEBUG(this.netname, " chose cp ranked ", ftos(bestvalue));
 
        if(cp.goalentity)
        {
@@ -1452,12 +1444,12 @@ void havocbot_goalrating_ons_controlpoints_attack(entity this, float ratingscale
                {
                        navigation_routerating(this, cp, ratingscale, 10000);
                }
-               LOG_DEBUG(strcat(this.netname, " found an attackable controlpoint at ", vtos(cp.origin) ,"\n"));
+               LOG_DEBUG(this.netname, " found an attackable controlpoint at ", vtos(cp.origin));
        }
        else
        {
                // Should be touched
-               LOG_DEBUG(strcat(this.netname, " found a touchable controlpoint at ", vtos(cp.origin) ,"\n"));
+               LOG_DEBUG(this.netname, " found a touchable controlpoint at ", vtos(cp.origin));
                found = false;
 
                // Look for auto generated waypoint
@@ -1510,7 +1502,7 @@ bool havocbot_goalrating_ons_generator_attack(entity this, float ratingscale)
 
                if(bestwp)
                {
-                       LOG_DEBUG("waypoints found around generator\n");
+                       LOG_DEBUG("waypoints found around generator");
                        navigation_routerating(this, bestwp, ratingscale, 10000);
                        bestwp.cnt += 1;
 
@@ -1523,7 +1515,7 @@ bool havocbot_goalrating_ons_generator_attack(entity this, float ratingscale)
                }
                else
                {
-                       LOG_DEBUG("generator found without waypoints around\n");
+                       LOG_DEBUG("generator found without waypoints around");
                        // if there aren't waypoints near the generator go straight to it
                        navigation_routerating(this, g, ratingscale, 10000);
                        this.havocbot_attack_time = 0;
@@ -1597,26 +1589,22 @@ void havocbot_ons_reset_role(entity this)
  */
 entity ons_Nearest_ControlPoint(entity this, vector pos, float max_dist)
 {
-       entity tmp_entity, closest_target = NULL;
-       tmp_entity = findchain(classname, "onslaught_controlpoint");
-       while(tmp_entity)
+       entity closest_target = NULL;
+       FOREACH_ENTITY_CLASS("onslaught_controlpoint", true,
        {
-               if(SAME_TEAM(tmp_entity, this))
-               if(tmp_entity.iscaptured)
-               if(max_dist <= 0 || vdist(tmp_entity.origin - pos, <=, max_dist))
-               if(vlen2(tmp_entity.origin - pos) <= vlen2(closest_target.origin - pos) || closest_target == NULL)
-                       closest_target = tmp_entity;
-               tmp_entity = tmp_entity.chain;
-       }
-       tmp_entity = findchain(classname, "onslaught_generator");
-       while(tmp_entity)
+               if(SAME_TEAM(it, this))
+               if(it.iscaptured)
+               if(max_dist <= 0 || vdist(it.origin - pos, <=, max_dist))
+               if(vlen2(it.origin - pos) <= vlen2(closest_target.origin - pos) || closest_target == NULL)
+                       closest_target = it;
+       });
+       FOREACH_ENTITY_CLASS("onslaught_generator", true,
        {
-               if(SAME_TEAM(tmp_entity, this))
-               if(max_dist <= 0 || vdist(tmp_entity.origin - pos, <, max_dist))
-               if(vlen2(tmp_entity.origin - pos) <= vlen2(closest_target.origin - pos) || closest_target == NULL)
-                       closest_target = tmp_entity;
-               tmp_entity = tmp_entity.chain;
-       }
+               if(SAME_TEAM(it, this))
+               if(max_dist <= 0 || vdist(it.origin - pos, <, max_dist))
+               if(vlen2(it.origin - pos) <= vlen2(closest_target.origin - pos) || closest_target == NULL)
+                       closest_target = it;
+       });
 
        return closest_target;
 }
@@ -1628,45 +1616,39 @@ entity ons_Nearest_ControlPoint(entity this, vector pos, float max_dist)
  */
 entity ons_Nearest_ControlPoint_2D(entity this, vector pos, float max_dist)
 {
-       entity tmp_entity, closest_target = NULL;
+       entity closest_target = NULL;
        vector delta;
        float smallest_distance = 0, distance;
 
-       tmp_entity = findchain(classname, "onslaught_controlpoint");
-       while(tmp_entity)
+       FOREACH_ENTITY_CLASS("onslaught_controlpoint", true,
        {
-               delta = tmp_entity.origin - pos;
+               delta = it.origin - pos;
                delta_z = 0;
                distance = vlen(delta);
 
-               if(SAME_TEAM(tmp_entity, this))
-               if(tmp_entity.iscaptured)
+               if(SAME_TEAM(it, this))
+               if(it.iscaptured)
                if(max_dist <= 0 || distance <= max_dist)
                if(closest_target == NULL || distance <= smallest_distance )
                {
-                       closest_target = tmp_entity;
+                       closest_target = it;
                        smallest_distance = distance;
                }
-
-               tmp_entity = tmp_entity.chain;
-       }
-       tmp_entity = findchain(classname, "onslaught_generator");
-       while(tmp_entity)
+       });
+       FOREACH_ENTITY_CLASS("onslaught_generator", true,
        {
-               delta = tmp_entity.origin - pos;
+               delta = it.origin - pos;
                delta_z = 0;
                distance = vlen(delta);
 
-               if(SAME_TEAM(tmp_entity, this))
+               if(SAME_TEAM(it, this))
                if(max_dist <= 0 || distance <= max_dist)
                if(closest_target == NULL || distance <= smallest_distance )
                {
-                       closest_target = tmp_entity;
+                       closest_target = it;
                        smallest_distance = distance;
                }
-
-               tmp_entity = tmp_entity.chain;
-       }
+       });
 
        return closest_target;
 }
@@ -1675,23 +1657,18 @@ entity ons_Nearest_ControlPoint_2D(entity this, vector pos, float max_dist)
  */
 int ons_Count_SelfControlPoints(entity this)
 {
-       entity tmp_entity;
-       tmp_entity = findchain(classname, "onslaught_controlpoint");
        int n = 0;
-       while(tmp_entity)
+       FOREACH_ENTITY_CLASS("onslaught_controlpoint", true,
        {
-               if(SAME_TEAM(tmp_entity, this))
-               if(tmp_entity.iscaptured)
+               if(SAME_TEAM(it, this))
+               if(it.iscaptured)
                        n++;
-               tmp_entity = tmp_entity.chain;
-       }
-       tmp_entity = findchain(classname, "onslaught_generator");
-       while(tmp_entity)
+       });
+       FOREACH_ENTITY_CLASS("onslaught_generator", true,
        {
-               if(SAME_TEAM(tmp_entity, this))
+               if(SAME_TEAM(it, this))
                        n++;
-               tmp_entity = tmp_entity.chain;
-       }
+       });
        return n;
 }
 
@@ -1944,7 +1921,7 @@ void ons_MonsterSpawn_Delayed(entity this)
 {
        entity own = this.owner;
 
-       if(!own) { remove(this); return; }
+       if(!own) { delete(this); return; }
 
        if(own.targetname)
        {
@@ -1957,7 +1934,7 @@ void ons_MonsterSpawn_Delayed(entity this)
                }
        }
 
-       remove(this);
+       delete(this);
 }
 
 MUTATOR_HOOKFUNCTION(ons, MonsterSpawn)
@@ -1973,7 +1950,7 @@ void ons_TurretSpawn_Delayed(entity this)
 {
        entity own = this.owner;
 
-       if(!own) { remove(this); return; }
+       if(!own) { delete(this); return; }
 
        if(own.targetname)
        {
@@ -1987,7 +1964,7 @@ void ons_TurretSpawn_Delayed(entity this)
                }
        }
 
-       remove(this);
+       delete(this);
 }
 
 MUTATOR_HOOKFUNCTION(ons, TurretSpawn)
@@ -2199,7 +2176,7 @@ keys:
  */
 spawnfunc(onslaught_link)
 {
-       if(!g_onslaught) { remove(this); return; }
+       if(!g_onslaught) { delete(this); return; }
 
        if (this.target == "" || this.target2 == "")
                objerror(this, "target and target2 must be set\n");
@@ -2224,7 +2201,7 @@ keys:
 
 spawnfunc(onslaught_controlpoint)
 {
-       if(!g_onslaught) { remove(this); return; }
+       if(!g_onslaught) { delete(this); return; }
 
        ons_ControlPoint_Setup(this);
 }
@@ -2240,7 +2217,7 @@ keys:
  */
 spawnfunc(onslaught_generator)
 {
-       if(!g_onslaught) { remove(this); return; }
+       if(!g_onslaught) { delete(this); return; }
        if(!this.team) { objerror(this, "team must be set"); }
 
        ons_GeneratorSetup(this);
@@ -2250,9 +2227,14 @@ spawnfunc(onslaught_generator)
 void ons_ScoreRules()
 {
        CheckAllowedTeams(NULL);
-       ScoreRules_basics(((c4>=0) ? 4 : (c3>=0) ? 3 : 2), SFL_SORT_PRIO_PRIMARY, 0, true);
+       int teams = 0;
+       if(c1 >= 0) teams |= BIT(0);
+       if(c2 >= 0) teams |= BIT(1);
+       if(c3 >= 0) teams |= BIT(2);
+       if(c4 >= 0) teams |= BIT(3);
+       ScoreRules_basics(teams, SFL_SORT_PRIO_PRIMARY, 0, true);
        ScoreInfo_SetLabel_TeamScore  (ST_ONS_CAPS,     "destroyed", SFL_SORT_PRIO_PRIMARY);
-       ScoreInfo_SetLabel_PlayerScore(SP_ONS_CAPS,     "caps",      SFL_SORT_PRIO_SECONDARY);
+       ScoreInfo_SetLabel_PlayerScore(SP_ONS_CAPS,    "caps",      SFL_SORT_PRIO_SECONDARY);
        ScoreInfo_SetLabel_PlayerScore(SP_ONS_TAKES,    "takes",     0);
        ScoreRules_basics_end();
 }