Military Patch

Programmers discuss here anything related to FreeOrion programming. Primarily for the developers to discuss.

Moderator: Committer

Post Reply
Message
Author
aphenine
Space Floater
Posts: 23
Joined: Tue Oct 05, 2010 10:15 pm

Military Patch

#1 Post by aphenine »

This is my first patch for FreeOrion. I hope you like it!

Summary:

Patch implements the feature request Ship Names and lays the groundwork for military information storage and handling with a view to implementing fleet lists (as requested in the Programming_Work wiki page under section Fleets Windows) plus some kind of general military dialogue box or screen (pending design discussion?) for general tinkering with all aspects military.

Details:

The patch adds a Military class to Empire, plus a const accessor method GetMilitary(). The Military class is there just to keep things tidy in Empire. The Military class implements the method GenerateFleetName( Fleet & ).

Inside Military, there is a military naming convention parent virtual class which can suggest a name. This is implemented currently using a class called WetNavyNamingConvention, which broadly implements the Fleet Name feature request, with some extra detail for the number of ships, drawn from historic Earth water based navies. This system allows the naming convention to be swapped out and changed during play or testing, with a view to letting players change their naming convention should a dialogue be implemented for this.

Military::GenerateFleetName( Fleet & ) is called in Empire's build complete section, inside Effect and in Order's new fleet creation order.

Testing

Colony fleets are named appropriately when built or split using the UI. Scout fleets aren't handled yet as I haven't figured out how to distinguish them from other unarmed civilian craft (or whether exploration should come under military). War fleet naming is not tested because I couldn't build a war fleet in a reasonable time.

Compiled fine with a build on Monday. No files changed since that directly affect this patch. But thought I'd say, just in case.

Design Rationale:

The obvious thing would have been to change the static function Fleet::GenerateFleetName( ships, fleet id ). I didn't do that because it seemed reasonable that players might want to set up their own default fleet names, based on their own ideas and I felt they should have that option. Empire was the place for that. Also, fleet has lots of useful methods for querying the state of the ships, which would have to be reimplemented if I just used the vector of ships in the static function, and that's just tedious. I also needed to store some variables (the number of fleet of a certain class, so I don't name two fleets the same) and I don't like storing things in static function calls, and since the values are per empire, I felt that a logical place to store them. I also felt that if fleet orders were implemented in the future, it would help having the full fleet variable to use, so you could not only take the composition, but the orders into account when assigning a name (for example, it would be sensible to name ships set to guard system X as the X System Defence Fleet as it would make it easier to track down in any lists).

Known Issues:

I haven't implemented serialisation yet. I also haven't tested it as fully as I'd like, and if someone could give me pointers to testing beyond playing the game until the code gets called, I would be exceedingly grateful! Also, any other things to think of?

I think that I'm doing stuff in a way that's sensible, but I'd really like feedback about the design decisions I made, whether they are OK and whether the project likes what I'm doing and how I'm doing it, before going any further. Please could you let me know what you think?

I also think that I'm heading into design territory and it would be lovely if there was some kind of discussion on the design forum about aspects of this. Obviously that depends on feedback I get here, but I have no idea how to begin about it, although I have a list of questions I would want considered.

The obvious thing is to move ship naming inside Military too. Yes/no?
Attachments

[The extension patch has been deactivated and can no longer be displayed.]


User avatar
pd
Graphics Lead Emeritus
Posts: 1924
Joined: Mon Mar 08, 2004 6:17 pm
Location: 52°16'N 10°31'E

Re: Military Patch

#2 Post by pd »

Nice to see a new contributor.

There was some discussion about the naming of fleets a while ago. Just wanted to make sure you were aware of it.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Military Patch

#3 Post by Geoff the Medio »

I have a few concerns...

I haven't looked carefully, but you appear to be renaming existing fleets in a few places, regardless of whether their names were specified by the player or autogenerated. This probably isn't a good idea... player-set names should generally be kept.

There could be a "Auto-Rename" command in the UI, though, that would decide an appropriate name and apply it. A right-click popup command seems appropriate, similar to the existing Rename commands.

There could also be a flag added to Fleet or UniverseObject to tell the game to automatically rename something whenever the appropriate conditions arise. This way, things could have automatically changing names, but if a player manually sets the name, it would be kept. Exactly how best to implement this, I'm not sure.

I'm not inclined to add a whole extra source file, Military.cpp in this case, for just fleet renaming, or on the assumption that we might in future have use for a "Military" class. If and when there is a need for a Military object that does a bunch more than renaming fleets, then that can be added. But for now, I'd prefer to stick to putting the new name-generating code into an existing file and/or class.

For now, it looks like you could just modify Fleet::GenerateFleetName... preferably this could be done without the need to serialize much, or anything...

Also, for a final submission, you'll need to move all the human-readable strings out of the source code and into a stringtable. The UserString function, and boost::format or FlexibleFormat for string substitutions, can be used for this.

Also, when returning strings that exist as non-function-local data, such as object member variables, prefer returning by const reference to returning by value.

aphenine
Space Floater
Posts: 23
Joined: Tue Oct 05, 2010 10:15 pm

Re: Military Patch

#4 Post by aphenine »

@pd

Thanks for the welcome! I also really appreciate the pointer. Very awesome. In this case I'd already seen it (that's where I got the link from), and why I was worried about bypassing Fleet's call of GenerateFleetName (Geoff the Medio really likes his static function, doesn't he?). I assume the person gave up. I feel a bit bad about poaching their bug, but they've had months to do it and they haven't replied. *shrugs* I hope they don't mind.

@Geoff the Medio

Thank you for looking over the patch briefly.
I haven't looked carefully, but you appear to be renaming existing fleets in a few places, regardless of whether their names were specified by the player or autogenerated. This probably isn't a good idea... player-set names should generally be kept.
No you haven't looked carefully. Yes, I use rename a lot, but that's because I need the fleet set up first before I can evaluate it for a name, and most of the functions pre-assume an existing name, so I got with the flow and rename afterwards. I can assure you that the rename in the new Fleet Order checks to see whether the name is autogenerated and only changes it then. The other two applications (there are only three) rename fleets that don't appear to exist yet, so I didn't need to perform a check. It may be simpler to create a new and separate create fleet command which uses the default name rather than hacking the existing one, or to use a set default string (e.g. "") to pass to the create new fleet order to trigger name generation, but I wanted to run that by the project first.
There could be a "Auto-Rename" command in the UI, though, that would decide an appropriate name and apply it. A right-click popup command seems appropriate, similar to the existing Rename commands.

There could also be a flag added to Fleet or UniverseObject to tell the game to automatically rename something whenever the appropriate conditions arise. This way, things could have automatically changing names, but if a player manually sets the name, it would be kept. Exactly how best to implement this, I'm not sure.
These are good ideas, but I didn't want to go that far without running them through someone else first. They may also not be necessary (see above). Fleets being created by drag and drop pose a problem as they get created in small chunks, so it makes sense to have an autorename button or command for when you're done (or if a fleet's circumstance changes e.g. your system defence fleet suddenly goes aggro). If you're good with that, I shall implement this when I start playing with the interfaces.
I'm not inclined to add a whole extra source file, Military.cpp in this case, for just fleet renaming, or on the assumption that we might in future have use for a "Military" class. If and when there is a need for a Military object that does a bunch more than renaming fleets, then that can be added. But for now, I'd prefer to stick to putting the new name-generating code into an existing file and/or class.
Um... didn't I say that? You know, in the post? I really, really want to add things to the Military class. Very soon. If you refuse to approve the Military class because I haven't written enough for it yet meaning that I can't write more for the Military class so you can approve it, I'll scream. Really I will. You're a human. You're not supposed to have circular dependency errors. That's what computers are for.
For now, it looks like you could just modify Fleet::GenerateFleetName... preferably this could be done without the need to serialize much, or anything...
Um, well, yes, if I excised the FleetClass map and stopped recording how many I had created of each class, I could do that... But that would make the whole thing less cool and leave me at risk of duplicating fleet names at the moment. Please can I bypass Fleet::GenerateFleetName? I promise the project will not spontaneously collapse into a black hole if I do. I gave some really good reasons in the post. And it'll make a lot of sense if any of the future stuff in the programming work wiki is actually true.
Also, for a final submission, you'll need to move all the human-readable strings out of the source code and into a stringtable. The UserString function, and boost::format or FlexibleFormat for string substitutions, can be used for this.

Also, when returning strings that exist as non-function-local data, such as object member variables, prefer returning by const reference to returning by value.
Ah, now these are useful. The string tables are for internationalisation, I take it? I remember the static Fleet::GenerateFleetName has an example. I can also see why you want me to return the references. Very good. Thank you. I shall make these changes and get back to you.

User avatar
Bigjoe5
Designer and Programmer
Posts: 2058
Joined: Tue Aug 14, 2007 6:33 pm
Location: Orion

Re: Military Patch

#5 Post by Bigjoe5 »

aphenine wrote:Um... didn't I say that? You know, in the post? I really, really want to add things to the Military class. Very soon. If you refuse to approve the Military class because I haven't written enough for it yet meaning that I can't write more for the Military class so you can approve it, I'll scream. Really I will. You're a human. You're not supposed to have circular dependency errors. That's what computers are for.
Didn't you know? Geoff is an engineer. :)

(Also, effectively the lead of just about every aspect of this project right now.)
Warning: Antarans in dimensional portal are closer than they appear.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Military Patch

#6 Post by Geoff the Medio »

aphenine wrote:I really, really want to add things to the Military class.
Could you elaborate on what you want to add to the Military class?
Please can I bypass Fleet::GenerateFleetName?
Yes, I think you've made a case for it.
The string tables are for internationalisation, I take it?
Yes.
Bigjoe5 wrote:Geoff is an engineer.
While I do have at least one engineering degree, I'm neither licensed nor working as an engineer.
(Also, effectively the lead of just about every aspect of this project right now.)
Not graphics, certainly.

aphenine
Space Floater
Posts: 23
Joined: Tue Oct 05, 2010 10:15 pm

Re: Military Patch

#7 Post by aphenine »

Could you elaborate on what you want to add to the Military class?
Most certainly.

As a general principle, I wish to use the Military class as the backend for some kind of military screen/overlay/pop-up (I haven't figured out which yet might be best yet and would like to ask about that). I also think about it as a class containing all the information the Ministry of Defence (if you had one) would normally handle for your Empire, as well as holding all global level data for your Empire's military.

I do have some specific ideas about what to add to the Military class that I think go with the game's current plans and shouldn't be too contentious:

* Naming and eyecandy: let users select how they name ships and fleets and control how their military is named and represented.
* Fleet lists and intelligence: I'd like to implement methods that either: will scan through the UniverseObject lists in the main map to return a list of friendly, allied, neutral or foreign fleets depending on user input; or maintain a map/list/vector of friendly fleets and the same for enemy fleets (but also including data about where they were last seen). These methods would be used by the eventual screen/overlay/pop-up in order to present the information to the user. I think this kind of thing has to be a pop-up or overlay in order to allow the map to jump to whatever is selected at the very least. This is what I'd move on to next if I continued with the class.
* Statistics: Various useful statistics to help aid decision making and the AI, including number of fleets, their main type and composition (e.g. scout/constructor/defensive/offensive/transport) and how many ships you have of certain types (if this isn't already represented in the ship designer classes, which I think it might be). I'm thinking of standardising the classification system for fleets and letting the Military class handle this, and then passing the results to the naming convention, rather than letting the naming convention figure it out, but I haven't decided yet.
* Default Rules of Engagement: Pretty much every military has rules on how to proceed in certain situations, called their Rules Of Engagement. From stuff like what to do about unidentified ships closing in to how to behave towards neutral powers you haven't signed any treaties with to how far you support your allies. A military class would be the logical place to put this info into and it would help avoid a lot of pointless pop-ups and decisions where you already know what you want your military to do. At the least it would help avoid MoO3 style pointless battles in shared systems and where two scout craft have met for the first time (unless you really really want to kill everyone you meet, and are a big fan of shoot first and ask questions later).
* Waypoints and Missions: There's a plan to create waypoints for fleets, and I assume that also means controlling what happens when a fleet reaches it (e.g. attack, colonise, move) which for now I'll call a mission. So this means it's probably a good idea to have some default settings for newly built ships, so that they can be assigned a mission (probably planetary or system defence). That would probably be best combined with Rules of Engagement.

I also have a few crazy ideas about how the game might progress in the future with regards to military stuff which would require global empire-level military settings, not to mention other people might have some ideas too. I think the Military class would be very useful for them. Some examples of things that are floating around in my head:

* Organisation: Most militaries organise their fleets and units in specific structures which they raid for Task Forces later on. I'd like to implement something similar, and make some function available to help organise fleets, call them together for action and disperse them over several systems/planets when done. Maybe also make some tools so that, rather than building ships in various places and pulling them together, you might also say to your Empire "I want such and such a fleet assembled at such and such planet" and the Military class makes it happen.
* Readiness: I'd like to make the maintenance amounts of fleets (and how much fuel and supplies they use) adjustable regarding readiness. So, for example, a defensive fleet on low readiness utilises half it's maintenance but suffers a half drop in combat capacity, as well as decreased sensor range, while the same fleet on high readiness would have boosted sensor range (because it would be patrolling actively) and a boosted combat capacity while burning through supplies and money. The central military class should have the ability to raise and lower states of readiness for your whole fleet, much like the DefCon system in the United States.
* Military Intelligence: What you know about the enemy fleets, systems and defences in a military way might all go in here, or if it's handled elsewhere,it might go here but with a military slant.
(Also, effectively the lead of just about every aspect of this project right now.) / Not graphics, certainly.
That's good to know. I'd guessed that this was true for programming, which is why I'm trying to get approval for what I'm doing and be open about what I'm thinking, but it's nice to have it spelt out ;)
Please can I bypass Fleet::GenerateFleetName? / Yes, I think you've made a case for it.
Yay! Thank you!
While I do have at least one engineering degree, I'm neither licensed nor working as an engineer.
Ah. But it does tend to get you to think in a certain way, doesn't it? I found that with my physics degree. As one example, physics used to play havoc with my time keeping. I am going to event X where I must do small tasks A, B and C before I go. Duration of A << duration of X and same for B and C, therefore each can be neglected for the purposes of time calculation. Dammit, why am I late for X? Again? *shakes head* I'm much happier now I've stopped doing that, and am very rarely late.

User avatar
Bigjoe5
Designer and Programmer
Posts: 2058
Joined: Tue Aug 14, 2007 6:33 pm
Location: Orion

Re: Military Patch

#8 Post by Bigjoe5 »

aphenine wrote:
While I do have at least one engineering degree, I'm neither licensed nor working as an engineer.
Ah. But it does tend to get you to think in a certain way, doesn't it? I found that with my physics degree. As one example, physics used to play havoc with my time keeping. I am going to event X where I must do small tasks A, B and C before I go. Duration of A << duration of X and same for B and C, therefore each can be neglected for the purposes of time calculation. Dammit, why am I late for X? Again? *shakes head* I'm much happier now I've stopped doing that, and am very rarely late.
That was mainly meant as a joke, as I'm a student of engineering myself. Generally, if you have a good idea, you shouldn't have a great deal of trouble getting approved by Geoff (or any relevant FO lead).
Warning: Antarans in dimensional portal are closer than they appear.

Post Reply