1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

[SpaceMod] Unit Sandbox

Discussion in 'Civ4 - Mod Components' started by Vadus, Mar 9, 2006.

  1. Vadus

    Vadus pretend the impossible

    Joined:
    Nov 23, 2003
    Messages:
    374
    Location:
    Northern Germany
    current Version : 0.1

    Hi all,

    let me present you the Unit Sandbox, with which you can rename and prepromote Units. These units can be built beside the original units.
    The good thing is, that this system isn't touching the xml structure. Only GlobalContext is used, so that this ModComponent can be added to another mod easily ;)
    Because this UnitSandbox will be a part of my SpaceMod, you will find some scifi designations in the files, e.g. the most important class , which is called : SpaceMod.py . But anyone is free to use this UnitBox for his mod.
    Changes in bigger files are surrounded with a comment containing the word 'Vadus' or 'SpaceMod' .
    here are some screenshots explaining, how the Sandbox is working:

    http://www.vadus.de/images/civ4Unitsandbox01.jpg
    http://www.vadus.de/images/civ4Unitsandbox02.jpg
    http://www.vadus.de/images/civ4Unitsandbox03.jpg
    http://www.vadus.de/images/civ4Unitsandbox04.jpg

    Many Thanks to talchas, Belizan, Kael and 12monkeys for answering my questions here :)

    Installation
    Unzip the file to your Civ4 Mod folder, and start the Mod 'Vadus' .

    Current Problems :
    1. Don't swich from civ to windows, while you have the SandBox Screen open,
    because internal variables will be reinitialized (which means that the civ variables will be refreshed, and the SpaceMod internals deleted), and the SandBox System won't work anymore
    2. I can't find the code lines for setting the name of the unit, which is currently built by a city, at the cities textbars on the map (not in city screen) ! So, where you can see the city name and the current production...
    3. Same thing with the unit name of the city production bar in the cityscreens header.

    Future Features
    1. UnitList of predefined units will be saved, too, so that the player will get the old unitlists when he loads a game.
    2. Buttons of the UnitSandbox Screen : Remove and Replace a predefined unit
    3. Change the unit costs, depending on the amount of promotions
    4. Change the List of Available Promotions by regarding the promotions dependencies
    5. Set the Unit MaxHitpoints with the Sandbox, if possible


    It would be great, if anyone wants to help me out a bit, because I have only time in the late evening to do something. And with my hole spacemod project, changes to this will take much much time ..
     

    Attached Files:

  2. woodelf

    woodelf Bard

    Joined:
    Jun 12, 2003
    Messages:
    15,036
    Location:
    Gallery
    Looks cool. ;)
     
  3. talchas

    talchas Chieftain

    Joined:
    Jan 3, 2006
    Messages:
    428
    You should probably take a look at the SD-Toolkit and save your info using that - it should fix both of these by letting Civ4 deal with these issues. Looks to me like you could do this:
    Code:
        def __init__(self): 
            """ Create singleton instance """ 
            # Check whether we already have an instance 
            if getInstance() is None: 
                # Create and remember instance 
                setInstance(SpaceMod.__impl())
                  
        def __getattr__(self, attr): 
            """ Delegate access to implementation """ 
            return getattr(getInstance(), attr) 
     
        def __setattr__(self, attr, value): 
            """ Delegate access to implementation """ 
            return setattr(getInstance(), attr, value) 
    
    def getInstance():
        try:
            return sdGetGlobal( 'MyModName_string', 'SpaceMod.py.instance' )
        except: # should only take the particular type that this throws, but I don't know what that is.
            return None
    def setInstance(inst):
        return sdSetGlobal( 'MyModName_string', 'SpaceMod.py.instance',inst)
    
    This might have two problems - it could slow the game down if you use SpaceMod.py a lot, as you are then unpickling each time - a fix would be to cache an instance like before, but call getInstance "if SpaceMod.__instance is None" and only make a new __impl if that also fails. The second problem.... I forget what I was going to say :blush:.
     
  4. This is just an incredible idea! I mean if this is possible maybe somebody will figure out a way to programmatically assemble units (as long as they share bones and animation it shouldn't be a problem), then you could not only assign promotions at will but will actually be able to assemble brand new units.

    Great job thinking outside the box Vadus. :goodjob:
     
  5. Vadus

    Vadus pretend the impossible

    Joined:
    Nov 23, 2003
    Messages:
    374
    Location:
    Northern Germany
    Is the Toolkit a Mod ? Or do I have to import something from civ4 additionaly ?
    I get the error : sdSetGlobal - not found

    EDIT : allright, found it : http://forums.civfanatics.com/showthread.php?t=146130
     
  6. GeoModder

    GeoModder Chieftain

    Joined:
    Nov 29, 2005
    Messages:
    7,512
    I think I'll link this mod to the AC modteam. :goodjob:
     
  7. Vadus

    Vadus pretend the impossible

    Joined:
    Nov 23, 2003
    Messages:
    374
    Location:
    Northern Germany
    do it ! :)
     
  8. GeoModder

    GeoModder Chieftain

    Joined:
    Nov 29, 2005
    Messages:
    7,512
    Done already. ;)
     
  9. Vadus

    Vadus pretend the impossible

    Joined:
    Nov 23, 2003
    Messages:
    374
    Location:
    Northern Germany
    @talchas :
    I tried your sample, but get an error in the sdToolKit.py (see attachment).
    After loading the mod, I get the message, that the Mod Data is initialized (dsToolKit.py -> sdModInit ) , but than after pressing the Unit Sandbox AdvisorButton the error occurs.

    Also when I import the SpaceMod.py in the sdToolKit the error occurs in the following function :
    Code:
    def sdSetGlobal( ModID, var, val ):
    	szGlobal = 'Global'
    	mTable           = sdModLoad(ModID)
    	if ( mTable.has_key(szGlobal) ):
    		eTable   = pickle.loads(mTable[szGlobal])   # <-- occurs here
    	else:
    		eTable   = {}
    	eTable[var]      = val
    	mTable[szGlobal] = pickle.dumps(eTable)
    	sdModSave(ModID, mTable)
    
    
    do you, or anyone else, have any thoughts about this ?
    I assume, that the pickle functionality only can load known instances from a dumped file like a list of strings and stuff , but no self made classes ? :hmm:
     

    Attached Files:

  10. talchas

    talchas Chieftain

    Joined:
    Jan 3, 2006
    Messages:
    428
    I'll go and fiddle around with python for a bit and see what is wrong
    I don't think so - the whole point is that pickle can serialize most classes with no effort. (or at least that is my understanding, anyone who actually really knows python feel free to correct me)
     
  11. talchas

    talchas Chieftain

    Joined:
    Jan 3, 2006
    Messages:
    428
    Ah, found the problem:
    From the pickle docs:
    So, __impl isn't pickleable. However, if you change over to using sd toolkit to make it singleton, then it doesn't matter - move all of the functions to class SpaceMod, remove __getattr__ and __setattr_ and instead of doing SpaceMod.SpaceMod().doStuff() do SpaceMod.getInstace().doStuff()
     
  12. Vadus

    Vadus pretend the impossible

    Joined:
    Nov 23, 2003
    Messages:
    374
    Location:
    Northern Germany
    Yes, this should behave like the actual Singelton. I will try, and test it also under the performance aspect.
     
  13. Belizan

    Belizan Chieftain

    Joined:
    Jan 11, 2006
    Messages:
    1,060
  14. pap1723

    pap1723 Chieftain

    Joined:
    Apr 19, 2001
    Messages:
    507
    Location:
    Chicago, IL
    First, great idea for a MOD, and great job! I may not be understanding how the upgrading system is working, but here are a few ideas (if this is not how it is already)...

    First, you can set the upgrades to the units in the future. They will use whatever experience points they have when they are built to upgrade, and they will continue to auto-update when they can based on what you chose for them on creation.

    Second, you can use as many upgrades as you want on a unit. The unit will be built with the upgrades from the beginning, however, the unit cannot upgrade again, will cost a lot more (cumulative for each upgrade)
     
  15. Vadus

    Vadus pretend the impossible

    Joined:
    Nov 23, 2003
    Messages:
    374
    Location:
    Northern Germany
    This is like it's working now. But the unit still can get promotions on the battlefield, but in my mind, this should be other promotions.
    For example : In the unitbox you can upgrade the unit from a set of 10 Promotions (e.g. Drive Level 1 - 3) . In the Battlefield the Unit can be upgraded with other, battle - promotions, like March ..
     
  16. Shqype

    Shqype Shqyptar

    Joined:
    Nov 15, 2005
    Messages:
    2,468
    Location:
    New York + Shqypni
    He didn't think outside the box, he thought inside the sandbox :lol:

    Looks very, very cool! Nice work :)
     
  17. darkedone02

    darkedone02 The Suggestor

    Joined:
    Mar 9, 2006
    Messages:
    1,728
    Location:
    Louisville, Kentucky
    finnally, we got a unit editor, this is great, good job. Just make sure you update this thing cause we want you to iron some bugs and improve this very important and useful component.
     

Share This Page