From: Mario Date: Wed, 28 Sep 2016 14:53:50 +0000 (+1000) Subject: Clean up monster spawn function a little, allow setting invasion spawnpoints to spawn... X-Git-Tag: xonotic-v0.8.2~564 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=4571aff00b14329c6a742cfa8a73c3303eb1f6b5;p=xonotic%2Fxonotic-data.pk3dir.git Clean up monster spawn function a little, allow setting invasion spawnpoints to spawn specific monsters with the spawnmob field --- diff --git a/qcsrc/common/monsters/sv_monsters.qc b/qcsrc/common/monsters/sv_monsters.qc index 9ac1f4e14..02ad23817 100644 --- a/qcsrc/common/monsters/sv_monsters.qc +++ b/qcsrc/common/monsters/sv_monsters.qc @@ -692,7 +692,8 @@ 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(NULL, targetname, this.target2); } + // update goal entity if lost + if(this.target2 && this.goalentity.targetname != this.target2) { this.goalentity = find(NULL, targetname, this.target2); } entity targ; diff --git a/qcsrc/common/monsters/sv_spawn.qc b/qcsrc/common/monsters/sv_spawn.qc index 50373cc2a..da924cf96 100644 --- a/qcsrc/common/monsters/sv_spawn.qc +++ b/qcsrc/common/monsters/sv_spawn.qc @@ -8,9 +8,8 @@ #include #include #endif -entity spawnmonster (string monster, float monster_id, entity spawnedby, entity own, vector orig, float respwn, float invincible, float moveflag) +entity spawnmonster (string monster, int monster_id, entity spawnedby, entity own, vector orig, bool respwn, bool invincible, int moveflag) { - float i; entity e = spawn(); e.spawnflags = MONSTERFLAG_SPAWNED; @@ -22,26 +21,26 @@ entity spawnmonster (string monster, float monster_id, entity spawnedby, entity if(monster == "random") { - RandomSelection_Init(); - for(i = MON_FIRST; i <= MON_LAST; ++i) - RandomSelection_Add(NULL, i, string_null, 1, 1); + RandomSelection_Init(); + FOREACH(Monsters, it != MON_Null, + { + RandomSelection_Add(it, 0, string_null, 1, 1); + }); - monster_id = RandomSelection_chosen_float; + monster_id = RandomSelection_chosen_ent.monsterid; } else if(monster != "") { - float found = 0; - entity mon; - for(i = MON_FIRST; i <= MON_LAST; ++i) + bool found = false; + FOREACH(Monsters, it != MON_Null, { - mon = get_monsterinfo(i); - if(mon.netname == monster) + if(it.netname == monster) { found = true; - monster_id = mon.monsterid; // we have the monster, old monster id is no longer required + monster_id = it.monsterid; // we have the monster, old monster id is no longer required break; } - } + }); if(!found) monster_id = ((monster_id > 0) ? monster_id : MON_FIRST); } diff --git a/qcsrc/common/monsters/sv_spawn.qh b/qcsrc/common/monsters/sv_spawn.qh index 0aba5c19d..00db84c1c 100644 --- a/qcsrc/common/monsters/sv_spawn.qh +++ b/qcsrc/common/monsters/sv_spawn.qh @@ -1,3 +1,3 @@ #pragma once -entity spawnmonster (string monster, float monster_id, entity spawnedby, entity own, vector orig, float respwn, float invincible, float moveflag); +entity spawnmonster (string monster, int monster_id, entity spawnedby, entity own, vector orig, bool respwn, bool invincible, int moveflag); diff --git a/qcsrc/server/mutators/mutator/gamemode_invasion.qc b/qcsrc/server/mutators/mutator/gamemode_invasion.qc index 515148c1b..61fe75ea4 100644 --- a/qcsrc/server/mutators/mutator/gamemode_invasion.qc +++ b/qcsrc/server/mutators/mutator/gamemode_invasion.qc @@ -15,6 +15,8 @@ int autocvar_g_invasion_monster_count; bool autocvar_g_invasion_zombies_only; float autocvar_g_invasion_spawn_delay; +.string spawnmob; + spawnfunc(invasion_spawnpoint) { if(!g_invasion) { delete(this); return; } @@ -23,9 +25,12 @@ spawnfunc(invasion_spawnpoint) IL_PUSH(g_invasion_spawns, this); if(autocvar_g_invasion_zombies_only) // precache only if it hasn't been already - if(this.monsterid) { - Monster mon = get_monsterinfo(this.monsterid); - mon.mr_precache(mon); + if(this.spawnmob) + { + FOREACH(Monsters, it.netname == this.spawnmob, + { + it.mr_precache(it); + }); } } @@ -59,7 +64,7 @@ entity invasion_PickSpawn() return RandomSelection_chosen_ent; } -void invasion_SpawnChosenMonster(float mon) +void invasion_SpawnChosenMonster(int mon) { entity spawn_point, monster; @@ -78,8 +83,8 @@ void invasion_SpawnChosenMonster(float mon) setthink(e, SUB_Remove); e.nextthink = time + 0.1; } - else - monster = spawnmonster("", ((spawn_point.monsterid) ? spawn_point.monsterid : mon), spawn_point, spawn_point, spawn_point.origin, false, false, 2); + else // if spawnmob field falls through (unset), fallback to mon (relying on spawnmonster for that behaviour) + monster = spawnmonster(spawn_point.spawnmob, mon, spawn_point, spawn_point, spawn_point.origin, false, false, 2); if(spawn_point) monster.target2 = spawn_point.target2; monster.spawnshieldtime = time;