change all function declarations (except builtins and data types) to ANSI C-like...
[divverent/nexuiz.git] / data / qcsrc / server / w_laser.qc
1 void(float imp) W_SwitchWeapon;
2
3 void W_Laser_Touch (void)
4 {
5         vector  dir;
6         vector org2;
7         vector normal;
8
9         if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
10         {
11                 remove(self);
12                 return;
13         }
14
15         if (other == self.owner)
16                 return;
17
18         normal = trace_plane_normal;
19         dir = normalize (self.owner.origin - self.origin);
20         org2 = findbetterlocation (self.origin, 8);
21
22         pointparticles(particleeffectnum("laser_impact"), org2, normal * 1000, 1);
23
24
25         self.event_damage = SUB_Null;
26         if (self.dmg)
27                 RadiusDamage (self, self.owner, cvar("g_balance_laser_secondary_damage"), cvar("g_balance_laser_secondary_edgedamage"), cvar("g_balance_laser_secondary_radius"), world, cvar("g_balance_laser_secondary_force"), IT_LASER);
28         else
29                 RadiusDamage (self, self.owner, cvar("g_balance_laser_primary_damage"), cvar("g_balance_laser_primary_edgedamage"), cvar("g_balance_laser_primary_radius"), world, cvar("g_balance_laser_primary_force"), IT_LASER);
30         sound (self, CHAN_BODY, "weapons/laserimpact.wav", 1, ATTN_NORM);
31
32         remove (self);
33 }
34
35 void W_Laser_Attack (float issecondary)
36 {
37         local entity missile;
38
39         W_SetupShot (self, '25 8 -8', FALSE, 3, "weapons/lasergun_fire.wav");
40         pointparticles(particleeffectnum("laser_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
41
42         missile = spawn ();
43         missile.owner = self;
44         missile.classname = "laserbolt";
45         missile.dmg = issecondary;
46         missile.bot_dodge = TRUE;
47         if (issecondary)
48                 missile.bot_dodgerating = cvar("g_balance_laser_secondary_damage");
49         else
50                 missile.bot_dodgerating = cvar("g_balance_laser_primary_damage");
51
52         missile.movetype = MOVETYPE_FLY;
53         missile.solid = SOLID_BBOX;
54
55         setmodel (missile, "models/laser.mdl"); // precision set below
56         setsize (missile, '0 0 0', '0 0 0');
57         setorigin (missile, w_shotorg);
58
59         if (issecondary)
60                 missile.velocity = w_shotdir * cvar("g_balance_laser_secondary_speed");
61         else
62                 missile.velocity = w_shotdir * cvar("g_balance_laser_primary_speed");
63         W_SetupProjectileVelocity(missile);
64         missile.angles = vectoangles (missile.velocity);
65         //missile.glow_color = 250; // 244, 250
66         //missile.glow_size = 120;
67         missile.touch = W_Laser_Touch;
68         missile.think = SUB_Remove;
69         if (issecondary)
70                 missile.nextthink = time + cvar("g_balance_laser_secondary_lifetime");
71         else
72                 missile.nextthink = time + cvar("g_balance_laser_primary_lifetime");
73
74         missile.effects = EF_LOWPRECISION;
75         missile.flags = FL_PROJECTILE;
76 }
77
78 float w_laser(float req)
79 {
80         local float r1;
81         local float r2;
82         if (req == WR_AIM)
83         {
84                 if(cvar("g_balance_laser_secondary"))
85                 {
86                         r1 = cvar("g_balance_laser_primary_damage");
87                         r2 = cvar("g_balance_laser_secondary_damage");
88                         if (random() * (r2 + r1) > r1)
89                                 self.BUTTON_ATCK2 = bot_aim(cvar("g_balance_laser_secondary_speed"), 0, cvar("g_balance_laser_secondary_lifetime"), FALSE);
90                         else
91                                 self.BUTTON_ATCK = bot_aim(cvar("g_balance_laser_primary_speed"), 0, cvar("g_balance_laser_primary_lifetime"), FALSE);
92                 }
93                 else
94                         self.BUTTON_ATCK = bot_aim(cvar("g_balance_laser_primary_speed"), 0, cvar("g_balance_laser_primary_lifetime"), FALSE);
95         }
96         else if (req == WR_THINK)
97         {
98                 if (self.BUTTON_ATCK)
99                 if (weapon_prepareattack(0, cvar("g_balance_laser_primary_refire")))
100                 {
101                         W_Laser_Attack(FALSE);
102                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_laser_primary_animtime"), w_ready);
103                 }
104                 if (self.BUTTON_ATCK2)
105                 {
106                         if(cvar("g_balance_laser_secondary"))
107                         {
108                                 if (weapon_prepareattack(0, cvar("g_balance_laser_secondary_refire")))
109                                 {
110                                         W_Laser_Attack(TRUE);
111                                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_laser_secondary_animtime"), w_ready);
112                                 }
113                         }
114                         else
115                         {
116                                 if (self.BUTTON_ATCK2)
117                                 if (client_hasweapon(self, self.cnt, TRUE, FALSE))
118                                         W_SwitchWeapon (self.cnt);
119                         }
120                 }
121         }
122         else if (req == WR_PRECACHE)
123         {
124                 precache_model ("models/laser.mdl");
125                 precache_model ("models/weapons/v_laser.md3");
126                 precache_model ("models/weapons/w_laser.zym");
127                 precache_sound ("weapons/lasergun_fire.wav");
128                 precache_sound ("weapons/laserimpact.wav");
129         }
130         else if (req == WR_SETUP)
131                 weapon_setup(WEP_LASER, "laser", 0);
132         else if (req == WR_CHECKAMMO1)
133                 return TRUE;
134         else if (req == WR_CHECKAMMO2)
135                 return TRUE;
136         else if (req == WR_REGISTER)
137                 weapon_register(WEP_LASER, 0);
138         return TRUE;
139 };