Page 1 of 3 123 LastLast
Results 1 to 20 of 48

Thread: Global cost editor

  1. #1

    Default Global cost editor

    Hey all,

    I have created a simple tool with which you can easily make basic changes to the costs of all units in export_descr_unit.txt and buildings in export_descr_buildings.txt by multiply them with a specific factor or to add/detract specific values from them. Decimals and negatives are allowed.

    Here's what the latest version looks like:



    If you find any bugs/issues please tell me!

    ============ How to use it ============

    1. Extract the zip after downloading and place the "Cost editor (global).exe" inside your modfolder. (or main RTW, BI or ALX folder if non-modfoldered)

    2. Launch the editor.

    3. Type whatever factor you like in the text box left of the appropriate convert button.

    4. Press any "Calculate new costs" button.

    5. A new EDU/EDB will be generated on your desktop.

    6. Back-up your current EDU/EDB.

    7. overwrite the mod EDU/EDB with the newly generated one.

    8. done.


    ============ Download ============

    Latest version:
    Version 3.0 - DOWNLOAD

    ========================

    Regards,
    PatricianS
    Last edited by Pat89; September 06, 2010 at 08:51 AM.

  2. #2

    Default Re: Global unit cost editor

    Looks great for changing costs and keeping the game balanced

    +rep Pat

  3. #3

    Default Re: Global unit cost editor

    Thanks

    I fixed a small (but important ) error... I made a typo in the form of an additional "\" which mean that the editor couldn't find the EDU in the first place

    DOWNLOAD

  4. #4
    RedFox's Avatar When it's done.™
    Join Date
    Nov 2006
    Location
    Estonia
    Posts
    3,027

    Default Re: Global unit cost editor

    PatricianS: Nice tool! I'm really glad to see that people in this community have come together to make modding RTW more fun and not let it die.

    A few words of advice though. You should cast the calculated result into an integer instead of a floating point number. This is rather easy to do in C# (I'm not really sure what you coded it in):

    Code:
                string line;
                string[] t;
                int[] n = new int[7];
                double input=0.66;
                char[] dlm={' ', '\t', ','};
                /////    {0}          {1} {2}  {3}  {4}  {5}  {6}
                line="stat_cost        1, 860, 390, 100, 200, 860";
                Console.WriteLine(line);
                t=line.Split(dlm, StringSplitOptions.RemoveEmptyEntries);
                // parse strings 2-6 to integers
                for (int i=2; i<=6; i++)
                {
                    int.TryParse(t[i], out n[i]);
                    n[i]=(int)(n[i]*input); // this is the cast
                }
                line="stat_cost        "+t[1]+", "+n[2]+", "+n[3]+", "+n[4]+", "+n[5]+", "+n[6];
                Console.WriteLine(line);
                Console.ReadKey(true);
    And output would be following:
    Code:
    stat_cost        1, 860, 390, 100, 200, 860
    stat_cost        1, 567, 257, 66, 132, 567
    This method is a bit faster than what you're doing at the moment. I tried your program and it took 2-3 seconds to complete. This one takes less than a second if you use a conditional"if (line.StartsWith("stat_c", StringComparison.Ordinal))".

    Also, I'm not really sure why the program is 896kb.. How many lines of code is it? Unused project assets being included?

  5. #5

    Default Re: Global unit cost editor

    Thanks for your comments!!

    Quote Originally Posted by RedFox View Post
    PatricianS: Nice tool! I'm really glad to see that people in this community have come together to make modding RTW more fun and not let it die.

    A few words of advice though. You should cast the calculated result into an integer instead of a floating point number. This is rather easy to do in C# (I'm not really sure what you coded it in):

    Code:
                string line;
                string[] t;
                int[] n = new int[7];
                double input=0.66;
                char[] dlm={' ', '\t', ','};
                /////    {0}          {1} {2}  {3}  {4}  {5}  {6}
                line="stat_cost        1, 860, 390, 100, 200, 860";
                Console.WriteLine(line);
                t=line.Split(dlm, StringSplitOptions.RemoveEmptyEntries);
                // parse strings 2-6 to integers
                for (int i=2; i<=6; i++)
                {
                    int.TryParse(t[i], out n[i]);
                    n[i]=(int)(n[i]*input); // this is the cast
                }
                line="stat_cost        "+t[1]+", "+n[2]+", "+n[3]+", "+n[4]+", "+n[5]+", "+n[6];
                Console.WriteLine(line);
                Console.ReadKey(true);
    And output would be following:
    Code:
    stat_cost        1, 860, 390, 100, 200, 860
    stat_cost        1, 567, 257, 66, 132, 567
    This method is a bit faster than what you're doing at the moment. I tried your program and it took 2-3 seconds to complete. This one takes less than a second if you use a conditional"if (line.StartsWith("stat_c", StringComparison.Ordinal))".
    I used AutoIt v3. It's a free to download thing... So I'm not really sure what an integer is, but by the looks of it I think here it's called an array. And I did use that.

    Also I added a sleep thing for testing purpose (of 3 seconds) which is why it takes so long to complete. I guess I can remove that

    Also, I'm not really sure why the program is 896kb.. How many lines of code is it? Unused project assets being included?
    Good point!

    I used another (unfinished) EDB editor tool as base from which to work on, but I forgot to remove most assets

    FYI, here's the code:
    Spoiler Alert, click show to read: 
    Code:
    #NoTrayIcon
    #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
    #AutoIt3Wrapper_icon=FoE.ico
    #AutoIt3Wrapper_Res_Comment=Made by PatricianS
    #AutoIt3Wrapper_Compression=4
    #AutoIt3Wrapper_Res_Description=Rome Total War Preferences Editor
    #AutoIt3Wrapper_Res_Fileversion=1.0.0.5
    #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
    #AutoIt3Wrapper_Add_Constants=n
    #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
    #include <GUIConstantsEx.au3>
    #include <ButtonConstants.au3>
    #Include <WinAPI.au3>
    #include <StaticConstants.au3>
    #include <Sound.au3>
    #include <Array.au3>
    
    ; ====================================
    ;
    ;           By PatricianS
    ;
    ; ====================================
    
    Opt('MustDeclareVars', 1)
    Opt('GUICloseOnESC', 0)
    
    Global $hGUI
    
    _Question()
    
    Func _Question()
        
        GUICreate ( "Increase unit costs", 260, 20 )
        GUISetState()
        
        Global $Factor, $FactorInput = GUICtrlCreateInput ( "", 0, 0, 60, 20 )
        Global $Convert = GUICtrlCreateButton( "Caclulate new costs", 60, 0, 200, 20 )
        Global $EDUFilePath = "Data\export_descr_unit.txt"
        
        While 1
            Switch GUIGetMsg()
                Case $GUI_EVENT_CLOSE
                    ExitLoop
                
                Case $Convert
                    $Factor = GUICtrlRead ( $FactorInput )
                    _Main()
                    
                    MsgBox(0, "Info", "A new EDU will be generated on your desktop when done.", 3)
                    
                    _FileWriteFromArray( @DesktopDir & "\export_descr_unit (costs increased with a factor " & $Factor & ").txt", $EDU, 1 )
                ;    _FileWriteFromArray( $EDUFilePath, $EDU, 1 )
                    
                    Sleep( 3000 )
                    
                    MsgBox(0, "Done", "Conversion completed.")
                    
                    ExitLoop
                
            EndSwitch
        WEnd
        
    EndFunc
    
    
    Func _Main()
        
        Global $EDU[99999]
        Global $Matches[99999]
        
        If FileExists ( $EDUFilePath ) Then ; Check for revision number
            _FileReadToArray( $EDUFilePath, $EDU )
        ;    _ArrayDisplay( $EDU )
    ;        MsgBox(0, "SRE Result", $CurrentRevision)
            
            For $a = 0 To $EDU[0]
                If StringLeft ( $EDU[$a], 9 ) = "stat_cost" Then
                    
                    ;MsgBox(0, "Result", "hit on line: " & $a)
                    
                    $Matches = StringSplit( $EDU[$a], ",")
                    ;$Matches = StringRegExp( $EDU[$a], "([0-9]{1,9})", 1)
                    
                    StringTrimLeft ( $Matches[2], 1 ) ; get rid of the additional space.
                    StringTrimLeft ( $Matches[3], 1 )
                    StringTrimLeft ( $Matches[4], 1 )
                    StringTrimLeft ( $Matches[5], 1 )
                    
                    $Matches[2] = $Matches[2] * $Factor
                    $Matches[3] = $Matches[3] * $Factor
                    $Matches[4] = $Matches[4] * $Factor
                    $Matches[5] = $Matches[5] * $Factor
                    
                    
                    ;_ArrayDisplay( $Matches )
                    
                    $EDU[$a] = $Matches[1] & ", " & $Matches[2] & ", "  & $Matches[3] & ", "  & $Matches[4] & ", "  & $Matches[5] & ","  & $Matches[6]
                    
                    ;_ArrayDisplay( $EDU )
                    
                    ;MsgBox(0, "Result", "The first number is: " & $Matches[2])
                    ;MsgBox(0, "Result", "The second number is: " & $Matches[3])
                    
                EndIf
            Next
        Else
            MsgBox(0, "Error", "No EDU found.")
        EndIf
    EndFunc



  6. #6

    Default Re: Global unit cost editor

    Looks a bit like scripting , but just a tatch harder

  7. #7

    Default Re: Global unit cost editor



    I have removed the sleep thing, so it's a bit faster now.

    Re the size, I guess that might be due to AutoIt being a bit less effective in compiling. I've removed an asset (for sounds) which saved 26 kB making a total of 871 kB. I can't get it any smaller...

    Here's the smaller version without sleeping thing (v1.2)
    DOWNLOAD

  8. #8
    RedFox's Avatar When it's done.™
    Join Date
    Nov 2006
    Location
    Estonia
    Posts
    3,027

    Default Re: Global unit cost editor

    PatricianS: An integer (int in C#) is a 'whole' number - without a floating point. For example: 2, -482, +2914; are integers, while 2.0, -239.66, +23.33 are floating point numbers (float in C#). Double precision floating points are called doubles (double in C#).

    As for the program being big - I guess it's due to the way the compiler works. It's rather exotic to use a scripting language like that.. I find more popular programming languages such as C#, VB and Python much more powerful, easier and practical. That's my opinion though .

    Anyway, you need to cast the calculations here into integers:
    Code:
                    $Matches[2] = $Matches[2] * $Factor
                    $Matches[3] = $Matches[3] * $Factor
                    $Matches[4] = $Matches[4] * $Factor
                    $Matches[5] = $Matches[5] * $Factor
    That means it will chop off any trailing floating points '.**', leaving a 'whole' number. So 222.5 will become 222


    Edit: By the way, Visual C# 2008 Express Edition (also VB, C++ and Python) are free to download. Just google for them if you're interested. C# is great.

  9. #9

    Default Re: Global unit cost editor

    Ah I see... thanks. After having a closer look through the help file, I found this:

    Quote Originally Posted by Int
    Returns the integer (whole number) representation of an expression.

    Int ( expression )


    Parameters
    expression = An expression to convert into an integer.

    Function IntReturn Value
    Success: Returns a integer. Failure: Returns 0 sets @error to 1 if not an integer, float or string.
    Remarks
    Fractional portions are truncated, so Int(1.999999) returns 1
    Int(0/0) returns -9.22337203685478e+018, if you were wondering.


    So I'll add that. Thanks a lot for pointing this out!!!

  10. #10
    Swagger's Avatar Imperial Coffee-Runner
    Join Date
    Apr 2007
    Location
    Portugal
    Posts
    12,453

    Default Re: Global unit cost editor

    will this also work for med2tw?
    Under the Patronage of the Dreadful cedric37!
    Ancs Guide, Emergent Factions , Yes/No Events |L'Outremer for Modders| Swagger's Skymod


  11. #11

    Default Re: Global unit cost editor

    Yes

    I just checked it and the M2 syntax is the same.

  12. #12

    Default Re: Global unit cost editor

    New version: v1.3 - DOWNLOAD

    It now gets rid of all decimals. Meaning that you now can use any factor you like
    (even if it's 0.3 or 2.75)

  13. #13
    Swagger's Avatar Imperial Coffee-Runner
    Join Date
    Apr 2007
    Location
    Portugal
    Posts
    12,453

    Default Re: Global unit cost editor

    ok... i'll take a look at this
    Under the Patronage of the Dreadful cedric37!
    Ancs Guide, Emergent Factions , Yes/No Events |L'Outremer for Modders| Swagger's Skymod


  14. #14
    RedFox's Avatar When it's done.™
    Join Date
    Nov 2006
    Location
    Estonia
    Posts
    3,027

    Default Re: Global unit cost editor

    You should add an extra feature where you can multiply OR add/subtract with different values (much like the unit stat multiplier).

  15. #15

    Default Re: Global unit cost editor

    Quote Originally Posted by RedFox View Post
    You should add an extra feature where you can multiply OR add/subtract with different values (much like the unit stat multiplier).
    Yes good idea!
    If the value you use to detract from the costs (in fact add up a negative value), then in some cases it might happen that the costs go below zero. To prevent this from happening, I added a warning telling you that this has happened and it will automatically change those negative costs to zero (so you at least do not get an error when launching the game).

    Btw, I have also added a similar function to edit building costs.
    (So could maybe some moderator change the title of this thread to "Global cost editor" instead of what it is now? thanks!!)
    Never mind... I noticed I could do it myself as well.

    This is how the new version looks like now:


    Version 2 - DOWNLOAD

    Last edited by Pat89; October 03, 2009 at 05:12 PM.

  16. #16
    RedFox's Avatar When it's done.™
    Join Date
    Nov 2006
    Location
    Estonia
    Posts
    3,027

    Default Re: Global cost editor

    I think you should make a new copy of the file(s) into the mod-folder itself and allow the user to Continue editing the files. For example, if somebody wanted to multiply the costs by 2.0x and add 200.

    In the stat multiplier, it recognized addition / multiplication by what you wrote.
    If you wrote "4", it added that; if you wrote "-4", it subtracted that. If you wrote *1.33, it multiplied with that.
    Of course, a fail-safe should be that no number in stats should go below 0, which you did add.

    What you could do, is let the user write an equation, for example:
    *2 +400 *0.66
    Where delimiters are spaces (' '). It would break it into an array and would be thrust into a for loop. That would also eliminate the need to continue editing the file.

  17. #17

    Default Re: Global cost editor

    good ideas ones again. Though I'm afraid it's pretty complex to do this

    I would love the idea of formula's though. Especially if they're more complex where you can refer to unit stats in your formula.

  18. #18

    Default Re: Global cost editor

    Good Job!

  19. #19
    Quinn Inuit's Avatar Artifex
    Join Date
    Sep 2006
    Location
    Virginia, USA
    Posts
    4,968

    Default Re: Global cost editor

    It disappeared. Could you upload it again?
    RTR Platinum Team Apprentice, RTR VII Team Member, and Extended Realism Mod Team Coordinator. Proud member of House Wilpuri under the patronage of Pannonian

    The ExRM forum: come for the mod, stay for the Classical History discussions. Or vice versa.

    My writing-related Twitter feed.

  20. #20

    Default Re: Global cost editor

    Hmm... Apparently SpeedyShare isn't very reliable. Uploaded to RapidShare now

    DOWNLOAD (v2.0)

Page 1 of 3 123 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
  •