]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Greatly simplify monster velocity calculation and use an intrusive list for monster...
authorMario <mario@smbclan.net>
Tue, 20 Jun 2017 00:57:42 +0000 (10:57 +1000)
committerMario <mario@smbclan.net>
Tue, 20 Jun 2017 00:57:42 +0000 (10:57 +1000)
qcsrc/common/monsters/sv_monsters.qc
qcsrc/server/client.qc
qcsrc/server/defs.qh
qcsrc/server/miscfunctions.qc
qcsrc/server/mutators/mutator/gamemode_invasion.qc
qcsrc/server/sv_main.qc

index 469dd7b9cd7d3ec41d609dc48def8cacb2825928..d7147e0bcedfd7bfefb8f3f0dcdf587e018967f8 100644 (file)
@@ -125,7 +125,7 @@ entity Monster_FindTarget(entity this)
        vector my_center = CENTER_OR_VIEWOFS(this);
 
        // find the closest acceptable target to pass to
-       FOREACH_ENTITY_RADIUS(this.origin, this.target_range, it.monster_attack,
+       IL_EACH(g_monster_targets, it.monster_attack && vdist(it.origin - this.origin, <, this.target_range),
        {
                if(Monster_ValidTarget(this, it))
                {
@@ -173,6 +173,8 @@ void monster_changeteam(entity this, int newteam)
        if(!teamplay) { return; }
 
        this.team = newteam;
+       if(!this.monster_attack)
+               IL_PUSH(g_monster_targets, this);
        this.monster_attack = true; // new team, activate attacking
        monster_setupcolors(this);
 
@@ -245,7 +247,7 @@ void Monster_Sound_Precache(string f)
        {
                if(tokenize_console(s) != 3)
                {
-                       LOG_TRACE("Invalid sound info line: ", s);
+                       //LOG_DEBUG("Invalid sound info line: ", s); // probably a comment, no need to spam warnings
                        continue;
                }
                PrecacheGlobalSound(strcat(argv(1), " ", argv(2)));
@@ -299,7 +301,7 @@ bool Monster_Sounds_Load(entity this, string f, int first)
        float fh = fopen(f, FILE_READ);
        if(fh < 0)
        {
-               LOG_TRACE("Monster sound file not found: ", f);
+               //LOG_DEBUG("Monster sound file not found: ", f); // no biggie, monster has no sounds, let's not spam it
                return false;
        }
        while((s = fgets(fh)))
@@ -565,7 +567,7 @@ vector Monster_Move_Target(entity this, entity targ)
                        || ((trace_fraction < 1) && (trace_ent != this.enemy)))
                {
                        this.enemy = NULL;
-                       this.pass_distance = 0;
+                       //this.pass_distance = 0;
                }
 
                if(this.enemy)
@@ -656,12 +658,13 @@ vector Monster_Move_Target(entity this, entity targ)
 
 void Monster_CalculateVelocity(entity this, vector to, vector from, float turnrate, float movespeed)
 {
-       float current_distance = vlen((('1 0 0' * to.x) + ('0 1 0' * to.y)) - (('1 0 0' * from.x) + ('0 1 0' * from.y))); // for the sake of this check, exclude Z axis
-       float initial_height = 0; //min(50, (targ_distance * tanh(20)));
-       float current_height = (initial_height * min(1, (this.pass_distance) ? (current_distance / this.pass_distance) : current_distance));
+       //float current_distance = vlen((('1 0 0' * to.x) + ('0 1 0' * to.y)) - (('1 0 0' * from.x) + ('0 1 0' * from.y))); // for the sake of this check, exclude Z axis
+       //float initial_height = 0; //min(50, (targ_distance * tanh(20)));
+       //float current_height = (initial_height * min(1, (this.pass_distance) ? (current_distance / this.pass_distance) : current_distance));
        //print("current_height = ", ftos(current_height), ", initial_height = ", ftos(initial_height), ".\n");
 
-       vector targpos;
+       vector targpos = to;
+#if 0
        if(current_height) // make sure we can actually do this arcing path
        {
                targpos = (to + ('0 0 1' * current_height));
@@ -677,6 +680,7 @@ void Monster_CalculateVelocity(entity this, vector to, vector from, float turnra
                }
        }
        else { targpos = to; }
+#endif
 
        //this.angles = normalize(('0 1 0' * to_y) - ('0 1 0' * from_y));
 
@@ -819,7 +823,7 @@ void Monster_Move(entity this, float runspeed, float walkspeed, float stpspeed)
                                this.monster_moveto = '0 0 0';
                                this.monster_face = '0 0 0';
 
-                               this.pass_distance = vlen((('1 0 0' * this.enemy.origin_x) + ('0 1 0' * this.enemy.origin_y)) - (('1 0 0' *  this.origin_x) + ('0 1 0' *  this.origin_y)));
+                               //this.pass_distance = vlen((('1 0 0' * this.enemy.origin_x) + ('0 1 0' * this.enemy.origin_y)) - (('1 0 0' *  this.origin_x) + ('0 1 0' *  this.origin_y)));
                                Monster_Sound(this, monstersound_sight, 0, false, CH_VOICE);
                        }
                }
@@ -1261,7 +1265,11 @@ bool Monster_Spawn_Setup(entity this)
        Monster_Sounds_Update(this);
 
        if(teamplay)
+       {
+               if(!this.monster_attack)
+                       IL_PUSH(g_monster_targets, this);
                this.monster_attack = true; // we can have monster enemies in team games
+       }
 
        Monster_Sound(this, monstersound_spawn, 0, false, CH_VOICE);
 
@@ -1355,7 +1363,7 @@ bool Monster_Spawn(entity this, bool check_appear, int mon_id)
        this.candrop                    = true;
        this.view_ofs                   = '0 0 0.7' * (this.maxs_z * 0.5);
        this.oldtarget2                 = this.target2;
-       this.pass_distance              = 0;
+       //this.pass_distance            = 0;
        this.deadflag                   = DEAD_NO;
        this.spawn_time                 = time;
        this.gravity                    = 1;
index 2ab3160ed7e951f390e402b4a480ed68e87e16be..381373ad2bcb713d93ccc4046efa6ac2341c14ed 100644 (file)
@@ -658,6 +658,8 @@ void PutClientInServer(entity this)
                if(!this.bot_attack)
                        IL_PUSH(g_bot_targets, this);
                this.bot_attack = true;
+               if(!this.monster_attack)
+                       IL_PUSH(g_monster_targets, this);
                this.monster_attack = true;
                navigation_dynamicgoal_init(this, false);
 
index ca7430de31eaaa17cfecdec04e6eef1c9ae2907e..7f0c2610f9ab40aa46d4c90aaa162fa99b5763a5 100644 (file)
@@ -479,3 +479,6 @@ STATIC_INIT(g_locations) { g_locations = IL_NEW(); }
 
 IntrusiveList g_saved_team;
 STATIC_INIT(g_saved_team) { g_saved_team = IL_NEW(); }
+
+IntrusiveList g_monster_targets;
+STATIC_INIT(g_monster_targets) { g_monster_targets = IL_NEW(); }
index c66a6328f65903d6d5d5e077a9ec06ae0a480209..24f16c487678c3c032ab1ab9ff5dfea0178716b0 100644 (file)
@@ -1262,7 +1262,7 @@ float MoveToRandomLocationWithinBounds(entity e, vector boundmin, vector boundma
     {
         setorigin(e, start);
         e.angles = vectoangles(end - start);
-        LOG_TRACE("Needed ", ftos(i + 1), " attempts");
+        LOG_DEBUG("Needed ", ftos(i + 1), " attempts");
         return true;
     }
     else
index cbff696fc5bf4489ac9e0c2e84cc06b55580084b..05a89c75df6e23a2ce7d3e059a1bb637bfc4efcc 100644 (file)
@@ -18,6 +18,8 @@ int autocvar_g_invasion_monster_count;
 bool autocvar_g_invasion_zombies_only;
 float autocvar_g_invasion_spawn_delay;
 
+bool inv_warning_shown; // spammy
+
 .string spawnmob;
 
 spawnfunc(invasion_wave)
@@ -103,7 +105,11 @@ void invasion_SpawnChosenMonster(Monster mon)
 
        if(spawn_point == NULL)
        {
-               LOG_TRACE("Warning: couldn't find any invasion_spawnpoint spawnpoints, attempting to spawn monsters in random locations");
+               if(!inv_warning_shown)
+               {
+                       inv_warning_shown = true;
+                       LOG_TRACE("Warning: couldn't find any invasion_spawnpoint spawnpoints, attempting to spawn monsters in random locations");
+               }
                entity e = spawn();
                setsize(e, mon.m_mins, mon.m_maxs);
 
@@ -156,6 +162,8 @@ void invasion_SpawnChosenMonster(Monster mon)
                }
        }
 
+       if(monster.monster_attack)
+               IL_REMOVE(g_monster_targets, monster);
        monster.monster_attack = false; // it's the player's job to kill all the monsters
 
        if(inv_roundcnt >= inv_maxrounds)
index 7ba19dafd5fcfe61489e3124f388869579877c38..0ae9b356cd3cdecbdcaf7e8c6c8c445d13fc847b 100644 (file)
@@ -378,6 +378,9 @@ LABEL(cvar_fail)
 
        set_movetype(this, this.movetype);
 
+       if(this.monster_attack)
+               IL_PUSH(g_monster_targets, this);
+
        // support special -1 and -2 angle from radiant
        if (this.angles == '0 -1 0')
                this.angles = '-90 0 0';