]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mapobjects/trigger/heal.qc
Merge branch 'master' into terencehill/bot_ai
[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                         if (toucher.health < this.max_health)
22                         {
23                                 playthesound = true;
24                                 toucher.health = min(toucher.health + this.health, this.max_health);
25                                 toucher.pauserothealth_finished = max(toucher.pauserothealth_finished, time + autocvar_g_balance_pause_health_rot);
26                         }
27
28                         if(playthesound)
29                                 _sound (toucher, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM);
30                 }
31         }
32 }
33
34 void trigger_heal_use(entity this, entity actor, entity trigger)
35 {
36         trigger_heal_touch(this, actor);
37 }
38
39 void trigger_heal_init(entity this)
40 {
41         this.active = ACTIVE_ACTIVE;
42         if(!this.delay)
43                 this.delay = 1;
44         if(!this.health)
45                 this.health = 10;
46         if(!this.max_health)
47                 this.max_health = 200; // max health topoff for field
48         if(this.noise == "")
49                 this.noise = "misc/mediumhealth.wav";
50         precache_sound(this.noise);
51 }
52
53 spawnfunc(trigger_heal)
54 {
55         EXACTTRIGGER_INIT;
56         settouch(this, trigger_heal_touch);
57         trigger_heal_init(this);
58 }
59
60 spawnfunc(target_heal)
61 {
62         this.use = trigger_heal_use;
63         trigger_heal_init(this);
64 }
65 #endif