Platy World Builder

Trying to merge the latest version of this into HR, and BUG is having a hissy fit about this section in CvEventManager.py:

Code:
	def __eventEditUnitNameApply(self, playerID, userData, popupReturn):	
		'Edit Unit Name Event'
		iUnitID = userData[0]
		unit = gc.getPlayer(playerID).getUnit(iUnitID)
		newName = popupReturn.getEditBoxString(0)
		if (len(newName) > 25):
			newName = newName[:25]			
		unit.setName(newName)
## Platy Builder ##
		if CyGame().GetWorldBuilderMode():
			WBUnitScreen.WBUnitScreen().placeStats()
			WBUnitScreen.WBUnitScreen().placeCurrentUnit()

	def __eventWBLandmarkPopupBegin(self, argsList):
		CyEngine().addLandmarkPopup(CyInterface().getMouseOverPlot())
		return

	def __eventWBLandmarkPopupApply(self, playerID, userData, popupReturn):
		if (popupReturn.getEditBoxString(0)):
			if (len(popupReturn.getEditBoxString(0))):
				CyEngine().addLandmarkPopup(CyInterface().getMouseOverPlot())
		return

	def __eventWBPlayerScriptPopupApply(self, playerID, userData, popupReturn):
		sScript = popupReturn.getEditBoxString(0)
		gc.getPlayer(userData[0]).setScriptData(CvUtil.convertToStr(sScript))
		WBPlayerScreen.WBPlayerScreen().placeScript()
		return

	def __eventWBCityScriptPopupApply(self, playerID, userData, popupReturn):
		sScript = popupReturn.getEditBoxString(0)
		pCity = gc.getPlayer(userData[0]).getCity(userData[1])
		pCity.setScriptData(CvUtil.convertToStr(sScript))
		WBCityEditScreen.WBCityEditScreen().placeStats()
		return

	def __eventWBUnitScriptPopupApply(self, playerID, userData, popupReturn):
		sScript = popupReturn.getEditBoxString(0)
		pUnit = gc.getPlayer(userData[0]).getUnit(userData[1])
		pUnit.setScriptData(CvUtil.convertToStr(sScript))
		WBUnitScreen.WBUnitScreen().placeScript()
		return

	def __eventWBScriptPopupBegin(self):
		return

	def __eventWBGameScriptPopupApply(self, playerID, userData, popupReturn):
		sScript = popupReturn.getEditBoxString(0)
		CyGame().setScriptData(CvUtil.convertToStr(sScript))
		WBGameDataScreen.WBGameDataScreen().placeScript()
		return

	def __eventWBPlotScriptPopupApply(self, playerID, userData, popupReturn):
		sScript = popupReturn.getEditBoxString(0)
		pPlot = CyMap().plot(userData[0], userData[1])
		pPlot.setScriptData(CvUtil.convertToStr(sScript))
		WBPlotScreen.WBPlotScreen().placeScript()
		return

BUG wants these events registered with it's own EventManager, but as usual it's a stupidly unintuitive process and I just can't get it to work. I'm slowly stripping the unneeded and frustrating parts of BUG out of HR, and while I've got rid of their GameUtils override, their EventManager stuff is a lot more entangled. My question for you though, is where and how are these events called? They're not in BTS' default EventManager and I can't find reference to them in any of the Platy Builder files (though I can see where the popups for them are created).
 
All over the place.
Unit Script Data, for instance is WBUnitScreen
 
Ah I see, I was looking for the event names directly, missed the section at the top of CvEventManager. Off topic: how do you reload Python in game? Is there a console command or something?
 
Reload?
Most python changes take effect immediately in game.

Else just simply load a saved game
 
Really? I've always had to relaunch the game even for the simplest python changes, e.g. resizing a panel, changing a string. I wonder if that's because I use the Mac version.
 
Certain positions in CvMainInterface for instance are defined only at start, so it will never be triggered again while the game is running.

If you notice, the default BTS codes there are all show and hide. Since all the positions are defined only when the game started/loaded, whatever changes to those positions will not be affected.

Starting/Loading a game however, is enough to reset all the values.

Python changes will only be effective if they are triggered.

For instance, if the effect of a wonder is to grant 100 gold every turn, changing it to grant 1000 gold instead will be effective the next turn, without the need to load the game.
 
Civ IV generally reloads Python automatically as soon as you save any change to a python file.

Some mods use additional python files which the game fails to load when it is reloading after a change. Those mods include Fall from Heaven 2 and all of its derivatives. As those are pretty much the only mods I play, I have gotten use to always saving the game, closing the program, and loading the saved game after any python change.

-----
I've been rather discouraged by the difficulty of merging your updated with FfH2/MNAI/MagisterModmod specific features, and am just now going back to trying after a long break.



I would still really like to be able to just type in some values. How much would that effect stability?


One change I made in my version which is not necessarily FfH2 specific is the ability to find a unit by its unitID. This is very useful for debugging, when one o the log files indicates that the problem (usually an AI getting stuck in a loop) is due to a specific unit. The way I implemented it, you can select any unit belonging o that player and copy that unit DI into a box to switch to that unit. It is then easy to delete the troublesome unit. Using +/- boxes is no good for cycling through unit IDs like that, as they are not sequential.

Would it be possible to add to the player at a screen a list of all the units the player owns, along with their unit IDs, where you could select specific units?

The ability to access such a list within the unit data screen could be useful to me too, for assigning a unit as having a specific summoner.
 
Version 3.8

WBList0000_zpsb9ea0ef2.jpg


The problem with having an input field similar to old WB version 2 is that inputing a value + refreshing the screen without ENTER => 100% CTD
 
I like the new screen, but referring to it as "Units" when it shows cities too seems odd.

I personally think that those menus to select what screen you are on would make more sense at the top of the screen rather than the bottom, but I guess that is just a minor matter of personal preference.

It was a major hassle for me to figure out how to get the Guaranteed Eligibility control on the Team Data screen working properly in FfH2, where there are no buildings related to votes but rather civics, but I think I finally managed to do it.

---
On the Unit Data screen, I've noticed that the Duplicate Unit button is not working. Neither is the top half of the kill button. I think that the Script Data Panel is overlapping those controls and making them inaccessible.

Edit: the duplicate unit button moves to the top and can be used if I just change something in the column above it, like setting the unit as having moves left or having already attacked. I can immediately undo it, but it does not seem like such a workaround should be needed.

I wonder if this would be different for those with different resolution screens.
 
Hotfix:
Changed "Units" to "Units + Cities"

I thought of placing it on top before also, but decided to leave it there since the bottom bar is empty except "Exit". Leave the top portion for other things if necessary.

Guaranteed Eligibility linked to buildings is just to display the respective button.
If it was so hard to change it to civics, just remove the button display.

Tested in both ultrapack and WB standalone, no issues with duplicate or kill.
 
I ended up moving the Kill button to the top, as its located in your modmod was the one spot with enough room for me to include 3 toggles I wanted.

Those were all for setting certain Feats as accomplished or not. I tried to make a more generalized way to let me adjust any feat, but that did not work so well. I had to make a different function name for each of them, but I did get all the ability working to toggle the 3 feats that players of FfH2 would most want the ability to alter.

-----
I have the Guaranteed Eligibility things working fine now, so it is no big deal.

Simply removing the button was not sufficient though. I could not select the things properly when they did not have a working mouseover.

---------
The script Data box was definitely blocking the duplicate button on my version. Maybe it depends on your screen resolution.

It is not a big deal for me though, as I had to rearrange things on that screen to get my FfH2 specific features to fit anyway.

----
I think that we should be able to click on the player name and the civilization name on the Player screen to change them, much the same way that we can change the name of units and cities.

How would I go about implementing that?

---------

I'm getting a python error whenever I try to switch to the Teams screen from the either the Projects or Technologies screens.

Code:
Traceback (most recent call last):

  File "CvScreensInterface", line 416, in handleInput

  File "WBProjectScreen", line 130, in handleInput

NameError: global name 'iTeam' is not defined
ERR: Python function handleInput failed, module CvScreensInterface
Traceback (most recent call last):

  File "CvScreensInterface", line 416, in handleInput

  File "WBTechScreen", line 87, in handleInput

NameError: global name 'iTeam' is not defined
ERR: Python function handleInput failed, module CvScreensInterface
 
Hotfix 2

1) Fixed iTeam undefined in Projects and Techs
2) Fixed Unit Script Data to properly scale with resolution
3) Renamed "Units" to "Units + Cities" in Projects

-----
I think it is possible to change names for human players only based on Profile.
So not much point in it
 
EDIT: Nevermind, figured it out.
 
There should really be an easy way to get back to the Units + Cities screen from the Unit Data and City Data screens.

(I went ahead and implemented this in my modmod last night, but I imagine others would like the ability too.)


I don't think that the Event screen should have to trigger the event for the owner of the tile. We should be able to trigger events on unowned tiles, particularly events that effect specific units which could very well be venturing into unowned or rival territory. We should be able to get to the event screen from the Unit Data and City Data screens.
 
Version 3.9

1) Reorganised Event Page to allow accessibility from neutral plots
Events0000_zps9264d09b.jpg


2) New Promotion Page
WBPromotions0000_zps73e7b251.jpg


New Features:
A) Ability to select unit in Promotions
B) Ability to copy all promotions to 1) All Units 2) Same Type 3) Same Combat 4) Same Domain

3) Added accessibility to pages to more of them
 
I went ahead and did a quick merge of Platy World Builder 3.9 with More Naval AI 2.52, and then ran into a few minor python errors when testing it.
Code:
Traceback (most recent call last):

  File "CvScreensInterface", line 737, in handleInput

  File "WBPromotionScreen", line 198, in handleInput

  File "WBPromotionScreen", line 85, in placeCopyAll

AttributeError: 'NoneType' object has no attribute 'getDescription'
ERR: Python function handleInput failed, module CvScreensInterface
Traceback (most recent call last):

  File "CvScreensInterface", line 737, in handleInput

  File "WBEventScreen", line 376, in handleInput

AttributeError: 'NoneType' object has no attribute 'initTriggeredData'
ERR: Python function handleInput failed, module CvScreensInterface

The problem on the Promotion screen occurred when I tried the option to copy a promotion to units of the same UNIT_COMBAT as a Worker, which has no unit combat. (Workers actually are part of UNITCOMBAT_CIVILIAN in my modmod, but that does not exist in MNAI and I always perform the simpler task of merging changes into MNAI first.)

I fixed it with this code:
Code:
	def placeCopyAll(self):
		screen = CyGInterfaceScreen( "WBPromotionScreen", CvScreenEnums.WB_PROMOTION)
		sText = CyTranslator().getText("TXT_KEY_PEDIA_CATEGORY_UNIT", ())
		if self.iCopyType == 1:
			sText = gc.getUnitInfo(pUnit.getUnitType()).getDescription() + " " + CyTranslator().getText("TXT_KEY_PEDIA_CATEGORY_UNIT", ())
		elif self.iCopyType == 2:
			[COLOR="Red"]if pUnit.getUnitCombatType() < 0:
				sText = CyTranslator().getText("TXT_PEDIA_NON_COMBAT", ())
			else:
				sText = gc.getUnitCombatInfo(pUnit.getUnitCombatType()).getDescription()[/COLOR]
		elif self.iCopyType == 3:
			sText = gc.getDomainInfo(pUnit.getDomainType()).getDescription()
		screen.setText("PromotionCopy", "Background", u"<font=3b>" + CyTranslator().getText("TXT_KEY_WB_COPY_ALL", (sText,)) + "</font>", CvUtil.FONT_LEFT_JUSTIFY, screen.getXResolution()/4 + 150, screen.getYResolution() - 42, -0.1, FontTypes.TITLE_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)


For the events, I probably tried to trigger them without first giving it all the needed arguments. When you choose an event at random, it is easy to do that. I think it would be a good idea for this screen to indicate what fields must be selected in order for the event to trigger, and to prevent players from triggering the event without the proper parameters set.
 
Bleh, forgot about the non combat units :D
Event requirements require many checks though, because some requirements depend on plot, tech, civics etc
So even if you input all entries, you still won't expect forest fire to trigger in the ocean
 
Hotfix:
Fix Non Combat Units in Promotions

@Events
I took a look at the modiki and is pretty disgusted.
There are at least 20 requirements to weed out those events that can never be triggered on that plot, such as player data like gold, civics and tech, plot data like features, plot type, terrain, city data like building present and so on...

Not something I intend to do on Chinese New Year.
 
Fix Event Player from being -1 in Event Page.
 
Version 3.10

Plot image in Edit Plot Screen now updates properly with any change.
 
Back
Top Bottom