1 #include "controlpoint.qh"
3 #include "teamradar.qh"
4 #include "../common/movetypes/movetypes.qh"
13 .vector cp_origin, cp_bob_origin;
22 .entity icon_realmodel;
24 void cpicon_draw(entity this)
26 if(time < this.move_time) { return; }
28 if(this.cp_bob_dmg_z > 0)
29 this.cp_bob_dmg_z = this.cp_bob_dmg_z - 3 * frametime;
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));
36 if(!this.iscaptured) this.alpha = this.health / this.max_health;
40 if (this.punchangle_x > 0)
42 this.punchangle_x = this.punchangle_x - 60 * frametime;
43 if (this.punchangle_x < 0)
44 this.punchangle_x = 0;
46 else if (this.punchangle_x < 0)
48 this.punchangle_x = this.punchangle_x + 60 * frametime;
49 if (this.punchangle_x > 0)
50 this.punchangle_x = 0;
53 if (this.punchangle_y > 0)
55 this.punchangle_y = this.punchangle_y - 60 * frametime;
56 if (this.punchangle_y < 0)
57 this.punchangle_y = 0;
59 else if (this.punchangle_y < 0)
61 this.punchangle_y = this.punchangle_y + 60 * frametime;
62 if (this.punchangle_y > 0)
63 this.punchangle_y = 0;
66 if (this.punchangle_z > 0)
68 this.punchangle_z = this.punchangle_z - 60 * frametime;
69 if (this.punchangle_z < 0)
70 this.punchangle_z = 0;
72 else if (this.punchangle_z < 0)
74 this.punchangle_z = this.punchangle_z + 60 * frametime;
75 if (this.punchangle_z > 0)
76 this.punchangle_z = 0;
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;
85 setorigin(this, this.cp_origin + this.cp_bob_origin + this.cp_bob_dmg);
88 void cpicon_damage(entity this, float hp)
90 if(!this.iscaptured) { return; }
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);
101 this.punchangle = (2 * randomvec() - '1 1 1') * 45;
103 this.cp_bob_dmg_z = (2 * random() - 1) * 15;
104 this.pain_finished = time + 1;
105 this.colormod = '2 2 2';
107 setsize(this, CPICON_MIN, CPICON_MAX);
110 void cpicon_construct(entity this)
112 this.netname = "Control Point Icon";
114 setmodel(this, MDL_ONS_CP);
115 setsize(this, CPICON_MIN, CPICON_MAX);
117 if(this.icon_realmodel == world)
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;
128 if(this.iscaptured) { this.icon_realmodel.solid = SOLID_BBOX; }
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;
137 this.draw = cpicon_draw;
138 this.cp_origin = this.origin;
139 this.cp_bob_origin = '0 0 0.1';
144 void cpicon_changeteam(entity this)
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;
154 this.colormap = 1024;
155 this.glowmod = '1 1 0';
156 this.teamradar_color = '1 1 0';
160 void ent_cpicon(entity this)
166 this.origin_x = ReadCoord();
167 this.origin_y = ReadCoord();
168 this.origin_z = ReadCoord();
169 setorigin(this, this.origin);
171 this.health = ReadByte();
172 this.max_health = ReadByte();
173 this.count = ReadByte();
174 this.team = ReadByte();
175 this.iscaptured = ReadByte();
178 this.count = (this.health - this.max_health) * frametime;
180 cpicon_changeteam(this);
181 cpicon_construct(this);
186 int _tmp = ReadByte();
187 if(_tmp != this.team)
190 cpicon_changeteam(this);
195 if(_tmp != this.health)
196 cpicon_damage(this, _tmp);