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