@name EOW
@inputs 
@outputs C Count Pos:vector On Ran
@persist Setup C [Colors Types Teams Tiles Player]:array
@persist [CA Movement Board Pieces]:table Count Turn Moves
@persist 
@trigger all
interval(100)

#Here's some things, get selection code done, when attacking: display winner's team color as
#the end point selection tool color. White if neither team wins.
#

if (first()) {
    
    #Tiles = "models/hunter/plates/plate025x025.mdl"
    #findInSphere(entity():pos(),500)
    #findSortByDistance(entity():pos())
    #findClipToModel(Tiles)
    #Board = array()
    #Board = findToArray()
    On = 1
    U="Vertical"
    H="Horizontal"
    D="Diagonal"
    
    R="red"
    Y="yellow"
    G="green"
    B="blue"
    V="black" 
    W="white"
    F="flag"
    
    E=entity()
    runOnChat(1)
    Types=array(R,Y,G,B,V,W,F)
    
    #C = 1
    Colors = array()
    Colors[1,vector]=vec(200,0,0)  #red
    Colors[2,vector]=vec(255,255,0) #yellow
    Colors[3,vector]=vec(0,128,0)  #green
    Colors[4,vector]=vec(0,0,255)  #blue
    Colors[5,vector]=vec(0,0,0)    #black
    Colors[6,vector]=vec(255,255,255) #white
    
    #I did this cause I don't want red vs yellow to be the thing, Blue vs Red is better
    #               Blue            Red             Green           Yellow          Black               White
    Teams=array(Colors[4,vector],Colors[1,vector],Colors[3,vector],Colors[2,vector],Colors[5,vector],Colors[6,vector])
    
    
    
    CA=table()
    ##                 R  Y  G  B  V
    CA[G,array]=array(-2,-1, 0, 1, 2)
    ##                 R  Y  G  B  V  
    CA[B,array]=array( 2,-2,-1 ,0, 1)
    ##                 R  Y  G  B  V
    CA[V,array]=array( 1, 2, -2,-1,0)
    ##                 R  Y  G  B  V
    CA[R,array]=array( 0, 1, 2 ,-2,-1)
    ##                 R  Y  G  B  V
    CA[Y,array]=array(-1, 0, 1, 2,-2)
    
    Movement=table()
    ##                     U H D or Up/Down, Horizontal/left/right Diagonal (any diagonal)
    Movement[R,vector]=vec(0,1,2)
    Movement[Y,vector]=vec(1,1,2)
    Movement[G,vector]=vec(2,2,0)
    Movement[B,vector]=vec(2,0,2)
    Movement[V,vector]=vec(2,2,1)
    Movement[W,vector]=vec(2,2,2)
    Tiles=array() #This corelates to the holos
    Board=table() #This corelates to grid coordianates
    Pieces=table() #This table holds the grid coordinates of pieces
    Height=20 #distance off the ground the board will spawn
    
    XY=6 #number of tiles in square's side
    #holoCreate(1,entity():pos()+vec(XY*Spacing,XY*Spacing,Height),vec(1,1,0.01)*20)
    #holoColor(1,vec(0,0,0))
    Count=0 #hologram counter
    Size=1 #size of tiles
    Spacing=13*Size #distance between holograms
    
    #function move(
    
    #}
    
    function attack(Attack:vector,Defend:vector,Loc:vector2){ #use the Attack/defend vec(Index,Side,Color) Loc vec2(x,y)
        
    }
    
    
    
    function number array:select(Side:number){
        #Play=Player[Side,entity] #Need an array of players entities
        
        Play=owner()
        findInCone(Play:shootPos(),Play:eye(),200,5)
        findIncludeClass("gmod_wire_hologram")
        findSortByDistance(Play:shootPos())
        Holos=findToArray()
        
        
        for(C=1,Holos:count()){
                HIndex=holoIndex(Holos[C,entity])
                Tile=Tiles[HIndex,vector]
                
                if(Tile){
                   
                    Loc=E:pos()+vec(Tile:x()*Spacing,Tile:y()*Spacing,Height-2)
                    holoCreate(Tiles:count()*3+1,Loc,vec(1.5,1.5,0.1)*Size,ang(),vec(255,255,255))
                    break
                    #timer("selection delay",1000)
                }
                
        }
       return HIndex 
    }
    function piece(Index:number,Side:number,Color:number,Pos:vector2){ 
        I=Index+Tiles:count()
        
        holoCreate(I,E:pos()+vec(Pos:x()*Spacing,Pos:y()*Spacing,Height+2),vec(1,0.5,0.1)*Size,ang(),Teams[Side,vector])
        holoCreate(I*2,E:pos()+vec(Pos:x()*Spacing,Pos:y()*Spacing,Height+4),vec(0.5,0.5,0.1)*Size,ang(),Colors[Color,vector])
    }
    function flagDraw(Index:number,Side:number,Pos:vector2){
        I=Index+Tiles:count()
        holoCreate(I,E:pos()+vec(Pos:x()*Spacing,Pos:y()*Spacing,Height+2),vec(0.5,0.5,0.1),ang(),Teams[Side,vector])
        holoCreate(I*2,E:pos()+vec(Pos:x()*Spacing,Pos:y()*Spacing,Height+2),vec(0.25,1,0.1),ang(),Teams[Side,vector])
        
    }
    
    Blank=array() #makes a bunch of place holder 0's
    for(C=1,XY){
        Blank:pushVector(vec(0,0,0)) #vec2(Index,Side,Color)
    }
    #Replicates one row of blank pieces into a grid
    for(C=1,XY){
        Pieces[C,array]=Blank:clone()
    }
    
    for(C=1,XY){
        for(D=1,XY){
            Count++
            Ran = randint(1,5)
            Board[C,array]:pushNumber(Ran)
            Tiles:pushVector(vec(C,D,Ran))
            #if(Ran!=5){
                holoCreate(Count,E:pos()+vec(Spacing*C,Spacing*D,Height+2))
                holoScale(Count,vec(1,1,0.1)*Size)
                holoColor(Count,Colors[Ran,vector])
            #}
            
            
        }
    }
    PieceCount=6
    for(C=1,PieceCount*2+2){
        
    }
}

array(owner()):select(1)
if(clk("selection delay")){holoDelete(HIndex)}
#Count = Board:count()
#Pos = Board:entity(C):pos()+vec(0,0,20)
#Tile = Board:entity(C)

#if (C<=Count) {

#[
if (Ran==1) {Tile:setColor(255,0,0) Colors:setString(C,R)}
if (Ran==2) {Tile:setColor(255,255,0) Colors:setString(C,Y)}
if (Ran==3) {Tile:setColor(65,163,0) Colors:setString(C,G)}
if (Ran==4) {Tile:setColor(0,0,255) Colors:setString(C,B)}
if (Ran==5) {Tile:setColor(0,0,0) Colors:setString(C,V)}
]#
#C+=1
#}

#Generate a board, and make a single large black holo then place 
#all the other colored holos on it and slightly raised to reduce
#holo counts by ~20%. 
