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