]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/triggers/trigger/hurt.qc
Merge branch 'TimePath/global_self' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / trigger / hurt.qc
1 #ifdef SVQC
2 void trigger_hurt_use()
3 {SELFPARAM();
4         if(IS_PLAYER(activator))
5                 self.enemy = activator;
6         else
7                 self.enemy = world; // let's just destroy it, if taking over is too much work
8 }
9
10 .float triggerhurttime;
11 void trigger_hurt_touch()
12 {SELFPARAM();
13         if (self.active != ACTIVE_ACTIVE)
14                 return;
15
16         if(self.team)
17                 if(((self.spawnflags & 4) == 0) == (self.team != other.team))
18                         return;
19
20         // only do the EXACTTRIGGER_TOUCH checks when really needed (saves some cpu)
21         if (other.iscreature)
22         {
23                 if (other.takedamage)
24                 if (other.triggerhurttime < time)
25                 {
26                         EXACTTRIGGER_TOUCH;
27                         other.triggerhurttime = time + 1;
28
29                         entity own;
30                         own = self.enemy;
31                         if (!IS_PLAYER(own))
32                         {
33                                 own = self;
34                                 self.enemy = world; // I still hate you all
35                         }
36
37                         Damage (other, self, own, self.dmg, DEATH_HURTTRIGGER, other.origin, '0 0 0');
38                 }
39         }
40         else if(other.damagedbytriggers)
41         {
42                 if(other.takedamage)
43                 {
44                         EXACTTRIGGER_TOUCH;
45                         Damage(other, self, self, self.dmg, DEATH_HURTTRIGGER, other.origin, '0 0 0');
46                 }
47         }
48
49         return;
50 }
51
52 /*QUAKED spawnfunc_trigger_hurt (.5 .5 .5) ?
53 Any object touching this will be hurt
54 set dmg to damage amount
55 defalt dmg = 5
56 */
57 .entity trigger_hurt_next;
58 entity trigger_hurt_last;
59 entity trigger_hurt_first;
60 void spawnfunc_trigger_hurt()
61 {SELFPARAM();
62         EXACTTRIGGER_INIT;
63         self.active = ACTIVE_ACTIVE;
64         self.touch = trigger_hurt_touch;
65         self.use = trigger_hurt_use;
66         self.enemy = world; // I hate you all
67         if (!self.dmg)
68                 self.dmg = 1000;
69         if (self.message == "")
70                 self.message = "was in the wrong place";
71         if (self.message2 == "")
72                 self.message2 = "was thrown into a world of hurt by";
73         // self.message = "someone like %s always gets wrongplaced";
74
75         if(!trigger_hurt_first)
76                 trigger_hurt_first = self;
77         if(trigger_hurt_last)
78                 trigger_hurt_last.trigger_hurt_next = self;
79         trigger_hurt_last = self;
80 }
81
82 float tracebox_hits_trigger_hurt(vector start, vector mi, vector ma, vector end)
83 {
84         entity th;
85
86         for(th = trigger_hurt_first; th; th = th.trigger_hurt_next)
87                 if(tracebox_hits_box(start, mi, ma, end, th.absmin, th.absmax))
88                         return true;
89
90         return false;
91 }
92 #endif