]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mapobjects/func/plat.qc
func_plat: Use Q3 defaults for .dmg .speed and .lip on Q3 maps
[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 engine 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                 if (e)
108                         this.noise1 = strzone(e);
109         }
110
111         if(this.noise && this.noise != "")
112         {
113                 precache_sound(this.noise);
114         }
115         if(this.noise1 && this.noise1 != "")
116         {
117                 precache_sound(this.noise1);
118         }
119
120         this.mangle = this.angles;
121         this.angles = '0 0 0';
122
123         this.classname = "plat";
124         this.draggable = drag_undraggable;
125         if (!InitMovingBrushTrigger(this))
126                 return;
127         this.effects |= EF_LOWPRECISION;
128         setsize (this, this.mins , this.maxs);
129
130         setblocked(this, plat_crush);
131
132         if (!this.speed) this.speed = q3compat ? 200 : 150;
133         if (!this.lip) this.lip = q3compat ? 8 : 16;
134         if (!this.height) this.height = this.size.z - this.lip;
135
136         this.pos1 = this.origin;
137         this.pos2 = this.origin;
138         this.pos2_z = this.origin.z - this.height;
139
140         this.reset = plat_reset;
141         this.reset(this);
142
143         InitializeEntity(this, plat_delayedinit, INITPRIO_FINDTARGET);
144 }
145 #elif defined(CSQC)
146 void plat_draw(entity this)
147 {
148         Movetype_Physics_NoMatchServer(this);
149         //Movetype_Physics_MatchServer(autocvar_cl_projectiles_sloppy);
150 }
151
152 NET_HANDLE(ENT_CLIENT_PLAT, bool isnew)
153 {
154         float sf = ReadByte();
155
156         if(sf & SF_TRIGGER_INIT)
157         {
158                 this.platmovetype_start = ReadByte();
159                 this.platmovetype_turn = ReadByte();
160                 this.platmovetype_end = ReadByte();
161                 this.spawnflags = ReadByte();
162
163                 this.model = strzone(ReadString());
164                 _setmodel(this, this.model);
165
166                 trigger_common_read(this, true);
167
168                 this.pos1 = ReadVector();
169                 this.pos2 = ReadVector();
170
171                 this.size = ReadVector();
172
173                 this.mangle = ReadAngleVector();
174
175                 this.speed = ReadShort();
176                 this.height = ReadShort();
177                 this.lip = ReadByte();
178                 this.state = ReadByte();
179
180                 this.dmg = ReadShort();
181
182                 this.classname = "plat";
183                 this.solid = SOLID_BSP;
184                 set_movetype(this, MOVETYPE_PUSH);
185                 this.drawmask = MASK_NORMAL;
186                 this.draw = plat_draw;
187                 if (isnew) IL_PUSH(g_drawables, this);
188                 this.use = plat_use;
189                 this.entremove = trigger_remove_generic;
190
191                 plat_reset(this); // also called here
192
193                 set_movetype(this, MOVETYPE_PUSH);
194                 this.move_time = time;
195
196                 if (!Q3COMPAT_COMMON || this.targetname == "")
197                         plat_spawn_inside_trigger(this);
198         }
199
200         if(sf & SF_TRIGGER_RESET)
201         {
202                 plat_reset(this);
203
204                 this.move_time = time;
205         }
206         return true;
207 }
208 #endif