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