80b7020130a945a2a76aa07ab707f75cfb926bc3
[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         PROJECTILE_MAKETRIGGER(gren);
131         gren.projectiledeathtype = WEP_GRENADE_LAUNCHER | HITTYPE_SECONDARY;
132         setsize(gren, '0 0 -3', '0 0 -3');
133         setorigin(gren, w_shotorg);
134
135         gren.nextthink = time + cvar("g_balance_grenadelauncher_secondary_lifetime");
136         gren.think = adaptor_think2use;
137         gren.use = W_Grenade_Explode2;
138         gren.touch = W_Grenade_Touch2;
139         gren.takedamage = DAMAGE_YES;
140         gren.health = cvar("g_balance_grenadelauncher_secondary_health");
141         gren.damageforcescale = cvar("g_balance_grenadelauncher_secondary_damageforcescale");
142         gren.event_damage = W_Grenade_Damage;
143         W_SETUPPROJECTILEVELOCITY_UP(gren, g_balance_grenadelauncher_secondary);
144
145         gren.angles = vectoangles (gren.velocity);
146         gren.flags = FL_PROJECTILE;
147
148         CSQCProjectile(gren, TRUE, PROJECTILE_GRENADE_BOUNCING, TRUE);
149 }
150
151 void spawnfunc_weapon_grenadelauncher (void)
152 {
153         weapon_defaultspawnfunc(WEP_GRENADE_LAUNCHER);
154 }
155
156 .float bot_secondary_grenademooth;
157 float w_glauncher(float req)
158 {
159         if (req == WR_AIM)
160         {
161                 self.BUTTON_ATCK = FALSE;
162                 self.BUTTON_ATCK2 = FALSE;
163                 if (self.bot_secondary_grenademooth == 0)
164                 {
165                         if(bot_aim(cvar("g_balance_grenadelauncher_primary_speed"), cvar("g_balance_grenadelauncher_primary_speed_up"), cvar("g_balance_grenadelauncher_primary_lifetime"), TRUE))
166                         {
167                                 self.BUTTON_ATCK = TRUE;
168                                 if(random() < 0.01) self.bot_secondary_grenademooth = 1;
169                         }
170                 }
171                 else
172                 {
173                         if(bot_aim(cvar("g_balance_grenadelauncher_secondary_speed"), cvar("g_balance_grenadelauncher_secondary_speed_up"), cvar("g_balance_grenadelauncher_secondary_lifetime"), TRUE))
174                         {
175                                 self.BUTTON_ATCK2 = TRUE;
176                                 if(random() < 0.02) self.bot_secondary_grenademooth = 0;
177                         }
178                 }
179         }
180         else if (req == WR_THINK)
181         {
182                 if (self.BUTTON_ATCK)
183                 if (weapon_prepareattack(0, cvar("g_balance_grenadelauncher_primary_refire")))
184                 {
185                         if(cvar("g_balance_grenadelauncher_primary2secondary"))
186                                 W_Grenade_Attack2();
187                         else
188                                 W_Grenade_Attack();
189                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_grenadelauncher_primary_animtime"), w_ready);
190                 }
191                 if (self.BUTTON_ATCK2 && !cvar("g_balance_grenadelauncher_primary2secondary"))
192                 if (weapon_prepareattack(1, cvar("g_balance_grenadelauncher_secondary_refire")))
193                 {
194                         W_Grenade_Attack2();
195                         weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_grenadelauncher_secondary_animtime"), w_ready);
196                 }
197         }
198         else if (req == WR_PRECACHE)
199         {
200                 precache_model ("models/weapons/g_gl.md3");
201                 precache_model ("models/weapons/v_gl.md3");
202                 precache_model ("models/weapons/h_gl.dpm");
203                 precache_sound ("weapons/grenade_bounce1.wav");
204                 precache_sound ("weapons/grenade_bounce2.wav");
205                 precache_sound ("weapons/grenade_bounce3.wav");
206                 precache_sound ("weapons/grenade_bounce4.wav");
207                 precache_sound ("weapons/grenade_bounce5.wav");
208                 precache_sound ("weapons/grenade_bounce6.wav");
209                 precache_sound ("weapons/grenade_fire.wav");
210         }
211         else if (req == WR_SETUP)
212                 weapon_setup(WEP_GRENADE_LAUNCHER);
213         else if (req == WR_CHECKAMMO1)
214                 return self.ammo_rockets >= cvar("g_balance_grenadelauncher_primary_ammo");
215         else if (req == WR_CHECKAMMO2)
216                 return self.ammo_rockets >= cvar("g_balance_grenadelauncher_secondary_ammo");
217         else if (req == WR_SUICIDEMESSAGE)
218         {
219                 if(w_deathtype & HITTYPE_SECONDARY)
220                         w_deathtypestring = "tried out his own grenade";
221                 else
222                         w_deathtypestring = "detonated";
223         }
224         else if (req == WR_KILLMESSAGE)
225         {
226                 if(w_deathtype & HITTYPE_SPLASH)
227                         if(w_deathtype & HITTYPE_BOUNCE) // (must be secondary then)
228                                 w_deathtypestring = "didn't see #'s grenade";
229                         else // unchecked: SECONDARY
230                                 w_deathtypestring = "almost dodged #'s grenade";
231                 else // unchecked: SECONDARY, BOUNCE
232                         w_deathtypestring = "ate #'s grenade";
233         }
234         return TRUE;
235 };
236 #endif