]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mapobjects/func/conveyor.qc
Transifex autosync
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mapobjects / 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 myself as current conveyor where possible
14         IL_EACH(g_conveyed, it.conveyor == this,
15         {
16                 it.conveyor = NULL;
17                 IL_REMOVE(g_conveyed, it);
18         });
19
20         if(this.active == ACTIVE_ACTIVE)
21         {
22                 FOREACH_ENTITY_RADIUS((this.absmin + this.absmax) * 0.5, vlen(this.absmax - this.absmin) * 0.5 + 1, it.conveyor.active == ACTIVE_NOT && isPushable(it),
23                 {
24                         if (WarpZoneLib_ExactTrigger_Touch(this, it, false))
25                         {
26                                 if(!it.conveyor)
27                                         IL_PUSH(g_conveyed, it);
28                                 it.conveyor = this;
29                         }
30                 });
31
32                 IL_EACH(g_conveyed, it.conveyor == this,
33                 {
34                         if(IS_CLIENT(it)) // doing it via velocity has quite some advantages
35                                 continue; // done in SV_PlayerPhysics   continue;
36
37                         setorigin(it, it.origin + this.movedir * PHYS_INPUT_FRAMETIME);
38                         move_out_of_solid(it);
39 #ifdef SVQC
40                         UpdateCSQCProjectile(it);
41 #endif
42                         /*
43                         // stupid conveyor code
44                         tracebox(it.origin, it.mins, it.maxs, it.origin + this.movedir * sys_frametime, MOVE_NORMAL, it);
45                         if(trace_fraction > 0)
46                                 setorigin(it, trace_endpos);
47                         */
48                 });
49         }
50
51 #ifdef SVQC
52         this.nextthink = time;
53 #endif
54 }
55
56 #ifdef SVQC
57
58 bool conveyor_send(entity this, entity to, int sendflags)
59 {
60         WriteHeader(MSG_ENTITY, ENT_CLIENT_CONVEYOR);
61         WriteByte(MSG_ENTITY, sendflags);
62
63         if(sendflags & SF_TRIGGER_INIT)
64         {
65                 WriteByte(MSG_ENTITY, this.warpzone_isboxy);
66                 WriteVector(MSG_ENTITY, this.origin);
67
68                 WriteVector(MSG_ENTITY, this.mins);
69                 WriteVector(MSG_ENTITY, this.maxs);
70
71                 WriteVector(MSG_ENTITY, this.movedir);
72
73                 WriteByte(MSG_ENTITY, this.speed);
74                 WriteByte(MSG_ENTITY, this.active);
75
76                 WriteString(MSG_ENTITY, this.targetname);
77                 WriteString(MSG_ENTITY, this.target);
78         }
79
80         if(sendflags & SF_TRIGGER_UPDATE)
81                 WriteByte(MSG_ENTITY, this.active);
82
83         return true;
84 }
85
86 void conveyor_init(entity this)
87 {
88         if (!this.speed) this.speed = 200;
89         this.movedir *= this.speed;
90         setthink(this, conveyor_think);
91         this.nextthink = time;
92         this.setactive = generic_netlinked_setactive;
93         if(this.targetname && this.targetname != "")
94         {
95                 // backwards compatibility
96                 this.use = generic_netlinked_legacy_use;
97         }
98         this.reset = generic_netlinked_reset;
99         this.reset(this);
100
101         Net_LinkEntity(this, 0, false, conveyor_send);
102
103         this.SendFlags |= SF_TRIGGER_INIT;
104 }
105
106 spawnfunc(trigger_conveyor)
107 {
108         SetMovedir(this);
109         EXACTTRIGGER_INIT;
110         conveyor_init(this);
111 }
112
113 spawnfunc(func_conveyor)
114 {
115         SetMovedir(this);
116         InitMovingBrushTrigger(this);
117         set_movetype(this, MOVETYPE_NONE);
118         conveyor_init(this);
119 }
120
121 #elif defined(CSQC)
122
123 void conveyor_draw(entity this) { conveyor_think(this); }
124
125 void conveyor_init(entity this, bool isnew)
126 {
127         if(isnew)
128                 IL_PUSH(g_drawables, this);
129         this.draw = conveyor_draw;
130         this.drawmask = MASK_NORMAL;
131
132         set_movetype(this, MOVETYPE_NONE);
133         this.model = "";
134         this.solid = SOLID_TRIGGER;
135         this.move_time = time;
136 }
137
138 NET_HANDLE(ENT_CLIENT_CONVEYOR, bool isnew)
139 {
140         int sendflags = ReadByte();
141
142         if(sendflags & SF_TRIGGER_INIT)
143         {
144                 this.warpzone_isboxy = ReadByte();
145                 this.origin = ReadVector();
146                 setorigin(this, this.origin);
147
148                 this.mins = ReadVector();
149                 this.maxs = ReadVector();
150                 setsize(this, this.mins, this.maxs);
151
152                 this.movedir = ReadVector();
153
154                 this.speed = ReadByte();
155                 this.active = ReadByte();
156
157                 this.targetname = strzone(ReadString());
158                 this.target = strzone(ReadString());
159
160                 conveyor_init(this, isnew);
161         }
162
163         if(sendflags & SF_TRIGGER_UPDATE)
164                 this.active = ReadByte();
165
166         return true;
167 }
168 #endif