]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/monsters/sv_monsters.qc
Cleanse the touch functions of the other evil
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / monsters / sv_monsters.qc
index 945a1de35ec341ee01004535d28969aab3407f0d..795e0310a263f35fd922478f1e9a1ad1125ad47d 100644 (file)
@@ -123,29 +123,26 @@ entity Monster_FindTarget(entity mon)
 {
        if(MUTATOR_CALLHOOK(MonsterFindTarget)) { return mon.enemy; } // Handled by a mutator
 
-       entity head, closest_target = world;
-       head = findradius(mon.origin, mon.target_range);
+       entity closest_target = NULL;
 
-       while(head) // find the closest acceptable target to pass to
+       // find the closest acceptable target to pass to
+       FOREACH_ENTITY_RADIUS(mon.origin, mon.target_range, it.monster_attack,
        {
-               if(head.monster_attack)
-               if(Monster_ValidTarget(mon, head))
+               if(Monster_ValidTarget(mon, it))
                {
                        // if it's a player, use the view origin as reference (stolen from RadiusDamage functions in g_damage.qc)
-                       vector head_center = CENTER_OR_VIEWOFS(head);
+                       vector head_center = CENTER_OR_VIEWOFS(it);
                        vector ent_center = CENTER_OR_VIEWOFS(mon);
 
                        if(closest_target)
                        {
                                vector closest_target_center = CENTER_OR_VIEWOFS(closest_target);
                                if(vlen2(ent_center - head_center) < vlen2(ent_center - closest_target_center))
-                                       { closest_target = head; }
+                                       { closest_target = it; }
                        }
-                       else { closest_target = head; }
+                       else { closest_target = it; }
                }
-
-               head = head.chain;
-       }
+       });
 
        return closest_target;
 }
@@ -394,7 +391,7 @@ bool Monster_Attack_Leap_Check(entity this, vector vel)
        return true;
 }
 
-bool Monster_Attack_Leap(entity this, vector anm, void(entity this) touchfunc, vector vel, float animtime)
+bool Monster_Attack_Leap(entity this, vector anm, void(entity this, entity toucher) touchfunc, vector vel, float animtime)
 {
        if(!Monster_Attack_Leap_Check(this, vel))
                return false;
@@ -418,7 +415,7 @@ bool Monster_Attack_Leap(entity this, vector anm, void(entity this) touchfunc, v
 
 void Monster_Attack_Check(entity this, entity targ)
 {
-       if((this == world || targ == world)
+       if((this == NULL || targ == NULL)
        || (!this.monster_attackfunc)
        || (time < this.attack_finished_single[0])
        ) { return; }
@@ -466,15 +463,15 @@ void Monster_UpdateModel(entity this)
        mon.mr_anim(mon, this);
 }
 
-void Monster_Touch(entity this)
+void Monster_Touch(entity this, entity toucher)
 {
-       if(other == world) { return; }
+       if(toucher == NULL) { return; }
 
-       if(other.monster_attack)
-       if(this.enemy != other)
-       if(!IS_MONSTER(other))
-       if(Monster_ValidTarget(this, other))
-               this.enemy = other;
+       if(toucher.monster_attack)
+       if(this.enemy != toucher)
+       if(!IS_MONSTER(toucher))
+       if(Monster_ValidTarget(this, toucher))
+               this.enemy = toucher;
 }
 
 void Monster_Miniboss_Check(entity this)
@@ -555,7 +552,7 @@ vector Monster_Move_Target(entity this, entity targ)
                targ_origin = WarpZone_RefSys_TransformOrigin(this.enemy, this, targ_origin); // origin of target as seen by the monster (us)
                WarpZone_TraceLine(this.origin, targ_origin, MOVE_NOMONSTERS, this);
 
-               if((this.enemy == world)
+               if((this.enemy == NULL)
                        || (IS_DEAD(this.enemy) || this.enemy.health < 1)
                        || (STAT(FROZEN, this.enemy))
                        || (this.enemy.flags & FL_NOTARGET)
@@ -564,13 +561,13 @@ vector Monster_Move_Target(entity this, entity targ)
                        || (vdist(this.origin - targ_origin, >, this.target_range))
                        || ((trace_fraction < 1) && (trace_ent != this.enemy)))
                {
-                       this.enemy = world;
+                       this.enemy = NULL;
                        this.pass_distance = 0;
                }
 
                if(this.enemy)
                {
-                       /*WarpZone_TrailParticles(world, particleeffectnum(EFFECT_RED_PASS), this.origin, targ_origin);
+                       /*WarpZone_TrailParticles(NULL, particleeffectnum(EFFECT_RED_PASS), this.origin, targ_origin);
                        print("Trace origin: ", vtos(targ_origin), "\n");
                        print("Target origin: ", vtos(this.enemy.origin), "\n");
                        print("My origin: ", vtos(this.origin), "\n"); */
@@ -690,7 +687,7 @@ void Monster_CalculateVelocity(entity this, vector to, vector from, float turnra
 
 void Monster_Move(entity this, float runspeed, float walkspeed, float stpspeed)
 {
-       if(this.target2) { this.goalentity = find(world, targetname, this.target2); }
+       if(this.target2) { this.goalentity = find(NULL, targetname, this.target2); }
 
        entity targ;
 
@@ -706,7 +703,7 @@ void Monster_Move(entity this, float runspeed, float walkspeed, float stpspeed)
                movelib_brake_simple(this, stpspeed);
                setanim(this, this.anim_idle, true, false, false);
 
-               this.enemy = world;
+               this.enemy = NULL;
                this.nextthink = time + this.ticrate;
 
                if(this.revive_progress >= 1)
@@ -725,7 +722,7 @@ void Monster_Move(entity this, float runspeed, float walkspeed, float stpspeed)
                movelib_brake_simple(this, stpspeed);
                setanim(this, this.anim_idle, true, false, false);
 
-               this.enemy = world;
+               this.enemy = NULL;
                this.nextthink = time + this.ticrate;
 
                if(this.health < 1)
@@ -750,7 +747,7 @@ void Monster_Move(entity this, float runspeed, float walkspeed, float stpspeed)
                        {
                                this.last_trace = time + 0.4;
 
-                               Damage (this, world, world, 2, DEATH_DROWN.m_id, this.origin, '0 0 0');
+                               Damage (this, NULL, NULL, 2, DEATH_DROWN.m_id, this.origin, '0 0 0');
                                this.angles = '90 90 0';
                                if(random() < 0.5)
                                {
@@ -782,7 +779,7 @@ void Monster_Move(entity this, float runspeed, float walkspeed, float stpspeed)
 
        if (MUTATOR_CALLHOOK(MonsterMove, this, runspeed, walkspeed, targ)
                || gameover
-               || this.draggedby != world
+               || this.draggedby != NULL
                || (round_handler_IsActive() && !round_handler_IsRoundStarted())
                || time < game_starttime
                || (autocvar_g_campaign && !campaign_bots_may_start)
@@ -802,7 +799,7 @@ void Monster_Move(entity this, float runspeed, float walkspeed, float stpspeed)
        if(teamplay)
        if(autocvar_g_monsters_teams)
        if(DIFF_TEAM(this.monster_follow, this))
-               this.monster_follow = world;
+               this.monster_follow = NULL;
 
        if(time >= this.last_enemycheck)
        {
@@ -866,7 +863,7 @@ void Monster_Move(entity this, float runspeed, float walkspeed, float stpspeed)
        }
        else
        {
-               entity e = find(world, targetname, this.target2);
+               entity e = find(NULL, targetname, this.target2);
                if(e.target2)
                        this.target2 = e.target2;
                else if(e.target)
@@ -954,8 +951,8 @@ void Monster_Reset(entity this)
 
        this.health = this.max_health;
        this.velocity = '0 0 0';
-       this.enemy = world;
-       this.goalentity = world;
+       this.enemy = NULL;
+       this.goalentity = NULL;
        this.attack_finished_single[0] = 0;
        this.moveto = this.origin;
 }
@@ -1012,7 +1009,7 @@ void Monster_Dead(entity this, entity attacker, float gibbed)
        this.solid                      = SOLID_CORPSE;
        this.takedamage         = DAMAGE_AIM;
        this.deadflag           = DEAD_DEAD;
-       this.enemy                      = world;
+       this.enemy                      = NULL;
        this.movetype           = MOVETYPE_TOSS;
        this.moveto                     = this.origin;
        settouch(this, Monster_Touch); // reset incase monster was pouncing
@@ -1047,7 +1044,7 @@ void Monster_Damage(entity this, entity inflictor, entity attacker, float damage
        if(time < this.spawnshieldtime && deathtype != DEATH_KILL.m_id)
                return;
 
-       if(deathtype == DEATH_FALL.m_id && this.draggedby != world)
+       if(deathtype == DEATH_FALL.m_id && this.draggedby != NULL)
                return;
 
        vector v;
@@ -1113,7 +1110,7 @@ void Monster_Damage(entity this, entity inflictor, entity attacker, float damage
 // don't check for enemies, just keep walking in a straight line
 void Monster_Move_2D(entity this, float mspeed, bool allow_jumpoff)
 {
-       if(gameover || (round_handler_IsActive() && !round_handler_IsRoundStarted()) || this.draggedby != world || time < game_starttime || (autocvar_g_campaign && !campaign_bots_may_start) || time < this.spawn_time)
+       if(gameover || (round_handler_IsActive() && !round_handler_IsRoundStarted()) || this.draggedby != NULL || time < game_starttime || (autocvar_g_campaign && !campaign_bots_may_start) || time < this.spawn_time)
        {
                mspeed = 0;
                if(time >= this.spawn_time)
@@ -1266,7 +1263,7 @@ bool Monster_Spawn_Setup(entity this)
 
        if(autocvar_g_monsters_healthbars)
        {
-               entity wp = WaypointSprite_Spawn(WP_Monster, 0, 1024, this, '0 0 1' * (this.maxs.z + 15), world, this.team, this, sprite, true, RADARICON_DANGER);
+               entity wp = WaypointSprite_Spawn(WP_Monster, 0, 1024, this, '0 0 1' * (this.maxs.z + 15), NULL, this.team, this, sprite, true, RADARICON_DANGER);
                wp.wp_extra = this.monsterid;
                wp.colormod = ((this.team) ? Team_ColorRGB(this.team) : '1 0 0');
                if(!(this.spawnflags & MONSTERFLAG_INVINCIBLE))
@@ -1325,7 +1322,7 @@ bool Monster_Spawn(entity this, int mon_id)
        this.solid                              = SOLID_BBOX;
        this.movetype                   = MOVETYPE_WALK;
        this.spawnshieldtime    = time + autocvar_g_monsters_spawnshieldtime;
-       this.enemy                              = world;
+       this.enemy                              = NULL;
        this.velocity                   = '0 0 0';
        this.moveto                             = this.origin;
        this.pos1                               = this.origin;