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