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