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