monastery AI random misbehavior

Bug #1770901 reported by ypopezios
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
widelands
Fix Released
High
Unassigned

Bug Description

In mission "Surprise, Surprise!", when I gathered the needed amount of wares to please the monastery, I got a message in my inbox with heading "Lua Coroutine Failed" and body:

[../src/scripting/lua_errors.cc:22][string
"scripting/mission_thread.lua"]:454: attempt to
index a nil value (field 'immovable')

Tags: campaign lua

Related branches

GunChleoc (gunchleoc)
Changed in widelands:
milestone: none → build20-rc1
importance: Undecided → High
tags: added: campaign
removed: inbox
Revision history for this message
hessenfarmer (stephan-lutz) wrote :

Hm the line refers to the little sentry around the monastery. However it is the last immovable to remove. Could you provide a savegame before the issue happened.

Changed in widelands:
assignee: nobody → hessenfarmer (stephan-lutz)
Revision history for this message
hessenfarmer (stephan-lutz) wrote :

Maybe I have seen something similar in the past but it was only once. Perhaps the monastery Ai dismantled the sentry, or at leat did try it although they don't have any builders. So if we can confirm this as reason for the bug I could think about a solution.

Revision history for this message
ypopezios (ypopezios) wrote :

Indeed the sentry was missing. And as a result, when I reached the target the monastery economy got self-destroyed and I got no reward for gathering the wares. And indeed that didn't happen when I played again. Adding an existence check before removing something would prevent the lua failure, but it wouldn't prevent AI's random misbehavior.

summary: - monastery nil immovable
+ monastery AI random misbehavior
Revision history for this message
kaputtnik (franku) wrote :

One could try to disable the ai for Vesta by changing in file player_names:

ai=

to

ai="empty"

Revision history for this message
GunChleoc (gunchleoc) wrote :

We should definitely set the Ai to empty.

There is also a possibly related bug: https://bugs.launchpad.net/widelands/+bug/1629691

Revision history for this message
hessenfarmer (stephan-lutz) wrote :

I already tried the Ai="empty" solution yesterday.

Result is that Player 3 (Vesta) is not initialized. And therefore the Monastery is not placed on the map.

So this is definitly no solution.
Currently I am thiunking about a Loop that checks whether the 5 Buildings still exist and replaces them instantly if set to dismanteled. The buildings itself are not really important cause they are replaced after the wares have been collected.
There are just 2 Problems with this:
1. due to the frequency of the Loop (probably 2 seconds) there might be the case where a dismateled building would become a normal one again. This small glitch might be noticed by a Player, but only if he has statistics and building names on. If the Ai is destroying the building this is a different Story cause this would look weird.
2. How to differentiate between the Ai destroying / dismantleing a building and the Player conquering the buildings. I need to experiment a bit with that case. Cause I can't predict what would happen.

Revision history for this message
hessenfarmer (stephan-lutz) wrote :

This Forum tread is exactly explaining the Problem.

https://wl.widelands.org/forum/topic/4201/

Revision history for this message
kaputtnik (franku) wrote :

> Result is that Player 3 (Vesta) is not initialized. And therefore the
> Monastery is not placed on the map.

You could place it manually in the starting condition. But of course there will be no 'action' (e.g. no wares get transported).

> Currently I am thiunking about a Loop that checks whether the 5
> Buildings still exist and replaces them instantly if set to dismanteled.

Such a loop may result a 'scripting vs. AI battle' where the ai removes the building, the script places a building and the ai removes it again... and so on.

I think the better solution would be to check if the immovable is NIL before trying to remove it.

Revision history for this message
hessenfarmer (stephan-lutz) wrote :

> You could place it manually in the starting condition. But of course there will be no 'action' > (e.g. no wares get transported).

The Mission Thread script tries to do exactly this when the Player has discovered the territory of the monastery. But as Player 3 isn't initialized, you can't place buildings for player 3. Placing them for player 1 would be no solution as you can't conquer the monastery. Placing them for Player 2 would lead to the same results as seen in this bug.

> Such a loop may result a 'scripting vs. AI battle' where the ai removes the building, the > script places a building and the ai removes it again... and so on.

As this happens only occasionally the chance of having to replace it would be very low. After reinstating the building this is a new entity for the AI so it does take time to gather enough "uselessness" points for the new building to get dismantled again. At least this is my understanding of the AI mechanisms.

> I think the better solution would be to check if the immovable is NIL before trying to remove it.

Problem is that after removal exactly the same buildings will be placed on the map again. But this time for player 1. So suddenly there will exist a building that has been dismantled or destroyed before. This replacement was done to reflect the story that the monastery has switched to the side of the player.
If the loop wont't work or perhaps as alternative solution I could Try to play around with the team property but I am afraid this won't work properly.

Revision history for this message
ypopezios (ypopezios) wrote :

> I think the better solution would be to check
> if the immovable is NIL before trying to remove it.

I have to repeat that checking for sentry's existence doesn't solve the scenario issue. When the sentry vanishes, there is no more option to conquer it. Furthermore, upon gathering of the wares, the monastery got self-destroyed, not giving the reward. Maybe the scenario code assumed that the sentry got conquered by the player.

Revision history for this message
ypopezios (ypopezios) wrote :

> it does take time to gather enough "uselessness" points

Seems that the solution would be to guarantee the usefulness of the sentry, whether directly or indirectly.

Revision history for this message
kaputtnik (franku) wrote :

> The Mission Thread script tries to do exactly this when the Player
> has discovered the territory of the monastery.

Hm, looks i miss a thing. Why are the buildings placed for Vesta after the player had discovered one of this fields?

https://bazaar.launchpad.net/~widelands-dev/widelands/trunk/view/head:/data/campaigns/emp04.wmf/scripting/mission_thread.lua#L382

Would it change the scenario if the buildings are placed right away from start?

Revision history for this message
hessenfarmer (stephan-lutz) wrote :

@ypopezios:
the idea of my proposed loop is indded to prevent the sentry from vanishing to keep it conquerable and existant. So the loop would check for existance and replace the sentry or any other of the buildings if necesary. This would only hardly noticable by the player.
The scenario is designed to let you have a real choice: if you conquer it, you get the plans for improved bread and beer production instantly, but you will suffer some bad things in the future.
I fyou gather the wares the monastery is not self destroyed, the original buildings of p3 are removed and exchanged by identical buildings of p1 (the warehouse will additionally prefilled with some benefits as well). But as the lua stopped in your game in the last line of removal it never reached the state to just set the new buildings so in this special case you don't get the reward. In your second run without the sentry being vanished this should have been the case though. Anyhow a savegame of the game would be very helpful to understand what is going on.
The "big" solution would be to have an additional AI state "dumb" to be useable in scenarios. Look at the forum discussion I linked. In this scenario we need to trick around the working AI logic to achieve the state of the Ai doing exactly nothing. This is hard to achieve though. (for example I just didn't give the Ai of p3 any wares or workers so it can't start building anything. However this can't prevent dismantling things or simply destroying them.

@kaputtnik:
the main reason for the late placement is to prevent the AI from doing weird things, like dismantling buildings. If we can fix this properly (at best by creating a new "dumb" AI state it might be possible to place them from the beginning.

My alternative solution would look like to allow the monastery AI to dismantle their sentry by just switching teams after delivery of the wares but I am not sure whether I can switch to shared economy mode in the scenario.

Revision history for this message
kaputtnik (franku) wrote :

Isn't an 'empty' AI a 'dumb' AI?

Just hacked the scenario with ai="empty" and prebuild buildings and roads for Vesta.

The Problem when removing the warehouse, or the sentry some yellow widelanders are walking around :S But this could be solved also, imho.

Revision history for this message
hessenfarmer (stephan-lutz) wrote :

@kaputtnik:

thanks a lot. maybe I was to impatient yesterday to really reach the fields that are necessary. Will incorporate your changes in the fix branch most probably. Will try to fix the remaining 5 widelanders walking around as well.

Revision history for this message
GunChleoc (gunchleoc) wrote :

How about having a custom warehouse building and give it the code of a headquarters? The conquer radius would make sure that surrounding buildings don't get destroyed for lack of territory, and you wouldn't need a sentry then unless you want it.

Revision history for this message
hessenfarmer (stephan-lutz) wrote :

That is a really good idea cause it would fit the peaceful appearance of a monastery much better. The only thing is we need probably a hint for the player to attack the warehouse if he wants to conquer the monastery. I will try to fix the issues this evening. At least kaputtnik convinced me that AI="empty" really works. And it looks a lot nicer as well as the Ai doesn't try to change the road network all the time.
I just want to try some solution with the team changing option that has been included for example in the frisian scenario 02. if this delivers the same results I could let the monastery stay as p3 instead of switching it to p1

Revision history for this message
hessenfarmer (stephan-lutz) wrote :

ok fix is uploaded.
removed the sentry completely.
now we have a building called temple of vesta which is a empire warehouse with the conquers property unlike a HQ it conquers only a radius of seven.
added some code to remov all p3 workers before removing the buildings to avoid yellow peole wandering around.
needs to be playtested fully though.

Changed in widelands:
status: New → In Progress
Revision history for this message
hessenfarmer (stephan-lutz) wrote :

@ypopezios
If your time allows please consider retesting the scenario and after that report your results in the branch under review

Thanks

Changed in widelands:
status: In Progress → Fix Committed
Revision history for this message
GunChleoc (gunchleoc) wrote :

Fixed in build20-rc1

Changed in widelands:
status: Fix Committed → Fix Released
Changed in widelands:
assignee: hessenfarmer (stephan-lutz) → nobody
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.