2 BobToolz plugin for GtkRadiant
3 Copyright (C) 2001 Gordon Biggans
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.
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.
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
22 #include "gtkr_list.h"
32 #include "ScriptParser.h"
35 #include "DTreePlanter.h"
38 #include "funchandlers.h"
40 bool DTreePlanter::OnMouseMove(guint32 nFlags, gdouble x, gdouble y) {
44 bool DTreePlanter::OnLButtonDown(guint32 nFlags, gdouble x, gdouble y) {
45 VIEWTYPE vt = m_XYWrapper->GetViewType();
58 m_XYWrapper->SnapToGrid( static_cast<int>(x), static_cast<int>(y), pt );
60 if(FindDropPoint(pt, vhit)) {
66 sprintf(buffer, "%i %i %i", (int)vhit[0], (int)vhit[1], (int)vhit[2]);
67 e.AddEPair("origin", buffer);
71 entity_t* pLastEntity = NULL;
72 entity_t* pThisEntity = NULL;
74 int entNum = -1, lastEntNum = -1, entpos;
75 for(int i = 0; i < 256; i++) {
76 sprintf(buffer, m_linkName, i);
77 pThisEntity = FindEntityFromTargetname( buffer, &entNum );
82 pLastEntity = pThisEntity;
87 sprintf(buffer, m_linkName, 0);
89 sprintf(buffer, m_linkName, entpos + 1);
92 e.AddEPair( "targetname", buffer );
96 e2.LoadFromEntity(lastEntNum, TRUE);
97 e2.AddEPair("target", buffer);
98 e2.RemoveFromRadiant();
99 e2.BuildInRadiant(FALSE);
105 int angleYaw = (rand() % (m_maxYaw - m_minYaw + 1)) + m_minYaw;
106 int anglePitch = (rand() % (m_maxPitch - m_minPitch + 1)) + m_minPitch;
108 sprintf(buffer, "%i %i 0", anglePitch, angleYaw);
109 e.AddEPair("angles", buffer);
113 int treetype = rand() % m_numModels;
114 e.AddEPair("model", m_trees[treetype].name);
118 float scale = (((rand()%1000)*0.001f) * (m_maxScale - m_minScale)) + m_minScale;
120 sprintf(buffer, "%f", scale );
121 e.AddEPair("modelscale", buffer);
124 e.BuildInRadiant( FALSE );
134 bool DTreePlanter::OnLButtonUp(guint32 nFlags, gdouble x, gdouble y) {
138 bool DTreePlanter::OnRButtonDown(guint32 nFlags, gdouble x, gdouble y) {
142 bool DTreePlanter::OnRButtonUp(guint32 nFlags, gdouble x, gdouble y) {
146 bool DTreePlanter::OnMButtonDown(guint32 nFlags, gdouble x, gdouble y) {
150 bool DTreePlanter::OnMButtonUp(guint32 nFlags, gdouble x, gdouble y) {
154 bool DTreePlanter::FindDropPoint(vec3_t in, vec3_t out) {
158 vec3_t vUp = { 0, 0, 1 };
159 vec3_t vForward = { 0, 1, 0 };
160 vec3_t vLeft = { 1, 0, 0 };
164 VectorCopy(in, p1.points[0]);
165 VectorCopy(in, p1.points[1]);
166 VectorCopy(in, p1.points[2]);
167 VectorMA(p1.points[1], 20, vUp, p1.points[1]);
168 VectorMA(p1.points[1], 20, vLeft, p1.points[2]);
170 VectorCopy(in, p2.points[0]);
171 VectorCopy(in, p2.points[1]);
172 VectorCopy(in, p2.points[2]);
173 VectorMA(p1.points[1], 20, vUp, p2.points[1]);
174 VectorMA(p1.points[1], 20, vForward, p2.points[2]);
182 int cnt = m_world.GetIDMax();
183 for(int i = 0; i < cnt; i++) {
184 DBrush* pBrush = m_world.GetBrushForID( i );
186 if(pBrush->IntersectsWith( &p1, &p2, temp )) {
189 VectorSubtract(in, temp, diff);
190 tempdist = VectorLength( diff );
191 if(!found || (tempdist < dist)) {
193 VectorCopy( temp, out );
202 void DTreePlanter::DropEntsToGround( void ) {
204 // tell Radiant we want to access the selected brushes
205 g_FuncTable.m_pfnAllocateSelectedBrushHandles();
209 int cnt = g_FuncTable.m_pfnSelectedBrushCount();
210 for(int i = 0; i < cnt; i++) {
211 brush_t *brush = (brush_t*)g_FuncTable.m_pfnGetSelectedBrushHandle(i);
213 ent.LoadFromEntity(brush->owner, TRUE);
215 DEPair* pEpair = ent.FindEPairByKey("origin");
221 sscanf( pEpair->value.GetBuffer(), "%f %f %f", &vec[0], &vec[1], &vec[2]);
223 FindDropPoint( vec, out );
226 sprintf( buffer, "%f %f %f", out[0], out[1], out[2] );
227 ent.AddEPair( "origin", buffer );
228 ent.RemoveFromRadiant();
229 ent.BuildInRadiant(FALSE);
232 g_FuncTable.m_pfnReleaseSelectedBrushHandles();
236 void DTreePlanter::MakeChain( void ) {
240 for(i = 0; i < m_linkNum; i++) {
241 DEntity e("info_train_spline_main");
243 sprintf( buffer, "%s_pt%i", m_linkName, i );
244 e.AddEPair( "targetname", buffer );
246 sprintf( buffer, "0 %i 0", i * 64 );
247 e.AddEPair( "origin", buffer );
249 if(i != m_linkNum-1) {
250 sprintf( buffer, "%s_pt%i", m_linkName, i+1 );
251 e.AddEPair( "target", buffer );
253 sprintf( buffer, "%s_ctl%i", m_linkName, i );
254 e.AddEPair( "control", buffer );
257 e.BuildInRadiant( FALSE );
260 for(i = 0; i < m_linkNum-1; i++) {
261 DEntity e("info_train_spline_control");
263 sprintf( buffer, "%s_ctl%i", m_linkName, i );
264 e.AddEPair( "targetname", buffer );
266 sprintf( buffer, "0 %i 0", (i * 64) + 32);
267 e.AddEPair( "origin", buffer );
269 e.BuildInRadiant( FALSE );
273 void DTreePlanter::SelectChain( void ) {
276 for(int i = 0; i < m_linkNum; i++) {
277 DEntity e("info_train_spline_main");
279 sprintf( buffer, "%s_pt%i", m_linkName, i );
280 e.AddEPair( "targetname", buffer );
282 sprintf( buffer, "0 %i 0", i * 64 );
283 e.AddEPair( "origin", buffer );
285 if(i != m_linkNum-1) {
286 sprintf( buffer, "%s_pt%i", m_linkName, i+1 );
287 e.AddEPair( "target", buffer );
289 sprintf( buffer, "%s_ctl%i", m_linkName, i );
290 e.AddEPair( "control", buffer );
293 e.BuildInRadiant( FALSE );
296 for(int i = 0; i < m_linkNum-1; i++) {
297 DEntity e("info_train_spline_control");
299 sprintf( buffer, "%s_ctl%i", m_linkName, i );
300 e.AddEPair( "targetname", buffer );
302 sprintf( buffer, "0 %i 0", (i * 64) + 32);
303 e.AddEPair( "origin", buffer );
305 e.BuildInRadiant( FALSE );