Xonotic
hellion_weapon.qc
Go to the documentation of this file.
1 #include "hellion_weapon.qh"
2 
3 #ifdef SVQC
4 
5 float autocvar_g_turrets_unit_hellion_shot_speed_gain;
6 float autocvar_g_turrets_unit_hellion_shot_speed_max;
7 
8 void turret_hellion_missile_think(entity this);
9 SOUND(HellionAttack_FIRE, W_Sound("electro_fire"));
10 METHOD(HellionAttack, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) {
11  bool isPlayer = IS_PLAYER(actor);
12  if (fire & 1)
13  if (!isPlayer || weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(electro, refire))) {
14  if (isPlayer) {
15  turret_initparams(actor);
16  W_SetupShot_Dir(actor, weaponentity, v_forward, false, 0, SND_HellionAttack_FIRE, CH_WEAPON_B, 0, DEATH_TURRET_HELLION.m_id);
17  actor.tur_shotdir_updated = w_shotdir;
18  actor.tur_shotorg = w_shotorg;
19  actor.tur_head = actor;
20  actor.shot_radius = 500;
21  weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready);
22  }
23  if (!isPlayer) {
24  if (actor.tur_head.frame != 0)
25  actor.tur_shotorg = gettaginfo(actor.tur_head, gettagindex(actor.tur_head, "tag_fire"));
26  else
27  actor.tur_shotorg = gettaginfo(actor.tur_head, gettagindex(actor.tur_head, "tag_fire2"));
28  }
29 
30  entity missile = turret_projectile(actor, SND_ROCKET_FIRE, 6, 10, DEATH_TURRET_HELLION.m_id, PROJECTILE_ROCKET, false, false);
31  te_explosion (missile.origin);
32  setthink(missile, turret_hellion_missile_think);
33  missile.nextthink = time;
34  missile.max_health = time + 9;
35  missile.tur_aimpos = randomvec() * 128;
36  missile.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_GUIDED_HEAT;
37  if (!isPlayer) actor.tur_head.frame += 1;
38  }
39 }
40 
41 void turret_hellion_missile_think(entity this)
42 {
43  vector olddir,newdir;
44  vector pre_pos;
45  float itime;
46 
47  this.nextthink = time + 0.05;
48 
49  olddir = normalize(this.velocity);
50 
51  if(this.max_health < time)
53 
54  // Enemy dead? just keep on the current heading then.
55  if ((this.enemy == NULL) || (IS_DEAD(this.enemy)))
56  {
57 
58  // Make sure we dont return to tracking a respawned player
59  this.enemy = NULL;
60 
61  // Turn model
62  this.angles = vectoangles(this.velocity);
63 
64  if(vdist(this.origin - this.owner.origin, >, (this.owner.shot_radius * 5)))
66 
67  // Accelerate
68  this.velocity = olddir * min(vlen(this.velocity) * (autocvar_g_turrets_unit_hellion_shot_speed_gain), (autocvar_g_turrets_unit_hellion_shot_speed_max));
69 
71 
72  return;
73  }
74 
75  // Enemy in range?
76  if(vdist(this.origin - this.enemy.origin, <, this.owner.shot_radius * 0.2))
78 
79  // Predict enemy position
80  itime = vlen(this.enemy.origin - this.origin) / vlen(this.velocity);
81  pre_pos = this.enemy.origin + this.enemy.velocity * itime;
82 
83  pre_pos = (pre_pos + this.enemy.origin) * 0.5;
84 
85  // Find out the direction to that place
86  newdir = normalize(pre_pos - this.origin);
87 
88  // Turn
89  newdir = normalize(olddir + newdir * 0.35);
90 
91  // Turn model
92  this.angles = vectoangles(this.velocity);
93 
94  // Accelerate
95  this.velocity = newdir * min(vlen(this.velocity) * (autocvar_g_turrets_unit_hellion_shot_speed_gain), (autocvar_g_turrets_unit_hellion_shot_speed_max));
96 
97  if (itime < 0.05)
99 
100  UpdateCSQCProjectile(this);
101 }
102 
103 #endif
#define WEP_CVAR_PRI(wepname, name)
Definition: all.qh:300
vector w_shotorg
Definition: tracing.qh:18
const int MIF_SPLASH
Definition: common.qh:34
entity() spawn
void w_ready(Weapon thiswep, entity actor,.entity weaponentity, int fire)
vector w_shotdir
Definition: tracing.qh:19
origin
Definition: ent_cs.qc:114
#define gettaginfo
Definition: post.qh:32
string W_Sound(string w_snd)
Definition: all.qc:281
#define METHOD(cname, name, prototype)
Definition: oo.qh:257
void turret_projectile_explode(entity this)
entity owner
Definition: main.qh:73
#define gettagindex
Definition: dpextensions.qh:16
entity enemy
Definition: sv_ctf.qh:143
void UpdateCSQCProjectile(entity e)
const int PROJECTILE_ROCKET
Definition: projectiles.qh:4
bool weapon_prepareattack(Weapon thiswep, entity actor,.entity weaponentity, bool secondary, float attacktime)
#define NULL
Definition: post.qh:17
float max_health
entity turret_projectile(entity actor, Sound _snd, float _size, float _health, float _death, float _proj_type, float _cull, float _cli_anim)
#define IS_DEAD(s)
Definition: utils.qh:26
float nextthink
Definition: csprogsdefs.qc:121
#define W_SetupShot_Dir(ent, wepent, s_forward, antilag, recoil, snd, chan, maxdamage, deathtype)
Definition: tracing.qh:31
vector(float skel, float bonenum) _skel_get_boneabs_hidden
#define vdist(v, cmp, f)
Vector distance comparison, avoids sqrt()
Definition: vector.qh:8
void weapon_thinkf(entity actor,.entity weaponentity, WFRAME fr, float t, void(Weapon thiswep, entity actor,.entity weaponentity, int fire) func)
#define setthink(e, f)
vector angles
Definition: csprogsdefs.qc:104
const int MIF_GUIDED_HEAT
Definition: common.qh:38
#define SOUND(name, path)
Definition: all.qh:30
float time
Definition: csprogsdefs.qc:16
vector velocity
Definition: csprogsdefs.qc:103
const int CH_WEAPON_B
Definition: sound.qh:8
const int MIF_PROXY
Definition: common.qh:36
#define IS_PLAYER(v)
Definition: utils.qh:9
vector v_forward
Definition: csprogsdefs.qc:31