change all function declarations (except builtins and data types) to ANSI C-like...
[divverent/nexuiz.git] / data / qcsrc / server / w_grenadelauncher.qc
1
2 void W_Grenade_Explode (void)
3 {
4         vector  org2;
5         org2 = findbetterlocation (self.origin, 12);
6         pointparticles(particleeffectnum("grenade_explode"), org2, '0 0 0', 1);
7         sound (self, CHAN_BODY, "weapons/grenade_impact.wav", 1, ATTN_NORM);
8
9         self.event_damage = SUB_Null;
10         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);
11
12         remove (self);
13 }
14
15 void W_Grenade_Explode2 (void)
16 {
17         vector  org2;
18         org2 = findbetterlocation (self.origin, 12);
19         pointparticles(particleeffectnum("grenade_explode"), org2, '0 0 0', 1);
20         sound (self, CHAN_BODY, "weapons/grenade_impact.wav", 1, ATTN_NORM);
21
22         self.event_damage = SUB_Null;
23         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);
24
25         remove (self);
26 }
27
28 void W_Grenade_Touch1 (void)
29 {
30         if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
31         {
32                 remove(self);
33                 return;
34         }
35         W_Grenade_Explode ();
36 }
37
38 void W_Grenade_Touch2 (void)
39 {
40         if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
41         {
42                 remove(self);
43                 return;
44         }
45         if (other.takedamage == DAMAGE_AIM)
46                 self.think ();
47         else
48         {
49                 float r;
50                 r = random() * 6;
51                 if(r < 1)
52                         sound (self, CHAN_IMPACT, "weapons/grenade_bounce1.wav", 1, ATTN_NORM);
53                 else if(r < 2)
54                         sound (self, CHAN_IMPACT, "weapons/grenade_bounce2.wav", 1, ATTN_NORM);
55                 else if(r < 3)
56                         sound (self, CHAN_IMPACT, "weapons/grenade_bounce3.wav", 1, ATTN_NORM);
57                 else if(r < 4)
58                         sound (self, CHAN_IMPACT, "weapons/grenade_bounce4.wav", 1, ATTN_NORM);
59                 else if(r < 5)
60                         sound (self, CHAN_IMPACT, "weapons/grenade_bounce5.wav", 1, ATTN_NORM);
61                 else
62                         sound (self, CHAN_IMPACT, "weapons/grenade_bounce6.wav", 1, ATTN_NORM);
63         }
64 }
65
66 void W_Grenade_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
67 {
68         self.health = self.health - damage;
69         if (self.health <= 0)
70         {
71                 self.owner = attacker;
72                 self.think ();
73         }
74 }
75
76 void W_Grenade_Attack (void)
77 {
78         local entity gren;
79
80         if (cvar("g_use_ammunition"))
81                 self.ammo_rockets = self.ammo_rockets - cvar("g_balance_grenadelauncher_primary_ammo");
82         W_SetupShot (self, '25 6 -8', FALSE, 4, "weapons/grenade_fire.wav");
83         //W_SetupShot (self, '25 8 -8', FALSE, 4, "weapons/grenade_fire.wav"); // TODO: move model to the right a little
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         gren.solid = SOLID_BBOX;
94         gren.effects = EF_LOWPRECISION;
95         gren.modelflags = MF_GRENADE;
96         setmodel(gren, "models/grenademodel.md3"); // precision set above
97         setsize(gren, '0 0 0', '0 0 0');
98         setorigin(gren, w_shotorg);
99
100         gren.nextthink = time + cvar("g_balance_grenadelauncher_primary_lifetime");
101         gren.think = W_Grenade_Explode;
102         gren.touch = W_Grenade_Touch1;
103         gren.velocity = w_shotdir * cvar("g_balance_grenadelauncher_primary_speed") + v_up * cvar("g_balance_grenadelauncher_primary_speed_up");
104         W_SetupProjectileVelocity(gren);
105         gren.avelocity_x = random () * -500 - 500;
106
107         gren.angles = vectoangles (gren.velocity);
108         gren.flags = FL_PROJECTILE;
109 }
110
111 void W_Grenade_Attack2 (void)
112 {
113         local entity gren;
114
115         if (cvar("g_use_ammunition"))
116                 self.ammo_rockets = self.ammo_rockets - cvar("g_balance_grenadelauncher_secondary_ammo");
117         W_SetupShot (self, '25 6 -8', FALSE, 4, "weapons/grenade_fire.wav");
118         //W_SetupShot (self, '25 8 -8', FALSE, 4, "weapons/grenade_fire.wav"); // TODO: move model to the right a little
119
120         pointparticles(particleeffectnum("grenadelauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
121
122         gren = spawn ();
123         gren.owner = self;
124         gren.classname = "grenade";
125         gren.bot_dodge = TRUE;
126         gren.bot_dodgerating = cvar("g_balance_grenadelauncher_secondary_damage");
127         gren.movetype = MOVETYPE_BOUNCE;
128         gren.solid = SOLID_BBOX;
129         gren.effects = EF_LOWPRECISION;
130         gren.modelflags = MF_GRENADE;
131         setmodel(gren, "models/grenademodel.md3"); // precision set above
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 = W_Grenade_Explode2;
137         gren.touch = W_Grenade_Touch2;
138         gren.takedamage = DAMAGE_YES;
139         gren.health = 10;
140         gren.damageforcescale = 4;
141         gren.event_damage = W_Grenade_Damage;
142         gren.velocity = w_shotdir * cvar("g_balance_grenadelauncher_secondary_speed") + v_up * cvar("g_balance_grenadelauncher_secondary_speed_up");
143         W_SetupProjectileVelocity(gren);
144         gren.avelocity = '100 150 100';
145
146         gren.angles = vectoangles (gren.velocity);
147         gren.flags = FL_PROJECTILE;
148 }
149
150 .float bot_secondary_grenademooth;
151 float w_glauncher(float req)
152 {
153         if (req == WR_AIM)
154         {
155                 self.BUTTON_ATCK = FALSE;
156                 self.BUTTON_ATCK2 = FALSE;
157                 if (self.bot_secondary_grenademooth == 0)
158                 {
159                         if(bot_aim(cvar("g_balance_grenadelauncher_primary_speed"), cvar("g_balance_grenadelauncher_primary_speed_up"), cvar("g_balance_grenadelauncher_primary_lifetime"), TRUE))
160                         {
161                                 self.BUTTON_ATCK = TRUE;
162                                 if(random() < 0.01) self.bot_secondary_grenademooth = 1;
163                         }
164                 }
165                 else
166                 {
167                         if(bot_aim(cvar("g_balance_grenadelauncher_secondary_speed"), cvar("g_balance_grenadelauncher_secondary_speed_up"), cvar("g_balance_grenadelauncher_secondary_lifetime"), TRUE))
168                         {
169                                 self.BUTTON_ATCK2 = TRUE;
170                                 if(random() < 0.02) self.bot_secondary_grenademooth = 0;
171                         }
172                 }
173         }
174         else if (req == WR_THINK)
175         {
176                 if (self.BUTTON_ATCK)
177                 if (weapon_prepareattack(0, cvar("g_balance_grenadelauncher_primary_refire")))
178                 {
179                         W_Grenade_Attack();
180                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_grenadelauncher_primary_animtime"), w_ready);
181                 }
182                 if (self.BUTTON_ATCK2)
183                 if (weapon_prepareattack(1, cvar("g_balance_grenadelauncher_secondary_refire")))
184                 {
185                         W_Grenade_Attack2();
186                         weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_grenadelauncher_secondary_animtime"), w_ready);
187                 }
188         }
189         else if (req == WR_PRECACHE)
190         {
191                 precache_model ("models/grenademodel.md3");
192                 precache_model ("models/weapons/g_gl.md3");
193                 precache_model ("models/weapons/v_gl.md3");
194                 precache_model ("models/weapons/w_gl.zym");
195                 precache_sound ("weapons/grenade_bounce1.wav");
196                 precache_sound ("weapons/grenade_bounce2.wav");
197                 precache_sound ("weapons/grenade_bounce3.wav");
198                 precache_sound ("weapons/grenade_bounce4.wav");
199                 precache_sound ("weapons/grenade_bounce5.wav");
200                 precache_sound ("weapons/grenade_bounce6.wav");
201                 precache_sound ("weapons/grenade_fire.wav");
202                 precache_sound ("weapons/grenade_impact.wav");
203         }
204         else if (req == WR_SETUP)
205                 weapon_setup(WEP_GRENADE_LAUNCHER, "gl", IT_ROCKETS);
206         else if (req == WR_CHECKAMMO1)
207                 return self.ammo_rockets >= cvar("g_balance_grenadelauncher_primary_ammo");
208         else if (req == WR_CHECKAMMO2)
209                 return self.ammo_rockets >= cvar("g_balance_grenadelauncher_secondary_ammo");
210         else if (req == WR_REGISTER)
211                 weapon_register(WEP_GRENADE_LAUNCHER, min(cvar("g_balance_grenadelauncher_primary_ammo"), cvar("g_balance_grenadelauncher_secondary_ammo")));
212         return TRUE;
213 };