]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/w_blaster.qc
Add weaponthrowable property to weapons
[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  */ ammo_none,
6 /* impulse   */ 1,
7 /* flags     */ WEP_FLAG_NORMAL | WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH,
8 /* rating    */ 0,
9 /* color     */ '1 0.5 0.5',
10 /* modelname */ "laser",
11 /* simplemdl */ "foobar",
12 /* crosshair */ "gfx/crosshairlaser 0.4",
13 /* wepimg    */ "weaponlaser",
14 /* refname   */ "blaster",
15 /* wepname   */ _("Blaster")
16 );
17
18 #define BLASTER_SETTINGS(w_cvar,w_prop) BLASTER_SETTINGS_LIST(w_cvar, w_prop, BLASTER, blaster)
19 #define BLASTER_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
20         w_cvar(id, sn, BOTH, animtime) \
21         w_cvar(id, sn, BOTH, damage) \
22         w_cvar(id, sn, BOTH, delay) \
23         w_cvar(id, sn, BOTH, edgedamage) \
24         w_cvar(id, sn, BOTH, force) \
25         w_cvar(id, sn, BOTH, lifetime) \
26         w_cvar(id, sn, BOTH, radius) \
27         w_cvar(id, sn, BOTH, refire) \
28         w_cvar(id, sn, BOTH, shotangle) \
29         w_cvar(id, sn, BOTH, speed) \
30         w_cvar(id, sn, BOTH, spread) \
31         w_cvar(id, sn, NONE, secondary) \
32         w_prop(id, sn, float,  switchdelay_raise, switchdelay_raise) \
33         w_prop(id, sn, float,  switchdelay_drop, switchdelay_drop) \
34         w_prop(id, sn, string, weaponreplace, weaponreplace) \
35         w_prop(id, sn, float,  weaponstart, weaponstart) \
36         w_prop(id, sn, float,  weaponstartoverride, weaponstartoverride) \
37         w_prop(id, sn, float,  weaponthrowable, weaponthrowable)
38
39 #ifdef SVQC
40 BLASTER_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
41 .float blaster_damage;
42 .float blaster_edgedamage;
43 .float blaster_radius;
44 .float blaster_force;
45 .float blaster_lifetime;
46 #endif
47 #else
48 #ifdef SVQC
49 void spawnfunc_weapon_blaster() { weapon_defaultspawnfunc(WEP_BLASTER); }
50 void spawnfunc_weapon_laser() { spawnfunc_weapon_blaster(); }
51
52 void W_Blaster_Touch()
53 {
54         PROJECTILE_TOUCH;
55
56         self.event_damage = func_null;
57
58         RadiusDamage(
59                 self,
60                 self.realowner,
61                 self.blaster_damage,
62                 self.blaster_edgedamage,
63                 self.blaster_radius,
64                 world,
65                 world,
66                 self.blaster_force,
67                 self.projectiledeathtype,
68                 other
69         );
70         
71         remove(self);
72 }
73
74 void W_Blaster_Think()
75 {
76         self.movetype = MOVETYPE_FLY;
77         self.think = SUB_Remove;
78         self.nextthink = time + self.blaster_lifetime;
79         CSQCProjectile(self, TRUE, PROJECTILE_BLASTER, TRUE);
80 }
81
82 void W_Blaster_Attack(
83         float atk_shotangle,
84         float atk_damage,
85         float atk_edgedamage,
86         float atk_radius,
87         float atk_force,
88         float atk_speed,
89         float atk_spread,
90         float atk_delay,
91         float atk_lifetime)
92 {
93         vector s_forward = v_forward * cos(atk_shotangle * DEG2RAD) + v_up * sin(atk_shotangle * DEG2RAD);
94
95         W_SetupShot_Dir(self, s_forward, FALSE, 3, "weapons/lasergun_fire.wav", CH_WEAPON_B, atk_damage);
96         pointparticles(particleeffectnum("laser_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
97
98         entity missile = spawn();
99         missile.owner = missile.realowner = self;
100         missile.classname = "blasterbolt";
101         missile.bot_dodge = TRUE;
102         missile.bot_dodgerating = atk_damage;
103         PROJECTILE_MAKETRIGGER(missile);
104
105         missile.blaster_damage = atk_damage;
106         missile.blaster_edgedamage = atk_edgedamage;
107         missile.blaster_radius = atk_radius;
108         missile.blaster_force = atk_force;
109         missile.blaster_lifetime = atk_lifetime;
110
111         setorigin(missile, w_shotorg);
112         setsize(missile, '0 0 0', '0 0 0');
113         
114         W_SetupProjVelocity_Explicit(
115                 missile,
116                 w_shotdir,
117                 v_up,
118                 atk_speed,
119                 0,
120                 0,
121                 atk_spread,
122                 FALSE
123         );
124         
125         missile.angles = vectoangles(missile.velocity);
126         
127         //missile.glow_color = 250; // 244, 250
128         //missile.glow_size = 120;
129
130         missile.touch = W_Blaster_Touch;
131         missile.flags = FL_PROJECTILE;
132         missile.missile_flags = MIF_SPLASH;
133         missile.projectiledeathtype = WEP_BLASTER; 
134         missile.think = W_Blaster_Think;
135         missile.nextthink = time + atk_delay;
136
137         other = missile; MUTATOR_CALLHOOK(EditProjectile);
138
139         if(time >= missile.nextthink)
140         {
141                 entity oldself;
142                 oldself = self;
143                 self = missile;
144                 self.think();
145                 self = oldself;
146         }
147 }
148 float W_Blaster(float request)
149 {
150         switch(request)
151         {
152                 case WR_AIM:
153                 {
154                         if(WEP_CVAR(blaster, secondary))
155                         {
156                                 if((random() * (WEP_CVAR_PRI(blaster, damage) + WEP_CVAR_SEC(blaster, damage))) > WEP_CVAR_PRI(blaster, damage))
157                                         { self.BUTTON_ATCK2 = bot_aim(WEP_CVAR_SEC(blaster, speed), 0, WEP_CVAR_SEC(blaster, lifetime), FALSE); }
158                                 else
159                                         { self.BUTTON_ATCK = bot_aim(WEP_CVAR_PRI(blaster, speed), 0, WEP_CVAR_PRI(blaster, lifetime), FALSE); }
160                         }
161                         else
162                                 { self.BUTTON_ATCK = bot_aim(WEP_CVAR_PRI(blaster, speed), 0, WEP_CVAR_PRI(blaster, lifetime), FALSE); }
163
164                         return TRUE;
165                 }
166                 
167                 case WR_THINK:
168                 {
169                         if(self.BUTTON_ATCK)
170                         {
171                                 if(weapon_prepareattack(0, WEP_CVAR_PRI(blaster, refire)))
172                                 {
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_Blaster_Attack(
203                                                                 WEP_CVAR_SEC(blaster, shotangle),
204                                                                 WEP_CVAR_SEC(blaster, damage),
205                                                                 WEP_CVAR_SEC(blaster, edgedamage),
206                                                                 WEP_CVAR_SEC(blaster, radius),
207                                                                 WEP_CVAR_SEC(blaster, force),
208                                                                 WEP_CVAR_SEC(blaster, speed),
209                                                                 WEP_CVAR_SEC(blaster, spread),
210                                                                 WEP_CVAR_SEC(blaster, delay),
211                                                                 WEP_CVAR_SEC(blaster, lifetime)
212                                                         );
213                                                         weapon_thinkf(WFRAME_FIRE2, WEP_CVAR_SEC(blaster, animtime), w_ready);
214                                                 }
215
216                                                 break;
217                                         }
218                                 }
219                         }
220                         return TRUE;
221                 }
222                 
223                 case WR_INIT: 
224                 {
225                         precache_model("models/weapons/g_laser.md3");
226                         precache_model("models/weapons/v_laser.md3");
227                         precache_model("models/weapons/h_laser.iqm");
228                         precache_sound("weapons/lasergun_fire.wav");
229                         BLASTER_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP)
230                         return TRUE;
231                 }
232                 
233                 case WR_SETUP:
234                 {
235                         self.ammo_field = ammo_none;
236                         return TRUE;
237                 }
238                 
239                 case WR_CHECKAMMO1:
240                 case WR_CHECKAMMO2:
241                 {
242                         return TRUE; // laser has infinite ammo
243                 }
244                 
245                 case WR_CONFIG:
246                 {
247                         BLASTER_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS)
248                         return TRUE;
249                 }
250                 
251                 case WR_SUICIDEMESSAGE:
252                 {
253                         return WEAPON_BLASTER_SUICIDE;
254                 }
255                 
256                 case WR_KILLMESSAGE:
257                 {
258                         return WEAPON_BLASTER_MURDER;
259                 }
260         }
261         return FALSE;
262 }
263 #endif
264 #ifdef CSQC
265 float W_Blaster(float request)
266 {
267         switch(request)
268         {
269                 case WR_IMPACTEFFECT:
270                 {
271                         vector org2;
272                         org2 = w_org + w_backoff * 6;
273                         pointparticles(particleeffectnum("laser_impact"), org2, w_backoff * 1000, 1);
274                         if(!w_issilent) { sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM); }
275                         return TRUE;
276                 }
277                 
278                 case WR_INIT:
279                 {
280                         precache_sound("weapons/laserimpact.wav");
281                         return TRUE;
282                 }
283                 case WR_ZOOMRETICLE:
284                 {
285                         // no weapon specific image for this weapon
286                         return FALSE;
287                 }
288         }
289         return FALSE;
290 }
291 #endif
292 #endif