Trying to Program Campaign A.I. Gatherers

I’m trying to program the scripts for some computer factions for my upcoming campaign, but I have a couple of major issues that both have to do with gatherers.

  1. I can’t get anybody to build new Lumber or Mining Camps when they find new resources, so they always end up walking absurd distances later in the game to gather resources. The resource-found wood/gold/stone thing doesn’t work for me, and tinkering with the min/max dropoff distances had no effect.

  2. One of the factions is supposed to exclusively focus on gathering food and wood, but after exhausting enough farms, they keep trying to switch to gold or stone if they can find it. This is extremely annoying because even if I set the percentage of stone and gold gathers to 0, they still end up switching to gold at some point and abandon the farms they’re supposed to rebuild, leaving ugly patches of dirt 2 behind and preventing them from tributing the appropriate resources throughout the remainder of the mission.

Did you set the drop distances to zero? This is how it should look:
(set-strategic-number sn-maximum-gold-drop-distance 0)
(set-strategic-number sn-maximum-stone-drop-distance 0)

It would be a little easier to see what was going wrong if you could share the script.

I never added those particular lines for the non-gold miners, so maybe that’s the issue. I’ll let you know what happens.

I do still feel concerned about the factions that are supposed to build new camps but don’t.

I’ll post part of the script if things still aren’t working right, too.

Okay, here are some excerpts from the faction that won’t build extra resource camps as I want:

(defrule	
	(true)
=>
    (set-strategic-number sn-maximum-town-size 35)
    (set-strategic-number sn-camp-max-distance 35)
    (set-strategic-number sn-mill-max-distance 35)
    (set-strategic-number sn-wall-targeting-mode 1)
    (set-strategic-number sn-percent-civilian-builders 15)
    (set-strategic-number sn-percent-civilian-gatherers 85)

	(set-strategic-number sn-number-explore-groups 1)
 	(set-strategic-number sn-total-number-explorers 1)

	(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-enemy-sighted-response-distance 15)
	(set-strategic-number sn-sentry-distance 15)
	(disable-self)
)

; Wood

(defrule
    (resource-found wood)
    (dropsite-min-distance wood > 5)
    (building-type-count-total lumber-camp < 3)
    (can-build lumber-camp)
=>
    (build lumber-camp)
)

; Gold

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

; Villager Designation

(defrule
    (true)
=>
    (set-strategic-number sn-food-gatherer-percentage 50)
    (set-strategic-number sn-wood-gatherer-percentage 25)
    (set-strategic-number sn-gold-gatherer-percentage 25)
    (set-strategic-number sn-maximum-food-drop-distance 5)
    (set-strategic-number sn-maximum-wood-drop-distance 12)
    (set-strategic-number sn-maximum-gold-drop-distance 8)
    (enable-timer 5 2700)
)

Now, for the faction that’s supposed to just send villagers to farms and wood but keeps disobeying the resource ratios I program:

(defrule	
	(true)
=>
    (set-strategic-number sn-maximum-town-size 80)
    (set-strategic-number sn-mill-max-distance 15)
    (set-strategic-number sn-percent-civilian-gatherers 100)
    (set-strategic-number sn-number-explore-groups 0)
 	(set-strategic-number sn-total-number-explorers 0)
)
; Villager Designation

(defrule
    (true)
=>
    (set-strategic-number sn-food-gatherer-percentage 71)
    (set-strategic-number sn-wood-gatherer-percentage 29)
    (set-strategic-number sn-maximum-food-drop-distance 5)
    (set-strategic-number sn-maximum-wood-drop-distance 8)
)

; Farm Maintenance

(defrule
    (idle-farm-count <= 1)
    (building-type-count-total farm less-than 50)
    (can-build farm)
=>
    (build farm)
)

; Tributes

(defrule
    (true)
=>
    (enable-timer 1 150)
    (enable-timer 2 150)
    (enable-timer 5 1800)
    (disable-self)
)

; Food Tributes
(defrule
    (timer-triggered 1)
    (not (event-detected trigger 22))
=>
    (tribute-to-player 2 food 1000)
    (tribute-to-player 3 food 1000)
    (disable-timer 1)
    (enable-timer 1 180)
)

; Wood Tributes
(defrule
    (timer-triggered 2)
    (not (event-detected trigger 21))
=>
    (tribute-to-player 3 wood 800)
    (tribute-to-player 2 wood 800)
    (disable-timer 2)
    (enable-timer 2 180)
)

; Extra Resources

(defrule
    (timer-triggered 5)
=>
    (cc-add-resource food 1000)
    (disable-timer 5)
    (enable-timer 5 300)
)

this value seems way too high. I think that could cause some of your issues.

Make those at least 20

I made it high because the player uses several mills and I wanted to make sure all of them were being used.

Does that cause the villagers to look farther for a suitable place to build a new resource camp? I thought it simply made them willing to walk farther from a camp they’ve already built.

I just increased the food drop distance and now those villagers are absolutely obsessed with gathering fish. I don’t want to get rid of all the fish on the map, but they keep walking too close to the base and the player’s towers keep whittling them down.

Hm, it’s hard to figure things out without having the entire script. If you like, you can turn over the file to me in a PM and I will have a closer look.

Hello Bassi! Sorry to contact you via replying to an (not directly) related thread, but I cannot seem to have found the option to PM people on this forum for some reasons.

I am Manu La Capuche, a fellow scenario designer, I’ve trying to figure out how to make scripted AIs create “editor-only units” via scripts since months, and I realized you managed to pull that off in the last scenario of the Burgundian campaign, where Compiègne actually creates Heavy Crossbowmen.

Now I am guessing this is done by typing the unit’s unique ID (several digits) as of the unit name in the code line, but I failed to figure all of these units digits. I also cannot extract the AIs at the moment from the last official campaigns for some reasons, so I cannot check out by myself.

Would you be able to tell me more about this?

Thanks for reading and your time, love your work! Cheers!

Hello Manu,

you are right, the units’ IDs are used in the scripts:

For the Heavy Crossbowman that is used in the Burgundy campaign, it looks like this in the script:

;UU 2
(defrule
(unit-type-count-total 493 less-than 15)
(can-train 493)
=>
(train 493)
)

493 is the ID of the Heavy Crossbowman. What you have to do to make this work is enabling the unit for the respective player in the editor. You have to use triggers for that. There is an effect (Enable Object) for that. In some cases you need to change the traning location as well, there is another effect for that.

Thank you for the quick response!

I figured this and managed it with the ID for the Genitours. And I am very used to all triggers including enabling objects, or training locations! For all others ‘editor’ units, I used to loop a Replace Unit trigger on a trainable unit, but this would reset the AI’s training amount each time, not ideal!

My main remaining questions would be where can you find each unit’s ID?

Thanks again for replying!

I just found out how to do it! So you answered all my questions!

Thank you again for your time, cheers!

Manu

Hi bassi,greeting,how can gpv be serperated into aoe2scenarioes?Or the official locked it to prevent the players from looking on it?How can custom campaign I made save it as aoe2campaign.gpv?Looking forward to your reply.