{DEFAULT4 from Akos Ivanyi} {An improvement form Def3b-world. (Stronger AND faster!) It requires that every nation has a capital and every land zone has a port. If you have any questions, write me: ivanyiakos@hotmail.com} version(4.0); mynat := getcurrentplayer(); freedipl := getnationdiplomaticactions(mynat); mycap := getnationcapitalzone(mynat); zones := getzonecount(); setarray(order,zones); setarray(targzone,zones); for n := 0 to zones -1 do begin order[n] := -1; targzone[n] := -1; end; setarray(newembzone,10); setarray(oldembzone,10); newembark := -1; oldembark := -1; for n := 0 to 9 do begin newembzone[n] := -1; if (getbraindata('emb' + inttostr(n)) <> '') and (getbraindata('emb' + inttostr(n)) <> '-1') then begin oldembark := n; oldembzone[n] := strtoint(getbraindata('emb' + inttostr(n))); end else oldembzone[n] := -1; end; {diplomatics} ally := -1; bnation := -1; bstance := -100; bmajor := 0; for n := 0 to getnationcount() - 1 do begin if isnationactive(n) and isnationmajorpower(n) and isnationalliedwith(n,mynat) and iszoneembattled(getnationcapitalzone(n)) then ally := getnationcapitalzone(n); if freedipl > 0 then begin stance := getnationstance(mynat,n); if isnationmajorpower(n) or (stance > 80) then major := 1 else major := 0; if (isnationactive(n) and (n <> mynat) and (not isnationatwarwith(n,mynat)) and (not isnationalliedwith(n,mynat))) then if (major > bmajor) or ((stance > bstance) and (major = bmajor)) then begin bnation := n; bstance := stance; bmajor := major; end; end; end; if freedipl > 0 then orderdiplomatic(bnation,3); {formations} orderchangeformations(10,10,60,80,60,40,10,10,10,20,60,40,60,80,80); {in case of crisis} if getbraindata('plus') = '' then setbraindata('plus','0'); pl := (strtoint(getbraindata('plus')) + 10); setbraindata('plus',inttostr(pl)); danger := 0; help := 0; crisis := -1; ship := -1; capforce := getzoneforcecountattack(mycap,true,false,false,true,true,false); for n := 0 to getzoneneighborcount(mycap) - 1 do begin nb := getzoneneighbor(mycap,n); danger := danger + getzoneforcecountattack(nb,false,true,true,true,true,false); help := help + getzoneforcecountattack(nb,true,false,false,true,false,false); if getzoneforcecountattack(nb,false,true,false,false,false,true) > 0 then ship := nb; end; if (((danger - help) * 1.2) > capforce) or (danger > (capforce * 3)) or (capforce < (150 + pl)) then crisis := 1; {zones} orderglobalclearresources(mycap); orderglobalrouteresources(mycap,5); for n := 0 to zones - 1 do begin island := 1; if iszoneland(n) then orderzoneconsolidate(n) else if iszonevisible(n) then begin merchant := -1; for i := 0 to getzoneunitcount(n) - 1 do begin if getunitforcecounttype(getzoneunit(n,i),0) > 0 then merchant := 1; end; if merchant = -1 then orderzoneconsolidate(n); end; if (getzoneautoroutezone(n) = n) and (getzoneowner(n) = mynat) then begin maxfact := -1; maxfactzone := -1; maxval := -1; maxvalzone := -1; max := -1; res := getzoneresources(n); if n = mycap then begin for i := 0 to getzoneunitcount(n) - 1 do orderunitdividepct(getzoneunit(n,i),50); end; for i := 0 to getzoneneighborcount(n) - 1 do begin nb := getzoneneighbor(n,i); if iszoneland(nb) then island := -1; if iszoneallied(nb) and (n <> mycap) then begin if getzonefactories(nb) > maxfact then begin maxfact := getzonefactories(nb); maxfactzone := nb; end; if getzonevalue(nb) > maxval then begin maxval := getzonevalue(nb); maxvalzone := nb; end; if (getzonevalue(nb) >= getzonevalue(n)) and (getzonefactories(nb) >= getzonefactories(n)) and (nb > max) then max := nb; end; end; if getzonefactories(n) < maxfact then orderautorouteresources(n,maxfactzone) else if maxvalzone <> -1 then begin if (getzonevalue(n) < maxval) and (getzonefactories(maxvalzone) >= getzonefactories(n)) then orderautorouteresources(n,maxvalzone); if (getzonevalue(n) = maxval) and (max > n) then orderautorouteresources(n,max); end; if (island = 1) and iszoneport(mycap) then orderautorouteresources(n,mycap); if ((crisis = 1) and (n = mycap)) or (findclosestenemyzone(n,5) <> -1) then orderbuildarmy(n,0,0,(res div 2),0); if getzonefactories(n) = 0 then begin if res > 24 then orderbuildfactory(n); end else if res > 24 then begin if getzonefactories(n) < getzonevalue(n) then orderbuildfactory(n) else orderbuildairforce(n,(res div 8),0,0,0,0); end else if (res > 3) and iszoneport(n) and (random(1,3) = 1) then begin if random(1,4) = 1 then orderbuildnavy(n,0,(res div 2),0,0,0,0,0) else orderbuildnavy(n,0,0,0,(res div 4),0,0,0); end else orderbuildarmy(n,0,0,(res div 2),0); end; end; {units} for n := 0 to getunitcount() - 1 do begin if getunitowner(n) = mynat then begin unitzone := getunitzone(n); shortest := 999999; disembzone := -1; dockzone := -1; myforce := getzoneforcecountattack(unitzone,true,false,false,true,false,false); maxvalenemy := -1; wstenemy := -1; wstneut := -1; sstfriend := -1; mev := -1; wef := 999999; wnf := 999999; sff := -1; if getunitclass(n) = 1 then begin if (ally <> -1) and (crisis = -1) and (getzoneforcecountattack(mycap,true,false,false,true,false,false) > (150 + pl)) then orderunitrebase(n,ally) else orderunitrebase(n,mycap); end else if getunitclass(n) = 2 then begin if getunitforcecount(n) > 200 then orderunitdividepct(n,50); if iszoneland(getunitzone(n)) then orderunitlaunch(n); if getunitboardedcount(n) > 0 then begin disembzone := findclosestenemyzone(unitzone,20); if (crisis = 1) and iszoneport(mycap) then if (truedistance(unitzone,mycap) < 10) then disembzone := mycap; if disembzone > -1 then begin if iszoneneighbor(disembzone,unitzone) then orderunitdisembarkall(n,disembzone) else begin for i := 0 to getzoneneighborcount(disembzone) - 1 do begin if not iszoneland(getzoneneighbor(disembzone,i)) then orderunitmove(n,getzoneneighbor(disembzone,i)); end; end; end; end else if (oldembark > -1) and (getunitforcecounttype(n,0) = 0) then begin for i := 0 to oldembark do begin if distance(unitzone,oldembzone[i]) < shortest then begin shortest := distance(unitzone,oldembzone[i]); dockzone := oldembzone[i]; end; end; if iszoneneighbor(unitzone,dockzone) then orderunitembarkall(n,dockzone) else begin for i := 0 to getzoneneighborcount(dockzone) -1 do begin if not iszoneland(getzoneneighbor(dockzone,i)) then orderunitmove(n,getzoneneighbor(dockzone,i)); end; end; end; if (getunitforcecounttype(n,0) = 0) and (ship <> -1) then if iszoneport(mycap) and (truedistance(unitzone,mycap) < 15) then orderunitmove(n,ship); end else begin cstenemy := findclosestenemyzone(unitzone,7); if cstenemy = -1 then begin mindist := 999999; for i := 0 to zones - 1 do begin if getzoneowner(i) <> -1 then if iszoneenemy(i) and (distance(unitzone,i) < mindist) then begin mindist := distance(unitzone,i); cstenemy := i; end; end; end; if cstenemy = -1 then cstenemy := mycap; dist := truedistance(unitzone,cstenemy); for i := 0 to getzoneneighborcount(unitzone) - 1 do begin nb := getzoneneighbor(unitzone,i); if iszoneallied(nb) then begin if getzoneforcecountattack(nb,true,false,false,true,true,false) > sff then begin sff := getzoneforcecountattack(nb,true,false,false,true,true,false); sstfriend := nb; end; td := truedistance(nb,cstenemy); if (td < dist) or (td = 1) then targzone[unitzone] := nb; end else if iszoneenemy(nb) then begin if getzoneforcecountattack(nb,false,true,false,true,true,false) < wef then begin wef := getzoneforcecountattack(nb,false,true,false,true,true,false); wstenemy := nb; end; if getzonevalue(nb) > mev then begin mev := getzonevalue(nb); maxvalenemy := nb; end; end else if getzoneowner(nb) <> -1 then begin if (getnationstance(mynat,getzoneowner(nb)) < 20) and (not isnationmajorpower(getzoneowner(nb))) and (getzoneforcecountattack(nb,false,true,true,true,true,false) < wnf) then begin wnf := getzoneforcecountattack(nb,false,true,true,true,true,false); wstneut := nb; end; end; end; a := 1; if (unitzone = mycap) and (getzoneforcecountattack(unitzone,true,false,false,false,true,false) < (150 + pl)) then a := 2; if maxvalenemy <> -1 then if (getzoneforcecountattack(maxvalenemy,false,true,true,true,true,true) - getzoneforcecountattack(maxvalenemy,true,false,false,true,false,false)) < ((myforce div a) * (1 - (getzoneborderdefense(maxvalenemy,unitzone) * 0.2)) * 0.9) then begin order[unitzone] := 1; {attack enemy with maximal value} targzone[unitzone] := maxvalenemy; end; if (wstenemy <> -1) and (order[unitzone] = -1) then if (wef - getzoneforcecountattack(wstenemy,true,false,false,true,false,false)) < ((myforce div a) * (1 - (getzoneborderdefense(wstenemy,unitzone) * 0.2)) * 0.9) then begin order[unitzone] := 2; {attack weakest enemy} targzone[unitzone] := wstenemy; end; if (wstenemy <> -1) and (sff > myforce) and (order[unitzone] = -1) then begin order[unitzone] := 6; {move to strongest friend} targzone[unitzone] := sstfriend; end; if (wstneut <> -1) and (order[unitzone] = -1) then if (wnf - getzoneforcecountattack(wstneut,true,false,false,true,false,false)) < ((myforce div a) * (1 - (getzoneborderdefense(wstneut,unitzone) * 0.2)) * 0.5) then begin order[unitzone] := 3; {attack weakest neutral} targzone[unitzone] := wstneut; end; if (order[unitzone] = -1) and (targzone[unitzone] <> -1) then order[unitzone] := 7; {move closer to enemy} if crisis = 1 then if (truedistance(unitzone,mycap) < 5) then for i := 0 to getzoneneighborcount(unitzone) - 1 do begin nb := getzoneneighbor(unitzone,i); if iszoneland(nb) then if distance(nb,mycap) < distance(unitzone,mycap) then begin targzone[unitzone] := nb; if iszoneallied (nb) then order[unitzone] := 8 else order[unitzone] := 4; {help own capital} end; end; if ally <> -1 then if (truedistance(unitzone,ally) < 5) and (order[unitzone] <> 4) and (order[unitzone] <> 8) then for i := 0 to getzoneneighborcount(unitzone) - 1 do begin nb := getzoneneighbor(unitzone,i); if iszoneland(nb) then if distance(nb,ally) < distance(unitzone,ally) then begin targzone[unitzone] := nb; if iszoneallied (nb) then order[unitzone] := 9 else order[unitzone] := 5; {help ally capital} end; end; if (myforce > 200) and ((crisis = -1) or (unitzone <> mycap)) and iszoneport(unitzone) and (order[unitzone] = -1) then begin newembark := newembark + 1; {waiting for embark} if newembark > 9 then newembark := 9; newembzone[newembark] := unitzone; end; if unitzone <> mycap then wait := -1 else begin wait := 1; for i := 0 to getzoneunitcount(unitzone) - 1 do begin half := i div 2; if (getzoneunit(unitzone,i) = n) and ((half * 2) = i) and (crisis = -1) then wait := -1; end; end; if (order[unitzone] < 6) and (wait = -1) then orderunitinvade(n,targzone[unitzone]); if (order[unitzone] > 5) and (wait = -1) then orderunitmove(n,targzone[unitzone]); end; end; end; for n := 0 to 9 do setbraindata('emb' + inttostr(n),inttostr(newembzone[n])); {end}