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