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