]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/triggers/func/plat.qc
Remove magic numbers from platforms (func_plat)
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / 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.sounds == 0) this.sounds = 2;
62
63         if (this.spawnflags & PLAT_CRUSH)
64         {
65                 this.dmg = 10000;
66         }
67
68     if (this.dmg && (this.message == "")) this.message = "was squished";
69     if (this.dmg && (this.message2 == "")) this.message2 = "was squished by";
70
71         if (this.sounds == 1)
72         {
73                 this.noise = "plats/plat1.wav";
74                 this.noise1 = "plats/plat2.wav";
75         }
76
77         if (this.sounds == 2)
78         {
79                 this.noise = "plats/medplat1.wav";
80                 this.noise1 = "plats/medplat2.wav";
81         }
82
83         if (this.sound1)
84                 this.noise = this.sound1;
85         if (this.sound2)
86                 this.noise1 = this.sound2;
87
88         if(this.noise && this.noise != "") { precache_sound(this.noise); }
89         if(this.noise1 && this.noise1 != "") { precache_sound(this.noise1); }
90
91         this.mangle = this.angles;
92         this.angles = '0 0 0';
93
94         this.classname = "plat";
95         if (!InitMovingBrushTrigger(this))
96                 return;
97         this.effects |= EF_LOWPRECISION;
98         setsize (this, this.mins , this.maxs);
99
100         setblocked(this, plat_crush);
101
102         if (!this.speed) this.speed = 150;
103         if (!this.lip) this.lip = 16;
104         if (!this.height) this.height = this.size.z - this.lip;
105
106         this.pos1 = this.origin;
107         this.pos2 = this.origin;
108         this.pos2_z = this.origin.z - this.height;
109
110         this.reset = plat_reset;
111         this.reset(this);
112
113         InitializeEntity(this, plat_delayedinit, INITPRIO_FINDTARGET);
114 }
115 #elif defined(CSQC)
116 void plat_draw(entity this)
117 {
118         Movetype_Physics_NoMatchServer(this);
119         //Movetype_Physics_MatchServer(autocvar_cl_projectiles_sloppy);
120 }
121
122 NET_HANDLE(ENT_CLIENT_PLAT, bool isnew)
123 {
124         float sf = ReadByte();
125
126         if(sf & SF_TRIGGER_INIT)
127         {
128                 this.platmovetype_start = ReadByte();
129                 this.platmovetype_turn = ReadByte();
130                 this.platmovetype_end = ReadByte();
131                 this.spawnflags = ReadByte();
132
133                 this.model = strzone(ReadString());
134                 _setmodel(this, this.model);
135
136                 trigger_common_read(this, true);
137
138                 this.pos1 = ReadVector();
139                 this.pos2 = ReadVector();
140
141                 this.size = ReadVector();
142
143                 this.mangle_x = ReadAngle();
144                 this.mangle_y = ReadAngle();
145                 this.mangle_z = ReadAngle();
146
147                 this.speed = ReadShort();
148                 this.height = ReadShort();
149                 this.lip = ReadByte();
150                 this.state = ReadByte();
151
152                 this.dmg = ReadShort();
153
154                 this.classname = "plat";
155                 this.solid = SOLID_BSP;
156                 set_movetype(this, MOVETYPE_PUSH);
157                 this.drawmask = MASK_NORMAL;
158                 this.draw = plat_draw;
159                 if (isnew) IL_PUSH(g_drawables, this);
160                 this.use = plat_use;
161                 this.entremove = trigger_remove_generic;
162
163                 plat_reset(this); // also called here
164
165                 set_movetype(this, MOVETYPE_PUSH);
166                 this.move_time = time;
167
168                 plat_spawn_inside_trigger(this);
169         }
170
171         if(sf & SF_TRIGGER_RESET)
172         {
173                 plat_reset(this);
174
175                 this.move_time = time;
176         }
177         return true;
178 }
179 #endif