updated readme
[divverent/nexuiz.git] / navnodeedit / src / wsystem.qc
1 void() LinkNavNodes;\r
2 \r
3 float(vector m1, vector m2, vector m3, vector m4) boxesoverlap =\r
4 {\r
5         return m2_x >= m3_x && m1_x <= m4_x && m2_y >= m3_y && m1_y <= m4_y && m2_z >= m3_z && m1_z <= m4_z;\r
6 };\r
7 \r
8 float(entity e, vector start, vector m1, vector m2, vector end) tracewalk =\r
9 {\r
10         local vector move;\r
11         local vector dir;\r
12         local vector nostependpos;\r
13         local float dist;\r
14         local float totaldist;\r
15         local float stepdist;\r
16         local float yaw;\r
17         local float ignorehazards;\r
18         local float p;\r
19         local float nostepfrac;\r
20         local entity saveself;\r
21         move = end - start;\r
22         move_z = 0;\r
23         dist = totaldist = vlen(move);\r
24         dir = normalize(move);\r
25         stepdist = 32;\r
26         saveself = self;\r
27         if (!tracewalkent)\r
28                 tracewalkent = spawn();\r
29         setsize(tracewalkent, m1, m2);\r
30         tracewalkent.owner = self; // avoid collisions\r
31         self = tracewalkent;\r
32         setorigin(self, start);\r
33         p = pointcontents(self.origin);\r
34         if (p == CONTENT_EMPTY)\r
35         {\r
36                 tracebox(start + '0 0 18', self.mins, self.maxs, start + '0 0 -18', FALSE, e);\r
37                 if (trace_fraction >= 1) // start isn't even on the floor\r
38                 {\r
39                         self = saveself;\r
40                         return 0;\r
41                 }\r
42         }\r
43         ignorehazards = FALSE;\r
44         p = pointcontents(start);\r
45         if (p == CONTENT_LAVA || p == CONTENT_SLIME)\r
46                 ignorehazards = TRUE;\r
47         yaw = vectoyaw(move);\r
48         move = end - self.origin;\r
49         while (1)\r
50         {\r
51                 if (boxesoverlap(end, end, self.absmin, self.absmax))\r
52                 {\r
53                         self = saveself;\r
54                         // succeeded\r
55                         return 1;\r
56                 }\r
57                 if (dist <= 0)\r
58                         break;\r
59                 if (stepdist > dist)\r
60                         stepdist = dist;\r
61                 dist = dist - stepdist;\r
62                 p = 0;\r
63                 if (!ignorehazards)\r
64                 {\r
65                         p = pointcontents(self.origin);\r
66                         if (p == CONTENT_LAVA || p == CONTENT_SLIME)\r
67                         {\r
68                                 self = saveself;\r
69                                 // hazards blocking path\r
70                                 return 0;\r
71                         }\r
72                 }\r
73                 if (p == 0)\r
74                         p = pointcontents(self.origin);\r
75                 if (p != CONTENT_EMPTY)\r
76                 {\r
77                         move = normalize(end - self.origin);\r
78                         tracebox(self.origin, self.mins, self.maxs, self.origin + move * stepdist, FALSE, e);\r
79                         if (trace_startsolid || trace_fraction < 1)\r
80                         {\r
81                                 self = saveself;\r
82                                 // failed\r
83                                 return 0;\r
84                         }\r
85                         setorigin(self, trace_endpos);\r
86                 }\r
87                 else\r
88                 {\r
89                         // walkmove failed, fall back to our own methods\r
90                         move = dir * stepdist + self.origin;\r
91                         // trace twice, first at ground level, then at\r
92                         // stepheight, stepheight trace will be used instead\r
93                         // of ground trace if it went further, if ground\r
94                         // level was chosen check if we made any progress,\r
95                         // if we did, fall to floor, if we did not, fail\r
96                         tracebox(self.origin, self.mins, self.maxs, move, FALSE, e);\r
97                         if (trace_startsolid)\r
98                         {\r
99                                 self = saveself;\r
100                                 // failed\r
101                                 return 0;\r
102                         }\r
103                         nostepfrac = trace_fraction;\r
104                         nostependpos = trace_endpos;\r
105                         tracebox(self.origin + '0 0 18', self.mins, self.maxs, move + '0 0 18', FALSE, e);\r
106                         if (trace_fraction > nostepfrac + 0.001)\r
107                         {\r
108                                 // stepped, fall to floor\r
109                                 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + '0 0 -65536', FALSE, e);\r
110                                 setorigin(self, trace_endpos);\r
111                         }\r
112                         else\r
113                         {\r
114                                 if (nostepfrac >= 0.001)\r
115                                 {\r
116                                         // moved, fall to floor\r
117                                         tracebox(nostependpos, self.mins, self.maxs, nostependpos + '0 0 -65536', FALSE, e);\r
118                                         setorigin(self, trace_endpos);\r
119                                 }\r
120                                 else\r
121                                 {\r
122                                         // didn't move\r
123                                         self = saveself;\r
124                                         // failed\r
125                                         return 0;\r
126                                 }\r
127                         }\r
128                 }\r
129         }\r
130         self = saveself;\r
131         // moved but didn't arrive at the intended destination\r
132         return 0;\r
133 };\r
134 \r
135 entity(entity start, vector org, float mode) FindCurrentNavNode =\r
136 {\r
137         local float f, best_f;\r
138         local entity e, best_e;\r
139 \r
140         best_f = 10000000;\r
141 \r
142         if (mode == M_OVERLAP)\r
143         {\r
144                 if (start.classname == "navnode")\r
145                         e = start.list;\r
146                 else\r
147                         e = navnode_chain;\r
148                 while (e)\r
149                 {\r
150                         if (boxesoverlap(org, org, e.origin + e.mins, e.origin + e.maxs))\r
151                                 return e;\r
152                         e = e.list;\r
153                 }\r
154         }\r
155         else if (mode == M_CLOSEST)\r
156         {\r
157                 if (start.classname == "navnode")\r
158                         e = start.list;\r
159                 else\r
160                         e = navnode_chain;\r
161                 while (e)\r
162                 {\r
163                         f = vlen(org - e.origin);\r
164                         if (f < best_f)\r
165                         {\r
166                                 best_e = e;\r
167                                 best_f = f;\r
168                         }\r
169                         e = e.list;\r
170                 }\r
171                 return best_e;\r
172         }\r
173         return world;\r
174 };\r
175 \r
176 vector(vector org) SnapToGrid =\r
177 {\r
178         local float grid;\r
179         local vector rl, rh, t1, t2, ret;\r
180 \r
181         grid = self.gridsize;\r
182 \r
183         if (org_x < 0)\r
184         {\r
185                 while (rh_x > org_x)\r
186                         rh_x = rh_x - grid;\r
187         }\r
188         else\r
189         {\r
190                 while (rh_x < org_x)\r
191                         rh_x = rh_x + grid;\r
192         }\r
193         if (org_y < 0)\r
194         {\r
195                 while (rh_y > org_y)\r
196                         rh_y = rh_y - grid;\r
197         }\r
198         else\r
199         {\r
200                 while (rh_y < org_y)\r
201                         rh_y = rh_y + grid;\r
202         }\r
203         if (org_z < 0)\r
204         {\r
205                 while (rh_z > org_z)\r
206                         rh_z = rh_z - grid;\r
207         }\r
208         else\r
209         {\r
210                 while (rh_z < org_z)\r
211                         rh_z = rh_z + grid;\r
212         }\r
213 \r
214         if (rh_x < 0)\r
215                 rl_x = rh_x + grid;\r
216         else\r
217                 rl_x = rh_x - grid;\r
218         if (rh_y < 0)\r
219                 rl_y = rh_y + grid;\r
220         else\r
221                 rl_y = rh_y - grid;\r
222         if (rh_z < 0)\r
223                 rl_z = rh_z + grid;\r
224         else\r
225                 rl_z = rh_z - grid;\r
226 \r
227         t1_x = rl_x;\r
228         t1_y = rl_y;\r
229         t1_z = rl_z;\r
230 \r
231         t2_x = rh_x;\r
232         t2_y = rh_y;\r
233         t2_z = rh_z;\r
234 \r
235         if (org_x < 0)\r
236                 org_x = org_x * -1;\r
237         if (org_y < 0)\r
238                 org_y = org_y * -1;\r
239         if (org_z < 0)\r
240                 org_z = org_z * -1;\r
241 \r
242         if (t1_x < 0)\r
243                 t1_x = t1_x * -1;\r
244         if (t1_y < 0)\r
245                 t1_y = t1_y * -1;\r
246         if (t1_z < 0)\r
247                 t1_z = t1_z * -1;\r
248 \r
249         if (t2_x < 0)\r
250                 t2_x = t2_x * -1;\r
251         if (t2_y < 0)\r
252                 t2_y = t2_y * -1;\r
253         if (t2_z < 0)\r
254                 t2_z = t2_z * -1;\r
255 \r
256         t1_x = org_x - t1_x;\r
257         t1_y = org_y - t1_y;\r
258         t1_z = org_z - t1_z;\r
259 \r
260         t2_x = org_x - t2_x;\r
261         t2_y = org_y - t2_y;\r
262         t2_z = org_z - t2_z;\r
263 \r
264         if (t1_x < 0)\r
265                 t1_x = t1_x * -1;\r
266         if (t1_y < 0)\r
267                 t1_y = t1_y * -1;\r
268         if (t1_z < 0)\r
269                 t1_z = t1_z * -1;\r
270 \r
271         if (t2_x < 0)\r
272                 t2_x = t2_x * -1;\r
273         if (t2_y < 0)\r
274                 t2_y = t2_y * -1;\r
275         if (t2_z < 0)\r
276                 t2_z = t2_z * -1;\r
277 \r
278         if (t1_x < t2_x)\r
279                 ret_x = rl_x;\r
280         else\r
281                 ret_x = rh_x;\r
282         if (t1_y < t2_y)\r
283                 ret_y = rl_y;\r
284         else\r
285                 ret_y = rh_y;\r
286         if (t1_z < t2_z)\r
287                 ret_z = rl_z;\r
288         else\r
289                 ret_z = rh_z;\r
290 \r
291         return ret;\r
292 };\r
293 \r
294 void(entity navn) FixPlanes =\r
295 {\r
296         local entity e;\r
297 \r
298         if (!navn)\r
299                 return;\r
300         e = navn.plane_chain;\r
301         if (e)\r
302         {\r
303                 setorigin(e, navn.origin + e.mangle*e.delay);\r
304                 e = e.plane_next;\r
305                 while (e != navn.plane_chain)\r
306                 {\r
307                         setorigin(e, navn.origin + e.mangle*e.delay);\r
308                         e = e.plane_next;\r
309                 }\r
310         }\r
311 };\r
312 \r
313 void(entity navn, vector org) MoveNavNode =\r
314 {\r
315         local entity e;\r
316 \r
317         if (!navn)\r
318                 return;\r
319         setorigin(navn, org);\r
320         FixPlanes(navn);\r
321         LinkNavNodes();\r
322 };\r
323 \r
324 float(entity navn, float ax, float amount) ResizeNavNode =\r
325 {\r
326         local vector v;\r
327 \r
328         if (!navn)\r
329                 return FALSE;\r
330 \r
331         if (ax == 0)\r
332         {\r
333                 amount = amount - navn.origin_x;\r
334                 if (amount < 0)\r
335                         amount = amount*-1;\r
336                 amount = amount - navn.maxs_x;\r
337                 v = navn.maxs;\r
338                 v_x = v_x + (amount*0.5);\r
339                 setsize(navn, v*-1, v);\r
340                 v = navn.origin;\r
341                 if (self.origin_x < navn.origin_x)\r
342                         v_x = navn.origin_x - (amount*0.5);\r
343                 else\r
344                         v_x = navn.origin_x + (amount*0.5);\r
345                 MoveNavNode(navn, v);\r
346         }\r
347         else if (ax == 1)\r
348         {\r
349                 amount = amount - navn.origin_y;\r
350                 if (amount < 0)\r
351                         amount = amount*-1;\r
352                 amount = amount - navn.maxs_y;\r
353                 v = navn.maxs;\r
354                 v_y = v_y + (amount*0.5);\r
355                 setsize(navn, v*-1, v);\r
356                 v = navn.origin;\r
357                 if (self.origin_y < navn.origin_y)\r
358                         v_y = navn.origin_y - (amount*0.5);\r
359                 else\r
360                         v_y = navn.origin_y + (amount*0.5);\r
361                 MoveNavNode(navn, v);\r
362         }\r
363         else if (ax == 2)\r
364         {\r
365                 amount = amount - navn.origin_z;\r
366                 if (amount < 0)\r
367                         amount = amount*-1;\r
368                 amount = amount - navn.maxs_z;\r
369                 v = navn.maxs;\r
370                 v_z = v_z + (amount*0.5);\r
371                 setsize(navn, v*-1, v);\r
372                 v = navn.origin;\r
373                 if (self.origin_z < navn.origin_z)\r
374                         v_z = navn.origin_z - (amount*0.5);\r
375                 else\r
376                         v_z = navn.origin_z + (amount*0.5);\r
377                 MoveNavNode(navn, v);\r
378         }\r
379         LinkNavNodes();\r
380         return TRUE;\r
381 };\r
382 \r
383 void(entity navn, vector normal, float dist) AddPlane =\r
384 {\r
385         local float f;\r
386 \r
387         if (!navn)\r
388                 return;\r
389 \r
390         newmis = spawn();\r
391         newmis.classname = "plane";\r
392         if (!navn.plane_chain)\r
393         {\r
394                 navn.plane_chain = newmis;\r
395                 newmis.plane_next = newmis;\r
396                 newmis.plane_prev = newmis;\r
397         }\r
398         else\r
399         {\r
400                 newmis.plane_next = navn.plane_chain;\r
401                 newmis.plane_prev = newmis.plane_next.plane_prev;\r
402                 newmis.plane_prev.plane_next = newmis;\r
403                 newmis.plane_next.plane_prev = newmis;\r
404         }\r
405         newmis.mangle = normal*-1;\r
406         newmis.delay = dist;\r
407         f = (navn.origin * newmis.mangle) - ((navn.origin + (newmis.delay * newmis.mangle)) * newmis.mangle);\r
408         if (f > 0)\r
409         {\r
410                 newmis.mangle = newmis.mangle*-1;\r
411                 newmis.delay = newmis.delay*-1;\r
412         }\r
413         setorigin (newmis, navn.origin + newmis.mangle*newmis.delay);\r
414         setmodel (newmis, "progs/plane.mdl");\r
415         newmis.angles = vectoangles(newmis.mangle);\r
416         newmis.effects = EF_NODRAW;\r
417 };\r
418 \r
419 void(entity navn, entity delplane) RemovePlane =\r
420 {\r
421         local entity e, y;\r
422 \r
423         e = navn.plane_chain;\r
424         if (e)\r
425         {\r
426                 if (e == delplane)\r
427                 {\r
428                         if (navn.plane_chain == e)\r
429                                 navn.plane_chain = e.plane_next;\r
430                         e.plane_prev.plane_next = e.plane_next;\r
431                         e.plane_next.plane_prev = e.plane_prev;\r
432                         remove (e);\r
433                         e = navn.plane_chain;\r
434                 }\r
435                 e = e.plane_next;\r
436                 while (e != navn.plane_chain)\r
437                 {\r
438                         if (e == delplane)\r
439                         {\r
440                                 if (navn.plane_chain == e)\r
441                                         navn.plane_chain = e.plane_next;\r
442                                 e.plane_prev.plane_next = e.plane_next;\r
443                                 e.plane_next.plane_prev = e.plane_prev;\r
444                                 remove (e);\r
445                                 e = navn.plane_chain;\r
446                         }\r
447                         e = e.plane_next;\r
448                 }\r
449                 if (navn.plane_chain.origin == nullvector)\r
450                         navn.plane_chain = world;\r
451         }\r
452 };\r
453 \r
454 void() RemoveClippoints =\r
455 {\r
456         if (self.clippoint1)\r
457         {\r
458                 if (self.clippoint2)\r
459                 {\r
460                         if (self.clippoint3)\r
461                                 remove (self.clippoint3);\r
462                         remove (self.clippoint2);\r
463                 }\r
464                 remove (self.clippoint1);\r
465         }\r
466         self.current_clippoint = world;\r
467         self.clippoint1 = self.clippoint2 = self.clippoint3 = world;\r
468 };\r
469 \r
470 void() ClippointThink =\r
471 {\r
472         local float p;\r
473 \r
474         self.nextthink = time + 0.1;\r
475 \r
476         p = pointcontents(self.origin);\r
477         if (p == CONTENT_SOLID)\r
478                 self.effects = EF_NODEPTHTEST | EF_ADDITIVE;\r
479         else\r
480                 self.effects = 0;\r
481 };\r
482 \r
483 void(vector org) SpawnClipPoint =\r
484 {\r
485         if (self.clippoint1)\r
486         {\r
487                 if (self.clippoint2)\r
488                 {\r
489                         if (self.clippoint3)\r
490                                 return;\r
491                         else\r
492                         {\r
493                                 self.clippoint3 = spawn();\r
494                                 setmodel(self.clippoint3, "progs/point.spr");\r
495                                 setsize(self.clippoint3, '0 0 0', '0 0 0');\r
496                                 self.clippoint3.classname = "clippoint";\r
497                                 self.clippoint3.scale = 0.5;\r
498                                 setorigin(self.clippoint3, org);\r
499                                 self.clippoint3.think = ClippointThink;\r
500                                 self.clippoint3.nextthink = time;\r
501                         }\r
502                 }\r
503                 else\r
504                 {\r
505                         self.clippoint2 = spawn();\r
506                         setmodel(self.clippoint2, "progs/point.spr");\r
507                         setsize(self.clippoint2, '0 0 0', '0 0 0');\r
508                         self.clippoint2.classname = "clippoint";\r
509                         self.clippoint2.scale = 0.5;\r
510                         setorigin(self.clippoint2, org);\r
511                         self.clippoint2.think = ClippointThink;\r
512                         self.clippoint2.nextthink = time;\r
513                 }\r
514         }\r
515         else\r
516         {\r
517                 self.clippoint1 = spawn();\r
518                 setmodel(self.clippoint1, "progs/point.spr");\r
519                 setsize(self.clippoint1, '0 0 0', '0 0 0');\r
520                 self.clippoint1.classname = "clippoint";\r
521                 self.clippoint1.scale = 0.5;\r
522                 setorigin(self.clippoint1, org);\r
523                 self.clippoint1.think = ClippointThink;\r
524                 self.clippoint1.nextthink = time;\r
525         }\r
526 };\r
527 \r
528 entity(vector org, vector nnmins, vector nnmaxs) SpawnNavNode =\r
529 {\r
530         newmis = spawn();\r
531         setmodel(newmis, "progs/navnode.spr");\r
532         setsize(newmis, nnmins, nnmaxs);\r
533         newmis.classname = "navnode";\r
534         newmis.frame = 20;\r
535         setorigin(newmis, org);\r
536         return newmis;\r
537 };\r
538 \r
539 void() LinkNavNodes =\r
540 {\r
541         local entity e, t;\r
542 \r
543         navnode_chain = world;\r
544         navnodes = 0;\r
545 \r
546         e = findchain(classname, "navnode");\r
547         while (e)\r
548         {\r
549                 e.list = navnode_chain;\r
550                 navnode_chain = e;\r
551                 e.delay = navnodes;\r
552                 navnodes = navnodes + 1;\r
553                 e = e.chain;\r
554         }\r
555 \r
556         e = navnode_chain;\r
557         while (e)\r
558         {\r
559                 if (e.link0)\r
560                 {\r
561                         e.link0.effects = 0;\r
562                         e.link0.frame = 20;\r
563                         if (e.link0.classname == "remotelinker")\r
564                         {\r
565                                 e.link0.think = SUB_Remove;\r
566                                 e.link0.nextthink = time;\r
567                                 t = navnode_chain;\r
568                                 while (t)\r
569                                 {\r
570                                         if (t.delay == e.link0.delay)\r
571                                                 e.link0 = t;\r
572                                         t = t.list;\r
573                                 }\r
574                                 e.lflags0 = e.lflags0 | LF_REMOTE;\r
575                         }\r
576                         else\r
577                         {\r
578                                 if (!(e.lflags0 & LF_REMOTE))\r
579                                 if (!boxesoverlap(e.origin + e.mins, e.origin + e.maxs, e.link0.origin + e.link0.mins, e.link0.origin + e.link0.maxs))\r
580                                         PushLinks(e, 0);\r
581                         }\r
582                 }\r
583                 if (e.link1)\r
584                 {\r
585                         e.link1.effects = 0;\r
586                         e.link1.frame = 20;\r
587                         if (e.link1.classname == "remotelinker")\r
588                         {\r
589                                 e.link1.think = SUB_Remove;\r
590                                 e.link1.nextthink = time;\r
591                                 t = navnode_chain;\r
592                                 while (t)\r
593                                 {\r
594                                         if (t.delay == e.link1.delay)\r
595                                                 e.link1 = t;\r
596                                         t = t.list;\r
597                                 }\r
598                                 e.lflags1 = e.lflags1 | LF_REMOTE;\r
599                         }\r
600                         else\r
601                         {\r
602                                 if (!(e.lflags1 & LF_REMOTE))\r
603                                 if (!boxesoverlap(e.origin + e.mins, e.origin + e.maxs, e.link1.origin + e.link1.mins, e.link1.origin + e.link1.maxs))\r
604                                         PushLinks(e, 1);\r
605                         }\r
606                 }\r
607                 if (e.link2)\r
608                 {\r
609                         e.link2.effects = 0;\r
610                         e.link2.frame = 20;\r
611                         if (e.link2.classname == "remotelinker")\r
612                         {\r
613                                 e.link2.think = SUB_Remove;\r
614                                 e.link2.nextthink = time;\r
615                                 t = navnode_chain;\r
616                                 while (t)\r
617                                 {\r
618                                         if (t.delay == e.link2.delay)\r
619                                                 e.link2 = t;\r
620                                         t = t.list;\r
621                                 }\r
622                                 e.lflags2 = e.lflags2 | LF_REMOTE;\r
623                         }\r
624                         else\r
625                         {\r
626                                 if (!(e.lflags2 & LF_REMOTE))\r
627                                 if (!boxesoverlap(e.origin + e.mins, e.origin + e.maxs, e.link2.origin + e.link2.mins, e.link2.origin + e.link2.maxs))\r
628                                         PushLinks(e, 2);\r
629                         }\r
630                 }\r
631                 if (e.link3)\r
632                 {\r
633                         e.link3.effects = 0;\r
634                         e.link3.frame = 20;\r
635                         if (e.link3.classname == "remotelinker")\r
636                         {\r
637                                 e.link3.think = SUB_Remove;\r
638                                 e.link3.nextthink = time;\r
639                                 t = navnode_chain;\r
640                                 while (t)\r
641                                 {\r
642                                         if (t.delay == e.link3.delay)\r
643                                                 e.link3 = t;\r
644                                         t = t.list;\r
645                                 }\r
646                                 e.lflags3 = e.lflags3 | LF_REMOTE;\r
647                         }\r
648                         else\r
649                         {\r
650                                 if (!(e.lflags3 & LF_REMOTE))\r
651                                 if (!boxesoverlap(e.origin + e.mins, e.origin + e.maxs, e.link3.origin + e.link3.mins, e.link3.origin + e.link3.maxs))\r
652                                         PushLinks(e, 3);\r
653                         }\r
654                 }\r
655                 if (e.link4)\r
656                 {\r
657                         e.link4.effects = 0;\r
658                         e.link4.frame = 20;\r
659                         if (e.link4.classname == "remotelinker")\r
660                         {\r
661                                 e.link4.think = SUB_Remove;\r
662                                 e.link4.nextthink = time;\r
663                                 t = navnode_chain;\r
664                                 while (t)\r
665                                 {\r
666                                         if (t.delay == e.link4.delay)\r
667                                                 e.link4 = t;\r
668                                         t = t.list;\r
669                                 }\r
670                                 e.lflags4 = e.lflags4 | LF_REMOTE;\r
671                         }\r
672                         else\r
673                         {\r
674                                 if (!(e.lflags4 & LF_REMOTE))\r
675                                 if (!boxesoverlap(e.origin + e.mins, e.origin + e.maxs, e.link4.origin + e.link4.mins, e.link4.origin + e.link4.maxs))\r
676                                         PushLinks(e, 4);\r
677                         }\r
678                 }\r
679                 if (e.link5)\r
680                 {\r
681                         e.link5.effects = 0;\r
682                         e.link5.frame = 20;\r
683                         if (e.link5.classname == "remotelinker")\r
684                         {\r
685                                 e.link5.think = SUB_Remove;\r
686                                 e.link5.nextthink = time;\r
687                                 t = navnode_chain;\r
688                                 while (t)\r
689                                 {\r
690                                         if (t.delay == e.link5.delay)\r
691                                                 e.link5 = t;\r
692                                         t = t.list;\r
693                                 }\r
694                                 e.lflags5 = e.lflags5 | LF_REMOTE;\r
695                         }\r
696                         else\r
697                         {\r
698                                 if (!(e.lflags5 & LF_REMOTE))\r
699                                 if (!boxesoverlap(e.origin + e.mins, e.origin + e.maxs, e.link5.origin + e.link5.mins, e.link5.origin + e.link5.maxs))\r
700                                         PushLinks(e, 5);\r
701                         }\r
702                 }\r
703                 if (e.link6)\r
704                 {\r
705                         e.link6.effects = 0;\r
706                         e.link6.frame = 20;\r
707                         if (e.link6.classname == "remotelinker")\r
708                         {\r
709                                 e.link6.think = SUB_Remove;\r
710                                 e.link6.nextthink = time;\r
711                                 t = navnode_chain;\r
712                                 while (t)\r
713                                 {\r
714                                         if (t.delay == e.link6.delay)\r
715                                                 e.link6 = t;\r
716                                         t = t.list;\r
717                                 }\r
718                                 e.lflags6 = e.lflags6 | LF_REMOTE;\r
719                         }\r
720                         else\r
721                         {\r
722                                 if (!(e.lflags6 & LF_REMOTE))\r
723                                 if (!boxesoverlap(e.origin + e.mins, e.origin + e.maxs, e.link6.origin + e.link6.mins, e.link6.origin + e.link6.maxs))\r
724                                         PushLinks(e, 6);\r
725                         }\r
726                 }\r
727                 if (e.link7)\r
728                 {\r
729                         e.link7.effects = 0;\r
730                         e.link7.frame = 20;\r
731                         if (e.link7.classname == "remotelinker")\r
732                         {\r
733                                 e.link7.think = SUB_Remove;\r
734                                 e.link7.nextthink = time;\r
735                                 t = navnode_chain;\r
736                                 while (t)\r
737                                 {\r
738                                         if (t.delay == e.link7.delay)\r
739                                                 e.link7 = t;\r
740                                         t = t.list;\r
741                                 }\r
742                                 e.lflags7 = e.lflags7 | LF_REMOTE;\r
743                         }\r
744                         else\r
745                         {\r
746                                 if (!(e.lflags7 & LF_REMOTE))\r
747                                 if (!boxesoverlap(e.origin + e.mins, e.origin + e.maxs, e.link7.origin + e.link7.mins, e.link7.origin + e.link7.maxs))\r
748                                         PushLinks(e, 7);\r
749                         }\r
750                 }\r
751                 if (e.link8)\r
752                 {\r
753                         e.link8.effects = 0;\r
754                         e.link8.frame = 20;\r
755                         if (e.link8.classname == "remotelinker")\r
756                         {\r
757                                 e.link8.think = SUB_Remove;\r
758                                 e.link8.nextthink = time;\r
759                                 t = navnode_chain;\r
760                                 while (t)\r
761                                 {\r
762                                         if (t.delay == e.link8.delay)\r
763                                                 e.link8 = t;\r
764                                         t = t.list;\r
765                                 }\r
766                                 e.lflags8 = e.lflags8 | LF_REMOTE;\r
767                         }\r
768                         else\r
769                         {\r
770                                 if (!(e.lflags8 & LF_REMOTE))\r
771                                 if (!boxesoverlap(e.origin + e.mins, e.origin + e.maxs, e.link8.origin + e.link8.mins, e.link8.origin + e.link8.maxs))\r
772                                         PushLinks(e, 8);\r
773                         }\r
774                 }\r
775                 if (e.link9)\r
776                 {\r
777                         e.link9.effects = 0;\r
778                         e.link9.frame = 20;\r
779                         if (e.link9.classname == "remotelinker")\r
780                         {\r
781                                 e.link9.think = SUB_Remove;\r
782                                 e.link9.nextthink = time;\r
783                                 t = navnode_chain;\r
784                                 while (t)\r
785                                 {\r
786                                         if (t.delay == e.link9.delay)\r
787                                                 e.link9 = t;\r
788                                         t = t.list;\r
789                                 }\r
790                                 e.lflags9 = e.lflags9 | LF_REMOTE;\r
791                         }\r
792                         else\r
793                         {\r
794                                 if (!(e.lflags9 & LF_REMOTE))\r
795                                 if (!boxesoverlap(e.origin + e.mins, e.origin + e.maxs, e.link9.origin + e.link9.mins, e.link9.origin + e.link9.maxs))\r
796                                         PushLinks(e, 9);\r
797                         }\r
798                 }\r
799                 if (e.link10)\r
800                 {\r
801                         e.link10.effects = 0;\r
802                         e.link10.frame = 20;\r
803                         if (e.link10.classname == "remotelinker")\r
804                         {\r
805                                 e.link10.think = SUB_Remove;\r
806                                 e.link10.nextthink = time;\r
807                                 t = navnode_chain;\r
808                                 while (t)\r
809                                 {\r
810                                         if (t.delay == e.link10.delay)\r
811                                                 e.link10 = t;\r
812                                         t = t.list;\r
813                                 }\r
814                                 e.lflags10 = e.lflags10 | LF_REMOTE;\r
815                         }\r
816                         else\r
817                         {\r
818                                 if (!(e.lflags10 & LF_REMOTE))\r
819                                 if (!boxesoverlap(e.origin + e.mins, e.origin + e.maxs, e.link10.origin + e.link10.mins, e.link10.origin + e.link10.maxs))\r
820                                         PushLinks(e, 10);\r
821                         }\r
822                 }\r
823                 if (e.link11)\r
824                 {\r
825                         e.link11.effects = 0;\r
826                         e.link11.frame = 20;\r
827                         if (e.link11.classname == "remotelinker")\r
828                         {\r
829                                 e.link11.think = SUB_Remove;\r
830                                 e.link11.nextthink = time;\r
831                                 t = navnode_chain;\r
832                                 while (t)\r
833                                 {\r
834                                         if (t.delay == e.link11.delay)\r
835                                                 e.link11 = t;\r
836                                         t = t.list;\r
837                                 }\r
838                                 e.lflags11 = e.lflags11 | LF_REMOTE;\r
839                         }\r
840                         else\r
841                         {\r
842                                 if (!(e.lflags11 & LF_REMOTE))\r
843                                 if (!boxesoverlap(e.origin + e.mins, e.origin + e.maxs, e.link11.origin + e.link11.mins, e.link11.origin + e.link11.maxs))\r
844                                         PushLinks(e, 11);\r
845                         }\r
846                 }\r
847                 if (e.link12)\r
848                 {\r
849                         e.link12.effects = 0;\r
850                         e.link12.frame = 20;\r
851                         if (e.link12.classname == "remotelinker")\r
852                         {\r
853                                 e.link12.think = SUB_Remove;\r
854                                 e.link12.nextthink = time;\r
855                                 t = navnode_chain;\r
856                                 while (t)\r
857                                 {\r
858                                         if (t.delay == e.link12.delay)\r
859                                                 e.link12 = t;\r
860                                         t = t.list;\r
861                                 }\r
862                                 e.lflags12 = e.lflags12 | LF_REMOTE;\r
863                         }\r
864                         else\r
865                         {\r
866                                 if (!(e.lflags12 & LF_REMOTE))\r
867                                 if (!boxesoverlap(e.origin + e.mins, e.origin + e.maxs, e.link12.origin + e.link12.mins, e.link12.origin + e.link12.maxs))\r
868                                         PushLinks(e, 12);\r
869                         }\r
870                 }\r
871                 if (e.link13)\r
872                 {\r
873                         e.link13.effects = 0;\r
874                         e.link13.frame = 20;\r
875                         if (e.link13.classname == "remotelinker")\r
876                         {\r
877                                 e.link13.think = SUB_Remove;\r
878                                 e.link13.nextthink = time;\r
879                                 t = navnode_chain;\r
880                                 while (t)\r
881                                 {\r
882                                         if (t.delay == e.link13.delay)\r
883                                                 e.link13 = t;\r
884                                         t = t.list;\r
885                                 }\r
886                                 e.lflags13 = e.lflags13 | LF_REMOTE;\r
887                         }\r
888                         else\r
889                         {\r
890                                 if (!(e.lflags13 & LF_REMOTE))\r
891                                 if (!boxesoverlap(e.origin + e.mins, e.origin + e.maxs, e.link13.origin + e.link13.mins, e.link13.origin + e.link13.maxs))\r
892                                         PushLinks(e, 13);\r
893                         }\r
894                 }\r
895                 if (e.link14)\r
896                 {\r
897                         e.link14.effects = 0;\r
898                         e.link14.frame = 20;\r
899                         if (e.link14.classname == "remotelinker")\r
900                         {\r
901                                 e.link14.think = SUB_Remove;\r
902                                 e.link14.nextthink = time;\r
903                                 t = navnode_chain;\r
904                                 while (t)\r
905                                 {\r
906                                         if (t.delay == e.link14.delay)\r
907                                                 e.link14 = t;\r
908                                         t = t.list;\r
909                                 }\r
910                                 e.lflags14 = e.lflags14 | LF_REMOTE;\r
911                         }\r
912                         else\r
913                         {\r
914                                 if (!(e.lflags14 & LF_REMOTE))\r
915                                 if (!boxesoverlap(e.origin + e.mins, e.origin + e.maxs, e.link14.origin + e.link14.mins, e.link14.origin + e.link14.maxs))\r
916                                         PushLinks(e, 14);\r
917                         }\r
918                 }\r
919                 if (e.link15)\r
920                 {\r
921                         e.link15.effects = 0;\r
922                         e.link15.frame = 20;\r
923                         if (e.link15.classname == "remotelinker")\r
924                         {\r
925                                 e.link15.think = SUB_Remove;\r
926                                 e.link15.nextthink = time;\r
927                                 t = navnode_chain;\r
928                                 while (t)\r
929                                 {\r
930                                         if (t.delay == e.link15.delay)\r
931                                                 e.link15 = t;\r
932                                         t = t.list;\r
933                                 }\r
934                                 e.lflags15 = e.lflags15 | LF_REMOTE;\r
935                         }\r
936                         else\r
937                         {\r
938                                 if (!(e.lflags15 & LF_REMOTE))\r
939                                 if (!boxesoverlap(e.origin + e.mins, e.origin + e.maxs, e.link15.origin + e.link15.mins, e.link15.origin + e.link15.maxs))\r
940                                         PushLinks(e, 15);\r
941                         }\r
942                 }\r
943                 if (e.link16)\r
944                 {\r
945                         e.link16.effects = 0;\r
946                         e.link16.frame = 20;\r
947                         if (e.link16.classname == "remotelinker")\r
948                         {\r
949                                 e.link16.think = SUB_Remove;\r
950                                 e.link16.nextthink = time;\r
951                                 t = navnode_chain;\r
952                                 while (t)\r
953                                 {\r
954                                         if (t.delay == e.link16.delay)\r
955                                                 e.link16 = t;\r
956                                         t = t.list;\r
957                                 }\r
958                                 e.lflags16 = e.lflags16 | LF_REMOTE;\r
959                         }\r
960                         else\r
961                         {\r
962                                 if (!(e.lflags16 & LF_REMOTE))\r
963                                 if (!boxesoverlap(e.origin + e.mins, e.origin + e.maxs, e.link16.origin + e.link16.mins, e.link16.origin + e.link16.maxs))\r
964                                         PushLinks(e, 16);\r
965                         }\r
966                 }\r
967                 if (e.link17)\r
968                 {\r
969                         e.link17.effects = 0;\r
970                         e.link17.frame = 20;\r
971                         if (e.link17.classname == "remotelinker")\r
972                         {\r
973                                 e.link17.think = SUB_Remove;\r
974                                 e.link17.nextthink = time;\r
975                                 t = navnode_chain;\r
976                                 while (t)\r
977                                 {\r
978                                         if (t.delay == e.link17.delay)\r
979                                                 e.link17 = t;\r
980                                         t = t.list;\r
981                                 }\r
982                                 e.lflags17 = e.lflags17 | LF_REMOTE;\r
983                         }\r
984                         else\r
985                         {\r
986                                 if (!(e.lflags17 & LF_REMOTE))\r
987                                 if (!boxesoverlap(e.origin + e.mins, e.origin + e.maxs, e.link17.origin + e.link17.mins, e.link17.origin + e.link17.maxs))\r
988                                         PushLinks(e, 17);\r
989                         }\r
990                 }\r
991                 if (e.link18)\r
992                 {\r
993                         e.link18.effects = 0;\r
994                         e.link18.frame = 20;\r
995                         if (e.link18.classname == "remotelinker")\r
996                         {\r
997                                 e.link18.think = SUB_Remove;\r
998                                 e.link18.nextthink = time;\r
999                                 t = navnode_chain;\r
1000                                 while (t)\r
1001                                 {\r
1002                                         if (t.delay == e.link18.delay)\r
1003                                                 e.link18 = t;\r
1004                                         t = t.list;\r
1005                                 }\r
1006                                 e.lflags18 = e.lflags18 | LF_REMOTE;\r
1007                         }\r
1008                         else\r
1009                         {\r
1010                                 if (!(e.lflags18 & LF_REMOTE))\r
1011                                 if (!boxesoverlap(e.origin + e.mins, e.origin + e.maxs, e.link18.origin + e.link18.mins, e.link18.origin + e.link18.maxs))\r
1012                                         PushLinks(e, 18);\r
1013                         }\r
1014                 }\r
1015                 if (e.link19)\r
1016                 {\r
1017                         e.link19.effects = 0;\r
1018                         e.link19.frame = 20;\r
1019                         if (e.link19.classname == "remotelinker")\r
1020                         {\r
1021                                 e.link19.think = SUB_Remove;\r
1022                                 e.link19.nextthink = time;\r
1023                                 t = navnode_chain;\r
1024                                 while (t)\r
1025                                 {\r
1026                                         if (t.delay == e.link19.delay)\r
1027                                                 e.link19 = t;\r
1028                                         t = t.list;\r
1029                                 }\r
1030                                 e.lflags19 = e.lflags19 | LF_REMOTE;\r
1031                         }\r
1032                         else\r
1033                         {\r
1034                                 if (!(e.lflags19 & LF_REMOTE))\r
1035                                 if (!boxesoverlap(e.origin + e.mins, e.origin + e.maxs, e.link19.origin + e.link19.mins, e.link19.origin + e.link19.maxs))\r
1036                                         PushLinks(e, 19);\r
1037                         }\r
1038                 }\r
1039                 e = e.list;\r
1040         }\r
1041         e = navnode_chain;\r
1042         while (e)\r
1043         {\r
1044                 t = navnode_chain;\r
1045                 while (t)\r
1046                 {\r
1047                         if (boxesoverlap(e.origin + e.mins, e.origin + e.maxs, t.origin + t.mins, t.origin + t.maxs))\r
1048                         if (t != e)\r
1049                         if (t != e.link0)\r
1050                         if (t != e.link1)\r
1051                         if (t != e.link2)\r
1052                         if (t != e.link3)\r
1053                         if (t != e.link4)\r
1054                         if (t != e.link5)\r
1055                         if (t != e.link6)\r
1056                         if (t != e.link7)\r
1057                         if (t != e.link8)\r
1058                         if (t != e.link9)\r
1059                         if (t != e.link10)\r
1060                         if (t != e.link11)\r
1061                         if (t != e.link12)\r
1062                         if (t != e.link13)\r
1063                         if (t != e.link14)\r
1064                         if (t != e.link15)\r
1065                         if (t != e.link16)\r
1066                         if (t != e.link17)\r
1067                         if (t != e.link18)\r
1068                         if (t != e.link19)\r
1069                         {\r
1070                                 if (!e.link0)\r
1071                                         e.link0 = t;\r
1072                                 else if (!e.link1)\r
1073                                         e.link1 = t;\r
1074                                 else if (!e.link2)\r
1075                                         e.link2 = t;\r
1076                                 else if (!e.link3)\r
1077                                         e.link3 = t;\r
1078                                 else if (!e.link4)\r
1079                                         e.link4 = t;\r
1080                                 else if (!e.link5)\r
1081                                         e.link5 = t;\r
1082                                 else if (!e.link6)\r
1083                                         e.link6 = t;\r
1084                                 else if (!e.link7)\r
1085                                         e.link7 = t;\r
1086                                 else if (!e.link8)\r
1087                                         e.link8 = t;\r
1088                                 else if (!e.link9)\r
1089                                         e.link9 = t;\r
1090                                 else if (!e.link10)\r
1091                                         e.link10 = t;\r
1092                                 else if (!e.link11)\r
1093                                         e.link11 = t;\r
1094                                 else if (!e.link12)\r
1095                                         e.link12 = t;\r
1096                                 else if (!e.link13)\r
1097                                         e.link13 = t;\r
1098                                 else if (!e.link14)\r
1099                                         e.link14 = t;\r
1100                                 else if (!e.link15)\r
1101                                         e.link15 = t;\r
1102                                 else if (!e.link16)\r
1103                                         e.link16 = t;\r
1104                                 else if (!e.link17)\r
1105                                         e.link17 = t;\r
1106                                 else if (!e.link18)\r
1107                                         e.link18 = t;\r
1108                                 else if (!e.link19)\r
1109                                         e.link19 = t;\r
1110                                 else\r
1111                                         dprint("WARNING: Too many linking NavNodes!\n");\r
1112                         }\r
1113                         t = t.list;\r
1114                 }\r
1115                 e = e.list;\r
1116         }\r
1117 };\r
1118 \r
1119 void() LoadNavNodes =\r
1120 {\r
1121         local float f, file, length;\r
1122         local float pdst;\r
1123         local float sfl;\r
1124         local float tfl0, tfl1, tfl2, tfl3, tfl4, tfl5, tfl6, tfl7, tfl8, tfl9;\r
1125         local float tfl10, tfl11, tfl12, tfl13, tfl14, tfl15, tfl16, tfl17, tfl18, tfl19;\r
1126         local string s;\r
1127         local float rl0, rl1, rl2, rl3, rl4, rl5, rl6, rl7, rl8, rl9;\r
1128         local float rl10, rl11, rl12, rl13, rl14, rl15, rl16, rl17, rl18, rl19;\r
1129         local vector pln;\r
1130         local vector wborg, wbmaxs, wbmins;\r
1131         local entity e, plane_storage;\r
1132 \r
1133         if (navnodes)\r
1134         {\r
1135                 dprint("NavNodes present, map needs to be reloaded to load navnode-file\n");\r
1136                 return;\r
1137         }\r
1138 \r
1139         plane_storage = spawn();\r
1140 \r
1141         length = strlen(world.model);\r
1142         length = length - 5;\r
1143         s = substring(world.model, 5, length);\r
1144         s = strcat(s, ".nnl");\r
1145 \r
1146         file = fopen(s, FILE_READ);\r
1147 \r
1148         if (file >= 0)\r
1149         {\r
1150                 s = fgets(file);\r
1151                 while (s == "navnode")\r
1152                 {\r
1153                         f = 0;\r
1154                         pdst = -1;\r
1155                         pln = nullvector;\r
1156                         wborg = wbmaxs = wbmins = nullvector;\r
1157                         plane_storage.plane_chain = world;\r
1158                         sfl = 0;\r
1159                         tfl0 = tfl1 = tfl2 = tfl3 = tfl4 = tfl5 = tfl6 = tfl7 = tfl8 = tfl9 = 0;\r
1160                         tfl10 = tfl11 = tfl12 = tfl13 = tfl14 = tfl15 = tfl16 = tfl17 = tfl18 = tfl19 = 0;\r
1161                         rl0 = rl1 = rl2 = rl3 = rl4 = rl5 = rl6 = rl7 = rl8 = rl9 = -1;\r
1162                         rl10 = rl11 = rl12 = rl13 = rl14 = rl15 = rl16 = rl17 = rl18 = rl19 = -1;\r
1163                         s = fgets(file);\r
1164                         wborg = stov(s);\r
1165                         s = fgets(file);\r
1166                         wbmins = stov(s);\r
1167                         s = fgets(file);\r
1168                         wbmaxs = stov(s);\r
1169                         s = fgets(file);\r
1170                         while (s == "plane")\r
1171                         {\r
1172                                 s = fgets(file);\r
1173                                 pln = stov(s);\r
1174                                 s = fgets(file);\r
1175                                 pdst = stof(s);\r
1176                                 AddPlane(plane_storage, pln*-1, pdst);\r
1177                                 s = fgets(file);\r
1178                         }\r
1179                         while (substring(s, 0, 6) == "remote")\r
1180                         {\r
1181                                 length = strlen(s);\r
1182                                 f = stof(substring(s, 6, length));\r
1183                                 s = fgets(file);\r
1184                                 if (!f)\r
1185                                         rl0 = stof(s);\r
1186                                 else if (f == 1)\r
1187                                         rl1 = stof(s);\r
1188                                 else if (f == 2)\r
1189                                         rl2 = stof(s);\r
1190                                 else if (f == 3)\r
1191                                         rl3 = stof(s);\r
1192                                 else if (f == 4)\r
1193                                         rl4 = stof(s);\r
1194                                 else if (f == 5)\r
1195                                         rl5 = stof(s);\r
1196                                 else if (f == 6)\r
1197                                         rl6 = stof(s);\r
1198                                 else if (f == 7)\r
1199                                         rl7 = stof(s);\r
1200                                 else if (f == 8)\r
1201                                         rl8 = stof(s);\r
1202                                 else if (f == 9)\r
1203                                         rl9 = stof(s);\r
1204                                 else if (f == 10)\r
1205                                         rl10 = stof(s);\r
1206                                 else if (f == 11)\r
1207                                         rl11 = stof(s);\r
1208                                 else if (f == 12)\r
1209                                         rl12 = stof(s);\r
1210                                 else if (f == 13)\r
1211                                         rl13 = stof(s);\r
1212                                 else if (f == 14)\r
1213                                         rl14 = stof(s);\r
1214                                 else if (f == 15)\r
1215                                         rl15 = stof(s);\r
1216                                 else if (f == 16)\r
1217                                         rl16 = stof(s);\r
1218                                 else if (f == 17)\r
1219                                         rl17 = stof(s);\r
1220                                 else if (f == 18)\r
1221                                         rl18 = stof(s);\r
1222                                 else if (f == 19)\r
1223                                         rl19 = stof(s);\r
1224                                 s = fgets(file);\r
1225                         }\r
1226                         if (s == "sflags")\r
1227                         {\r
1228                                 s = fgets(file);\r
1229                                 sfl = stof(s);\r
1230                                 s = fgets(file);\r
1231                         }\r
1232                         while (substring(s, 0, 6) == "lflags")\r
1233                         {\r
1234                                 length = strlen(s);\r
1235                                 f = stof(substring(s, 6, length));\r
1236                                 s = fgets(file);\r
1237                                 if (!f)\r
1238                                         tfl0 = stof(s);\r
1239                                 else if (f == 1)\r
1240                                         tfl1 = stof(s);\r
1241                                 else if (f == 2)\r
1242                                         tfl2 = stof(s);\r
1243                                 else if (f == 3)\r
1244                                         tfl3 = stof(s);\r
1245                                 else if (f == 4)\r
1246                                         tfl4 = stof(s);\r
1247                                 else if (f == 5)\r
1248                                         tfl5 = stof(s);\r
1249                                 else if (f == 6)\r
1250                                         tfl6 = stof(s);\r
1251                                 else if (f == 7)\r
1252                                         tfl7 = stof(s);\r
1253                                 else if (f == 8)\r
1254                                         tfl8 = stof(s);\r
1255                                 else if (f == 9)\r
1256                                         tfl9 = stof(s);\r
1257                                 else if (f == 10)\r
1258                                         tfl10 = stof(s);\r
1259                                 else if (f == 11)\r
1260                                         tfl11 = stof(s);\r
1261                                 else if (f == 12)\r
1262                                         tfl12 = stof(s);\r
1263                                 else if (f == 13)\r
1264                                         tfl13 = stof(s);\r
1265                                 else if (f == 14)\r
1266                                         tfl14 = stof(s);\r
1267                                 else if (f == 15)\r
1268                                         tfl15 = stof(s);\r
1269                                 else if (f == 16)\r
1270                                         tfl16 = stof(s);\r
1271                                 else if (f == 17)\r
1272                                         tfl17 = stof(s);\r
1273                                 else if (f == 18)\r
1274                                         tfl18 = stof(s);\r
1275                                 else if (f == 19)\r
1276                                         tfl19 = stof(s);\r
1277                                 s = fgets(file);\r
1278                         }\r
1279                         e = SpawnNavNode(wborg, wbmins, wbmaxs);\r
1280                         if (plane_storage.plane_chain)\r
1281                                 e.plane_chain = plane_storage.plane_chain;\r
1282                         e.sflags = sfl;\r
1283                         e.lflags0 = tfl0;\r
1284                         e.lflags1 = tfl1;\r
1285                         e.lflags2 = tfl2;\r
1286                         e.lflags3 = tfl3;\r
1287                         e.lflags4 = tfl4;\r
1288                         e.lflags5 = tfl5;\r
1289                         e.lflags6 = tfl6;\r
1290                         e.lflags7 = tfl7;\r
1291                         e.lflags8 = tfl8;\r
1292                         e.lflags9 = tfl9;\r
1293                         e.lflags10 = tfl10;\r
1294                         e.lflags11 = tfl11;\r
1295                         e.lflags12 = tfl12;\r
1296                         e.lflags13 = tfl13;\r
1297                         e.lflags14 = tfl14;\r
1298                         e.lflags15 = tfl15;\r
1299                         e.lflags16 = tfl16;\r
1300                         e.lflags17 = tfl17;\r
1301                         e.lflags18 = tfl18;\r
1302                         e.lflags19 = tfl19;\r
1303                         if (rl0 > -1)\r
1304                         {\r
1305                                 newmis = spawn();\r
1306                                 newmis.classname = "remotelinker";\r
1307                                 newmis.delay = rl0;\r
1308                                 e.link0 = newmis;\r
1309                         }\r
1310                         if (rl1 > -1)\r
1311                         {\r
1312                                 newmis = spawn();\r
1313                                 newmis.classname = "remotelinker";\r
1314                                 newmis.delay = rl1;\r
1315                                 e.link1 = newmis;\r
1316                         }\r
1317                         if (rl2 > -1)\r
1318                         {\r
1319                                 newmis = spawn();\r
1320                                 newmis.classname = "remotelinker";\r
1321                                 newmis.delay = rl2;\r
1322                                 e.link2 = newmis;\r
1323                         }\r
1324                         if (rl3 > -1)\r
1325                         {\r
1326                                 newmis = spawn();\r
1327                                 newmis.classname = "remotelinker";\r
1328                                 newmis.delay = rl3;\r
1329                                 e.link3 = newmis;\r
1330                         }\r
1331                         if (rl4 > -1)\r
1332                         {\r
1333                                 newmis = spawn();\r
1334                                 newmis.classname = "remotelinker";\r
1335                                 newmis.delay = rl4;\r
1336                                 e.link4 = newmis;\r
1337                         }\r
1338                         if (rl5 > -1)\r
1339                         {\r
1340                                 newmis = spawn();\r
1341                                 newmis.classname = "remotelinker";\r
1342                                 newmis.delay = rl5;\r
1343                                 e.link5 = newmis;\r
1344                         }\r
1345                         if (rl6 > -1)\r
1346                         {\r
1347                                 newmis = spawn();\r
1348                                 newmis.classname = "remotelinker";\r
1349                                 newmis.delay = rl6;\r
1350                                 e.link6 = newmis;\r
1351                         }\r
1352                         if (rl7 > -1)\r
1353                         {\r
1354                                 newmis = spawn();\r
1355                                 newmis.classname = "remotelinker";\r
1356                                 newmis.delay = rl7;\r
1357                                 e.link7 = newmis;\r
1358                         }\r
1359                         if (rl8 > -1)\r
1360                         {\r
1361                                 newmis = spawn();\r
1362                                 newmis.classname = "remotelinker";\r
1363                                 newmis.delay = rl8;\r
1364                                 e.link8 = newmis;\r
1365                         }\r
1366                         if (rl9 > -1)\r
1367                         {\r
1368                                 newmis = spawn();\r
1369                                 newmis.classname = "remotelinker";\r
1370                                 newmis.delay = rl9;\r
1371                                 e.link9 = newmis;\r
1372                         }\r
1373                         if (rl10 > -1)\r
1374                         {\r
1375                                 newmis = spawn();\r
1376                                 newmis.classname = "remotelinker";\r
1377                                 newmis.delay = rl10;\r
1378                                 e.link10 = newmis;\r
1379                         }\r
1380                         if (rl11 > -1)\r
1381                         {\r
1382                                 newmis = spawn();\r
1383                                 newmis.classname = "remotelinker";\r
1384                                 newmis.delay = rl11;\r
1385                                 e.link11 = newmis;\r
1386                         }\r
1387                         if (rl12 > -1)\r
1388                         {\r
1389                                 newmis = spawn();\r
1390                                 newmis.classname = "remotelinker";\r
1391                                 newmis.delay = rl12;\r
1392                                 e.link12 = newmis;\r
1393                         }\r
1394                         if (rl13 > -1)\r
1395                         {\r
1396                                 newmis = spawn();\r
1397                                 newmis.classname = "remotelinker";\r
1398                                 newmis.delay = rl13;\r
1399                                 e.link13 = newmis;\r
1400                         }\r
1401                         if (rl14 > -1)\r
1402                         {\r
1403                                 newmis = spawn();\r
1404                                 newmis.classname = "remotelinker";\r
1405                                 newmis.delay = rl14;\r
1406                                 e.link14 = newmis;\r
1407                         }\r
1408                         if (rl15 > -1)\r
1409                         {\r
1410                                 newmis = spawn();\r
1411                                 newmis.classname = "remotelinker";\r
1412                                 newmis.delay = rl15;\r
1413                                 e.link15 = newmis;\r
1414                         }\r
1415                         if (rl16 > -1)\r
1416                         {\r
1417                                 newmis = spawn();\r
1418                                 newmis.classname = "remotelinker";\r
1419                                 newmis.delay = rl16;\r
1420                                 e.link16 = newmis;\r
1421                         }\r
1422                         if (rl17 > -1)\r
1423                         {\r
1424                                 newmis = spawn();\r
1425                                 newmis.classname = "remotelinker";\r
1426                                 newmis.delay = rl17;\r
1427                                 e.link17 = newmis;\r
1428                         }\r
1429                         if (rl18 > -1)\r
1430                         {\r
1431                                 newmis = spawn();\r
1432                                 newmis.classname = "remotelinker";\r
1433                                 newmis.delay = rl18;\r
1434                                 e.link18 = newmis;\r
1435                         }\r
1436                         if (rl19 > -1)\r
1437                         {\r
1438                                 newmis = spawn();\r
1439                                 newmis.classname = "remotelinker";\r
1440                                 newmis.delay = rl19;\r
1441                                 e.link19 = newmis;\r
1442                         }\r
1443                         FixPlanes(e);\r
1444                 }\r
1445                 fclose(file);\r
1446         }\r
1447         remove(plane_storage);\r
1448         plane_storage = world;\r
1449         LinkNavNodes();\r
1450 };\r
1451 \r
1452 void() SaveNavNodes =\r
1453 {\r
1454         local float file, length;\r
1455         local float tfl0, tfl1, tfl2, tfl3, tfl4, tfl5, tfl6, tfl7, tfl8, tfl9;\r
1456         local float tfl10, tfl11, tfl12, tfl13, tfl14, tfl15, tfl16, tfl17, tfl18, tfl19;\r
1457         local string s;\r
1458         local entity e, e2;\r
1459 \r
1460         length = strlen(world.model);\r
1461         length = length - 5;\r
1462         s = substring(world.model, 5, length);\r
1463         s = strcat(s, ".nnl");\r
1464 \r
1465         file = fopen(s, FILE_WRITE);\r
1466 \r
1467         if (file >= 0)\r
1468         {\r
1469                 e = navnode_chain;\r
1470                 while (e)\r
1471                 {\r
1472                         fputs(file, "navnode\n");\r
1473                         fputs(file, ftos(e.origin_x));\r
1474                         fputs(file, " ");\r
1475                         fputs(file, ftos(e.origin_y));\r
1476                         fputs(file, " ");\r
1477                         fputs(file, ftos(e.origin_z));\r
1478                         fputs(file, "\n");\r
1479                         fputs(file, ftos(e.mins_x));\r
1480                         fputs(file, " ");\r
1481                         fputs(file, ftos(e.mins_y));\r
1482                         fputs(file, " ");\r
1483                         fputs(file, ftos(e.mins_z));\r
1484                         fputs(file, "\n");\r
1485                         fputs(file, ftos(e.maxs_x));\r
1486                         fputs(file, " ");\r
1487                         fputs(file, ftos(e.maxs_y));\r
1488                         fputs(file, " ");\r
1489                         fputs(file, ftos(e.maxs_z));\r
1490                         fputs(file, "\n");\r
1491                         if (e.plane_chain)\r
1492                         {\r
1493                                 e2 = e.plane_chain;\r
1494                                 fputs(file, "plane\n");\r
1495                                 fputs(file, ftos(e2.mangle_x));\r
1496                                 fputs(file, " ");\r
1497                                 fputs(file, ftos(e2.mangle_y));\r
1498                                 fputs(file, " ");\r
1499                                 fputs(file, ftos(e2.mangle_z));\r
1500                                 fputs(file, "\n");\r
1501                                 fputs(file, ftos(e2.delay));\r
1502                                 fputs(file, "\n");\r
1503                                 e2 = e2.plane_next;\r
1504                                 while (e2 != e.plane_chain)\r
1505                                 {\r
1506                                         fputs(file, "plane\n");\r
1507                                         fputs(file, ftos(e2.mangle_x));\r
1508                                         fputs(file, " ");\r
1509                                         fputs(file, ftos(e2.mangle_y));\r
1510                                         fputs(file, " ");\r
1511                                         fputs(file, ftos(e2.mangle_z));\r
1512                                         fputs(file, "\n");\r
1513                                         fputs(file, ftos(e2.delay));\r
1514                                         fputs(file, "\n");\r
1515                                         e2 = e2.plane_next;\r
1516                                 }\r
1517                         }\r
1518                         if (e.lflags0 & LF_REMOTE)\r
1519                         {\r
1520                                 fputs(file, "remote0\n");\r
1521                                 fputs(file, ftos(e.link0.delay));\r
1522                                 fputs(file, "\n");\r
1523                         }\r
1524                         if (e.lflags1 & LF_REMOTE)\r
1525                         {\r
1526                                 fputs(file, "remote1\n");\r
1527                                 fputs(file, ftos(e.link1.delay));\r
1528                                 fputs(file, "\n");\r
1529                         }\r
1530                         if (e.lflags2 & LF_REMOTE)\r
1531                         {\r
1532                                 fputs(file, "remote2\n");\r
1533                                 fputs(file, ftos(e.link2.delay));\r
1534                                 fputs(file, "\n");\r
1535                         }\r
1536                         if (e.lflags3 & LF_REMOTE)\r
1537                         {\r
1538                                 fputs(file, "remote3\n");\r
1539                                 fputs(file, ftos(e.link3.delay));\r
1540                                 fputs(file, "\n");\r
1541                         }\r
1542                         if (e.lflags4 & LF_REMOTE)\r
1543                         {\r
1544                                 fputs(file, "remote4\n");\r
1545                                 fputs(file, ftos(e.link4.delay));\r
1546                                 fputs(file, "\n");\r
1547                         }\r
1548                         if (e.lflags5 & LF_REMOTE)\r
1549                         {\r
1550                                 fputs(file, "remote5\n");\r
1551                                 fputs(file, ftos(e.link5.delay));\r
1552                                 fputs(file, "\n");\r
1553                         }\r
1554                         if (e.lflags6 & LF_REMOTE)\r
1555                         {\r
1556                                 fputs(file, "remote6\n");\r
1557                                 fputs(file, ftos(e.link6.delay));\r
1558                                 fputs(file, "\n");\r
1559                         }\r
1560                         if (e.lflags7 & LF_REMOTE)\r
1561                         {\r
1562                                 fputs(file, "remote7\n");\r
1563                                 fputs(file, ftos(e.link7.delay));\r
1564                                 fputs(file, "\n");\r
1565                         }\r
1566                         if (e.lflags8 & LF_REMOTE)\r
1567                         {\r
1568                                 fputs(file, "remote8\n");\r
1569                                 fputs(file, ftos(e.link8.delay));\r
1570                                 fputs(file, "\n");\r
1571                         }\r
1572                         if (e.lflags9 & LF_REMOTE)\r
1573                         {\r
1574                                 fputs(file, "remote9\n");\r
1575                                 fputs(file, ftos(e.link9.delay));\r
1576                                 fputs(file, "\n");\r
1577                         }\r
1578                         if (e.lflags10 & LF_REMOTE)\r
1579                         {\r
1580                                 fputs(file, "remote10\n");\r
1581                                 fputs(file, ftos(e.link10.delay));\r
1582                                 fputs(file, "\n");\r
1583                         }\r
1584                         if (e.lflags11 & LF_REMOTE)\r
1585                         {\r
1586                                 fputs(file, "remote11\n");\r
1587                                 fputs(file, ftos(e.link11.delay));\r
1588                                 fputs(file, "\n");\r
1589                         }\r
1590                         if (e.lflags12 & LF_REMOTE)\r
1591                         {\r
1592                                 fputs(file, "remote12\n");\r
1593                                 fputs(file, ftos(e.link12.delay));\r
1594                                 fputs(file, "\n");\r
1595                         }\r
1596                         if (e.lflags13 & LF_REMOTE)\r
1597                         {\r
1598                                 fputs(file, "remote13\n");\r
1599                                 fputs(file, ftos(e.link13.delay));\r
1600                                 fputs(file, "\n");\r
1601                         }\r
1602                         if (e.lflags14 & LF_REMOTE)\r
1603                         {\r
1604                                 fputs(file, "remote14\n");\r
1605                                 fputs(file, ftos(e.link14.delay));\r
1606                                 fputs(file, "\n");\r
1607                         }\r
1608                         if (e.lflags15 & LF_REMOTE)\r
1609                         {\r
1610                                 fputs(file, "remote15\n");\r
1611                                 fputs(file, ftos(e.link15.delay));\r
1612                                 fputs(file, "\n");\r
1613                         }\r
1614                         if (e.lflags16 & LF_REMOTE)\r
1615                         {\r
1616                                 fputs(file, "remote16\n");\r
1617                                 fputs(file, ftos(e.link16.delay));\r
1618                                 fputs(file, "\n");\r
1619                         }\r
1620                         if (e.lflags17 & LF_REMOTE)\r
1621                         {\r
1622                                 fputs(file, "remote17\n");\r
1623                                 fputs(file, ftos(e.link17.delay));\r
1624                                 fputs(file, "\n");\r
1625                         }\r
1626                         if (e.lflags18 & LF_REMOTE)\r
1627                         {\r
1628                                 fputs(file, "remote18\n");\r
1629                                 fputs(file, ftos(e.link18.delay));\r
1630                                 fputs(file, "\n");\r
1631                         }\r
1632                         if (e.lflags19 & LF_REMOTE)\r
1633                         {\r
1634                                 fputs(file, "remote19\n");\r
1635                                 fputs(file, ftos(e.link19.delay));\r
1636                                 fputs(file, "\n");\r
1637                         }\r
1638                         tfl0 = e.lflags0 - (e.lflags0 & LF_REMOTE);\r
1639                         tfl1 = e.lflags1 - (e.lflags1 & LF_REMOTE);\r
1640                         tfl2 = e.lflags2 - (e.lflags2 & LF_REMOTE);\r
1641                         tfl3 = e.lflags3 - (e.lflags3 & LF_REMOTE);\r
1642                         tfl4 = e.lflags4 - (e.lflags4 & LF_REMOTE);\r
1643                         tfl5 = e.lflags5 - (e.lflags5 & LF_REMOTE);\r
1644                         tfl6 = e.lflags6 - (e.lflags6 & LF_REMOTE);\r
1645                         tfl7 = e.lflags7 - (e.lflags7 & LF_REMOTE);\r
1646                         tfl8 = e.lflags8 - (e.lflags8 & LF_REMOTE);\r
1647                         tfl9 = e.lflags9 - (e.lflags9 & LF_REMOTE);\r
1648                         tfl10 = e.lflags10 - (e.lflags10 & LF_REMOTE);\r
1649                         tfl11 = e.lflags11 - (e.lflags11 & LF_REMOTE);\r
1650                         tfl12 = e.lflags12 - (e.lflags12 & LF_REMOTE);\r
1651                         tfl13 = e.lflags13 - (e.lflags13 & LF_REMOTE);\r
1652                         tfl14 = e.lflags14 - (e.lflags14 & LF_REMOTE);\r
1653                         tfl15 = e.lflags15 - (e.lflags15 & LF_REMOTE);\r
1654                         tfl16 = e.lflags16 - (e.lflags16 & LF_REMOTE);\r
1655                         tfl17 = e.lflags17 - (e.lflags17 & LF_REMOTE);\r
1656                         tfl18 = e.lflags18 - (e.lflags18 & LF_REMOTE);\r
1657                         tfl19 = e.lflags19 - (e.lflags19 & LF_REMOTE);\r
1658                         if (e.sflags)\r
1659                         {\r
1660                                 fputs(file, "sflags\n");\r
1661                                 fputs(file, ftos(e.sflags));\r
1662                                 fputs(file, "\n");\r
1663                         }\r
1664                         if (tfl0)\r
1665                         {\r
1666                                 fputs(file, "lflags0\n");\r
1667                                 fputs(file, ftos(tfl0));\r
1668                                 fputs(file, "\n");\r
1669                         }\r
1670                         if (tfl1)\r
1671                         {\r
1672                                 fputs(file, "lflags1\n");\r
1673                                 fputs(file, ftos(tfl1));\r
1674                                 fputs(file, "\n");\r
1675                         }\r
1676                         if (tfl2)\r
1677                         {\r
1678                                 fputs(file, "lflags2\n");\r
1679                                 fputs(file, ftos(tfl2));\r
1680                                 fputs(file, "\n");\r
1681                         }\r
1682                         if (tfl3)\r
1683                         {\r
1684                                 fputs(file, "lflags3\n");\r
1685                                 fputs(file, ftos(tfl3));\r
1686                                 fputs(file, "\n");\r
1687                         }\r
1688                         if (tfl4)\r
1689                         {\r
1690                                 fputs(file, "lflags4\n");\r
1691                                 fputs(file, ftos(tfl4));\r
1692                                 fputs(file, "\n");\r
1693                         }\r
1694                         if (tfl5)\r
1695                         {\r
1696                                 fputs(file, "lflags5\n");\r
1697                                 fputs(file, ftos(tfl5));\r
1698                                 fputs(file, "\n");\r
1699                         }\r
1700                         if (tfl6)\r
1701                         {\r
1702                                 fputs(file, "lflags6\n");\r
1703                                 fputs(file, ftos(tfl6));\r
1704                                 fputs(file, "\n");\r
1705                         }\r
1706                         if (tfl7)\r
1707                         {\r
1708                                 fputs(file, "lflags7\n");\r
1709                                 fputs(file, ftos(tfl7));\r
1710                                 fputs(file, "\n");\r
1711                         }\r
1712                         if (tfl8)\r
1713                         {\r
1714                                 fputs(file, "lflags8\n");\r
1715                                 fputs(file, ftos(tfl8));\r
1716                                 fputs(file, "\n");\r
1717                         }\r
1718                         if (tfl9)\r
1719                         {\r
1720                                 fputs(file, "lflags9\n");\r
1721                                 fputs(file, ftos(tfl9));\r
1722                                 fputs(file, "\n");\r
1723                         }\r
1724                         if (tfl10)\r
1725                         {\r
1726                                 fputs(file, "lflags10\n");\r
1727                                 fputs(file, ftos(tfl10));\r
1728                                 fputs(file, "\n");\r
1729                         }\r
1730                         if (tfl11)\r
1731                         {\r
1732                                 fputs(file, "lflags11\n");\r
1733                                 fputs(file, ftos(tfl11));\r
1734                                 fputs(file, "\n");\r
1735                         }\r
1736                         if (tfl12)\r
1737                         {\r
1738                                 fputs(file, "lflags12\n");\r
1739                                 fputs(file, ftos(tfl12));\r
1740                                 fputs(file, "\n");\r
1741                         }\r
1742                         if (tfl13)\r
1743                         {\r
1744                                 fputs(file, "lflags13\n");\r
1745                                 fputs(file, ftos(tfl13));\r
1746                                 fputs(file, "\n");\r
1747                         }\r
1748                         if (tfl14)\r
1749                         {\r
1750                                 fputs(file, "lflags14\n");\r
1751                                 fputs(file, ftos(tfl14));\r
1752                                 fputs(file, "\n");\r
1753                         }\r
1754                         if (tfl15)\r
1755                         {\r
1756                                 fputs(file, "lflags15\n");\r
1757                                 fputs(file, ftos(tfl15));\r
1758                                 fputs(file, "\n");\r
1759                         }\r
1760                         if (tfl16)\r
1761                         {\r
1762                                 fputs(file, "lflags16\n");\r
1763                                 fputs(file, ftos(tfl16));\r
1764                                 fputs(file, "\n");\r
1765                         }\r
1766                         if (tfl17)\r
1767                         {\r
1768                                 fputs(file, "lflags17\n");\r
1769                                 fputs(file, ftos(tfl17));\r
1770                                 fputs(file, "\n");\r
1771                         }\r
1772                         if (tfl18)\r
1773                         {\r
1774                                 fputs(file, "lflags18\n");\r
1775                                 fputs(file, ftos(tfl18));\r
1776                                 fputs(file, "\n");\r
1777                         }\r
1778                         if (tfl19)\r
1779                         {\r
1780                                 fputs(file, "lflags19\n");\r
1781                                 fputs(file, ftos(tfl19));\r
1782                                 fputs(file, "\n");\r
1783                         }\r
1784                         e = e.list;\r
1785                 }\r
1786         }\r
1787         fclose(file);\r
1788 };