Proposed feature: Speak of "supplies" (not "fuel") in a "Coast" unit loss message

Can you help improve your favourite game? Hardcore C mages, talented artists, and players with any level of experience are welcome!
cazfi
Elite
Posts: 3077
Joined: Tue Jan 29, 2013 6:54 pm

Proposed feature: Speak of "supplies" (not "fuel") in a "Coast" unit loss message

Post by cazfi »

osdn #43318: Targeted to freeciv-3.0.0: When a "Coast" unit is lost, message should not say that it run out of fuel, but that it run out of supplies.
nef
Elite
Posts: 324
Joined: Mon Jun 25, 2018 5:01 pm

Re: Proposed feature: Speak of "supplies" (not "fuel") in a "Coast" unit loss message

Post by nef »

A Lua callback could be used to customise the text. THERE ARE OTHER REASONS (in addition to 'supplies') why the unit may be lost.

Similar to the 2.6.5 unit killed message except that here there is time to provide the tolua (and the Lua).
Ignatus
Elite
Posts: 644
Joined: Mon Nov 06, 2017 12:05 pm
Location: St.Petersburg, Russia
Contact:

Re: Proposed feature: Speak of "supplies" (not "fuel") in a "Coast" unit loss message

Post by Ignatus »

nef wrote:A Lua callback could be used to customise the text. THERE ARE OTHER REASONS (in addition to 'supplies') why the unit may be lost.

Similar to the 2.6.5 unit killed message except that here there is time to provide the tolua (and the Lua).
Well, it may come to v.3.1 in another ticket. We have already unhardcoded "they scatter in therror" hut message. Maybe it would be a good idea to make all standard event messages ruleset defineded one or another way... just there are other goals on board.
nef
Elite
Posts: 324
Joined: Mon Jun 25, 2018 5:01 pm

Re: Proposed feature: Speak of "supplies" (not "fuel") in a "Coast" unit loss message

Post by nef »

Ignatus wrote:Maybe it would be a good idea to make all standard event messages ruleset defineded one or another way...
Make that "excellent idea"

A correction to my own post: in this particular case NO CHANGE is needed to tolua. All that is required is for the current message to be DELETED from the sever code and be replaced by this (untested) callback:

Code: Select all

function _deflua_out_of_fuel(unit, player, reason)
  if    reason == "fuel"
  then 
        local function colour(text, fg, bg) 
            return "[c"..
               (fg and (" fg=%q"):format(fg) or "")..
               (bg and (" bg=%q"):format(bg) or "")..
               "]"..text.."[/c]" end
        local function link(object, text) local Type = tolua.type(object)
             return ("[l tgt=%q"):format(Type:lower())..
                     (Type ~= "Tile" and (" id="..MF(object.id)) or
                       (" x="..MF(object.x).." y="..MF(object.y)) )..
                     "]"..text.."[/l]" end
                     
        notify.event (player, unit.tile, E.UNIT_LOST_MISC,
            colour( _('Your %s has run out of fuel.'),"#860000"),
            link(unit.tile, unit.utype:name_translation()))
  end
end;
 signal.connect("unit_lost","_deflua_out_of_fuel")
which would be placed in default.lua. I can dust off a project as soon as fc 2.6.6 hits the streets giving an example of how to override this with a message such as "Your %s has run out of food and water" IF this ticket is also advanced to fc 2.6.6.

I presume that the current ticket will break all current translations, so a question I have is "is there some way to make safe the existing translations using notify.event?"

EDIT: I have updated the Lua code above to include a period (... fuel.) so that the text is (visually) identical to that produced by the server code. Hopefully this will preserve translations. Note that the callback has been tested with a regular fighter.

EDIT 2: (Third time lucky?) It took me quite some time to figure out what 'featured text' was but all's well that ends well. The REPLACEMENT code above will produce an exact (visual) replica - now also in the chat log which is the only place featured text can be seen. Note that the colour cast (for the entire message) is a guess, but who really cares? I have structured the message to (hopefully) avoid breaking translations. Advice on this would be welcome. Finally, I have added the conventional prefix to the function name to make life even easier for our overworked developers.

EDIT 3: Have I nailed it this time??? This version is functionally (and visually) identical to the message generated by the server, that is, the text of the utype name translation now has a tile link to where the unit was lost. I have now used two functions to make the coding easier (and cleaner). I have a third to complete the suite but I will provide that in a later post.
Last edited by nef on Mon Feb 21, 2022 10:21 pm, edited 3 times in total.
cazfi
Elite
Posts: 3077
Joined: Tue Jan 29, 2013 6:54 pm

Re: Proposed feature: Speak of "supplies" (not "fuel") in a "Coast" unit loss message

Post by cazfi »

nef wrote: I can dust off a project as soon as fc 2.6.6 hits the streets giving an example of how to override this with a message such as "Your %s has run out of food and water" IF this ticket is also advanced to fc 2.6.6.
It would break compatibility (existing rulesets with custom default.lua do not have the message), so can't happen in S2_6 or S3_0. Next feature release is freeciv-3.1.
cazfi
Elite
Posts: 3077
Joined: Tue Jan 29, 2013 6:54 pm

Re: Proposed feature: Speak of "supplies" (not "fuel") in a "Coast" unit loss message

Post by cazfi »

Opened a new ticket about moving the message to default.lua in development branches -> osdn #43341. For S3_0 I think the current patch should still go forward.
cazfi
Elite
Posts: 3077
Joined: Tue Jan 29, 2013 6:54 pm

Re: Proposed feature: Speak of "supplies" (not "fuel") in a "Coast" unit loss message

Post by cazfi »

cazfi wrote:Opened a new ticket about moving the message to default.lua in development branches -> osdn #43341.
Thinking it would be trivial, I started implementing it, but then gave up when the need to create a tile link for the message came up.
nef
Elite
Posts: 324
Joined: Mon Jun 25, 2018 5:01 pm

Re: Proposed feature: Speak of "supplies" (not "fuel") in a "Coast" unit loss message

Post by nef »

cazfi wrote:
nef wrote: I can dust off a project as soon as fc 2.6.6 hits the streets giving an example of how to override this with a message such as "Your %s has run out of food and water" IF this ticket is also advanced to fc 2.6.6.
It would break compatibility (existing rulesets with custom default.lua do not have the message), so can't happen in S2_6 or S3_0. Next feature release is freeciv-3.1.
I can understand the dilemma here because it also applies to those who have implemented the hut enter project.

In considering this issue my opinions were:
  • a. Modders should, in general, not mess with default/default.lua. I avoid it. The hut enter project was a special case much like the current in that it ought to be included in the distro. For those who mess with their ruleset default.lua then the next point applies.
    b. Maybe there are others but all that I can think of who actually need a custom version of default.lua are those who only have a single ruleset using the custom default.lua such as MP (notably LT). In this situation, the distinction between default.lua and script.lua is only a matter of order of execution. The requirement for the proposed callback is that it is the last signal.connect (for "unit_lost"). All that is required is for the code above (from the post, or from the hypothetical distro) to be copied into 'the right place' in their *.lua. IMO if these people managed to customise their default.lua then I think this copy/paste exercise would not be beyond their talents.
    If there are other callbacks also demanding to be last then, and only then, a merge of the function bodies is indicated. But once again, if this is the case, then some considerable Lua competence would have been needed, and the merge should be well within that competency.
So I think the issue boils down to this: is it better to endure a minor inconvenience now, and get this done and over with, or let it drag on for years?
nef
Elite
Posts: 324
Joined: Mon Jun 25, 2018 5:01 pm

Re: Proposed feature: Speak of "supplies" (not "fuel") in a "Coast" unit loss message

Post by nef »

cazfi wrote:
cazfi wrote:Opened a new ticket about moving the message to default.lua in development branches -> osdn #43341.
Thinking it would be trivial, I started implementing it, but then gave up when the need to create a tile link for the message came up.
I don`t understand this. The callback code WORKS. The (optional) second argument to notify.event is the tile and the code provided works just fine. Maybe the confusion here is in not realising that the unit is still alive (i.e. not Nonexistent) while the callback is in progress so fields like unit.tile are still valid. In fact the Player argument is redundant because unit.owner (should) also work.

The unit_lost callback does have some pathological problems but none that adversely affect the callback above. The redundancy may have been an (unsuccessful) attempt to avoid the problems but I don`t know.

There is one issue that I have not yet tested: what happens when there is a sequence of callbacks; but so far I have not yet seen any problems.
cazfi
Elite
Posts: 3077
Joined: Tue Jan 29, 2013 6:54 pm

Re: Proposed feature: Speak of "supplies" (not "fuel") in a "Coast" unit loss message

Post by cazfi »

nef wrote:
cazfi wrote:
cazfi wrote:Opened a new ticket about moving the message to default.lua in development branches -> osdn #43341.
Thinking it would be trivial, I started implementing it, but then gave up when the need to create a tile link for the message came up.
I don`t understand this.
A featured text link for the unit, not just unit's name, should be inserted to the message. Otherwise it's a regression compared to the current message sent from the C-code.

While it should be possible to construct the link using just lua (it's just text, after all), I'd prefer to keep information about tags etc in just one place, in C-code. That's why there's now osdn #43343 to provide featured text utilities to lua side.
Post Reply