]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/triggers/trigger/teleport.qc
49e8cdb5549ddf462990a7230617062f77b408d1
[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 ()
15 {SELFPARAM();
16         if (self.active != ACTIVE_ACTIVE)
17                 return;
18
19 #ifdef SVQC
20         if (!other.teleportable)
21                 return;
22
23         if(other.vehicle)
24         if(!other.vehicle.teleportable)
25                 return;
26
27         if(IS_TURRET(other))
28                 return;
29 #elif defined(CSQC)
30         if(!IS_PLAYER(other))
31                 return;
32 #endif
33
34         if(IS_DEAD(other))
35                 return;
36
37         if(self.team)
38                 if(((self.spawnflags & 4) == 0) == (DIFF_TEAM(this, other)))
39                         return;
40
41         EXACTTRIGGER_TOUCH;
42
43 #ifdef SVQC
44         if(IS_PLAYER(other))
45                 RemoveGrapplingHook(other);
46 #endif
47
48         entity e;
49         e = Simple_TeleportPlayer(self, other);
50
51 #ifdef SVQC
52         string s = self.target; self.target = string_null;
53         SUB_UseTargets(self, other, other); // TODO: should we be using other for trigger too?
54         if (!self.target) self.target = s;
55
56         SUB_UseTargets(e, other, other);
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         self.angles = '0 0 0';
83
84         self.active = ACTIVE_ACTIVE;
85         //trigger_init(self); // only for predicted triggers?
86         EXACTTRIGGER_INIT;
87         self.use1 = trigger_teleport_use;
88
89         if(self.noise != "")
90                 FOREACH_WORD(self.noise, true, precache_sound(it));
91
92         // this must be called to spawn the teleport waypoints for bots
93         InitializeEntity(self, teleport_findtarget, INITPRIO_FINDTARGET);
94
95         if (self.target == "")
96         {
97                 objerror ("Teleporter with no target");
98                 return;
99         }
100
101         self.teleport_next = teleport_first;
102         teleport_first = self;
103 }
104 #elif defined(CSQC)
105 NET_HANDLE(ENT_CLIENT_TRIGGER_TELEPORT, bool isnew)
106 {
107         self.classname = "trigger_teleport";
108         int mytm = ReadByte(); if(mytm) { self.team = mytm - 1; }
109         self.spawnflags = ReadInt24_t();
110         self.active = ReadByte();
111         self.speed = ReadCoord();
112
113         trigger_common_read(true);
114
115         self.entremove = trigger_remove_generic;
116         self.solid = SOLID_TRIGGER;
117         //self.draw = trigger_draw_generic;
118         //self.move_touch = trigger_push_touch;
119         self.drawmask = MASK_NORMAL;
120         self.move_time = time;
121         defer(self, 0.25, teleport_findtarget);
122
123         self.teleport_next = teleport_first;
124         teleport_first = self;
125
126         return true;
127 }
128
129 #endif