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