]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/w_blaster.qc
Further cleanup of laser, plus remove useless mode declarations
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / w_blaster.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(
3 /* WEP_##id */ LASER,
4 /* function */ W_Laser,
5 /* ammotype */ 0,
6 /* impulse  */ 1,
7 /* flags    */ WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH,
8 /* rating   */ 0,
9 /* model    */ "laser",
10 /* netname  */ "laser",
11 /* fullname */ _("Blaster")
12 );
13 #else
14 #ifdef SVQC
15 void spawnfunc_weapon_laser() { weapon_defaultspawnfunc(WEP_LASER); }
16
17 void W_Laser_Touch()
18 {
19         PROJECTILE_TOUCH;
20
21         self.event_damage = func_null;
22         
23         if(self.dmg)
24                 RadiusDamage(self, self.realowner, autocvar_g_balance_laser_secondary_damage, autocvar_g_balance_laser_secondary_edgedamage, autocvar_g_balance_laser_secondary_radius, world, world, autocvar_g_balance_laser_secondary_force, self.projectiledeathtype, other);
25         else
26                 RadiusDamage(self, self.realowner, autocvar_g_balance_laser_primary_damage, autocvar_g_balance_laser_primary_edgedamage, autocvar_g_balance_laser_primary_radius, world, world, autocvar_g_balance_laser_primary_force, self.projectiledeathtype, other);
27
28         remove(self);
29 }
30
31 void W_Laser_Think()
32 {
33         self.movetype = MOVETYPE_FLY;
34         self.think = SUB_Remove;
35         
36         if(self.dmg)
37                 self.nextthink = time + autocvar_g_balance_laser_secondary_lifetime;
38         else
39                 self.nextthink = time + autocvar_g_balance_laser_primary_lifetime;
40                 
41         CSQCProjectile(self, TRUE, PROJECTILE_LASER, TRUE);
42 }
43
44 void W_Laser_Attack(float issecondary)
45 {
46         entity missile;
47         vector s_forward;
48         float a;
49
50         a = autocvar_g_balance_laser_primary_shotangle;
51         s_forward = v_forward * cos(a * DEG2RAD) + v_up * sin(a * DEG2RAD);
52
53         //if(nodamage)
54         //      W_SetupShot_Dir(self, s_forward, FALSE, 3, "weapons/lasergun_fire.wav", CH_WEAPON_B, 0);
55         /*else*/if(issecondary == 1)
56                 W_SetupShot_Dir(self, s_forward, FALSE, 3, "weapons/lasergun_fire.wav", CH_WEAPON_B, autocvar_g_balance_laser_secondary_damage);
57         else
58                 W_SetupShot_Dir(self, s_forward, FALSE, 3, "weapons/lasergun_fire.wav", CH_WEAPON_B, autocvar_g_balance_laser_primary_damage);
59         pointparticles(particleeffectnum("laser_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
60
61         missile = spawn();
62         missile.owner = missile.realowner = self;
63         missile.classname = "laserbolt";
64         missile.dmg = 0;
65         missile.bot_dodge = TRUE;
66         missile.bot_dodgerating = autocvar_g_balance_laser_primary_damage;
67
68         PROJECTILE_MAKETRIGGER(missile);
69         missile.projectiledeathtype = WEP_LASER;
70
71         setorigin(missile, w_shotorg);
72         setsize(missile, '0 0 0', '0 0 0');
73
74         W_SETUPPROJECTILEVELOCITY(missile, g_balance_laser_primary);
75         missile.angles = vectoangles(missile.velocity);
76         //missile.glow_color = 250; // 244, 250
77         //missile.glow_size = 120;
78         missile.touch = W_Laser_Touch;
79
80         missile.flags = FL_PROJECTILE;
81         missile.missile_flags = MIF_SPLASH; 
82
83         missile.think = W_Laser_Think;
84         missile.nextthink = time + autocvar_g_balance_laser_primary_delay;
85
86         other = missile; MUTATOR_CALLHOOK(EditProjectile);
87
88         if(time >= missile.nextthink)
89         {
90                 entity oldself;
91                 oldself = self;
92                 self = missile;
93                 self.think();
94                 self = oldself;
95         }
96 }
97 float W_Laser(float request)
98 {
99         switch(request)
100         {
101                 case WR_AIM:
102                 {
103                         if(autocvar_g_balance_laser_secondary)
104                         {
105                                 if((random() * (autocvar_g_balance_laser_primary_damage + autocvar_g_balance_laser_secondary_damage)) > autocvar_g_balance_laser_primary_damage)
106                                         { self.BUTTON_ATCK2 = bot_aim(autocvar_g_balance_laser_secondary_speed, 0, autocvar_g_balance_laser_secondary_lifetime, FALSE); }
107                                 else
108                                         { self.BUTTON_ATCK = bot_aim(autocvar_g_balance_laser_primary_speed, 0, autocvar_g_balance_laser_primary_lifetime, FALSE); }
109                         }
110                         else
111                                 { self.BUTTON_ATCK = bot_aim(autocvar_g_balance_laser_primary_speed, 0, autocvar_g_balance_laser_primary_lifetime, FALSE); }
112
113                         return TRUE;
114                 }
115                 
116                 case WR_THINK:
117                 {
118                         if(autocvar_g_balance_laser_reload_ammo && self.clip_load < 1) // forced reload
119                                 WEP_ACTION(self.weapon, WR_RELOAD);
120                         else if(self.BUTTON_ATCK)
121                         {
122                                 if(weapon_prepareattack(0, autocvar_g_balance_laser_primary_refire))
123                                 {
124                                         W_DecreaseAmmo(ammo_none, 1, TRUE); // WEAPONTODO is this necessary?
125                                         W_Laser_Attack(FALSE);
126                                         weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_laser_primary_animtime, w_ready);
127                                 }
128                         }
129                         else if(self.BUTTON_ATCK2)
130                         {
131                                 switch(autocvar_g_balance_laser_secondary)
132                                 {
133                                         case 0: // switch to last used weapon
134                                         {
135                                                 if(self.switchweapon == WEP_LASER) // don't do this if already switching
136                                                         W_LastWeapon();
137                                                 break;
138                                         }
139
140                                         case 1: // normal projectile secondary
141                                         {
142                                                 if(weapon_prepareattack(1, autocvar_g_balance_laser_secondary_refire))
143                                                 {
144                                                         W_DecreaseAmmo(ammo_none, 1, TRUE);
145                                                         W_Laser_Attack(TRUE);
146                                                         weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_laser_secondary_animtime, w_ready);
147                                                 }
148
149                                                 break;
150                                         }
151                                 }
152                         }
153                         return TRUE;
154                 }
155                 
156                 case WR_INIT: 
157                 {
158                         precache_model("models/weapons/g_laser.md3");
159                         precache_model("models/weapons/v_laser.md3");
160                         precache_model("models/weapons/h_laser.iqm");
161                         precache_sound("weapons/lasergun_fire.wav");
162                         return TRUE;
163                 }
164                 
165                 case WR_SETUP:
166                 {
167                         self.current_ammo = ammo_none;
168                         return TRUE;
169                 }
170                 
171                 case WR_CHECKAMMO1:
172                 case WR_CHECKAMMO2:
173                 {
174                         return TRUE; // laser has infinite ammo
175                 }
176                 
177                 case WR_RELOAD:
178                 {
179                         W_Reload(0, "weapons/reload.wav");
180                         return TRUE;
181                 }
182                 
183                 case WR_SUICIDEMESSAGE:
184                 {
185                         return WEAPON_LASER_SUICIDE;
186                 }
187                 
188                 case WR_KILLMESSAGE:
189                 {
190                         return WEAPON_LASER_MURDER;
191                 }
192         }
193         
194         return TRUE;
195 }
196 #endif
197 #ifdef CSQC
198 float W_Laser(float request)
199 {
200         switch(request)
201         {
202                 case WR_IMPACTEFFECT:
203                 {
204                         vector org2;
205                         org2 = w_org + w_backoff * 6;
206                         pointparticles(particleeffectnum("new_laser_impact"), org2, w_backoff * 1000, 1);
207                         if(!w_issilent) { sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM); }
208                         return TRUE;
209                 }
210                 
211                 case WR_INIT:
212                 {
213                         precache_sound("weapons/laserimpact.wav");
214                         return TRUE;
215                 }
216         }
217         
218         return TRUE;
219 }
220 #endif
221 #endif