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

Create an account  

 
Game mechanics

Right, but I'm operating on the assumption that the game isn't going to be balanced around my bezerker strategy. Which means, other humans in 1410 on lunatic are not going to have 1200+ power production. If we want anything aside from bezerkers/kill-all-the-ai-before-1408 strategies to work, then we have to assume that, for instance, the strongest AI might actually get 2 nodes. And the human won't have 13 nodes, they'll have 6. Which means instead of the AI having 1300 and me having 1200, the AI will have 1500 power production, and the human will have 800.

I don't think the human will ever overcome that kind of power disparity.

And obviously I can fortress strike the AI, but that's again, not due to my power production, that's due to resistance bonus + holy bonus with 6-7 bezerkers, windwalking at speed 5 (or 13 if you want to cheat and use Jaer.) Or 8 bezerkers if the opponent isn't sorcery. Not something I think we're balancing around.

The power production directly leads to number of enemy doomstacks, and the human simply can't keep up with that much power production - the AI in question, with 'only' 1300 power production, and no Aether Binding, had 450 casting skill in early 1410. That means they could summon almost an entire STACK of water elementals every turn. (They won't obviously, but, I have seen AI summon as many as 6 of their top creatures in one turn.)
Reply

On a different note: Sorcery conjunctions seem too strong when it appears in the 'late' game (late in this case being based on the best player power production, not an actual timeline). One conjunction (not sure how long it lasted, definitely less than a year) saw me gain a little over 200 casting skill (and as above, I wasn't in the lead for power production. Obviously I would have gained a little without the conjunction, and I built 2 or 3 amp towers in that time, but at least 75% of that was due to the conjunction; partially because I dropped everything to focus on skill. At the start it was more than 20 casting skill per turn.) Yes everyone gets it, but it means only people within about 20% of the best player power production are going to have a shot just because the lead player is going to skyrocket ahead of everyone else.


Or maybe sorcery conjunctions should make war with the strongest player(s) far more likely, in an effort to force them not to spend power production on skill?
Reply

On a different different note: Arnuz how do you keep them warped??? The last game I tried warp node against the AI, they never lasted more than 2 turns. (And even then, if I only warped one node at a time, it never lasted longer than a single turn, which meant it was more expensive for me to cast, than it was for the enemy to lose the production AND dispel it the next turn. I was a specialist, but they had aether binding, which effectively negate each other.)
Reply

I'm managing... Maybe it's because I've managed to grab more myrran nodes than the AI, with my fast strategy? As a result I'm actually stronger than the AIs in terms of production, after the warping. It'd be different in a few years or if I hadn't gone to grab some of the myrran nodes first.

Here's a save.

(October 23rd, 2017, 06:17)Nelphine Wrote: Right, but I'm operating on the assumption that the game isn't going to be balanced around my bezerker strategy. Which means, other humans in 1410 on lunatic are not going to have 1200+ power production.  If we want anything aside from bezerkers/kill-all-the-ai-before-1408 strategies to work, then we have to assume that, for instance, the strongest AI might actually get 2 nodes. And the human won't have 13 nodes, they'll have 6.  Which means instead of the AI having 1300 and me having 1200, the AI will have 1500 power production, and the human will have 800.  

I don't think the human will ever overcome that kind of power disparity.

And obviously I can fortress strike the AI, but that's again, not due to my power production, that's due to resistance bonus + holy bonus with 6-7 bezerkers, windwalking at speed 5 (or 13 if you want to cheat and use Jaer.) Or 8 bezerkers if the opponent isn't sorcery. Not something I think we're balancing around.

The power production directly leads to number of enemy doomstacks, and the human simply can't keep up with that much power production - the AI in question, with 'only' 1300 power production, and no Aether Binding, had 450 casting skill in early 1410.  That means they could summon almost an entire STACK of water elementals every turn. (They won't obviously, but, I have seen AI summon as many as 6 of their top creatures in one turn.)

You don't really need that much to fortress strike. You can also use 2 to 5 stacks of lower cost (prod+buff) units. The important is to damage units on every wave, something you can work into your tactic. You can also stay allied/pacted until the strike, and time the strike around that. And you can build a diplomacy strategy that complements well with your military strategy. The AIs can't do any of that. Sure there comes a time where the disparity in mana production makes it impossible even to navigate around the stacks, but again, that's the human's responsibility to avoid delaying so much.

We can differ on opinions on how strong the advantage should be. In any case, that's the good part of the game and the challenge there is to make it not too easy. The t40 issue is that there are only common spells available or relevant, and that by then anything that happens is up to luck... The luck of geographical boundaries, the luck of aggressive neighbours, the luck of neighbours with races that build military strength quickly, the luck of accessible nodes and lairs... All of that might well be part of the game, but if we add also the luck of doomstacks popping out from nothing without any possibility to be aware of them, we are way too far into dicerolls realm.

Maybe a totally different approach would be to give to each race a way to maintain situational awareness... What if, say, all cavalry had high scouting bonuses? It was used for that after all.


Attached Files
.gam   SAVE8.GAM (Size: 151.94 KB / Downloads: 0)
Reply

Quote: What if, say, all cavalry had high scouting bonuses? It was used for that after all.

Interesting idea but with doomstacks moving 3 tiles a turn it wouldn't help any. Sure, you get to see the stack a turn earlier which means you can...buy a swordsmen or maybe summon a hell hound to it but the kind of army you need to stop 6+ nagas won't make it there in that one turn 90% of the time.

Early game is certainly too random but not much can be done about that, at least on the terrain part. We've already altered diplomacy to make it much less likely the player finds themselves in a multi-front early war but obviously it's not possible to completely eliminate it. Enemy wizards are random by definition so not much can be done about that either - you either get enemies that your strategy is good against or not.
Reply

Sure, what I don't appreciate is having to need a "trick" - that's not a strategy. For me, draconian archers, my FM ghouls, Nelphine's life berserkers or catwalk's high speed shenanigans are all tricks. At lunatic, there's only tricks right now. Maybe that's intended? OK fair enought - although I'd content that if nothing should win lunatic then nothing shall, not just tricks shall - but at master? It's still mostly tricks as soon as you're not in luck (see the tests where we're forced to revert to tricks). So one way or another the luck can be beaten by tricks, not by strategy, which diminishes the strategy part.

Sorry if I repeat myself, but to leave this impasse the only way I see is:
1- nerf tricks till nothing can win lunatic
2- nerf t40 AI cheating till something can win lunatic again
3- boost longer term cheating to counter point 2
4- see what's going on, repeat if necessary

This needs dynamic cheating, which you've described as "p. hard". You mentioned something about making mana/gold cheating dynamic being not as difficult as skill some time ago... What's happened to that line of thought? I remember that you first mentioned that but then went on to say that the AI needs the mana, but that was before the changes to garrisons. Time to re-evaluate this?
Reply

1. The tricks listed generally are built from elements that are individually fine and cannot be nerfed, or abuse core game mechanics (such as military strength calculations)  which cannot be improved further. Draconian (bowmen or otherwise) might be the exception that might need nerfing. Ghouls idk, I had no luck trying to play those. It's up for later testing, but honestly there is no room for nerfing ghouls either. Any weaker and they are just a bottom tier unplayable unit. They have 3 attack strength limited to 3 shots and poison 1, it doesn't go much lower than that.
2. We can either have AI that doesn't cheat and then fast strategies are the only thing in the game (because they crush the AI before they can defend themselves, why play ANYTHING else?), or we can have them cheat a lot and then fast strategies are the only thing in the game but to a lesser extent - as you currently observe.
The latter is clearly better for three reason :
-If the enemy isn't attacking you, slower strategies are playable
-Even if they do the amount of force needed to defend is not as much as that needed for attacking so it's not forcing the fast strategy as much as the alternative. Defender has an advantage.
-If the AI is the attacker, a lot of their units won't be relevant as they stay home defending cities. So the overall forces the player needs are lower.
3. See 2, if we don't reduce the early bonus there is no need for this.

Mana/gold cheating being dynamic is most likely doable but I haven't yet understood how it can help without putting the game back to that old state of "raze first 3 AI capitals before 1405 because fast races can, and playing anything else is just stupid and pointless."

Seriously, we have "early game tactics too powerful" and "late game tactics too weak" both listed as known problems we can't solve. Your suggestion escalates both of these problems by making early game offense work better and late game offense worse against the AI. So why are you so persistent about it?

Quote: I remember that you first mentioned that but then went on to say that the AI needs the mana, but that was before the changes to garrisons. Time to re-evaluate this?

What the AI does with the units once summoned has no relevance on it being unable to tell if it can afford summoning more or not. Nothing changed there.
Reply

I think for me, we have a list if tricks we can't do anything about. However, one of the BIG things that super heavy cheating is designed to stop is wasting AI mana - and making sure the AI never accidentally gets itself into a state where it can't afford its own troops.

The first, I'd like to consider a trick - if someone honestly wants to build dozens or hundreds of spearmen, no amount if cheating will prevent it, and any other valid strategy such as economic destruction is vastly more difficult to do - to the point that I consider city curses and warp node completely useless. (Even Armageddon + doomsday + meteor storm didn't noticeably hurt the AI except to get rid of piles of troops that I ignore and normally just move around until the site is defeated anyway - in other words it had no affect on gameplay).

The second concern, that the ai doesn't understand maintenance is valid - but I've never seen the AI on advanced or above come remotely close to being worried about resources (even when it buys amplifying towers) until I've fortress strikes them and taken at least 1/4 of their other cities. Only then does the AI begin to need to watch resources (not that it can watch its resources of course). And even then I've taken out so many troops, I don't see the AI disband a single threatening stack until I've taken out 90% of his cities.

To me that means there is leeway. Yes the AI needs cheating. But not to the gargantuan levels it currently has.

And I disagree with arnuz. I don't think the late game AI needs as much cheating any more than the early game. Tricks will beat the ai, even if you gave back 400% cheating bonuses. Not using tricks, the AI simply crushes the human, per my discussion on power production and casting skill.
Reply

Come on, making cheating dynamic doesn't mean zeroing it ("AI that doesn't cheat and then fast strategies are the only thing in the game "); it means reducing it somewhat at t40 but it can mean increasing it afterwards.

> What the AI does with the units once summoned has no relevance on it being unable to tell if it can afford summoning more or not. Nothing changed there.
Of course, but what it does with them has relevance to the number of units running around. If that's more than before - which it is for the case of aggressive, at least - then I see a possible avenue for implementing dynamic cheating.

The tricks: well, fixes have been proposed. I won't repeat them here, my point is to try to prove that however difficult something needs to be done. If I can't manage, well, I tried.

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.

> we have "early game tactics too powerful" and "late game tactics too weak" both listed as known problems we can't solve. Your suggestion escalates both of these problems by making early game offense work better and late game offense worse against the AI. So why are you so persistent about it?
Because then I don't think I've yet managed to communicate clearly what I am trying to do. Reduce early cheating = same garrisons, but less doomstacks, so no, there isn't any additional traction to "raze first 3 AI capitals before 1405 because fast races". Raise later cheating = reinforcing the late AI. So it's quite the contrary of what I've managed to transmit - way to go me, I'm supposed to communicate for a living lol.
Reply

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.

Turn 200, your suggestion.
AI has 10000 military power. (We raised it.)
Human late strategy has 5000, this didn't change. So late strategies are now worse than before - they can't compete at the time they are meant to.
Human early strategy has ~15000 - they conquered the entire plane early so they hold 4 wizards worth of resources out of which a few cities are early races and don't contribute as much as the rest (otherwise it would be 20).
So it clearly makes early strategies win more and late game strategies win less, reducing the diversity of playable strategies and overall hurting the game.


Quote:If that's more than before - which it is for the case of aggressive, at least

Depends on your "before". Compared to 5.0, it's less. 5.0 left no intercontinental units in cities while 5.01 leaves the same amount it would from non-intercontinental. So if you mean this change, the direction is the opposite of what you refer to.
Compared to 4.x, it's about the same - aggressive keeps 1 fewer in cities but peaceful and maniacal keeps 1 more. But 4.x had larger AI bonus so if that's your base version for comparing then the AI bonus reduction has already been done.

Quote: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

cmp ax,si
jnz ququq
cmp byte ptr es:[bx+5], 22h
jnz ququq
jmp notinc
ququq:
inc di
cmp di,[0BD92h]
jl nextunit7
; Incarnation possible
mov di,8Eh
jmp ssdone
notinc:

call NofHeroes

cmp ax,6 ; Already 6 heroes, can't summon one
jge TryAgain

mov cx,ax

mov ax,85h
call isknown
or ax,ax
jz cantres
cmp cx,5
jge cantres ; don't use if only one slot left

; Resurrection
xor di,di
nexthero5:

mov bx,si
shl bx,2
les     bx, [bx-6DCEh]
mov     ax, di
mov     dx, 0Ch
imul    dx
add     bx, ax
cmp     word ptr es:[bx], 0
jge notdead
cmp     word ptr es:[bx], 0FFECh    ; Irrecoverable dead!
jz notdead

cmp word ptr es:[bx], 0FFFCh
jg notdead ; Don't bother if hero is less than level 4!
jmp dorevive
notdead:
inc di
cmp di,22h
jl nexthero5

jmp cantres

DoRevive:
mov di,85h
jmp ssdone

cantres:

mov di,0D4h ; Summon Champion
mov ax,0D4h
call isknown
or ax,ax
jnz ssdone

cmp cx,4
jge TryAgain

mov di,0D0h
mov ax,0D0h
call isknown
or ax,ax
jnz ssdone

jmp TryAgain
ski9:

;---------------------------
; 9 - Spell Blast
;---------------------------

cmp cx,9
jnz ski10
mov di,03Ah
jmp ssdone
ski10:

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

cmp cx,10
jnz ski11
mov di,034h
mov word ptr [bp-2],100 ; While works better with less slider, potential damage in one hit is higher with max 100%
jmp ssdone
ski11:

;--------------------------------------
; 11 - Create Artifact or Enchant Item
;--------------------------------------

cmp cx,11
jnz ski12

mov di,0D3h ; Create Artifact
mov ax,0D3h
call isknown
or ax,ax
jnz ssdone

mov di,0CFh ; Enchant Item
jmp ssdone

ski12:

;---------------------------
; 12 - Spell of Mastery
;---------------------------

cmp cx,12
jnz ski13
mov di,0D5h
jmp ssdone2
ski13:


;---------------------------
; 13 - Global Enchantments
;---------------------------

cmp cx,13
jnz ski14
jmp skiptable6
GlobalTable:
db 0C5h,050 ; SLOT 0 - Eternal Night
db 0C6h,050 ; SLOT 1 - Evil Omens
db 0BCh,050 ; SLOT 2 - Zombie Mastery
db 03Bh,025 ; SLOT 3 - Aura of Majesty
db 039h,035 ; SLOT 4 - AEther Binding
db 04Fh,130 ; SLOT 5 - Suppress Magic
db 000h,000 ; SLOT 6 (Time Stop)
db 028h,120 ; SLOT 8 - Fairy Ring
db 022h,050 ; SLOT 7 - Seismic Mastery
db 026h,045 ; SLOT 9 - Herb Mastery
db 074h,001 ; SLOT10 - Chaos Surge
db 06Ch,090 ; SLOT11 - Doom Mastery
db 072h,066 ; SLOT12 - Doomsday
db 071h,040 ; SLOT13 - Meteor Storm
db 078h,150 ; SLOT14 - Armageddon
db 09Dh,120 ; SLOT15 - Enlightenment
db 09Ch,050 ; SLOT16 - Life Force
db 09Eh,125 ; SLOT17 - Crusade
db 07Fh,025 ; SLOT18 - Just Cause
db 09Ah,045 ; SLOT19 - Holy Arms
db 087h,004 ; SLOT20 - Divine Order
db 0A0h,150 ; SLOT21 - Charm of Life
db 0CEh,010 ; SLOT22 - Detect Magic
db 01Ch,044 ; SLOT23 - Survival Instinct

LoadGlobals:
mov bx,GlobalTable
mov cx,23
call loadtable

call ChaosSurgeDecider

cmp ax,10
jge csok
mov word ptr [0D39Ch],0  ; Do not use
jmp asdfg
csok:
imul word ptr [0D39Ch]
mov word ptr [0D39Ch],ax ; Priority = number of chaos units
asdfg:

push si
push cs
call DivineOrderValue
pop cx

cmp ax,10
jge divordok
mov word ptr [0D3B0h],0
jmp ujyhyh
divordok:
imul word ptr [0D3B0h]
mov word ptr [0D3B0h],ax ; Priority = 5* "Divine Order needed"
ujyhyh:

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 nosup8
mov word ptr [0D3B4h],0  ; Suppress Magic in effect - Don't bother with Detect Magic (Spell Blast)
nosup8:

; If enchantment already cast, don't do it again!
mov ax,si
call getwiz
xor di,di
nextench:
cmp byte ptr [bx+di-5CB4h],0
jz rrrr
push di
sal di,1
mov word ptr [di+0D388h],0
pop di
rrrr:
inc di
cmp di,23
jle nextench

mov ax,3Ah
call isknown
or ax,ax
jnz ok336
mov word ptr [0D3B4h],0  ; Spell Blast unknown - don't do Detect Magic
ok336:

retn
skiptable6:
call LoadGlobals

Call SelectASpell

cmp ax,0
jl dosummon

mov bx,ax
sal bx,1

mov al,cs:[bx+Globaltable]
xor ah,ah
mov di,ax
cmp di,0
jg ssdone
jmp dosummon
ski14:

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

cmp cx,14
jnz ski15
mov di,044h
jmp ssdone
ski15:

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

cmp cx,15
jnz ski16
mov di,0ADh
jmp ssdone
ski16:

;---------------------------
; 16 - Focus Magic
;---------------------------

cmp cx,16
jnz ski17
mov di,02Fh
jmp ssdone
ski17:

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

cmp cx,17
jnz ski18
mov di,050h
jmp ssdone
ski18:

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

cmp cx,18
jnz ski19
mov di,045h
jmp ssdone
ski19:

;---------------------------
; 20 - Invisibility
;---------------------------

cmp cx,20
jnz ski21
mov di,03Eh
jmp ssdone
ski21:

;---------------------------
; 21 - Final Wave
;---------------------------

cmp cx,21
jnz ski22
mov di,0C7h
jmp ssdone
ski22:

;---------------------------
; 22 - Great Unsummoning
;---------------------------

cmp cx,22
jnz ski23
mov di,04Bh
jmp ssdone
ski23:

;---------------------------
; 23 - Nature's Cures
;---------------------------

cmp cx,23
jnz ski24
mov di,013h
jmp ssdone
ski24:

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

cmp cx,24
jnz ski25
mov di,0CBh
jmp ssdone
ski25:

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

cmp cx,25
jnz ski26
mov di,08Ah
jmp ssdone
ski26:

;---------------------------
; 26 - Spell Lock
;---------------------------

cmp cx,26
jnz ski27
mov di,036h
jmp ssdone
ski27:

;-----------------------------
; 27 - Doomstack Enabling
;-----------------------------

cmp cx,27
jnz ski28

mov di,0A8h ; Wraith Form - prioritize, gives immunity to web, entangle and crack's call, relevant in doomstack!
mov ax,0A8h
call isknown
or ax,ax
jnz ssdone

mov di,08h ; Water Walking
jmp ssdone
ski28:


;---------------------------------
; 19 - Cheap Buff Stacking Tactic
;---------------------------------

cmp cx,19
jnz ski20
jmp skiptable7
CheapTable:
db 07Bh,100 ; SLOT 0 - Endurance
db 07Ch,020 ; SLOT 1 - Holy Weapon
db 07Eh,090 ; SLOT 2 - Holy Armor
db 082h,110 ; SLOT 3 - Heroism
db 056h,090 ; SLOT 4 - Flame Blade
db 079h,130 ; SLOT 5 - Bless
db 029h,120 ; SLOT 6 - Resist Magic
db 002h,020 ; SLOT 7 - Resist Elements
db 0A8h,033 ; SLOT 8 - Wraith Form
db 015h,050 ; SLOT 9 - Elemental Armor
skiptable7:

mov bx,Cheaptable
mov cx,9
call loadtable

Call SelectASpell

cmp ax,0
jl TryAgain

mov bx,ax
sal bx,1

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


ski20:


ssdone:

;----------------------------------------------------
; Check if can afford casting this spell?
;----------------------------------------------------

call getincome
mov     ax, si
mov     dx, 4C8h
imul    dx
mov     bx, ax
mov     ax, [bx-5EDAh]
mov     bx, 5
cwd
idiv    bx
add     ax, [bp-0Ah]
push    ax
mov     ax, di
mov     dx, 24h ; '$'
imul    dx
les     bx, [912Ch] ; Spell_Data_Structure_Offset dword_3FBCC
add     bx, ax
mov     ax, es:[bx+1Ah]
mov     bx, 0Ah
cwd
idiv    bx
inc     ax
inc     ax
pop     dx
cmp     ax, dx
jle     short loc_E3B3B
xor di,di                       ; Mana crystals/5+Mana income<Spell cost/10 then do not cast!
loc_E3B3B:

ssdone2:
jmp setspellanddone


.org 368Ah
EarthGateTarget:

.org 3720h
SpellBlastNeeded:

.org 392Ch
NatureEyeTarget:

.org 39ADh
Transmutetarget:

.org 3B2Ch
CTtarget:

.org 3D79h
FFTarget:

.org 3E39h
Uranustarget:

.org 3EBAh
Gaiatarget:

.org 3F3Bh
WoFTarget:

.org 3FBCh
WoDTarget:

.org 403Dh
HeavenlyTarget:

.org 40BEh
AltarTarget:

.org 413Fh
StreamTarget:

.org 41C0h
InspirationTarget:

.org 4241h
ProsperityTarget:

.org 42C2h
AstralTarget:

.org 4343h
DarkRitualTarget:

.org 43ECh
CSTarget:

.org 446Dh
Wardtarget:

.org 4711h
ConsTarget:

.org 4B49h
CityCurseTarget:

.org 56ABh
WarpNodeTarget:

.org 5773h
DisjunctionTarget:

.org 6284h
StasisTarget:

.org 66C2h
DispellingWaveTarget:

.org 7395h
DivineOrderValue:

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.
Reply



Forum Jump: