{ A smarter Japan AI } const LAND = 0; const AIR = 1; const SEA = 2; const TRANSPORT = 9; NbrZones := GetZoneCount(); NbrUnits := GetUnitCount(); NbrNations := GetNationCount(); CurrentPlayer := GetCurrentPlayer(); Version( 4.0 ); US := -1; USSR := -1; Germany := -1; France := -1; For i := 0 to getnationcount() - 1 do begin name := getnationname(i); If name = 'United States' then US := i; If name = 'USSR' then USSR := i; If name = 'Germany' then Germany := i; If name = 'France' then France := i; end; {Diplomatics} like := - 100; friend := -1; points := 0; For i := 0 to NbrNations - 1 do begin stance := getnationstance(CurrentPlayer, i); npoints := 0; If isnationmajorpower(i) then npoints := 1; If (stance > like) AND (i <> USSR) AND (stance < 100) AND (npoints >= points) AND ( isnationactive(i) ) AND (i <> CurrentPlayer) then begin friend := i; points := npoints; like := getnationstance(CurrentPlayer, i); end; end; If getnationdiplomaticactions(CurrentPlayer) > 0 then If friend <> -1 then orderdiplomatic(friend, 7); MyCap := findzonename('Japan'); OrderChangeResearchSpending(20); OrderChangeResearchLevel(0, 100); nokorea := false; Port := findzonename('Korea'); If getzoneowner(Port) <> CurrentPlayer then begin Port := findzonename('Japan'); nokorea := true; end; factory := 0; center := -1; For i := 0 to NbrZones - 1 do begin If (getzoneowner(i) = CurrentPlayer) AND (iszoneport(i)) then orderautorouteresources(i, Port); If (getzonefactories(i) > factory) AND (getzoneowner(i) = CurrentPlayer) AND (i <> MyCap) then begin factory := getzonefactories(i); center := i; end; end; If nokorea then center := Port; If center = -1 then center := Port; If (getzonefactories(center) < getzonevalue(center)) AND (getzoneresources(center) > 25) then orderbuildfactory(center); OrderGlobalRouteResources(center, 20); f := 5 * getzonefactories(center); Troops := getzoneresources(center) div 2; If Troops > f then Troops := f; Orderbuildarmy(center, Troops, 0, 0, 0); setarray( AttackTroops, NbrZones ); For i := 0 to NbrZones - 1 do AttackTroops[i] := -1; zKorea := findzonename('Korea'); zGermany := findzonename('Germany'); zManchuria := findzonename('Manchuria'); zVladivostok := findzonename('Vladivostok'); zRussia := findzonename('Inner Russia'); zFrance := findzonename('Northern France'); zSA := findzonename('South Africa'); {african := false; for i := 0 to NbrUnits - 1 do If getunitclass(i) = Land then If isnationalliedwith(CurrentPlayer, getunitowner(i)) then If distance(zSA, getunitzone(i)) < distance(getunitzone(i), zGermany) then african := true;} for i := 0 to NbrUnits - 1 do begin if ( GetUnitOwner( i ) = CurrentPlayer ) then begin uc := GetUnitClass( i ); nCode := GetUnitID( i ); sCode := IntToStr( nCode ); uZone := getunitzone(i); if ( uc = LAND ) then begin If AttackTroops[uZone] = -1 then AttackTroops[uZone] := i else orderunitmerge(i, AttackTroops[uZone]); If getzoneowner(zKorea) <> CurrentPlayer then nTarget := zKorea else if getzoneowner(zManchuria) <> CurrentPlayer then nTarget := zManchuria else if getzoneowner(zVladivostok) <> CurrentPlayer then nTarget :=zVladivostok else if (isnationactive(USSR)) AND (getzoneforcecountattack(uZone, true, false, false, true, true, true) < getzoneforcecountdefense(zRussia, false, true, true, true, true, true)) then begin nTarget := -1; dist := 9999999; for j := 0 to getzoneneighborcount(zRussia) - 1 do begin tzone := getzoneneighbor(zRussia, j); ndist := distance(uZone, tzone); If (getzoneowner(getzoneneighbor(zRussia, j)) = USSR) AND (ndist < dist) then begin nTarget := tzone; dist := ndist; end; end; If nTarget = -1 then nTarget := findzonename('Lower Urals'); end else if isnationactive(USSR) then nTarget := zRussia else begin If (NOT isnationactive(Germany)) OR ((getbraindata(IntToStr(getunitid(i))) = 'a') OR ((getbraindata(IntToStr(getunitid(i))) = '') AND (random(1, 100) > 50))) then begin nTarget := FindClosestEnemyZone( GetUnitZone( i ), 20 ); setbraindata(IntToSTr(getunitid(i)), 'a'); end else begin nTarget := zGermany; setbraindata(inttostr(getunitid(i)), 'g'); end end; neighbor := -1; dist := 9999999; If nTarget >= 0 then begin For j := 0 to getzoneneighborcount(uZone) - 1 do begin tZone := getzoneneighbor(uZone, j); ndist := distance(tZone, nTarget); If (iszoneland(tZone)) AND (ndist < dist) AND ((tZone <> zRussia) OR (nTarget = zRussia))then begin neighbor := tZone; dist := ndist; end; end; end; if ( nTarget >= 0 ) AND (neighbor >= 0) then begin if ((getzoneowner(neighbor) = CurrentPlayer) OR (isnationalliedwith(CurrentPlayer, getzoneowner(neighbor)))) OR (getzoneowner(nTarget) = CurrentPlayer) then OrderUnitMove( i, nTarget ) else OrderUnitInvade( i, neighbor ); end; If (getzonename(uZone) = 'Japan') OR (getzonename(uZone) = 'Hokkaido') then orderunitmove(i, MyCap) end else if ( uc = AIR ) then begin if ((GetZoneOwner( GetUnitZone( i ) ) <> CurrentPlayer) AND (NOT iszoneallied(uZone))) AND (getunitbasezone(i) <> -1) then begin if GetZoneForceCount( GetUnitZone( i ), false, true, true, true, true, true ) = 0 then begin OrderUnitReturnToBase( i ); end; end else begin If getunitorder(i) <> 0 then begin orderunitreturntobase(i); end else begin If isnationactive(France) then bigtarg := zFrance else if (iszoneenemy(zManchuria)) OR (getbraindata(IntToSTr(getunitid(i)) + 'rm') = '') then begin bigtarg := zManchuria; setbraindata(IntToStr(getunitid(i)) + 'rm', '1'); end { else if (iszoneenemy(zSA)) AND (African) then bigtarg := zSA} else if isnationactive(USSR) then bigtarg := zRussia else bigtarg := findzonename('England'); hitrussia := iszoneembattled(bigtarg); If hitrussia then hitrussia := getunitrange(i) >= truedistance(uZone, bigtarg); If hitrussia then begin orderunitairstrike(i, bigtarg) end else begin dist := 999999; nTarget := -1; for j := 0 to NbrZones - 1 do begin ndist := distance(j, zKorea); If j <> bigtarg then if ndist < dist then if getzoneforcecount(j, false, true, false, true, false, false) > 0 then if getzoneowner(j) <> -1 then if isnationmajorpower(getzoneowner(j)) then if truedistance(uZone, j) <= getunitrange(i) then begin nTarget := j; dist := ndist; end; end; If (nTarget <> -1) then begin orderunitairstrike(i, nTarget) end else begin dist := 999999; nBase := -1; for j := 0 to NbrZones - 1 do if (( (iszoneallied(j)) AND ((isnationactive(France)) OR (NOT isnationactive(USSR)) )) OR (getzoneowner(j) = CurrentPlayer) ) AND (distance(j, bigtarg) < dist) then if truedistance(j, uZone) <= getunitrange(i) * 3 then begin dist := distance(j, bigtarg); nBase := j; end; If nBase <> -1 then begin orderunitrebase(i, nBase); end; end; end; end; end; end else if ( uc = SEA ) then begin Korea := findzonename('Korea'); If getunitboardedcount(i) > 0 then begin If Iszoneneighbor(Korea, uZone) then begin orderunitdisembarkall(i, Korea) end else begin dist := 99999; czone := -1; for j := 0 to getzoneneighborcount(Korea) - 1 do If NOT iszoneland(getzoneneighbor(Korea, j)) then If truedistance(getzoneneighbor(Korea, j), uZone) < dist then begin dist := truedistance(getzoneneighbor(Korea, j), uZone); czone := getzoneneighbor(Korea, j); end; orderunitmove(i, czone); end; end else begin If Iszoneneighbor(MyCap, uZone) then begin If getzoneforcecount(MyCap, true, false, false, true, false, false) > 5 then orderunitembarkall(i, MyCap) end else begin for j := 0 to getzoneneighborcount(Port) - 1 do If NOT iszoneland(j) then orderunitmove(i, j); end; end; end; end; end;