]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/triggers/trigger/hurt.qc
Merge branch 'master' into Mario/showspecs
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / trigger / hurt.qc
1 #ifdef SVQC
2 void trigger_hurt_use(entity this, entity actor, entity trigger)
3 {
4         if(IS_PLAYER(actor))
5                 this.enemy = actor;
6         else
7                 this.enemy = NULL; // let's just destroy it, if taking over is too much work
8 }
9
10 .float triggerhurttime;
11 void trigger_hurt_touch(entity this, entity toucher)
12 {
13         if (this.active != ACTIVE_ACTIVE)
14                 return;
15
16         if(this.team)
17                 if(((this.spawnflags & 4) == 0) == (this.team != toucher.team))
18                         return;
19
20         // only do the EXACTTRIGGER_TOUCH checks when really needed (saves some cpu)
21         if (toucher.iscreature)
22         {
23                 if (toucher.takedamage)
24                 if (toucher.triggerhurttime < time)
25                 {
26                         EXACTTRIGGER_TOUCH(this, toucher);
27                         toucher.triggerhurttime = time + 1;
28
29                         entity own;
30                         own = this.enemy;
31                         if (!IS_PLAYER(own))
32                         {
33                                 own = this;
34                                 this.enemy = NULL; // I still hate you all
35                         }
36
37                         Damage (toucher, this, own, this.dmg, DEATH_HURTTRIGGER.m_id, toucher.origin, '0 0 0');
38                 }
39         }
40         else if(toucher.damagedbytriggers)
41         {
42                 if(toucher.takedamage)
43                 {
44                         EXACTTRIGGER_TOUCH(this, toucher);
45                         Damage(toucher, this, this, this.dmg, DEATH_HURTTRIGGER.m_id, toucher.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 spawnfunc(trigger_hurt)
61 {
62         EXACTTRIGGER_INIT;
63         this.active = ACTIVE_ACTIVE;
64         settouch(this, trigger_hurt_touch);
65         this.use = trigger_hurt_use;
66         this.enemy = world; // I hate you all
67         if (!this.dmg)
68                 this.dmg = 1000;
69         if (this.message == "")
70                 this.message = "was in the wrong place";
71         if (this.message2 == "")
72                 this.message2 = "was thrown into a world of hurt by";
73         // this.message = "someone like %s always gets wrongplaced";
74
75         if(!trigger_hurt_first)
76                 trigger_hurt_first = this;
77         if(trigger_hurt_last)
78                 trigger_hurt_last.trigger_hurt_next = this;
79         trigger_hurt_last = this;
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