]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/triggers/trigger/teleport.qc
Merge branch 'TimePath/modules'
[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                 RemoveGrapplingHook(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         this.teleport_next = teleport_first;
103         teleport_first = this;
104 }
105 #elif defined(CSQC)
106 NET_HANDLE(ENT_CLIENT_TRIGGER_TELEPORT, bool isnew)
107 {
108         this.classname = "trigger_teleport";
109         int mytm = ReadByte(); if(mytm) { this.team = mytm - 1; }
110         this.spawnflags = ReadInt24_t();
111         this.active = ReadByte();
112         this.speed = ReadCoord();
113
114         trigger_common_read(this, true);
115
116         this.entremove = trigger_remove_generic;
117         this.solid = SOLID_TRIGGER;
118         //settouch(this, trigger_push_touch);
119         this.move_time = time;
120         defer(this, 0.25, teleport_findtarget);
121
122         this.teleport_next = teleport_first;
123         teleport_first = this;
124
125         return true;
126 }
127
128 #endif