#include "GrowingPanicle.h"
#include "GrowingPanicle.c7"
ClassImp(GrowingPanicle);
void GrowingPanicle::_init()
{
  
  mStart.x('I', 20).x('F', 1).x('A', 0, 0);
}
GrowingPanicle::GrowingPanicle(const Text_t* n, const Text_t* t) :
GrowingPlant(n, t),
mLateralAngle(90),
mSColor(1, 1, 1),
mSSize(0.15),
mTColor(0, 0, 1),
mTSize(0.3),
mUColor(0, 1, 1),
mUSize(0.2)
{
  _init();
}
GrowingPanicle::~GrowingPanicle()
{}
void GrowingPanicle::SegmentStepTime(GrowingPlant::Segments_i ref, Segments_t& in, Segments_t& out)
{
  
  int delay = 2;
  
  
  
  out.s('/', 180);
  out.s('+', mLateralAngle);  
  out.s('A', 2, 0);
  out.s('O', 1, 1);
  
  Segment& seg   = *ref;
  
  switch (seg.mType)
  {
    case'A': 
    {
      
      Segments_i back  = NeighbourBack(in, ref);
      if (back != in.end() && (*back).mType == 'S')
      { 
       
        
         out.x('T', 0).x("O");
        
        
      }
      else if (seg.mParam1 > 0)
      {
        out.x('A', seg.mParam1 - 1, seg.mParam2);
      }
      else if (seg.mParam1 == 0)
      {
        out.x("[+G]").x('F', 1, seg.mParam2).x("/").x('A', delay, seg.mParam2);
      }
      break;
    }
      
     
    case 'F':
    {
      Segments_i back  = NeighbourBack(in, ref);
      if (back != in.end() && (*back).mType == 'S')
      { 
       
        out.x(seg.mType, seg.mParam1, seg.mParam2).x('S', 1, 1);
        break;
      }
      
      Segments_i front = NeighbourFront(in, ref, 0, false);
      if (front != in.end() && (*front).mType == 'T') 
      { 
        
        out.x('T', (*front).mParam1 + 1).x('F', 1, seg.mParam2).x('U',  (*front).mParam1 -1);
        break;
      } 
      
      
      out.x(seg.mType, seg.mParam1, seg.mParam2);
      break;
    }
      
      
      
    case 'G':
    {
      
    
      Segments_i back  = NeighbourBack(in, ref, -1);
      if (back != in.end() && (*back).mType == 'U')
      { 
        
         out.x('I', (*back).mParam1).x('F', 1, 1).x('A', delay, 1);
        
        break;
      }
      
      out.x(seg.mType, seg.mParam1, seg.mParam2);
      break;
    }
      
      
    case 'I':
    {
     
      if (seg.mParam1 == 0)
      {
      
        out.x('S', 0);
      }
      else
      {
        out.x('I', seg.mParam1 -1);
       
      }
      break;
    }
    
      
    case 'S':
    case 'T':
    {
      break;
    }
    case 'O':
    {
      
      out.x(seg.mType, seg.mParam1+1, seg.mParam2+1);
      break; 
    }
    default:
    {
      
      out.x(seg.mType, seg.mParam1, seg.mParam2);
    }
  }