Xonotic
plat.qc
Go to the documentation of this file.
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 || q3compat)
80  {
81  // Plats in Q3 always have sounds (they're hard coded in Q3 engine)
82  this.noise = "plats/medplat1.wav";
83  this.noise1 = "plats/medplat2.wav";
84  }
85 
86  // WARNING: backwards compatibility because people don't use already existing fields :(
87  if (this.sound1)
88  this.noise = this.sound1;
89  if (this.sound2)
90  this.noise1 = this.sound2;
91 
92  if (q3compat)
93  {
94  // CPMA adds these fields for overriding the engine sounds
95  string s = GetField_fullspawndata(this, "sound_start", true);
96  string e = GetField_fullspawndata(this, "sound_end", true);
97 
98  if (s)
99  this.noise = strzone(s);
100  if (e)
101  this.noise1 = strzone(e);
102  }
103 
104  if(this.noise && this.noise != "")
105  {
106  precache_sound(this.noise);
107  }
108  if(this.noise1 && this.noise1 != "")
109  {
110  precache_sound(this.noise1);
111  }
112 
113  this.mangle = this.angles;
114  this.angles = '0 0 0';
115 
116  this.classname = "plat";
117  this.draggable = drag_undraggable;
118  if (!InitMovingBrushTrigger(this))
119  return;
120  this.effects |= EF_LOWPRECISION;
121  setsize (this, this.mins , this.maxs);
122 
123  setblocked(this, plat_crush);
124 
125  if (!this.speed) this.speed = 150;
126  if (!this.lip) this.lip = 16;
127  if (!this.height) this.height = this.size.z - this.lip;
128 
129  this.pos1 = this.origin;
130  this.pos2 = this.origin;
131  this.pos2_z = this.origin.z - this.height;
132 
133  this.reset = plat_reset;
134  this.reset(this);
135 
136  InitializeEntity(this, plat_delayedinit, INITPRIO_FINDTARGET);
137 }
138 #elif defined(CSQC)
139 void plat_draw(entity this)
140 {
142  //Movetype_Physics_MatchServer(autocvar_cl_projectiles_sloppy);
143 }
144 
145 NET_HANDLE(ENT_CLIENT_PLAT, bool isnew)
146 {
147  float sf = ReadByte();
148 
149  if(sf & SF_TRIGGER_INIT)
150  {
151  this.platmovetype_start = ReadByte();
152  this.platmovetype_turn = ReadByte();
153  this.platmovetype_end = ReadByte();
154  this.spawnflags = ReadByte();
155 
156  this.model = strzone(ReadString());
157  _setmodel(this, this.model);
158 
159  trigger_common_read(this, true);
160 
161  this.pos1 = ReadVector();
162  this.pos2 = ReadVector();
163 
164  this.size = ReadVector();
165 
166  this.mangle = ReadAngleVector();
167 
168  this.speed = ReadShort();
169  this.height = ReadShort();
170  this.lip = ReadByte();
171  this.state = ReadByte();
172 
173  this.dmg = ReadShort();
174 
175  this.classname = "plat";
176  this.solid = SOLID_BSP;
178  this.drawmask = MASK_NORMAL;
179  this.draw = plat_draw;
180  if (isnew) IL_PUSH(g_drawables, this);
181  this.use = plat_use;
182  this.entremove = trigger_remove_generic;
183 
184  plat_reset(this); // also called here
185 
187  this.move_time = time;
188 
190  }
191 
192  if(sf & SF_TRIGGER_RESET)
193  {
194  plat_reset(this);
195 
196  this.move_time = time;
197  }
198  return true;
199 }
200 #endif
float state
Definition: subs.qh:32
string sound2
Definition: platforms.qc:178
void plat_reset(entity this)
Definition: platforms.qc:180
#define REGISTER_NET_LINKED(id)
Definition: net.qh:67
float speed
Definition: subs.qh:41
string GetField_fullspawndata(entity e, string f,...)
Definition: main.qc:400
const int SF_TRIGGER_INIT
Definition: defs.qh:22
string noise
Definition: progsdefs.qc:209
#define ReadString
float platmovetype_end
Definition: subs.qh:44
string sound1
Definition: platforms.qc:178
void plat_use(entity this, entity actor, entity trigger)
Definition: platforms.qc:168
entity() spawn
vector maxs
Definition: csprogsdefs.qc:113
#define NET_HANDLE(id, param)
Definition: net.qh:12
float dmg
Definition: platforms.qh:6
entity to
Definition: self.qh:96
spawnfunc(info_player_attacker)
Definition: sv_assault.qc:283
origin
Definition: ent_cs.qc:114
void Movetype_Physics_NoMatchServer(entity this)
Definition: movetypes.qc:839
string classname
Definition: csprogsdefs.qc:107
vector size
Definition: csprogsdefs.qc:114
float effects
Definition: csprogsdefs.qc:111
float spawnflags
Definition: progsdefs.qc:191
float platmovetype_turn
Definition: subs.qc:105
string model
Definition: csprogsdefs.qc:108
void plat_crush(entity this, entity blocker)
Definition: platforms.qc:138
int q3compat
Definition: quake3.qh:3
vector mins
Definition: csprogsdefs.qc:113
ERASEABLE entity IL_PUSH(IntrusiveList this, entity it)
Push to tail.
const int CRUSH
Definition: defs.qh:11
float height
Definition: jumppads.qh:12
float MOVETYPE_PUSH
Definition: progsdefs.qc:253
const int SF_TRIGGER_RESET
Definition: defs.qh:24
string noise1
Definition: progsdefs.qc:209
string message
Definition: powerups.qc:19
float platmovetype_start
Definition: subs.qh:44
const float MASK_NORMAL
Definition: csprogsdefs.qc:164
float drawmask
Definition: csprogsdefs.qc:95
const float SOLID_BSP
Definition: csprogsdefs.qc:248
void InitializeEntity(entity e, void(entity this) func, int order)
Definition: world.qc:2146
float move_time
Definition: movetypes.qh:77
float lip
Definition: subs.qh:40
void plat_spawn_inside_trigger(entity this)
Definition: platforms.qc:21
bool drag_undraggable(entity draggee, entity dragger)
Definition: cheats.qc:897
vector pos1
Definition: subs.qh:50
vector mangle
Definition: subs.qh:51
vector angles
Definition: csprogsdefs.qc:104
float sounds
Definition: subs.qh:42
#define use
Definition: csprogsdefs.qh:50
float time
Definition: csprogsdefs.qc:16
vector pos2
Definition: subs.qh:50
IntrusiveList g_drawables
Definition: main.qh:77
void set_movetype(entity this, int mt)
float EF_LOWPRECISION
float solid
Definition: csprogsdefs.qc:99