]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/w_blaster.qc
Begin adding support for weaponstart and weaponreplace properties
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / w_blaster.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(
3 /* WEP_##id */ BLASTER,
4 /* function */ W_Blaster,
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
14 #define BLASTER_SETTINGS(w_cvar,w_prop) \
15         w_cvar(WEP_BLASTER, blaster, MO_BOTH, animtime) \
16         w_cvar(WEP_BLASTER, blaster, MO_BOTH, damage) \
17         w_cvar(WEP_BLASTER, blaster, MO_BOTH, delay) \
18         w_cvar(WEP_BLASTER, blaster, MO_BOTH, edgedamage) \
19         w_cvar(WEP_BLASTER, blaster, MO_BOTH, force) \
20         w_cvar(WEP_BLASTER, blaster, MO_BOTH, lifetime) \
21         w_cvar(WEP_BLASTER, blaster, MO_BOTH, radius) \
22         w_cvar(WEP_BLASTER, blaster, MO_BOTH, refire) \
23         w_cvar(WEP_BLASTER, blaster, MO_BOTH, shotangle) \
24         w_cvar(WEP_BLASTER, blaster, MO_BOTH, speed) \
25         w_cvar(WEP_BLASTER, blaster, MO_BOTH, spread) \
26         w_cvar(WEP_BLASTER, blaster, MO_NONE, secondary) \
27         w_prop(WEP_BLASTER, blaster, float,  reloading_ammo, reload_ammo) \
28         w_prop(WEP_BLASTER, blaster, float,  reloading_time, reload_time) \
29         w_prop(WEP_BLASTER, blaster, float,  switchdelay_raise, switchdelay_raise) \
30         w_prop(WEP_BLASTER, blaster, float,  switchdelay_drop, switchdelay_drop)
31
32 #ifdef SVQC
33 BLASTER_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
34 .float blaster_damage;
35 .float blaster_edgedamage;
36 .float blaster_radius;
37 .float blaster_force;
38 .float blaster_lifetime;
39 #endif
40 #else
41 #ifdef SVQC
42 void spawnfunc_weapon_blaster() { weapon_defaultspawnfunc(WEP_BLASTER); }
43 void spawnfunc_weapon_laser() { spawnfunc_weapon_blaster(); }
44
45 void W_Blaster_Touch()
46 {
47         PROJECTILE_TOUCH;
48
49         self.event_damage = func_null;
50
51         RadiusDamage(
52                 self,
53                 self.realowner,
54                 self.blaster_damage,
55                 self.blaster_edgedamage,
56                 self.blaster_radius,
57                 world,
58                 world,
59                 self.blaster_force,
60                 self.projectiledeathtype,
61                 other
62         );
63         
64         remove(self);
65 }
66
67 void W_Blaster_Think()
68 {
69         self.movetype = MOVETYPE_FLY;
70         self.think = SUB_Remove;
71         self.nextthink = time + self.blaster_lifetime;
72         CSQCProjectile(self, TRUE, PROJECTILE_BLASTER, TRUE);
73 }
74
75 void W_Blaster_Attack(
76         float atk_shotangle,
77         float atk_damage,
78         float atk_edgedamage,
79         float atk_radius,
80         float atk_force,
81         float atk_speed,
82         float atk_spread,
83         float atk_delay,
84         float atk_lifetime)
85 {
86         vector s_forward = v_forward * cos(atk_shotangle * DEG2RAD) + v_up * sin(atk_shotangle * DEG2RAD);
87
88         W_SetupShot_Dir(self, s_forward, FALSE, 3, "weapons/lasergun_fire.wav", CH_WEAPON_B, atk_damage);
89         pointparticles(particleeffectnum("laser_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
90
91         entity missile = spawn();
92         missile.owner = missile.realowner = self;
93         missile.classname = "blasterbolt";
94         missile.bot_dodge = TRUE;
95         missile.bot_dodgerating = atk_damage;
96         PROJECTILE_MAKETRIGGER(missile);
97
98         missile.blaster_damage = atk_damage;
99         missile.blaster_edgedamage = atk_edgedamage;
100         missile.blaster_radius = atk_radius;
101         missile.blaster_force = atk_force;
102         missile.blaster_lifetime = atk_lifetime;
103
104         setorigin(missile, w_shotorg);
105         setsize(missile, '0 0 0', '0 0 0');
106         
107         W_SetupProjectileVelocityEx(
108                 missile,
109                 w_shotdir,
110                 v_up,
111                 atk_speed,
112                 0,
113                 0,
114                 atk_spread,
115                 FALSE
116         );
117         
118         missile.angles = vectoangles(missile.velocity);
119         
120         //missile.glow_color = 250; // 244, 250
121         //missile.glow_size = 120;
122
123         missile.touch = W_Blaster_Touch;
124         missile.flags = FL_PROJECTILE;
125         missile.missile_flags = MIF_SPLASH;
126         missile.projectiledeathtype = WEP_BLASTER; 
127         missile.think = W_Blaster_Think;
128         missile.nextthink = time + atk_delay;
129
130         other = missile; MUTATOR_CALLHOOK(EditProjectile);
131
132         if(time >= missile.nextthink)
133         {
134                 entity oldself;
135                 oldself = self;
136                 self = missile;
137                 self.think();
138                 self = oldself;
139         }
140 }
141 float W_Blaster(float request)
142 {
143         switch(request)
144         {
145                 case WR_AIM:
146                 {
147                         if(WEP_CVAR(blaster, secondary))
148                         {
149                                 if((random() * (WEP_CVAR_PRI(blaster, damage) + WEP_CVAR_SEC(blaster, damage))) > WEP_CVAR_PRI(blaster, damage))
150                                         { self.BUTTON_ATCK2 = bot_aim(WEP_CVAR_SEC(blaster, speed), 0, WEP_CVAR_SEC(blaster, lifetime), FALSE); }
151                                 else
152                                         { self.BUTTON_ATCK = bot_aim(WEP_CVAR_PRI(blaster, speed), 0, WEP_CVAR_PRI(blaster, lifetime), FALSE); }
153                         }
154                         else
155                                 { self.BUTTON_ATCK = bot_aim(WEP_CVAR_PRI(blaster, speed), 0, WEP_CVAR_PRI(blaster, lifetime), FALSE); }
156
157                         return TRUE;
158                 }
159                 
160                 case WR_THINK:
161                 {
162                         if(WEP_CVAR(blaster, reload_ammo) && self.clip_load < 1) // forced reload
163                         {
164                                 WEP_ACTION(self.weapon, WR_RELOAD);
165                         }
166                         else if(self.BUTTON_ATCK)
167                         {
168                                 if(weapon_prepareattack(0, WEP_CVAR_PRI(blaster, refire)))
169                                 {
170                                         W_DecreaseAmmo(ammo_none, 1, TRUE); // WEAPONTODO is this necessary?
171                                         W_Blaster_Attack(
172                                                 WEP_CVAR_PRI(blaster, shotangle),
173                                                 WEP_CVAR_PRI(blaster, damage),
174                                                 WEP_CVAR_PRI(blaster, edgedamage),
175                                                 WEP_CVAR_PRI(blaster, radius),
176                                                 WEP_CVAR_PRI(blaster, force),
177                                                 WEP_CVAR_PRI(blaster, speed),
178                                                 WEP_CVAR_PRI(blaster, spread),
179                                                 WEP_CVAR_PRI(blaster, delay),
180                                                 WEP_CVAR_PRI(blaster, lifetime)
181                                         );
182                                         weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(blaster, animtime), w_ready);
183                                 }
184                         }
185                         else if(self.BUTTON_ATCK2)
186                         {
187                                 switch(WEP_CVAR(blaster, secondary))
188                                 {
189                                         case 0: // switch to last used weapon
190                                         {
191                                                 if(self.switchweapon == WEP_BLASTER) // don't do this if already switching
192                                                         W_LastWeapon();
193                                                 break;
194                                         }
195
196                                         case 1: // normal projectile secondary
197                                         {
198                                                 if(weapon_prepareattack(1, WEP_CVAR_SEC(blaster, refire)))
199                                                 {
200                                                         W_DecreaseAmmo(ammo_none, 1, TRUE);
201                                                         W_Blaster_Attack(
202                                                                 WEP_CVAR_SEC(blaster, shotangle),
203                                                                 WEP_CVAR_SEC(blaster, damage),
204                                                                 WEP_CVAR_SEC(blaster, edgedamage),
205                                                                 WEP_CVAR_SEC(blaster, radius),
206                                                                 WEP_CVAR_SEC(blaster, force),
207                                                                 WEP_CVAR_SEC(blaster, speed),
208                                                                 WEP_CVAR_SEC(blaster, spread),
209                                                                 WEP_CVAR_SEC(blaster, delay),
210                                                                 WEP_CVAR_SEC(blaster, lifetime)
211                                                         );
212                                                         weapon_thinkf(WFRAME_FIRE2, WEP_CVAR_SEC(blaster, animtime), w_ready);
213                                                 }
214
215                                                 break;
216                                         }
217                                 }
218                         }
219                         return TRUE;
220                 }
221                 
222                 case WR_INIT: 
223                 {
224                         precache_model("models/weapons/g_laser.md3");
225                         precache_model("models/weapons/v_laser.md3");
226                         precache_model("models/weapons/h_laser.iqm");
227                         precache_sound("weapons/lasergun_fire.wav");
228                         BLASTER_SETTINGS(WEP_SKIPCVAR, WEP_SET_PROP)
229                         return TRUE;
230                 }
231                 
232                 case WR_SETUP:
233                 {
234                         self.current_ammo = ammo_none;
235                         return TRUE;
236                 }
237                 
238                 case WR_CHECKAMMO1:
239                 case WR_CHECKAMMO2:
240                 {
241                         return TRUE; // laser has infinite ammo
242                 }
243                 
244                 case WR_CONFIG:
245                 {
246                         BLASTER_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS)
247                         return TRUE;
248                 }
249                 
250                 case WR_RELOAD:
251                 {
252                         W_Reload(0, "weapons/reload.wav");
253                         return TRUE;
254                 }
255                 
256                 case WR_SUICIDEMESSAGE:
257                 {
258                         return WEAPON_LASER_SUICIDE;
259                 }
260                 
261                 case WR_KILLMESSAGE:
262                 {
263                         return WEAPON_LASER_MURDER;
264                 }
265         }
266         
267         return TRUE;
268 }
269 #endif
270 #ifdef CSQC
271 float W_Blaster(float request)
272 {
273         switch(request)
274         {
275                 case WR_IMPACTEFFECT:
276                 {
277                         vector org2;
278                         org2 = w_org + w_backoff * 6;
279                         pointparticles(particleeffectnum("new_laser_impact"), org2, w_backoff * 1000, 1);
280                         if(!w_issilent) { sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM); }
281                         return TRUE;
282                 }
283                 
284                 case WR_INIT:
285                 {
286                         precache_sound("weapons/laserimpact.wav");
287                         return TRUE;
288                 }
289         }
290         
291         return TRUE;
292 }
293 #endif
294 #endif