]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/w_laser.qc
do less audio spam for triggers that don't even respond to players
[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
74 float w_laser(float req)
75 {
76         local float r1;
77         local float r2;
78         if (req == WR_AIM)
79         {
80                 if(cvar("g_balance_laser_secondary"))
81                 {
82                         r1 = cvar("g_balance_laser_primary_damage");
83                         r2 = cvar("g_balance_laser_secondary_damage");
84                         if (random() * (r2 + r1) > r1)
85                                 self.BUTTON_ATCK2 = bot_aim(cvar("g_balance_laser_secondary_speed"), 0, cvar("g_balance_laser_secondary_lifetime"), FALSE);
86                         else
87                                 self.BUTTON_ATCK = bot_aim(cvar("g_balance_laser_primary_speed"), 0, cvar("g_balance_laser_primary_lifetime"), FALSE);
88                 }
89                 else
90                         self.BUTTON_ATCK = bot_aim(cvar("g_balance_laser_primary_speed"), 0, cvar("g_balance_laser_primary_lifetime"), FALSE);
91         }
92         else if (req == WR_THINK)
93         {
94                 if (self.BUTTON_ATCK)
95                 if (weapon_prepareattack(0, cvar("g_balance_laser_primary_refire")))
96                 {
97                         W_Laser_Attack(FALSE);
98                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_laser_primary_animtime"), w_ready);
99                 }
100                 if (self.BUTTON_ATCK2)
101                 {
102                         if(cvar("g_balance_laser_secondary"))
103                         {
104                                 if (weapon_prepareattack(0, cvar("g_balance_laser_secondary_refire")))
105                                 {
106                                         W_Laser_Attack(TRUE);
107                                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_laser_secondary_animtime"), w_ready);
108                                 }
109                         }
110                         else
111                         {
112                                 if(self.switchweapon == WEP_LASER) // don't do this if already switching
113                                         W_SwitchWeapon (self.cnt);
114                         }
115                 }
116         }
117         else if (req == WR_PRECACHE)
118         {
119                 precache_model ("models/laser.mdl");
120                 precache_model ("models/weapons/v_laser.md3");
121                 precache_model ("models/weapons/w_laser.zym");
122                 precache_sound ("weapons/lasergun_fire.wav");
123                 precache_sound ("weapons/laserimpact.wav");
124         }
125         else if (req == WR_SETUP)
126                 weapon_setup(WEP_LASER);
127         else if (req == WR_CHECKAMMO1)
128                 return TRUE;
129         else if (req == WR_CHECKAMMO2)
130                 return TRUE;
131         else if (req == WR_SUICIDEMESSAGE)
132                 w_deathtypestring = "lasered himself to hell";
133         else if (req == WR_KILLMESSAGE)
134         {
135                 w_deathtypestring = "was lasered to death by"; // unchecked: SPLASH
136         }
137         return TRUE;
138 };