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