]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mapobjects/func/plat.qc
func_door and func_plat fixes and Q3 compatibility
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mapobjects / func / plat.qc
1 #include "plat.qh"
2 REGISTER_NET_LINKED(ENT_CLIENT_PLAT)
3
4 #ifdef SVQC
5 void plat_link(entity this);
6
7 void plat_delayedinit(entity this)
8 {
9         plat_link(this);
10         // Q3 uses only a truth check of .targetname to decide whether to spawn a trigger
11         if(!Q3COMPAT_COMMON || this.targetname == "")
12                 plat_spawn_inside_trigger(this); // the "start moving" trigger
13 }
14
15 float plat_send(entity this, entity to, float sf)
16 {
17         WriteHeader(MSG_ENTITY, ENT_CLIENT_PLAT);
18         WriteByte(MSG_ENTITY, sf);
19
20         if(sf & SF_TRIGGER_INIT)
21         {
22                 WriteByte(MSG_ENTITY, this.platmovetype_start);
23                 WriteByte(MSG_ENTITY, this.platmovetype_turn);
24                 WriteByte(MSG_ENTITY, this.platmovetype_end);
25                 WriteByte(MSG_ENTITY, this.spawnflags);
26
27                 WriteString(MSG_ENTITY, this.model);
28
29                 trigger_common_write(this, true);
30
31                 WriteVector(MSG_ENTITY, this.pos1);
32                 WriteVector(MSG_ENTITY, this.pos2);
33
34                 WriteVector(MSG_ENTITY, this.size);
35
36                 WriteAngleVector(MSG_ENTITY, this.mangle);
37
38                 WriteShort(MSG_ENTITY, this.speed);
39                 WriteShort(MSG_ENTITY, this.height);
40                 WriteByte(MSG_ENTITY, this.lip);
41                 WriteByte(MSG_ENTITY, this.state);
42
43                 WriteShort(MSG_ENTITY, this.dmg);
44         }
45
46         if(sf & SF_TRIGGER_RESET)
47         {
48                 // used on client
49         }
50
51         return true;
52 }
53
54 void plat_link(entity this)
55 {
56         //Net_LinkEntity(this, 0, false, plat_send);
57 }
58
59 spawnfunc(func_plat)
60 {
61         if (q3compat)
62         {
63                 this.spawnflags = 0; // Q3 plats have no spawnflags
64                 if (!this.dmg) this.dmg = 2;
65         }
66         else if (this.spawnflags & CRUSH)
67         {
68                 this.dmg = 10000;
69         }
70
71         if (this.dmg && (this.message == ""))
72         {
73                 this.message = "was squished";
74         }
75         if (this.dmg && (this.message2 == ""))
76         {
77                 this.message2 = "was squished by";
78         }
79
80         if (this.sounds == 1)
81         {
82                 this.noise = "plats/plat1.wav";
83                 this.noise1 = "plats/plat2.wav";
84         }
85
86         if (this.sounds == 2 || q3compat)
87         {
88                 // Plats in Q3 always have sounds (they're hard coded in Q3 engine)
89                 this.noise = "plats/medplat1.wav";
90                 this.noise1 = "plats/medplat2.wav";
91         }
92
93         // WARNING: backwards compatibility because people don't use already existing fields :(
94         if (this.sound1)
95                 this.noise = this.sound1;
96         if (this.sound2)
97                 this.noise1 = this.sound2;
98
99         if (q3compat)
100         {
101                 // CPMA adds these fields for overriding the Q3 default sounds
102                 string s = GetField_fullspawndata(this, "sound_start", true);
103                 string e = GetField_fullspawndata(this, "sound_end", true);
104
105                 if (s)
106                         this.noise = strzone(s);
107                 else
108                 {
109                         // PK3s supporting Q3A sometimes include custom sounds at Q3 default paths
110                         s = "sound/movers/plats/pt1_strt.wav";
111                         if (FindFileInMapPack(s))
112                                 this.noise = s;
113                 }
114
115                 if (e)
116                         this.noise1 = strzone(e);
117                 else
118                 {
119                         e = "sound/movers/plats/pt1_end.wav";
120                         if (FindFileInMapPack(e))
121                                 this.noise1 = e;
122                 }
123         }
124
125         if(this.noise && this.noise != "")
126         {
127                 precache_sound(this.noise);
128         }
129         if(this.noise1 && this.noise1 != "")
130         {
131                 precache_sound(this.noise1);
132         }
133
134         this.mangle = this.angles;
135         this.angles = '0 0 0';
136
137         this.classname = "plat";
138         this.draggable = drag_undraggable;
139         if (!InitMovingBrushTrigger(this))
140                 return;
141         this.effects |= EF_LOWPRECISION;
142         setsize (this, this.mins , this.maxs);
143
144         setblocked(this, plat_crush);
145
146         if (!this.speed) this.speed = q3compat ? 200 : 150;
147         if (!this.lip) this.lip = q3compat ? 8 : 16;
148         if (!this.height) this.height = this.size.z - this.lip;
149
150         this.pos1 = this.origin;
151         this.pos2 = this.origin;
152         this.pos2_z = this.origin.z - this.height;
153
154         this.reset = plat_reset;
155         this.reset(this);
156
157         InitializeEntity(this, plat_delayedinit, INITPRIO_FINDTARGET);
158 }
159 #elif defined(CSQC)
160 void plat_draw(entity this)
161 {
162         Movetype_Physics_NoMatchServer(this);
163         //Movetype_Physics_MatchServer(autocvar_cl_projectiles_sloppy);
164 }
165
166 NET_HANDLE(ENT_CLIENT_PLAT, bool isnew)
167 {
168         float sf = ReadByte();
169
170         if(sf & SF_TRIGGER_INIT)
171         {
172                 this.platmovetype_start = ReadByte();
173                 this.platmovetype_turn = ReadByte();
174                 this.platmovetype_end = ReadByte();
175                 this.spawnflags = ReadByte();
176
177                 this.model = strzone(ReadString());
178                 _setmodel(this, this.model);
179
180                 trigger_common_read(this, true);
181
182                 this.pos1 = ReadVector();
183                 this.pos2 = ReadVector();
184
185                 this.size = ReadVector();
186
187                 this.mangle = ReadAngleVector();
188
189                 this.speed = ReadShort();
190                 this.height = ReadShort();
191                 this.lip = ReadByte();
192                 this.state = ReadByte();
193
194                 this.dmg = ReadShort();
195
196                 this.classname = "plat";
197                 this.solid = SOLID_BSP;
198                 set_movetype(this, MOVETYPE_PUSH);
199                 this.drawmask = MASK_NORMAL;
200                 this.draw = plat_draw;
201                 if (isnew) IL_PUSH(g_drawables, this);
202                 this.use = plat_use;
203                 this.entremove = trigger_remove_generic;
204
205                 plat_reset(this); // also called here
206
207                 set_movetype(this, MOVETYPE_PUSH);
208                 this.move_time = time;
209
210                 if(!Q3COMPAT_COMMON || this.targetname == "")
211                         plat_spawn_inside_trigger(this);
212         }
213
214         if(sf & SF_TRIGGER_RESET)
215         {
216                 plat_reset(this);
217
218                 this.move_time = time;
219         }
220         return true;
221 }
222 #endif