Xonotic
heal.qc
Go to the documentation of this file.
1 #include "heal.qh"
2 #ifdef SVQC
3 .float triggerhealtime;
4 void trigger_heal_touch(entity this, entity toucher)
5 {
6  if (this.active != ACTIVE_ACTIVE)
7  return;
8 
9  // only do the EXACTTRIGGER_TOUCH checks when really needed (saves some cpu)
10  if (toucher.iscreature)
11  {
12  if (toucher.takedamage && !IS_DEAD(toucher) && toucher.triggerhealtime < time)
13  {
14  bool is_trigger = this.targetname == "";
15  if(is_trigger)
16  EXACTTRIGGER_TOUCH(this, toucher);
17  if(this.delay > 0)
18  toucher.triggerhealtime = time + this.delay;
19 
20  bool playthesound = (this.spawnflags & HEAL_SOUND_ALWAYS);
21  bool healed = Heal(toucher, this, this.health, this.max_health);
22 
23  if(playthesound || healed)
24  _sound (toucher, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM);
25  }
26  }
27 }
28 
29 void trigger_heal_use(entity this, entity actor, entity trigger)
30 {
31  trigger_heal_touch(this, actor);
32 }
33 
34 void trigger_heal_init(entity this)
35 {
36  this.active = ACTIVE_ACTIVE;
37  if(!this.delay)
38  this.delay = 1;
39  if(!this.health)
40  this.health = 10;
41  if(!this.max_health)
42  this.max_health = 200; // max health topoff for field
43  if(this.noise == "")
44  this.noise = "misc/mediumhealth.wav";
45  precache_sound(this.noise);
46 }
47 
48 spawnfunc(trigger_heal)
49 {
51  settouch(this, trigger_heal_touch);
52  trigger_heal_init(this);
53 }
54 
55 spawnfunc(target_heal)
56 {
57  this.use = trigger_heal_use;
58  trigger_heal_init(this);
59 }
60 #endif
#define EXACTTRIGGER_INIT
Definition: common.qh:117
string noise
Definition: progsdefs.qc:209
#define EXACTTRIGGER_TOUCH(e, t)
Definition: common.qh:116
entity() spawn
spawnfunc(info_player_attacker)
Definition: sv_assault.qc:283
float spawnflags
Definition: progsdefs.qc:191
const int CH_TRIGGER
Definition: sound.qh:12
const int HEAL_SOUND_ALWAYS
Definition: heal.qh:4
float delay
Definition: subs.qh:38
const int ACTIVE_ACTIVE
Definition: defs.qh:37
float max_health
const float VOL_BASE
Definition: sound.qh:36
bool Heal(entity targ, entity inflictor, float amount, float limit)
Definition: damage.qc:1063
#define IS_DEAD(s)
Definition: utils.qh:26
const float ATTEN_NORM
Definition: sound.qh:30
float health
Definition: progsdefs.qc:137
#define _sound(e, c, s, v, a)
Definition: sound.qh:50
string targetname
Definition: progsdefs.qc:194
int active
Definition: defs.qh:34
#define use
Definition: csprogsdefs.qh:50
float time
Definition: csprogsdefs.qc:16