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