I had a itch, I had to scratch (v2.6)

Contribute, display and discuss rulesets and modpacks for use in Freeciv here.
Post Reply
omero
Posts: 48
Joined: Fri Mar 31, 2023 10:43 am

I had a itch, I had to scratch (v2.6)

Post by omero »

BEWARE: This might result long, uninteresting and/or already covered elsewhere.

Thus, one thing I always disliked (in most rulesets), is that upon entering a hut,
on some occasions *BOOM* City happens. Me and the fc code greatly differ about
when and why a tile would qualify for being a decent spot to place a city.
Triggering the city foundation when entering a hut has always been considered
an unfortunate event for me, requiring turns and turns waiting growth,
disbanding, relocating... Maybe a tile or two away from the original hut spot.

My mission: avoid the foundation of a city in a random spot because a
curious explorer (whatever) entered a hut (Minor Tribe Village).

The idea: Settlers OR Migrants instead.

After some digging around , I found several threads (most if not all
authored/involving Nef) about 'hut enter' events and several approaches
centered on 'default.lua' alterations.

I settled (pun intended) on one version (the most 'generic and complete') and started hacking.
My hacks turn up working fine and instead of an instant city, one gets Settlers (25%) or Migrants (75%).

I was dubious about replacing <...>/default/default.lua with an altered version,
and attempts to integrate the relevant sections in <...>/ruleset/script.lua were miserably failing.

My understanding was that one should not tamper with <...>/default/default.lua and
instead do all the work in his <...>/ruleset/script.lua instead, but that is not going to end well.

When no <...>/ruleset/default.lua is found, then <...>/default/default.lua is sourced.
That is guaranteed to be there, else your installation is ... Flawed.

See? When your <...>/ruleset/script.lua has stuff that "would" belong in a default.lua,
you have a problem of precedence. Last one sourced, wins: .../default/default.lua!

However, seems that having <...>/ruleset/default.lua will stop the hunt
for <...>/default/default.lua (apparently). I ended up doing precisely this,
in other words, let the .../default/default.lua alone but have
my altered one present as .../ruleset/default.lua.

I am confused and need some advices/clarifications about how to correctly
implement this for an hypothetical (far into the future) modpack.

EDIT: For the records, the patch with modifications in attachment.
Attachments
default.lua.26x.2023-06-09.0a1.lua.patch.tar.bz2
(1.65 KiB) Downloaded 131 times
Last edited by omero on Sat Jun 10, 2023 8:55 pm, edited 1 time in total.
cazfi
Elite
Posts: 3077
Joined: Tue Jan 29, 2013 6:54 pm

Re: I had a itch, I had to scratch (v2.6)

Post by cazfi »

You can provide your own custom default.lua, like you already discovered, as part of your ruleset. The downside of that is that you are then responsible of maintaining and updating your copy of it from freeciv version to the next.
cazfi
Elite
Posts: 3077
Joined: Tue Jan 29, 2013 6:54 pm

Re: I had a itch, I had to scratch (v2.6)

Post by cazfi »

As for precedence, it should have been correct since freeciv-2.4.5: https://web.archive.org/web/20170307053 ... ugs/?23101

script.lua callback should run first, and be able to tell that processing should end there (i.e, that default.lua callback should not be called)
omero
Posts: 48
Joined: Fri Mar 31, 2023 10:43 am

Re: I had a itch, I had to scratch (v2.6)

Post by omero »

cazfi wrote: Thu Jun 08, 2023 9:35 am As for precedence, it should have been correct since freeciv-2.4.5: https://web.archive.org/web/20170307053 ... ugs/?23101

script.lua callback should run first, and be able to tell that processing should end there (i.e, that default.lua callback should not be called)
I understand.
What I find confusing is that when ruleset supplies a script.lua, the search for a default.lua (inside the ruleset dir or anywhere else) should not occur.

In other words, everything the ruleset needs to be done in lua,
should be carried out in script.lua and NOTHING else.

This is how I have interpreted the comments at the beginning of default.lua (the one supplied with the source code distribution).

Code: Select all


-- When creating new ruleset, you should copy this file only if you
-- need to override default one. Usually you should implement your
-- own scripts in ruleset specific script.lua. This way maintaining
-- ruleset is easier as you do not need to keep your own copy of
-- default.lua updated when ever it changes in Freeciv distribution.

My apologies if my interpretation is incorrect.
Cheers, o/

Addendum: When a default.lua is still searched for and processed after a ruleset script.lua, then the script.lua is maybe supplementing but not overriding the default.lua.
Last edited by omero on Sat Jun 10, 2023 1:00 am, edited 1 time in total.
cazfi
Elite
Posts: 3077
Joined: Tue Jan 29, 2013 6:54 pm

Re: I had a itch, I had to scratch (v2.6)

Post by cazfi »

Both script.lua and default.lua are always used. The idea of the division is that default.lua usually comes from default/default.lua while rulesets implement script.lua part themselves. E.g. there's no need for each ruleset to implement huts related code themselves (and to maintain such a script from freeciv version to freeciv version!)

I'm sorry if the wording is misleading. Feel free to suggest improvements.
omero
Posts: 48
Joined: Fri Mar 31, 2023 10:43 am

Re: I had a itch, I had to scratch (v2.6)

Post by omero »

cazfi wrote: Sat Jun 10, 2023 12:54 am Both script.lua and default.lua are always used. The idea of the division is that default.lua usually comes from default/default.lua while rulesets implement script.lua part themselves. E.g. there's no need for each ruleset to implement huts related code themselves (and to maintain such a script from freeciv version to freeciv version!)

I'm sorry if the wording is misleading. Feel free to suggest improvements.
I have read this after editing my previous comment.
The fact that a default.lua is processed nevertheless is not clearly stated anywhere, hence my confusion.

Infact, my initial expectations where that I only needed implementing what I needed within script.lua alone, and now I understand why it was not working.
Besides, a ruleset could _want_ to have his own way of dealing with huts, thus needing to alter the default 'hut enter' behavior.
cazfi
Elite
Posts: 3077
Joined: Tue Jan 29, 2013 6:54 pm

Re: I had a itch, I had to scratch (v2.6)

Post by cazfi »

omero wrote: Sat Jun 10, 2023 1:04 amInfact, my initial expectations where that I only needed implementing what I needed within script.lua alone, and now I understand why it was not working.
Besides, a ruleset could _want_ to have his own way of dealing with huts, thus needing to alter the default 'hut enter' behavior.
And there's two ways to achieve that.

1) script.lua callback for "hut_enter" signal can return 'true' to stop signal emission to default.lua callbacks ( https://www.freeciv.org/wiki/Lua_refere ... ual#signal )
2) The ruleset can implement also its own default.lua
omero
Posts: 48
Joined: Fri Mar 31, 2023 10:43 am

Re: I had a itch, I had to scratch (v2.6)

Post by omero »

cazfi wrote: Sat Jun 10, 2023 1:23 am
omero wrote: Sat Jun 10, 2023 1:04 amInfact, my initial expectations where that I only needed implementing what I needed within script.lua alone, and now I understand why it was not working.
Besides, a ruleset could _want_ to have his own way of dealing with huts, thus needing to alter the default 'hut enter' behavior.
And there's two ways to achieve that.

1) script.lua callback for "hut_enter" signal can return 'true' to stop signal emission to default.lua callbacks ( https://www.freeciv.org/wiki/Lua_refere ... ual#signal )
2) The ruleset can implement also its own default.lua
Yes, now everything is crystal clear!
Thank you :)
omero
Posts: 48
Joined: Fri Mar 31, 2023 10:43 am

Re: I had a itch, I had to scratch (v2.6)

Post by omero »

Attached patch to original post, for the records.
Also, I'd like to know if it could be done any better than the inelegant kludge I resorted to :)
Post Reply