Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
cl_controlpoint.qc
Go to the documentation of this file.
1#include "cl_controlpoint.qh"
2
3.vector colormod;
4.float alpha;
5.int count;
7
9
11
13
14.vector punchangle;
15
17
19
21{
22 if(time < this.move_time) { return; }
23
24 if(this.cp_bob_dmg_z > 0)
25 this.cp_bob_dmg_z = this.cp_bob_dmg_z - 3 * frametime;
26 else
27 this.cp_bob_dmg_z = 0;
28 this.cp_bob_origin_z = 9 * (1 - cos(1.875 * time));
29 this.colormod = '1 1 1' * (2 - bound(0, (this.pain_finished - time) / 10, 1));
30
31 if(!this.iscaptured) this.alpha = GetResource(this, RES_HEALTH) / this.max_health;
32
33 if(this.iscaptured)
34 {
35 if (this.punchangle_x > 0)
36 {
37 this.punchangle_x = this.punchangle_x - 60 * frametime;
38 if (this.punchangle_x < 0)
39 this.punchangle_x = 0;
40 }
41 else if (this.punchangle_x < 0)
42 {
43 this.punchangle_x = this.punchangle_x + 60 * frametime;
44 if (this.punchangle_x > 0)
45 this.punchangle_x = 0;
46 }
47
48 if (this.punchangle_y > 0)
49 {
50 this.punchangle_y = this.punchangle_y - 60 * frametime;
51 if (this.punchangle_y < 0)
52 this.punchangle_y = 0;
53 }
54 else if (this.punchangle_y < 0)
55 {
56 this.punchangle_y = this.punchangle_y + 60 * frametime;
57 if (this.punchangle_y > 0)
58 this.punchangle_y = 0;
59 }
60
61 if (this.punchangle_z > 0)
62 {
63 this.punchangle_z = this.punchangle_z - 60 * frametime;
64 if (this.punchangle_z < 0)
65 this.punchangle_z = 0;
66 }
67 else if (this.punchangle_z < 0)
68 {
69 this.punchangle_z = this.punchangle_z + 60 * frametime;
70 if (this.punchangle_z > 0)
71 this.punchangle_z = 0;
72 }
73
74 this.angles_x = this.punchangle_x;
75 this.angles_y = this.punchangle_y + this.angles_y;
76 this.angles_z = this.punchangle_z;
77 this.angles_y = this.angles_y + 45 * frametime;
78 }
79
80 setorigin(this, this.cp_origin + this.cp_bob_origin + eZ * this.cp_bob_dmg_z);
81}
82
83void cpicon_damage(entity this, float hp)
84{
85 if(!this.iscaptured) { return; }
86
87 if(hp < this.max_health * 0.25)
88 setmodel(this, MDL_ONS_CP3);
89 else if(hp < this.max_health * 0.50)
90 setmodel(this, MDL_ONS_CP2);
91 else if(hp < this.max_health * 0.75)
92 setmodel(this, MDL_ONS_CP1);
93 else
94 setmodel(this, MDL_ONS_CP);
95
96 if(hp < GetResource(this, RES_HEALTH))
97 {
98 const int MIN_PUNCHANGLE = 8;
99 const int MAX_PUNCHANGLE = 25;
100 this.punchangle = (2 * randomvec() - '1 1 1') * (MAX_PUNCHANGLE - MIN_PUNCHANGLE);
101 this.punchangle.x += (this.punchangle.x >= 0 ? MIN_PUNCHANGLE : -MIN_PUNCHANGLE);
102 this.punchangle.y += (this.punchangle.y >= 0 ? MIN_PUNCHANGLE : -MIN_PUNCHANGLE);
103 this.punchangle.z += (this.punchangle.z >= 0 ? MIN_PUNCHANGLE : -MIN_PUNCHANGLE);
104
105 this.cp_bob_dmg_z = (2 * random() - 1) * 15;
106 this.pain_finished = time + 1;
107 this.colormod = '2 2 2';
108 }
109 else
110 this.pain_finished = 0;
111
112 setsize(this, CPICON_MIN, CPICON_MAX);
113}
114
115void cpicon_construct(entity this, bool isnew)
116{
117 this.netname = "Control Point Icon";
118
119 this.solid = SOLID_NOT; // before setmodel/setsize to prevent area grid linking
120 setmodel(this, MDL_ONS_CP);
121 setsize(this, CPICON_MIN, CPICON_MAX);
122
123 if(this.icon_realmodel == NULL)
124 {
125 this.icon_realmodel = new(cpicon_model);
126 this.icon_realmodel.solid = SOLID_NOT;
127 setmodel(this.icon_realmodel, MDL_Null);
128 setorigin(this.icon_realmodel, this.origin);
129 setsize(this.icon_realmodel, CPICON_MIN, CPICON_MAX);
131 }
132
133 if(this.iscaptured)
134 {
135 this.icon_realmodel.solid = SOLID_BBOX;
136 setorigin(this.icon_realmodel, this.icon_realmodel.origin); // link
137 }
138
140 this.move_time = time;
141 this.drawmask = MASK_NORMAL;
142 this.alpha = 1;
143 this.draw = cpicon_draw;
144 this.cp_origin = this.origin;
145 this.cp_bob_origin = '0 0 0.1';
146
147 if(isnew)
148 IL_PUSH(g_drawables, this);
149}
150
151.vector glowmod;
153{
154 if(this.team)
155 {
156 this.glowmod = Team_ColorRGB(this.team - 1);
157 this.teamradar_color = Team_ColorRGB(this.team - 1);
158 this.colormap = 1024 + (this.team - 1) * 17;
159 }
160 else
161 {
162 this.colormap = 1024;
163 this.glowmod = '1 1 0';
164 this.teamradar_color = '1 1 0';
165 }
166}
167
168NET_HANDLE(ENT_CLIENT_CONTROLPOINT_ICON, bool isnew)
169{
170 return = true;
171 int sf = ReadByte();
172
173 if(sf & CPSF_SETUP)
174 {
175 this.origin = ReadVector();
176 setorigin(this, this.origin);
177
178 SetResourceExplicit(this, RES_HEALTH, ReadByte());
179 this.max_health = ReadByte();
180 this.count = ReadByte();
181 this.team = ReadByte();
182 this.iscaptured = ReadByte();
183
184 if(!this.count)
185 this.count = (GetResource(this, RES_HEALTH) - this.max_health) * frametime;
186
187 cpicon_changeteam(this);
188 cpicon_construct(this, isnew);
189 }
190
191 if(sf & CPSF_STATUS)
192 {
193 int _tmp = ReadByte();
194 if(_tmp != this.team)
195 {
196 this.team = _tmp;
197 cpicon_changeteam(this);
198 }
199
200 _tmp = ReadByte();
201
202 if(_tmp != GetResource(this, RES_HEALTH))
203 cpicon_damage(this, _tmp);
204
205 SetResourceExplicit(this, RES_HEALTH, _tmp);
206 }
207}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
float max_health
vector punchangle
float pain_finished
void cpicon_draw(entity this)
void cpicon_construct(entity this, bool isnew)
entity icon_realmodel
vector cp_origin
bool iscaptured
void cpicon_changeteam(entity this)
float cp_bob_dmg_z
void cpicon_damage(entity this, float hp)
vector cp_bob_origin
const vector CPICON_MIN
const vector CPICON_MAX
const int CPSF_SETUP
const int CPSF_STATUS
float GetResource(entity e, Resource res_type)
Returns the current amount of resource the given entity has.
bool SetResourceExplicit(entity e, Resource res_type, float amount)
Sets the resource amount of an entity without calling any hooks.
string netname
Definition powerups.qc:20
vector colormod
Definition powerups.qc:21
float count
Definition powerups.qc:22
float alpha
Definition items.qc:13
IntrusiveList g_drawables
Definition main.qh:91
int team
Definition main.qh:188
#define setmodel(this, m)
Definition model.qh:26
float drawmask
float frametime
const float MASK_NORMAL
const float SOLID_BBOX
const float SOLID_NOT
float time
float colormap
vector origin
vector glowmod
angles_y
Definition ent_cs.qc:119
solid
Definition ent_cs.qc:165
ERASEABLE entity IL_PUSH(IntrusiveList this, entity it)
Push to tail.
#define NET_HANDLE(id, param)
Definition net.qh:15
#define ReadVector()
Definition net.qh:367
int ReadByte()
float bound(float min, float value, float max)
float cos(float f)
float random(void)
vector randomvec(void)
void set_movetype(entity this, int mt)
Definition movetypes.qc:4
float move_time
Definition movetypes.qh:77
const int MOVETYPE_NOCLIP
Definition movetypes.qh:137
#define NULL
Definition post.qh:14
vector Team_ColorRGB(int teamid)
Definition teams.qh:76
const vector eZ
Definition vector.qh:46