]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/electro.qc
Merge branch 'master' into Lyberta/RandomItems
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / electro.qc
1 #include "electro.qh"
2
3 #ifdef SVQC
4
5 void W_Electro_TriggerCombo(vector org, float rad, entity own)
6 {
7         entity e = WarpZone_FindRadius(org, rad, !WEP_CVAR(electro, combo_comboradius_thruwall));
8         while(e)
9         {
10                 if(e.classname == "electro_orb")
11                 {
12                         // do we allow thruwall triggering?
13                         if(WEP_CVAR(electro, combo_comboradius_thruwall))
14                         {
15                                 // if distance is greater than thruwall distance, check to make sure it's not through a wall
16                                 if(vdist(e.WarpZone_findradius_dist, >, WEP_CVAR(electro, combo_comboradius_thruwall)))
17                                 {
18                                         WarpZone_TraceLine(org, e.origin, MOVE_NOMONSTERS, e);
19                                         if(trace_fraction != 1)
20                                         {
21                                                 // trigger is through a wall and outside of thruwall range, abort
22                                                 e = e.chain;
23                                                 continue;
24                                         }
25                                 }
26                         }
27
28                         // change owner to whoever caused the combo explosion
29                         e.realowner = own;
30                         e.takedamage = DAMAGE_NO;
31                         e.classname = "electro_orb_chain";
32
33                         // now set the next one to trigger as well
34                         setthink(e, W_Electro_ExplodeCombo);
35
36                         // delay combo chains, looks cooler
37                         e.nextthink =
38                                 (
39                                         time
40                                         +
41                                         (WEP_CVAR(electro, combo_speed) ?
42                                                 (vlen(e.WarpZone_findradius_dist) / WEP_CVAR(electro, combo_speed))
43                                                 :
44                                                 0
45                                         )
46                                 );
47                 }
48                 e = e.chain;
49         }
50 }
51
52 void W_Electro_ExplodeCombo(entity this)
53 {
54         W_Electro_TriggerCombo(this.origin, WEP_CVAR(electro, combo_comboradius), this.realowner);
55
56         this.event_damage = func_null;
57
58         RadiusDamage(
59                 this,
60                 this.realowner,
61                 WEP_CVAR(electro, combo_damage),
62                 WEP_CVAR(electro, combo_edgedamage),
63                 WEP_CVAR(electro, combo_radius),
64                 NULL,
65                 NULL,
66                 WEP_CVAR(electro, combo_force),
67                 WEP_ELECTRO.m_id | HITTYPE_BOUNCE, // use THIS type for a combo because primary can't bounce
68                 NULL
69         );
70
71         delete(this);
72 }
73
74 void W_Electro_Explode(entity this, entity directhitentity)
75 {
76         if(directhitentity.takedamage == DAMAGE_AIM)
77                 if(IS_PLAYER(directhitentity))
78                         if(DIFF_TEAM(this.realowner, directhitentity))
79                                 if(!IS_DEAD(directhitentity))
80                                         if(IsFlying(directhitentity))
81                                                 Send_Notification(NOTIF_ONE, this.realowner, MSG_ANNCE, ANNCE_ACHIEVEMENT_ELECTROBITCH);
82
83         this.event_damage = func_null;
84         this.takedamage = DAMAGE_NO;
85
86         if(this.move_movetype == MOVETYPE_BOUNCE || this.classname == "electro_orb") // TODO: classname is more reliable anyway?
87         {
88                 RadiusDamage(
89                         this,
90                         this.realowner,
91                         WEP_CVAR_SEC(electro, damage),
92                         WEP_CVAR_SEC(electro, edgedamage),
93                         WEP_CVAR_SEC(electro, radius),
94                         NULL,
95                         NULL,
96                         WEP_CVAR_SEC(electro, force),
97                         this.projectiledeathtype,
98                         directhitentity
99                 );
100         }
101         else
102         {
103                 W_Electro_TriggerCombo(this.origin, WEP_CVAR_PRI(electro, comboradius), this.realowner);
104                 RadiusDamage(
105                         this,
106                         this.realowner,
107                         WEP_CVAR_PRI(electro, damage),
108                         WEP_CVAR_PRI(electro, edgedamage),
109                         WEP_CVAR_PRI(electro, radius),
110                         NULL,
111                         NULL,
112                         WEP_CVAR_PRI(electro, force),
113                         this.projectiledeathtype,
114                         directhitentity
115                 );
116         }
117
118         delete(this);
119 }
120
121 void W_Electro_Explode_use(entity this, entity actor, entity trigger)
122 {
123         W_Electro_Explode(this, trigger);
124 }
125
126 void W_Electro_TouchExplode(entity this, entity toucher)
127 {
128         PROJECTILE_TOUCH(this, toucher);
129         W_Electro_Explode(this, toucher);
130 }
131
132
133 void sys_phys_update_single(entity this);
134
135 void W_Electro_Bolt_Think(entity this)
136 {
137         // sys_phys_update_single(this);
138         if(time >= this.ltime)
139         {
140                 this.use(this, NULL, NULL);
141                 return;
142         }
143
144         if(WEP_CVAR_PRI(electro, midaircombo_radius))
145         {
146                 float found = 0;
147                 entity e = WarpZone_FindRadius(this.origin, WEP_CVAR_PRI(electro, midaircombo_radius), true);
148
149                 // loop through nearby orbs and trigger them
150                 while(e)
151                 {
152                         if(e.classname == "electro_orb")
153                         {
154                                 // change owner to whoever caused the combo explosion
155                                 e.realowner = this.realowner;
156                                 e.takedamage = DAMAGE_NO;
157                                 e.classname = "electro_orb_chain";
158
159                                 // now set the next one to trigger as well
160                                 setthink(e, W_Electro_ExplodeCombo);
161
162                                 // delay combo chains, looks cooler
163                                 e.nextthink =
164                                         (
165                                                 time
166                                                 +
167                                                 (WEP_CVAR(electro, combo_speed) ?
168                                                         (vlen(e.WarpZone_findradius_dist) / WEP_CVAR(electro, combo_speed))
169                                                         :
170                                                         0
171                                                 )
172                                         );
173
174                                 ++found;
175                         }
176                         e = e.chain;
177                 }
178
179                 // if we triggered an orb, should we explode? if not, lets try again next time
180                 if(found && WEP_CVAR_PRI(electro, midaircombo_explode))
181                         { this.use(this, NULL, NULL); }
182                 else
183                         { this.nextthink = min(time + WEP_CVAR_PRI(electro, midaircombo_interval), this.ltime); }
184         }
185         else { this.nextthink = this.ltime; }
186         // this.nextthink = time;
187 }
188
189 void W_Electro_Attack_Bolt(Weapon thiswep, entity actor, .entity weaponentity)
190 {
191         entity proj;
192
193         W_DecreaseAmmo(thiswep, actor, WEP_CVAR_PRI(electro, ammo), weaponentity);
194
195         W_SetupShot_ProjectileSize(
196                 actor,
197                 weaponentity,
198                 '0 0 -3',
199                 '0 0 -3',
200                 false,
201                 2,
202                 SND_ELECTRO_FIRE,
203                 CH_WEAPON_A,
204                 WEP_CVAR_PRI(electro, damage)
205         );
206
207         Send_Effect(EFFECT_ELECTRO_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
208
209         proj = new(electro_bolt);
210         proj.owner = proj.realowner = actor;
211         proj.bot_dodge = true;
212         proj.bot_dodgerating = WEP_CVAR_PRI(electro, damage);
213         proj.use = W_Electro_Explode_use;
214         setthink(proj, W_Electro_Bolt_Think);
215         proj.nextthink = time;
216         proj.ltime = time + WEP_CVAR_PRI(electro, lifetime);
217         PROJECTILE_MAKETRIGGER(proj);
218         proj.projectiledeathtype = WEP_ELECTRO.m_id;
219         setorigin(proj, w_shotorg);
220
221         // if (IS_CSQC)
222         set_movetype(proj, MOVETYPE_FLY);
223         W_SetupProjVelocity_PRI(proj, electro);
224         proj.angles = vectoangles(proj.velocity);
225         settouch(proj, W_Electro_TouchExplode);
226         setsize(proj, '0 0 -3', '0 0 -3');
227         proj.flags = FL_PROJECTILE;
228         IL_PUSH(g_projectiles, proj);
229         IL_PUSH(g_bot_dodge, proj);
230         proj.missile_flags = MIF_SPLASH;
231
232         CSQCProjectile(proj, true, PROJECTILE_ELECTRO_BEAM, true);
233
234         MUTATOR_CALLHOOK(EditProjectile, actor, proj);
235         // proj.com_phys_pos = proj.origin;
236         // proj.com_phys_vel = proj.velocity;
237 }
238
239 void W_Electro_Orb_Stick(entity this, entity to)
240 {
241         entity newproj = spawn();
242         newproj.classname = this.classname;
243
244         newproj.bot_dodge = this.bot_dodge;
245         newproj.bot_dodgerating = this.bot_dodgerating;
246
247         newproj.owner = this.owner;
248         newproj.realowner = this.realowner;
249         setsize(newproj, this.mins, this.maxs);
250         setorigin(newproj, this.origin);
251         setmodel(newproj, MDL_PROJECTILE_ELECTRO);
252         newproj.angles = vectoangles(-trace_plane_normal); // face against the surface
253
254         newproj.takedamage = this.takedamage;
255         newproj.damageforcescale = this.damageforcescale;
256         newproj.health = this.health;
257         newproj.event_damage = this.event_damage;
258         newproj.spawnshieldtime = this.spawnshieldtime;
259         newproj.damagedbycontents = true;
260         IL_PUSH(g_damagedbycontents, newproj);
261
262         set_movetype(newproj, MOVETYPE_NONE); // lock the orb in place
263         newproj.projectiledeathtype = this.projectiledeathtype;
264
265         settouch(newproj, func_null);
266         setthink(newproj, getthink(this));
267         newproj.nextthink = this.nextthink;
268         newproj.use = this.use;
269         newproj.flags = this.flags;
270         IL_PUSH(g_projectiles, newproj);
271         IL_PUSH(g_bot_dodge, newproj);
272
273         delete(this);
274
275         if(to)
276                 SetMovetypeFollow(this, to);
277 }
278
279 void W_Electro_Orb_Touch(entity this, entity toucher)
280 {
281         PROJECTILE_TOUCH(this, toucher);
282         if(toucher.takedamage == DAMAGE_AIM)
283                 { if(WEP_CVAR_SEC(electro, touchexplode)) { W_Electro_Explode(this, toucher); } }
284         else
285         {
286                 //UpdateCSQCProjectile(this);
287                 spamsound(this, CH_SHOTS, SND_ELECTRO_BOUNCE, VOL_BASE, ATTEN_NORM);
288                 this.projectiledeathtype |= HITTYPE_BOUNCE;
289
290                 if(WEP_CVAR_SEC(electro, stick))
291                         W_Electro_Orb_Stick(this, toucher);
292         }
293 }
294
295 void W_Electro_Orb_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
296 {
297         if(this.health <= 0)
298                 return;
299
300         // note: combos are usually triggered by W_Electro_TriggerCombo, not damage
301         float is_combo = (inflictor.classname == "electro_orb_chain" || inflictor.classname == "electro_bolt");
302
303         if(!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, (is_combo ? 1 : -1)))
304                 return; // g_projectiles_damage says to halt
305
306         this.health = this.health - damage;
307         if(this.health <= 0)
308         {
309                 this.takedamage = DAMAGE_NO;
310                 this.nextthink = time;
311                 if(is_combo)
312                 {
313                         // change owner to whoever caused the combo explosion
314                         this.realowner = inflictor.realowner;
315                         this.classname = "electro_orb_chain";
316                         setthink(this, W_Electro_ExplodeCombo);
317                         this.nextthink = time +
318                                 (
319                                         // bound the length, inflictor may be in a galaxy far far away (warpzones)
320                                         min(
321                                                 WEP_CVAR(electro, combo_radius),
322                                                 vlen(this.origin - inflictor.origin)
323                                         )
324                                         /
325                                         // delay combo chains, looks cooler
326                                         WEP_CVAR(electro, combo_speed)
327                                 );
328                 }
329                 else
330                 {
331                         this.use = W_Electro_Explode_use;
332                         setthink(this, adaptor_think2use); // not _hittype_splash, as this runs "immediately"
333                 }
334         }
335 }
336
337 void W_Electro_Attack_Orb(Weapon thiswep, entity actor, .entity weaponentity)
338 {
339         W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(electro, ammo), weaponentity);
340
341         W_SetupShot_ProjectileSize(
342                 actor,
343                 weaponentity,
344                 '-4 -4 -4',
345                 '4 4 4',
346                 false,
347                 2,
348                 SND_ELECTRO_FIRE2,
349                 CH_WEAPON_A,
350                 WEP_CVAR_SEC(electro, damage)
351         );
352
353         w_shotdir = v_forward; // no TrueAim for grenades please
354
355         Send_Effect(EFFECT_ELECTRO_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
356
357         entity proj = new(electro_orb);
358         proj.owner = proj.realowner = actor;
359         proj.use = W_Electro_Explode_use;
360         setthink(proj, adaptor_think2use_hittype_splash);
361         proj.bot_dodge = true;
362         proj.bot_dodgerating = WEP_CVAR_SEC(electro, damage);
363         proj.nextthink = time + WEP_CVAR_SEC(electro, lifetime);
364         PROJECTILE_MAKETRIGGER(proj);
365         proj.projectiledeathtype = WEP_ELECTRO.m_id | HITTYPE_SECONDARY;
366         setorigin(proj, w_shotorg);
367
368         //proj.glow_size = 50;
369         //proj.glow_color = 45;
370         set_movetype(proj, MOVETYPE_BOUNCE);
371         W_SetupProjVelocity_UP_SEC(proj, electro);
372         settouch(proj, W_Electro_Orb_Touch);
373         setsize(proj, '-4 -4 -4', '4 4 4');
374         proj.takedamage = DAMAGE_YES;
375         proj.damageforcescale = WEP_CVAR_SEC(electro, damageforcescale);
376         proj.health = WEP_CVAR_SEC(electro, health);
377         proj.event_damage = W_Electro_Orb_Damage;
378         proj.flags = FL_PROJECTILE;
379         IL_PUSH(g_projectiles, proj);
380         IL_PUSH(g_bot_dodge, proj);
381         proj.damagedbycontents = (WEP_CVAR_SEC(electro, damagedbycontents));
382         if(proj.damagedbycontents)
383                 IL_PUSH(g_damagedbycontents, proj);
384
385         proj.bouncefactor = WEP_CVAR_SEC(electro, bouncefactor);
386         proj.bouncestop = WEP_CVAR_SEC(electro, bouncestop);
387         proj.missile_flags = MIF_SPLASH | MIF_ARC;
388
389 #if 0
390         entity p2;
391         p2 = spawn();
392         copyentity(proj, p2);
393         setmodel(p2, MDL_PROJECTILE_ELECTRO);
394         setsize(p2, proj.mins, proj.maxs);
395 #endif
396
397         CSQCProjectile(proj, true, PROJECTILE_ELECTRO, false); // no culling, it has sound
398
399         MUTATOR_CALLHOOK(EditProjectile, actor, proj);
400 }
401
402 void W_Electro_CheckAttack(Weapon thiswep, entity actor, .entity weaponentity, int fire)
403 {
404         if(actor.(weaponentity).electro_count > 1)
405         if(PHYS_INPUT_BUTTON_ATCK2(actor))
406         if(weapon_prepareattack(thiswep, actor, weaponentity, true, -1))
407         {
408                 W_Electro_Attack_Orb(WEP_ELECTRO, actor, weaponentity);
409                 actor.(weaponentity).electro_count -= 1;
410                 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(electro, animtime), W_Electro_CheckAttack);
411                 return;
412         }
413         // WEAPONTODO: when the player releases the button, cut down the length of refire2?
414         w_ready(thiswep, actor, weaponentity, fire);
415 }
416
417 .float bot_secondary_electromooth;
418
419 METHOD(Electro, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
420 {
421     PHYS_INPUT_BUTTON_ATCK(actor) = PHYS_INPUT_BUTTON_ATCK2(actor) = false;
422     if(vdist(actor.origin - actor.enemy.origin, >, 1000)) { actor.bot_secondary_electromooth = 0; }
423     if(actor.bot_secondary_electromooth == 0)
424     {
425         float shoot;
426
427         if(WEP_CVAR_PRI(electro, speed))
428             shoot = bot_aim(actor, weaponentity, WEP_CVAR_PRI(electro, speed), 0, WEP_CVAR_PRI(electro, lifetime), false);
429         else
430             shoot = bot_aim(actor, weaponentity, 1000000, 0, 0.001, false);
431
432         if(shoot)
433         {
434             PHYS_INPUT_BUTTON_ATCK(actor) = true;
435             if(random() < 0.01) actor.bot_secondary_electromooth = 1;
436         }
437     }
438     else
439     {
440         if(bot_aim(actor, weaponentity, WEP_CVAR_SEC(electro, speed), WEP_CVAR_SEC(electro, speed_up), WEP_CVAR_SEC(electro, lifetime), true))
441         {
442             PHYS_INPUT_BUTTON_ATCK2(actor) = true;
443             if(random() < 0.03) actor.bot_secondary_electromooth = 0;
444         }
445     }
446 }
447 METHOD(Electro, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
448 {
449     if(autocvar_g_balance_electro_reload_ammo) // forced reload // WEAPONTODO
450     {
451         float ammo_amount = 0;
452         if(actor.(weaponentity).clip_load >= WEP_CVAR_PRI(electro, ammo))
453             ammo_amount = 1;
454         if(actor.(weaponentity).clip_load >= WEP_CVAR_SEC(electro, ammo))
455             ammo_amount += 1;
456
457         if(!ammo_amount)
458         {
459             thiswep.wr_reload(thiswep, actor, weaponentity);
460             return;
461         }
462     }
463
464     if(fire & 1)
465     {
466         if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(electro, refire)))
467         {
468                 W_Electro_Attack_Bolt(thiswep, actor, weaponentity);
469                 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready);
470         }
471     }
472     else if(fire & 2)
473     {
474         if(time >= actor.(weaponentity).electro_secondarytime)
475         if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(electro, refire)))
476         {
477             W_Electro_Attack_Orb(thiswep, actor, weaponentity);
478             actor.(weaponentity).electro_count = WEP_CVAR_SEC(electro, count);
479             weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(electro, animtime), W_Electro_CheckAttack);
480             actor.(weaponentity).electro_secondarytime = time + WEP_CVAR_SEC(electro, refire2) * W_WeaponRateFactor(actor);
481         }
482     }
483 }
484 METHOD(Electro, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
485 {
486     float ammo_amount = GetResourceAmount(actor, thiswep.ammo_type) >= WEP_CVAR_PRI(electro, ammo);
487     ammo_amount += actor.(weaponentity).(weapon_load[WEP_ELECTRO.m_id]) >= WEP_CVAR_PRI(electro, ammo);
488     return ammo_amount;
489 }
490 METHOD(Electro, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
491 {
492     float ammo_amount;
493     if(WEP_CVAR(electro, combo_safeammocheck)) // true if you can fire at least one secondary blob AND one primary shot after it, otherwise false.
494     {
495         ammo_amount = GetResourceAmount(actor, thiswep.ammo_type) >= WEP_CVAR_SEC(electro, ammo) + WEP_CVAR_PRI(electro, ammo);
496         ammo_amount += actor.(weaponentity).(weapon_load[WEP_ELECTRO.m_id]) >= WEP_CVAR_SEC(electro, ammo) + WEP_CVAR_PRI(electro, ammo);
497     }
498     else
499     {
500         ammo_amount = GetResourceAmount(actor, thiswep.ammo_type) >= WEP_CVAR_SEC(electro, ammo);
501         ammo_amount += actor.(weaponentity).(weapon_load[WEP_ELECTRO.m_id]) >= WEP_CVAR_SEC(electro, ammo);
502     }
503     return ammo_amount;
504 }
505 METHOD(Electro, wr_resetplayer, void(entity thiswep, entity actor))
506 {
507     for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
508     {
509         .entity weaponentity = weaponentities[slot];
510         actor.(weaponentity).electro_secondarytime = time;
511     }
512 }
513 METHOD(Electro, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
514 {
515     W_Reload(actor, weaponentity, min(WEP_CVAR_PRI(electro, ammo), WEP_CVAR_SEC(electro, ammo)), SND_RELOAD);
516 }
517 METHOD(Electro, wr_suicidemessage, Notification(entity thiswep))
518 {
519     if(w_deathtype & HITTYPE_SECONDARY)
520         return WEAPON_ELECTRO_SUICIDE_ORBS;
521     else
522         return WEAPON_ELECTRO_SUICIDE_BOLT;
523 }
524 METHOD(Electro, wr_killmessage, Notification(entity thiswep))
525 {
526     if(w_deathtype & HITTYPE_SECONDARY)
527     {
528         return WEAPON_ELECTRO_MURDER_ORBS;
529     }
530     else
531     {
532         if(w_deathtype & HITTYPE_BOUNCE)
533             return WEAPON_ELECTRO_MURDER_COMBO;
534         else
535             return WEAPON_ELECTRO_MURDER_BOLT;
536     }
537 }
538
539 #endif
540 #ifdef CSQC
541
542 METHOD(Electro, wr_impacteffect, void(entity thiswep, entity actor))
543 {
544     vector org2;
545     org2 = w_org + w_backoff * 6;
546     if(w_deathtype & HITTYPE_SECONDARY)
547     {
548         pointparticles(EFFECT_ELECTRO_BALLEXPLODE, org2, '0 0 0', 1);
549         if(!w_issilent)
550             sound(actor, CH_SHOTS, SND_ELECTRO_IMPACT, VOL_BASE, ATTEN_NORM);
551     }
552     else
553     {
554         if(w_deathtype & HITTYPE_BOUNCE)
555         {
556             // this is sent as "primary (w_deathtype & HITTYPE_BOUNCE)" to distinguish it from (w_deathtype & HITTYPE_SECONDARY) bounced balls
557             pointparticles(EFFECT_ELECTRO_COMBO, org2, '0 0 0', 1);
558             if(!w_issilent)
559                 sound(actor, CH_SHOTS, SND_ELECTRO_IMPACT_COMBO, VOL_BASE, ATTEN_NORM);
560         }
561         else
562         {
563             pointparticles(EFFECT_ELECTRO_IMPACT, org2, '0 0 0', 1);
564             if(!w_issilent)
565                 sound(actor, CH_SHOTS, SND_ELECTRO_IMPACT, VOL_BASE, ATTEN_NORM);
566         }
567     }
568 }
569
570 #endif