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