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