centerprints now are managed independently per line
[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         te_explosion (org2);
7         //effect (org2, "models/sprites/grenexpl.spr", 0, 12, 35);
8         sound (self, CHAN_BODY, "weapons/grenade_impact.ogg", 1, ATTN_NORM);
9
10         self.event_damage = SUB_Null;
11         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);
12
13         remove (self);
14 }
15
16 void W_Grenade_Explode2 (void)
17 {
18         vector  org2;
19         org2 = findbetterlocation (self.origin, 12);
20         te_explosion (org2);
21         //effect (org2, "models/sprites/grenexpl.spr", 0, 12, 35);
22         sound (self, CHAN_BODY, "weapons/grenade_impact.ogg", 1, ATTN_NORM);
23
24         self.event_damage = SUB_Null;
25         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);
26
27         remove (self);
28 }
29
30 void W_Grenade_Touch1 (void)
31 {
32         if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
33         {
34                 remove(self);
35                 return;
36         }
37         W_Grenade_Explode ();
38 }
39
40 void W_Grenade_Touch2 (void)
41 {
42         if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
43         {
44                 remove(self);
45                 return;
46         }
47         if (other.takedamage == DAMAGE_AIM)
48                 self.think ();
49         else
50         {
51                 float r;
52                 r = random() * 3;
53                 if(r < 1)
54                         sound (self, CHAN_IMPACT, "weapons/grenade_bounce1.ogg", 1, ATTN_NORM);
55                 else if(r < 2)
56                         sound (self, CHAN_IMPACT, "weapons/grenade_bounce2.ogg", 1, ATTN_NORM);
57                 else
58                         sound (self, CHAN_IMPACT, "weapons/grenade_bounce3.ogg", 1, ATTN_NORM);
59         }
60 }
61
62 void W_Grenade_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
63 {
64         self.health = self.health - damage;
65         if (self.health <= 0)
66         {
67                 self.owner = attacker;
68                 self.think ();
69         }
70 }
71
72 void W_Grenade_Attack (void)
73 {
74         local entity gren;
75
76         if (cvar("g_use_ammunition"))
77                 self.ammo_rockets = self.ammo_rockets - cvar("g_balance_grenadelauncher_primary_ammo");
78         W_SetupShot (self, '15 8 -8', FALSE, 4, "weapons/grenade_fire.ogg");
79
80         gren = spawn ();
81         gren.owner = self;
82         gren.classname = "grenade";
83         gren.bot_dodge = TRUE;
84         gren.bot_dodgerating = cvar("g_balance_grenadelauncher_primary_damage");
85         gren.movetype = MOVETYPE_BOUNCE;
86         gren.solid = SOLID_BBOX;
87         gren.effects = EF_NOSHADOW | EF_LOWPRECISION;
88         setmodel(gren, "models/grenademodel.md3");
89         setsize(gren, '0 0 0', '0 0 0');
90         setorigin(gren, w_shotorg);
91
92         gren.nextthink = time + cvar("g_balance_grenadelauncher_primary_lifetime");
93         gren.think = W_Grenade_Explode;
94         gren.touch = W_Grenade_Touch1;
95         gren.velocity = v_forward * cvar("g_balance_grenadelauncher_primary_speed") + v_up * cvar("g_balance_grenadelauncher_primary_speed_up");
96         gren.avelocity_x = random () * -500 - 500;
97
98         gren.angles = vectoangles (gren.velocity);
99         gren.flags = FL_PROJECTILE;
100 }
101
102 void W_Grenade_Attack2 (void)
103 {
104         local entity gren;
105
106         if (cvar("g_use_ammunition"))
107                 self.ammo_rockets = self.ammo_rockets - cvar("g_balance_grenadelauncher_secondary_ammo");
108         W_SetupShot (self, '15 8 -8', FALSE, 4, "weapons/grenade_fire.ogg");
109
110         gren = spawn ();
111         gren.owner = self;
112         gren.classname = "grenade";
113         gren.bot_dodge = TRUE;
114         gren.bot_dodgerating = cvar("g_balance_grenadelauncher_secondary_damage");
115         gren.movetype = MOVETYPE_BOUNCE;
116         gren.solid = SOLID_BBOX;
117         gren.effects = EF_NOSHADOW | EF_LOWPRECISION;
118         setmodel(gren, "models/grenademodel.md3");
119         setsize(gren, '0 0 -3', '0 0 -3');
120         setorigin(gren, w_shotorg);
121
122         gren.nextthink = time + cvar("g_balance_grenadelauncher_secondary_lifetime");
123         gren.think = W_Grenade_Explode2;
124         gren.touch = W_Grenade_Touch2;
125         gren.takedamage = DAMAGE_YES;
126         gren.health = 10;
127         gren.damageforcescale = 4;
128         gren.event_damage = W_Grenade_Damage;
129         gren.velocity = v_forward * cvar("g_balance_grenadelauncher_secondary_speed") + v_up * cvar("g_balance_grenadelauncher_secondary_speed_up");
130         gren.avelocity = '100 150 100';
131
132         gren.angles = vectoangles (gren.velocity);
133         gren.flags = FL_PROJECTILE;
134 }
135
136 float(float req) w_glauncher =
137 {
138         if (req == WR_AIM)
139                 self.button0 = bot_aim(cvar("g_balance_grenadelauncher_primary_speed"), cvar("g_balance_grenadelauncher_primary_speed_up"), cvar("g_balance_grenadelauncher_primary_lifetime"), TRUE);
140         else if (req == WR_THINK)
141         {
142                 if (self.button0)
143                 if (weapon_prepareattack(0, cvar("g_balance_grenadelauncher_primary_refire")))
144                 {
145                         W_Grenade_Attack();
146                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_grenadelauncher_primary_animtime"), w_ready);
147                 }
148                 if (self.button3)
149                 if (weapon_prepareattack(1, cvar("g_balance_grenadelauncher_secondary_refire")))
150                 {
151                         W_Grenade_Attack2();
152                         weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_grenadelauncher_secondary_animtime"), w_ready);
153                 }
154         }
155         else if (req == WR_SETUP)
156                 weapon_setup(WEP_GRENADE_LAUNCHER, "gl", IT_ROCKETS);
157         else if (req == WR_CHECKAMMO1)
158                 return self.ammo_rockets >= cvar("g_balance_grenadelauncher_primary_ammo");
159         else if (req == WR_CHECKAMMO2)
160                 return self.ammo_rockets >= cvar("g_balance_grenadelauncher_secondary_ammo");
161         return TRUE;
162 };