Clear out .health and .armorvalue from the client side
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / gamemodes / gamemode / onslaught / cl_controlpoint.qc
1 #include "cl_controlpoint.qh"
2
3 .vector colormod;
4 .float alpha;
5 .int count;
6 .float pain_finished;
7
8 .bool iscaptured;
9
10 .vector cp_origin, cp_bob_origin;
11 .float cp_bob_spd;
12
13 .vector cp_bob_dmg;
14
15 .vector punchangle;
16
17 .float max_health;
18
19 .entity icon_realmodel;
20
21 void cpicon_draw(entity this)
22 {
23         if(time < this.move_time) { return; }
24
25         if(this.cp_bob_dmg_z > 0)
26                 this.cp_bob_dmg_z = this.cp_bob_dmg_z - 3 * frametime;
27         else
28                 this.cp_bob_dmg_z = 0;
29         this.cp_bob_origin_z = 4 * PI * (1 - cos(this.cp_bob_spd));
30         this.cp_bob_spd = this.cp_bob_spd + 1.875 * frametime;
31         this.colormod = '1 1 1' * (2 - bound(0, (this.pain_finished - time) / 10, 1));
32
33         if(!this.iscaptured) this.alpha = GetResourceAmount(this, RESOURCE_HEALTH) / this.max_health;
34
35         if(this.iscaptured)
36         {
37                 if (this.punchangle_x > 0)
38                 {
39                         this.punchangle_x = this.punchangle_x - 60 * frametime;
40                         if (this.punchangle_x < 0)
41                                 this.punchangle_x = 0;
42                 }
43                 else if (this.punchangle_x < 0)
44                 {
45                         this.punchangle_x = this.punchangle_x + 60 * frametime;
46                         if (this.punchangle_x > 0)
47                                 this.punchangle_x = 0;
48                 }
49
50                 if (this.punchangle_y > 0)
51                 {
52                         this.punchangle_y = this.punchangle_y - 60 * frametime;
53                         if (this.punchangle_y < 0)
54                                 this.punchangle_y = 0;
55                 }
56                 else if (this.punchangle_y < 0)
57                 {
58                         this.punchangle_y = this.punchangle_y + 60 * frametime;
59                         if (this.punchangle_y > 0)
60                                 this.punchangle_y = 0;
61                 }
62
63                 if (this.punchangle_z > 0)
64                 {
65                         this.punchangle_z = this.punchangle_z - 60 * frametime;
66                         if (this.punchangle_z < 0)
67                                 this.punchangle_z = 0;
68                 }
69                 else if (this.punchangle_z < 0)
70                 {
71                         this.punchangle_z = this.punchangle_z + 60 * frametime;
72                         if (this.punchangle_z > 0)
73                                 this.punchangle_z = 0;
74                 }
75
76                 this.angles_x = this.punchangle_x;
77                 this.angles_y = this.punchangle_y + this.angles_y;
78                 this.angles_z = this.punchangle_z;
79                 this.angles_y = this.angles_y + 45 * frametime;
80         }
81
82         setorigin(this, this.cp_origin + this.cp_bob_origin + this.cp_bob_dmg);
83 }
84
85 void cpicon_damage(entity this, float hp)
86 {
87         if(!this.iscaptured) { return; }
88
89         if(hp < this.max_health * 0.25)
90                 setmodel(this, MDL_ONS_CP3);
91         else if(hp < this.max_health * 0.50)
92                 setmodel(this, MDL_ONS_CP2);
93         else if(hp < this.max_health * 0.75)
94                 setmodel(this, MDL_ONS_CP1);
95         else if(hp <= this.max_health || hp >= this.max_health)
96                 setmodel(this, MDL_ONS_CP);
97
98         this.punchangle = (2 * randomvec() - '1 1 1') * 45;
99
100         this.cp_bob_dmg_z = (2 * random() - 1) * 15;
101         this.pain_finished = time + 1;
102         this.colormod = '2 2 2';
103
104         setsize(this, CPICON_MIN, CPICON_MAX);
105 }
106
107 void cpicon_construct(entity this, bool isnew)
108 {
109         this.netname = "Control Point Icon";
110
111         setmodel(this, MDL_ONS_CP);
112         setsize(this, CPICON_MIN, CPICON_MAX);
113
114         if(this.icon_realmodel == NULL)
115         {
116                 this.icon_realmodel = spawn();
117                 setmodel(this.icon_realmodel, MDL_Null);
118                 setorigin(this.icon_realmodel, this.origin);
119                 setsize(this.icon_realmodel, CPICON_MIN, CPICON_MAX);
120                 set_movetype(this.icon_realmodel, MOVETYPE_NOCLIP);
121                 this.icon_realmodel.solid = SOLID_NOT;
122         }
123
124         if(this.iscaptured) { this.icon_realmodel.solid = SOLID_BBOX; }
125
126         set_movetype(this, MOVETYPE_NOCLIP);
127         this.solid                      = SOLID_NOT;
128         set_movetype(this, MOVETYPE_NOCLIP);
129         this.move_time          = time;
130         this.drawmask           = MASK_NORMAL;
131         this.alpha                      = 1;
132         this.draw                       = cpicon_draw;
133         this.cp_origin          = this.origin;
134         this.cp_bob_origin      = '0 0 0.1';
135         this.cp_bob_spd         = 0;
136
137         if(isnew)
138                 IL_PUSH(g_drawables, this);
139 }
140
141 .vector glowmod;
142 void cpicon_changeteam(entity this)
143 {
144         if(this.team)
145         {
146                 this.glowmod = Team_ColorRGB(this.team - 1);
147                 this.teamradar_color = Team_ColorRGB(this.team - 1);
148                 this.colormap = 1024 + (this.team - 1) * 17;
149         }
150         else
151         {
152                 this.colormap = 1024;
153                 this.glowmod = '1 1 0';
154                 this.teamradar_color = '1 1 0';
155         }
156 }
157
158 NET_HANDLE(ENT_CLIENT_CONTROLPOINT_ICON, bool isnew)
159 {
160         return = true;
161         int sf = ReadByte();
162
163         if(sf & CPSF_SETUP)
164         {
165                 this.origin = ReadVector();
166                 setorigin(this, this.origin);
167
168                 SetResourceAmountExplicit(this, RESOURCE_HEALTH, ReadByte());
169                 this.max_health = ReadByte();
170                 this.count = ReadByte();
171                 this.team = ReadByte();
172                 this.iscaptured = ReadByte();
173
174                 if(!this.count)
175                         this.count = (GetResourceAmount(this, RESOURCE_HEALTH) - this.max_health) * frametime;
176
177                 cpicon_changeteam(this);
178                 cpicon_construct(this, isnew);
179         }
180
181         if(sf & CPSF_STATUS)
182         {
183                 int _tmp = ReadByte();
184                 if(_tmp != this.team)
185                 {
186                         this.team = _tmp;
187                         cpicon_changeteam(this);
188                 }
189
190                 _tmp = ReadByte();
191
192                 if(_tmp != GetResourceAmount(this, RESOURCE_HEALTH))
193                         cpicon_damage(this, _tmp);
194
195                 SetResourceAmountExplicit(this, RESOURCE_HEALTH, _tmp);
196         }
197 }