set %fallo 0
set %llevamucho 0
set %transcurrido 0

if #targcurs = 0
    key %LastObject
target 3s
if #targcurs = 0
  exit

click %1 %2
for %i 1 6
 { 
                    call keepalive
  if #targcurs = 0
     goto amosacortar
  wait 1
  }
set %1 %msg_noarbol
exit

amosacortar:

set %1 0
goto PasaDeApuntar


apicar:

if %TiraLogs <> SI
  {
    if %maxpeso <= #weight
     goto Journal_End
  }

 msg $/ %Finish_Read $
reintento:
 if %fallo > 3
     goto Journal_End
  key %LastObject
  target 4s
  key %LastTarget
 PasaDeApuntar:
  set %initpicar #SCNT

; Nos sale el letrero de atacar a un azul
 if #contkind = STJC
    {
     click 376 312
     wait 2s
     click 376 312
     wait 2s
     goto Journal_End
    }

  goto clickok

clickok:
                   call keepalive
wait 10

set %tmp #scnt
set %transcurrido %tmp - %initpicar

  if %transcurrido > 14
     {
     set %fallo %fallo + 2
     wait 2s
      goto apicar
     }

set %i 0
JournalLoop:
 scanjournal %i
wait 1
if %msg_targeterror in #journal
    goto Journal_End
if %msg_nologs in #journal
    goto Journal_End
if %msg_reach in #journal
    goto Journal_End
if %msg_enhojas in #journal
    goto Journal_End
if %msg_lejos in #journal
    goto Journal_End
if %msg_noarbol in #journal
    goto Journal_End
if %msg_attackanimal in #journal
    goto Journal_End



if %msg_fail in #journal
  {
     set %llevamucho %llevamucho + 1
     if %llevamucho > 8
               goto Journal_End
     if %transcurrido < 3
          wait 6s
     goto apicar
   }

if %msg_saveworld in #journal 
 {
  msg $/ %Finish_Read $
  wait 20s
  goto clickok
 }

if %msg_getlog in #journal
   {
    goto apicar
   }

 if %Finish_Read in #journal
     goto clickok
 
 set %i %i + 1
 if %i > 12
     {  
       msg $/ %Finish_Read $
       goto clickok
     }
goto JournalLoop

Journal_End: 

msg $/ %Finish_Read $


;msg $Sacabo$
;halt