# -*- coding: cp1252 -*- # -*- coding: utf-8 -*- import os import re import codecs # WHAT IT DOES: # Modifies the specified parameters # of every unit/equipment of Hearts of Iron IV. # This will modify the txt files directly in # their original folder -- make backups! # HOW IT WORKS: # A set of functions is defined, # one function for each main type of # equipment for which we would like costs to # be different: infantry, planes, ships, etc. # In a first pass, removes the values and replaces # them with a relevant string (ex: inf_build_cost_ic). # Then a second set of two functions will make # a second pass and replace these strings # by the value specified below. # /!\NOTE/!\: # Some values are in the "equipment" folder, # other are in the "units" folder one step above. # Which is why most functions are split in 2. koopa_inf_build_cost_ic = "0.2" # equipment, default 1936: 0.4 koopa_inf_build_cost_steel = "1" # equipment, default 1936: 2 koopa_inf_training_time = "5" # units, default: 90 koopa_inf_combat_width = "0" # units, default: 2 koopa_light_tank_build_cost_ic = "2" # equipment, default 1934: 8 koopa_light_tank_build_cost_steel = "1" # equipment, default 1934: 2 koopa_light_tank_training_time = "5" # units, default: 180 koopa_light_tank_combat_width = "0" # units, default: 2 koopa_medium_tank_build_cost_ic = "4" # equipment, default 1934: 12 koopa_medium_tank_build_cost_tungsten = "0" # equipment, default 1934: 2 koopa_medium_tank_build_cost_steel = "1" # equipment, default 1934: 2 koopa_medium_tank_training_time = "5" # units, default: 180 koopa_medium_tank_combat_width = "0" # units, default: 2 koopa_heavy_tank_build_cost_ic = "8" # equipment, default 1934: 25 koopa_heavy_tank_build_cost_chromium = "0" # equipment, default 1934: 3 koopa_heavy_tank_build_cost_steel = "1" # equipment, default 1934: 3 koopa_heavy_tank_training_time = "5" # units, default: 180 koopa_heavy_tank_combat_width = "0" # units, default: 2 koopa_super_heavy_tank_build_cost_ic = "16" # equipment, default 1934: 100 koopa_super_heavy_tank_build_cost_chromium = "0" # equipment, default 1934: 4 koopa_super_heavy_tank_build_cost_steel = "1" # equipment, default 1934: 3 koopa_super_heavy_tank_training_time = "5" # units, default: 180 koopa_super_heavy_tank_combat_width = "0" # units, default: 2 koopa_amphibious_tank_build_cost_ic = "3" # equipment, default 1934: 10 koopa_amphibious_tank_build_cost_steel = "1" # equipment, default 1934: 2 koopa_amphibious_tank_training_time = "5" # units, default: 180 koopa_amphibious_tank_combat_width = "0" # units, default: 2 koopa_modern_tank_build_cost_ic = "10" # equipment, default 1934: 28 koopa_modern_tank_build_cost_chromium = "0" # equipment, default 1934: 4 koopa_modern_tank_build_cost_steel = "1" # equipment, default 1934: 3 koopa_modern_tank_training_time = "5" # units, default: 180 koopa_modern_tank_combat_width = "0" # units, default: 2 #note: this will affect all single_engine planes since they are all in the same folder #default is default value of the first equipment in the file koopa_single_engine_build_cost_ic = "5" # equipment, default 1933: 22 koopa_single_engine_build_cost_aluminium = "1" # equipment, default 1933: 2 koopa_single_engine_build_cost_rubber = "1" # equipment, default 1933: 1 #note: this will affect all twin_engine planes since they are all in the same folder #default is default value of the first equipment in the file koopa_twin_engine_build_cost_ic = "8" # equipment, default 1933: 35 koopa_twin_engine_build_cost_aluminium = "1" # equipment, default 1933: 2 koopa_twin_engine_build_cost_rubber = "1" # equipment, default 1933: 1 #note: this will affect all quad_engine planes since they are all in the same folder #default is default value of the first equipment in the file koopa_quad_engine_build_cost_ic = "15" # equipment, default 1933: 60 koopa_quad_engine_build_cost_aluminium = "1" # equipment, default 1933: 3 koopa_quad_engine_build_cost_rubber = "1" # equipment, default 1933: 2 #note: this will affect all destroyers since they are all in the same folder #default is default value of the first equipment in the file koopa_light_ship_build_cost_ic = "40" # equipment, default 1922: 400 koopa_light_ship_build_cost_steel = "1" # equipment, default 1922: 2 koopa_light_ship_build_cost_chromium = "1" # equipment, default 1922: 1 #note: this will affect all cruisers since they are all in the same folder #default is default value of the first equipment in the file koopa_cruiser_build_cost_ic = "90" # equipment, default 1922: 1800 koopa_cruiser_build_cost_steel = "1" # equipment, default 1922: 1 koopa_cruiser_build_cost_chromium = "1" # equipment, default 1922: 1 #note: this will affect all battleships since they are all in the same folder #default is default value of the first equipment in the file koopa_heavy_ship_build_cost_ic = "150" # equipment, default 1922: 3300 koopa_heavy_ship_build_cost_steel = "1" # equipment, default 1922: 1 koopa_heavy_ship_build_cost_chromium = "1" # equipment, default 1922: 1 #note: this will affect all carriers since they are all in the same folder #default is default value of the first equipment in the file koopa_carrier_build_cost_ic = "150" # equipment, default 1922: 2450 koopa_carrier_build_cost_steel = "1" # equipment, default 1922: 3 koopa_carrier_build_cost_chromium = "1" # equipment, default 1922: 1 #note: this will affect all modules in 00_ship_modules.txt koopa_ship_module_build_cost_ic = "0" koopa_ship_module_convert_cost_ic = "0" koopa_ship_module_build_cost_steel = "0" koopa_ship_module_build_cost_chromium = "0" # First pass functions # ======================================================================================================= # INFANTRY UNITS # ======================================================================================================= def modify_infantry_equipment(f): print("Working on: units/equipment/"+f) f_path = re.sub(".+\.txt","units/equipment/\g<0>",f) # will be read from then deleted f_original = open(f_path,"r", encoding="utf-8") # original file (full path), read only name_of_f_path_modified = re.sub("(.+)\.txt","units/equipment/\g<1>_m.txt",f) # the name of the modified file f_path_modified = open(name_of_f_path_modified,"w+", encoding="utf-8") #^ modified file will be named *_m.txt (modified) for line in f_original: # ====== Infantry build cost (_ic) ====== line = re.sub('build_cost_ic = .+','build_cost_ic = koopa_inf_build_cost_ic',line) # ====== Infantry build cost (Steel) ====== line = re.sub('steel = .+','steel = koopa_inf_build_cost_steel',line) f_path_modified.write(line) f_original.close() f_path_modified.close() os.remove("./units/equipment/"+f) print("removed "+f) os.rename(name_of_f_path_modified,"./units/equipment/"+f) print("renamed "+name_of_f_path_modified+" into "+f) def modify_infantry_units(f): print("Working on: units/"+f) f_path = re.sub(".+\.txt","units/\g<0>",f) # will be read from then deleted f_original = open(f_path,"r", encoding="utf-8") # original file (full path), read only name_of_f_path_modified = re.sub("(.+)\.txt","units/\g<1>_m.txt",f) # the name of the modified file f_path_modified = open(name_of_f_path_modified,"w+", encoding="utf-8") #^ modified file will be named *_m.txt (modified) for line in f_original: # ====== Infantry training time ====== line = re.sub('training_time = .+','training_time = koopa_inf_training_time',line) # ====== Infantry combat width ====== line = re.sub('combat_width = .+','combat_width = koopa_inf_combat_width',line) f_path_modified.write(line) f_original.close() f_path_modified.close() os.remove("./units/"+f) print("removed "+f) os.rename(name_of_f_path_modified,"./units/"+f) print("renamed "+name_of_f_path_modified+" into "+f) # ======================================================================================================= # LIGHT TANK UNITS # ======================================================================================================= def modify_light_tank_equipment(f): print("Working on: units/equipment/"+f) f_path = re.sub(".+\.txt","units/equipment/\g<0>",f) # will be read from then deleted f_original = open(f_path,"r", encoding="utf-8") # original file (full path), read only name_of_f_path_modified = re.sub("(.+)\.txt","units/equipment/\g<1>_m.txt",f) # the name of the modified file f_path_modified = open(name_of_f_path_modified,"w+", encoding="utf-8") #^ modified file will be named *_m.txt (modified) for line in f_original: # ====== Light tank build cost (_ic) ====== line = re.sub('build_cost_ic = .+','build_cost_ic = koopa_light_tank_build_cost_ic',line) # ====== Light tank build cost (Steel) ====== line = re.sub('steel = .+','steel = koopa_light_tank_build_cost_steel',line) f_path_modified.write(line) f_original.close() f_path_modified.close() os.remove("./units/equipment/"+f) print("removed "+f) os.rename(name_of_f_path_modified,"./units/equipment/"+f) print("renamed "+name_of_f_path_modified+" into "+f) def modify_light_tank_units(f): print("Working on: units/"+f) f_path = re.sub(".+\.txt","units/\g<0>",f) # will be read from then deleted f_original = open(f_path,"r", encoding="utf-8") # original file (full path), read only name_of_f_path_modified = re.sub("(.+)\.txt","units/\g<1>_m.txt",f) # the name of the modified file f_path_modified = open(name_of_f_path_modified,"w+", encoding="utf-8") #^ modified file will be named *_m.txt (modified) for line in f_original: # ====== Light tank training time ====== line = re.sub('training_time = .+','training_time = koopa_light_tank_training_time',line) # ====== Light tank combat width ====== line = re.sub('combat_width = .+','combat_width = koopa_light_tank_combat_width',line) f_path_modified.write(line) f_original.close() f_path_modified.close() os.remove("./units/"+f) print("removed "+f) os.rename(name_of_f_path_modified,"./units/"+f) print("renamed "+name_of_f_path_modified+" into "+f) # ======================================================================================================= # MEDIUM TANK UNITS # ======================================================================================================= def modify_medium_tank_equipment(f): print("Working on: units/equipment/"+f) f_path = re.sub(".+\.txt","units/equipment/\g<0>",f) # will be read from then deleted f_original = open(f_path,"r", encoding="utf-8") # original file (full path), read only name_of_f_path_modified = re.sub("(.+)\.txt","units/equipment/\g<1>_m.txt",f) # the name of the modified file f_path_modified = open(name_of_f_path_modified,"w+", encoding="utf-8") #^ modified file will be named *_m.txt (modified) for line in f_original: # ====== Medium tank build cost (_ic) ====== line = re.sub('build_cost_ic = .+','build_cost_ic = koopa_medium_tank_build_cost_ic',line) # ====== Medium tank build cost (Steel) ====== line = re.sub('steel = .+','steel = koopa_medium_tank_build_cost_steel',line) # ====== Medium tank build cost (Tungsten) ====== line = re.sub('tungsten = .+','tungsten = koopa_medium_tank_build_cost_tungsten',line) f_path_modified.write(line) f_original.close() f_path_modified.close() os.remove("./units/equipment/"+f) print("removed "+f) os.rename(name_of_f_path_modified,"./units/equipment/"+f) print("renamed "+name_of_f_path_modified+" into "+f) def modify_medium_tank_units(f): print("Working on: units/"+f) f_path = re.sub(".+\.txt","units/\g<0>",f) # will be read from then deleted f_original = open(f_path,"r", encoding="utf-8") # original file (full path), read only name_of_f_path_modified = re.sub("(.+)\.txt","units/\g<1>_m.txt",f) # the name of the modified file f_path_modified = open(name_of_f_path_modified,"w+", encoding="utf-8") #^ modified file will be named *_m.txt (modified) for line in f_original: # ====== Medium tank training time ====== line = re.sub('training_time = .+','training_time = koopa_medium_tank_training_time',line) # ====== Medium tank combat width ====== line = re.sub('combat_width = .+','combat_width = koopa_medium_tank_combat_width',line) f_path_modified.write(line) f_original.close() f_path_modified.close() os.remove("./units/"+f) print("removed "+f) os.rename(name_of_f_path_modified,"./units/"+f) print("renamed "+name_of_f_path_modified+" into "+f) # ======================================================================================================= # HEAVY TANK UNITS # ======================================================================================================= def modify_heavy_tank_equipment(f): print("Working on: units/equipment/"+f) f_path = re.sub(".+\.txt","units/equipment/\g<0>",f) # will be read from then deleted f_original = open(f_path,"r", encoding="utf-8") # original file (full path), read only name_of_f_path_modified = re.sub("(.+)\.txt","units/equipment/\g<1>_m.txt",f) # the name of the modified file f_path_modified = open(name_of_f_path_modified,"w+", encoding="utf-8") #^ modified file will be named *_m.txt (modified) for line in f_original: # ====== Heavy tank build cost (_ic) ====== line = re.sub('build_cost_ic = .+','build_cost_ic = koopa_heavy_tank_build_cost_ic',line) # ====== Heavy tank build cost (Steel) ====== line = re.sub('steel = .+','steel = koopa_heavy_tank_build_cost_steel',line) # ====== Heavy tank build cost (Chromium) ====== line = re.sub('chromium = .+','chromium = koopa_heavy_tank_build_cost_chromium',line) f_path_modified.write(line) f_original.close() f_path_modified.close() os.remove("./units/equipment/"+f) print("removed "+f) os.rename(name_of_f_path_modified,"./units/equipment/"+f) print("renamed "+name_of_f_path_modified+" into "+f) def modify_heavy_tank_units(f): print("Working on: units/"+f) f_path = re.sub(".+\.txt","units/\g<0>",f) # will be read from then deleted f_original = open(f_path,"r", encoding="utf-8") # original file (full path), read only name_of_f_path_modified = re.sub("(.+)\.txt","units/\g<1>_m.txt",f) # the name of the modified file f_path_modified = open(name_of_f_path_modified,"w+", encoding="utf-8") #^ modified file will be named *_m.txt (modified) for line in f_original: # ====== Heavy tank training time ====== line = re.sub('training_time = .+','training_time = koopa_heavy_tank_training_time',line) # ====== Heavy tank combat width ====== line = re.sub('combat_width = .+','combat_width = koopa_heavy_tank_combat_width',line) f_path_modified.write(line) f_original.close() f_path_modified.close() os.remove("./units/"+f) print("removed "+f) os.rename(name_of_f_path_modified,"./units/"+f) print("renamed "+name_of_f_path_modified+" into "+f) # ======================================================================================================= # SUPER HEAVY TANK UNITS # ======================================================================================================= def modify_super_heavy_tank_equipment(f): print("Working on: units/equipment/"+f) f_path = re.sub(".+\.txt","units/equipment/\g<0>",f) # will be read from then deleted f_original = open(f_path,"r", encoding="utf-8") # original file (full path), read only name_of_f_path_modified = re.sub("(.+)\.txt","units/equipment/\g<1>_m.txt",f) # the name of the modified file f_path_modified = open(name_of_f_path_modified,"w+", encoding="utf-8") #^ modified file will be named *_m.txt (modified) for line in f_original: # ====== Super Heavy tank build cost (_ic) ====== line = re.sub('build_cost_ic = .+','build_cost_ic = koopa_super_heavy_tank_build_cost_ic',line) # ====== Super Heavy tank build cost (Steel) ====== line = re.sub('steel = .+','steel = koopa_super_heavy_tank_build_cost_steel',line) # ====== Super Heavy tank build cost (Chromium) ====== line = re.sub('chromium = .+','chromium = koopa_super_heavy_tank_build_cost_chromium',line) f_path_modified.write(line) f_original.close() f_path_modified.close() os.remove("./units/equipment/"+f) print("removed "+f) os.rename(name_of_f_path_modified,"./units/equipment/"+f) print("renamed "+name_of_f_path_modified+" into "+f) def modify_super_heavy_tank_units(f): print("Working on: units/"+f) f_path = re.sub(".+\.txt","units/\g<0>",f) # will be read from then deleted f_original = open(f_path,"r", encoding="utf-8") # original file (full path), read only name_of_f_path_modified = re.sub("(.+)\.txt","units/\g<1>_m.txt",f) # the name of the modified file f_path_modified = open(name_of_f_path_modified,"w+", encoding="utf-8") #^ modified file will be named *_m.txt (modified) for line in f_original: # ====== Super Heavy tank training time ====== line = re.sub('training_time = .+','training_time = koopa_super_heavy_tank_training_time',line) # ====== Super Heavy tank combat width ====== line = re.sub('combat_width = .+','combat_width = koopa_super_heavy_tank_combat_width',line) f_path_modified.write(line) f_original.close() f_path_modified.close() os.remove("./units/"+f) print("removed "+f) os.rename(name_of_f_path_modified,"./units/"+f) print("renamed "+name_of_f_path_modified+" into "+f) # ======================================================================================================= # AMPHIBIOUS TANK UNITS # ======================================================================================================= def modify_amphibious_tank_equipment(f): print("Working on: units/equipment/"+f) f_path = re.sub(".+\.txt","units/equipment/\g<0>",f) # will be read from then deleted f_original = open(f_path,"r", encoding="utf-8") # original file (full path), read only name_of_f_path_modified = re.sub("(.+)\.txt","units/equipment/\g<1>_m.txt",f) # the name of the modified file f_path_modified = open(name_of_f_path_modified,"w+", encoding="utf-8") #^ modified file will be named *_m.txt (modified) for line in f_original: # ====== Amphibious tank build cost (_ic) ====== line = re.sub('build_cost_ic = .+','build_cost_ic = koopa_amphibious_tank_build_cost_ic',line) # ====== Amphibious tank build cost (Steel) ====== line = re.sub('steel = .+','steel = koopa_amphibious_tank_build_cost_steel',line) f_path_modified.write(line) f_original.close() f_path_modified.close() os.remove("./units/equipment/"+f) print("removed "+f) os.rename(name_of_f_path_modified,"./units/equipment/"+f) print("renamed "+name_of_f_path_modified+" into "+f) def modify_amphibious_tank_units(f): print("Working on: units/"+f) f_path = re.sub(".+\.txt","units/\g<0>",f) # will be read from then deleted f_original = open(f_path,"r", encoding="utf-8") # original file (full path), read only name_of_f_path_modified = re.sub("(.+)\.txt","units/\g<1>_m.txt",f) # the name of the modified file f_path_modified = open(name_of_f_path_modified,"w+", encoding="utf-8") #^ modified file will be named *_m.txt (modified) for line in f_original: # ====== Amphibious tank training time ====== line = re.sub('training_time = .+','training_time = koopa_amphibious_tank_training_time',line) # ====== Amphibious tank combat width ====== line = re.sub('combat_width = .+','combat_width = koopa_amphibious_tank_combat_width',line) f_path_modified.write(line) f_original.close() f_path_modified.close() os.remove("./units/"+f) print("removed "+f) os.rename(name_of_f_path_modified,"./units/"+f) print("renamed "+name_of_f_path_modified+" into "+f) # ======================================================================================================= # MODERN TANK UNITS # ======================================================================================================= def modify_modern_tank_equipment(f): print("Working on: units/equipment/"+f) f_path = re.sub(".+\.txt","units/equipment/\g<0>",f) # will be read from then deleted f_original = open(f_path,"r", encoding="utf-8") # original file (full path), read only name_of_f_path_modified = re.sub("(.+)\.txt","units/equipment/\g<1>_m.txt",f) # the name of the modified file f_path_modified = open(name_of_f_path_modified,"w+", encoding="utf-8") #^ modified file will be named *_m.txt (modified) for line in f_original: # ====== Modern tank build cost (_ic) ====== line = re.sub('build_cost_ic = .+','build_cost_ic = koopa_modern_tank_build_cost_ic',line) # ====== Modern tank build cost (Steel) ====== line = re.sub('steel = .+','steel = koopa_modern_tank_build_cost_steel',line) # ====== Modern tank build cost (Chromium) ====== line = re.sub('chromium = .+','chromium = koopa_modern_tank_build_cost_chromium',line) f_path_modified.write(line) f_original.close() f_path_modified.close() os.remove("./units/equipment/"+f) print("removed "+f) os.rename(name_of_f_path_modified,"./units/equipment/"+f) print("renamed "+name_of_f_path_modified+" into "+f) def modify_modern_tank_units(f): print("Working on: units/"+f) f_path = re.sub(".+\.txt","units/\g<0>",f) # will be read from then deleted f_original = open(f_path,"r", encoding="utf-8") # original file (full path), read only name_of_f_path_modified = re.sub("(.+)\.txt","units/\g<1>_m.txt",f) # the name of the modified file f_path_modified = open(name_of_f_path_modified,"w+", encoding="utf-8") #^ modified file will be named *_m.txt (modified) for line in f_original: # ====== Modern tank training time ====== line = re.sub('training_time = .+','training_time = koopa_modern_tank_training_time',line) # ====== Modern tank combat width ====== line = re.sub('combat_width = .+','combat_width = koopa_modern_tank_combat_width',line) f_path_modified.write(line) f_original.close() f_path_modified.close() os.remove("./units/"+f) print("removed "+f) os.rename(name_of_f_path_modified,"./units/"+f) print("renamed "+name_of_f_path_modified+" into "+f) # ======================================================================================================= # SINGLE ENGINE AIR UNITS # important parameters only found in the "equipment" folder, hence why only 1 function # ======================================================================================================= def modify_single_engine_equipment(f): print("Working on: units/equipment/"+f) f_path = re.sub(".+\.txt","units/equipment/\g<0>",f) # will be read from then deleted f_original = open(f_path,"r", encoding="utf-8") # original file (full path), read only name_of_f_path_modified = re.sub("(.+)\.txt","units/equipment/\g<1>_m.txt",f) # the name of the modified file f_path_modified = open(name_of_f_path_modified,"w+", encoding="utf-8") #^ modified file will be named *_m.txt (modified) for line in f_original: # ====== Single engine airframe build cost (_ic) ====== line = re.sub('build_cost_ic = .+','build_cost_ic = koopa_single_engine_build_cost_ic',line) # ====== Single engine airframe build cost (Aluminium) ====== line = re.sub('aluminium = .+','aluminium = koopa_single_engine_build_cost_aluminium',line) # ====== Single engine airframe build cost (Rubber) ====== line = re.sub('rubber = .+','rubber = koopa_single_engine_build_cost_rubber',line) f_path_modified.write(line) f_original.close() f_path_modified.close() os.remove("./units/equipment/"+f) print("removed "+f) os.rename(name_of_f_path_modified,"./units/equipment/"+f) print("renamed "+name_of_f_path_modified+" into "+f) # ======================================================================================================= # TWIN ENGINE AIR UNITS # important parameters only found in the "equipment" folder, hence why only 1 function # ======================================================================================================= def modify_twin_engine_equipment(f): print("Working on: units/equipment/"+f) f_path = re.sub(".+\.txt","units/equipment/\g<0>",f) # will be read from then deleted f_original = open(f_path,"r", encoding="utf-8") # original file (full path), read only name_of_f_path_modified = re.sub("(.+)\.txt","units/equipment/\g<1>_m.txt",f) # the name of the modified file f_path_modified = open(name_of_f_path_modified,"w+", encoding="utf-8") #^ modified file will be named *_m.txt (modified) for line in f_original: # ====== Twin engine airframe build cost (_ic) ====== line = re.sub('build_cost_ic = .+','build_cost_ic = koopa_twin_engine_build_cost_ic',line) # ====== Twin engine airframe build cost (Aluminium) ====== line = re.sub('aluminium = .+','aluminium = koopa_twin_engine_build_cost_aluminium',line) # ====== Twin engine airframe build cost (Rubber) ====== line = re.sub('rubber = .+','rubber = koopa_twin_engine_build_cost_rubber',line) f_path_modified.write(line) f_original.close() f_path_modified.close() os.remove("./units/equipment/"+f) print("removed "+f) os.rename(name_of_f_path_modified,"./units/equipment/"+f) print("renamed "+name_of_f_path_modified+" into "+f) # ======================================================================================================= # QUAD ENGINE AIR UNITS # important parameters only found in the "equipment" folder, hence why only 1 function # ======================================================================================================= def modify_quad_engine_equipment(f): print("Working on: units/equipment/"+f) f_path = re.sub(".+\.txt","units/equipment/\g<0>",f) # will be read from then deleted f_original = open(f_path,"r", encoding="utf-8") # original file (full path), read only name_of_f_path_modified = re.sub("(.+)\.txt","units/equipment/\g<1>_m.txt",f) # the name of the modified file f_path_modified = open(name_of_f_path_modified,"w+", encoding="utf-8") #^ modified file will be named *_m.txt (modified) for line in f_original: # ====== Quad engine airframe build cost (_ic) ====== line = re.sub('build_cost_ic = .+','build_cost_ic = koopa_quad_engine_build_cost_ic',line) # ====== Quad engine airframe build cost (Aluminium) ====== line = re.sub('aluminium = .+','aluminium = koopa_quad_engine_build_cost_aluminium',line) # ====== Quad engine airframe build cost (Rubber) ====== line = re.sub('rubber = .+','rubber = koopa_quad_engine_build_cost_rubber',line) f_path_modified.write(line) f_original.close() f_path_modified.close() os.remove("./units/equipment/"+f) print("removed "+f) os.rename(name_of_f_path_modified,"./units/equipment/"+f) print("renamed "+name_of_f_path_modified+" into "+f) # ======================================================================================================= # LIGHT SHIP UNITS (DESTROYERS) # important parameters only found in the "equipment" folder, hence why only 1 function # ======================================================================================================= def modify_light_ship_equipment(f): print("Working on: units/equipment/"+f) f_path = re.sub(".+\.txt","units/equipment/\g<0>",f) # will be read from then deleted f_original = open(f_path,"r", encoding="utf-8") # original file (full path), read only name_of_f_path_modified = re.sub("(.+)\.txt","units/equipment/\g<1>_m.txt",f) # the name of the modified file f_path_modified = open(name_of_f_path_modified,"w+", encoding="utf-8") #^ modified file will be named *_m.txt (modified) for line in f_original: # ====== Light ship (destroyer) build cost (_ic) ====== line = re.sub('build_cost_ic = .+','build_cost_ic = koopa_light_ship_build_cost_ic',line) # ====== Light ship (destroyer) build cost (Steel) ====== line = re.sub('steel = .+','steel = koopa_light_ship_build_cost_steel',line) # ====== Light ship (destroyer) build cost (Chromium) ====== line = re.sub('chromium = .+','chromium = koopa_light_ship_build_cost_chromium',line) f_path_modified.write(line) f_original.close() f_path_modified.close() os.remove("./units/equipment/"+f) print("removed "+f) os.rename(name_of_f_path_modified,"./units/equipment/"+f) print("renamed "+name_of_f_path_modified+" into "+f) # ======================================================================================================= # CRUISER UNITS # important parameters only found in the "equipment" folder, hence why only 1 function # ======================================================================================================= def modify_cruiser_equipment(f): print("Working on: units/equipment/"+f) f_path = re.sub(".+\.txt","units/equipment/\g<0>",f) # will be read from then deleted f_original = open(f_path,"r", encoding="utf-8") # original file (full path), read only name_of_f_path_modified = re.sub("(.+)\.txt","units/equipment/\g<1>_m.txt",f) # the name of the modified file f_path_modified = open(name_of_f_path_modified,"w+", encoding="utf-8") #^ modified file will be named *_m.txt (modified) for line in f_original: # ====== Cruiser build cost (_ic) ====== line = re.sub('build_cost_ic = .+','build_cost_ic = koopa_cruiser_build_cost_ic',line) # ====== Cruiser build cost (Steel) ====== line = re.sub('steel = .+','steel = koopa_cruiser_build_cost_steel',line) # ====== Cruiser build cost (Chromium) ====== line = re.sub('chromium = .+','chromium = koopa_cruiser_build_cost_chromium',line) f_path_modified.write(line) f_original.close() f_path_modified.close() os.remove("./units/equipment/"+f) print("removed "+f) os.rename(name_of_f_path_modified,"./units/equipment/"+f) print("renamed "+name_of_f_path_modified+" into "+f) # ======================================================================================================= # HEAVY SHIP UNITS (BATTLESHIPS) # important parameters only found in the "equipment" folder, hence why only 1 function # ======================================================================================================= def modify_heavy_ship_equipment(f): print("Working on: units/equipment/"+f) f_path = re.sub(".+\.txt","units/equipment/\g<0>",f) # will be read from then deleted f_original = open(f_path,"r", encoding="utf-8") # original file (full path), read only name_of_f_path_modified = re.sub("(.+)\.txt","units/equipment/\g<1>_m.txt",f) # the name of the modified file f_path_modified = open(name_of_f_path_modified,"w+", encoding="utf-8") #^ modified file will be named *_m.txt (modified) for line in f_original: # ====== Heavy ship (battleship) build cost (_ic) ====== line = re.sub('build_cost_ic = .+','build_cost_ic = koopa_heavy_ship_build_cost_ic',line) # ====== Heavy ship (battleship) build cost (Steel) ====== line = re.sub('steel = .+','steel = koopa_heavy_ship_build_cost_steel',line) # ====== Heavy ship (battleship) build cost (Chromium) ====== line = re.sub('chromium = .+','chromium = koopa_heavy_ship_build_cost_chromium',line) f_path_modified.write(line) f_original.close() f_path_modified.close() os.remove("./units/equipment/"+f) print("removed "+f) os.rename(name_of_f_path_modified,"./units/equipment/"+f) print("renamed "+name_of_f_path_modified+" into "+f) # ======================================================================================================= # CARRIERS UNITS # Important parameters only found in the "equipment" folder, hence why only 1 function # ======================================================================================================= def modify_carrier_equipment(f): print("Working on: units/equipment/"+f) f_path = re.sub(".+\.txt","units/equipment/\g<0>",f) # will be read from then deleted f_original = open(f_path,"r", encoding="utf-8") # original file (full path), read only name_of_f_path_modified = re.sub("(.+)\.txt","units/equipment/\g<1>_m.txt",f) # the name of the modified file f_path_modified = open(name_of_f_path_modified,"w+", encoding="utf-8") #^ modified file will be named *_m.txt (modified) for line in f_original: # ====== Carrier build cost (_ic) ====== line = re.sub('build_cost_ic = .+','build_cost_ic = koopa_carrier_build_cost_ic',line) # ====== Carrier ship (battleship) build cost (Steel) ====== line = re.sub('steel = .+','steel = koopa_carrier_build_cost_steel',line) # ====== Carrier ship (battleship) build cost (Chromium) ====== line = re.sub('chromium = .+','chromium = koopa_carrier_build_cost_chromium',line) f_path_modified.write(line) f_original.close() f_path_modified.close() os.remove("./units/equipment/"+f) print("removed "+f) os.rename(name_of_f_path_modified,"./units/equipment/"+f) print("renamed "+name_of_f_path_modified+" into "+f) # ======================================================================================================= # SHIP MODULES # Important parameters only found in the "equipment/modules" folder, hence why only 1 function # ======================================================================================================= def modify_ship_module_equipment(f): print("Working on: units/equipment/"+f) f_path = re.sub(".+\.txt","units/equipment/modules/\g<0>",f) # will be read from then deleted f_original = open(f_path,"r", encoding="utf-8") # original file (full path), read only name_of_f_path_modified = re.sub("(.+)\.txt","units/equipment/modules/\g<1>_m.txt",f) # the name of the modified file f_path_modified = open(name_of_f_path_modified,"w+", encoding="utf-8") #^ modified file will be named *_m.txt (modified) for line in f_original: # ====== Ship module build cost (_ic) ====== line = re.sub('build_cost_ic = .+','build_cost_ic = koopa_ship_module_build_cost_ic',line) # ====== Ship module convert cost (_ic) ====== line = re.sub('convert_cost_ic = .+','convert_cost_ic = koopa_ship_module_convert_cost_ic',line) # ====== Ship module build cost (Steel) ====== line = re.sub('steel = .+','steel = koopa_ship_module_build_cost_steel',line) # ====== Ship module build cost (Chromium) ====== line = re.sub('chromium = .+','chromium = koopa_ship_module_build_cost_chromium',line) f_path_modified.write(line) f_original.close() f_path_modified.close() os.remove("./units/equipment/modules/"+f) print("removed "+f) os.rename(name_of_f_path_modified,"./units/equipment/modules/"+f) print("renamed "+name_of_f_path_modified+" into "+f) # Second pass functions (passes on all files so only 2 functions needed) def apply_values_equipment(f): f_path = re.sub(".+\.txt","units/equipment/\g<0>",f) f_original = open(f_path,"r", encoding="utf-8") # original file (full path), read only name_of_f_path_modified = re.sub("(.+)\.txt","units/equipment/\g<1>_m.txt",f) # the name of the modified file f_path_modified = open(name_of_f_path_modified,"w+", encoding="utf-8") for line in f_original: line = re.sub('koopa_inf_build_cost_ic',koopa_inf_build_cost_ic,line) line = re.sub('koopa_inf_build_cost_steel',koopa_inf_build_cost_steel,line) line = re.sub('koopa_light_tank_build_cost_ic',koopa_light_tank_build_cost_ic,line) line = re.sub('koopa_light_tank_build_cost_steel',koopa_light_tank_build_cost_steel,line) line = re.sub('koopa_medium_tank_build_cost_ic',koopa_medium_tank_build_cost_ic,line) line = re.sub('koopa_medium_tank_build_cost_tungsten',koopa_medium_tank_build_cost_tungsten,line) line = re.sub('koopa_medium_tank_build_cost_steel',koopa_medium_tank_build_cost_steel,line) line = re.sub('koopa_heavy_tank_build_cost_ic',koopa_heavy_tank_build_cost_ic,line) line = re.sub('koopa_heavy_tank_build_cost_chromium',koopa_heavy_tank_build_cost_chromium,line) line = re.sub('koopa_heavy_tank_build_cost_steel',koopa_heavy_tank_build_cost_steel,line) line = re.sub('koopa_super_heavy_tank_build_cost_ic',koopa_super_heavy_tank_build_cost_ic,line) line = re.sub('koopa_super_heavy_tank_build_cost_chromium',koopa_super_heavy_tank_build_cost_chromium,line) line = re.sub('koopa_super_heavy_tank_build_cost_steel',koopa_super_heavy_tank_build_cost_steel,line) line = re.sub('koopa_amphibious_tank_build_cost_ic',koopa_amphibious_tank_build_cost_ic,line) line = re.sub('koopa_amphibious_tank_build_cost_steel',koopa_amphibious_tank_build_cost_steel,line) line = re.sub('koopa_modern_tank_build_cost_ic',koopa_modern_tank_build_cost_ic,line) line = re.sub('koopa_modern_tank_build_cost_chromium',koopa_modern_tank_build_cost_chromium,line) line = re.sub('koopa_modern_tank_build_cost_steel',koopa_modern_tank_build_cost_steel,line) line = re.sub('koopa_single_engine_build_cost_ic',koopa_single_engine_build_cost_ic,line) line = re.sub('koopa_single_engine_build_cost_aluminium',koopa_single_engine_build_cost_aluminium,line) line = re.sub('koopa_single_engine_build_cost_rubber',koopa_single_engine_build_cost_rubber,line) line = re.sub('koopa_twin_engine_build_cost_ic',koopa_twin_engine_build_cost_ic,line) line = re.sub('koopa_twin_engine_build_cost_aluminium',koopa_twin_engine_build_cost_aluminium,line) line = re.sub('koopa_twin_engine_build_cost_rubber',koopa_twin_engine_build_cost_rubber,line) line = re.sub('koopa_quad_engine_build_cost_ic',koopa_quad_engine_build_cost_ic,line) line = re.sub('koopa_quad_engine_build_cost_aluminium',koopa_quad_engine_build_cost_aluminium,line) line = re.sub('koopa_quad_engine_build_cost_rubber',koopa_quad_engine_build_cost_rubber,line) line = re.sub('koopa_light_ship_build_cost_ic',koopa_light_ship_build_cost_ic,line) line = re.sub('koopa_light_ship_build_cost_steel',koopa_light_ship_build_cost_steel,line) line = re.sub('koopa_light_ship_build_cost_chromium',koopa_light_ship_build_cost_chromium,line) line = re.sub('koopa_cruiser_build_cost_ic',koopa_cruiser_build_cost_ic,line) line = re.sub('koopa_cruiser_build_cost_steel',koopa_cruiser_build_cost_steel,line) line = re.sub('koopa_cruiser_build_cost_chromium',koopa_cruiser_build_cost_chromium,line) line = re.sub('koopa_heavy_ship_build_cost_ic',koopa_heavy_ship_build_cost_ic,line) line = re.sub('koopa_heavy_ship_build_cost_steel',koopa_heavy_ship_build_cost_steel,line) line = re.sub('koopa_heavy_ship_build_cost_chromium',koopa_heavy_ship_build_cost_chromium,line) line = re.sub('koopa_carrier_build_cost_ic',koopa_carrier_build_cost_ic,line) line = re.sub('koopa_carrier_build_cost_steel',koopa_carrier_build_cost_steel,line) line = re.sub('koopa_carrier_build_cost_chromium',koopa_carrier_build_cost_chromium,line) line = re.sub('koopa_ship_module_build_cost_ic',koopa_ship_module_build_cost_ic,line) line = re.sub('koopa_ship_module_build_cost_steel',koopa_ship_module_build_cost_steel,line) line = re.sub('koopa_ship_module_build_cost_chromium',koopa_ship_module_build_cost_chromium,line) f_path_modified.write(line) f_original.close() f_path_modified.close() os.remove("./units/equipment/"+f) os.rename(name_of_f_path_modified,"./units/equipment/"+f) def apply_values_units(f): f_path = re.sub(".+\.txt","units/\g<0>",f) f_original = open(f_path,"r", encoding="utf-8") # original file (full path), read only name_of_f_path_modified = re.sub("(.+)\.txt","units/\g<1>_m.txt",f) # the name of the modified file f_path_modified = open(name_of_f_path_modified,"w+", encoding="utf-8") for line in f_original: line = re.sub('koopa_inf_training_time',koopa_inf_training_time,line) line = re.sub('koopa_inf_combat_width',koopa_inf_combat_width,line) line = re.sub('koopa_light_tank_training_time',koopa_light_tank_training_time,line) line = re.sub('koopa_light_tank_combat_width',koopa_light_tank_combat_width,line) line = re.sub('koopa_medium_tank_training_time',koopa_medium_tank_training_time,line) line = re.sub('koopa_medium_tank_combat_width',koopa_medium_tank_combat_width,line) line = re.sub('koopa_heavy_tank_training_time',koopa_heavy_tank_training_time,line) line = re.sub('koopa_heavy_tank_combat_width',koopa_heavy_tank_combat_width,line) line = re.sub('koopa_super_heavy_tank_training_time',koopa_super_heavy_tank_training_time,line) line = re.sub('koopa_super_heavy_tank_combat_width',koopa_super_heavy_tank_combat_width,line) line = re.sub('koopa_amphibious_tank_training_time',koopa_amphibious_tank_training_time,line) line = re.sub('koopa_amphibious_tank_combat_width',koopa_amphibious_tank_combat_width,line) line = re.sub('koopa_modern_tank_training_time',koopa_modern_tank_training_time,line) line = re.sub('koopa_modern_tank_combat_width',koopa_modern_tank_combat_width,line) f_path_modified.write(line) f_original.close() f_path_modified.close() os.remove("./units/"+f) os.rename(name_of_f_path_modified,"./units/"+f) def apply_values_ship_modules(f): f_path = re.sub(".+\.txt","units/equipment/modules/\g<0>",f) f_original = open(f_path,"r", encoding="utf-8") # original file (full path), read only name_of_f_path_modified = re.sub("(.+)\.txt","units/equipment/modules/\g<1>_m.txt",f) # the name of the modified file f_path_modified = open(name_of_f_path_modified,"w+", encoding="utf-8") for line in f_original: line = re.sub('koopa_ship_module_build_cost_ic',koopa_ship_module_build_cost_ic,line) line = re.sub('koopa_ship_module_convert_cost_ic',koopa_ship_module_convert_cost_ic,line) line = re.sub('koopa_ship_module_build_cost_steel',koopa_ship_module_build_cost_steel,line) line = re.sub('koopa_ship_module_build_cost_chromium',koopa_ship_module_build_cost_chromium,line) f_path_modified.write(line) f_original.close() f_path_modified.close() os.remove("./units/equipment/modules/"+f) os.rename(name_of_f_path_modified,"./units/equipment/modules/"+f) # all prefixes: # EQUIPMENT: # (tank|anti_t|anti_a|art|inf|mech|motor|single|twin|quad|suppor|ship) # ("single": monoengine planes, "twin": twin engines planes, etc) # ("suppor": support) # UNITS: # (inf|engi) # first pass # ================= # INFANTRY UNITS # ================= for file in os.listdir("./units/equipment"): if re.match('(inf|suppor).+\.txt', file): modify_infantry_equipment(file) for file in os.listdir("./units"): if re.match('(inf|engi|field|logisti|militar|reco|signa|maintenanc).+\.txt', file): modify_infantry_units(file) # ================= # LIGHT TANK UNITS # ================= for file in os.listdir("./units/equipment"): if re.match('tank_light\.txt', file): modify_light_tank_equipment(file) for file in os.listdir("./units"): if re.match('light_armor\.txt', file): modify_light_tank_units(file) # ================= # MEDIUM TANK UNITS # ================= for file in os.listdir("./units/equipment"): if re.match('tank_medium\.txt', file): modify_medium_tank_equipment(file) for file in os.listdir("./units"): if re.match('medium_armor\.txt', file): modify_medium_tank_units(file) # ================= # HEAVY TANK UNITS # ================= for file in os.listdir("./units/equipment"): if re.match('tank_heavy\.txt', file): modify_heavy_tank_equipment(file) for file in os.listdir("./units"): if re.match('heavy_armor\.txt', file): modify_heavy_tank_units(file) # ================= # SUPER HEAVY TANK UNITS # ================= for file in os.listdir("./units/equipment"): if re.match('tank_super_heavy\.txt', file): modify_super_heavy_tank_equipment(file) for file in os.listdir("./units"): if re.match('super_heavy_armor\.txt', file): modify_super_heavy_tank_units(file) # ================= # AMPHIBIOUS TANK UNITS # ================= for file in os.listdir("./units/equipment"): if re.match('tank_amphibious\.txt', file): modify_amphibious_tank_equipment(file) for file in os.listdir("./units"): if re.match('amphibious_armor\.txt', file): modify_amphibious_tank_units(file) # ================= # MODERN TANK UNITS # ================= for file in os.listdir("./units/equipment"): if re.match('tank_modern\.txt', file): modify_modern_tank_equipment(file) for file in os.listdir("./units"): if re.match('modern_armor\.txt', file): modify_modern_tank_units(file) # ================= # SINGLE ENGINE AIR UNITS # ================= for file in os.listdir("./units/equipment"): if re.match('single_engine_airframe\.txt', file): modify_single_engine_equipment(file) # ================= # TWIN ENGINE AIR UNITS # ================= for file in os.listdir("./units/equipment"): if re.match('twin_engine_airframe\.txt', file): modify_twin_engine_equipment(file) # ================= # QUAD ENGINE AIR UNITS # ================= for file in os.listdir("./units/equipment"): if re.match('quad_engine_airframe\.txt', file): modify_quad_engine_equipment(file) # ================= # LIGHT SHIP (DESTROYER) UNITS # ================= for file in os.listdir("./units/equipment"): if re.match('ship_hull_light\.txt', file): modify_light_ship_equipment(file) # ================= # CRUISER UNITS # ================= for file in os.listdir("./units/equipment"): if re.match('ship_hull_cruiser\.txt', file): modify_cruiser_equipment(file) # ================= # HEAVY SHIP (BATTLESHIP) UNITS # ================= for file in os.listdir("./units/equipment"): if re.match('ship_hull_heavy\.txt', file): modify_heavy_ship_equipment(file) # ================= # CARRIER UNITS # ================= for file in os.listdir("./units/equipment"): if re.match('ship_hull_carrier\.txt', file): modify_carrier_equipment(file) # ================= # SHIP MODULES # ================= for file in os.listdir("./units/equipment/modules"): if re.match('00_ship_modules\.txt', file): modify_ship_module_equipment(file) # second pass print("Applying values in the files in the \"equipment\" folder") for file in os.listdir("./units/equipment"): if re.match('.+\.txt', file): apply_values_equipment(file) print("Applying values in the files in the \"units\" folder") for file in os.listdir("./units"): if re.match('.+\.txt', file): apply_values_units(file) print("Applying values in the files in the \"equipment/modules\" folder") for file in os.listdir("./units/equipment/modules"): if re.match('.+\.txt', file): apply_values_ship_modules(file) print("done")