FreeOrion

Forums for the FreeOrion project
It is currently Sun May 19, 2013 3:36 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: [PATCH] Starting fleets names not looked up in stringtables
PostPosted: Wed Nov 30, 2011 8:28 pm 
Online
Programmer and Packager
User avatar

Joined: Wed Nov 16, 2011 12:56 pm
Posts: 761
Location: Sol III
I noticed that the starting fleets in recent build no longer had names like "Colony Fleet", "Scout Fleet" etc., but "FN_COLONY_FLEET", "FN_SCOUT_FLEET" etc. Apparently these string identifiers don't get translated into the corresponding string entries in the stringtables.

Looking at the FleetPlan and FleetPlanManager classes code revealed that FleetPlan has a member flag which decides if the fleet name stored in m_name will be looked up in the stringtabels (via call to UserString()). This flags defaults to false in the ctor code, and nowhere in the rest of the code it gets set to true, resulting in never being translated in the corresponding entry in the stringtables.

I tried to find out where and how this flag has been set to true for the starting fleet plans in rev 4471 (where it worked, fleet names have been translated), but I have to admit I failed. I guess it happened somewhere in the old parser code, but I coudn't figure it out, I'm a bit out of my legue here :? :wink:

So I finally came up with the idea to check if the first three characters of m_name equal "FN_" in FleetPlan::Name(), and if that's the case to ignore the lookup flag, looking up the name regardless and returning the translated string (instead of the identifier string). Test build went fine, fleet names of the starting fleets were back to normal.

However, I doubt that this is the way things should work, but this was the best I could think of. I have no idea in what way the parser code would have to be modified to get the original behaviour. Nevertheless I attached a patch, it should work at least as a temporary solution. Don't know if you want to incorporate it into SVN...

EDIT: Don't use patch attached to this post, it's obsolete and has been replaced by a new one! See subsequent post below.


Attachments:
Starting_Fleet_Names.patch [504 Bytes]
Downloaded 2 times


Last edited by Vezzra on Thu Dec 01, 2011 10:42 am, edited 1 time in total.
Top
 Profile  
 
 Post subject: Re: [PATCH] Starting fleets names not looked up in stringtab
PostPosted: Wed Nov 30, 2011 9:40 pm 
Offline
Programming, Design, and De Facto Lead
User avatar

Joined: Wed Oct 08, 2003 1:33 am
Posts: 7887
Location: Vancouver, BC
In 4471, the FleetPlan parsing looked like this:
Code:
        fleet_plan_p =
            (str_p("fleet")
             >> name_label >>           name_p[fleet_plan_p.name = arg1]
             >> ships_label
             >> (name_p[push_back_(fleet_plan_p.ship_designs, arg1)] |
                 ('[' >> *(name_p[push_back_(fleet_plan_p.ship_designs, arg1)]) >> ']'))
            [fleet_plan_p.this_ = new_<FleetPlan>(fleet_plan_p.name, fleet_plan_p.ship_designs, val(true))]);
The val(true) is the parameter to the FleetPlan constructor to tell it to look up the names in the stringtable. So, for FleetPlans created by parsing, this flag was always true.

I'm not sure if there's any case where fleet plans are made not by parsing, but it'd probably be OK to change the default value of that parameter for FleetPlan to true.

To replicate the old behaviour, you might be able to pass true to the FleetPlan constructor in the parser. I'm not sure if this needs wrapping in something like val(true) as was required for the old parser, but the relevant bit of FleetPlansParser.cpp is
Code:
new_<FleetPlan>(_a, _b)
which is not specifying anything for the third parameter, so is using the default false, resulting in the names not being looked up in the stringtable, as that's what that parameter specifies.

Inspecting the name for FN_ is indeed not a good idea.


Top
 Profile  
 
 Post subject: Re: [PATCH] Starting fleets names not looked up in stringtab
PostPosted: Thu Dec 01, 2011 10:40 am 
Online
Programmer and Packager
User avatar

Joined: Wed Nov 16, 2011 12:56 pm
Posts: 761
Location: Sol III
Geoff the Medio wrote:
...I'm not sure if there's any case where fleet plans are made not by parsing, but it'd probably be OK to change the default value of that parameter for FleetPlan to true.

As far as I can tell fleet plans currently are only used to set up the starting fleets, and because of that my first try to solve the issue has been exactly that, changing the default value of that parameter to true. However, I wasn't comfortable with that solution because I thought this flag surely exists and defaults to false for a reason. Maybe there is no apparent use for it now, but whoever wrote that code might had some future use in mind. Not that my solution was any better, on the contrary... :oops: :wink:

Quote:
To replicate the old behaviour, you might be able to pass true to the FleetPlan constructor in the parser.

Well, when in doubt go with the original plan (that already proved to be working), so I decided to replicate the old behaviour. Which I was able to do now, thanks to your hints :)

Quote:
I'm not sure if this needs wrapping in something like val(true) as was required for the old parser...

Definitely needs wrapping - not wrapping leads to crashes, as I just found out. However, I had to use "phoenix::val" instead of just "val". Made a build and ran a quick test game, starting fleet names are back, everything seems to work fine. New patch attached.

Quote:
Inspecting the name for FN_ is indeed not a good idea.

Yeah, that's not a fix, but a hack, and I didn't like it at all. Doing it this way was just asking for trouble. MUCH better now :mrgreen:


Attachments:
Starting_Fleet_Names.patch [575 Bytes]
Downloaded 7 times
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group