Page 1 of 2 12 LastLast
Results 1 to 20 of 22

Thread: [SUBMOD] Script for changing sprite draw distance

  1. #1

    Default [SUBMOD] Script for changing sprite draw distance

    This should work with any version of EBII.

    The unit sprites - the 2D pictures of units that replace the 3D models when you zoom out - are drawn at a pretty short distance in EBII. To increase that distance, one has to edit numbers in lots and lots of lines in the modeldb file (I explain here how to do it manually), which is very tedious. So I wrote a quick Python 3 script to do that automatically instead, and thought I would share it in case anyone wants to use it!

    Disclaimer: I made this for my own use and have only done a bit of testing. Use at your own risk! Always make backups! I do not take responsibility for anything that might go wrong.

    How to use:
    1) Install Python 3 if you don't have it (go here: https://www.python.org/downloads/ and pick the latest version of Python 3).
    2) Download the attached file increase_sprite_distance.zip from this post (or copy the code below and paste it into a new file that you name with a .py extension), unzip it, and put the unzipped .py file in the folder .../Medieval II Total War/mods/ebii/data/unit_models
    3) Run the file with Python3. You will be promted to enter a number to multiply the draw distance by, for example 3 or 4.5
    4) A new file called battle_models_EDITED.modeldb will appear. move the original file; battle_models.modeldb, to some other location and remove "_EDITED" from the name of the new file.
    5) Play!

    To undo the changes, just paste the original battle_models.modeldb into .../Medieval II Total War/mods/ebii/data/unit_models and overwrite.

    Mods: I hope it is okay to post scripts in this forum. It's trivial to open the file with a text editor to make sure it does what I claim it does. This is the code in the attached file:
    Spoiler Alert, click show to read: 

    Code:
    # Author: Paltmull
    # Script to edit distance for unit detail in EBII.
    # Place file in same folder as battle_models.modeldb.
    # Input number can be a floating point number or an integer.
    
    from math import floor
    
    mul = float(input('Enter number to multiply draw distance by: '))
    
    with open('battle_models.modeldb', 'r') as infile:
        with open('battle_models_EDITED.modeldb', 'w') as outfile:
            for line in infile:
                words = line.split()
                if len(words) == 3 and words[1].endswith('.mesh'):
                    words[2] = str(floor(float(words[2]) * mul))
                outfile.write(' '.join(words) + '\n')
    
    print('Saved to "battle_models_EDITED.modeldb"')
    input('Press enter to exit.')


    Note: If you want to remove the drawing of sprites altogether, then you can simply open medieval2.preference.cfg in the Medieval II main folder and set unit_detail to highest rather than using this.
    Note2: I don't know what maximum integer value they use. If it's low, setting too high a factor could cause weird behavior. But you remembered to save the original file, right?
    Attached Files Attached Files
    Last edited by Paltmull; April 22, 2017 at 10:57 AM.

  2. #2

    Default Re: [SUBMOD] Script for changing sprite draw distance

    Nice, I can't wait to try this out!

  3. #3

    Default Re: [SUBMOD] Script for changing sprite draw distance

    It doesn't seem to work. The script doesn't spit out any new files (whether or not the old one is in that folder).

  4. #4

    Default Re: [SUBMOD] Script for changing sprite draw distance

    Ahh, nevermind. Script does work after all.

  5. #5
    VektorT's Avatar Biarchus
    Join Date
    Oct 2008
    Location
    Brazil
    Posts
    694

    Default Re: [SUBMOD] Script for changing sprite draw distance

    Oh, that's something I was waiting for a while! Thanks!

  6. #6
    Yerevan's Avatar Campidoctor
    Join Date
    Mar 2012
    Location
    Germany
    Posts
    1,504

    Default Re: [SUBMOD] Script for changing sprite draw distance

    Quote Originally Posted by Petrobras View Post
    Oh, that's something I was waiting for a while! Thanks!
    Me too :-)

    Thanks Paltmull !
    " Gentlemen, you can't fight in here! This is the War Room! "

  7. #7
    shogon's Avatar Civis
    Join Date
    Dec 2012
    Location
    Manteca, CA
    Posts
    181

    Default Re: [SUBMOD] Script for changing sprite draw distance

    Indeed, thank you Paltmull
    40%
    40%
    40%
    40%
    "
    It's a real upgrade, and we're not even halfway to alpha."

  8. #8

    Default Re: [SUBMOD] Script for changing sprite draw distance

    This is amazing, no more ugly sprite armies unless zoomed in. \o/

    Really needs to be promoted more so all EB 2 players can put this to use.

  9. #9

    Default Re: [SUBMOD] Script for changing sprite draw distance

    What's the maximum draw distance?

  10. #10

    Default Re: [SUBMOD] Script for changing sprite draw distance

    Quote Originally Posted by Atilla View Post
    What's the maximum draw distance?
    I'd guess it's only limited by whatever range they use for the the integers that represent the distances. So for example a signed 16-bit integer would give a max of 32,767 while a signed 32-bit integer would give a max of 2,147,483,647, and 65,535 or 4,294,967,295 for unsigned integers. So if max is 65,535 and the highest value in battle_models.modeldb is for example 6400, then you shouldn't use a factor higher than 10. You'll probably notice if you've set it too high, with glitches and/or crashes. If you're gonna use values that high you'll be better off just disabling the sprites altogether by setting unit_detail to highest in medieval2.preference.cfg.

    I added a note in the original post regarding this.

    Thanks all, btw! Glad it's working!
    Last edited by Paltmull; April 22, 2017 at 10:58 AM.

  11. #11

    Default Re: [SUBMOD] Script for changing sprite draw distance

    Quote Originally Posted by Atilla View Post
    What's the maximum draw distance?
    If performance isn't a concern, you can simply open medieval2.preference.cfg in Notepad++ and change unit_detail = highest . Save the file, then right click on it, hit properties, and set the file to "read-only" (to prevent the game from reverting your settings). This will ensure that all units are rendered in full 3D at all times.

    edit: beaten!

  12. #12
    Gigantus's Avatar I am not special - I am a limited edition.
    Patrician took an arrow to the knee spy of the council

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    53,125
    Blog Entries
    35

    Default Re: [SUBMOD] Script for changing sprite draw distance

    Quote Originally Posted by HaHawk View Post
    If performance isn't a concern, you can simply open medieval2.preference.cfg in Notepad++ and change unit_detail = highest . Save the file, then right click on it, hit properties, and set the file to "read-only" (to prevent the game from reverting your settings). This will ensure that all units are rendered in full 3D at all times.

    edit: beaten!
    Rather use the in-game video options (options\video\advanced) to make this setting and don't forget to click 'apply' once done. Making the default CFG file read-only will disable the CFG file for future setting changes.

    Alternatively add the entry to EBII's CFG file in the [video] section.


    Rule of thumb: don't manually change settings in the default CFG file, use the mod's CFG file to do this. The default CFG file's entries will be updated with the mod's CFG file's settings.










  13. #13

    Default Re: [SUBMOD] Script for changing sprite draw distance

    Quote Originally Posted by Gigantus View Post
    Rather use the in-game video options (options\video\advanced) to make this setting and don't forget to click 'apply' once done. Making the default CFG file read-only will disable the CFG file for future setting changes.

    Alternatively add the entry to EBII's CFG file in the [video] section.


    Rule of thumb: don't manually change settings in the default CFG file, use the mod's CFG file to do this. The default CFG file's entries will be updated with the mod's CFG file's settings.
    Setting "unit detail" to "highest" in the in-game settings will actually set it to "higher" in the CFG, and at that setting sprites will still be used. So there is no way to get rid of sprites altogether using the in-game settings.

  14. #14
    Gigantus's Avatar I am not special - I am a limited edition.
    Patrician took an arrow to the knee spy of the council

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    53,125
    Blog Entries
    35

    Default Re: [SUBMOD] Script for changing sprite draw distance

    I wasn't aware of that - then it's best to add the line to the mod's CFG file.

    I just added that entry to my trusty Bare Geomod's CFG file and started a quick battle. It involved 13 units on my side and the lag (which I never have with that low number of units) was noticeable. After exiting I checked the default CFG file and the value (unit_detail = highest) was transferred - I will however change it to high as the lag is simply too high without sprites, I won't bother trying siege battles with multiple stacks. I'll rather use the script method from the OP.










  15. #15
    Campidoctor
    Join Date
    Jan 2005
    Location
    AEnima City, USA
    Posts
    1,646

    Default Re: [SUBMOD] Script for changing sprite draw distance

    I'd suggest people who have pretty good rigs to try the cfg method first to see how it runs for them. I've been playing that way for a long time (runs smooth for me) and can't imagine going back to sprites. The battlefield is so gorgeous from so many different angles!

  16. #16

    Default Re: [SUBMOD] Script for changing sprite draw distance

    Bump! This should work fine for 2.3 too!

  17. #17

    Default Re: [SUBMOD] Script for changing sprite draw distance

    Indeed. works very well for me

  18. #18

    Default Re: [SUBMOD] Script for changing sprite draw distance

    It used to work in 2.2 for me but now it crashes on startup in 2.3. D:
    The only thing you cannot do with a bayonet is sit on it. Charles Maurice de Talleyrand-Périgord,1st Prime Minister of France, Prince of Benevento.

  19. #19
    Gigantus's Avatar I am not special - I am a limited edition.
    Patrician took an arrow to the knee spy of the council

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    53,125
    Blog Entries
    35

    Default Re: [SUBMOD] Script for changing sprite draw distance

    Try using another multiplier value.










  20. #20

    Default Re: [SUBMOD] Script for changing sprite draw distance

    Tried another one. Still crashes. Could it be related to using an old version of Python? I got one that had an installer as I couldnt figure out the new ones which no longer use one.
    The only thing you cannot do with a bayonet is sit on it. Charles Maurice de Talleyrand-Périgord,1st Prime Minister of France, Prince of Benevento.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •