add a missing cvar
[divverent/nexuiz.git] / data / qcsrc / server / w_grenadelauncher.qc
1 void W_Grenade_Explode (void)
2 {
3         if(other.takedamage == DAMAGE_AIM)
4                 if(other.classname == "player")
5                         if(IsDifferentTeam(self.owner, other))
6                                 if(other.deadflag == DEAD_NO)
7                                         if(IsFlying(other))
8                                                 announce(self.owner, "announcer/male/airshot.wav");
9
10         self.event_damage = SUB_Null;
11         self.takedamage = DAMAGE_NO;
12         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"), self.projectiledeathtype, other);
13
14         remove (self);
15 }
16
17 void W_Grenade_Explode2 (void)
18 {
19         if(other.takedamage == DAMAGE_AIM)
20                 if(other.classname == "player")
21                         if(IsDifferentTeam(self.owner, other))
22                                 if(IsFlying(other))
23                                         announce(self.owner, "announcer/male/airshot.wav");
24
25         self.event_damage = SUB_Null;
26         self.takedamage = DAMAGE_NO;
27         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"), self.projectiledeathtype, other);
28
29         remove (self);
30 }
31
32 void W_Grenade_Touch1 (void)
33 {
34         PROJECTILE_TOUCH;
35         W_Grenade_Explode ();
36 }
37
38 void W_Grenade_Touch2 (void)
39 {
40         PROJECTILE_TOUCH;
41         if (other.takedamage == DAMAGE_AIM)
42         {
43                 self.use ();
44         }
45         else
46         {
47                 float r;
48                 r = random() * 6;
49                 if(r < 1)
50                         spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce1.wav", VOL_BASE, ATTN_NORM);
51                 else if(r < 2)
52                         spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce2.wav", VOL_BASE, ATTN_NORM);
53                 else if(r < 3)
54                         spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce3.wav", VOL_BASE, ATTN_NORM);
55                 else if(r < 4)
56                         spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce4.wav", VOL_BASE, ATTN_NORM);
57                 else if(r < 5)
58                         spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce5.wav", VOL_BASE, ATTN_NORM);
59                 else
60                         spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce6.wav", VOL_BASE, ATTN_NORM);
61                 self.projectiledeathtype |= HITTYPE_BOUNCE;
62         }
63 }
64
65 void W_Grenade_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
66 {
67         if (self.health <= 0)
68                 return;
69         self.health = self.health - damage;
70         if (self.health <= 0)
71         {
72                 W_PrepareExplosionByDamage(attacker, self.think);
73         }
74 }
75
76 void W_Grenade_Attack (void)
77 {
78         local entity gren;
79
80         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
81                 self.ammo_rockets = self.ammo_rockets - cvar("g_balance_grenadelauncher_primary_ammo");
82         W_SetupShot_ProjectileSize (self, '0 0 -3', '0 0 -3', FALSE, 4, "weapons/grenade_fire.wav", cvar("g_balance_grenadelauncher_primary_damage"));
83         w_shotdir = v_forward; // no TrueAim for grenades please
84
85         pointparticles(particleeffectnum("grenadelauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
86
87         gren = spawn ();
88         gren.owner = self;
89         gren.classname = "grenade";
90         gren.bot_dodge = TRUE;
91         gren.bot_dodgerating = cvar("g_balance_grenadelauncher_primary_damage");
92         gren.movetype = MOVETYPE_BOUNCE;
93         PROJECTILE_MAKETRIGGER(gren);
94         gren.projectiledeathtype = WEP_GRENADE_LAUNCHER;
95         setorigin(gren, w_shotorg);
96         setsize(gren, '0 0 -3', '0 0 -3');
97
98         gren.nextthink = time + cvar("g_balance_grenadelauncher_primary_lifetime");
99         gren.think = adaptor_think2use;
100         gren.use = W_Grenade_Explode;
101         gren.touch = W_Grenade_Touch1;
102         W_SETUPPROJECTILEVELOCITY_UP(gren, g_balance_grenadelauncher_primary);
103
104         gren.angles = vectoangles (gren.velocity);
105         gren.flags = FL_PROJECTILE;
106
107         CSQCProjectile(gren, TRUE, PROJECTILE_GRENADE, TRUE);   
108 }
109
110 void W_Grenade_Attack2 (void)
111 {
112         local entity gren;
113
114         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
115                 self.ammo_rockets = self.ammo_rockets - cvar("g_balance_grenadelauncher_secondary_ammo");
116         W_SetupShot_ProjectileSize (self, '0 0 -3', '0 0 -3', FALSE, 4, "weapons/grenade_fire.wav", cvar("g_balance_grenadelauncher_secondary_damage"));
117         w_shotdir = v_forward; // no TrueAim for grenades please
118
119         pointparticles(particleeffectnum("grenadelauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
120
121         gren = spawn ();
122         gren.owner = self;
123         gren.classname = "grenade";
124         gren.bot_dodge = TRUE;
125         gren.bot_dodgerating = cvar("g_balance_grenadelauncher_secondary_damage");
126         gren.movetype = MOVETYPE_BOUNCE;
127         PROJECTILE_MAKETRIGGER(gren);
128         gren.projectiledeathtype = WEP_GRENADE_LAUNCHER | HITTYPE_SECONDARY;
129         setsize(gren, '0 0 -3', '0 0 -3');
130         setorigin(gren, w_shotorg);
131
132         gren.nextthink = time + cvar("g_balance_grenadelauncher_secondary_lifetime");
133         gren.think = adaptor_think2use;
134         gren.use = W_Grenade_Explode2;
135         gren.touch = W_Grenade_Touch2;
136         gren.takedamage = DAMAGE_YES;
137         gren.health = cvar("g_balance_grenadelauncher_secondary_health");
138         gren.damageforcescale = cvar("g_balance_grenadelauncher_secondary_damageforcescale");
139         gren.event_damage = W_Grenade_Damage;
140         W_SETUPPROJECTILEVELOCITY_UP(gren, g_balance_grenadelauncher_secondary);
141
142         gren.angles = vectoangles (gren.velocity);
143         gren.flags = FL_PROJECTILE;
144
145         CSQCProjectile(gren, TRUE, PROJECTILE_GRENADE_BOUNCING, TRUE);
146 }
147
148 void spawnfunc_weapon_grenadelauncher (void)
149 {
150         weapon_defaultspawnfunc(WEP_GRENADE_LAUNCHER);
151 }
152
153 .float bot_secondary_grenademooth;
154 float w_glauncher(float req)
155 {
156         if (req == WR_AIM)
157         {
158                 self.BUTTON_ATCK = FALSE;
159                 self.BUTTON_ATCK2 = FALSE;
160                 if (self.bot_secondary_grenademooth == 0)
161                 {
162                         if(bot_aim(cvar("g_balance_grenadelauncher_primary_speed"), cvar("g_balance_grenadelauncher_primary_speed_up"), cvar("g_balance_grenadelauncher_primary_lifetime"), TRUE))
163                         {
164                                 self.BUTTON_ATCK = TRUE;
165                                 if(random() < 0.01) self.bot_secondary_grenademooth = 1;
166                         }
167                 }
168                 else
169                 {
170                         if(bot_aim(cvar("g_balance_grenadelauncher_secondary_speed"), cvar("g_balance_grenadelauncher_secondary_speed_up"), cvar("g_balance_grenadelauncher_secondary_lifetime"), TRUE))
171                         {
172                                 self.BUTTON_ATCK2 = TRUE;
173                                 if(random() < 0.02) self.bot_secondary_grenademooth = 0;
174                         }
175                 }
176         }
177         else if (req == WR_THINK)
178         {
179                 if (self.BUTTON_ATCK)
180                 if (weapon_prepareattack(0, cvar("g_balance_grenadelauncher_primary_refire")))
181                 {
182                         W_Grenade_Attack();
183                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_grenadelauncher_primary_animtime"), w_ready);
184                 }
185                 if (self.BUTTON_ATCK2)
186                 if (weapon_prepareattack(1, cvar("g_balance_grenadelauncher_secondary_refire")))
187                 {
188                         W_Grenade_Attack2();
189                         weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_grenadelauncher_secondary_animtime"), w_ready);
190                 }
191         }
192         else if (req == WR_PRECACHE)
193         {
194                 precache_model ("models/weapons/g_gl.md3");
195                 precache_model ("models/weapons/v_gl.md3");
196                 precache_model ("models/weapons/h_gl.dpm");
197                 precache_sound ("weapons/grenade_bounce1.wav");
198                 precache_sound ("weapons/grenade_bounce2.wav");
199                 precache_sound ("weapons/grenade_bounce3.wav");
200                 precache_sound ("weapons/grenade_bounce4.wav");
201                 precache_sound ("weapons/grenade_bounce5.wav");
202                 precache_sound ("weapons/grenade_bounce6.wav");
203                 precache_sound ("weapons/grenade_fire.wav");
204         }
205         else if (req == WR_SETUP)
206                 weapon_setup(WEP_GRENADE_LAUNCHER);
207         else if (req == WR_CHECKAMMO1)
208                 return self.ammo_rockets >= cvar("g_balance_grenadelauncher_primary_ammo");
209         else if (req == WR_CHECKAMMO2)
210                 return self.ammo_rockets >= cvar("g_balance_grenadelauncher_secondary_ammo");
211         else if (req == WR_SUICIDEMESSAGE)
212         {
213                 if(w_deathtype & HITTYPE_SECONDARY)
214                         w_deathtypestring = "tried out his own grenade";
215                 else
216                         w_deathtypestring = "detonated";
217         }
218         else if (req == WR_KILLMESSAGE)
219         {
220                 if(w_deathtype & HITTYPE_SPLASH)
221                         if(w_deathtype & HITTYPE_BOUNCE) // (must be secondary then)
222                                 w_deathtypestring = "didn't see #'s grenade";
223                         else // unchecked: SECONDARY
224                                 w_deathtypestring = "almost dodged #'s grenade";
225                 else // unchecked: SECONDARY, BOUNCE
226                         w_deathtypestring = "ate #'s grenade";
227         }
228         return TRUE;
229 };