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