contract ARK_VOTER_1_00{

  ARK Ark;
  ARKController_1_00 controller;
  address owner;
  mapping(uint => uint)thresold;
  Vote[] votes;
  uint max;
  uint min;
  Vote[] tv;
  uint[] lastblock;
  uint vmin=30;
  uint vmax=700;
  uint qmin=30;
  uint qmax=700;

        struct Vote {
        uint up;
        uint down;

        mapping (address => bool) voters;
        }

////////////////////////////////////////////////
    log[] logs;

    struct log{
    address admin;
    string action;
    address addr;
    uint i;
    }
////////////////////////////////////////////////

   function ARK_VOTER_1_00(uint a,uint b,uint c,uint d,uint e,uint f){

   owner=msg.sender;
   //tv.push();
   thresold[0]=a; //blackflag quorum
   thresold[1]=b; //censor quorum
   thresold[2]=c; //price vote quorum
   thresold[3]=d; //quorum voting quorum
   thresold[4]=e;
   thresold[5]=f;

   for(uint z=0;z<9;z++){ votes.push(Vote({up:0,down:0})); lastblock.push(1);}
   min=50000000000000000;
   max=2000000000000000000;
   vmin=30;
   vmax=700;
   qmin=30;
   qmax=700;
   }

  

    function setOwner(address a) {
    if(msg.sender!=owner)throw;
    owner=a;
    logs.push(log(owner,"setOwner",a,0));
    }


    function setSource(address a) {
    if(msg.sender!=owner)throw;
    Ark=ARK(a);
    logs.push(log(owner,"setSource",a,0));
    }

    function setController(address a) {
    if(msg.sender!=owner)throw;
    controller=ARKController_1_00(a);
    logs.push(log(owner,"setController",a,0));
    }

    function readLog(uint i)constant returns(address,string,address){
    log l=logs[i];
    return(l.admin,l.action,l.addr);
    }

    function setThresold(uint i,uint j){
    if(msg.sender!=owner)throw;
    thresold[i]=j;

    if(i==0)logs.push(log(owner,"setThresold0",0x0,j));
    if(i==1)logs.push(log(owner,"setThresold1",0x0,j));
    if(i==2)logs.push(log(owner,"setThresold2",0x0,j));
    if(i==3)logs.push(log(owner,"setThresold3",0x0,j));
    if(i==4)logs.push(log(owner,"setThresold4",0x0,j));
    if(i==5)logs.push(log(owner,"setThresold5",0x0,j));

    }

    function setMin(uint i,uint w) {
    if(msg.sender!=owner)throw;
    if(w==0){min=i; logs.push(log(owner,"setMin",0x0,i));}
    if(w==1){vmin=i; logs.push(log(owner,"setVMin",0x0,i));}
    if(w==2){qmin=i; logs.push(log(owner,"setQMin",0x0,i));}
    }

    function setMax(uint i,uint w) {
    if(msg.sender!=owner)throw;
    if(w==0){max=i; logs.push(log(owner,"setMax",0x0,i));}
    if(w==1){vmax=i; logs.push(log(owner,"setVMax",0x0,i));}
    if(w==2){qmax=i; logs.push(log(owner,"setQMax",0x0,i));}
    }

    function setPrice(uint i,uint j) {
    if(msg.sender!=owner)throw;

    if(i==0)logs.push(log(owner,"setPrice0",0x0,j));
    if(i==1)logs.push(log(owner,"setPrice1",0x0,j));
    if(i==2)logs.push(log(owner,"setPrice2",0x0,j));
    if(i==3)logs.push(log(owner,"setPrice3",0x0,j));
    if(i==4)logs.push(log(owner,"setPrice4",0x0,j));
    if(i==5)logs.push(log(owner,"setPrice5",0x0,j));
    controller.setPrice(i,j);

    }
    
    function check(uint i)constant returns(bool){
        if((Ark.getOwnedBot(msg.sender,0)>0)&&(block.number-lastblock[i]>1000)){return true;}else{return false;}   
    }
    
      
    function votePrice(uint x,bool v){
       

        Vote V=votes[x];
        var(a,b,c,d,e) = Ark.getLastPrice(x);

        if(check(x)&&(!(V.voters[msg.sender]))&&(x<=5)&&(a<=max)&&(a>=min)){

        V.voters[msg.sender]=true;

            
        
           
            if(v){V.up++;
                  if(V.up>thresold[2]){
                      
                            uint u=a+(a/10);
                            controller.setPrice(x,u);
                            lastblock[x]=block.number;
                            votes[x]=Vote({up:0,down:0});
                  }
            }else{
                  V.down++;
                  if(V.down>thresold[2]){
                       
                            uint z=a-(a/10);
                            controller.setPrice(x,z);
                            lastblock[x]=block.number;
                            votes[x]=Vote({up:0,down:0});
                      
                  }
            }
           
        
        }else{throw;}
        }


        function voteQuorum(uint x,bool v){

        Vote V=votes[x];

        if((check(x))&&(!(V.voters[msg.sender]))&&(x>5)&&(x<9)&&(thresold[x-6]<vmax)&&(thresold[x-6]>vmin)){

        V.voters[msg.sender]=true;
           
            if(v){V.up++;
                  if(V.up>thresold[3]){                       
                       thresold[x-6]+=thresold[x-6]/10;
                       lastblock[x]=block.number;
                       votes[x]=Vote({up:0,down:0});
                  }
            }else{
                  V.down++;
                  if(V.down>thresold[3]){
                    thresold[x-6]-=thresold[x-6]/10;
                    lastblock[x]=block.number;
                    votes[x]=Vote({up:0,down:0});
                  }
            }
            
        
        }else{throw;}
        }



        function voteSuperQuorum(uint x,bool v){
     
        Vote V=votes[x];

        if((check(x))&&(!(V.voters[msg.sender]))&&(x>8)&&(thresold[3]<qmax)&&(thresold[3]>qmin)){

        V.voters[msg.sender]=true;
           
            if(v){V.up++;
                  if(V.up>thresold[3]){                       
                  thresold[3]+=thresold[3]/10;
                  lastblock[x]=block.number;
                  votes[x]=Vote({up:0,down:0});   
                  }
            }else{
                  V.down++;
                  if(V.down>thresold[3]){
                  thresold[3]-=thresold[3]/10;
                  lastblock[x]=block.number;
                  votes[x]=Vote({up:0,down:0});  
                  }
            }
            
        
        }else{throw;}
        }


        function getVotes(uint x) constant returns(uint,uint,bool){
        Vote V=votes[x];
        return (V.up,V.down,V.voters[msg.sender]);
        }

        function getThresold(uint i)constant returns(uint){return thresold[i];}

        function getMinMax()constant returns(uint,uint,uint,uint,uint,uint){return (min,max,vmin,vmax,qmin,qmax);}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function ARK_VOTER_1_00(uint a,uint b,uint c,uint d,uint e,uint f){

owner=msg.sender;
//tv.push();
thresold[0]=a; //blackflag quorum
thresold[1]=b; //censor quorum
thresold[2]=c; //price vote quorum
thresold[3]=d; //quorum voting quorum
thresold[4]=e;
thresold[5]=f;

for(uint z=0;z<9;z++){ votes.push(Vote({up:0,down:0})); lastblock.push(1);}
min=50000000000000000;
max=2000000000000000000;
vmin=30;
vmax=700;
qmin=30;
qmax=700;
}

////////////////////////////////////////////////