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