]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mapobjects/func/plat.qc
Merge branch 'master' into terencehill/lms_updates
[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                 WriteAngleVector(MSG_ENTITY, this.mangle);
35
36                 WriteShort(MSG_ENTITY, this.speed);
37                 WriteShort(MSG_ENTITY, this.height);
38                 WriteByte(MSG_ENTITY, this.lip);
39                 WriteByte(MSG_ENTITY, this.state);
40
41                 WriteShort(MSG_ENTITY, this.dmg);
42         }
43
44         if(sf & SF_TRIGGER_RESET)
45         {
46                 // used on client
47         }
48
49         return true;
50 }
51
52 void plat_link(entity this)
53 {
54         //Net_LinkEntity(this, 0, false, plat_send);
55 }
56
57 spawnfunc(func_plat)
58 {
59         if (this.spawnflags & CRUSH)
60         {
61                 this.dmg = 10000;
62         }
63
64     if (this.dmg && (this.message == ""))
65         {
66                 this.message = "was squished";
67         }
68     if (this.dmg && (this.message2 == ""))
69         {
70                 this.message2 = "was squished by";
71         }
72
73         if (this.sounds == 1)
74         {
75                 this.noise = "plats/plat1.wav";
76                 this.noise1 = "plats/plat2.wav";
77         }
78
79         if (this.sounds == 2)
80         {
81                 this.noise = "plats/medplat1.wav";
82                 this.noise1 = "plats/medplat2.wav";
83         }
84
85         // WARNING: backwards compatibility because people don't use already existing fields :(
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 != "")
92         {
93                 precache_sound(this.noise);
94         }
95         if(this.noise1 && this.noise1 != "")
96         {
97                 precache_sound(this.noise1);
98         }
99
100         this.mangle = this.angles;
101         this.angles = '0 0 0';
102
103         this.classname = "plat";
104         this.draggable = drag_undraggable;
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 = ReadVector();
149                 this.pos2 = ReadVector();
150
151                 this.size = ReadVector();
152
153                 this.mangle = ReadAngleVector();
154
155                 this.speed = ReadShort();
156                 this.height = ReadShort();
157                 this.lip = ReadByte();
158                 this.state = ReadByte();
159
160                 this.dmg = ReadShort();
161
162                 this.classname = "plat";
163                 this.solid = SOLID_BSP;
164                 set_movetype(this, MOVETYPE_PUSH);
165                 this.drawmask = MASK_NORMAL;
166                 this.draw = plat_draw;
167                 if (isnew) IL_PUSH(g_drawables, this);
168                 this.use = plat_use;
169                 this.entremove = trigger_remove_generic;
170
171                 plat_reset(this); // also called here
172
173                 set_movetype(this, MOVETYPE_PUSH);
174                 this.move_time = time;
175
176                 plat_spawn_inside_trigger(this);
177         }
178
179         if(sf & SF_TRIGGER_RESET)
180         {
181                 plat_reset(this);
182
183                 this.move_time = time;
184         }
185         return true;
186 }
187 #endif