]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/triggers/func/ladder.qc
Link ladders (landing on them is rough, unfixable currently)
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / func / ladder.qc
1 REGISTER_NET_LINKED(ENT_CLIENT_LADDER)
2
3 void func_ladder_touch()
4 {SELFPARAM();
5 #ifdef SVQC
6         if (!other.iscreature)
7                 return;
8         if(IS_VEHICLE(other))
9                 return;
10 #endif
11
12         EXACTTRIGGER_TOUCH;
13
14         other.ladder_time = time + 0.1;
15         other.ladder_entity = self;
16 }
17
18 #ifdef SVQC
19 bool func_ladder_send(entity to, int sf)
20 {SELFPARAM();
21         WriteHeader(MSG_ENTITY, ENT_CLIENT_LADDER);
22
23         int f = 0;
24         if(self.warpzone_isboxy)
25                 BITSET_ASSIGN(f, 1);
26         if(self.origin != '0 0 0')
27                 BITSET_ASSIGN(f, 4);
28         WriteByte(MSG_ENTITY, f);
29
30         // we need THESE to render the warpzone (and cull properly)...
31         if(f & 4)
32         {
33                 WriteCoord(MSG_ENTITY, self.origin.x);
34                 WriteCoord(MSG_ENTITY, self.origin.y);
35                 WriteCoord(MSG_ENTITY, self.origin.z);
36         }
37
38         WriteShort(MSG_ENTITY, self.modelindex);
39         WriteCoord(MSG_ENTITY, self.mins.x);
40         WriteCoord(MSG_ENTITY, self.mins.y);
41         WriteCoord(MSG_ENTITY, self.mins.z);
42         WriteCoord(MSG_ENTITY, self.maxs.x);
43         WriteCoord(MSG_ENTITY, self.maxs.y);
44         WriteCoord(MSG_ENTITY, self.maxs.z);
45         WriteByte(MSG_ENTITY, bound(1, self.scale * 16, 255));
46
47         WriteString(MSG_ENTITY, self.classname);
48         WriteByte(MSG_ENTITY, self.skin);
49         WriteCoord(MSG_ENTITY, self.speed);
50
51         trigger_common_write(false);
52
53         return true;
54 }
55
56 void func_ladder_link()
57 {
58         self.SendEntity = func_ladder_send;
59         self.SendFlags = 0xFFFFFF;
60         //self.model = "null";
61 }
62
63 void func_ladder_init()
64 {
65         //self.mdl = self.model;
66         string m = self.model;
67         WarpZoneLib_ExactTrigger_Init();
68         if(m != "")
69         {
70                 precache_model(m);
71                 _setmodel(self, m); // no precision needed
72         }
73         setorigin(self, self.origin);
74         if(self.scale)
75                 setsize(self, self.mins * self.scale, self.maxs * self.scale);
76         else
77                 setsize(self, self.mins, self.maxs);
78         self.touch = func_ladder_touch;
79
80         func_ladder_link();
81 }
82
83 spawnfunc(func_ladder)
84 {
85         func_ladder_init();
86 }
87
88 spawnfunc(func_water)
89 {
90         func_ladder_init();
91 }
92
93 #elif defined(CSQC)
94 .float speed;
95
96 void func_ladder_remove()
97 {
98         if(self.classname) { strunzone(self.classname); }
99         self.classname = string_null;
100 }
101
102 NET_HANDLE(ENT_CLIENT_LADDER, bool isnew)
103 {
104         int f = ReadByte();
105         self.warpzone_isboxy = (f & 1);
106         if(f & 4)
107         {
108                 self.origin_x = ReadCoord();
109                 self.origin_y = ReadCoord();
110                 self.origin_z = ReadCoord();
111         }
112         else
113                 self.origin = '0 0 0';
114
115         self.modelindex = ReadShort();
116         self.mins_x = ReadCoord();
117         self.mins_y = ReadCoord();
118         self.mins_z = ReadCoord();
119         self.maxs_x = ReadCoord();
120         self.maxs_y = ReadCoord();
121         self.maxs_z = ReadCoord();
122         self.scale = ReadByte() / 16;
123         self.classname = strzone(ReadString());
124         self.skin = ReadByte();
125         self.speed = ReadCoord();
126
127         trigger_common_read(false);
128
129         self.solid = SOLID_TRIGGER;
130         self.move_touch = func_ladder_touch;
131         self.drawmask = MASK_NORMAL;
132         self.move_time = time;
133         self.entremove = func_ladder_remove;
134
135         return true;
136 }
137 #endif