From acb4979d359741c2f4a98b1b9fc0c1db7bcdb2b7 Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 20 Jun 2017 10:57:42 +1000 Subject: [PATCH] Greatly simplify monster velocity calculation and use an intrusive list for monster targets --- qcsrc/common/monsters/sv_monsters.qc | 28 ++++++++++++------- qcsrc/server/client.qc | 2 ++ qcsrc/server/defs.qh | 3 ++ qcsrc/server/miscfunctions.qc | 2 +- .../mutators/mutator/gamemode_invasion.qc | 10 ++++++- qcsrc/server/sv_main.qc | 3 ++ 6 files changed, 36 insertions(+), 12 deletions(-) diff --git a/qcsrc/common/monsters/sv_monsters.qc b/qcsrc/common/monsters/sv_monsters.qc index 469dd7b9c..d7147e0bc 100644 --- a/qcsrc/common/monsters/sv_monsters.qc +++ b/qcsrc/common/monsters/sv_monsters.qc @@ -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; diff --git a/qcsrc/server/client.qc b/qcsrc/server/client.qc index 2ab3160ed..381373ad2 100644 --- a/qcsrc/server/client.qc +++ b/qcsrc/server/client.qc @@ -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); diff --git a/qcsrc/server/defs.qh b/qcsrc/server/defs.qh index ca7430de3..7f0c2610f 100644 --- a/qcsrc/server/defs.qh +++ b/qcsrc/server/defs.qh @@ -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(); } diff --git a/qcsrc/server/miscfunctions.qc b/qcsrc/server/miscfunctions.qc index c66a6328f..24f16c487 100644 --- a/qcsrc/server/miscfunctions.qc +++ b/qcsrc/server/miscfunctions.qc @@ -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 diff --git a/qcsrc/server/mutators/mutator/gamemode_invasion.qc b/qcsrc/server/mutators/mutator/gamemode_invasion.qc index cbff696fc..05a89c75d 100644 --- a/qcsrc/server/mutators/mutator/gamemode_invasion.qc +++ b/qcsrc/server/mutators/mutator/gamemode_invasion.qc @@ -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) diff --git a/qcsrc/server/sv_main.qc b/qcsrc/server/sv_main.qc index 7ba19dafd..0ae9b356c 100644 --- a/qcsrc/server/sv_main.qc +++ b/qcsrc/server/sv_main.qc @@ -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'; -- 2.39.2