]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/w_laser.qc
MinstaNex now can shoot through warpzones... using warpzone-aware tracebox and trailp...
[divverent/nexuiz.git] / data / qcsrc / server / w_laser.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(LASER, w_laser, 0, 1, WEP_FLAG_NORMAL | WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH, 0, "laser", "laser", "Laser");
3 #else
4 void(float imp) W_SwitchWeapon;
5
6 void W_Laser_Touch (void)
7 {
8         PROJECTILE_TOUCH;
9
10         self.event_damage = SUB_Null;
11         if (self.dmg)
12                 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);
13         else
14                 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);
15
16         remove (self);
17 }
18
19 void W_Laser_Think()
20 {
21         self.movetype = MOVETYPE_FLY;
22         self.think = SUB_Remove;
23         if (self.dmg)
24                 self.nextthink = time + cvar("g_balance_laser_secondary_lifetime");
25         else
26                 self.nextthink = time + cvar("g_balance_laser_primary_lifetime");
27         CSQCProjectile(self, TRUE, PROJECTILE_LASER, TRUE);
28 }
29
30 void W_Laser_Attack (float issecondary)
31 {
32         local entity missile;
33         vector s_forward;
34         float a;
35         float nodamage;
36
37         if(issecondary == 2) // minstanex shot
38                 nodamage = g_minstagib;
39         else
40                 nodamage = FALSE;
41
42         if (issecondary == 1)
43                 a = cvar("g_balance_laser_secondary_shotangle");
44         else
45                 a = cvar("g_balance_laser_primary_shotangle");
46         s_forward = v_forward * cos(a * DEG2RAD) + v_up * sin(a * DEG2RAD);
47
48         if(nodamage)
49                 W_SetupShot_Dir (self, s_forward, FALSE, 3, "weapons/lasergun_fire.wav", 0);
50         else if(issecondary == 1)
51                 W_SetupShot_Dir (self, s_forward, FALSE, 3, "weapons/lasergun_fire.wav", cvar("g_balance_laser_secondary_damage"));
52         else
53                 W_SetupShot_Dir (self, s_forward, FALSE, 3, "weapons/lasergun_fire.wav", cvar("g_balance_laser_primary_damage"));
54         pointparticles(particleeffectnum("laser_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
55
56         missile = spawn ();
57         missile.owner = self;
58         missile.classname = "laserbolt";
59         missile.dmg = (issecondary == 1);
60         if(!nodamage)
61         {
62                 missile.bot_dodge = TRUE;
63                 if (issecondary == 1)
64                         missile.bot_dodgerating = cvar("g_balance_laser_secondary_damage");
65                 else
66                         missile.bot_dodgerating = cvar("g_balance_laser_primary_damage");
67         }
68
69         PROJECTILE_MAKETRIGGER(missile);
70         missile.projectiledeathtype = WEP_LASER;
71         if(issecondary == 1)
72                 missile.projectiledeathtype |= HITTYPE_SECONDARY;
73
74         setorigin (missile, w_shotorg);
75         setsize(missile, '0 0 0', '0 0 0');
76
77         if (issecondary == 1)
78                 W_SETUPPROJECTILEVELOCITY(missile, g_balance_laser_secondary);
79         else
80                 W_SETUPPROJECTILEVELOCITY(missile, g_balance_laser_primary);
81         missile.angles = vectoangles (missile.velocity);
82         //missile.glow_color = 250; // 244, 250
83         //missile.glow_size = 120;
84         missile.touch = W_Laser_Touch;
85
86         missile.flags = FL_PROJECTILE;
87
88         missile.think = W_Laser_Think;
89         if (issecondary == 1)
90                 missile.nextthink = time + cvar("g_balance_laser_secondary_delay");
91         else
92                 missile.nextthink = time + cvar("g_balance_laser_primary_delay");
93         if(time >= missile.nextthink)
94         {
95                 entity oldself;
96                 oldself = self;
97                 self = missile;
98                 self.think();
99                 self = oldself;
100         }
101 }
102
103 void W_Laser_Attack2 (void) // gauntlet
104 {
105         W_SetupShot (self, TRUE, 0, "weapons/gauntlet_fire.wav", cvar("g_balance_laser_primary_damage"));
106
107         WarpZone_traceline_antilag(self, w_shotorg, w_shotorg + w_shotdir * cvar("g_balance_laser_primary_radius"), FALSE, self, ANTILAG_LATENCY(self));
108
109         pointparticles(particleeffectnum("laser_gauntlet"), w_shotorg + w_shotdir * cvar("g_balance_laser_primary_radius"), '0 0 0', 1);
110
111         if (trace_fraction < 1)
112                 Damage(trace_ent, self, self, cvar("g_balance_laser_primary_damage"), WEP_LASER | HITTYPE_SECONDARY, trace_endpos, cvar("g_balance_laser_primary_force") * w_shotdir);
113 }
114
115 void spawnfunc_weapon_laser (void)
116 {
117         weapon_defaultspawnfunc(WEP_LASER);
118 }
119
120 float w_laser(float req)
121 {
122         local float r1;
123         local float r2;
124         if (req == WR_AIM)
125         {
126                 if(cvar("g_balance_laser_secondary"))
127                 {
128                         r1 = cvar("g_balance_laser_primary_damage");
129                         r2 = cvar("g_balance_laser_secondary_damage");
130                         if (random() * (r2 + r1) > r1)
131                                 self.BUTTON_ATCK2 = bot_aim(cvar("g_balance_laser_secondary_speed"), 0, cvar("g_balance_laser_secondary_lifetime"), FALSE);
132                         else
133                                 self.BUTTON_ATCK = bot_aim(cvar("g_balance_laser_primary_speed"), 0, cvar("g_balance_laser_primary_lifetime"), FALSE);
134                 }
135                 else
136                         self.BUTTON_ATCK = bot_aim(cvar("g_balance_laser_primary_speed"), 0, cvar("g_balance_laser_primary_lifetime"), FALSE);
137         }
138         else if (req == WR_THINK)
139         {
140                 if (self.BUTTON_ATCK)
141                 if (weapon_prepareattack(0, cvar("g_balance_laser_primary_refire")))
142                 {
143                         if(cvar("g_balance_laser_gauntlet"))
144                                 W_Laser_Attack2();
145                         else
146                                 W_Laser_Attack(0);
147                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_laser_primary_animtime"), w_ready);
148                 }
149                 if (self.BUTTON_ATCK2)
150                 {
151                         if(cvar("g_balance_laser_secondary"))
152                         {
153                                 if (weapon_prepareattack(0, cvar("g_balance_laser_secondary_refire")))
154                                 {
155                                         W_Laser_Attack(1);
156                                         weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_laser_secondary_animtime"), w_ready);
157                                 }
158                         }
159                         else
160                         {
161                                 if(self.switchweapon == WEP_LASER) // don't do this if already switching
162                                         W_SwitchWeapon (self.cnt);
163                         }
164                 }
165         }
166         else if (req == WR_PRECACHE)
167         {
168                 precache_model ("models/weapons/g_laser.md3");
169                 precache_model ("models/weapons/v_laser.md3");
170                 precache_model ("models/weapons/h_laser.dpm");
171                 precache_sound ("weapons/lasergun_fire.wav");
172                 precache_sound ("weapons/gauntlet_fire.wav");
173         }
174         else if (req == WR_SETUP)
175                 weapon_setup(WEP_LASER);
176         else if (req == WR_CHECKAMMO1)
177                 return TRUE;
178         else if (req == WR_CHECKAMMO2)
179                 return TRUE;
180         else if (req == WR_SUICIDEMESSAGE)
181                 w_deathtypestring = "lasered themself to hell";
182         else if (req == WR_KILLMESSAGE)
183         {
184                 w_deathtypestring = "was lasered to death by"; // unchecked: SPLASH
185         }
186         return TRUE;
187 };
188 #endif