]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - contrib/bobtoolz/DTreePlanter.h
61bc1e8950e50130b2a4a79250aa1954ce0e21d7
[xonotic/netradiant.git] / contrib / bobtoolz / DTreePlanter.h
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 #define MAX_QPATH 64
33
34 typedef struct treeModel_s {
35         char name[MAX_QPATH];
36 } treeModel_t;
37
38 #define MAX_TP_MODELS 256
39
40 class DTreePlanter {
41   MouseEventHandlerId m_mouseDown;
42 public:
43         SignalHandlerResult mouseDown(const WindowVector& position, ButtonIdentifier button, ModifierFlags modifiers);
44   typedef Member3<DTreePlanter, const WindowVector&, ButtonIdentifier, ModifierFlags, SignalHandlerResult, &DTreePlanter::mouseDown> MouseDownCaller;
45
46   DTreePlanter() {
47                 m_numModels =   0;
48                 m_offset =              0;
49                 m_maxPitch =    0;
50                 m_minPitch =    0;
51                 m_maxYaw =              0;
52                 m_minYaw =              0;
53                 m_setAngles =   false;
54                 m_useScale =    false;
55                 m_autoLink =    false;
56                 m_linkNum =             0;
57
58                 m_world.LoadSelectedBrushes();
59
60                 char buffer[256];
61                 GetFilename( buffer, "bt/tp_ent.txt" );
62
63                 FILE* file = fopen( buffer, "rb" );
64                 if(file) {
65                         fseek( file, 0, SEEK_END );
66                         int len = ftell( file );
67                         fseek( file, 0, SEEK_SET );
68
69                         if(len) {
70                                 char* buf = new char[len+1];
71                                 buf[len] = '\0';
72                                 // parser will do the cleanup, dont delete.
73
74                                 fread( buf, len, 1, file );
75
76                                 CScriptParser parser;
77                                 parser.SetScript( buf );
78
79                                 ReadConfig( &parser );
80                         }
81
82                         fclose( file );
83                 }
84
85     m_mouseDown = GlobalRadiant().XYWindowMouseDown_connect(makeSignalHandler3(MouseDownCaller(), *this));
86         }
87
88   virtual ~DTreePlanter()
89   {
90     GlobalRadiant().XYWindowMouseDown_disconnect(m_mouseDown);
91   }
92
93 #define MT(t)   string_equal_nocase( pToken, t )
94 #define GT              pToken = pScriptParser->GetToken( true )
95 #define CT              if(!*pToken) { return; }
96
97         void ReadConfig( CScriptParser* pScriptParser ) {
98                 const char* GT;
99                 CT;
100
101                 do {
102                         GT;
103                         if(*pToken == '}') {
104                                 break;
105                         }
106
107                         if(MT("model")) {
108                                 if(m_numModels >= MAX_TP_MODELS) {
109                                         return;
110                                 }
111
112                                 GT; CT;
113
114                                 strncpy( m_trees[m_numModels++].name, pToken, MAX_QPATH );
115                         } else if(MT("link")) {
116                                 GT; CT;
117
118                                 strncpy( m_linkName, pToken, MAX_QPATH );
119
120                                 m_autoLink = true;
121                         } else if(MT("entity")) {
122                                 GT; CT;
123
124                                 strncpy( m_entType, pToken, MAX_QPATH );
125                         } else if(MT("offset")) {
126                                 GT; CT;
127
128                                 m_offset = atoi(pToken);
129                         } else if(MT("pitch")) {
130                                 GT; CT;
131
132                                 m_minPitch = atoi(pToken);
133
134                                 GT; CT;
135
136                                 m_maxPitch = atoi(pToken);
137
138                                 m_setAngles = true;
139                         } else if(MT("yaw")) {
140                                 GT; CT;
141
142                                 m_minYaw = atoi(pToken);
143
144                                 GT; CT;
145
146                                 m_maxYaw = atoi(pToken);
147
148                                 m_setAngles = true;
149                         } else if(MT("scale")) {
150                                 GT; CT;
151
152                                 m_minScale = static_cast<float>(atof(pToken));
153
154                                 GT; CT;
155
156                                 m_maxScale = static_cast<float>(atof(pToken));
157
158                                 m_useScale = true;
159                         } else if(MT("numlinks")) {
160                                 GT; CT;
161
162                                 m_linkNum = atoi( pToken );
163                         }
164                 } while( true );
165         }
166
167         bool FindDropPoint(vec3_t in, vec3_t out);
168         void DropEntsToGround( void );
169         void MakeChain( void );
170         void SelectChain( void );
171
172 private:
173         DEntity                 m_world;
174
175         treeModel_t             m_trees[MAX_TP_MODELS];
176
177         int                             m_numModels;
178         int                             m_offset;
179         int                             m_maxPitch;
180         int                             m_minPitch;
181         int                             m_maxYaw;
182         int                             m_minYaw;
183
184         char                    m_entType[MAX_QPATH];
185         char                    m_linkName[MAX_QPATH];
186         int                             m_linkNum;
187
188         float                   m_minScale;
189         float                   m_maxScale;
190
191         bool                    m_useScale;
192         bool                    m_setAngles;
193         bool                    m_autoLink;
194 };
195
196 #endif