]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/triggers/func/conveyor.qc
Merge branch 'terencehill/quickmenu_file_example' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / func / conveyor.qc
1 REGISTER_NET_LINKED(ENT_CLIENT_CONVEYOR)
2
3 void conveyor_think()
4 {SELFPARAM();
5 #ifdef CSQC
6         // TODO: check if this is what is causing the glitchiness when switching between them
7         float dt = time - self.move_time;
8         self.move_time = time;
9         if(dt <= 0) { return; }
10 #endif
11         entity e;
12
13         // set myself as current conveyor where possible
14         for(e = world; (e = findentity(e, conveyor, self)); )
15                 e.conveyor = world;
16
17         if(self.state)
18         {
19                 for(e = findradius((self.absmin + self.absmax) * 0.5, vlen(self.absmax - self.absmin) * 0.5 + 1); e; e = e.chain)
20                         if(!e.conveyor.state)
21                                 if(isPushable(e))
22                                 {
23                                         vector emin = e.absmin;
24                                         vector emax = e.absmax;
25                                         if(self.solid == SOLID_BSP)
26                                         {
27                                                 emin -= '1 1 1';
28                                                 emax += '1 1 1';
29                                         }
30                                         if(boxesoverlap(emin, emax, self.absmin, self.absmax)) // quick
31                                                 if(WarpZoneLib_BoxTouchesBrush(emin, emax, self, e)) // accurate
32                                                         e.conveyor = self;
33                                 }
34
35                 for(e = world; (e = findentity(e, conveyor, self)); )
36                 {
37                         if(IS_CLIENT(e)) // doing it via velocity has quite some advantages
38                                 continue; // done in SV_PlayerPhysics   continue;
39
40                         setorigin(e, e.origin + self.movedir * PHYS_INPUT_FRAMETIME);
41                         move_out_of_solid(e);
42 #ifdef SVQC
43                         UpdateCSQCProjectile(e);
44 #endif
45                         /*
46                         // stupid conveyor code
47                         tracebox(e.origin, e.mins, e.maxs, e.origin + self.movedir * sys_frametime, MOVE_NORMAL, e);
48                         if(trace_fraction > 0)
49                                 setorigin(e, trace_endpos);
50                         */
51                 }
52         }
53
54 #ifdef SVQC
55         self.nextthink = time;
56 #endif
57 }
58
59 #ifdef SVQC
60
61 void conveyor_use()
62 {SELFPARAM();
63         self.state = !self.state;
64
65         self.SendFlags |= 2;
66 }
67
68 void conveyor_reset()
69 {SELFPARAM();
70         self.state = (self.spawnflags & 1);
71
72         self.SendFlags |= 2;
73 }
74
75 bool conveyor_send(entity this, entity to, int sf)
76 {
77         WriteHeader(MSG_ENTITY, ENT_CLIENT_CONVEYOR);
78         WriteByte(MSG_ENTITY, sf);
79
80         if(sf & 1)
81         {
82                 WriteByte(MSG_ENTITY, self.warpzone_isboxy);
83                 WriteCoord(MSG_ENTITY, self.origin_x);
84                 WriteCoord(MSG_ENTITY, self.origin_y);
85                 WriteCoord(MSG_ENTITY, self.origin_z);
86
87                 WriteCoord(MSG_ENTITY, self.mins_x);
88                 WriteCoord(MSG_ENTITY, self.mins_y);
89                 WriteCoord(MSG_ENTITY, self.mins_z);
90                 WriteCoord(MSG_ENTITY, self.maxs_x);
91                 WriteCoord(MSG_ENTITY, self.maxs_y);
92                 WriteCoord(MSG_ENTITY, self.maxs_z);
93
94                 WriteCoord(MSG_ENTITY, self.movedir_x);
95                 WriteCoord(MSG_ENTITY, self.movedir_y);
96                 WriteCoord(MSG_ENTITY, self.movedir_z);
97
98                 WriteByte(MSG_ENTITY, self.speed);
99                 WriteByte(MSG_ENTITY, self.state);
100
101                 WriteString(MSG_ENTITY, self.targetname);
102                 WriteString(MSG_ENTITY, self.target);
103         }
104
105         if(sf & 2)
106                 WriteByte(MSG_ENTITY, self.state);
107
108         return true;
109 }
110
111 void conveyor_init()
112 {SELFPARAM();
113         if (!self.speed)
114                 self.speed = 200;
115         self.movedir = self.movedir * self.speed;
116         self.think = conveyor_think;
117         self.nextthink = time;
118         IFTARGETED
119         {
120                 self.use = conveyor_use;
121                 self.reset = conveyor_reset;
122                 conveyor_reset();
123         }
124         else
125                 self.state = 1;
126
127         FixSize(self);
128
129         Net_LinkEntity(self, 0, false, conveyor_send);
130
131         self.SendFlags |= 1;
132 }
133
134 spawnfunc(trigger_conveyor)
135 {
136         SetMovedir(self);
137         EXACTTRIGGER_INIT;
138         conveyor_init();
139 }
140
141 spawnfunc(func_conveyor)
142 {
143         SetMovedir(self);
144         InitMovingBrushTrigger();
145         self.movetype = MOVETYPE_NONE;
146         conveyor_init();
147 }
148
149 #elif defined(CSQC)
150
151 void conveyor_draw(entity this) { WITH(entity, self, this, conveyor_think()); }
152
153 void conveyor_init()
154 {SELFPARAM();
155         self.draw = conveyor_draw;
156         self.drawmask = MASK_NORMAL;
157
158         self.movetype = MOVETYPE_NONE;
159         self.model = "";
160         self.solid = SOLID_TRIGGER;
161         self.move_origin = self.origin;
162         self.move_time = time;
163 }
164
165 NET_HANDLE(ENT_CLIENT_CONVEYOR, bool isnew)
166 {
167         float sf = ReadByte();
168
169         if(sf & 1)
170         {
171                 self.warpzone_isboxy = ReadByte();
172                 self.origin_x = ReadCoord();
173                 self.origin_y = ReadCoord();
174                 self.origin_z = ReadCoord();
175                 setorigin(self, self.origin);
176
177                 self.mins_x = ReadCoord();
178                 self.mins_y = ReadCoord();
179                 self.mins_z = ReadCoord();
180                 self.maxs_x = ReadCoord();
181                 self.maxs_y = ReadCoord();
182                 self.maxs_z = ReadCoord();
183                 setsize(self, self.mins, self.maxs);
184
185                 self.movedir_x = ReadCoord();
186                 self.movedir_y = ReadCoord();
187                 self.movedir_z = ReadCoord();
188
189                 self.speed = ReadByte();
190                 self.state = ReadByte();
191
192                 self.targetname = strzone(ReadString());
193                 self.target = strzone(ReadString());
194
195                 conveyor_init();
196         }
197
198         if(sf & 2)
199                 self.state = ReadByte();
200
201         return true;
202 }
203 #endif