Topic: How can I replace immovables?
Posted at: 2021-11-23, 01:52
I'm trying to learn how to create addons by implementing https://www.widelands.org/forum/topic/5458/ but I ran into some problems when I tried to test it. I attached my code for Empire coal mine.
Problem 1: How to replace a unit?
When I try to start a game with this addon, it fails with this error:
What am I doing wrong? Or may this be a bug in the unit replacement code?
Unfortunately I couldn't find an example for replacing units, only for adding new ones. I'm not even sure if I need
Problem 2: Multiple units in the official resource indicator definitions
Before the above error message, the following warnings are logged:
These warnings go away if I edit the main definitions in data/tribes/immovables/resi and move the redefined units to separate directories, but the error remains. It looks as if when coal_1 is replaced, all others registered at the same time are removed as well. I figure it may prevent redefining these units, and so I think it is a bug in these data files, because when I first copied the data/tribes/immovables/resi directory to the addon, and edited the
In this case the unused key warnings were for the Amazon resis, and the error was with the Amazon gold_1 resi.
Posted at: 2021-11-23, 08:49
I had a quick look at the attached file – what you are doing is to create some new immovables, but you're not adding a link between these items and the immovables placed by the geologist.
There are three ways to achieve what you want:
Let me know if you want me to add
The "multiple units in one file" errors happen because the official resi definitions themselves have not yet been converted to the new format. As long as this has not been done, you'll need to batch-replace all resource indicators of a tribe at the same time or there will be bugs.
Posted at: 2021-11-23, 10:18
Is that possible with
As far as I was able to figure it out this is the only way that may (should?) be possible with the current code, because
Yes, I saw that. It is far from ideal to copy the whole item definition just to change 5% of it. However it's not just the
That would be quite a big change to
Well, I hoped it would be possible to do it with the current code. But modifying immovable programs (2.) is clearly something that will be needed by some addon sooner or later. I may try to do it though, based on #4866.
But how should I handle the attribute issue? I think it would make sense to add the indicated resource as attribute to resis in the official definition. Is that OK? If not, it seems quite a big change to
BTW, is it possible to use multiple attributes in
I tried it, but it doesn't work. (see the original post)
Edited: 2021-11-23, 14:36