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.