]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/w_laser.qc
laser and hlac: csqc projectile
[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         PROJECTILE_TOUCH;
10
11         normal = trace_plane_normal;
12         dir = normalize (self.owner.origin - self.origin);
13         org2 = findbetterlocation (self.origin, 8);
14
15         pointparticles(particleeffectnum("laser_impact"), org2, normal * 1000, 1);
16
17
18         self.event_damage = SUB_Null;
19         if (self.dmg)
20                 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"), self.projectiledeathtype, other);
21         else
22                 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"), self.projectiledeathtype, other);
23         sound (self, CHAN_PROJECTILE, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM);
24
25         remove (self);
26 }
27
28 void W_Laser_Attack (float issecondary)
29 {
30         local entity missile;
31
32         W_SetupShot (self, '25 8 -8', FALSE, 3, "weapons/lasergun_fire.wav");
33         pointparticles(particleeffectnum("laser_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
34
35         missile = spawn ();
36         missile.owner = self;
37         missile.classname = "laserbolt";
38         missile.dmg = issecondary;
39         missile.bot_dodge = TRUE;
40         if (issecondary)
41                 missile.bot_dodgerating = cvar("g_balance_laser_secondary_damage");
42         else
43                 missile.bot_dodgerating = cvar("g_balance_laser_primary_damage");
44
45         missile.movetype = MOVETYPE_FLY;
46         missile.solid = SOLID_BBOX;
47         missile.projectiledeathtype = WEP_LASER;
48         if(issecondary)
49                 missile.projectiledeathtype |= HITTYPE_SECONDARY;
50
51         setmodel (missile, "models/laser.mdl"); // precision set below
52         setsize (missile, '0 0 0', '0 0 0');
53         setorigin (missile, w_shotorg);
54
55         if (issecondary)
56                 missile.velocity = w_shotdir * cvar("g_balance_laser_secondary_speed");
57         else
58                 missile.velocity = w_shotdir * cvar("g_balance_laser_primary_speed");
59         W_SetupProjectileVelocity(missile);
60         missile.angles = vectoangles (missile.velocity);
61         //missile.glow_color = 250; // 244, 250
62         //missile.glow_size = 120;
63         missile.touch = W_Laser_Touch;
64         missile.think = SUB_Remove;
65         if (issecondary)
66                 missile.nextthink = time + cvar("g_balance_laser_secondary_lifetime");
67         else
68                 missile.nextthink = time + cvar("g_balance_laser_primary_lifetime");
69
70         missile.effects = EF_LOWPRECISION;
71         missile.flags = FL_PROJECTILE;
72
73         CSQCProjectile(missile, TRUE, PROJECTILE_LASER);
74 }
75
76 float w_laser(float req)
77 {
78         local float r1;
79         local float r2;
80         if (req == WR_AIM)
81         {
82                 if(cvar("g_balance_laser_secondary"))
83                 {
84                         r1 = cvar("g_balance_laser_primary_damage");
85                         r2 = cvar("g_balance_laser_secondary_damage");
86                         if (random() * (r2 + r1) > r1)
87                                 self.BUTTON_ATCK2 = bot_aim(cvar("g_balance_laser_secondary_speed"), 0, cvar("g_balance_laser_secondary_lifetime"), FALSE);
88                         else
89                                 self.BUTTON_ATCK = bot_aim(cvar("g_balance_laser_primary_speed"), 0, cvar("g_balance_laser_primary_lifetime"), FALSE);
90                 }
91                 else
92                         self.BUTTON_ATCK = bot_aim(cvar("g_balance_laser_primary_speed"), 0, cvar("g_balance_laser_primary_lifetime"), FALSE);
93         }
94         else if (req == WR_THINK)
95         {
96                 if (self.BUTTON_ATCK)
97                 if (weapon_prepareattack(0, cvar("g_balance_laser_primary_refire")))
98                 {
99                         W_Laser_Attack(FALSE);
100                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_laser_primary_animtime"), w_ready);
101                 }
102                 if (self.BUTTON_ATCK2)
103                 {
104                         if(cvar("g_balance_laser_secondary"))
105                         {
106                                 if (weapon_prepareattack(0, cvar("g_balance_laser_secondary_refire")))
107                                 {
108                                         W_Laser_Attack(TRUE);
109                                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_laser_secondary_animtime"), w_ready);
110                                 }
111                         }
112                         else
113                         {
114                                 if(self.switchweapon == WEP_LASER) // don't do this if already switching
115                                         W_SwitchWeapon (self.cnt);
116                         }
117                 }
118         }
119         else if (req == WR_PRECACHE)
120         {
121                 precache_model ("models/laser.mdl");
122                 precache_model ("models/weapons/v_laser.md3");
123                 precache_model ("models/weapons/w_laser.zym");
124                 precache_sound ("weapons/lasergun_fire.wav");
125                 precache_sound ("weapons/laserimpact.wav");
126         }
127         else if (req == WR_SETUP)
128                 weapon_setup(WEP_LASER);
129         else if (req == WR_CHECKAMMO1)
130                 return TRUE;
131         else if (req == WR_CHECKAMMO2)
132                 return TRUE;
133         else if (req == WR_SUICIDEMESSAGE)
134                 w_deathtypestring = "lasered himself to hell";
135         else if (req == WR_KILLMESSAGE)
136         {
137                 w_deathtypestring = "was lasered to death by"; // unchecked: SPLASH
138         }
139         return TRUE;
140 };