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