Are you, in fact, a pregnant lady who lives in the apartment next door to Superdeath's parents? - Commodore

Create an account  

 
Game Report: Easy game, vacant capital circa 1401

Quote: I'd like to see the AI economy more closely resemble human players economy.

We all do but the AI will never be smart enough for that. Doing so requires the ability to coordiante movement and attacks and fight effectively using a small number of troops.
But you can prove I'm wrong. Here is the entire "select production" procedure. Suggest improvements that enable the AI to perform better on a lower gold or maintenance advantage - while also maintaining that some AI personalities prefer some types of buildings, others prefer others.

Code:
org 0x0E8

; bp+6 - WIZARD
; bp+8 - CITY

; bp-2 - Best Priority
; bp-4 - Best thing to build
; bp-6 - Nofavailable things to build
; bp-8 - Wizard objective
; bp-A - Own and enemy cities on continent
; bp-C - Owned settlers on continent
; bp-E - City continent
; bp-10 - Nof Garrison units
; bp-12 - ORES
; bp-14 - Nof Engineers owned on continent
; bp-16 - Units allowed
; bp-18 - Stored production ID
; bp-1Ah - City plane
; bp-1Ch - City X
; bp-1Eh - City Y
; bp-20h - Nof own cities
; bp-22h - Nof own cities making Trade Goods
; bp-88h - list of things that can be built
; bp-8Ah - Own race
; bp-90h - Owned settlers on plane

push    bp
mov     bp, sp
sub     sp, 090h
push    si
push    di

jmp start

GetAvailableProduction:
lea     ax, [bp-88h]
push    ax
lea     ax, [bp-4]
push    ax
lea     ax, [bp-2]
push    ax
lea     ax, [bp-6]
push    ax
push    [bp+8]
;call    j_CreateAvailableBuildingList
db 9Ah,43h,00,0C0h,01
add     sp, 0Ah
retn

random:
push ax
db 9Ah,0D8h,00,0B0h,00
pop dx
retn

ProductionAnalisys:
;call ProductionAnalysis
db 9Ah, 98h, 00, 10h, 05
retn

getunrest:
push word ptr [bp+8]
db 9Ah,0A2h,00,70h,04
pop dx
retn


RacePreference:
db 0 ; Barbarian
db 5 ; Beastmen
db 6 ; Dark Elf
db 6 ; Draconain
db 5 ; Dwarf
db 1 ; Gnoll
db 2 ; Halfling
db 5 ; High Elf
db 5 ; High Men
db 2 ; Klackon
db 2 ; Lizardmen
db 4 ; Nomad
db 3 ; Orc
db 5 ; Troll
db 0 ;
db 0 ;

;=================================================================
;=================================================================
; START HERE
;=================================================================
;=================================================================
; INITIALIZE DATA
;=================================================================


start:
call getcurrenttown
cmp byte ptr es:[bx+14h],0
jnz notoutpost
mov ax,0
jmp buildthis ; Outpost, always set it to "None"
notoutpost:

call GetavailableProduction

mov ax,[bp+8]
call ProductionAnalisys

mov al,ch
cbw
mov [bp-10h],ax ; Nof garrison units
mov al,cl
cbw
mov [bp-12h],ax ; Ores

mov [bp-0Ah],dx ; Own and Enemy city count

; Store Objective
call getwiz
mov ax,[bx-611Ch]
mov [bp-8],ax

; Store town race, location
call getcurrenttown
mov al,es:[bx+0Eh]
cbw
mov [bp-8Ah],ax
mov al,es:[bx+0Fh]
cbw
mov [bp-1Ch],ax

mov al,es:[bx+10h]
cbw
mov [bp-1Eh],ax

mov al,es:[bx+11h]
cbw
mov [bp-1Ah],ax

;=================================================================
; NETURAL CITY EXCEPTIONS
;=================================================================

cmp [bp+6],5
jnz wecanstart
mov ax,9
call random
dec ax
mov word ptr [bp-16h],ax ; 11.1% chance for producing a building
or ax,ax
jz notbuildx
cmp [bp-10h],9
jge nedonothing
call getcurrenttown
mov al,es:[bx+14h]
sal al,1
cmp al,[bp-10h]
jg notbuildx
nedonothing:
mov ax,1 ; Trade Goods - Do not build a unit if already having max possible in garrison - would cause losing one, reducing garrison diversity!
jmp buildthis
notbuildx:
jmp NEUTRAL1
wecanstart:

;=================================================================
; TRADE GOODS RATIO CALCULATION
;=================================================================

xor di,di
mov word ptr [bp-20h],di
mov word ptr [bp-22h],di

lph1:
cmp di,[0BD94h]
jg donetownanal

mov     ax, di
call gettowndata
mov     al, es:[bx+12h]
cbw
cmp     ax, [bp+6]
jnz skip
;Owned city
inc word ptr [bp-20h] ;
cmp     word ptr es:[bx+1Ch], 1
jnz skip
inc word ptr [bp-22h] ; Trade Goods cities
skip:
inc di
jmp lph1

donetownanal:
cmp [bp-22h],0
jnz zerosafe3
mov [bp-22h],1
zerosafe3:

;=================================================================
; VIZIER CANNOT CHANGE FROM UNITS
;=================================================================

cmp [bp+6],0
jnz notvizier
; If it's the human player's city then
; it's the Grand Vizier!

call getcurrenttown
cmp     word ptr es:[bx+1Ch], 64h ; Set to make a unit? Skip!
jg donotchange
mov word ptr [bp-16h],0
jmp VIZIER
notvizier:

;=================================================================
; CITY CONTINENT
;=================================================================

mov     ax, [bp-1Ah]
mov     dx, 960h
imul    dx
les     bx, [9CD0h] ;ContinentIDforMapLocation
add     bx, ax
mov     ax, [bp-1Eh]
mov     dx, 3Ch ; '<'
imul    dx
add     bx, ax
add     bx, [bp-1Ch]
mov     al, es:[bx]
mov     ah, 0
mov     [bp-0Eh], ax

;=================================================================
; COUNT OWNED SETTLERS AND ENGINEERS
;=================================================================

mov word ptr [bp-0Ch],0
mov word ptr [bp-090h],0
mov word ptr [bp-014h],0

xor di,di
lph2:
cmp di,[0BD92h] ; Max units
jge doneunits

mov     ax, di
mov     cl, 5
shl     ax, cl
les     bx, [9EC2h]
add     bx, ax
mov     al, es:[bx+3]
cbw
cmp     ax, [bp+6]
jnz notowned
; Own unit
mov     al, es:[bx+2]
cbw
cmp     ax, [bp-1Ah]
jz sameplane
cmp byte ptr es:[bx+14h], 1
jz sameplane
jmp notowned
; Unit is owned and on the same plane as this city so it's relevant
sameplane:

push es
push bx

mov     al, es:[bx+5]
mov     ah, 0
mov     dx, 24h ; '$'
imul    dx
mov     bx, ax
push bx
test    word ptr [bx+1BAh], 20h
jz notsettler
inc word ptr [bp-090h]   ; Settler, same plane
notsettler:

pop ax
pop bx
pop es
push ax

mov al,es:[bx+2]
cbw
mov     dx, 960h
imul    dx
mov cx,ax
mov     al, es:[bx+1]
cbw
mov     dx, 3Ch ; '<'
imul    dx
add cx,ax
mov     al, es:[bx]
cbw
add     cx, ax
les bx, [9CD0h]
add bx,cx
mov al,es:[bx]
xor ah,ah
cmp ax,[bp-0Eh]

pop bx
jnz Diffcontinent

test    word ptr [bx+1BAh], 20h
jz notsettler2
inc word ptr [bp-0Ch]    ;Settler, same continent
notsettler2:

cmp     byte ptr [bx+1B2h], 0
jle     notengi
inc word ptr [bp-14h]
notengi:

Diffcontinent:

notowned:
inc di
jmp lph2
doneunits:

;=================================================================
; SETTLER OR ENGINEER PRODUCED ON PLANE ALREADY?
;=================================================================

xor di,di
lph32:
cmp di,[0BD94h]
jge doneagain2

mov     ax, di
call gettowndata
mov     al, es:[bx+12h]
cbw
cmp     ax, [bp+6]
jnz nextc2 ; ignore enemy cities

cmp di,[bp+8] ; ignore itself
jz nextc2

mov     al, es:[bx+11h]
cmp al,[bp-1Ah]
jnz nextc2 ; Ignore other plane, only same plane counts.

mov ax, es:[bx+1Ch] ; Now producing?
cmp     ax, 64h ; 'd'
jl      nextc2
add     ax, 0FF9Ch
mov     dx, 24h ; '$'
imul    dx
mov     bx, ax
cmp     byte ptr [bx+1B2h], 0
jle     short loc_EAE7A2
mov     word ptr [bp-14h], 1 ; Already producing engineer on plane
loc_EAE7A2:


test    word ptr [bx+1BAh], 20h ; already producing settler
jz      short loc_EAE6E2
inc     word ptr [bp-090h] ; +1 Settler on plane (will be produced so no different than already existing)

mov     ax, di
call gettowndata
mov al,es:[bx+11h]
cbw
mov     dx, 960h
imul    dx
mov cx,ax
mov     al, es:[bx+10h]
cbw
mov     dx, 3Ch ; '<'
imul    dx
add cx,ax
mov     al, es:[bx+0Fh]
cbw
add     cx, ax
les bx, [9CD0h]
add bx,cx
mov al,es:[bx]
xor ah,ah
cmp ax,[bp-0Eh]
jnz diffconti2
inc     word ptr [bp-0Ch] ; +1 Settler on continent (will be produced so no different than already existing)
diffconti2:

loc_EAE6E2:
nextc2:
inc di
jmp lph32
doneagain2:


;=================================================================
; SETTLER NEEDED DECISION
;=================================================================

; City has enough POP?
mov     ax, [bp+8]
call gettowndata
cmp     byte ptr es:[bx+14h], 3
jl nosettler
;=====================================
; Reached max amount of towns?
cmp word ptr [0BD94h],99
jge nosettler
;=====================================
mov ax,1
cmp [0BD9Ah],0 ; Land Size - Tiny, 1 settler
jz tiny
inc ax ; Otherwise 2 settlers
cmp [0BD9Ah],2 ; Land Size - Small or Fair
jle tiny ; Otherwise check diffculty
cmp [0BD96h],2 ; Extreme or higher
jle tiny
call getwiz   ; is ax safe!
cmp byte ptr [bx-60C9h],0
jz tiny ; Not Myrran
cmp byte ptr [-60C9h],0
jnz tiny ; Human player is Myrran, plane too crowded for turbo settling strategy
cmp word ptr [0BD90h],100
jg tiny ; Turn>100 don't boost settling
add ax,2 ; +2 settler if large land, myrran ai alone, early game
tiny:
cmp word ptr [bp-0Ch],ax  ; 1 Settler on Tiny per continent, 2 otherwise
jge nosettler  ; Continent has enough, don't need
add ax,2
cmp word ptr [bp-090h],ax ; If globally 3 or 4 settlers total on plane, do not make more as well!
jge nosettler
settler:
mov word ptr [bp-0Ch],1     ; Settler needed
jmp donex
nosettler:
mov word ptr [bp-0Ch],0     ; Settler unnecessary
donex:

;============================================================================
; Is this city the best RACE for settler on the plane?
;============================================================================

xor di,di
lph3:
cmp di,[0BD94h]
jge doneagain
mov     ax, di
call gettowndata
mov     al, es:[bx+12h]
cbw
cmp     ax, [bp+6]
jnz nextc ; ignore enemy cities

cmp di,[bp+8] ; ignore itself
jz nextc

mov     al, es:[bx+11h]
cmp al,[bp-1Ah]
jnz nextc ; Ignore other plane, only same plane counts. Even if better race exists on other plane, it might not be able to get to this one.

mov     bl, es:[bx+0Eh]
xor     bh, bh
mov     al, cs:[bx+Racepreference]
mov     bl, [bp-08Ah]
cmp     al, cs:[bx+Racepreference]
jle     nextc
mov     word ptr [bp-0Ch], 0
nextc:
inc di
jmp lph3
doneagain:

;========================================================================
; MANDATORY BUILDINGS (Sawmill, Smithy, Fighter's, Stables, University)
;========================================================================

call getcurrenttown

; Force Sawmill
cmp     byte ptr es:[bx+2Eh], 0FFh
jnz havesawmill
mov ax,0Fh
jmp buildthis
havesawmill:

; Force Smithy
cmp     byte ptr es:[bx+27h], 0FFh
jnz havesmithy
mov ax,8
jmp buildthis
havesmithy:

; Force Fighter's Guild sometimes
cmp     byte ptr [bp-090h], 2
jl notfighter
cmp     word ptr [bp-10h], 4
jge fighter
mov     word ptr [bp-0Ch], 0 ; Already have 2 settlers globally and fewer than 4 units, don't make settler!
jmp notfighter
fighter:
cmp byte ptr [-60C9h],0
jnz myrranship
call getwiz
cmp byte ptr [bx-60C9h],0
jz notmyrranship
myrranship: ; If human or AI is Myrran priorize ship access anyway - early land grab is critical with fewer wizards on own plane!
cmp word ptr [0BD90h],50
jg notmyrranship

; build ship wright's guild
call getcurrenttown
cmp     byte ptr es:[bx+2Bh], 0FFh
jnz notmyrranship

xor di,di
productionloop2:
cmp     di, [bp-6]
jge finally2

mov     bx, di
shl     bx, 1
lea     ax, [bp-88h]
add     bx, ax

cmp byte ptr [bx],12; Production candidate list element
jz doshipwright
inc di
jmp productionloop2
doshipwright:
mov ax,12
jmp buildthis

finally2:
notmyrranship:

call getcurrenttown

cmp     [bp-8Ah], 5 ; Gnoll
jz     Gnoll1
cmp     [bp-8Ah], 4 ; Dwarf
jz     Dwarf1
cmp     byte ptr es:[bx+24h], 0FFh
jnz     notfighter
mov ax,5 ; Fighter's Guild
jmp buildthis
Dwarf1:
cmp     byte ptr es:[bx+3Fh], 0FFh
jnz     NotBH
mov ax,20h   ; Builder's Hall
jmp buildthis
notBH:
cmp     byte ptr es:[bx+33h], 0FFh
jnz notfighter
mov ax,14h  ; Build University (for Steam Cannons)
jmp buildthis
Gnoll1:
cmp     byte ptr es:[bx+28h], 0FFh
jnz     NotFighter
mov ax,9 ; Stables (for Wolf Riders and production)
notfighter:

;======================================================
;======================================================
; UNIT OR BUILDING ROLL
;======================================================
;======================================================

xor di,di

cmp     byte ptr es:[bx+5Bh], 0
jz notaltar
add di,6 ; +6 Altar of Battle
jmp notcollege

notaltar:

cmp     byte ptr es:[bx+22h], 0FFh
jz notbarracks
inc di ; +1 Barracks
notbarracks:

cmp     byte ptr es:[bx+26h], 0FFh
jz notcollege
add di,3 ; +3 War College
notcollege:

cmp     byte ptr es:[bx+28h], 0FFh
jz notstables
inc di ; +1 Stables
cmp [bp-8Ah],5 ; Gnoll
jz betterstables
cmp [bp-8Ah],11 ; Nomad
jz betterstables
jmp notstables
betterstables:
add di,4 ; Horsebowmen or Wolf Riders!
notstables:

cmp     byte ptr es:[bx+24h], 0FFh ; Fighter's Guild
jz sk5
add di,4
cmp [bp-8Ah], 0
jnz sk6
add di,8    ; Additional +8 if Barbarian
sk6:
cmp [bp-8Ah], 5
jnz sk5
add di,5    ; Additional +5 if Gnoll
sk5:

cmp     byte ptr es:[bx+25h], 0FFh ; Armorer's Guild
jz sk7
add di,6
sk7:

cmp     byte ptr es:[bx+2Ah], 0FFh ; Fantastic Stable
jz sk8
add di,6
sk8:

;------------------------------------Alchemist's Guild
cmp     byte ptr es:[bx+32h], 0FFh ;
jz sk9
add di,3

; Mithril, Adamant, Orihalcon

test  [bp-12h],2
jz notada
sal di,1 ; Double bonus from buildings if adamantium
jmp notmit
notada:

test  [bp-12h],1
jz notmit
mov ax,di
sar ax,1
add di,ax ; +50% bonus from buildings if mithril
notmit:

test  [bp-12h],4
jz notori
add di,3
call magician
or ax,ax
jz notori
add di,7 ; +10 if Orihalcon magicians, +3 if just Orihalcon
notori:

sk9:
cmp     byte ptr es:[bx+34h], 0FFh ; Wizard's Guild
jz sk10
call Magician
or ax,ax
jz sk10
add di,4 ; Magicians available!
sk10:

test [bp-12h],8
jz notiron
add di,2
notiron:

test [bp-12h],10h
jz notcoal
add di,4
notcoal:

mov dx,[bp-0Ah]

cmp dl,dh
jg owncontinent
sal di,1 ; double unit priority if shared continent with enemy

sar dh,1
cmp dl,dh ; Enemy has at least twice the presence
jg owncontinent
cmp     byte ptr es:[bx+24h], 0FFh ; Fighter's Guild
jz owncontinent
mov word ptr [bp-16h],1 ; Force unit production 100%
jmp nounits
owncontinent:

cmp [bp-8],1
jnz notmilitarist
add di,4 ; +40% for Militarist
notmilitarist:

cmp [bp-8],3
jnz notperf
sub di,4 ; -40% for Perfectionist
notperf:

add di,7 ; Base value

cmp [0BD92h],1880 ; Global max units almost exceeded, stop production!
jl ok4
mov di,1
ok4:

mov word ptr [bp-16h],0
mov ax,di
call random
cmp ax,[bp-10h]
jle nounits
inc word ptr [bp-16h]
nounits:


cmp [bp-8Ah],0 ; Barbarians cannot build alchemist guilds!
jz notorex18
test [bp-12h],7
jz notorex18
call getcurrenttown
cmp     byte ptr es:[bx+32h], 0FFh ; Have mithril/ori/adamant and no alchemist guild yet? buildings over units!
jnz notorex18
mov word ptr [bp-16h],0
notorex18:

cmp     word ptr [bp-10h], 3
jg enoughunits
mov word ptr [bp-16h],1 ; Fewer than 4 units? Make a unit!
enoughunits:

;======================================================
;======================================================
;======================================================
;======================================================
; SELECT PRODUCTION
;======================================================
;======================================================
;======================================================
;======================================================

NEUTRAL1:
VIZIER:

mov word ptr [bp-2],-100
mov word ptr [bp-4],1 ; Trade goods

xor di,di

productionloop:
cmp     di, [bp-6]
jge finally

mov     bx, di
shl     bx, 1
lea     ax, [bp-88h]
add     bx, ax

mov cx,[bx]; Production candidate list element

xor si,si

cmp cx,100
jl buildingevalute

;======================================================
;======================================================
; UNIT PRIORITIES
;======================================================
;======================================================

cmp [bp+6],0
jz cantdothis ; Grand Vizier cannot build units, ever!!!

mov [bp-18h],cx
sub cx,100

;----------
; Settlers
;----------
call getunittype
test    word ptr [bx+1BAh], 20h
jz notsettler7

cmp [bp+6],5
jz cantdothis ; No settler for neutrals

cmp     word ptr [bp-0Ch], 0 ; "Settler Needed"?
jz cantdothis
mov ax,1
cmp [0BD90h],30
jle notearly
inc ax
notearly:
cmp [0BD90h],100
jle notearly2
inc ax
inc ax
notearly2:
call random ; 100% in first 30 turns, 50% after, 25% after turn 100
cmp ax,1
jnz cantdothis
mov ax, word ptr [bp-18h]
jmp buildthis
notsettler7:

;----------
; Engineers
;----------
call getunittype
cmp     byte ptr [bx+1B2h], 0
jz notengineer7

cmp [bp+6],5
jz cantdothis ; No engineer for neutrals

cmp [bp-14h],0
jnz notengineer7
mov ax,4
call random
cmp ax,1
jnz cantdothis
mov ax, word ptr [bp-18h]
jmp buildthis
notengineer7:

;----------
; Ships
;----------
call getunittype
cmp     byte ptr [bx+1B0h], 0
jle notship

cmp [bp+6],5
jz cantdothis ; No ship for neutrals

call getcurrenttown
cmp cx,36
jz isgalley
cmp cx,37
jnz iswarship
; Trireme - Don't if Ship Yard, build Galley instead
cmp byte ptr es:[bx+2Ch],0FFh
jnz cantdothis ; No Trireme if Galley is available
isgalley:
; Galley or Trireme - Don't if Maritime Guild, build Warship instead
cmp byte ptr es:[bx+2Dh],0FFh
jnz cantdothis ; No Galley if Warship available
iswarship:


push cx
mov     ax, 5
sub     ax, [0BD9Ah] ;Landmass ;word_4283A
mov     bx, [0BD90h] ; Turns ;word_42830
mov     cl, 5
sar     bx, cl
mul     bx
add     ax, 6
pop cx

mov     bx, [bp-1Ah]
cmp     al, [bx-6F6Ch]
jb cantdothis ; Already too many ships owned on plane!

mov ax,word ptr [bp-18h]
cmp byte ptr [bx-6F6Ch],0
jz buildthis ; Zero ships? Immeditely build one!
mov ax,5 ; Otherwise 20% we build a ship
call random
cmp ax,1
jnz cantdothis
mov ax, word ptr [bp-18h]
jmp buildthis

notship:
; If neither
cmp word ptr [bp-16h],0 ; If not "unit wanted" then don't do random units - settler/engineer/ship is ok!
jz cantdothis

;----------------------
; Priests or Shamans (Purify and Healer)
;----------------------
call getunittype
mov ax,7
cmp cx,75 ; Draconian Air Ship - always build some for transport even if obsoleted by other units and cannot be built
jz wantthis
cmp cx,113 ; High Men Paladins - always build some for Holy Bonus even if obsoleted by other units and cannot be built (unlikely but magicians with orihalcon and figure bonus with many levels can...)
jz wantthis
test    word ptr [bx+1BAh], 4000h
jz notshaman
mov ax,12
wantthis:
call random
cmp ax,1
jnz notshaman
mov ax, word ptr [bp-18h]
jmp buildthis ; Do shaman 1/12 of time if available - ensures there are healers and purifiers even if the unit itself is obsolete
; But if not, use normal chance - it might be the best unit the city has!
notshaman:

; Military unit production priority
call getunittype
mov al,[bx+1B5h]
cbw
mov si,ax ; Priority load from unit tables!

cmp [bp+6],5
jz unitending ; Neutrals don't use any logic for units, just build according to base priorities

mov al,[bx+1B1h] ; Figures

mov ah,[bx+19Fh] ; Ranged Type

push ax
mov al,[bx+1B4h] ; Movement flags

mov dx,[bp-0Ah]
or dh,dh
jnz haveenemyepresence
; No enemy presence on continent. Slightly prefer flier/swimmer
test al,0Eh ; Fly, Swim, Sail
jz haveenemyepresence
add si,6 ; Major priority boost to intercontinental unit!
cmp [bp-8],4
jnz skip7748
add si,6 ; Expansionist, greatly prefer flying units
skip7748:

haveenemyepresence:

call getcurrenttown

pop dx ; Ranged Type, Figures
mov al,dl
cbw
push ax ; Figures

xor ax,ax ; Number of level/ore stat gain
cmp     byte ptr es:[bx+5Bh], 0
jz notaltar3
mov ax,3
notaltar3:

cmp     byte ptr es:[bx+32h], 0FFh ;
jz doneboosting ; Ignore ores if no alchemist's guild!

cmp dh,30
jle nonmagic
cmp dh,100
jge nonmagic
; Magical ranged unit
test  [bp-12h],4
jz doneboosting
add si,10 ; Orihalcon, boost priority of magic ranged unit greatly!
jmp doneboosting

nonmagic:
test  [bp-12h],2 ; Adamantium
jz notada2
inc ax ; Worth 2 levels
inc ax
jmp notmit2
notada2:

test  [bp-12h],1 ; Mithril
jz notmit2
inc ax ; Worth 1 level
notmit2:

doneboosting:

cmp     byte ptr es:[bx+22h], 0FFh
jz xkxkx1
inc ax
xkxkx1:
cmp     byte ptr es:[bx+26h], 0FFh
jz xkxkx2
inc ax
xkxkx2:

call getwiz
cmp     byte ptr [bx-5CA3h], 0
jz nocrusade
inc ax
nocrusade:
cmp     byte ptr [bx-60D1h], 0
jz nowarlord
inc ax
nowarlord:

pop bx ; Figures get
imul bx
add si,ax ; +1/figures priority for each levelup - More figures benefit from levels more!

unitending:
mov cx, word ptr [bp-18h]
jmp checkpriority
buildingevalute:

;======================================================
;======================================================
; TRADE GOODS PRIORITY
;======================================================
;======================================================

cmp cx,1
jnz not1
; Trade Goods

cmp [bp+6],5
jz cantdothis

mov ax,[bp-20h]
xor dx,dx
idiv word ptr [bp-22h] ; Cities owned/Cities doing Trade Goods
cmp ax,3
jl cantdothis ; No more than 1/3 of cities can do Trade Goods at a time

call getcurrenttown
cmp byte ptr es:[bx+5Dh],20
jl cantdothis ; Don't if city has low production
cmp word ptr [0BD90h],50
jl cantdothis ; Not before turn 50
call getwiz
mov ax,[bx-5DE0h]
cmp ax,6000
jg cantdothis ; Don't do trade goods if over 6000 gold, but is default if nothing available
cmp ax,500
jge not1
add si,8 ; High priority below 500 gold, otherwise just basic priority
not1:

;======================================================
;======================================================
; HOUSING
;======================================================
;======================================================

cmp cx,2
jnz not2

cmp [bp+6],5
jz cantdothis

call getcurrenttown
cmp es:[bx+14h],5
jg cantdothis ; Never if pop>5
cmp es:[bx+15h],1
jg cantdothis ; Never if more than 1 farmer
mov si,20 ; Priority equal to basic buildings
not2:

;======================================================
;======================================================
; BUILDING PRIORITIES
;======================================================
;======================================================

cmp word ptr [bp-16h],0 ; If "unit wanted" then don't do any building
jnz canotdothis

cmp [bp+6],5
jz checkpriority ; Neutrals don't think and build at random

;======================================================
; GRAND VIZIER
;======================================================

cmp [bp+6],0
jnz notvizier2

mov bx,cx
mov al,cs:[bx+MilitaryTable]
cmp word ptr [9D22h],2
jz miliallow
mov al,cs:[bx+NonMilitaryTable]
miliallow:
cbw
cmp ax,0
jz cantdothis
add si,ax
mov ax,20
jmp vizierpriority
MilitaryTable:
db 0,0,0
;  BAR COL FIG ARM WAR SMI STA ANI FAN SWR SYA MAR SAW LIB SAG ORA ALC UNI
db 073,030,073,060,055,080,080,060,058,060,040,020,100,080,060,030,070,080
;  WIZ SHR AMP PAR CAT MAR BAN MER GRA FAR FOR BUI MEC MIN WAL
db 055,060,055,080,058,080,060,060,070,060,080,080,080,080,073
NonMilitaryTable:
db 0,0,0
;  BAR COL FIG ARM WAR SMI STA ANI FAN SWR SYA MAR SAW LIB SAG ORA ALC UNI
db 000,000,000,000,000,000,000,060,000,040,000,000,100,080,060,030,070,080
;  WIZ SHR AMP PAR CAT MAR BAN MER GRA FAR FOR BUI MEC MIN WAL
db 055,060,058,080,058,080,060,040,080,080,080,080,080,080,000

notvizier2:

;======================================================
; AI
;======================================================

cmp cx,7 ; War College
jz thistoo2
cmp cx,3 ; Barracks
jnz not3
thistoo2:
call Military
call EXP
not3:

cmp cx,18 ; Oracle
jz thistoo5
cmp cx,4 ; Colosseum
jnz not4
call Economy
thistoo5:
call Unrest
not4:

cmp cx,13 ; Ship Yard
jz thistoo9
cmp cx,14 ; Maritime Guild
jz thistoo9
cmp cx,9 ; Stables
jz thistoo1
cmp cx,11 ; Fantastic Stables
jz thistoo9
cmp cx,6 ; Armorer's Guild
jz thistoo1
cmp cx,5 ; Fighter's Guild
jz thistoo1
jmp not5
thistoo9:
cmp [bp-8],4
jnz skip449
add si,3 ; Expansionist, twice the chance for Naval buildings
skip449:
thistoo1:
call Military ; Pure Military Buildings
not5:


cmp cx,31 ; Forester's Guild
jz thistoo4
cmp cx,10 ; Animist's Guild
jz thistoo3
cmp cx,30 ; Farmer's Market
jz thistoo3
cmp cx,29 ; Granary
jnz not29
cmp [0BD96h],3
jl thistoo3
add si,20 ; Extreme and Impossible, Granary is priority building (gets built faster and extra worker/pop growth is worth more, also longer games mroe likely so better return on investment)
jmp thistoo3
thistoo4:
mov ax,[bp+8]

cmp [bp-8Ah],7
jnz thistoo3
call Military ; For High Elves, Forester's Guild is a Military building too!
thistoo3:
call Food
not29:

cmp cx,12
jnz not12
; Ship Wright's Guild

cmp word ptr [0BD90h],30
jl cantdothis ; Don't bother with ships before turn 30

cmp [bp-8],4
jnz skip448
add si,3 ; Expansionist, twice the chance for Naval buildings
skip448:

call getwiz
cmp [bx-5EA8h],2 ; Floating Island known, don't rush ship wrigth
jz nonbasic

mov     bx, [bp-1Ah]
cmp byte ptr [bx-6F6Ch],0  ; 0 ships owned
jnz nonbasic
add si,21
mov ax,[0BD9Ah]; Land size
sal ax,2
sub si,ax ; -4 priority for each landmass above "Tiny"
nonbasic:

call getcurrenttown
cmp     byte ptr es:[bx+3Fh], 0FFh
jz not12
call Economy ; Required for Merchant's Guilds if BH already done
not12:

cmp cx,16 ; Library
jnz not16
add si,20 ; Basic building
call Research

test [bp-12h],7
jz notorex56
add si,30 ; Very high priority if mithril/ori/adam
call military
jmp not16 ; And ignore Alchemist retort
notorex56:
not16:

cmp cx,17 ; Sages Guild
jnz not17
call Research
not17:

cmp cx,19 ; Alchmist Guild
jnz not19

call Military

test [bp-12h],7
jz notorex
add si,30 ; Very high priority if mithril/ori/adam
jmp not19 ; And ignore Alchemist retort
notorex:

call getwiz
cmp byte ptr [bx-60D2h],0
jz asds
sub si,5  ; Alchemist retort - less urgent to build A. Guild!
asds:
jmp amplifier ; Required for Amplifier Tower so gain its priority too!
not19:

cmp cx,20 ; University
jnz not20
call Research
call Production ; Required for Mecha Guilds
not20:

cmp cx,21 ; Wizard's Guild
jnz not21
call getcurrenttown
cmp byte ptr es:[bx+47h],0
jnz noturanus1
add si,3 ; Prefer is Uranus Bless
noturanus1:

call Research
call Power
call Magician
or al,al
jz not21
call Military ; counts as a Military building too is Magicians are available!
not21:

cmp cx,25 ; Cathedral
jz thistoo6
cmp cx,24 ; Parthenon
jz thistoo6
cmp cx,22 ; Shrine
jnz not22
thistoo6:
call Unrest
call Power
call Religion
not22:

cmp cx,23 ; Amplifying Tower
jnz not23

call Research ; Not a real research building but synergy with that - if more research is done, stronger spells can be used from the skill!

amplifier:
call getcurrenttown
cmp byte ptr es:[bx+47h],0
jnz noturanus2
add si,3 ; Prefer is Uranus Bless
noturanus2:

call getwiz
cmp byte ptr [bx-5CB0h],0
jz notbinding
add si,3 ; Want it more if AEther Binding
notbinding:

mov ax,[bx-60E0h] ; Casting Skilll
add ax,30
cmp ax,[0BD90h]
jg notlowskill
add si,7 ; Major priority boost if skill under (Turns-30)
notlowskill:
cmp [0BD96h],3
jl not23
add si,3 ; Some priority boost for extreme and impossible levels (faster to build, more gold to buy, casting skill multiplier higher)
not23:

cmp cx,28 ; Merchant's Guild
jz thistoo7
cmp cx,27 ; Bank
jz thistoo7
cmp cx,26 ; Marketplace
jnz not26
add si,20 ; Basic building
thistoo7:
call Economy
not26:

cmp cx,32 ; Builder's Hall
jnz not32
add si,10 ; Semi-Basic building - unlocks a lot of stuff and has low cost
not32:

cmp cx,33 ; Mecha
jz thistoo8
cmp cx,34 ; Miner
jnz not33
thistoo8:
call Production
not33:

cmp cx,35 ; City Walls
jnz not35
call Military
mov dx,[bp-0Ah]
cmp dl,dh
jg not35
; Equal or fewer cities than enemies on continent
add si,25 ; Wall priority very high
not35:


;*****







mov     ax, cx
mov     dx, 34h ; '4'
imul    dx
les     bx, [938Ch]
add     bx, ax
mov     ax, es:[bx+2Ch]
; AX= building cost
push ax
call getcurrenttown
mov bl,es:[bx+5Dh]
xor bh,bh
or bx,bx
jnz safezero
inc bx
safezero:
pop ax
push ax
xor dx,dx
idiv bx
cmp ax,12
jle nottoolong
; Check for buildings that are bought quickly
cmp cx,21 ; Wizard's Guild
jz nottoolong
cmp cx,23 ; Amplifying Tower
jz nottoolong
cmp cx,5 ; Fighter's Guild
jz nottoolong
sub si,7 ; Lower priority if it would take over 10 turns
nottoolong:
pop ax
cmp     word ptr [bp-0Ch], 0
jz checkpriority
; Settler Needed then don't start an expensive project costing over 200!
cmp ax,200
jg cantdothis

checkpriority:
; + RND(20) for randomness
mov ax,20
cmp [0BD96h],2
jge skip44
add ax,10 ; Normal or Easy difficulty, additional +10 randomity
skip44:
vizierpriority:
call random
add si,ax
cmp si,[bp-2]
jle worse
mov [bp-2],si
mov [bp-4],cx
worse:

cantdothis:
canotdothis:
inc di
jmp productionloop

finally:
mov ax,[bp-4]

buildthis:
push ax
call getcurrenttown
pop ax
mov     word ptr es:[bx+1Ch],ax

donotchange:
pop     di
pop     si
mov     sp, bp
pop     bp
retf


gettowndata:
mov     dx, 72h ; 'r'
imul    dx
les     bx, [9CBCh]
add     bx, ax
retn

getcurrenttown:
mov     ax, [bp+8]
call gettowndata
retn

magician:
mov ax,[bp+8]

mov al,[bp-8Ah]
;cmp al,0 ; Is 0 anyway
;jz nope
cmp al,4
jz nope
cmp al,5
jz nope
cmp al,9
jz nope
cmp al,10
jz nope
retn
nope:
xor ax,ax
yes:
retn


getunittype:
mov ax,cx
mov     dx, 24h ; '$'
imul    dx
mov     bx, ax
retn


;------------------------------
; Military buildings
;------------------------------

Military:
add si,2 ; Military buildins more important than others
cmp [bp-8],1
jnz skip442
add si,3 ; Militarist, twice the chance for Military buildings
skip442:

cmp [bp-8],4
jnz skip443
add si,3 ; Expansionist, twice the chance for Military buildings
skip443:

test [bp-12h],2
jz notada5
add si,7 ; Adamantium, strong preference of military
notada5:

test [bp-12h],1
jz notmit5
add si,3 ; Mithril, medium preference of military
notmit5:

test [bp-12h],4
jz notori5
add si,1 ; Orihalcon, Small preference of miltiary
notori5:

mov dx,[bp-0Ah]
cmp dl,dh
jg safeplace1
add si,7 ; More priority if enemy present
sar dh,1
cmp dl,dh ; Enemy has at least twice the presence
jg safeplace1
mov si,100 ; Only military buildings if strong enemy presence
safeplace1:
retn

Economy:
cmp [bp-8],3
jnz skip551
add si,3 ; Perfectionist, twice the chance
skip551:

cmp [bp-8],1
jnz skip666
add si,1 ; Militarist, small boost - more units eat more gold
skip666:

call getcurrenttown
cmp byte ptr es:[bx+14h],15
jl sk111
add si,3 ; High population city, prefer (% bonus to gold, or Colosseum for Fame)
sk111:
retn


EXP:
call getcurrenttown
cmp     byte ptr es:[bx+5Bh], 0
jz notaltar6
mov si,-500
notaltar6:
cmp [bp-8],1
jnz skip334
add si,3 ; Militarist, twice the chance for EXP buildings - but not for Expansionist!
skip334:

cmp [bp-8],3
jnz skip335
add si,3 ; Perfectionist, twice the chance for EXP buildings - low preference for units but when doing them, they're good!
skip335:

retn

Food:
call getcurrenttown
cmp byte ptr es:[bx+14h],3
jg sk222
add si,2 ; Low population, prefer food building - added hammers worth more!
sk222:

cmp [0BD96h],4
jnz notfamine
cmp byte ptr es:[bx+4Ah],0
jz notfamine
add si,20 ; High priority to counter famine - on Impossible only!
notfamine:

cmp [bp-8],0
jnz skip542
add si,2 ; Pragmatist, small preference of these - they pay off most on very long term and benefit all areas equally (gold, production, power if race makes any)
skip542:

cmp [bp-8],3
jnz skip742
add si,3 ; Perfectionist, prefer these - more production and population for stronger economy
skip742:

retn

Research:
call getwiz
cmp word ptr [bx-5ED4h], 0 ; Nothing being researched - Don't boost. Might still want for other purposes (University and Library unlocks stuff)
jz skip557
cmp word ptr [bx-5ED4h], 0D5h
jnz notsom
add si,4 ; Spell of Mastery is being researched, high priority!
notsom:
cmp byte ptr [bx-60CBh], 0 ;
jz notsage
add si,3 ; Priorize research buildings if Sage Master
notsage:

cmp [bp-8],2
jnz skip557
add si,4 ; Theurgist, very high chance for research
skip557:
retn

Power:
add si,2 ; Power buildins more important than others
cmp [bp-8],2
jnz skip556
add si,1 ; Theurgist, small preference
skip556:
retn

Production:

test [bp-12h],1Fh
jz prod1
add si,3 ; Mithril/Adamant/Orihalcon/Iron/Coal - we want to boost production here
prod1:

; preferece scales up based on difficulty
add si,[0BD96h]

cmp [bp-8],3
jnz skip339
add si,7 ; Perfectionist, very high preference to do the production buildings early
skip339:

cmp [bp-8Ah], 4 ; Dwarf
jnz notdwarf1
add si,7  ; Dwarves want Miner's and Mecha's more than others! (for mining bonus and higher base production values)
notdwarf1:
call getcurrenttown
cmp     byte ptr es:[bx+44h], 0 ; Chaos Rift
jz notchaos
add si,10 ; Production buildings first to counter destruction effect
notchaos:

retn

Unrest:
push cx
call Getunrest ; not CX safe!
pop cx
add si,ax ; +1 priority of unrest reducing building for each existing unrest point
retn

Religion:
call getwiz
cmp byte ptr [bx-60CDh], 0 ;
jz notcult
add si,4 ; Priorize religious buildins if cult leader
notcult:
call getcurrenttown
cmp byte ptr es:[bx+45h],0
jz notritual
add si,4 ; Priorize more if Dark Rituals
notritual:
retn

getwiz:
push ax
mov ax,4C8h
imul word ptr [bp+6]
mov bx,ax
pop ax
retn

;
;-Completely new "AI select production" procedure with major improvements! Priority system used is now similar to the combat spellcasting one - semi-random, semi-determined.
;-AI will not build Triremes in cities that has a Ship Yard
;-AI will not build Galleys in cities that have a Maritime Guild
;-AI will build units more often in cities that have a working Adamant, Mithril or Orihalcon
;-AI will build units more often in cities can build magicians and have Orihalcon
;-AI will build units more often in cities that have Iron or Coal
;-AI will build units more often in cities located on enemy continents
;-if enemy cities outnumber owned cities on the continent and the city has a Fighter's Guild, the AI will only build units there
;-AI will build Stables as the mandatory early military building in place of Fighter's Guild in Gnoll cities
;-AI has a lower priority to start buildings that take over 10 turns to complete, unless it's a building the AI prefers to rush-buy anyway
;-Only one settler production ongoing at a time, and preferred settler race restrictions are now limited to the same plane only
;-Normal and Easy difficulty had a larger random factor in building selection
;-Units with a higher figure count receive extra priority for each level expected for the unit (Barracks, War College, Altar of Battle, Crusade, Warlord)
;-Magical ranged units receive priority for available Orihalcon if Alchemist's Guild is present
;-Units with no Magical ranged attacks receive priority for higher figure count if Mithril or Adamantium with an alchemist's guild is present the same way as from levels
;-Flying and Swimming units gain additional priority if no enemy city is present on the continent
;-High Elves now recognize Forester's Guild as a Military building (Longbowmen)
;-Alchemist Guild gains priority if Adamantium, Orihalcon or Mithril is present
;-Alchemist Guild loses priority if wizard has Alchemy
;-Wizard's Guild counts as a Military building for races that can build Magicians
;-Military buildings gain priority if Adamantium, Orihalcon or Mithril is present  
;-Military buildings gain priority if the continent is mainly controlled by enemies
;-Preferences of buildings for each objective :
;Pragmatist
;Food (minor)
;
;Theurgist
;Research (major), Power (very minor)
;
;Militarist
;Military, EXP, Economy (minor)
;
;Expansionist
;Military, Naval
;
;Perfectionist
;Production (extreme), Economy, EXP, Food
;-Military and Power buildings have a somewhat higher base priority than other types of buildings (unchanged)
;-Unrest buildings gain priority if unrest is higher
;-Production buildings gain priority for Dwarves or if Chaos Rift is present
;-Research buildings gain priority is Spell of Mastery is being researched
;-On impossible difficulty, Food buildings gain priority if Famine is present
;-Religious power producing buildings are priorized if Cult Leader or Dark Rituals
;-Research buildings are priorized if Sage Master
;-Alchemist Guild, Amplifying Tower and Wizard's Guild priorized if Uranus' Blessing
;-Experience buildings are not built if Altar of Battle is on the city
;-Neutrals now use the same base unit preferences as wizards, but ignore all additional logic. Chance of unit is 75%, building is 25% regardless of garrison size.
;-Library further priorized if Mithril, Orihalcon or Adamant to unlock Alchemist's Guild faster
;-Expansionist wizards prefer flying units and Fantastic Stables
;-Production buildings are preferred more on higher difficulties
;-Production buildings are preferred more is Mithril/Orihalcon/Adamant/Iron/Coal available













; Priority difference % chance for higher priority to get chosen
; 01 57%
; 02 61%
; 03 66%
; 04 70%
; 05 73%
; 06 77%
; 07 80%
; 08 83%
; 09 86%
; 10 88.75%
; 11 91%
; 12 93%
; 13 94.75%
; 14 96.25%
; 15 97.5%
; 16 98.5%
; 17 99.25%
; 18 99.75%
; 19 100%

and this is the decision for buying :

Code:
; IN :
; CITY ID = ax
push    bp
mov     bp, sp
sub     sp, 12h
push    si
push    di
mov si,ax ; SI = City being checked

;jmp start
; GetTerrainTileListNearTown_NotCorruptedOnly:
;
;lea ax, [bp-72h]
;push ax
;lea ax, [bp-40h]
;push ax
;
;mov     al, es:[bx+11h]
;cbw
;push ax
;
;mov     al, es:[bx+10h]
;cbw
;push    ax
;
;mov     al, es:[bx+0Fh]
;cbw
;push    ax

; Far call

;db 9Ah, 20h, 00, 70h, 04

;add sp,0Ah

;retn
;start:

;==========================================================
; Check for ORES
;==========================================================
mov word ptr [bp-6],0

mov ax,si
call gettown

mov al, es:[bx+12h]
cbw
mov [bp-8],ax ; Owner of city

call getcontinent
mov [bp-0Ah],ax

;call GetTerrainTileListNearTown_NotCorruptedOnly
;mov di,ax ; Number of tiles in list

mov ax,si
call gettown

push si

mov al, es:[bx+0Fh]
cbw
mov [bp-2],ax ; X


mov al, es:[bx+10h]
cbw
mov [bp-4],ax ; Y

mov al, es:[bx+11h]
cbw
mov cx,ax ; Plane

mov di,-2

lph1:
mov si,-2
lph2:
cmp si,2
jz xcorner
cmp si,-2
jz xcorner
jmp notcorner
xcorner:
cmp di,2
jz next
cmp di,-2
jz next
notcorner:
push si
push di
add si,[bp-2]
add di,[bp-4]
call CheckOre
pop di
pop si
next:
inc si
cmp si,2
jle lph2
inc di
cmp di,2
jle lph1

pop si

;==========================================================
; Cities on continent (own and enemy)
;==========================================================
mov word ptr [bp-0Ch],0
mov word ptr [bp-0Eh],0

xor di,di
lph3:

mov ax,di
call gettown
call getcontinent
cmp [bp-0Ah],ax
jnz difcont
mov ax,di
call gettown
mov al, es:[bx+12h]
cbw
cmp ax,[bp-8]
jnz notown
inc word ptr [bp-0Ch]
jmp difcont
notown:
call isenemy
or al,al
jz difcont
inc word ptr [bp-0Eh]

difcont:
inc di
cmp di, [0BD94h] ; Max cities
jl lph3

;==========================================================
; Count Garrison
;==========================================================

mov word ptr [bp-10h],0

mov ax,si
call gettown

push si
mov si,es:[bx+0Fh]
mov cx,es:[bx+11h]

xor di,di
nextunit:
mov     ax, di
mov bx,20h
imul bx
les     bx, [9EC2h]
add     bx, ax

cmp es:[bx],si
jnz notgarr
cmp es:[bx+2],cx
jnz notgarr
inc word ptr [bp-10h]

notgarr:

inc di
cmp di,[0BD92h]
jl nextunit
pop si

;==========================================================
; Calculate BUY multiplier
;==========================================================

mov ax,4C8h
imul word ptr [bp-8]
mov bx,ax

cmp [bx-5DE0h],10000 ; Over 10k gold - buy anything
jg BUY
mov ax,si
call gettown
mov ax, es:[bx+1Ch]
cmp ax,15 ; SAWMILL
jz BUY
cmp ax,5 ; Fighter's Guild
jz BUY2
cmp ax,19 ; Alchemist's Guild
jz BUY2
;cmp ax,17 ; Sage's Guild
;jz BUY2
cmp ax,21 ; Wizard's Guild
jz BUY2
cmp ax,23 ; Amplifier Tower
jz BUY2
mov di,64
jmp done
BUY2:
mov di,4
done:
;
mov cl,[bp-6]
mov dl,[bp-0Ch]
mov dh,[bp-0Eh]
mov ch,[bp-10h]

cmp ch,2 ; fewer than 2 units, always buy
jl BUY

cmp ax,100
jle notunit  ; Not producing unit
cmp ch,6
jge enoughgarrison
; Fewer than 6 defenders and we are making a unit
sar di,1 ; 2x the preference to buy here if below 6
cmp ch,4
jge enoughgarrison
sar di,1 ; 4x the preference to buy here if below 4
enoughgarrison:

cmp dl,dh
jg owncontinent
sar di,1 ; 2x priority if contested continent and unit

sar dh,1
cmp dl,dh ; Enemy has at least twice the presence
jg owncontinent
mov di,4 ; Very high preference to buy the unit
owncontinent:
notunit:

; Iron, Coal reduces cost, so we can ignore, lower price increases chance to buy there
test cl,2
jz notada
sar di,2 ; High priority to buy
jmp notmithr
notada:

test cl,1
jz notmithr
sar di,1 ; High priority to buy
notmithr:

test cl,4
jz notori
sar di,1 ; Orihalcon
notori:

or di,di  ; protection from div by zero
jnz alldone
BUY:
mov di,1
alldone:
mov ax,si
call gettown
cmp byte ptr es:[bx+44h],0
jle notrift
sal di,2 ; Avoid buying
notrift:
mov cl,[bp-6]
mov dl,[bp-0Ch]
mov dh,[bp-0Eh]
mov ch,[bp-10h]
mov ax,di

pop     di
pop     si
mov     sp, bp
pop     bp
retf

; OUT :
; CL - ORE - 1 Mithril, 2 Adamant, 4 Orihalcon, 8 Iron, 10 Coal
; CH - Number of garrison units
; DL - Number of OWN cities on continent
; DH - Number of ENEMY cities on continent (no treaty and not lawful+ or war - ignore peace treaty, is temporal)
; AX - BUY multiplier

gettown:
mov     dx, 72h ; 'r'
imul    dx
les     bx, [9CBCh]
add     bx, ax
retn

; SI,DI position, CX plane
; [bp-6] found ORE
checkore:
push si
push di
cmp di,40
jge corrupted
cmp di,0
jle corrupted
cmp si,60
jle sx1
sub si,60
sx1:
cmp si,0
jge sx2
add si,60
sx2:

mov     ax, cx
mov     dx, 960h
imul    dx
les     bx, [9CB4h]
add     bx, ax
mov     ax, di
mov     dx, 3Ch ; '<'
imul    dx
add     bx, ax
add     bx, si
test    byte ptr es:[bx], 20h
jnz corrupted

mov     ax, cx
mov     dx, 960h
imul    dx
les     bx, [9CB8h]
add     bx, ax
mov     ax, di
mov     dx, 3Ch ; '<'
imul    dx
add     bx, ax
add     bx, si
mov     al, es:[bx] ; ORE
and al,1Fh

cmp al,1
jnz skip1
or [bp-6],8  ; IRON
skip1:

cmp al,2
jnz skip2
or [bp-6],10h ; COAL
skip2:

cmp al,6
jnz skip3
or [bp-6],1 ; Mithril
skip3:

cmp al,7 ; Adamant
jnz skip4
or [bp-6],2
skip4:

cmp al,10h
jnz skip5
or [bp-6],4 ; Orihalcon
skip5:

corrupted:
pop di
pop si
retn

getcontinent:
mov     al, es:[bx+11h] ; Plane
cbw
mov     dx, 960h
imul    dx
mov cx,ax
mov     al, es:[bx+10h] ; Y
cbw
mov     dx, 3Ch ; '<'
imul    dx
add     cx, ax
mov al, es:[bx+0Fh]
cbw
add  cx,ax
les     bx, [9CD0h] ;ContinentIDforMapLocation
add bx,cx
mov al,es:[bx]
cbw
retn

; IN AX = wizard ID
isenemy:
cmp ax,[bp-8] ; Self = not enemy
jz peace
mov bx,4C8h
imul bx
mov bx,ax
add bx,[bp-8]
cmp byte ptr [bx-5FDEh],3
jge war
cmp byte ptr [bx-5FDEh],0
jz neutral
peace:
mov al,0 ; Treaty or Peaceful or Lawful
retn
neutral:
mov ax,4C8h
imul word ptr [bp-8]
mov bx,ax
cmp [bx-611Eh],4
jge peace
war:
mov al,1 ; War or Chaotic/Agressive/Ruthless/Maniacal
retn
Reply

So for this, I would want to add a high priority (but not forced) for economy buildings if the AI gold is under x amount (probably 500), and a forced priority if under 100 gold (since AI start with at least 100 gold on each difficulty this would only happen if they were spending too much). I'd also want to add priority for economy buildings if net income is less than +10, but I'm not sure that's doable based on the info available.

If city population*tax rate is at least 20 (10 if alchemy retort) economy buildings should count as power buildings, and with higher priority than any actual power building.

Will look at buying when I can.

Also I'm not even sure you can check tax rate or wizard gold from here which might defeat this whole purpose.
Reply

(March 15th, 2017, 07:46)Nelphine Wrote: So for this, I would want to add a high priority (but not forced) for economy buildings if the AI gold is under x amount (probably 500), and a forced priority if under 100 gold (since AI start with at least 100 gold on each difficulty this would only happen if they were spending too much). I'd also want to add priority for economy buildings if net income is less than +10, but I'm not sure that's doable based on the info available.

If city population*tax rate is at least 20 (10 if alchemy retort) economy buildings should count as power buildings, and with higher priority than any actual power building.

Will look at buying when I can.

Also I'm not even sure you can check tax rate or wizard gold from here which might defeat this whole purpose.

All right, let's see what can be done.

Builder's Hall - now counts as an Economy building (unlocks bank/merchant/engineer)
Economy buildings - +6 priority if gold<500, +20 priority if gold<100.
Marketplace - Forced after sawmill, settlers, smithy, ship wrights, but before fighter's guild or equivalent if gold<100
Income - Prefer not to include this, calling the global income calculator is probably not safe here and might cause major slowdown - this procedure is run once every turn for every city
Economy counting as power - I don't see the point, gold cannot be converted into research or casting skill, and even into mana only if it's critically low or the wizard has Alchemy. Economy buildings already have additional priority if pop>15.

Space is an issue at the buying procedure, we shouldn't add anything too detailed there unless I can find a larger block of consecutive space somewhere else (unlikely).
Reply

I'm not sure I'd want to include builders hall as economy. Most of the time, if a builders hall isn't built, then the town is low population, so building a bank or merchants guild isn't worth it anyway. By leaving builders hall as non economy, then the later economy buildings only become a priority when the town is big enough to support them.
Reply

(March 15th, 2017, 11:01)Nelphine Wrote: I'm not sure I'd want to include builders hall as economy. Most of the time, if a builders hall isn't built, then the town is low population, so building a bank or merchants guild isn't worth it anyway. By leaving builders hall as non economy, then the later economy buildings only become a priority when the town is big enough to support them.

Good point. I'll undo that part then.
Reply

My guess is that buying units happens too often in the early game, especially if the continent is shared with another wizard (who isn't even met yet). For instance, they start with less than 4 units, so buying a unit is hig h priority - and the other wizard has just as many cities and units so buying units is even higher priority. If at all possible, don't buy anything when doing so would bring the AI under 75 gold (maybe 50 or even 100) - especially with the starting sawmill. If you had more space I'd put a turn limit on the increased priority to buy units due to enemy presence on the continent (say, not before turn 20), and also a turn limit on the increase priority due to small garrisons (say turn 10). But the 50-100g limit should be plenty.
Reply

(March 16th, 2017, 15:36)Nelphine Wrote: My guess is that buying units happens too often in the early game, especially if the continent is shared with another wizard (who isn't even met yet). For instance, they start with less than 4 units, so buying a unit is hig h priority - and the other wizard has just as many cities and units so buying units is even higher priority. If at all possible, don't buy anything when doing so would bring the AI under 75 gold (maybe 50 or even 100) - especially with the starting sawmill. If you had more space I'd put a turn limit on the increased priority to buy units due to enemy presence on the continent (say, not before turn 20), and also a turn limit on the increase priority due to small garrisons (say turn 10). But the 50-100g limit should be plenty.

The AI will most likely build settlers and fighter's guilds in the first 20 turn. (They might build 2 swordsmen to reach 4 units but that's about it and only on normal where they don't start with extras)

Buying works like this : the return value from this procedure is a multiplier (calculated in DI, returned in AX). If the AI has gold>=the cost*this multiplier, it will be bought, otherwise not. A multiplier of anything above 1 means the AI can't spend their last gold coins on it.
Units have a default multiplier of 100, which gets lowered by the modifiers you mention above - but aside from the worst case situation of having adamant AND at least double enemy presence on the continent, this multiplier will never go down to 1.
The exceptions are having less than 2 units defending, which results in the 1x multiplier. Among buildings, Sawmill uses 1x, and if the AI has over 10k gold, everything does. Otherwise, even the Fighter's Guild and Settlers have a higher multiplier (which might not be the correct choice, buying in the capital in the early game is always best as it accelerates expansion) of 4.
Reply

Can it buy something past the turn it starts producing it? Buying the last 25 production on anything could still result in too low gold. (Or worse, the last 10 production, if it happened to build a bunch of things before a marketplace on easy difficulty. I'm using 50-100 as the hard limit specifically to avoid cases where the AI has negative income for several turns after the last purchase. Presuming of course it will never have worse than -10 or -15 gold income for too long.)
Reply

(March 16th, 2017, 16:27)Nelphine Wrote: Can it buy something past the turn it starts producing it? Buying the last 25 production on anything could still result in too low gold. (Or worse, the last 10 production, if it happened to build a bunch of things before a marketplace on easy difficulty. I'm using 50-100 as the hard limit specifically to avoid cases where the AI has negative income for several turns after the last purchase. Presuming of course it will never have worse than -10 or -15 gold income for too long.)

Yes it can - that's the point of the system, to distribute gold between all cities, but with cities that have a higher priority getting larger amounts more often.

For example if the AI has 800 gold, they'll buy at most the last 8 production (for 16 gold) on a generic purchase (100x), at most 100 production (for 200 gold) on a multiplier 4 Fighter's Guild, etc., so the city/thing with higher priority will get more of the gold available. As the Gold decreases, spending decreases everywhere along with it, which prevents it from running out - except in the case of 1x multiplier buys but those shouldn't be frequent enough to actually drain the gold from the AI on their own. This system tends to result in an equilibrium where the income and spending naturally balances out, keeping the gold reserve around the same amount.

The AI should never, ever have a negative gold income outside Easy difficulty - aside from situations like pestilence on all their cities reducing population to 1 in which case they already lost anyway.
Even if they do have a negative income, they'll disband units way before actually hitting zero : if the AI can't expect to maintain all their units for at least 16 (or 32? not sure) turns, they start disbanding - in other words with an income of -10 they either still have 160 (or 320) gold, or disband something to increase the income.
And for Easy, I already disabled buying altogether as it's unsafe and the AI doesn't need to be able to do that for that difficulty anyway - the whole point of Easy is the have AI with very slow progress that can be defeated effortlessly.
Reply

Oh i didn't realize you had negated buying on Easy. That should be fine then.
Reply



Forum Jump: