Project Perfect Mod Forums
:: Home :: Get Hosted :: PPM FAQ :: Forum FAQ :: Privacy Policy :: Search :: Memberlist :: Usergroups :: Register :: Profile :: Log in to check your private messages :: Log in ::


The time now is Sat Apr 13, 2024 12:22 am
All times are UTC + 0
Python script to compare units/buildings
Moderators: Global Moderators, Red Alert 2 Moderators
Post new topic   Reply to topic Page 1 of 1 [3 Posts] Mark the topic unread ::  View previous topic :: View next topic
Author Message
nlspeed
Grenadier


Joined: 26 Dec 2016

PostPosted: Wed Apr 05, 2023 11:06 am    Post subject:  Python script to compare units/buildings Reply with quote  Mark this post and the followings unread

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):

Back to top
View user's profile Send private message
G-E
Defense Minister


Joined: 09 Feb 2015

PostPosted: Wed Apr 05, 2023 1:40 pm    Post subject: Reply with quote  Mark this post and the followings unread

What exactly are you comparing?

_________________
http://www.moddb.com/mods/scorched-earth-ra2-mod-with-smart-ai

Back to top
View user's profile Send private message
nlspeed
Grenadier


Joined: 26 Dec 2016

PostPosted: Wed Apr 05, 2023 2:30 pm    Post subject: Reply with quote  Mark this post and the followings unread

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.

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [3 Posts] Mark the topic unread ::  View previous topic :: View next topic
 
Share on TwitterShare on FacebookShare on Google+Share on DiggShare on RedditShare on PInterestShare on Del.icio.usShare on Stumble Upon
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


Powered by phpBB © phpBB Group

[ Time: 0.1544s ][ Queries: 11 (0.0080s) ][ Debug on ]