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