]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mapobjects/func/plat.qc
func_plat: don't spawn a "start moving" trigger when .targetname is set 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 (this.spawnflags & CRUSH)
62         {
63                 this.dmg = 10000;
64         }
65
66         if (this.dmg && (this.message == ""))
67         {
68                 this.message = "was squished";
69         }
70         if (this.dmg && (this.message2 == ""))
71         {
72                 this.message2 = "was squished by";
73         }
74
75         if (this.sounds == 1)
76         {
77                 this.noise = "plats/plat1.wav";
78                 this.noise1 = "plats/plat2.wav";
79         }
80
81         if (this.sounds == 2 || q3compat)
82         {
83                 // Plats in Q3 always have sounds (they're hard coded in Q3 engine)
84                 this.noise = "plats/medplat1.wav";
85                 this.noise1 = "plats/medplat2.wav";
86         }
87
88         // WARNING: backwards compatibility because people don't use already existing fields :(
89         if (this.sound1)
90                 this.noise = this.sound1;
91         if (this.sound2)
92                 this.noise1 = this.sound2;
93
94         if (q3compat)
95         {
96                 // CPMA adds these fields for overriding the engine sounds
97                 string s = GetField_fullspawndata(this, "sound_start", true);
98                 string e = GetField_fullspawndata(this, "sound_end", true);
99
100                 if (s)
101                         this.noise = strzone(s);
102                 if (e)
103                         this.noise1 = strzone(e);
104         }
105
106         if(this.noise && this.noise != "")
107         {
108                 precache_sound(this.noise);
109         }
110         if(this.noise1 && this.noise1 != "")
111         {
112                 precache_sound(this.noise1);
113         }
114
115         this.mangle = this.angles;
116         this.angles = '0 0 0';
117
118         this.classname = "plat";
119         this.draggable = drag_undraggable;
120         if (!InitMovingBrushTrigger(this))
121                 return;
122         this.effects |= EF_LOWPRECISION;
123         setsize (this, this.mins , this.maxs);
124
125         setblocked(this, plat_crush);
126
127         if (!this.speed) this.speed = 150;
128         if (!this.lip) this.lip = 16;
129         if (!this.height) this.height = this.size.z - this.lip;
130
131         this.pos1 = this.origin;
132         this.pos2 = this.origin;
133         this.pos2_z = this.origin.z - this.height;
134
135         this.reset = plat_reset;
136         this.reset(this);
137
138         InitializeEntity(this, plat_delayedinit, INITPRIO_FINDTARGET);
139 }
140 #elif defined(CSQC)
141 void plat_draw(entity this)
142 {
143         Movetype_Physics_NoMatchServer(this);
144         //Movetype_Physics_MatchServer(autocvar_cl_projectiles_sloppy);
145 }
146
147 NET_HANDLE(ENT_CLIENT_PLAT, bool isnew)
148 {
149         float sf = ReadByte();
150
151         if(sf & SF_TRIGGER_INIT)
152         {
153                 this.platmovetype_start = ReadByte();
154                 this.platmovetype_turn = ReadByte();
155                 this.platmovetype_end = ReadByte();
156                 this.spawnflags = ReadByte();
157
158                 this.model = strzone(ReadString());
159                 _setmodel(this, this.model);
160
161                 trigger_common_read(this, true);
162
163                 this.pos1 = ReadVector();
164                 this.pos2 = ReadVector();
165
166                 this.size = ReadVector();
167
168                 this.mangle = ReadAngleVector();
169
170                 this.speed = ReadShort();
171                 this.height = ReadShort();
172                 this.lip = ReadByte();
173                 this.state = ReadByte();
174
175                 this.dmg = ReadShort();
176
177                 this.classname = "plat";
178                 this.solid = SOLID_BSP;
179                 set_movetype(this, MOVETYPE_PUSH);
180                 this.drawmask = MASK_NORMAL;
181                 this.draw = plat_draw;
182                 if (isnew) IL_PUSH(g_drawables, this);
183                 this.use = plat_use;
184                 this.entremove = trigger_remove_generic;
185
186                 plat_reset(this); // also called here
187
188                 set_movetype(this, MOVETYPE_PUSH);
189                 this.move_time = time;
190
191                 if (!Q3COMPAT_COMMON || this.targetname == "")
192                         plat_spawn_inside_trigger(this);
193         }
194
195         if(sf & SF_TRIGGER_RESET)
196         {
197                 plat_reset(this);
198
199                 this.move_time = time;
200         }
201         return true;
202 }
203 #endif