]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/triggers/func/plat.qc
36b4eeffffa1dd1af0d57f66b7207e2fde7c9802
[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                 this.noise = "plats/plat1.wav";
77                 this.noise1 = "plats/plat2.wav";
78         }
79
80         if (this.sounds == 2)
81         {
82                 this.noise = "plats/medplat1.wav";
83                 this.noise1 = "plats/medplat2.wav";
84         }
85
86         if (this.sound1)
87                 this.noise = this.sound1;
88         if (this.sound2)
89                 this.noise1 = this.sound2;
90
91         if(this.noise && this.noise != "") { precache_sound(this.noise); }
92         if(this.noise1 && this.noise1 != "") { precache_sound(this.noise1); }
93
94         this.mangle = this.angles;
95         this.angles = '0 0 0';
96
97         this.classname = "plat";
98         if (!InitMovingBrushTrigger(this))
99                 return;
100         this.effects |= EF_LOWPRECISION;
101         setsize (this, this.mins , this.maxs);
102
103         setblocked(this, plat_crush);
104
105         if (!this.speed) this.speed = 150;
106         if (!this.lip) this.lip = 16;
107         if (!this.height) this.height = this.size.z - this.lip;
108
109         this.pos1 = this.origin;
110         this.pos2 = this.origin;
111         this.pos2_z = this.origin.z - this.height;
112
113         this.reset = plat_reset;
114         this.reset(this);
115
116         InitializeEntity(this, plat_delayedinit, INITPRIO_FINDTARGET);
117 }
118 #elif defined(CSQC)
119 void plat_draw(entity this)
120 {
121         Movetype_Physics_NoMatchServer(this);
122         //Movetype_Physics_MatchServer(autocvar_cl_projectiles_sloppy);
123 }
124
125 NET_HANDLE(ENT_CLIENT_PLAT, bool isnew)
126 {
127         float sf = ReadByte();
128
129         if(sf & SF_TRIGGER_INIT)
130         {
131                 this.platmovetype_start = ReadByte();
132                 this.platmovetype_turn = ReadByte();
133                 this.platmovetype_end = ReadByte();
134                 this.spawnflags = ReadByte();
135
136                 this.model = strzone(ReadString());
137                 _setmodel(this, this.model);
138
139                 trigger_common_read(this, true);
140
141                 this.pos1_x = ReadCoord();
142                 this.pos1_y = ReadCoord();
143                 this.pos1_z = ReadCoord();
144                 this.pos2_x = ReadCoord();
145                 this.pos2_y = ReadCoord();
146                 this.pos2_z = ReadCoord();
147
148                 this.size_x = ReadCoord();
149                 this.size_y = ReadCoord();
150                 this.size_z = ReadCoord();
151
152                 this.mangle_x = ReadAngle();
153                 this.mangle_y = ReadAngle();
154                 this.mangle_z = ReadAngle();
155
156                 this.speed = ReadShort();
157                 this.height = ReadShort();
158                 this.lip = ReadByte();
159                 this.state = ReadByte();
160
161                 this.dmg = ReadShort();
162
163                 this.classname = "plat";
164                 this.solid = SOLID_BSP;
165                 set_movetype(this, MOVETYPE_PUSH);
166                 this.drawmask = MASK_NORMAL;
167                 this.draw = plat_draw;
168                 if (isnew) IL_PUSH(g_drawables, this);
169                 this.use = plat_use;
170                 this.entremove = trigger_remove_generic;
171
172                 plat_reset(this); // also called here
173
174                 set_movetype(this, MOVETYPE_PUSH);
175                 this.move_time = time;
176
177                 plat_spawn_inside_trigger(this);
178         }
179
180         if(sf & SF_TRIGGER_RESET)
181         {
182                 plat_reset(this);
183
184                 this.move_time = time;
185         }
186         return true;
187 }
188 #endif