myAi

Upload your latest creations here.
Please note that by posting comments to posts in this forum you forfeit your personal copyright on whatever you post. AI Scripters reserves the right to re-use objective comments in script reviews without requiring the posting author's permission. Credit, where appropriate will be given in such cases.
Post Reply
User avatar
the1unknown
Yogi
Posts: 344
Joined: Sat Jul 21, 2018 3:27 am

myAi

Post by the1unknown »

I don't know when I will get back at editing aoe2-ai, so , I will upload the my work here.
I selected a few AI that I made, most of them are tests and notes for me to learn ai scripting.

rynnogift, mygift, arrowSuit and maru are not that bad :lol:

RynnoGift.rar
v2
(11.67 KiB) Downloaded 84 times
myGift.zip
v1
(19.4 KiB) Downloaded 83 times
notes-tests Script.AI.zip
v1
(8.01 KiB) Downloaded 85 times
The reason rynno does not hunt boars is because rynno does not like to hunt his brothers :lol:

this video is fake ! ->https://www.youtube.com/watch?v=gheevrZ8mg8
__________________________________________________________________________________________________________________________
__________________________________________________________________________________________________________________________

here is the script for the FE ai

My long term goal for this AI is to make him go up to imp and have a decent-fun game. I don't intend to make him A GOOD PLAYER. I would want to focus more on the fun/chating/wierd strategy part.

Code: Select all

; exploring with scout , not villagers
(defrule
   (true) ; Facts go here
=>
   (set-strategic-number sn-initial-exploration-required 0) ; Actions after here.
   (set-strategic-number sn-percent-civilian-builders 50)
   (set-strategic-number sn-percent-civilian-gatherers 20)
   (set-strategic-number sn-percent-civilian-explorers 0)
   (set-strategic-number sn-cap-civilian-builders 250)
   (set-strategic-number sn-cap-civilian-gatherers 0)
   (set-strategic-number sn-cap-civilian-explorers 0)
   (set-strategic-number sn-number-explore-groups 1)
   (set-strategic-number sn-total-number-explorers 1)
   (chat-to-all " Hi ")
   (disable-self)
)


;building houses
(defrule
(can-build house)
(housing-headroom < 4)
(population-headroom > 3)
 (population-headroom != 0)
=>
(build house)
)

;training vills dark age
(defrule
(current-age == dark-age)
(unit-type-count-total villager < 30)
(can-train villager)
=>
(train villager)
)





;get loom
(defrule
(can-research ri-loom)
=>
(research ri-loom)
)

;research wheel barrow
(defrule
(research-available ri-wheel-barrow)
=>
(research ri-wheel-barrow)
)

;advance to feudal
(defrule
(can-research feudal-age)
=>
(research feudal-age)
)

;advance to castle
(defrule
(can-research castle-age)
=>
(research castle-age)
)

;advance to imp
(defrule
(can-research imperial-age)
=>
(research imperial-age)
)


;training vills feudal age
(defrule
(current-age == feudal-age)
(unit-type-count-total villager > 40)
(unit-type-count-total villager < 50)
(can-train villager)
=>
(train villager)
)

;build lumbercamp
(defrule
(can-build lumber-camp)
(unit-type-count villager > 10)
=>
(build lumber-camp)
(set-strategic-number sn-maximum-wood-drop-distance 3)
 (up-modify-sn sn-camp-max-distance c:+ 3)
)

;build mill
(defrule
(can-build mill)
(resource-found food)
(building-type-count-total mill >= 0)
(building-type-count-total mill < 2)
=>
(build mill)
(set-strategic-number sn-maximum-food-drop-distance 5)
(set-strategic-number sn-maximum-hunt-drop-distance 8)
)


;mill deer
;(defrule
;(resource-found deer)
;=>
;(build mlll)
;)
	

;build farms
(defrule
(current-age == dark-age)
;(building-type-count-total lumber-camp > 0) ; We want a lumber camp before farms
(unit-type-count-total villager > 8)
(building-type-count-total farm < 15)
;(idle-farm-count < 4) ; Only build farms if there are less than 4 idle farms
=>
(build farm)
)

(defrule
	(game-time greater-than 45)
	(building-type-count town-center less-than 1)
	(can-build town-center)
=>
	(build town-center)
)

(defrule
	(building-type-count-total blacksmith less-than 1)
	(can-build blacksmith)
=>
	(build blacksmith)
)

(defrule
	(building-type-count-total university less-than 1)
	(can-build university)
=>
	(build university)
)

(defrule
	(building-type-count-total market less-than 1)
	(can-build market)
=>
	(build market)
)

(defrule
	(building-type-count-total monastery < 1)
	(can-build monastery)
=>
	(build monastery)
)



(defrule
(can-research ri-redemption)
=>
(research ri-redemption)
)


(defrule
(can-research ri-sanctity)
=>
(research ri-sanctity)
)

(defrule
(can-research ri-illumination)
=>
(research ri-illumination)
)


(defrule
	(building-type-count-total castle < 1)
	(can-build castle)
=>
	(build castle)
)

(defrule
	(building-type-count-total siege-workshop < 1)
	(can-build siege-workshop)
=>
	(build siege-workshop)
)

(defrule
	(resource-found gold)
	(building-type-count-total mining-camp < 5)
	(dropsite-min-distance gold > 7)
	(can-build mining-camp)
=>
	(build mining-camp)
	(chat-local-to-self "gold place")
	)
	
	(defrule
	(resource-found stone)
	(building-type-count-total mining-camp < 5)
	(dropsite-min-distance stone > 7)
	(can-build mining-camp)
=>
	(build mining-camp)
	(chat-local-to-self "rock place")
)

;;;;;;;;;;TRAIN FISHING-SHIP
(defrule
(current-age == dark-age)
(unit-type-count fishing-ship < 2)
=>
(train fishing-ship)
)

;;;;;;;;;;TRAIN MILITIAMAN
(defrule
(current-age == dark-age)
(food-amount > 600)
(unit-type-count villager > 100)
(unit-type-count militiaman < 10)
(can-train militiaman)
=>
(train militiaman)
)
;drop resources distance
(defrule
  (true)
=>
  (set-strategic-number sn-maximum-food-drop-distance 5)
  (set-strategic-number sn-maximum-wood-drop-distance 4)
  (set-strategic-number sn-maximum-gold-drop-distance 1)
  (set-strategic-number sn-maximum-stone-drop-distance 1)
  (set-strategic-number sn-maximum-town-size 8)
  (set-strategic-number sn-mill-max-distance 15)
  (set-strategic-number sn-camp-max-distance 4)
  (set-strategic-number sn-enable-boar-hunting 1)

)

(defrule
(current-age == dark-age)
(unit-type-count-total villager > 15)
=>
   (set-strategic-number sn-initial-exploration-required 1) ; Actions after here.
   (set-strategic-number sn-percent-civilian-builders 50)
   (set-strategic-number sn-percent-civilian-gatherers 20)
   (set-strategic-number sn-percent-civilian-explorers 0)
   (set-strategic-number sn-cap-civilian-builders 250)
   (set-strategic-number sn-cap-civilian-gatherers 20)
)

;

;stable spam
(defrule
(can-build stable)
(building-type-count-total stable < 6)
=>
(build stable)
)

;scout spam
(defrule
	(can-train scout-cavalry-line)
	(unit-type-count-total  scout-cavalry < 30)
=>
	(train scout-cavalry-line)
)

(defrule
(can-research ri-husbandry)
=>
(research ri-husbandry)
)

(defrule
(can-research ri-bloodlines)
=>
(research ri-bloodlines)
)

(defrule
(can-research ri-forging)
=>
(research ri-forging)
)

;watch-tower
(defrule
(can-build watch-tower)
(building-type-count-total stable < 6)
=>
(build watch-tower)
)

;(defrule
;(resource-found fish)
;=> 
;(chat-to-all "Now I'm gonna make some Docks!")

	; Adjust Stance
	;------------------------------
	(defrule
		(players-stance any-enemy ally)
	=>
		(chat-to-player this-any-enemy "41It is good to have you as a friend.")
		(set-stance this-any-enemy neutral)
	)
	(defrule
		(or
			(or
				(players-stance any-ally neutral)
				(players-stance any-ally enemy)
			)
			(or
				(players-stance any-neutral neutral)
				(players-stance any-neutral enemy)
			)
		)
	=>
		(chat-to-player this-any-ally "40I have been betrayed.")
		(chat-to-player this-any-neutral "40I have been betrayed.")
		(set-stance this-any-ally enemy)
		(set-stance this-any-neutral enemy)
	)


(defrule
(true)

(cheats-enabled)
=>
(chat-to-all "Let the cheating begin!" )
(disable-self)
)

(defrule
(current-age == feudal-age)
(can-build barracks)
(building-type-count-total barracks <= 1)
=>
(build barracks) )

(defrule
(can-build archery-range)
(building-type-count-total archery-range <= 1)
=>
(build archery-range) )

;attack
(defrule
(military-population > 10)
(not(town-under-attack)
)
=>
(attack-now)
)

(load "myGift/resign")



(defconst sn-military-level 190)
(defconst sn-infantry-threat 53)
(defconst sn-archer-threat 64)
(defconst sn-cavalry-threat 65)
(defconst sn-military-superiority 192)

(defconst sn-food-modifier-percentage 156)
(defconst sn-wood-modifier-percentage 157)
(defconst sn-stone-modifier-percentage 158)
(defconst sn-gold-modifier-percentage 159)
(defconst sn-target-player-number 249)
(defconst sn-focus-player-number 251)
;(defconst sn-target-point-adjustment 292)
(defconst sn-allow-sheep-exploration 147)



(defrule (true) =>
 (up-assign-builders c: house c: 1) 
 (up-assign-builders c: town-center c: 3) 
 (up-assign-builders c: castle c: 15)
  (up-assign-builders c:  monastery c: 15)
   (up-assign-builders c: watch-tower c: 8)
    (up-assign-builders c: stable c: 2)
 (disable-self) )
 
 ;;;;;;;;;;TRAIN MONKS
(defrule
(unit-type-count monk < 3)
(can-train monk)
=>
(train monk)
)

;;;;;;;;;;train rams
(defrule
(current-age >= imperial-age)
(can-train battering-ram)
=>
(train battering-ram)
)


 
NOTE: it's really a mess, the scripts are not organized at all because ..it's a testing AI only for helping me learn ai scripting
so whatever I see and read on internet, I put there the script to see how it's working.


FIRST PROBLEM: the AI doesn't make lumbercamp anymore
SECOND PROBLEM: the AI has too many idles


I did not use goals and defconst because I didn't learn them yet and I don't know how and what they do
Last edited by the1unknown on Thu Dec 27, 2018 7:15 am, edited 5 times in total.
"you don't have to be great to start, but you have to start to be great" -the villager

User avatar
Esty
Guru
Posts: 929
Joined: Wed Dec 30, 2015 7:37 am

Re: myAi

Post by Esty »

Your problem with lumber-camp is linked to the value defined here :
=> (set-strategic-number sn-camp-max-distance 4)
4 isn't enough. sn-camp-max-distance is the number of tiles between your town center and the placement of your lumber-camp. A value too short won't let your AI to build it. I suggest you a value around 15, which is fine at the start of the game.
And when you define this kind of strategic numbers, it's better to disable-self the rule at its end. That way it is read once only ; it's pretty important when, after a certain time, the strategic number are set with new and different values.

Care : camp-max-distance concern lumber-camps AND mining-camps. You should make a condition for your mining-camp if you dont want it to be built before your LC by using (building-type-count lumber-camp > 0).

How goals work :
You can use goals without having defconst them. For exemple, you want a goal which trigger when you have researched some important upgrades.

Code: Select all

(defrule)
(true)
=>
(set-goal 1 0)
(disable-self))
The goal called "1 " is set to a value of zero at the start.

Code: Select all

(defrule
(research-completed ri-fletching)
(research-completed ri-padded-archer-armor)
=>
(set-goal 1 1)
(disable-self))
When those 2 upgrades are researched, the goal called "1" is set to 1
When goal 1 is set to 1 you want to train archers

Code: Select all

(defrule
(goal 1 1)
(can-train archer-line)
=>
(train archer-line))
Now, if you define the constant of your goal :

(defconst feudal-upgrades-researched 1)

It means that you give a name to your goal 1. Your codes will become :

Code: Select all

(defrule)
(true)
=>
(set-goal feudal-upgrades-researched 0)
(disable-self))

(defrule
(research-completed ri-fletching)
(research-completed ri-padded-archer-armor)
=>
(set-goal feudal-upgrades-researched 1)
(disable-self))

(defrule
(goal feudal-upgrades-researched 1)
(can-train archer-line)
=>
(train archer-line))
To name your goals by defonst can be really important when you've got more than 50 goals. That way you know exactly their role/capacity.
Now, the value attributed to your goal, here 0 or 1 can be defconst too :

Code: Select all

(defconst YES 1)
(defconst NO 2)

(defrule)
(true)
=>
(set-goal feudal-upgrades-researched NO)
(disable-self))

(defrule
(research-completed ri-fletching)
(research-completed ri-padded-archer-armor)
=>
(set-goal feudal-upgrades-researched YES)
(disable-self))

(defrule
(goal feudal-upgrades-researched YES)
(can-train archer-line)
=>
(train archer-line))
I hope it's clearer for you.
Author of the TRiBaL_Warriors AI and currently PharaoN :dance

User avatar
the1unknown
Yogi
Posts: 344
Joined: Sat Jul 21, 2018 3:27 am

Re: myAi

Post by the1unknown »

Esty wrote:..
I hope it's clearer for you.
thanks.

here's my test

Code: Select all

(defrule
(true)
=>
(set-goal 1 0)
(disable-self))

(defrule
(research-completed ri-loom)
=>
(set-goal 1 1)
(disable-self))

(defrule
(goal 1 1)
=>
	(chat-to-all "loom is done")
	(disable-self) )
	

(defconst dark-upgrades-researched 1)

(defrule
(true)
=>
(set-goal dark-upgrades-researched 0)
(disable-self))

(defrule
(unit-type-count scout-cavalry  > 3)
=>
(set-goal dark-upgrades-researched 1)
(disable-self))

(defrule
(goal dark-upgrades-researched 1)
=>
(chat-to-all " i have 3 scouts")
(disable-self)
)
"you don't have to be great to start, but you have to start to be great" -the villager

User avatar
the1unknown
Yogi
Posts: 344
Joined: Sat Jul 21, 2018 3:27 am

Re: myAi

Post by the1unknown »

now my AI listen to me.
whenever he can, he will make a lumbercamp

Image


also he doesn't care there are only three trees
Image
"you don't have to be great to start, but you have to start to be great" -the villager

User avatar
Esty
Guru
Posts: 929
Joined: Wed Dec 30, 2015 7:37 am

Re: myAi

Post by Esty »

GOOD !
Now you can add and test this in your conditions for your lumber-camp : (dropsite-min-distance wood > 2)
With this, Only when your lumber-camp is built too far from the forest (more than 2 tiles), one new lumber-camp is requiered.
for exemple, you could have :

Code: Select all

(defrule
(unit-type-count villager >= 11)
(or   (and   (current-age == dark-age)
                 (building-type-count-total lumber-camp <= 0))
        (and   (current-age > dark-age)
                (dropsite-min-distance wood > 2)))
(can-build lumber-camp)
(up-pending-objects c: lumber-camp < 1)
=>
(build lumber-camp))
(set-strategic-number sn-allow-adjacent-dropsites 1)
What is the difference between unit-type-count and unit-type-count-total :
Unit-type-count doesn't count the buildings under contruction, instead of unit-type-count-total which will count any building regardless if its under construction or totally built.
Up-pending-objects is used to define how many buildings can be built at the same time. In this exemple, i want my ai to build lumber-camps one by one.
sn-allow-adjacent-dropsites defined to "1" means your building will be built at a distance of zero to ur resource. If set to 0, your camp will be built at a distance = 1 tile.

ps : your 2nd screenshot is really cool ! perfect placement for a LC :rofl
Author of the TRiBaL_Warriors AI and currently PharaoN :dance

User avatar
the1unknown
Yogi
Posts: 344
Joined: Sat Jul 21, 2018 3:27 am

Re: myAi

Post by the1unknown »

Code: Select all

(defrule
	(taunt-detected any-human 888)
=>
	(cc-add-resource wood 500)
	(cc-add-resource food 500)
	(cc-add-resource gold 500)
	(cc-add-resource stone 500)
	
	(acknowledge-taunt this-any-human 888) ) 
the AI didn't get any extra resources. Is this code not working in aok ?

I don't get any error..
"you don't have to be great to start, but you have to start to be great" -the villager

User avatar
the1unknown
Yogi
Posts: 344
Joined: Sat Jul 21, 2018 3:27 am

Re: myAi

Post by the1unknown »

neither this..

Code: Select all

(defrule
	(taunt-detected any-human 999)
=>
	(acknowledge-taunt this-any-human 999)
	(tribute-to-player any-enemy  wood  1000)
	(tribute-to-player any-enemy  food  1000)
	(tribute-to-player any-enemy  gold  1000)
	(tribute-to-player any-enemy  stone  1000) )
"you don't have to be great to start, but you have to start to be great" -the villager

User avatar
CheeseOnToast
Yogi
Posts: 387
Joined: Sun Aug 31, 2014 5:48 pm

Re: myAi

Post by CheeseOnToast »

I think the maximum amount of taunts which can be used is between 1 and 255 :)

User avatar
the1unknown
Yogi
Posts: 344
Joined: Sat Jul 21, 2018 3:27 am

Re: myAi

Post by the1unknown »

CheeseOnToast wrote:I think the maximum amount of taunts which can be used is between 1 and 255 :)
yes, is working with a low number. thanks
"you don't have to be great to start, but you have to start to be great" -the villager

User avatar
the1unknown
Yogi
Posts: 344
Joined: Sat Jul 21, 2018 3:27 am

Re: myAi

Post by the1unknown »

I've made an ai with the FE ai builder
http://www.forgottenempires.net/aibuilder/

In aok and aofe I get "2005" invalid identifier feudal , line 36
the one with red



(defrule
(goal combi yes)
(goal allow-advancing yes)
(or
(or
(goal end-age feudal)
(goal end-age castle)
)
(goal end-age imperial)
)
(can-research-with-escrow feudal-age)
=>
(release-escrow food)
(release-escrow gold)
(research feudal-age)
)


builder upgrades.per

Code: Select all

;-----Escrow-----

(defrule
	(or
		(or
			(escrow-amount wood > 2000)
			(escrow-amount food > 2000)
		)
		(or
			(escrow-amount gold > 3000)
			(escrow-amount stone > 3000)
		)
	)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	 
)

(defrule
	(true)
=>
	(set-escrow-percentage wood 30)
	(set-escrow-percentage food 30)
	(set-escrow-percentage gold 30)
	(set-escrow-percentage stone 30)
)

;-----Advance age-----
(defrule
	(goal combi yes)
	(goal allow-advancing yes)
	(or
		(or
			(goal end-age feudal)
			(goal end-age castle)
		)
		(goal end-age imperial)
	)
	(can-research-with-escrow feudal-age)
=>
	(release-escrow food)
	(release-escrow gold)
	(research feudal-age)
)

(defrule
	(goal combi yes)
	(goal allow-advancing yes)
	(or
		(goal end-age castle)
		(goal end-age imperial)
	)
	(can-research-with-escrow castle-age)
=>
	(release-escrow food)
	(release-escrow gold)
	(research castle-age)
)
(defrule
	(goal combi yes)
	(goal allow-advancing yes)
	(goal end-age imperial)
	(can-research-with-escrow imperial-age)
=>
	(release-escrow food)
	(release-escrow gold)
	(research imperial-age)
)

;UNIT UPGRADES

(defrule
	(goal combi 1)
	(goal military-techs 1)
	(can-research-with-escrow my-unique-unit-upgrade)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research my-unique-unit-upgrade)
	(chat-local-to-self "research elite uniques")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
	(can-research-with-escrow my-unique-research)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research my-unique-research)
	(chat-local-to-self "research unique research")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
	(unit-type-count militiaman > 3)
	(can-research-with-escrow ri-man-at-arms)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-man-at-arms)
	(chat-local-to-self "research man-at-arms")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
	(unit-type-count eagle-warrior > 3)
	(can-research-with-escrow ri-elite-eagle-warrior)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-elite-eagle-warrior)
	(chat-local-to-self "research elite eagle warrior")
)


(defrule
	(goal combi 1)
	(goal military-techs 1)
	(unit-type-count man-at-arms > 6)
	(can-research-with-escrow ri-long-swordsman)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
    (research ri-long-swordsman)
	(chat-local-to-self "research long swordsman ")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
	(unit-type-count long-swordsman > 6)
	(can-research-with-escrow ri-two-handed-swordsman)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
    (research ri-two-handed-swordsman)
	(chat-local-to-self "research two-handed-swordsman")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
	(unit-type-count two-handed-swordsman > 6)
	(can-research-with-escrow ri-champion)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
    (research ri-champion)
	(chat-local-to-self "research champion")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
	(unit-type-count-total spearman > 2)
	(can-research-with-escrow ri-pikeman)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
    (research ri-pikeman)
	(chat-local-to-self "research pike")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
	(unit-type-count-total pikeman > 2)
	(can-research-with-escrow ri-halberdier)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
    (research ri-halberdier)
	(chat-local-to-self "research halberd")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
	(unit-type-count-total scout-cavalry > 2)
	(can-research-with-escrow ri-light-cavalry)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-light-cavalry)
	(chat-local-to-self "research light-cavalry")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
	(unit-type-count-total light-cavalry > 3)
	(can-research-with-escrow ri-hussar)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-hussar)
	(chat-local-to-self "research hussar")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
	(unit-type-count-total camel > 2)
	(can-research-with-escrow ri-heavy-camel)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
    (research ri-heavy-camel)
	(chat-local-to-self "research heavy camel")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
    (unit-type-count-total knight > 2)
	(can-research-with-escrow ri-cavalier)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
    (research ri-cavalier)
	(chat-local-to-self "research cavalier")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
    (unit-type-count-total cavalier > 2)
	(can-research-with-escrow ri-paladin)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
    (research ri-paladin)
	(chat-local-to-self "research paladin")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
	(unit-type-count archer > 6)
	(can-research-with-escrow ri-crossbow)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
    (research ri-crossbow)
	(chat-local-to-self "research crossbow")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
	(unit-type-count crossbowman > 6)
	(can-research-with-escrow ri-arbalest)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
    (research ri-arbalest)
	(chat-local-to-self "research arbalest")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
	(unit-type-count cavalry-archer > 6)
	(can-research-with-escrow ri-heavy-cavalry-archer)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
    (research ri-heavy-cavalry-archer)
	(chat-local-to-self "research heavy-cavalry-archer")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
	(unit-type-count-total skirmisher > 2)
	(can-research-with-escrow ri-elite-skirmisher)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
    (research ri-elite-skirmisher)
	(chat-local-to-self "research elite skirmisher")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
	(unit-type-count scorpion > 4)
	(can-research-with-escrow ri-heavy-scorpion)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
    (research ri-heavy-scorpion)
	(chat-local-to-self "research heavy-scorpion")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
    (unit-type-count battering-ram > 2)
	(can-research-with-escrow ri-capped-ram)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
    (research ri-capped-ram)
	(chat-local-to-self "research capped ram")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
    (unit-type-count capped-ram > 2)
	(can-research-with-escrow ri-siege-ram)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
    (research ri-siege-ram)
	(chat-local-to-self "research siege-ram")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
	(unit-type-count mangonel > 3)
	(can-research-with-escrow ri-onager)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
      (research ri-onager)
	(chat-local-to-self "research onager")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
    (unit-type-count onager > 3)
	(can-research-with-escrow ri-siege-onager)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
    (research ri-siege-onager)
	(chat-local-to-self "research siege onager")
)

;DOCK UNITS
(defrule
	(goal combi 1)
	(goal dock-techs 1)
	(unit-type-count galley > 2)
	(can-research-with-escrow ri-war-galley)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
    (research ri-war-galley)
	(chat-local-to-self "research war-galley")
)

(defrule
	(goal combi 1)
	(goal dock-techs 1)
	(unit-type-count war-galley > 2)
	(can-research-with-escrow ri-galleon)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
    (research ri-galleon)
	(chat-local-to-self "research galleon")
)

(defrule
	(goal combi 1)
	(goal dock-techs 1)
	(or
		(unit-type-count galleon > 2)
		(unit-type-count war-galley > 2)
	)
	(can-research-with-escrow ri-cannon-galleon)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
    (research ri-cannon-galleon)
	(chat-local-to-self "research cannon-galleon")
)

(defrule
	(goal combi 1)
	(goal dock-techs 1)
	(unit-type-count-total fire-ship > 1)
	(can-research-with-escrow ri-fast-fire-ship)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
    (research ri-fast-fire-ship)
	(chat-local-to-self "research fast-fire-ship")
)

(defrule
	(goal combi 1)
	(goal dock-techs 1)
	(unit-type-count demolition-ship > 2)
	(can-research-with-escrow ri-heavy-demolition-ship)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
    (research ri-heavy-demolition-ship)
	(chat-local-to-self "research heavy-demolition-ship")
)

; ////////////////////////WEAPONS/////////////////////////////////////////////////

(defrule
	(goal combi 1)
	(goal military-techs 1)
	(can-research-with-escrow ri-forging)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
     (research ri-forging)
	(chat-local-to-self "research forging")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
	(can-research-with-escrow ri-iron-casting)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-iron-casting)
	(chat-local-to-self "research iron-casting")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
	(can-research-with-escrow ri-blast-furnace)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-blast-furnace)
	(chat-local-to-self "research blast-furnace")
)

;ARCHER UPGRADES -- cost food/gold
(defrule
	(goal combi 1)
	(goal military-techs 1)
	(can-research-with-escrow ri-fletching)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-fletching)
	(chat-local-to-self "research fletching")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
	(can-research-with-escrow ri-bodkin-arrow)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-bodkin-arrow)
	(chat-local-to-self "research bodkin-arrow")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
	(can-research-with-escrow ri-bracer)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-bracer)
	(chat-local-to-self "research bracer")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
	(unit-type-count-total cavalry-archer-line > 3)
	(can-research-with-escrow ri-parthian-tactics)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-parthian-tactics)
	(chat-local-to-self "research parthian tactics")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
	(or
		(unit-type-count-total archer-line > 3)
		(or
			(unit-type-count-total skirmisher-line > 3)
			(unit-type-count-total cavalry-archer-line > 3)
		)
	)
	(can-research-with-escrow ri-thumb-ring)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-thumb-ring)
	(chat-local-to-self "research thumb ring")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
	(or
		(unit-type-count-total archer-line > 3)
		(or
			(unit-type-count-total skirmisher-line > 3)
			(unit-type-count-total cavalry-archer-line > 3)
		)
	)
	(can-research-with-escrow ri-padded-archer-armor)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-padded-archer-armor)
	(chat-local-to-self "research padded-archer-armor")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
	(or
		(unit-type-count-total archer-line > 3)
		(or
			(unit-type-count-total skirmisher-line > 3)
			(unit-type-count-total cavalry-archer-line > 3)
		)
	)
	(can-research-with-escrow ri-leather-archer-armor)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-leather-archer-armor)
	(chat-local-to-self "research leather-archer-armor")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
	(or
		(unit-type-count-total archer-line > 3)
		(or
			(unit-type-count-total skirmisher-line > 3)
			(unit-type-count-total cavalry-archer-line > 3)
		)
	)
	(can-research-with-escrow ri-ring-archer-armor)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-ring-archer-armor)
	(chat-local-to-self "research ring-archer-armor")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
	(or
		(unit-type-count-total eagle-warrior-line > 3)
		(or
			(unit-type-count-total militiaman-line > 3)
			(unit-type-count-total spearman-line > 3)
		)
	)
	(can-research-with-escrow ri-scale-mail)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-scale-mail)
	(chat-local-to-self "research scale-mail")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
	(or
		(unit-type-count-total eagle-warrior-line > 3)
		(or
			(unit-type-count-total militiaman-line > 3)
			(unit-type-count-total spearman-line > 3)
		)
	)
	(can-research-with-escrow ri-chain-mail)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-chain-mail)
	(chat-local-to-self "research chain-mail")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
	(or
		(unit-type-count-total eagle-warrior-line > 3)
		(or
			(unit-type-count-total militiaman-line > 3)
			(unit-type-count-total spearman-line > 3)
		)
	)
	(can-research-with-escrow ri-plate-mail)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-plate-mail)
	(chat-local-to-self "research plate-mail")
)


(defrule
	(goal combi 1)
	(goal military-techs 1)
	(or
		(unit-type-count-total eagle-warrior-line > 3)
		(or
			(unit-type-count-total militiaman-line > 3)
			(unit-type-count-total spearman-line > 3)
		)
	)
	(can-research-with-escrow ri-tracking)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-tracking)
	(chat-local-to-self "research tracking")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
	(or
		(unit-type-count-total eagle-warrior-line > 3)
		(or
			(unit-type-count-total militiaman-line > 3)
			(unit-type-count-total spearman-line > 3)
		)
	)
	(can-research-with-escrow ri-squires)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-squires)
	(chat-local-to-self "research squires")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
	(or
		(unit-type-count-total cavalry-archer-line > 3)
		(or
			(unit-type-count-total knight-line > 3)
			(unit-type-count-total scout-cavalry-line > 3)
		)
	)
	(can-research-with-escrow ri-bloodlines)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-bloodlines)
	(chat-local-to-self "research bloodlines")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
	(or
		(unit-type-count-total knight-line > 3)
		(unit-type-count-total scout-cavalry-line > 3)
	)
	(can-research-with-escrow ri-scale-barding)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-scale-barding)
	(chat-local-to-self "research scale-barding")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
	(or
		(unit-type-count-total knight-line > 3)
		(unit-type-count-total scout-cavalry-line > 3)
	)
	(can-research-with-escrow ri-chain-barding)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-chain-barding)
	(chat-local-to-self "research chain-barding")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
	(or
		(unit-type-count-total knight-line > 3)
		(unit-type-count-total scout-cavalry-line > 3)
	)
	(can-research-with-escrow ri-plate-barding)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-plate-barding)
	(chat-local-to-self "research plate-barding")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
	(or
		(unit-type-count-total cavalry-archer-line > 3)
		(or
			(unit-type-count-total knight-line > 3)
			(unit-type-count-total scout-cavalry-line > 3)
		)
	)
	(can-research-with-escrow ri-husbandry)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-husbandry)
	(chat-local-to-self "research husbandry")
)

; /////////////////////SIEGE RESEARCH ITEMS///////////////////////////

(defrule
	(goal combi 1)
	(goal military-techs 1)
	(can-research-with-escrow ri-siege-engineers)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-siege-engineers)
	(chat-local-to-self "research siege-engineers")
)

;FORTRESS UPGRADES
(defrule
	(goal combi 1)
	(goal university-techs 1)
	(can-research-with-escrow ri-hoardings)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-hoardings)
	(chat-local-to-self "research hoardings")
)

;SHIPS
(defrule
	(goal combi 1)
	(goal dock-techs 1)
	(unit-type-count cannon-galleon > 2)
	(can-research-with-escrow ri-deck-guns)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-deck-guns)
	(chat-local-to-self "research deck guns ")
)

(defrule
	(goal combi 1)
	(goal dock-techs 1)
	(or
		(unit-type-count transport-ship > 0)
		(unit-type-count galley-line > 2)
	)
	(can-research-with-escrow ri-careening)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-careening)
	(chat-local-to-self "research careening ")
)

(defrule
	(goal combi 1)
	(goal dock-techs 1)
	(or
		(unit-type-count transport-ship > 0)
		(unit-type-count galley-line > 2)
	)
	(can-research-with-escrow ri-dry-dock)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-dry-dock)
	(chat-local-to-self "research dry-dock ")
)

(defrule
	(goal combi 1)
	(goal dock-techs 1)
	(or
		(unit-type-count galley-line > 2)
		(or
			(unit-type-count-total cannon-galleon-line > 1)
			(unit-type-count-total fire-ship-line > 1)
		)
	)
	(can-research-with-escrow ri-shipwright)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-shipwright)
	(chat-local-to-self "research shipwright ")
)

;OTHER RESEARCH ITEMS
(defrule
	(goal combi 1)
	(goal military-techs 1)
	(can-research-with-escrow ri-ballistics)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-ballistics)
	(chat-local-to-self "research ballistics ")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
	(can-research-with-escrow ri-chemistry)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-chemistry)
	(chat-local-to-self "research chemistry ")
)

(defrule
	(goal combi 1)
	(goal military-techs 1)
	(can-research-with-escrow ri-conscription)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-conscription)
	(chat-local-to-self "research conscription")
)

; //////////////////////ECONOMIC/////////////////////////////

;mining-camp items
(defrule
	(goal combi 1)
	(goal economic-techs 1)
	(can-research-with-escrow ri-gold-mining)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-gold-mining)
	(chat-local-to-self "research gold mining")
)

(defrule
	(goal combi 1)
	(goal economic-techs 1)
	(can-research-with-escrow ri-gold-shaft-mining)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-gold-shaft-mining)
	(chat-local-to-self "research gold shaft mining")
)

(defrule
	(goal combi 1)
	(goal economic-techs 1)
	(building-type-count mining-camp > 1)
	(can-research-with-escrow ri-stone-mining)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-stone-mining)
	(chat-local-to-self "research stone mining")
)

(defrule
	(goal combi 1)
	(goal economic-techs 1)
	(building-type-count mining-camp > 1)
	(can-research-with-escrow ri-stone-shaft-mining)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-stone-shaft-mining)
	(chat-local-to-self "research stone shaft mining")
)

;mill items
(defrule
	(goal combi 1)
	(goal economic-techs 1)
	(can-research-with-escrow ri-horse-collar)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-horse-collar)
	(chat-local-to-self "research horse collar")
)

(defrule
	(goal combi 1)
	(goal economic-techs 1)
	(can-research-with-escrow ri-heavy-plow)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-heavy-plow)
	(chat-local-to-self "research heavy plow")
)

(defrule
	(goal combi 1)
	(goal economic-techs 1)
	(can-research-with-escrow ri-crop-rotation)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-crop-rotation)
	(chat-local-to-self "research crop rotation")
)

;saw mill
(defrule
	(goal combi 1)
	(goal economic-techs 1)
	(can-research-with-escrow ri-double-bit-axe)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-double-bit-axe)
	(chat-local-to-self "research double bit axe")
)

(defrule
	(goal combi 1)
	(goal economic-techs 1)
	(can-research-with-escrow ri-bow-saw)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-bow-saw)
	(chat-local-to-self "research bow saw")
)

(defrule
	(goal combi 1)
	(goal economic-techs 1)
	(can-research-with-escrow ri-two-man-saw)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-two-man-saw)
	(chat-local-to-self "research 2 man saw")
)

;university stuff
(defrule
	(goal combi 1)
	(goal university-techs 1)
	(can-research-with-escrow ri-masonry)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-masonry)
	(chat-local-to-self "research masonry")
)

(defrule
	(goal combi 1)
	(goal university-techs 1)
	(can-research-with-escrow ri-architecture)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-architecture)
	(chat-local-to-self "research architecture")
)

(defrule
	(goal combi 1)
	(goal economic-techs 1)
	(can-research-with-escrow ri-stonecutting)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-stonecutting)
	(chat-local-to-self "research stonecutting")
)

;market & town center
(defrule
	(goal combi 1)
	(goal economic-techs 1)
	(or
		(unit-type-count-total trade-cart > 1)
		(unit-type-count-total trade-cog > 1)
	)
	(can-research-with-escrow ri-caravan)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-caravan)
	(chat-local-to-self "caravan")
)

(defrule
	(goal combi 1)
	(goal economic-techs 1)
	(can-research-with-escrow ri-guilds)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-guilds)
	(chat-local-to-self "research guilds")
)

(defrule
	(goal combi 1)
	(goal economic-techs 1)
	(current-age >= castle-age)
	(can-research-with-escrow ri-loom)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-loom)
	(chat-local-to-self "research loom")
)

(defrule
	(goal combi 1)
	(goal economic-techs 1)
	(can-research-with-escrow ri-hand-cart)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-hand-cart)
	(chat-local-to-self "research hand-cart")
)

(defrule
	(goal combi 1)
	(goal economic-techs 1)
	(can-research-with-escrow ri-wheel-barrow)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-wheel-barrow)
	(chat-local-to-self "research wheelbarrow")
)

(defrule
	(goal combi 1)
	(goal economic-techs 1)
	(or
		(players-stance any-computer ally)
		(players-stance any-human ally)
	)
	(can-research-with-escrow ri-coinage)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-coinage)
	(chat-local-to-self "research coinage")
)

(defrule
	(goal combi 1)
	(goal economic-techs 1)
	(or
		(players-stance any-computer ally)
		(players-stance any-human ally)
	)
	(can-research-with-escrow ri-banking)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-banking)
	(chat-local-to-self "research banking")
)

; ////////////////////MONK/////////////////
(defrule
	(goal combi 1)
	(goal monastery-techs 1)
	(or
		(cc-players-unit-type-count any-enemy monk > 1)
        (unit-type-count-total war-elephant-line > 2)
	)
	(can-research-with-escrow ri-faith)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-faith)
	(chat-local-to-self "research faith")
)

(defrule
	(difficulty <= moderate)
	(goal combi 1)
	(goal monastery-techs 1)
	(cc-players-unit-type-count any-enemy monk > 1)
	(can-research-with-escrow ri-heresy)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-heresy)
	(chat-local-to-self "research heresy")
)

(defrule
	(goal combi 1)
	(goal monastery-techs 1)
    (cc-players-unit-type-count any-enemy monk > 2)
	(can-research-with-escrow ri-atonement)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-atonement)
	(chat-local-to-self "research atonement")
)

(defrule
	(goal combi 1)
	(goal monastery-techs 1)
	(unit-type-count-total monk > 2)
	(can-research-with-escrow ri-block-printing)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-block-printing)
	(chat-local-to-self "research block printing")
)

(defrule
	(goal combi 1)
	(goal monastery-techs 1)
	(unit-type-count-total monk > 2)
	(can-research-with-escrow ri-illumination)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-illumination)
	(chat-local-to-self "research illumination")
)

(defrule
	(goal combi 1)
	(goal monastery-techs 1)
	(unit-type-count-total monk > 2)
	(can-research-with-escrow ri-fervor)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-fervor)
	(chat-local-to-self "research fervor")
)

(defrule
	(goal combi 1)
	(goal monastery-techs 1)
	(unit-type-count-total monk > 2)
	(can-research-with-escrow ri-redemption)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-redemption)
	(chat-local-to-self "research redemption")
)

(defrule
	(goal combi 1)
	(goal monastery-techs 1)
	(unit-type-count-total monk > 2)
	(can-research-with-escrow ri-sanctity)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-sanctity)
	(chat-local-to-self "research sanctity")
)

(defrule
	(goal combi 1)
	(goal monastery-techs 1)
	(unit-type-count-total monk > 3)
	(can-research-with-escrow ri-theocracy)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-theocracy)
	(chat-local-to-self "research theocracy")
)


;TOWERS & WALLS

(defrule
	(goal combi 1)
	(goal university-techs 1)
	(building-type-count-total watch-tower > 1)
	(can-research-with-escrow ri-guard-tower)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
    (research ri-guard-tower)
	(chat-local-to-self "research guard tower")
)

(defrule
	(goal combi 1)
	(goal university-techs 1)
	(building-type-count-total guard-tower > 1)
	(can-research-with-escrow ri-keep)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
    (research ri-keep)
	(chat-local-to-self "research keep")
)

(defrule
	(goal combi 1)
	(goal university-techs 1)
	(building-type-count university > 0)
	(building-type-count-total watch-tower-line > 3)
	(research-available ri-bombard-tower)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
    (research ri-bombard-tower)
	(chat-local-to-self "research bombard-tower")
)

(defrule
	(goal combi 1)
	(goal university-techs 1)
	(building-type-count-total watch-tower-line > 3)
	(can-research-with-escrow ri-heated-shot)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
     (research ri-heated-shot)
	(chat-local-to-self "research heated-shot")
)

(defrule
	(difficulty <= moderate) ; moderate, hard and hardest
	(goal combi 1)
	(goal university-techs 1)
	(or
		(building-type-count-total castle > 0)
		(building-type-count-total watch-tower-line > 2)
	)
	(can-research-with-escrow ri-murder-holes)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-murder-holes)
	(chat-local-to-self "research murder-holes")
)

(defrule
	(goal combi 1)
	(goal university-techs 1)
(or
		(building-type-count-total castle > 0)
		(building-type-count-total watch-tower-line > 2)
	)
	(can-research-with-escrow ri-fortified-wall)
=>
	(release-escrow wood)
	(release-escrow food)
	(release-escrow gold)
	(release-escrow stone)
	(research ri-fortified-wall)
	(chat-local-to-self "research fortifications")
)

ai per:

Code: Select all

;-------------------------------------------------------
;theGift
;-------------------------------------------------------
;Generated with AIBuilder

;This ai is meant for campaigns only. It's able to create units, research techs and attack. It also has some economic activity but not really enough to support the AI so it's possible to cheat to make up for the missing economic activity.


;***Set Constants***
;---GENERAL---
(defconst yes 1)
(defconst no 0)
(defconst aisignal 1)

;---GOALS---
;(defconst unit3 camel-line)
;(defconst unit7 skirmisher-line)
;(defconst naval1 demolition-ship-line)

(defconst unit1 spearman-line)
(defconst unit2 scout-cavalry-line)
(defconst unit3 knight-line)
(defconst unit4 monk)
(defconst unit5 archer-line)
(defconst unit6 my-unique-unit-line)
(defconst unit7 hand-cannoneer)
(defconst siege1 battering-ram-line)
(defconst siege2 trebuchet)
(defconst siege3 bombard-cannon)
(defconst naval1 fire-ship-line)
(defconst naval2 cannon-galleon-line)
(defconst naval3 galley-line)
(defconst blacksmith-techs 5)
(defconst military-techs 6)
(defconst economic-techs 7)
(defconst university-techs 8)
(defconst monastery-techs 9)
(defconst dock-techs 10)
(defconst build-houses 11)
(defconst end-age 12)
(defconst allow-cheats 13)
(defconst use-market 14)
(defconst default-resign 15)
(defconst allow-advancing 16)
(defconst allow-signal 17)
(defconst active-at-start 18)
(defconst activate 19)
(defconst combi 20)

;---ATTACKS--- 
(defconst attack-timer 2)
(defconst interval-timer 3)
(defconst standby 0)
(defconst offence 1)
(defconst reset-attack 2)
(defconst attack-goal 3)

;---UPGRADES---
(defconst food-escrow 50)
(defconst wood-escrow 50)
(defconst gold-escrow 50)
(defconst stone-escrow 25)

;---OTHERS---
(defconst percentage-builders 20) 
(defconst percentage-gatherers 80) 
(defconst percentage-explorers 1) 
(defconst food-gatherers 60) 
(defconst wood-gatherers 25)
(defconst gold-gatherers 10)
(defconst stone-gatherers 5)
(defconst end-feudal 1)
(defconst end-castle 2)
(defconst end-imperial 3)
(defconst task-soldiers yes)

;---Amounts---
(defconst amount-farms 30)
(defconst amount-villagers 50)
(defconst amount-traders 8)
(defconst amount-sea-traders 8)
(defconst amount-fishing-ships 6)
(defconst amount-town-centers 2)
(defconst amount-lumber-camps 2)
(defconst amount-mills 2)
(defconst amount-mining-camp-gold 2)
(defconst amount-mining-camp-stone 2)
(defconst amount-barracks 2)
(defconst amount-archery-ranges 2)
(defconst amount-stables 2)
(defconst amount-siege-workshops 1)
(defconst amount-docks 2)
(defconst amount-universities 1)
(defconst amount-blacksmiths 1)
(defconst amount-markets 1)
(defconst amount-monasteries 1)
(defconst amount-castles 10)
(defconst amount-towers 20)
(defconst amount-bombard-towers 10)


;***Set Goals***
;---Upgrades---

(defrule
	(true)
=>
	(set-goal economic-techs yes)
	(set-goal military-techs yes)
	(set-goal blacksmith-techs yes)
	(set-goal university-techs yes)
	(set-goal monastery-techs yes)
	(set-goal dock-techs yes)
	(disable-self)
)

;---General---

(defrule
	(true)
=>
	(set-goal allow-advancing yes)
	(set-goal build-houses yes)
	(set-goal end-age end-imperial)
	(set-goal use-market yes)
	(set-goal allow-cheats no)
	(set-goal default-resign no)
	(set-goal allow-signal 1)
	(set-goal active-at-start 0)
	(disable-self)
)

;---Activation---
;when a signal is send or the AI is allowed to be active at start it will tell the AI to enable the activate goal. This goal will make the AI active. (Combi is for backwards compability)

(defrule
	(or
		(and
		(event-detected trigger aisignal)
		(goal allow-signal yes)
		)
	(goal active-at-start yes)
	)
=>
	(set-goal activate yes)
	(set-goal combi yes)
	(disable-self)
)


;***Setup***
;---Load Externals---
;load extra files. These files are generic and take care of the resigning of the AI, its upgrades and the active use of the market.

(load "builder resign")
(load "builder upgrades")
(load "builder market")

;---Immobile Behaviour---
;default behaviour is set to immobile

(defrule
	(goal active-at-start no)
=>
	(set-strategic-number sn-maximum-food-drop-distance 0)
	(set-strategic-number sn-maximum-wood-drop-distance 0)
	(set-strategic-number sn-maximum-gold-drop-distance 0)
	(set-strategic-number sn-maximum-hunt-drop-distance 0)
	(set-strategic-number sn-maximum-stone-drop-distance 0)
	(set-strategic-number sn-food-gatherer-percentage 0)
	(set-strategic-number sn-wood-gatherer-percentage 0)
	(set-strategic-number sn-gold-gatherer-percentage 0)
	(set-strategic-number sn-stone-gatherer-percentage 0)
	(set-strategic-number sn-cap-civilian-explorers 0)
	(set-strategic-number sn-percent-civilian-explorers 0) 
	(disable-self)
)

(defrule	
	(goal active-at-start no)
=>
	(set-strategic-number sn-defense-distance 20)
	(set-strategic-number sn-sentry-distance 20)
	(set-strategic-number sn-percent-enemy-sighted-response 100)
	(set-strategic-number sn-number-explore-groups 0)
	(set-strategic-number sn-percent-attack-soldiers 0)
	(set-strategic-number sn-task-ungrouped-soldiers 0)
	(set-strategic-number sn-number-attack-groups 0)
	(set-strategic-number sn-enemy-sighted-response-distance 10)
	(set-strategic-number sn-total-number-explorers 0)
	(set-strategic-number sn-minimum-town-size 0)
	(set-strategic-number sn-maximum-town-size 0)
	(disable-self)
)

;---Active Behaviour---
;when activated the AI will begin to play

(defrule
	(goal activate yes)
=>
	(set-strategic-number sn-percent-civilian-builders percentage-builders)
	(set-strategic-number sn-percent-civilian-gatherers percentage-gatherers)
	(set-strategic-number sn-percent-civilian-explorers 0)
	(set-strategic-number sn-number-explore-groups 1)
 	(set-strategic-number sn-total-number-explorers percentage-explorers)
	(set-strategic-number sn-food-gatherer-percentage food-gatherers)
	(set-strategic-number sn-wood-gatherer-percentage wood-gatherers)
	(set-strategic-number sn-gold-gatherer-percentage gold-gatherers)
	(set-strategic-number sn-stone-gatherer-percentage stone-gatherers)
	(disable-self)
)

(defrule
	(goal activate yes)
=>
	(set-strategic-number sn-maximum-hunt-drop-distance 30)
	(set-strategic-number sn-mill-max-distance 30)
	(set-strategic-number sn-maximum-gold-drop-distance 20)
	(set-strategic-number sn-maximum-stone-drop-distance 20)
	(set-strategic-number sn-maximum-food-drop-distance 10) 
	(set-strategic-number sn-maximum-wood-drop-distance 20)
	(set-strategic-number sn-task-ungrouped-soldiers task-soldiers)
	(disable-self)
)

;***AI Behaviour***
;-----Dodging rules-----
;ability of the AI to dodge enemy missiles shot at them and maintaining distance when engaging with enemies. The lower the number how better they are at it.

(defrule
	(difficulty == easiest)
=>
	(set-difficulty-parameter ability-to-maintain-distance 90)
	(set-difficulty-parameter ability-to-dodge-missiles 90)
	(disable-self)
)

(defrule
	(difficulty == easy)
=>
	(set-difficulty-parameter ability-to-maintain-distance 70)
	(set-difficulty-parameter ability-to-dodge-missiles 70)
	(disable-self)
)

(defrule
	(difficulty == moderate)
=>
	(set-difficulty-parameter ability-to-maintain-distance 50) 
	(set-difficulty-parameter ability-to-dodge-missiles 50)
	(disable-self)
)

(defrule
	(difficulty == hard)
=>
	(set-difficulty-parameter ability-to-maintain-distance 30) 
	(set-difficulty-parameter ability-to-dodge-missiles 30)
	(disable-self)
)

(defrule
	(difficulty == hardest)
=>
	(set-difficulty-parameter ability-to-maintain-distance 0) 
	(set-difficulty-parameter ability-to-dodge-missiles 0)
	(disable-self)
)

;***Production***
;---Homebase Stats---

(defrule
	(goal activate yes)
=>
	(set-strategic-number sn-maximum-town-size 15)
    (set-strategic-number sn-camp-max-distance 20)
   	(set-strategic-number sn-mill-max-distance 30)
	(set-strategic-number sn-percent-enemy-sighted-response 50)
	(set-strategic-number sn-enemy-sighted-response-distance 15)
	(set-strategic-number sn-blot-exploration-map 0)
	(set-strategic-number sn-sentry-distance 20)
	(disable-self)
)

;---Farming and Civilians---

(defrule
	(goal activate yes)
	(building-type-count-total farm less-than amount-farms)
	(or
	(building-type-count-total mill > 0)
	(building-type-count-total town-center > 0)
	)
	(idle-farm-count <= 1)
	(can-build farm)
=>
	(build farm)
)

(defrule
	(goal activate yes)
	(unit-type-count-total villager < amount-villagers)
	(can-train villager)
=>
	(train villager)
) 

(defrule
	(goal activate yes)
	(unit-type-count-total trade-cart < amount-traders)
	(can-train trade-cart)
=>
	(train trade-cart)
) 

(defrule
	(goal activate yes)
	(unit-type-count-total trade-cog < amount-sea-traders)
	(can-train trade-cog)
=>
	(train trade-cog)
) 

(defrule
	(goal activate yes)
	(unit-type-count-total fishing-ship < amount-fishing-ships)
	(dropsite-min-distance food < 20)
	(can-train fishing-ship)
=>
	(train fishing-ship)
) 

;---Economic Buildings---

(defrule
	(goal activate yes)
	(building-type-count-total town-center < amount-town-centers)
	(can-build town-center)
=>
	(build town-center)
) 

(defrule
	(goal activate yes)
	(housing-headroom less-than 4)
	(population-headroom greater-than 0)
	(can-build house)
	(goal build-houses 1)
=>
	(build house)
)

(defrule
	(goal activate yes)
	(resource-found wood)
	(dropsite-min-distance wood > 4)
	(building-type-count-total lumber-camp < amount-lumber-camps)
	(can-build lumber-camp)
=>
	(build lumber-camp)
) 

(defrule
	(goal activate yes)
	(building-type-count-total mill < amount-mills)
	(dropsite-min-distance food > 5)
	(can-build mill)
=>
	(build mill)
) 

(defrule
	(goal activate yes)
	(resource-found gold)
	(building-type-count-total mining-camp < amount-mining-camp-gold)
	(dropsite-min-distance gold > 5)
	(can-build mining-camp)
=>
	(build mining-camp)
) 

(defrule
	(goal activate yes)
	(resource-found stone)
	(building-type-count-total mining-camp < amount-mining-camp-stone)
	(dropsite-min-distance stone > 5)
	(can-build mining-camp)
=>
	(build mining-camp)
) 

;---Military and Research Buildings---

(defrule
	(goal activate yes)
	(building-type-count-total barracks < amount-barracks)
	(can-build barracks)
=>
	(build barracks)
) 

(defrule
	(goal activate yes)	
	(building-type-count-total archery-range < amount-archery-ranges)
	(can-build archery-range)
=>
	(build archery-range)
) 

(defrule
	(goal activate yes)
	(building-type-count-total stable < amount-stables)
	(can-build stable)
=>
	(build stable)
) 

(defrule
	(goal activate yes)
	(building-type-count-total siege-workshop < amount-siege-workshops)
	(can-build siege-workshop)
=>
	(build siege-workshop)
) 

(defrule
	(goal activate yes)
	(building-type-count-total dock < amount-docks)
	(can-build dock)
=>
	(build dock)
) 

(defrule
	(goal activate yes)
	(building-type-count-total university < amount-universities)
	(can-build university)
=>
	(build university)
) 

(defrule
	(goal activate yes)
	(building-type-count-total blacksmith < amount-blacksmiths)
	(can-build blacksmith)
=>
	(build blacksmith)
) 

(defrule
	(goal activate yes)
	(building-type-count-total market < amount-markets)
	(can-build market)
=>
	(build market)
) 

(defrule
	(goal activate yes)
	(building-type-count-total monastery < amount-monasteries)
	(can-build monastery)
=>
	(build monastery)
) 

(defrule
	(goal activate yes)
	(building-type-count-total castle < amount-castles)
	(can-build castle)
=>
	(build castle)
) 

(defrule
	(goal activate yes)
	(building-type-count-total watch-tower-line < amount-towers)
	(can-build watch-tower-line)
=>
	(build watch-tower-line)
) 

(defrule
	(goal activate yes)
	(building-type-count-total bombard-tower < amount-bombard-towers)
	(can-build bombard-tower)
=>
	(build bombard-tower)
) 

;***Assault rules***
;---Assault stats---

(defrule
	(goal activate yes)
=>
	(set-strategic-number sn-do-not-scale-for-difficulty-level no)
	(set-strategic-number sn-wall-targeting-mode yes)
	(disable-self)
)

;-----Offence-----
;activate the first attack (the amount of time for this is represented by 10)

(defrule
	(goal activate yes)
=>
	(enable-timer attack-timer 10)
	(set-goal attack-goal standby)
	(disable-self)
)

;first attack is activated and a new timer (amount of time being 0) is enabled to already activate the next attack later on

(defrule 
	(timer-triggered attack-timer)
	(goal attack-goal standby)
	(military-population >= 10)
	(defend-soldier-count >= 10)
	(not (town-under-attack))
=>
	(set-strategic-number sn-percent-enemy-sighted-response 60)
	(set-strategic-number sn-enemy-sighted-response-distance 40) 
	(set-goal attack-goal offence) 
	(disable-timer attack-timer) 
	(enable-timer attack-timer 0);Interval between attacks
)

;the ai stops his attacks and resets everything until the next wave
(defrule 
	;(goal attack-goal reset-attack) 
	(timer-triggered interval-timer)
=> 
	(disable-timer interval-timer) 
	(set-goal attack-goal standby)
) 

;the ai will keep his units at his base when on standby

(defrule 
	(goal attack-goal standby)
=> 
	(set-strategic-number sn-group-form-distance 25)
	(set-strategic-number sn-maximum-attack-group-size 0) 
	(set-strategic-number sn-minimum-attack-group-size 0) 
	(set-strategic-number sn-number-attack-groups 0)
	(set-strategic-number sn-number-boat-attack-groups 0)
	(set-strategic-number sn-minimum-boat-attack-group-size 0)
	(set-strategic-number sn-maximum-boat-attack-group-size 0)
	(disable-timer interval-timer) 
	(enable-timer interval-timer 10)
	;(set-goal attack-goal reset-attack)
)

;the ai gathers his troops and attacks the enemy with the amount stated below

(defrule 
	(goal attack-goal offence) ;Attacking - Groups
=> 
	(set-strategic-number sn-group-form-distance 5)
	(set-strategic-number sn-number-attack-groups 3)
	(set-strategic-number sn-maximum-attack-group-size 0) 
	(set-strategic-number sn-minimum-attack-group-size 0) 
	(set-strategic-number sn-number-boat-attack-groups 2)
	(set-strategic-number sn-minimum-boat-attack-group-size 0)
	(set-strategic-number sn-maximum-boat-attack-group-size 0)
	(set-goal attack-goal reset-attack)
)

;---Defence---
;Not implemented anymore


;***Production2***
;---Military---
;a scout unit for exploring

(defrule
	(goal activate yes)
	(unit-type-count-total scout-cavalry-line < 1)
	(can-train scout-cavalry-line)
=>
	(train scout-cavalry-line)
) 

;___EASIEST___

(defrule
	(goal activate yes)
	(unit-type-count-total unit1 < 1)
	(can-train unit1)
	(difficulty == easiest)
=>
	(train unit1)
)

(defrule
	(goal activate yes)
	(unit-type-count-total unit2 < 1)
	(can-train unit2)
	(difficulty == easiest)
=>
	(train unit2)
)

(defrule
	(goal activate yes)
	(unit-type-count-total unit3 < 1)
	(can-train unit3)
	(difficulty == easiest)
=>
	(train unit3)
)

(defrule
	(goal activate yes)
	(unit-type-count-total unit4 < 1)
	(can-train unit4)
	(difficulty == easiest)
=>
	(train unit4)
)

(defrule
	(goal activate yes)
	(unit-type-count-total unit5 < 1)
	(can-train unit5)
	(difficulty == easiest)
=>
	(train unit5)
)

(defrule
	(goal activate yes)
	(unit-type-count-total unit6 < 1)
	(can-train unit6)
	(difficulty == easiest)
=>
	(train unit6)
)

(defrule
	(goal activate yes)
	(unit-type-count-total unit7 < 2)
	(can-train unit7)
	(difficulty == easiest)
=>
	(train unit7)
)

(defrule
	(goal activate yes)
	(not (town-under-attack))
	(unit-type-count-total siege1 < 1)
	(can-train siege1)
	(difficulty == easiest)
=>
	(train siege1)
)

(defrule
	(goal activate yes)
	(not (town-under-attack))
	(unit-type-count-total siege2 < 0)
	(can-train siege2)
	(difficulty == easiest)
=>
	(train siege2)
)

(defrule
	(goal activate yes)
	(not (town-under-attack))
	(unit-type-count-total siege3 < 0)
	(can-train siege3)
	(difficulty == easiest)
=>
	(train siege3)
)

;___EASY___

(defrule
	(goal activate yes)
	(unit-type-count-total unit1 < 1)
	(can-train unit1)
	(difficulty == easy)
=>
	(train unit1)
)

(defrule
	(goal activate yes)
	(unit-type-count-total unit2 < 2)
	(can-train unit2)
	(difficulty == easy)
=>
	(train unit2)
)

(defrule
	(goal activate yes)
	(unit-type-count-total unit3 < 1)
	(can-train unit3)
	(difficulty == easy)
=>
	(train unit3)
)

(defrule
	(goal activate yes)
	(unit-type-count-total unit4 < 1)
	(can-train unit4)
	(difficulty == easy)
=>
	(train unit4)
)

(defrule
	(goal activate yes)
	(unit-type-count-total unit5 < 3)
	(can-train unit5)
	(difficulty == easy)
=>
	(train unit5)
)

(defrule
	(goal activate yes)
	(unit-type-count-total unit6 < 1)
	(can-train unit6)
	(difficulty == easy)
=>
	(train unit6)
)

(defrule
	(goal activate yes)
	(unit-type-count-total unit7 < 5)
	(can-train unit7)
	(difficulty == easy)
=>
	(train unit7)
)

(defrule
	(goal activate yes)
	(not (town-under-attack))
	(unit-type-count-total siege1 < 1)
	(can-train siege1)
	(difficulty == easy)
=>
	(train siege1)
)

(defrule
	(goal activate yes)
	(not (town-under-attack))
	(unit-type-count-total siege2 < 1)
	(can-train siege2)
	(difficulty == easy)
=>
	(train siege2)
)

(defrule
	(goal activate yes)
	(not (town-under-attack))
	(unit-type-count-total siege3 < 1)
	(can-train siege3)
	(difficulty == easy)
=>
	(train siege3)
)

;___MODERATE___

(defrule
	(goal activate yes)
	(unit-type-count-total unit1 < 2)
	(can-train unit1)
	(difficulty == moderate)
=>
	(train unit1)
)

(defrule
	(goal activate yes)
	(unit-type-count-total unit2 < 3)
	(can-train unit2)
	(difficulty == moderate)
=>
	(train unit2)
)

(defrule
	(goal activate yes)
	(unit-type-count-total unit3 < 2)
	(can-train unit3)
	(difficulty == moderate)
=>
	(train unit3)
)

(defrule
	(goal activate yes)
	(unit-type-count-total unit4 < 2)
	(can-train unit4)
	(difficulty == moderate)
=>
	(train unit4)
)

(defrule
	(goal activate yes)
	(unit-type-count-total unit5 < 4)
	(can-train unit5)
	(difficulty == moderate)
=>
	(train unit5)
)

(defrule
	(goal activate yes)
	(unit-type-count-total unit6 < 2)
	(can-train unit6)
	(difficulty == moderate)
=>
	(train unit6)
)

(defrule
	(goal activate yes)
	(unit-type-count-total unit7 < 7)
	(can-train unit7)
	(difficulty == moderate)
=>
	(train unit7)
)

(defrule
	(goal activate yes)
	(not (town-under-attack))
	(unit-type-count-total siege1 < 2)
	(can-train siege1)
	(difficulty == moderate)
=>
	(train siege1)
)

(defrule
	(goal activate yes)
	(not (town-under-attack))
	(unit-type-count-total siege2 < 1)
	(can-train siege2)
	(difficulty == moderate)
=>
	(train siege2)
)

(defrule
	(goal activate yes)
	(not (town-under-attack))
	(unit-type-count-total siege3 < 1)
	(can-train siege3)
	(difficulty == moderate)
=>
	(train siege3)
)

;___HARD___
(defrule

	(goal activate yes)
	(unit-type-count-total unit1 < 3)
	(can-train unit1)
	(difficulty == hard)
=>
	(train unit1)
)

(defrule
	(goal activate yes)
	(unit-type-count-total unit2 < 4)
	(can-train unit2)
	(difficulty == hard)
=>
	(train unit2)
)

(defrule
	(goal activate yes)
	(unit-type-count-total unit3 < 3)
	(can-train unit3)
	(difficulty == hard)
=>
	(train unit3)
)

(defrule
	(goal activate yes)
	(unit-type-count-total unit4 < 3)
	(can-train unit4)
	(difficulty == hard)
=>
	(train unit4)
)

(defrule
	(goal activate yes)
	(unit-type-count-total unit5 < 5)
	(can-train unit5)
	(difficulty == hard)
=>
	(train unit5)
)
(defrule
	(goal activate yes)
	(unit-type-count-total unit6 < 3)
	(can-train unit6)
	(difficulty == hard)
=>
	(train unit6)
)
(defrule
	(goal activate yes)
	(unit-type-count-total unit7 < 9)
	(can-train unit7)
	(difficulty == hard)
=>
	(train unit7)
)

(defrule
	(goal activate yes)
	(not (town-under-attack))
	(unit-type-count-total siege1 < 3)
	(can-train siege1)
	(difficulty == hard)
=>
	(train siege1)
)

(defrule
	(goal activate yes)
	(not (town-under-attack))
	(unit-type-count-total siege2 < 1)
	(can-train siege2)
	(difficulty == hard)
=>
	(train siege2)
)

(defrule
	(goal activate yes)
	(not (town-under-attack))
	(unit-type-count-total siege3 < 1)
	(can-train siege3)
	(difficulty == hard)
=>
	(train siege3)
)

;___HARDEST___

(defrule
	(goal activate yes)
	(unit-type-count-total unit1 < 3)
	(can-train unit1)
	(difficulty == hardest)
=>
	(train unit1)
)

(defrule
	(goal activate yes)
	(unit-type-count-total unit2 < 5)
	(can-train unit2)
	(difficulty == hardest)
=>
	(train unit2)
)

(defrule
	(goal activate yes)
	(unit-type-count-total unit3 < 3)
	(can-train unit3)
	(difficulty == hardest)
=>
	(train unit3)
)

(defrule
	(goal activate yes)
	(unit-type-count-total unit4 < 3)
	(can-train unit4)
	(difficulty == hardest)
=>
	(train unit4)
)

(defrule
	(goal activate yes)
	(unit-type-count-total unit5 < 7)
	(can-train unit5)
	(difficulty == hardest)
=>
	(train unit5)
)
(defrule
	(goal activate yes)
	(unit-type-count-total unit6 < 3)
	(can-train unit6)
	(difficulty == hardest)
=>
	(train unit6)
)
(defrule
	(goal activate yes)
	(unit-type-count-total unit7 < 12)
	(can-train unit7)
	(difficulty == hardest)
=>
	(train unit7)
)

(defrule
	(goal activate yes)
	(not (town-under-attack))
	(unit-type-count-total siege1 < 3)
	(can-train siege1)
	(difficulty == hardest)
=>
	(train siege1)
)

(defrule
	(goal activate yes)
	(not (town-under-attack))
	(unit-type-count-total siege2 < 2)
	(can-train siege2)
	(difficulty == hardest)
=>
	(train siege2)
)

(defrule
	(goal activate yes)
	(not (town-under-attack))
	(unit-type-count-total siege3 < 2)
	(can-train siege3)
	(difficulty == hardest)
=>
	(train siege3)
)

;---Naval---
;___EASIEST___

(defrule
	(goal activate yes)
	(difficulty == easiest)
	(unit-type-count-total naval1 < 1)
	(can-train naval1)
=>
	(train naval1)
) 

(defrule
	(goal activate yes)
	(difficulty == easiest)
	(unit-type-count-total naval2 < 0)
	(can-train naval2)
=>
	(train naval2)
) 

(defrule
	(goal activate yes)
	(difficulty == easiest)
	(unit-type-count-total naval3 < 2)
	(can-train naval3)
=>
	(train naval3)
) 

;___EASY___

(defrule
	(goal activate yes)
	(difficulty == easy)
	(unit-type-count-total naval1 < 1)
	(can-train naval1)
=>
	(train naval1)
) 

(defrule
	(goal activate yes)
	(difficulty == easy)
	(unit-type-count-total naval2 < 1)
	(can-train naval2)
=>
	(train naval2)
) 

(defrule
	(goal activate yes)
	(difficulty == easy)
	(unit-type-count-total naval3 < 3)
	(can-train naval3)
=>
	(train naval3)
) 

;___MODERATE___

(defrule
	(goal activate yes)
	(difficulty == moderate)
	(unit-type-count-total naval1 < 2)
	(can-train naval1)
=>
	(train naval1)
) 
(defrule
	(goal activate yes)
	(difficulty == moderate)
	(unit-type-count-total naval2 < 1)
	(can-train naval2)
=>
	(train naval2)
) 
(defrule
	(goal activate yes)
	(difficulty == moderate)
	(unit-type-count-total naval3 < 5)
	(can-train naval3)
=>
	(train naval3)
) 

;___HARD___

(defrule
	(goal activate yes)
	(difficulty == hard)
	(unit-type-count-total naval1 < 3)
	(can-train naval1)
=>
	(train naval1)
) 

(defrule
	(goal activate yes)
	(difficulty == hard)
	(unit-type-count-total naval2 < 1)
	(can-train naval2)
=>
	(train naval2)
) 

(defrule
	(goal activate yes)
	(difficulty == hard)
	(unit-type-count-total naval3 < 7)
	(can-train naval3)
=>
	(train naval3)
) 

;___HARDEST___

(defrule
	(goal activate yes)
	(difficulty == hardest)
	(unit-type-count-total naval1 < 3)
	(can-train naval1)
=>
	(train naval1)
) 

(defrule
	(goal activate yes)
	(difficulty == hardest)
	(unit-type-count-total naval2 < 2)
	(can-train naval2)
=>
	(train naval2)
) 

(defrule
	(goal activate yes)
	(difficulty == hardest)
	(unit-type-count-total naval3 < 8)
	(can-train naval3)
=>
	(train naval3)
) 

;***Market sales***

(defrule
	(goal activate yes)
	(gold-amount >= 1500)
	(wood-amount <= 200)
	(commodity-buying-price wood <= 150)
	(can-buy-commodity wood)
	(goal use-market 1)
=>
	(buy-commodity wood)
)

(defrule
	(goal activate yes)
	(gold-amount >= 1500)
	(food-amount <= 200)
	(commodity-buying-price food <= 150)
	(can-buy-commodity food)
	(goal use-market 1)
=>
	(buy-commodity food)
)

(defrule
	(goal activate yes)
	(gold-amount >= 500)
	(food-amount <= 100)
	(can-buy-commodity food)
	(goal use-market 1)
=>
	(buy-commodity food)
)

(defrule
	(goal activate yes)
	(gold-amount >= 2000)
	(stone-amount <= 500)
	(commodity-buying-price stone <= 100)
	(can-buy-commodity stone)
	(goal use-market 1)
=>
	(buy-commodity stone)
)

(defrule
	(goal activate yes)
	(gold-amount >= 1500)
	(stone-amount <= 200)
	(commodity-buying-price stone <= 200)
	(can-buy-commodity stone)
	(goal use-market 1)
=>
	(buy-commodity stone)
)

(defrule
	(goal activate yes)
	(wood-amount >= 2000)
	(or
		(gold-amount < 200)
		(food-amount < 200)
	)
	(can-sell-commodity wood)
	(goal use-market 1)
=>
	(sell-commodity wood)
)

(defrule
	(goal activate yes)
	(food-amount >= 2000)
	(or
		(gold-amount < 200)
		(wood-amount < 200)
	)
	(can-sell-commodity food)
	(goal use-market 1)
=>
	(sell-commodity food)
)

(defrule
	(goal activate yes)
	(stone-amount >= 1500)
	(or
		(or
			(gold-amount < 200)
			(wood-amount < 200)
		)
		(food-amount < 200)
	)
	(commodity-selling-price stone >= 70)
	(can-sell-commodity stone)
	(goal use-market 1)
=>
	(sell-commodity stone)
)

;***Resigning***

(defrule
	(goal activate yes)
	(building-type-count town-center < 1)
   	(building-type-count castle < 1)
	(military-population <= 5)
	(goal default-resign 1)
=>
	(set-goal 1 19)
	(disable-self)
)

;***Cheats***

(defrule
	(goal activate yes)
	(goal allow-cheats 1)
=>
	(enable-timer 1 0)
	(disable-self)
)

(defrule
	(timer-triggered 1)
	(or
	(difficulty == easiest)
	(difficulty == easy)
	)
=>
	(cc-add-resource food 0)
	(cc-add-resource wood 0)
	(cc-add-resource gold 0)
	(cc-add-resource stone 0)
	(disable-timer 1)
	(enable-timer 1 0)
)

(defrule
	(timer-triggered 1)
	(difficulty == moderate)
=>
	(cc-add-resource food 0)
	(cc-add-resource wood 0)
	(cc-add-resource gold 0)
	(cc-add-resource stone 0)
	(disable-timer 1)
	(enable-timer 1 0)
)

(defrule
	(timer-triggered 1)
	(or
	(difficulty == hard)
	(difficulty == hardest)
	)
=>
	(cc-add-resource food 0)
	(cc-add-resource wood 0)
	(cc-add-resource gold 0)
	(cc-add-resource stone 0)
	(disable-timer 1)
	(enable-timer 1 0)
)


builder market.per

Code: Select all

;Scenario market
;sells and buys but does not advance

; ///////////////////////// FEUDAL

(defrule
	(current-age == feudal-age)
	(gold-amount >= 500)
	(wood-amount <= 100)
	(commodity-buying-price wood <= 100)
	(can-buy-commodity wood)
=>
	(chat-local-to-self "Wood panic")
	(buy-commodity wood)
)

(defrule
	(current-age == feudal-age)
	(gold-amount >= 500)
	(food-amount <= 100)
	(commodity-buying-price food <= 100)
	(can-buy-commodity food)
=>
	(chat-local-to-self "Food panic")
	(buy-commodity food)
)

(defrule
	(current-age == feudal-age)
	(gold-amount >= 600)
	(stone-amount <= 100)
	(commodity-buying-price stone <= 200)
	(can-buy-commodity stone)
=>
	(chat-local-to-self "need stone")
	(buy-commodity stone)
)

(defrule
	(current-age == feudal-age)
	(wood-amount >= 500)
	(or
		(gold-amount < 100)
		(food-amount < 100)
	)
	(commodity-selling-price wood >= 50)
	(can-sell-commodity wood)
=>
	(chat-local-to-self "Gold panic; sell wood")
	(sell-commodity wood)
)

(defrule
	(current-age == feudal-age)
	(food-amount >= 1000)
	(or
		(gold-amount < 100)
		(wood-amount < 100)
	)
	(can-sell-commodity food)
=>
	(chat-local-to-self "excess food")
	(sell-commodity food)
)

(defrule
	(current-age == feudal-age)
	(stone-amount >= 1000)
	(or
		(gold-amount < 100)
		(wood-amount < 100)
	)
	(can-sell-commodity stone)
=>
	(chat-local-to-self "excess stone")
	(sell-commodity stone)
)

;****************************CASTLE
(defrule
	(current-age == castle-age)
	(gold-amount >= 1000)
	(wood-amount <= 200)
	(commodity-buying-price wood <= 100)
	(can-buy-commodity wood)
=>
	(chat-local-to-self "Wood panic")
	(buy-commodity wood)
)

(defrule
	(current-age == castle-age)
	(gold-amount >= 500)
	(wood-amount <= 100)
	(can-buy-commodity wood)
=>
	(chat-local-to-self "Wood panic")
	(buy-commodity wood)
)

(defrule
	(current-age == castle-age)
	(gold-amount >= 1000)
	(food-amount <= 200)
	(commodity-buying-price food <= 100)
	(can-buy-commodity food)
=>
	(chat-local-to-self "Food panic")
	(buy-commodity food)
)

(defrule
	(current-age == castle-age)
	(gold-amount >= 500)
	(food-amount <= 100)
	(can-buy-commodity food)
=>
	(chat-local-to-self "Food panic")
	(buy-commodity food)
)

(defrule
	(current-age == castle-age)
	(gold-amount >= 1200)
	(stone-amount <= 200)
	(commodity-buying-price stone <= 200)
	(can-buy-commodity stone)
=>
	(chat-local-to-self "need stone")
	(buy-commodity stone)
)

(defrule
	(current-age == castle-age)
	(wood-amount >= 1000)
	(or
		(gold-amount < 200)
		(food-amount < 200)
	)
	(commodity-selling-price wood >= 25)
	(can-sell-commodity wood)
=>
	(chat-local-to-self "Gold panic; sell wood")
	(sell-commodity wood)
)

(defrule
	(current-age == castle-age)
	(food-amount >= 1200)
	(or
		(gold-amount < 200)
		(wood-amount < 200)
	)
	(can-sell-commodity food)
=>
	(chat-local-to-self "excess food")
	(sell-commodity food)
)

(defrule
	(current-age == castle-age)
	(stone-amount >= 1000)
	(or
		(gold-amount < 200)
		(wood-amount < 200)
	)
	(can-sell-commodity stone)
=>
	(chat-local-to-self "excess stone")
	(sell-commodity stone)
)


;****************************
;imperial age

(defrule
	(gold-amount >= 1500)
	(wood-amount <= 200)
	(can-buy-commodity wood)
=>
	(chat-local-to-self "Wood panic")
	(buy-commodity wood)
)

(defrule
	(gold-amount >= 1500)
	(food-amount <= 200)
	(can-buy-commodity food)
=>
	(chat-local-to-self "Food panic")
	(buy-commodity food)
)

(defrule
	(gold-amount >= 1500)
	(stone-amount <= 200)
	(can-buy-commodity stone)
=>
	(chat-local-to-self "need stone")
	(buy-commodity stone)
)

(defrule
	(wood-amount >= 1500)
	(or
		(gold-amount < 200)
		(food-amount < 200)
	)
	(can-sell-commodity wood)
=>
	(chat-local-to-self "Gold panic; sell wood")
	(sell-commodity wood)
)

(defrule
	(food-amount >= 1500)
	(or
		(gold-amount < 200)
		(wood-amount < 200)
	)
	(can-sell-commodity food)
=>
	(chat-local-to-self "excess food")
	(sell-commodity food)
)

(defrule
	(stone-amount >= 1500)
	(or
		(or
			(gold-amount < 200)
			(wood-amount < 200)
		)
		(food-amount < 200)
	)
	(can-sell-commodity stone)
=>
	(chat-local-to-self "excess stone")
	(sell-commodity stone)
)

"you don't have to be great to start, but you have to start to be great" -the villager

Post Reply