]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/triggers/func/plat.qc
Ensure headers are always #included
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / 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                 WriteCoord(MSG_ENTITY, this.pos1_x);
30                 WriteCoord(MSG_ENTITY, this.pos1_y);
31                 WriteCoord(MSG_ENTITY, this.pos1_z);
32                 WriteCoord(MSG_ENTITY, this.pos2_x);
33                 WriteCoord(MSG_ENTITY, this.pos2_y);
34                 WriteCoord(MSG_ENTITY, this.pos2_z);
35
36                 WriteCoord(MSG_ENTITY, this.size_x);
37                 WriteCoord(MSG_ENTITY, this.size_y);
38                 WriteCoord(MSG_ENTITY, this.size_z);
39
40                 WriteAngle(MSG_ENTITY, this.mangle_x);
41                 WriteAngle(MSG_ENTITY, this.mangle_y);
42                 WriteAngle(MSG_ENTITY, this.mangle_z);
43
44                 WriteShort(MSG_ENTITY, this.speed);
45                 WriteShort(MSG_ENTITY, this.height);
46                 WriteByte(MSG_ENTITY, this.lip);
47                 WriteByte(MSG_ENTITY, this.state);
48
49                 WriteShort(MSG_ENTITY, this.dmg);
50         }
51
52         if(sf & SF_TRIGGER_RESET)
53         {
54                 // used on client
55         }
56
57         return true;
58 }
59
60 void plat_link(entity this)
61 {
62         //Net_LinkEntity(this, 0, false, plat_send);
63 }
64
65 spawnfunc(func_plat)
66 {
67         if (this.sounds == 0) this.sounds = 2;
68
69     if (this.spawnflags & 4) this.dmg = 10000;
70
71     if (this.dmg && (this.message == "")) this.message = "was squished";
72     if (this.dmg && (this.message2 == "")) this.message2 = "was squished by";
73
74         if (this.sounds == 1)
75         {
76                 precache_sound ("plats/plat1.wav");
77                 precache_sound ("plats/plat2.wav");
78                 this.noise = "plats/plat1.wav";
79                 this.noise1 = "plats/plat2.wav";
80         }
81
82         if (this.sounds == 2)
83         {
84                 precache_sound ("plats/medplat1.wav");
85                 precache_sound ("plats/medplat2.wav");
86                 this.noise = "plats/medplat1.wav";
87                 this.noise1 = "plats/medplat2.wav";
88         }
89
90         if (this.sound1)
91         {
92                 precache_sound (this.sound1);
93                 this.noise = this.sound1;
94         }
95         if (this.sound2)
96         {
97                 precache_sound (this.sound2);
98                 this.noise1 = this.sound2;
99         }
100
101         this.mangle = this.angles;
102         this.angles = '0 0 0';
103
104         this.classname = "plat";
105         if (!InitMovingBrushTrigger(this))
106                 return;
107         this.effects |= EF_LOWPRECISION;
108         setsize (this, this.mins , this.maxs);
109
110         setblocked(this, plat_crush);
111
112         if (!this.speed) this.speed = 150;
113         if (!this.lip) this.lip = 16;
114         if (!this.height) this.height = this.size.z - this.lip;
115
116         this.pos1 = this.origin;
117         this.pos2 = this.origin;
118         this.pos2_z = this.origin.z - this.height;
119
120         this.reset = plat_reset;
121         this.reset(this);
122
123         InitializeEntity(this, plat_delayedinit, INITPRIO_FINDTARGET);
124 }
125 #elif defined(CSQC)
126 void plat_draw(entity this)
127 {
128         Movetype_Physics_NoMatchServer(this);
129         //Movetype_Physics_MatchServer(autocvar_cl_projectiles_sloppy);
130 }
131
132 NET_HANDLE(ENT_CLIENT_PLAT, bool isnew)
133 {
134         float sf = ReadByte();
135
136         if(sf & SF_TRIGGER_INIT)
137         {
138                 this.platmovetype_start = ReadByte();
139                 this.platmovetype_turn = ReadByte();
140                 this.platmovetype_end = ReadByte();
141                 this.spawnflags = ReadByte();
142
143                 this.model = strzone(ReadString());
144                 _setmodel(this, this.model);
145
146                 trigger_common_read(this, true);
147
148                 this.pos1_x = ReadCoord();
149                 this.pos1_y = ReadCoord();
150                 this.pos1_z = ReadCoord();
151                 this.pos2_x = ReadCoord();
152                 this.pos2_y = ReadCoord();
153                 this.pos2_z = ReadCoord();
154
155                 this.size_x = ReadCoord();
156                 this.size_y = ReadCoord();
157                 this.size_z = ReadCoord();
158
159                 this.mangle_x = ReadAngle();
160                 this.mangle_y = ReadAngle();
161                 this.mangle_z = ReadAngle();
162
163                 this.speed = ReadShort();
164                 this.height = ReadShort();
165                 this.lip = ReadByte();
166                 this.state = ReadByte();
167
168                 this.dmg = ReadShort();
169
170                 this.classname = "plat";
171                 this.solid = SOLID_BSP;
172                 set_movetype(this, MOVETYPE_PUSH);
173                 this.drawmask = MASK_NORMAL;
174                 this.draw = plat_draw;
175                 if (isnew) IL_PUSH(g_drawables, this);
176                 this.use = plat_use;
177                 this.entremove = trigger_remove_generic;
178
179                 plat_reset(this); // also called here
180
181                 set_movetype(this, MOVETYPE_PUSH);
182                 this.move_time = time;
183
184                 plat_spawn_inside_trigger(this);
185         }
186
187         if(sf & SF_TRIGGER_RESET)
188         {
189                 plat_reset(this);
190
191                 this.move_time = time;
192         }
193         return true;
194 }
195 #endif