Debian Codegraph @

contrib/bobtoolz/DTreePlanter.h

raw symbols SCIP
1 /*
2 BobToolz plugin for GtkRadiant
3 Copyright (C) 2001 Gordon Biggans
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20 #ifndef __DTREE_H__
21 #define __DTREE_H__
22
23 #include "qerplugin.h"
24 #include "signal/isignal.h"
25 #include "string/string.h"
26
27 #include "DEntity.h"
28 #include "ScriptParser.h"
29 #include "mathlib.h"
30 #include "misc.h"
31
32 const int MAX_QPATH = 64;
33
34 typedef struct treeModel_s {
35 char name[MAX_QPATH];
36 } treeModel_t;
37
38 const int MAX_TP_MODELS = 256;
39
40 class DTreePlanter {
41 MouseEventHandlerId m_mouseDown;
42 SignalHandlerId m_destroyed;
43 public:
44 SignalHandlerResult mouseDown( const WindowVector& position, ButtonIdentifier button, ModifierFlags modifiers );
45 typedef Member<DTreePlanter, SignalHandlerResult(const WindowVector&, ButtonIdentifier, ModifierFlags), &DTreePlanter::mouseDown> MouseDownCaller;
46 void destroyed(){
47 m_mouseDown = MouseEventHandlerId();
48 m_destroyed = SignalHandlerId();
49 }
50 typedef Member<DTreePlanter, void(), &DTreePlanter::destroyed> DestroyedCaller;
51
52 DTreePlanter() {
53 m_numModels = 0;
54 m_offset = 0;
55 m_maxPitch = 0;
56 m_minPitch = 0;
57 m_maxYaw = 0;
58 m_minYaw = 0;
59 m_setAngles = false;
60 m_useScale = false;
61 m_autoLink = false;
62 m_linkNum = 0;
63
64 m_world.LoadSelectedBrushes();
65
66 char buffer[256];
67 GetFilename( buffer, "bt/tp_ent.txt" );
68
69 FILE* file = fopen( buffer, "rb" );
70 if ( file ) {
71 fseek( file, 0, SEEK_END );
72 int len = ftell( file );
73 fseek( file, 0, SEEK_SET );
74
75 if ( len ) {
76 char* buf = new char[len + 1];
77 buf[len] = '\0';
78 // parser will do the cleanup, dont delete.
79
80 fread( buf, len, 1, file );
81
82 CScriptParser parser;
83 parser.SetScript( buf );
84
85 ReadConfig( &parser );
86 }
87
88 fclose( file );
89 }
90
91 m_mouseDown = GlobalRadiant().XYWindowMouseDown_connect( makeSignalHandler3( MouseDownCaller(), *this ) );
92 m_destroyed = GlobalRadiant().XYWindowDestroyed_connect( makeSignalHandler( DestroyedCaller(), *this ) );
93 }
94
95 virtual ~DTreePlanter(){
96 if ( !m_mouseDown.isNull() ) {
97 GlobalRadiant().XYWindowMouseDown_disconnect( m_mouseDown );
98 }
99 if ( !m_destroyed.isNull() ) {
100 GlobalRadiant().XYWindowDestroyed_disconnect( m_destroyed );
101 }
102 }
103
104 #define MT( t ) string_equal_nocase( pToken, t )
105 #define GT pToken = pScriptParser->GetToken( true )
106 #define CT if ( !*pToken ) { return; }
107
108 void ReadConfig( CScriptParser* pScriptParser ) {
109 const char* GT;
110 CT;
111
112 do {
113 GT;
114 if ( *pToken == '}' ) {
115 break;
116 }
117
118 if ( MT( "model" ) ) {
119 if ( m_numModels >= MAX_TP_MODELS ) {
120 return;
121 }
122
123 GT; CT;
124
125 strncpy( m_trees[m_numModels++].name, pToken, MAX_QPATH );
126 }
127 else if ( MT( "link" ) ) {
128 GT; CT;
129
130 strncpy( m_linkName, pToken, MAX_QPATH );
131
132 m_autoLink = true;
133 }
134 else if ( MT( "entity" ) ) {
135 GT; CT;
136
137 strncpy( m_entType, pToken, MAX_QPATH );
138 }
139 else if ( MT( "offset" ) ) {
140 GT; CT;
141
142 m_offset = atoi( pToken );
143 }
144 else if ( MT( "pitch" ) ) {
145 GT; CT;
146
147 m_minPitch = atoi( pToken );
148
149 GT; CT;
150
151 m_maxPitch = atoi( pToken );
152
153 m_setAngles = true;
154 }
155 else if ( MT( "yaw" ) ) {
156 GT; CT;
157
158 m_minYaw = atoi( pToken );
159
160 GT; CT;
161
162 m_maxYaw = atoi( pToken );
163
164 m_setAngles = true;
165 }
166 else if ( MT( "scale" ) ) {
167 GT; CT;
168
169 m_minScale = static_cast<float>( atof( pToken ) );
170
171 GT; CT;
172
173 m_maxScale = static_cast<float>( atof( pToken ) );
174
175 m_useScale = true;
176 }
177 else if ( MT( "numlinks" ) ) {
178 GT; CT;
179
180 m_linkNum = atoi( pToken );
181 }
182 } while ( true );
183 }
184
185 bool FindDropPoint( vec3_t in, vec3_t out );
186 void DropEntsToGround( void );
187 void MakeChain( int linkNum, const char* linkName );
188 void SelectChain( void );
189
190 private:
191 DEntity m_world;
192
193 treeModel_t m_trees[MAX_TP_MODELS];
194
195 int m_numModels;
196 int m_offset;
197 int m_maxPitch;
198 int m_minPitch;
199 int m_maxYaw;
200 int m_minYaw;
201
202 char m_entType[MAX_QPATH];
203 char m_linkName[MAX_QPATH];
204 int m_linkNum;
205
206 float m_minScale;
207 float m_maxScale;
208
209 bool m_useScale;
210 bool m_setAngles;
211 bool m_autoLink;
212 };
213
214 #endif