
    ' Creat By Atomose Studio 2026 with LibertyBasic 4.51 pro

    nomainwin
    GameVersion$ = "1.5" : build = 2 : version = 2

    on error goto [noSav]
    open "pref.txt" for input as #secu
    input #secu, pass$
    input #secu, version
    input #secu, autoSAVmode
    close #secu
    if pass$ = "1" then end
    [noSav]
    on error goto 0
    pass$ = "1"
    open "pref.txt" for output as #secu
    print #secu, pass$
    print #secu, version
    print #secu, autoSAVmode
    close #secu

    ' détection de la langue du pc
    version = 2
    open "getlang.bat" for output as #bat
    q$ = chr$(34)
    print #bat, "reg query " + q$ + "HKCU\Control Panel\International" + q$ + " /v LocaleName > reglang.txt"
    close #bat
    run "getlang.bat"
    timer 500, [lireRegistre]
    wait

    [lireRegistre]
    on error goto [menuMultijoueur]
    open "reglang.txt" for input as #regcheck
    close #regcheck
    on error goto [erreurGenerale]
    open "reglang.txt" for input as #reg
    while not(eof(#reg))
        line input #reg, ligne$
        if instr(lower$(ligne$), "fr-") > 0 then version = 1
    wend
    close #reg
    kill "reglang.txt"
    kill "getlang.bat"

    ' correcteur DPI pour haute résolution
    DPI.AWARENESS.CONTEXT.PER.MONITOR.AWARE = -1 '-3
    CALLDLL #user32, "SetThreadDpiAwarenessContext", DPI.AWARENESS.CONTEXT.PER.MONITOR.AWARE AS LONG, RetVal AS LONG


    f$ = chr$(34) + "data\hit.wav" + chr$(34)
    r$ = mcisend$("open " + f$ + " type waveaudio alias hit")

    sprites$ = "about academie academie1 academie1b academie2 academie2b academieB arrow back balise building button1 button1b button2 button2b button2c button2d button3 button3b button3c button4 caserne caserne1 caserne1b caserne2 caserne2b caserneB check construct1 construct2 construct3 construct4 demolir eau eau1 ennemiA ennemiB ennemiC ferme ferme1 ferme1b ferme2 ferme2b fermeB foret foret1 foret2 herbe herbe1 herbe2 herbe7 herbe8 herbe9 herbe10 herbe11 herbe12 herbe13 home humain0 humain1 humain2 loca1 loca2 maison maison1 maison1b maison2 maison2b maisonB MAP1mini MAP2mini MonsterA montagne montagne1 montagne2 perso perso1 perso2 perso3 persoXL recherche1OFF recherche1ON recherche2OFF recherche2ON rechercheAcademikOFF rechercheAcademikON repare ressource1 ressource2 ressource3 ressource4 screenINI screenINI2 soldat1 soldat2 system system2 system3 tour tour1 tour1b tour2 tour2b tourB"
    for s = 1 to 104
        loadbmp word$(sprites$,s), "data\"+word$(sprites$,s)+".bmp"
    next

    dim pop(1000), popMAX(1000), peonCOST(1000), peonTIME(1000), nombrePeon(1000), nourriture(1000), bois(1000), minerais(1000)
    dim peonSELECT(1000), lvlPEON(1000), xpPEON(1000), xpTotalPEON(1000), PVpeon(1000),PvMAXpeon(1000), ATKpeon(1000), DEFpeon(1000), nourritureRestante(1000)
    dim nombreFerme(1000), nombreCaserne(1000), nombreAcademie(1000), nombreTour(1000), Pvtown(1000), PvtownMax(1000), upgradeVILLE(1000), recherche(1000), mineraisDispo(1000), boisDispo(1000)
    dim POSxSOLDATa(1000), POSySOLDATa(1000), POSxSOLDATb(1000), POSySOLDATb(1000), POSxTOWER(1000), POSyTOWER(1000), reloadTower(1000), DEFtour(1000), ATKtour(1000), Team(100), Race(100)
    dim XpSoldatA(1000), XpTotalSoldatA(1000), LvlSoldatA(1000), nombreSoldatA(1000), soldat1Select(1000), XpSoldatB(1000), XpTotalSoldatB(1000), LvlSoldatB(1000), nombreSoldatB(1000), soldat2Select(1000)
    dim PVsoldatP1(1000), PvMAXsoldatP1(1000), PvCamp(1000), PvMaxCamp(1000), POSxCAMP(1000), POSyCAMP(1000), DEFcamp(1000), IDcampX(1000), IDcampY(1000)
    dim mXmoove(1000), mYmoove(1000), mX2moove(1000), mY2moove(1000), mX3moove(1000), mY3moove(1000), mX4moove(1000), mY4moove(1000), AI$(1000), AI(1000)
    dim IDtour(1000), IDfermage(1000), IDfermageX(1000), IDfermageY(1000), IDtourX(1000), IDtourY(1000), rechercheAcad(1000), lvlAcademie(1000), CampX(1000), CampY(1000)
    dim PVsoldatA(1000), PvMAXsoldatA(1000), ATKsoldatA(1000), DEFsoldatA(1000), PVsoldatB(1000), PvMAXsoldatB(1000), ATKsoldatB(1000), DEFsoldatB(1000), targetBattle(1000)
    dim PVpeonE(1000), PvMAXpeonE(1000), ATKpeonE(1000), DEFpeonE(1000), reloadTime(1000), px(1000), py(1000)
    dim IDunitP1(1000), IDunitP2(1000), PVsoldatP1(1000), PvMAXsoldatP1(1000), POSxSOLDATp1(1000), POSySOLDATp1(1000), MoovingTO(1000), ATKsoldatP1(1000), DEFsoldatP1(1000), XpSoldatP1(1000), XpTotalSoldatP1(1000),LvlSoldatP1(1000)
    dim POSxSOLDATp2(1000), POSySOLDATp2(1000), PVsoldatP2(1000), PVMAXsoldatP2(1000), ATKsoldatP2(1000), DEFsoldatP2(1000), reloadTimeE(1000), targetBattleE(1000)
    dim PvFerme(1000), PvFermeMAX(1000), DEFferme(1000), IDfermeX(1000), IDfermeY(1000), POSxFerme(1000), POSyFerme(1000), arrowActive(1000)
    dim arrow1Active(1000), arrow2Active(1000), arrow3Active(1000), arrow4Active(1000), arrow5Active(1000), arrow6Active(1000), arrow7Active(1000), arrow8Active(1000)
    dim arrow9Active(1000), arrow10Active(1000), arrow11Active(1000), arrow12Active(1000), arrow13Active(1000), iniWorkerIA(1000)
    dim IDacademieX(1000), IDacademieY(1000), POSxAcademie(1000), POSyAcademie(1000), PvAcademie(1000), PvMaxAcademie(1000), DEFacademie(1000), lvlAcademie(1000)
    dim PVsoldatP1(1000), PvMAXsoldatP1(1000), POSxVillage(1000), POSyVillage(1000), lvlVILLE(1000), PlayerAlive(1000), PVunitE(1000), IDunitE(1000), cxOLD(1000), cyOLD(1000), xOLD(1000), yOLD(1000)
    dim x(1000), y(1000), xX(1000), yY(1000), cx(1000), cy(1000), dist(1000), tx(1000), ty(1000), NworkerMINE(1000), NworkerWOOD(1000), NworkerFARM(1000)
    dim MoovingTOai(1000), MoovingTO2ai(1000), MoovingTO3ai(1000), mXmoove1AI(1000), mYmoove1AI(1000), mXmoove2AI(1000), mYmoove2AI(1000), mXmooveAI(1000), mYmooveAI(1000), nPOSxSOLDATp2(1000), nPOSySOLDATp2(1000)
    dim IDfermageAI(1000), IDfermageXai(1000), IDfermageYai(1000), IDcampXai(1000), IDcampYai(1000), IDtourXai(1000), IDtourYai(1000), IDacademieXai(1000), IDacademieYai(1000), ciblageP1(1000), ciblageP2(1000)
    dim limiteWorkerFermage(1000), limiteFermage(1000), localisationFermage(1000), limiteWorkerBois(1000), limiteBois(1000), localisationBois(1000), limiteWorkerMine(1000), limiteMine(1000), localisationMine(1000)
    dim limiteWorker2Fermage(1000), UnitP2intoArmy(1000), localisationTower(1000), ciblage(1000), terrainSprites$(1000), nourritureRestante2(1000)

  ' playwave "data\music.wav", loop : music = 1
    bruitage = 1

    [ini]
    timer 0
    WindowWidth = 1152 : WindowHeight = 800 : UpperLeftX=int((DisplayWidth-WindowWidth)/2) : UpperLeftY=int((DisplayHeight-WindowHeight)/2) : loading = 0 : mapSelected = 1
    nourriture(1) = 200 : bois(1) = 50 : minerais(1) = 0 : pop(1) = 0 : popMAX(1) = 10 : numSoldatP1 = 0 : p(xNEW,yNEW) = 0
    nourriture(2) = 200 : bois(2) = 50 : minerais(2) = 0 : pop(2) = 0 : popMAX(2) = 10 : numSoldatP2 = 0
    if version = 1 then Race1$ = "Humains" : Race2$ = "Humains" : Race3$ = "------" : Race4$ = "------" : Race5$ = "------" : Race6$ = "------" : Race7$ = "------" : Race8$ = "------" : Race9$ = "------" : Race10$ = "------"
    if version = 2 then Race1$ = "Humans" : Race2$ = "Humans" : Race3$ = "------" : Race4$ = "------" : Race5$ = "------" : Race6$ = "------" : Race7$ = "------" : Race8$ = "------" : Race9$ = "------" : Race10$ = "------"
    AI(2) = 1 : AI(3) = 0 : AI(4) = 0 : AI(5) = 0 : AI(6) = 0 : AI(7) = 0 : AI(8) = 0 : AI(9) = 0 : AI(10) = 0
    Race(1) = 1 : Race(2) = 1 : Race(3) = 0 : Race(4) = 0 : Race(5) = 0 : Race(6) = 0 : Race(7) = 0 : Race(8) = 0 : Race(9) = 0 : Race(10) = 0
    Team(1) = 1 : Team(2) = 2 : Team(3) = 0 : Team(4) = 0 : Team(5) = 0 : Team(6) = 0 : Team(7) = 0 : Team(8) = 0 : Team(9) = 0 : Team(10) = 0
    if version = 1 then AI$(2) = "Ordinateur - Simple" : AI$(3) = "Aucun" : AI$(4) = "Aucun" : AI$(5) = "Aucun" : AI$(6) = "Aucun" : AI$(7) = "Aucun" : AI$(8) = "Aucun" : AI$(9) = "Aucun": AI$(10) = "Aucun"
    if version = 2 then AI$(2) = "Computer - Easy" : AI$(3) = "None" : AI$(4) = "None" : AI$(5) = "None" : AI$(6) = "None" : AI$(7) = "None" : AI$(8) = "None" : AI$(9) = "None": AI$(10) = "None"
    NplaerMaxOnMap = 2 : costValorHommeArme1 = 40 : costValorHommeArme2 = 0 : costValorHommeArme3 = 10 : peonCOST = 20
    costValorLancier1 = 30 : costValorLancier2 = 10 : costValorLancier3 = 0
    CostNourritureCamp = 50 : CostBoisCamp = 50 : CostMineraisCamp = 20
    CostNourritureFermage = 0 : CostBoisFermage = 30 : CostMineraisFermage = 0
    CostNourritureTour = 0 : CostBoisTour = 50 : CostMineraisTour = 0
    CostNourritureCaserne = 15 : CostBoisCaserne = 40 : CostMineraisCaserne = 0
    recherche(1) = 0 : recherche(2) = 0 : recherche(3) = 0 : recherche(4) = 0 : INgame = 0
    rechercheAcad(1) = 0 : rechercheAcad(2) = 0 : rechercheAcad(3) = 0 : rechercheAcad(4) = 0 : rechercheAcad(5) = 0 : rechercheAcad(6) = 0 : rechercheAcad(7) = 0 : rechercheAcad(8) = 0 : rechercheAcad(9) = 0 : rechercheAcad(10) = 0
    ConstructionAcademie = 0 : ConstructionCamp = 0 : ConstructionFermeMax = 2 : ConstructionFerme = 0 : ConstructionTourMax = 2 : ConstructionTour = 0 : ConstructionFermeDONE = 0 : ConstructionTourDONE = 0
    PlayerAlive(3) = 0 : PlayerAlive(4) = 0 : PlayerAlive(5) = 0 : PlayerAlive(6) = 0 : PlayerAlive(7) = 0 : PlayerAlive(8) = 0 : PlayerAlive(9) = 0 : PlayerAlive(10) = 0
    LockTeam = 1 : RegenMap = 0 : UnitHostile = 0 : Heroes = 0 : Dynasty = 0 : PlayerAlive(2) = 1
    ConstructionTourMaxAI1 = 4 : ConstructionFermeMaxAI1 = 2 : compteurTowerAI = 1 : compteurAcadAI = 1 : compteurCampAI = 1 : compteurFermeAI = 1 : compteurTower = 1 : compteurAcad = 1 : compteurCamp = 1 : compteurFarm = 1
    nombrePeon(1) = 0 : nombrePeon(2) = 0 : nombreSoldatA(1) = 0 : nombreSoldatB(1) = 0 : upgradeVILLE(1) = 0 : limiteFermage(1) = 0 : limiteBois(1) = 0 : limiteMines(1) = 0
    activationConstrucAcad = 0 : acadX = 0 : acadY = 0 : activationConstrucFarm = 0 : farmX = 0 : farmY = 0 : activationConstrucTower = 0 : towerX = 0 : towerY = 0 : activationConstrucCamp = 0 : campX = 0 : campY = 0
    ConstructionFermeAI1 = 0 : ConstructionAcademieAI1 = 0 : ConstructionCampAI1 = 0 : ConstructionTourAI1 = 0 : XvilleP2 = 0 : YvilleP2 = 0 : activationConstrucTowerIA = 0 : towerAIx = 0 : towerAIy = 0
    activationConstrucAcadIA = 0 : acadAIx = 0 : acadAIy = 0 : activationConstrucCampIA = 0 : campAIx = 0 : campAIy = 0 : activationConstrucFermeIA = 0 : farmAIx = 0 : farmAIy = 0
    spriteCmd$ = "spritexy " : visibleCmd$ = "; SpriteVisible " : frontCmd$ = " on; spritetofront "

    for x = 1 to 800
        IDunitP1(x) = 0
        PVsoldatP1(x) = 0
        PVsoldatP2(x) = 0
        IDfermageX(x) = 0
        IDfermageY(x) = 0
        localisationFermage(x) = 0
    next x

    graphicbox #ini.map, 0, 0, 1200, WindowHeight-28
    Stylebits #ini, 0, _WS_MAXIMIZEBOX or _WS_MINIMIZEBOX, _WS_EX_CLIENTEDGE , 0
    open "" for window_nf as #ini
    #ini, "trapclose [quitIni]"
    #ini.map, "setfocus; down; fill black"
    #ini.map, "when leftButtonDown [positionButton]"

    hGBox = hwnd(#ini.map)
    CallDLL #user32, "GetDC",_
        hGBox As ulong,_  'handle of graphicbox
        gDC As ulong      'device context
    CallDLL #gdi32, "SetBkMode",_
        gDC As ulong,_          'handle of graphicbox
        _TRANSPARENT As long,_  'flag for transparent/opaque background
        result As long          'previous bkmode
    CallDLL#user32,"ReleaseDC",_
        hGBox As ulong,_    'graphicbox handle
        gDC As ulong,_      'device context
        result As long

    #ini.map "drawbmp screenINI 0 0"
    if version = 1 then #ini.map, "drawbmp button1b 220 360; drawbmp button2 230 460; drawbmp button2c 230 530; drawbmp button2d 230 600"
    if version = 2 then #ini.map, "drawbmp button1 220 360; drawbmp button2b 230 460; drawbmp button2c 230 530; drawbmp button2d 230 600"
    print #ini.map, "font Arial 8; color white; place 1060 755 ;\"; "Version ";GameVersion$;".";build
    print #ini.map, "flush"
    wait

    [positionButton]
    mX = MouseX : mY = MouseY
 '   notice mX;" : ";mY
    if mX > 220 and mX <390 and mY >360 and mY <410 then
        timer 0
        if bruitage = 1 then r$ = mcisend$("play hit from 0")
        goto [ini2]
    end if
    if mX > 230 and mX <480 and mY >460 and mY <500 then
        timer 0
        if bruitage = 1 then r$ = mcisend$("play hit from 0")
        goto [Loadgame]
    end if
    if mX > 230 and mX <480 and mY >530 and mY <570 then
        if bruitage = 1 then r$ = mcisend$("play hit from 0")
        goto [options]
    end if
    if mX > 230 and mX <480 and mY >600 and mY <640 then
        if bruitage = 1 then r$ = mcisend$("play hit from 0")
        goto [about]
    end if
    wait

    [minimyze]
    handle = hwnd(#ini)
    ShowFlag = _SW_MINIMIZE
    calldll #user32,"ShowWindow",_
        handle as long,_        'handle of window or control
        ShowFlag as long,_ 'how to display the window
        result As boolean
    wait

    [positionButton2]
    mX = MouseX : mY = MouseY
   ' notice mX;" : ";mY
    if bruitage = 1 then r$ = mcisend$("play hit from 0")
    if mX >837 and mX <1007 and mY >630 and mY <680 then goto [game]
    if mX >35 and mX <80 and mY >35 and mY <70 then goto [quit2]

    if mX >985 and mX <1005 and mY >550 and mY <575 then
        mapSelected = mapSelected + 1
        if mapSelected > 2 then mapSelected = 1
        goto [refreshMAP]
    end if
    if mX >955 and mX <975 and mY >550 and mY <575 then
        mapSelected = mapSelected - 1
        if mapSelected < 1 then mapSelected = 2
        goto [refreshMAP]
    end if
    if mX >790 and mX <802 and mY >570 and mY <582 then
        if LockTeam = 0 then LockTeam = 1 : goto [refreshMAP]
        if LockTeam = 1 then LockTeam = 0 : goto [refreshMAP]
    end if
        if version = 1 and mX >772 and mX <784 and mY >570 and mY <582 then notice " " + chr$(13) +  "Verrouille les équipes. Vous ne pouvez pas changer d'équipe en jeu."
        if version = 2 and mX >772 and mX <784 and mY >570 and mY <582 then notice " " + chr$(13) +  "Locks teams. You cannot change teams in-game."
    if mX >790 and mX <802 and mY >590 and mY <602 then
        if RegenMap = 0 then RegenMap = 1 : goto [refreshMAP]
        if RegenMap = 1 then RegenMap = 0 : goto [refreshMAP]
    end if
        if version = 1 and mX >772 and mX <784 and mY >590 and mY <602 then notice " " + chr$(13) +  "Le bois et la pierre sur la carte apparaissent de façon continue en des positions aléatoires."
        if version = 2 and mX >772 and mX <784 and mY >590 and mY <602 then notice " " + chr$(13) +  "Wood and stone on the map spawn continuously in random positions."
    if mX >790 and mX <802 and mY >610 and mY <622 then
        if autoSAVmode = 0 then autoSAVmode = 1 : goto [refreshMAP]
        if autoSAVmode = 1 then autoSAVmode = 0 : goto [refreshMAP]
    end if
        if version = 1 and mX >772 and mX <784 and mY >610 and mY <622 then notice " " + chr$(13) +  "Active la sauvegarde automatique du jeu toutes les 5mn."
        if version = 2 and mX >772 and mX <784 and mY >610 and mY <622 then notice " " + chr$(13) +  "Enables automatic saving of the game every 5 minutes."
    if mX >790 and mX <802 and mY >630 and mY <642 then
        if UnitHostile = 0 then UnitHostile = 1 : goto [refreshMAP]
        if UnitHostile = 1 then UnitHostile = 0 : goto [refreshMAP]
    end if
        if version = 1 and mX >772 and mX <784 and mY >630 and mY <642 then notice " " + chr$(13) +  "Des camps d'unités hostiles 'non joueur' sont disposés sur la carte. Tuer ces unités permet de gagner de l'expérience et des ressources."
        if version = 2 and mX >772 and mX <784 and mY >630 and mY <642 then notice " " + chr$(13) +  "Camps of hostile 'non-player' units are placed on the map. Killing these units grants experience and resources."
    if mX >790 and mX <802 and mY >650 and mY <662 then
        if Heroes = 0 then Heroes = 1 : goto [refreshMAP]
        if Heroes = 1 then Heroes = 0 : goto [refreshMAP]
    end if
        if version = 1 and mX >772 and mX <784 and mY >650 and mY <662 then notice " " + chr$(13) +  "Vos unités ont la capacité d'emmagasiner de l'expérience en tuant d'autres unités. Cela leur permet de monter de niveau et de gagner en puissance indépendamment des recherches."
        if version = 2 and mX >772 and mX <784 and mY >650 and mY <662 then notice " " + chr$(13) +  "Your units have the ability to gain experience by killing other units. This allows them to level up and gain power independent of research."
    if mX >790 and mX <802 and mY >670 and mY <692 then
        if Dynasty = 0 then Dynasty = 1 : goto [refreshMAP]
        if Dynasty = 1 then Dynasty = 0 : goto [refreshMAP]
    end if
        if version = 1 and mX >772 and mX <784 and mY >670 and mY <692 then notice " " + chr$(13) +  "La condition majeure pour gagner la partie est de détruire le village/bastion de l'ennemi. Il perd alors la partie, même s'il a encore une armée ou d'autres bâtiments."
        if version = 2 and mX >772 and mX <784 and mY >670 and mY <692 then notice " " + chr$(13) +  "The main condition to win the game is to destroy the enemy's village/stronghold. He then loses the game, even if he still has an army or other buildings."

    if mX >450 and mX <485 and mY >250 and mY <280 and NplaerMaxOnMap = 2 then teamSelect = 1 : goto [teamCHOICE]
    if mX >450 and mX <485 and mY >290 and mY <320 and NplaerMaxOnMap = 2 then teamSelect = 2 : goto [teamCHOICE]
    if mX >450 and mX <485 and mY >330 and mY <360 and NplaerMaxOnMap = 3 then teamSelect = 3 : goto [teamCHOICE]
    if mX >450 and mX <485 and mY >370 and mY <400 and NplaerMaxOnMap = 4 then teamSelect = 4 : goto [teamCHOICE]
    if mX >450 and mX <485 and mY >410 and mY <440 and NplaerMaxOnMap = 5 then teamSelect = 5 : goto [teamCHOICE]
    if mX >450 and mX <485 and mY >450 and mY <480 and NplaerMaxOnMap = 6 then teamSelect = 6 : goto [teamCHOICE]
    if mX >450 and mX <485 and mY >490 and mY <520 and NplaerMaxOnMap = 7 then teamSelect = 7 : goto [teamCHOICE]
    if mX >450 and mX <485 and mY >530 and mY <560 and NplaerMaxOnMap = 8 then teamSelect = 8 : goto [teamCHOICE]
    if mX >450 and mX <485 and mY >570 and mY <600 and NplaerMaxOnMap = 9 then teamSelect = 9 : goto [teamCHOICE]
    if mX >450 and mX <485 and mY >610 and mY <640 and NplaerMaxOnMap = 10 then teamSelect = 10 : goto [teamCHOICE]

    if mX >300 and mX <395 and mY >250 and mY <280 and NplaerMaxOnMap = 2 then raceSelect = 1 : goto [raceCHOICE]
    if mX >300 and mX <395 and mY >290 and mY <320 and NplaerMaxOnMap = 2 then raceSelect = 2 : goto [raceCHOICE]
    if mX >300 and mX <395 and mY >330 and mY <360 and NplaerMaxOnMap = 3 then raceSelect = 3 : goto [raceCHOICE]
    if mX >300 and mX <395 and mY >370 and mY <400 and NplaerMaxOnMap = 4 then raceSelect = 4 : goto [raceCHOICE]
    if mX >300 and mX <395 and mY >410 and mY <440 and NplaerMaxOnMap = 5 then raceSelect = 5 : goto [raceCHOICE]
    if mX >300 and mX <395 and mY >450 and mY <580 and NplaerMaxOnMap = 6 then raceSelect = 6 : goto [raceCHOICE]
    if mX >300 and mX <395 and mY >490 and mY <520 and NplaerMaxOnMap = 7 then raceSelect = 7 : goto [raceCHOICE]
    if mX >300 and mX <395 and mY >530 and mY <560 and NplaerMaxOnMap = 8 then raceSelect = 8 : goto [raceCHOICE]
    if mX >300 and mX <395 and mY >570 and mY <600 and NplaerMaxOnMap = 9 then raceSelect = 9 : goto [raceCHOICE]
    if mX >300 and mX <395 and mY >610 and mY <640 and NplaerMaxOnMap = 10 then raceSelect = 10 : goto [raceCHOICE]

    if NplaerMaxOnMap >= 2 and mX >125 and mX <275 and mY >290 and mY <320 and NplaerMaxOnMap = 2 then playerSelect = 2 : goto [playerCHOICE]
    if NplaerMaxOnMap >= 3 and mX >125 and mX <275 and mY >330 and mY <360 and NplaerMaxOnMap = 3 then playerSelect = 3 : goto [playerCHOICE]
    if NplaerMaxOnMap >= 4 and mX >125 and mX <275 and mY >370 and mY <400 and NplaerMaxOnMap = 4 then playerSelect = 4 : goto [playerCHOICE]
    if NplaerMaxOnMap >= 5 and mX >125 and mX <275 and mY >410 and mY <440 and NplaerMaxOnMap = 5 then playerSelect = 5 : goto [playerCHOICE]
    if NplaerMaxOnMap >= 6 and mX >125 and mX <275 and mY >450 and mY <480 and NplaerMaxOnMap = 6 then playerSelect = 6 : goto [playerCHOICE]
    if NplaerMaxOnMap >= 7 and mX >125 and mX <275 and mY >490 and mY <520 and NplaerMaxOnMap = 7 then playerSelect = 7 : goto [playerCHOICE]
    if NplaerMaxOnMap >= 8 and mX >125 and mX <275 and mY >530 and mY <560 and NplaerMaxOnMap = 8 then playerSelect = 8 : goto [playerCHOICE]
    if NplaerMaxOnMap >= 9 and mX >125 and mX <275 and mY >570 and mY <600 and NplaerMaxOnMap = 9 then playerSelect = 9 : goto [playerCHOICE]
    if NplaerMaxOnMap >= 10 and mX >125 and mX <275 and mY >610 and mY <640 and NplaerMaxOnMap = 10 then playerSelect = 10 : goto [playerCHOICE]

    wait

    [playerCHOICE]
    if version = 1 then
        dim aiTexts$(5)
        aiTexts$(0) = "Aucun"
        aiTexts$(1) = "Ordinateur - Facile"
        aiTexts$(2) = "Ordinateur - Normal"
        aiTexts$(3) = "Ordinateur - Difficile"
        aiTexts$(4) = "Ordinateur - Extrême"
        else
            dim aiTexts$(5)
            aiTexts$(0) = "None"
            aiTexts$(1) = "Computer - Easy"
            aiTexts$(2) = "Computer - Normal"
            aiTexts$(3) = "Computer - Hard"
            aiTexts$(4) = "Computer - Extreme"
    end if
    if playerSelect >= 2 and playerSelect <= 10 then
        AI(playerSelect) = AI(playerSelect) + 1
        yPos = 313 + (playerSelect - 2) * 40
        print #ini.map, "place 140 ";yPos;" ;\"; "         "
        if AI(playerSelect) > 4 then
            AI(playerSelect) = 0
            Team(playerSelect) = 0
            Race(playerSelect) = 0
            select case playerSelect
                case 2: Race2$ = ""
                case 3: Race3$ = ""
                case 4: Race4$ = ""
                case 5: Race5$ = ""
                case 6: Race6$ = ""
                case 7: Race7$ = ""
                case 8: Race8$ = ""
                case 9: Race9$ = ""
                case 10: Race10$ = ""
            end select
            print #ini.map, "place 315 ";yPos;" ;\"; "                     "
        end if
        select case playerSelect
            case 2: AI$(2) = aiTexts$(AI(2))
            case 3: AI$(3) = aiTexts$(AI(3))
            case 4: AI$(4) = aiTexts$(AI(4))
            case 5: AI$(5) = aiTexts$(AI(5))
            case 6: AI$(6) = aiTexts$(AI(6))
            case 7: AI$(7) = aiTexts$(AI(7))
            case 8: AI$(8) = aiTexts$(AI(8))
            case 9: AI$(9) = aiTexts$(AI(9))
            case 10: AI$(10) = aiTexts$(AI(10))
        end select
    end if
    goto [refreshMAP]

    [teamCHOICE]
    if teamSelect = 1 then Team(1) = Team(1) + 1 : print #ini.map, "place 460 273 ;\"; "     "
        if Team(1) >10 then Team(1) = 1
    if teamSelect = 2 then Team(2) = Team(2) + 1 : print #ini.map, "place 460 313 ;\"; "     "
        if Team(2) >10 then Team(2) = 1
    if teamSelect = 3 then Team(3) = Team(3) + 1 : print #ini.map, "place 460 353 ;\"; "     "
        if Team(3) >10 then Team(3) = 1
    if teamSelect = 4 then Team(4) = Team(4) + 1 : print #ini.map, "place 460 393 ;\"; "     "
        if Team(4) >10 then Team(4) = 1
    if teamSelect = 5 then Team(5) = Team(5) + 1 : print #ini.map, "place 460 433 ;\"; "     "
        if Team(5) >10 then Team(5) = 1
    if teamSelect = 6 then Team(6) = Team(6) + 1 : print #ini.map, "place 460 473 ;\"; "     "
        if Team(6) >10 then Team(6) = 1
    if teamSelect = 7 then Team(7) = Team(7) + 1 : print #ini.map, "place 460 513 ;\"; "     "
        if Team(7) >10 then Team(7) = 1
    if teamSelect = 8 then Team(8) = Team(8) + 1 : print #ini.map, "place 460 553 ;\"; "     "
        if Team(8) >10 then Team(8) = 1
    if teamSelect = 9 then Team(9) = Team(9) + 1 : print #ini.map, "place 460 593 ;\"; "     "
        if Team(9) >10 then Team(9) = 1
    if teamSelect = 10 then Team(10) = Team(10) + 1 : print #ini.map, "place 460 633 ;\"; "     "
        if Team(10) >10 then Team(10) = 1
    goto [refreshMAP]

    [raceCHOICE]
    if version = 1 then
        dim raceNames$(5)
        raceNames$(1) = "Humains"
        raceNames$(2) = "Orcs"
        raceNames$(3) = "Elfes"
        raceNames$(4) = "Morts-vivants"
        raceNames$(5) = "Nains"
    end if
    if version = 2 then
        dim raceNames$(5)
        raceNames$(1) = "Humans"
        raceNames$(2) = "Orcs"
        raceNames$(3) = "Elves"
        raceNames$(4) = "Undead"
        raceNames$(5) = "Dwarves"
    end if
    if raceSelect >= 1 and raceSelect <= 10 then
        Race(raceSelect) = Race(raceSelect) + 1
        yPos = 273 + (raceSelect - 1) * 40
        print #ini.map, "place 315 ";yPos;" ;\"; "                     "
        if Race(raceSelect) > 5 then Race(raceSelect) = 1
        select case raceSelect
            case 1: Race1$ = raceNames$(Race(1))
            case 2: Race2$ = raceNames$(Race(2))
            case 3: Race3$ = raceNames$(Race(3))
            case 4: Race4$ = raceNames$(Race(4))
            case 5: Race5$ = raceNames$(Race(5))
            case 6: Race6$ = raceNames$(Race(6))
            case 7: Race7$ = raceNames$(Race(7))
            case 8: Race8$ = raceNames$(Race(8))
            case 9: Race9$ = raceNames$(Race(9))
            case 10: Race10$ = raceNames$(Race(10))
        end select
    end if
    goto [refreshMAP]

    [ini2]
    if Setting = 1 then close #setting : Setting = 0
    if about = 1 then close #about : about = 0
    #ini, "trapclose [quit2]"
    #ini.map, "setfocus; down; fill ";185;" ";122;" ";87
    #ini.map, "when leftButtonDown [positionButton2]"
    #ini.map, "drawbmp back 40 40; drawbmp screenINI2 337 40; drawbmp button4 955 550"
    if version = 1 then #ini.map "drawbmp button1b 837 630"
    if version = 2 then #ini.map "drawbmp button1 837 630"

    if version = 1 then
        print #ini.map, "font Arial 9 ; color black; place 617 580 ;\"; "Verrouillage des équipes " : #ini.map "drawbmp check 787 568" : #ini.map "drawbmp about 770 568"
        print #ini.map, "place 617 600 ;\"; "Ressources inépuisables" : #ini.map "drawbmp check 787 588" : #ini.map "drawbmp about 770 588"
        print #ini.map, "place 617 640 ;\"; "Camps hostiles" : #ini.map "drawbmp check 787 628" : #ini.map "drawbmp about 770 628"
        print #ini.map, "place 617 660 ;\"; "Unités héroïques" : #ini.map "drawbmp check 787 648" : #ini.map "drawbmp about 770 648"
        print #ini.map, "place 617 680 ;\"; "Dynastie" : #ini.map "drawbmp check 787 668" : #ini.map "drawbmp about 770 668"
        print #ini.map, "place 617 620 ;\"; "Auto-Sauvegarde :" : #ini.map "drawbmp check 787 608" : #ini.map "drawbmp about 770 608"
        #ini.map "drawbmp button3b 160 200"
    end if
    if version = 2 then
        print #ini.map, "font Arial 9 ; color black; place 617 580 ;\"; "Team Lockdown " : #ini.map "drawbmp check 787 568" : #ini.map "drawbmp about 770 568"
        print #ini.map, "place 617 600 ;\"; "Inexhaustible resources" : #ini.map "drawbmp check 787 588" : #ini.map "drawbmp about 770 588"
        print #ini.map, "place 617 640 ;\"; "Hostile camps" : #ini.map "drawbmp check 787 628" : #ini.map "drawbmp about 770 628"
        print #ini.map, "place 617 660 ;\"; "Heroic Units" : #ini.map "drawbmp check 787 648" : #ini.map "drawbmp about 770 648"
        print #ini.map, "place 617 680 ;\"; "Dynasty" : #ini.map "drawbmp check 787 668" : #ini.map "drawbmp about 770 668"
        print #ini.map, "place 617 620 ;\"; "Auto-Save :" : #ini.map "drawbmp check 787 608" : #ini.map "drawbmp about 770 608"
        print #ini.map, "font Arial 11 italic; color black; place 627 210 ;\"; "Continents (2 players max)"
        #ini.map "drawbmp button3c 156 200"
    end if

    CallDLL #gdi32, "SetBkMode",_
        gDC As ulong,_          'handle of graphicbox
        _OPAQUE As long,_       'flag for transparent/opaque background
        result As long          'previous bkmode

    [refreshMAP]
    if mapSelected = 1 then
        #ini.map, "drawbmp MAP1mini 617 220"
        if version = 1 then print #ini.map, "backcolor ";185;" ";122;" ";87;"; font Arial 11 italic; color black; place 627 210 ;\"; "Continent (2 joueurs max)      "
        if version = 2 then print #ini.map, "backcolor ";185;" ";122;" ";87;"; font Arial 11 italic; color black; place 627 210 ;\"; "Continent (2 players max)      "
    end if
    if mapSelected = 2 then
        #ini.map, "drawbmp MAP2mini 617 220"
        if version = 1 then print #ini.map, "backcolor ";185;" ";122;" ";87;"; font Arial 11 italic; color black; place 627 210 ;\"; "La ligne (2 joueurs max)       "
        if version = 2 then print #ini.map, "backcolor ";185;" ";122;" ";87;"; font Arial 11 italic; color black; place 627 210 ;\"; "The line (2 players max)       "
    end if

    print #ini.map, "size 8; color ";255;" ";204;" ";50
    print #ini.map, "set ";795;" ";576
    print #ini.map, "set ";795;" ";596
    print #ini.map, "set ";795;" ";616
    print #ini.map, "set ";795;" ";636
    print #ini.map, "set ";795;" ";656
    print #ini.map, "set ";795;" ";676

    if autoSAVmode = 1 then print #ini.map, "size 8; color black; set ";795;" ";616
    if LockTeam = 1 then print #ini.map, "size 8; color black; set ";795;" ";576
    if RegenMap = 1 then print #ini.map, "size 8; color black; set ";795;" ";596
    if UnitHostile = 1 then print #ini.map, "size 8; color black; set ";795;" ";636
    if Heroes = 1 then print #ini.map, "size 8; color black; set ";795;" ";656
    if Dynasty = 1 then print #ini.map, "size 8; color black; set ";795;" ";676

    print #ini.map, "backcolor ";255;" ";204;" ";50;" ;font Arial 9; color black"
    #ini.map "drawbmp button3 127 250; drawbmp button3 127 290; drawbmp button3 127 330; drawbmp button3 127 370; drawbmp button3 127 410; drawbmp button3 127 450; drawbmp button3 127 490; drawbmp button3 127 530; drawbmp button3 127 570; drawbmp button3 127 610"

    if version = 1 and AI(2) = 1 and Race(2) = 0 and Race2$ = "" then Race(2) = 1 : Race2$ = "Humains"
    if version = 2 and AI(2) = 1 and Race(2) = 0 and Race2$ = "" then Race(2) = 1 : Race2$ = "Humans"
    if version = 1 and AI(3) = 1 and Race(3) = 0 and Race2$ = "" then Race(3) = 1 : Race3$ = "Humains"
    if version = 2 and AI(3) = 1 and Race(3) = 0 and Race2$ = "" then Race(3) = 1 : Race3$ = "Humans"
    if version = 1 and AI(4) = 1 and Race(4) = 0 and Race2$ = "" then Race(4) = 1 : Race4$ = "Humains"
    if version = 2 and AI(4) = 1 and Race(4) = 0 and Race2$ = "" then Race(4) = 1 : Race4$ = "Humans"
    if version = 1 and AI(5) = 1 and Race(5) = 0 and Race2$ = "" then Race(5) = 1 : Race5$ = "Humains"
    if version = 2 and AI(5) = 1 and Race(5) = 0 and Race2$ = "" then Race(5) = 1 : Race5$ = "Humans"
    if version = 1 and AI(6) = 1 and Race(6) = 0 and Race2$ = "" then Race(6) = 1 : Race6$ = "Humains"
    if version = 2 and AI(6) = 1 and Race(6) = 0 and Race2$ = "" then Race(6) = 1 : Race6$ = "Humans"
    if version = 1 and AI(7) = 1 and Race(7) = 0 and Race2$ = "" then Race(7) = 1 : Race7$ = "Humains"
    if version = 2 and AI(7) = 1 and Race(7) = 0 and Race2$ = "" then Race(7) = 1 : Race7$ = "Humans"
    if version = 1 and AI(8) = 1 and Race(8) = 0 and Race2$ = "" then Race(8) = 1 : Race8$ = "Humains"
    if version = 2 and AI(8) = 1 and Race(8) = 0 and Race2$ = "" then Race(8) = 1 : Race8$ = "Humans"
    if version = 1 and AI(9) = 1 and Race(9) = 0 and Race2$ = "" then Race(9) = 1 : Race9$ = "Humains"
    if version = 2 and AI(9) = 1 and Race(9) = 0 and Race2$ = "" then Race(9) = 1 : Race9$ = "Humans"
    if version = 1 and AI(10) = 1 and Race(10) = 0 and Race2$ = "" then Race(10) = 1 : Race10$ = "Humains"
    if version = 2 and AI(10) = 1 and Race(10) = 0 and Race2$ = "" then Race(10) = 1 : Race10$ = "Humans"

    if NplaerMaxOnMap >=1 and version = 1 then print #ini.map, "place 460 273 ;\"; Team(1) : print #ini.map, "place 315 273 ;\"; Race1$ : print #ini.map, "place 140 273 ;\"; "Joueur"
    if NplaerMaxOnMap >=1 and version = 2 then print #ini.map, "place 460 273 ;\"; Team(1) : print #ini.map, "place 315 273 ;\"; Race1$ : print #ini.map, "place 140 273 ;\"; "Player"
    if NplaerMaxOnMap >=2 then print #ini.map, "place 460 313 ;\"; Team(2) : print #ini.map, "place 315 313 ;\"; Race2$ : print #ini.map, "place 140 313 ;\"; AI$(2) : PlayerAlive(2) = 1
    if NplaerMaxOnMap >=3 then print #ini.map, "place 460 353 ;\"; Team(3) : print #ini.map, "place 315 353 ;\"; Race3$ : print #ini.map, "place 140 353 ;\"; AI$(3) : PlayerAlive(3) = 1
    if NplaerMaxOnMap >=4 then print #ini.map, "place 460 393 ;\"; Team(4) : print #ini.map, "place 315 393 ;\"; Race4$ : print #ini.map, "place 140 393 ;\"; AI$(4) : PlayerAlive(4) = 1
    if NplaerMaxOnMap >=5 then print #ini.map, "place 460 433 ;\"; Team(5) : print #ini.map, "place 315 433 ;\"; Race5$ : print #ini.map, "place 140 433 ;\"; AI$(5) : PlayerAlive(5) = 1
    if NplaerMaxOnMap >=6 then print #ini.map, "place 460 473 ;\"; Team(6) : print #ini.map, "place 315 473 ;\"; Race6$ : print #ini.map, "place 140 473 ;\"; AI$(6) : PlayerAlive(6) = 1
    if NplaerMaxOnMap >=7 then print #ini.map, "place 460 513 ;\"; Team(7) : print #ini.map, "place 315 513 ;\"; Race7$ : print #ini.map, "place 140 513 ;\"; AI$(7) : PlayerAlive(7) = 1
    if NplaerMaxOnMap >=8 then print #ini.map, "place 460 553 ;\"; Team(8) : print #ini.map, "place 315 553 ;\"; Race8$ : print #ini.map, "place 140 553 ;\"; AI$(8) : PlayerAlive(8) = 1
    if NplaerMaxOnMap >=9 then print #ini.map, "place 460 593 ;\"; Team(9) : print #ini.map, "place 315 593 ;\"; Race9$ : print #ini.map, "place 140 593 ;\"; AI$(9) : PlayerAlive(9) = 1
    if NplaerMaxOnMap >=10 then print #ini.map, "place 460 633 ;\"; Team(10) : print #ini.map, "place 315 633 ;\"; Race10$ : print #ini.map, "place 140 633 ;\"; AI$(10) : PlayerAlive(10) = 1
    print #ini.map, "flush"
    wait

    [noLoad]
    loading = 0 : close #secu : wait
    [Loadgame]
    on error goto [noLoad]
    dir$ = "" : file$ = "data.txt"
    if fileExist(dir$, file$) = 0 then
        if version = 1 then notice " " + chr$(13) + "Pas de sauvegarde détectée" : wait
        if version = 2 then notice " " + chr$(13) + "No backup detected" : wait
    end if

    loading = 1 : nSave = 0 : errorTxt = 1
    open "data.txt" for input as #secu

    ' === JOUEUR 1 ===
    input #secu, nourriture(1) : nSave = nSave + 1
    input #secu, bois(1) : nSave = nSave + 1
    input #secu, minerais(1) : nSave = nSave + 1
    input #secu, pop(1) : nSave = nSave + 1
    input #secu, popMAX(1) : nSave = nSave + 1
    input #secu, nombrePeon(1) : nSave = nSave + 1
    input #secu, ConstructionFermeDONE : nSave = nSave + 1
    input #secu, ConstructionTourDONE : nSave = nSave + 1
    input #secu, ConstructionFerme : nSave = nSave + 1
    input #secu, ConstructionTour : nSave = nSave + 1
    input #secu, ConstructionAcademie : nSave = nSave + 1
    input #secu, ConstructionCamp : nSave = nSave + 1
    input #secu, nombreSoldatA(1) : nSave = nSave + 1
    input #secu, nombreSoldatB(1) : nSave = nSave + 1
    for r = 1 to 10
        input #secu, rechercheAcad(r) : nSave = nSave + 1
    next r
    input #secu, Dynasty : nSave = nSave + 1
    input #secu, numSoldatP1 : nSave = nSave + 1

    for x = 1 to numSoldatP1
        input #secu, IDunitP1(x) : nSave = nSave + 1
        select case IDunitP1(x)
            case 1, 2, 3  ' Soldats/Workers
                input #secu, PVsoldatP1(x)
                input #secu, PvMAXsoldatP1(x)
                input #secu, ATKsoldatP1(x)
                input #secu, DEFsoldatP1(x)
                input #secu, POSxSOLDATp1(x)
                input #secu, POSySOLDATp1(x)
                input #secu, XpSoldatP1(x)
                input #secu, XpTotalSoldatP1(x)
                input #secu, LvlSoldatP1(x)
                input #secu, reloadTime(x)
            case 4  ' Tour
                input #secu, IDtourX(x)
                input #secu, IDtourY(x)
                input #secu, POSxTOWER(x)
                input #secu, POSyTOWER(x)
                input #secu, PVsoldatP1(x)
                input #secu, PvMAXsoldatP1(x)
                input #secu, DEFtour(x)
                input #secu, ATKtour(x)
                input #secu, reloadTower(x)
                input #secu, localisationTower(x)
            case 6  ' Camp
                input #secu, IDcampX(x)
                input #secu, IDcampY(x)
                input #secu, POSxCAMP(x)
                input #secu, POSyCAMP(x)
                input #secu, PvCamp(x)
                input #secu, PvMaxCamp(x)
                input #secu, DEFcamp(x)
            case 7  ' Ferme
                input #secu, IDfermeX(x)
                input #secu, IDfermeY(x)
                input #secu, POSxFerme(x)
                input #secu, POSyFerme(x)
                input #secu, PvFerme(x)
                input #secu, PvFermeMAX(x)
                input #secu, DEFferme(x)
                input #secu, nourritureRestante(x)
                input #secu, localisationFermage(x)
            case 8  ' Académie
                input #secu, IDacademieX(x)
                input #secu, IDacademieY(x)
                input #secu, POSxAcademie(x)
                input #secu, POSyAcademie(x)
                input #secu, PvAcademie(x)
                input #secu, PvMaxAcademie(x)
                input #secu, DEFacademie(x)
                input #secu, lvlAcademie(x)
            case 9  ' Village
                input #secu, IDvillageX(x)
                input #secu, IDvillageY(x)
                input #secu, POSxVillage(x)
                input #secu, POSyVillage(x)
                input #secu, PVsoldatP1(x)
                input #secu, PvMAXsoldatP1(x)
                input #secu, DEFvillage(x)
                input #secu, lvlVILLE(x)
        end select
    next x
    for r = 1 to 4
        input #secu, recherche(r)
    next r
    input #secu, ConstructionTourMax
    input #secu, ConstructionFermeMax
    input #secu, upgradeVILLE(1)
    input #secu, limiteFermage(1)
    input #secu, limiteBois(1)
    input #secu, limiteMines(1)
    input #secu, activationConstrucAcad
    input #secu, compteurAcad
    input #secu, acadX
    input #secu, acadY
    input #secu, activationConstrucFarm
    input #secu, compteurFarm
    input #secu, farmX
    input #secu, farmY
    input #secu, activationConstrucTower
    input #secu, compteurTower
    input #secu, towerX
    input #secu, towerY
    input #secu, activationConstrucCamp
    input #secu, compteurCamp
    input #secu, campX
    input #secu, campY
    ' === JOUEUR 2 (IA) ===
    input #secu, nourriture(2)
    input #secu, bois(2)
    input #secu, minerais(2)
    input #secu, pop(2)
    input #secu, popMAX(2)
    input #secu, nombrePeon(2)
    input #secu, ConstructionFermeAI1
    input #secu, ConstructionFermeDONEai1
    input #secu, ConstructionAcademieAI1
    input #secu, ConstructionCampAI1
    input #secu, ConstructionTourAI1
    input #secu, ConstructionTourMaxAI1
    input #secu, XvilleP2
    input #secu, YvilleP2
    input #secu, numSoldatP2
    input #secu, nombreSoldatA(2)
    input #secu, nombreSoldatB(2)
    input #secu, limiteFermage(2)
    input #secu, limiteBois(2)
    input #secu, limiteMines(2)
    for y = 1 to numSoldatP2
        input #secu, IDunitP2
        IDunitP2(y) = IDunitP2
        if IDunitP2(y) <= 0 then goto [skipLoadAI]
      '  notice y;" : ";numSoldatP2; " (";IDunitP2(y)
        select case IDunitP2(y)
            case 1, 2, 3  ' Soldats/Workers IA
                input #secu, PVsoldatP2 : PVsoldatP2(y) = PVsoldatP2
                input #secu, PVMAXsoldatP2 : PVMAXsoldatP2(y) = PVMAXsoldatP2
                input #secu, ATKsoldatP2 : ATKsoldatP2(y) = ATKsoldatP2
                input #secu, DEFsoldatP2 : DEFsoldatP2(y) = DEFsoldatP2
                input #secu, POSxSOLDATp2 : POSxSOLDATp2(y) = POSxSOLDATp2
                input #secu, POSySOLDATp2 : POSySOLDATp2(y) = POSySOLDATp2
                input #secu, reloadTimeE : reloadTimeE(y) = reloadTimeE
            case 7  ' Ferme IA
                input #secu, IDfermageXai : IDfermageXai(y) = IDfermageXai
                input #secu, IDfermageYai : IDfermageYai(y) = IDfermageYai
                input #secu, POSxSOLDATp2 : POSxSOLDATp2(y) = POSxSOLDATp2
                input #secu, POSySOLDATp2 : POSySOLDATp2(y) = POSySOLDATp2
                input #secu, PVsoldatP2 : PVsoldatP2(y) = PVsoldatP2
                input #secu, PVMAXsoldatP2 : PVMAXsoldatP2(y) = PVMAXsoldatP2
                input #secu, DEFsoldatP2 : DEFsoldatP2(y) = DEFsoldatP2
                input #secu, nourritureRestante2 : nourritureRestante2(y) = nourritureRestante2
            case 4, 5, 6  ' Village/Académie/Camp IA
                input #secu, POSxSOLDATp2 : POSxSOLDATp2(y) = POSxSOLDATp2
                input #secu, POSySOLDATp2 : POSySOLDATp2(y) = POSySOLDATp2
                input #secu, PVsoldatP2 : PVsoldatP2(y) = PVsoldatP2
                input #secu, PVMAXsoldatP2 : PVMAXsoldatP2(y) = PVMAXsoldatP2
                input #secu, DEFsoldatP2 : DEFsoldatP2(y) = DEFsoldatP2
            case 8  ' Tour IA
                input #secu, POSxSOLDATp2 : POSxSOLDATp2(y) = POSxSOLDATp2
                input #secu, POSySOLDATp2 : POSySOLDATp2(y) = POSySOLDATp2
                input #secu, PVsoldatP2 : PVsoldatP2(y) = PVsoldatP2
                input #secu, PVMAXsoldatP2 : PVMAXsoldatP2(y) = PVMAXsoldatP2
                input #secu, ATKsoldatP2 : ATKsoldatP2(y) = ATKsoldatP2
                input #secu, DEFsoldatP2 : DEFsoldatP2(y) = DEFsoldatP2
                input #secu, IDtourXai : IDtourXai(y) = IDtourXai
                input #secu, IDtourYai : IDtourYai(y) = IDtourYai
        end select
    [skipLoadAI]
    next y
    input #secu, activationConstrucTowerIA
    input #secu, compteurTowerAI
    input #secu, towerAIx
    input #secu, towerAIy
    input #secu, activationConstrucAcadIA
    input #secu, compteurAcadAI
    input #secu, acadAIx
    input #secu, acadAIy
    input #secu, activationConstrucCampIA
    input #secu, compteurCampAI
    input #secu, campAIx
    input #secu, campAIy
    input #secu, activationConstrucFermeIA
    input #secu, compteurFermeAI
    input #secu, farmAIx
    input #secu, farmAIy
    input #secu, ia1discoverPlayer
    close #secu
    goto [game]

    [w]
    wait
    [options]
    if Setting = 1 then close #setting
    Setting = 1
    WindowWidth = 300 : WindowHeight = 110 : UpperLeftX=int((DisplayWidth-WindowWidth)/2) : UpperLeftY=int((DisplayHeight-WindowHeight)/2)

    checkbox #setting.cb1, "Fr", [langue1], [langue1], 170, 10, 40, 20
    checkbox #setting.cb2, "Eng", [langue2], [langue2], 230, 10, 40, 20
    checkbox #setting.cb3, "On", [musiqueON], [musiqueON], 170, 30, 40, 20
    checkbox #setting.cb4, "Off", [musiqueOFF], [musiqueOFF], 230, 30, 40, 20
    checkbox #setting.cb5, "On", [bruitageON], [bruitageON], 170, 50, 40, 20
    checkbox #setting.cb6, "Off", [bruitageOFF], [bruitageOFF], 230, 50, 40, 20
    if version = 1 then
        statictext #setting, "Langue", 15, 10, 150, 20
        statictext #setting, "Musique", 15, 30, 150, 20
        statictext #setting, "Bruitage", 15, 50, 150, 20
    end if
    if version = 2 then
        statictext #setting, "Language", 15, 10, 150, 20
        statictext #setting, "Music", 15, 30, 150, 20
        statictext #setting, "Sound effects", 15, 50, 150, 20
    end if

    Stylebits #setting, 0, _WS_MAXIMIZEBOX or _WS_MINIMIZEBOX, _WS_EX_CLIENTEDGE or _WS_EX_TOPMOST, 0
    Open "" for window_nf As #setting
    if version = 1 then print #setting.cb1, "set" : print #setting.cb2, "reset"
    if version = 2 then print #setting.cb2, "set" : print #setting.cb1, "reset"
    if music = 0 then print #setting.cb4, "set" : print #setting.cb3, "reset"
    if music = 1 then print #setting.cb3, "set" : print #setting.cb4, "reset"
    if bruitage = 1 then print #setting.cb5, "set" : print #setting.cb6, "reset"
    if bruitage = 0 then print #setting.cb6, "set" : print #setting.cb5, "reset"
    #setting, "trapclose [quitSetting]"
    #setting, "font Courier_New 10"
    wait

    [musiqueON]
    if bruitage = 1 then r$ = mcisend$("play hit from 0")
  '  playwave "data\music.wav", loop
    music = 1 : print #setting.cb3, "set" : print #setting.cb4, "reset" : wait
    [musiqueOFF]
    if bruitage = 1 then r$ = mcisend$("play hit from 0")
   ' playwave ""
    music = 0 : print #setting.cb4, "set" : print #setting.cb3, "reset" : wait
    [bruitageON]
    if bruitage = 1 then r$ = mcisend$("play hit from 0")
    bruitage = 1 : print #setting.cb5, "set" : print #setting.cb6, "reset" : wait
    [bruitageOFF]
    bruitage = 0 : print #setting.cb6, "set" : print #setting.cb5, "reset" : wait

    [langue1]
    if bruitage = 1 then r$ = mcisend$("play hit from 0")
    if INgame = 0 then version = 1 : print #setting.cb1, "set" : print #setting.cb2, "reset" : close #ini : goto [ini]
    if INgame = 1 then version = 1 : print #setting.cb1, "set" : print #setting.cb2, "reset" : goto [endLEVEL]
    [langue2]
    if bruitage = 1 then r$ = mcisend$("play hit from 0")
    if INgame = 0 then version = 2 : print #setting.cb2, "set" : print #setting.cb1, "reset" : close #ini : goto [ini]
    if INgame = 1 then version = 2 : print #setting.cb2, "set" : print #setting.cb1, "reset" : goto [endLEVEL]
    [SavAuto]
    if bruitage = 1 then r$ = mcisend$("play hit from 0")
    if autoSAVmode = 0 then autoSAVmode = 1 : print #setting.cb7, "set" : wait
    if autoSAVmode = 1 then autoSAVmode = 0 : print #setting.cb7, "reset" : wait

    [quitSetting]
    if bruitage = 1 then r$ = mcisend$("play hit from 0")
    if Setting = 1 then close #setting : Setting = 0
    if INgame = 0 then wait
    goto [endLEVEL]

    [about]
    on error goto [w]
    WindowWidth=270 : WindowHeight=145
    UpperLeftX=int((DisplayWidth-WindowWidth)/2) : UpperLeftY=int((DisplayHeight-WindowHeight)/2)
    if about = 1 then close #about
    about = 1
    graphicbox #about.map, 2, 2, WindowWidth-10, WindowHeight-32
    open "" for window_nf as #about
    #about, "trapclose [about2]"
    #about.map, "cls;down;fill white"
    print #about.map, "font Courier_New 10; color black;backcolor white"
    if version = 1 then print #about.map, "place 20 30 ;\"; "Warcraft Legacy\Créé par Atomose Studio ® \Avec Liberty Basic 4.51 pro\\Mettre à jour sur atomose.fr"
    if version = 2 then print #about.map, "place 20 30 ;\"; "Warcraft Legacy\Created by Atomose Studio ® \With Liberty Basic 4.51 pro\\Upgrade it on atomose.fr"
    #about, "font Courier_New 8"
    print #about.map, "color black"
    wait
    [about2]
    if bruitage = 1 then r$ = mcisend$("play hit from 0")
    timer 0 : close #about : about = 0 : wait

    [game]
    close #ini
    if Setting = 1 then close #setting : Setting = 0
    if about = 1 then close #about : about = 0
    cursor CROSSHAIR
    WindowWidth = 1152 : WindowHeight = 800 : UpperLeftX=int((DisplayWidth-WindowWidth)/2) : UpperLeftY=int((DisplayHeight-WindowHeight)/2) : x = 30 : y = 28
    global dy, dx : dim p(x,y), Xcoord(2000), Ycoord(2000)
    graphicbox #main.map, 2, 0, 866, WindowHeight-30
    graphicbox #main.map2, 870, 0, 274, WindowHeight-30
    Stylebits #main, 0, _WS_MAXIMIZEBOX or _WS_MINIMIZEBOX, _WS_EX_CLIENTEDGE or _WS_EX_TOPMOST, 0
    open "" for window_nf as #main
    #main, "trapclose [quit]"
    #main.map, "setfocus; down; fill white"
    #main.map2, "setfocus; down; fill white"
    on error goto [whereISerror]
    if mapSelected = 1 then goto [map1]
    if mapSelected = 2 then goto [map2]

    [map1] ' continents 2 players
    redim p(x,y)
    redim b(x,y)
    redim c(x,y)
    data 016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016
    data 016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016
    data 016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016
    data 016,016,016,016,008,007,007,007,007,007,007,007,007,007,007,007,007,007,007,007,007,007,007,007,007,006,016,016,016,016
    data 016,016,016,016,009,004,003,003,003,003,003,003,003,004,003,003,000,000,000,003,004,003,003,000,004,005,016,016,016,016
    data 016,016,016,016,009,003,004,003,003,003,003,000,003,003,004,003,003,003,000,000,000,000,003,000,000,005,016,016,016,016
    data 016,016,016,016,009,000,000,000,000,003,000,000,000,000,000,003,003,003,004,003,003,000,000,000,000,005,016,016,016,016
    data 016,016,016,016,009,000,000,000,000,000,000,003,000,000,003,003,003,000,003,003,000,000,000,000,000,005,016,016,016,016
    data 016,016,016,016,009,003,000,000,000,000,004,003,003,000,003,003,003,000,003,000,000,000,000,000,000,005,016,016,016,016
    data 016,016,016,016,009,003,003,003,000,004,004,003,000,000,004,003,000,000,000,000,003,000,004,003,003,005,016,016,016,016
    data 016,016,016,016,009,003,003,000,000,000,003,000,000,003,004,000,000,003,000,000,004,000,003,003,004,005,016,016,016,016
    data 016,016,016,016,009,003,004,003,000,000,000,000,000,000,000,000,003,004,003,000,000,000,000,000,000,005,016,016,016,016
    data 016,016,016,016,009,000,003,000,000,003,000,003,003,000,000,003,003,004,003,003,000,003,003,004,000,005,016,016,016,016
    data 016,016,016,016,009,003,000,000,003,000,000,000,003,003,000,000,003,000,000,000,000,000,000,000,000,005,016,016,016,016
    data 016,016,016,016,009,004,000,000,000,000,000,000,000,000,000,000,000,000,000,004,000,000,000,000,000,005,016,016,016,016
    data 016,016,016,016,009,004,003,000,000,003,000,000,000,000,003,000,000,000,000,003,004,000,000,000,003,005,016,016,016,016
    data 016,016,016,016,009,003,004,003,000,004,000,000,003,000,000,000,000,000,003,003,000,004,003,000,003,005,016,016,016,016
    data 016,016,016,016,009,000,004,004,000,003,000,000,004,000,000,000,003,004,004,003,000,003,003,000,000,005,016,016,016,016
    data 016,016,016,016,009,000,003,000,000,000,000,004,004,003,000,000,000,004,003,003,003,000,004,003,000,005,016,016,016,016
    data 016,016,016,016,009,000,000,000,000,000,000,000,003,000,000,003,000,000,003,004,003,003,003,003,003,005,016,016,016,016
    data 016,016,016,016,009,000,000,000,000,000,000,000,000,000,000,003,003,000,000,003,004,003,003,000,000,005,016,016,016,016
    data 016,016,016,016,009,003,000,000,003,000,003,000,000,000,000,000,003,000,000,003,004,003,003,000,000,005,016,016,016,016
    data 016,016,016,016,009,003,000,003,003,003,000,000,000,003,000,000,000,000,000,003,000,000,000,000,000,005,016,016,016,016
    data 016,016,016,016,009,004,003,003,003,004,000,000,004,003,003,000,000,003,004,000,000,000,000,000,000,005,016,016,016,016
    data 016,016,016,016,010,011,011,011,011,011,011,011,011,011,011,011,011,011,011,011,011,011,011,011,011,012,016,016,016,016
    data 016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016
    data 016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016
    data 016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016
    restore [map1]
    goto [endMAPselected]

    [map2] ' the line 2 players
    redim p(x,y)
    redim b(x,y)
    redim c(x,y)
    data 016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016
    data 016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016
    data 016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016
    data 016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016
    data 016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016
    data 016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016
    data 016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016
    data 016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016
    data 016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016
    data 016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016
    data 016,016,016,016,008,007,007,007,007,007,007,007,007,007,007,007,007,007,007,007,007,007,007,007,007,006,016,016,016,016
    data 016,016,016,016,009,000,003,000,000,003,000,003,003,000,000,003,003,004,003,003,000,003,003,004,000,005,016,016,016,016
    data 016,016,016,016,009,003,000,000,003,000,000,000,003,003,000,000,003,000,000,000,000,000,000,000,000,005,016,016,016,016
    data 016,016,016,016,009,004,000,000,000,000,000,000,000,000,000,000,000,000,000,004,000,000,000,000,000,005,016,016,016,016
    data 016,016,016,016,009,004,003,000,000,003,000,000,000,000,003,000,000,000,000,003,004,000,000,000,003,005,016,016,016,016
    data 016,016,016,016,009,003,004,003,000,004,000,000,003,000,000,000,000,000,003,003,000,004,003,000,003,005,016,016,016,016
    data 016,016,016,016,009,000,004,004,000,003,000,000,004,000,000,000,003,004,004,003,000,003,003,000,000,005,016,016,016,016
    data 016,016,016,016,010,011,011,011,011,011,011,011,011,011,011,011,011,011,011,011,011,011,011,011,011,012,016,016,016,016
    data 016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016
    data 016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016
    data 016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016
    data 016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016
    data 016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016
    data 016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016
    data 016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016
    data 016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016
    data 016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016
    data 016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016,016
    restore [map2]

    [endMAPselected]
    for b=0 to y-1
        for a=0 to x-1
            XY = XY + 1
            read valeur
            p(a,b)= valeur : b(a,b) = valeur : c(a,b) = XY
            if valeur = 3 then b(a,b) = int(rnd(1)*2500+1000)
            if valeur = 4 then b(a,b) = int(rnd(1)*2500+1000)
        next a
    next b
    XY = 0 : menuCONSTRUCTION = 1 : showFPS = 60

    if loading = 1 then
        ConstructionFermeAI1 = 0 : ConstructionTourAI1 = 0
        for x = 1 to numSoldatP2
            if IDunitP2(x) = 1 then print #main.map,"addsprite ennemiA";x;" ennemiA"
            if IDunitP2(x) = 2 then print #main.map,"addsprite ennemiB";x;" ennemiB"
            if IDunitP2(x) = 3 then print #main.map,"addsprite ennemiC";x;" ennemiC"
            if IDunitP2(x) = 6 and PVsoldatP2(x) > 0 then p(POSxSOLDATp2(x)/96,POSySOLDATp2(x)/96) = 26
            if IDunitP2(x) = 7 and PVsoldatP2(x) > 0 then p(IDfermageXai(x)/96,IDfermageYai(x)/96) = 28 : b(IDfermageXai(x)/96,IDfermageYai(x)/96) = nourritureRestante2(x) : ConstructionFermeAI1 = ConstructionFermeAI1 + 1
            if IDunitP2(x) = 5 and PVsoldatP2(x) > 0 then p(POSxSOLDATp2(x)/96,POSySOLDATp2(x)/96) = 24
            if IDunitP2(x) = 8 and PVsoldatP2(x) > 0 then p(POSxSOLDATp2(x)/96,POSySOLDATp2(x)/96) = 30 : ConstructionTourAI1 = ConstructionTourAI1 + 1
            if IDunitP2(x) = 4 then p(XvilleP2,YvilleP2) = 22 : if PVsoldatP2(x) <=0 then p(XvilleP2,YvilleP2) = 23
        next x
        ConstructionFerme = 0 : ConstructionTour = 0
        for y = 1 to numSoldatP1
            if IDunitP1(y) = 1 then print #main.map,"addsprite HommeDarme";y;" perso2"
            if IDunitP1(y) = 2 then print #main.map,"addsprite Lancier";y;" perso3"
            if IDunitP1(y) = 3 then print #main.map,"addsprite peon";y;" perso1"
            if IDunitP1(y) = 4 then p(IDtourX(y)/96,IDtourY(y)/96) = 13 : ConstructionTour = ConstructionTour + 1
            if IDunitP1(y) = 6 and PvCamp(y) > 0 then p(campX,campY) = 14
            if IDunitP1(y) = 7 and PvFerme(y) > 0 and nourritureRestante(y) > 0 then p(IDfermeX(y)/96,IDfermeY(y)/96) = 1 : b(IDfermeX(y)/96,IDfermeY(y)/96) = nourritureRestante(y) : ConstructionFerme = ConstructionFerme + 1
            if IDunitP1(y) = 8 and PvAcademie(y) >0 then p(IDacademieX(y)/96,IDacademieY(y)/96) = 15
            if IDunitP1(y) = 9 then p(IDvillageX(y),IDvillageY(y)) = 2 : if PVsoldatP1(y) <=0 then p(IDvillageX(y),IDvillageY(y)) = 21
        next y
    end if

    if loading = 0 then
        'player
        numSoldatP1 = 1 : IDunitP1(numSoldatP1)= 9
        if mapSelected = 1 then xNEW = 7 : yNEW = 6
        if mapSelected = 2 then xNEW = 5 : yNEW = 13
        p(xNEW,yNEW) = 2 : POSxVillage(numSoldatP1) = xNEW*96 : POSyVillage(numSoldatP1) = yNEW*96
        IDvillageX(numSoldatP1) = xNEW : IDvillageY(numSoldatP1) = yNEW : DEFvillage(numSoldatP1) = 1
        lvlVILLE(numSoldatP1) = 1 : PVsoldatP1(numSoldatP1) = 100 : PvMAXsoldatP1(numSoldatP1) = 100 : upgradeVILLE(numSoldatP1) = 0
        nombrePeon(1) = 0 : nombreSoldatA(1) = 0 : nombreSoldatB(1) = 0 : lvlAcademie(1) = 0 : limiteFermage(1) = 1 : limiteBois(1) = 4 : limiteMines(1) = 1
        'AI 1
        numSoldatP2 = 1 : IDunitP2(numSoldatP2) = 4
        if mapSelected = 1 then XvilleP2 = 22 : YvilleP2 = 22
        if mapSelected = 2 then XvilleP2 = 24 : YvilleP2 = 13
        p(XvilleP2,YvilleP2) = 22 : POSxSOLDATp2(numSoldatP2) = XvilleP2*96 : POSySOLDATp2(numSoldatP2) = YvilleP2*96 : ia1discoverPlayer = 0
        DEFsoldatP2(numSoldatP2) = 1 : lvlVILLEAI(numSoldatP2) = 1 : PVsoldatP2(numSoldatP2) = 100 : PVMAXsoldatP2(numSoldatP2) = 100 : upgradeVILLEAI(numSoldatP2) = 0
        nombrePeon(2) = 0 : nombreSoldatA(2) = 0 : nombreSoldatB(2) = 0 : lvlAcademie(2) = 0
        nourriture(2) = 200 : bois(2) = 50 : minerais(2) = 0 : pop(2) = 0 : popMAX(2) = 15 : limiteFermage(2) = 1 : limiteBois(2) = 4 : limiteMines(2) = 1
        ConstructionFermeAI1 = 0 : ConstructionFermeMaxAI1 = 2
    end if

    print #main.map, "addsprite system system; spritexy system 15 12; SpriteVisible system off"
    print #main.map, "addsprite system2 system2; spritexy system2 40 12; SpriteVisible system2 off"
    print #main.map, "addsprite system3 system3; spritexy system3 65 12; SpriteVisible system3 off"
    print #main.map, "addsprite home home; spritexy home 830 12; SpriteVisible home on"
    print #main.map, "addsprite loca1 loca1; spritexy loca1 805 12; SpriteVisible loca1 on"
    print #main.map, "addsprite loca2 loca2; spritexy loca2 780 12; SpriteVisible loca2 on"
    if mapSelected = 1 then valIniX =3 : valIniY = 2 : MinMAPmooveX = 380 : MinMAPmooveY = 290 : MaxMAPmooveX = 2330 : MaxMAPmooveY = 2240
    if mapSelected = 2 then valIniX =1 : valIniY = 9 : MinMAPmooveX = 380 : MinMAPmooveY = 960 : MaxMAPmooveX = 2330 : MaxMAPmooveY = 1575

 '   valIniX =41 : valIniY = 31
    loading = 0 : moovingActivation = 1
    securityMOOVE2 = 0

    hGBox = hwnd(#main.map)
    CallDLL #user32, "GetDC",_
        hGBox As ulong,_  'handle of graphicbox
        gDC As ulong      'device context
    CallDLL #gdi32, "SetBkMode",_
        gDC As ulong,_          'handle of graphicbox
        _TRANSPARENT As long,_  'flag for transparent/opaque background
        result As long          'previous bkmode
    CallDLL#user32,"ReleaseDC",_
        hGBox As ulong,_    'graphicbox handle
        gDC As ulong,_      'device context
        result As long
    goto [positionINI]


    [GAMElaws]
    if laws = 1 then close #laws
    laws = 1
    WindowWidth = 350 : WindowHeight = 170 : UpperLeftX=int((DisplayWidth-WindowWidth)/2) : UpperLeftY=int((DisplayHeight-WindowHeight)/2)

    if version = 1 then
        statictext #laws, "Verrouillage des équipes", 15, 10, 200, 20
            if LockTeam = 0 then statictext #laws, "Désactivé", 245, 10, 80, 20
            if LockTeam = 1 then statictext #laws, "Activé", 245, 10, 80, 20
        statictext #laws, "Ressources inépuisables", 15, 30, 200, 20
            if RegenMap = 0 then statictext #laws, "Désactivé", 245, 30, 80, 20
            if RegenMap = 1 then statictext #laws, "Activé", 245, 30, 80, 20
        statictext #laws, "Sauvegarde automatique", 15, 50, 200, 20
            if autoSAVmode = 0 then statictext #laws, "Désactivé", 245, 50, 80, 20
            if autoSAVmode = 1 then statictext #laws, "Activé", 245, 50, 80, 20
        statictext #laws, "Camps hostiles", 15, 70, 200, 20
            if UnitHostile = 0 then statictext #laws, "Désactivé", 245, 70, 80, 20
            if UnitHostile = 1 then statictext #laws, "Activé", 245, 70, 80, 20
        statictext #laws, "Unités héroïques", 15, 90, 200, 20
            if Heroes = 0 then statictext #laws, "Désactivé", 245, 90, 80, 20
            if Heroes = 1 then statictext #laws, "Activé", 245, 90, 80, 20
        statictext #laws, "Dynastie", 15, 110, 200, 20
            if Dynasty = 0 then statictext #laws, "Désactivé", 245, 110, 80, 20
            if Dynasty = 1 then statictext #laws, "Activé", 245, 110, 80, 20
    end if
    if version = 2 then
        statictext #laws, "Team Lockdown", 15, 10, 200, 20
            if LockTeam = 0 then statictext #laws, "Disable", 245, 10, 80, 20
            if LockTeam = 1 then statictext #laws, "Enable", 245, 10, 80, 20
        statictext #laws, "Inexhaustible resources", 15, 30, 200, 20
            if RegenMap = 0 then statictext #laws, "Disable", 245, 30, 80, 20
            if RegenMap = 1 then statictext #laws, "Enable", 245, 30, 80, 20
        statictext #laws, "Auto Backup", 15, 50, 200, 20
            if autoSAVmode = 0 then statictext #laws, "Disable", 245, 50, 80, 20
            if autoSAVmode = 1 then statictext #laws, "Enable", 245, 50, 80, 20
        statictext #laws, "Hostile camps", 15, 70, 200, 20
            if UnitHostile = 0 then statictext #laws, "Disable", 245, 70, 80, 20
            if UnitHostile = 1 then statictext #laws, "Enable", 245, 70, 80, 20
        statictext #laws, "Heroic Units", 15, 90, 200, 20
            if Heroes = 0 then statictext #laws, "Disable", 245, 90, 80, 20
            if Heroes = 1 then statictext #laws, "Enable", 245, 90, 80, 20
        statictext #laws, "Dynasty", 15, 110, 200, 20
            if Dynasty = 0 then statictext #laws, "Disable", 245, 110, 80, 20
            if Dynasty = 1 then statictext #laws, "Enable", 245, 110, 80, 20
    end if

    Stylebits #laws, 0, _WS_MAXIMIZEBOX or _WS_MINIMIZEBOX, _WS_EX_CLIENTEDGE or _WS_EX_TOPMOST, 0
    if version = 1 then Open "Paramètres de la partie" for window_nf As #laws
    if version = 2 then Open "Game setting" for window_nf As #laws
    #laws, "trapclose [quitlaws]"
    #laws, "font Courier_New 10"
    wait

    [quitlaws]
    if bruitage = 1 then r$ = mcisend$("play hit from 0")
    close #laws : laws = 0 : wait

'----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'------------------------      BOUCLE PRINCIPALE DU JEU      ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    [whereISerror]
    print #main.map2, "place 15 750 ;\"; "Error detected : line ";errorTxt : kill "data.txt"
    wait

    [endLEVEL]
    scan
    on error goto [whereISerror]
    MouseXini = MouseX : MouseYini = MouseY : INgame = 1
    #main.map, "discard; when leftButtonDown [position]; when rightButtonMove [moovingXY]; when leftButtonUp [selectXY]; when rightButtonDown [GoMoove]"
    #main.map2, "discard; when leftButtonDown [build]"

    if moovingActivation >= 1 and moovingActivation < 3 then
        num1 = 0 : bgList$ = ""
        terrainSprites$(0) = "herbe1"
        terrainSprites$(16) = "eau1"
        terrainSprites$(5) = "herbe2"
        terrainSprites$(6) = "herbe10"
        terrainSprites$(7) = "herbe9"
        terrainSprites$(8) = "herbe11"
        terrainSprites$(9) = "herbe7"
        terrainSprites$(10) = "herbe12"
        terrainSprites$(11) = "herbe8"
        terrainSprites$(12) = "herbe13"
        terrainSprites$(1) = "ferme1"
        terrainSprites$(19) = "ferme1b"
        terrainSprites$(13) = "tour1"
        terrainSprites$(17) = "tour1b"
        terrainSprites$(14) = "caserne1"
        terrainSprites$(18) = "caserne1b"
        terrainSprites$(15) = "academie1"
        terrainSprites$(20) = "academie1b"
        terrainSprites$(2) = "maison1"
        terrainSprites$(21) = "maison1b"
        terrainSprites$(22) = "maison2"
        terrainSprites$(23) = "maison2b"
        terrainSprites$(24) = "academie2"
        terrainSprites$(25) = "academie2b"
        terrainSprites$(26) = "caserne2"
        terrainSprites$(27) = "caserne2b"
        terrainSprites$(28) = "ferme2"
        terrainSprites$(29) = "ferme2b"
        terrainSprites$(30) = "tour2"
        terrainSprites$(31) = "tour2b"
        terrainSprites$(999) = "building"
        for y = int(0+valIniY) to int(valIniY+8)
            valY = 96*(y-(0+valIniY))
            for x = int(0+valIniX) to int(valIniX+9)
                valX = 96*(x-(0+valIniX))
                num1 = num1 + 1
                sprName$ = "spr" + str$(num1)
                tileType = p(x, y)
                spriteName$ = terrainSprites$(tileType)
                if tileType = 3 and b(x,y) <= 2000 then spriteName$ = "foret2"
                if tileType = 3 and b(x,y) > 2000 then spriteName$ = "foret1"
                if tileType = 4 and b(x,y) <= 2000 then spriteName$ = "montagne2"
                if tileType = 4 and b(x,y) > 2000 then spriteName$ = "montagne1"
                print #main.map, "addsprite ";sprName$;" ";spriteName$;"; spritexy ";sprName$;" ";valX;" ";valY
                bgList$ = bgList$ + " " + sprName$
            next x
        next y
    end if

    time = time$("seconds")
    if time > TimeOld then gosub [boucle]
    TimeOld = time : fps = fps +1

    gosub [CoreAI]

    print #main.map, "SpriteVisible system on; spritetofront system; SpriteVisible system2 on; spritetofront system2; SpriteVisible system3 on; spritetofront system3"
    print #main.map, "SpriteVisible home on; spritetofront home; SpriteVisible loca1 on; spritetofront loca1; SpriteVisible loca2 on; spritetofront loca2"
    #main.map "drawsprites"

    if activationConstrucAcad = 1 then print #main.map, "place ";int((((acadX)-valIniX)*96)+40);" ";int((((acadY)-valIniY)*96)+20);" ;\"; compteurAcad
    if activationConstrucFarm = 1 then print #main.map, "place ";int((((farmX)-valIniX)*96)+40);" ";int((((farmY)-valIniY)*96)+20);" ;\"; compteurFarm
    if activationConstrucTower = 1 then print #main.map, "place ";int((((towerX)-valIniX)*96)+40);" ";int((((towerY)-valIniY)*96)+20);" ;\"; compteurTower
    if activationConstrucCamp = 1 then print #main.map, "place ";int((((campX)-valIniX)*96)+40);" ";int((((campY)-valIniY)*96)+20);" ;\"; compteurCamp

    if moovingActivation = 1 then
        num1OLD = num1 : num2 = 0 : moovingActivation = moovingActivation + 1
        for r = 0 to num1OLD-1
            num2 = num2 +1 : print #main.map,"removesprite ";"spr";num2
        next r
    end if
    goto [endLEVEL]

'----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'-----end main loop---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    [chercheRESSOURCE]
    offsetX = int(rnd(1)*30-50) : offsetY = int(rnd(1)*30-40)
    if p(XvilleP2-2,YvilleP2-2) = ressourceW and p((POSxSOLDATp2(i)/96)+1,(POSySOLDATp2(i)/96)+0.5) <> ressourceW then MoovingTOai(i) = 1 : mXmoove1AI(i) = (XvilleP2-2)*96 + offsetX : mYmoove1AI(i) = (YvilleP2-2)*96 + offsetY
    if p(XvilleP2-1,YvilleP2-2) = ressourceW and p((POSxSOLDATp2(i)/96)+1,(POSySOLDATp2(i)/96)+0.5) <> ressourceW then MoovingTOai(i) = 1 : mXmoove1AI(i) = (XvilleP2-1)*96 + offsetX : mYmoove1AI(i) = (YvilleP2-2)*96 + offsetY
    if p(XvilleP2,YvilleP2-2) = ressourceW and p((POSxSOLDATp2(i)/96)+1,(POSySOLDATp2(i)/96)+0.5) <> ressourceW then MoovingTOai(i) = 1   : mXmoove1AI(i) = (XvilleP2)*96 + offsetX   : mYmoove1AI(i) = (YvilleP2-2)*96 + offsetY
    if p(XvilleP2+1,YvilleP2-2) = ressourceW and p((POSxSOLDATp2(i)/96)+1,(POSySOLDATp2(i)/96)+0.5) <> ressourceW then MoovingTOai(i) = 1 : mXmoove1AI(i) = (XvilleP2+1)*96 + offsetX : mYmoove1AI(i) = (YvilleP2-2)*96 + offsetY
    if p(XvilleP2+2,YvilleP2-2) = ressourceW and p((POSxSOLDATp2(i)/96)+1,(POSySOLDATp2(i)/96)+0.5) <> ressourceW then MoovingTOai(i) = 1 : mXmoove1AI(i) = (XvilleP2+2)*96 + offsetX : mYmoove1AI(i) = (YvilleP2-2)*96 + offsetY
    if p(XvilleP2-1,YvilleP2) = ressourceW and p((POSxSOLDATp2(i)/96)+1,(POSySOLDATp2(i)/96)+0.5) <> ressourceW then MoovingTOai(i) = 1   : mXmoove1AI(i) = (XvilleP2-1)*96 + offsetX : mYmoove1AI(i) = (YvilleP2)*96 + offsetY
    if p(XvilleP2-1,YvilleP2-1) = ressourceW and p((POSxSOLDATp2(i)/96)+1,(POSySOLDATp2(i)/96)+0.5) <> ressourceW then MoovingTOai(i) = 1 : mXmoove1AI(i) = (XvilleP2-1)*96 + offsetX : mYmoove1AI(i) = (YvilleP2-1)*96 + offsetY
    if p(XvilleP2-1,YvilleP2+1) = ressourceW and p((POSxSOLDATp2(i)/96)+1,(POSySOLDATp2(i)/96)+0.5) <> ressourceW then MoovingTOai(i) = 1 : mXmoove1AI(i) = (XvilleP2-1)*96 + offsetX : mYmoove1AI(i) = (YvilleP2+1)*96 + offsetY
    if p(XvilleP2-2,YvilleP2-1) = ressourceW and p((POSxSOLDATp2(i)/96)+1,(POSySOLDATp2(i)/96)+0.5) <> ressourceW then MoovingTOai(i) = 1 : mXmoove1AI(i) = (XvilleP2-2)*96 + offsetX : mYmoove1AI(i) = (YvilleP2-1)*96 + offsetY
    if p(XvilleP2-2,YvilleP2) = ressourceW and p((POSxSOLDATp2(i)/96)+1,(POSySOLDATp2(i)/96)+0.5) <> ressourceW then MoovingTOai(i) = 1   : mXmoove1AI(i) = (XvilleP2-2)*96 + offsetX : mYmoove1AI(i) = (YvilleP2)*96 + offsetY
    if p(XvilleP2-2,YvilleP2+1) = ressourceW and p((POSxSOLDATp2(i)/96)+1,(POSySOLDATp2(i)/96)+0.5) <> ressourceW then MoovingTOai(i) = 1 : mXmoove1AI(i) = (XvilleP2-2)*96 + offsetX : mYmoove1AI(i) = (YvilleP2+1)*96 + offsetY
    if p(XvilleP2,YvilleP2-1) = ressourceW and p((POSxSOLDATp2(i)/96)+1,(POSySOLDATp2(i)/96)+0.5) <> ressourceW then MoovingTOai(i) = 1   : mXmoove1AI(i) = (XvilleP2)*96 + offsetX   : mYmoove1AI(i) = (YvilleP2-1)*96 + offsetY
    if p(XvilleP2,YvilleP2-2) = ressourceW and p((POSxSOLDATp2(i)/96)+1,(POSySOLDATp2(i)/96)+0.5) <> ressourceW then MoovingTOai(i) = 1   : mXmoove1AI(i) = (XvilleP2)*96 + offsetX   : mYmoove1AI(i) = (YvilleP2-2)*96 + offsetY
    if p(XvilleP2,YvilleP2+1) = ressourceW and p((POSxSOLDATp2(i)/96)+1,(POSySOLDATp2(i)/96)+0.5) <> ressourceW then MoovingTOai(i) = 1   : mXmoove1AI(i) = (XvilleP2)*96 + offsetX   : mYmoove1AI(i) = (YvilleP2+1)*96 + offsetY
    if p(XvilleP2,YvilleP2+2) = ressourceW and p((POSxSOLDATp2(i)/96)+1,(POSySOLDATp2(i)/96)+0.5) <> ressourceW then MoovingTOai(i) = 1   : mXmoove1AI(i) = (XvilleP2)*96 + offsetX   : mYmoove1AI(i) = (YvilleP2+2)*96 + offsetY
    if p(XvilleP2+1,YvilleP2) = ressourceW and p((POSxSOLDATp2(i)/96)+1,(POSySOLDATp2(i)/96)+0.5) <> ressourceW then MoovingTOai(i) = 1   : mXmoove1AI(i) = (XvilleP2+1)*96 + offsetX : mYmoove1AI(i) = (YvilleP2)*96 + offsetY
    if p(XvilleP2+1,YvilleP2-1) = ressourceW and p((POSxSOLDATp2(i)/96)+1,(POSySOLDATp2(i)/96)+0.5) <> ressourceW then MoovingTOai(i) = 1 : mXmoove1AI(i) = (XvilleP2+1)*96 + offsetX : mYmoove1AI(i) = (YvilleP2-1)*96 + offsetY
    if p(XvilleP2+1,YvilleP2+1) = ressourceW and p((POSxSOLDATp2(i)/96)+1,(POSySOLDATp2(i)/96)+0.5) <> ressourceW then MoovingTOai(i) = 1 : mXmoove1AI(i) = (XvilleP2+1)*96 + offsetX : mYmoove1AI(i) = (YvilleP2+1)*96 + offsetY
    if p(XvilleP2+2,YvilleP2-1) = ressourceW and p((POSxSOLDATp2(i)/96)+1,(POSySOLDATp2(i)/96)+0.5) <> ressourceW then MoovingTOai(i) = 1 : mXmoove1AI(i) = (XvilleP2+2)*96 + offsetX : mYmoove1AI(i) = (YvilleP2-1)*96 + offsetY
    if p(XvilleP2+2,YvilleP2) = ressourceW and p((POSxSOLDATp2(i)/96)+1,(POSySOLDATp2(i)/96)+0.5) <> ressourceW then MoovingTOai(i) = 1   : mXmoove1AI(i) = (XvilleP2+2)*96 + offsetX : mYmoove1AI(i) = (YvilleP2)*96 + offsetY
    if p(XvilleP2+2,YvilleP2+1) = ressourceW and p((POSxSOLDATp2(i)/96)+1,(POSySOLDATp2(i)/96)+0.5) <> ressourceW then MoovingTOai(i) = 1 : mXmoove1AI(i) = (XvilleP2+2)*96 + offsetX : mYmoove1AI(i) = (YvilleP2+1)*96 + offsetY
    return

    [boucle]
    showFPS = fps : compteurAtkAI1 = compteurAtkAI1 - 1 : cleanupCounter = cleanupCounter + 1

    if noRESSOURCEshow = 0 then
        print #main.map2, "font Courier_New 10; color black"
        print #main.map2, "place 73 36 ;\"; "          "
        print #main.map2, "place 73 36 ;\"; int(nourriture(1));"(";NworkerFARM(1)+2;")"
        print #main.map2, "place 73 66 ;\"; "          "
        print #main.map2, "place 73 66 ;\"; int(bois(1));"(";NworkerWOOD(1);")"
        print #main.map2, "place 190 36 ;\"; "          "
        print #main.map2, "place 190 36 ;\"; int(minerais(1));"(";NworkerMINE(1);")"
        print #main.map2, "place 190 66 ;\"; "          "
        print #main.map2, "place 190 66 ;\"; pop(1); "/";popMAX(1)
    end if

    if menuCONSTRUCTION = 0 and AchatUnitMode = 0 and p(xNEW,yNEW) = 4 and version = 1 then print #main.map2, "place 15 475 ;\"; "Minerais disponible : " ; b(xNEW,yNEW) ; "    " : print #main.map2, "place 15 460 ;\"; "Mineur(s) : "; NworkerMINE(1); "/";limiteMines(1); "  "
    if menuCONSTRUCTION = 0 and AchatUnitMode = 0 and p(xNEW,yNEW) = 3 and version = 1 then print #main.map2, "place 15 475 ;\"; "Bois disponible : " ; b(xNEW,yNEW) ; "    " : print #main.map2, "place 15 460 ;\"; "Bûcheron(s) : "; NworkerWOOD(1); "/";limiteBois(1); "  "
    if menuCONSTRUCTION = 0 and AchatUnitMode = 0 and p(xNEW,yNEW) = 1 and version = 1 then
        for t = 1 to numSoldatP1
            if IDunitP1(t) = 7 and c(xNEW,yNEW) = localisationFermage(t) then ID2 = t
        next t
        print #main.map2, "place 15 445 ;\"; "Nourriture disponible : " ; b(xNEW,yNEW) ; "    " : print #main.map2, "place 15 430 ;\"; "Fermier(s) : "; limiteWorkerFermage(ID2); " / ";limiteFermage(1); "  "
    end if
    if menuCONSTRUCTION = 0 and AchatUnitMode = 0 and p(xNEW,yNEW) = 4 and version = 2 then print #main.map2, "place 15 475 ;\"; "Minerals available : " ; b(xNEW,yNEW) ; "    " : print #main.map2, "place 15 460 ;\"; "Miner(s) : "; NworkerMINE(1); "/";limiteMines(1); "  "
    if menuCONSTRUCTION = 0 and AchatUnitMode = 0 and p(xNEW,yNEW) = 3 and version = 2 then print #main.map2, "place 15 475 ;\"; "Wood available : " ; b(xNEW,yNEW) ; "    " : print #main.map2, "place 15 460 ;\"; "Woodcutter(s) : "; NworkerWOOD(1); "/";limiteBois(1); "  "
    if menuCONSTRUCTION = 0 and AchatUnitMode = 0 and p(xNEW,yNEW) = 1 and version = 2 then
        for t = 1 to numSoldatP1
            if IDunitP1(t) = 7 and c(xNEW,yNEW) = localisationFermage(t) then ID2 = t
        next t
        print #main.map2, "place 15 445 ;\"; "Food available : " ; b(xNEW,yNEW) ; "    " : print #main.map2, "place 15 430 ;\"; "Farmer(s) : "; limiteWorkerFermage(ID2); " / ";limiteFermage(1); "  "
    end if

    if cleanupCounter >= 30 then
        nombrePeon(2) = 0 : nombreSoldatA(2) = 0 : nombreSoldatB(2) = 0 : pop(2) = 0 : securityMOOVE2 = 0
        for k = 1 to numSoldatP2
            if IDunitP2(k) = 1 and PVsoldatP2(k) > 0 then nombreSoldatA(2) = nombreSoldatA(2) + 1 : pop(2) = pop(2) +1
            if IDunitP2(k) = 2 and PVsoldatP2(k) > 0 then nombreSoldatB(2) = nombreSoldatB(2) + 1 : pop(2) = pop(2) +1
            if IDunitP2(k) = 3 and PVsoldatP2(k) > 0 then nombrePeon(2) = nombrePeon(2) +1 : pop(2) = pop(2) +1
        next k
        cleanupCounter = 0
        for cleanI = 1 to numSoldatP2
            if PVsoldatP2(cleanI) <= 0 and arrow1Active(cleanI) = 1 then
                print #main.map, "removesprite arrowX";cleanI;"Y";cleanI
                arrow1Active(cleanI) = 0
            end if
        next cleanI
    end if
    if autoSAVmode = 1 then autoSAV = autoSAV + 1
    if autoSAV >= 300 then autoSAV = 0 : goto [autoSAVE]
    if rechercheAcad(7) = 1 then nourriture(1) = nourriture(1) + 1 : bois(1) = bois(1) + 1 : minerais(1) = minerais(1) + 1
    if RegenMap = 1 then regenMAPx = int(rnd(1)*30+1) : regenMAPy = int(rnd(1)*28+1) : if b(regenMAPx,regenMAPy) > 50 then b(regenMAPx,regenMAPy) = b(regenMAPx,regenMAPy) + 50

    ' ressource AI 1
    NworkerWOOD(2) = 0 : NworkerFARM(2) = 0 : NworkerMINE(2) = 0
    for b = 1 to numSoldatP2
        if PVsoldatP2(b) <=0 then goto [SKIPai1b]
        select case IDunitP2(b)
            case 3
            cellCheck = int((POSxSOLDATp2(b)/96)+1)
            cellCheckY = int((POSySOLDATp2(b)/96)+0.5)
            if p(cellCheck, cellCheckY) = 28 and NworkerFARM(2) < limiteFermage(2) then
                NworkerFARM(2) = NworkerFARM(2) + 1 : nourriture(2) = nourriture(2) + 1 : nourritureRESTANT = b(cellCheck, cellCheckY) : b(cellCheck, cellCheckY) = nourritureRESTANT - 1
                if b(cellCheck, cellCheckY) <= 0 then
                    for f = 1 to numSoldatP2
                        checkCell = int((POSxSOLDATp2(f)/96)+1)
                        checkCellY = int((POSySOLDATp2(f)/96)+0.5)
                        if p(checkCell, checkCellY) = 28 then mXmoove1AI(f) = 0 : mYmoove1AI(f) = 0 : MoovingTOai(f) = 0
                    next f
                    PVsoldatP2(b) = 0 : b(cellCheck, cellCheckY) = 0 : p(cellCheck, cellCheckY) = 0 : moovingActivation = 2 : ConstructionFermeAI1 = ConstructionFermeAI1 - 1 : goto [endLEVEL]
                end if
            end if
            if p((POSxSOLDATp2(b)/96)+1,(POSySOLDATp2(b)/96)+0.5) = 4 and NworkerMINE(2) < limiteMines(2) then
                NworkerMINE(2) = NworkerMINE(2) + 1 : minerais(2) = minerais(2) + 1 : mineraisRESTANT = b((POSxSOLDATp2(b)/96)+1,(POSySOLDATp2(b)/96)+0.5) : b((POSxSOLDATp2(b)/96)+1,(POSySOLDATp2(b)/96)+0.5) = mineraisRESTANT - 1
                if b((POSxSOLDATp2(b)/96)+1,(POSySOLDATp2(b)/96)+0.5) <= 0 then p((POSxSOLDATp2(b)/96)+1,(POSySOLDATp2(b)/96)+0.5) = 0 : b((POSxSOLDATp2(b)/96)+1,(POSySOLDATp2(b)/96)+0.5) = 0 : moovingActivation = 2 : MoovingTOai(b) = 0 : goto [endLEVEL]
            end if
            if p((POSxSOLDATp2(b)/96)+1,(POSySOLDATp2(b)/96)+0.5) = 3 and NworkerWOOD(2) < limiteBois(2) then
                NworkerWOOD(2) = NworkerWOOD(2) + 1 : bois(2) = bois(2) + 1 : boisRESTANT = b((POSxSOLDATp2(b)/96)+1,(POSySOLDATp2(b)/96)+0.5) : b((POSxSOLDATp2(b)/96)+1,(POSySOLDATp2(b)/96)+0.5) = boisRESTANT - 1
                if b((POSxSOLDATp2(b)/96)+1,(POSySOLDATp2(b)/96)+0.5) <= 0 then b((POSxSOLDATp2(b)/96)+1,(POSySOLDATp2(b)/96)+0.5) = 0 : p((POSxSOLDATp2(b)/96)+1,(POSySOLDATp2(b)/96)+0.5) = 0 : moovingActivation = 2 : MoovingTOai(b) = 0 : goto [endLEVEL]
            end if
        end select
        [SKIPai1b]
    next b

    ' ressource joueur
    NworkerWOOD(1) = 0 : NworkerFARM(1) = 0 : NworkerMINE(1) = 0
    for a = 1 to numSoldatP1
        limiteWorkerFermage(a) = 0
    next a
    for u = 1 to numSoldatP1
        if PVsoldatP1(u) <= 0 and PvFerme(u) <= 0 and PvCamp(u) <= 0 and PvAcademie(u) <= 0 then goto [SKIPb]
        select case IDunitP1(u)
            case 3
                for x = 1 to numSoldatP1
                    select case IDunitP1(x)
                        case 7
                            if c((POSxSOLDATp1(u)/96)+1,(POSySOLDATp1(u)/96)+0.5) = localisationFermage(x) and limiteWorkerFermage(x) < limiteFermage(1) then
                                limiteWorkerFermage(x) = limiteWorkerFermage(x) + 1 : nourriture(1) = nourriture(1) + 1 : NworkerFARM(1) = NworkerFARM(1) + 1 : nourritureRESTANT = b((POSxSOLDATp1(u)/96)+1,(POSySOLDATp1(u)/96)+0.5) : b((POSxSOLDATp1(u)/96)+1,(POSySOLDATp1(u)/96)+0.5) = nourritureRESTANT - 1
                                if b((POSxSOLDATp1(u)/96)+1,(POSySOLDATp1(u)/96)+0.5) <= 0 then
                                    for f = 1 to numSoldatP1
                                        if IDfermageX(f) = (POSxSOLDATp1(u)/96)+1 and IDfermageY(f) = (POSySOLDATp1(u)/96)+0.5 then IDfermage(f) = 0 : IDfermageX(f) = 0 : IDfermageY(f) = 0
                                    next f
                                    PvFerme(u) = 0 : localisationFermage(x) = 0 : b((POSxSOLDATp1(u)/96)+1,(POSySOLDATp1(u)/96)+0.5) = 0 : p((POSxSOLDATp1(u)/96)+1,(POSySOLDATp1(u)/96)+0.5) = 0 : moovingActivation = 2 : ConstructionFerme = ConstructionFerme - 1 : print #main.map2, "cls"
                                    if ConstructionFerme < 0 then ConstructionFerme = 0
                                    goto [refreshLAND]
                                end if
                            end if
                    end select
                next x
                if p((POSxSOLDATp1(u)/96)+1,(POSySOLDATp1(u)/96)+0.5) = 4 and NworkerMINE(1) < limiteMines(1) then
                    NworkerMINE(1) = NworkerMINE(1) + 1 : minerais(1) = minerais(1) + 1 : mineraisRESTANT = b((POSxSOLDATp1(u)/96)+1,(POSySOLDATp1(u)/96)+0.5) : b((POSxSOLDATp1(u)/96)+1,(POSySOLDATp1(u)/96)+0.5) = mineraisRESTANT - 1
                    if b((POSxSOLDATp1(u)/96)+1,(POSySOLDATp1(u)/96)+0.5) <= 0 then p((POSxSOLDATp1(u)/96)+1,(POSySOLDATp1(u)/96)+0.5) = 0 : b((POSxSOLDATp1(u)/96)+1,(POSySOLDATp1(u)/96)+0.5) = 0 : moovingActivation = 2 : print #main.map2, "cls" : goto [endLEVEL]
                end if
                if p((POSxSOLDATp1(u)/96)+1,(POSySOLDATp1(u)/96)+0.5) = 3 and NworkerWOOD(1) < limiteBois(1) then
                    NworkerWOOD(1) = NworkerWOOD(1) + 1 : bois(1) = bois(1) + 1 : boisRESTANT = b((POSxSOLDATp1(u)/96)+1,(POSySOLDATp1(u)/96)+0.5) : b((POSxSOLDATp1(u)/96)+1,(POSySOLDATp1(u)/96)+0.5) = boisRESTANT - 1
                    if b((POSxSOLDATp1(u)/96)+1,(POSySOLDATp1(u)/96)+0.5) <= 0 then b((POSxSOLDATp1(u)/96)+1,(POSySOLDATp1(u)/96)+0.5) = 0 : p((POSxSOLDATp1(u)/96)+1,(POSySOLDATp1(u)/96)+0.5) = 0 : moovingActivation = 2 : print #main.map2, "cls" : goto [endLEVEL]
                end if
        end select
        [SKIPb]
    next u

    if activationConstrucAcad = 1 then compteurAcad = compteurAcad - 1 : p(acadX,acadY) = 999
    if activationConstrucFarm = 1 then compteurFarm = compteurFarm - 1 : p(farmX,farmY) = 999
    if activationConstrucTower = 1 then compteurTower = compteurTower - 1 : p(towerX,towerY) = 999
    if activationConstrucCamp = 1 then compteurCamp = compteurCamp - 1 : p(campX,campY) = 999
    if activationConstrucTowerIA = 1 then compteurTowerAI = compteurTowerAI - 1 : p(towerAIx,towerAIy) = 999
    if activationConstrucAcadIA = 1 then compteurAcadAI = compteurAcadAI - 1 : p(acadAIx,acadAIy) = 999
    if activationConstrucCampIA = 1 then compteurCampAI = compteurCampAI - 1 : p(campAIx,campAIy) = 999
    if activationConstrucFermeIA = 1 then compteurFermeAI = compteurFermeAI - 1 : p(farmAIx,farmAIy) = 999

    'academy
    if compteurAcad <= 0 and activationConstrucAcad = 1 then
        activationConstrucAcad = 0 : numSoldatP1 = numSoldatP1 + 1 : IDunitP1(numSoldatP1) = 8 : lvlAcademie(numSoldatP1) = 1 : PvAcademie(numSoldatP1) = 40 : PvMaxAcademie(numSoldatP1) = 40 : DEFacademie(numSoldatP1) = 0 : p(acadX,acadY) = 15 : IDacademieX(numSoldatP1) = acadX*96 : IDacademieY(numSoldatP1) = acadY*96 : POSxAcademie(numSoldatP1) = IDacademieX(numSoldatP1) : POSyAcademie(numSoldatP1) = IDacademieY(numSoldatP1) : moovingActivation = 1
        if rechercheAcad(1) = 1 then PvAcademie(numSoldatP1) = PvAcademie(numSoldatP1) + 5 : PvMaxAcademie(numSoldatP1) = PvMaxAcademie(numSoldatP1) + 5
        if rechercheAcad(9) = 1 then DEFacademie(numSoldatP1) = DEFacademie(numSoldatP1) + 1
        goto [endBuildAI1]
    end if
    'farm
    if compteurFarm <= 0 and activationConstrucFarm = 1 then
        activationConstrucFarm = 0 : numSoldatP1 = numSoldatP1 + 1 : localisationFermage(numSoldatP1) = c(farmX,farmY) : IDunitP1(numSoldatP1) = 7 : b(farmX,farmY) = 200 : PvFerme(numSoldatP1) = 5 : PvFermeMAX(numSoldatP1) = 5 : DEFferme(numSoldatP1) = 0 : p(farmX,farmY) = 1 : IDfermeX(numSoldatP1) = farmX*96 : IDfermeY(numSoldatP1) = farmY*96 : POSxFerme(numSoldatP1) = IDfermeX(numSoldatP1) : POSyFerme(numSoldatP1) = IDfermeY(numSoldatP1) : moovingActivation = 1
        if rechercheAcad(1) = 1 then PvFerme(numSoldatP1) = PvFerme(numSoldatP1) + 5 : PvFermeMAX(numSoldatP1) = PvFermeMAX(numSoldatP1) + 5
        if rechercheAcad(9) = 1 then DEFferme(numSoldatP1) = DEFferme(numSoldatP1) + 1
        if rechercheAcad(2) = 1 then b(farmX,farmY) = 550
        goto [endBuildAI1]
    end if
    'tower
    if compteurTower <= 0 and activationConstrucTower = 1 then
        activationConstrucTower = 0 : numSoldatP1 = numSoldatP1 + 1 : localisationTower(numSoldatP1) = c(towerX,towerY) : IDunitP1(numSoldatP1) = 4 : PVsoldatP1(numSoldatP1) = 15 : PvMAXsoldatP1(numSoldatP1) = 15 : DEFtour(numSoldatP1) = 2 : ATKtour(numSoldatP1) = 5 : p(towerX,towerY) = 13 : reloadTower(numSoldatP1) = 10 : IDtourX(numSoldatP1) = towerX*96 : IDtourY(numSoldatP1) = towerY*96 : POSxTOWER(numSoldatP1) = IDtourX(numSoldatP1) : POSyTOWER(numSoldatP1) = IDtourY(numSoldatP1) : moovingActivation = 1
        if rechercheAcad(1) = 1 then PVsoldatP1(numSoldatP1) = PVsoldatP1(numSoldatP1) + 5 : PvMAXsoldatP1(numSoldatP1) = PvMAXsoldatP1(numSoldatP1) + 5
        if rechercheAcad(8) = 1 then PVsoldatP1(numSoldatP1) = PVsoldatP1(numSoldatP1) + 10 : PvMAXsoldatP1(numSoldatP1) = PvMAXsoldatP1(numSoldatP1) + 10
        if rechercheAcad(9) = 1 then DEFtour(numSoldatP1) = DEFtour(numSoldatP1) + 1
        goto [endBuildAI1]
    end if
    'camp
    if compteurCamp <= 0 and activationConstrucCamp = 1 then
        activationConstrucCamp = 0 : numSoldatP1 = numSoldatP1 + 1 : IDunitP1(numSoldatP1) = 6 : PvCamp(numSoldatP1) = 30 : PvMaxCamp(numSoldatP1) = 30 : DEFcamp(numSoldatP1) = 0 : p(campX,campY) = 14 : IDcampX(numSoldatP1) = campX*96 : IDcampY(numSoldatP1) = campY*96 : POSxCAMP(numSoldatP1) = IDcampX(numSoldatP1) : POSyCAMP(numSoldatP1) = IDcampY(numSoldatP1) : moovingActivation = 1
        if rechercheAcad(1) = 1 then PvCamp(numSoldatP1) = PvCamp(numSoldatP1) + 5 : PvMaxCamp(numSoldatP1) = PvMaxCamp(numSoldatP1) + 5
        if rechercheAcad(9) = 1 then DEFcamp(numSoldatP1) = DEFcamp(numSoldatP1) + 1
        goto [endBuildAI1]
    end if

    ' ressources de base
    nourriture(1) = nourriture(1) + 2
    nourriture(2) = nourriture(2) + 2  : bois(2) = bois(2) + 1 : minerais(2) = minerais(2) + 1

    'worker p2
    if nombrePeon(2) < 4 and nourriture(2) >= 20 and pop(2) < popMAX(2) and PVsoldatP2(1) > 0 then
        nombrePeon(2) = nombrePeon(2) + 1 : pop(2) = pop(2) + 1
        numSoldatP2 = numSoldatP2 + 1 : IDunitP2(numSoldatP2) = 3 : POSxSOLDATp2(numSoldatP2) = int(rnd(1)*50+(XvilleP2*95))  : POSySOLDATp2(numSoldatP2) = int(rnd(1)*50+(YvilleP2*96))
        PVsoldatP2(numSoldatP2) = 4 : PVMAXsoldatP2(numSoldatP2) = PVsoldatP2(numSoldatP2) : ATKsoldatP2(numSoldatP2) = 2 : DEFsoldatP2(numSoldatP2) = 0 : reloadTimeE(numSoldatP2) = 50
        nworker2 = nworker2 + 1 : nourriture(2) = nourriture(2) - 20
        print #main.map, "addsprite ennemiC";numSoldatP2;" ennemiC; spritexy ennemiC";numSoldatP2;" ";POSxSOLDATp2(numSoldatP2);" ";POSySOLDATp2(numSoldatP2);"; SpriteVisible ennemiC";numSoldatP2;" on; spritetofront ennemiC";numSoldatP2
    end if


    armyP2 = nombreSoldatA(2)+nombreSoldatB(2)
    minArmySize = 6  ' Taille minimale de l'armée
    if nourriture(2) > 300 and bois(2) > 200 then minArmySize = 10

    shouldAttack = 0
    if armyP2 >= minArmySize and ia1discoverPlayer = 1 then shouldAttack = 1

    if securityMOOVE2 = 0 then
        if ia1discoverPlayer = 0 and minArmySize >= 2 then
            securityMOOVE2 = 1
            if mapSelected = 1 then MooveXp2 = int(rnd(1)*(MaxMAPmooveX-430)+(MinMAPmooveX-20)) : MooveYp2 = int(rnd(1)*(MaxMAPmooveY-340)+(MinMAPmooveY-10))
            if mapSelected = 2 then MooveXp2 = int(rnd(1)*(MaxMAPmooveX-430)+(MinMAPmooveX-20)) : MooveYp2 = int(rnd(1)*(MaxMAPmooveY-1100)+(MinMAPmooveY-10))
            for i = 1 to numSoldatP2
                select case IDunitP2(i)
                    case 1,2
                        if PVsoldatP2(i) > 0 then
                            mXmoove1AI(i) = int(rnd(1)*50+MooveXp2) : mYmoove1AI(i) = int(rnd(1)*50+MooveYp2)
                            UnitP2intoArmy(i) = 1 : MoovingTOai(i) = 1
                        end if
                end select
            next i
        end if
        if ia1discoverPlayer = 1 and shouldAttack = 1 then
            MooveXp2 = (IDvillageX(1)*96)-192 : MooveYp2 = (IDvillageY(1)*96)-192
            securityMOOVE2 = 1
            for i = 1 to numSoldatP2
                select case IDunitP2(i)
                    case 1,2
                        if PVsoldatP2(i) > 0 then
                            mXmoove1AI(i) = int(rnd(1)*200+MooveXp2) : mYmoove1AI(i) = int(rnd(1)*200+MooveYp2)
                            UnitP2intoArmy(i) = 1 : MoovingTOai(i) = 1
                        end if
                end select
            next i
        end if
    end if

    ' Riposte
    if ia1attacked = 1 and compteurAtkAI1 = 0 then
    if armyP2 >= 5 then
        MooveXp2 = (IDvillageX(1)*96)-96 : MooveYp2 = (IDvillageY(1)*96)-96
        securityMOOVE2 = 1 : compteurAtkAI1 = 100
        for i = 1 to numSoldatP2
            select case IDunitP2(i)
                case 1,2
                    if PVsoldatP2(i) > 0 then
                        mXmoove1AI(i) = int(rnd(1)*200+MooveXp2) : mYmoove1AI(i) = int(rnd(1)*200+MooveYp2)
                        UnitP2intoArmy(i) = 1 : MoovingTOai(i) = 1
                    end if
            end select
        next i
    end if
    end if

    'towers
    if compteurTowerAI <= 0 and activationConstrucTowerIA = 1 then activationConstrucTowerIA = 0 : numSoldatP2 = numSoldatP2 + 1 : IDunitP2(numSoldatP2) = 8 : PVsoldatP2(numSoldatP2) = 15 : PVMAXsoldatP2(numSoldatP2) = 15 : ATKsoldatP2(numSoldatP2) = 5 : reloadTimeE(numSoldatP2) = 50 : DEFsoldatP2(numSoldatP2) = 0 : p(towerAIx,towerAIy) = 30 : bois(2) = bois(2) - 50 : minerais(2) = minerais(2) - 15 : IDtourXai(numSoldatP2) = towerAIx*96 : IDtourYai(numSoldatP2) = towerAIy*96 : POSxSOLDATp2(numSoldatP2) = IDtourXai(numSoldatP2) : POSySOLDATp2(numSoldatP2) = IDtourYai(numSoldatP2) : moovingActivation = 1 ': goto [endBuildAI1]
    'academy
    if compteurAcadAI <= 0 and activationConstrucAcadIA = 1 then activationConstrucAcadIA = 0 : numSoldatP2 = numSoldatP2 + 1 : IDunitP2(numSoldatP2) = 5 : PVsoldatP2(numSoldatP2) = 40 : PVMAXsoldatP2(numSoldatP2) = 40 : ATKsoldatP2(numSoldatP2) = 0 : DEFsoldatP2(numSoldatP2) = 0 : p(acadAIx,acadAIy) = 24 : bois(2) = bois(2) - 110 : minerais(2) = minerais(2) - 50 : IDacademieXai(numSoldatP2) = acadAIx*96 : IDacademieYai(numSoldatP2) = acadAIy*96 : POSxSOLDATp2(numSoldatP2) = IDacademieXai(numSoldatP2) : POSySOLDATp2(numSoldatP2) = IDacademieYai(numSoldatP2) : moovingActivation = 1 ': goto [endBuildAI1]
    'camp
    if compteurCampAI <= 0 and activationConstrucCampIA = 1 then activationConstrucCampIA = 0 : numSoldatP2 = numSoldatP2 + 1 : IDunitP2(numSoldatP2) = 6 : PVsoldatP2(numSoldatP2) = 30 : PVMAXsoldatP2(numSoldatP2) = 30 : ATKsoldatP2(numSoldatP2) = 0 : DEFsoldatP2(numSoldatP2) = 0 : p(campAIx,campAIy) = 26 : bois(2) = bois(2) - 60 : IDcampXai(numSoldatP2) = campAIx*96 : IDcampYai(numSoldatP2) = campAIy*96 : POSxSOLDATp2(numSoldatP2) = IDcampXai(numSoldatP2) : POSySOLDATp2(numSoldatP2) = IDcampYai(numSoldatP2) : ConstructionCampAI1 = ConstructionCampAI1 + 1 : moovingActivation = 1 ': goto [endBuildAI1]
    'farm
    if compteurFermeAI <= 0 and activationConstrucFermeIA = 1 then iniWorkerIA = 2 : Skipp = 1 : activationConstrucFermeIA = 0 : numSoldatP2 = numSoldatP2 + 1 : IDunitP2(numSoldatP2) = 7 : PVsoldatP2(numSoldatP2) = 10 : PVMAXsoldatP2(numSoldatP2) = 10 : ATKsoldatP2(numSoldatP2) = 0 : DEFsoldatP2(numSoldatP2) = 0 : p(farmAIx,farmAIy) = 28 : b(farmAIx,farmAIy) = 1500 : bois(2) = bois(2) - 35 : IDfermageXai(numSoldatP2) = farmAIx*96 : IDfermageYai(numSoldatP2) = farmAIy*96 : POSxSOLDATp2(numSoldatP2) = IDfermageXai(numSoldatP2) : POSySOLDATp2(numSoldatP2) = IDfermageYai(numSoldatP2) : moovingActivation = 1 ': goto [endBuildAI1]

    if nombrePeon(2) >0 then
        choixConstruc = int(rnd(1)*5+1)
        select case choixConstruc
            case 1 'farm
            PositionBatAI = int(rnd(1)*14+1)
            select case PositionBatAI
                case 1
                    if activationConstrucFermeIA = 0 and ConstructionFermeAI1 < ConstructionFermeMaxAI1 and bois(2) >40 and (p(XvilleP2-1,YvilleP2) = 0 or p(XvilleP2-1,YvilleP2) = 25 or p(XvilleP2-1,YvilleP2) = 27 or p(XvilleP2-1,YvilleP2) = 29 or p(XvilleP2-1,YvilleP2) = 31) then p(XvilleP2-1,YvilleP2) = 999 : activationConstrucFermeIA = 1 : farmAIx = XvilleP2-1 : farmAIy = YvilleP2 : compteurFermeAI = 4 : ConstructionFermeAI1 = ConstructionFermeAI1 + 1 : moovingActivation = 1
                case 2
                    if activationConstrucFermeIA = 0 and ConstructionFermeAI1 < ConstructionFermeMaxAI1 and bois(2) >40 and (p(XvilleP2-1,YvilleP2-1) = 0 or p(XvilleP2-1,YvilleP2-1) = 25 or p(XvilleP2-1,YvilleP2-1) = 27 or p(XvilleP2-1,YvilleP2-1) = 29 or p(XvilleP2-1,YvilleP2-1) = 31) then p(XvilleP2-1,YvilleP2-1) = 999 : activationConstrucFermeIA = 1 : farmAIx = XvilleP2-1 : farmAIy = YvilleP2-1 : compteurFermeAI = 4 : ConstructionFermeAI1 = ConstructionFermeAI1 + 1 : moovingActivation = 1
                case 3
                    if activationConstrucFermeIA = 0 and ConstructionFermeAI1 < ConstructionFermeMaxAI1 and bois(2) >40 and (p(XvilleP2,YvilleP2-1) = 0 or p(XvilleP2,YvilleP2-1) = 25 or p(XvilleP2,YvilleP2-1) = 27 or p(XvilleP2,YvilleP2-1) = 29 or p(XvilleP2,YvilleP2-1) = 31) then p(XvilleP2,YvilleP2-1) = 999 : activationConstrucFermeIA = 1 : farmAIx = XvilleP2 : farmAIy = YvilleP2-1 : compteurFermeAI = 4 : ConstructionFermeAI1 = ConstructionFermeAI1 + 1 : moovingActivation = 1
                case 4
                    if activationConstrucFermeIA = 0 and ConstructionFermeAI1 < ConstructionFermeMaxAI1 and bois(2) >40 and (p(XvilleP2+1,YvilleP2-1) = 0 or p(XvilleP2+1,YvilleP2-1) = 25 or p(XvilleP2+1,YvilleP2-1) = 27 or p(XvilleP2+1,YvilleP2-1) = 29 or p(XvilleP2+1,YvilleP2-1) = 31) then p(XvilleP2+1,YvilleP2-1) = 999 : activationConstrucFermeIA = 1 : farmAIx = XvilleP2+1 : farmAIy = YvilleP2-1 : compteurFermeAI = 4 : ConstructionFermeAI1 = ConstructionFermeAI1 + 1 : moovingActivation = 1
                case 5
                    if activationConstrucFermeIA = 0 and ConstructionFermeAI1 < ConstructionFermeMaxAI1 and bois(2) >40 and (p(XvilleP2+1,YvilleP2) = 0 or p(XvilleP2+1,YvilleP2) = 25 or p(XvilleP2+1,YvilleP2) = 27 or p(XvilleP2+1,YvilleP2) = 29 or p(XvilleP2+1,YvilleP2) = 31) then p(XvilleP2+1,YvilleP2) = 999 : activationConstrucFermeIA = 1 : farmAIx = XvilleP2+1 : farmAIy = YvilleP2 : compteurFermeAI = 4 : ConstructionFermeAI1 = ConstructionFermeAI1 + 1 : moovingActivation = 1
                case 6
                    if activationConstrucFermeIA = 0 and ConstructionFermeAI1 < ConstructionFermeMaxAI1 and bois(2) >40 and (p(XvilleP2-1,YvilleP2+1) = 0 or p(XvilleP2-1,YvilleP2+1) = 25 or p(XvilleP2-1,YvilleP2+1) = 27 or p(XvilleP2-1,YvilleP2+1) = 29 or p(XvilleP2-1,YvilleP2+1) = 31) then p(XvilleP2-1,YvilleP2+1) = 999 : activationConstrucFermeIA = 1 : farmAIx = XvilleP2-1 : farmAIy = YvilleP2+1 : compteurFermeAI = 4 : ConstructionFermeAI1 = ConstructionFermeAI1 + 1 : moovingActivation = 1
                case 7
                    if activationConstrucFermeIA = 0 and ConstructionFermeAI1 < ConstructionFermeMaxAI1 and bois(2) >40 and (p(XvilleP2,YvilleP2+1) = 0 or p(XvilleP2,YvilleP2+1) = 25 or p(XvilleP2,YvilleP2+1) = 27 or p(XvilleP2,YvilleP2+1) = 29 or p(XvilleP2,YvilleP2+1) = 31) then p(XvilleP2,YvilleP2+1) = 999 : activationConstrucFermeIA = 1 : farmAIx = XvilleP2 : farmAIy = YvilleP2+1 : compteurFermeAI = 4 : ConstructionFermeAI1 = ConstructionFermeAI1 + 1 : moovingActivation = 1
                case 8
                    if activationConstrucFermeIA = 0 and ConstructionFermeAI1 < ConstructionFermeMaxAI1 and bois(2) >40 and (p(XvilleP2+1,YvilleP2+1) = 0 or p(XvilleP2+1,YvilleP2+1) = 25 or p(XvilleP2+1,YvilleP2+1) = 27 or p(XvilleP2+1,YvilleP2+1) = 29 or p(XvilleP2+1,YvilleP2+1) = 31) then p(XvilleP2+1,YvilleP2+1) = 999 : activationConstrucFermeIA = 1 : farmAIx = XvilleP2+1 : farmAIy = YvilleP2+1 : compteurFermeAI = 4 : ConstructionFermeAI1 = ConstructionFermeAI1 + 1 : moovingActivation = 1
                case 9
                    if activationConstrucFermeIA = 0 and ConstructionFermeAI1 < ConstructionFermeMaxAI1 and bois(2) >40 and (p(XvilleP2+2,YvilleP2+1) = 0 or p(XvilleP2+2,YvilleP2+1) = 25 or p(XvilleP2+2,YvilleP2+1) = 27 or p(XvilleP2+2,YvilleP2+1) = 29 or p(XvilleP2+2,YvilleP2+1) = 31) then p(XvilleP2+2,YvilleP2+1) = 999 : activationConstrucFermeIA = 1 : farmAIx = XvilleP2+2 : farmAIy = YvilleP2+1 : compteurFermeAI = 4 : ConstructionFermeAI1 = ConstructionFermeAI1 + 1 : moovingActivation = 1
                case 10
                    if activationConstrucFermeIA = 0 and ConstructionFermeAI1 < ConstructionFermeMaxAI1 and bois(2) >40 and (p(XvilleP2+2,YvilleP2) = 0 or p(XvilleP2+2,YvilleP2) = 25 or p(XvilleP2+2,YvilleP2) = 27 or p(XvilleP2+2,YvilleP2) = 29 or p(XvilleP2+2,YvilleP2) = 31) then p(XvilleP2+2,YvilleP2) = 999 : activationConstrucFermeIA = 1 : farmAIx = XvilleP2+2 : farmAIy = YvilleP2 : compteurFermeAI = 4 : ConstructionFermeAI1 = ConstructionFermeAI1 + 1 : moovingActivation = 1
                case 11
                    if activationConstrucFermeIA = 0 and ConstructionFermeAI1 < ConstructionFermeMaxAI1 and bois(2) >40 and (p(XvilleP2+2,YvilleP2-1) = 0 or p(XvilleP2+2,YvilleP2-1) = 25 or p(XvilleP2+2,YvilleP2-1) = 27 or p(XvilleP2+2,YvilleP2-1) = 29 or p(XvilleP2+2,YvilleP2-1) = 31) then p(XvilleP2+2,YvilleP2-1) = 999 : activationConstrucFermeIA = 1 : farmAIx = XvilleP2+2 : farmAIy = YvilleP2-1 : compteurFermeAI = 4 : ConstructionFermeAI1 = ConstructionFermeAI1 + 1 : moovingActivation = 1
                case 12
                    if activationConstrucFermeIA = 0 and ConstructionFermeAI1 < ConstructionFermeMaxAI1 and bois(2) >40 and (p(XvilleP2-2,YvilleP2+1) = 0 or p(XvilleP2-2,YvilleP2+1) = 25 or p(XvilleP2-2,YvilleP2+1) = 27 or p(XvilleP2-2,YvilleP2+1) = 29 or p(XvilleP2-2,YvilleP2+1) = 31) then p(XvilleP2-2,YvilleP2+1) = 999 : activationConstrucFermeIA = 1 : farmAIx = XvilleP2-2 : farmAIy = YvilleP2+1 : compteurFermeAI = 4 : ConstructionFermeAI1 = ConstructionFermeAI1 + 1 : moovingActivation = 1
                case 13
                    if activationConstrucFermeIA = 0 and ConstructionFermeAI1 < ConstructionFermeMaxAI1 and bois(2) >40 and (p(XvilleP2-2,YvilleP2) = 0 or p(XvilleP2-2,YvilleP2) = 25 or p(XvilleP2-2,YvilleP2) = 27 or p(XvilleP2-2,YvilleP2) = 29 or p(XvilleP2-2,YvilleP2) = 31) then p(XvilleP2-2,YvilleP2) = 999 : activationConstrucFermeIA = 1 : farmAIx = XvilleP2-2 : farmAIy = YvilleP2 : compteurFermeAI = 4 : ConstructionFermeAI1 = ConstructionFermeAI1 + 1 : moovingActivation = 1
                case 14
                    if activationConstrucFermeIA = 0 and ConstructionFermeAI1 < ConstructionFermeMaxAI1 and bois(2) >40 and (p(XvilleP2-2,YvilleP2-1) = 0 or p(XvilleP2-2,YvilleP2-1) = 25 or p(XvilleP2-2,YvilleP2-1) = 27 or p(XvilleP2-2,YvilleP2-1) = 29 or p(XvilleP2-2,YvilleP2-1) = 31) then p(XvilleP2-2,YvilleP2-1) = 999 : activationConstrucFermeIA = 1 : farmAIx = XvilleP2-2 : farmAIy = YvilleP2-1 : compteurFermeAI = 4 : ConstructionFermeAI1 = ConstructionFermeAI1 + 1 : moovingActivation = 1
            end select
            case 2 'camp
            PositionBatAI = int(rnd(1)*14+1)
            select case PositionBatAI
                case 1
                    if activationConstrucCampIA = 0 and ConstructionCampAI1 < 1 and bois(2) >60 and (p(XvilleP2-1,YvilleP2) = 0 or p(XvilleP2-1,YvilleP2) = 25 or p(XvilleP2-1,YvilleP2) = 27 or p(XvilleP2-1,YvilleP2) = 29 or p(XvilleP2-1,YvilleP2) = 31) then p(XvilleP2-1,YvilleP2) = 999 : activationConstrucCampIA = 1 : campAIx = XvilleP2-1 : campAIy = YvilleP2 : compteurCampAI = 8 : moovingActivation = 1
                case 2
                    if activationConstrucCampIA = 0 and ConstructionCampAI1 < 1 and bois(2) >60 and (p(XvilleP2-1,YvilleP2-1) = 0 or p(XvilleP2-1,YvilleP2-1) = 25 or p(XvilleP2-1,YvilleP2-1) = 27 or p(XvilleP2-1,YvilleP2-1) = 29 or p(XvilleP2-1,YvilleP2-1) = 31) then p(XvilleP2-1,YvilleP2-1) = 999 : activationConstrucCampIA = 1 : campAIx = XvilleP2-1 : campAIy = YvilleP2-1 : compteurCampAI = 8 : moovingActivation = 1
                case 3
                    if activationConstrucCampIA = 0 and ConstructionCampAI1 < 1 and bois(2) >60 and (p(XvilleP2,YvilleP2-1) = 0 or p(XvilleP2,YvilleP2-1) = 25 or p(XvilleP2,YvilleP2-1) = 27 or p(XvilleP2,YvilleP2-1) = 29 or p(XvilleP2,YvilleP2-1) = 31) then p(XvilleP2,YvilleP2-1) = 999 : activationConstrucCampIA = 1 : campAIx = XvilleP2 : campAIy = YvilleP2-1 : compteurCampAI = 8 : moovingActivation = 1
                case 4
                    if activationConstrucCampIA = 0 and ConstructionCampAI1 < 1 and bois(2) >60 and (p(XvilleP2+1,YvilleP2-1) = 0 or p(XvilleP2+1,YvilleP2-1) = 25 or p(XvilleP2+1,YvilleP2-1) = 27 or p(XvilleP2+1,YvilleP2-1) = 29 or p(XvilleP2+1,YvilleP2-1) = 31) then p(XvilleP2+1,YvilleP2-1) = 999 : activationConstrucCampIA = 1 : campAIx = XvilleP2+1 : campAIy = YvilleP2-1 : compteurCampAI = 8 : moovingActivation = 1
                case 5
                    if activationConstrucCampIA = 0 and ConstructionCampAI1 < 1 and bois(2) >60 and (p(XvilleP2+1,YvilleP2) = 0 or p(XvilleP2+1,YvilleP2) = 25 or p(XvilleP2+1,YvilleP2) = 27 or p(XvilleP2+1,YvilleP2) = 29 or p(XvilleP2+1,YvilleP2) = 31) then p(XvilleP2+1,YvilleP2) = 999 : activationConstrucCampIA = 1 : campAIx = XvilleP2+1 : campAIy = YvilleP2 : compteurCampAI = 8 : moovingActivation = 1
                case 6
                    if activationConstrucCampIA = 0 and ConstructionCampAI1 < 1 and bois(2) >60 and (p(XvilleP2-1,YvilleP2+1) = 0 or p(XvilleP2-1,YvilleP2+1) = 25 or p(XvilleP2-1,YvilleP2+1) = 27 or p(XvilleP2-1,YvilleP2+1) = 29 or p(XvilleP2-1,YvilleP2+1) = 31) then p(XvilleP2-1,YvilleP2+1) = 999 : activationConstrucCampIA = 1 : campAIx = XvilleP2-1 : campAIy = YvilleP2+1 : compteurCampAI = 8 : moovingActivation = 1
                case 7
                    if activationConstrucCampIA = 0 and ConstructionCampAI1 < 1 and bois(2) >60 and (p(XvilleP2,YvilleP2+1) = 0 or p(XvilleP2,YvilleP2+1) = 25 or p(XvilleP2,YvilleP2+1) = 27 or p(XvilleP2,YvilleP2+1) = 29 or p(XvilleP2,YvilleP2+1) = 31) then p(XvilleP2,YvilleP2+1) = 999 : activationConstrucCampIA = 1 : campAIx = XvilleP2 : campAIy = YvilleP2+1 : compteurCampAI = 8 : moovingActivation = 1
                case 8
                    if activationConstrucCampIA = 0 and ConstructionCampAI1 < 1 and bois(2) >60 and (p(XvilleP2+1,YvilleP2+1) = 0 or p(XvilleP2+1,YvilleP2+1) = 25 or p(XvilleP2+1,YvilleP2+1) = 27 or p(XvilleP2+1,YvilleP2+1) = 29 or p(XvilleP2+1,YvilleP2+1) = 31) then p(XvilleP2+1,YvilleP2+1) = 999 : activationConstrucCampIA = 1 : campAIx = XvilleP2+1 : campAIy = YvilleP2+1 : compteurCampAI = 8 : moovingActivation = 1
                case 9
                    if activationConstrucCampIA = 0 and ConstructionCampAI1 < 1 and bois(2) >60 and (p(XvilleP2+2,YvilleP2+1) = 0 or p(XvilleP2+2,YvilleP2+1) = 25 or p(XvilleP2+2,YvilleP2+1) = 27 or p(XvilleP2+2,YvilleP2+1) = 29 or p(XvilleP2+2,YvilleP2+1) = 31) then p(XvilleP2+2,YvilleP2+1) = 999 : activationConstrucCampIA = 1 : campAIx = XvilleP2+2 : campAIy = YvilleP2+1 : compteurCampAI = 8 : moovingActivation = 1
                case 10
                    if activationConstrucCampIA = 0 and ConstructionCampAI1 < 1 and bois(2) >60 and (p(XvilleP2+2,YvilleP2) = 0 or p(XvilleP2+2,YvilleP2) = 25 or p(XvilleP2+2,YvilleP2) = 27 or p(XvilleP2+2,YvilleP2) = 29 or p(XvilleP2+2,YvilleP2) = 31) then p(XvilleP2+2,YvilleP2) = 999 : activationConstrucCampIA = 1 : campAIx = XvilleP2+2 : campAIy = YvilleP2 : compteurCampAI = 8 : moovingActivation = 1
                case 11
                    if activationConstrucCampIA = 0 and ConstructionCampAI1 < 1 and bois(2) >60 and (p(XvilleP2+2,YvilleP2-1) = 0 or p(XvilleP2+2,YvilleP2-1) = 25 or p(XvilleP2+2,YvilleP2-1) = 27 or p(XvilleP2+2,YvilleP2-1) = 29 or p(XvilleP2+2,YvilleP2-1) = 31) then p(XvilleP2+2,YvilleP2-1) = 999 : activationConstrucCampIA = 1 : campAIx = XvilleP2+2 : campAIy = YvilleP2-1 : compteurCampAI = 8 : moovingActivation = 1
                case 12
                    if activationConstrucCampIA = 0 and ConstructionCampAI1 < 1 and bois(2) >60 and (p(XvilleP2-2,YvilleP2+1) = 0 or p(XvilleP2-2,YvilleP2+1) = 25 or p(XvilleP2-2,YvilleP2+1) = 27 or p(XvilleP2-2,YvilleP2+1) = 29 or p(XvilleP2-2,YvilleP2+1) = 31) then p(XvilleP2-2,YvilleP2+1) = 999 : activationConstrucCampIA = 1 : campAIx = XvilleP2-2 : campAIy = YvilleP2+1 : compteurCampAI = 8 : moovingActivation = 1
                case 13
                    if activationConstrucCampIA = 0 and ConstructionCampAI1 < 1 and bois(2) >60 and (p(XvilleP2-2,YvilleP2) = 0 or p(XvilleP2-2,YvilleP2) = 25 or p(XvilleP2-2,YvilleP2) = 27 or p(XvilleP2-2,YvilleP2) = 29 or p(XvilleP2-2,YvilleP2) = 31) then p(XvilleP2-2,YvilleP2) = 999 : activationConstrucCampIA = 1 : campAIx = XvilleP2-2 : campAIy = YvilleP2 : compteurCampAI = 8 : moovingActivation = 1
                case 14
                    if activationConstrucCampIA = 0 and ConstructionCampAI1 < 1 and bois(2) >60 and (p(XvilleP2-2,YvilleP2-1) = 0 or p(XvilleP2-2,YvilleP2-1) = 25 or p(XvilleP2-2,YvilleP2-1) = 27 or p(XvilleP2-2,YvilleP2-1) = 29 or p(XvilleP2-2,YvilleP2-1) = 31) then p(XvilleP2-2,YvilleP2-1) = 999 : activationConstrucCampIA = 1 : campAIx = XvilleP2-2 : campAIy = YvilleP2-1 : compteurCampAI = 8 : moovingActivation = 1
            end select
            case 3'academy
            PositionBatAI = int(rnd(1)*14+1)
            select case PositionBatAI
                case 1
                    if activationConstrucAcadIA = 0 and ConstructionAcademieAI1 < 1 and bois(2) >110 and minerais(2) >50 and (p(XvilleP2-1,YvilleP2) = 0 or p(XvilleP2-1,YvilleP2) = 25 or p(XvilleP2-1,YvilleP2) = 27 or p(XvilleP2-1,YvilleP2) = 29 or p(XvilleP2-1,YvilleP2) = 31) then p(XvilleP2-1,YvilleP2) = 999 : activationConstrucAcadIA = 1 : acadAIx = XvilleP2-1 : acadAIy = YvilleP2 : compteurAcadAI = 15 : ConstructionAcademieAI1 = ConstructionAcademieAI1 + 1 : moovingActivation = 1
                case 2
                    if activationConstrucAcadIA = 0 and ConstructionAcademieAI1 < 1 and bois(2) >110 and minerais(2) >50 and (p(XvilleP2-1,YvilleP2-1) = 0 or p(XvilleP2-1,YvilleP2-1) = 25 or p(XvilleP2-1,YvilleP2-1) = 27 or p(XvilleP2-1,YvilleP2-1) = 29 or p(XvilleP2-1,YvilleP2-1) = 31) then p(XvilleP2-1,YvilleP2-1) = 999 : activationConstrucAcadIA = 1 : acadAIx = XvilleP2-1 : acadAIy = YvilleP2-1 : compteurAcadAI = 15 : ConstructionAcademieAI1 = ConstructionAcademieAI1 + 1 : moovingActivation = 1
                case 3
                    if activationConstrucAcadIA = 0 and ConstructionAcademieAI1 < 1 and bois(2) >110 and minerais(2) >50 and (p(XvilleP2,YvilleP2-1) = 0 or p(XvilleP2,YvilleP2-1) = 25 or p(XvilleP2,YvilleP2-1) = 27 or p(XvilleP2,YvilleP2-1) = 29 or p(XvilleP2,YvilleP2-1) = 31) then p(XvilleP2,YvilleP2-1) = 999 : activationConstrucAcadIA = 1 : acadAIx = XvilleP2 : acadAIy = YvilleP2-1 : compteurAcadAI = 15 : ConstructionAcademieAI1 = ConstructionAcademieAI1 + 1 : moovingActivation = 1
                case 4
                    if activationConstrucAcadIA = 0 and ConstructionAcademieAI1 < 1 and bois(2) >110 and minerais(2) >50 and (p(XvilleP2+1,YvilleP2-1) = 0 or p(XvilleP2+1,YvilleP2-1) = 25 or p(XvilleP2+1,YvilleP2-1) = 27 or p(XvilleP2+1,YvilleP2-1) = 29 or p(XvilleP2+1,YvilleP2-1) = 31) then p(XvilleP2+1,YvilleP2-1) = 999 : activationConstrucAcadIA = 1 : acadAIx = XvilleP2+1 : acadAIy = YvilleP2-1 : compteurAcadAI = 15 : ConstructionAcademieAI1 = ConstructionAcademieAI1 + 1 : moovingActivation = 1
                case 5
                    if activationConstrucAcadIA = 0 and ConstructionAcademieAI1 < 1 and bois(2) >110 and minerais(2) >50 and (p(XvilleP2+1,YvilleP2) = 0 or p(XvilleP2+1,YvilleP2) = 25 or p(XvilleP2+1,YvilleP2) = 27 or p(XvilleP2+1,YvilleP2) = 29 or p(XvilleP2+1,YvilleP2) = 31) then p(XvilleP2+1,YvilleP2) = 999 : activationConstrucAcadIA = 1 : acadAIx = XvilleP2+1 : acadAIy = YvilleP2 : compteurAcadAI = 15 : ConstructionAcademieAI1 = ConstructionAcademieAI1 + 1 : moovingActivation = 1
                case 6
                    if activationConstrucAcadIA = 0 and ConstructionAcademieAI1 < 1 and bois(2) >110 and minerais(2) >50 and (p(XvilleP2-1,YvilleP2+1) = 0 or p(XvilleP2-1,YvilleP2+1) = 25 or p(XvilleP2-1,YvilleP2+1) = 27 or p(XvilleP2-1,YvilleP2+1) = 29 or p(XvilleP2-1,YvilleP2+1) = 31) then p(XvilleP2-1,YvilleP2+1) = 999 : activationConstrucAcadIA = 1 : acadAIx = XvilleP2-1 : acadAIy = YvilleP2+1 : compteurAcadAI = 15 : ConstructionAcademieAI1 = ConstructionAcademieAI1 + 1 : moovingActivation = 1
                case 7
                    if activationConstrucAcadIA = 0 and ConstructionAcademieAI1 < 1 and bois(2) >110 and minerais(2) >50 and (p(XvilleP2,YvilleP2+1) = 0 or p(XvilleP2,YvilleP2+1) = 25 or p(XvilleP2,YvilleP2+1) = 27 or p(XvilleP2,YvilleP2+1) = 29 or p(XvilleP2,YvilleP2+1) = 31) then p(XvilleP2,YvilleP2+1) = 999 : activationConstrucAcadIA = 1 : acadAIx = XvilleP2 : acadAIy = YvilleP2+1 : compteurAcadAI = 15 : ConstructionAcademieAI1 = ConstructionAcademieAI1 + 1 : moovingActivation = 1
                case 8
                    if activationConstrucAcadIA = 0 and ConstructionAcademieAI1 < 1 and bois(2) >110 and minerais(2) >50 and (p(XvilleP2+1,YvilleP2+1) = 0 or p(XvilleP2+1,YvilleP2+1) = 25 or p(XvilleP2+1,YvilleP2+1) = 27 or p(XvilleP2+1,YvilleP2+1) = 29 or p(XvilleP2+1,YvilleP2+1) = 31) then p(XvilleP2+1,YvilleP2+1) = 999 : activationConstrucAcadIA = 1 : acadAIx = XvilleP2+1 : acadAIy = YvilleP2+1 : compteurAcadAI = 15 : ConstructionAcademieAI1 = ConstructionAcademieAI1 + 1 : moovingActivation = 1
                case 9
                    if activationConstrucAcadIA = 0 and ConstructionAcademieAI1 < 1 and bois(2) >110 and minerais(2) >50 and (p(XvilleP2+2,YvilleP2+1) = 0 or p(XvilleP2+2,YvilleP2+1) = 25 or p(XvilleP2+2,YvilleP2+1) = 27 or p(XvilleP2+2,YvilleP2+1) = 29 or p(XvilleP2+2,YvilleP2+1) = 31) then p(XvilleP2+2,YvilleP2+1) = 999 : activationConstrucAcadIA = 1 : acadAIx = XvilleP2+2 : acadAIy = YvilleP2+1 : compteurAcadAI = 15 : ConstructionAcademieAI1 = ConstructionAcademieAI1 + 1 : moovingActivation = 1
                case 10
                    if activationConstrucAcadIA = 0 and ConstructionAcademieAI1 < 1 and bois(2) >110 and minerais(2) >50 and (p(XvilleP2+2,YvilleP2) = 0 or p(XvilleP2+2,YvilleP2) = 25 or p(XvilleP2+2,YvilleP2) = 27 or p(XvilleP2+2,YvilleP2) = 29 or p(XvilleP2+2,YvilleP2) = 31) then p(XvilleP2+2,YvilleP2) = 999 : activationConstrucAcadIA = 1 : acadAIx = XvilleP2+2 : acadAIy = YvilleP2 : compteurAcadAI = 15 : ConstructionAcademieAI1 = ConstructionAcademieAI1 + 1 : moovingActivation = 1
                case 11
                    if activationConstrucAcadIA = 0 and ConstructionAcademieAI1 < 1 and bois(2) >110 and minerais(2) >50 and (p(XvilleP2+2,YvilleP2-1) = 0 or p(XvilleP2+2,YvilleP2-1) = 25 or p(XvilleP2+2,YvilleP2-1) = 27 or p(XvilleP2+2,YvilleP2-1) = 29 or p(XvilleP2+2,YvilleP2-1) = 31) then p(XvilleP2+2,YvilleP2-1) = 999 : activationConstrucAcadIA = 1 : acadAIx = XvilleP2+2 : acadAIy = YvilleP2-1 : compteurAcadAI = 15 : ConstructionAcademieAI1 = ConstructionAcademieAI1 + 1 : moovingActivation = 1
                case 12
                    if activationConstrucAcadIA = 0 and ConstructionAcademieAI1 < 1 and bois(2) >110 and minerais(2) >50 and (p(XvilleP2-2,YvilleP2+1) = 0 or p(XvilleP2-2,YvilleP2+1) = 25 or p(XvilleP2-2,YvilleP2+1) = 27 or p(XvilleP2-2,YvilleP2+1) = 29 or p(XvilleP2-2,YvilleP2+1) = 31) then p(XvilleP2-2,YvilleP2+1) = 999 : activationConstrucAcadIA = 1 : acadAIx = XvilleP2-2 : acadAIy = YvilleP2+1 : compteurAcadAI = 15 : ConstructionAcademieAI1 = ConstructionAcademieAI1 + 1 : moovingActivation = 1
                case 13
                    if activationConstrucAcadIA = 0 and ConstructionAcademieAI1 < 1 and bois(2) >110 and minerais(2) >50 and (p(XvilleP2-2,YvilleP2) = 0 or p(XvilleP2-2,YvilleP2) = 25 or p(XvilleP2-2,YvilleP2) = 27 or p(XvilleP2-2,YvilleP2) = 29 or p(XvilleP2-2,YvilleP2) = 31) then p(XvilleP2-2,YvilleP2) = 999 : activationConstrucAcadIA = 1 : acadAIx = XvilleP2-2 : acadAIy = YvilleP2 : compteurAcadAI = 15 : ConstructionAcademieAI1 = ConstructionAcademieAI1 + 1 : moovingActivation = 1
                case 14
                    if activationConstrucAcadIA = 0 and ConstructionAcademieAI1 < 1 and bois(2) >110 and minerais(2) >50 and (p(XvilleP2-2,YvilleP2-1) = 0 or p(XvilleP2-2,YvilleP2-1) = 25 or p(XvilleP2-2,YvilleP2-1) = 27 or p(XvilleP2-2,YvilleP2-1) = 29 or p(XvilleP2-2,YvilleP2-1) = 31) then p(XvilleP2-2,YvilleP2-1) = 999 : activationConstrucAcadIA = 1 : acadAIx = XvilleP2-2 : acadAIy = YvilleP2-1 : compteurAcadAI = 15 : ConstructionAcademieAI1 = ConstructionAcademieAI1 + 1 : moovingActivation = 1
            end select
            case 4'tower
            PositionBatAI = int(rnd(1)*14+1)
            select case PositionBatAI
                case 1
                    if activationConstrucTowerIA = 0 and ConstructionTourAI1 < ConstructionTourMaxAI1 and bois(2) >50 and minerais(2) >15 and (p(XvilleP2-1,YvilleP2) = 0 or p(XvilleP2-1,YvilleP2) = 25 or p(XvilleP2-1,YvilleP2) = 27 or p(XvilleP2-1,YvilleP2) = 29 or p(XvilleP2-1,YvilleP2) = 31) then p(XvilleP2-1,YvilleP2) = 999 : activationConstrucTowerIA = 1 : towerAIx = XvilleP2-1 : towerAIy = YvilleP2 : compteurTowerAI = 10 : ConstructionTourAI1 = ConstructionTourAI1 + 1 : moovingActivation = 1
                case 2
                    if activationConstrucTowerIA = 0 and ConstructionTourAI1 < ConstructionTourMaxAI1 and bois(2) >50 and minerais(2) >15 and (p(XvilleP2-1,YvilleP2-1) = 0 or p(XvilleP2-1,YvilleP2-1) = 25 or p(XvilleP2-1,YvilleP2-1) = 27 or p(XvilleP2-1,YvilleP2-1) = 29 or p(XvilleP2-1,YvilleP2-1) = 31) then p(XvilleP2-1,YvilleP2-1) = 999 : activationConstrucTowerIA = 1 : towerAIx = XvilleP2-1 : towerAIy = YvilleP2-1 : compteurTowerAI = 10 : ConstructionTourAI1 = ConstructionTourAI1 + 1 : moovingActivation = 1
                case 3
                    if activationConstrucTowerIA = 0 and ConstructionTourAI1 < ConstructionTourMaxAI1 and bois(2) >50 and minerais(2) >15 and (p(XvilleP2,YvilleP2-1) = 0 or p(XvilleP2,YvilleP2-1) = 25 or p(XvilleP2,YvilleP2-1) = 27 or p(XvilleP2,YvilleP2-1) = 29 or p(XvilleP2,YvilleP2-1) = 31) then p(XvilleP2,YvilleP2-1) = 999 : activationConstrucTowerIA = 1 : towerAIx = XvilleP2 : towerAIy = YvilleP2-1 : compteurTowerAI = 10 : ConstructionTourAI1 = ConstructionTourAI1 + 1 : moovingActivation = 1
                case 4
                    if activationConstrucTowerIA = 0 and ConstructionTourAI1 < ConstructionTourMaxAI1 and bois(2) >50 and minerais(2) >15 and (p(XvilleP2+1,YvilleP2-1) = 0 or p(XvilleP2+1,YvilleP2-1) = 25 or p(XvilleP2+1,YvilleP2-1) = 27 or p(XvilleP2+1,YvilleP2-1) = 29 or p(XvilleP2+1,YvilleP2-1) = 31) then p(XvilleP2+1,YvilleP2-1) = 999 : activationConstrucTowerIA = 1 : towerAIx = XvilleP2+1 : towerAIy = YvilleP2-1 : compteurTowerAI = 10 : ConstructionTourAI1 = ConstructionTourAI1 + 1 : moovingActivation = 1
                case 5
                    if activationConstrucTowerIA = 0 and ConstructionTourAI1 < ConstructionTourMaxAI1 and bois(2) >50 and minerais(2) >15 and (p(XvilleP2+1,YvilleP2) = 0 or p(XvilleP2+1,YvilleP2) = 25 or p(XvilleP2+1,YvilleP2) = 27 or p(XvilleP2+1,YvilleP2) = 29 or p(XvilleP2+1,YvilleP2) = 31) then p(XvilleP2+1,YvilleP2) = 999 : activationConstrucTowerIA = 1 : towerAIx = XvilleP2+1 : towerAIy = YvilleP2 : compteurTowerAI = 10 : ConstructionTourAI1 = ConstructionTourAI1 + 1 : moovingActivation = 1
                case 6
                    if activationConstrucTowerIA = 0 and ConstructionTourAI1 < ConstructionTourMaxAI1 and bois(2) >50 and minerais(2) >15 and (p(XvilleP2-1,YvilleP2+1) = 0 or p(XvilleP2-1,YvilleP2+1) = 25 or p(XvilleP2-1,YvilleP2+1) = 27 or p(XvilleP2-1,YvilleP2+1) = 29 or p(XvilleP2-1,YvilleP2+1) = 31) then p(XvilleP2-1,YvilleP2+1) = 999 : activationConstrucTowerIA = 1 : towerAIx = XvilleP2-1 : towerAIy = YvilleP2+1 : compteurTowerAI = 10 : ConstructionTourAI1 = ConstructionTourAI1 + 1 : moovingActivation = 1
                case 7
                    if activationConstrucTowerIA = 0 and ConstructionTourAI1 < ConstructionTourMaxAI1 and bois(2) >50 and minerais(2) >15 and (p(XvilleP2,YvilleP2+1) = 0 or p(XvilleP2,YvilleP2+1) = 25 or p(XvilleP2,YvilleP2+1) = 27 or p(XvilleP2,YvilleP2+1) = 29 or p(XvilleP2,YvilleP2+1) = 31) then p(XvilleP2,YvilleP2+1) = 999 : activationConstrucTowerIA = 1 : towerAIx = XvilleP2 : towerAIy = YvilleP2+1 : compteurTowerAI = 10 : ConstructionTourAI1 = ConstructionTourAI1 + 1 : moovingActivation = 1
                case 8
                    if activationConstrucTowerIA = 0 and ConstructionTourAI1 < ConstructionTourMaxAI1 and bois(2) >50 and minerais(2) >15 and (p(XvilleP2+1,YvilleP2+1) = 0 or p(XvilleP2+1,YvilleP2+1) = 25 or p(XvilleP2+1,YvilleP2+1) = 27 or p(XvilleP2+1,YvilleP2+1) = 29 or p(XvilleP2+1,YvilleP2+1) = 31) then p(XvilleP2+1,YvilleP2+1) = 999 : activationConstrucTowerIA = 1 : towerAIx = XvilleP2+1 : towerAIy = YvilleP2+1 : compteurTowerAI = 10 : ConstructionTourAI1 = ConstructionTourAI1 + 1 : moovingActivation = 1
                case 9
                    if activationConstrucTowerIA = 0 and ConstructionTourAI1 < ConstructionTourMaxAI1 and bois(2) >50 and minerais(2) >15 and (p(XvilleP2+2,YvilleP2+1) = 0 or p(XvilleP2+2,YvilleP2+1) = 25 or p(XvilleP2+2,YvilleP2+1) = 27 or p(XvilleP2+2,YvilleP2+1) = 29 or p(XvilleP2+2,YvilleP2+1) = 31) then p(XvilleP2+2,YvilleP2+1) = 999 : activationConstrucTowerIA = 1 : towerAIx = XvilleP2+2 : towerAIy = YvilleP2+1 : compteurTowerAI = 10 : ConstructionTourAI1 = ConstructionTourAI1 + 1 : moovingActivation = 1
                case 10
                    if activationConstrucTowerIA = 0 and ConstructionTourAI1 < ConstructionTourMaxAI1 and bois(2) >50 and minerais(2) >15 and (p(XvilleP2+2,YvilleP2) = 0 or p(XvilleP2+2,YvilleP2) = 25 or p(XvilleP2+2,YvilleP2) = 27 or p(XvilleP2+2,YvilleP2) = 29 or p(XvilleP2+2,YvilleP2) = 31) then p(XvilleP2+2,YvilleP2) = 999 : activationConstrucTowerIA = 1 : towerAIx = XvilleP2+2 : towerAIy = YvilleP2 : compteurTowerAI = 10 : ConstructionTourAI1 = ConstructionTourAI1 + 1 : moovingActivation = 1
                case 11
                    if activationConstrucTowerIA = 0 and ConstructionTourAI1 < ConstructionTourMaxAI1 and bois(2) >50 and minerais(2) >15 and (p(XvilleP2+2,YvilleP2-1) = 0 or p(XvilleP2+2,YvilleP2-1) = 25 or p(XvilleP2+2,YvilleP2-1) = 27 or p(XvilleP2+2,YvilleP2-1) = 29 or p(XvilleP2+2,YvilleP2-1) = 31) then p(XvilleP2+2,YvilleP2-1) = 999 : activationConstrucTowerIA = 1 : towerAIx = XvilleP2+2 : towerAIy = YvilleP2-1 : compteurTowerAI = 10 : ConstructionTourAI1 = ConstructionTourAI1 + 1 : moovingActivation = 1
                case 12
                    if activationConstrucTowerIA = 0 and ConstructionTourAI1 < ConstructionTourMaxAI1 and bois(2) >50 and minerais(2) >15 and (p(XvilleP2-2,YvilleP2+1) = 0 or p(XvilleP2-2,YvilleP2+1) = 25 or p(XvilleP2-2,YvilleP2+1) = 27 or p(XvilleP2-2,YvilleP2+1) = 29 or p(XvilleP2-2,YvilleP2+1) = 31) then p(XvilleP2-2,YvilleP2+1) = 999 : activationConstrucTowerIA = 1 : towerAIx = XvilleP2-2 : towerAIy = YvilleP2+1 : compteurTowerAI = 10 : ConstructionTourAI1 = ConstructionTourAI1 + 1 : moovingActivation = 1
                case 13
                    if activationConstrucTowerIA = 0 and ConstructionTourAI1 < ConstructionTourMaxAI1 and bois(2) >50 and minerais(2) >15 and (p(XvilleP2-2,YvilleP2) = 0 or p(XvilleP2-2,YvilleP2) = 25 or p(XvilleP2-2,YvilleP2) = 27 or p(XvilleP2-2,YvilleP2) = 29 or p(XvilleP2-2,YvilleP2) = 31) then p(XvilleP2-2,YvilleP2) = 999 : activationConstrucTowerIA = 1 : towerAIx = XvilleP2-2 : towerAIy = YvilleP2 : compteurTowerAI = 10 : ConstructionTourAI1 = ConstructionTourAI1 + 1 : moovingActivation = 1
                case 14
                    if activationConstrucTowerIA = 0 and ConstructionTourAI1 < ConstructionTourMaxAI1 and bois(2) >50 and minerais(2) >15 and (p(XvilleP2-2,YvilleP2-1) = 0 or p(XvilleP2-2,YvilleP2-1) = 25 or p(XvilleP2-2,YvilleP2-1) = 27 or p(XvilleP2-2,YvilleP2-1) = 29 or p(XvilleP2-2,YvilleP2-1) = 31) then p(XvilleP2-2,YvilleP2-1) = 999 : activationConstrucTowerIA = 1 : towerAIx = XvilleP2-2 : towerAIy = YvilleP2-1 : compteurTowerAI = 10 : ConstructionTourAI1 = ConstructionTourAI1 + 1 : moovingActivation = 1
            end select
            case else
        end select
    end if
    [endBuildAI1]

    'infantery p2
    if nombreSoldatA(2) < 4 and ConstructionCampAI1 >0 and activationConstrucCamp = 0 and nourriture(2) >= 40 and minerais(2) >= 10 and pop(2) < popMAX(2) then
        nombreSoldatA(2) = nombreSoldatA(2) + 1
        pop(2) = pop(2) + 1
        nourriture(2) = nourriture(2) - 40
        minerais(2) = minerais(2) - 10
        numSoldatP2 = numSoldatP2 + 1
        IDunitP2(numSoldatP2) = 1
        for b = 1 to numSoldatP2
            if IDunitP2(b) = 6 then Xutil = POSxSOLDATp2(b) : Yutil = POSySOLDATp2(b)
        next b
        POSxSOLDATp2(numSoldatP2) = int(rnd(1)*50+Xutil-50)
        POSySOLDATp2(numSoldatP2) = int(rnd(1)*50+Yutil-50)
        PVsoldatP2(numSoldatP2) = 8 : PVMAXsoldatP2(numSoldatP2) = 8
        ATKsoldatP2(numSoldatP2) = 4
        DEFsoldatP2(numSoldatP2) = 1
        reloadTimeE(numSoldatP2) = 50
        UnitP2intoArmy(numSoldatP2) = 0
        MoovingTOai(numSoldatP2) = 0
        ciblage(numSoldatP2) = 0
        print #main.map, "addsprite ennemiA";numSoldatP2;" ennemiA";"; spritexy ennemiA";numSoldatP2;" ";int((((POSxSOLDATp2(numSoldatP2)/96)-valIniX)*96)+70);" ";int((((POSySOLDATp2(numSoldatP2)/96)-valIniY)*96)+70);"; SpriteVisible ennemiA";numSoldatP2;" on; spritetofront ennemiA";numSoldatP2
        securityMOOVE2 = 0
    end if

    'lancer p2
    if nombreSoldatB(2) < 4 and ConstructionCampAI1 >0 and activationConstrucCamp = 0 and nourriture(2) >= 30 and bois(2) >= 10 and pop(2) < popMAX(2) then
        nombreSoldatB(2) = nombreSoldatB(2) + 1
        pop(2) = pop(2) + 1
        nourriture(2) = nourriture(2) - 30
        bois(2) = bois(2) - 10
        numSoldatP2 = numSoldatP2 + 1
        IDunitP2(numSoldatP2) = 2
        for b = 1 to numSoldatP2
            if IDunitP2(b) = 6 then Xutil = POSxSOLDATp2(b) : Yutil = POSySOLDATp2(b)
        next b
        POSxSOLDATp2(numSoldatP2) = int(rnd(1)*50+Xutil-50)
        POSySOLDATp2(numSoldatP2) = int(rnd(1)*50+Yutil-50)
        PVsoldatP2(numSoldatP2) = 6 : PVMAXsoldatP2(numSoldatP2) = 6
        ATKsoldatP2(numSoldatP2) = 3
        DEFsoldatP2(numSoldatP2) = 1
        reloadTimeE(numSoldatP2) = 50
        UnitP2intoArmy(numSoldatP2) = 0
        MoovingTOai(numSoldatP2) = 0
        ciblage(numSoldatP2) = 0
        print #main.map, "addsprite ennemiB";numSoldatP2;" ennemiB";"; spritexy ennemiB";numSoldatP2;" ";int((((POSxSOLDATp2(numSoldatP2)/96)-valIniX)*96)+70);" ";int((((POSySOLDATp2(numSoldatP2)/96)-valIniY)*96)+70);"; SpriteVisible ennemiB";numSoldatP2;" on; spritetofront ennemiB";numSoldatP2
        securityMOOVE2 = 0
    end if
    ia1attacked = 0
    print #main.map2, "place 15 753 ;\"; "fps : ";showFPS;"      "
    fps = 0

    ' Nettoyage des cibles invalides
    for cleanTarget = 1 to numSoldatP2
        if ciblage(cleanTarget) > 0 then
        ' Vérifier si la cible existe encore
        targetExists = 0
        for checkJ = 1 to numSoldatP1
            if IDunitP1(checkJ) > 0 and PVsoldatP1(checkJ) > 0 then targetExists = 1
        next checkJ
        if targetExists = 0 then ciblage(cleanTarget) = 0
    end if
    next cleanTarget

    return

    [errorSAV]
    notice "la sauvegarde ne peut pas être effectuée (";erorsav;")"
    close #secu : wait

    [WorkerBuilder]
    for o = 1 to numSoldatP1
        if IDunitP1(o) = 3 then peonSELECT(o) = 0
    next o
    if version = 1 then notice " " + chr$(13) +  "Votre constructeur est trop loin pour construire le bâtiment." : IDconstruction = 0 : goto [refreshLAND]
    if version = 2 then notice " " + chr$(13) +  "Your builder is too far away to construct the building." : IDconstruction = 0 : goto [refreshLAND]

    [position]
    mX1 = MouseX : mY1 = MouseY : xNEW = int(valIniX+(mX1/96)) : yNEW = int(valIniY+(mY1/96)) : menuCONSTRUCTION = 0 : unlockACHATunit = 0  : AchatUnitMode = 0 : noRESSOURCEshow = 0
    print #main.map2, "cls"


 '  notice c(xNEW,yNEW)

    if mX1 >40 and mX1 < 55 and mY1 <40 then
        if bruitage = 1 then r$ = mcisend$("play hit from 0")
        noRESSOURCEshow = 1 : AchatUnitMode = 1 : print #main.map2, "cls" : goto [options]
    end if
    if mX1 >65 and mX1 < 80 and mY1 <40 then
        if bruitage = 1 then r$ = mcisend$("play hit from 0")
        noRESSOURCEshow = 1 : AchatUnitMode = 1 : print #main.map2, "cls" : goto [GAMElaws]
    end if


    if mX1 > 780 and mX1 < 800 and mY1 > 12 and mY1 < 32 then
        noRESSOURCEshow = 1 : AchatUnitMode = 1
        [remakePOSsoldat0]
        for o = 1 to numSoldatP1
            if IDunitP1(o) = 3 and o > oOld and PVsoldatP1(o) > 0 then oOld = o : valIniX = int(POSxSOLDATp1(o)/96)-3 : valIniY = int(POSySOLDATp1(o)/96)-3 : moovingActivation = 2 : goto [endLEVEL]
            if IDunitP1(o) = 3 and o = oOld and PVsoldatP1(o) > 0 then oOld = 0 : moovingActivation = 2
            if o = numSoldatP1 and nombrePeon(1) > 0 then o = 0 : goto [remakePOSsoldat0]
        next o
    wait
    end if

    if mX1 > 805 and mX1 < 825 and mY1 > 12 and mY1 < 32 then
        noRESSOURCEshow = 1 : AchatUnitMode = 1
        [remakePOSsoldat1]
        for a = 1 to numSoldatP1
            if IDunitP1(a) = 1 and a > oOld2 and PVsoldatP1(a) > 0 then oOld2 = a : valIniX = int(POSxSOLDATp1(a)/96)-3 : valIniY = int(POSySOLDATp1(a)/96)-3 : moovingActivation = 2 : goto [endLEVEL]
            if IDunitP1(a) = 1 and a = oOld2 and PVsoldatP1(a) > 0 then oOld2 = 0 : moovingActivation = 2
            if a = numSoldatP1 and nombreSoldatA(1) > 0 then a = 0 : goto [remakePOSsoldat1]
        next a
        [remakePOSsoldat2]
        for b = 1 to numSoldatP1
            if IDunitP1(b) = 2 and b > oOld3 and PVsoldatP1(b) > 0 then oOld3 = b : valIniX = int(POSxSOLDATp1(b)/96)-3 : valIniY = int(POSySOLDATp1(b)/96)-3 : moovingActivation = 2 : goto [endLEVEL]
            if IDunitP1(b) = 2 and b = oOld3 and PVsoldatP1(b) > 0 then oOld3 = 0 : moovingActivation = 2
            if b = numSoldatP1 and nombreSoldatB(1) > 0 then b = 0 :  goto [remakePOSsoldat2]
        next b
     wait
    end if

    if mX1 > 830 and mX1 < 850 and mY1 > 12 and mY1 < 32 then valIniX =3 : valIniY = 2 : moovingActivation = 2 : noRESSOURCEshow = 1 : AchatUnitMode = 1 : goto [endLEVEL]

    'notice p(xNEW,yNEW)
    if mX1 < 35 and mY1 <40 then
        on error goto [errorSAV]
        if bruitage = 1 then r$ = mcisend$("play hit from 0")
        [autoSAVE]
        nSave = 0
        open "data.txt" for output as #secu
        erorsav = 1
        print #secu, int(nourriture(1)) : nSave = nSave + 1
        print #secu, int(bois(1)) : nSave = nSave + 1
        print #secu, int(minerais(1)) : nSave = nSave + 1
        print #secu, pop(1) : nSave = nSave + 1
        print #secu, popMAX(1) : nSave = nSave + 1
        print #secu, nombrePeon(1) : nSave = nSave + 1
        print #secu, ConstructionFermeDONE : nSave = nSave + 1
        print #secu, ConstructionTourDONE : nSave = nSave + 1
        print #secu, ConstructionFerme : nSave = nSave + 1
        print #secu, ConstructionTour : nSave = nSave + 1
        print #secu, ConstructionAcademie : nSave = nSave + 1
        print #secu, ConstructionCamp : nSave = nSave + 1
        print #secu, nombreSoldatA(1) : nSave = nSave + 1
        print #secu, nombreSoldatB(1) : nSave = nSave + 1
        print #secu, rechercheAcad(1) : nSave = nSave + 1
        print #secu, rechercheAcad(2) : nSave = nSave + 1
        print #secu, rechercheAcad(3) : nSave = nSave + 1
        print #secu, rechercheAcad(4) : nSave = nSave + 1
        print #secu, rechercheAcad(5) : nSave = nSave + 1
        print #secu, rechercheAcad(6) : nSave = nSave + 1
        print #secu, rechercheAcad(7) : nSave = nSave + 1
        print #secu, rechercheAcad(8) : nSave = nSave + 1
        print #secu, rechercheAcad(9) : nSave = nSave + 1
        print #secu, rechercheAcad(10) : nSave = nSave + 1
        print #secu, Dynasty : nSave = nSave + 1
        print #secu, numSoldatP1 : nSave = nSave + 1
        erorsav = 2
        for x = 1 to numSoldatP1
            if IDunitP1(x) = 1 or IDunitP1(x) = 2 or IDunitP1(x) = 3 then
                print #secu, IDunitP1(x) : nSave = nSave + 1
                print #secu, PVsoldatP1(x) : nSave = nSave + 1
                print #secu, PvMAXsoldatP1(x) : nSave = nSave + 1
                print #secu, ATKsoldatP1(x) : nSave = nSave + 1
                print #secu, DEFsoldatP1(x) : nSave = nSave + 1
                print #secu, int(POSxSOLDATp1(x)) : nSave = nSave + 1
                print #secu, int(POSySOLDATp1(x)) : nSave = nSave + 1
                print #secu, XpSoldatP1(x) : nSave = nSave + 1
                print #secu, XpTotalSoldatP1(x) : nSave = nSave + 1
                print #secu, LvlSoldatP1(x) : nSave = nSave + 1
                print #secu, reloadTime(x) : nSave = nSave + 1
            end if
            if IDunitP1(x) = 4 then
                print #secu, IDunitP1(x) : nSave = nSave + 1
                print #secu, IDtourX(x) : nSave = nSave + 1
                print #secu, IDtourY(x) : nSave = nSave + 1
                print #secu, int(POSxTOWER(x)) : nSave = nSave + 1
                print #secu, int(POSyTOWER(x)) : nSave = nSave + 1
                print #secu, PVsoldatP1(x) : nSave = nSave + 1
                print #secu, PvMAXsoldatP1(x) : nSave = nSave + 1
                print #secu, DEFtour(x) : nSave = nSave + 1
                print #secu, ATKtour(x) : nSave = nSave + 1
                print #secu, reloadTower(x) : nSave = nSave + 1
                print #secu, localisationTower(x)
            end if
            if IDunitP1(x) = 6 then
                print #secu, IDunitP1(x) : nSave = nSave + 1
                print #secu, IDcampX(x) : nSave = nSave + 1
                print #secu, IDcampY(x) : nSave = nSave + 1
                print #secu, int(POSxCAMP(x)) : nSave = nSave + 1
                print #secu, int(POSyCAMP(x)) : nSave = nSave + 1
                print #secu, PvCamp(x) : nSave = nSave + 1
                print #secu, PvMaxCamp(x) : nSave = nSave + 1
                print #secu, DEFcamp(x) : nSave = nSave + 1
            end if
            if IDunitP1(x) = 7 then
                nourritureRestante(x) = b(IDfermeX(x)/96,IDfermeY(x)/96)
                print #secu, IDunitP1(x) : nSave = nSave + 1
                print #secu, IDfermeX(x) : nSave = nSave + 1
                print #secu, IDfermeY(x) : nSave = nSave + 1
                print #secu, int(POSxFerme(x)) : nSave = nSave + 1
                print #secu, int(POSyFerme(x)) : nSave = nSave + 1
                print #secu, PvFerme(x) : nSave = nSave + 1
                print #secu, PvFermeMAX(x) : nSave = nSave + 1
                print #secu, DEFferme(x) : nSave = nSave + 1
                print #secu, nourritureRestante(x) : nSave = nSave + 1
                print #secu, localisationFermage(x)
            end if
            if IDunitP1(x) = 8 then
                print #secu, IDunitP1(x) : nSave = nSave + 1
                print #secu, IDacademieX(x) : nSave = nSave + 1
                print #secu, IDacademieY(x) : nSave = nSave + 1
                print #secu, int(POSxAcademie(x)) : nSave = nSave + 1
                print #secu, int(POSyAcademie(x)) : nSave = nSave + 1
                print #secu, PvAcademie(x) : nSave = nSave + 1
                print #secu, PvMaxAcademie(x) : nSave = nSave + 1
                print #secu, DEFacademie(x) : nSave = nSave + 1
                print #secu, lvlAcademie(x) : nSave = nSave + 1
            end if
            if IDunitP1(x) = 9 then
                print #secu, IDunitP1(x) : nSave = nSave + 1
                print #secu, IDvillageX(x) : nSave = nSave + 1
                print #secu, IDvillageY(x) : nSave = nSave + 1
                print #secu, int(POSxVillage(x)) : nSave = nSave + 1
                print #secu, int(POSyVillage(x)) : nSave = nSave + 1
                print #secu, PVsoldatP1(x) : nSave = nSave + 1
                print #secu, PvMAXsoldatP1(x) : nSave = nSave + 1
                print #secu, DEFvillage(x) : nSave = nSave + 1
                print #secu, lvlVILLE(x) : nSave = nSave + 1
            end if
        next x
        erorsav = 3
        print #secu, recherche(1) : nSave = nSave + 1
        print #secu, recherche(2) : nSave = nSave + 1
        print #secu, recherche(3) : nSave = nSave + 1
        print #secu, recherche(4) : nSave = nSave + 1
        print #secu, ConstructionTourMax : nSave = nSave + 1
        print #secu, ConstructionFermeMax : nSave = nSave + 1
        print #secu, upgradeVILLE(1) : nSave = nSave + 1
        print #secu, limiteFermage(1)
        print #secu, limiteBois(1)
        print #secu, limiteMines(1)
        print #secu, activationConstrucAcad
        print #secu, compteurAcad
        print #secu, acadX
        print #secu, acadY
        print #secu, activationConstrucFarm
        print #secu, compteurFarm
        print #secu, farmX
        print #secu, farmY
        print #secu, activationConstrucTower
        print #secu, compteurTower
        print #secu, towerX
        print #secu, towerY
        print #secu, activationConstrucCamp
        print #secu, compteurCamp
        print #secu, campX
        print #secu, campY
        erorsav = 4
        'AI 2
        print #secu, int(nourriture(2)) : nSave = nSave + 1
        print #secu, int(bois(2)) : nSave = nSave + 1
        print #secu, int(minerais(2)) : nSave = nSave + 1
        print #secu, pop(2) : nSave = nSave + 1
        print #secu, popMAX(2) : nSave = nSave + 1
        print #secu, nombrePeon(2)
        print #secu, ConstructionFermeAI1
        print #secu, ConstructionFermeDONEai1
        print #secu, ConstructionAcademieAI1
        print #secu, ConstructionCampAI1
        print #secu, ConstructionTourAI1
        print #secu, ConstructionTourMaxAI1
        print #secu, XvilleP2
        print #secu, YvilleP2
        print #secu, numSoldatP2
        print #secu, nombreSoldatA(2)
        print #secu, nombreSoldatB(2)
        print #secu, limiteFermage(2)
        print #secu, limiteBois(2)
        print #secu, limiteMines(2)
        erorsav = 5
        for y = 1 to numSoldatP2
            if IDunitP2(y) = 1 or IDunitP2(y) = 2 or IDunitP2(y) = 3 then
                erorsav = 51
                print #secu, IDunitP2(y) : nSave = nSave + 1
                print #secu, PVsoldatP2(y) : nSave = nSave + 1
                print #secu, PVMAXsoldatP2(y) : nSave = nSave + 1
                print #secu, ATKsoldatP2(y) : nSave = nSave + 1
                print #secu, DEFsoldatP2(y) : nSave = nSave + 1
                print #secu, int(POSxSOLDATp2(y)) : nSave = nSave + 1
                print #secu, int(POSySOLDATp2(y)) : nSave = nSave + 1
                print #secu, reloadTimeE(y) : nSave = nSave + 1
            end if
            if IDunitP2(y) = 7 then
                erorsav = 52
               ' notice b(IDfermageXai(y)/96, IDfermageYai(y)/96)
                print #secu, IDunitP2(y) : nSave = nSave + 1
                print #secu, IDfermageXai(y) : nSave = nSave + 1
                print #secu, IDfermageYai(y) : nSave = nSave + 1
                print #secu, int(POSxSOLDATp2(y)) : nSave = nSave + 1
                print #secu, int(POSySOLDATp2(y)) : nSave = nSave + 1
                print #secu, PVsoldatP2(y) : nSave = nSave + 1
                print #secu, PVMAXsoldatP2(y) : nSave = nSave + 1
                print #secu, DEFsoldatP2(y) : nSave = nSave + 1
                print #secu, b(IDfermageXai(y)/96, IDfermageYai(y)/96) : nSave = nSave + 1
            end if
            if IDunitP2(y) = 4 or IDunitP2(y) = 5 or IDunitP2(y) = 6 then
                erorsav = 53
                print #secu, IDunitP2(y) : nSave = nSave + 1
                print #secu, int(POSxSOLDATp2(y)) : nSave = nSave + 1
                print #secu, int(POSySOLDATp2(y)) : nSave = nSave + 1
                print #secu, PVsoldatP2(y) : nSave = nSave + 1
                print #secu, PVMAXsoldatP2(y) : nSave = nSave + 1
                print #secu, DEFsoldatP2(y) : nSave = nSave + 1
            end if
            if IDunitP2(y) = 8 then
                erorsav = 54
                print #secu, IDunitP2(y) : nSave = nSave + 1
                print #secu, int(POSxSOLDATp2(y)) : nSave = nSave + 1
                print #secu, int(POSySOLDATp2(y)) : nSave = nSave + 1
                print #secu, PVsoldatP2(y) : nSave = nSave + 1
                print #secu, PVMAXsoldatP2(y) : nSave = nSave + 1
                print #secu, ATKsoldatP2(y) : nSave = nSave + 1
                print #secu, DEFsoldatP2(y) : nSave = nSave + 1
                print #secu, IDtourXai(y)
                print #secu, IDtourYai(y)
            end if
        next y
        erorsav = 6
        print #secu, activationConstrucTowerIA
        print #secu, compteurTowerAI
        print #secu, towerAIx
        print #secu, towerAIy
        print #secu, activationConstrucAcadIA
        print #secu, compteurAcadAI
        print #secu, acadAIx
        print #secu, acadAIy
        print #secu, activationConstrucCampIA
        print #secu, compteurCampAI
        print #secu, campAIx
        print #secu, campAIy
        print #secu, activationConstrucFermeIA
        print #secu, compteurFermeAI
        print #secu, farmAIx
        print #secu, farmAIy
        print #secu, ia1discoverPlayer
        close #secu
        print #main.map2, "cls"
        if version = 1 then notice " " + chr$(13) +  "Données sauvegardées"';nSave
        if version = 2 then notice " " + chr$(13) +  "Data saved"
        goto [refreshLAND]
    end if


    if activationConstrucAcad = 0 and IDconstruction = 1 and (p(xNEW,yNEW) = 0 or p(xNEW,yNEW) = 17 or p(xNEW,yNEW) = 18 or p(xNEW,yNEW) = 19 or p(xNEW,yNEW) = 20) then
        for k = 1 to numSoldatP1
            if peonSELECT(k) = 1 then IDworker = k
        next k
        if xNEW < int(POSxSOLDATp1(IDworker)/96) or xNEW > int(POSxSOLDATp1(IDworker)/96)+2 or yNEW < int(POSySOLDATp1(IDworker)/96) or yNEW > int(POSySOLDATp1(IDworker)/96)+2 then goto [WorkerBuilder]
        if ConstructionAcademie = 1 and version = 1 then notice " " + chr$(13) +  "Le nombre maximal de ce batiment est atteint." : IDconstruction = 0 : goto [refreshLAND]
        if CostNourritureCamp > nourriture(1) and version = 1 then notice " " + chr$(13) +  "Vous n'avez pas assez de nourriture pour construire ce batiment !" : IDconstruction = 0 : goto [refreshLAND]
        if CostBoisCamp > bois(1) and version = 1 then notice " " + chr$(13) +  "Vous n'avez pas assez de bois pour construire ce batiment !" : IDconstruction = 0 : goto [refreshLAND]
        if CostMineraisCamp > minerais(1) and version = 1 then notice " " + chr$(13) +  "Vous n'avez pas assez de minerais pour construire ce batiment !" : IDconstruction = 0 : goto [refreshLAND]
        if ConstructionAcademie = 1 and version = 2 then notice " " + chr$(13) +  "The maximum number of this building has been reached." : IDconstruction = 0 : goto [refreshLAND]
        if CostNourritureCamp > nourriture(1) and version = 2 then notice " " + chr$(13) +  "You don't have enough food to build this building!" : IDconstruction = 0 : goto [refreshLAND]
        if CostBoisCamp > bois(1) and version = 2 then notice " " + chr$(13) +  "You don't have enough wood to build this building!" : IDconstruction = 0 : goto [refreshLAND]
        if CostMineraisCamp > minerais(1) and version = 2 then notice " " + chr$(13) +  "You don't have enough ores to build this building!" : IDconstruction = 0 : goto [refreshLAND]
        activationConstrucAcad = 1 : compteurAcad = 15 : acadX = xNEW : acadY = yNEW : p(acadX,acadY) = 999 : moovingActivation = 1 : ConstructionAcademie = 1
        nourriture(1) = nourriture(1) - CostNourritureCamp : bois(1) = bois(1) - CostBoisCamp : minerais(1) = minerais(1) - CostMineraisCamp
    end if

    if activationConstrucFarm = 0 and IDconstruction = 2 and (p(xNEW,yNEW) = 0 or p(xNEW,yNEW) = 17 or p(xNEW,yNEW) = 18 or p(xNEW,yNEW) = 19 or p(xNEW,yNEW) = 20) then
        for k = 1 to numSoldatP1
            if peonSELECT(k) = 1 then IDworker = k
        next k
        if xNEW < int(POSxSOLDATp1(IDworker)/96) or xNEW > int(POSxSOLDATp1(IDworker)/96)+2 or yNEW < int(POSySOLDATp1(IDworker)/96) or yNEW > int(POSySOLDATp1(IDworker)/96)+2 then goto [WorkerBuilder]
        if ConstructionFerme >= ConstructionFermeMax and version = 1 then notice " " + chr$(13) +  "Le nombre maximal de ce batiment est atteint." : IDconstruction = 0 : goto [refreshLAND]
        if CostNourritureFermage > nourriture(1) and version = 1 then notice " " + chr$(13) +  "Vous n'avez pas assez de nourriture pour construire ce batiment !" : IDconstruction = 0 : goto [refreshLAND]
        if CostBoisFermage > bois(1) and version = 1 then notice " " + chr$(13) +  "Vous n'avez pas assez de bois pour construire ce batiment !" : IDconstruction = 0 : goto [refreshLAND]
        if CostMineraisFermage > minerais(1) and version = 1 then notice " " + chr$(13) +  "Vous n'avez pas assez de minerais pour construire ce batiment !" : IDconstruction = 0 : goto [refreshLAND]
        if ConstructionFerme >= ConstructionFermeMax and version = 2 then notice " " + chr$(13) +  "The maximum number of this building has been reached." : IDconstruction = 0 : goto [refreshLAND]
        if CostNourritureFermage > nourriture(1) and version = 2 then notice " " + chr$(13) +  "You don't have enough food to build this building!" : IDconstruction = 0 : goto [refreshLAND]
        if CostBoisFermage > bois(1) and version = 2 then notice " " + chr$(13) +  "You don't have enough wood to build this building!" : IDconstruction = 0 : goto [refreshLAND]
        if CostMineraisFermage > minerais(1) and version = 2 then notice " " + chr$(13) +  "You don't have enough ores to build this building!" : IDconstruction = 0 : goto [refreshLAND]
        activationConstrucFarm = 1 : compteurFarm = 4 : farmX = xNEW : farmY = yNEW : p(farmX,farmY) = 999 : moovingActivation = 1 : ConstructionFerme = ConstructionFerme + 1 : ConstructionFermeDONE = ConstructionFermeDONE + 1
        nourriture(1) = nourriture(1) - CostNourritureFermage : bois(1) = bois(1) - CostBoisFermage : minerais(1) = minerais(1) - CostMineraisFermage
    end if

    if activationConstrucTower = 0 and IDconstruction = 3 and (p(xNEW,yNEW) = 0 or p(xNEW,yNEW) = 17 or p(xNEW,yNEW) = 18 or p(xNEW,yNEW) = 19 or p(xNEW,yNEW) = 20) then
        for k = 1 to numSoldatP1
            if peonSELECT(k) = 1 then IDworker = k
        next k
        if xNEW < int(POSxSOLDATp1(IDworker)/96) or xNEW > int(POSxSOLDATp1(IDworker)/96)+2 or yNEW < int(POSySOLDATp1(IDworker)/96) or yNEW > int(POSySOLDATp1(IDworker)/96)+2 then goto [WorkerBuilder]
        if ConstructionTour >= ConstructionTourMax and version = 1 then notice " " + chr$(13) +  "Le nombre maximal de ce batiment est atteint." : IDconstruction = 0 : goto [refreshLAND]
        if CostNourritureTour > nourriture(1) and version = 1 then notice " " + chr$(13) +  "Vous n'avez pas assez de nourriture pour construire ce batiment !" : IDconstruction = 0 : goto [refreshLAND]
        if CostBoisTour > bois(1) and version = 1 then notice " " + chr$(13) +  "Vous n'avez pas assez de bois pour construire ce batiment !" : IDconstruction = 0 : goto [refreshLAND]
        if CostMineraisTour > minerais(1) and version = 1 then notice " " + chr$(13) +  "Vous n'avez pas assez de minerais pour construire ce batiment !" : IDconstruction = 0 : goto [refreshLAND]
        if ConstructionTour >= ConstructionTourMax and version = 2 then notice " " + chr$(13) +  "The maximum number of this building has been reached." : IDconstruction = 0 : goto [refreshLAND]
        if CostNourritureTour > nourriture(1) and version = 2 then notice " " + chr$(13) +  "You don't have enough food to build this building!" : IDconstruction = 0 : goto [refreshLAND]
        if CostBoisTour > bois(1) and version = 2 then notice " " + chr$(13) +  "You don't have enough wood to build this building!" : IDconstruction = 0 : goto [refreshLAND]
        if CostMineraisTour > minerais(1) and version = 2 then notice " " + chr$(13) +  "You don't have enough ores to build this building!" : IDconstruction = 0 : goto [refreshLAND]
        activationConstrucTower = 1 : compteurTower = 10 : towerX = xNEW : towerY = yNEW : p(towerX,towerY) = 999 : moovingActivation = 1 : ConstructionTour = ConstructionTour + 1 : ConstructionTourDONE = ConstructionTourDONE + 1
        nourriture(1) = nourriture(1) - CostNourritureTour : bois(1) = bois(1) - CostBoisTour : minerais(1) = minerais(1) - CostMineraisTour
    end if

    if activationConstrucCamp = 0 and IDconstruction = 4 and (p(xNEW,yNEW) = 0 or p(xNEW,yNEW) = 17 or p(xNEW,yNEW) = 18 or p(xNEW,yNEW) = 19 or p(xNEW,yNEW) = 20) then
        for k = 1 to numSoldatP1
            if peonSELECT(k) = 1 then IDworker = k
        next k
        if xNEW < int(POSxSOLDATp1(IDworker)/96) or xNEW > int(POSxSOLDATp1(IDworker)/96)+2 or yNEW < int(POSySOLDATp1(IDworker)/96) or yNEW > int(POSySOLDATp1(IDworker)/96)+2 then goto [WorkerBuilder]
        if ConstructionCamp = 1 and version = 1 then notice " " + chr$(13) +  "Le nombre maximal de ce batiment est atteint." : IDconstruction = 0 : goto [refreshLAND]
        if CostNourritureCaserne > nourriture(1) and version = 1 then notice " " + chr$(13) +  "Vous n'avez pas assez de nourriture pour construire ce batiment !" : IDconstruction = 0 : goto [refreshLAND]
        if CostBoisCaserne > bois(1) and version = 1 then notice " " + chr$(13) +  "Vous n'avez pas assez de bois pour construire ce batiment !" : IDconstruction = 0 : goto [refreshLAND]
        if CostMineraisCaserne > minerais(1) and version = 1 then notice " " + chr$(13) +  "Vous n'avez pas assez de minerais pour construire ce batiment !" : IDconstruction = 0 : goto [refreshLAND]
        if ConstructionCamp = 1 and version = 2 then notice " " + chr$(13) +  "The maximum number of this building has been reached." : IDconstruction = 0 : goto [refreshLAND]
        if CostNourritureCaserne > nourriture(1) and version = 2 then notice " " + chr$(13) +  "You don't have enough food to build this building!" : IDconstruction = 0 : goto [refreshLAND]
        if CostBoisCaserne > bois(1) and version = 2 then notice " " + chr$(13) +  "You don't have enough wood to build this building!" : IDconstruction = 0 : goto [refreshLAND]
        if CostMineraisCaserne > minerais(1) and version = 2 then notice " " + chr$(13) +  "You don't have enough ores to build this building!" : IDconstruction = 0 : goto [refreshLAND]
        activationConstrucCamp = 1 : compteurCamp = 8 : campX = xNEW : campY = yNEW : p(campX,campY) = 999 : moovingActivation = 1 : ConstructionCamp = 1
        nourriture(1) = nourriture(1) - CostNourritureCaserne : bois(1) = bois(1) - CostBoisCaserne : minerais(1) = minerais(1) - CostMineraisCaserne
    end if

    select case p(xNEW,yNEW)
        case 13
            unlockACHATunit = 0
            #main.map2 "drawbmp tour 36 150; drawbmp ressource1 36 20; drawbmp ressource2 36 50; drawbmp ressource3 155 20; drawbmp ressource4 155 50; drawbmp repare 36 150; drawbmp demolir 210 150"
            for t = 1 to numSoldatP1
                if IDunitP1(t) = 4 and c(xNEW,yNEW) = localisationTower(t) then ID = t
            next t
            print #main.map2, "font Courier_New 10; color blue; backcolor white"
            if version = 1 then
                if rechercheAcad(3) = 0 then print #main.map2, "place 36 110 ;\"; "Tour de guet"
                if rechercheAcad(3) = 1 then print #main.map2, "place 36 110 ;\"; "Tour"
                print #main.map2, "place 15 350 ;\"; "    - Batiment défensif -"
                print #main.map2, "font Courier_New 10; color black; backcolor white"
                print #main.map2, "place 36 130 ;\"; "Durabilité : "; PVsoldatP1(ID); "/";PvMAXsoldatP1(ID); " [";DEFtour(ID);"]  "
                if rechercheAcad(3) = 0 then
                    print #main.map2, "place 15 470 ;\"; "! : Vous devez terminer la \recherche dans l'académie pour \que votre tour puisse tirer \des flèches sur les unitées \ennemies."
                end if
                if rechercheAcad(3) = 1 then
                    print #main.map2, "place 15 470 ;\"; "Valeur d'attaque : "; ATKtour(ID); "       "
                    print #main.map2, "place 15 485 ;\"; "Recharge de l'attaque : 50"
                end if
                print #main.map2, "place 15 380 ;\"; "Ce batiment sert à défendre \votre territoire en tirant des \flèches sur tout ennemis à \portée de tir."
            end if
            if version = 2 then
                if rechercheAcad(3) = 0 then print #main.map2, "place 36 110 ;\"; "Watchtower"
                if rechercheAcad(3) = 1 then print #main.map2, "place 36 110 ;\"; "Tower"
                print #main.map2, "place 15 350 ;\"; "    - Defensive building -"
                print #main.map2, "font Courier_New 10; color black; backcolor white"
                print #main.map2, "place 36 130 ;\"; "Durability : "; PVsoldatP1(ID); "/";PvMAXsoldatP1(ID); " [";DEFtour(ID);"]  "
                if rechercheAcad(3) = 0 then
                    print #main.map2, "place 15 470 ;\"; "! : You must complete the \research in the academy for \your tower to be able to shoot \arrows at enemy units."
                end if
                if rechercheAcad(3) = 1 then
                    print #main.map2, "place 15 470 ;\"; "Attack Value : "; ATKtour(ID); "       "
                    print #main.map2, "place 15 485 ;\"; "Attack cooldown : 50"
                end if
                print #main.map2, "place 15 380 ;\"; "This building is used to defend \your territory by shooting \arrows at any enemies within \range."
            end if
        case 14
            unlockACHATunit = 0 : AchatUnitMode = 1
            CoorXcamps = xNEW : CoorYcamps = yNEW
            for t = 1 to numSoldatP1
                if IDunitP1(t) = 6 then ID = t
            next t
            #main.map2 "drawbmp caserne 36 150; drawbmp ressource1 36 20; drawbmp ressource2 36 50; drawbmp ressource3 155 20; drawbmp ressource4 155 50; drawbmp repare 36 150; drawbmp demolir 210 150"
            #main.map2 "drawbmp humain1 20 400; drawbmp humain2 20 490"
            if version = 1 then
                print #main.map2, "font Courier_New 10; color blue; backcolor white"
                print #main.map2, "place 36 110 ;\"; "Camp d'entrainement"
                print #main.map2, "place 40 370 ;\"; "- Unités disponibles -"
                print #main.map2, "font Courier_New 10; color black; backcolor white"
                print #main.map2, "place 36 130 ;\"; "Durabilité : "; PvCamp(ID); "/";PvMaxCamp(ID); " [";DEFcamp(ID);"]  "
                print #main.map2, "font Courier_New 8 bold; color black; backcolor white"
                print #main.map2, "place 70 414 ;\"; "Fantassin léger"
                print #main.map2, "place 70 504 ;\"; "Lancier"
                print #main.map2, "font Courier_New 9 bold; color black; backcolor white"
                print #main.map2, "place 206 425 ;\"; "Former\\";nombreSoldatA(1)
                print #main.map2, "place 206 515 ;\"; "Former\\";nombreSoldatB(1)
            end if
            if version = 2 then
                print #main.map2, "font Courier_New 10; color blue; backcolor white"
                print #main.map2, "place 36 110 ;\"; "Training camp"
                print #main.map2, "place 60 370 ;\"; "- Available units -"
                print #main.map2, "font Courier_New 10; color black; backcolor white"
                print #main.map2, "place 36 130 ;\"; "Durability : "; PvCamp(ID); "/";PvMaxCamp(ID); " [";DEFcamp(ID);"]  "
                print #main.map2, "font Courier_New 8 bold; color black; backcolor white"
                print #main.map2, "place 70 414 ;\"; "Infantryman"
                print #main.map2, "place 70 504 ;\"; "Lancer"
                print #main.map2, "font Courier_New 9 bold; color black; backcolor white"
                print #main.map2, "place 206 425 ;\"; "Train\\";nombreSoldatA(1)
                print #main.map2, "place 206 515 ;\"; "Train\\";nombreSoldatB(1)
            end if
            print #main.map2, "place 90 428 ;\"; costValorHommeArme1
            print #main.map2, "place 90 443 ;\"; costValorHommeArme2
            print #main.map2, "place 90 458 ;\"; costValorHommeArme3
            print #main.map2, "place 158 428 ;\"; "8"
            print #main.map2, "place 158 443 ;\"; "1"
            print #main.map2, "place 158 458 ;\"; "3"
            print #main.map2, "place 90 518 ;\"; costValorLancier1
            print #main.map2, "place 90 533 ;\"; costValorLancier2
            print #main.map2, "place 90 548 ;\"; costValorLancier3
            print #main.map2, "place 158 518 ;\"; "5"
            print #main.map2, "place 158 533 ;\"; "2"
            print #main.map2, "place 158 548 ;\"; "4"
        case 15
            [refreshAca]
            unlockACHATunit = 0
            #main.map2 "drawbmp academie 36 150; drawbmp ressource1 36 20; drawbmp ressource2 36 50; drawbmp ressource3 155 20; drawbmp ressource4 155 50; drawbmp repare 36 150; drawbmp demolir 210 150"
            for t = 1 to numSoldatP1
                if IDunitP1(t) = 8 then ID = t
            next t
            if version = 1 then
                print #main.map2, "font Courier_New 10; color blue; backcolor white"
                print #main.map2, "place 36 110 ;\"; "Académie niveau ";lvlAcademie(ID)
                print #main.map2, "place 28 330 ;\"; "- Recherches disponibles -"
                print #main.map2, "font Courier_New 10; color black; backcolor white"
                print #main.map2, "place 36 130 ;\"; "Durabilité : "; PvAcademie(ID); "/";PvMaxAcademie(ID); " [";DEFacademie(ID);"]  "
                print #main.map2, "font Courier_New 8; color black; backcolor white"
                print #main.map2, "place 50 360 ;\"; "Augmente la durabilité des \bâtiments de 5."
                print #main.map2, "place 50 400 ;\"; "Augmente la quantité de \nourriture des fermes de 450."
                print #main.map2, "place 50 440 ;\"; "Vos tours peuvent maintenant\tirer des flèches."
                print #main.map2, "place 50 480 ;\"; "Augmente la santé de vos\villageois de 2."
                print #main.map2, "place 50 520 ;\"; "Augmente la population max\de votre village de 10."
                print #main.map2, "place 50 560 ;\"; "Augmente la durabilité du village\de 100 et sa défense de 1."
                print #main.map2, "place 50 600 ;\"; "Vous avez un revenu régulier\de chaque ressources. (1/sc)"
                print #main.map2, "place 50 640 ;\"; "Augmente la durabilité de\vos tours de 10."
                print #main.map2, "place 50 680 ;\"; "Augmente la resistance de\vos batiments de 1."
            end if
            if version = 2 then
                print #main.map2, "font Courier_New 10; color blue; backcolor white"
                print #main.map2, "place 36 110 ;\"; "Academy level ";lvlAcademie(ID)
                print #main.map2, "place 46 330 ;\"; "- Available research -"
                print #main.map2, "font Courier_New 10; color black; backcolor white"
                print #main.map2, "place 36 130 ;\"; "Durability : "; PvAcademie(ID); "/";PvMaxAcademie(ID); " [";DEFacademie(ID);"]  "
                print #main.map2, "font Courier_New 8; color black; backcolor white"
                print #main.map2, "place 50 360 ;\"; "Increases the durability of \buildings by 5."
                print #main.map2, "place 50 400 ;\"; "Increases the amount of \food from farms by 450."
                print #main.map2, "place 50 440 ;\"; "Your towers can now shoot \arrows."
                print #main.map2, "place 50 480 ;\"; "Increases the health of \your villagers by 2."
                print #main.map2, "place 50 520 ;\"; "Increases your village's \max population by 10."
                print #main.map2, "place 50 560 ;\"; "Increases the durability of \village by 100 and armor by 1."
                print #main.map2, "place 50 600 ;\"; "You have a regular income \from each resource. (1/sc)"
                print #main.map2, "place 50 640 ;\"; "Increases the durability of \your towers by 10."
                print #main.map2, "place 50 680 ;\"; "Increases the resistance of \your buildings by 1."
            end if
            if rechercheAcad(1) = 0 then #main.map2 "drawbmp rechercheAcademikOFF 15 350"
            if rechercheAcad(1) = 1 then #main.map2 "drawbmp rechercheAcademikON 15 350"
            if rechercheAcad(2) = 0 then #main.map2 "drawbmp rechercheAcademikOFF 15 390"
            if rechercheAcad(2) = 1 then #main.map2 "drawbmp rechercheAcademikON 15 390"
            if rechercheAcad(3) = 0 then #main.map2 "drawbmp rechercheAcademikOFF 15 430"
            if rechercheAcad(3) = 1 then #main.map2 "drawbmp rechercheAcademikON 15 430"
            if rechercheAcad(4) = 0 then #main.map2 "drawbmp rechercheAcademikOFF 15 470"
            if rechercheAcad(4) = 1 then #main.map2 "drawbmp rechercheAcademikON 15 470"
            if rechercheAcad(5) = 0 then #main.map2 "drawbmp rechercheAcademikOFF 15 510"
            if rechercheAcad(5) = 1 then #main.map2 "drawbmp rechercheAcademikON 15 510"
            if rechercheAcad(6) = 0 then #main.map2 "drawbmp rechercheAcademikOFF 15 550"
            if rechercheAcad(6) = 1 then #main.map2 "drawbmp rechercheAcademikON 15 550"
            if rechercheAcad(7) = 0 then #main.map2 "drawbmp rechercheAcademikOFF 15 590"
            if rechercheAcad(7) = 1 then #main.map2 "drawbmp rechercheAcademikON 15 590"
            if rechercheAcad(8) = 0 then #main.map2 "drawbmp rechercheAcademikOFF 15 630"
            if rechercheAcad(8) = 1 then #main.map2 "drawbmp rechercheAcademikON 15 630"
            if rechercheAcad(9) = 0 then #main.map2 "drawbmp rechercheAcademikOFF 15 670"
            if rechercheAcad(9) = 1 then #main.map2 "drawbmp rechercheAcademikON 15 670"
        case 1
            print #main.map2, "cls"
            unlockACHATunit = 0
            #main.map2 "drawbmp ferme 36 150; drawbmp ressource1 36 20; drawbmp ressource2 36 50; drawbmp ressource3 155 20; drawbmp ressource4 155 50; drawbmp repare 36 150; drawbmp demolir 210 150"
            for t = 1 to numSoldatP1
                if IDunitP1(t) = 7 and c(xNEW,yNEW) = localisationFermage(t) then ID = t
            next t
            for a = 1 to numSoldatP1
                limiteWorkerFermage(a) = 0
            next a
            for u = 1 to numSoldatP1
                select case IDunitP1(u)
                    case 3
                    if PVsoldatP1(u) <= 0 then goto [nextFarmer]
                        for x = 1 to numSoldatP1
                            if IDunitP1(x) = 7 and c(xNEW,yNEW) = localisationFermage(x) and c((POSxSOLDATp1(u)/96)+1,(POSySOLDATp1(u)/96)+0.5) = localisationFermage(x) then limiteWorkerFermage(x) = limiteWorkerFermage(x) + 1 : ID2 = x
                            if limiteWorkerFermage(x) > limiteFermage(1) then limiteWorkerFermage(x) = limiteFermage(1)
                        next x
                end select
                [nextFarmer]
            next u
            if version = 1 then
                print #main.map2, "font Courier_New 10; color blue; backcolor white"
                print #main.map2, "place 36 110 ;\"; "Fermage"
                print #main.map2, "place 15 350 ;\"; "    - Ressource primaire -"
                print #main.map2, "font Courier_New 10; color black; backcolor white"
                print #main.map2, "place 36 130 ;\"; "Durabilité : "; PvFerme(ID); "/";PvFermeMAX(ID); " [";DEFferme(ID);"]  "
                print #main.map2, "place 15 430 ;\"; "Fermier(s) : "; limiteWorkerFermage(ID2); " / ";limiteFermage(1)
                print #main.map2, "place 15 380 ;\"; "Fournie de la nourriture\lorsque ces terres sont \exploitées.\\\\\(Pour récolter la ressource \vous devez selectionner un \paysan et l'envoyer sur la \ressource avec un clic droit)"
            end if
            if version = 2 then
                print #main.map2, "font Courier_New 10; color blue; backcolor white"
                print #main.map2, "place 36 110 ;\"; "Farming"
                print #main.map2, "place 15 350 ;\"; "    - Primary resource -"
                print #main.map2, "font Courier_New 10; color black; backcolor white"
                print #main.map2, "place 36 130 ;\"; "Durability : "; PvFerme(ID); "/";PvFermeMAX(ID); " [";DEFferme(ID);"]  "
                print #main.map2, "place 15 430 ;\"; "Farmer(s) : "; limiteWorkerFermage(ID2); " / ";limiteFermage(1)
                print #main.map2, "place 15 380 ;\"; "Provides food when these \lands are exploited.\\\\\(To harvest the resource you \must select a farmer and \send him to the resource \with a right click)"
            end if
        case 4
            unlockACHATunit = 0
            #main.map2 "drawbmp montagne 36 150; drawbmp ressource1 36 20; drawbmp ressource2 36 50; drawbmp ressource3 155 20; drawbmp ressource4 155 50"
            NworkerMINE(1) = 0
            for u = 1 to numSoldatP1
                select case IDunitP1(u)
                    case 3
                        if PVsoldatP1(u) <= 0 then goto [nextMiner]
                        if p((POSxSOLDATp1(u)/96)+1,(POSySOLDATp1(u)/96)+0.5) = 4 then NworkerMINE(1) = NworkerMINE(1) + 1
                        if NworkerMINE(1) > limiteMines(1) then NworkerMINE(1) = limiteMines(1)
                end select
                [nextMiner]
            next u
            if version = 1 then
                print #main.map2, "font Courier_New 10; color blue; backcolor white"
                print #main.map2, "place 36 130 ;\"; "MONTAGNES"
                print #main.map2, "place 15 350 ;\"; "    - Ressource primaire -"
                print #main.map2, "font Courier_New 10; color black; backcolor white"
                print #main.map2, "place 15 460 ;\"; "Mineur(s) : "; NworkerMINE(1); "/";limiteMines(1)
                print #main.map2, "place 15 380 ;\"; "Contient des minerais précieux \pour la construction de vos \bâtiments et le développement \de votre armée.\\\\\(Pour récolter la ressource \vous devez selectionner un \paysan et l'envoyer sur la \ressource avec un clic droit)"
            end if
            if version = 2 then
                print #main.map2, "font Courier_New 10; color blue; backcolor white"
                print #main.map2, "place 36 130 ;\"; "MOUNTAINS"
                print #main.map2, "place 15 350 ;\"; "    - Primary resource -"
                print #main.map2, "font Courier_New 10; color black; backcolor white"
                print #main.map2, "place 15 460 ;\"; "Miner(s) : "; NworkerMINE(1); "/";limiteMines(1)
                print #main.map2, "place 15 380 ;\"; "Contains valuable ores for \the construction of your \buildings and the development \of your army.\\\\\(To harvest the resource \you must select a \farmer and send him to the \resource with a right click)"
            end if
        case 3
            unlockACHATunit = 0
            #main.map2 "drawbmp foret 36 150; drawbmp ressource1 36 20; drawbmp ressource2 36 50; drawbmp ressource3 155 20; drawbmp ressource4 155 50"
            NworkerWOOD(1) = 0
            for u = 1 to numSoldatP1
                select case IDunitP1(u)
                    case 3
                        if PVsoldatP1(u) <= 0 then goto [nextWood]
                        if p((POSxSOLDATp1(u)/96)+1,(POSySOLDATp1(u)/96)+0.5) = 3 then NworkerWOOD(1) = NworkerWOOD(1) + 1
                        if NworkerWOOD(1) > limiteBois(1) then NworkerWOOD(1) = limiteBois(1)
                end select
                [nextWood]
            next u
            if version = 1 then
                print #main.map2, "font Courier_New 10; color blue; backcolor white"
                print #main.map2, "place 36 130 ;\"; "FORÊTS"
                print #main.map2, "place 15 350 ;\"; "    - Ressource primaire -"
                print #main.map2, "font Courier_New 10; color black; backcolor white"
                print #main.map2, "place 15 460 ;\"; "Bûcheron(s) : "; NworkerWOOD(1); "/";limiteBois(1)
                print #main.map2, "place 15 380 ;\"; "Contient des minerais précieux \pour la construction de vos \bâtiments et le développement \de votre armée.\\\\\(Pour récolter la ressource \vous devez selectionner un \paysan et l'envoyer sur la \ressource avec un clic droit)"
            end if
            if version = 2 then
                print #main.map2, "font Courier_New 10; color blue; backcolor white"
                print #main.map2, "place 36 130 ;\"; "FORESTS"
                print #main.map2, "place 15 350 ;\"; "    - Primary resource -"
                print #main.map2, "font Courier_New 10; color black; backcolor white"
                print #main.map2, "place 15 460 ;\"; "Woodcutter(s) : "; NworkerWOOD(1); "/";limiteBois(1)
                print #main.map2, "place 15 380 ;\"; "Contains raw wood for the \construction of your buildings \and the development of your \army. \\\\\(To harvest the resource \you must select a farmer and \send him to the resource with \a right click)"
            end if
        case 6,7,8,9,10,11,12,16
            unlockACHATunit = 0
            #main.map2 "drawbmp eau 36 150; drawbmp ressource1 36 20; drawbmp ressource2 36 50; drawbmp ressource3 155 20; drawbmp ressource4 155 50"
            if version = 1 then
                print #main.map2, "font Courier_New 10; color blue; backcolor white"
                print #main.map2, "place 36 130 ;\"; "OCEAN"
                print #main.map2, "font Courier_New 10; color black; backcolor white"
                print #main.map2, "place 50 350 ;\"; "- Non constructible -"
            end if
            if version = 2 then
                print #main.map2, "font Courier_New 10; color blue; backcolor white"
                print #main.map2, "place 36 130 ;\"; "OCEAN"
                print #main.map2, "font Courier_New 10; color black; backcolor white"
                print #main.map2, "place 50 350 ;\"; "- Not buildable -"
            end if
        case 0
            unlockACHATunit = 0
            [refreshLAND]
            #main.map2 "cls; drawbmp herbe 36 150; drawbmp ressource1 36 20; drawbmp ressource2 36 50; drawbmp ressource3 155 20; drawbmp ressource4 155 50"
            if version = 1 then
                print #main.map2, "font Courier_New 10; color blue; backcolor white"
                print #main.map2, "place 36 130 ;\"; "PLAINES"
                print #main.map2, "font Courier_New 10; color black; backcolor white"
                print #main.map2, "place 65 350 ;\"; "- Constructible -"
            end if
            if version = 2 then
                print #main.map2, "font Courier_New 10; color blue; backcolor white"
                print #main.map2, "place 36 130 ;\"; "PLAINS"
                print #main.map2, "font Courier_New 10; color black; backcolor white"
                print #main.map2, "place 65 350 ;\"; "- Buildable -"
            end if
        case 24
            #main.map2 "cls; drawbmp academieB 36 150; drawbmp ressource1 36 20; drawbmp ressource2 36 50; drawbmp ressource3 155 20; drawbmp ressource4 155 50"
            for t = 1 to numSoldatP2
                if IDunitP2(t) = 5 then ID = t
            next t
            if version = 1 then
                print #main.map2, "font Courier_New 10; color blue; backcolor white"
                print #main.map2, "place 36 110 ;\"; "(AI) Académie"
                print #main.map2, "font Courier_New 10; color black; backcolor white"
                print #main.map2, "place 36 130 ;\"; "Durabilité : ";PVsoldatP2(ID);" / ";PVMAXsoldatP2(ID)
            end if
            if version = 2 then
                print #main.map2, "font Courier_New 10; color blue; backcolor white"
                print #main.map2, "place 36 110 ;\"; "(AI) Academy"
                print #main.map2, "font Courier_New 10; color black; backcolor white"
                print #main.map2, "place 36 130 ;\"; "Durability : ";PVsoldatP2(ID);" / ";PVMAXsoldatP2(ID)
            end if
        case 26
            #main.map2 "cls; drawbmp caserneB 36 150; drawbmp ressource1 36 20; drawbmp ressource2 36 50; drawbmp ressource3 155 20; drawbmp ressource4 155 50"
            for t = 1 to numSoldatP2
                if IDunitP2(t) = 6 then ID = t
            next t
            if version = 1 then
                print #main.map2, "font Courier_New 10; color blue; backcolor white"
                print #main.map2, "place 36 110 ;\"; "(AI) Camp"
                print #main.map2, "font Courier_New 10; color black; backcolor white"
                print #main.map2, "place 36 130 ;\"; "Durabilité : ";PVsoldatP2(ID);" / ";PVMAXsoldatP2(ID)
            end if
            if version = 2 then
                print #main.map2, "font Courier_New 10; color blue; backcolor white"
                print #main.map2, "place 36 110 ;\"; "(AI) Camp"
                print #main.map2, "font Courier_New 10; color black; backcolor white"
                print #main.map2, "place 36 130 ;\"; "Durability : ";PVsoldatP2(ID);" / ";PVMAXsoldatP2(ID)
            end if
        case 22
            #main.map2 "cls; drawbmp maisonB 36 150; drawbmp ressource1 36 20; drawbmp ressource2 36 50; drawbmp ressource3 155 20; drawbmp ressource4 155 50"
            for t = 1 to numSoldatP2
                if IDunitP2(t) = 4 then ID = t
            next t
            if version = 1 then
                print #main.map2, "font Courier_New 10; color blue; backcolor white"
                print #main.map2, "place 36 110 ;\"; "(AI) Village niveau ";lvlVILLEAI(ID)
                print #main.map2, "font Courier_New 10; color black; backcolor white"
                print #main.map2, "place 36 130 ;\"; "Durabilité : ";PVsoldatP2(ID);" / ";PVMAXsoldatP2(ID)
            end if
            if version = 2 then
                print #main.map2, "font Courier_New 10; color blue; backcolor white"
                print #main.map2, "place 36 110 ;\"; "(AI) Village Level ";lvlVILLEAI(ID)
                print #main.map2, "font Courier_New 10; color black; backcolor white"
                print #main.map2, "place 36 130 ;\"; "Durability : ";PVsoldatP2(ID);" / ";PVMAXsoldatP2(ID)
            end if
        case 28
            #main.map2 "cls; drawbmp fermeB 36 150; drawbmp ressource1 36 20; drawbmp ressource2 36 50; drawbmp ressource3 155 20; drawbmp ressource4 155 50"
            for t = 1 to numSoldatP2
                if xNEW = IDfermageXai(t)/96 and yNEW = IDfermageYai(t)/96 then ID = t
            next t
            if version = 1 then
                print #main.map2, "font Courier_New 10; color blue; backcolor white"
                print #main.map2, "place 36 110 ;\"; "(AI) Ferme"
                print #main.map2, "font Courier_New 10; color black; backcolor white"
                print #main.map2, "place 36 130 ;\"; "Durabilité : ";PVsoldatP2(ID);" / ";PVMAXsoldatP2(ID)
            end if
            if version = 2 then
                print #main.map2, "font Courier_New 10; color blue; backcolor white"
                print #main.map2, "place 36 110 ;\"; "(AI) Farm"
                print #main.map2, "font Courier_New 10; color black; backcolor white"
                print #main.map2, "place 36 130 ;\"; "Durability : ";PVsoldatP2(ID);" / ";PVMAXsoldatP2(ID)
            end if
        case 30
            #main.map2 "cls; drawbmp tourB 36 150; drawbmp ressource1 36 20; drawbmp ressource2 36 50; drawbmp ressource3 155 20; drawbmp ressource4 155 50"
            for t = 1 to numSoldatP2
                if xNEW = IDtourXai(t)/96 and yNEW = IDtourYai(t)/96 then ID = t
            next t
            if version = 1 then
                print #main.map2, "font Courier_New 10; color blue; backcolor white"
                print #main.map2, "place 36 110 ;\"; "(AI) Tour"
                print #main.map2, "font Courier_New 10; color black; backcolor white"
                print #main.map2, "place 36 130 ;\"; "Durabilité : ";PVsoldatP2(ID);" / ";PVMAXsoldatP2(ID)
            end if
            if version = 2 then
                print #main.map2, "font Courier_New 10; color blue; backcolor white"
                print #main.map2, "place 36 110 ;\"; "(AI) Tower"
                print #main.map2, "font Courier_New 10; color black; backcolor white"
                print #main.map2, "place 36 130 ;\"; "Durability : ";PVsoldatP2(ID);" / ";PVMAXsoldatP2(ID)
            end if
        case 2
            [positionINI]
            if PVsoldatP1(1) <=0 then goto [refreshLAND]
            print #main.map2, "cls"
            unlockACHATunit = 1 : menuCONSTRUCTION = 0
            #main.map2 "drawbmp maison 36 150; drawbmp humain0 20 530; drawbmp ressource1 36 20; drawbmp ressource2 36 50; drawbmp ressource3 155 20; drawbmp ressource4 155 50; drawbmp repare 36 150"
            for t = 1 to numSoldatP1
                if IDunitP1(t) = 9 then ID = t
            next t

            if lvlVILLE(ID) = 1 then
                if recherche(1) = 0 then #main.map2 "drawbmp recherche1OFF 36 420"
                if recherche(1) = 1 then #main.map2 "drawbmp recherche1ON 36 420"
                if recherche(2) = 0 then #main.map2 "drawbmp recherche1OFF 90 420"
                if recherche(2) = 1 then #main.map2 "drawbmp recherche1ON 90 420"
                if recherche(3) = 0 then #main.map2 "drawbmp recherche2OFF 144 420"
                if recherche(3) = 1 then #main.map2 "drawbmp recherche2ON 144 420"
                if recherche(4) = 0 then #main.map2 "drawbmp recherche1OFF 198 420"
                if recherche(4) = 1 then #main.map2 "drawbmp recherche1ON 198 420"
            end if
            if lvlVILLE(ID) = 2 then
                if recherche(1) = 0 then #main.map2 "drawbmp recherche2OFF 36 420"
                if recherche(1) = 1 then #main.map2 "drawbmp recherche2ON 36 420"
                if recherche(2) = 0 then #main.map2 "drawbmp recherche2OFF 90 420"
                if recherche(2) = 1 then #main.map2 "drawbmp recherche2ON 90 420"
                if recherche(3) = 0 then #main.map2 "drawbmp recherche2OFF 144 420"
                if recherche(3) = 1 then #main.map2 "drawbmp recherche2ON 144 420"
                if recherche(4) = 0 then #main.map2 "drawbmp recherche2OFF 198 420"
                if recherche(4) = 1 then #main.map2 "drawbmp recherche2ON 198 420"
            end if

            if version = 1 then
                print #main.map2, "font Courier_New 10; color blue; backcolor white"
                print #main.map2, "place 36 110 ;\"; "Village niveau ";lvlVILLE(ID)
                print #main.map2, "place 30 400 ;\"; "- Développement possible -"
                print #main.map2, "place 30 505 ;\"; "- Unité(s) disponible(s) -"
                print #main.map2, "font Courier_New 10; color black; backcolor white"
                print #main.map2, "place 36 130 ;\"; "Durabilité : ";PVsoldatP1(ID);"/";PvMAXsoldatP1(ID); " [";DEFvillage(ID);"]  "
                print #main.map2, "font Courier_New 9 italic; color black; backcolor white"
                print #main.map2, "place 20 325 ;\"; "Info : lorsque ce bâtiment est \totalement développé, il augmente \d'un niveau et gagne en points de \durabilité."
                print #main.map2, "font Courier_New 8 bold; color black; backcolor white"
                print #main.map2, "place 70 544 ;\"; "Villageois"
                print #main.map2, "font Courier_New 9 bold; color black; backcolor white"
                print #main.map2, "place 206 555 ;\"; "Former\\";nombrePeon(1)
            end if
            if version = 2 then
                print #main.map2, "font Courier_New 10; color blue; backcolor white"
                print #main.map2, "place 36 110 ;\"; "Village Level ";lvlVILLE(1)
                print #main.map2, "place 35 400 ;\"; "- Possible development -"
                print #main.map2, "place 46 505 ;\"; "- Unit(s) available -"
                print #main.map2, "font Courier_New 10; color black; backcolor white"
                print #main.map2, "place 36 130 ;\"; "Durability : ";PVsoldatP1(ID);"/";PvMAXsoldatP1(ID); " [";DEFvillage(ID);"]  "
                print #main.map2, "font Courier_New 9 italic; color black; backcolor white"
                print #main.map2, "place 20 325 ;\"; "Info : When this building is \fully developed, it increases by \one level and gains durability \points."
                print #main.map2, "font Courier_New 8 bold; color black; backcolor white"
                print #main.map2, "place 70 544 ;\"; "Villagers"
                print #main.map2, "font Courier_New 9 bold; color black; backcolor white"
                print #main.map2, "place 206 555 ;\"; "Train\\";nombrePeon(1)
            end if
            print #main.map2, "place 87 558 ;\"; peonCOST
            print #main.map2, "place 87 573 ;\"; "0"
            print #main.map2, "place 87 588 ;\"; "0"
            print #main.map2, "place 158 558 ;\"; ""; 4+ 2*rechercheAcad(4)
            print #main.map2, "place 158 573 ;\"; "0"
            print #main.map2, "place 158 588 ;\"; "2"
    end select

    #main.map2 "drawbmp ressource1 36 20; drawbmp ressource2 36 50; drawbmp ressource3 155 20; drawbmp ressource4 155 50"
    goto [endLEVEL]


    [build]
    mXX = MouseX : mYY = MouseY
    errorTxt = 1000
    if p(xNEW,yNEW) = 15 and mXX > 15 and mXX <40 and mYY >350 and mYY <375 and rechercheAcad(1) = 0 then
        if version = 1 then confirm "Rechercher pour 80 de bois et 25 de minerais ?";rep$
        if version = 2 then confirm "Search for 80 wood and 25 ore?";rep$
        if rep$ = "no" then goto [endLEVEL]
        if int(bois(1)) < 80 and version = 1 then notice " " + chr$(13) +  "Vous n'avez pas assez de bois !" : goto [endLEVEL]
        if int(minerais(1)) < 25 and version = 1 then notice " " + chr$(13) +  "Vous n'avez pas assez de minerais !" : goto [endLEVEL]
        if int(bois(1)) < 80 and version = 2 then notice " " + chr$(13) +  "You don't have enough wood !" : goto [endLEVEL]
        if int(minerais(1)) < 25 and version = 2 then notice " " + chr$(13) +  "You don't have enough ores !" : goto [endLEVEL]
        bois(1) = bois(1) - 80
        minerais(1) = minerais(1) - 25
        for f = 1 to numSoldatP1
            if IDunitP1(f) = 4 then PVsoldatP1(f) = PVsoldatP1(f) + 5 : PvMAXsoldatP1(f) = PvMAXsoldatP1(f) + 5
            if IDunitP1(f) = 6 then PvCamp(f) = PvCamp(f) + 5 : PvMaxCamp(f) = PvMaxCamp(f) + 5
            if IDunitP1(f) = 7 then PvFerme(f) = PvFerme(f) + 5 : PvFermeMAX(f) = PvFermeMAX(f) + 5
            if IDunitP1(f) = 8 then PvAcademie(f) = PvAcademie(f) + 5 : PvMaxAcademie(f) = PvMaxAcademie(f) + 5
            if IDunitP1(f) = 9 then PVsoldatP1(f) = PVsoldatP1(f) + 5 : PvMAXsoldatP1(f) = PvMAXsoldatP1(f) + 5
        next f
        rechercheAcad(1) = 1 : goto [refreshAca]
    end if
    if p(xNEW,yNEW) = 15 and mXX > 15 and mXX <40 and mYY >390 and mYY <415 and rechercheAcad(2) = 0 then
        if version = 1 then confirm "Rechercher pour 200 de nourriture, 50 de bois ?";rep$
        if version = 2 then confirm "Search for 200 food and 50 wood ?";rep$
        if rep$ = "no" then goto [endLEVEL]
        if int(nourriture(1)) < 200 and version = 1 then notice " " + chr$(13) +  "vous n'avez pas assez de nourriture !" : goto [endLEVEL]
        if int(bois(1)) < 50 and version = 1 then notice " " + chr$(13) +  "vous n'avez pas assez de bois !" : goto [endLEVEL]
        if int(nourriture(1)) < 200 and version = 2 then notice " " + chr$(13) +  "You don't have enough food !" : goto [endLEVEL]
        if int(bois(1)) < 50 and version = 2 then notice " " + chr$(13) +  "You don't have enough wood !" : goto [endLEVEL]
        nourriture(1) = nourriture(1) - 200
        bois(1) = bois(1) - 50
        rechercheAcad(2) = 1 : goto [refreshAca]
    end if
    if p(xNEW,yNEW) = 15 and mXX > 15 and mXX <40 and mYY >430 and mYY <455 and rechercheAcad(3) = 0 then
        if version = 1 then confirm "Rechercher pour 140 de bois et 30 de minerais ?";rep$
        if version = 2 then confirm "Search for 140 wood and 30 ore?";rep$
        if rep$ = "no" then goto [endLEVEL]
        if int(bois(1)) < 140 and version = 1 then notice " " + chr$(13) +  "vous n'avez pas assez de bois !" : goto [endLEVEL]
        if int(minerais(1)) < 30 and version = 1 then notice " " + chr$(13) +  "vous n'avez pas assez de minerais !" : goto [endLEVEL]
        if int(bois(1)) < 140 and version = 2 then notice " " + chr$(13) +  "You don't have enough wood !" : goto [endLEVEL]
        if int(minerais(1)) < 30 and version = 2 then notice " " + chr$(13) +  "You don't have enough ores !" : goto [endLEVEL]
        bois(1) = bois(1) - 140
        minerais(1) = minerais(1) - 30
        rechercheAcad(3) = 1 : goto [refreshAca]
    end if
    if p(xNEW,yNEW) = 15 and mXX > 15 and mXX <40 and mYY >470 and mYY <495 and rechercheAcad(4) = 0 then
        if version = 1 then confirm "Rechercher pour 100 de nourriture ?";rep$
        if version = 2 then confirm "Search for 100 food ?";rep$
        if rep$ = "no" then goto [endLEVEL]
        if int(nourriture(1)) < 100 and version = 1 then notice " " + chr$(13) +  "vous n'avez pas assez de nourriture !" : goto [endLEVEL]
        if int(nourriture(1)) < 100 and version = 2 then notice " " + chr$(13) +  "You don't have enough food !" : goto [endLEVEL]
        nourriture(1) = nourriture(1) - 100
        for f = 1 to numSoldatP1
            if IDunitP1(f) = 3 then PVsoldatP1(f) = PVsoldatP1(f) + 2 : PvMAXsoldatP1(f) = PvMAXsoldatP1(f) + 2
        next f
        rechercheAcad(4) = 1 : goto [refreshAca]
    end if
    if p(xNEW,yNEW) = 15 and mXX > 15 and mXX <40 and mYY >510 and mYY <535 and rechercheAcad(5) = 0 then
        if version = 1 then confirm "Rechercher pour 400 de nourriture, 600 de bois et 150 de minerais ?";rep$
        if version = 2 then confirm "Search for 400 food, 600 wood and 150 ore?";rep$
        if rep$ = "no" then goto [endLEVEL]
        if int(nourriture(1)) < 400 and version = 1 then notice " " + chr$(13) +  "vous n'avez pas assez de nourriture !" : goto [endLEVEL]
        if int(bois(1)) < 600 and version = 1 then notice " " + chr$(13) +  "vous n'avez pas assez de bois !" : goto [endLEVEL]
        if int(minerais(1)) < 150 and version = 1 then notice " " + chr$(13) +  "vous n'avez pas assez de minerais !" : goto [endLEVEL]
        if int(nourriture(1)) < 400 and version = 2 then notice " " + chr$(13) +  "You don't have enough food !" : goto [endLEVEL]
        if int(bois(1)) < 600 and version = 2 then notice " " + chr$(13) +  "You don't have enough wood !" : goto [endLEVEL]
        if int(minerais(1)) < 150 and version = 2 then notice " " + chr$(13) +  "You don't have enough ores !" : goto [endLEVEL]
        nourriture(1) = nourriture(1) - 400
        bois(1) = bois(1) - 600
        minerais(1) = minerais(1) - 150
        popMAX(1) = popMAX(1) + 10
        rechercheAcad(5) = 1 : goto [refreshAca]
    end if
    if p(xNEW,yNEW) = 15 and mXX > 15 and mXX <40 and mYY >550 and mYY <575 and rechercheAcad(6) = 0 then
        if version = 1 then confirm "Rechercher pour 200 de bois et 60 de minerais ?";rep$
        if version = 2 then confirm "Search 200 wood and 60 ore?";rep$
        if rep$ = "no" then goto [endLEVEL]
        if int(bois(1)) < 200 and version = 1 then notice " " + chr$(13) +  "vous n'avez pas assez de bois !" : goto [endLEVEL]
        if int(minerais(1)) < 60 and version = 1 then notice " " + chr$(13) +  "vous n'avez pas assez de minerais !" : goto [endLEVEL]
        if int(bois(1)) < 200 and version = 2 then notice " " + chr$(13) +  "You don't have enough wood !" : goto [endLEVEL]
        if int(minerais(1)) < 60 and version = 2 then notice " " + chr$(13) +  "You don't have enough ores !" : goto [endLEVEL]
        bois(1) = bois(1) - 200
        minerais(1) = minerais(1) - 60
        for f = 1 to numSoldatP1
            if IDunitP1(f) = 9 then PVsoldatP1(f) = PVsoldatP1(f) + 100 : PvMAXsoldatP1(f) = PvMAXsoldatP1(f) + 100 : DEFvillage(f) = DEFvillage(f) + 1
        next f
        rechercheAcad(6) = 1 : goto [refreshAca]
    end if
    if p(xNEW,yNEW) = 15 and mXX > 15 and mXX <40 and mYY >590 and mYY <615 and rechercheAcad(7) = 0 then
        if version = 1 then confirm "Rechercher pour 150 de nourriture, 150 de bois et 150 de minerais ?";rep$
        if version = 2 then confirm "Search for 150 food, 150 wood and 150 ore?";rep$
        if rep$ = "no" then goto [endLEVEL]
        if int(nourriture(1)) < 150 and version = 1 then notice " " + chr$(13) +  "vous n'avez pas assez de nourriture !" : goto [endLEVEL]
        if int(bois(1)) < 150 and version = 1 then notice " " + chr$(13) +  "vous n'avez pas assez de bois !" : goto [endLEVEL]
        if int(minerais(1)) < 150 and version = 1 then notice " " + chr$(13) +  "vous n'avez pas assez de minerais !" : goto [endLEVEL]
        if int(nourriture(1)) < 150 and version = 2 then notice " " + chr$(13) +  "You don't have enough food !" : goto [endLEVEL]
        if int(bois(1)) < 150 and version = 2 then notice " " + chr$(13) +  "You don't have enough wood !" : goto [endLEVEL]
        if int(minerais(1)) < 150 and version = 2 then notice " " + chr$(13) +  "You don't have enough ores !" : goto [endLEVEL]
        nourriture(1) = nourriture(1) - 150
        bois(1) = bois(1) - 150
        minerais(1) = minerais(1) - 150
        rechercheAcad(7) = 1 : goto [refreshAca]
    end if
    if p(xNEW,yNEW) = 15 and mXX > 15 and mXX <40 and mYY >630 and mYY <655 and rechercheAcad(8) = 0 then
        if version = 1 then confirm "Rechercher pour 70 de bois et 25 de minerais ?";rep$
        if version = 2 then confirm "Search for 70 wood and 25 ore?";rep$
        if rep$ = "no" then goto [endLEVEL]
        if int(bois(1)) < 70 and version = 1 then notice " " + chr$(13) +  "vous n'avez pas assez de bois !" : goto [endLEVEL]
        if int(minerais(1)) < 25 and version = 1 then notice " " + chr$(13) +  "vous n'avez pas assez de minerais !" : goto [endLEVEL]
        if int(bois(1)) < 70 and version = 2 then notice " " + chr$(13) +  "You don't have enough wood !" : goto [endLEVEL]
        if int(minerais(1)) < 25 and version = 2 then notice " " + chr$(13) +  "You don't have enough ores !" : goto [endLEVEL]
        bois(1) = bois(1) - 70
        minerais(1) = minerais(1) - 25
        for f = 1 to numSoldatP1
            if IDunitP1(f) = 4 then PVsoldatP1(f) = PVsoldatP1(f) + 10 : PvMAXsoldatP1(f) = PvMAXsoldatP1(f) + 10
        next f
        rechercheAcad(8) = 1 : goto [refreshAca]
    end if
    if p(xNEW,yNEW) = 15 and mXX > 15 and mXX <40 and mYY >670 and mYY <695 and rechercheAcad(9) = 0 then
        if version = 1 then confirm "Rechercher pour 200 de bois et 100 de minerais ?";rep$
        if version = 2 then confirm "Search for 200 wood and 100 ore?";rep$
        if rep$ = "no" then goto [endLEVEL]
        if int(bois(1)) < 200 and version = 1 then notice " " + chr$(13) +  "vous n'avez pas assez de bois !" : goto [endLEVEL]
        if int(minerais(1)) < 100 and version = 1 then notice " " + chr$(13) +  "vous n'avez pas assez de minerais !" : goto [endLEVEL]
        if int(bois(1)) < 200 and version = 2 then notice " " + chr$(13) +  "You don't have enough wood !" : goto [endLEVEL]
        if int(minerais(1)) < 100 and version = 2 then notice " " + chr$(13) +  "You don't have enough ores !" : goto [endLEVEL]
        bois(1) = bois(1) - 200
        minerais(1) = minerais(1) - 100
        for f = 1 to numSoldatP1
            if IDunitP1(f) = 4 then DEFtour(f) = DEFtour(f) + 1
            if IDunitP1(f) = 6 then DEFcamp(f) = DEFcamp(f) + 1
            if IDunitP1(f) = 7 then DEFferme(f) = DEFferme(f) + 1
            if IDunitP1(f) = 8 then DEFacademie(f) = DEFacademie(f) + 1
            if IDunitP1(f) = 9 then DEFvillage(f) = DEFvillage(f) + 1
        next f
        rechercheAcad(9) = 1 : goto [refreshAca]
    end if

    if mXX > 36 and mXX <62 and mYY >150 and mYY <175 and p(xNEW,yNEW) = 2 then
        if version = 1 then txt$ = "Votre bâtiment est en parfait état." : condition = 0
        if version = 2 then txt$ = "Your building is in perfect condition." : condition = 0
        for t = 1 to numSoldatP1
            if IDunitP1(t) = 9 and PVsoldatP1(t) < PvMAXsoldatP1(t) and version = 1 then txt$ = "Voulez-vous faire les réparations de votre village pour ";PvMAXsoldatP1(t)-PVsoldatP1(t);" de bois ?" : condition = 1 : regenID = t
            if IDunitP1(t) = 9 and PVsoldatP1(t) < PvMAXsoldatP1(t) and version = 2 then txt$ = "Do you want to do the repairs of your village for ";PvMAXsoldatP1(t)-PVsoldatP1(t);" wood ?" : condition = 1 : regenID = t
        next t
        if condition = 0 then notice " " + chr$(13) +  txt$ : wait
        if condition = 1 then confirm txt$;rep$
        if rep$ = "no" then goto [endLEVEL]
        if int(bois(1)) < int(PvMAXsoldatP1(regenID)-PVsoldatP1(regenID)) and version = 1 then notice " " + chr$(13) +  "Vous n'avez pas assez de bois pour lancer les réparations !" : goto [endLEVEL]
        if int(bois(1)) < int(PvMAXsoldatP1(regenID)-PVsoldatP1(regenID)) and version = 2 then notice " " + chr$(13) +  "You don't have enough wood to start repairs!" : goto [endLEVEL]
        bois(1) = int(bois(1)) - int(PvMAXsoldatP1(regenID)-PVsoldatP1(regenID))
        PVsoldatP1(regenID) = PvMAXsoldatP1(regenID)
    end if
    if mXX > 36 and mXX <62 and mYY >150 and mYY <175 and p(xNEW,yNEW) = 15 then
        if version = 1 then txt$ = "Votre bâtiment est en parfait état." : condition = 0
        if version = 2 then txt$ = "Your building is in perfect condition." : condition = 0
        for t = 1 to numSoldatP1
            if IDunitP1(t) = 8 and PvAcademie(t) < PvMaxAcademie(t) and version = 1 then txt$ = "Voulez-vous faire les réparations de votre village pour ";PvMaxAcademie(t)-PvAcademie(t);" de bois ?" : condition = 1 : regenID = t
            if IDunitP1(t) = 8 and PvAcademie(t) < PvMaxAcademie(t) and version = 2 then txt$ = "Do you want to do the repairs of your village for ";PvMaxAcademie(t)-PvAcademie(t);" wood ?" : condition = 1 : regenID = t
        next t
        if condition = 0 then notice " " + chr$(13) +  txt$ : wait
        if condition = 1 then confirm txt$;rep$
        if rep$ = "no" then goto [endLEVEL]
        if int(bois(1)) < int(PvMaxAcademie(regenID)-PvAcademie(regenID)) and version = 1 then notice " " + chr$(13) +  "Vous n'avez pas assez de bois pour lancer les réparations !" : goto [endLEVEL]
        if int(bois(1)) < int(PvMaxAcademie(regenID)-PvAcademie(regenID)) and version = 2 then notice " " + chr$(13) +  "You don't have enough wood to start repairs!" : goto [endLEVEL]
        bois(1) = int(bois(1)) - int(PvMaxAcademie(regenID)-PvAcademie(regenID))
        PvAcademie(regenID) = PvMaxAcademie(regenID)
    end if
    if mXX > 36 and mXX <62 and mYY >150 and mYY <175 and p(xNEW,yNEW) = 14 then
        if version = 1 then txt$ = "Votre bâtiment est en parfait état." : condition = 0
        if version = 2 then txt$ = "Your building is in perfect condition." : condition = 0
        for t = 1 to numSoldatP1
            if IDunitP1(t) = 6 and PvCamp(t) < PvMaxCamp(t) and version = 1 then txt$ = "Voulez-vous faire les réparations de votre village pour ";PvMaxCamp(t)-PvCamp(t);" de bois ?" : condition = 1 : regenID = t
            if IDunitP1(t) = 6 and PvCamp(t) < PvMaxCamp(t) and version = 2 then txt$ = "Do you want to do the repairs of your village for ";PvMaxCamp(t)-PvCamp(t);" wood ?" : condition = 1 : regenID = t
        next t
        if condition = 0 then notice " " + chr$(13) +  txt$ : wait
        if condition = 1 then confirm txt$;rep$
        if rep$ = "no" then goto [endLEVEL]
        if int(bois(1)) < int(PvMaxCamp(regenID)-PvCamp(regenID)) and version = 1 then notice " " + chr$(13) +  "Vous n'avez pas assez de bois pour lancer les réparations !" : goto [endLEVEL]
        if int(bois(1)) < int(PvMaxCamp(regenID)-PvCamp(regenID)) and version = 2 then notice " " + chr$(13) +  "You don't have enough wood to start repairs!" : goto [endLEVEL]
        bois(1) = int(bois(1)) - int(PvMaxCamp(regenID)-PvCamp(regenID))
        PvCamp(regenID) = PvMaxCamp(regenID)
    end if
    if mXX > 36 and mXX <62 and mYY >150 and mYY <175 and p(xNEW,yNEW) = 1 then
        if version = 1 then txt$ = "Votre bâtiment est en parfait état." : condition = 0
        if version = 2 then txt$ = "Your building is in perfect condition." : condition = 0
        for t = 1 to numSoldatP1
            if IDunitP1(t) = 7 and c(xNEW,yNEW) = localisationFermage(t) and PvFerme(t) < PvFermeMAX(t) and version = 1 then txt$ = "Voulez-vous faire les réparations de votre village pour ";PvFermeMAX(t)-PvFerme(t);" de bois ?" : condition = 1 : regenID = t
            if IDunitP1(t) = 7 and c(xNEW,yNEW) = localisationFermage(t) and PvFerme(t) < PvFermeMAX(t) and version = 2 then txt$ = "Do you want to do the repairs of your village for ";PvFermeMAX(t)-PvFerme(t);" wood ?" : condition = 1 : regenID = t
        next t
        if condition = 0 then notice " " + chr$(13) +  txt$ : wait
        if condition = 1 then confirm txt$;rep$
        if rep$ = "no" then goto [endLEVEL]
        if int(bois(1)) < int(PvFermeMAX(regenID)-PvFerme(regenID)) and version = 1 then notice " " + chr$(13) +  "Vous n'avez pas assez de bois pour lancer les réparations !" : goto [endLEVEL]
        if int(bois(1)) < int(PvFermeMAX(regenID)-PvFerme(regenID)) and version = 2 then notice " " + chr$(13) +  "You don't have enough wood to start repairs!" : goto [endLEVEL]
        bois(1) = int(bois(1)) - int(PvFermeMAX(regenID)-PvFerme(regenID))
        PvFerme(regenID) = PvFermeMAX(regenID)
    end if
    if mXX > 36 and mXX <62 and mYY >150 and mYY <175 and p(xNEW,yNEW) = 13 then
        if version = 1 then txt$ = "Votre bâtiment est en parfait état." : condition = 0
        if version = 2 then txt$ = "Your building is in perfect condition." : condition = 0
        for t = 1 to numSoldatP1
            if IDunitP1(t) = 4 and c(xNEW,yNEW) = localisationTower(t) and PVsoldatP1(t) < PvMAXsoldatP1(t) and version = 1 then txt$ = "Voulez-vous faire les réparations de votre village pour ";PvMAXsoldatP1(t)-PVsoldatP1(t);" de bois ?" : condition = 1 : regenID = t
            if IDunitP1(t) = 4 and c(xNEW,yNEW) = localisationTower(t) and PVsoldatP1(t) < PvMAXsoldatP1(t) and version = 2 then txt$ = "Do you want to do the repairs of your village for ";PvMAXsoldatP1(t)-PVsoldatP1(t);" wood ?" : condition = 1 : regenID = t
        next t
        if condition = 0 then notice " " + chr$(13) +  txt$ : wait
        if condition = 1 then confirm txt$;rep$
        if rep$ = "no" then goto [endLEVEL]
        if int(bois(1)) < int(PvMAXsoldatP1(regenID)-PVsoldatP1(regenID)) and version = 1 then notice " " + chr$(13) +  "Vous n'avez pas assez de bois pour lancer les réparations !" : goto [endLEVEL]
        if int(bois(1)) < int(PvMAXsoldatP1(regenID)-PVsoldatP1(regenID)) and version = 2 then notice " " + chr$(13) +  "You don't have enough wood to start repairs!" : goto [endLEVEL]
        bois(1) = int(bois(1)) - int(PvMAXsoldatP1(regenID)-PVsoldatP1(regenID))
        PVsoldatP1(regenID) = PvMAXsoldatP1(regenID)
    end if

    if mXX > 210 and mXX <236 and mYY >150 and mYY <175 and p(xNEW,yNEW) = 13 then
        if version = 1 then txt$ = "Voulez-vous détruire ce bâtiment ?"
        if version = 2 then txt$ = "Do you want to destroy this building?"
        confirm txt$;rep$
        if rep$ = "no" then goto [endLEVEL]
        for t = 1 to numSoldatP1
            if IDunitP1(t) = 4 and c(xNEW,yNEW) = localisationTower(t) then
                IDtour(t) = 0
                IDtourX(t) = 0
                IDtourY(t) = 0
                POSxTOWER(t) = 0
                POSyTOWER(t) = 0
                PVsoldatP1(t) = 0
                PvMAXsoldatP1(t) = 0
                localisationTower(t) = 0
                DEFtour(t) = 0
                ATKtour(t) = 0
            end if
        next t
        p(xNEW,yNEW) = 0 : IDconstruction = 0 : moovingActivation = 2 : ConstructionTour = ConstructionTour - 1
        print #main.map2, "cls"
    end if
    if mXX > 210 and mXX <236 and mYY >150 and mYY <175 and p(xNEW,yNEW) = 1 then
        if version = 1 then txt$ = "Voulez-vous détruire ce bâtiment ?"
        if version = 2 then txt$ = "Do you want to destroy this building?"
        confirm txt$;rep$
        if rep$ = "no" then goto [endLEVEL]
        for t = 1 to numSoldatP1
            if IDunitP1(t) = 7 and c(xNEW,yNEW) = localisationFermage(t) then
                localisationFermage(t) = 0
                nourritureRestante(t) = 0
                IDfermeX(t) = 0
                IDfermeY(t) = 0
                POSxFerme(t) = 0
                POSyFerme(t) = 0
                PvFerme(t) = 0
                PvFermeMAX(t) = 0
                DEFferme(t) = 0
            end if
        next t
        p(xNEW,yNEW) = 0 : IDconstruction = 0 : moovingActivation = 2 : ConstructionFerme = ConstructionFerme - 1
        if ConstructionFerme < 0 then ConstructionFerme = 0
        print #main.map2, "cls"
    end if
    if mXX > 210 and mXX <236 and mYY >150 and mYY <175 and p(xNEW,yNEW) = 15 then
        if version = 1 then txt$ = "Voulez-vous détruire ce bâtiment ?"
        if version = 2 then txt$ = "Do you want to destroy this building?"
        confirm txt$;rep$
        if rep$ = "no" then goto [endLEVEL]
        ConstructionAcademie = 0
        for t = 1 to numSoldatP1
            if IDunitP1(t) = 8 then PvAcademie(t) = 0 : PvMaxAcademie(t) = 0
        next t
        p(xNEW,yNEW) = 0 : IDconstruction = 0 : moovingActivation = 2
        print #main.map2, "cls"
    end if
    if mXX > 210 and mXX <236 and mYY >150 and mYY <175 and p(xNEW,yNEW) = 14 then
        if version = 1 then txt$ = "Voulez-vous détruire ce bâtiment ?"
        if version = 2 then txt$ = "Do you want to destroy this building?"
        confirm txt$;rep$
        if rep$ = "no" then goto [endLEVEL]
        ConstructionCamp = 0
        for t = 1 to numSoldatP1
            if IDunitP1(t) = 6 then PvCamp(t) = 0 : PvMaxCamp(t) = 0
        next t
        p(xNEW,yNEW) = 0 : IDconstruction = 0 : moovingActivation = 2
        print #main.map2, "cls"
    end if


    if unlockACHATunit = 1 and mXX > 200 and mXX <255 and mYY >530 and mYY <570 then
        if version = 1 and nourriture(1) < peonCOST then notice " " + chr$(13) +  "vous n'avez pas assez de nourriture !" : goto [endLEVEL]
        if version = 1 and pop(1) >= popMAX(1) then notice " " + chr$(13) +  "Vous n'avez plus de place disponible. Vous devez développer les logements de votre village." : goto [endLEVEL]
        if version = 2 and nourriture(1) < peonCOST then notice " " + chr$(13) +  "You don't have enough food!" : goto [endLEVEL]
        if version = 2 and pop(1) >= popMAX(1) then notice " " + chr$(13) +  "You have no more space available. You need to develop the housing in your village." : goto [endLEVEL]
        nourriture(1) = nourriture(1) - peonCOST
        nombrePeon(1) = nombrePeon(1) + 1
        pop(1) = pop(1) + 1
        numSoldatP1 = numSoldatP1+1
        IDunitP1(numSoldatP1) = 3
        POSxSOLDATp1(numSoldatP1) = int(rnd(1)*24 +(IDvillageX(1)*96-48))
        POSySOLDATp1(numSoldatP1) = int(rnd(1)*24 +(IDvillageY(1)*96+24))
        PVsoldatP1(numSoldatP1) = 4 : if rechercheAcad(4) = 1 then PVsoldatP1(numSoldatP1) = PVsoldatP1(numSoldatP1) + 2
        PvMAXsoldatP1(numSoldatP1) = PVsoldatP1(numSoldatP1)
        ATKsoldatP1(numSoldatP1) = 2
        DEFsoldatP1(numSoldatP1) = 0
        xpPEON(numSoldatP1) = 0
        xpTotalPEON(numSoldatP1) = 5
        lvlPEON(numSoldatP1) = 1
        reloadTime(numSoldatP1) = 15
        targetBattle(numSoldatP1) = 0
        print #main.map,"addsprite peon";numSoldatP1;" perso1; spritexy peon";numSoldatP1;" ";POSxSOLDATp1(numSoldatP1);" ";POSySOLDATp1(numSoldatP1);"; SpriteVisible peon";numSoldatP1;" on; spritetofront peon";numSoldatP1
    end if
    if AchatUnitMode = 1 and mXX > 200 and mXX <255 and mYY >400 and mYY <445 then
        if version = 1 and  nourriture(1) < costValorHommeArme1 then notice " " + chr$(13) +  "vous n'avez pas assez de nourriture !" : goto [endLEVEL]
        if version = 1 and  bois(1) < costValorHommeArme2 then notice " " + chr$(13) +  "vous n'avez pas assez de bois !" : goto [endLEVEL]
        if version = 1 and  minerais(1) < costValorHommeArme3 then notice " " + chr$(13) +  "vous n'avez pas assez de minerais !" : goto [endLEVEL]
        if version = 1 and  pop(1) >= popMAX(1) then notice " " + chr$(13) +  "Vous n'avez plus de place disponible. Vous devez développer les logements de votre village." : goto [endLEVEL]
        if version = 2 and  nourriture(1) < costValorHommeArme1 then notice " " + chr$(13) +  "You don't have enough food!" : goto [endLEVEL]
        if version = 2 and  bois(1) < costValorHommeArme2 then notice " " + chr$(13) +  "You don't have enough wood!" : goto [endLEVEL]
        if version = 2 and  minerais(1) < costValorHommeArme3 then notice " " + chr$(13) +  "You don't have enough minerals!" : goto [endLEVEL]
        if version = 2 and  pop(1) >= popMAX(1) then notice " " + chr$(13) +  "You have no more space available. You need to develop the housing in your village." : goto [endLEVEL]
        nourriture(1) = nourriture(1) - costValorHommeArme1
        bois(1) = bois(1) - costValorHommeArme2
        minerais(1) = minerais(1) - costValorHommeArme3
        nombreSoldatA(1) = nombreSoldatA(1) + 1
        pop(1) = pop(1) + 1
        numSoldatP1 = numSoldatP1+1
        IDunitP1(numSoldatP1) = 1
        POSxSOLDATp1(numSoldatP1) = int(rnd(1)*96 +((CoorXcamps-0.5)*96))
        POSySOLDATp1(numSoldatP1) = int(rnd(1)*96 +((CoorYcamps-0.5)*96))
        PVsoldatP1(numSoldatP1) = 8 : PvMAXsoldatP1(numSoldatP1) = PVsoldatP1(numSoldatP1)
        ATKsoldatP1(numSoldatP1) = 3
        DEFsoldatP1(numSoldatP1) = 1
        XpSoldatP1(numSoldatP1) = 0
        XpTotalSoldatP1(numSoldatP1) = 5
        LvlSoldatP1(numSoldatP1) = 1
        reloadTime(numSoldatP1) = 8
        targetBattle(numSoldatP1) = 0
        print #main.map,"addsprite HommeDarme";numSoldatP1;" perso2; spritexy HommeDarme";numSoldatP1;" ";POSxSOLDATp1(numSoldatP1);" ";POSySOLDATp1(numSoldatP1);"; SpriteVisible HommeDarme";numSoldatP1;" on; spritetofront HommeDarme";numSoldatP1
        print #main.map2, "font Courier_New 9 bold; color black; backcolor white"
        if version = 1 then print #main.map2, "place 206 425 ;\"; "Former\\";nombreSoldatA(1)
        if version = 2 then print #main.map2, "place 206 425 ;\"; "Train\\";nombreSoldatA(1)
    end if
    if AchatUnitMode = 1 and mXX > 200 and mXX <255 and mYY >490 and mYY <535 then
        if version = 1 and nourriture(1) < costValorLancier1 then notice " " + chr$(13) +  "vous n'avez pas assez de nourriture !" : goto [endLEVEL]
        if version = 1 and bois(1) < costValorLancier2 then notice " " + chr$(13) +  "vous n'avez pas assez de bois !" : goto [endLEVEL]
        if version = 1 and minerais(1) < costValorLancier3 then notice " " + chr$(13) +  "vous n'avez pas assez de minerais !" : goto [endLEVEL]
        if version = 1 and pop(1) >= popMAX(1) then notice " " + chr$(13) +  "Vous n'avez plus de place disponible. Vous devez développer les logements de votre village." : goto [endLEVEL]
        if version = 2 and nourriture(1) < costValorLancier1 then notice " " + chr$(13) +  "You don't have enough food!" : goto [endLEVEL]
        if version = 2 and bois(1) < costValorLancier2 then notice " " + chr$(13) +  "You don't have enough wood!" : goto [endLEVEL]
        if version = 2 and minerais(1) < costValorLancier3 then notice " " + chr$(13) +  "You don't have enough minerals!" : goto [endLEVEL]
        if version = 2 and pop(1) >= popMAX(1) then notice " " + chr$(13) +  "You have no more space available. You need to develop the housing in your village." : goto [endLEVEL]
        nourriture(1) = nourriture(1) - costValorLancier1
        bois(1) = bois(1) - costValorLancier2
        minerais(1) = minerais(1) - costValorLancier3
        nombreSoldatB(1) = nombreSoldatB(1) + 1
        pop(1) = pop(1) + 1
        numSoldatP1 = numSoldatP1+1
        IDunitP1(numSoldatP1) = 2
        POSxSOLDATp1(numSoldatP1) = int(rnd(1)*96 +((CoorXcamps-0.5)*96))
        POSySOLDATp1(numSoldatP1) = int(rnd(1)*96 +((CoorYcamps-0.5)*96))
        PVsoldatP1(numSoldatP1) = 5 : PvMAXsoldatP1(numSoldatP1) = PVsoldatP1(numSoldatP1)
        ATKsoldatP1(numSoldatP1) = 5
        DEFsoldatP1(numSoldatP1) = 2
        XpSoldatP1(numSoldatP1) = 0
        XpTotalSoldatP1(numSoldatP1) = 4
        LvlSoldatP1(numSoldatP1) = 1
        reloadTime(numSoldatP1) = 10
        targetBattle(numSoldatP1) = 0
        print #main.map,"addsprite Lancier";numSoldatP1;" perso3; spritexy Lancier";numSoldatP1;" ";POSxSOLDATp1(numSoldatP1);" ";POSySOLDATp1(numSoldatP1);"; SpriteVisible Lancier";numSoldatP1;" on; spritetofront Lancier";numSoldatP1
        print #main.map2, "font Courier_New 9 bold; color black; backcolor white"
        if version = 1 then print #main.map2, "place 206 515 ;\"; "Former\\";nombreSoldatB(1)
        if version = 2 then print #main.map2, "place 206 515 ;\"; "Train\\";nombreSoldatB(1)
    end if

    '----------upgrade village lvl 1 to 2
    if lvlVILLE(1) = 1 and mXX > 35 and mXX <65 and mYY >415 and mYY <455 and menuCONSTRUCTION = 0 and  unlockACHATunit = 1 then
        if version = 1 then confirm " " + chr$(13) +"Augmenter le nombre de logement de +1 pour 40 de bois ?";confirm$
        if version = 2 then confirm " " + chr$(13) +"Increase the number of housing by +1 for 40 wood?";confirm$
        if confirm$ = "no" then goto [endLEVEL]
        if version = 1 and bois(1) < 40 then notice " " + chr$(13) +  "Vous n'avez pas assez de bois pour cela !" : goto [endLEVEL]
        if version = 2 and bois(1) < 40 then notice " " + chr$(13) +  "You don't have enough wood for that!" : goto [endLEVEL]
        bois(1) = int(bois(1) - 40) : upgradeVILLE(1) = upgradeVILLE(1) + 1 : popMAX(1) = popMAX(1) + 1 : recherche(1) = 1
        gosub [upgradeCITY] : goto [endRechearch]
    end if
    if lvlVILLE(1) = 1 and mXX > 90 and mXX <120 and mYY >415 and mYY <455 and menuCONSTRUCTION = 0 and  unlockACHATunit = 1 then
        if version = 1 then confirm " " + chr$(13) +"Augmenter le nombre de logement de +2 pour 100 de bois ?";confirm$
        if version = 2 then confirm " " + chr$(13) +"Increase the number of housing by +2 for 100 wood?";confirm$
        if confirm$ = "no" then goto [endLEVEL]
        if version = 1 and bois(1) < 100 then notice " " + chr$(13) +  "Vous n'avez pas assez de bois pour cela !" : goto [endLEVEL]
        if version = 2 and bois(1) < 100 then notice " " + chr$(13) +  "You don't have enough wood for that!" : goto [endLEVEL]
        bois(1) = int(bois(1) - 100) : upgradeVILLE(1) = upgradeVILLE(1) + 1 : popMAX(1) = popMAX(1) + 2 : recherche(2) = 1
        gosub [upgradeCITY] : goto [endRechearch]
    end if
    if lvlVILLE(1) = 1 and mXX > 145 and mXX <175 and mYY >415 and mYY <455 and menuCONSTRUCTION = 0 and  unlockACHATunit = 1 then
        if version = 1 then confirm " " + chr$(13) +"Renforcer les défenses du village de +20 pour 60 de bois ?";confirm$
        if version = 2 then confirm " " + chr$(13) +"Reinforce the village defenses by +20 for 60 wood?";confirm$
        if confirm$ = "no" then goto [endLEVEL]
        if version = 1 and bois(1) < 60 then notice " " + chr$(13) +  "Vous n'avez pas assez de bois pour cela !" : goto [endLEVEL]
        if version = 2 and bois(1) < 60 then notice " " + chr$(13) +  "You don't have enough wood for that!" : goto [endLEVEL]
        bois(1) = int(bois(1) - 60) : upgradeVILLE(1) = upgradeVILLE(1) + 1 : recherche(3) = 1
        for t = 1 to numSoldatP1
            if IDunitP1(t) = 9 then PVsoldatP1(t) = PVsoldatP1(t) + 20 : PvMAXsoldatP1(t) = PvMAXsoldatP1(t) + 20
        next t
        gosub [upgradeCITY] : goto [endRechearch]
    end if
    if lvlVILLE(1) = 1 and mXX > 195 and mXX <225 and mYY >415 and mYY <455 and menuCONSTRUCTION = 0 and  unlockACHATunit = 1 then
        if version = 1 then confirm " " + chr$(13) +"Augmenter le nombre de logement de +3 pour 150 de bois ?";confirm$
        if version = 2 then confirm " " + chr$(13) +"Increase the number of housing by +3 for 150 wood?";confirm$
        if confirm$ = "no" then goto [endLEVEL]
        if version = 1 and bois(1) < 150 then notice " " + chr$(13) +  "Vous n'avez pas assez de bois pour cela !" : goto [endLEVEL]
        if version = 2 and bois(1) < 150 then notice " " + chr$(13) +  "You don't have enough wood for that!" : goto [endLEVEL]
        bois(1) = int(bois(1) - 150) : upgradeVILLE(1) = upgradeVILLE(1) + 1 : popMAX(1) = popMAX(1) + 3 : recherche(4) = 1
        gosub [upgradeCITY] : goto [endRechearch]
    end if
    '----------upgrade village lvl 2 to 3
    if lvlVILLE(1) = 2 and mXX > 35 and mXX <65 and mYY >415 and mYY <455 and menuCONSTRUCTION = 0 and  unlockACHATunit = 1 then
        if version = 1 then confirm " " + chr$(13) +"Renforcer les défenses du village de +10 pour 40 de bois ?";confirm$
        if version = 2 then confirm " " + chr$(13) +"Reinforce the village defenses by +10 for 40 wood?";confirm$
        if confirm$ = "no" then goto [endLEVEL]
        if version = 1 and bois(1) < 40 then notice " " + chr$(13) +  "Vous n'avez pas assez de bois pour cela !" : goto [endLEVEL]
        if version = 2 and bois(1) < 40 then notice " " + chr$(13) +  "You don't have enough wood for that!" : goto [endLEVEL]
        bois(1) = int(bois(1) - 40) : upgradeVILLE(1) = upgradeVILLE(1) + 1 : recherche(1) = 1
        for t = 1 to numSoldatP1
            if IDunitP1(t) = 9 then PVsoldatP1(t) = PVsoldatP1(t) + 10 : PvMAXsoldatP1(t) = PvMAXsoldatP1(t) + 10
        next t
        gosub [upgradeCITY] : goto [endRechearch]
    end if
    if lvlVILLE(1) = 2 and mXX > 90 and mXX <120 and mYY >415 and mYY <455 and menuCONSTRUCTION = 0 and  unlockACHATunit = 1 then
        if version = 1 then confirm " " + chr$(13) +"Renforcer les défenses du village de +20 pour 70 de bois ?";confirm$
        if version = 2 then confirm " " + chr$(13) +"Reinforce the village defenses by +20 for 70 wood?";confirm$
        if confirm$ = "no" then goto [endLEVEL]
        if version = 1 and bois(1) < 70 then notice " " + chr$(13) +  "Vous n'avez pas assez de bois pour cela !" : goto [endLEVEL]
        if version = 2 and bois(1) < 70 then notice " " + chr$(13) +  "You don't have enough wood for that!" : goto [endLEVEL]
        bois(1) = int(bois(1) - 50) : upgradeVILLE(1) = upgradeVILLE(1) + 1 : recherche(2) = 1
        for t = 1 to numSoldatP1
            if IDunitP1(t) = 9 then PVsoldatP1(t) = PVsoldatP1(t) + 20 : PvMAXsoldatP1(t) = PvMAXsoldatP1(t) + 20
        next t
        gosub [upgradeCITY] : goto [endRechearch]
    end if
    if lvlVILLE(1) = 2 and mXX > 145 and mXX <175 and mYY >415 and mYY <455 and menuCONSTRUCTION = 0 and  unlockACHATunit = 1 then
        if version = 1 then confirm " " + chr$(13) +"Renforcer les défenses du village de +40 pour 250 de bois ?";confirm$
        if version = 2 then confirm " " + chr$(13) +"Reinforce the village defenses by +40 for 250 wood?";confirm$
        if confirm$ = "no" then goto [endLEVEL]
        if version = 1 and bois(1) < 250 then notice " " + chr$(13) +  "Vous n'avez pas assez de bois pour cela !" : goto [endLEVEL]
        if version = 2 and bois(1) < 250 then notice " " + chr$(13) +  "You don't have enough wood for that!" : goto [endLEVEL]
        bois(1) = int(bois(1) - 250) : upgradeVILLE(1) = upgradeVILLE(1) + 1 : recherche(3) = 1
        for t = 1 to numSoldatP1
            if IDunitP1(t) = 9 then PVsoldatP1(t) = PVsoldatP1(t) + 40 : PvMAXsoldatP1(t) = PvMAXsoldatP1(t) + 40
        next t
        gosub [upgradeCITY] : goto [endRechearch]
    end if
    if lvlVILLE(1) = 2 and mXX > 195 and mXX <225 and mYY >415 and mYY <455 and menuCONSTRUCTION = 0 and  unlockACHATunit = 1 then
        if version = 1 then confirm " " + chr$(13) +"Renforcer les défenses du village de +20 pour 110 de bois ?";confirm$
        if version = 2 then confirm " " + chr$(13) +"Reinforce the village defenses by +20 for 110 wood?";confirm$
        if confirm$ = "no" then goto [endLEVEL]
        if version = 1 and bois(1) < 110 then notice " " + chr$(13) +  "Vous n'avez pas assez de bois pour cela !" : goto [endLEVEL]
        if version = 2 and bois(1) < 110 then notice " " + chr$(13) +  "You don't have enough wood for that!" : goto [endLEVEL]
        bois(1) = int(bois(1) - 110) : upgradeVILLE(1) = upgradeVILLE(1) + 1 : recherche(4) = 1
        for t = 1 to numSoldatP1
            if IDunitP1(t) = 9 then PVsoldatP1(t) = PVsoldatP1(t) + 20 : PvMAXsoldatP1(t) = PvMAXsoldatP1(t) + 20
        next t
        gosub [upgradeCITY] : goto [endRechearch]
    end if
    '-----------------------------------------------------------------------------------------
    [endRechearch]
    IDconstruction = 0
    if unlockACHATunit = 1 then goto [positionINI]
    if AchatUnitMode = 0 and menuCONSTRUCTION = 1 then print #main.map2, "size 3; color white" : print #main.map2, "line "; 14; " "; 250; " "; 14; " "; 740 : print #main.map2, "line "; 255; " "; 250; " "; 255; " "; 740
    if menuCONSTRUCTION = 1 and mXX > 25 and mXX <245 and mYY >250 and mYY <340 then IDconstruction = 1 : print #main.map2, "color darkgreen" : print #main.map2, "line "; 14; " "; 250; " "; 14; " "; 340 : print #main.map2, "line "; 255; " "; 250; " "; 255; " "; 340
    if menuCONSTRUCTION = 1 and mXX > 25 and mXX <245 and mYY >350 and mYY <440 then IDconstruction = 2 : print #main.map2, "color darkgreen" : print #main.map2, "line "; 14; " "; 350; " "; 14; " "; 440 : print #main.map2, "line "; 255; " "; 350; " "; 255; " "; 440
    if menuCONSTRUCTION = 1 and mXX > 25 and mXX <245 and mYY >450 and mYY <540 then IDconstruction = 3 : print #main.map2, "color darkgreen" : print #main.map2, "line "; 14; " "; 450; " "; 14; " "; 540 : print #main.map2, "line "; 255; " "; 450; " "; 255; " "; 540
    if menuCONSTRUCTION = 1 and mXX > 25 and mXX <245 and mYY >550 and mYY <640 then IDconstruction = 4 : print #main.map2, "color darkgreen" : print #main.map2, "line "; 14; " "; 550; " "; 14; " "; 640 : print #main.map2, "line "; 255; " "; 550; " "; 255; " "; 640
    goto [endLEVEL]

    [upgradeCITY]
    if (upgradeVILLE(1) = 4 or upgradeVILLE(1) = 8) then
        ConstructionFermeMax = ConstructionFermeMax + 1 : ConstructionTourMax = ConstructionTourMax + 2 : lvlVILLE(1) = lvlVILLE(1) + 1 : recherche(1) = 0 : recherche(2) = 0 : recherche(3) = 0 : recherche(4) = 0
        limiteBois(1) = limiteBois(1) + 2 : limiteMines(1) = limiteMines(1) + 1
        for t = 1 to numSoldatP1
            if IDunitP1(t) = 9 then PVsoldatP1(t) = PVsoldatP1(t) + 40 : PvMAXsoldatP1(t) = PvMAXsoldatP1(t) + 40
        next t
    end if
    return

    [moovingXY]
    moovingActivation = 1
    if MouseY < MouseYini-2 then
        dy = -1
        if showFPS >=80 then valIniY = valIniY+(1*dy)*0.1
        if showFPS <80 and showFPS >40 then valIniY = valIniY+(1*dy)*0.15
        if showFPS <= 40 then valIniY = valIniY+(1*dy)*0.25
        if valIniY < 0 then valIniY = 0
    end if
    if MouseY > MouseYini+2 then
        dy = 1
        if showFPS >=80 then valIniY = valIniY+(1*dy)*0.1
        if showFPS <80 and showFPS >40 then valIniY = valIniY+(1*dy)*0.15
        if showFPS <= 40 then valIniY = valIniY+(1*dy)*0.25
        if valIniY > 20 then valIniY = 20
    end if
    if MouseX < MouseXini-2 then
        dx = -1
        if showFPS >=80 then valIniX = valIniX+dx*0.1
        if showFPS <80 and showFPS >40 then valIniX = valIniX+dx*0.15
        if showFPS <= 40 then valIniX = valIniX+dx*0.25
        if valIniX < 0 then valIniX = 0
    end if
    if MouseX > MouseXini+2 then
        dx = 1
        if showFPS >=80 then valIniX = valIniX+dx*0.1
        if showFPS <80 and showFPS >40 then valIniX = valIniX+dx*0.15
        if showFPS <= 40 then valIniX = valIniX+dx*0.25
        if valIniX > 21 then valIniX = 21
    end if
    goto [endLEVEL]


    [AIunitVIEW]
        noRESSOURCEshow = 1
        print #main.map2, "cls"
        print #main.map2, "font Courier_New 12 bold; color black; backcolor white"
        if version = 1 then
            if IDunitP2(soldat2VIEW) = 1 then print #main.map2, "drawbmp soldat1 36 100" : print #main.map2, "place 36 70 ;\"; "(AI) Fantassin"
            if IDunitP2(soldat2VIEW) = 2 then print #main.map2, "drawbmp soldat2 36 100" : print #main.map2, "place 36 70 ;\"; "(AI) Lancier"
            print #main.map2, "font Courier_New 11"
            print #main.map2, "place 15 180 ;\"; "Attaque : ";ATKsoldatP2(soldat2VIEW)
            print #main.map2, "place 15 195 ;\"; "Armure : ";DEFsoldatP2(soldat2VIEW)
            print #main.map2, "place 15 210 ;\"; "Vitesse d'attaque : ";50
            print #main.map2, "place 80 110 ;\"; "Santé : ";PVsoldatP2(soldat2VIEW); "/" ;PVMAXsoldatP2(soldat2VIEW)
        end if
        if version = 2 then
            if IDunitP2(soldat2VIEW) = 1 then print #main.map2, "drawbmp soldat1 36 100" : print #main.map2, "place 36 70 ;\"; "(AI) Infantryman"
            if IDunitP2(soldat2VIEW) = 2 then print #main.map2, "drawbmp soldat2 36 100" : print #main.map2, "place 36 70 ;\"; "(AI) Lancier"
            print #main.map2, "font Courier_New 11"
            print #main.map2, "place 15 180 ;\"; "Attack : ";ATKsoldatP2(soldat2VIEW)
            print #main.map2, "place 15 195 ;\"; "Armor : ";DEFsoldatP2(soldat2VIEW)
            print #main.map2, "place 15 210 ;\"; "Attack speed : ";50
            print #main.map2, "place 80 110 ;\"; "Health : ";PVsoldatP2(soldat2VIEW); "/" ;PVMAXsoldatP2(soldat2VIEW)
        end if
    goto [endLEVEL]

    ' ------------------------

    [selectXY]
    mX = MouseX-10 : mY = MouseY : menuCONSTRUCTION = 0 :  SelectedArmy0 = 0 : SelectedArmy1 = 0 : SelectedArmy2 = 0 : IDconstruction = 0

    for p = 1 to numSoldatP2
        if IDunitP2(p) = 1 then
            if (int((((POSxSOLDATp2(p)/96)-valIniX)*96)+80) >= mX1 and int((((POSxSOLDATp2(p)/96)-valIniX)*96)+80) <= mX and int((((POSySOLDATp2(p)/96)-valIniY)*96)+80) >= mY1 and int((((POSySOLDATp2(p)/96)-valIniY)*96)+80) <= mY) or (int((((POSxSOLDATp2(p)/96)-valIniX)*96)+80) <= mX1 and int((((POSxSOLDATp2(p)/96)-valIniX)*96)+80) >= mX and int((((POSySOLDATp2(p)/96)-valIniY)*96)+80) >= mY1 and int((((POSySOLDATp2(p)/96)-valIniY)*96)+80) <= mY) or (int((((POSxSOLDATp2(p)/96)-valIniX)*96)+80) >= mX1 and int((((POSxSOLDATp2(p)/96)-valIniX)*96)+80) <= mX and int((((POSySOLDATp2(p)/96)-valIniY)*96)+80) <= mY1 and int((((POSySOLDATp2(p)/96)-valIniY)*96)+80) >= mY) or (int((((POSxSOLDATp2(p)/96)-valIniX)*96)+80) <= mX1 and int((((POSxSOLDATp2(p)/96)-valIniX)*96)+80) >= mX and int((((POSySOLDATp2(p)/96)-valIniY)*96)+80) <= mY1 and int((((POSySOLDATp2(p)/96)-valIniY)*96)+80) >= mY) then soldat2VIEW = p  : goto [AIunitVIEW]
            if int((((POSxSOLDATp2(p)/96)-valIniX)*96)+48) > mX-30 and int((((POSxSOLDATp2(p)/96)-valIniX)*96)+48) < mX-10 and int((((POSySOLDATp2(p)/96)-valIniY)*96)+48) > mY-20 and int((((POSySOLDATp2(p)/96)-valIniY)*96)+48) < mY then soldat2VIEW = p : goto [AIunitVIEW]
        end if
        if IDunitP2(p) = 2 then
            soldat2Select(p) = 0
            if (int((((POSxSOLDATp2(p)/96)-valIniX)*96)+80) >= mX1 and int((((POSxSOLDATp2(p)/96)-valIniX)*96)+80) <= mX and int((((POSySOLDATp2(p)/96)-valIniY)*96)+80) >= mY1 and int((((POSySOLDATp2(p)/96)-valIniY)*96)+80) <= mY) or (int((((POSxSOLDATp2(p)/96)-valIniX)*96)+80) <= mX1 and int((((POSxSOLDATp2(p)/96)-valIniX)*96)+80) >= mX and int((((POSySOLDATp2(p)/96)-valIniY)*96)+80) >= mY1 and int((((POSySOLDATp2(p)/96)-valIniY)*96)+80) <= mY) or (int((((POSxSOLDATp2(p)/96)-valIniX)*96)+80) >= mX1 and int((((POSxSOLDATp2(p)/96)-valIniX)*96)+80) <= mX and int((((POSySOLDATp2(p)/96)-valIniY)*96)+80) <= mY1 and int((((POSySOLDATp2(p)/96)-valIniY)*96)+80) >= mY) or (int((((POSxSOLDATp2(p)/96)-valIniX)*96)+80) <= mX1 and int((((POSxSOLDATp2(p)/96)-valIniX)*96)+80) >= mX and int((((POSySOLDATp2(p)/96)-valIniY)*96)+80) <= mY1 and int((((POSySOLDATp2(p)/96)-valIniY)*96)+80) >= mY) then soldat2VIEW = p : goto [AIunitVIEW]
            if int((((POSxSOLDATp2(p)/96)-valIniX)*96)+48) > mX-30 and int((((POSxSOLDATp2(p)/96)-valIniX)*96)+48) < mX-10 and int((((POSySOLDATp2(p)/96)-valIniY)*96)+48) > mY-20 and int((((POSySOLDATp2(p)/96)-valIniY)*96)+48) < mY then soldat2VIEW = p : goto [AIunitVIEW]
        end if
    next p

    for p = 1 to numSoldatP1
        if IDunitP1(p) = 1 then
            soldat1Select(p) = 0
            if (int((((POSxSOLDATp1(p)/96)-valIniX)*96)+80) >= mX1 and int((((POSxSOLDATp1(p)/96)-valIniX)*96)+80) <= mX and int((((POSySOLDATp1(p)/96)-valIniY)*96)+80) >= mY1 and int((((POSySOLDATp1(p)/96)-valIniY)*96)+80) <= mY) or (int((((POSxSOLDATp1(p)/96)-valIniX)*96)+80) <= mX1 and int((((POSxSOLDATp1(p)/96)-valIniX)*96)+80) >= mX and int((((POSySOLDATp1(p)/96)-valIniY)*96)+80) >= mY1 and int((((POSySOLDATp1(p)/96)-valIniY)*96)+80) <= mY) or (int((((POSxSOLDATp1(p)/96)-valIniX)*96)+80) >= mX1 and int((((POSxSOLDATp1(p)/96)-valIniX)*96)+80) <= mX and int((((POSySOLDATp1(p)/96)-valIniY)*96)+80) <= mY1 and int((((POSySOLDATp1(p)/96)-valIniY)*96)+80) >= mY) or (int((((POSxSOLDATp1(p)/96)-valIniX)*96)+80) <= mX1 and int((((POSxSOLDATp1(p)/96)-valIniX)*96)+80) >= mX and int((((POSySOLDATp1(p)/96)-valIniY)*96)+80) <= mY1 and int((((POSySOLDATp1(p)/96)-valIniY)*96)+80) >= mY) then soldat1Select(p) = 1 : AchatUnitMode = 1 : SelectedArmy1 = SelectedArmy1 + 1 : unicSoldat = p
            if int((((POSxSOLDATp1(p)/96)-valIniX)*96)+48) > mX-30 and int((((POSxSOLDATp1(p)/96)-valIniX)*96)+48) < mX-10 and int((((POSySOLDATp1(p)/96)-valIniY)*96)+48) > mY-20 and int((((POSySOLDATp1(p)/96)-valIniY)*96)+48) < mY then soldat1Select(p) = 1 : AchatUnitMode = 1 : SelectedArmy1 = SelectedArmy1 + 1 : unicSoldat = p
        end if
        if IDunitP1(p) = 2 then
            soldat2Select(p) = 0
            if (int((((POSxSOLDATp1(p)/96)-valIniX)*96)+80) >= mX1 and int((((POSxSOLDATp1(p)/96)-valIniX)*96)+80) <= mX and int((((POSySOLDATp1(p)/96)-valIniY)*96)+80) >= mY1 and int((((POSySOLDATp1(p)/96)-valIniY)*96)+80) <= mY) or (int((((POSxSOLDATp1(p)/96)-valIniX)*96)+80) <= mX1 and int((((POSxSOLDATp1(p)/96)-valIniX)*96)+80) >= mX and int((((POSySOLDATp1(p)/96)-valIniY)*96)+80) >= mY1 and int((((POSySOLDATp1(p)/96)-valIniY)*96)+80) <= mY) or (int((((POSxSOLDATp1(p)/96)-valIniX)*96)+80) >= mX1 and int((((POSxSOLDATp1(p)/96)-valIniX)*96)+80) <= mX and int((((POSySOLDATp1(p)/96)-valIniY)*96)+80) <= mY1 and int((((POSySOLDATp1(p)/96)-valIniY)*96)+80) >= mY) or (int((((POSxSOLDATp1(p)/96)-valIniX)*96)+80) <= mX1 and int((((POSxSOLDATp1(p)/96)-valIniX)*96)+80) >= mX and int((((POSySOLDATp1(p)/96)-valIniY)*96)+80) <= mY1 and int((((POSySOLDATp1(p)/96)-valIniY)*96)+80) >= mY) then soldat2Select(p) = 1 : AchatUnitMode = 1 : SelectedArmy2 = SelectedArmy2 + 1 : unicSoldat = p
            if int((((POSxSOLDATp1(p)/96)-valIniX)*96)+48) > mX-30 and int((((POSxSOLDATp1(p)/96)-valIniX)*96)+48) < mX-10 and int((((POSySOLDATp1(p)/96)-valIniY)*96)+48) > mY-20 and int((((POSySOLDATp1(p)/96)-valIniY)*96)+48) < mY then soldat2Select(p) = 1 : AchatUnitMode = 1 : SelectedArmy2 = SelectedArmy2 + 1 : unicSoldat = p
        end if
    next p

    if SelectedArmy1 >0 or SelectedArmy2 >0 then
        noRESSOURCEshow = 1
        print #main.map2, "cls; drawbmp soldat1 36 100; drawbmp soldat2 36 170"
        print #main.map2, "font Courier_New 14 bold; color black; backcolor white"
        if version = 1 then
            print #main.map2, "place 36 50 ;\"; "Armée sélectionnée"
            print #main.map2, "font Courier_New 11"
            print #main.map2, "place 90 130 ;\"; "X ";SelectedArmy1;"\Fantassin léger"
            print #main.map2, "place 90 200 ;\"; "X ";SelectedArmy2;"\Lancier"
        end if
        if version = 2 then
            print #main.map2, "place 36 50 ;\"; "Selected Army"
            print #main.map2, "font Courier_New 11"
            print #main.map2, "place 90 130 ;\"; "X ";SelectedArmy1;"\Infantryman"
            print #main.map2, "place 90 200 ;\"; "X ";SelectedArmy2;"\Lancer"
        end if
    end if

    if SelectedArmy1+SelectedArmy2 = 1 then
        noRESSOURCEshow = 1
        print #main.map2, "cls"
        print #main.map2, "font Courier_New 12 bold; color black; backcolor white"
        if version = 1 then
            if IDunitP1(unicSoldat) = 1 then print #main.map2, "drawbmp soldat1 36 100" : print #main.map2, "place 36 70 ;\"; "Fantassin"
            if IDunitP1(unicSoldat) = 2 then print #main.map2, "drawbmp soldat2 36 100" : print #main.map2, "place 36 70 ;\"; "Lancier"
            print #main.map2, "font Courier_New 11"
            if Heroes = 1 then print #main.map2, "place 80 135 ;\"; "Niveau : ";LvlSoldatP1(unicSoldat)
            if Heroes = 1 then print #main.map2, "place 80 150 ;\"; "Progression : ";XpSoldatP1(unicSoldat); "/" ;XpTotalSoldatP1(unicSoldat)
            print #main.map2, "place 15 180 ;\"; "Attaque : ";ATKsoldatP1(unicSoldat)
            print #main.map2, "place 15 195 ;\"; "Armure : ";DEFsoldatP1(unicSoldat)
            print #main.map2, "place 15 210 ;\"; "Vitesse d'attaque : ";200
            print #main.map2, "place 80 110 ;\"; "Santé : ";PVsoldatP1(unicSoldat); "/" ;PvMAXsoldatP1(unicSoldat)
        end if
        if version = 2 then
            if IDunitP1(unicSoldat) = 1 then print #main.map2, "drawbmp soldat1 36 100" : print #main.map2, "place 36 70 ;\"; "Infantryman"
            if IDunitP1(unicSoldat) = 2 then print #main.map2, "drawbmp soldat2 36 100" : print #main.map2, "place 36 70 ;\"; "Lancer"
            print #main.map2, "font Courier_New 11"
            if Heroes = 1 then print #main.map2, "place 80 135 ;\"; "Level : ";LvlSoldatP1(unicSoldat)
            if Heroes = 1 then print #main.map2, "place 80 150 ;\"; "Experience : ";XpSoldatP1(unicSoldat); "/" ;XpTotalSoldatP1(unicSoldat)
            print #main.map2, "place 15 180 ;\"; "Attack : ";ATKsoldatP1(unicSoldat)
            print #main.map2, "place 15 195 ;\"; "Armor : ";DEFsoldatP1(unicSoldat)
            print #main.map2, "place 15 210 ;\"; "Attack speed : ";200
            print #main.map2, "place 80 110 ;\"; "Health : ";PVsoldatP1(unicSoldat); "/" ;PvMAXsoldatP1(unicSoldat)
        end if
    end if

    for o = 1 to numSoldatP1
        if IDunitP1(o) = 3 then peonSELECT(o) = 0
    next o
    if nombrePeon(1) > 0 then
        for p = 1 to numSoldatP1
            if IDunitP1(p) = 3 then
            if int((((POSxSOLDATp1(p)/96)-valIniX)*96)+48) > mX-30 and int((((POSxSOLDATp1(p)/96)-valIniX)*96)+48) < mX-10 and int((((POSySOLDATp1(p)/96)-valIniY)*96)+48) > mY-20 and int((((POSySOLDATp1(p)/96)-valIniY)*96)+48) < mY then goto [selectAworker]
            if (int((((POSxSOLDATp1(p)/96)-valIniX)*96)+80) >= mX1 and int((((POSxSOLDATp1(p)/96)-valIniX)*96)+80) <= mX and int((((POSySOLDATp1(p)/96)-valIniY)*96)+80) >= mY1 and int((((POSySOLDATp1(p)/96)-valIniY)*96)+80) <= mY) or (int((((POSxSOLDATp1(p)/96)-valIniX)*96)+80) <= mX1 and int((((POSxSOLDATp1(p)/96)-valIniX)*96)+80) >= mX and int((((POSySOLDATp1(p)/96)-valIniY)*96)+80) >= mY1 and int((((POSySOLDATp1(p)/96)-valIniY)*96)+80) <= mY) or (int((((POSxSOLDATp1(p)/96)-valIniX)*96)+80) >= mX1 and int((((POSxSOLDATp1(p)/96)-valIniX)*96)+80) <= mX and int((((POSySOLDATp1(p)/96)-valIniY)*96)+80) <= mY1 and int((((POSySOLDATp1(p)/96)-valIniY)*96)+80) >= mY) or (int((((POSxSOLDATp1(p)/96)-valIniX)*96)+80) <= mX1 and int((((POSxSOLDATp1(p)/96)-valIniX)*96)+80) >= mX and int((((POSySOLDATp1(p)/96)-valIniY)*96)+80) <= mY1 and int((((POSySOLDATp1(p)/96)-valIniY)*96)+80) >= mY) then
                [selectAworker]
                menuCONSTRUCTION = 1 : unlockACHATunit = 0 : SelectedArmy0 = SelectedArmy0 + 1 : peonSELECT(p) = 1
                print #main.map2, "cls; drawbmp persoXL 36 150; drawbmp ressource1 36 20; drawbmp ressource2 36 50; drawbmp ressource3 155 20; drawbmp ressource4 155 50; drawbmp construct2 24 350; drawbmp construct1 24 250; drawbmp construct1 24 250; drawbmp construct3 24 450; drawbmp construct4 24 550"
                print #main.map2, "font Courier_New 14; color blue; backcolor white"
                if version = 1 then
                    print #main.map2, "place 35 130 ;\"; "VILLAGEOIS"
                    print #main.map2, "font Courier_New 10 bold; color black"
                    print #main.map2, "place 82 270 ;\"; "Académie (";ConstructionAcademie;" /1)"
                    print #main.map2, "place 80 370 ;\"; "Fermage (";ConstructionFerme;" /";ConstructionFermeMax;")"
                    if rechercheAcad(3) = 0 then print #main.map2, "place 80 470 ;\"; "Tour de guet (";ConstructionTour;" /";ConstructionTourMax;")"
                    if rechercheAcad(3) = 1 then print #main.map2, "place 80 470 ;\"; "Tour (";ConstructionTour;" /";ConstructionTourMax;")"
                    print #main.map2, "place 80 570 ;\"; "Campement (";ConstructionCamp;" /1)"
                    print #main.map2, "font Courier_New 9"
                    print #main.map2, "place 80 160 ;\"; "Santé : ";PVsoldatP1(p); " / ";PvMAXsoldatP1(p);"\Attaque : ";ATKsoldatP1(p);"\Armure : ";DEFsoldatP1(p)
                    print #main.map2, "place 43 308 ;\"; CostNourritureCamp
                    print #main.map2, "place 43 322 ;\"; CostBoisCamp
                    print #main.map2, "place 43 336 ;\"; CostMineraisCamp
                    print #main.map2, "place 82 292 ;\"; "Lieu principal ou vous \pourrez développer de \nouvelles technologies."
                    print #main.map2, "place 43 408 ;\"; CostNourritureFermage
                    print #main.map2, "place 43 422 ;\"; CostBoisFermage
                    print #main.map2, "place 43 436 ;\"; CostMineraisFermage
                    print #main.map2, "place 82 392 ;\"; "Terres cultivables qui\vous fournissent de\la nourriture."
                    print #main.map2, "place 43 508 ;\"; CostNourritureTour
                    print #main.map2, "place 43 522 ;\"; CostBoisTour
                    print #main.map2, "place 43 536 ;\"; CostMineraisTour
                    print #main.map2, "place 82 492 ;\"; "Bâtiment défensif qui\défend une zone en\cas d'invasion."
                    print #main.map2, "place 43 608 ;\"; CostNourritureCaserne
                    print #main.map2, "place 43 622 ;\"; CostBoisCaserne
                    print #main.map2, "place 43 636 ;\"; CostMineraisCaserne
                    print #main.map2, "place 82 592 ;\"; "Bâtiment pour former\vos soldat et les \améliorer."
                end if
                if version = 2 then
                    print #main.map2, "place 35 130 ;\"; "VILLAGERS"
                    print #main.map2, "font Courier_New 10 bold; color black"
                    print #main.map2, "place 82 270 ;\"; "Academy (";ConstructionAcademie;" /1)"
                    print #main.map2, "place 80 370 ;\"; "Farming (";ConstructionFerme;" /";ConstructionFermeMax;")"
                    if rechercheAcad(3) = 0 then print #main.map2, "place 80 470 ;\"; "Watchtower (";ConstructionTour;" /";ConstructionTourMax;")"
                    if rechercheAcad(3) = 1 then print #main.map2, "place 80 470 ;\"; "Tower (";ConstructionTour;" /";ConstructionTourMax;")"
                    print #main.map2, "place 80 570 ;\"; "Camp (";ConstructionCamp;" /1)"
                    print #main.map2, "font Courier_New 9"
                    print #main.map2, "place 80 160 ;\"; "Health : ";PVsoldatP1(p); " / ";PvMAXsoldatP1(p);"\Attack : ";ATKsoldatP1(p);"\Armor : ";DEFsoldatP1(p)
                    print #main.map2, "place 43 308 ;\"; CostNourritureCamp
                    print #main.map2, "place 43 322 ;\"; CostBoisCamp
                    print #main.map2, "place 43 336 ;\"; CostMineraisCamp
                    print #main.map2, "place 82 292 ;\"; "Main place where you \can develop new \technologies."
                    print #main.map2, "place 43 408 ;\"; CostNourritureFermage
                    print #main.map2, "place 43 422 ;\"; CostBoisFermage
                    print #main.map2, "place 43 436 ;\"; CostMineraisFermage
                    print #main.map2, "place 82 392 ;\"; "Farmland that provides \you with food."
                    print #main.map2, "place 43 508 ;\"; CostNourritureTour
                    print #main.map2, "place 43 522 ;\"; CostBoisTour
                    print #main.map2, "place 43 536 ;\"; CostMineraisTour
                    print #main.map2, "place 82 492 ;\"; "Defensive building \that defends an area \in case of invasion."
                    print #main.map2, "place 43 608 ;\"; CostNourritureCaserne
                    print #main.map2, "place 43 622 ;\"; CostBoisCaserne
                    print #main.map2, "place 43 636 ;\"; CostMineraisCaserne
                    print #main.map2, "place 82 592 ;\"; "Building to train your \soldiers and improve \them."
                end if
            end if
            end if
        next p
    end if
    goto [endLEVEL]

    [GoMoove]
    mX = MouseX : mY = MouseY
   ' notice mX; " : "; mY
    for p = 1 to numSoldatP1
        if IDunitP1(p) = 1 then
            MouseXrnd2 = MouseX+int(rnd(1)*40-30) : MouseYrnd2 = MouseY+int(rnd(1)*30-10)
            if soldat1Select(p) = 1 then mX2moove(p) = int(MouseXrnd2-48+(valIniX*96)) : mY2moove(p) = int(MouseYrnd2-48+(valIniY*96)) : MoovingTO(p) = 2
        end if
        if IDunitP1(p) = 2 then
            MouseXrnd3 = MouseX+int(rnd(1)*40-30) : MouseYrnd3 = MouseY+int(rnd(1)*30-10)
            if soldat2Select(p) = 1 then mX3moove(p) = int(MouseXrnd3-48+(valIniX*96)) : mY3moove(p) = int(MouseYrnd3-48+(valIniY*96)) : MoovingTO(p) = 3
        end if
        if IDunitP1(p) = 3 then
            MouseXrnd1 = MouseX+int(rnd(1)*40-30) : MouseYrnd1 = MouseY+int(rnd(1)*30-10)
            if peonSELECT(p) = 1 then mXmoove(p) = int(MouseXrnd1-72+(valIniX*96)) : mYmoove(p) = int(MouseYrnd1-72+(valIniY*96)) : MoovingTO(p) = 1
        end if
    next p
    goto [endLEVEL]

    [quit]
    if about = 1 then close #about : about = 0
    if Setting = 1 then close #setting : Setting = 0
    if laws = 1 then close #laws : laws = 0
    close #main : goto [ini]
    [quit2]
    close #ini : goto [ini]
    [quitIni]
    if about = 1 then close #about
    if Setting = 1 then close #setting
    if laws = 1 then close #laws
    pass$ = "0"
    open "pref.txt" for output as #secu
    print #secu, pass$
    print #secu, version
    print #secu, autoSAVmode
    close #secu
    close #ini
    'playwave ""
    end

    [CoreAI]
    NworkerWOOD(2) = 0 : NworkerFARM(2) = 0 : NworkerMINE(2) = 0

    for i = 1 to numSoldatP2
        if IDunitP2(i) = 0 or (PVsoldatP2(i) <= 0 and IDunitP2(i) <= 3) or IDunitP2(i) > 3 then goto [SKIPai1]
        posX2 = POSxSOLDATp2(i) : posY2 = POSySOLDATp2(i) : gridX2 = int((posX2/96)+0.5) : gridY2 = int((posY2/96)+0.5)

    select case IDunitP2(i)
        case 3 ' Worker AI
            cellType = p(gridX2, gridY2)
            if cellType = 3 then NworkerWOOD(2) = NworkerWOOD(2) + 1
            if cellType = 28 then NworkerFARM(2) = NworkerFARM(2) + 1
            if cellType = 4 then NworkerMINE(2) = NworkerMINE(2) + 1
            if iniWorkerIA(i) = 2 then
                iniWorkerIA(i) = 1 : MoovingTOai(i) = 0
                if ConstructionFermeAI1 > 0 and NworkerFARM(2) < 1 then
                    ressourceW = 28 : gosub [chercheRESSOURCE]
                else
                    if NworkerMINE(2) < 1 then
                        ressourceW = 4 : gosub [chercheRESSOURCE]
                    else
                        ressourceW = 3 : gosub [chercheRESSOURCE]
                    end if
                end if
                goto [skippRemakeRess]
            end if

            if iniWorkerIA(i) = 0 then
                iniWorkerIA(i) = 1 : MoovingTOai(i) = 0
                if ConstructionFermeAI1 > 0 and NworkerFARM(2) < 1 then
                    ressourceW = 28 : gosub [chercheRESSOURCE]
                else
                    if NworkerMINE(2) < 1 then
                        ressourceW = 4 : gosub [chercheRESSOURCE]
                    else
                        ressourceW = 3 : gosub [chercheRESSOURCE]
                    end if
                end if
                goto [skippRemakeRess]
            end if

            if (cellType <> 3 and cellType <> 4 and cellType <> 28 and MoovingTOai(i) = 0) or MoovingTOai(i) > 0 then
                if MoovingTOai(i) > 0 then goto [skippRemakeRess]
                if ConstructionFermeAI1 > 0 and NworkerFARM(2) < 1 then
                    ressourceW = 28 : gosub [chercheRESSOURCE]
                else
                    if NworkerMINE(2) < 1 then
                        ressourceW = 4 : gosub [chercheRESSOURCE]
                    else
                        if NworkerWOOD(2) < 2 then
                            ressourceW = 3 : gosub [chercheRESSOURCE]
                        else
                            ressourceW = 3 : gosub [chercheRESSOURCE]
                        end if
                    end if
                end if
                goto [skippRemakeRess]
            end if

            if MoovingTOai(i) = 0 and cellType > 0 then
                shouldReassign = 0 : newRessource = 0

                if cellType = 28 and NworkerFARM(2) > 1 then
                    shouldReassign = 1
                    if NworkerMINE(2) < 1 then
                        newRessource = 4
                    else
                        if NworkerWOOD(2) < 2 then
                            newRessource = 3
                        end if
                    end if
                end if

                if cellType = 4 and NworkerMINE(2) > 1 and shouldReassign = 0 then
                    shouldReassign = 1
                    if ConstructionFermeAI1 > 0 and NworkerFARM(2) < 1 then
                        newRessource = 28
                    else
                        if NworkerWOOD(2) < 2 then
                            newRessource = 3
                        end if
                    end if
                end if

                if cellType = 3 and shouldReassign = 0 then
                    if NworkerWOOD(2) > 2 then
                        if ConstructionFermeAI1 > 0 and NworkerFARM(2) < 1 then
                            shouldReassign = 1
                            newRessource = 28
                        else
                            if NworkerMINE(2) < 1 then
                                shouldReassign = 1
                                newRessource = 4
                            end if
                        end if
                    end if
                end if

                if cellType = 3 and shouldReassign = 0 then
                    if ConstructionFermeAI1 > 0 and NworkerFARM(2) < 1 then
                        if NworkerWOOD(2) >= 2 then
                            shouldReassign = 1
                            newRessource = 28
                        end if
                    else
                        if NworkerMINE(2) < 1 and NworkerWOOD(2) >= 2 then
                            shouldReassign = 1
                            newRessource = 4
                        end if
                    end if
                end if

                if shouldReassign = 1 and newRessource > 0 then
                    ressourceW = newRessource
                    gosub [chercheRESSOURCE]
                end if
            end if

            for defenseCheck = 1 to numSoldatP1
                if PVsoldatP1(defenseCheck) <= 0 then goto [skipDefenseCheck]
                unitType = IDunitP1(defenseCheck)
                if unitType < 1 or unitType > 3 then goto [skipDefenseCheck]
                dx = POSxSOLDATp1(defenseCheck) - posX2 : dy = POSySOLDATp1(defenseCheck) - posY2
                distDef = dx*dx + dy*dy
                if distDef < 900 and reloadTimeE(i) <= 0 then
                    reloadTimeE(i) = 200
                    damage = ATKsoldatP2(i) - DEFsoldatP1(defenseCheck)
                    if damage < 1 then damage = 1
                    PVsoldatP1(defenseCheck) = PVsoldatP1(defenseCheck) - damage
                    if PVsoldatP1(defenseCheck) <= 0 then
                        MoovingTO(defenseCheck) = 0
                        POSxSOLDATp1(defenseCheck) = 0 : POSySOLDATp1(defenseCheck) = 0
                        pop(1) = pop(1) - 1 : if pop(1) < 0 then pop(1) = 0
                        select case unitType
                            case 1
                                print #main.map, "removesprite HommeDarme";defenseCheck
                                nombreSoldatA(1) = nombreSoldatA(1) - 1
                            case 2
                                print #main.map, "removesprite Lancier";defenseCheck
                                nombreSoldatB(1) = nombreSoldatB(1) - 1
                            case 3
                                print #main.map, "removesprite peon";defenseCheck
                                nombrePeon(1) = nombrePeon(1) - 1
                        end select
                    end if
                end if
                [skipDefenseCheck]
            next defenseCheck

            [skippRemakeRess]
            if MoovingTOai(i) > 0 then
                targetX = mXmoove1AI(i) : targetY = mYmoove1AI(i)
                if abs(targetX - posX2) > 5 then
                if posX2 > MinMAPmooveX and posX2 > targetX then POSxSOLDATp2(i) = posX2 - 2
                if posX2 < MaxMAPmooveX and posX2 < targetX then POSxSOLDATp2(i) = posX2 + 2
                end if
                if abs(targetY - posY2) > 5 then
                if posY2 > MinMAPmooveY and posY2 > targetY then POSySOLDATp2(i) = posY2 - 2
                if posY2 < MaxMAPmooveY and posY2 < targetY then POSySOLDATp2(i) = posY2 + 2
                end if
                if abs(targetX - posX2) < 10 and abs(targetY - posY2) < 10 then
                    MoovingTOai(i) = 0
                    finalGridX = int((POSxSOLDATp2(i)/96)+0.5)
                    finalGridY = int((POSySOLDATp2(i)/96)+0.5)
                    finalCell = p(finalGridX, finalGridY)
                    if (ressourceW = 3 and finalCell <> 3) or (ressourceW = 4 and finalCell <> 4) or (ressourceW = 28 and finalCell <> 28) then
                        if iniWorkerIA(i) <> 99 then
                            iniWorkerIA(i) = 99
                            gosub [chercheRESSOURCE]
                        else
                            iniWorkerIA(i) = 1
                        end if
                    else
                        iniWorkerIA(i) = 1
                    end if
                end if
            end if

            case 1,2 ' Soldats AI
                villageX1 = IDvillageX(1)*96 : villageY1 = IDvillageY(1)*96
                distToVillage = abs(posX2 - villageX1) + abs(posY2 - villageY1)
                if ia1discoverPlayer = 0 and distToVillage < 400 then ia1discoverPlayer = 1 : securityMOOVE2 = 0
                if UnitP2intoArmy(i) = 1 and MoovingTOai(i) = 1 then
                    targetX = mXmoove1AI(i) : targetY = mYmoove1AI(i)
                    if abs(targetX - posX2) > 5 then
                    if posX2 > MinMAPmooveX and posX2 > targetX then POSxSOLDATp2(i) = posX2 - 2
                    if posX2 < MaxMAPmooveX and posX2 < targetX then POSxSOLDATp2(i) = posX2 + 2
                    end if
                    if abs(targetY - posY2) > 5 then
                    if posY2 > MinMAPmooveY and posY2 > targetY then POSySOLDATp2(i) = posY2 - 2
                    if posY2 < MaxMAPmooveY and posY2 < targetY then POSySOLDATp2(i) = posY2 + 2
                    end if
                    if abs(targetX - posX2) < 50 and abs(targetY - posY2) < 50 then
                        MoovingTOai(i) = 0
                        UnitP2intoArmy(i) = 0
                        unitesArrivees = 0
                        for checkUnit = 1 to numSoldatP2
                            if (IDunitP2(checkUnit) = 1 or IDunitP2(checkUnit) = 2) and UnitP2intoArmy(checkUnit) = 0 and PVsoldatP2(checkUnit) > 0 then unitesArrivees = unitesArrivees + 1
                        next checkUnit
                        if unitesArrivees >= armyP2 * 0.5 then securityMOOVE2 = 0
                    end if
                end if
        end select
        [SKIPai1]
    next i
    for i = 1 to numSoldatP2
        if PVsoldatP2(i) <= 0 or IDunitP2(i) = 0 then goto [skipDisplayAI]
        if IDunitP2(i) < 1 or IDunitP2(i) > 3 then goto [skipDisplayAI]
        spriteX = int((((POSxSOLDATp2(i)/96)-valIniX)*96)+70)
        spriteY = int((((POSySOLDATp2(i)/96)-valIniY)*96)+50)
        if spriteX > 5 and spriteX < 830 and spriteY > 5 and spriteY < 735 then
            select case IDunitP2(i)
                case 1 : print #main.map, "spritexy ennemiA";i;" ";spriteX;" ";spriteY;"; SpriteVisible ennemiA";i;" on; spritetofront ennemiA";i
                case 2 : print #main.map, "spritexy ennemiB";i;" ";spriteX;" ";spriteY;"; SpriteVisible ennemiB";i;" on; spritetofront ennemiB";i
                case 3 : print #main.map, "spritexy ennemiC";i;" ";spriteX;" ";spriteY;"; SpriteVisible ennemiC";i;" on; spritetofront ennemiC";i
            end select
        end if
        [skipDisplayAI]
    next i
    for j = 1 to numSoldatP1
        if IDunitP1(j) = 0 then goto [SKIPcore]
        if PVsoldatP1(j) <= 0 and IDunitP1(j) < 4 then goto [SKIPcore]
        posX1 = POSxSOLDATp1(j) : posY1 = POSySOLDATp1(j)
        if PVsoldatP1(j) > 0 then
            movingMode = MoovingTO(j) : unitType = IDunitP1(j)
            if movingMode = 1 and unitType = 3 then ' Worker
                targetX = mXmoove(j) : targetY = mYmoove(j)
                if abs(targetX - posX1) > 5 then
                if posX1 > MinMAPmooveX and posX1 > targetX then POSxSOLDATp1(j) = posX1 - 2
                if posX1 < MaxMAPmooveX and posX1 < targetX then POSxSOLDATp1(j) = posX1 + 2
                end if
                if abs(targetY - posY1) > 5 then
                if posY1 > MinMAPmooveY and posY1 > targetY then POSySOLDATp1(j) = posY1 - 2
                if posY1 < MaxMAPmooveY and posY1 < targetY then POSySOLDATp1(j) = posY1 + 2
                end if
                if abs(targetX - posX1) < 8 and abs(targetY - posY1) < 8 then MoovingTO(j) = 0
            end if
            if movingMode = 2 and unitType = 1 then ' Homme d'arme
                targetX = mX2moove(j) : targetY = mY2moove(j)
                if abs(targetX - posX1) > 5 then
                if posX1 > MinMAPmooveX and posX1 > targetX then POSxSOLDATp1(j) = posX1 - 2
                if posX1 < MaxMAPmooveX and posX1 < targetX then POSxSOLDATp1(j) = posX1 + 2
                end if
                if abs(targetY - posY1) > 5 then
                if posY1 > MinMAPmooveY and posY1 > targetY then POSySOLDATp1(j) = posY1 - 2
                if posY1 < MaxMAPmooveY and posY1 < targetY then POSySOLDATp1(j) = posY1 + 2
                end if
                if abs(targetX - posX1) < 8 and abs(targetY - posY1) < 8 then MoovingTO(j) = 0
            end if
            if movingMode = 3 and unitType = 2 then ' Lancier
                targetX = mX3moove(j) : targetY = mY3moove(j)
                if abs(targetX - posX1) > 5 then
                if posX1 > MinMAPmooveX and posX1 > targetX then POSxSOLDATp1(j) = posX1 - 2
                if posX1 < MaxMAPmooveX and posX1 < targetX then POSxSOLDATp1(j) = posX1 + 2
                end if
                if abs(targetY - posY1) > 5 then
                if posY1 > MinMAPmooveY and posY1 > targetY then POSySOLDATp1(j) = posY1 - 2
                if posY1 < MaxMAPmooveY and posY1 < targetY then POSySOLDATp1(j) = posY1 + 2
                end if
                if abs(targetX - posX1) < 8 and abs(targetY - posY1) < 8 then MoovingTO(j) = 0
            end if
        end if
        for e = 1 to numSoldatP2
            if PVsoldatP2(e) <= 0 then goto [SkipIA]
            posX2 = POSxSOLDATp2(e) : posY2 = POSySOLDATp2(e)
            spriteXe = int((((posX2/96)-valIniX)*96)+70) : spriteYe = int((((posY2/96)-valIniY)*96)+50)
            select case IDunitP1(j)
            ' ============================================================
            case 1,2,3 ' Guerrier/Ouvrier P1
            ' ============================================================
                select case IDunitP2(e)
                    case 1,2,3 ' vs Guerrier/Ouvrier P2
                        dx = posX1 - posX2 : dy = posY1 - posY2 : dist1 = abs(dx) + abs(dy)
                        if dist1 < 100 and PVsoldatP1(j) > 0 then ' 100 pixels
                            if IDunitP1(j) <> 3 then
                                if dx > 0 then POSxSOLDATp1(j) = posX1 - 2 else POSxSOLDATp1(j) = posX1 + 2
                                if dy > 0 then POSySOLDATp1(j) = posY1 - 2 else POSySOLDATp1(j) = posY1 + 2
                            end if
                            if IDunitP2(e) <> 3 then
                                if dx > 0 then POSxSOLDATp2(e) = posX2 + 2 else POSxSOLDATp2(e) = posX2 - 2
                                if dy > 0 then POSySOLDATp2(e) = posY2 + 2 else POSySOLDATp2(e) = posY2 - 2
                            end if
                            reloadTimeE(e) = reloadTimeE(e) - 1
                            reloadTime(j) = reloadTime(j) - 1
                            if dist1 < 30 then
                                if reloadTimeE(e) <= 0 then reloadTimeE(e) = 200 : PVsoldatP1(j) = PVsoldatP1(j) - (ATKsoldatP2(e) - DEFsoldatP1(j))
                                if PVsoldatP1(j) <= 0 then
                                    MoovingTO(j) = 0 : POSxSOLDATp1(j) = 0 : POSySOLDATp1(j) = 0 : pop(1) = pop(1) - 1 : if pop(1) < 0 then pop(1) = 0
                                    select case IDunitP1(j)
                                        case 1
                                            print #main.map, "removesprite HommeDarme";j : nombreSoldatA(1) = nombreSoldatA(1) - 1
                                        case 2
                                            print #main.map, "removesprite Lancier";j : nombreSoldatB(1) = nombreSoldatB(1) - 1
                                        case 3
                                            print #main.map, "removesprite peon";j : nombrePeon(1) = nombrePeon(1) - 1
                                    end select
                                end if
                                if reloadTime(j) <= 0 then
                                    if IDunitP1(j) <> 3 then MoovingTO(j) = 0
                                    reloadTime(j) = 200 : PVsoldatP2(e) = PVsoldatP2(e) - (ATKsoldatP1(j) - DEFsoldatP2(e))
                                end if
                                if PVsoldatP2(e) <= 0 then
                                    pop(2) = pop(2) - 1 : if pop(2) < 0 then pop(2) = 0
                                    select case IDunitP2(e)
                                        case 1: nombreSoldatA(2) = nombreSoldatA(2) - 1
                                        case 2: nombreSoldatB(2) = nombreSoldatB(2) - 1
                                        case 3: nombrePeon(2) = nombrePeon(2) - 1 : print #main.map2, "cls"
                                    end select
                                end if
                            end if
                        end if
                    case 8 ' vs Tour P2
                        if IDunitP1(j) = 3 then goto [SkipIA]
                        dx = posX1 - posX2 : dy = posY1 - posY2 : dist1 = abs(dx) + abs(dy)
                        if dist1 < 200 and PVsoldatP1(j) > 0 then '200
                            ia1attacked = 1
                            if dx > 0 then POSxSOLDATp1(j) = posX1 - 2
                            if dx < -80 then POSxSOLDATp1(j) = posX1 + 2
                            if dy > 0 then POSySOLDATp1(j) = posY1 - 2
                            if dy < 0 then POSySOLDATp1(j) = posY1 + 2
                            if dist1 < 50 then '50
                                reloadTime(j) = reloadTime(j) - 1
                                if reloadTime(j) <= 0 then reloadTime(j) = 200 : PVsoldatP2(e) = PVsoldatP2(e) - (ATKsoldatP1(j) - DEFsoldatP2(e))
                            end if
                            reloadTimeE(e) = reloadTimeE(e) - 1
                            if arrow1Active(e) = 1 and PVsoldatP2(e) > 0 then
                                dx2 = cxOLD(e) - xOLD(e) : dy2 = cyOLD(e) - yOLD(e)
                                if abs(dx2) > 4 or abs(dy2) > 4 then
                                    if dx2 > 1 then xOLD(e) = xOLD(e) + 2
                                    if dx2 < -1 then xOLD(e) = xOLD(e) - 2
                                    if dy2 > 1 then yOLD(e) = yOLD(e) + 2
                                    if dy2 < -1 then yOLD(e) = yOLD(e) - 2
                                    print #main.map, "spritexy arrowX";xX(e);"Y";yY(e);" ";xOLD(e)-5;" ";yOLD(e);"; spritetofront arrowX";xX(e);"Y";yY(e)
                                    if abs(dx2) < 4 and abs(dy2) < 4 then print #main.map, "removesprite arrowX";xX(e);"Y";yY(e) : arrow1Active(e) = 0
                                    goto [noArrow6]
                                end if
                            end if
                            arrow1Active(e) = 0
                            [noArrow6]
                            if reloadTimeE(e) <= 0 then
                                x(e) = int((((posX2/96)-valIniX)*96)+50)
                                y(e) = int((((posY2/96)-valIniY)*96)+30)
                                xX(e) = int((((posX2/96)-valIniX)*96)+30)
                                yY(e) = int((((posY2/96)-valIniY)*96)+120)
                                cx(e) = int((((posX1/96)-valIniX)*96)+80)
                                cy(e) = int((((posY1/96)-valIniY)*96)+60)
                                cxOLD(e) = cx(e) : cyOLD(e) = cy(e) : xOLD(e) = x(e) : yOLD(e) = y(e)
                                print #main.map, "addsprite arrowX";xX(e);"Y";yY(e);" arrow; spritexy arrowX";xX(e);"Y";yY(e);" ";x(e)-5;" ";y(e);"; spritetofront arrowX";xX(e);"Y";yY(e)
                                reloadTimeE(e) = 200 : PVsoldatP1(j) = PVsoldatP1(j) - (ATKsoldatP2(e) - DEFsoldatP1(j)) : arrow1Active(e) = 1
                                if PVsoldatP1(j) <= 0 then
                                    POSxSOLDATp1(j) = 0 : POSySOLDATp1(j) = 0 : pop(1) = pop(1) - 1 : if pop(1) < 0 then pop(1) = 0
                                    select case IDunitP1(j)
                                        case 1
                                            print #main.map, "removesprite HommeDarme";j : nombreSoldatA(1) = nombreSoldatA(1) - 1
                                        case 2
                                            print #main.map, "removesprite Lancier";j : nombreSoldatB(1) = nombreSoldatB(1) - 1
                                        case 3
                                            print #main.map, "removesprite peon";j : nombrePeon(1) = nombrePeon(1) - 1
                                    end select
                                end if
                            end if
                        end if
                    case 4,5,6,7 ' autres bat p2
                        if IDunitP1(j) = 3 then goto [SkipIA]
                        dx = posX2 - posX1 : dy = posY2 - posY1
                        distance = dx*dx + dy*dy
                        if distance < 4900 and PVsoldatP2(e) > 0 then ' ~70 pixels
                            ia1attacked = 1
                            if distance > 1600 then ' ~40 pixels - distance d'attaque
                            if dx > 0 then POSxSOLDATp1(j) = posX1 + 2
                            if dx < 0 then POSxSOLDATp1(j) = posX1 - 2
                            if dy > 0 then POSySOLDATp1(j) = posY1 + 2
                            if dy < 0 then POSySOLDATp1(j) = posY1 - 2
                        end if
                        if distance <= 1600 then ' ~40 pixels
                            MoovingTO(j) = 0
                            reloadTime(j) = reloadTime(j) - 1
                            if reloadTime(j) <= 0 then
                                reloadTime(j) = 200
                                PVsoldatP2(e) = PVsoldatP2(e) - (ATKsoldatP1(j) - DEFsoldatP2(e))
                                if IDunitP2(e) = 4 and PVsoldatP2(e) <= 0 then notice "VICTORY !!!" : goto [quit]
                            end if
                        end if
                    end if
                end select
            ' ============================================================
            case 4 ' Tour P1
            ' ============================================================
                if IDunitP2(e) < 1 or IDunitP2(e) > 3 then goto [SkipIA]
                dx = POSxTOWER(j) - posX2 : dy = POSyTOWER(j) - posY2 : dist4 = abs(dx) + abs(dy)
                if dist4 < 200 then '200
                    if dx < 0 then POSxSOLDATp2(e) = posX2 - 2
                    if dx > 0 then POSxSOLDATp2(e) = posX2 + 2
                    if dy < 0 then POSySOLDATp2(e) = posY2 - 2
                    if dy > 0 then POSySOLDATp2(e) = posY2 + 2
                    if dist4 < 50 then reloadTimeE(e) = reloadTimeE(e) - 1 '50
                    if dist4 < 50 and reloadTimeE(e) <= 0 then reloadTimeE(e) = 200 : PVsoldatP1(j) = PVsoldatP1(j) - (ATKsoldatP2(e) - DEFtour(j))
                    if PVsoldatP1(j) <= 0 then print #main.map2, "cls" : p(IDtourX(j)/96, IDtourY(j)/96) = 17 : moovingActivation = 1 : ConstructionTour = ConstructionTour - 1 : goto [SkipMooveTower]
                    reloadTower(j) = reloadTower(j) - 1
                    if arrow7Active(j) = 1 and PVsoldatP1(j) > 0 and rechercheAcad(3) = 1 then
                        dx2 = cxOLD(j) - xOLD(j) : dy2 = cyOLD(j) - yOLD(j)
                        if abs(dx2) > 4 or abs(dy2) > 4 then
                            if dx2 > 1 then xOLD(j) = xOLD(j) + 2
                            if dx2 < -1 then xOLD(j) = xOLD(j) - 2
                            if dy2 > 1 then yOLD(j) = yOLD(j) + 2
                            if dy2 < -1 then yOLD(j) = yOLD(j) - 2
                            print #main.map, "spritexy arrowX";xX(j);"Y";yY(j);" ";xOLD(j)-5;" ";yOLD(j);"; spritetofront arrowX";xX(j);"Y";yY(j)
                            goto [noArrow1]
                        end if
                    end if
                    arrow7Active(j) = 0
                    [noArrow1]
                    if reloadTower(j) <= 0 and rechercheAcad(3) = 1 then
                        x(j) = int((((POSxTOWER(j)/96)-valIniX)*96)+60)
                        y(j) = int((((POSyTOWER(j)/96)-valIniY)*96)+30)
                        xX(j) = int((((POSxTOWER(j)/96)-valIniX)*96)+30)
                        yY(j) = int((((POSyTOWER(j)/96)-valIniY)*96)+80)
                        cx(j) = int((((posX2/96)-valIniX)*96)+80)
                        cy(j) = int((((posY2/96)-valIniY)*96)+60)
                        cxOLD(j) = cx(j) : cyOLD(j) = cy(j) : xOLD(j) = x(j) : yOLD(j) = y(j)
                        print #main.map, "addsprite arrowX";xX(j);"Y";yY(j);" arrow; spritexy arrowX";xX(j);"Y";yY(j);" ";x(j)-5;" ";y(j);"; spritetofront arrowX";xX(j);"Y";yY(j)
                        reloadTower(j) = 200 : PVsoldatP2(e) = PVsoldatP2(e) - (ATKtour(j) - DEFsoldatP2(e)) : arrow7Active(j) = 1
                        if PVsoldatP2(e) <= 0 then
                            pop(2) = pop(2) - 1 : if pop(2) < 0 then pop(2) = 0
                            select case IDunitP2(e)
                                case 1: nombreSoldatA(2) = nombreSoldatA(2) - 1
                                case 2: nombreSoldatB(2) = nombreSoldatB(2) - 1
                                case 3: nombrePeon(2) = nombrePeon(2) - 1
                            end select
                        end if
                    end if
                    [SkipMooveTower]
                end if
            ' ============================================================
            case 6 ' Camp P1
            ' ============================================================
                if PvCamp(j) <= 0 then goto [SkipIA]
                if IDunitP2(e) < 1 or IDunitP2(e) > 3 then goto [SkipIA]
                dx = IDcampX(j) - posX2 : dy = IDcampY(j) - posY2 : dist6 = abs(dx) + abs(dy)
                if dist6 < 150 and (ciblage(e) = 0 or ciblage(e) = j) then '150
                    ciblage(e) = j
                    if dx > 40 then POSxSOLDATp2(e) = posX2 + 2
                    if dx < -40 then POSxSOLDATp2(e) = posX2 - 2
                    if dy > 30 then POSySOLDATp2(e) = posY2 + 2
                    if dy < -30 then POSySOLDATp2(e) = posY2 - 2
                    if dist6 < 50 then reloadTimeE(e) = reloadTimeE(e) - 1 '50
                    if reloadTimeE(e) <= 0 and dist6 < 50 then
                        reloadTimeE(e) = 200 : PvCamp(j) = PvCamp(j) - (ATKsoldatP2(e) - DEFcamp(j))
                        if PvCamp(j) <= 0 then
                            p(IDcampX(j)/96, IDcampY(j)/96) = 18 : moovingActivation = 1 : ConstructionCamp = 0 : print #main.map2, "cls"
                            for i = 1 to numSoldatP2
                                if ciblage(i) = j then ciblage(i) = 0
                            next i
                        end if
                    end if
                end if
            ' ============================================================
            case 7 ' Ferme P1
            ' ============================================================
                if PvFerme(j) <= 0 then goto [SkipIA]
                if ciblage(e) <> j and ciblage(e) > 0 then goto [SkipIA]
                if IDunitP2(e) < 1 or IDunitP2(e) > 3 then goto [SkipIA]
                dx = IDfermeX(j) - posX2 : dy = IDfermeY(j) - posY2 : dist7 = abs(dx) + abs(dy)
                if dist7 < 150 and (ciblage(e) = 0 or ciblage(e) = j) then '150
                    ciblage(e) = j
                    if dx > 40 then POSxSOLDATp2(e) = posX2 + 2
                    if dx < -40 then POSxSOLDATp2(e) = posX2 - 2
                    if dy > 30 then POSySOLDATp2(e) = posY2 + 2
                    if dy < -30 then POSySOLDATp2(e) = posY2 - 2
                    if dist7 < 50 then reloadTimeE(e) = reloadTimeE(e) - 1 '50
                    if reloadTimeE(e) <= 0 and dist7 < 50 then
                        reloadTimeE(e) = 200 : PvFerme(j) = PvFerme(j) - (ATKsoldatP2(e) - DEFferme(j))
                        if PvFerme(j) <= 0 then
                            p(IDfermeX(j)/96, IDfermeY(j)/96) = 19 : moovingActivation = 1 : ConstructionFerme = ConstructionFerme - 1
                            if ConstructionFerme < 0 then ConstructionFerme = 0
                            localisationFermage(j) = 0
                            for i = 1 to numSoldatP2
                                if ciblage(i) = j then ciblage(i) = 0
                            next i
                        end if
                    end if
                end if
            ' ============================================================
            case 8 ' Académie P1
            ' ============================================================
                if PvAcademie(j) <= 0 then goto [SkipIA]
                if ciblage(e) <> j and ciblage(e) > 0 then goto [SkipIA]
                if IDunitP2(e) < 1 or IDunitP2(e) > 3 then goto [SkipIA]
                dx = IDacademieX(j) - posX2 : dy = IDacademieY(j) - posY2 : dist8 = abs(dx) + abs(dy)
                if dist8 < 150 and (ciblage(e) = 0 or ciblage(e) = j) then '150
                    ciblage(e) = j
                    if dx > 40 then POSxSOLDATp2(e) = posX2 + 2
                    if dx < -40 then POSxSOLDATp2(e) = posX2 - 2
                    if dy > 30 then POSySOLDATp2(e) = posY2 + 2
                    if dy < -30 then POSySOLDATp2(e) = posY2 - 2
                    if dist8 < 50 then reloadTimeE(e) = reloadTimeE(e) - 1 '50
                    if reloadTimeE(e) <= 0 and dist8 < 50 then
                        reloadTimeE(e) = 200 : PvAcademie(j) = PvAcademie(j) - (ATKsoldatP2(e) - DEFacademie(j))
                        if PvAcademie(j) <= 0 then
                            p(IDacademieX(j)/96, IDacademieY(j)/96) = 20 : moovingActivation = 1 : ConstructionAcademie = 0 : print #main.map2, "cls"
                            for i = 1 to numSoldatP2
                                if ciblage(i) = j then ciblage(i) = 0
                            next i
                        end if
                    end if
                end if
            ' ============================================================
            case 9 ' Village P1
            ' ============================================================
                if ciblage(e) <> j and ciblage(e) > 0 then goto [SkipIA]
                if IDunitP2(e) < 1 or IDunitP2(e) > 3 then goto [SkipIA]
                dx = POSxVillage(j) - posX2 : dy = POSyVillage(j) - posY2 : dist9 = abs(dx) + abs(dy)
                if dist9 < 150 and (ciblage(e) = 0 or ciblage(e) = j) then '150
                    ciblage(e) = j
                    if dx > 40 then POSxSOLDATp2(e) = posX2 + 2
                    if dx < -40 then POSxSOLDATp2(e) = posX2 - 2
                    if dy > 30 then POSySOLDATp2(e) = posY2 + 2
                    if dy < -30 then POSySOLDATp2(e) = posY2 - 2
                    if dist9 < 50 then reloadTimeE(e) = reloadTimeE(e) - 1 '50
                    if reloadTimeE(e) <= 0 and dist9 < 50 then
                        reloadTimeE(e) = 200 : PVsoldatP1(j) = PVsoldatP1(j) - (ATKsoldatP2(e) - DEFvillage(j))
                        if PVsoldatP1(j) <= 0 then
                            print #main.map2, "cls" : p(IDvillageX(j), IDvillageY(j)) = 21 : moovingActivation = 1
                            for i = 1 to numSoldatP2
                                if ciblage(i) = j then ciblage(i) = 0
                            next i
                            notice "GAME OVER" : goto [quit]
                        end if
                    end if
                end if
            end select

            if PVsoldatP2(e) <= 0 then
                select case IDunitP2(e)
                    case 1
                        print #main.map, "removesprite ennemiA";e : POSxSOLDATp2(e) = 0 : POSySOLDATp2(e) = 0 : targetBattleE(j) = 0 : UnitP2intoArmy(e) = 0 : MoovingTOai(e) = 0 : ciblage(e) = 0
                    case 2
                        print #main.map, "removesprite ennemiB";e : POSxSOLDATp2(e) = 0 : POSySOLDATp2(e) = 0 : targetBattleE(j) = 0 : UnitP2intoArmy(e) = 0 : MoovingTOai(e) = 0 : ciblage(e) = 0
                    case 3
                        print #main.map, "removesprite ennemiC";e : POSxSOLDATp2(e) = 0 : POSySOLDATp2(e) = 0 : targetBattleE(j) = 0 : UnitP2intoArmy(e) = 0 : MoovingTOai(e) = 0 : ciblage(e) = 0
                    case 4
                        p(int(posX2/96), int(posY2/96)) = 23 : moovingActivation = 1
                    case 5
                        p(int(posX2/96), int(posY2/96)) = 25 : moovingActivation = 1 : ConstructionAcademieAI1 = 0
                    case 6
                        p(int(posX2/96), int(posY2/96)) = 27 : moovingActivation = 1 : ConstructionCampAI1 = 0
                    case 7
                        p(int(posX2/96), int(posY2/96)) = 29 : moovingActivation = 1 : ConstructionFermeAI1 = ConstructionFermeAI1 - 1
                    case 8
                        p(int(posX2/96), int(posY2/96)) = 31 : moovingActivation = 1 : ConstructionTourAI1 = ConstructionTourAI1 - 1
                end select
                if IDunitP2(e) >= 1 and IDunitP2(e) <= 2 then securityMOOVE2 = 0
            end if
            if PVsoldatP2(e) > 0 and IDunitP2(e) >= 1 and IDunitP2(e) <= 3 then
                spriteName$ = ""
                select case IDunitP2(e)
                    case 1: spriteName$ = "ennemiA" + str$(e)
                    case 2: spriteName$ = "ennemiB" + str$(e)
                    case 3: spriteName$ = "ennemiC" + str$(e)
                end select
                if spriteName$ <> "" then
                    if spriteXe > 5 and spriteXe < 830 and spriteYe > 5 and spriteYe < 735 then print #main.map, spriteCmd$;spriteName$;" ";spriteXe;" ";spriteYe;visibleCmd$;spriteName$;frontCmd$;spriteName$
                end if
            end if

            [SkipIA]
        next e

        if PVsoldatP1(j) > 0 and IDunitP1(j) > 0 and IDunitP1(j) <= 3 then
            spriteXj = int((((posX1/96)-valIniX)*96)+70) : spriteYj = int((((posY1/96)-valIniY)*96)+50)
            if spriteXj > 5 and spriteXj < 830 and spriteYj > 5 and spriteYj < 735 then
                select case IDunitP1(j)
                    case 1 : print #main.map, "spritexy HommeDarme";j;" ";spriteXj;" ";spriteYj;"; SpriteVisible HommeDarme";j;" on; spritetofront HommeDarme";j
                    case 2 : print #main.map, "spritexy Lancier";j;" ";spriteXj;" ";spriteYj;"; SpriteVisible Lancier";j;" on; spritetofront Lancier";j
                    case 3 : print #main.map, "spritexy peon";j;" ";spriteXj;" ";spriteYj;"; SpriteVisible peon";j;" on; spritetofront peon";j
                end select
            end if
        end if

        [SKIPcore]
    next j
    return

    function mcisend$(s$)
        buffer$=space$(256)+chr$(0)
        calldll #winmm,"mciSendStringA",s$ as ptr,buffer$ as ptr,_
                256 as long,0 as long,r as long
        if r>0 then
            mcisend$="error r="+str$(r)+" "+buffer$
        else
            mcisend$=buffer$
        end if
    end function

    function fileExist(dir$,file$)
        dim info$(10, 10)
        files dir$,file$, info$(
        if val(info$(0, 0)) > 0 then
            fileExist = 1
        else
            fileExist = 0
        end if
    end function

