]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/gamec/cl_weapons.c
added minstagib mutator, killmessages and a first bunch of announcer messages (soundf...
[divverent/nexuiz.git] / data / qcsrc / gamec / cl_weapons.c
1 // generic weapons table
2 // add new weapons here
3 void(float wpn, float wrequest) weapon_action =
4 {
5         if (cvar("g_minstagib"))
6         {
7                 if (wpn == WEP_NEX)
8                         w_nex(wrequest);
9                 return;
10         }
11         
12         if (wpn == WEP_LASER)
13                 w_laser(wrequest);
14         else if (wpn == WEP_SHOTGUN)
15                 w_shotgun(wrequest);
16         else if (wpn == WEP_UZI)
17                 w_uzi(wrequest);
18         else if (wpn == WEP_GRENADE_LAUNCHER)
19                 w_glauncher(wrequest);
20         else if (wpn == WEP_ELECTRO)
21                 w_electro(wrequest);
22         else if (wpn == WEP_CRYLINK)
23                 w_crylink(wrequest);
24         else if (wpn == WEP_NEX)
25                 w_nex(wrequest);
26         else if (wpn == WEP_HAGAR)
27                 w_hagar(wrequest);
28         else if (wpn == WEP_ROCKET_LAUNCHER)
29                 w_rlauncher(wrequest);
30 };
31
32 // switch between weapons
33 void(float imp) W_SwitchWeapon
34 {
35         weapon_hasammo = TRUE;
36         if (!client_hasweapon(self, imp, TRUE))
37         {
38                 if (!weapon_hasammo)
39                         sprint(self, "You don't have any ammo for that weapon\n");
40                 else
41                         sprint(self, "You don't own that weapon\n");
42         }
43         else
44                 self.switchweapon = imp;
45 };
46
47 // next weapon
48 void() W_NextWeapon =
49 {
50         local float weaponwant;
51
52         weaponwant = self.switchweapon + 1;
53         if (weaponwant < WEP_FIRST)
54                 weaponwant = WEP_LAST;
55         if (weaponwant > WEP_LAST)
56                 weaponwant = WEP_FIRST;
57         weapon_hasammo = TRUE;
58         while(!client_hasweapon(self, weaponwant, TRUE))
59         {
60                 weaponwant = weaponwant + 1;
61                 if (weaponwant < WEP_FIRST)
62                         weaponwant = WEP_LAST;
63                 if (weaponwant > WEP_LAST)
64                         weaponwant = WEP_FIRST;
65         }
66         self.switchweapon = weaponwant;
67 };
68
69 // prev weapon
70 void() W_PreviousWeapon =
71 {
72         local float weaponwant;
73
74         weaponwant = self.switchweapon - 1;
75         if (weaponwant < WEP_FIRST)
76                 weaponwant = WEP_LAST;
77         if (weaponwant > WEP_LAST)
78                 weaponwant = WEP_FIRST;
79         weapon_hasammo = TRUE;
80         while(!client_hasweapon(self, weaponwant, TRUE))
81         {
82                 weaponwant = weaponwant - 1;
83                 if (weaponwant < WEP_FIRST)
84                         weaponwant = WEP_LAST;
85                 if (weaponwant > WEP_LAST)
86                         weaponwant = WEP_FIRST;
87         }
88         self.switchweapon = weaponwant;
89 };
90
91 // Bringed back weapon frame
92 void() W_WeaponFrame =
93 {
94         if (!self.weaponentity || self.health <= 0)
95                 return; // Dead player can't use weapons and injure impulse commands
96
97         if (cvar("g_antilag"))
98         {
99                 // if aiming at a player and the original trace won't hit that player
100                 // anymore, try aiming at the player's new position
101                 if (self.cursor_trace_ent)
102                 {
103                         if (self.cursor_trace_ent.takedamage)
104                         {
105                                 traceline(self.origin + self.view_ofs, self.cursor_trace_endpos, FALSE, self);
106                                 if (trace_ent != self.cursor_trace_ent)
107                                 {
108                                         traceline(self.origin + self.view_ofs, self.cursor_trace_ent.origin + (self.cursor_trace_ent.mins + self.cursor_trace_ent.maxs) * 0.5, FALSE, self);
109                                         if (trace_ent == self.cursor_trace_ent)
110                                                 self.cursor_trace_endpos = trace_endpos;
111                                 }
112                         }
113                 }
114                 self.v_angle = vectoangles(self.cursor_trace_endpos - (self.origin + self.view_ofs));
115                 self.v_angle_x = 0 - self.v_angle_x;
116         }
117
118         makevectors(self.v_angle);
119
120         // Change weapon
121         if (self.weapon != self.switchweapon)
122         {
123                 if (self.weaponentity.state == WS_CLEAR)
124                 {
125                         self.weaponentity.state = WS_RAISE;
126                         weapon_action(self.switchweapon, WR_SETUP);
127                         // VorteX: add player model weapon select frame here
128                         // setcustomframe(PlayerWeaponRaise);
129                         weapon_action(self.weapon, WR_UPDATECOUNTS);
130                         weapon_action(self.weapon, WR_RAISE);
131                 }
132                 else if (self.weaponentity.state == WS_READY)
133                 {
134                         sound (self, CHAN_WEAPON, "weapons/weapon_switch.wav", 1, ATTN_NORM);
135                         self.weaponentity.state = WS_DROP;
136                         // VorteX: add player model weapon deselect frame here
137                         // setcustomframe(PlayerWeaponDrop);
138                         weapon_action(self.weapon, WR_DROP);
139                 }
140         }
141
142         if (self.button0)
143                 weapon_action(self.weapon, WR_FIRE1);
144         if (self.button3)
145                 weapon_action(self.weapon, WR_FIRE2);
146
147         // do weapon think
148         if (time >= self.weapon_nextthink)
149                 if (self.weapon_nextthink > 0)
150                         self.weapon_think();
151
152         // weapon bobbing and script actions
153         local float bobintensity, q1pitching, framespeed, diff;
154         local vector vel, realorg, layer1, boblayer;
155
156         bobintensity = cvar("g_viewweapon_bobintensity"); // weapon bob intensity
157         q1pitching = fabs(cvar("g_viewweapon_q1pitching")); // q1 style of "bob" when looking up and down
158
159         realorg = self.weaponentity.origin + self.weaponentity.view_ofs;
160         realorg = realorg - self.weaponentity.finaldest; // finaldest is last bob position
161
162         // VorteX: actually this is needed for weapon screen offset
163         if (q1pitching)
164         {
165                 self.weaponentity.view_ofs_x = q1pitching*bound(-5.5, self.v_angle_x/45, 5.5);
166                 self.weaponentity.view_ofs_z = q1pitching*bound(-1.5, self.v_angle_x/60, 1.5);
167         }
168
169         // weapon origin interpolation, layer 1
170         if (realorg != self.weaponentity.pos1)
171         {
172                 framespeed = frametime*self.weaponentity.lip*10; // lip is speed of origin changing (of layer1)
173                 diff = vlen(realorg - self.weaponentity.pos1);
174                 // VorteX: add speed modifier (haste)?
175                 layer1 = frametime*10*self.weaponentity.lip*normalize(self.weaponentity.pos1 - realorg);
176                 if (diff <= vlen(layer1))
177                         layer1 = normalize(self.weaponentity.pos1 - realorg)*diff;
178         }
179
180         // weapon bobbing (q3-style)
181         if (self.flags & FL_ONGROUND && self.waterlevel < 2)
182         {
183                 // VorteX: only xy velocity matters
184                 vel_x = self.velocity_x;
185                 vel_y = self.velocity_y;
186                 framespeed = vlen(vel);
187                 // Y axis
188                 diff = bobintensity*framespeed/300;
189                 self.weaponentity.destvec_y = self.weaponentity.destvec_y + frametime*10;
190                 boblayer_y = diff*cos(self.weaponentity.destvec_y + 90);
191                 // Z axis
192                 diff = bobintensity*framespeed/540;
193                 self.weaponentity.destvec_z = self.weaponentity.destvec_z + frametime*20;
194                 boblayer_z = diff*cos(self.weaponentity.destvec_z);
195                 self.weaponentity.finaldest = boblayer;
196         }
197         else if (self.waterlevel > 0)
198         {// swim, all velocity matters
199                 // X axis
200                 framespeed = vlen(self.velocity);
201                 diff = bobintensity*framespeed/100;
202                 self.weaponentity.destvec_x = self.weaponentity.destvec_x + frametime*6;
203                 boblayer_x = diff*cos(self.weaponentity.destvec_x);
204                 self.weaponentity.finaldest = boblayer;
205         }
206         else
207                 self.weaponentity.finaldest = '0 0 0';
208         self.weaponentity.origin = realorg + boblayer + layer1 - self.weaponentity.view_ofs;
209 };