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