Xonotic
raptor_weapons.qc
Go to the documentation of this file.
1 #include "raptor_weapons.qh"
2 
3 #ifdef SVQC
4 
5 METHOD(RaptorCannon, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) {
6  bool isPlayer = IS_PLAYER(actor);
7  entity player = isPlayer ? actor : actor.owner;
8  entity veh = player.vehicle;
9  // 1 [wait] 1 [wait] 2 [wait] 2 [wait] [wait]
10  float t = autocvar_g_vehicle_raptor_cannon_refire * (1 + ((veh.misc_bulletcounter + 1) >= 4));
11  if (fire & 1)
12  if (weapon_prepareattack(thiswep, player, weaponentity, false, t)) {
13  if (isPlayer) W_SetupShot_Dir(player, weaponentity, v_forward, false, 0, SND_Null, CH_WEAPON_B, 0, DEATH_VH_RAPT_CANNON.m_id);
14  vector org = w_shotorg;
16  if (veh) {
17  veh.misc_bulletcounter += 1;
18  org = (veh.misc_bulletcounter <= 2) ? gettaginfo(veh.gun1, gettagindex(veh.gun1, "fire1"))
19  : (((veh.misc_bulletcounter >= 4) ? veh.misc_bulletcounter = 0 : 0), gettaginfo(veh.gun2, gettagindex(veh.gun2, "fire1")));
20  dir = v_forward;
21  veh.vehicle_energy -= autocvar_g_vehicle_raptor_cannon_cost;
22  actor.cnt = time;
23  }
24  vehicles_projectile(veh, EFFECT_RAPTOR_MUZZLEFLASH, SND_LASERGUN_FIRE,
25  org, normalize(dir + randomvec() * autocvar_g_vehicle_raptor_cannon_spread) * autocvar_g_vehicle_raptor_cannon_speed,
26  autocvar_g_vehicle_raptor_cannon_damage, autocvar_g_vehicle_raptor_cannon_radius, autocvar_g_vehicle_raptor_cannon_force, 0,
27  DEATH_VH_RAPT_CANNON.m_id, PROJECTILE_RAPTORCANNON, 0, true, true, player);
28  weapon_thinkf(player, weaponentity, WFRAME_FIRE1, 0, w_ready);
29  }
30 }
31 METHOD(RaptorCannon, wr_checkammo1, bool(RacerAttack thiswep, entity actor, .entity weaponentity)) {
32  bool isPlayer = IS_PLAYER(actor);
33  entity player = isPlayer ? actor : actor.owner;
34  entity veh = player.vehicle;
35  return isPlayer || veh.vehicle_energy >= autocvar_g_vehicle_raptor_cannon_cost;
36 }
37 
38 
39 void raptor_bombdrop(entity this);
40 METHOD(RaptorBomb, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) {
41  bool isPlayer = IS_PLAYER(actor);
42  entity player = isPlayer ? actor : actor.owner;
43  entity veh = player.vehicle;
44  if (fire & 2)
45  if (!isPlayer || weapon_prepareattack(thiswep, player, weaponentity, true, autocvar_g_vehicle_raptor_bombs_refire)) {
46  entity e = (veh) ? veh : player;
47  raptor_bombdrop(e);
48  weapon_thinkf(player, weaponentity, WFRAME_FIRE2, 0, w_ready);
49  }
50 }
51 
52 void raptor_flare_think(entity this);
53 void raptor_flare_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force);
54 void raptor_flare_touch(entity this, entity toucher);
55 
56 METHOD(RaptorFlare, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) {
57  bool isPlayer = IS_PLAYER(actor);
58  entity player = isPlayer ? actor : actor.owner;
59  entity veh = player.vehicle;
60  if (fire & 2)
61  if (!isPlayer || weapon_prepareattack(thiswep, player, weaponentity, true, autocvar_g_vehicle_raptor_flare_refire)) {
62  vector forward, right, up;
63  MAKE_VECTORS(player.v_angle, forward, right, up);
64  for(int i = 0; i < 3; ++i) {
65  entity _flare = new(RaptorFlare_flare);
66  setmodel(_flare, MDL_VEH_RAPTOR_FLARE);
67  _flare.effects = EF_LOWPRECISION | EF_FLAME;
68  _flare.scale = 0.5;
69  setorigin(_flare, actor.origin - '0 0 16');
70  set_movetype(_flare, MOVETYPE_TOSS);
71  _flare.gravity = 0.15;
72  _flare.velocity = 0.25 * actor.velocity + (forward + randomvec() * 0.25)* -500;
73  setthink(_flare, raptor_flare_think);
74  _flare.nextthink = time;
75  _flare.owner = veh ? veh : player;
76  _flare.solid = SOLID_CORPSE;
77  _flare.takedamage = DAMAGE_YES;
78  _flare.event_damage = raptor_flare_damage;
79  SetResourceExplicit(_flare, RES_HEALTH, 20);
80  _flare.tur_impacttime = time + autocvar_g_vehicle_raptor_flare_lifetime;
81  settouch(_flare, raptor_flare_touch);
82  }
83  weapon_thinkf(player, weaponentity, WFRAME_FIRE2, 0, w_ready);
84  }
85 }
86 
87 
88 void raptor_bomblet_boom(entity this)
89 {
90  RadiusDamage (this, this.realowner, autocvar_g_vehicle_raptor_bomblet_damage,
91  autocvar_g_vehicle_raptor_bomblet_edgedamage,
92  autocvar_g_vehicle_raptor_bomblet_radius, NULL, NULL,
93  autocvar_g_vehicle_raptor_bomblet_force, DEATH_VH_RAPT_BOMB.m_id, DMG_NOWEP, NULL);
94  delete(this);
95 }
96 
97 void raptor_bomblet_touch(entity this, entity toucher)
98 {
99  if(toucher == this.owner)
100  return;
101 
102  PROJECTILE_TOUCH(this, toucher);
103  setthink(this, raptor_bomblet_boom);
104  this.nextthink = time + random() * autocvar_g_vehicle_raptor_bomblet_explode_delay;
105 }
106 
107 void raptor_bomb_burst(entity this)
108 {
109  if(this.cnt > time)
110  if(autocvar_g_vehicle_raptor_bomblet_alt)
111  {
112  this.nextthink = time;
113  traceline(this.origin, this.origin + (normalize(this.velocity) * autocvar_g_vehicle_raptor_bomblet_alt), MOVE_NORMAL, this);
114  if((trace_fraction == 1.0) || (vdist(this.origin - this.owner.origin, <, autocvar_g_vehicle_raptor_bomblet_radius)))
115  {
116  UpdateCSQCProjectile(this);
117  return;
118  }
119  }
120 
121  entity bomblet;
122  float i;
123 
124  Damage_DamageInfo(this.origin, 0, 0, 0, '0 0 0', DEATH_VH_RAPT_FRAGMENT.m_id, 0, this);
125 
126  for(i = 0; i < autocvar_g_vehicle_raptor_bomblets; ++i)
127  {
128  bomblet = new(raptor_bomb_bomblet);
129  setorigin(bomblet, this.origin);
130 
131  set_movetype(bomblet, MOVETYPE_TOSS);
132  settouch(bomblet, raptor_bomblet_touch);
133  setthink(bomblet, raptor_bomblet_boom);
134  bomblet.nextthink = time + 5;
135  bomblet.owner = this.owner;
136  bomblet.realowner = this.realowner;
137  bomblet.velocity = normalize(normalize(this.velocity) + (randomvec() * autocvar_g_vehicle_raptor_bomblet_spread)) * vlen(this.velocity);
138 
139  PROJECTILE_MAKETRIGGER(bomblet);
140  CSQCProjectile(bomblet, true, PROJECTILE_RAPTORBOMBLET, true);
141  }
142 
143  delete(this);
144 }
145 
146 void raptor_bomb_touch(entity this, entity toucher)
147 {
148  raptor_bomb_burst(this);
149 }
150 
151 void raptor_bombdrop(entity this)
152 {
153  entity bomb_1 = new(bombmount_left);
154  entity bomb_2 = new(bombmount_right);
155 
156  vector org = gettaginfo(this, gettagindex(this, "bombmount_left"));
157  setorigin(bomb_1, org);
158  org = gettaginfo(this, gettagindex(this, "bombmount_right"));
159  setorigin(bomb_2, org);
160 
161  set_movetype(bomb_1, MOVETYPE_BOUNCE);
162  set_movetype(bomb_2, MOVETYPE_BOUNCE);
163  bomb_1.velocity = bomb_2.velocity = this.velocity;
164  settouch(bomb_1, raptor_bomb_touch);
165  settouch(bomb_2, raptor_bomb_touch);
166  setthink(bomb_1, raptor_bomb_burst);
167  setthink(bomb_2, raptor_bomb_burst);
168  bomb_1.cnt = bomb_2.cnt = time + 10;
169 
170  if(autocvar_g_vehicle_raptor_bomblet_alt)
171  bomb_1.nextthink = bomb_2.nextthink = time;
172  else
173  bomb_1.nextthink = bomb_2.nextthink = time + autocvar_g_vehicle_raptor_bomblet_time;
174 
175  bomb_1.owner = bomb_2.owner = this;
176  bomb_1.realowner = bomb_2.realowner = this.owner;
177  bomb_1.solid = bomb_2.solid = SOLID_BBOX;
178  bomb_1.gravity = bomb_2.gravity = 1;
179 
180  PROJECTILE_MAKETRIGGER(bomb_1);
181  PROJECTILE_MAKETRIGGER(bomb_2);
182 
183  CSQCProjectile(bomb_1, true, PROJECTILE_RAPTORBOMB, true);
184  CSQCProjectile(bomb_2, true, PROJECTILE_RAPTORBOMB, true);
185 }
186 
187 void raptor_flare_touch(entity this, entity toucher)
188 {
189  delete(this);
190 }
191 
192 void raptor_flare_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
193 {
194  TakeResource(this, RES_HEALTH, damage);
195  if(GetResource(this, RES_HEALTH) <= 0)
196  delete(this);
197 }
198 
199 void raptor_flare_think(entity this)
200 {
201  this.nextthink = time + 0.1;
202  IL_EACH(g_projectiles, it.enemy == this.owner,
203  {
204  if(vdist(this.origin - it.origin, <, autocvar_g_vehicle_raptor_flare_range))
205  if(random() > autocvar_g_vehicle_raptor_flare_chase)
206  it.enemy = this;
207  });
208 
209  if(this.tur_impacttime < time)
210  delete(this);
211 }
212 
213 #endif
214 
215 #ifdef CSQC
216 
217 void RaptorCBShellfragDraw(entity this)
218 {
219  if(wasfreed(this))
220  return;
221 
222  Movetype_Physics_MatchTicrate(this, autocvar_cl_gibs_ticrate, autocvar_cl_gibs_sloppy);
223  this.avelocity += randomvec() * 15;
224  this.renderflags = 0;
225 
226  if(this.cnt < time)
227  this.alpha = bound(0, this.nextthink - time, 1);
228 
229  if(this.alpha < ALPHA_MIN_VISIBLE)
230  delete(this);
231 }
232 
233 void RaptorCBShellfragToss(vector _org, vector _vel, vector _ang)
234 {
235  entity sfrag = new(RaptorCBShellfrag);
236  setmodel(sfrag, MDL_VEH_RAPTOR_CB_FRAGMENT);
237  setorigin(sfrag, _org);
238 
240  sfrag.gravity = 0.15;
241  sfrag.solid = SOLID_CORPSE;
242 
243  sfrag.draw = RaptorCBShellfragDraw;
244  IL_PUSH(g_drawables, sfrag);
245 
246  sfrag.velocity = _vel;
247  sfrag.avelocity = prandomvec() * vlen(sfrag.velocity);
248  sfrag.angles = _ang;
249 
250  sfrag.move_time = time;
251  sfrag.damageforcescale = 4;
252 
253  sfrag.nextthink = time + 3;
254  sfrag.cnt = time + 2;
255  sfrag.alpha = 1;
256  sfrag.drawmask = MASK_NORMAL;
257 }
258 
259 #endif
#define IL_EACH(this, cond, body)
const float ALPHA_MIN_VISIBLE
Definition: main.qh:128
float alpha
Definition: items.qc:14
vector w_shotorg
Definition: tracing.qh:18
#define PROJECTILE_MAKETRIGGER(e)
Definition: common.qh:29
bool SetResourceExplicit(entity e, Resource res_type, float amount)
Sets the resource amount of an entity without calling any hooks.
Definition: cl_resources.qc:15
const float EF_FLAME
Definition: csprogsdefs.qc:302
float MOVETYPE_TOSS
Definition: progsdefs.qc:252
const int PROJECTILE_RAPTORBOMBLET
Definition: projectiles.qh:26
entity() spawn
const float MOVE_NORMAL
Definition: csprogsdefs.qc:252
void w_ready(Weapon thiswep, entity actor,.entity weaponentity, int fire)
float tur_impacttime
Definition: sv_turrets.qh:33
vector w_shotdir
Definition: tracing.qh:19
origin
Definition: ent_cs.qc:114
#define gettaginfo
Definition: post.qh:32
vector avelocity
Definition: csprogsdefs.qc:105
float MOVETYPE_BOUNCE
Definition: progsdefs.qc:256
#define METHOD(cname, name, prototype)
Definition: oo.qh:257
void CSQCProjectile(entity e, float clientanimate, int type, float docull)
#define DMG_NOWEP
Definition: damage.qh:126
entity owner
Definition: main.qh:73
float renderflags
Definition: main.qh:95
#define gettagindex
Definition: dpextensions.qh:16
void TakeResource(entity receiver, Resource res_type, float amount)
Takes an entity some resource.
Definition: cl_resources.qc:31
#define PROJECTILE_TOUCH(e, t)
Definition: common.qh:27
#define setmodel(this, m)
Definition: model.qh:26
RES_HEALTH
Definition: ent_cs.qc:126
float cnt
Definition: powerups.qc:24
ERASEABLE entity IL_PUSH(IntrusiveList this, entity it)
Push to tail.
void UpdateCSQCProjectile(entity e)
void Movetype_Physics_MatchTicrate(entity this, float tr, bool sloppy)
Definition: movetypes.qc:869
bool weapon_prepareattack(Weapon thiswep, entity actor,.entity weaponentity, bool secondary, float attacktime)
#define NULL
Definition: post.qh:17
const float MASK_NORMAL
Definition: csprogsdefs.qc:164
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
IntrusiveList g_projectiles
Definition: common.qh:46
const int PROJECTILE_RAPTORBOMB
Definition: projectiles.qh:25
float GetResource(entity e, Resource res_type)
Returns the current amount of resource the given entity has.
Definition: cl_resources.qc:10
vector prandomvec()
Definition: random.qc:113
#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)
float RadiusDamage(entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity cantbe, entity mustbe, float forceintensity, int deathtype,.entity weaponentity, entity directhitentity)
Definition: damage.qc:1057
entity realowner
Definition: common.qh:25
const float SOLID_BBOX
Definition: csprogsdefs.qc:246
void Damage_DamageInfo(vector org, float coredamage, float edgedamage, float rad, vector force, int deathtype, float bloodtype, entity dmgowner)
setorigin(ent, v)
#define setthink(e, f)
entity vehicles_projectile(entity this, entity _mzlfx, Sound _mzlsound, vector _org, vector _vel, float _dmg, float _radi, float _force, float _size, int _deahtype, float _projtype, float _health, bool _cull, bool _clianim, entity _owner)
Definition: sv_vehicles.qc:223
const int PROJECTILE_RAPTORCANNON
Definition: projectiles.qh:24
float time
Definition: csprogsdefs.qc:16
vector velocity
Definition: csprogsdefs.qc:103
const int CH_WEAPON_B
Definition: sound.qh:8
int dir
Definition: impulse.qc:89
float trace_fraction
Definition: csprogsdefs.qc:36
IntrusiveList g_drawables
Definition: main.qh:77
void set_movetype(entity this, int mt)
#define IS_PLAYER(v)
Definition: utils.qh:9
float EF_LOWPRECISION
vector v_forward
Definition: csprogsdefs.qc:31
const float SOLID_CORPSE
Definition: csprogsdefs.qc:249
float DAMAGE_YES
Definition: progsdefs.qc:283