]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/w_blaster.qc
Make it mostly compile... just gotta deal with the changes to bullet code
[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 void W_Laser_Shockwave(void);
117 void W_Laser_Melee(void);
118 float W_Laser(float request)
119 {
120         switch(request)
121         {
122                 case WR_AIM:
123                 {
124                         if((autocvar_g_balance_laser_secondary == 2) && (vlen(self.origin-self.enemy.origin) <= autocvar_g_balance_laser_melee_range))
125                                 self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, FALSE);
126                         else
127                                 self.BUTTON_ATCK = bot_aim(1000000, 0, 1, FALSE);
128                         return TRUE;
129                 }
130                 
131                 case WR_THINK:
132                 {
133                         if(autocvar_g_balance_laser_reload_ammo && self.clip_load < 1) // forced reload
134                                 WEP_ACTION(self.weapon, WR_RELOAD);
135                         else if(self.BUTTON_ATCK)
136                         {
137                                 if(weapon_prepareattack(0, autocvar_g_balance_laser_primary_refire))
138                                 {
139                                         W_DecreaseAmmo(ammo_none, 1, TRUE);
140
141                                         if not(autocvar_g_balance_laser_primary)
142                                                 W_Laser_Shockwave();
143                                         else
144                                                 W_Laser_Attack(FALSE);
145
146                                         weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_laser_primary_animtime, w_ready);
147                                 }
148                         }
149                         else if(self.BUTTON_ATCK2)
150                         {
151                                 switch(autocvar_g_balance_laser_secondary)
152                                 {
153                                         case 0: // switch to last used weapon
154                                         {
155                                                 if(self.switchweapon == WEP_LASER) // don't do this if already switching
156                                                         W_LastWeapon();
157
158                                                 break;
159                                         }
160
161                                         case 1: // normal projectile secondary
162                                         {
163                                                 if(weapon_prepareattack(1, autocvar_g_balance_laser_secondary_refire))
164                                                 {
165                                                         W_DecreaseAmmo(ammo_none, 1, TRUE);
166                                                         W_Laser_Attack(TRUE);
167                                                         weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_laser_secondary_animtime, w_ready);
168                                                 }
169
170                                                 break;
171                                         }
172
173                                         case 2: // melee attack secondary
174                                         {
175                                                 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
176                                                 if(weapon_prepareattack(1, autocvar_g_balance_laser_melee_refire))
177                                                 {
178                                                         // attempt forcing playback of the anim by switching to another anim (that we never play) here...
179                                                         W_Laser_Melee();
180                                                         weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_laser_melee_animtime, w_ready);
181                                                 }
182                                         }
183                                 }
184                         }
185                         return TRUE;
186                 }
187                 
188                 case WR_INIT: 
189                 {
190                         precache_model("models/weapons/g_laser.md3");
191                         precache_model("models/weapons/v_laser.md3");
192                         precache_model("models/weapons/h_laser.iqm");
193                         precache_sound("weapons/lasergun_fire.wav");
194                         return TRUE;
195                 }
196                 
197                 case WR_SETUP:
198                 {
199                         self.current_ammo = ammo_none;
200                         return TRUE;
201                 }
202                 
203                 case WR_CHECKAMMO1:
204                 case WR_CHECKAMMO2:
205                 {
206                         return TRUE; // laser has infinite ammo
207                 }
208                 
209                 case WR_RELOAD:
210                 {
211                         W_Reload(0, "weapons/reload.wav");
212                         return TRUE;
213                 }
214                 
215                 case WR_SUICIDEMESSAGE:
216                 {
217                         return WEAPON_LASER_SUICIDE;
218                 }
219                 
220                 case WR_KILLMESSAGE:
221                 {
222                         return WEAPON_LASER_MURDER;
223                 }
224         }
225         
226         return TRUE;
227 }
228 #endif
229 #ifdef CSQC
230 float W_Laser(float request)
231 {
232         switch(request)
233         {
234                 case WR_IMPACTEFFECT:
235                 {
236                         vector org2;
237                         org2 = w_org + w_backoff * 6;
238                         pointparticles(particleeffectnum("new_laser_impact"), org2, w_backoff * 1000, 1);
239                         if(!w_issilent) { sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM); }
240                         return TRUE;
241                 }
242                 
243                 case WR_INIT:
244                 {
245                         precache_sound("weapons/laserimpact.wav");
246                         return TRUE;
247                 }
248         }
249         
250         return TRUE;
251 }
252 #endif
253 #endif