]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - tools/quake3/q3map2/leakfile.c
e8108c6fbe22dbb0ac873b1d1a29a0c865604f49
[xonotic/netradiant.git] / tools / quake3 / q3map2 / leakfile.c
1 /*\r
2 Copyright (C) 1999-2007 id Software, Inc. and contributors.\r
3 For a list of contributors, see the accompanying CONTRIBUTORS file.\r
4 \r
5 This file is part of GtkRadiant.\r
6 \r
7 GtkRadiant is free software; you can redistribute it and/or modify\r
8 it under the terms of the GNU General Public License as published by\r
9 the Free Software Foundation; either version 2 of the License, or\r
10 (at your option) any later version.\r
11 \r
12 GtkRadiant is distributed in the hope that it will be useful,\r
13 but WITHOUT ANY WARRANTY; without even the implied warranty of\r
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
15 GNU General Public License for more details.\r
16 \r
17 You should have received a copy of the GNU General Public License\r
18 along with GtkRadiant; if not, write to the Free Software\r
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\r
20 \r
21 ----------------------------------------------------------------------------------\r
22 \r
23 This code has been altered significantly from its original form, to support\r
24 several games based on the Quake III Arena engine, in the form of "Q3Map2."\r
25 \r
26 ------------------------------------------------------------------------------- */\r
27 \r
28 \r
29 \r
30 /* marker */\r
31 #define LEAKFILE_C\r
32 \r
33 \r
34 \r
35 /* dependencies */\r
36 #include "q3map2.h"\r
37 \r
38 \r
39 \r
40 /*\r
41 ==============================================================================\r
42 \r
43 LEAK FILE GENERATION\r
44 \r
45 Save out name.line for qe3 to read\r
46 ==============================================================================\r
47 */\r
48 \r
49 \r
50 /*\r
51 =============\r
52 LeakFile\r
53 \r
54 Finds the shortest possible chain of portals\r
55 that leads from the outside leaf to a specifically\r
56 occupied leaf\r
57 \r
58 TTimo: builds a polyline xml node\r
59 =============\r
60 */\r
61 xmlNodePtr LeakFile (tree_t *tree)\r
62 {\r
63         vec3_t  mid;\r
64         FILE    *linefile;\r
65         char    filename[1024];\r
66         node_t  *node;\r
67         int             count;\r
68         xmlNodePtr xml_node, point;\r
69 \r
70         if (!tree->outside_node.occupied)\r
71                 return NULL;\r
72 \r
73         Sys_FPrintf (SYS_VRB,"--- LeakFile ---\n");\r
74 \r
75         //\r
76         // write the points to the file\r
77         //\r
78         sprintf (filename, "%s.lin", source);\r
79         linefile = fopen (filename, "w");\r
80         if (!linefile)\r
81                 Error ("Couldn't open %s\n", filename);\r
82 \r
83   xml_node = xmlNewNode (NULL, "polyline");\r
84 \r
85         count = 0;\r
86         node = &tree->outside_node;\r
87         while (node->occupied > 1)\r
88         {\r
89                 int                     next;\r
90                 portal_t        *p, *nextportal;\r
91                 node_t          *nextnode;\r
92                 int                     s;\r
93 \r
94                 // find the best portal exit\r
95                 next = node->occupied;\r
96                 for (p=node->portals ; p ; p = p->next[!s])\r
97                 {\r
98                         s = (p->nodes[0] == node);\r
99                         if (p->nodes[s]->occupied\r
100                                 && p->nodes[s]->occupied < next)\r
101                         {\r
102                                 nextportal = p;\r
103                                 nextnode = p->nodes[s];\r
104                                 next = nextnode->occupied;\r
105                         }\r
106                 }\r
107                 node = nextnode;\r
108                 WindingCenter (nextportal->winding, mid);\r
109                 fprintf (linefile, "%f %f %f\n", mid[0], mid[1], mid[2]);\r
110                 point = xml_NodeForVec(mid);\r
111                 xmlAddChild(xml_node, point);\r
112                 count++;\r
113         }\r
114         // add the occupant center\r
115         GetVectorForKey (node->occupant, "origin", mid);\r
116 \r
117         fprintf (linefile, "%f %f %f\n", mid[0], mid[1], mid[2]);\r
118         point = xml_NodeForVec(mid);\r
119         xmlAddChild(xml_node, point);\r
120         Sys_FPrintf( SYS_VRB, "%9d point linefile\n", count+1);\r
121 \r
122         fclose (linefile);\r
123         \r
124         return xml_node;\r
125 }\r
126 \r