Siege-Simulating Scenario (Probability, "Messenger" AI)

The place to post your WML questions and answers.

Moderators: Forum Moderators, Developers

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Post Reply
User avatar
CalculusKing
Posts: 42
Joined: April 5th, 2016, 9:20 am

Siege-Simulating Scenario (Probability, "Messenger" AI)

Post by CalculusKing » July 14th, 2018, 11:56 pm

I'm working on Scenario 8 of my campaign, The Young Khan, and it is supposed to be a very unique scenario where the goal is to cut off an enemy city from supply and siege it down. This requires some pretty advanced mechanics, and while I have a basic understanding of programming (in Java and Python, if it matters) I would like a little help picking the specific means by which I might create the following mechanics:

Background:
- The city is Westin c. 673 YW, massively enlarged from the time of Deoran.
- Westin can be approached from the north, west, or east by river.
- Westin can be approached from the northwest, north, northeast, or south by road.
- The player's army (comprised mostly of Dunefolk) starts in the south.
- Westin is impregnable: impassable terrain (deep water, gatehouses made of rusty gates and stone walls) prevents entry into the city.
- Small enemy detachments (separate sides with leaders) guard a few key points around the city.
- The plan is for the scenario to last a week in story time, so either it needs to be 42 turns or it needs a custom schedule.

(X can refer to any probability, and "probability X" in one entry is not necessarily equal to "probability X" in another entry)
1. Every turn, with probability X, a cart will spawn with a couple guards at a road in the north and head for the northern gate.
2. Like 1, but with the northwestern road and western gate.
3. Like 1, but with the northeastern road and northeastern gate.
4. Every turn, with probability X, a ship will spawn in the west and head for the city.
5. Like 4, but the ship spawns in the east.
6. Like 4, but the ship spawns in the north.
7. With probability X, a band of troops spawns in the southwest. The troops will be randomly chosen to be one of several squad types (such as a sergeant leading a few spearmen and bowmen, a dragoon leading a couple cavalry, a lancer or knight leading a couple horsemen, etc...). The probability of each squad type's selection is not necessarily equal.
8. Like 7, but with possibly a different distribution of possible squads, and in the northeast.

9. All randomly spawned enemy troops/transports/carts head for the city, and despawn upon reaching its walls. The main enemy gets the recruit cost of each unit that reaches its walls except for transports or carts, which give it larger amounts of gold.
10. Each transport/cart spawn can be disabled by keeping troops in the correct hexes (which are given objective markers).
11. The main enemy loses a fixed amount of gold each turn (he may neither recruit units nor recall units nor move his starting units)
12. Once the main enemy's gold goes to zero, the human player wins.
13. If the player cuts off all supply routes to the city, the main enemy will randomly spawn sorties of troops from the city along the river (they are transported in boats). Each unit killed has its recruitment price charged to the main enemy. The sorties continue until either the enemy receives another supply transport/cart (that is, the player is forced off of objective hexes and a transport or cart spawns randomly and makes its way to the city) or the main enemy runs out of gold.

Thank you for reading to the end of this post. And thanks in advance to anyone who can offer advice. The map for the scenario is attached below.
Attachments
08_Taking_Westin.map
(9.25 KiB) Downloaded 25 times

User avatar
Ravana
Moderator
Posts: 1828
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Siege-Simulating Scenario (Probability, "Messenger" AI)

Post by Ravana » July 15th, 2018, 12:06 am

It seems complicated enough that I suggest doing that logic in Lua.

User avatar
CalculusKing
Posts: 42
Joined: April 5th, 2016, 9:20 am

Re: Siege-Simulating Scenario (Probability, "Messenger" AI)

Post by CalculusKing » July 15th, 2018, 5:33 am

Thanks again for the advice, Ravana. I should note that before reading your suggestion (but after posting) I managed to get a feasible conditional execution model underway in WML. It uses 15 variables. I'd like your input on this model:
- eight rand vars (initialized to '0', rolled on '1..100' for events)
- six deterministic integer vars (valued '0' or '1') which remember whether the corresponding routes are blocked
- one last deterministic integer var (valued '0' or '1') which remembers whether the enemy has started to sortie from the city to break the blockade

- the enemy gets a negative income (income can be negative, right?)

- most stuff is handled in a single event which fires at the start of every new turn
- the stuff below is to be accomplished with if-then-else and if-then-elseif-then... statements
- first, the victory condition (enemy has gold =<0) is checked for. If so, then the victory dialogue runs and the scenario ends in victory.
- if victory is not attained, it then sets each of the "supply route blocked" variables to 1 (if the supply route in question is blocked) or 0 (otherwise)
- each supply route, if not blocked, has its corresponding die rolled. If the roll falls within the right range, a caravan (if land) or transport (if water) is spawned.
- each reinforcement route (two of them, and neither can be blocked) has its corresponding die rolled. The computer consults a table (represented as a nest of conditional execution statements) that determines whether a squad is deployed, and, if so, what type of squad is deployed.
- if all supply routes are blocked, the 'sortie' variable is set to 1

- at the end of the player turn, if the enemy 'sortie' variable is activated, the following happens:
- an animation plays, sending a fake ship to a location on the river.
- a ship unit is created at the destination
- several enemy units spawn near the ship
- a variable is set representing the total gold value of the sortie
- a variable is set representing the total losses of the sortie

- die event for side-2 units is described below (all side 2 units which the player fights are sorties)
- if half or more of the gold value of the sortie is lost:
------- if the ship is not destroyed, the survivors disappear into the ship and the ship heads back home before disappearing (move_unit statements and kill statements (die events are not triggered, of course))
------- if the ship is destroyed, the enemy units fight to the death
- the gold value of the destroyed unit is removed from the enemy treasury (thus hastening the player's victory)

- moveto event player 6, 7 units (fleeing troops and civilian supply units)
- if an enemy of side 6 or 7 reaches the gate, wall, or docks of the fort, it despawns
- if it is any unit except a transport or cart, its gold value is added to the enemy gold
- if it is a transport or cart, a larger amount is added
- if the AI needs to be tweaked because of the loss of a protected unit, it will be done here

- so I think I'll have that taken care of. Anyone have a good explainer on "messenger" AI they can link to? I need to have entire squads of units seek escape. That means that even if the protected unit escapes, the others must try to do the same.

mattsc
Posts: 1062
Joined: October 13th, 2010, 6:14 pm
Location: Wandering, mostly aimlessly

Re: Siege-Simulating Scenario (Probability, "Messenger" AI)

Post by mattsc » July 15th, 2018, 11:55 pm

I probably should not reply to this without having read (and thought about) the entire thread, but it's either that or not reply at all for ... several days, probably. So, I apologize if I missed something and am just taking the following in isolation:
CalculusKing wrote:
July 15th, 2018, 5:33 am
- so I think I'll have that taken care of. Anyone have a good explainer on "messenger" AI they can link to? I need to have entire squads of units seek escape. That means that even if the protected unit escapes, the others must try to do the same.
The best existing description is that on the Micro AI wiki page. It says there that "if a messenger dies, the escort units previously staying with it now join one of the other messengers if there are any left (otherwise they follow default AI behavior)." Moving the unit(s) off the map is the same as dying, as far as the AI is concerned. So that means that what you want is not possible with the Messenger MAI.

You can use the Goto Micro AI instead. Depending on what exactly you want, I can think of three different ways:
  • Use the Goto MAI in the first place for all units, including the "messenger". That won't make the other units protect the messenger though.
  • Add the Goto MAI for the other units in an event once the messenger escapes.
  • Add the Goto MAI from the beginning with a ca_score value that's lower than that of the Messenger MAI, so that it only takes effect once the Messenger MAI is not active any more (i.e. once the messenger has escaped).
Hope that helps.

User avatar
CalculusKing
Posts: 42
Joined: April 5th, 2016, 9:20 am

Re: Siege-Simulating Scenario (Probability, "Messenger" AI)

Post by CalculusKing » July 16th, 2018, 4:43 am

Thank you. This is exactly what I needed. I've been putting together a macro with "messenger" AI, but I can replace it with the micro AI you suggested and it will actually simplify my task considerably.

[micro_ai]
action=add
side=6
ai_type=goto
[filter_location]
x="11,12,13,14,15,16,17,18,19,20,21,22,23,24"
y="9-16,8-16,8-17,7-17,7-18,6-18,7-19,7-19,8-20,8-19,9-19,9-14,11-14,11-13"
[/filter_location]
[/micro_ai]
[micro_ai]
action=add
side=7
ai_type=goto
[filter_location]
x,y=29,18
[/filter_location]
[/micro_ai]

Side 6 will now handle all units except the eastern water spawn (goal is to be next to the city walls/docks).
Side 7 will handle the eastern water spawn (goal is to reach the water tile next to a bridge).
Edit: cant make it indent properly

Post Reply