]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/w_laser.qc
fix a stupid bug
[divverent/nexuiz.git] / data / qcsrc / server / w_laser.qc
1 void(float imp) W_SwitchWeapon;
2
3 void W_Laser_Touch (void)
4 {
5         PROJECTILE_TOUCH;
6
7         self.event_damage = SUB_Null;
8         if (self.dmg)
9                 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);
10         else
11                 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);
12
13         remove (self);
14 }
15
16 void W_Laser_Attack (float issecondary)
17 {
18         local entity missile;
19         vector s_forward;
20         float a;
21         float nodamage;
22
23         if(issecondary == 2) // minstanex shot
24                 nodamage = g_minstagib;
25         else
26                 nodamage = FALSE;
27
28         if (issecondary == 1)
29                 a = cvar("g_balance_laser_secondary_shotangle");
30         else
31                 a = cvar("g_balance_laser_primary_shotangle");
32         s_forward = v_forward * cos(a * DEG2RAD) + v_up * sin(a * DEG2RAD);
33
34         if(nodamage)
35                 W_SetupShot_Dir (self, s_forward, FALSE, 3, "weapons/lasergun_fire.wav", 0);
36         else if(issecondary == 1)
37                 W_SetupShot_Dir (self, s_forward, FALSE, 3, "weapons/lasergun_fire.wav", cvar("g_balance_laser_secondary_damage"));
38         else
39                 W_SetupShot_Dir (self, s_forward, FALSE, 3, "weapons/lasergun_fire.wav", cvar("g_balance_laser_primary_damage"));
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 == 1);
46         if(!nodamage)
47         {
48                 missile.bot_dodge = TRUE;
49                 if (issecondary == 1)
50                         missile.bot_dodgerating = cvar("g_balance_laser_secondary_damage");
51                 else
52                         missile.bot_dodgerating = cvar("g_balance_laser_primary_damage");
53         }
54
55         missile.movetype = MOVETYPE_FLY;
56         PROJECTILE_MAKETRIGGER(missile);
57         missile.projectiledeathtype = WEP_LASER;
58         if(issecondary == 1)
59                 missile.projectiledeathtype |= HITTYPE_SECONDARY;
60
61         setorigin (missile, w_shotorg);
62         setsize(missile, '0 0 0', '0 0 0');
63
64         if (issecondary == 1)
65                 missile.velocity = w_shotdir * cvar("g_balance_laser_secondary_speed");
66         else
67                 missile.velocity = w_shotdir * cvar("g_balance_laser_primary_speed");
68         W_SetupProjectileVelocity(missile);
69         missile.angles = vectoangles (missile.velocity);
70         //missile.glow_color = 250; // 244, 250
71         //missile.glow_size = 120;
72         missile.touch = W_Laser_Touch;
73         missile.think = SUB_Remove;
74         if (issecondary == 1)
75                 missile.nextthink = time + cvar("g_balance_laser_secondary_lifetime");
76         else
77                 missile.nextthink = time + cvar("g_balance_laser_primary_lifetime");
78
79         missile.flags = FL_PROJECTILE;
80
81         CSQCProjectile(missile, TRUE, PROJECTILE_LASER, TRUE);
82 }
83
84 void spawnfunc_weapon_laser (void)
85 {
86         weapon_defaultspawnfunc(WEP_LASER);
87 }
88
89 float w_laser(float req)
90 {
91         local float r1;
92         local float r2;
93         if (req == WR_AIM)
94         {
95                 if(cvar("g_balance_laser_secondary"))
96                 {
97                         r1 = cvar("g_balance_laser_primary_damage");
98                         r2 = cvar("g_balance_laser_secondary_damage");
99                         if (random() * (r2 + r1) > r1)
100                                 self.BUTTON_ATCK2 = bot_aim(cvar("g_balance_laser_secondary_speed"), 0, cvar("g_balance_laser_secondary_lifetime"), FALSE);
101                         else
102                                 self.BUTTON_ATCK = bot_aim(cvar("g_balance_laser_primary_speed"), 0, cvar("g_balance_laser_primary_lifetime"), FALSE);
103                 }
104                 else
105                         self.BUTTON_ATCK = bot_aim(cvar("g_balance_laser_primary_speed"), 0, cvar("g_balance_laser_primary_lifetime"), FALSE);
106         }
107         else if (req == WR_THINK)
108         {
109                 if (self.BUTTON_ATCK)
110                 if (weapon_prepareattack(0, cvar("g_balance_laser_primary_refire")))
111                 {
112                         W_Laser_Attack(0);
113                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_laser_primary_animtime"), w_ready);
114                 }
115                 if (self.BUTTON_ATCK2)
116                 {
117                         if(cvar("g_balance_laser_secondary"))
118                         {
119                                 if (weapon_prepareattack(0, cvar("g_balance_laser_secondary_refire")))
120                                 {
121                                         W_Laser_Attack(1);
122                                         weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_laser_secondary_animtime"), w_ready);
123                                 }
124                         }
125                         else
126                         {
127                                 if(self.switchweapon == WEP_LASER) // don't do this if already switching
128                                         W_SwitchWeapon (self.cnt);
129                         }
130                 }
131         }
132         else if (req == WR_PRECACHE)
133         {
134                 precache_model ("models/weapons/g_laser.md3");
135                 precache_model ("models/weapons/v_laser.md3");
136                 precache_model ("models/weapons/h_laser.dpm");
137                 precache_sound ("weapons/lasergun_fire.wav");
138         }
139         else if (req == WR_SETUP)
140                 weapon_setup(WEP_LASER);
141         else if (req == WR_CHECKAMMO1)
142                 return TRUE;
143         else if (req == WR_CHECKAMMO2)
144                 return TRUE;
145         else if (req == WR_SUICIDEMESSAGE)
146                 w_deathtypestring = "lasered himself to hell";
147         else if (req == WR_KILLMESSAGE)
148         {
149                 w_deathtypestring = "was lasered to death by"; // unchecked: SPLASH
150         }
151         return TRUE;
152 };