]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/w_blaster.qc
Merge remote-tracking branch 'origin/master' into samual/weapons
[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 void(float imp) W_SwitchWeapon;
17 void() W_LastWeapon;
18
19 void SendCSQCShockwaveParticle(vector endpos) 
20 {
21         //endpos = WarpZone_UnTransformOrigin(transform, endpos);
22         
23         WriteByte(MSG_BROADCAST, SVC_TEMPENTITY);
24         WriteByte(MSG_BROADCAST, TE_CSQC_SHOCKWAVEPARTICLE);
25         WriteCoord(MSG_BROADCAST, w_shotorg_x);
26         WriteCoord(MSG_BROADCAST, w_shotorg_y);
27         WriteCoord(MSG_BROADCAST, w_shotorg_z);
28         WriteCoord(MSG_BROADCAST, endpos_x);
29         WriteCoord(MSG_BROADCAST, endpos_y);
30         WriteCoord(MSG_BROADCAST, endpos_z);
31         WriteByte(MSG_BROADCAST, bound(0, autocvar_g_balance_laser_shockwave_spread_max, 255));
32         WriteByte(MSG_BROADCAST, bound(0, autocvar_g_balance_laser_shockwave_spread_min, 255));
33         WriteByte(MSG_BROADCAST, num_for_edict(self));
34 }
35
36 void W_Laser_Touch()
37 {
38         PROJECTILE_TOUCH;
39
40         self.event_damage = func_null;
41         
42         if(self.dmg)
43                 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);
44         else
45                 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);
46
47         remove(self);
48 }
49
50 void W_Laser_Think()
51 {
52         self.movetype = MOVETYPE_FLY;
53         self.think = SUB_Remove;
54         
55         if(self.dmg)
56                 self.nextthink = time + autocvar_g_balance_laser_secondary_lifetime;
57         else
58                 self.nextthink = time + autocvar_g_balance_laser_primary_lifetime;
59                 
60         CSQCProjectile(self, TRUE, PROJECTILE_LASER, TRUE);
61 }
62
63 void W_Laser_Attack(float issecondary)
64 {
65         entity missile;
66         vector s_forward;
67         float a;
68
69         a = autocvar_g_balance_laser_primary_shotangle;
70         s_forward = v_forward * cos(a * DEG2RAD) + v_up * sin(a * DEG2RAD);
71
72         //if(nodamage)
73         //      W_SetupShot_Dir(self, s_forward, FALSE, 3, "weapons/lasergun_fire.wav", CH_WEAPON_B, 0);
74         /*else*/if(issecondary == 1)
75                 W_SetupShot_Dir(self, s_forward, FALSE, 3, "weapons/lasergun_fire.wav", CH_WEAPON_B, autocvar_g_balance_laser_secondary_damage);
76         else
77                 W_SetupShot_Dir(self, s_forward, FALSE, 3, "weapons/lasergun_fire.wav", CH_WEAPON_B, autocvar_g_balance_laser_primary_damage);
78         pointparticles(particleeffectnum("laser_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
79
80         missile = spawn();
81         missile.owner = missile.realowner = self;
82         missile.classname = "laserbolt";
83         missile.dmg = 0;
84         missile.bot_dodge = TRUE;
85         missile.bot_dodgerating = autocvar_g_balance_laser_primary_damage;
86
87         PROJECTILE_MAKETRIGGER(missile);
88         missile.projectiledeathtype = WEP_LASER;
89
90         setorigin(missile, w_shotorg);
91         setsize(missile, '0 0 0', '0 0 0');
92
93         W_SETUPPROJECTILEVELOCITY(missile, g_balance_laser_primary);
94         missile.angles = vectoangles(missile.velocity);
95         //missile.glow_color = 250; // 244, 250
96         //missile.glow_size = 120;
97         missile.touch = W_Laser_Touch;
98
99         missile.flags = FL_PROJECTILE;
100         missile.missile_flags = MIF_SPLASH; 
101
102         missile.think = W_Laser_Think;
103         missile.nextthink = time + autocvar_g_balance_laser_primary_delay;
104
105         other = missile; MUTATOR_CALLHOOK(EditProjectile);
106
107         if(time >= missile.nextthink)
108         {
109                 entity oldself;
110                 oldself = self;
111                 self = missile;
112                 self.think();
113                 self = oldself;
114         }
115 }
116
117 float W_Laser(float request)
118 {
119         switch(request)
120         {
121                 case WR_AIM:
122                 {
123                         if((autocvar_g_balance_laser_secondary == 2) && (vlen(self.origin-self.enemy.origin) <= autocvar_g_balance_laser_melee_range))
124                                 self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, FALSE);
125                         else
126                                 self.BUTTON_ATCK = bot_aim(1000000, 0, 1, FALSE);
127                         return TRUE;
128                 }
129                 
130                 case WR_THINK:
131                 {
132                         if(autocvar_g_balance_laser_reload_ammo && self.clip_load < 1) // forced reload
133                                 WEP_ACTION(self.weapon, WR_RELOAD);
134                         else if(self.BUTTON_ATCK)
135                         {
136                                 if(weapon_prepareattack(0, autocvar_g_balance_laser_primary_refire))
137                                 {
138                                         W_DecreaseAmmo(ammo_none, 1, TRUE);
139
140                                         if not(autocvar_g_balance_laser_primary)
141                                                 W_Laser_Shockwave();
142                                         else
143                                                 W_Laser_Attack(FALSE);
144
145                                         weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_laser_primary_animtime, w_ready);
146                                 }
147                         }
148                         else if(self.BUTTON_ATCK2)
149                         {
150                                 switch(autocvar_g_balance_laser_secondary)
151                                 {
152                                         case 0: // switch to last used weapon
153                                         {
154                                                 if(self.switchweapon == WEP_LASER) // don't do this if already switching
155                                                         W_LastWeapon();
156
157                                                 break;
158                                         }
159
160                                         case 1: // normal projectile secondary
161                                         {
162                                                 if(weapon_prepareattack(1, autocvar_g_balance_laser_secondary_refire))
163                                                 {
164                                                         W_DecreaseAmmo(ammo_none, 1, TRUE);
165                                                         W_Laser_Attack(TRUE);
166                                                         weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_laser_secondary_animtime, w_ready);
167                                                 }
168
169                                                 break;
170                                         }
171
172                                         case 2: // melee attack secondary
173                                         {
174                                                 if(!self.crouch) // we are not currently crouching; this fixes an exploit where your melee anim is not visible, and besides wouldn't make much sense
175                                                 if(weapon_prepareattack(1, autocvar_g_balance_laser_melee_refire))
176                                                 {
177                                                         // attempt forcing playback of the anim by switching to another anim (that we never play) here...
178                                                         W_Laser_Melee();
179                                                         weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_laser_melee_animtime, w_ready);
180                                                 }
181                                         }
182                                 }
183                         }
184                         return TRUE;
185                 }
186                 
187                 case WR_INIT: 
188                 {
189                         precache_model("models/weapons/g_laser.md3");
190                         precache_model("models/weapons/v_laser.md3");
191                         precache_model("models/weapons/h_laser.iqm");
192                         precache_sound("weapons/lasergun_fire.wav");
193                         return TRUE;
194                 }
195                 
196                 case WR_SETUP:
197                 {
198                         self.current_ammo = ammo_none;
199                         return TRUE;
200                 }
201                 
202                 case WR_CHECKAMMO1:
203                 case WR_CHECKAMMO2:
204                 {
205                         return TRUE; // laser has infinite ammo
206                 }
207                 
208                 case WR_RELOAD:
209                 {
210                         W_Reload(0, "weapons/reload.wav");
211                         return TRUE;
212                 }
213                 
214                 case WR_SUICIDEMESSAGE:
215                 {
216                         return WEAPON_LASER_SUICIDE;
217                 }
218                 
219                 case WR_KILLMESSAGE:
220                 {
221                         return WEAPON_LASER_MURDER;
222                 }
223         }
224         
225         return TRUE;
226 }
227 #endif
228 #ifdef CSQC
229 float W_Laser(float request)
230 {
231         switch(request)
232         {
233                 case WR_IMPACTEFFECT:
234                 {
235                         vector org2;
236                         org2 = w_org + w_backoff * 6;
237                         pointparticles(particleeffectnum("new_laser_impact"), org2, w_backoff * 1000, 1);
238                         if(!w_issilent) { sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM); }
239                         return TRUE;
240                 }
241                 
242                 case WR_INIT:
243                 {
244                         precache_sound("weapons/laserimpact.wav");
245                         return TRUE;
246                 }
247         }
248         
249         return TRUE;
250 }
251 #endif
252 #endif