Cleanse the touch functions of the other evil
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / trigger / teleport.qc
1 REGISTER_NET_LINKED(ENT_CLIENT_TRIGGER_TELEPORT)
2
3 #ifdef SVQC
4 void trigger_teleport_use(entity this, entity actor, entity trigger)
5 {
6         if(teamplay)
7                 this.team = actor.team;
8 #ifdef SVQC
9         this.SendFlags |= SF_TRIGGER_UPDATE;
10 #endif
11 }
12 #endif
13
14 void Teleport_Touch(entity this, entity toucher)
15 {
16         if (this.active != ACTIVE_ACTIVE)
17                 return;
18
19 #ifdef SVQC
20         if (!toucher.teleportable)
21                 return;
22
23         if(toucher.vehicle)
24         if(!toucher.vehicle.teleportable)
25                 return;
26
27         if(IS_TURRET(toucher))
28                 return;
29 #elif defined(CSQC)
30         if(!IS_PLAYER(toucher))
31                 return;
32 #endif
33
34         if(IS_DEAD(toucher))
35                 return;
36
37         if(this.team)
38                 if(((this.spawnflags & 4) == 0) == (DIFF_TEAM(this, toucher)))
39                         return;
40
41         EXACTTRIGGER_TOUCH(this, toucher);
42
43 #ifdef SVQC
44         if(IS_PLAYER(toucher))
45                 RemoveGrapplingHook(toucher);
46 #endif
47
48         entity e;
49         e = Simple_TeleportPlayer(this, toucher);
50
51 #ifdef SVQC
52         string s = this.target; this.target = string_null;
53         SUB_UseTargets(this, toucher, toucher); // TODO: should we be using toucher for trigger too?
54         if (!this.target) this.target = s;
55
56         SUB_UseTargets(e, toucher, toucher);
57 #endif
58 }
59
60 #ifdef SVQC
61 float trigger_teleport_send(entity this, entity to, float sf)
62 {
63         WriteHeader(MSG_ENTITY, ENT_CLIENT_TRIGGER_TELEPORT);
64
65         WriteByte(MSG_ENTITY, this.team);
66         WriteInt24_t(MSG_ENTITY, this.spawnflags);
67         WriteByte(MSG_ENTITY, this.active);
68         WriteCoord(MSG_ENTITY, this.speed);
69
70         trigger_common_write(this, true);
71
72         return true;
73 }
74
75 void trigger_teleport_link(entity this)
76 {
77         //trigger_link(this, trigger_teleport_send);
78 }
79
80 spawnfunc(trigger_teleport)
81 {
82         this.angles = '0 0 0';
83
84         this.active = ACTIVE_ACTIVE;
85         //trigger_init(this); // only for predicted triggers?
86         EXACTTRIGGER_INIT;
87         this.use = trigger_teleport_use;
88
89         if(this.noise != "")
90                 FOREACH_WORD(this.noise, true, precache_sound(it));
91
92         // this must be called to spawn the teleport waypoints for bots
93         InitializeEntity(this, teleport_findtarget, INITPRIO_FINDTARGET);
94
95         if (this.target == "")
96         {
97                 objerror (this, "Teleporter with no target");
98                 return;
99         }
100
101         this.teleport_next = teleport_first;
102         teleport_first = this;
103 }
104 #elif defined(CSQC)
105 NET_HANDLE(ENT_CLIENT_TRIGGER_TELEPORT, bool isnew)
106 {
107         this.classname = "trigger_teleport";
108         int mytm = ReadByte(); if(mytm) { this.team = mytm - 1; }
109         this.spawnflags = ReadInt24_t();
110         this.active = ReadByte();
111         this.speed = ReadCoord();
112
113         trigger_common_read(this, true);
114
115         this.entremove = trigger_remove_generic;
116         this.solid = SOLID_TRIGGER;
117         //this.move_touch = trigger_push_touch;
118         this.move_time = time;
119         defer(this, 0.25, teleport_findtarget);
120
121         this.teleport_next = teleport_first;
122         teleport_first = this;
123
124         return true;
125 }
126
127 #endif