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

Python issues

Discussion in 'Civ4Col - Medieval: Conquests' started by orlanth, Dec 29, 2013.

  1. orlanth

    orlanth Storm God. Yarr!

    Joined:
    Nov 17, 2001
    Messages:
    1,759
    I PMed Platyping to see if he'd be willing to look at M:C & potentially help out with Python issues; he is temporarily out of commission but hopefully may be able to look at it once installed.
    Here is a list of Python stuff from the other thread. Personally I don't mind either way about whether uninvented yields can be seen in city screens, but having some Bonuses able to be hidden on the map until a tech is discovered is a good thought (IIRC they did this in Civ4, where techs could separately unlock:
    1) when a given Bonus becomes visible on the map
    2) when the Bonus becomes exploitable & can be used (applies its pluses to yield production)

    Potentially Perpetually Perplexing Python Projects:
    1. Tech screen resolution: make screens viewable for multiple resolutions (does this need to be done for other screens too?)
    2. Bonus resources should be hidden on the map until invented
    3. For multiple new yields, all the tiny Gamefonts yield icons in Pedia (and some other screens) will be difficult for new players to identify & know what they mean. Is it possible to add a tooltip that displays the text name of the yield when hovering over its Gamefonts icon? Alternately, could just add text name of yields to appear alongside the icon when needed: eg +25% Chainmail :greatwork: production instead of +25% :greatwork: production. Think this is already the case for some Pedia pages but not all.
    4. City screen resources: Yields not yet invented should be hidden. The main problem is that the list of resources is generated on game start/load rather than when the screen is opened. This makes it tricky to add something during a game.
    5. Planning to re-add Civics screen; either like vanilla or a modification like Nightingale found here: http://forums.civfanatics.com/showthread.php?t=517549
     
  2. Kailric

    Kailric Jack of All Trades

    Joined:
    Mar 25, 2008
    Messages:
    3,094
    Location:
    Marooned, Y'isrumgone
    I believe these two could be easily implemented as I have thought of this before. I haven't looked at the code yet but it seems like we could add a new attribute to plots like "techbonus". If a bonus has to be discovered at the start of the game then instead of a plot being assigned a bonus it is instead assigned to "techbonus". Then once the bonus is discovered by the viewing player the plot is then assigned the bonus. Maybe something like that could work for us. Also, if the above fix works it should work for city screens as well, as the city screen plots are simply map plots. When you open a the city screen the map centers on that city and leaves visible the plots in the plot screen.

    There maybe an easier way but that is one potential way.
     
  3. Kailric

    Kailric Jack of All Trades

    Joined:
    Mar 25, 2008
    Messages:
    3,094
    Location:
    Marooned, Y'isrumgone
    This is the actually code from Civ4 and it appears just the way I imagined it would. I am not sure if adding TeamType to getBonusType is all we would need to do for visibility of the Bonus but it should work for things like calculating yields. I am sure we can figure it out though.

    Code:
    BonusTypes CvPlot::getBonusType(TeamTypes eTeam) const
    {
    	if (eTeam != NO_TEAM)
    	{
    		if (m_eBonusType != NO_BONUS)
    		{
    			if (!(GET_TEAM(eTeam).isHasTech((TechTypes)(GC.getBonusInfo((BonusTypes)m_eBonusType).getTechReveal()))))
    			{
    				return NO_BONUS;
    			}
    		}
    	}
    
    	return (BonusTypes)m_eBonusType;
    }
     
  4. platyping

    platyping Sleeping Dragon

    Joined:
    Oct 22, 2010
    Messages:
    4,626
    Location:
    Emerald Dreams
  5. Nightinggale

    Nightinggale Chieftain Supporter

    Joined:
    Feb 2, 2009
    Messages:
    3,987
    I already wrote CvPlayer::canUseBonus(BonusTypes eBonus) to quickly tell if a player has access to a special bonus or not.

    Looks like just writing code like this will not really solve the problem. The current python code use plot owner as eTeam when adding yield gain and possibly also bonus graphics. We should use the Civ4 solution where bonuses (and yield gain?) use the player's inventions as base to draw the map nomatter who owns the plots. Currently mountains provide stone in unclaimed plots, but not once claimed unless you have invented stone. It would be better to tell what yield YOU would gain from a plot instead of revealing not yet invented yields.

    I was talking about the yield rows in the bottom of the city screen, not the map. Each yield has a fixed sized and location for its "box" meaning resizing them to add another one appears to be impossible. At least nothing I tried worked. If we could re-allocate or resize the boxes then the rest of the needed code to hide/show invented yields would be fairly strait forward.
     
  6. Kailric

    Kailric Jack of All Trades

    Joined:
    Mar 25, 2008
    Messages:
    3,094
    Location:
    Marooned, Y'isrumgone
    Well, dag nabit:cry: By creating one Python Screen for Trade Screens I created an issue with my Trade Screen Quick links at the top of each Trade Screen. They send all the correct info just like they should but that is the problem. The links tell python to open the Single Trade Screen... which is already open:crazyeye: So, the links do nothing. Open this screen Python, and Python goes, "It's already open, duh!!":p

    So I am pondering how to fix this... an idea has just come to mind. What if I use two almost exact copy Python screens, except each Python screen will call the other in its quick links. Ok, going to see if this works. I already have 3 Python Trade Screens so, just need to change the code in one other one...


    Also, since I was needing to use this thread I decided to make an update on these issues, orlanth you can update this first post if you like...

    This still needs to be investigated further

    This is fixed and working in development version

    This still needs to be investigated further

    This is fixed and working in development version

    Civic Screen is in and steadily improving :goodjob:
     
  7. Kailric

    Kailric Jack of All Trades

    Joined:
    Mar 25, 2008
    Messages:
    3,094
    Location:
    Marooned, Y'isrumgone
    This worked like a charm.. only problem is if I update one trade screen I'll have to update the other. Not so big a deal since it is just a copy and past operation. But still, it would be nice to find another way perhaps with just one single screen.

    Anyway, it is so cool how sometimes taking a break and writing about your problem you can many times solve it.:goodjob:

    Edit: Now my issue is HotKeys. By bypassing the Control system to have one Python Trade Screen (or two) there will no longer be a hot key for all the trade screens. However, there can be one hot key that Brings up the First Trade Screen. I just tried this and it works. Because the doControl() command does not pass arguments we cannot pass what trade screen it is, we just have to set a default in the SingleTradeScreen. Unless someone can think of something else... hmm, ponder ponder...

    BOOOOMMM!!!!!:spear: my pondering may have paid off. ControlInfos are defined in the XML just like all other xml values. We just add a new XML tag to ControlInfos for the type of TradeScreen. Then when CONTROL_SPICE_ROUTE_SCREEN is called we get the TradeScreen with a GC.getControlInfo(CONTROL_SPICE_ROUTE_SCREEN).getTradeScreen(), then we can pass that argument on to the SingleTradeScreen.

    I'll have to work this out in the morning but it seems like it should work fine. When that is done I'll work up some screen shots of button placements so we can decide where we would like our buttons.

    One point to make, ControlTypes are not really modder friendly as you have to edit the DLL to get them in the game. So, I can go ahead and add a few more dummy ones the just return false if nothing is assigned (there is already 3). Albeit, we will need hotkeys assigned to them as well.
     
  8. Nightinggale

    Nightinggale Chieftain Supporter

    Joined:
    Feb 2, 2009
    Messages:
    3,987
    Well if you commit once in a while and push, then I would be able to look at the code and just maybe I could come up with an idea. You don't have to make everything for a certain feature to commit. In fact it would make sense to commit at certain milestones, such as the time when you manage to display two different trade screens using one python file.

    The domestic advisor is just one python file, which then has a variable to tell which state it is in. Clicking the buttons change state and redraw. Give each trade screen a state ID (make it the same as trade screen ID) and the system should work just fine. I think I would be able to implement something like that.
     
  9. Kailric

    Kailric Jack of All Trades

    Joined:
    Mar 25, 2008
    Messages:
    3,094
    Location:
    Marooned, Y'isrumgone
    Yeah, I've been commiting just haven't been pushing:D Besides, you were brainstorming. :sleep:

    I brainstormed as well and woke up remembering that you can check Widgets in the python as well. It could be as simple as making the widget close the screen so a new one can open, I'll have to see, but as you pointed out it is doable.
     
  10. Kailric

    Kailric Jack of All Trades

    Joined:
    Mar 25, 2008
    Messages:
    3,094
    Location:
    Marooned, Y'isrumgone
    Actually, I just discovered my issue...
    Code:
    if screen.isActive():
        return
    When ever I would call up a new screen, this code would cancel it:crazyeye:

    It works fine with one TradeScreen python file if I comment out those two lines. Question is, will that cause issues? Checking the code the one place this would be called more than once is when a Ship arrives at a TradeScreen and it auto calls up the screen. However, the code checks if there is already a screen up and cancels the call if there is.

    I see that having one TradeScreen Python file would lead to issues if you have two ships just arrive at two different TradeScreens. The way the code is now it checks for queued python screen text like "showSpiceRouteScreen". And since all the screens use that same python screen only one of the ships would be queued for popup. So, I need to check for TradeScreen route instead of the text in the queue.
     
  11. Nightinggale

    Nightinggale Chieftain Supporter

    Joined:
    Feb 2, 2009
    Messages:
    3,987
    Good question. I will look into it ASAP.

    One thing I can think of before reading the code is to have a variable for current trade screen and one for requested. The return statement should then only trigger if those two are identical. I need to look into the code to say if I think that is a good solution though.
     
  12. Nightinggale

    Nightinggale Chieftain Supporter

    Joined:
    Feb 2, 2009
    Messages:
    3,987
    The start of the function is like this:
    Code:
    def interfaceScreen(self, iTradeRoute):
    (skipped lines)
    if screen.isActive():
    	return
    Line 85:
    Code:
    if (iTradeRoute >= 0):
    	self.TRADE_SCREEN_SPICE_ROUTE_MARKET = iTradeRoute
    I wonder if self.TRADE_SCREEN_SPICE_ROUTE_MARKET can be set to -1 in init and then the return code is written:
    Code:
    if screen.isActive() and  and iTradeRoute == self.TRADE_SCREEN_SPICE_ROUTE_MARKET:
    	return
    That way the return will only trigger if you try to switch to the already selected trade screen. Maybe iTradeRoute should be >= 0 too.
     
  13. Kailric

    Kailric Jack of All Trades

    Joined:
    Mar 25, 2008
    Messages:
    3,094
    Location:
    Marooned, Y'isrumgone
    Most of the screens have the return on if already active, this may have been used so that pressing a control key, like F2 would only bring the screen up if it wasn't already up. F2 use to bring up the Spice Route Screen, and it still does since the code will default to EuropeType 1 (self.TRADE_SCREEN_SPICE_ROUTE_MARKET = 1) which is the SpiceRoute currently. But if we add a new xml tag to ControlInfos like I mentioned we can define what Trade Screen is being called. So, that when you press F2 it will check if the Spice Route Screen is already up as you pointed out, and this should resolve any issues. Also, we have never decided on what the HotKeys should be.

    We could make at least 3 of the F keys, for Trade Screens. Right now we have F2,F3,F4 for TradeScreens, so we could do F2-F4, Alt+F2-F4, and perhaps Shift+F2-F4 for a total of 9 default Trade Screens players can add, already defined in the Control Infos. Then all they have to do is add the Trade Screen info in EuropeInfos and then add the EuropeType to ControlInfos.
     
  14. Nightinggale

    Nightinggale Chieftain Supporter

    Joined:
    Feb 2, 2009
    Messages:
    3,987
    How about every time a trade screen is drawn, the ID is send to the DLL. If F2 is pressed, it will open the trade screen based on this memory. If the memory is -1 (default at start) or the trade screen in question can't be used, loop though all trade screens and enter the first usable one.

    I consider the hotkey to a specific one a minor problem. In fact I consider it a detail, which should not be looked at until everything else is working.
     
  15. Kailric

    Kailric Jack of All Trades

    Joined:
    Mar 25, 2008
    Messages:
    3,094
    Location:
    Marooned, Y'isrumgone
    Heh, everything else is working (in regards to one python file for TradeScreens). But, I need to clean up the code, and it would only take a few minutes to actually get the Hotkeys to work correctly, plus I want to experiment with button placement so I'll do that all at once, but fo now I am looking over my todo list...
     
  16. Kailric

    Kailric Jack of All Trades

    Joined:
    Mar 25, 2008
    Messages:
    3,094
    Location:
    Marooned, Y'isrumgone
    I was looking into Domestic Adviser and just seeing what it would take to make it so you can add/remove any Transport to a Trade Route right there on the screen but there are issues...

    The Buttons that work are added with a screen.addCheckBoxGFCAt("RoutePanel" + str(iRow),.. with a WIDGET_GENERAL value of 10001

    Then the Bottom row lists all transports with the same addCheckBoxGFCAt function and same the WIDGET_GENERAL value of 10001.

    When the code checks for what widget was pressed the Bottom row is completely ignored and never is sent to def handleInput. Makes no sense.
     
  17. Nightinggale

    Nightinggale Chieftain Supporter

    Joined:
    Feb 2, 2009
    Messages:
    3,987
    Code:
    def handleInput (self, inputClass):
    	if (inputClass.getNotifyCode() == NotifyCode.NOTIFY_CLICKED):
    		if (inputClass.getButtonType() == WidgetTypes.WIDGET_GENERAL):
    			iData = inputClass.getData1()
    			elif (iData == 10001):
    				if (self.selectedSelectionGroupHeadUnitID == inputClass.getData2()):
    					self.selectedSelectionGroupHeadUnitID = -1
    					self.drawContents()
    				else:
    					self.selectedSelectionGroupHeadUnitID = inputClass.getData2()
    					self.drawContents()
    Looks ok to me. All buttons have the ID 10001, but also they all add the unitID as Data2 (the next argument in screen.addCheckBoxGFCAt).

    The problem appears to be that as far as I can tell, self.selectedSelectionGroupHeadUnitID is only used to set help text :confused:
    I suspect this screen is left unfinished. It's a RaR feature and they ended up with a traderoute interface outside the domestic advisor.

    I think we should forget about the current file and make a plan for what we want the interface to do. Once there is a clear goal, we can see how much of the existing code we can reuse and maybe we should write a new page from scratch. Try writing precisely what you want to do regarding trading in DA (in the AI trading thread) and once we have a clear concept of the goal, we can focus on how to code it. I would love to add more pages to DA, but I don't know what you are thinking unless you tell me ;)
     
  18. Kailric

    Kailric Jack of All Trades

    Joined:
    Mar 25, 2008
    Messages:
    3,094
    Location:
    Marooned, Y'isrumgone
    Ok, will do. Except... It really bugs me though when stupid things like this come up and there is this berserk viking part of me that wants to keep swinging at it until its dead:deadhorse:

    As far as I can tell this part of the code is mostly untouched compared to vanilla. And if we attempt to build our own here we may encounter the same issue unless we figure out what is happening.

    The code loops all traderoutes and then adds units to that traderoute row if it is assigned to it. Only the first Icon that is placed is click-able, which is strange since they all have unique names. The help text appears on all route units and also the bottom row units. So, something in the configuration is making it so only the first unit button placed for that Unit is allow to send info the handleInput....
     
  19. Kailric

    Kailric Jack of All Trades

    Joined:
    Mar 25, 2008
    Messages:
    3,094
    Location:
    Marooned, Y'isrumgone
    Ok, I am about done investigating this for now. I posted a new thread where we can discuss the domestic advisor.

    It still don't make since why the bottom button's widget does not work, and only 1 of the other buttons work per unit. On the screen that list citizens every button works, so I know it can be done.
     
  20. Kailric

    Kailric Jack of All Trades

    Joined:
    Mar 25, 2008
    Messages:
    3,094
    Location:
    Marooned, Y'isrumgone
    :deadhorse:

    I tried, I really did, but I could not stay away...

    Ok, The code works fine up to 8 Routes, after that you start having those issues I described above. This is a Vanilla Bug as I tested this in vanilla, all works fine until you add that 9th trade route, or at least with the setup I had in the game. :crazyeye:
     

Share This Page