Author Topic: [Kit] Campaign AI Fixes and Tweaks  (Read 13924 times)

0 Members and 1 Guest are viewing this topic.

motomataru

  • External Developer
  • *
  • Battles are best won before the fighting begins.
    • Skype - motomataru
    • Steam - motomataru
    • YouTube - motomataru
    • View Profile
  • Faction: Rhodok
  • MP nick: Motobert
  • M&BWBVC
[Kit] Campaign AI Fixes and Tweaks
« on: September 19, 2012, 03:37:59 PM »
I didn't think there'd be much discussion for my Campaign AI mod, but since there is some...

This thread is in support of the Campaign AI mod here:

http://mountandblade.nexusmods.com/mods/3614
http://mountandblade.nexusmods.com/mods/2475 (playable Native demo)

The Campaign AI mod restores campaign level activity and lord missions to those seen in early versions of Warband. The campaign map is much livelier.

Following is a summary of the changes:

General fixes
1. Put more party actions into play.
2. Don't restrict parties to castle on a 30% basis (for an army of ideal size 300, this can be quite a large party).
3. To balance #1, reduce amount of village raiding, in part by removing that as faction objective.
4. Resolve confusion between party size and party strength (size generally 1/20 of strength).
5. Resolve confusion between the scale of the two distance functions (one is 1/100 of other).
6. Avoid setting invalid AI objectives.
7. Prevent marshal from gathering troops at previous enemy objective.
8. Prevent marshal from getting stranded during operations.
9. Handle spai_screening_party better as a substate of spai_accompanying_army.
10. Apply lord personalities to process_hero_ai as well as party_set_ai_state.

Problem: Lords ignore each other
1. Tweak aggressiveness setting, updating.
2. Fix marshal’s screening party (now averages 150 troops, large enough to face enemies).
3. Have screening party for marshal at all times, not just after an offensive starts.
3. Have marshal’s followers get aggressive close to objective.
4a. Cause two nearby enemy marshals to attack rather than just pass by.
4b. Make parties aggressive when their commander joins battle.

Problem: Factions ignore trouble at home
1. Fix parties will reinforce their weak centers (if fall below 100 troops – not below 7).
2. Faction AI more dynamic (will get more defensive as it gets smaller, damaged).
3. Defend even if have more desirable attack if not going to attack anyway.
4. Generalize marshal emergency behavior.
5. Have faction defend even without a marshal.
6. Attack village raiders as well as town besiegers.
7. Generalize defensive behavior of attacking armies (instead of just patrolling the center being attacked).
8. Have patrolling armies stick close to the center they are patrolling.

Problem: Small marshals run away from objectives
1. Allow weak parties to recruit before other actions.
2. Put in low-priority recruit option for all parties (not just weak ones).
3. Weak marshals levy troops from over-defended centers (leaving garrisons of 100-700).
4. Add party size component to voting decisions (weight about 50% of renown).
5. Weak marshals lose renown (thereby leading to lower size expectations & better marshals elected).

« Last Edit: September 19, 2012, 03:40:01 PM by motomataru »


Efe Karacar

  • Duke
  • *
  • aka Belendor
    • Steam - Belendor
    • Twitch.tv - Belendorr
    • YouTube - Belendor
    • View Profile
    • Art of Efe Karacar
  • Faction: Swadian
  • MP nick: Belendor
  • WBWF&SNWVCM&B
Re: [Kit] Campaign AI Fixes and Tweaks
« Reply #1 on: September 19, 2012, 03:45:22 PM »
Sweet, is it possible to make so factions fight with each other often, or in other term, launch crusades more often?

motomataru

  • External Developer
  • *
  • Battles are best won before the fighting begins.
    • Skype - motomataru
    • Steam - motomataru
    • YouTube - motomataru
    • View Profile
  • Faction: Rhodok
  • MP nick: Motobert
  • M&BWBVC
Re: [Kit] Campaign AI Fixes and Tweaks
« Reply #2 on: September 19, 2012, 03:47:32 PM »
I think that's true, but remember that periodically the party leader changes his mission. It's either a standard trigger or fires whenever a diplomatic relation between factions changes. I'd have to look it up again. The list of options makes strict priorities. Since I moved recruitment for underpowered parties high in the list (to give underpowered marshals a chance to bulk up), you'll often see lords jet out of feasts to pick up taxes/recruits, and sometimes you'll even see them return to the feast.

I suppose it would be easy enough to add a condition that lords of particular psyche would NOT recruit during a feast.

Thanks for both answers. So, lower initiative point will make the party's leader has more chance to continue his objective without changing his mind in the middle, won't it?

I ask it, because after I implement Moto's tweak, my tournaments attract fewer heroes to join than before. They just come back to their centers in the way to tournament's town because a treat on their villages. I like it, it's more realistic, but I want some bad heroes will neglect the villagers life to look after the glory of tournament.


motomataru

  • External Developer
  • *
  • Battles are best won before the fighting begins.
    • Skype - motomataru
    • Steam - motomataru
    • YouTube - motomataru
    • View Profile
  • Faction: Rhodok
  • MP nick: Motobert
  • M&BWBVC
Re: [Kit] Campaign AI Fixes and Tweaks
« Reply #3 on: September 19, 2012, 03:59:57 PM »
Actually, faction AI is quite a separate matter. I in fact DID overhaul it for Brytenwalda, but because Diplomacy's stuff was mixed in, I didn't make a mod of it. Some of the things I did was:

- restrict diplomacy to next-of-neighbor. Brytenwalda has 32 factions. It made no sense for Kent to suddenly decide to invade Munster six factions distant. M&B having only a handful of neighboring factions never had to develop such a mechanism.

- cultural antipathies. A big part of the Brytenwalda story is the clash of nationalities and/or religions, so I put in some biases there. Fanatically Christian Kent won't always attack fanactically pagan Mierce, but it's more likely to consider it.

One diplomatic thing IS in Campaign AI simply because it was easier to deal with it there. Campaign AI restricts objectives to the nearest walled center (no more attacking the empire next door from its far end!), but I added former or original centers to consideration. So in my Vaegir role in the Native application, for example, there was typically a back and forth with the Nords for Auburq, Jeribe, and the other border walled centers.

Sweet, is it possible to make so factions fight with each other often, or in other term, launch crusades more often?


Swyter

  • Grandmaster Knight
  • *
  • »Star Wars Conquest Dev Team Leader
    • View Profile
    • [my tiny homepage]
  • Faction: Swadian
  • MP nick: Sareth | Swyter
  • WBM&BWF&S
Re: [Kit] Campaign AI Fixes and Tweaks
« Reply #4 on: September 19, 2012, 04:17:31 PM »
You are great, mate. The best one of the rare breed of AI coders over here.
If we don't give you much talk is because of the complexity and fine tuning of triggers that turns all this thing into black magic.

We all value and admire you work, don't even doubt about it. :)

Star Wars Conquest wouldn't be as half as fun as it is right now thanks to your scripts.
I haven't forgotten about when the combat consisted in massive brawls of guys wielding pipes, batons and stuff.


I've been starting to introduce myself in AI programming for creating the behaviours of some special units in the map lately.
For example, rare independent ore miners that wander around the asteroids from time to time, neutrals that avoid conflicts.

Random clone remnants in the less populated areas in the galaxy. And is fun once you get it, but extremely time consuming to tweak.
So much to take account of too, as you can't predict the player.

Efe Karacar

  • Duke
  • *
  • aka Belendor
    • Steam - Belendor
    • Twitch.tv - Belendorr
    • YouTube - Belendor
    • View Profile
    • Art of Efe Karacar
  • Faction: Swadian
  • MP nick: Belendor
  • WBWF&SNWVCM&B
Re: [Kit] Campaign AI Fixes and Tweaks
« Reply #5 on: September 19, 2012, 04:27:07 PM »
It is sad there is almost noone who took care of the "mission" AI. Bots are still noob-ass.

Is there anyway to disable the default AI, and apply your own methods? Either in Mission or on World?

dunde

  • Count
  • *
  • Curious Coder of The Vision
    • View Profile
  • Faction: Swadian
  • WB
Re: [Kit] Campaign AI Fixes and Tweaks
« Reply #6 on: September 19, 2012, 04:31:11 PM »
Thanks again for sharing this code, motomataru.  I learn much from it. I like you create this threat so I won't spam the formation thread with questions about this code, later.

I think that's true, but remember that periodically the party leader changes his mission. It's either a standard trigger or fires whenever a diplomatic relation between factions changes. I'd have to look it up again. The list of options makes strict priorities. Since I moved recruitment for underpowered parties high in the list (to give underpowered marshals a chance to bulk up), you'll often see lords jet out of feasts to pick up taxes/recruits, and sometimes you'll even see them return to the feast.

I suppose it would be easy enough to add a condition that lords of particular psyche would NOT recruit during a feast.
I haven't tested long enough to experience the lords leave the feast and come back again. On my mods, he can't leave the town if he still compete on the feast tournament. Leaving the town earlier, and he will be disqualified from the tournament if he miss his fight schedule.
I added 'stay at tournament' at script_npc_decision_checklist_party_ai before. I added under
(eq, ":do_only_collecting_rents", 0), along with native's list like hosting feast, etc before. As you deprecated this check, I move it on else_try before #following player order. It will keep the lord stay at the tournament town as long he still compete in. May be I will add some check according to lord personalities to give some condition that push him forgetting his tournament fight and do something else mor urgent.
Code: [Select]
       # MOTO end move functionality to party_set_ai_state to generalize
        (assign, ":action", spai_patrolling_around_center),               
        (assign, ":object", ":faction_object"),
        (try_begin),
          (eq, ":troop_no", "$g_talk_troop"),
          (str_store_string, s14, "str_as_the_marshall_i_am_leading_our_forces_in_search_of_the_enemy"),
          (str_store_string, s16, "str_i_intend_to_lead_our_forces_out_to_find_the_enemy"),
        (try_end),
      # (try_end), MOTO move functionality to party_set_ai_state to generalize
     
    (else_try),
      (faction_slot_eq, ":faction_no", slot_faction_marshall, ":troop_no"),
      (faction_slot_eq, ":faction_no", slot_faction_ai_state, sfai_attacking_enemy_army),
      (faction_get_slot, ":faction_object", ":faction_no", slot_faction_ai_object),
      (party_is_active, ":faction_object"),
     
      (assign, ":action", spai_engaging_army),
      (assign, ":object", ":faction_object"),
      (try_begin),
        (eq, ":troop_no", "$g_talk_troop"),
        (str_store_string, s14, "str_as_the_marshall_i_am_leading_our_forces_to_engage_the_enemy_in_battle"),
        (str_store_string, s16, "str_i_intend_to_lead_our_forces_out_to_engage_the_enemy"),
      (try_end),
 
  # Dunde's Tournament BEGIN
  #In a Town for a Tournament and still in competition
  (else_try),   
    (is_between, ":cur_center_no", towns_begin, towns_end),
    (eq, ":cur_center_no", "$g_tournament_town"),
    (troop_get_slot, ":current_tier", tournament_data, slot_tournament_tier_pointer),
    (troop_slot_ge, ":troop_no", slot_troop_tour_seed, ":current_tier"),
    (troop_slot_eq, ":troop_no", slot_troop_tour_withdrawn, 0),
    (assign, ":action", spai_holding_center),
    (assign, ":object", ":cur_center_no"),
    (try_begin),
      (eq, ":troop_no", "$g_talk_troop"),
      (str_store_string, s14, "str_i_am_in_the_tournament1"),
      (str_store_string, s16, "str_i_am_in_the_tournament2"),
    (try_end),   
  # Dunde's Tournament END

I realized about the recruiting priority upgrade, so I changed the center he will visit for recruiting to the tournament town if it's friendly and close enough.
Code: [Select]
   (try_begin),
      (ge, ":hiring_budget", ":reinforcement_cost"),
           
      (assign, ":action", spai_holding_center),
      (assign, ":object", ":center_to_visit"),
 
      (try_begin),
         (eq, ":troop_no", "$g_talk_troop"),
         (str_store_string, s14, "str_i_dont_have_enough_troops_and_i_need_to_get_some_more"),
         (str_store_string, s16, "str_i_am_running_low_on_troops"),
      (try_end),
   
    # Dunde's Tournament BEGIN
      # Well, recruiting and tournament at once. Who could ask for more?   
      (try_begin), # Change Direction to Tournament Town for registration
        (is_between, "$g_tournament_town", towns_begin, towns_end),
        (call_script, "script_get_relation_between_parties", ":party_no", "$g_tournament_town"),
        (ge, reg0, 0),
        (party_slot_eq, "$g_tournament_town", slot_town_has_tournament, 2),
        (party_get_position, pos0, "$g_tournament_town"),
        (party_get_position, pos1, ":party_no"),
        (get_distance_between_positions, ":dist", pos0, pos1),         
        (le, ":dist", 15000),
        (assign, ":object", "$g_tournament_town"),
        (try_begin),
          (eq, ":troop_no", "$g_talk_troop"),
          (str_store_string, s14, "str_i_want_to_join_a_tournament_for_gaining_troops1"),
          (str_store_string, s16, "str_i_want_to_join_a_tournament_for_gaining_troops2"),
        (try_end),       
      (try_end),


It is sad there is almost noone who took care of the "mission" AI. Bots are still noob-ass.

Is there anyway to disable the default AI, and apply your own methods? Either in Mission or on World?
You should try Motomataru's FormAI.

motomataru

  • External Developer
  • *
  • Battles are best won before the fighting begins.
    • Skype - motomataru
    • Steam - motomataru
    • YouTube - motomataru
    • View Profile
  • Faction: Rhodok
  • MP nick: Motobert
  • M&BWBVC
Re: [Kit] Campaign AI Fixes and Tweaks
« Reply #7 on: September 19, 2012, 10:37:30 PM »
Swyter: I thought you were releasing .904!  :D We had that problem in Brytenwalda, too. I think our last release was supposed to be a year ago, but we couldn't resist adding new features that then would need debugging. Well, it gave me the chance to put v4 of FormAI in it...

Player feedback is invaluable. I had no idea that what I had done here had affected tournaments, because I simply wasn't paying attention to them while running this code over and over again. It's many hours running the game through its paces, and it's sort of luck when you spot some odd situation. Happened to me with this, for example, when a Nord invasion by chance passed by a Vaegir invasion heading the other direction. No one attempted to attack outside the screening parties; hence my addition of the marshal-attack-nearby-marshal and followers-aid-embattled-marshal codes.

Belendor: you're probably right. The way I named this mod makes it seem much more far-reaching than it is. I really just wanted Native party AI to work better. Perhaps "Map Party AI" would be a better name.

Dunde: I really don't know how tournaments interface with party AI. What you did looks like one way to handle it, though you have to be sure you want the priority that high. Really what is needed is a mechanism to reorder this list depending on circumstances and NPC personalities. Not an easy project, but if I were doing it I'd first evaluate each option. You wouldn't have to track every one, simply keep track of the "high score" and which option produced it. THEN run the switch with the option chosen.

Your second solution: interesting, but why not? I doubt anyone would even notice a lord recruiting in a town that's not his base...

EDIT: But if he's outside his culture (e.g. a Nord lord at a Vaegir tournament), then he might get the wrong sort of troops. Check the recruit script to see whether it gets the recruit template from current center or somehow derives it from the lord. Dim recollection tells me it's the former. NM. It's based on the party's faction, so your solution will work.
« Last Edit: September 19, 2012, 10:53:29 PM by motomataru »


Iorya Dragon

  • Sergeant
  • *
  • "Blessed is the mind too small to doubt"
    • View Profile
  • Faction: Swadian
  • M&BWB
Re: [Kit] Campaign AI Fixes and Tweaks
« Reply #8 on: September 21, 2012, 04:29:59 AM »
Very nice mate, this is what campaign AI needed. Can i use this in Warband Enhanced? With credit of course.
"I remember the first days of M&B. The sun rose, and when I looked at the window again, The Darkness"  Sarejo

dunde

  • Count
  • *
  • Curious Coder of The Vision
    • View Profile
  • Faction: Swadian
  • WB
Re: [Kit] Campaign AI Fixes and Tweaks
« Reply #9 on: September 21, 2012, 06:13:52 AM »
I had no idea that what I had done here had affected tournaments, because I simply wasn't paying attention to them while running this code over and over again.
May be it won't effect native tournaments as they 're done from start tier to the end tier in one trigger only or when the player enter it from town menu. My tournament 's running schedule based and it will need  4-5 hours game time. The lords participate in the tournament must stay longer. I solved my problem by giving higher priority to the tournament if it's close and consider the tournament as something the lords must do business in the center.

Beetus

  • Veteran
  • *
  • pls
    • View Profile
  • Faction: Swadian
Re: [Kit] Campaign AI Fixes and Tweaks
« Reply #10 on: February 23, 2013, 08:21:07 PM »
Quote
- restrict diplomacy to next-of-neighbor. Brytenwalda has 32 factions. It made no sense for Kent to suddenly decide to invade Munster six factions distant. M&B having only a handful of neighboring factions never had to develop such a mechanism.

It would be awesome if you included that in this kit... I play Europe 1200 and it really annoys me when Ireland declares war on some Italian states :l

mike56

  • Master Knight
  • *
  • Caballeros de Calradia admin
    • View Profile
    • Caballeros de Calradia
  • Faction: Nord
  • MP nick: CdC_mikeboix
  • WBNWWF&SM&BVC
Re: [Kit] Campaign AI Fixes and Tweaks
« Reply #11 on: March 19, 2014, 09:53:21 PM »
Hello mates, and specially hello, motomataru. Hope you read this.
I've seen on a curious mod your IA and Formations code implemented... with some great modifications.

In this code, not all the factions used the formations. It was a roman vs barbarian mod, so that the Romans used formations and the barbarions don't.

Do you know how can I modify the code to obtain this? Just apply the formations to some factions?

Thanks a lot!


motomataru

  • External Developer
  • *
  • Battles are best won before the fighting begins.
    • Skype - motomataru
    • Steam - motomataru
    • YouTube - motomataru
    • View Profile
  • Faction: Rhodok
  • MP nick: Motobert
  • M&BWBVC
Re: [Kit] Campaign AI Fixes and Tweaks
« Reply #12 on: March 20, 2014, 07:49:39 PM »
Do you know how can I modify the code to obtain this? Just apply the formations to some factions?
If you want to exempt the barbarian faction from the AI, modify lines 1069-1071 from formAI_scripts_wb.py
Code: [Select]
(this_or_next|eq, AI_for_kingdoms_only, 0),
(this_or_next|eq, ":ai_faction", fac_deserters), #deserters have military training
(is_between, ":ai_faction", kingdoms_begin, kingdoms_end),
Then they will always execute a simple charge.

If instead you want them to use the AI, but only not the formations, then have script_cf_battlegroup_valid_formation return 0 when it is called for them.

Hope this helps!
--M


mike56

  • Master Knight
  • *
  • Caballeros de Calradia admin
    • View Profile
    • Caballeros de Calradia
  • Faction: Nord
  • MP nick: CdC_mikeboix
  • WBNWWF&SM&BVC
Re: [Kit] Campaign AI Fixes and Tweaks
« Reply #13 on: March 20, 2014, 08:23:03 PM »
Thanks a lot, motomataru, thought it would be a lot more difficult!
Will try and say :D


kyfohatl

  • Sergeant
  • *
    • View Profile
  • Faction: Neutral
  • WB
Re: [Kit] Campaign AI Fixes and Tweaks
« Reply #14 on: October 11, 2014, 02:12:28 AM »
Hi everyone, I was googling "m&b better AI mod" and I came across this mod. I really dislike the native AI - both campaign and battle AI - , so I would love to use this with any mod I play, so I had a couple of questions about it:

1. This is basically the same AI mod that is used in Prophesy of Pendor and Brytenwalda correct? Or is this an even better version of the AI they use?

2. I am a noob and have no clue regarding intalling this mod. I can install modules but I don't actually know how to install individual scripts like this, and the instructions on the nexus page seem to be for mod developers and people who know what they are doing. Could someone please give me a noob-friendly step by step guide on how to install this mod? Say I want to use this with the Europe 1200 or Persino mods; how do I go about it? And which one of the files do I download? The "ready_to_play" one or the "script"?

3. As far as I can tell only PoP and Brytenwalda use this mod (as they specifically mention "improved campaign AI" in their feature list). Are there other mods that use this?

I know these are dumb questions but I would be very thankful if anyone could answer them. Thanks in advance  :)