Posted: Wed Apr 05, 2023 11:06 am Post subject:
Python script to compare units/buildings
A simple Python script to compare units/buildings in rulesmd.ini or spawner.xdp (or technically any .ini-layout kind of file). Should be self-explanatory, but I added some comments anyway.
You might want to add some additional code to investigate projectiles too, for e.g. prism shrapnel. Or to properly handle cases such as the V3 or the Aircraft Carrier, that do not actually attack with their weapon. Also applies to gatling stages. This wasn't necessary for my purposes, so I didn't do it (yet?) - but I'm pretty sure anyone reading this can figure out how to make this based on the code below.
In general, this could be coded >much< better (using functions, for one), but I made this as quick-and-dirty as possible, as it works for my purposes, and I thought some might find it useful, so here it is:
Code:
import configparser
config = configparser.ConfigParser(interpolation=None)#,inline_comment_prefixes=';')
config.read("C:\\Program Files (x86)\\EA Games\\Command & Conquer The First Decade\\Command & Conquer Red Alert(tm) II\RA2\\rulesmd.ini") #Your rulesmd.ini or spawner.xdp directory/file
unitslist = ['E1','E2','INIT'] #The units/buildings you want to compare
unitattributeslist = ['name','cost','prerequisite','armor','strength','speed','sight','primary','secondary','eliteprimary','elitesecondary','occupyweapon','eliteoccupyweapon'] #The unit/building attributes you want to compare
weaponattributeslist = ['damage','rof','range','speed','burst','warhead'] #The weapon attributes you want to compare
warheadattributeslist = ['verses','cellspread','percentatmax','pronedamage'] #The warhead attributes you want to compare
for unit1 in unitslist:
unitresult = {i:j for i,j in config.items(unit1)}
for unitattribute in unitattributeslist:
for unit2 in unitresult.items():
if unitattribute in unit2:
print(str(unit2).split(';')[0].strip()) #Ignores comments (';' and anything after it) and ignores leading or trailing whitespaces (e.g. often there is a space before ';')
if unitattribute in ('primary','secondary','eliteprimary','elitesecondary','occupyweapon','eliteoccupyweapon'):
weaponresult = {k:j for k,j in config.items(unitresult[unitattribute].split(';')[0].strip())}
for weaponattribute in weaponattributeslist:
for weapon1 in weaponresult.items():
if weaponattribute in weapon1:
print(' ',str(weapon1).split(';')[0].strip())
if weaponattribute in ('warhead'):
warheadresult = {k:j for k,j in config.items(weaponresult[weaponattribute].split(';')[0].strip())}
for warheadattribute in warheadattributeslist:
for warhead1 in warheadresult.items():
if warheadattribute in warhead1:
print(' ',str(warhead1).split(';')[0].strip())
print('')
Output (note that I have removed elite weapons and occupy weapons from my mod):
Whatever you want to compare; look at the output picture. It is simply a thing I put together in a few minutes because this is an easier overview than needing to Ctrl F '[e1]', '[M60]', '[e2]', '[M1Carbine]', et cetera, and either remembering all the results or writing them down. Now I can see them automatically within seconds. QUICK_EDIT
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum