a691b866f789b448c8cfdf0d699cb2de892e9f85
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / nades / net.qc
1 #include "net.qh"
2
3 #ifdef GAMEQC
4
5 #include "nades.qh"
6
7 #ifdef CSQC
8 .float ltime;
9 void orb_draw(entity this)
10 {
11         float dt = time - this.move_time;
12         this.move_time = time;
13         if(dt <= 0)
14                 return;
15
16         this.alpha = (this.ltime - time) / this.orb_lifetime;
17         this.scale = min((1 - this.alpha)*this.orb_lifetime*4,1)*this.orb_radius;
18         this.angles = this.angles + dt * this.avelocity;
19 }
20
21 void orb_setup(entity e)
22 {
23         setmodel(e, MDL_NADE_ORB);
24         e.skin = 1;
25
26         setorigin(e, e.origin);
27
28         float model_radius = e.maxs.x;
29         vector size = '1 1 1' * e.orb_radius / 2;
30         setsize(e,-size,size);
31         e.orb_radius = e.orb_radius/model_radius*0.6;
32
33         e.draw = orb_draw;
34         IL_PUSH(g_drawables, e);
35         e.health = 255;
36         set_movetype(e, MOVETYPE_NONE);
37         e.solid = SOLID_NOT;
38         e.drawmask = MASK_NORMAL;
39         e.scale = 0.01;
40         e.avelocity = '7 0 11';
41         e.renderflags |= RF_ADDITIVE;
42 }
43 #endif
44
45 REGISTER_NET_LINKED(Nade_Orb)
46
47 #ifdef CSQC
48 NET_HANDLE(Nade_Orb, bool isNew)
49 {
50         Net_Accept(Nade_Orb);
51         int sf = ReadByte();
52         if (sf & 1) {
53                 this.origin = ReadVector();
54                 setorigin(this, this.origin);
55                 this.colormod = ReadVector();
56                 this.orb_lifetime = ReadByte();
57                 this.orb_radius = ReadShort();
58                 this.ltime = time + ReadByte()/10.0;
59                 // this.ltime = time + this.orb_lifetime;
60                 orb_setup(this);
61         }
62         return true;
63 }
64 #endif
65
66 #ifdef SVQC
67 bool orb_send(entity this, entity to, int sf)
68 {
69         int channel = MSG_ENTITY;
70         WriteHeader(channel, Nade_Orb);
71         WriteByte(channel, sf);
72         if (sf & 1) {
73                 WriteVector(channel, this.origin);
74
75                 WriteVector(channel, this.colormod);
76
77                 WriteByte(channel, this.orb_lifetime);
78                 //WriteByte(MSG_ENTITY, this.ltime - time + 1);
79                 WriteShort(channel, this.orb_radius);
80                 // round time delta to a 1/10th of a second
81                 WriteByte(channel, (this.ltime - time)*10.0+0.5);
82         }
83         return true;
84 }
85 #endif
86
87 #endif