Unit Icons Added By Conditions


  • Admin

    Ever wish you could add a small indicator on units that are improved when you research a tech? Or when some condition is met? Well I think this would be a cool addition especially for maps that use tech/conditions to alter unit options.

    The idea would be to allow map makers to specify a properties file that references a condition, unit type, and image. If the condition is true then the specified image is layered onto the unit images for that type (similar to how unit flags work). You could have multiple images added to the same unit type and they would be layered in the order specified in the properties file.

    unit_icons.properties example:
    Total_World_War__December_1941.Germany.germanFighter;conditionAttachmentgermanImprovedFighters=gold_star.png
    Total_World_War__December_1941.Germany.germanNavalFighter;conditionAttachmentgermanImprovedFighters=gold_star.png
    Total_World_War__December_1941.Germany.germanFighter;conditionAttachmentgermanIncreasedFighterRange=increased_range.png
    Total_World_War__December_1941.Germany.germanBunker=german_flag.png (always true)

    PR: https://github.com/triplea-game/triplea/pull/3451

    Tested (TWW)

    • Created property file (map/unit_icons.properties):
    Total_World_War__December_1941_BETA.Germany.germanNavalFighter=air.png
    Total_World_War__December_1941_BETA.Germany.germanFighter;conditionAttachmentgermanImprovedFighters=air.png
    
    • Create unit icon image (map/unitIcons/air.png):
      air
    • TEST: Unit icon is applied to german naval fighters on game started
    • TEST: Unit icon is applied to german fighters when Germany researches and activates Improved Fighters

  • Donators Moderators Admin

    @redrum 0_1528263189834_New icon proposal.png

    Here's a conceptualization.

    unit_icons.properties example:
    Global_Domination.conditionAttachmentjapanImprovedFighters.japanFighter=green_piece.png
    Global_Domination.conditionAttachmentjapanIncreasedFighterRange.japanFighter=yellow_piece.png
    Global_Domination.conditionAttachmentjapanImprovedEngines.japanFighter=red_piece.png



  • Similar system could potentially be used for stack numbers. By layering premade images over the unit.


  • Moderators

    @redrum Not a clear user case myself, as I'm not sure how much I like tech, but I'm thinking it would be good having an additional reference for the unit owner. The basic concept of tech itself is to differentiate the same unit for different players (unlike TWW, that has mostly player specific units).
    Also having the possibility of always having it (tho you could have it by having a condition that is always true), so you can simply use it for multi-layered images; like having flags (270BC...) or red dots (NWO...) not as part of the basic picture, even tho they would be always there, anyways.



  • @redrum Oh wow, now that I think of it, this feature would solve what would have been a huge challenge implementing a feature for Fallen Empire. No need to hurry though, It's not going to be in the alpha version.


  • Moderators

    @redrum Also maybe being able to change the unit image totally, instead of just adding another on top of it. This is how the hardcoded techs work, like when you get JetFighter.
    I definitely think the term "decoration" is not good here, as this is probably something you want to use not for mainly decorative aims.


  • Admin

    @cernel

    1. How about icons instead of decorations? I don't really care that much about the name so whatever the consensus is.

    2. Yeah, having an option for always TRUE for things like flags/dots/etc that you want to always have on certain unit images is probably useful to avoid needing filler conditions and that would probably be easy by having the option to specifying 'TRUE' or 'ALWAYS' instead of a condition name.

    3. I guess having the player name as well would help for cases where you don't have player specific units and say want different icons on the same unit type for different players.

    4. I did think a little about completely replacing unit images as well and kind of arguments for both sides. It adds another parameter and a bit of complexity. Are there good use cases or if you are completely replacing the image then should it really be a different unit? Starts to get to what really is a 'unit' as I find the JetFighter example feels strange on most maps as all my units suddenly look like an entirely different image (though might be because of the drastic difference in the unit image that most maps use instead of just adding some stripes or something which could be achieved with icons then).


  • Admin

    PR: https://github.com/triplea-game/triplea/pull/3451

    Tested (TWW)

    • Created property file (map/unit_icons.properties)
    Total_World_War__December_1941_BETA.Germany.germanNavalFighter=air.png
    Total_World_War__December_1941_BETA.Germany.germanFighter;conditionAttachmentgermanImprovedFighters=air.png
    
    • Create unit icon image (map/unitIcons/air.png)
      air
    • TEST: Unit icon is applied to german naval fighters on game started
    • TEST: Unit icon is applied to german fighters when Germany researches Improved Fighters

  • Donators Moderators Admin

    @redrum So where do these go?

    Is there a complete example of this somewhere?


  • Admin

    @hepps In the bolded paths above. Essentially just need to do 2 things:

    1. Add unit_icons.properties file to your map directory with at least 1 valid line
    2. Add unitIcons folder and an image inside to your map directory

    I'll add an example to POS2 repo once the PR merges.


  • Donators Moderators Admin

    @redrum

    Is there a changelog for pos2 xml?


  • Admin

    @general_zod Yep: https://github.com/triplea-maps/the_pact_of_steel/commits/master/map/games/pact_of_steel_2.xml

    Essentially those should mostly line up with either things that were identified as missing from POS2 XML or things completed from the features list: https://forums.triplea-game.org/topic/182/guidelines-and-feature-request-list


  • Donators Moderators Admin

    @redrum I like the idea in general. But I wonder if it can be, even more constructive with abilities similar to those of the hard coded techs, which swap images completely.


  • Admin

    @general_zod Overriding (or swapping) the unit images would be possible to add into this feature as well (@Cernel mentioned that too). I couldn't think of a lot of good use cases though. The hard coded techs is one use case though IMO not really a good one as seeing bombers magically change into like stealth bombers with bomber range is researched seems weird and they should probably just have some icon added to them. Can you think of some good examples?


  • Donators Moderators Admin

    Very excited about this! For TWW this will immediately solve the problem of great games ending horribly due to a player not remembering an enemy has a technology that can dramatically affect battles. And all without having to make 400 extra units and unit images!

    Here is some light TWW porn....

    0_1528477816251_Example for new Icons with explanations.png

    I couldn't be happier with this development! GREAT WORK (as always) Red! You are truly a God amongst men.


  • Admin

    @hepps Looks cool. Out of curiosity, any reason for not putting them all in the bottom right or top left?

    You also might want to tone down the lime green just a tad.


  • Donators Moderators Admin

    @redrum I'll give it some more thought and get back to ya.


  • Donators Moderators Admin

    @redrum What you got against lime green anyway? That's like the third time you've dissed the lime green! 🙂

    I was trying to avoid covering distinguishing parts of certain unit images. Very preliminary work done within 1/2 an hour of seeing this new feature come to fruition. Just take a pill... or a Bourbon... or both. Revisions will come when I sit down with my partner to finalize the designs. 🙂


  • Admin

    @hepps Lol. It hurts my eyes! Definitely could use a pill and a Bourbon right now but have a few more hours of work to survive first. TGIF!


  • Moderators

    So you are going for adding a folder for these images. This makes me think it'd rule out the switch alternative to support, as it would be weird to have the new image outside the "units" folder, and it would not make sense to be defined as an icon for the starting image, anyway.
    I'm unconvinced about this, especially on the account that of the few hard-coded techs, changing unit images, we have, few of them work in the way of adding any icons (I think the only case are heavy bombers, AA radar and rockets), but in the way of changing the image itself, either totally (improved factories etc.) or by adding a couple white stripes or such (super submarines etc.).
    Of course, one could hack an image changing by just having the basic image totally transparent, and adding the icons on top of it as the actual images, making sure you start with an icon and the condition of the first one becomes false when the new one is true.

    I don't have any particular examples in mind, as, as I said, I'm not huge on tech (both as a maker and as a user) and I'm not sure how can you get examples, in the moment, so far, anything like this has been limited only to a part of the few hard-coded techs available. I don't even know if and how I would be using this feature. But, in general, having the possibility of changing the image completely should feel of superior quality. All your fighters becoming jets, when you get the tech, is obviously silly, but you can have more sensible examples, like warriors turning into werewolves, Gandalf turning from grey to white, cavemen turning into spearmen, a battleship getting a radiotelemetre, or a factory looking more modern, rather than having an icon beside that tells you now it is more modern (kinda cheap). Beside, if this is not supported, I can see mapmakers hacking it by just assuring that the new image completely covers the old one (or by even more devious means...). The long range fighters, on the other hand, receiving a couple of white stripes is not making a lot more sense: just paint some stripes on the wings, they'll fly better. Not like that having the image not changing completely helps making more sense, I tend to think.
    Anyway, probably the strongest argument is that icons telling what is what are likely suboptimal with respect to an integrated approach, as you, then, need to watch several images to know about one unit. From my point of view, even only adding two stripes to a fighter is more user friendly than adding an icon beside to tell that is an advanced version of the former. Like, I would not advice to substitute all Adv.Fighter in WAW with regular fighters images with an "A" symbol or something beside, no matter how much the current stripes solution is cheap, anyway.
    It is basically the same reason why (as long as you have 12 or less players) it is better having units ownership depending on colours, than adding a flag or any symbol beside, to tell the ownership.

    On the name, it depends on what this is going to be.
    If it is going to be just an overlay thing, like decoration would imply, i don't think "Icon" is good, either, as it makes me rather think of something stand-alone (like it would be fitting if you want to add a small side-image highlighting some stuff regarding the unit, but here we could also use this thing to add white stripes for long range or whatever, and that would definitely be not an icon). In such a case, I'd call it "Unit Indicators", if that would sound fine to the average English speaker (or signage or such).
    However, icon would be good enough as a title of this thread if you go for an integrated approach using the current basic "units" folder, without adding another folder specifically for this feature (and, in this case, the only name we need to add is only how to call the properties file, that would be the only addition).

    So, my suggestion is not adding any "unitIcons", or whatever, new folder, but doing everything inside the current "units" folder. For the iconic part of it, the icons of general use would stay directly inside the "units" folder (where currently nothing is referenced, anyways), while player specific icons would go inside the players subfolders, with the unit images they are for.

    So, instead of making some overlay thing on top of the current units stuff, I would rather go for expanding what is supported via the "units" folder itself only, by allowing defining multiple layers for images, that would also cover all what at this feature request (and more).

    First of all, before getting to the conditions part, expanding the functionality of the current "units" folder system, by allowing having images directly in it, instead of in the players subfolders.
    When a unit image is called, the engine will search for it in the player subfolders (just like now) and, if not finding it in it, it will, then, search for it directly in the general "units" folder (and, then, go searching in the program assets, of course, the same way).

    All images for this feature would stay in the current "units" folder, as well (so not adding another folder for these things), and the property sheet being called "unit_display.properties".
    Inside such file, you would have entries like:

    info_name.unit_name.player_name.conditionAttachment=image_name

    The "info_name" being the info name for the game, that defines what xml we are using (that is what game we are referring to).
    The "unit_name" being the name of the unit inside that xml.
    The "player_name" being the name of a player inside that xml.
    The "conditionAttachment" being a condition defined inside that xml.
    The "image_name" being the name of the image file.

    Assuming everything else is self explanatory, the way "conditionAttachment" works is that it is a check that is true if the condition is true.
    The first two entries are mandatory.
    The third and fourth entries are optional, and both (the "player_name" and the "conditionAttachment") are always true, if absent.

    So, you can also have:

    game_name.unit_name.player_name=image_name

    And this would always apply, to that player only.

    And you can also have:

    game_name.unit_name.conditionAttachment=image_name

    And this would apply to all players, if the condition is true.

    Or you can just have:

    game_name.unit_name=image_name

    This always applying to all players.

    I guess all the above would be feasible by the engine checking how many entries and, in case of three, if the third one starts exactly as "conditionAttachment" or not.

    For using this feature as a simple overlay (merely as an alternative to having it directly in the image itself, as per the only current practice), in a map like Napoleonic Empires, in which the ships are the same for everyone, but with different flags, you can have the ships images directly in the "units" folder, plus a single "flag" image per each player subfolder.
    Then, in the "unit_display.properties" you would have:

    Napoleonic_Empires.Cutter=Cutter.png
    Napoleonic_Empires.Cutter=flag.png

    So, everyone will get the same "Cutter" image, while the players will get different "flag" image, but this is not to be specified in the properties, as it just depend on the positions in the units folder, as said.
    Of course, switched over, if, instead, you want the Cutter to be superimposed to the flag.

    If and only if the unit_display.properties is absent or no entries are present or no entries are valid (for that player or at all), then the default image is used.

    If any entries in unit_display.properties are valid, then the default is not used at all (so, nothing is superimposed to the default: to superimpose you need to specify what would be the default in the properties, as an always true entry).

    If you want entries in properties to not superimpose, you just need to assure that the condition of the first entry becomes always false when the condition of the second entry is true, in the xml (you need to code the condition accordingly). I believe this would mean that TWW would superimpose after the first, if I'm assuming correctly that when you get a new level of the same kind of tech, the preceding one remains true.

    For example, inside the property sheet, you can have only an entry like this, if you want the unit to be completely changed:

    Total_World_War_December_1941.germanFighter.conditionAttachmentgermanImprovedFighters=fighter_improved.png

    In this case, normally, the unit displayed is the default one (like not having an entry, when the entry is not valid). When the condition is true, instead, the "fighter_improved" is displayed, in substitution.

    On the other hand, if you want to just have a overlay, you would have an entry like this:

    Total_World_War_December_1941.germanFighter=fighter.png
    Total_World_War_December_1941.germanFighter.conditionAttachmentgermanImprovedFighters=gold_star.png

    In this case, the "gold_star" image would be just superimpose to the always true "fighter" image.

    In both the above cases the "player_name" is absent, thus this will apply to any "germanFighter" units in the map, regardless of ownership.

    On the other hand, I tend to think that one should not code the xml thinking about skin elements, so it would be rather better having:

    info_name.unit_name.player_name.conditionAttachment1:conditionAttachment2:...:conditionAttachmentN.conditionType=image_name

    When conditionType can be AND, OR, etc. (what's supported for triggers).

    So, to be clear, what I'm saying is that you don't really need to make a way to define if stuff superimpose or replace, but you can have that it just always superimposes, and assure the lower levers to disappear (not being drawn anymore), when wanted, by conditions.

    Moreover, it would be good also the "player_name" allowing for multiple (but you can just repeat the entry as many times as you need to; so I'm not sure about this).

    p.s.: A remaining matter to define, then, would be if this feature should be switchable by the user and which way. This really needs to be sorted out, as well, since, for example, you should never be able to switch off the flags of the ships of Napoleonic Empires, as that is the only way to differentiate them by ownership. So, if I would make something like that, and this feature would be optional, I would still have the flags in the image themselves, to avoid them being ever not displayed. Probably, to keep it simple, just having a single entry in properties that define if everything or nothing can be turned off, by the user (when turned off, it would be like the map having no unit_display.properties).