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