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