updated readme
[divverent/nexuiz.git] / navnodeedit / src / client.qc
1 void(string s) SV_ParseClientCommand =\r
2 {\r
3         local float f, f2, args;\r
4         local string c, s1;\r
5         local vector v;\r
6         local entity navcurrent, navother;\r
7 \r
8         f = -1;\r
9 \r
10         args = tokenize(s);\r
11         c = argv(0);\r
12         if (c == "say")\r
13         {\r
14                 c = argv(1);\r
15                 navcurrent = self.current_navnode;\r
16                 navother = self.other_navnode;\r
17                 if (c == "origin")\r
18                 {\r
19                         if (navcurrent)\r
20                         {\r
21                                 s1 = argv(2);\r
22                                 s1 = strcat(s1, " ");\r
23                                 s1 = strcat(s1, argv(3));\r
24                                 s1 = strcat(s1, " ");\r
25                                 s1 = strcat(s1, argv(4));\r
26                                 v = stov(s1);\r
27                                 setorigin(navcurrent, v);\r
28                         }\r
29                         else\r
30                                 sprint(self, "No selection\n");\r
31                 }\r
32                 else if (c == "resize")\r
33                 {\r
34                         if (!ResizeNavNode(navcurrent, self.axis, stof(argv(2))))\r
35                                 sprint(self, "No selection\n");\r
36                 }\r
37                 else if (c == "save")\r
38                 {\r
39                         LinkNavNodes();\r
40                         SaveNavNodes();\r
41                 }\r
42                 else if (c == "load")\r
43                         LoadNavNodes();\r
44                 else if (c == "teleport")\r
45                 {\r
46                         if (navcurrent)\r
47                         {\r
48                                 if (navcurrent.sflags & S_TELEPORT)\r
49                                         navcurrent.sflags = navcurrent.sflags - (navcurrent.sflags & S_TELEPORT);\r
50                                 else\r
51                                         navcurrent.sflags = navcurrent.sflags | S_TELEPORT;\r
52                         }\r
53                         else\r
54                                 sprint(self, "No selection\n");\r
55                 }\r
56                 else if (c == "door")\r
57                 {\r
58                         if (navcurrent)\r
59                         {\r
60                                 if (navcurrent.sflags & S_DOOR)\r
61                                         navcurrent.sflags = navcurrent.sflags - (navcurrent.sflags & S_DOOR);\r
62                                 else\r
63                                         navcurrent.sflags = navcurrent.sflags | S_DOOR;\r
64                         }\r
65                         else\r
66                                 sprint(self, "No selection\n");\r
67                 }\r
68                 else if (c == "touch")\r
69                 {\r
70                         if (navcurrent)\r
71                         {\r
72                                 if (navcurrent.sflags & S_TOUCH)\r
73                                         navcurrent.sflags = navcurrent.sflags - (navcurrent.sflags & S_TOUCH);\r
74                                 else\r
75                                         navcurrent.sflags = navcurrent.sflags | S_TOUCH;\r
76                         }\r
77                         else\r
78                                 sprint(self, "No selection\n");\r
79                 }\r
80                 else if (c == "nolink")\r
81                 {\r
82                         if (argv(2))\r
83                                 f = stof(argv(2));\r
84                         LFlagChange(navcurrent, f, LF_NOLINK);\r
85                 }\r
86                 else if (c == "nowalk")\r
87                 {\r
88                         if (argv(2))\r
89                                 f = stof(argv(2));\r
90                         LFlagChange(navcurrent, f, LF_NOWALK);\r
91                 }\r
92                 else if (c == "bad")\r
93                 {\r
94                         if (argv(2))\r
95                                 f = stof(argv(2));\r
96                         LFlagChange(navcurrent, f, LF_BAD);\r
97                 }\r
98                 else if (c == "bigdrop")\r
99                 {\r
100                         if (argv(2))\r
101                                 f = stof(argv(2));\r
102                         LFlagChange(navcurrent, f, LF_BIGDROP);\r
103                 }\r
104                 else if (c == "remote")\r
105                         RemoteLinkHandling(navcurrent, navother);\r
106                 else\r
107                         clientcommand(self, s);         \r
108         }\r
109         else\r
110                 clientcommand(self, s);\r
111 };\r
112 \r
113 void() FixFrames =\r
114 {\r
115         local entity e;\r
116 \r
117         if (self.other_navnode)\r
118                 self.other_navnode.colormod = '0 0 0';\r
119 \r
120         if (self.current_navnode)\r
121         {\r
122                 self.current_navnode.colormod = '0 0 0';\r
123                 self.current_navnode.scale = 1;\r
124                 e = self.current_navnode.plane_chain;\r
125                 if (e)\r
126                 {\r
127                         e.effects = EF_NODRAW;\r
128                         e = e.plane_next;\r
129                         while (e != self.current_navnode.plane_chain)\r
130                         {\r
131                                 e.effects = EF_NODRAW;\r
132                                 e = e.plane_next;\r
133                         }\r
134                 }\r
135                 if (self.current_navnode.link0)\r
136                 {\r
137                         self.current_navnode.link0.effects = 0;\r
138                         self.current_navnode.link0.frame = 20;\r
139                         if (self.current_navnode.link1)\r
140                         {\r
141                                 self.current_navnode.link1.effects = 0;\r
142                                 self.current_navnode.link1.frame = 20;\r
143                                 if (self.current_navnode.link2)\r
144                                 {\r
145                                         self.current_navnode.link2.effects = 0;\r
146                                         self.current_navnode.link2.frame = 20;\r
147                                         if (self.current_navnode.link3)\r
148                                         {\r
149                                                 self.current_navnode.link3.effects = 0;\r
150                                                 self.current_navnode.link3.frame = 20;\r
151                                                 if (self.current_navnode.link4)\r
152                                                 {\r
153                                                         self.current_navnode.link4.effects = 0;\r
154                                                         self.current_navnode.link4.frame = 20;\r
155                                                         if (self.current_navnode.link5)\r
156                                                         {\r
157                                                                 self.current_navnode.link5.effects = 0;\r
158                                                                 self.current_navnode.link5.frame = 20;\r
159                                                                 if (self.current_navnode.link6)\r
160                                                                 {\r
161                                                                         self.current_navnode.link6.effects = 0;\r
162                                                                         self.current_navnode.link6.frame = 20;\r
163                                                                         if (self.current_navnode.link7)\r
164                                                                         {\r
165                                                                                 self.current_navnode.link7.effects = 0;\r
166                                                                                 self.current_navnode.link7.frame = 20;\r
167                                                                                 if (self.current_navnode.link8)\r
168                                                                                 {\r
169                                                                                         self.current_navnode.link8.effects = 0;\r
170                                                                                         self.current_navnode.link8.frame = 20;\r
171                                                                                         if (self.current_navnode.link9)\r
172                                                                                         {\r
173                                                                                                 self.current_navnode.link9.effects = 0;\r
174                                                                                                 self.current_navnode.link9.frame = 20;\r
175                                                                                                 if (self.current_navnode.link10)\r
176                                                                                                 {\r
177                                                                                                         self.current_navnode.link10.effects = 0;\r
178                                                                                                         self.current_navnode.link10.frame = 20;\r
179                                                                                                         if (self.current_navnode.link11)\r
180                                                                                                         {\r
181                                                                                                                 self.current_navnode.link11.effects = 0;\r
182                                                                                                                 self.current_navnode.link11.frame = 20;\r
183                                                                                                                 if (self.current_navnode.link12)\r
184                                                                                                                 {\r
185                                                                                                                         self.current_navnode.link12.effects = 0;\r
186                                                                                                                         self.current_navnode.link12.frame = 20;\r
187                                                                                                                         if (self.current_navnode.link13)\r
188                                                                                                                         {\r
189                                                                                                                                 self.current_navnode.link13.effects = 0;\r
190                                                                                                                                 self.current_navnode.link13.frame = 20;\r
191                                                                                                                                 if (self.current_navnode.link14)\r
192                                                                                                                                 {\r
193                                                                                                                                         self.current_navnode.link14.effects = 0;\r
194                                                                                                                                         self.current_navnode.link14.frame = 20;\r
195                                                                                                                                         if (self.current_navnode.link15)\r
196                                                                                                                                         {\r
197                                                                                                                                                 self.current_navnode.link15.effects = 0;\r
198                                                                                                                                                 self.current_navnode.link15.frame = 20;\r
199                                                                                                                                                 if (self.current_navnode.link16)\r
200                                                                                                                                                 {\r
201                                                                                                                                                         self.current_navnode.link16.effects = 0;\r
202                                                                                                                                                         self.current_navnode.link16.frame = 20;\r
203                                                                                                                                                         if (self.current_navnode.link17)\r
204                                                                                                                                                         {\r
205                                                                                                                                                                 self.current_navnode.link17.effects = 0;\r
206                                                                                                                                                                 self.current_navnode.link17.frame = 20;\r
207                                                                                                                                                                 if (self.current_navnode.link18)\r
208                                                                                                                                                                 {\r
209                                                                                                                                                                         self.current_navnode.link18.effects = 0;\r
210                                                                                                                                                                         self.current_navnode.link18.frame = 20;\r
211                                                                                                                                                                         if (self.current_navnode.link19)\r
212                                                                                                                                                                         {\r
213                                                                                                                                                                                 self.current_navnode.link19.effects = 0;\r
214                                                                                                                                                                                 self.current_navnode.link19.frame = 20;\r
215                                                                                                                                                                         }\r
216                                                                                                                                                                 }\r
217                                                                                                                                                         }\r
218                                                                                                                                                 }\r
219                                                                                                                                         }\r
220                                                                                                                                 }\r
221                                                                                                                         }\r
222                                                                                                                 }\r
223                                                                                                         }\r
224                                                                                                 }\r
225                                                                                         }\r
226                                                                                 }\r
227                                                                         }\r
228                                                                 }\r
229                                                         }\r
230                                                 }\r
231                                         }\r
232                                 }\r
233                         }\r
234                 }\r
235         }\r
236 };\r
237 \r
238 void() SwitchNavNode =\r
239 {\r
240         FixFrames();\r
241         self.current_navnode = FindCurrentNavNode(self.current_navnode, self.origin, self.selmode);\r
242         if (!self.current_navnode)\r
243                 self.current_navnode = FindCurrentNavNode(world, self.origin, self.selmode);\r
244 };\r
245 \r
246 void(float match) SwitchAxis =\r
247 {\r
248         if (match == -1)\r
249         {\r
250                 self.axis = self.axis + 1;\r
251                 if (self.axis > 2)\r
252                         self.axis = 0;\r
253         }\r
254         else if (match == 0)\r
255                 self.axis = 0;\r
256         else if (match == 1)\r
257                 self.axis = 1;\r
258         else if (match == 2)\r
259                 self.axis = 2;\r
260 };\r
261 \r
262 void(float i) ImpulseCommands =\r
263 {\r
264         local float f;\r
265         local vector v;\r
266         local entity e;\r
267 \r
268         if (self.confirm && i >= 1 && i <= 9)\r
269         {\r
270                 Select(i);\r
271                 return;\r
272         }\r
273         else if (i == 101)\r
274         {\r
275                 if (self.button3 & !self.button4)\r
276                 {\r
277                         if (self.axis == 0)\r
278                                 f = self.current_navnode.origin_x + self.current_navnode.maxs_x;\r
279                         else if (self.axis == 1)\r
280                                 f = self.current_navnode.origin_y + self.current_navnode.maxs_y;\r
281                         else if (self.axis == 2)\r
282                                 f = self.current_navnode.origin_z + self.current_navnode.maxs_z;\r
283                         f = f + self.gridsize;\r
284                         ResizeNavNode(self.current_navnode, self.axis, f);\r
285                 }\r
286                 else if (self.button4 & !self.button3)\r
287                 {\r
288                         if (self.current_clippoint)\r
289                         {\r
290                                 e = self.current_clippoint;\r
291                                 v = self.current_clippoint.origin;\r
292                         }\r
293                         else\r
294                         {\r
295                                 e = self.current_navnode;\r
296                                 v = self.current_navnode.origin;\r
297                         }\r
298                         if (self.axis == 0)\r
299                                 v_x = v_x + self.gridsize;\r
300                         else if (self.axis == 1)\r
301                                 v_y = v_y + self.gridsize;\r
302                         else if (self.axis == 2)\r
303                                 v_z = v_z + self.gridsize;\r
304                         MoveNavNode(e, v);\r
305                 }\r
306                 else if (self.button3 & self.button4)\r
307                 {\r
308                         if (self.current_clippoint)\r
309                         {\r
310                                 if (self.current_clippoint == self.clippoint1)\r
311                                 {\r
312                                         if (self.clippoint2)\r
313                                                 self.current_clippoint = self.clippoint2;\r
314                                         else\r
315                                                 self.current_clippoint = self.clippoint1;\r
316                                 }\r
317                                 else if (self.current_clippoint == self.clippoint2)\r
318                                 {\r
319                                         if (self.clippoint3)\r
320                                                 self.current_clippoint = self.clippoint3;\r
321                                         else\r
322                                                 self.current_clippoint = self.clippoint1;\r
323                                 }\r
324                                 else if (self.current_clippoint == self.clippoint3)\r
325                                         self.current_clippoint = self.clippoint1;\r
326                         }\r
327                         else\r
328                                 self.current_plane = self.current_plane.plane_next;\r
329                 }\r
330                 else\r
331                         self.gridsize = self.gridsize * 2;\r
332         }\r
333         else if (i == 102)\r
334         {\r
335                 if (self.button3 & !self.button4)\r
336                 {\r
337                         if (self.axis == 0)\r
338                                 f = self.current_navnode.origin_x + self.current_navnode.maxs_x;\r
339                         else if (self.axis == 1)\r
340                                 f = self.current_navnode.origin_y + self.current_navnode.maxs_y;\r
341                         else if (self.axis == 2)\r
342                                 f = self.current_navnode.origin_z + self.current_navnode.maxs_z;\r
343                         f = f - self.gridsize;\r
344                         ResizeNavNode(self.current_navnode, self.axis, f);\r
345                 }\r
346                 else if (self.button4 & !self.button3)\r
347                 {\r
348                         if (self.current_clippoint)\r
349                         {\r
350                                 e = self.current_clippoint;\r
351                                 v = self.current_clippoint.origin;\r
352                         }\r
353                         else\r
354                         {\r
355                                 e = self.current_navnode;\r
356                                 v = self.current_navnode.origin;\r
357                         }\r
358                         if (self.axis == 0)\r
359                                 v_x = v_x - self.gridsize;\r
360                         else if (self.axis == 1)\r
361                                 v_y = v_y - self.gridsize;\r
362                         else if (self.axis == 2)\r
363                                 v_z = v_z - self.gridsize;\r
364                         MoveNavNode(e, v);\r
365                 }\r
366                 else if (self.button3 & self.button4)\r
367                 {\r
368                         if (self.current_clippoint)\r
369                         {\r
370                                 if (self.current_clippoint == self.clippoint1)\r
371                                 {\r
372                                         if (self.clippoint3)\r
373                                                 self.current_clippoint = self.clippoint3;\r
374                                         else if (self.clippoint2)\r
375                                                 self.current_clippoint = self.clippoint2;\r
376                                         else\r
377                                                 self.current_clippoint = self.clippoint1;\r
378                                 }\r
379                                 else if (self.current_clippoint == self.clippoint2)\r
380                                         self.current_clippoint = self.clippoint1;\r
381                                 else if (self.current_clippoint == self.clippoint3)\r
382                                         self.current_clippoint = self.clippoint2;\r
383                         }\r
384                         else\r
385                                 self.current_plane = self.current_plane.plane_prev;\r
386                 }\r
387                 else\r
388                 {\r
389                         self.gridsize = self.gridsize * 0.5;\r
390                         if (self.gridsize < 1)\r
391                                 self.gridsize = 1;\r
392                 }\r
393         }\r
394         else if (i == 110)      // Spawns new navnode\r
395         {\r
396                 if (!self.lockselection)\r
397                 {\r
398                         v = SnapToGrid(self.origin);\r
399                         e = SpawnNavNode(v, '-32 -32 -32', '32 32 32');\r
400                         LinkNavNodes();\r
401                         if (e)\r
402                         {\r
403                                 FixFrames();\r
404                                 self.current_navnode = e;\r
405                                 self.other_navnode = e;\r
406                                 self.lockselection = TRUE;\r
407                                 self.confirm = 0;\r
408                         }\r
409                 }\r
410         }\r
411         else if (i == 111)      // Deletes current navnode (FIXME: better solution? most think remote functions checking for variables in cases such as this is ugly)\r
412         {\r
413                 if (self.current_navnode)\r
414                 {\r
415                         self.confirm = C_DELETE_NAVNODE;\r
416                         self.lockselection = TRUE;\r
417                 }\r
418         }\r
419         else if (i == 112)      // Deletes current plane (FIXME: better solution? most think remote functions checking for variables in cases such as this is ugly)\r
420         {\r
421                 if (self.current_plane)\r
422                 {\r
423                         self.confirm = C_DELETE_PLANE;\r
424                         self.lockselection = TRUE;\r
425                 }\r
426         }\r
427         else if (i == 120)      // Switches navnode in case of overlap\r
428         {\r
429                 if (!self.lockselection)\r
430                 if (self.selmode == M_OVERLAP)\r
431                         SwitchNavNode();\r
432         }\r
433         else if (i == 121)      // Switches selection mode\r
434         {\r
435                 if (self.selmode == M_OVERLAP)\r
436                         self.selmode = M_CLOSEST;\r
437                 else if (self.selmode == M_CLOSEST)\r
438                         self.selmode = M_OVERLAP;\r
439         }\r
440         else if (i == 122)      // Cycles through axis\r
441                 SwitchAxis(-1);\r
442         else if (i == 123)      // Switches to X axis\r
443                 SwitchAxis(0);\r
444         else if (i == 124)      // Switches to Y axis\r
445                 SwitchAxis(1);\r
446         else if (i == 125)      // Switches to Z axis\r
447                 SwitchAxis(2);\r
448 };\r
449 \r
450 void() ClientKill = {};\r
451 \r
452 void() ClientConnect =\r
453 {\r
454         bprint (self.netname);\r
455         bprint (" has connected\n");\r
456 };\r
457 \r
458 void() ClientDisconnect =\r
459 {\r
460         bprint (self.netname);\r
461         bprint (" has disconnected\n");\r
462 };\r
463 \r
464 float BT_LIGHTNING = 0;\r
465 float BT_BEAM = 1;\r
466 \r
467 void(float beamtype, vector bmins, vector bmaxs) BeamBox =\r
468 {\r
469         local vector v1, v2;\r
470 \r
471         v1 = bmaxs;\r
472         v2 = bmaxs;\r
473         v2_x = bmins_x;\r
474         if (beamtype == BT_LIGHTNING)\r
475                 te_lightning1(world, v1, v2);\r
476         else\r
477                 te_beam(world, v1, v2);\r
478         v1 = bmaxs;\r
479         v2 = bmaxs;\r
480         v2_y = bmins_y;\r
481         if (beamtype == BT_LIGHTNING)\r
482                 te_lightning1(world, v1, v2);\r
483         else\r
484                 te_beam(world, v1, v2);\r
485         v1 = bmaxs;\r
486         v2 = bmaxs;\r
487         v2_z = bmins_z;\r
488         if (beamtype == BT_LIGHTNING)\r
489                 te_lightning1(world, v1, v2);\r
490         else\r
491                 te_beam(world, v1, v2);\r
492         v1 = bmins;\r
493         v2 = bmins;\r
494         v2_x = bmaxs_x;\r
495         if (beamtype == BT_LIGHTNING)\r
496                 te_lightning1(world, v1, v2);\r
497         else\r
498                 te_beam(world, v1, v2);\r
499         v1 = bmins;\r
500         v2 = bmins;\r
501         v2_y = bmaxs_y;\r
502         if (beamtype == BT_LIGHTNING)\r
503                 te_lightning1(world, v1, v2);\r
504         else\r
505                 te_beam(world, v1, v2);\r
506         v1 = bmins;\r
507         v2 = bmins;\r
508         v2_z = bmaxs_z;\r
509         if (beamtype == BT_LIGHTNING)\r
510                 te_lightning1(world, v1, v2);\r
511         else\r
512                 te_beam(world, v1, v2);\r
513         v1 = bmins;\r
514         v1_z = bmaxs_z;\r
515         v2 = bmins;\r
516         v2_x = bmaxs_x;\r
517         v2_z = bmaxs_z;\r
518         if (beamtype == BT_LIGHTNING)\r
519                 te_lightning1(world, v1, v2);\r
520         else\r
521                 te_beam(world, v1, v2);\r
522         v1 = bmins;\r
523         v1_z = bmaxs_z;\r
524         v2 = bmins;\r
525         v2_y = bmaxs_y;\r
526         v2_z = bmaxs_z;\r
527         if (beamtype == BT_LIGHTNING)\r
528                 te_lightning1(world, v1, v2);\r
529         else\r
530                 te_beam(world, v1, v2);\r
531         v1 = bmaxs;\r
532         v1_z = bmins_z;\r
533         v2 = bmaxs;\r
534         v2_x = bmins_x;\r
535         v2_z = bmins_z;\r
536         if (beamtype == BT_LIGHTNING)\r
537                 te_lightning1(world, v1, v2);\r
538         else\r
539                 te_beam(world, v1, v2);\r
540         v1 = bmaxs;\r
541         v1_z = bmins_z;\r
542         v2 = bmaxs;\r
543         v2_y = bmins_y;\r
544         v2_z = bmins_z;\r
545         if (beamtype == BT_LIGHTNING)\r
546                 te_lightning1(world, v1, v2);\r
547         else\r
548                 te_beam(world, v1, v2);\r
549         v1 = bmins;\r
550         v1_x = bmaxs_x;\r
551         v2 = bmaxs;\r
552         v2_y = bmins_y;\r
553         if (beamtype == BT_LIGHTNING)\r
554                 te_lightning1(world, v1, v2);\r
555         else\r
556                 te_beam(world, v1, v2);\r
557         v1 = bmins;\r
558         v1_y = bmaxs_y;\r
559         v2 = bmaxs;\r
560         v2_x = bmins_x;\r
561         if (beamtype == BT_LIGHTNING)\r
562                 te_lightning1(world, v1, v2);\r
563         else\r
564                 te_beam(world, v1, v2);\r
565 };\r
566 \r
567 void() PlayerPreThink =\r
568 {\r
569         local float f;\r
570         local vector v, edge1, edge2, org, tvec, intonav; // FIXME\r
571         local string s;\r
572         local entity e, navcurrent, navother, delplane;\r
573 \r
574         if (self.selmode == M_OVERLAP)\r
575         {\r
576                 if (self.current_navnode)\r
577                 if (!self.lockselection)\r
578                 if (!boxesoverlap(self.origin, self.origin, self.current_navnode.origin + self.current_navnode.mins, self.current_navnode.origin + self.current_navnode.maxs))\r
579                 {\r
580                         FixFrames();\r
581                         self.other_navnode = world;\r
582                         self.current_navnode = world;\r
583                 }\r
584         }\r
585         else if (self.selmode == M_CLOSEST)\r
586         {\r
587                 if (self.current_navnode)\r
588                 if (!self.lockselection)\r
589                 {\r
590                         e = FindCurrentNavNode(world, self.origin, self.selmode);\r
591                         if (e != self.current_navnode)\r
592                         {\r
593                                 FixFrames();\r
594                                 self.other_navnode = world;\r
595                                 self.current_navnode = world;\r
596                         }\r
597                 }\r
598         }\r
599 \r
600         if (self.current_navnode)\r
601                 navcurrent = self.current_navnode;\r
602         else\r
603         {\r
604                 self.current_plane = world;\r
605                 navcurrent = self.current_navnode = FindCurrentNavNode(world, self.origin, self.selmode);\r
606         }\r
607 \r
608         navother = FindCurrentNavNode(world, self.origin, self.selmode);\r
609         if (self.other_navnode)\r
610         if (navother != self.other_navnode)\r
611         {\r
612                 if (self.other_navnode != self.current_navnode)\r
613                         self.other_navnode.colormod = '0 0 0';\r
614         }\r
615         self.other_navnode = navother;\r
616 \r
617         if (self.button0)\r
618         {\r
619                 if (!(self.buttonflag & B_FLAG0))\r
620                 {\r
621                         if (!self.button2)\r
622                         {\r
623                                 if (self.button3 & !self.button4)\r
624                                 {\r
625                                         makevectors(self.v_angle);\r
626                                         traceline(self.origin, self.origin + v_forward*8192, TRUE, world);\r
627                                         v = SnapToGrid(trace_endpos);\r
628                                         if (self.axis == 0)\r
629                                                 ResizeNavNode(navcurrent, self.axis, v_x);\r
630                                         else if (self.axis == 1)\r
631                                                 ResizeNavNode(navcurrent, self.axis, v_y);\r
632                                         else if (self.axis == 2)\r
633                                                 ResizeNavNode(navcurrent, self.axis, v_z);\r
634                                 }\r
635                                 else if (self.button4 & !self.button3)\r
636                                 {\r
637                                         makevectors(self.v_angle);\r
638                                         traceline(self.origin, self.origin + v_forward*8192, TRUE, world);\r
639                                         if (self.current_clippoint)\r
640                                                 e = self.current_clippoint;\r
641                                         else\r
642                                                 e = navcurrent;\r
643                                         v = SnapToGrid(trace_endpos);\r
644                                         MoveNavNode(e, v);\r
645                                 }\r
646                                 else if (self.button3 & self.button4)\r
647                                 {\r
648                                         if (self.clippoint3)\r
649                                         {\r
650                                                 edge1=self.clippoint1.origin-self.clippoint2.origin;\r
651                                                 edge2=self.clippoint3.origin-self.clippoint2.origin;\r
652                                                 v_x=edge1_y*edge2_z-edge1_z*edge2_y;\r
653                                                 v_y=edge1_z*edge2_x-edge1_x*edge2_z;\r
654                                                 v_z=edge1_x*edge2_y-edge1_y*edge2_x;\r
655                                                 v = normalize(v);\r
656                                                 org = (((self.clippoint1.origin + self.clippoint2.origin)*0.5) + self.clippoint3.origin)*0.5;\r
657                                                 RemoveClippoints();\r
658                                         }\r
659                                         else\r
660                                         {\r
661                                                 makevectors(self.v_angle);\r
662                                                 traceline(self.origin, self.origin + v_forward*8192, TRUE, world);\r
663                                                 v = trace_plane_normal;\r
664                                                 org = trace_endpos;\r
665                                         }\r
666                                         f = rint(v * (navcurrent.origin - org));\r
667                                         delplane = world;\r
668                                         e = navcurrent.plane_chain;\r
669                                         if (e)\r
670                                         {\r
671                                                 if (e.mangle == v*-1)\r
672                                                 if (e.delay == f)\r
673                                                         delplane = e;\r
674                                                 e = e.plane_next;\r
675                                                 while (e != navcurrent.plane_chain)\r
676                                                 {\r
677                                                         if (e.mangle == v*-1)\r
678                                                         if (e.delay == f)\r
679                                                                 delplane = e;\r
680                                                         e = e.plane_next;\r
681                                                 }\r
682                                         }\r
683                                         if (delplane)\r
684                                         {\r
685                                                 RemovePlane(navcurrent, delplane);\r
686                                                 self.current_plane = world;\r
687                                         }\r
688                                         else\r
689                                                 AddPlane(navcurrent, v, f);\r
690                                 }\r
691                         }\r
692                 }\r
693                 self.buttonflag = self.buttonflag | B_FLAG0;\r
694         }\r
695         else\r
696                 self.buttonflag = self.buttonflag - (self.buttonflag & B_FLAG0);\r
697 \r
698         if (self.button2)\r
699         {\r
700                 if (!(self.buttonflag & B_FLAG2))\r
701                 {\r
702                         if (!self.button0)\r
703                         {\r
704                                 if (self.button3 & !self.button4)\r
705                                 {\r
706                                         v = SnapToGrid(self.origin);\r
707                                         ResizeNavNode(navcurrent, 0, v_x);\r
708                                         ResizeNavNode(navcurrent, 1, v_y);\r
709                                         ResizeNavNode(navcurrent, 2, v_z);\r
710                                 }\r
711                                 else if (self.button4 & !self.button3)\r
712                                 {\r
713                                         if (self.current_clippoint)\r
714                                                 e = self.current_clippoint;\r
715                                         else\r
716                                                 e = navcurrent;\r
717                                         v = SnapToGrid(self.origin);\r
718                                         MoveNavNode(e, v);\r
719                                 }\r
720                                 else if (self.button3 & self.button4)\r
721                                 {\r
722                                         if (navcurrent)\r
723                                         if (self.lockselection)\r
724                                         {\r
725                                                 v = SnapToGrid(self.origin);\r
726                                                 SpawnClipPoint(v);\r
727                                         }\r
728                                 }\r
729                                 else if (!self.confirm)\r
730                                 {\r
731                                         if (self.lockselection)\r
732                                         {\r
733                                                 RemoveClippoints();\r
734                                                 self.lockselection = FALSE;\r
735                                         }\r
736                                         else\r
737                                                 self.lockselection = TRUE;\r
738                                 }\r
739                         }\r
740                 }\r
741                 self.buttonflag = self.buttonflag | B_FLAG2;\r
742         }\r
743         else\r
744                 self.buttonflag = self.buttonflag - (self.buttonflag & B_FLAG2);\r
745 \r
746         if (time >= self.ltntime + 0.15)\r
747         {\r
748                 self.ltntime = time;\r
749                 if (navcurrent)\r
750                 {\r
751                         navcurrent.scale = 0.2;\r
752                         if (!self.current_plane)\r
753                                 self.current_plane = navcurrent.plane_chain;\r
754                         if (self.lockselection)\r
755                         {\r
756                                 if (self.clippoint1)\r
757                                 {\r
758                                         if (!self.current_clippoint)\r
759                                                 self.current_clippoint = self.clippoint1;\r
760                                         if (self.current_clippoint == self.clippoint1)\r
761                                         {\r
762                                                 self.clippoint1.colormod = '1 0 0';\r
763                                                 if (self.clippoint2)\r
764                                                 {\r
765                                                         self.clippoint2.colormod = '0 0 0';\r
766                                                         if (self.clippoint3)\r
767                                                                 self.clippoint3.colormod = '0 0 0';\r
768                                                 }\r
769                                         }\r
770                                         else if (self.current_clippoint == self.clippoint2)\r
771                                         {\r
772                                                 self.clippoint2.colormod = '1 0 0';\r
773                                                 if (self.clippoint1)\r
774                                                 {\r
775                                                         self.clippoint1.colormod = '0 0 0';\r
776                                                         if (self.clippoint3)\r
777                                                                 self.clippoint3.colormod = '0 0 0';\r
778                                                 }\r
779                                         }\r
780                                         else if (self.current_clippoint == self.clippoint3)\r
781                                         {\r
782                                                 self.clippoint3.colormod = '1 0 0';\r
783                                                 if (self.clippoint1)\r
784                                                 {\r
785                                                         self.clippoint1.colormod = '0 0 0';\r
786                                                         if (self.clippoint2)\r
787                                                                 self.clippoint2.colormod = '0 0 0';\r
788                                                 }\r
789                                         }\r
790                                 }\r
791                                 navcurrent.colormod = '0.25 0.25 1';\r
792                                 BeamBox(BT_LIGHTNING, navcurrent.origin + navcurrent.mins, navcurrent.origin + navcurrent.maxs);\r
793                                 e = navcurrent.plane_chain;\r
794                                 if (e)\r
795                                 {\r
796                                         if (self.current_plane == e)\r
797                                                 e.skin = 3;\r
798                                         else\r
799                                                 e.skin = 1;\r
800                                         e.effects = EF_NODEPTHTEST | EF_ADDITIVE | EF_FULLBRIGHT;\r
801                                         e = e.plane_next;\r
802                                         while (e != navcurrent.plane_chain)\r
803                                         {\r
804                                                 if (self.current_plane == e)\r
805                                                         e.skin = 3;\r
806                                                 else\r
807                                                         e.skin = 1;\r
808                                                 e.effects = EF_NODEPTHTEST | EF_ADDITIVE | EF_FULLBRIGHT;\r
809                                                 e = e.plane_next;\r
810                                         }\r
811                                 }\r
812                                 if (navother != navcurrent)\r
813                                 {\r
814                                         navother.colormod = '1 0 0';\r
815                                         BeamBox(BT_BEAM, navother.origin + navother.mins, navother.origin + navother.maxs);\r
816                                 }\r
817                         }\r
818                         else\r
819                         {\r
820                                 navcurrent.colormod = '1 0 0';\r
821                                 BeamBox(BT_BEAM, navcurrent.origin + navcurrent.mins, navcurrent.origin + navcurrent.maxs);\r
822                                 e = navcurrent.plane_chain;\r
823                                 if (e)\r
824                                 {\r
825                                         if (self.current_plane == e)\r
826                                                 e.skin = 2;\r
827                                         else\r
828                                                 e.skin = 0;\r
829                                         e.effects = EF_NODEPTHTEST | EF_ADDITIVE | EF_FULLBRIGHT;\r
830                                         e = e.plane_next;\r
831                                         while (e != navcurrent.plane_chain)\r
832                                         {\r
833                                                 if (self.current_plane == e)\r
834                                                         e.skin = 2;\r
835                                                 else\r
836                                                         e.skin = 0;\r
837                                                 e.effects = EF_NODEPTHTEST | EF_ADDITIVE | EF_FULLBRIGHT;\r
838                                                 e = e.plane_next;\r
839                                         }\r
840                                 }\r
841                         }\r
842                         e = navcurrent.plane_chain;\r
843                         if (e)\r
844                         {\r
845                                 if (e.mangle_x < 0)\r
846                                         tvec_x = self.origin_x + self.mins_x;\r
847                                 else\r
848                                         tvec_x = self.origin_x + self.maxs_x;\r
849                                 if (e.mangle_y < 0)\r
850                                         tvec_y = self.origin_y + self.mins_y;\r
851                                 else\r
852                                         tvec_y = self.origin_y + self.maxs_y;\r
853                                 if (e.mangle_z < 0)\r
854                                         tvec_z = self.origin_z + self.mins_z;\r
855                                 else\r
856                                         tvec_z = self.origin_z + self.maxs_z;\r
857                                 f = (tvec * e.mangle) - ((navcurrent.origin + (e.delay * e.mangle)) * e.mangle);\r
858                                 if (f > 0)\r
859                                         intonav = intonav + e.mangle*-1;\r
860                                 e = e.plane_next;\r
861                                 while (e != navcurrent.plane_chain)\r
862                                 {\r
863                                         if (e.mangle_x < 0)\r
864                                                 tvec_x = self.origin_x + self.mins_x;\r
865                                         else\r
866                                                 tvec_x = self.origin_x + self.maxs_x;\r
867                                         if (e.mangle_y < 0)\r
868                                                 tvec_y = self.origin_y + self.mins_y;\r
869                                         else\r
870                                                 tvec_y = self.origin_y + self.maxs_y;\r
871                                         if (e.mangle_z < 0)\r
872                                                 tvec_z = self.origin_z + self.mins_z;\r
873                                         else\r
874                                                 tvec_z = self.origin_z + self.maxs_z;\r
875                                         f = (tvec * e.mangle) - ((navcurrent.origin + (e.delay * e.mangle)) * e.mangle);\r
876                                         if (f > 0)\r
877                                                 intonav = intonav + e.mangle*-1;\r
878                                         e = e.plane_next;\r
879                                 }\r
880                         }\r
881                         intonav = normalize(intonav);\r
882                         // te_lightning1(self, self.origin, self.origin + intonav*200);\r
883                         if (navcurrent.link0)\r
884                         {\r
885                                 navcurrent.link0.effects = EF_NODEPTHTEST;\r
886                                 navcurrent.link0.frame = 0;\r
887                                 if (navcurrent.lflags0 & LF_REMOTE)\r
888                                         navcurrent.link0.frame = navcurrent.link0.frame + 21;\r
889                                 if (navcurrent.link1)\r
890                                 {\r
891                                         navcurrent.link1.effects = EF_NODEPTHTEST;\r
892                                         navcurrent.link1.frame = 1;\r
893                                         if (navcurrent.lflags1 & LF_REMOTE)\r
894                                                 navcurrent.link1.frame = navcurrent.link1.frame + 21;\r
895                                         if (navcurrent.link2)\r
896                                         {\r
897                                                 navcurrent.link2.effects = EF_NODEPTHTEST;\r
898                                                 navcurrent.link2.frame = 2;\r
899                                                 if (navcurrent.lflags2 & LF_REMOTE)\r
900                                                         navcurrent.link2.frame = navcurrent.link2.frame + 21;\r
901                                                 if (navcurrent.link3)\r
902                                                 {\r
903                                                         navcurrent.link3.effects = EF_NODEPTHTEST;\r
904                                                         navcurrent.link3.frame = 3;\r
905                                                         if (navcurrent.lflags3 & LF_REMOTE)\r
906                                                                 navcurrent.link3.frame = navcurrent.link3.frame + 21;\r
907                                                         if (navcurrent.link4)\r
908                                                         {\r
909                                                                 navcurrent.link4.effects = EF_NODEPTHTEST;\r
910                                                                 navcurrent.link4.frame = 4;\r
911                                                                 if (navcurrent.lflags4 & LF_REMOTE)\r
912                                                                         navcurrent.link4.frame = navcurrent.link4.frame + 21;\r
913                                                                 if (navcurrent.link5)\r
914                                                                 {\r
915                                                                         navcurrent.link5.effects = EF_NODEPTHTEST;\r
916                                                                         navcurrent.link5.frame = 5;\r
917                                                                         if (navcurrent.lflags5 & LF_REMOTE)\r
918                                                                                 navcurrent.link5.frame = navcurrent.link5.frame + 21;\r
919                                                                         if (navcurrent.link6)\r
920                                                                         {\r
921                                                                                 navcurrent.link6.effects = EF_NODEPTHTEST;\r
922                                                                                 navcurrent.link6.frame = 6;\r
923                                                                                 if (navcurrent.lflags6 & LF_REMOTE)\r
924                                                                                         navcurrent.link6.frame = navcurrent.link6.frame + 21;\r
925                                                                                 if (navcurrent.link7)\r
926                                                                                 {\r
927                                                                                         navcurrent.link7.effects = EF_NODEPTHTEST;\r
928                                                                                         navcurrent.link7.frame = 7;\r
929                                                                                         if (navcurrent.lflags7 & LF_REMOTE)\r
930                                                                                                 navcurrent.link7.frame = navcurrent.link7.frame + 21;\r
931                                                                                         if (navcurrent.link8)\r
932                                                                                         {\r
933                                                                                                 navcurrent.link8.effects = EF_NODEPTHTEST;\r
934                                                                                                 navcurrent.link8.frame = 8;\r
935                                                                                                 if (navcurrent.lflags8 & LF_REMOTE)\r
936                                                                                                         navcurrent.link8.frame = navcurrent.link8.frame + 21;\r
937                                                                                                 if (navcurrent.link9)\r
938                                                                                                 {\r
939                                                                                                         navcurrent.link9.effects = EF_NODEPTHTEST;\r
940                                                                                                         navcurrent.link9.frame = 9;\r
941                                                                                                         if (navcurrent.lflags9 & LF_REMOTE)\r
942                                                                                                                 navcurrent.link9.frame = navcurrent.link9.frame + 21;\r
943                                                                                                         if (navcurrent.link10)\r
944                                                                                                         {\r
945                                                                                                                 navcurrent.link10.effects = EF_NODEPTHTEST;\r
946                                                                                                                 navcurrent.link10.frame = 10;\r
947                                                                                                                 if (navcurrent.lflags10 & LF_REMOTE)\r
948                                                                                                                         navcurrent.link10.frame = navcurrent.link10.frame + 21;\r
949                                                                                                                 if (navcurrent.link11)\r
950                                                                                                                 {\r
951                                                                                                                         navcurrent.link11.effects = EF_NODEPTHTEST;\r
952                                                                                                                         navcurrent.link11.frame = 11;\r
953                                                                                                                         if (navcurrent.lflags11 & LF_REMOTE)\r
954                                                                                                                                 navcurrent.link11.frame = navcurrent.link11.frame + 21;\r
955                                                                                                                         if (navcurrent.link12)\r
956                                                                                                                         {\r
957                                                                                                                                 navcurrent.link12.effects = EF_NODEPTHTEST;\r
958                                                                                                                                 navcurrent.link12.frame = 12;\r
959                                                                                                                                 if (navcurrent.lflags12 & LF_REMOTE)\r
960                                                                                                                                         navcurrent.link12.frame = navcurrent.link12.frame + 21;\r
961                                                                                                                                 if (navcurrent.link13)\r
962                                                                                                                                 {\r
963                                                                                                                                         navcurrent.link13.effects = EF_NODEPTHTEST;\r
964                                                                                                                                         navcurrent.link13.frame = 13;\r
965                                                                                                                                         if (navcurrent.lflags13 & LF_REMOTE)\r
966                                                                                                                                                 navcurrent.link13.frame = navcurrent.link13.frame + 21;\r
967                                                                                                                                         if (navcurrent.link14)\r
968                                                                                                                                         {\r
969                                                                                                                                                 navcurrent.link14.effects = EF_NODEPTHTEST;\r
970                                                                                                                                                 navcurrent.link14.frame = 14;\r
971                                                                                                                                                 if (navcurrent.lflags14 & LF_REMOTE)\r
972                                                                                                                                                         navcurrent.link14.frame = navcurrent.link14.frame + 21;\r
973                                                                                                                                                 if (navcurrent.link15)\r
974                                                                                                                                                 {\r
975                                                                                                                                                         navcurrent.link15.effects = EF_NODEPTHTEST;\r
976                                                                                                                                                         navcurrent.link15.frame = 15;\r
977                                                                                                                                                         if (navcurrent.lflags15 & LF_REMOTE)\r
978                                                                                                                                                                 navcurrent.link15.frame = navcurrent.link15.frame + 21;\r
979                                                                                                                                                         if (navcurrent.link16)\r
980                                                                                                                                                         {\r
981                                                                                                                                                                 navcurrent.link16.effects = EF_NODEPTHTEST;\r
982                                                                                                                                                                 navcurrent.link16.frame = 16;\r
983                                                                                                                                                                 if (navcurrent.lflags16 & LF_REMOTE)\r
984                                                                                                                                                                         navcurrent.link16.frame = navcurrent.link16.frame + 21;\r
985                                                                                                                                                                 if (navcurrent.link17)\r
986                                                                                                                                                                 {\r
987                                                                                                                                                                         navcurrent.link17.effects = EF_NODEPTHTEST;\r
988                                                                                                                                                                         navcurrent.link17.frame = 17;\r
989                                                                                                                                                                         if (navcurrent.lflags17 & LF_REMOTE)\r
990                                                                                                                                                                                 navcurrent.link17.frame = navcurrent.link17.frame + 21;\r
991                                                                                                                                                                         if (navcurrent.link18)\r
992                                                                                                                                                                         {\r
993                                                                                                                                                                                 navcurrent.link18.effects = EF_NODEPTHTEST;\r
994                                                                                                                                                                                 navcurrent.link18.frame = 18;\r
995                                                                                                                                                                                 if (navcurrent.lflags18 & LF_REMOTE)\r
996                                                                                                                                                                                         navcurrent.link18.frame = navcurrent.link18.frame + 21;\r
997                                                                                                                                                                                 if (navcurrent.link19)\r
998                                                                                                                                                                                 {\r
999                                                                                                                                                                                         navcurrent.link19.effects = EF_NODEPTHTEST;\r
1000                                                                                                                                                                                         navcurrent.link19.frame = 19;\r
1001                                                                                                                                                                                         if (navcurrent.lflags19 & LF_REMOTE)\r
1002                                                                                                                                                                                                 navcurrent.link19.frame = navcurrent.link19.frame + 21;\r
1003                                                                                                                                                                                 }\r
1004                                                                                                                                                                         }\r
1005                                                                                                                                                                 }\r
1006                                                                                                                                                         }\r
1007                                                                                                                                                 }\r
1008                                                                                                                                         }\r
1009                                                                                                                                 }\r
1010                                                                                                                         }\r
1011                                                                                                                 }\r
1012                                                                                                         }\r
1013                                                                                                 }\r
1014                                                                                         }\r
1015                                                                                 }\r
1016                                                                         }\r
1017                                                                 }\r
1018                                                         }\r
1019                                                 }\r
1020                                         }\r
1021                                 }\r
1022                         }\r
1023                 }\r
1024         }       \r
1025 };\r
1026 \r
1027 void() PlayerPostThink =\r
1028 {\r
1029         MainMenu();\r
1030 \r
1031         if (self.impulse)\r
1032                 ImpulseCommands(self.impulse);\r
1033         self.impulse = 0;\r
1034 };\r
1035 \r
1036 void() NavOrgThink =\r
1037 {\r
1038         self.nextthink = time + 0.1;\r
1039 \r
1040         setorigin(self, self.owner.current_navnode.origin);\r
1041 };\r
1042 \r
1043 void() PutClientInServer =\r
1044 {\r
1045         local entity spawn_spot;\r
1046 \r
1047         spawn_spot = find (world, classname, "info_player_start");\r
1048         if (!spawn_spot)\r
1049                 spawn_spot = find (world, classname, "info_player_deathmatch");\r
1050 \r
1051         self.classname = "player";\r
1052         self.health = 100;\r
1053         self.solid = SOLID_SLIDEBOX;\r
1054         self.movetype = MOVETYPE_FLY;\r
1055         self.flags = FL_CLIENT;\r
1056         self.nextthink = time;\r
1057         self.think = SUB_Null;\r
1058 \r
1059         setorigin(self, spawn_spot.origin);\r
1060         self.angles = spawn_spot.angles;\r
1061         self.fixangle = TRUE;\r
1062 \r
1063         // setmodel (self, "progs/bbox.mdl");\r
1064         setmodel (self, "progs/null.spr");\r
1065         // setsize (self, '-16 -16 -28', '16 16 28');\r
1066         setsize (self, '-1 -1 -1', '1 1 1');\r
1067         self.gridsize = 8;\r
1068 \r
1069         self.navorg1 = spawn();\r
1070         setmodel(self.navorg1, "progs/org.mdl");\r
1071         setsize(self.navorg1, '0 0 0', '0 0 0');\r
1072         self.navorg1.effects = EF_FULLBRIGHT;\r
1073         self.navorg1.owner = self;\r
1074         self.navorg1.think = NavOrgThink;\r
1075         self.navorg1.nextthink = time;\r
1076         self.navorg2 = spawn();\r
1077         setmodel(self.navorg2, "progs/org2.mdl");\r
1078         setsize(self.navorg2, '0 0 0', '0 0 0');\r
1079         self.navorg2.effects = EF_ADDITIVE | EF_FULLBRIGHT;\r
1080         self.navorg2.owner = self;\r
1081         self.navorg2.think = NavOrgThink;\r
1082         self.navorg2.nextthink = time;\r
1083 };\r
1084 \r
1085 void() SV_PlayerPhysics =\r
1086 {\r
1087         local   vector  wishvel, wishdir;\r
1088         local   float   wishspeed, f;\r
1089 \r
1090         if (self.movetype == MOVETYPE_NONE)\r
1091                 return;\r
1092 \r
1093         if (self.punchangle != '0 0 0')\r
1094                 self.punchangle = self.punchangle * (1 - frametime * 3);\r
1095 \r
1096         if (self.punchvector != '0 0 0')\r
1097                 self.punchvector = self.punchvector * (1 - frametime * 3);\r
1098 \r
1099         // if dead, behave differently\r
1100         if (self.deadflag)\r
1101                 return;\r
1102 \r
1103         if (self.movetype == MOVETYPE_FLY || self.movetype == MOVETYPE_NOCLIP)\r
1104         {\r
1105                 self.velocity = self.velocity * (1 - frametime * sv_friction);\r
1106                 makevectors(self.v_angle);\r
1107                 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;\r
1108         }\r
1109 \r
1110         // acceleration\r
1111         if (time >= self.teleport_time)\r
1112         {\r
1113                 wishdir = normalize(wishvel);\r
1114                 wishspeed = vlen(wishvel);\r
1115                 if (wishspeed > sv_maxspeed)\r
1116                         wishspeed = sv_maxspeed;\r
1117                 f = wishspeed - (self.velocity * wishdir);\r
1118                 if (f > 0)\r
1119                         self.velocity = self.velocity + wishdir * min(f, sv_accelerate * frametime * wishspeed);\r
1120         }\r
1121 };