Xonotic
hurt.qc
Go to the documentation of this file.
1 #include "hurt.qh"
2 #ifdef SVQC
3 void trigger_hurt_use(entity this, entity actor, entity trigger)
4 {
5  if(IS_PLAYER(actor))
6  this.enemy = actor;
7  else
8  this.enemy = NULL; // let's just destroy it, if taking over is too much work
9 }
10 
11 .float triggerhurttime;
12 void trigger_hurt_touch(entity this, entity toucher)
13 {
14  if (!toucher.takedamage)
15  return;
16  if (this.active != ACTIVE_ACTIVE)
17  return;
18 
19  if(this.team)
20  if(((this.spawnflags & INVERT_TEAMS) == 0) == (this.team != toucher.team))
21  return;
22 
23  // only do the EXACTTRIGGER_TOUCH checks when really needed (saves some cpu)
24  if (toucher.iscreature)
25  {
26  if (time >= toucher.triggerhurttime + ((q3compat && !(this.spawnflags & HURT_SLOW)) ? autocvar_sys_ticrate : 1))
27  {
28  EXACTTRIGGER_TOUCH(this, toucher);
29  toucher.triggerhurttime = time;
30 
31  entity own;
32  own = this.enemy;
33  if (!IS_PLAYER(own))
34  {
35  own = this;
36  this.enemy = NULL; // I still hate you all
37  }
38 
39  Damage (toucher, this, own, this.dmg, DEATH_HURTTRIGGER.m_id, DMG_NOWEP, toucher.origin, '0 0 0');
40  }
41  }
42  else if(toucher.damagedbytriggers)
43  {
44  EXACTTRIGGER_TOUCH(this, toucher);
45  Damage(toucher, this, this, this.dmg, DEATH_HURTTRIGGER.m_id, DMG_NOWEP, toucher.origin, '0 0 0');
46  }
47 }
48 
49 /*QUAKED spawnfunc_trigger_hurt (.5 .5 .5) ?
50 Any object touching this will be hurt
51 set dmg to damage amount
52 default dmg = 10000
53 */
54 .entity trigger_hurt_next;
55 entity trigger_hurt_last;
56 entity trigger_hurt_first;
57 spawnfunc(trigger_hurt)
58 {
60  this.active = ACTIVE_ACTIVE;
61  settouch(this, trigger_hurt_touch);
62  this.use = trigger_hurt_use;
63  this.enemy = world; // I hate you all
64  if (!this.dmg)
65  this.dmg = ((q3compat) ? 5 : 10000);
66  if (this.message == "")
67  this.message = "was in the wrong place";
68  if (this.message2 == "")
69  this.message2 = "was thrown into a world of hurt by";
70  // this.message = "someone like %s always gets wrongplaced";
71 
72  if(!trigger_hurt_first)
73  trigger_hurt_first = this;
74  if(trigger_hurt_last)
75  trigger_hurt_last.trigger_hurt_next = this;
76  trigger_hurt_last = this;
77 }
78 
79 bool tracebox_hits_trigger_hurt(vector start, vector e_min, vector e_max, vector end)
80 {
81  entity th;
82 
83  for(th = trigger_hurt_first; th; th = th.trigger_hurt_next)
84  if(tracebox_hits_box(start, e_min, e_max, end, th.absmin, th.absmax))
85  return true;
86 
87  return false;
88 }
89 #endif
entity world
Definition: csprogsdefs.qc:15
const int INVERT_TEAMS
Definition: defs.qh:10
#define EXACTTRIGGER_INIT
Definition: common.qh:117
int team
Definition: main.qh:157
#define EXACTTRIGGER_TOUCH(e, t)
Definition: common.qh:116
entity() spawn
float autocvar_sys_ticrate
Definition: main.qh:17
float dmg
Definition: platforms.qh:6
spawnfunc(info_player_attacker)
Definition: sv_assault.qc:283
float spawnflags
Definition: progsdefs.qc:191
#define DMG_NOWEP
Definition: damage.qh:126
int q3compat
Definition: quake3.qh:3
entity enemy
Definition: sv_ctf.qh:143
const int ACTIVE_ACTIVE
Definition: defs.qh:37
string message
Definition: powerups.qc:19
#define NULL
Definition: post.qh:17
void Damage(entity targ, entity inflictor, entity attacker, float damage, int deathtype,.entity weaponentity, vector hitloc, vector force)
Definition: damage.qc:583
vector(float skel, float bonenum) _skel_get_boneabs_hidden
int active
Definition: defs.qh:34
#define use
Definition: csprogsdefs.qh:50
float time
Definition: csprogsdefs.qc:16
#define IS_PLAYER(v)
Definition: utils.qh:9