]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Use a spawnflag to check if the monster has re-spawned
authorMario <mario.mario@y7mail.com>
Tue, 3 Dec 2013 14:14:34 +0000 (01:14 +1100)
committerMario <mario.mario@y7mail.com>
Tue, 3 Dec 2013 14:14:34 +0000 (01:14 +1100)
qcsrc/common/monsters/monster/mage.qc
qcsrc/common/monsters/spawn.qc
qcsrc/common/monsters/sv_monsters.qc
qcsrc/common/monsters/sv_monsters.qh
qcsrc/server/mutators/gamemode_invasion.qc

index 83924ab7d613e5dc426671be2b1f4d336c4a801b..6822363c56888742788beedd7e3af894caddc685 100644 (file)
@@ -147,7 +147,7 @@ void mage_spike_think()
                        self.wait = bound((autocvar_g_monster_mage_attack_spike_smart_trace_min), vlen(self.origin - trace_endpos), self.wait = (autocvar_g_monster_mage_attack_spike_smart_trace_max));
 
                        // Calc how important it is that we turn and add this to the desierd (enemy) dir.
-                       desireddir      = normalize(((trace_plane_normal * (1 - trace_fraction)) + (desireddir * trace_fraction)) * 0.5);
+                       desireddir = normalize(((trace_plane_normal * (1 - trace_fraction)) + (desireddir * trace_fraction)) * 0.5);
                }
 
                newdir = normalize(olddir + desireddir * turnrate); // take the average of the 2 directions; not the best method but simple & easy
index 3fe8567aee36c8f178616d76e8dad81fd234fae7..924a728a07678ed0101b537a35ba07a8997f8d69 100644 (file)
@@ -4,6 +4,7 @@ entity spawnmonster (string monster, float monster_id, entity spawnedby, entity
        initialize_field_db();
 
        entity e = spawn();
+       float i;
 
        e.spawnflags = MONSTERFLAG_SPAWNED;
 
@@ -12,9 +13,18 @@ entity spawnmonster (string monster, float monster_id, entity spawnedby, entity
 
        setorigin(e, orig);
 
+       if(monster == "random")
+       {
+               RandomSelection_Init();
+               for(i = MON_FIRST; i <= MON_LAST; ++i)
+                       RandomSelection_Add(world, 0, (get_monsterinfo(i)).netname, 1, 1);
+
+               monster = RandomSelection_chosen_string;
+       }
+
        if(monster != "")
        {
-               float i, found = 0;
+               float found = 0;
                entity mon;
                for(i = MON_FIRST; i <= MON_LAST; ++i)
                {
index 8176dee3df1f59ab75052c1b7981786159e10895..28a78ceb87f4ddd8123e8cc72fef483ccfbc14d0 100644 (file)
@@ -361,7 +361,7 @@ void Monster_Fade ()
 {
        if(Monster_CanRespawn(self))
        {
-               self.monster_respawned = TRUE;
+               self.spawnflags |= MONSTERFLAG_RESPAWNED;
                self.think = self.monster_spawnfunc;
                self.nextthink = time + self.respawntime;
                self.ltime = 0;
@@ -379,7 +379,16 @@ void Monster_Fade ()
                setmodel(self, "null");
        }
        else
+       {
+               // number of monsters spawned with mobspawn command
+               totalspawned -= 1;
+
+               if(IS_CLIENT(self.realowner))
+               if(!(self.spawnflags & MONSTERFLAG_RESPAWNED))
+                               self.realowner.monstercount -= 1;
+
                SUB_SetFade(self, time + 3, 1);
+       }
 }
 
 float Monster_CanJump (vector vel)
@@ -798,7 +807,7 @@ void monsters_corpse_damage (entity inflictor, entity attacker, float damage, fl
                Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
 
                if(IS_CLIENT(self.realowner))
-               if(!self.monster_respawned)
+               if(!(self.spawnflags & MONSTERFLAG_RESPAWNED))
                        self.realowner.monstercount -= 1;
 
                self.think = SUB_Remove;
@@ -822,21 +831,20 @@ void monster_die(entity attacker, float gibbed)
 
        MonsterSound(monstersound_death, 0, FALSE, CH_VOICE);
 
-       if(!(self.spawnflags & MONSTERFLAG_SPAWNED) && !self.monster_respawned)
+       if(!(self.spawnflags & MONSTERFLAG_SPAWNED) && !(self.spawnflags & MONSTERFLAG_RESPAWNED))
                monsters_killed += 1;
 
        if(IS_PLAYER(attacker))
-       if( autocvar_g_monsters_score_spawned ||
-                       ( !(self.spawnflags & MONSTERFLAG_SPAWNED) && !self.monster_respawned) )
+       if(autocvar_g_monsters_score_spawned || !((self.spawnflags & MONSTERFLAG_SPAWNED) || (self.spawnflags & MONSTERFLAG_RESPAWNED)))
                PlayerScore_Add(attacker, SP_SCORE, +autocvar_g_monsters_score_kill);
 
-       if(!Monster_CanRespawn(self) || gibbed)
+       if(!Monster_CanRespawn(self) && gibbed)
        {
                // number of monsters spawned with mobspawn command
                totalspawned -= 1;
 
                if(IS_CLIENT(self.realowner))
-               if(!self.monster_respawned)
+               if(!(self.spawnflags & MONSTERFLAG_RESPAWNED))
                        self.realowner.monstercount -= 1;
        }
 
@@ -973,7 +981,7 @@ float monster_spawn()
 {
        MON_ACTION(self.monsterid, MR_SETUP);
 
-       if(!self.monster_respawned)
+       if(!(self.spawnflags & MONSTERFLAG_RESPAWNED))
        {
                Monster_CheckMinibossFlag();
                self.health *= Monster_SkillModifier();
@@ -985,7 +993,7 @@ float monster_spawn()
        if(IS_PLAYER(self.monster_owner))
                self.effects |= EF_DIMLIGHT;
 
-       if(!self.monster_respawned)
+       if(!(self.spawnflags & MONSTERFLAG_RESPAWNED))
        if(!self.skin)
                self.skin = rint(random() * 4);
 
@@ -1032,7 +1040,7 @@ float monster_initialize(float mon_id, float nodrop)
                self.team = 0;
 
        if(!(self.spawnflags & MONSTERFLAG_SPAWNED)) // naturally spawned monster
-       if(!self.monster_respawned)
+       if(!(self.spawnflags & MONSTERFLAG_RESPAWNED))
                monsters_total += 1;
 
        setmodel(self, mon.model);
@@ -1115,7 +1123,7 @@ float monster_initialize(float mon_id, float nodrop)
        if(!monster_spawn())
                return FALSE;
 
-       if(!self.monster_respawned)
+       if(!(self.spawnflags & MONSTERFLAG_RESPAWNED))
                monster_setupcolors();
 
        CSQCMODEL_AUTOINIT();
index a35d888050a2a035e98c05eb574da3a0a196e2cb..65331207279af26037e6a9084253e4cb7d8ebc45 100644 (file)
@@ -59,8 +59,6 @@ ALLMONSTERSOUNDS
 
 float GetMonsterSoundSampleField_notFound;
 
-.float monster_respawned; // used to make sure we're not recounting respawned monster stats
-
 const float MONSTERSKILL_NOTEASY = 256; // monster will not spawn on skill <= 1
 const float MONSTERSKILL_NOTMEDIUM = 512; // monster will not spawn on skill 2
 const float MONSTERSKILL_NOTHARD = 1024; // monster will not spawn on skill >= 3
@@ -72,6 +70,7 @@ const float MONSTERFLAG_FLY_VERTICAL = 8; // fly/swim vertically
 const float MONSTERFLAG_INFRONT = 32; // only check for enemies infront of us
 const float MONSTERFLAG_MINIBOSS = 64; // monster spawns as mini-boss (also has a chance of naturally becoming one)
 const float MONSTERFLAG_SPAWNED = 16384; // flag for spawned monsters
+const float MONSTERFLAG_RESPAWNED = 32768; // flag for re-spawned monsters
 
 .void() monster_spawnfunc;
 
index f7442c1ca03e53a6462863f17e9fdc01a2402ab9..2147e6a816720859ebd01d590e1042e660b89d32 100644 (file)
@@ -18,7 +18,7 @@ float invasion_PickMonster(float supermonster_count)
        for(i = MON_FIRST; i <= MON_LAST; ++i)
        {
                mon = get_monsterinfo(i);
-               if((mon.spawnflags & MONSTER_TYPE_FLY) || (mon.spawnflags & MONSTER_TYPE_SWIM) || (mon.spawnflags & MON_FLAG_SUPERMONSTER && supermonster_count >= 1))
+               if((mon.spawnflags & MONSTER_TYPE_FLY) || (mon.spawnflags & MONSTER_TYPE_SWIM) || ((mon.spawnflags & MON_FLAG_SUPERMONSTER) && supermonster_count >= 1))
                        continue; // flying/swimming monsters not yet supported
 
                RandomSelection_Add(world, i, "", 1, 1);
@@ -183,7 +183,7 @@ void Invasion_RoundStart()
 
 MUTATOR_HOOKFUNCTION(invasion_MonsterDies)
 {
-       if(!self.monster_respawned)
+       if(!(self.spawnflags & MONSTERFLAG_RESPAWNED))
        {
                numkilled += 1;
                maxcurrent -= 1;
@@ -206,7 +206,7 @@ MUTATOR_HOOKFUNCTION(invasion_MonsterSpawn)
        if(roundcnt < maxrounds && self.spawnflags & MONSTERFLAG_MINIBOSS)
                self.spawnflags &= ~MONSTERFLAG_MINIBOSS;
 
-       if(!self.monster_respawned)
+       if(!(self.spawnflags & MONSTERFLAG_RESPAWNED))
        {
                numspawned += 1;
                maxcurrent += 1;