]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/clientkill.qc
Move ClientKill code into its own file
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / clientkill.qc
1 #include "clientkill.qh"
2
3 #include <server/defs.qh>
4
5 #include "g_damage.qh"
6 #include "teamplay.qh"
7
8 #include <common/vehicles/sv_vehicles.qh>
9 #include <common/notifications/all.qh>
10 #include <common/stats.qh>
11
12 void ClientKill_Now_TeamChange(entity this)
13 {
14         if (this.killindicator_teamchange == -1)
15         {
16                 TeamBalance_JoinBestTeam(this);
17         }
18         else if (this.killindicator_teamchange == -2)
19         {
20                 if (blockSpectators)
21                         Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_SPECTATE_WARNING, autocvar_g_maxplayers_spectator_blocktime);
22                 PutObserverInServer(this);
23         }
24         else
25                 SV_ChangeTeam(this, this.killindicator_teamchange - 1);
26         this.killindicator_teamchange = 0;
27 }
28
29 void ClientKill_Now(entity this)
30 {
31         if (this.vehicle)
32         {
33                 vehicles_exit(this.vehicle, VHEF_RELEASE);
34                 if (!this.killindicator_teamchange)
35                 {
36                         this.vehicle_health = -1;
37                         Damage(this, this, this, 1 , DEATH_KILL.m_id, DMG_NOWEP, this.origin, '0 0 0');
38                 }
39         }
40
41         if (this.killindicator && !wasfreed(this.killindicator))
42                 delete(this.killindicator);
43
44         this.killindicator = NULL;
45
46         if (this.killindicator_teamchange)
47                 ClientKill_Now_TeamChange(this);
48
49         if (!IS_SPEC(this) && !IS_OBSERVER(this) && MUTATOR_CALLHOOK(ClientKill_Now, this) == false)
50         {
51                 Damage(this, this, this, 100000, DEATH_KILL.m_id, DMG_NOWEP, this.origin, '0 0 0');
52         }
53
54         // now I am sure the player IS dead
55 }
56 void KillIndicator_Think(entity this)
57 {
58         if (game_stopped)
59         {
60                 this.owner.killindicator = NULL;
61                 delete(this);
62                 return;
63         }
64
65         if (this.owner.alpha < 0 && !this.owner.vehicle)
66         {
67                 this.owner.killindicator = NULL;
68                 delete(this);
69                 return;
70         }
71
72         if (this.cnt <= 0)
73         {
74                 ClientKill_Now(this.owner);
75                 return;
76         }
77         else if (this.count == 1) // count == 1 means that it's silent
78         {
79                 this.nextthink = time + 1;
80                 this.cnt -= 1;
81         }
82         else
83         {
84                 if (this.cnt <= 10)
85                         setmodel(this, MDL_NUM(this.cnt));
86                 if (IS_REAL_CLIENT(this.owner))
87                 {
88                         if (this.cnt <= 10)
89                                 Send_Notification(NOTIF_ONE, this.owner, MSG_ANNCE, Announcer_PickNumber(CNT_KILL, this.cnt));
90                 }
91                 this.nextthink = time + 1;
92                 this.cnt -= 1;
93         }
94 }
95
96 .float lip;
97 float clientkilltime;
98 .float clientkill_nexttime;
99 void ClientKill_TeamChange(entity this, float targetteam) // 0 = don't change, -1 = auto, -2 = spec
100 {
101         if (game_stopped)
102                 return;
103
104         float killtime = autocvar_g_balance_kill_delay;
105
106         if (MUTATOR_CALLHOOK(ClientKill, this, killtime))
107                 return;
108         killtime = M_ARGV(1, float);
109
110         this.killindicator_teamchange = targetteam;
111
112         if (!this.killindicator)
113         {
114                 if (!IS_DEAD(this))
115                 {
116                         killtime = max(killtime, this.clientkill_nexttime - time);
117                         this.clientkill_nexttime = time + killtime + autocvar_g_balance_kill_antispam;
118                 }
119
120                 if (killtime <= 0 || !IS_PLAYER(this) || IS_DEAD(this))
121                 {
122                         ClientKill_Now(this);
123                 }
124                 else
125                 {
126                         float starttime = max(time, clientkilltime);
127
128                         this.killindicator = spawn();
129                         this.killindicator.owner = this;
130                         this.killindicator.scale = 0.5;
131                         setattachment(this.killindicator, this, "");
132                         setorigin(this.killindicator, '0 0 52');
133                         setthink(this.killindicator, KillIndicator_Think);
134                         this.killindicator.nextthink = starttime + (this.lip) * 0.05;
135                         clientkilltime = max(clientkilltime, this.killindicator.nextthink + 0.05);
136                         this.killindicator.cnt = ceil(killtime);
137                         this.killindicator.count = bound(0, ceil(killtime), 10);
138                         //sprint(this, strcat("^1You'll be dead in ", ftos(this.killindicator.cnt), " seconds\n"));
139
140                         IL_EACH(g_clones, it.enemy == this && !(it.effects & CSQCMODEL_EF_RESPAWNGHOST),
141                         {
142                                 it.killindicator = spawn();
143                                 it.killindicator.owner = it;
144                                 it.killindicator.scale = 0.5;
145                                 setattachment(it.killindicator, it, "");
146                                 setorigin(it.killindicator, '0 0 52');
147                                 setthink(it.killindicator, KillIndicator_Think);
148                                 it.killindicator.nextthink = starttime + (it.lip) * 0.05;
149                                 //clientkilltime = max(clientkilltime, it.killindicator.nextthink + 0.05);
150                                 it.killindicator.cnt = ceil(killtime);
151                         });
152                         this.lip = 0;
153                 }
154         }
155         if (this.killindicator)
156         {
157                 if (targetteam == 0) // just die
158                 {
159                         this.killindicator.colormod = '0 0 0';
160                         if(IS_REAL_CLIENT(this))
161                         if(this.killindicator.cnt > 0)
162                                 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_TEAMCHANGE_SUICIDE, this.killindicator.cnt);
163                 }
164                 else if (targetteam == -1) // auto
165                 {
166                         this.killindicator.colormod = '0 1 0';
167                         if(IS_REAL_CLIENT(this))
168                         if(this.killindicator.cnt > 0)
169                                 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_TEAMCHANGE_AUTO, this.killindicator.cnt);
170                 }
171                 else if (targetteam == -2) // spectate
172                 {
173                         this.killindicator.colormod = '0.5 0.5 0.5';
174                         if(IS_REAL_CLIENT(this))
175                         if(this.killindicator.cnt > 0)
176                                 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_TEAMCHANGE_SPECTATE, this.killindicator.cnt);
177                 }
178                 else
179                 {
180                         this.killindicator.colormod = Team_ColorRGB(targetteam);
181                         if(IS_REAL_CLIENT(this))
182                         if(this.killindicator.cnt > 0)
183                                 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, APP_TEAM_NUM(targetteam, CENTER_TEAMCHANGE), this.killindicator.cnt);
184                 }
185         }
186
187 }
188
189 // Called when a client types 'kill' in the console
190 void ClientKill(entity this)
191 {
192         // TODO: once .health is removed, will need to check it here for the "already dead" message!
193
194         if (game_stopped || this.player_blocked || STAT(FROZEN, this))
195                 return;
196
197         ClientKill_TeamChange(this, 0);
198 }