import Plant:"/ESRI.lib/rules/Plants/Plant_Loader.cga"
import Text:"/ESRI.lib/rules/General/Text.cga"


PlantNumber = Plant.nPlants


@Hidden
attr SubSplit = 0
@Hidden
attr Length = 0


@StartRule
Area-->
  alignScopeToGeometry(yUp,1)
  s(PlantNumber*20,0,20)
  set(Length,scope.sx)
  plantpoints(0)

plantpoints(counter)-->
  case SubSplit <= PlantNumber:
  split(x) {Length/PlantNumber:plantArea(SubSplit) | ~1: set(SubSplit, SubSplit+1) plantpoints(SubSplit)}
  else:
  NIL

plantArea(plantnum)-->
  comp(f) {top=PlacePlant(plantnum)[Ground]}


PlacePlant(plantnum)-->
  set(Plant.Name, Plant._commonName(SubSplit))
  set(Plant.Height, Plant._heightMax(SubSplit))
  set(Plant.Radius, Plant._radius(SubSplit,Plant.Height))
  Plant.Generate
  set (Text.Text,Plant.Name)
  set (Text.Size,2)
  rotate(abs, world, 270,180,270)
  t(Plant.Height,0,scope.sy/2-Text.Size)
  Text.Generate   
    
 Ground-->
  color("#56a554")