[TOOL] Empires Vehicle Sort 0.2

Discussion in 'Coding' started by PatPeter, Sep 6, 2011.

  1. PatPeter

    PatPeter I have no idea what I am talking about

    Messages:
    250
    Likes Received:
    0
    Trophy Points:
    0
    I started on this tool last summer but became busy and did not finish it until this summer. Ironically I actually finished it the summer that I started it, the only thing I was missing was a function to write the maps (vehicle customizations) to their respective files.

    How to use:
    1. Place EmpiresVehicleSort.exe in "C:\Program Files (x86)\Steam\steamapps\%STEAMNAME%\empires\empires\scripts\presets".
    2. Add all your "*_preset.txt" files to a .zip archive.
    3. Double-click EmpiresVehicleSort.exe.
    4. ????
    5. PROFIT!

    If anyone starts using this there are a few improvements to still be made to the code. Namely, I need to create a custom typedef in order to have an unsorted map<string,string> so that "Default*" gets bumped to the top and cannot be deleted (the top configuration cannot be deleted).

    Improvements to be done:
    • Fix bug where a single misplaced character at the beginning of a line can folly the entire program (but it cannot delete your presets as it error checks).
    • Replaced if/else statements on characters with switches.
    • Replace linear statements with a universal for loop.

    So, if I have a vehicle named 3PEReaXXFNF (heavy tank with dual-HE, no MG, and one upgraded ML), and there's no other tank above that tank, you can never delete it. Speaking of abbreviations there is a word document in the archive with the abbreviations I use for each weapon. There were enough letters to fit each weapon using only one letter, which appeased my perfectionism.

    Also, I placed my source in the archive because I would not expect myself to run a program without knowing how it works and what it does.
     

    Attached Files:

    Last edited: Sep 7, 2011
  2. Lawliet

    Lawliet Member

    Messages:
    869
    Likes Received:
    19
    Trophy Points:
    0
    Your awesome. This reminds me of that thing Meliarion made.
     
  3. PatPeter

    PatPeter I have no idea what I am talking about

    Messages:
    250
    Likes Received:
    0
    Trophy Points:
    0
    vBulletin needs a 'Like' button so I can like your post.

    What did Meliarion make?
     
  4. ViroMan

    ViroMan Black Hole (*sniff*) Bully

    Messages:
    8,382
    Likes Received:
    4
    Trophy Points:
    0
    well there is a like thread option... and to prove my point.. I gave you 1 out of 5 stars.
     
  5. PatPeter

    PatPeter I have no idea what I am talking about

    Messages:
    250
    Likes Received:
    0
    Trophy Points:
    0
    Why might I ask?
     
  6. ViroMan

    ViroMan Black Hole (*sniff*) Bully

    Messages:
    8,382
    Likes Received:
    4
    Trophy Points:
    0
    no particular reason for the low score... just to prove that it works.
     
  7. Trickster

    Trickster Retired Developer

    Messages:
    16,576
    Likes Received:
    46
    Trophy Points:
    0
    Nice tool. How does it work in terms of script updating? Meliarion's was nice, but it broke every time the scripts were updated, will yours adapt?
     
  8. ViroMan

    ViroMan Black Hole (*sniff*) Bully

    Messages:
    8,382
    Likes Received:
    4
    Trophy Points:
    0
    god it drove me damn near crazy trying to read the structure of that file. Perhaps restructuring it with proper tabs and spaces would make it a ton easier to read.

    Why did you open ALL the files then save them? Why not open then save the file then move on to the next? didn't seem to make any sense.

    Why not use a simple switch instead of all the else ifs?

    anyways... I redid alot of stuff to make it readable to me(and maby others) and traded all those useless else ifs for 2 switches and now I give it back to you. ;)
     

    Attached Files:

    • evs.zip
      File size:
      2.6 KB
      Views:
      6
  9. PatPeter

    PatPeter I have no idea what I am talking about

    Messages:
    250
    Likes Received:
    0
    Trophy Points:
    0
    :\

    Right now what it does is it reads the title and the content of a vehicle, for instance:

    Code:
    "File Title" // Automated by program, but I tested this by changing it to VehicleType and Empires still read it.
    {
        "Vehicle2Name" // Program pulls the title out 
        { // Program puts the title line above and this line into an abstract data type reference of the vehicle's name
    // ... None of this matters
        } // Stop reading of vehicle
        "Vehicle1Name"
        {
    // ... None of this matters
        }
    }

    In other words, this program was written for 2.24d, unless some major update completely changes how saving presets work, such as putting vehicles in groups or some such, it can't break.

    Do you know how the Source engine reads and writes to the preset files Trickster? If I knew how the Source engine did it I could either implement their method or examine it to ensure my program is 'unbreakable' (or rather to avoid breaking as long as possible).

    Also Trickster:

    Code:
    	//cout << "Opening vehicle_imp_afv_mkii_preset.txt       ";
    	//map<string,string> imp_afv_mkii = open_file("vehicle_imp_afv_mkii_preset.txt");
    
    	//cout << "Opening vehicle_nf_light_tank_mkii_preset.txt ";
    	//map<string,string> nf_light_tank_mkii = open_file("vehicle_nf_light_tank_mkii_preset.txt");

    /me Q_Q

    What application did you use to zip your file? I had to download it and use 7-Zip to open it, the defaulted Windows Explorer to Firefox did not work.

    http://en.wikipedia.org/wiki/Indent_style#Variant:_1TBS: Sorry what about proper tabs and spaces? I'm fairly sure you aren't more authoritative than the Unix and Linux kernels.

    Allman style is a waste of a newline, spaces are a waste of a character (2 spaces vs. 1 tab). Also, every example on this page features indentation of 4 columns with the exception of BSD KNF style with 8 columns and banner style with your 2 columns.

    How would you truncate a file while it's already open? I reopened them so that I could use ios::trunc.

    Unless you mean I should have made a function that opened each file and saved it to a temporary map, and then proceeded to run write_to_file inside of said function with that map and the function's parameters. I had already planned this when I said:


    The reason I made it linear is four simple words: I. Wanted. This. Done.

    After having the algorithms complete, but the program on the back-burner because I just did not have time to finish it last academic year, I just wanted to finish this and give it to the community.

    Trust me, I know the errors of CTRL+C and CTRL+V:

    http://forums.bukkit.org/threads/inactive-sqlite-and-mysql-tutorial-library.17034/page-11#post-623487

    Good suggestion! I've never gotten used to using switches as none of my first languages had switches in them (horrible, right?).

    I'll totally change those if/else statements, but it would be a grievous sin to reject The One True Brace Style.
     
  10. ViroMan

    ViroMan Black Hole (*sniff*) Bully

    Messages:
    8,382
    Likes Received:
    4
    Trophy Points:
    0
    sorry.. ya I ziped it with 7z but forum won't let you attach a 7z file I just named it zip... sorry I should have told you.

    Also why truncate the file since it will be the same size? Bring the file pointer to the start then start spewing the data back out. Im not totally sure if thats possible with the older filestream stuff. Never touch it if I can avoid it.
    fopen is your C friend. It will work in all compilers that support c which... is all of them(I think). The command your looking for is fopen(FileName,"r+"); with the + your in "update" mode. Read the file then use fseek to go back to the start and begin writing.

    ohh and for the style...
    1TBSucks


    Allman ftw. :P

    joking aside...
    I use Allman style because it is so much easier to read. sure its uses more characters and lines but, its easier to read. Its not like you have a shortage of HD space for your 11kb file is there?
     
    Last edited: Sep 7, 2011
  11. f1r3w4rr10r

    f1r3w4rr10r Modeler

    Messages:
    2,475
    Likes Received:
    4
    Trophy Points:
    0
    i use 1TBS myself too
    but honestly just because the autobuild of eclipse uses it too

    for switches: cant wait for java7 to get officialy released and supported by eclipse, because: Strings in switches FTW ;P
     
  12. PatPeter

    PatPeter I have no idea what I am talking about

    Messages:
    250
    Likes Received:
    0
    Trophy Points:
    0
    Eww, pure C, EWWW. I can't complain though since Linux is written in it. The question is, what's more complex: closing and reopening the file or using fopen()?

    Then it comes down to a difference of opinion. I have a much easier time reading 1TBS and it's not so much as I find Allman style hard to read as much as I find it annoying to read.

    SCREW YOU WARRIOR, I was going to say that I did not use a switch because, being more of a Java programmer than a C++ programmer, I was waiting for Java switches to support Strings and therefore not in the habit of using switches on chars.

    Then I realized Java supports char switches.
    Then I realized my algorithm would never compare two characters at a time because it only fetches one char from the string array.
    Then I realized it was better to take the suggestion.
     
    Last edited: Sep 7, 2011

Share This Page