fast_ai issue (not sure where to post this)

Having trouble with the game? Report issues and get help here. Read this first!

Moderator: Forum Moderators

Forum rules
Before reporting issues in this section, you must read the following topic:
Post Reply
User avatar
Spannerbag
Posts: 505
Joined: December 18th, 2016, 6:14 pm
Location: Yes

fast_ai issue (not sure where to post this)

Post by Spannerbag »

Hi all,

I'm developing my own campaign and had a working scenario but decided as it involves numerous units to try out fast_ai.

My PC is minimum spec (Windows 7 sp1) but runs the game OK and the fast_ai test scenario also works fine, so the issue is definitely with my code :doh:

The sides using the fast_ai (3 and 4) begin the scenario with no leader and controller null.
I.e. for side 3:

Code: Select all

    no_leader=yes
    side=3
    controller=null
Side 3 does get a leader later on (2 eventually actually) whereas side 3 remains leaderless.
Both display the same behaviour.

And it's the controller=null that I suspect is the issue.

Everything actually works, but a lua error is issued when (I think) the first unit moves.
<Lua error> ai/micro_ais/ca_fast_attack_utils.lua:145 table index is nil
stack traceback:
ai/micro_ais/ca_fast_attack_utils.lua:145 in field 'single_unit_info'
ai/micro_ais/ca_fast_attack_utils.lua:178: in field 'get_unit_info'
ai/micro_ais/ca_fast_attack_combat.lua:83: in function <ai/micro_ais/ca_fast_attack_combat.lua:7>
(...tail calls...)


This is a cosmetic issue I think: gameplay seems to proceed OK.
It's probably a red herring but the lua console only mentions that this add-on doesn't have an "_info.cfg" - which is fair enough as I didn't d/l the add-on from the server but am writing it myself...

I've tried adding the fast_in the prestart event and also defering it until side 3 actually has a leader but no change.
I.e.:

Code: Select all

    [micro_ai]			# Do this later (here) so side 3 has a leader
      side=3
      ai_type=fast_ai
      action=add
    [/micro_ai]
I can revert to the default ai as that makes a pretty fair fist of smooth gameplay - I was just curious to see how the fast_ai compared.

Again, apologies if this isn't the right place to post this.
Of course if there is a [wml] fix or a lua "suppress messages" option that would be a nice quick fix for now.

If you need more info please let me know; I'm happy to help.

Thanks in advance for your time and trouble!
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: fast_ai issue (not sure where to post this)

Post by mattsc »

Hi Spannerbag,

Thanks for the detailed report. This is definitely something that should not happen and everything points to a bug in the Fast MAI code. Based on where in the code it occurs, it looks like you might have a weapon special that the AI does not deal with correctly, but that's just a guess and I can't tell more than that without being able to reproduce the problem. So, could you send me a savegame for a case when this happens (ideally one simply has to end the player's turn for the error message to be triggered) and the scenario/campaign code? If this is for a campaign that you do not want to be public yet, you can send it to me in a PM.

Also, which version of Wesnoth are you using?
User avatar
Spannerbag
Posts: 505
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: fast_ai issue (not sure where to post this)

Post by Spannerbag »

mattsc wrote: August 9th, 2018, 1:49 pm Hi Spannerbag,

Thanks for the detailed report. This is definitely something that should not happen and everything points to a bug in the Fast MAI code. Based on where in the code it occurs, it looks like you might have a weapon special that the AI does not deal with correctly, but that's just a guess and I can't tell more than that without being able to reproduce the problem. So, could you send me a savegame for a case when this happens (ideally one simply has to end the player's turn for the error message to be triggered) and the scenario/campaign code? If this is for a campaign that you do not want to be public yet, you can send it to me in a PM.

Also, which version of Wesnoth are you using?
Thanks for the reply :)
I made a single change to my scenario and this seems to have fixed it: I changed controller=null to controller=ai in the [side]s.
The issue went away.
I haven't exhaustively tested this because I've been working on a campaign that's grown like topsy and is about 80% complete and playable.
Having started ages ago on 1.12 (yes, I've been writing and testing it that long!) I decided to port it to 1.14.4.

Sadly I encountered multiple issues (e.g. changed savegame format, different wml tolerances - e.g. slashes and the need to specify "type" in [side] tags in 1.14.4) so I was beginning to lose the will to live when this came up :roll:

This is an early scenario and there's nothing exotic around yet except that the units controlled by the ai have a mix of regular + custom traits. I'm happy to send you a savegame and code but would suggest that it might, IMHO, be better to change the fast_ai scenario (~data/ai/micro_ais/scenarios/fast.cfg) that comes with Wesnoth and see if that replicates the issue?

To replicate my setup just change the fast_ai [side] controller to null then on turn 2 use [modify_side] [ai] to change controller to ai and then [micro_ai] to add the fast_ai. That way there is far less clutter and should (hopefully!) replicate the issue. Just a thought...
I.e.

Code: Select all

    [side]
        side=1
#        controller=ai
        controller=null
        type=Orcish Warlord
        x,y=40,1

        persistent=no
        canrecruit=yes
        recruit=Orcish Grunt,Orcish Archer,Orcish Assassin,Wolf Rider
        gold=1000
    [/side]
then add a turn event

Code: Select all

# Turn event to change controller and add fast_ai
  [event]
    name=turn 1
    [modify_side]
      side=1
      controller=ai
    [/modify_side]
    [micro_ai]
        side=1
        ai_type=fast_ai
        action=add
    [/micro_ai]
  [/event]
I've not tested the above but it should work.

Let me know if you'd still like a savegame and code.

Again, thanks for replying.
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: fast_ai issue (not sure where to post this)

Post by mattsc »

Hi again — yeah, porting campaigns can be frustrating, I sympathize.

I tried what you suggested (in fact, I tried several variations of it). It was a good idea, but I was unable to reproduce your problem that way. So unless you have another suggestion, I guess I'll need that savegame if we want to investigate this further. :hmm:
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: fast_ai issue (not sure where to post this)

Post by gfgtdf »

the erro message ai/micro_ais/ca_fast_attack_utils.lua:145 table index is nil is quite clear as line 145 of tht file is a[sp[2].id] = true which means sp[2].id is nil. meaning you have a cahnce_to_hit weapon special without an id= attriute, ofc the should also be fixed in the ai file (check for sp[2].id beein nil before using it)
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: fast_ai issue (not sure where to post this)

Post by mattsc »

Oh, duh! I should have noticed that. I'll fix that in the AI. But in the meantime, that gives you an easy workaround. Thanks, gfgtdf.
User avatar
Spannerbag
Posts: 505
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: fast_ai issue (not sure where to post this) *Resolved*

Post by Spannerbag »

gfgtdf wrote: August 9th, 2018, 11:35 pm the erro message ai/micro_ais/ca_fast_attack_utils.lua:145 table index is nil is quite clear as line 145 of tht file is a[sp[2].id] = true which means sp[2].id is nil. meaning you have a cahnce_to_hit weapon special without an id= attriute, ofc the should also be fixed in the ai file (check for sp[2].id beein nil before using it)
Hi gfgtdf,

I should've checked this earlier; mattsc mentioned weapon specials and I forgot about a custom trait available to ai controlled units :doh: (again).

I tried adding id=... in various places and this worked:

Code: Select all

#define TRAIT_SICKLY SICKLINESS_PERCENTAGE SICKLINESS_DAMAGE SICKLINESS_HITCHANCE
  [trait]
    id=sickly{SICKLINESS_PERCENTAGE}_{SICKLINESS_DAMAGE}_{SICKLINESS_HITCHANCE}
...(snipped for brevity/clarity)...
      [set_specials]
         mode=append
        [chance_to_hit]
          id=sickly_cth{SICKLINESS_PERCENTAGE}_{SICKLINESS_DAMAGE}_{SICKLINESS_HITCHANCE}
          multiply={SICKLINESS_HITCHANCE}
          cumulative=yes
        [/chance_to_hit]
      [/set_specials]
    [/effect]
  [/trait]
#enddef
Adding the line id=sickly_cth{SICKLINESS_PERCENTAGE}_{SICKLINESS_DAMAGE}_{SICKLINESS_HITCHANCE} did the trick :D

So I need to trawl through my weapon specials and add ids ad I'll be sorted.
Thanks to all who took the trouble to reply!
Cheers!
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: fast_ai issue (not sure where to post this)

Post by mattsc »

Spannerbag wrote: August 10th, 2018, 1:34 pm So I need to trawl through my weapon specials and add ids ad I'll be sorted.
I just fixed the Fast Micro AI for chance-to-hit weapon specials without ids. So you could simply wait until 1.14.5 is out and it will work without you having to change your specials. Or you could change that file in your copy of Wesnoth locally and continue working on it right now (of course, that won't work for others if you upload this before 1.14.5 is out).

Thanks for reporting this!
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: fast_ai issue (not sure where to post this)

Post by gfgtdf »

mattsc wrote: August 10th, 2018, 2:19 pm
Spannerbag wrote: August 10th, 2018, 1:34 pm So I need to trawl through my weapon specials and add ids ad I'll be sorted.
So you could simply wait until 1.14.5 is out and it will work without you having to change your specials.
well even if this is fixed in 1.14.5 it's still better to have the workaround in your addon since there will still be players that use wesnoth 1.14.4 or older.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
User avatar
Spannerbag
Posts: 505
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: fast_ai issue (not sure where to post this)

Post by Spannerbag »

mattsc wrote: August 10th, 2018, 2:19 pm I just fixed the Fast Micro AI for chance-to-hit weapon specials without ids. So you could simply wait until 1.14.5 is out and it will work without you having to change your specials. Or you could change that file in your copy of Wesnoth locally and continue working on it right now (of course, that won't work for others if you upload this before 1.14.5 is out).

Thanks for reporting this!
Thanks for the swift resolution. I'm not sure I could face any more potential migration issues at present so I'll stick with 1.14.4 and when (if ever!) I get this finished I'll migrate to the current Wesnoth stable version then. Fingers crossed when I get to the more complex stuff!

So, it'll be published when the stable version is 2.73.5...
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
Tad_Carlucci
Inactive Developer
Posts: 503
Joined: April 24th, 2016, 4:18 pm

Re: fast_ai issue (not sure where to post this)

Post by Tad_Carlucci »

So you're sure your great grandchild will actually finish it? /s
I forked real life and now I'm getting merge conflicts.
Post Reply