]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/g_violence.qc
Net: register all types
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / g_violence.qc
1 #include "g_violence.qh"
2
3 .int state;
4
5 REGISTER_NET_TEMP(net_gibsplash)
6
7 bool Violence_GibSplash_SendEntity(entity this, entity to, int sf)
8 {
9         int channel = MSG_ONE;
10         msg_entity = to;
11         WriteHeader(channel, net_gibsplash);
12         WriteByte(channel, this.state); // actually type
13         WriteByte(channel, bound(1, this.cnt * 16, 255)); // gibbage amount multiplier
14         WriteShort(channel, floor(this.origin.x / 4)); // not using a coord here, as gibs don't need this accuracy
15         WriteShort(channel, floor(this.origin.y / 4)); // not using a coord here, as gibs don't need this accuracy
16         WriteShort(channel, floor(this.origin.z / 4)); // not using a coord here, as gibs don't need this accuracy
17         WriteShort(channel, this.oldorigin.x); // acrually compressed velocity
18         return true;
19 }
20
21 void Violence_GibSplash_At(vector org, vector dir, float type, float amount, entity gibowner, entity attacker)
22 {SELFPARAM();
23         if(g_cts) // no gibs in CTS
24                 return;
25
26         entity e = new(gibsplash);
27         e.cnt = amount;
28         e.state = type; // should stay smaller than 15
29         if(!sound_allowed(MSG_BROADCAST, gibowner) || !sound_allowed(MSG_BROADCAST, attacker))
30                 e.state |= 0x40; // "silence" bit
31         e.state |= 8 * self.species; // gib type, ranges from 0 to 15
32
33         // if this is a copied dead body, send the num of its player instead
34         // TODO: remove this field, read from model txt files
35         if(self.classname == "body")
36                 e.team = num_for_edict(self.enemy);
37         else
38                 e.team = num_for_edict(self);
39
40         setorigin(e, org);
41         e.velocity = dir;
42
43         e.oldorigin_x = compressShortVector(e.velocity);
44
45         entity cl; FOR_EACH_REALCLIENT(cl) Violence_GibSplash_SendEntity(e, cl, 0);
46         remove(e);
47 }
48
49 void Violence_GibSplash(entity source, float type, float amount, entity attacker)
50 {
51         Violence_GibSplash_At(source.origin + source.view_ofs, source.velocity, type, amount, source, attacker);
52 }