1 #include "controlpoint.qh"
3 #include "teamradar.qh"
4 #include "../common/movetypes/movetypes.qh"
12 .vector cp_origin, cp_bob_origin;
21 .entity icon_realmodel;
23 void cpicon_draw(entity this)
25 if(time < this.move_time) { return; }
27 if(this.cp_bob_dmg_z > 0)
28 this.cp_bob_dmg_z = this.cp_bob_dmg_z - 3 * frametime;
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));
35 if(!this.iscaptured) this.alpha = this.health / this.max_health;
39 if (this.punchangle_x > 0)
41 this.punchangle_x = this.punchangle_x - 60 * frametime;
42 if (this.punchangle_x < 0)
43 this.punchangle_x = 0;
45 else if (this.punchangle_x < 0)
47 this.punchangle_x = this.punchangle_x + 60 * frametime;
48 if (this.punchangle_x > 0)
49 this.punchangle_x = 0;
52 if (this.punchangle_y > 0)
54 this.punchangle_y = this.punchangle_y - 60 * frametime;
55 if (this.punchangle_y < 0)
56 this.punchangle_y = 0;
58 else if (this.punchangle_y < 0)
60 this.punchangle_y = this.punchangle_y + 60 * frametime;
61 if (this.punchangle_y > 0)
62 this.punchangle_y = 0;
65 if (this.punchangle_z > 0)
67 this.punchangle_z = this.punchangle_z - 60 * frametime;
68 if (this.punchangle_z < 0)
69 this.punchangle_z = 0;
71 else if (this.punchangle_z < 0)
73 this.punchangle_z = this.punchangle_z + 60 * frametime;
74 if (this.punchangle_z > 0)
75 this.punchangle_z = 0;
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;
84 setorigin(this, this.cp_origin + this.cp_bob_origin + this.cp_bob_dmg);
87 void cpicon_damage(entity this, float hp)
89 if(!this.iscaptured) { return; }
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);
100 this.punchangle = (2 * randomvec() - '1 1 1') * 45;
102 this.cp_bob_dmg_z = (2 * random() - 1) * 15;
103 this.pain_finished = time + 1;
104 this.colormod = '2 2 2';
106 setsize(this, CPICON_MIN, CPICON_MAX);
109 void cpicon_construct(entity this)
111 this.netname = "Control Point Icon";
113 setmodel(this, MDL_ONS_CP);
114 setsize(this, CPICON_MIN, CPICON_MAX);
116 if(this.icon_realmodel == world)
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;
127 if(this.iscaptured) { this.icon_realmodel.solid = SOLID_BBOX; }
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;
136 this.draw = cpicon_draw;
137 this.cp_origin = this.origin;
138 this.cp_bob_origin = '0 0 0.1';
143 void cpicon_changeteam(entity this)
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;
153 this.colormap = 1024;
154 this.glowmod = '1 1 0';
155 this.teamradar_color = '1 1 0';
159 void ent_cpicon(entity this)
165 this.origin_x = ReadCoord();
166 this.origin_y = ReadCoord();
167 this.origin_z = ReadCoord();
168 setorigin(this, this.origin);
170 this.health = ReadByte();
171 this.max_health = ReadByte();
172 this.count = ReadByte();
173 this.team = ReadByte();
174 this.iscaptured = ReadByte();
177 this.count = (this.health - this.max_health) * frametime;
179 cpicon_changeteam(this);
180 cpicon_construct(this);
185 int _tmp = ReadByte();
186 if(_tmp != this.team)
189 cpicon_changeteam(this);
194 if(_tmp != this.health)
195 cpicon_damage(this, _tmp);