]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/gamemodes/gamemode/onslaught/cl_controlpoint.qc
Merge branch 'master' into TimePath/scoreboard_elo
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / gamemodes / gamemode / onslaught / cl_controlpoint.qc
1 #include "cl_controlpoint.qh"
2
3 .vector colormod;
4 .float alpha;
5 .int count;
6 .float pain_finished;
7
8 .bool iscaptured;
9
10 .vector cp_origin, cp_bob_origin;
11 .float cp_bob_spd;
12
13 .vector cp_bob_dmg;
14
15 .vector punchangle;
16
17 .float max_health;
18
19 .entity icon_realmodel;
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 = this.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 + this.cp_bob_dmg);
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)
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 = spawn();
117                 setmodel(this.icon_realmodel, MDL_Null);
118                 setorigin(this.icon_realmodel, this.origin);
119                 setsize(this.icon_realmodel, CPICON_MIN, CPICON_MAX);
120                 set_movetype(this.icon_realmodel, MOVETYPE_NOCLIP);
121                 this.icon_realmodel.solid = SOLID_NOT;
122         }
123
124         if(this.iscaptured) { this.icon_realmodel.solid = SOLID_BBOX; }
125
126         set_movetype(this, MOVETYPE_NOCLIP);
127         this.solid                      = SOLID_NOT;
128         set_movetype(this, MOVETYPE_NOCLIP);
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
138 .vector glowmod;
139 void cpicon_changeteam(entity this)
140 {
141         if(this.team)
142         {
143                 this.glowmod = Team_ColorRGB(this.team - 1);
144                 this.teamradar_color = Team_ColorRGB(this.team - 1);
145                 this.colormap = 1024 + (this.team - 1) * 17;
146         }
147         else
148         {
149                 this.colormap = 1024;
150                 this.glowmod = '1 1 0';
151                 this.teamradar_color = '1 1 0';
152         }
153 }
154
155 NET_HANDLE(ENT_CLIENT_CONTROLPOINT_ICON, bool isnew)
156 {
157         return = true;
158         int sf = ReadByte();
159
160         if(sf & CPSF_SETUP)
161         {
162                 this.origin_x = ReadCoord();
163                 this.origin_y = ReadCoord();
164                 this.origin_z = ReadCoord();
165                 setorigin(this, this.origin);
166
167                 this.health = ReadByte();
168                 this.max_health = ReadByte();
169                 this.count = ReadByte();
170                 this.team = ReadByte();
171                 this.iscaptured = ReadByte();
172
173                 if(!this.count)
174                         this.count = (this.health - this.max_health) * frametime;
175
176                 cpicon_changeteam(this);
177                 cpicon_construct(this);
178         }
179
180         if(sf & CPSF_STATUS)
181         {
182                 int _tmp = ReadByte();
183                 if(_tmp != this.team)
184                 {
185                         this.team = _tmp;
186                         cpicon_changeteam(this);
187                 }
188
189                 _tmp = ReadByte();
190
191                 if(_tmp != this.health)
192                         cpicon_damage(this, _tmp);
193
194                 this.health = _tmp;
195         }
196 }