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