]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - contrib/bobtoolz/DTreePlanter.cpp
Revert partially (auto) "reformat code! now the code is only ugly on the *inside*"
[xonotic/netradiant.git] / contrib / bobtoolz / DTreePlanter.cpp
index 9207f1ce2472a786a7c9b15e7d26c98849bdb8db..78fa550dee92c91e03799367f95a3bda6c4b3db3 100644 (file)
 #include "scenelib.h"
 
 
+
 #include "funchandlers.h"
 
-SignalHandlerResult
-DTreePlanter::mouseDown(const WindowVector &position, ButtonIdentifier button, ModifierFlags modifiers)
-{
-    if (button != c_buttonLeft) {
-        return SIGNAL_CONTINUE_EMISSION;
-    }
-    VIEWTYPE vt = GlobalRadiant().XYWindow_getViewType();
-
-    switch (vt) {
-        case XY:
-            break;
-        case YZ:
-        case XZ:
-        default:
-            return SIGNAL_CONTINUE_EMISSION;
-    }
+SignalHandlerResult DTreePlanter::mouseDown( const WindowVector& position, ButtonIdentifier button, ModifierFlags modifiers ){
+       if ( button != c_buttonLeft ) {
+               return SIGNAL_CONTINUE_EMISSION;
+       }
+       VIEWTYPE vt = GlobalRadiant().XYWindow_getViewType();
 
-    Vector3 pt, vhit;
+       switch ( vt ) {
+       case XY:
+               break;
+       case YZ:
+       case XZ:
+       default:
+               return SIGNAL_CONTINUE_EMISSION;
+       }
 
-    pt = vector3_snapped(GlobalRadiant().XYWindow_windowToWorld(position), GlobalRadiant().getGridSize());
+       Vector3 pt, vhit;
 
-    if (FindDropPoint(vector3_to_array(pt), vector3_to_array(vhit))) {
-        vhit[2] += m_offset;
+       pt = vector3_snapped( GlobalRadiant().XYWindow_windowToWorld( position ), GlobalRadiant().getGridSize() );
 
-        char buffer[128];
-        DEntity e(m_entType);
+       if ( FindDropPoint( vector3_to_array( pt ), vector3_to_array( vhit ) ) ) {
+               vhit[2] += m_offset;
 
-        sprintf(buffer, "%i %i %i", (int) vhit[0], (int) vhit[1], (int) vhit[2]);
-        e.AddEPair("origin", buffer);
+               char buffer[128];
+               DEntity e( m_entType );
 
-        if (m_autoLink) {
+               sprintf( buffer, "%i %i %i", (int)vhit[0], (int)vhit[1], (int)vhit[2] );
+               e.AddEPair( "origin", buffer );
 
-            const scene::Path *pLastEntity = NULL;
-            const scene::Path *pThisEntity = NULL;
+               if ( m_autoLink ) {
 
-            int entpos;
-            for (int i = 0; i < 256; i++) {
-                sprintf(buffer, m_linkName, i);
-                pThisEntity = FindEntityFromTargetname(buffer);
+                       const scene::Path* pLastEntity = NULL;
+                       const scene::Path* pThisEntity = NULL;
 
-                if (pThisEntity) {
-                    entpos = i;
-                    pLastEntity = pThisEntity;
-                }
-            }
+                       int entpos;
+                       for ( int i = 0; i < 256; i++ ) {
+                               sprintf( buffer, m_linkName, i );
+                               pThisEntity = FindEntityFromTargetname( buffer );
 
-            if (!pLastEntity) {
-                sprintf(buffer, m_linkName, 0);
-            } else {
-                sprintf(buffer, m_linkName, entpos + 1);
-            }
+                               if ( pThisEntity ) {
+                                       entpos = i;
+                                       pLastEntity = pThisEntity;
+                               }
+                       }
 
-            e.AddEPair("targetname", buffer);
+                       if ( !pLastEntity ) {
+                               sprintf( buffer, m_linkName, 0 );
+                       }
+                       else {
+                               sprintf( buffer, m_linkName, entpos + 1 );
+                       }
 
-            if (pLastEntity) {
-                DEntity e2;
-                e2.LoadFromEntity(pLastEntity->top(), true);
-                e2.AddEPair("target", buffer);
-                e2.RemoveFromRadiant();
-                e2.BuildInRadiant(false);
-            }
+                       e.AddEPair( "targetname", buffer );
 
-        }
+                       if ( pLastEntity ) {
+                               DEntity e2;
+                               e2.LoadFromEntity( pLastEntity->top(), true );
+                               e2.AddEPair( "target", buffer );
+                               e2.RemoveFromRadiant();
+                               e2.BuildInRadiant( false );
+                       }
 
-        if (m_setAngles) {
-            int angleYaw = (rand() % (m_maxYaw - m_minYaw + 1)) + m_minYaw;
-            int anglePitch = (rand() % (m_maxPitch - m_minPitch + 1)) + m_minPitch;
+               }
 
-            sprintf(buffer, "%i %i 0", anglePitch, angleYaw);
-            e.AddEPair("angles", buffer);
-        }
+               if ( m_setAngles ) {
+                       int angleYaw = ( rand() % ( m_maxYaw - m_minYaw + 1 ) ) + m_minYaw;
+                       int anglePitch = ( rand() % ( m_maxPitch - m_minPitch + 1 ) ) + m_minPitch;
 
-        if (m_numModels) {
-            int treetype = rand() % m_numModels;
-            e.AddEPair("model", m_trees[treetype].name);
-        }
+                       sprintf( buffer, "%i %i 0", anglePitch, angleYaw );
+                       e.AddEPair( "angles", buffer );
+               }
 
-        if (m_useScale) {
-            float scale = (((rand() % 1000) * 0.001f) * (m_maxScale - m_minScale)) + m_minScale;
+               if ( m_numModels ) {
+                       int treetype = rand() % m_numModels;
+                       e.AddEPair( "model", m_trees[treetype].name );
+               }
 
-            sprintf(buffer, "%f", scale);
-            e.AddEPair("modelscale", buffer);
-        }
+               if ( m_useScale ) {
+                       float scale = ( ( ( rand() % 1000 ) * 0.001f ) * ( m_maxScale - m_minScale ) ) + m_minScale;
 
-        e.BuildInRadiant(false);
-    }
+                       sprintf( buffer, "%f", scale );
+                       e.AddEPair( "modelscale", buffer );
+               }
 
-    if (m_autoLink) {
-        DoTrainPathPlot();
-    }
+               e.BuildInRadiant( false );
+       }
 
-    return SIGNAL_STOP_EMISSION;
-}
+       if ( m_autoLink ) {
+               DoTrainPathPlot();
+       }
 
-bool DTreePlanter::FindDropPoint(vec3_t in, vec3_t out)
-{
-    DPlane p1;
-    DPlane p2;
-
-    vec3_t vUp = {0, 0, 1};
-    vec3_t vForward = {0, 1, 0};
-    vec3_t vLeft = {1, 0, 0};
-
-    in[2] = 65535;
-
-    VectorCopy(in, p1.points[0]);
-    VectorCopy(in, p1.points[1]);
-    VectorCopy(in, p1.points[2]);
-    VectorMA(p1.points[1], 20, vUp, p1.points[1]);
-    VectorMA(p1.points[1], 20, vLeft, p1.points[2]);
-
-    VectorCopy(in, p2.points[0]);
-    VectorCopy(in, p2.points[1]);
-    VectorCopy(in, p2.points[2]);
-    VectorMA(p1.points[1], 20, vUp, p2.points[1]);
-    VectorMA(p1.points[1], 20, vForward, p2.points[2]);
-
-    p1.Rebuild();
-    p2.Rebuild();
-
-    bool found = false;
-    vec3_t temp;
-    vec_t dist;
-    int cnt = m_world.GetIDMax();
-    for (int i = 0; i < cnt; i++) {
-        DBrush *pBrush = m_world.GetBrushForID(i);
-
-        if (pBrush->IntersectsWith(&p1, &p2, temp)) {
-            vec3_t diff;
-            vec_t tempdist;
-            VectorSubtract(in, temp, diff);
-            tempdist = VectorLength(diff);
-            if (!found || (tempdist < dist)) {
-                dist = tempdist;
-                VectorCopy(temp, out);
-                found = true;
-            }
-        }
-    }
+       return SIGNAL_STOP_EMISSION;
+}
 
-    return found;
+bool DTreePlanter::FindDropPoint( vec3_t in, vec3_t out ) {
+       DPlane p1;
+       DPlane p2;
+
+       vec3_t vUp =        { 0, 0, 1 };
+       vec3_t vForward =   { 0, 1, 0 };
+       vec3_t vLeft =      { 1, 0, 0 };
+
+       in[2] = 65535;
+
+       VectorCopy( in, p1.points[0] );
+       VectorCopy( in, p1.points[1] );
+       VectorCopy( in, p1.points[2] );
+       VectorMA( p1.points[1], 20, vUp,         p1.points[1] );
+       VectorMA( p1.points[1], 20, vLeft,       p1.points[2] );
+
+       VectorCopy( in, p2.points[0] );
+       VectorCopy( in, p2.points[1] );
+       VectorCopy( in, p2.points[2] );
+       VectorMA( p1.points[1], 20, vUp,         p2.points[1] );
+       VectorMA( p1.points[1], 20, vForward,    p2.points[2] );
+
+       p1.Rebuild();
+       p2.Rebuild();
+
+       bool found = false;
+       vec3_t temp;
+       vec_t dist;
+       int cnt = m_world.GetIDMax();
+       for ( int i = 0; i < cnt; i++ ) {
+               DBrush* pBrush = m_world.GetBrushForID( i );
+
+               if ( pBrush->IntersectsWith( &p1, &p2, temp ) ) {
+                       vec3_t diff;
+                       vec_t tempdist;
+                       VectorSubtract( in, temp, diff );
+                       tempdist = VectorLength( diff );
+                       if ( !found || ( tempdist < dist ) ) {
+                               dist = tempdist;
+                               VectorCopy( temp, out );
+                               found  = true;
+                       }
+               }
+       }
+
+       return found;
 }
 
-class TreePlanterDropEntityIfSelected {
-    mutable DEntity ent;
-    DTreePlanter &planter;
+class TreePlanterDropEntityIfSelected
+{
+mutable DEntity ent;
+DTreePlanter& planter;
 public:
-    TreePlanterDropEntityIfSelected(DTreePlanter &planter) : planter(planter)
-    {
-    }
-
-    void operator()(scene::Instance &instance) const
-    {
-        if (!instance.isSelected()) {
-            return;
-        }
-        ent.LoadFromEntity(instance.path().top());
-
-        DEPair *pEpair = ent.FindEPairByKey("origin");
-        if (!pEpair) {
-            return;
-        }
-
-        vec3_t vec, out;
-        sscanf(pEpair->value.GetBuffer(), "%f %f %f", &vec[0], &vec[1], &vec[2]);
-
-        planter.FindDropPoint(vec, out);
-
-        char buffer[256];
-        sprintf(buffer, "%f %f %f", out[0], out[1], out[2]);
-        ent.AddEPair("origin", buffer);
-        ent.RemoveFromRadiant();
-        ent.BuildInRadiant(false);
-    }
+TreePlanterDropEntityIfSelected( DTreePlanter& planter ) : planter( planter ){
+}
+void operator()( scene::Instance& instance ) const {
+       if ( !instance.isSelected() ) {
+               return;
+       }
+       ent.LoadFromEntity( instance.path().top() );
+
+       DEPair* pEpair = ent.FindEPairByKey( "origin" );
+       if ( !pEpair ) {
+               return;
+       }
+
+       vec3_t vec, out;
+       sscanf( pEpair->value.GetBuffer(), "%f %f %f", &vec[0], &vec[1], &vec[2] );
+
+       planter.FindDropPoint( vec, out );
+
+       char buffer[256];
+       sprintf( buffer, "%f %f %f", out[0], out[1], out[2] );
+       ent.AddEPair( "origin", buffer );
+       ent.RemoveFromRadiant();
+       ent.BuildInRadiant( false );
+}
 };
 
-void DTreePlanter::DropEntsToGround(void)
-{
-    Scene_forEachEntity(TreePlanterDropEntityIfSelected(*this));
+void DTreePlanter::DropEntsToGround( void ) {
+       Scene_forEachEntity( TreePlanterDropEntityIfSelected( *this ) );
 }
 
-void DTreePlanter::MakeChain(int linkNum, const char *linkName)
-{
-    char buffer[256];
-    int i;
-    for (i = 0; i < linkNum; i++) {
-        DEntity e("info_train_spline_main");
+void DTreePlanter::MakeChain( int linkNum, const char* linkName ) {
+       char buffer[256];
+       int i;
+       for ( i = 0; i < linkNum; i++ ) {
+               DEntity e( "info_train_spline_main" );
 
-        sprintf(buffer, "%s_pt%i", linkName, i);
-        e.AddEPair("targetname", buffer);
+               sprintf( buffer, "%s_pt%i", linkName, i );
+               e.AddEPair( "targetname", buffer );
 
-        sprintf(buffer, "0 %i 0", i * 64);
-        e.AddEPair("origin", buffer);
+               sprintf( buffer, "0 %i 0", i * 64 );
+               e.AddEPair( "origin", buffer );
 
-        if (i != m_linkNum - 1) {
-            sprintf(buffer, "%s_pt%i", linkName, i + 1);
-            e.AddEPair("target", buffer);
+               if ( i != m_linkNum - 1 ) {
+                       sprintf( buffer, "%s_pt%i", linkName, i + 1 );
+                       e.AddEPair( "target", buffer );
 
-            sprintf(buffer, "%s_ctl%i", linkName, i);
-            e.AddEPair("control", buffer);
-        }
-        e.BuildInRadiant(false);
-    }
+                       sprintf( buffer, "%s_ctl%i", linkName, i );
+                       e.AddEPair( "control", buffer );
+               }
+               e.BuildInRadiant( false );
+       }
 
-    for (i = 0; i < linkNum - 1; i++) {
-        DEntity e("info_train_spline_control");
+       for ( i = 0; i < linkNum - 1; i++ ) {
+               DEntity e( "info_train_spline_control" );
 
-        sprintf(buffer, "%s_ctl%i", linkName, i);
-        e.AddEPair("targetname", buffer);
+               sprintf( buffer, "%s_ctl%i", linkName, i );
+               e.AddEPair( "targetname", buffer );
 
-        sprintf(buffer, "0 %i 0", (i * 64) + 32);
-        e.AddEPair("origin", buffer);
+               sprintf( buffer, "0 %i 0", ( i * 64 ) + 32 );
+               e.AddEPair( "origin", buffer );
 
-        e.BuildInRadiant(false);
-    }
+               e.BuildInRadiant( false );
+       }
 }
 
-void DTreePlanter::SelectChain(void)
-{
+void DTreePlanter::SelectChain( void ) {
 /*     char buffer[256];
 
     for(int i = 0; i < m_linkNum; i++) {