new sounds for grenade bounce and rocket alt-fire and credit Christian Ice for these
[divverent/nexuiz.git] / data / qcsrc / server / gamec / w_grenadelauncher.c
1 void() glauncher_ready_01;
2 void() glauncher_fire1_01;
3 void() glauncher_fire2_01;
4 void() glauncher_deselect_01;
5 void() glauncher_select_01;
6
7 float() glauncher_check =
8 {
9         if (self.ammo_rockets >= cvar("g_balance_grenadelauncher_primary_ammo"))
10                 return TRUE;
11         return FALSE;
12 };
13
14 float() glauncher_check2 =
15 {
16         if (self.ammo_rockets >= cvar("g_balance_grenadelauncher_secondary_ammo"))
17                 return TRUE;
18         return FALSE;
19 };
20
21 void(float req) w_glauncher =
22 {
23         if (req == WR_IDLE)
24                 glauncher_ready_01();
25         else if (req == WR_FIRE1)
26                 weapon_prepareattack(glauncher_check, glauncher_check, glauncher_fire1_01, cvar("g_balance_grenadelauncher_primary_refire"));
27         else if (req == WR_FIRE2)
28                 weapon_prepareattack(glauncher_check2, glauncher_check2, glauncher_fire2_01, cvar("g_balance_grenadelauncher_secondary_refire"));
29         else if (req == WR_RAISE)
30                 glauncher_select_01();
31         else if (req == WR_UPDATECOUNTS)
32                 self.currentammo = self.ammo_rockets;
33         else if (req == WR_DROP)
34                 glauncher_deselect_01();
35         else if (req == WR_SETUP)
36                 weapon_setup(WEP_GRENADE_LAUNCHER, "w_gl.zym", IT_ROCKETS);
37         else if (req == WR_CHECKAMMO)
38                 weapon_hasammo = glauncher_check() + glauncher_check2();
39 };
40
41 void W_Grenade_Explode (void)
42 {
43         vector  org2;
44         org2 = findbetterlocation (self.origin);
45         te_explosion (org2);
46         effect (org2, "models/sprites/grenexpl.spr", 0, 12, 35);
47         sound (self, CHAN_BODY, "weapons/grenade_impact.ogg", 1, ATTN_NORM);
48
49         self.event_damage = SUB_Null;
50         RadiusDamage (self, self.owner, cvar("g_balance_grenadelauncher_primary_damage"), cvar("g_balance_grenadelauncher_primary_edgedamage"), cvar("g_balance_grenadelauncher_primary_radius"), world, cvar("g_balance_grenadelauncher_primary_force"), IT_GRENADE_LAUNCHER);
51
52         remove (self);
53 }
54
55 void W_Grenade_Explode2 (void)
56 {
57         vector  org2;
58         org2 = findbetterlocation (self.origin);
59         te_explosion (org2);
60         effect (org2, "models/sprites/grenexpl.spr", 0, 12, 35);
61         sound (self, CHAN_BODY, "weapons/grenade_impact.ogg", 1, ATTN_NORM);
62
63         self.event_damage = SUB_Null;
64         RadiusDamage (self, self.owner, cvar("g_balance_grenadelauncher_secondary_damage"), cvar("g_balance_grenadelauncher_secondary_edgedamage"), cvar("g_balance_grenadelauncher_secondary_radius"), world, cvar("g_balance_grenadelauncher_secondary_force"), IT_GRENADE_LAUNCHER);
65
66         remove (self);
67 }
68
69 void W_Grenade_Touch (void)
70 {
71         if (other.takedamage == DAMAGE_AIM)
72                 self.think ();
73         else
74         {
75                 float r;
76                 r = random() * 3;
77                 if(r < 1)
78                         sound (self, CHAN_IMPACT, "weapons/grenade_bounce1.ogg", 1, ATTN_NORM);
79                 else if(r < 2)
80                         sound (self, CHAN_IMPACT, "weapons/grenade_bounce2.ogg", 1, ATTN_NORM);
81                 else
82                         sound (self, CHAN_IMPACT, "weapons/grenade_bounce3.ogg", 1, ATTN_NORM);
83         }
84 }
85
86 void W_Grenade_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
87 {
88         self.health = self.health - damage;
89         if (self.health <= 0)
90         {
91                 self.owner = attacker;
92                 self.think ();
93         }
94 }
95
96 void W_Grenade_Attack (void)
97 {
98         local entity gren;
99         local vector org;
100
101         sound (self, CHAN_WEAPON, "weapons/grenade_fire.ogg", 1, ATTN_NORM);
102         if (self.items & IT_STRENGTH)
103                 sound (self, CHAN_AUTO, "weapons/strength_fire.ogg", 1, ATTN_NORM);
104
105         self.punchangle_x = -4;
106         if (cvar("g_use_ammunition"))
107                 self.ammo_rockets = self.ammo_rockets - cvar("g_balance_grenadelauncher_primary_ammo");
108         org = W_MuzzleOrigin (self, '24 8 -10');
109
110         gren = spawn ();
111         gren.owner = self;
112         gren.classname = "grenade";
113         gren.movetype = MOVETYPE_BOUNCE;
114         gren.solid = SOLID_BBOX;
115         gren.effects = EF_NOSHADOW;
116         setmodel(gren, "models/grenademodel.md3");
117         setsize(gren, '0 0 0', '0 0 0');
118         setorigin(gren, org);
119
120         gren.nextthink = time + cvar("g_balance_grenadelauncher_primary_lifetime");
121         gren.think = W_Grenade_Explode;
122         gren.touch = W_Grenade_Explode;
123         gren.velocity = v_forward * cvar("g_balance_grenadelauncher_primary_speed") + v_up * cvar("g_balance_grenadelauncher_primary_speed_up");
124         gren.avelocity_x = random () * -500 - 500;
125
126         gren.angles = vectoangles (gren.velocity);
127 }
128
129 void W_Grenade_Attack2 (void)
130 {
131         local entity gren;
132         local vector org;
133
134         sound (self, CHAN_WEAPON, "weapons/grenade_fire.ogg", 1, ATTN_NORM);
135         if (self.items & IT_STRENGTH)
136                 sound (self, CHAN_AUTO, "weapons/strength_fire.ogg", 1, ATTN_NORM);
137
138         self.punchangle_x = -4;
139         if (cvar("g_use_ammunition"))
140                 self.ammo_rockets = self.ammo_rockets - cvar("g_balance_grenadelauncher_secondary_ammo");
141         org = W_MuzzleOrigin (self, '24 8 -10');
142
143         gren = spawn ();
144         gren.owner = self;
145         gren.classname = "grenade";
146         gren.movetype = MOVETYPE_BOUNCE;
147         gren.solid = SOLID_BBOX;
148         gren.effects = EF_NOSHADOW;
149         setmodel(gren, "models/grenademodel.md3");
150         setsize(gren, '0 0 -3', '0 0 -3');
151         setorigin(gren, org);
152
153         gren.nextthink = time + cvar("g_balance_grenadelauncher_secondary_lifetime");
154         gren.think = W_Grenade_Explode2;
155         gren.touch = W_Grenade_Touch;
156         gren.takedamage = DAMAGE_YES;
157         gren.health = 10;
158         gren.damageforcescale = 4;
159         gren.event_damage = W_Grenade_Damage;
160         gren.velocity = v_forward * cvar("g_balance_grenadelauncher_secondary_speed") + v_up * cvar("g_balance_grenadelauncher_secondary_speed_up");
161         gren.avelocity = '100 150 100';
162
163         gren.angles = vectoangles (gren.velocity);
164 }
165
166 // weapon frames
167
168 void()  glauncher_ready_01 =    {weapon_thinkf(WFRAME_IDLE, 0.1, glauncher_ready_01); self.weaponentity.state = WS_READY;};
169 void()  glauncher_select_01 =   {weapon_thinkf(-1, cvar("g_balance_weaponswitchdelay"), w_ready); weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, '0 0 0');};
170 void()  glauncher_deselect_01 = {weapon_thinkf(-1, cvar("g_balance_weaponswitchdelay"), w_clear); weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, PLAYER_WEAPONSELECTION_RANGE);};
171 void()  glauncher_fire1_01 =
172 {
173         weapon_doattack(glauncher_check, glauncher_check, W_Grenade_Attack);
174         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_grenadelauncher_primary_animtime"), glauncher_ready_01);
175 };
176 void()  glauncher_fire2_01 =
177 {
178         weapon_doattack(glauncher_check2, glauncher_check2, W_Grenade_Attack2);
179         weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_grenadelauncher_secondary_animtime"), glauncher_ready_01);
180 };