]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/gamec/w_grenadelauncher.c
add csqc skeleton for Nexuiz
[divverent/nexuiz.git] / data / qcsrc / server / gamec / w_grenadelauncher.c
1 void() glauncher_ready_01;
2 void() glauncher_fire1_01;
3 void() glauncher_deselect_01;
4 void() glauncher_select_01;
5
6 float() glauncher_check =
7 {
8         if (self.ammo_rockets >= 2)
9                 return TRUE;
10         return FALSE;
11 };
12
13 void(float req) w_glauncher =
14 {
15         if (req == WR_IDLE)
16                 glauncher_ready_01();
17         else if (req == WR_FIRE1)
18                 weapon_prepareattack(glauncher_check, glauncher_check, glauncher_fire1_01, cvar("g_balance_grenadelauncher_refire"));
19         else if (req == WR_FIRE2)
20                 weapon_prepareattack(glauncher_check, glauncher_check, glauncher_fire1_01, cvar("g_balance_grenadelauncher_refire2"));
21         else if (req == WR_RAISE)
22                 glauncher_select_01();
23         else if (req == WR_UPDATECOUNTS)
24                 self.currentammo = self.ammo_rockets;
25         else if (req == WR_DROP)
26                 glauncher_deselect_01();
27         else if (req == WR_SETUP)
28                 weapon_setup(WEP_GRENADE_LAUNCHER, "w_gl.zym", IT_ROCKETS);
29         else if (req == WR_CHECKAMMO)
30                 weapon_hasammo = glauncher_check();
31 };
32
33 void W_Grenade_Explode (void)
34 {
35         vector  org2;
36         org2 = findbetterlocation (self.origin);
37         te_explosion (org2);
38         effect (org2, "models/sprites/grenexpl.spr", 0, 12, 35);
39         sound (self, CHAN_BODY, "weapons/grenade_impact.ogg", 1, ATTN_NORM);
40
41         self.event_damage = SUB_Null;
42         RadiusDamage (self, self.owner, cvar("g_balance_grenadelauncher_damage"), cvar("g_balance_grenadelauncher_edgedamage"), cvar("g_balance_grenadelauncher_radius"), world, cvar("g_balance_grenadelauncher_force"), IT_GRENADE_LAUNCHER);
43
44         remove (self);
45 }
46
47 void W_Grenade_Touch (void)
48 {
49         if (other.takedamage == DAMAGE_AIM)
50                 W_Grenade_Explode ();
51         else
52                 sound (self, CHAN_IMPACT, "weapons/grenade_bounce.ogg", 1, ATTN_NORM);
53 }
54
55 void W_Grenade_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
56 {
57         self.health = self.health - damage;
58         if (self.health <= 0)
59                 W_Grenade_Explode();
60 }
61
62 void W_Grenade_Attack (void)
63 {
64         local entity gren;
65         local vector org;
66
67         
68         local vector trueaim;
69         trueaim = W_TrueAim();
70
71         sound (self, CHAN_WEAPON, "weapons/grenade_fire.ogg", 1, ATTN_NORM);
72         if (self.items & IT_STRENGTH) {
73                 sound (self, CHAN_AUTO, "weapons/strength_fire.ogg", 1, ATTN_NORM);
74         }
75         
76         self.punchangle_x = -4;
77         if (cvar("g_use_ammunition"))
78                 self.ammo_rockets = self.ammo_rockets - 2;
79         org = self.origin + self.view_ofs + v_forward * 15 + v_right * 5 + v_up * -12;
80
81         gren = spawn ();
82         gren.owner = self;
83         gren.classname = "grenade";
84         gren.movetype = MOVETYPE_BOUNCE;
85         gren.solid = SOLID_BBOX;
86         setmodel(gren, "models/grenademodel.md3");
87         setsize(gren, '-6 -6 -3', '6 6 3');
88         setorigin(gren, org);
89
90         if (self.button3)
91         {
92                 gren.nextthink = time + 2.5;
93                 gren.think = W_Grenade_Explode;
94                 gren.touch = W_Grenade_Touch;
95                 gren.takedamage = DAMAGE_YES;
96                 gren.health = 10;
97                 gren.damageforcescale = 4;
98                 gren.event_damage = W_Grenade_Damage;
99                 gren.velocity = normalize(trueaim - org) * cvar("g_balance_grenadelauncher_speed2") + v_up * cvar("g_balance_grenadelauncher_speed2_up");
100                 gren.avelocity = '100 150 100';
101         }
102         else
103         {
104                 gren.nextthink = time + 30;
105                 gren.think = W_Grenade_Explode;
106                 gren.touch = W_Grenade_Explode;
107                 gren.velocity = normalize(trueaim - org) * cvar("g_balance_grenadelauncher_speed") + v_up * cvar("g_balance_grenadelauncher_speed_up");
108                 gren.avelocity_x = random () * -500 - 500;
109         }
110
111         gren.angles = vectoangles (gren.velocity);
112 }
113
114 // weapon frames
115
116 void()  glauncher_ready_01 =    {weapon_thinkf(WFRAME_IDLE, 0.1, glauncher_ready_01); self.weaponentity.state = WS_READY;};
117 void()  glauncher_select_01 =   {weapon_thinkf(-1, cvar("g_balance_weaponswitchdelay"), w_ready); weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, '0 0 0');};
118 void()  glauncher_deselect_01 = {weapon_thinkf(-1, cvar("g_balance_weaponswitchdelay"), w_clear); weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, PLAYER_WEAPONSELECTION_RANGE);};
119 void()  glauncher_fire1_01 =
120 {
121         weapon_doattack(glauncher_check, glauncher_check, W_Grenade_Attack);
122         weapon_thinkf(WFRAME_FIRE1, 0.3, glauncher_ready_01);
123 };