]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/tturrets/system/system_damage.qc
Merge branch 'master' into mario/monsters
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / tturrets / system / system_damage.qc
1 /*
2 * Spawn a boom, trow fake bits arround
3 * and hide the real ones.
4 */
5 void turret_hide()
6 {
7     self.effects   |= EF_NODRAW;
8     self.nextthink = time + self.respawntime - 0.2;
9     self.think     = turret_stdproc_respawn;
10 }
11
12 void turret_stdproc_die()
13 {
14     self.deadflag           = DEAD_DEAD;
15     self.tur_head.deadflag  = self.deadflag;
16
17 // Unsolidify and hide real parts
18     self.solid              = SOLID_NOT;
19     self.tur_head.solid     = self.solid;
20
21     self.event_damage           = func_null;
22     self.takedamage             = DAMAGE_NO;
23
24     self.health             = 0;
25         
26         MUTATOR_CALLHOOK(TurretDies);
27
28 // Go boom
29     //RadiusDamage (self,self, min(self.ammo,50),min(self.ammo,50) * 0.25,250,world,min(self.ammo,50)*5,DEATH_TURRET,world);
30
31     if(self.damage_flags & TFL_DMG_DEATH_NORESPAWN)
32     {
33         if (self.turret_diehook)
34             self.turret_diehook();
35
36         remove(self.tur_head);
37         remove(self);
38     }
39     else
40     {
41                 // Setup respawn
42         self.SendFlags      |= TNSF_STATUS;
43         self.nextthink      = time + 0.2;
44         self.think          = turret_hide;
45         
46         if (self.turret_diehook)
47             self.turret_diehook();
48     }
49 }
50
51 void turret_stdproc_respawn()
52 {
53     // Make sure all parts belong to the same team since
54     // this function doubles as "teamchange" function.
55     self.tur_head.team  = self.team;
56
57     self.effects             &~= EF_NODRAW;
58     self.deadflag           = DEAD_NO;
59     self.effects            = EF_LOWPRECISION;
60     self.solid              = SOLID_BBOX;
61     
62     self.takedamage                     = DAMAGE_AIM;
63     self.event_damage           = turret_stdproc_damage;
64
65     self.avelocity              = '0 0 0';
66     self.tur_head.avelocity     = self.avelocity;
67     self.tur_head.angles        = self.idle_aim;
68     self.health                 = self.tur_health;
69         self.max_health                         = self.tur_health;
70
71     self.enemy                  = world;
72     self.volly_counter          = self.shot_volly;
73     self.ammo                   = self.ammo_max;
74
75     self.nextthink  = time + self.ticrate;
76     self.think      = turret_think;
77     
78     self.SendFlags  = TNSF_FULL_UPDATE;
79
80     if (self.turret_respawnhook)
81         self.turret_respawnhook();
82 }
83
84 /*
85 * Standard damage proc.
86 */
87 void turret_stdproc_damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector vforce)
88 {
89     // Enougth allready!
90     if(self.deadflag == DEAD_DEAD)
91         return;
92
93     // Inactive turrets take no damage. (hm..)
94     if not (self.active)
95         return;
96
97     if (teamplay)
98     if (self.team == attacker.team)
99     {
100         // This does not happen anymore. Re-enable if you fix that.
101         if(clienttype(attacker) == CLIENTTYPE_REAL)
102             sprint(attacker, "\{1}Turret tells you: I'm on your team!\n");
103
104         if(autocvar_g_friendlyfire)
105             damage = damage * autocvar_g_friendlyfire;
106         else
107             return;
108     }
109
110     self.health = self.health - damage;
111
112     // thorw head slightly off aim when hit?
113     if (self.damage_flags & TFL_DMG_HEADSHAKE)
114     {
115         self.tur_head.angles_x = self.tur_head.angles_x + (-0.5 + random()) * damage;
116         self.tur_head.angles_y = self.tur_head.angles_y + (-0.5 + random()) * damage;
117         
118         self.SendFlags  |= TNSF_ANG;
119     }
120
121     if (self.turrcaps_flags & TFL_TURRCAPS_MOVE)
122         self.velocity = self.velocity + vforce;
123     
124     if (self.health <= 0)
125     {
126         self.event_damage           = func_null;
127         self.tur_head.event_damage  = func_null;
128         self.takedamage             = DAMAGE_NO;
129         self.nextthink = time;
130         self.think = turret_stdproc_die;
131     }
132     
133     self.SendFlags  |= TNSF_STATUS;
134 }