]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mutators/mutator/nades/net.qc
Merge branch 'terencehill/mapvote_winnermap' into 'master'
[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 #include <client/view.qh>
9
10 .float ltime;
11 void orb_draw(entity this)
12 {
13         float dt = time - this.move_time;
14         this.move_time = time;
15         if(dt <= 0)
16                 return;
17
18         this.alpha = (this.ltime - time) / this.orb_lifetime;
19         this.scale = min((1 - this.alpha)*this.orb_lifetime*4,1)*this.orb_radius;
20         this.angles = this.angles + dt * this.avelocity;
21 }
22
23 float orb_drawtime; // global storage of last drawn orb frame, to counter overlapping orbs
24 void orb_draw2d(entity this)
25 {
26         if(time <= orb_drawtime)
27                 return;
28
29         if(boxesoverlap(view_origin - '1 1 1', view_origin + '1 1 1', this.absmin, this.absmax))
30         {
31                 orb_drawtime = time; // prevent rendering more than one of these per frame!
32                 float orb_alpha = 0.65 * (this.ltime - time) / this.orb_lifetime;
33                 drawfill('0 0 0', vec2(vid_conwidth, vid_conheight), this.colormod, autocvar_hud_colorflash_alpha * orb_alpha, DRAWFLAG_ADDITIVE);
34         }
35 }
36
37 void orb_setup(entity e)
38 {
39         setmodel(e, MDL_NADE_ORB);
40         e.skin = 1;
41
42         setorigin(e, e.origin);
43
44         float model_radius = e.maxs.x;
45         vector size = '1 1 1' * e.orb_radius / 2;
46         setsize(e,-size,size);
47         e.orb_radius = e.orb_radius/model_radius*0.6;
48
49         e.draw = orb_draw;
50         e.draw2d = orb_draw2d;
51         IL_PUSH(g_drawables, e);
52         IL_PUSH(g_drawables_2d, e);
53         SetResourceExplicit(e, RES_HEALTH, 255);
54         set_movetype(e, MOVETYPE_NONE);
55         e.solid = SOLID_NOT;
56         e.drawmask = MASK_NORMAL;
57         e.scale = 0.01;
58         e.avelocity = '7 0 11';
59         e.renderflags |= RF_ADDITIVE;
60 }
61 #endif
62
63 REGISTER_NET_LINKED(Nade_Orb)
64
65 #ifdef CSQC
66 NET_HANDLE(Nade_Orb, bool isNew)
67 {
68         Net_Accept(Nade_Orb);
69         int sf = ReadByte();
70         if (sf & 1) {
71                 this.origin = ReadVector();
72                 setorigin(this, this.origin);
73                 this.colormod = ReadVector();
74                 this.orb_lifetime = ReadByte();
75                 this.orb_radius = ReadShort();
76                 this.ltime = time + ReadByte()/10.0;
77                 // this.ltime = time + this.orb_lifetime;
78                 orb_setup(this);
79         }
80         return true;
81 }
82 #endif
83
84 #ifdef SVQC
85 bool orb_send(entity this, entity to, int sf)
86 {
87         int channel = MSG_ENTITY;
88         WriteHeader(channel, Nade_Orb);
89         WriteByte(channel, sf);
90         if (sf & 1) {
91                 WriteVector(channel, this.origin);
92
93                 WriteVector(channel, this.colormod);
94
95                 WriteByte(channel, this.orb_lifetime);
96                 //WriteByte(MSG_ENTITY, this.ltime - time + 1);
97                 WriteShort(channel, this.orb_radius);
98                 // round time delta to a 1/10th of a second
99                 WriteByte(channel, (this.ltime - time)*10.0+0.5);
100         }
101         return true;
102 }
103 #endif
104
105 #endif