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