]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mapobjects/trigger/heal.qc
3f3e6c579bccbe612b48d4289f6c059b006a88f4
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mapobjects / trigger / heal.qc
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, GetResourceAmount(this, RESOURCE_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(!GetResourceAmount(this, RESOURCE_HEALTH))
40                 SetResourceAmount(this, RESOURCE_HEALTH, 10); // TODO: use a special field for this, it doesn't have actual health!
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 {
50         EXACTTRIGGER_INIT;
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