As a French person I feel like it's my duty to explain strikes to you. - AdrienIer

Create an account  

 
Game mechanics

So the problem I have is this: from my experience, on master, the ai currently has strength 40 on turn 40.

Late game human has strength 8 on turn 40.
Early game human has strength 30 on turn 40. (Not including trick strategies. So for instance, this might be a gnoll build, which must be an early strategy.)

Then as arnuz says, it becomes about luck. Is your neighbor positioned such that your str 30 can roll the AI and thereby give you a shot at the next AI? Yes? Good keep playing. No? Start again.


Playing a slow strategy? Defend your one or two cities, expand slowly.

Turn 200: AI military 5000.
Human trick strategy won already.
Human fast strategy, 1000
Human slow strategy: 2500.

(Reminder: these are current numbers in my opinion.)

IF your sample numbers were common then I understand your hesitation. But past advanced (and even sometimes advanced) the strongest AI simply is ahead of the human.

So the meta is: play at normal/advanced, learn the game. Try expert or master without tricks and realize you're simply massively outgunned. Learn a trick, win expert/master. Try trick on lunatic and slaughter that too.



All that being said, I think advanced and expert are in pretty good shape. However, master really encourages tricks, and lunatic requires them.

What I want to see is a subtle reduction, that 10% ish across the board, so that expert doesn't smash weaker strategies thus encouraging tricks (imagine mono death, without research retorts, and the human doesnt abuse ghouls - but late game finds a sorcery book, gets focus magic, happens to try it on ghouls, and thinks man, I wish I'd done that from the start! Now trick gets developed, and player skips from a lost expert, to smashing lunatic.)

That also puts lunatic around where master us now, which is possible, but difficult, without tricks.


Our disagreement seems to be scale. You don't think it will change anything, I specifically want subtle incremental changes.
Reply

Quote:Then as arnuz says, it becomes about luck.

If you mean early strategies, that's how it should be.
If an early strategy offers a reliable way of winning the game, no one will play anything else. Why bother winning a game in 30 hours if I can play an early strategy and have the same win percentage, but each game only takes 8 hours? Not to mention less playing time means less chances to make mistakes, thus a higher actual win percentage where the "perfect play" win percentage would be otherwise equal.

In theory, it sounds nice that early and late strategies are equal, but in practice, early should be weaker. Aside from the above two reasons, also because the luck factor is higher in a shorter game, and the players gets to enjoy less of the game content (higher tier units, higher tier spells, etc).

If your numbers are correct that means the game is exactly where it should be - early strategies are less reliable but faster and easier to play. Late strategies are more reliable but harder to play. And tricks beat both but that's a different story, we have to measure each of those individually.

Anyway, it has been stated a few times that a small reduction in AI bonus from expert up is being considered, but I want to play enough games to be able to judge that. I played, what, one, incomplete Expert game in 5.01 and none at Master or Lunatic since 4.x? How am I supposed to be able to adjust these with 10% accuracy if I haven't even played any? Heck, even testing every race exceeds my capability, 3 games with each of the 14 races is 42 games, at 20 hours each, that's 840 hours of game time. If I sit down now, don't sleep, don't eat, and don't read the forum, I can do it in, what, 35 days? A more realistic schedule would be 2 hours a day, for a total of 420 days...and that's still pushing it a little, doing it every single day. And races are a lot more important thing than a 10% adjustment to AI bonus.

I have repeatedly asked for youtube gameplay videos but not getting much of those. Playing myself is far more time consuming and exhausting so don't expect progress any time soon if we do it that way. (Yes the video has the same length but I can fast forward all the unimportant parts such as picking buildings in 20 cities each turn so watching it takes like a quarter of the time.)
Reply

That's actually the first time you've come out and said you're seriously considering reducing cheating bonuses at any level. You've generally appeared highly resistant to any such changes, beyond a general 'this is a discussion'. Its also the first time you've unequivocally stated that your decision to do so hinges on ether you playing it or being able to see YouTube videos.

I've also repeatedly stated why I can't do such videos. I'm quite content to wait 15 months (or longer) for you to test things if that's what it requires. Hopefully other people can give you videos!

All I can do is give you all the feedback I can from my games. That is the discussion I can provide, and which I was under the impression you wanted; I also try to give you different examples whenever I find them, so that you have specific numbers on which to have those discussions.
Reply

Well, ok, maybe I just said those difficulty levels are still not properly tested to make a decision, but that kinda implies there is a chance for reduction. At the very least, I don't expect the test results to say "game is too easy now, AI needs more resources" so it's either no change or less resources. In which case we still don't know how much and which kind.

I'm very resistant to reducing the casting bonus and the maintenance bonus specifically, so there is close to no chance for those two. Power bonus has a chance, gold, production have a better chance. I doubt research needs a reduction, as we have been increasing it in the past, but that's also a possibility. Population growth bonus is already very low so idk if reducing that would affect anything at all. But first we need data and for that we need time. And we probably want to get the races properly balanced first. Realms are about right now, sorcery and supreme light being the only two that might need changes. Retorts are unlikely to need any significant change. Map generation, starting conditions and diplomacy seems fine as well. (or at least we don't have better options)
But races aren't, at least some of them are outdated and need further testing so there is that too.
Reply

Thanks for the clarifications, I'm also happy to wait like Nelphine, this is not meant to stress you out and hopefully isn't resulting in this.

My idea is to reduce the power and gold bonus, so anything that provides ways to cast stuff. The ratio of summons vs buffs/specials can then be tweaked to maintain the same amount of the latter.

I also wouldn't mind to see a declaration like "lunatic is meant to be won with tricks!". I'd still hope that tricks can be nerfed... Speaking of that, I've come up perhaps with a solution to ghouls. I'll bring it up on their thread.

My objective is to make the game less luck based @t40, not just for early starters, but for every strategy. I think I therefore disagree with your analysis. Let's see...


(October 23rd, 2017, 11:42)Seravy Wrote:
Quote: it means reducing it somewhat at t40 but it can mean increasing it afterwards.

It's not the amount that's the problem, it's the DIRECTION. The suggested direction will escalate a known problem. So I'm not doing it because it will make things WORSE.

Your premise is wrong. You are basically saying "If the AI has less early advantage, we can play late game strategies without losing to it". And I'm saying "If the AI has less early advantage, early strategies beat it even more so late strategies will be obsolete, no one would play them."

But ok, let's look at some numbers.

(This is an example, not actual ingame numbers)

Turn 40, Currently.
AI has 40 total military power. Out of this 20 is garrison, 20 is free stacks to attack people with.
Human player playing late strategy has 10 - they are in trouble which is why you suggest what you do.
Human player playing early strategy has 80 - they can crush the AI and maintain enough defenses to not lose the game, but it'll cost them half their armies so they can only do one enemy wizard before the others get strong enough to have a chance to stop the invasion.

Turn 200, Currently.
AI has 5000 total military power.
Human late strategy has, ideally, 5000 to match it and result in an interesting game.
Human early strategy either already won or lost, so it's not relevant here.



Turn 40 your suggestion.
AI has only 20 military power. Probably all 20 garrison, maybe one or two weak stacks free.
Human playing late strategy has 10 - they are good to go. Your suggestion seems to fix this case.
Human player playing early strategy still has 80 - but this now enables them to crush all 3 other wizards on Arcanus. Maybe not all the fortresses, but as the AIs are now without free units, all the hamlets can be conquered, and that means eventually the fortresses fall to. By 1406-1408 Arcanus has only the human player.

So far so good, but I differ on the last part. Maybe I need to add a point to my proposal, we have to make the AIs more risk averse - maybe getting them to defend more? The result of a subtle - as Nelphine correctly mentions - nerf should be that they can defend like before - if not better - but have less roaming stuff at t40. So that as a result, there's less chances to get slaughtered by the roaming hordes against which nothing can be done...
So we actually nerf the early aggression somewhat: if AIs defend the same or better there's less possibility to get their stuff. What you've already done - with the number of summons in cities - might well be enough, or if as you say it results in on average the same numbers then perhaps we need to raise it by 1 across every category?




(October 23rd, 2017, 11:42)Seravy Wrote: The summoning: surely the AIs use a rule right now, because there're retorts and number of books and difficulty levels that affect how much mana they have. Is the amount of mana completely ignored? I don't know how this works, so I can't really answer there.

This is the "rule" :
Code:
.org 8E6h
;-----------------------------
; Categories
; [bp-60h] + 00 -MAGIC SPIRIT
; [bp-5Eh] + 01 -Summon
; [bp-5Ch] + 02 -Unit Buff
; [bp-5Ah] + 03 -City Buff
; [bp-58h] + 04 -DisenchantArea
; [bp-56h] + 05 -Disjunction
; [bp-54h] + 06 -Curse
; [bp-52h] + 07 -Wind walking /Floating Island / Wraith Form / Water Walking / Flight - use if not enough ships in this order of pref. -Only after turn 20!
; [bp-50h] + 08 -Hero (Summon Hero, Summon Champion, Incarnation, Resurrection) - do not pick if no hero slots!
; [bp-4Eh] + 09 -Spell Blast
; [bp-4Ch] + 10 -Dispelling Wave
; [bp-4Ah] + 11 -Items/Artifacts
; [bp-48h] + 12 -Spell of Mastery (Skip cost vs mana check!)
; [bp-46h] + 13 -Global Enchantment
; [bp-44h] + 14 -Stasis (cast on incoming doomstack)
; [bp-42h] + 15 -Lycanthropy (affect by Divine order as enchantment, high priority in early game, low later)
; [bp-40h] + 16 -Focus Magic
; [bp-3Eh] + 17 -Time Stop
; [bp-3Ch] + 18 -Magic Immunity
; [bp-3Ah] + 19 -Cheap Buff stacking - Don't do if Doom Mastery, Suppress Magic
; [bp-38h] + 20 -Invisibility (spam more Invisibility - only during Divine Order and war with the human player?)
; [bp-36h] + 21 -Final Wave
; [bp-34h] + 22 -Great Unsummoning
; [bp-32h] + 23 -Nature's Cures (NOT IMPLEMENTED - unsure - the AI probably has way too many damaged stacks at a time for this to be a good choice to use?)
; [bp-30h] + 24 -Summoning Circle
; [bp-2Eh] + 25 -Planar Travel
; [bp-2Ch] + 26 -Spell Lock
; [bp-2Ah] - 27 -Doomstack Participation (Wraith Form and Water Walking)
; [bp-28h] - 28
; [bp-26h] - 29
; [bp-24h] - 30
; [bp-22h] - 31
; [bp-20h] - 32
; [bp-1Eh] - 33
; [bp-1Ch] - 34
; [bp-1Ah] - 35
; [bp-18h] - 36
; [bp-16h] - 37
; [bp-14h] - 38
; [bp-12h] - 39
; [bp-10h] - 40
;
;
;
;-----------------------------
; [bp-A] - temp use
; [bp-8] - temp use
; [bp-6] - temp use
; [bp-4] -
; [bp-2] - intended slider amount

jmp start

setspellanddone:
push word ptr [bp-2]  ;Slider Amount
push    di              ; Spell ID
push    si              ; Wizard ID
;call    j_Cast_A_Spell
db 9Ah,2Fh,00,30h,04h
add     sp, 6
pop     di
pop     si
mov     sp, bp
pop     bp
retf

getincome:
lea     ax, [bp-0Ah]
push    ax
lea     ax, [bp-8]
push    ax
lea     ax, [bp-6]
push    ax
push    si
;call    sub_356CE
db 9Ah,3Eh,00,0C0h,03
add     sp, 8
retn

SelectASpell:
mov     ax, 32h ; '2'
push    ax
mov     ax, 0D386h
push    ax
db 09Ah,0D6h,06,08,00
pop cx
pop cx
dec ax
retn

PickCategory:
mov     ax, 40 ; '2'
push    ax
lea ax,[bp-60h]
push    ax
db 09Ah,0D6h,06,08,00
mov cx,ax
pop ax
pop ax
;dec cx
; return CX = category
retn

NofHeroes:
push si
db 9Ah,34h,00,0C8h,03
pop cx
retn

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

getwiz:
mov bx,4C8h
imul bx
mov bx,ax
retn

isknown:
push ax
mov ax,si
call getwiz
pop ax
add bx,ax
xor ax,ax
cmp byte ptr [bx-5ED3h],2
jnz notknown
inc ax
notknown:
retn

loadtable:
push bx
xor bx,bx
nextclear:
mov word ptr [bx+0D386h],0
inc bx
inc bx
cmp bx,100
jl nextclear
pop bx

nextentry:
push bx
add bx,cx
add bx,cx
mov al,cs:[bx] ; Spell ID
xor ah,ah
push bx
push ax
call isknown
or ax,ax
pop ax
pop bx
jz zero
xor ah,ah
mov al,cs:[bx+1] ; Priority
jmp notzero
zero: ; Priority in AX, zero if spell unknown
xor ax,ax
notzero:
mov bx,cx
add bx,cx
mov word ptr [bx+0D388h],ax
pop bx
dec cx
cmp cx,0
jge nextentry
retn

addto:
cmp word ptr [bx],0
jz bad4144
add word ptr [bx],ax
bad4144:
retn

GlobalEnchantmentEffects:
; In : DX = Own wizard ID
push di
xor cx,cx
xor di,di
xor ax,ax
next:
push ax
push dx
mov ax,4C8h
imul di
mov bx,ax
pop dx
pop ax

cmp di,dx ;Not own spell
jz skip

cmp byte ptr [bx-5CAFh],0 ;Suppress Magic in effect?
jz skip2
inc ch
skip2:

cmp byte ptr [bx-5CA7h],0 ;Meteor storm in effect?
jz skip1
inc cl
skip1:
    
cmp byte ptr [bx-5CADh],0 ;Fairy Ring in effect?
jz skip3
inc al
skip3:
    
skip:

cmp byte ptr [bx-5CAAh],0 ;Chaos Surge in effect?  (including own)
jz skip4
inc ah
skip4:


inc di
cmp di,[0BD9Ch]
jl next
pop di
mov dx,ax
retn

; Out : CL = number of meteor storms in effect
;       CH = Suppress Magics
;       DL = Fairy Rings
;       DH = Chaos Surges

ChaosSurgeDecider:
push si
push di
xor di,di
xor si,si
loophead9:
cmp si,[0BD92h]
jge done9

mov     ax, si
mov     cl, 5
shl     ax, cl
les     bx, [9EC2h]
add     bx, ax

test es:[bx+17h],1Ch
jnz ischaos9

push bx
mov     al, es:[bx+5]
mov     ah, 0
mov     dx, 24h ; '$'
imul    dx
mov     bx, ax

mov al,[bx+1A9h]

pop bx
cmp al,18
jnz next9

ischaos9:
mov al,es:[bx+3]
cbw
cmp ax,[bp+6]
jnz notown9
inc di
jmp next9
notown9:

mov     dx, 4C8h
imul    dx
add     ax, [bp+6]
mov bx,ax
cmp     byte ptr [bx-5FDEh],2
jz next9
dec di

next9:
inc si
jmp loophead9
done9:
mov ax,di

pop di
pop si
retn

FocusMagicNeeded:
push di
xor di,di
xor cx,cx
lphew:
cmp di,[0BD92h]
jge doneew
loc_5A74C:
mov     ax, di
mov bx,20h
imul bx
les     bx, [9EC2h]
add     bx, ax

test byte ptr es:[bx+19h],8 ; Already has Focus Magic?
jnz nextew

mov al,es:[bx+3]
cmp al,[bp+6]
jnz nextew
; Own unit
mov al,es:[bx+5]
cmp al,162 ; Efreet
jz yesew
cmp al,170 ; Wraiths
jz yesew
cmp al,169 ; Demon
jz yesew
cmp al,172 ; Death Knight
jz yesew
cmp al,181 ; Cockatrices
jz yesew
cmp al,195 ; Djinn
jz yesew
jmp nextew
yesew:
inc cx

nextew:
inc di
jmp lphew
doneew:
pop di
retn

SpellLockNeeded:
push di
xor di,di
lphewsl:
cmp di,[0BD92h]
jge doneewsl
loc_5A74Csl:
mov     ax, di
mov bx,20h
imul bx
les     bx, [9EC2h]
add     bx, ax

test byte ptr es:[bx+19h],40h ; Already has Spell Lock
jnz nextewsl

mov al,es:[bx+3]
cmp al,[bp+6]
jnz nextewsl
; Own unit
xor cx,cx
mov ax, es:[bx+18h]
call countbuffs
mov ax, es:[bx+1Ah]
call countbuffs
cmp cx,4
jl nextewsl
add word ptr [bp-2Ch],5 ; 5 Spell Lock priority for unit with 4 spells
cmp cx,5
jl nextewsl
add word ptr [bp-2Ch],20 ; 25 Spell Lock priority for unit with 5 spells
cmp cx,8
jl nextewsl
add word ptr [bp-2Ch],200 ; 225 Spell Lock priority for unit with 8+ spells
nextewsl:
inc di
jmp lphewsl
doneewsl:
pop di
retn

countbuffs:
xor dx,dx
push cx
mov     cx, 10h
loc_C1CAB:
test    ax, 1
jz      short loc_C1CB3
inc dx
loc_C1CB3:
shr     ax, 1
loop    loc_C1CAB
pop cx
add cx,dx
retn

UnsummonDecider:
push si
push di
xor di,di
xor si,si
loophead777:
cmp si,[0BD92h]
jge done777

mov     ax, si
mov     cl, 5
shl     ax, cl
les     bx, [9EC2h]
add     bx, ax

test es:[bx+17h],3Ch ; Fantastic creature (chaos channel, undead)
jnz ischaos777
cmp byte ptr es:[bx+5],154
jb next777 ; Normal unit, ignore
ischaos777:
push bx
mov     al, es:[bx+5]
mov     ah, 0
mov     dx, 24h ; '$'
imul    dx
mov     bx, ax

mov al,[bx+1A4h]

pop bx
cmp al,12 ; too much resistance
jg next777

mov al,es:[bx+3]
cbw
cmp ax,[bp+6]
jz next777 ; Own unit : ignore
cmp al,5
jz next777 ; Neutral ignore

inc di ; Enemy unit

mov     dx, 4C8h
imul    dx
add     ax, [bp+6]
mov bx,ax
cmp     byte ptr [bx-5FDEh],2
jnz next777
dec di ; Allied unit!
dec di
next777:
inc si
jmp loophead777
done777:
mov ax,di

pop di
pop si
retn


;=====================================================
;=====================================================
;=====================================================
; Procedure starts here
;=====================================================
;=====================================================
;=====================================================

start:
push    bp
mov     bp, sp
sub     sp, 60h
push    si
push    di

mov si,[bp+6] ; SI = Wizard

;----------------------------------------------------
; Spell categories known
;----------------------------------------------------

TryAgain:

; Zero all categories
xor di,di
nextcat:
mov bx,[9120h]
add bx,di
mov byte ptr [bx],0
inc di
cmp di,5Ah      ; Max 90 categories
jle nextcat

xor di,di
nextspell:
inc di

cmp di,214
jg donecats

mov ax,si
call getwiz

cmp [bx+di-5ED3h],2
jnz nextspell

cmp di,51h
jz nextspell ; Ignore spell lock - doesn't unlock "buff" categories by itself

mov     ax, 24h
imul    di
les     bx, [912Ch] ; Spell_Data_Structure_Offset
add     bx, ax
mov     al, es:[bx+13h]
cbw
mov     cx, ax
or      ax, ax
jz nextspell ; Category 0 - spell is uncategorized

mov     al, es:[bx+18h]
cbw
or      ax, ax
jl nextspell ; Combat only - skip

mov     bx, [9120h] ; SpellTypeAvailable
add     bx, cx
mov     byte ptr [bx], 1

jmp nextspell

donecats:

;=====================================================
;=====================================================
; Category selection
;=====================================================
;=====================================================

; Zero all categories
xor ax,ax
xor cx,cx
lp111:
mov di,cx
sal di,1
mov [bp+di-60h],ax
inc cx
cmp cx,40
jl lp111

;----------------------------
; 01 - Summons
mov word ptr [bp-5Eh],100 ; 01 -Summon, base priority = 100

mov bx,[9120h] ; Spell Categories Known
cmp byte ptr [bx+4Ah],1 ; Best summon category known
jnz plplpw
add word ptr [bp-5Eh],100 ; + 100 Summon
plplpw:
cmp byte ptr [bx+4Eh],1 ; Second best summon category known
jnz plplpwq
add word ptr [bp-5Eh],50 ; + 50 Summon
plplpwq:
;cmp byte ptr [bx+38h],1 ; Third best summon category known (better rares)
;jnz plplpwqq
;add word ptr [bp-5Eh],25 ; + 25 Summon
;plplpwqq:

;----------------------------
; 08 - Heroes
call NofHeroes

cmp ax,6
jge dontgethero
mov cx,6
sub cx,ax
sal cx,3 ; 8 priority for each empty slot

xor di,di
mov ax,08Eh
call Isknown
add di,ax
mov ax,0D0h
call Isknown
add di,ax
mov ax,0D4h
call Isknown
add di,ax
mov ax,085h
call Isknown
add di,ax

or di,di
jz dontgethero

mov ax,82h
call isknown
or ax,ax
jz uququq
sal cx,1 ; Double of that if Heroism is available
jmp wewewe
uququq:

mov ax,si
call getwiz
cmp byte ptr [bx-5CA5h],0
jz wewewe
sal cx,1 ; Double of that if Enlightenment is in effect
wewewe:

cmp word ptr [bx-6112h],100
jl wewewe2
sar cx,1 ; Halve if 100+ Fame (easy to hire)
wewewe2:

cmp di,2
jle awer
add cx,30 ; At least two spells known - can do better than just normal summon hero
awer:

cmp di,3
jle awer2
add cx,70 ; At least 3 spells known - meaning incarnation or resurrection is available, should invest regardless of slots!
awer2:

mov word ptr [bp-50h],cx  ; 08 - Hero Summons
dontgethero:

;----------------------------
; 00 - Magic Spirit
mov ax,si
call getwiz
mov     ax, [bx-6104h]
mov     [bp-6], ax ; Plane of Summoning Circle
xor di,di
xor dx,dx
nextunit6:
mov     ax, di
mov     cl, 5
shl     ax, cl
les     bx, [9EC2h]
add     bx, ax
mov     al, es:[bx+3]
cbw
cmp     ax, si
jnz nextuu
mov     al, es:[bx+2]
cbw
cmp     ax, [bp-6]
jnz nextuu
push dx
mov     al, es:[bx+5]
mov     ah, 0
mov     dx, 24h ; '$'
imul    dx
mov     bx, ax
pop dx
test    word ptr [bx+1BAh], 400h
jz nextuu
inc dx
nextuu:
inc di
cmp di,[0BD92h]
jl nextunit6
cmp dx,3
jge have3spirits
mov word ptr [bp-60h],120 ; Less than 3 spirits - spirit priority = 120
have3spirits:


;----------------------------
; 01 - Summons
mov ax,si
call getwiz
cmp     byte ptr [bx-60C3h], 0
jz notconjurer
add word ptr [bp-5Eh],50 ; 01 -Summon, Conjurer priority +50
notconjurer:

;----------------------------
; 04 - Disenchant Area
mov ax,0CCh
call isknown
or ax,ax
jz cantdispel

xor di,di
nextcity334:
mov     ax, di
mov     dx, 72h ; 'r'
imul    dx
les     bx, [9CBCh] ;dword_4075C
add     bx, ax
mov     al, es:[bx+12h]
cbw
cmp ax,si
jnz notown54
cmp     byte ptr es:[bx+44h], 0 ; Chaos Rift
jz wer1
add word ptr [bp-58h],22
wer1:
cmp     byte ptr es:[bx+46h], 0 ; Evil Presence
jz wer2
add word ptr [bp-58h],17
wer2:
cmp     byte ptr es:[bx+48h], 0 ; Pestilence
jz wer3
add word ptr [bp-58h],30
wer3:
cmp     byte ptr es:[bx+4Ah], 0 ; Famine
jz wer4
add word ptr [bp-58h],22
wer4:

notown54:
inc di
cmp di,[0BD94h]
jl nextcity334

xor di,di
nextnode334:
mov     ax, di
mov     dx, 30h ; '0'
imul    dx
les     bx, [9CCCh] ;dword_4076C
add     bx, ax
mov     al, es:[bx+3]
cbw
cmp     ax, si
jnz notown144
test byte ptr es:[bx+2Eh],1
jz notown144
add word ptr [bp-58h],50 ; Warped Node
notown144:

inc di
cmp di,30
jl nextnode334
cantdispel:

;----------------------------
; 05 - Disjunction

xor di,di
mov ax,0D2h
call isknown
or ax,ax
jz ghgh
mov di,0D2h
ghgh:

mov ax,04Ch
call isknown
or ax,ax
jz ghgh2
mov di,04Ch
ghgh2:

or di,di
jz cantdispel2

push si
push di
lea ax,[bp-6]   ; Target Spell
push ax
lea ax,[bp-8]   ; Target Wizard
push ax
push cs
call DisjunctionTarget
add sp,8

mov [bp-56h],cx ; Disjunction priority

cantdispel2:

;----------------------------
; 10 - Dispelling Wave

mov ax,34h
call isknown
or ax,ax
jz nodiwave

push si
call DispellingWaveTarget
add sp,2
cmp dx,8
jl nodiwave
sub dx,6
shl dx,1
mov word ptr [bp-4Ch],dx ;  10 -Dispelling Wave
nodiwave:

;----------------------------
; 12 - Spell of Mastery
mov ax,0D5h
call isknown
or ax,ax
jz skipSOM
mov word ptr [bp-48h],500 ; Spell of Mastery known - priority 500
skipSOM:

; Do not cast spell of mastery if we have spell blast and need to stop another wizard with higher skill from casting it!
mov ax,si
call getwiz
cmp     byte ptr [bx-5E99h], 2
jnz     short locret_E423E
mov     ax, [bx-60E0h]
mov     cx, 4
imul    cx
mov     cx, 5
idiv    cx
mov     dx, ax
xor     cx, cx
loc_E4217:
cmp     cx, [bp+6]
jz      short loc_E4237
push    dx
mov     ax, 4C8h
imul    cx
mov     bx, ax
pop     dx
cmp     byte ptr [bx-5DFEh], 2
jnz     short loc_E4237
cmp     dx, [bx-60E0h]
jge     short loc_E4237
mov word ptr [bp-48h], 0
loc_E4237:
inc     cx
cmp     cx, [0BD9Ch] ;word_4283C
jl      short loc_E4217
locret_E423E:

;----------------------------
; 04, 05 - Extra dispel power effects
mov ax,si
call getwiz

cmp     byte ptr [bx-60C4h], 0
jz      short loc_E41E7
; Runemaster
mov ax,3
imul word ptr [bp-56h]
mov word ptr [bp-56h],ax ; 3x Disjunction priority
sal word ptr [bp-58h],2 ; 4x Disenchant Area priority
sal word ptr [bp-4Ch],1 ; 2x Dispelling Wave

loc_E41E7:
cmp     byte ptr [bx-5CB0h], 0
jz      short loc_E41F4
; AEther Binding
sal word ptr [bp-56h],1 ; 2x Disjunction
sal word ptr [bp-58h],1 ; 2x Disenchant
sal word ptr [bp-4Ch],1 ; 2x Dispelling Wave
loc_E41F4:

;cmp     byte ptr [bx-5E87h], 2
;jnz     short loc_E41FE
; Known Spell Binding
;loc_E41FE:

;----------------------------
; 06 - Curses
mov ax,si
call getwiz
mov bx,word ptr [bx-611Eh]
sal bx,1
mov ax,cs:[bx+CursePersonTable]
add word ptr [bp-54h],ax ; Base priority for personalities
jmp skiptable99
CursePersonTable:
dw 125 ; Maniacal
dw 075 ; Ruthless
dw 030 ; Aggressive
dw 030 ; Chaotic
dw 012 ; Lawful
dw 004 ; Peaceful
skiptable99:

;----------------------------
; 03 - City buffs

mov bx,[9120h] ; Spell Categories Known
cmp byte ptr [bx+8],1 ; Low priority
jnz plplp
mov word ptr [bp-5Ah],40 ; + 03 -City Buff
plplp:

cmp byte ptr [bx+2Ch],1 ; Military priority
jnz plplp2
mov word ptr [bp-5Ah],60 ; + 03 -City Buff
plplp2:

cmp byte ptr [bx+33h],1 ; High priority
jnz plplp3
mov word ptr [bp-5Ah],100 ; + 03 -City Buff
plplp3:

cmp byte ptr [bx+25h],1 ; Terrain modifier
jnz plplp4
add word ptr [bp-5Ah],30 ; + 03 -City Buff
plplp4:

mov ax,48h
call isknown
or ax,ax
jz noward1
add word ptr [bp-5Ah],50 ; Spell Ward known
noward1:

;----------------------------
; 02 - Unit buffs

mov bx,[9120h] ; Spell Categories Known
cmp byte ptr [bx+7],1 ; Low priority
jnz rtrtrtr1
mov word ptr [bp-5Ch],50 ;  + 02 -Unit Buff
rtrtrtr1:

cmp byte ptr [bx+0Ah],1 ; Medium priority
jnz rtrtrtr2
mov word ptr [bp-5Ch],100 ;  + 02 -Unit Buff
rtrtrtr2:

cmp byte ptr [bx+1Dh],1 ; High priority
jnz rtrtrtr3
mov word ptr [bp-5Ch],166 ;  + 02 -Unit Buff
rtrtrtr3:

;----------------------------
; 09 - Spell Blast

mov ax,3Ah
call isknown
or ax,ax
jz nospellblast
call SpellBlastNeeded
or ax,ax
jl nospellblast
mov word ptr [bp-4Eh],3000 ; If blast needed, very high priority to use it! 09 -Spell Blast
nospellblast:

;----------------------------
; 13 - Global Enchantment

call LoadGlobals

xor cx,cx
xor bx,bx
nextclear7:
add cx, word ptr [bx+0D386h]
inc bx
inc bx
cmp bx,100
jl nextclear7

mov word ptr [bp-46h], cx ; + 13 -Global Enchantment

mov ax,si
call getwiz
cmp     word ptr [bx-5EDAh], 0C8h ; Don't do if low on mana
jge     short loc_E4996
mov word ptr [bp-46h], 0
loc_E4996:

or cx,cx
jz skipggg
cmp word ptr [0BD90h],100
jge skipggg
mov word ptr [bp-46h], 1000 ; Have a global enchantment before turn 100? Use it ASAP, it's Just Cause or Aura of Majesty (or maybe AEther Binding/Divine Order)!
skipggg:


;----------------------------
; 16 - Focus Magic
mov ax,2Fh
call isknown
or ax,ax
jz nofo
call FocusMagicNeeded
mov     ax, 32h ; '2'
imul    cx
mov [bp-40h],ax ; 16 -Focus Magic

nofo:

;---------------------------------------------------------------------
; 27 - Water Walking/Wraith Form to enable participation in doomstacks

; Past turn 200 only
cmp word ptr [0BD90h],200
jle nointercontinentalneed

; If AI doesn't know intercontinental very rare summon
xor cx,cx
mov ax,47h ; Djinn
call isknown
or cx,ax
mov ax,4Eh ; Sky Drake
call isknown
or cx,ax
mov ax,76h ; Great Drake
call isknown
or cx,ax
mov ax,6Ah ; Efreet
call isknown
or cx,ax
mov ax,6Bh ; Doom Bat
call isknown
or cx,ax
mov ax,9Fh ; Archangel
call isknown
or cx,ax
mov ax,0B8h ; Wraiths
call isknown
or cx,ax
mov ax,0C1h ; Death Knights
call isknown
or cx,ax
mov ax,0C8h ; Demon Lord
call isknown

or cx,ax
jnz nointercontinentalneed

mov ax,8 ; Water Walking
call isknown
or ax,ax
jnz yes771
mov ax,0A8h ; Wraith Form
call isknown
or ax,ax
jz nointercontinentalneed
yes771:

mov word ptr [bp-2Ah],100 ; fairly high priority - these are cheap spells and intercontinental units are vastly larger threat to the human player!
nointercontinentalneed:

;----------------------------
; 07 - Intercontinental travel category

; Doesn't have enough ships
mov al,[9094h]  ; Arcanus ships
add al,[9095h]  ; Myrror ships
cmp al,[0BD96h] ; Difficulty
jg noshipneeded

needintercontinental:

xor di,di
mov ax,3Fh
call isknown
add di,ax
mov ax,2Bh
call isknown
add di,ax
mov ax,0A8h
call isknown
add di,ax
mov ax,08h
call isknown
add di,ax
mov ax,38h
call isknown
add di,ax
or di,di
jz noshipneeded
mov word ptr [bp-52h],33 ; Cast one / 3 summon spells
noshipneeded:

;----------------------------
; 11 - Items/Artifacts

mov bx,[9120h] ; Spell Categories Known
cmp byte ptr [bx+36h],1 ; Enchant/create
jnz plplpwggf
cmp word ptr [0BD90h],180 ; Don't before turn 180
jl plplpwggf
mov ax,si
call getwiz
mov word ptr [bp-4Ah],8
cmp     byte ptr [bx-60C1h], 0
jz plplpwggf2
mov word ptr [bp-4Ah],20 ; One item for 5 creatures
plplpwggf2:

cmp word ptr [bx-60D6h],3  ;At least 3 LIFE books! If the AI can't heal the heroes, equipping them is a bad move!!!
jge asasaqq
sub word ptr [bp-4Ah],3 ; Less if not a life wizard.
asasaqq:

cmp word ptr [bx-60DAh],3  ;At least 3 Sorcery books! (Sorcery items are good. Also hero might be protected by Magic Immunity!)
jge asasaqq2
sub word ptr [bp-4Ah],3 ; Less if not a sorcery wizard.
asasaqq2:

plplpwggf:

;----------------------------
; 14 - Stasis

mov ax,44h
call isknown
or ax,ax
jz notdoom1

cmp word ptr [0BD96h],3 ; If difficulty Hard or lower, don't attempt to freeze enemy stacks - not enough overland skill discount, and also this is not a player friendly tactic.
jl notdoom1
mov ax,si
call getwiz
cmp word ptr [bx-60E0h],250 ; If skill<250, can't afford using Stasis every turn, would take up more than 25% skill per stack
jle notdoom1


mov di,si
mov si,44h

lea ax,[bp-0Ah]
push ax
lea ax,[bp-8]
push ax
lea ax,[bp-6] ; TargetunitID
push ax
push di
push cs
call StasisTarget
add sp,8
mov si,di
or ax,ax
jz notdoom1 ; No target found

mov ax,[bp-6]
mov cl,5
shl ax,cl
les bx,[9EC2h]
add bx,ax

mov word ptr [bp-6],0

mov dx,es:[bx] ; Pos X,Y
mov di,es:[bx+2] ; Plane, Owner

cmp byte ptr es:[bx+3],0
jnz notdoom1

; is it near the capital?
mov     ax, si
mov     cl, 2
shl     ax, cl
les     bx, [9CC8h] ;Fortress
add     bx, ax

mov al,es:[bx]
sub al,dl
cmp al,0
jge tdtdtd
neg al
tdtdtd:
cmp al,7
jg notdoom1

mov ah,es:[bx+1]
sub ah,dh
cmp ah,0
jge tdtdtd2
neg ah
tdtdtd2:
cmp ah,7
jg notdoom1
; Stack is in a distance of 7 or less from the capital!

xor cx,cx
nextunit222:
push cx
mov cl,5
shl ax,cl
pop cx
les bx,[9EC2h]
add bx,ax
cmp es:[bx],dx
jnz notqqwe
cmp es:[bx+2],di
jnz notqqwe
; Unit is part of the targeted stack
mov al,es:[bx+5]
xor ah,ah
cmp ax,22h
jle doomstack
push dx
mov     dx, 24h ; '$'
imul    dx
pop dx
mov     bx, ax
cmp word ptr [bx+1A6h],250 ; At least cost 250 units
jle notqqwe
doomstack:
inc word ptr [bp-6]

notqqwe:
inc cx
cmp cx,[0BD92h]
jl nextunit222

cmp word ptr [bp-6],5
jl notdoom1
; At least 5 units of high value (251+) or hero
; this is a doomstack!
; (disregard buffs - dispelling wave should solve that)
mov word ptr [bp-44h],10000 ; Must stop doomstack before it attacks!
notdoom1:

;----------------------------
; 15 - Lycanthropy

mov ax,0ADh
call isknown
or ax,ax
jz noli
mov word ptr [bp-42h], 5 ; Low priority in late game
cmp word ptr [0BD90h],120
jge noli
mov word ptr [bp-42h], 180 ; High priority in early game
noli:

;----------------------------
; 17 -Time Stop

mov ax,50h
call isknown
or ax,ax
jz notimestop
mov ax,si
call getwiz
cmp byte ptr [bx-5CAEh], 0 ; Already in effect
jnz notimestop

cmp word ptr [bx-5EDAh], 1388h ; Not enough mana to use - requires at least 5000
jl notimestop
mov word ptr [bp-3Eh],1000 ; Can cast Time Stop? Do it! 17 -Time Stop

cmp word ptr [911Ah],0
jg notimestop
cmp word ptr [bx-5EDAh], 15000 ; But wait until 15000 if not planning to attack, is more economical
jge notimestop
mov word ptr [bp-3Eh],0 ; Waiting for more mana
notimestop:

;----------------------------
; 18 - Magic Immunity

mov ax,45h
call isknown
or ax,ax
jz notmaimu
mov word ptr [bp-3Ch],50 ; Default, use once per two summoned creatures
notmaimu:


;----------------------------
;19 -Cheap Buff stacking - Don't do if Doom Mastery, Suppress Magic

xor cx,cx
mov ax,82h ; Heroism
call isknown
add cx,ax
mov ax,7Eh ; Holy Armor
call isknown
add cx,ax
mov ax,7Bh ; Endurance
call isknown
add cx,ax
mov ax,79h ; Bless
call isknown
add cx,ax
mov ax,29h ; Resist Magic
call isknown
add cx,ax
mov ax,56h ; Flame Blade
call isknown
add cx,ax

cmp cx,4 ; Use additional cheap buff stacking tactic id and only if at least 4 of the above are known
jl dorrr
cmp word ptr [0BD90h],120 ; Don't before turn 120, these aren't cheap at all that early! (if no summon, buffs will automatically get used instead)
jl dorrr
mov word ptr [bp-3Ah],150 ; 1.5 buffs per summon

dorrr:

;----------------------------
; 26 - Spell Lock
call SpellLockNeeded

mov ax,36h
call isknown
or ax,ax
jnz notlock1
mov word ptr [bp-2Ch],0
notlock1:
;----------------------------
; 21 - Final Wave

mov ax,0C7h
call isknown
or ax,ax
jz notwave6
mov word ptr [bp-36h],60 ;  60 priority
notwave6:

;----------------------------
; 22 - Great unsummoning

mov ax,04Bh
call isknown
or ax,ax
jz notwave8
Call UnsummonDecider
cmp ax,5
jl notwave8
sal ax,1
mov word ptr [bp-34h],ax ; priority = 2x enemy fantastic units in play
notwave8:

;----------------------------
; 25 -Planar Travel

cmp word ptr [0BD90h],100 ; Not after turn 100
jge qoqoqoq
mov ax,8Ah
call isknown
or ax,ax
jz qoqoqoq ; Planer Travel must be known
mov ax,8Bh
call isknown
or ax,ax
jnz qoqoqoq ; Astral Gate must be unknown
mov word ptr [bp-2Eh],40
qoqoqoq:

;----------------------------
; 24 - Summoning Circle

mov ax,0CBh
call isknown
or ax,ax
jz nocir

mov     ax, si
shl     ax, 1
mov     bx, [8F98h] ; Circle needed timer
add     bx, ax
cmp     byte ptr [bx], 0
jg  nocir

; At least 2 cities known

xor cx,cx
xor     di, di
nextcit11:
mov     ax, di
mov     dx, 72h ; 'r'
imul    dx
les     bx, [9CBCh] ; dword_4075C
add     bx, ax
mov     al, es:[bx+12h]
cbw
cmp     ax, si
jnz aswq
inc cx
aswq:
inc di
cmp di,[0BD94h]
jl nextcit11
cmp cx,2
jl nocir
mov word ptr [bp-30h],4000 ; 24 -Summoning Circle
nocir:

;-----------------------------
; 06 - Curses
mov bx,[9120h] ; Spell Categories Known

cmp byte ptr [bx+34h],0 ; Building Destruction - Earthquake, Chaos rift
jz curse666a
add word ptr [bp-54h],25 ; +25 priority
curse666a:

cmp byte ptr [bx+1Ch],0 ; Direct Damage - Blizzard, Fire Storm
jz curse666b
add word ptr [bp-54h],18 ; +18 priority
curse666b:

cmp byte ptr [bx+29h],0 ; Warp Node
jz curse666c
add word ptr [bp-54h],18 ; +18 priority
curse666c:

cmp byte ptr [bx+4Fh],0 ; Top curses - Call the Void, Pestilence
jz curse666d
add word ptr [bp-54h],65 ; +65 priority
curse666d:

cmp byte ptr [bx+39h],0 ; Basic city curses - Famine, Evil presence
jz curse666e
add word ptr [bp-54h],40 ; +40 priority
curse666e:

;----------------------------
; More armies needed tactic - 01, 06
mov ax,si
call getwiz
cmp word ptr [bx-5C9Ch], 3 ; Main tactic - more armies needed
jnz ujuj
add word ptr [bp-5Eh],40 ; +40 Summons

mov ax,[bp-54h]
sar ax,2
add word ptr [bp-54h],ax ; +25% to curses

mov bx,[9120h] ; Spell Categories Known
cmp byte ptr [bx+2Ch],1 ; Military purpose city buffs (Cloud of Shadow, Altar of Battle, Spell Ward, etc)
jnz jojojo
add word ptr [bp-5Ah],30 ; +30 Military purpose city buffs
jojojo:


ujuj:
mov ax,si
call getwiz
cmp word ptr [bx-5C9Ch], 4 ; Main tactic - much armies needed
jnz ujuj2
add word ptr [bp-5Eh],100 ; +100 Summons

mov ax,[bp-54h]
sar ax,1
add word ptr [bp-54h],ax ; +50% to curses

jnz jojojo2
add word ptr [bp-5Ah],75 ; +75 Military purpose city buffs
jojojo2:
ujuj2:


;-----------------------------
; Objectives
mov ax,si
call getwiz

; Militarist
cmp     byte ptr [bx-611Ch], 1
jnz cvcvcv
add word ptr [bp-5Eh],33 ; +33 summoning
cmp word ptr [bp-5Ch],0
jz skip78282g
add word ptr [bp-5Ch],33 ; +33 Unit buffs
skip78282g:
cvcvcv:

; Theurgist
cmp     byte ptr [bx-611Ch], 2
jnz cvcvcv2
cmp word ptr [bp-5Ah],0
jz skip78281x
add word ptr [bp-5Ah],50 ; +50 City buffs
skip78281x:
;cmp word ptr [bp-46h],0
;jz skip78281y
sal word ptr [bp-46h],1 ; Global Enchantments double
;skip78281y:
cvcvcv2:

; Perfectionist
cmp     byte ptr [bx-611Ch], 3
jnz cvcvcv3
cmp word ptr [bp-5Ch],0
jz skip78282w
mov ax,[0BD90h]
cmp ax,120
jl a7a7a7a
mov ax,120
a7a7a7a:
add word ptr [bp-5Ch],ax ; +120 Unit buffs, or current turn if below
skip78282w:
cmp word ptr [bp-5Ah],0
jz skip78281xg
add word ptr [bp-5Ah],50 ; +50 City buffs
skip78281xg:
cvcvcv3:

; Expansionist
cmp     byte ptr [bx-611Ch], 4
jnz cvcvcv4
add word ptr [bp-5Eh],33 ; +33 summoning
cmp word ptr [bp-5Ch],0
jz skip78282gqq
sub word ptr [bp-5Ch],40 ; -40 Unit buffs
skip78282gqq:
mov ax,[bp-54h]
sar ax,1
add word ptr [bp-54h],ax ; +50% to curses
cvcvcv4:

;----------------------------
; Divine Order

xor cx,cx
loc_E45DF:
mov     ax, cx
mov     dx, 4C8h
imul    dx
mov     bx, ax
cmp     byte ptr [bx-5CA0h], 0
jz      short loc_E460D

; Divine Order in effect
mov ax,[bp-54h]
cwd
mov bx,3
idiv bx
add word ptr [bp-54h],ax ; +33% to Curses for each
sal word ptr [bp-42h],1 ; Double Lycanthropy - cheaper werewolves are great when summoning is more expensive. Still fairly low in late game unless 3+ divine orders!
mov ax,[bp-3Ah]
sar ax,1
add word ptr [bp-3Ah],ax ; Do 50% more "cheap buff stacking" tactic for each
add word ptr [bp-38h],50 ; Cast more Invisibility tactic
cmp word ptr [bp-5Ch],0
jz skip78282
add word ptr [bp-5Ch],40 ; +40 Unit buffs
skip78282:

cmp word ptr [bp-3Ch],0
jz skip782829    
add word ptr [bp-3Ch],25 ; +25 Magic Immunity
skip782829:

cmp word ptr [bp-5Ah],0
jz skip78281
add word ptr [bp-5Ah],30 ; +30 City buffs
skip78281:

loc_E460D:
inc     cx
cmp     cx, 4
jle     short loc_E45DF

;-----------------------------
;
cmp word ptr [-60DAh],4 ; Don't do invisibility spam tactic if human is sorcery (dispelling wave counters it too well!)
jge dont111

mov ax,si
call getwiz
cmp byte ptr [bx-5FDEh],1
jz dont111
cmp byte ptr [bx-5FDEh],2
jnz war111
dont111:
mov word ptr [bp-38h],0 ; Don't do invisibility spam tactic if pact or alliance with human!
war111:

mov ax,4Ah
call isknown
jz aawwwee
mov word ptr [bp-38h],0 ; Don't do invisibility spam tactic if mass invisibility is known!
aawwwee:

;-----------------------------------------------------------
; Spirit, priority 0 before turn 20 - no need for them yet

cmp word ptr [0BD90h],20
jg assqq
mov word ptr [bp-60h],0 ; Magic Spirit category - Do not use!
assqq:

;-----------------------------------------
; Suppress, Meteor, Wrath modifiers
mov dx,si
call GlobalEnchantmentEffects
; Out : CL = number of meteor storms in effect
;       CH = Suppress Magics
;       DL = Fairy Rings
;       DH = Chaos Surges

or ch,ch
jz nosup111
; Suppress Magic in effect
mov word ptr [bp-60h],0 ; Magic Spirit category - Do not use!
mov word ptr [bp-52h],0 ; Intercontinental travel cateogory - Do not use (all low cost spells, except wind walking which is still only 250)
sar word ptr [bp-5Ch],1 ; Unit buffs halved - low chance of success
sar word ptr [bp-5Ah],1 ; City buffs halved - low chance of success
mov word ptr [bp-58h],0 ; Disenchant Area zero - cost 25 spell, wasteful, unlikely to succeed
sar word ptr [bp-4Eh],3 ; Spell Blast reduced - still try but don't go overboard.
sar word ptr [bp-4Ch],1 ; Dispelling Wave halved - low chance of success, but potential high damage, worth some try
mov word ptr [bp-44h],0 ; Stasis
mov word ptr [bp-42h],0 ; Lycanthropy
mov word ptr [bp-40h],0 ; Focus Magic
mov word ptr [bp-3Ah],0 ; Cheap Buff Stacking
mov word ptr [bp-38h],0 ; Invisibility
mov word ptr [bp-32h],0 ; Nature's Cures
mov word ptr [bp-30h],0 ; Summoning Circle
mov word ptr [bp-2Eh],0 ; Planar Travel
mov word ptr [bp-2Ch],0 ; Spell Lock
mov word ptr [bp-2Ah],0 ; Waterwalk/Wraith Form for doomstack
nosup111:

or dl,dl
jz nowrath13
;Fairy Ring in effect
;mov word ptr [bp-36h],0 ; Final Wave
;mov word ptr [bp-34h],0 ; Great Unsummoning
mov word ptr [bp-50h],0 ; Hero summoning (nonnature expensive spells, except basic Summon Hero which is obsolete by the time NW comes into play)
mov word ptr [bp-4Ah],0 ; Item creation
; Unsure about Time Stop, too powerful, probably worth it anyway!
nowrath13:







; Curse priority zero if no hostility!
cmp word ptr [911Ah],0
jg safecurse
mov word ptr [bp-54h],0 ; 06 -Curse
safecurse:

;Curse priority zero if no curses known!
mov bx,[9120h] ; Spell Categories Known

cmp byte ptr [bx+34h],1 ; Building Destruction - Earthquake, Chaos rift
jz curseok9

cmp byte ptr [bx+1Ch],1 ; Direct Damage - Blizzard, Fire Storm
jz curseok9

cmp byte ptr [bx+29h],1 ; Warp Node
jz curseok9

cmp byte ptr [bx+4Fh],1 ; Top curses - Call the Void, Pestilence
jz curseok9

cmp byte ptr [bx+39h],1 ; Basic city curses - Famine, Evil presence
jz curseok9

cmp byte ptr [bx+22h],1 ; Spell Blast
jz curseok9

cmp byte ptr [bx+0Eh],1 ; Weak Curses - Stasis, Corruption, Raise Volcano, Drain Power
jz curseok9

mov word ptr [bp-54h],0 ; 06 - Curse, zero if none known!

curseok9:



























;self: jmp self

call pickcategory

;mov ax,si
;call getwiz
;mov word ptr [bx-60ECh], cx


;=====================================================
;=====================================================
; Spell from category
;=====================================================
;=====================================================
; In CX = category
; Out DI = spell

;---------------------------
; 0 -Magic Spirit category
;---------------------------
cmp cx,0
jnz ski1
dospirit:
mov di,0C9h ; Magic Spirit
mov ax,81h  ; Guardian Spirit
call isknown
or ax,ax
jz ssdone
mov di,81h
jmp ssdone
ski1:

;---------------------------
; 1 - Summon category
;---------------------------
cmp cx,1
jnz ski2
jmp skiptable1
summontable:
db 006h,003 ; SLOT 0 - War Bears
db 009h,003 ; SLOT 1 - Sprites
db 00Eh,012 ; SLOT 2 - Giant Spiders
db 014h,020 ; SLOT 3 - Great Lizard
db 017h,032 ; SLOT 4 - Stone Giant
db 01Bh,050 ; SLOT 5 - Gorgons
db 020h,100 ; SLOT 6 - Behemoth
db 024h,150 ; SLOT 7 - Colossus
db 027h,150 ; SLOT 8 - Great Wyrm
db 037h,016 ; SLOT 9 - Water Elemental
db 041h,024 ; SLOT10 - Storm Giant
db 047h,075 ; SLOT11 - Djinn
db 04Eh,150 ; SLOT12 - Sky Drake
db 054h,002 ; SLOT13 - Hell Hound
db 05Fh,006 ; SLOT14 - Gargoyles
db 06Bh,050 ; SLOT15 - Doom Bat
db 067h,024 ; SLOT16 - Chaos Spawn
db 05Ch,012 ; SLOT17 - Fire Giant
db 064h,016 ; SLOT18 - Chimera
db 06Ah,040 ; SLOT19 - Efreet
db 06Fh,032 ; SLOT20 - Hydra
db 076h,150 ; SLOT21 - Great Drake
db 088h,010 ; SLOT22 - Unicorns
db 093h,024 ; SLOT23 - Angel
db 09Fh,090 ; SLOT24 - Archangel
db 000h,000 ; SLOT25
db 0A1h,001 ; SLOT26 - Skeleton
db 0A6h,004 ; SLOT27 - Ghouls
db 0B0h,012 ; SLOT28 - Night Stalker
db 031h,002 ; SLOT29 - Nagas
db 0B8h,032 ; SLOT30 - Wraiths
db 0B4h,024 ; SLOT31 - Shadow Demons
db 0C1h,064 ; SLOT32 - Death Knights
db 0C8h,200 ; SLOT33 - Demon Lord
db 000h,000 ; SLOT34
db 000h,000 ; SLOT35
db 000h,000 ; SLOT36
db 000h,000 ; SLOT37
db 000h,000 ; SLOT38
db 000h,000 ; SLOT39
db 000h,000 ; SLOT40
db 000h,000 ; SLOT41
db 011h,012 ; SLOT42 - Cockatrices
db 0BFh,032 ; SLOT43 - Summon Demon
skiptable1:
dosummon:
mov bx,summontable
mov cx,43
call loadtable

; If Death Knights, Wraiths = zero
mov ax,0C1h
call isknown
or ax,ax
jz skip555
mov word ptr [0D3C4h],0 ; Wraiths Priority zero
skip555:

mov dx,si
call GlobalEnchantmentEffects

; Out : CL = number of meteor storms in effect
;       CH = Suppress Magics
;       DL = Fairy Rings
;       DH = Chaos Surges

cmp cl,0
jle nomoremeteor

mov word ptr [0D388h],0 ; War Bears
mov word ptr [0D3C2h],0 ; Nagas
mov word ptr [0D38Ah],0 ; Sprites
mov word ptr [0D38Ch],0 ; Giant Spiders
mov word ptr [0D3A2h],0 ; Hell Hounds
mov word ptr [0D3ACh],0 ; Chimeras
mov word ptr [0D3B4h],0 ; Unicorns
mov word ptr [0D3BCh],0 ; Skeletons
mov word ptr [0D3BEh],0 ; Ghouls
shr word ptr [0D3DCh],1 ; Halved cockatrices

nomoremeteor:

nextsurge:
cmp dh,0
jle nomoresurge

mov ax,40
mov bx,0D3A4h ; Gargoyles
call addto

mov al,50
mov bx,0D3ACh ; Chimeras
call addto

mov al,100
mov bx,0D3B0h ; Hydra
call addto

mov al,20
mov bx,0D3A2h ; Hell Hounds
call addto

mov ax,10
mov bx,0D3A6h ; Doom Bat
call addto

;mov ax,20
mov bx,0D3A8h ; Chaos Spawn
call addto

mov bx,0D3AAh ; Fire Giant
call addto

mov bx,0D3AEh ; Efreet
call addto

mov bx,0D3B2h ; Great Drake
call addto

dec dh
jmp nextsurge

nomoresurge:

cmp ch,0
jle nomoresuppress

mov word ptr [0D388h],0 ; War Bears
mov word ptr [0D3C2h],0 ; Nagas
mov word ptr [0D38Ah],0 ; Sprites
mov word ptr [0D38Ch],0 ; Giant Spiders
;mov word ptr [0D39Ah],0 ; Floating Island
mov word ptr [0D3A2h],0 ; Hell Hounds
mov word ptr [0D3A4h],0 ; Gargoyles
mov word ptr [0D3AAh],0 ; Fire Giants
mov word ptr [0D3BCh],0 ; Skeletons
mov word ptr [0D3BEh],0 ; Ghouls
;mov word ptr [0D3CEh],0 ; Magic Spirit
mov word ptr [0D3DCh],0 ; Cockatrices

shl word ptr [0D392h],1 ; Gorgons x2
shl word ptr [0D394h],1 ; Behemoth x2
shl word ptr [0D396h],2 ; Colossus x4
shl word ptr [0D398h],2 ; Wyrm x4
shl word ptr [0D39Eh],1 ; Djinn x2
shl word ptr [0D3A0h],2 ; Sky Drake x4
shl word ptr [0D3B0h],1 ; Hydra x2
shl word ptr [0D3B2h],2 ; Great Drake x4
shl word ptr [0D3B8h],2 ; Archangel x4
shl word ptr [0D3C4h],1 ; Wraiths x2
shl word ptr [0D3C8h],2 ; Death Knights x2
shl word ptr [0D3CAh],2 ; Demon Lord x4

nomoresuppress:

nextwrath:
cmp dl,0
jle nomorewrath

; Don't cast - these aren't worth letting the enemy get a free summon
;mov word ptr [0D3D8h],0 ; Summon Champion
;mov word ptr [0D3D2h],0 ; Enchant Item
;mov word ptr [0D3D4h],0 ; Create Artifact

; Reduced priority
sar word ptr [0D3A8h],2 ; Chaos Spawn
sar word ptr [0D3B6h],1 ; Angel
sar word ptr [0D3C4h],1 ; Wraiths
sar word ptr [0D39Ch],1 ; Storm Giant
sar word ptr [0D3AEh],1 ; Efreet
sar word ptr [0D3B0h],1 ; Hydra
; Doom Bats?
; Gorgons?
;sar word ptr [0D39Eh],1 ; Djinn
;sar word ptr [0D39Eh],1 ; Sky Drake
;sar word ptr [0D3B2h],1 ; Great Drake
;sar word ptr [0D3B8h],1 ; Archangel
;sar word ptr [0D3C8h],1 ; Death Knights
;sar word ptr [0D3CAh],1 ; Demon Lord
sar word ptr [0D3CCh],1 ; Resurrection

dec dl
jmp nextwrath

nomorewrath:

Call SelectASpell

cmp ax,0
jl failed533 ; -1 = failed to pick a spell

mov bx,ax
sal bx,1

mov al,cs:[bx+Summontable]
xor ah,ah
mov di,ax
cmp di,0
jg ssdone
failed533:
; Failed to pick a summoning spell!
; Do a Unit Buff instead
mov cx,2
ski2:

;---------------------------
; 2 - Unit Buff category
;---------------------------
cmp cx,2
jnz ski3
jmp skiptable2
bufftable:
db 002h,003 ; SLOT 0 - Resist Elements
db 02Fh,009 ; SLOT 1 - Focus Magic
db 015h,010 ; SLOT 2 - Elemental Armor
db 018h,030 ; SLOT 3 - Iron Skin
db 01Fh,050 ; SLOT 4 - Regeneration
db 029h,015 ; SLOT 5 - Resist Magic
db 000h,000 ; SLOT 6
db 000h,000 ; SLOT 7
db 045h,020 ; SLOT 8 - Magic Immunity
db 056h,009 ; SLOT 9 - Flame Blade
db 000h,000 ; SLOT10
db 063h,015 ; SLOT11 - Immolation
db 07Ch,006 ; SLOT12 - Holy Weapon
db 079h,010 ; SLOT13 - Bless
db 07Eh,015 ; SLOT14 - Holy Armor
db 082h,018 ; SLOT15 - Heroism
db 083h,005 ; SLOT16 - True Sight
db 08Fh,050 ; SLOT17 - Invulnerability
db 08Dh,050 ; SLOT18 - Lionheart
db 000h,000 ; SLOT19
db 0A4h,005 ; SLOT20 - Cloak of Fear
db 000h,000 ; SLOT21
db 0A8h,015 ; SLOT22 - Wraith Form
db 008h,015 ; SLOT23 - Water Walking
db 010h,012 ; SLOT24 - Land Linking
db 000h,000 ; SLOT25
db 038h,015 ; SLOT26 - Flight
db 03Fh,050 ; SLOT27 - Wind Walking
db 07Bh,015 ; SLOT28 - Endurance
db 000h,000 ; SLOT29
db 08Ah,010 ; SLOT30 - Planar Travel
db 000h,000 ; SLOT31
db 000h,000 ; SLOT32
db 036h,010 ; SLOT33 - Spell Lock
db 03Eh,040 ; SLOT34 - Invisibility
db 05Dh,015 ; SLOT35 - Chaos Channels
db 000h,000 ; SLOT36 (was Lycanthropy, separating)
db 0B3h,020 ; SLOT37 - Blood Lust
db 02Ch,010 ; SLOT38 - Guardian Wind
skiptable2:

mov bx,bufftable
mov cx,38
call loadtable

cmp [0BD90h],10
jge canfocus1
mov word ptr [0D38Ah],0
canfocus1:

mov     ax, 4C8h
imul    si
mov     bx, ax
cmp     byte ptr [bx-5CA1h], 0
jnz arms
cmp     byte ptr [bx-5E39h], 2
jnz     short loc_E5864
arms:
mov word ptr [0D3A0h],0 ; Holy Weapon zero if Holy Arms in effect or known
loc_E5864:

; Chaos Channels do not use during Doom Mastery
mov ax,si
call getwiz
cmp     byte ptr [bx-5CA9h], 0
jz     short loc_E5619
mov word ptr [0D3CEh],0
loc_E5619:

mov dx,si
call GlobalEnchantmentEffects

; Out : CL = number of meteor storms in effect
;       CH = Suppress Magics
;       DL = Fair Rings
;       DH = Chaos Surges

nextmeteor2:
cmp cl,0
jle nomoremeteor2

mov ax,25
mov bx,0D388h ; Resist elements +25
call addto
mov al,50
mov bx,0D38Ch ; +50 Elemental Armor
call addto
mov al,10
mov bx,0D38Eh ; +10 Iron Skin
call addto

mov al,10
mov bx,0D390h ; +10 Regeneration
call addto

mov al,10
mov bx,0D398h ; +10 Magic Immunity
call addto

mov al,35
mov bx,0D3A2h ; Bless +35
call addto

mov al,20
mov bx,0D3AAh ; Invulnerability +20
call addto

dec cl
jmp nextmeteor2


nomoremeteor2:


nextsurge2:
cmp dh,0
jle nomoresurge2

mov ax,60
mov bx,0D3CEh ; Chaos Channels +60
call addto

dec dh
jmp nextsurge2

nomoresurge2:

cmp ch,0
jle nomoresuppress2

mov word ptr [0D388h],0 ; Resist Elements
mov word ptr [0D392h],0 ; Resist Magic
mov word ptr [0D3A0h],0 ; Holy Weapon
mov word ptr [0D3A4h],0 ; Holy Armor
mov word ptr [0D3A6h],0 ; Heroism
mov word ptr [0D3A8h],0 ; True Sight
mov word ptr [0D3B0h],0 ; Cloak of Fear
mov word ptr [0D3B6h],0 ; Waterwalking
mov word ptr [0D3C4h],0 ; Planar Travel

nomoresuppress2:


Call SelectASpell

cmp ax,0
jl dospirit

mov bx,ax
sal bx,1

mov al,cs:[bx+Bufftable]
xor ah,ah
mov di,ax
jmp ssdone

ski3:

;---------------------------
; 3 - City Buff Category
;---------------------------
cmp cx,3
jnz ski4
jmp skiptable3
citytable:
db 003h,005 ; SLOT 0 - Nature's Eye
db 012h,020 ; SLOT 1 - Transmute
db 00Fh,020 ; SLOT 2 - Change Terrain
db 000h,000 ; SLOT 3
db 03Dh,035 ; SLOT 4 - Uranus's Blessing
db 025h,100 ; SLOT 5 - Earth Gate
db 01Dh,050 ; SLOT 6 - Gaia's Blessing
db 046h,012 ; SLOT 7 - Flying Fortress
db 057h,012 ; SLOT 8 - Wall of Fire
db 080h,025 ; SLOT 9 - Heavenly Light
db 084h,030 ; SLOT10 - Stream of Life
db 090h,030 ; SLOT11 - Inspirations
db 091h,030 ; SLOT12 - Prosperity
db 08Bh,015 ; SLOT13 - Astral Gate
db 0BEh,045 ; SLOT14 - Dark Rituals
db 0B9h,025 ; SLOT15 - Cloud of Shadow
db 048h,050 ; SLOT16 - Spell Ward
db 09Bh,025 ; SLOT17 - Consecration
db 0B2h,012 ; SLOT18 - Wall of Darkness
db 092h,010 ; SLOT19 - Altar of Battle


skiptable3:

mov bx,citytable
mov cx,19
call loadtable

lea ax,[bp-6]
push ax
push si
push cs
call NatureEyetarget
pop cx
pop cx
or ax,ax
jnz okeye
mov word ptr [0D388h],0
okeye:

lea ax,[bp-0Ah]
push ax
lea ax,[bp-8]
push ax
lea ax,[bp-6]
push ax
push si
push cs
call Transmutetarget
pop cx
pop cx
pop cx
pop cx
or ax,ax
jnz oktrans
mov word ptr [0D38Ah],0
oktrans:

lea ax,[bp-0Ah]
push ax
lea ax,[bp-8]
push ax
lea ax,[bp-6]
push ax
push si
push cs
call CTtarget
pop cx
pop cx
pop cx
pop cx
or ax,ax
jnz okCT
mov word ptr [0D38Ch],0
okCT:

lea ax,[bp-6]
push ax
push si
push cs
call UranusTarget
pop cx
pop cx
or ax,ax
jnz okura
mov word ptr [0D390h],0
okura:

lea ax,[bp-6]
push ax
push si
push cs
call EarthGateTarget
pop cx
pop cx
or ax,ax
jnz okEG
mov word ptr [0D392h],0
okEG:

lea ax,[bp-6]
push ax
push si
push cs
call GaiaTarget
pop cx
pop cx
or ax,ax
jnz okGB
mov word ptr [0D394h],0
okGB:

lea ax,[bp-6]
push ax
push si
push cs
call FFTarget
pop cx
pop cx
or ax,ax
jnz okFF
mov word ptr [0D396h],0
okFF:

lea ax,[bp-6]
push ax
push si
push cs
call WoFTarget
pop cx
pop cx
or ax,ax
jnz okWoF
mov word ptr [0D398h],0
okWoF:

lea ax,[bp-6]
push ax
push si
push cs
call HeavenlyTarget
pop cx
pop cx
or ax,ax
jnz okHeav
mov word ptr [0D39Ah],0
okHeav:

lea ax,[bp-6]
push ax
push si
push cs
call StreamTarget
pop cx
pop cx
or ax,ax
jnz okSL
mov word ptr [0D39Ch],0
okSL:

lea ax,[bp-6]
push ax
push si
push cs
call InspirationTarget
pop cx
pop cx
or ax,ax
jnz okIns
mov word ptr [0D39Eh],0
okIns:

lea ax,[bp-6]
push ax
push si
push cs
call ProsperityTarget
pop cx
pop cx
or ax,ax
jnz okProsp
mov word ptr [0D3A0h],0
okProsp:

lea ax,[bp-6]
push ax
push si
push cs
call AstralTarget
pop cx
pop cx
or ax,ax
jnz okAstral
mov word ptr [0D3A2h],0
okAstral:

lea ax,[bp-6]
push ax
push si
push cs
call DarkRitualTarget
pop cx
pop cx
or ax,ax
jnz okDark
mov word ptr [0D3A4h],0
okDark:

lea ax,[bp-6]
push ax
push si
push cs
call CSTarget
pop cx
pop cx
or ax,ax
jnz okCS
mov word ptr [0D3A6h],0
okCS:

lea ax,[bp-8]
push ax
lea ax,[bp-6]
push ax
push si
push cs
call WardTarget
pop cx
pop cx
pop cx
or ax,ax
jnz okWard
mov word ptr [0D3A8h],0
okWard:

lea ax,[bp-6]
push ax
push si
push cs
call ConsTarget
pop cx
pop cx
or ax,ax
jnz okCons
mov word ptr [0D3AAh],0
okCons:

lea ax,[bp-6]
push ax
push si
push cs
call WoDTarget
pop cx
pop cx
or ax,ax
jnz okWoD
mov word ptr [0D3ACh],0
okWoD:

lea ax,[bp-6]
push ax
push si
push cs
call AltarTarget
pop cx
pop cx
or ax,ax
jnz okAltar
mov word ptr [0D3AEh],0
okAltar:

Call SelectASpell

cmp ax,0
jl TryAgain ; Failed to pick a city buff - pick another category!

mov bx,ax
sal bx,1

mov al,cs:[bx+Citytable]
xor ah,ah
mov di,ax

or di,di
jle TryAgain ; Failed to pick a city buff - pick another category!
jmp ssdone

ski4:

;---------------------------
; 4 - Disenchant Area Category
;---------------------------

cmp cx,4
jnz ski5
mov di,0CCh
mov word ptr [bp-2],25 ; Extra slider 25% - works best without extra slider
jmp ssdone
ski5:

;---------------------------
; 5 - Disjunction Category
;---------------------------

cmp cx,5
jnz ski6

mov di,4Ch
mov ax,4Ch
call isknown ; Spell Binding if able!
or ax,ax
jnz sliderset
; Disjunction!
mov di,0D2h

sliderset:
push si
push di
lea ax,[bp-6]   ; Target Spell
push ax
lea ax,[bp-8]   ; Target Wizard
push ax
push cs
call DisjunctionTarget
add sp,8

cmp [bp-6],071h ; Against Meteor, Nature's Wrath, use 1200 (100% success)
jz need1200
; NW removed from the game
;cmp [bp-6],028h ; Against Meteor, Nature's Wrath, use 1200 (100% success)
;jz need1200

mov cx,1
xor dx,dx
nwiz:
mov     ax, cx
shl     ax, 2
les     bx, [9CC8h]
add     bx, ax
cmp     byte ptr es:[bx+3], 0
jz deadwiz
inc dx
deadwiz:
inc cx
cmp cx,[0BD9Ch] ;maxwizards
jl nwiz

; There are dx wizards in the game.
; Chance to actually proceed with dispel is only 1/(2*number of wizards)
sal dx,1
call random
cmp ax,1
jnz TryAgain

mov word ptr [bp-2],50 ; Default, use 1125 strength disjunctions

cmp [bp-6],04Fh ; Against Supress use max
jz supress

;cmp [bp-6],87h ; Against Divine Order, Detect Magic use base 375 value
;jz minimaldis
;cmp [bp-6],0CEh ; Against Divine Order, Detect Magic use base 375 value
;jz minimaldis
;cmp [bp-6],07Fh ; Against Just Cause use base 375 value
;jz minimaldis
;cmp [bp-6],039h ; Against AEther Binding use 600
;jz aether
jmp ds2
;minimaldis:
;mov word ptr [bp-2],0
;jmp ds2
;aether:
;mov word ptr [bp-2],15
;jmp ds2
supress:
mov word ptr [bp-2],100
jmp ds2
need1200:
mov word ptr [bp-2],55
ds2:

mov ax,[bp-6]
mov     dx, 24h ; '$'
imul    dx
les     bx, [91C2h] ; Spell_Data_Structure_Offset
add     bx, ax

mov     ax, es:[bx+1Ah] ; Spell cost

mov cx,ax
sar ax,1
add cx,ax ; 1.5 times the cost

;Runemaster
;AEther Binding

mov ax,si
call getwiz
cmp byte ptr [bx-60C4h],0 ; Runemaster
jz uhuhu
sar cx,1  ; 2 times means 50% resistance
uhuhu:

cmp byte ptr [bx-5CB0h],0 ; AEther Binding
jz uhuhu2
sar cx,1 ; Doube strength means half power
uhuhu2:

mov ax,100
imul cx
mov cx,375 ; How many % of the base amount needed?
idiv cx
inc ax ; Round up
sub ax,100
or ax,ax
jge asdf
xor ax,ax ; Can't do less then 0% slider
asdf:

cmp ax,[bp-2]
jge ssdone
mov ax,[bp-2]
jmp ssdone ; If less is enough for 100% go with less

ski6:

;---------------------------
; 6 - Curse category
;---------------------------
cmp cx,6
jnz ski7
jmp skiptable4
Cursetable:
db 019h,003 ; SLOT 0 - Blizzard
db 01Ah,015 ; SLOT 1 - Earthquake
db 03Ah,010 ; SLOT 2 - Spell Blast
db 044h,008 ; SLOT 3 - Stasis
db 000h,000 ; SLOT 4
db 055h,008 ; SLOT 5 - Corruption
db 061h,015 ; SLOT 6 - Fire Storm
db 062h,025 ; SLOT 7 - Raise Volcano
db 000h,000 ; SLOT 8
db 06Eh,040 ; SLOT 9 - Chaos Rift
db 077h,200 ; SLOT10 - Call the Void
db 0BDh,030 ; SLOT11 - Famine
db 0BAh,025 ; SLOT12 - Warp Node
db 000h,000 ; SLOT13
db 0ABh,020 ; SLOT14 - Drain Power
db 0B7h,030 ; SLOT15 - Evil Presence
db 000h,000 ; SLOT16 (was Dispelling Wave, do not use randomly, always on-demand)
db 0C4h,060 ; SLOT17 - Pestilence

skiptable4:

mov bx,Cursetable
mov cx,17
call loadtable


; Earthquake
mov ax,si
call getwiz
cmp     byte ptr [bx-5CACh], 0
jz noquake
push bx
mov bx,[9120h] ; Spell Categories Known
mov al, byte ptr [bx+4Ah] ; Best summon category known
add al, byte ptr [bx+4Eh] ; Second best summon category known
pop bx
cmp al,0
jz noquake ; Still cast EQ if no global summon to trigger SM.
mov word ptr [0D38Ah],0
noquake:

; Spell Blast, don't if human skill is low
cmp word ptr [-60E0h],200
jge oktoblast
mov word ptr [0D38Ch],0
oktoblast:

; No Raise Volcano during Armageddon!
mov ax,si
call getwiz
cmp     byte ptr [bx-5CA6h], 0
jz nogeddon
mov word ptr [0D396h],0
nogeddon:

; Warp Node check for valid target
mov ax,0BAh
push ax
lea ax,[bp-6]
push ax
push cs
call WarpNodeTarget
pop cx
pop cx
or ax,ax
jnz validtarget1
mov word ptr [0D3A0h],0 ;Do not use if no valid target!
validtarget1:

; Evil Presense check for valid target
push si
mov ax,0B7h
push ax
lea ax,[bp-6]
push ax
push 6
push cs
call CityCurseTarget
add sp,8
or ax,ax
jnz validtarget2
mov word ptr [0D3A6h],0 ;Do not use if no valid target!
validtarget2:

; Famine check for valid target
push si
mov ax,0BDh
push ax
lea ax,[bp-6]
push ax
push 6
push cs
call CityCurseTarget
add sp,8
or ax,ax
jnz validtarget3
mov word ptr [0D39Eh],0 ;Do not use if no valid target!
validtarget3:

; Pestilence check for valid target
push si
mov ax,0C4h
push ax
lea ax,[bp-6]
push ax
push 6
push cs
call CityCurseTarget
add sp,8
or ax,ax
jnz validtarget4
mov word ptr [0D3AAh],0 ;Do not use if no valid target!
validtarget4:

; Rift check for valid target
push si
mov ax,06Eh
push ax
lea ax,[bp-6]
push ax
push 6
push cs
call CityCurseTarget
add sp,8
or ax,ax
jnz validtarget5
mov word ptr [0D39Ah],0 ;Do not use if no valid target!
validtarget5:

mov dx,si
call GlobalEnchantmentEffects

; Out : CL = number of meteor storms in effect
;       CH = Suppress Magics
;       DL = Fairy Rings
;       DH = Chaos Surges

cmp ch,0
jle nomoresuppress4

mov word ptr [0D388h],0 ; Blizzard
mov word ptr [0D38Ch],0 ; Spell Blast
mov word ptr [0D38Eh],0 ; Stasis
mov word ptr [0D392h],0 ; Corruption
mov word ptr [0D396h],0 ; Raise Volcano
mov ax,100
mov bx,0D39Ch ; Call the void +100
call addto
;mov word ptr [0D3A2h],0 ; Black Wind
mov word ptr [0D3A4h],0 ; Drain Power

nomoresuppress4:

cmp dl,0
jle nowrath4

sar word ptr [0D39Ch],1 ; Call the Void

nowrath4:

Call SelectASpell

cmp ax,0
jl TryAgain

mov bx,ax
sal bx,1

mov al,cs:[bx+Cursetable]
xor ah,ah
mov di,ax
cmp di,0
jg ssdone
jmp TryAgain



ski7:

;-----------------------------
; 7 - Intercontinental access
;-----------------------------

cmp cx,7
jnz ski8

mov di,03Fh ; Wind Walking
mov ax,3Fh
call isknown
or ax,ax
jnz ssdone

mov di,02Bh ; Floating Island
mov ax,2Bh
call isknown
or ax,ax
jnz ssdone

mov di,0A8h ; Wraith Form
mov ax,0A8h
call isknown
or ax,ax
jnz ssdone

mov di,08h ; Water Walking
mov ax,08h
call isknown
or ax,ax
jnz ssdone

mov di,38h
jmp ssdone
ski8:

;-----------------------------
; 8 - HeroSummoning
;-----------------------------

cmp cx,8
jnz ski9

mov ax,8Eh
call isknown
or ax,ax
jz notinc
;Incarnation known, is it already in play?

xor di,di
nextunit7:

mov ax,di
mov cl,5
shl ax,cl
les bx,[9EC2h]
add bx,ax

mov al,es:[bx+3]
cbw



The only mana related thing there is :
" Mana crystals/5+Mana income<Spell cost/10 then do not cast!"
meaning if the AI picked a spell, and it's too expensive to finish in a reasonable time, the AI won't cast that turn. But for something like a Naga (70) to trigger this, the AI would need less than 35 mana crystals with a zero income, or a negative income. It's mostly meant to prevent the AI from casting expensive spells like global enchantments when they still can't afford the cost but found it in treasure.

I see another check in the global enchantment procedure with a comment concerning mana, but I don't see it used to decide how much power to allocate to mana or skill. Is that fixed? Does it not consider the treasury for allocating to skill? That's limited. Yes I see the issue... Basically, the amount of resources or the net income is not considered, it just stops casting when out of skill or out of mana.

However, since basically the AI is designed to work like this I see it as not an issue, I'd say that limiting the resources is actually the natural way to do this since the game already has a table that limits resources for lower income levels. I'd at least test this if we can achieve dynamic cheating affordably in terms of your work. It'd seem at first glance that the best way to address this would be to make the limitation relatively equal between skill and power/gold, because the relation might be by design, but if skill is more difficult then let's try power/gold first, and see what happens.
Reply

Quote:we have to make the AIs more risk averse - maybe getting them to defend more?


With 5.01 the AI already has the best possible garrison forces - stacking 9 summoned creatures in every city of course is better but it's unrealistic. 1-3 of them is probably the best the AI can actually achieve before hitting the next tier of summons. Also, defenses aren't very effective against human players who know what the strength and weaknesses of units are - they can prepare a stack that counters the defenders unless the AI has several tiers of advantage in unit quality.

If you specifically mean turn 40 and before, there is only one problem with that. If the AI does not have free (intercontinental) stacks roaming around in a quantity that is a threat, the human player is free to conquer any of the AI's cities, and believe me they WILL find some. It doesn't take a genius to follow the AI settlers and steal the city once it's a hamlet, and the only thing that prevents the player from doing that to get 8-10 free cities is the retaliation from the AI after it. New hamlets are unlikely to have a relevant number of summons defending them - that requires the AI to research summoning circle, hit that city with the spell and then summon something before moving the circle. That gives a head start to the player (2-3 times as many cities) and a major slowdown to the AI (half their cities gone). We have been there and it was ugly.
Also, the majority of summons will hit the capital or the "frontier city", only 1 out of 3 goes somewhere else. So increasing garrisons requirements won't do much, the capital already needs the maximal 9 units and the frontier city needing 1 extra makes no real difference. Other cities won't reach the required 2 in the 40 turns anyway (except maybe on Lunatic)

Quote:I see another check in the global enchantment procedure with a comment concerning mana,

Nice catch, this made me realize the priority of 0 if low mana should come after the check for early turn enchantment, not after.

Quote:how much power to allocate to mana or skill.

That's a different procedure, here :
Code:
; 955 bytes of space!
jmp start
RNG:
push ax
db 9Ah,0D8h,00,0B0h,00
pop cx
retn

getRPincome:
; How much RP we can make if we push research up to 80%?
call getwiz
mov byte ptr [bx-610Ch], 80 ; Research
mov byte ptr [bx-610Ah], 0 ; Skill
mov byte ptr [bx-610Bh], 20 ; Mana

push si

lea ax,[bp-0Eh]
push ax

lea ax,[bp-6]
push ax

lea ax,[bp-8]
push ax

;call getincome
db 09Ah, 75h, 00, 0C0h,03
add sp,8

mov ax,[bp-6]
or ax,ax
jnz safenonzero
inc ax
safenonzero:
; Return in AX
retn

getwiz:
mov ax,4C8h
imul si
mov bx,ax
retn

getrequiredmanalevel:
mov dx,4000
mov ax,[bp-0Ah]
cmp word ptr [0BD90h],50
jle early1
inc cl
early1:
cmp word ptr [0BD90h],100
jle early2
inc cl
early2:

sal dx,cl ; mana level 3 = usual,
sal ax,cl

cmp ax,dx
jbe skip11
mov ax,dx
skip11:
retn

gethistorian: ; in AX = wizard
push cx
push dx
mov cx,4C8h
imul cx
mov bx,8Fh
cmp word ptr [0BD90h],8Fh
jge skip111
mov bx,word ptr [0BD90h]
skip111:
dec bx
sal bx,1
add bx,ax
mov ax,[bx-5DD4h]
pop dx
pop cx
retn

gethistorianratio:
push cx
push ax
xor cx,cx
xor dx,dx
nextwizzz:
mov ax,cx
call gethistorian
cmp ax,dx
jl nothigher
mov dx,ax
nothigher:
inc cx
cmp cx,[0BD9Ch] ; max wizards
jl nextwizzz
pop ax
call gethistorian
or dx,dx
jz allzero
mov bx,dx
mov cx,200
imul cx
idiv bx
allzero:
pop cx
retn ; Return 200 for strongest wizard, proportionally for less

; SI : wizard ID
; bp-2 Research priority
; bp-3 Mana priority
; bp-4 Skill priority
; bp-A Casting Skill
; bp-C : mana crystals

raisepeace:
xor di,di
nextwiz2:
call getwiz
add bx,di
add bx,di
mov ax,[bx-5FFCh] ; +20 peace interest. The war is expensive and we want to stop it!
add ax,20
cmp ax,200
jl ok77
mov ax,200
ok77:
mov [bx-5FFCh],ax
sub bx,di
add byte ptr [bx-5FE4h],3 ; Improve relations by 3 per turn : we are researching SoM and it cannot be blasted
                          ; so other players are not a threat, no need to be aggressive at all    
                          ; in fact getting allies helps winning!
cmp byte ptr [bx-5FE4h],100
jle ok88
mov byte ptr [bx-5FE4h],100
ok88:
inc di
cmp di,[0BD9Ch] ; max wizards
jl nextwiz2
retn

start:
call getwiz
mov ax,[bx-5EDAh]
mov [bp-0Ch],ax

;==============================================================
; Defaults - even distribution
;==============================================================

mov byte ptr [bp-2],4
mov byte ptr [bp-3],2 ; Less mana preferece, as it defaults to minimal 20%
mov byte ptr [bp-4],4

;=====================================================
; Objective, Personality
;=====================================================

cmp [bx-611Ch],2
jnz nottheurgist
add byte ptr [bp-2],3 ; Theurgist +3 Research!
nottheurgist:

cmp [bx-611Ch],3
jnz notperfect
add byte ptr [bp-4],3 ; Perfectionist +3 Skill!
notperfect:

cmp [bx-611Ch],1
jnz notmili
add byte ptr [bp-3],2 ; Militarist +2 Mana!
notmili:

cmp [bx-611Ch],5
jnz notpeace
add byte ptr [bp-2],3 ; Peaceful +3 Research
notpeace:

;=====================================================
; Time Stop
;=====================================================

cmp     word ptr [bx-60E4h], 50h
jnz nottimestop1
; Time Stop is being cast, dump everything into MANA! More mana means more time to cast = better use than raising skill!
mov byte ptr [bx-610Ch], 0 ; Research
mov byte ptr [bx-610Ah], 0 ; Skill
mov byte ptr [bx-610Bh], 100 ; Mana
jmp exit
nottimestop1:
; Time Stop is known, but not currently being cast
cmp     byte ptr [bx-5E83h], 2
jnz nottimestop2
add byte ptr [bp-3],10 ; +10 to Mana, need a lot for this spell
nottimestop2:

;=====================================================
; Distribution Strategy
;=====================================================

; Gold reserves lower than 2x gold upkeep cost, make more mana?
; Does not consider AI discount, should be ignored!
; Alchemy automatically makes gold from mana if needed, then low mana would force mana production up anyway!

;cmp word ptr [bx-5C9Ch], 6
;jnz ns1
;add byte ptr [bp-3],0  
;ns1:

cmp word ptr [bx-5C9Ch], 1 ; Research behind human player by at least 25%, or not having the first 15 spells done!
jnz ns2
add byte ptr [bp-2],3
ns2:

cmp word ptr [bx-5C9Ch], 2 ; Cast skill below 80 or not at least 50% more than human player!
jnz ns3
add byte ptr [bp-4],2
ns3:

;=====================================================
; Retorts
;=====================================================

cmp byte ptr [bx-60CBh], 1 ; Sage Master
jnz notsage
add byte ptr [bp-2],3 ; Sage Master prefer research
notsage:

cmp byte ptr [bx-60C8h], 1 ; Archmage
jnz notarch
add byte ptr [bp-4],3 ; Archmage prefer skill
notarch:

;cmp byte ptr [bx-60C7h], 1 ; Mana Focusing
;jnz notmf
;add byte ptr [bp-3],2 ; Mana Focusing prefer mana
;notmf:

cmp byte ptr [bx-60CAh], 1 ; Chaneller
jnz notchan
sub byte ptr [bp-3],1 ; Chanellers need less mana
notchan:

cmp byte ptr [bx-60D2h], 1 ; Alchemy
jnz notalch
sub byte ptr [bp-3],2 ; Alchemy needs much less mana, gets made from gold!
notalch:

cmp byte ptr [bp-3],0 ; Don't drop below zero!
jge ok43
mov byte ptr [bp-3],0
ok43:

;=====================================================
; Special conditions (spells, events)
;=====================================================

cmp byte ptr [bx-5CA5h],0
jz noenlightenment
sar byte ptr [bp-2],1 ; Halve priority of producing research if Enlightenment in effect
noenlightenment:

les     bx, [9998h]
cmp     word ptr es:[bx+5Ch], 2
jnz     notsorc

; Sorcery conjunction
call getwiz
mov byte ptr [bx-610Ch], 0 ; Research

mov cl,2
call getrequiredmanalevel
cmp ax,[bp-0Ch]
jg needmana1
mov byte ptr [bx-610Ah], 90 ; Skill
mov byte ptr [bx-610Bh], 10 ; Mana
jmp exit
needmana1: ; Critically low on mana, only do 25% skill and hope 75% mana is enough
mov byte ptr [bx-610Ah], 25 ; Skill
mov byte ptr [bx-610Bh], 75 ; Mana
jmp exit
notsorc:

;=====================================================
; Researching Spell of Mastery strategy!
;=====================================================

call getwiz
cmp     byte ptr [bx-5ED4h], 0D5h ; SoM being researched
jnz notSomRes

; avoid research if spell blast known by anyone
xor di,di
lph1:
cmp si,di
jz skipself

mov     ax, di
mov     cl, 2
shl     ax, cl
les     bx, [9CC8h]
add     bx, ax
cmp     byte ptr es:[bx+3], 0
jz skipself ; Also skip if banished or eliminated wizard. Eliminated cannot blast, banished is likely to get eliminated by the time SoM research is done, especially if they don't return meanwhile (which would stop this strategy)

mov ax,4C8h
imul di
mov bx,ax
cmp byte ptr [bx-5E99h],0
jnz blast
skipself:
inc di
cmp di,[0BD9Ch] ; max wizards
jl lph1
jmp Somres1
blast:
stopres1:
mov byte prt [bp-2],0 ; No research on SoM if any other player has Spell Blast!
jmp notSoMRes

; If strongest AI and human far behind, push research some
somres1:
mov ax,si
call gethistorianratio
cmp ax,150  ; We aren't near the top
jb notthis
mov ax,0
call gethistorianratio
cmp ax,100
ja notthis ; Human player close in power, now is the time to act not research!
add byte ptr [bp-2],5 ; We are near the top of the chart, push research quite a lot but not all the way
notthis:

; If not strongest AI and at war with human, put research to zero
mov ax,si
call gethistorianratio
cmp ax,120  ; We aren't near the top
jg webig
call getwiz
cmp word ptr [bx-5C98h],2
jg blast ; Do not research if we are not very strong and we are at war with human
webig:

; if total RP income can finish research in 50 turns, push research to max, skill to zero, mana to minimal
; During this period, raise peace willingness to everyone
call getwiz
mov di,word ptr [bx-5EDCh] ; Research cost remaining!

call getRPincome
xchg ax,di
xor dx,dx ; Divide cost with RP/turn
div di
cmp ax,50
jge notquick ; Can finish it in less than 50 turns : go for it!

mov cl,2
call getrequiredmanalevel
cmp ax,[bp-0Ch]
jle exit ; We have enough mana left, keep going with 80% research, 20% mana!
;Do not have 16*skill in mana, or 8000 whichever is lower
call getwiz
mov byte ptr [bx-610Ch], 40 ; Research
mov byte ptr [bx-610Ah], 0 ; Skill
mov byte ptr [bx-610Bh], 60 ; Mana
call raisepeace ; low on mana, speading too much in combat! Should stop wars!
jmp exit

notquick:
NotSomRes:

;=====================================================
; Mana / Skill ratio problems
;=====================================================

cmp word ptr [bp-0Ah],500 ; Skill>=500
jle nottoohighskill
sar byte ptr [bp-4],1 ; Halve priority of skill
nottoohighskill:

mov cl,3
call getrequiredmanalevel

cmp ax,[bp-0Ch]
jle enoughmana ; Do not have 32*skill in mana, or 16000 whichever is lower
call getwiz
mov byte ptr [bx-610Ch], 0 ; Research
mov byte ptr [bx-610Ah], 0 ; Skill
mov byte ptr [bx-610Bh], 100 ; Mana
jmp exit
enoughmana:

cmp word ptr [bp-0Ch], 20000
jle notmanaoverflow
mov byte ptr [bp-3],0 ; Do not produce mana at all except the required 20%
notmanaoverflow:

;=====================================================
; Casting SOM
;=====================================================

call getwiz
cmp word ptr [bx-60E4h], 0D5h
jnz notSoMCast
mov byte ptr [bx-610Ch], 0 ; Research
mov byte ptr [bx-610Ah], 10 ; Skill
mov byte ptr [bx-610Bh], 90 ; Mana - must have as much resources as we can for the final war!
jmp exit
notSoMCast:

;=====================================================
; EARLY GAME
;=====================================================
call getwiz

cmp word ptr [0BD90h],60 ; TURN
jg lateforrush

cmp byte ptr [bx-5ED4h], 0Eh ; Giant Spiders
jz pushresearch
cmp byte ptr [bx-5ED4h], 5Fh ; Gargoyles
jz pushresearch
cmp byte ptr [bx-5ED4h], 0ADh ; Lycantropy
jnz lateforrush
pushresearch:
mov byte ptr [bx-610Ch], 80 ; Research
mov byte ptr [bx-610Ah], 0 ; Skill
mov byte ptr [bx-610Bh], 20 ; Mana
jmp exit
lateforrush:

cmp word ptr [0BD90h],30 ; TURN
jg notearlygame

cmp word ptr [bp-0Ch],250 ; We have enough mana, can do anything
jge notearlygame

mov byte ptr [bx-610Ch], 0 ; Research
mov byte ptr [bx-610Ah], 0 ; Skill
mov byte ptr [bx-610Bh], 100 ; Mana

cmp word ptr [bx-60D4h],2
jge nonlife
cmp word ptr [bx-60DCh],2
jge nonlife
cmp word ptr [bx-60D8h],4
jge nonlife
cmp word ptr [bx-60DAh],4
jge nonlife
cmp word ptr [0BD90h],10 ; TURN
jl nonlife

; Monolife wizard with no early summon - push research to get the important missing early commons
mov byte ptr [bx-610Ch], 50 ; Research
mov byte ptr [bx-610Ah], 0 ; Skill
mov byte ptr [bx-610Bh], 50 ; Mana
jmp exit

nonlife:
cmp word ptr [bp-0Ah],26 ; Casting skill
jge exit
cmp word ptr [bp-0Ch],100
jle exit ; Must have 100+ mana crystals
mov byte ptr [bx-610Ah], 25 ; Skill
mov byte ptr [bx-610Bh], 75 ; Mana
jmp exit

notearlygame:
;=====================================================
; Any researchable spell left?
;=====================================================
call getwiz
cmp     word ptr [bx-5ED4h],0
jnz stillresearching
mov byte ptr [bp-2],0 ; No spell currently researched : RES PRIO=0!
stillresearching:
;=====================================================
; Distribute power based on weights randomly
;=====================================================

mov byte ptr [bx-610Ch], 0 ; Research
mov byte ptr [bx-610Ah], 0 ; Skill
mov byte ptr [bx-610Bh], 20 ; Mana

xor di,di
nextroll:
mov al,[bp-2]
add al,[bp-3]
add al,[bp-4]
xor ah,ah
call RNG
push ax
call getwiz
pop ax
cmp al,[bp-2]
jg notres
inc byte ptr [bx-610Ch]
jmp done
notres:
mov cl,[bp-2]
add cl,[bp-3]
cmp al,cl
jg notmana
inc byte ptr [bx-610Bh]
jmp done
notmana:
inc byte ptr [bx-610Ah]
done:
inc di
cmp di,80
jl nextroll
exit:
pop     di
pop     si
mov     sp, bp
pop     bp
retf

If the AI has that low mana to trigger that condition on global enchantments, it means it's already spending 100% on producing mana and it's still not enough.

Quote: skill is more difficult
No, it's outright impossible.
Reply

(October 24th, 2017, 09:40)Seravy Wrote:
Quote:we have to make the AIs more risk averse - maybe getting them to defend more?

With 5.01 the AI already has the best possible garrison forces - stacking 9 summoned creatures in every city of course is better but it's unrealistic. 1-3 of them is probably the best the AI can actually achieve before hitting the next tier of summons. Also, defenses aren't very effective against human players who know what the strength and weaknesses of units are - they can prepare a stack that counters the defenders unless the AI has several tiers of advantage in unit quality.

If you specifically mean turn 40 and before, there is only one problem with that. If the AI does not have free (intercontinental) stacks roaming around in a quantity that is a threat, the human player is free to conquer any of the AI's cities, and believe me they WILL find some. It doesn't take a genius to follow the AI settlers and steal the city once it's a hamlet, and the only thing that prevents the player from doing that to get 8-10 free cities is the retaliation from the AI after it. New hamlets are unlikely to have a relevant number of summons defending them - that requires the AI to research summoning circle, hit that city with the spell and then summon something before moving the circle. That gives a head start to the player (2-3 times as many cities) and a major slowdown to the AI (half their cities gone). We have been there and it was ugly.
Also, the majority of summons will hit the capital or the "frontier city", only 1 out of 3 goes somewhere else. So increasing garrisons requirements won't do much, the capital already needs the maximal 9 units and the frontier city needing 1 extra makes no real difference. Other cities won't reach the required 2 in the 40 turns anyway (except maybe on Lunatic)

Yes, I specifically mean t40. Afterwards you can increase the cheating for me, but Nelphine disagrees on this.

Make summoning circle known from the beginning to everybody, the AIs benefit more from it and they can defend their huge number of hamlets. I'd content that perhaps they shouldn't expand so much but maybe that's for another discussion. If the player still manages to capture those cities - which now are frankly pretty useless for quite a long time - then the player is using an aggressive strategy and shouldn't really be penalized for that. The player doesn't have any cheating bonus and can't properly garrison the cities, meaning that as soon as the AI starts pumping out cheat stuff - and it's easier with less cities to garrison - the war consequences will be felt!


(October 24th, 2017, 09:40)Seravy Wrote:
Quote:how much power to allocate to mana or skill.

That's a different procedure, here :
Code:
; 955 bytes of space!
jmp start
RNG:
push ax
db 9Ah,0D8h,00,0B0h,00
pop cx
retn

getRPincome:
; How much RP we can make if we push research up to 80%?
call getwiz
mov byte ptr [bx-610Ch], 80 ; Research
mov byte ptr [bx-610Ah], 0 ; Skill
mov byte ptr [bx-610Bh], 20 ; Mana

push si

lea ax,[bp-0Eh]
push ax

lea ax,[bp-6]
push ax

lea ax,[bp-8]
push ax

;call getincome
db 09Ah, 75h, 00, 0C0h,03
add sp,8

mov ax,[bp-6]
or ax,ax
jnz safenonzero
inc ax
safenonzero:
; Return in AX
retn

getwiz:
mov ax,4C8h
imul si
mov bx,ax
retn

getrequiredmanalevel:
mov dx,4000
mov ax,[bp-0Ah]
cmp word ptr [0BD90h],50
jle early1
inc cl
early1:
cmp word ptr [0BD90h],100
jle early2
inc cl
early2:

sal dx,cl ; mana level 3 = usual,
sal ax,cl

cmp ax,dx
jbe skip11
mov ax,dx
skip11:
retn

gethistorian: ; in AX = wizard
push cx
push dx
mov cx,4C8h
imul cx
mov bx,8Fh
cmp word ptr [0BD90h],8Fh
jge skip111
mov bx,word ptr [0BD90h]
skip111:
dec bx
sal bx,1
add bx,ax
mov ax,[bx-5DD4h]
pop dx
pop cx
retn

gethistorianratio:
push cx
push ax
xor cx,cx
xor dx,dx
nextwizzz:
mov ax,cx
call gethistorian
cmp ax,dx
jl nothigher
mov dx,ax
nothigher:
inc cx
cmp cx,[0BD9Ch] ; max wizards
jl nextwizzz
pop ax
call gethistorian
or dx,dx
jz allzero
mov bx,dx
mov cx,200
imul cx
idiv bx
allzero:
pop cx
retn ; Return 200 for strongest wizard, proportionally for less

; SI : wizard ID
; bp-2 Research priority
; bp-3 Mana priority
; bp-4 Skill priority
; bp-A Casting Skill
; bp-C : mana crystals

raisepeace:
xor di,di
nextwiz2:
call getwiz
add bx,di
add bx,di
mov ax,[bx-5FFCh] ; +20 peace interest. The war is expensive and we want to stop it!
add ax,20
cmp ax,200
jl ok77
mov ax,200
ok77:
mov [bx-5FFCh],ax
sub bx,di
add byte ptr [bx-5FE4h],3 ; Improve relations by 3 per turn : we are researching SoM and it cannot be blasted
                         ; so other players are not a threat, no need to be aggressive at all    
                         ; in fact getting allies helps winning!
cmp byte ptr [bx-5FE4h],100
jle ok88
mov byte ptr [bx-5FE4h],100
ok88:
inc di
cmp di,[0BD9Ch] ; max wizards
jl nextwiz2
retn

start:
call getwiz
mov ax,[bx-5EDAh]
mov [bp-0Ch],ax

;==============================================================
; Defaults - even distribution
;==============================================================

mov byte ptr [bp-2],4
mov byte ptr [bp-3],2 ; Less mana preferece, as it defaults to minimal 20%
mov byte ptr [bp-4],4

;=====================================================
; Objective, Personality
;=====================================================

cmp [bx-611Ch],2
jnz nottheurgist
add byte ptr [bp-2],3 ; Theurgist +3 Research!
nottheurgist:

cmp [bx-611Ch],3
jnz notperfect
add byte ptr [bp-4],3 ; Perfectionist +3 Skill!
notperfect:

cmp [bx-611Ch],1
jnz notmili
add byte ptr [bp-3],2 ; Militarist +2 Mana!
notmili:

cmp [bx-611Ch],5
jnz notpeace
add byte ptr [bp-2],3 ; Peaceful +3 Research
notpeace:

;=====================================================
; Time Stop
;=====================================================

cmp     word ptr [bx-60E4h], 50h
jnz nottimestop1
; Time Stop is being cast, dump everything into MANA! More mana means more time to cast = better use than raising skill!
mov byte ptr [bx-610Ch], 0 ; Research
mov byte ptr [bx-610Ah], 0 ; Skill
mov byte ptr [bx-610Bh], 100 ; Mana
jmp exit
nottimestop1:
; Time Stop is known, but not currently being cast
cmp     byte ptr [bx-5E83h], 2
jnz nottimestop2
add byte ptr [bp-3],10 ; +10 to Mana, need a lot for this spell
nottimestop2:

;=====================================================
; Distribution Strategy
;=====================================================

; Gold reserves lower than 2x gold upkeep cost, make more mana?
; Does not consider AI discount, should be ignored!
; Alchemy automatically makes gold from mana if needed, then low mana would force mana production up anyway!

;cmp word ptr [bx-5C9Ch], 6
;jnz ns1
;add byte ptr [bp-3],0  
;ns1:

cmp word ptr [bx-5C9Ch], 1 ; Research behind human player by at least 25%, or not having the first 15 spells done!
jnz ns2
add byte ptr [bp-2],3
ns2:

cmp word ptr [bx-5C9Ch], 2 ; Cast skill below 80 or not at least 50% more than human player!
jnz ns3
add byte ptr [bp-4],2
ns3:

;=====================================================
; Retorts
;=====================================================

cmp byte ptr [bx-60CBh], 1 ; Sage Master
jnz notsage
add byte ptr [bp-2],3 ; Sage Master prefer research
notsage:

cmp byte ptr [bx-60C8h], 1 ; Archmage
jnz notarch
add byte ptr [bp-4],3 ; Archmage prefer skill
notarch:

;cmp byte ptr [bx-60C7h], 1 ; Mana Focusing
;jnz notmf
;add byte ptr [bp-3],2 ; Mana Focusing prefer mana
;notmf:

cmp byte ptr [bx-60CAh], 1 ; Chaneller
jnz notchan
sub byte ptr [bp-3],1 ; Chanellers need less mana
notchan:

cmp byte ptr [bx-60D2h], 1 ; Alchemy
jnz notalch
sub byte ptr [bp-3],2 ; Alchemy needs much less mana, gets made from gold!
notalch:

cmp byte ptr [bp-3],0 ; Don't drop below zero!
jge ok43
mov byte ptr [bp-3],0
ok43:

;=====================================================
; Special conditions (spells, events)
;=====================================================

cmp byte ptr [bx-5CA5h],0
jz noenlightenment
sar byte ptr [bp-2],1 ; Halve priority of producing research if Enlightenment in effect
noenlightenment:

les     bx, [9998h]
cmp     word ptr es:[bx+5Ch], 2
jnz     notsorc

; Sorcery conjunction
call getwiz
mov byte ptr [bx-610Ch], 0 ; Research

mov cl,2
call getrequiredmanalevel
cmp ax,[bp-0Ch]
jg needmana1
mov byte ptr [bx-610Ah], 90 ; Skill
mov byte ptr [bx-610Bh], 10 ; Mana
jmp exit
needmana1: ; Critically low on mana, only do 25% skill and hope 75% mana is enough
mov byte ptr [bx-610Ah], 25 ; Skill
mov byte ptr [bx-610Bh], 75 ; Mana
jmp exit
notsorc:

;=====================================================
; Researching Spell of Mastery strategy!
;=====================================================

call getwiz
cmp     byte ptr [bx-5ED4h], 0D5h ; SoM being researched
jnz notSomRes

; avoid research if spell blast known by anyone
xor di,di
lph1:
cmp si,di
jz skipself

mov     ax, di
mov     cl, 2
shl     ax, cl
les     bx, [9CC8h]
add     bx, ax
cmp     byte ptr es:[bx+3], 0
jz skipself ; Also skip if banished or eliminated wizard. Eliminated cannot blast, banished is likely to get eliminated by the time SoM research is done, especially if they don't return meanwhile (which would stop this strategy)

mov ax,4C8h
imul di
mov bx,ax
cmp byte ptr [bx-5E99h],0
jnz blast
skipself:
inc di
cmp di,[0BD9Ch] ; max wizards
jl lph1
jmp Somres1
blast:
stopres1:
mov byte prt [bp-2],0 ; No research on SoM if any other player has Spell Blast!
jmp notSoMRes

; If strongest AI and human far behind, push research some
somres1:
mov ax,si
call gethistorianratio
cmp ax,150  ; We aren't near the top
jb notthis
mov ax,0
call gethistorianratio
cmp ax,100
ja notthis ; Human player close in power, now is the time to act not research!
add byte ptr [bp-2],5 ; We are near the top of the chart, push research quite a lot but not all the way
notthis:

; If not strongest AI and at war with human, put research to zero
mov ax,si
call gethistorianratio
cmp ax,120  ; We aren't near the top
jg webig
call getwiz
cmp word ptr [bx-5C98h],2
jg blast ; Do not research if we are not very strong and we are at war with human
webig:

; if total RP income can finish research in 50 turns, push research to max, skill to zero, mana to minimal
; During this period, raise peace willingness to everyone
call getwiz
mov di,word ptr [bx-5EDCh] ; Research cost remaining!

call getRPincome
xchg ax,di
xor dx,dx ; Divide cost with RP/turn
div di
cmp ax,50
jge notquick ; Can finish it in less than 50 turns : go for it!

mov cl,2
call getrequiredmanalevel
cmp ax,[bp-0Ch]
jle exit ; We have enough mana left, keep going with 80% research, 20% mana!
;Do not have 16*skill in mana, or 8000 whichever is lower
call getwiz
mov byte ptr [bx-610Ch], 40 ; Research
mov byte ptr [bx-610Ah], 0 ; Skill
mov byte ptr [bx-610Bh], 60 ; Mana
call raisepeace ; low on mana, speading too much in combat! Should stop wars!
jmp exit

notquick:
NotSomRes:

;=====================================================
; Mana / Skill ratio problems
;=====================================================

cmp word ptr [bp-0Ah],500 ; Skill>=500
jle nottoohighskill
sar byte ptr [bp-4],1 ; Halve priority of skill
nottoohighskill:

mov cl,3
call getrequiredmanalevel

cmp ax,[bp-0Ch]
jle enoughmana ; Do not have 32*skill in mana, or 16000 whichever is lower
call getwiz
mov byte ptr [bx-610Ch], 0 ; Research
mov byte ptr [bx-610Ah], 0 ; Skill
mov byte ptr [bx-610Bh], 100 ; Mana
jmp exit
enoughmana:

cmp word ptr [bp-0Ch], 20000
jle notmanaoverflow
mov byte ptr [bp-3],0 ; Do not produce mana at all except the required 20%
notmanaoverflow:

;=====================================================
; Casting SOM
;=====================================================

call getwiz
cmp word ptr [bx-60E4h], 0D5h
jnz notSoMCast
mov byte ptr [bx-610Ch], 0 ; Research
mov byte ptr [bx-610Ah], 10 ; Skill
mov byte ptr [bx-610Bh], 90 ; Mana - must have as much resources as we can for the final war!
jmp exit
notSoMCast:

;=====================================================
; EARLY GAME
;=====================================================
call getwiz

cmp word ptr [0BD90h],60 ; TURN
jg lateforrush

cmp byte ptr [bx-5ED4h], 0Eh ; Giant Spiders
jz pushresearch
cmp byte ptr [bx-5ED4h], 5Fh ; Gargoyles
jz pushresearch
cmp byte ptr [bx-5ED4h], 0ADh ; Lycantropy
jnz lateforrush
pushresearch:
mov byte ptr [bx-610Ch], 80 ; Research
mov byte ptr [bx-610Ah], 0 ; Skill
mov byte ptr [bx-610Bh], 20 ; Mana
jmp exit
lateforrush:

cmp word ptr [0BD90h],30 ; TURN
jg notearlygame

cmp word ptr [bp-0Ch],250 ; We have enough mana, can do anything
jge notearlygame

mov byte ptr [bx-610Ch], 0 ; Research
mov byte ptr [bx-610Ah], 0 ; Skill
mov byte ptr [bx-610Bh], 100 ; Mana

cmp word ptr [bx-60D4h],2
jge nonlife
cmp word ptr [bx-60DCh],2
jge nonlife
cmp word ptr [bx-60D8h],4
jge nonlife
cmp word ptr [bx-60DAh],4
jge nonlife
cmp word ptr [0BD90h],10 ; TURN
jl nonlife

; Monolife wizard with no early summon - push research to get the important missing early commons
mov byte ptr [bx-610Ch], 50 ; Research
mov byte ptr [bx-610Ah], 0 ; Skill
mov byte ptr [bx-610Bh], 50 ; Mana
jmp exit

nonlife:
cmp word ptr [bp-0Ah],26 ; Casting skill
jge exit
cmp word ptr [bp-0Ch],100
jle exit ; Must have 100+ mana crystals
mov byte ptr [bx-610Ah], 25 ; Skill
mov byte ptr [bx-610Bh], 75 ; Mana
jmp exit

notearlygame:
;=====================================================
; Any researchable spell left?
;=====================================================
call getwiz
cmp     word ptr [bx-5ED4h],0
jnz stillresearching
mov byte ptr [bp-2],0 ; No spell currently researched : RES PRIO=0!
stillresearching:
;=====================================================
; Distribute power based on weights randomly
;=====================================================

mov byte ptr [bx-610Ch], 0 ; Research
mov byte ptr [bx-610Ah], 0 ; Skill
mov byte ptr [bx-610Bh], 20 ; Mana

xor di,di
nextroll:
mov al,[bp-2]
add al,[bp-3]
add al,[bp-4]
xor ah,ah
call RNG
push ax
call getwiz
pop ax
cmp al,[bp-2]
jg notres
inc byte ptr [bx-610Ch]
jmp done
notres:
mov cl,[bp-2]
add cl,[bp-3]
cmp al,cl
jg notmana
inc byte ptr [bx-610Bh]
jmp done
notmana:
inc byte ptr [bx-610Ah]
done:
inc di
cmp di,80
jl nextroll
exit:
pop     di
pop     si
mov     sp, bp
pop     bp
retf

If the AI has that low mana to trigger that condition on global enchantments, it means it's already spending 100% on producing mana and it's still not enough.

This is great. If my parsing of the code is correct: mana and gold are meant to be the limiters by design. The fact that AIs may end up starved is by design. After all, the player can end up starved as well. The AIs end up starved more easily the easier the difficulty level, or the lower the power production to nodes/retorts/etc. So, reducing or increasing them seems to be the good way to balance

(October 24th, 2017, 09:40)Seravy Wrote:
Quote: skill is more difficult
No, it's outright impossible.

OK! See above.
Reply

Quote:and they can defend their huge number of hamlets.

Nope, the AI doesn't do "on demand" summoning. There is no connection between casting a summoning spell and the position of the circle. And I don't want to implement it because it can be abused.
Reply

No need for on demand. What I mean is, it comes automatically thanks to the higher ratio of defending units, despite a reduction in overall number of summons at t40:

"Also, the majority of summons will hit the capital or the "frontier city", only 1 out of 3 goes somewhere else. So increasing garrisons requirements won't do much, the capital already needs the maximal 9 units and the frontier city needing 1 extra makes no real difference. Other cities won't reach the required 2 in the 40 turns anyway (except maybe on Lunatic)"

We've seen the reports of 5 stacks of summons at t40. You mention 1/3, if that third were in hamlets instead than roaming, thanks to summoning circle known from the beginning, then that'd be 3 - 4 covered hamlets. That assures the first settler wave, which is more important because those cities are older. At least from a high level it seems to numerically work.
Reply

Quote:No need for on demand. What I mean is, it comes automatically thanks to the higher ratio of defending units, despite a reduction in overall number of summons

More like, it's back to pre-5.0 levels, but yes.

Quote:We've seen the reports of 5 stacks of summons at t40.

That...sounds a lot. Let me calculate.
Assuming 12 books, 24 skill. On Lunatic only, with casting modifier, 60/turn. Nagas cost 70, so 5 stacks cost 9*5*70=3150 total
in 40 turns that requires  78 casting/turn but the AI also spends on other spells so it's more realistic to say they need like double the 60 they actually have. So even on Lunatic that's not normal and means the AI found an early node which it melded and/or found a large cache of mana crystals so it could push skill or had some other early advantage and even then probably also needed Spellweaver for 5 full stacks (our of which one was locked in their capital). On the other hand, if it's Hell Hounds or Skeletons which are cheap, it's perfectly possible to have that many.

Also, note that producing a 10th unit in a city will kick the one out that has the lowers "garrison value" which is an entirely different measurement than the one that holds back the unit. Units that are high value but are poor city defenders might get held back but then kicked out anyway as soon as the city is full. Nagas are very likely to suffer this fate as their garrison rating is a mere 6 - they are an offensive role unit, behind a city wall they are just sitting ducks. On the other hand Ghouls and Sprites are unlikely to get replaced until Magicians because they are good defenders.
Reply



Forum Jump: