Merge branch 'master' into Mario/notifications
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / gamemode_onslaught.qc
index 8bbe4bd..74cba28 100644 (file)
@@ -406,12 +406,12 @@ void onslaught_generator_think()
                                                d = d + 1;
                                e = e.chain;
                        }
-                       
+
                        if(autocvar_g_campaign && autocvar__campaign_testrun)
                                d = d * self.max_health;
                        else
                                d = d * self.max_health / max(30, 60 * autocvar_timelimit_suddendeath);
-                       
+
                        Damage(self, self, self, d, DEATH_HURTTRIGGER, self.origin, '0 0 0');
                }
                else if (overtime_msg_time)
@@ -509,7 +509,7 @@ void onslaught_generator_deaththink()
        vector org;
        float i;
 
-       if not (self.count)
+       if (!self.count)
                self.count = 40;
 
        // White shockwave
@@ -613,7 +613,7 @@ void onslaught_generator_damage(entity inflictor, entity attacker, float damage,
 #endif
                self.lasthealth = self.health;
        }
-       else if not(warmup_stage)
+       else if (!warmup_stage)
        {
                if (attacker == self)
                        bprint(Team_ColoredFullName(self.team), " generator spontaneously exploded due to overtime!\n");
@@ -909,13 +909,13 @@ void spawnfunc_onslaught_generator()
        precache_sound("onslaught/electricity_explode.wav");
        if (!self.team)
                objerror("team must be set");
-       
+
        if(self.team == NUM_TEAM_1)
         ons_red_generator = self;
 
        if(self.team == NUM_TEAM_2)
         ons_blue_generator = self;
-        
+
        self.team_saved = self.team;
        self.colormap = 1024 + (self.team - 1) * 17;
        self.solid = SOLID_BBOX;
@@ -955,7 +955,7 @@ void spawnfunc_onslaught_generator()
        waypoint_spawnforitem(self);
 
        onslaught_updatelinks();
-       
+
        self.reset = onslaught_generator_reset;
 }
 
@@ -1083,7 +1083,7 @@ void onslaught_controlpoint_icon_think()
         float _friendly_count = 0;
         float _dist;
         entity _player;
-        
+
         FOR_EACH_PLAYER(_player)
         {
             if(!_player.deadflag)
@@ -1225,7 +1225,7 @@ void onslaught_controlpoint_icon_buildthink()
        a = onslaught_controlpoint_can_be_linked(self.owner, self.owner.team);
        if(!a)
                return;
-    
+
        self.health = self.health + self.count;
 
        if (self.health >= self.max_health)
@@ -1270,7 +1270,7 @@ void onslaught_controlpoint_touch()
 {
        entity e;
        float a;
-       if not(IS_PLAYER(other))
+       if (!IS_PLAYER(other))
                return;
        a = onslaught_controlpoint_attackable(self, other.team);
        if(a != 2 && a != 4)
@@ -1303,6 +1303,12 @@ void onslaught_controlpoint_touch()
        onslaught_updatelinks();
 }
 
+void onslaught_controlpoint_think()
+{
+       self.nextthink = time;
+       CSQCMODEL_AUTOUPDATE();
+}
+
 void onslaught_controlpoint_reset()
 {
        if(self.goalentity && self.goalentity != world)
@@ -1315,8 +1321,9 @@ void onslaught_controlpoint_reset()
        self.isshielded = TRUE;
        self.enemy.solid = SOLID_NOT;
        self.enemy.colormap = self.colormap;
-       self.think = self.enemy.think = func_null;
-       self.nextthink = 0; // don't like func_null :P
+       self.think = onslaught_controlpoint_think;
+       self.enemy.think = func_null;
+       self.nextthink = time; // don't like func_null :P
        setmodel(self, "models/onslaught/controlpoint_pad.md3");
        //setsize(self, '-32 -32 0', '32 32 8');
 
@@ -1326,6 +1333,8 @@ void onslaught_controlpoint_reset()
 
        activator = self;
        SUB_UseTargets(); // to reset the structures, playerspawns etc.
+       
+       CSQCMODEL_AUTOUPDATE();
 }
 
 /*QUAKED spawnfunc_onslaught_controlpoint (0 .5 .8) (-32 -32 0) (32 32 128)
@@ -1396,6 +1405,9 @@ void spawnfunc_onslaught_controlpoint()
        self.enemy.colormap = self.colormap;
 
        waypoint_spawnforitem(self);
+       
+       self.think = onslaught_controlpoint_think;
+       self.nextthink = time;
 
        WaypointSprite_SpawnFixed(string_null, self.origin + '0 0 128', self, sprite, RADARICON_NONE, '0 0 0');
        WaypointSprite_UpdateRule(self.sprite, NUM_TEAM_2, SPRITERULE_TEAMPLAY);
@@ -1403,6 +1415,8 @@ void spawnfunc_onslaught_controlpoint()
        onslaught_updatelinks();
 
        self.reset = onslaught_controlpoint_reset;
+       
+       CSQCMODEL_AUTOINIT();
 }
 
 float onslaught_link_send(entity to, float sendflags)
@@ -1523,24 +1537,24 @@ MUTATOR_HOOKFUNCTION(ons_BuildMutatorsPrettyString)
 
 MUTATOR_HOOKFUNCTION(ons_Spawn_Score)
 {
-    
+
     /*
     float _neer_home = (random() > 0.5 ? TRUE : FALSE);
-    
+
        RandomSelection_Init();
-       
+
        if(self.team == NUM_TEAM_1)
         RandomSelection_Add(ons_red_generator, 0, string_null, 1, 1);
-       
+
        if(self.team == NUM_TEAM_2)
         RandomSelection_Add(ons_blue_generator, 0, string_null, 1, 1);
-       
+
        entity _cp = findchain(classname, "onslaught_controlpoint"):
        while _cp;
        {
-           if(_cp.team == self.team)            
+           if(_cp.team == self.team)
             RandomSelection_Add(_cp, 0, string_null, 1, 1);
-               
+
                _cp = _cp.chain;
        }
 
@@ -1551,9 +1565,9 @@ MUTATOR_HOOKFUNCTION(ons_Spawn_Score)
        }
        else if(self.team == spawn_spot.team)
                spawn_score_x += SPAWN_PRIO_NEAR_TEAMMATE_SAMETEAM; // prefer same team, if we can't find a spawn near teammate
-    
+
     */
-    
+
        return 0;
 }
 
@@ -1561,55 +1575,55 @@ MUTATOR_HOOKFUNCTION(ons_PlayerSpawn)
 {
     if(!autocvar_g_onslaught_spawn_at_controlpoints)
         return 0;
-        
+
     if(random() < 0.5)  // 50/50 chane to use default spawnsystem.
         return 0;
-    
+
     float _close_to_home = ((random() > 0.5) ? TRUE : FALSE);
     entity _best = world, _trg_gen = world;
     float _score, _best_score = MAX_SHOT_DISTANCE;
-    
+
        RandomSelection_Init();
-    
+
        if(self.team == NUM_TEAM_1)
        {
            if(!_close_to_home)
             _trg_gen = ons_blue_generator;
-        else    
-            _trg_gen  = ons_red_generator;        
+        else
+            _trg_gen  = ons_red_generator;
        }
-       
+
        if(self.team == NUM_TEAM_2)
        {
            if(_close_to_home)
             _trg_gen = ons_blue_generator;
-        else    
-            _trg_gen  = ons_red_generator;        
+        else
+            _trg_gen  = ons_red_generator;
        }
-       
+
        entity _cp = findchain(classname, "onslaught_controlpoint");
        while(_cp)
        {
-           if(_cp.team == self.team)            
-        {            
+           if(_cp.team == self.team)
+        {
             _score = vlen(_trg_gen.origin - _cp.origin);
             if(_score < _best_score)
             {
                 _best = _cp;
-                _best_score = _score;            
+                _best_score = _score;
             }
-        }              
+        }
                _cp = _cp.chain;
        }
-       
-    vector _loc;        
-    float i;    
+
+    vector _loc;
+    float i;
     if(_best)
     {
         for(i = 0; i < 10; ++i)
         {
             _loc = _best.origin + '0 0 96';
-            _loc += ('0 1 0' * random()) * 128; 
+            _loc += ('0 1 0' * random()) * 128;
             tracebox(_loc, PL_MIN, PL_MAX, _loc, MOVE_NORMAL, self);
             if(trace_fraction == 1.0 && !trace_startsolid)
             {
@@ -1623,13 +1637,13 @@ MUTATOR_HOOKFUNCTION(ons_PlayerSpawn)
     {
         if(!autocvar_g_onslaught_spawn_at_generator)
             return 0;
-        
+
         _trg_gen = ((self.team == NUM_TEAM_1) ? ons_red_generator : ons_blue_generator);
-        
+
         for(i = 0; i < 10; ++i)
         {
             _loc = _trg_gen.origin + '0 0 96';
-            _loc += ('0 1 0' * random()) * 128; 
+            _loc += ('0 1 0' * random()) * 128;
             tracebox(_loc, PL_MIN, PL_MAX, _loc, MOVE_NORMAL, self);
             if(trace_fraction == 1.0 && !trace_startsolid)
             {
@@ -1639,15 +1653,49 @@ MUTATOR_HOOKFUNCTION(ons_PlayerSpawn)
             }
         }
     }
-    
+
     return 0;
 }
 
+MUTATOR_HOOKFUNCTION(ons_MonsterThink)
+{
+       entity e = find(world, targetname, self.target);
+       if (e != world)
+               self.team = e.team;
+
+       return FALSE;
+}
+
+MUTATOR_HOOKFUNCTION(ons_MonsterSpawn)
+{
+       entity e, ee = world;
+       
+       if(self.targetname)
+       {
+               e = find(world,target,self.targetname);
+               if(e != world)
+               {
+                       self.team = e.team;
+                       ee = e;
+               }
+       }
+       
+       if(ee)
+       {
+        activator = ee;
+        self.use();
+    }
+
+       return FALSE;
+}
+
 MUTATOR_DEFINITION(gamemode_onslaught)
 {
        MUTATOR_HOOK(BuildMutatorsPrettyString, ons_BuildMutatorsPrettyString, CBC_ORDER_ANY);
        MUTATOR_HOOK(BuildMutatorsString, ons_BuildMutatorsString, CBC_ORDER_ANY);
        MUTATOR_HOOK(PlayerSpawn, ons_PlayerSpawn, CBC_ORDER_ANY);
+       MUTATOR_HOOK(MonsterMove, ons_MonsterThink, CBC_ORDER_ANY);
+       MUTATOR_HOOK(MonsterSpawn, ons_MonsterSpawn, CBC_ORDER_ANY);
        //MUTATOR_HOOK(Spawn_Score, ons_Spawn_Score, CBC_ORDER_ANY);
 
        MUTATOR_ONADD