]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/controlpoint.qc
Move mod directory below qcsrc
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / controlpoint.qc
1 #include "controlpoint.qh"
2 #include "gibs.qh"
3 #include "teamradar.qh"
4 #include "../common/movetypes/movetypes.qh"
5
6 .float alpha;
7 bool cpicon_precached;
8 .int count;
9 .float pain_finished;
10
11 .bool iscaptured;
12
13 .vector cp_origin, cp_bob_origin;
14 .float cp_bob_spd;
15
16 .vector cp_bob_dmg;
17
18 .vector punchangle;
19
20 .float max_health;
21
22 .entity icon_realmodel;
23
24 void cpicon_precache()
25 {
26         if(cpicon_precached)
27                 return; // already precached
28
29         precache_model("models/onslaught/controlpoint_icon_dmg3.md3");
30         precache_model("models/onslaught/controlpoint_icon_dmg2.md3");
31         precache_model("models/onslaught/controlpoint_icon_dmg1.md3");
32         precache_model("models/onslaught/controlpoint_icon.md3");
33
34         cpicon_precached = true;
35 }
36
37 void cpicon_draw()
38 {
39         if(time < self.move_time) { return; }
40
41         if(self.cp_bob_dmg_z > 0)
42                 self.cp_bob_dmg_z = self.cp_bob_dmg_z - 3 * frametime;
43         else
44                 self.cp_bob_dmg_z = 0;
45         self.cp_bob_origin_z = 4 * PI * (1 - cos(self.cp_bob_spd));
46         self.cp_bob_spd = self.cp_bob_spd + 1.875 * frametime;
47         self.colormod = '1 1 1' * (2 - bound(0, (self.pain_finished - time) / 10, 1));
48
49         if(!self.iscaptured) self.alpha = self.health / self.max_health;
50
51         if(self.iscaptured)
52         {
53                 if (self.punchangle_x > 0)
54                 {
55                         self.punchangle_x = self.punchangle_x - 60 * frametime;
56                         if (self.punchangle_x < 0)
57                                 self.punchangle_x = 0;
58                 }
59                 else if (self.punchangle_x < 0)
60                 {
61                         self.punchangle_x = self.punchangle_x + 60 * frametime;
62                         if (self.punchangle_x > 0)
63                                 self.punchangle_x = 0;
64                 }
65
66                 if (self.punchangle_y > 0)
67                 {
68                         self.punchangle_y = self.punchangle_y - 60 * frametime;
69                         if (self.punchangle_y < 0)
70                                 self.punchangle_y = 0;
71                 }
72                 else if (self.punchangle_y < 0)
73                 {
74                         self.punchangle_y = self.punchangle_y + 60 * frametime;
75                         if (self.punchangle_y > 0)
76                                 self.punchangle_y = 0;
77                 }
78
79                 if (self.punchangle_z > 0)
80                 {
81                         self.punchangle_z = self.punchangle_z - 60 * frametime;
82                         if (self.punchangle_z < 0)
83                                 self.punchangle_z = 0;
84                 }
85                 else if (self.punchangle_z < 0)
86                 {
87                         self.punchangle_z = self.punchangle_z + 60 * frametime;
88                         if (self.punchangle_z > 0)
89                                 self.punchangle_z = 0;
90                 }
91
92                 self.angles_x = self.punchangle_x;
93                 self.angles_y = self.punchangle_y + self.move_angles_y;
94                 self.angles_z = self.punchangle_z;
95                 self.move_angles_y = self.move_angles_y + 45 * frametime;
96         }
97
98         setorigin(self, self.cp_origin + self.cp_bob_origin + self.cp_bob_dmg);
99 }
100
101 void cpicon_damage(float hp)
102 {
103         if(!self.iscaptured) { return; }
104
105         if(hp < self.max_health * 0.25)
106                 setmodel(self, "models/onslaught/controlpoint_icon_dmg3.md3");
107         else if(hp < self.max_health * 0.50)
108                 setmodel(self, "models/onslaught/controlpoint_icon_dmg2.md3");
109         else if(hp < self.max_health * 0.75)
110                 setmodel(self, "models/onslaught/controlpoint_icon_dmg1.md3");
111         else if(hp <= self.max_health || hp >= self.max_health)
112                 setmodel(self, "models/onslaught/controlpoint_icon.md3");
113
114         self.punchangle = (2 * randomvec() - '1 1 1') * 45;
115
116         self.cp_bob_dmg_z = (2 * random() - 1) * 15;
117         self.pain_finished = time + 1;
118         self.colormod = '2 2 2';
119
120         setsize(self, CPICON_MIN, CPICON_MAX);
121 }
122
123 void cpicon_construct()
124 {
125         self.netname = "Control Point Icon";
126
127         setmodel(self, "models/onslaught/controlpoint_icon.md3");
128         setsize(self, CPICON_MIN, CPICON_MAX);
129
130         if(self.icon_realmodel == world)
131         {
132                 self.icon_realmodel = spawn();
133                 setmodel(self.icon_realmodel, "null");
134                 setorigin(self.icon_realmodel, self.origin);
135                 setsize(self.icon_realmodel, CPICON_MIN, CPICON_MAX);
136                 self.icon_realmodel.movetype = MOVETYPE_NOCLIP;
137                 self.icon_realmodel.solid = SOLID_NOT;
138                 self.icon_realmodel.move_origin = self.icon_realmodel.origin;
139         }
140
141         if(self.iscaptured) { self.icon_realmodel.solid = SOLID_BBOX; }
142
143         self.move_movetype      = MOVETYPE_NOCLIP;
144         self.solid                      = SOLID_NOT;
145         self.movetype           = MOVETYPE_NOCLIP;
146         self.move_origin        = self.origin;
147         self.move_time          = time;
148         self.drawmask           = MASK_NORMAL;
149         self.alpha                      = 1;
150         self.draw                       = cpicon_draw;
151         self.cp_origin          = self.origin;
152         self.cp_bob_origin      = '0 0 0.1';
153         self.cp_bob_spd         = 0;
154 }
155
156 .vector glowmod;
157 void cpicon_changeteam()
158 {
159         if(self.team)
160         {
161                 self.glowmod = Team_ColorRGB(self.team - 1);
162                 self.teamradar_color = Team_ColorRGB(self.team - 1);
163                 self.colormap = 1024 + (self.team - 1) * 17;
164         }
165         else
166         {
167                 self.colormap = 1024;
168                 self.glowmod = '1 1 0';
169                 self.teamradar_color = '1 1 0';
170         }
171 }
172
173 void ent_cpicon()
174 {
175         int sf = ReadByte();
176
177         if(sf & CPSF_SETUP)
178         {
179                 self.origin_x = ReadCoord();
180                 self.origin_y = ReadCoord();
181                 self.origin_z = ReadCoord();
182                 setorigin(self, self.origin);
183
184                 self.health = ReadByte();
185                 self.max_health = ReadByte();
186                 self.count = ReadByte();
187                 self.team = ReadByte();
188                 self.iscaptured = ReadByte();
189
190                 if(!self.count)
191                         self.count = (self.health - self.max_health) * frametime;
192
193                 cpicon_changeteam();
194                 cpicon_precache();
195                 cpicon_construct();
196         }
197
198         if(sf & CPSF_STATUS)
199         {
200                 int _tmp = ReadByte();
201                 if(_tmp != self.team)
202                 {
203                         self.team = _tmp;
204                         cpicon_changeteam();
205                 }
206
207                 _tmp = ReadByte();
208
209                 if(_tmp != self.health)
210                         cpicon_damage(_tmp);
211
212                 self.health = _tmp;
213         }
214 }