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