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