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: Place EmpiresVehicleSort.exe in "C:\Program Files (x86)\Steam\steamapps\%STEAMNAME%\empires\empires\scripts\presets". Add all your "*_preset.txt" files to a .zip archive. Double-click EmpiresVehicleSort.exe. ???? 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.
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?
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.
:\ 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.
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. 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?
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
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.