1. We have added the ability to collapse/expand forum categories and widgets on forum home.
    Dismiss Notice
  2. Photobucket has changed its policy concerning hotlinking images and now requires an account with a $399.00 annual fee to allow hotlink. More information is available at: this link.
    Dismiss Notice
  3. All Civ avatars are brought back and available for selection in the Avatar Gallery! There are 945 avatars total.
    Dismiss Notice
  4. To make the site more secure, we have installed SSL certificates and enabled HTTPS for both the main site and forums.
    Dismiss Notice
  5. Civ6 is released! Order now! (Amazon US | Amazon UK | Amazon CA | Amazon DE | Amazon FR)
    Dismiss Notice
  6. Dismiss Notice
  7. Forum account upgrades are available for ad-free browsing.
    Dismiss Notice

[BtS SDK] Don't show units over cities

Discussion in 'Civ4 - Mod Components' started by 77alex77, Jan 14, 2008.

  1. 77alex77

    77alex77 Chieftain

    Joined:
    Oct 25, 2007
    Messages:
    91
    Location:
    Somewhere beyond the sea
    Hi there,
    in CivIII there has been an option called "Show units over cities" or something like that. If it was disabled units located in cities were not shown on the map.
    I know that there isn't such an option in CivIV but I wanted to have it more than ever, because it doesn't look good if a huge knight or whatever is standing on my city so that all the buildings cannot be seen properly.
    I did some research in the SDK and found a simpel but 'suboptimal' solution:
    I modified the function "updateCenterUnit()" in CvPlot.cpp:
    Spoiler :
    void CvPlot::updateCenterUnit()
    {
    if (!GC.IsGraphicsInitialized())
    {
    return;
    }

    if (!isActiveVisible(true))
    {
    setCenterUnit(NULL);
    return;
    }

    setCenterUnit(getSelectedUnit());

    // BEGIN 77alex77 don't show units over cities

    //if this plot has a city and no unit is selected:
    //set no center unit
    if (getCenterUnit() == NULL && !(getPlotCity() == NULL))
    {
    return;
    }

    // END 77alex77 don't show units over cities

    if (getCenterUnit() == NULL)
    {
    setCenterUnit(getBestDefender(GC.getGameINLINE().getActivePlayer(), NO_PLAYER, NULL, false, false, true));
    }

    if (getCenterUnit() == NULL)
    {
    setCenterUnit(getBestDefender(GC.getGameINLINE().getActivePlayer()));
    }

    if (getCenterUnit() == NULL)
    {
    setCenterUnit(getBestDefender(NO_PLAYER, GC.getGameINLINE().getActivePlayer(), gDLL->getInterfaceIFace()->getHeadSelectedUnit(), true));
    }

    if (getCenterUnit() == NULL)
    {
    setCenterUnit(getBestDefender(NO_PLAYER, GC.getGameINLINE().getActivePlayer(), gDLL->getInterfaceIFace()->getHeadSelectedUnit()));
    }

    if (getCenterUnit() == NULL)
    {
    setCenterUnit(getBestDefender(NO_PLAYER, GC.getGameINLINE().getActivePlayer()));
    }
    }

    This solution is 'suboptimal' because units in cities cannot be selected the normal way (left mouse button) anymore.
    They have to be selected via the context menu. The context menu for a tile can by default be accessed by "shift + left mouse button" or, if the respective option is activated (Civ4 options menu), by "right mouse button". Once a unit is selected, the usual plot list will appear and units can be selected as normal. It is also possible to select units in the city screen.
    I will see if I can get this fixed. Perhaps someone knows a simple solution for this problem.

    I don't know if there are other drawbacks. I played with this modification nearly half of a game and I had no problems. I also did some WB experiments to see if it effects bombing, nuking, etc. but it doesn't seem so.

    I know that there might be not many civers who want such a 'feature', but I always missed this option and now it is 'really' possible to see all the city buildings on the world map.

    I integrated my modification in the BtS 3.17 dll.

    Installation instructions are included in the readme.
    It is possible to start using this dll in the middle of a game.
    So if you are interested, just have a look.
    If you don't like it, just restore your old dll.


    Don't show units over cities DLL (BtS 3.17):
    Download here
     
  2. keldath

    keldath LivE LonG AnD PrOsPeR

    Joined:
    Dec 20, 2005
    Messages:
    6,144
    Location:
    israel
    very cool idea!!
    well done!
     
  3. frekk

    frekk Scourge of St. Lawrence

    Joined:
    Jun 21, 2003
    Messages:
    3,151
    Location:
    Kingston, Ontario
    Awesome!! Thankyou so much!! I was just asking about this the other day!!

    I really missed this from civ3. Not so much because of the giants towering over the city, but because it obscures the city graphics.

    Just curious, is it possible to use the CvGameCoreDLL.dll in a mod or custom assets rather than replacing the original?
     
  4. 77alex77

    77alex77 Chieftain

    Joined:
    Oct 25, 2007
    Messages:
    91
    Location:
    Somewhere beyond the sea
    I'm not sure if it can be placed in the custom assets folder. I read somewhere that this isn't possible as the dll will be ignored.

    It is possible to install it as a mod but I didn't try it.
    What you would have to do is to create the following folders:
    .../Sid Meier's Civilization IV/Beyond the Sword/Mods/ModName
    and
    .../Sid Meier's Civilization IV/Beyond the Sword/Mods/ModName/Assets
    The dll has to be placed in the .../ModName/Assets folder.
    Then you should be able to load the mod called "ModName" as normal.
    I'm not sure if a ModName.ini is also needed...will try it later.

    I don't recommend to install it as a mod.
    If you install it as described in the readme you can easily switch between the dlls (by renaming the files for example).
    So if you are in the middel of a game and you think: "I want to see my glorious cities!" just use the provided dll and play on.
    If you now play 50 turns and you think: "My citizens must feel unprotected if the garrison troops are not displayed." ;)
    just switch back to your normal dll.
    If it is installed as a mod you will have to start a new game to try it.
     
  5. frekk

    frekk Scourge of St. Lawrence

    Joined:
    Jun 21, 2003
    Messages:
    3,151
    Location:
    Kingston, Ontario
    Ok, been trying this out and I can't live without it now. But I have a problem now, because there is another SDK mod I can't live without. I know nothing about programming but I'm extremely tempted to try my hand at merging the two since I see the code posted above, it makes it look easy. Exactly how difficult would it be for me to learn from scratch (no programming knowledge at all, other than some xml and doing a few Winmerge python merges) how to merge this with another SKD mod? Would it be a complex thing that I'd spend days of trial and error on, or something I could figure out and do in 4 or 5 hours of an evening?
     
  6. 77alex77

    77alex77 Chieftain

    Joined:
    Oct 25, 2007
    Messages:
    91
    Location:
    Somewhere beyond the sea
    I'm sure, as you have done some xml and python stuff already, that you will figure this out in less than 4 hours.
    Of course you will need the complete source code of the SDK mod. Just open the file "CvPlot.cpp" and search for the function "updateCenterUnit()". The only thing you have to do is to insert that little code fragment given in the first post.
    This one:
    Spoiler :
    // BEGIN 77alex77 don't show units over cities

    //if this plot has a city and no unit is selected:
    //set no center unit
    if (getCenterUnit() == NULL && !(getPlotCity() == NULL))
    {
    return;
    }

    // END 77alex77 don't show units over cities

    Be sure to insert it at the right place. So right after "setCenterUnit(getSelectedUnit());".

    Now, that the merging is done, all you have to do is to compile the source code to get your "CvGameCoreDLL.dll".
    This is also not difficult as there is an excellent tutorial.
    If you follow the instructions step by step, nothing will go wrong.

    I don't think so, but it might be possible that the merging will not work if...
    ...the other mod also modifies the "updateCenterUnit()" function. In this case you would have to figure out what it does there.
    ...the other mod uses the variable "centerUnit" for other purposes than to determine which unit of a stack should be displayed. But this is unlikely.

    I hope this helped. Have fun!

    alex
     

Share This Page