Simple Python Things

Sadly not always, but hopefully often enough :).



No, would not, it's still the wrong callback ;) Just move it over to canConstruct, that should not be a problem in any way.
Edit: Before here was nonsense :mischief:.
If these callbacks return "False", they just will not have any effect.
In the case here, it returns True in the case a city does not have power, so cities without power can not construct it.

2. edit: this all depends on how you put the building in the XML.
If you can normally build it, then you're right here, then use the cannot construct to restrict it only to certain cities.
If you could normally not build it (due to whatever restrictions, because it's attached to future tech, whatever), then you would have to use the canConstruct callback to allow it for certain cities.

Thanks, it works partially now. The Particle Generator is a World Wonder and when I use canConstruct like this:
Code:
	def canConstruct(self,argsList):
		pCity = argsList[0]
		eBuilding = argsList[1]
		bContinue = argsList[2]
		bTestVisible = argsList[3]
		bIgnoreCost = argsList[4]

                ### Particle Accelerator begins ###
		###########################################################################################

		if ( eBuilding == gc.getInfoTypeForString("BUILDING_PARTICLE_ACCELERATOR") ):

			### check if city has power ###
			##pPlayer = gc.getPlayer(pCity.plot().getOwner())
			##iPID = pPlayer.getID()
			##iTID = pPlayer.getTeam()
			power = pCity.isPower()

			if ( power == true ):
				return true

			return false

		###########################################################################################
		### Particle Accelerator ends ###
		
		return false
I can start building the Particle Generator in all my cities with power. Somehow there should be a check whether the Particle Generator is already being built in another city...
Would this be possible?
 
First, as to how to do the additional check...

The CyGame has an isBuildingClassMaxedOut function (as does the team and player, for team and national wonders). The CyPlayer has a getBuildingClassMaking function.

So uncommenting the line where pPlayer is set and changing the condition to also check the relevant "maxed-outness" and to see if one is already being built should do the trick:
Code:
			eBuildingClass = gc.getBuildingInfo(eBuilding).getBuildingClassType()
			if ( power == true ) and (not CyGame().isBuildingClassMaxedOut(eBuildingClass, 0)) and (pPlayer.getBuildingClassMaking(eBuildingClass) < 1):
				return true

Or something like that. I didn't test it. Instead of hardcoding a "1" in there it could check for the number allowed via the building class info's getMaxGlobalInstances function.

Second, and probably more importantly...

On the other hand, I think the cannotConstruct version is much easier. If the only additional thing for the building is that it can't be built if there is no power, but every other criteria is normal, then using the cannotConstruct means you automatically already got the check to see if the wonder has been build or is being built elsewhere in the regular checks the DLL does (allowing you to do without any of the above changes). Using the canConstruct version, I think you'll find that you can probably also built your particle accelerator before the required tech is researched unless it is the same tech that first lets you get power in a city - or, at least, the AI will be able to do so (I'm not sure but the player may not get the button to build it added to the interface until the proper tech is researched, but the AI doesn't use that interface) - so you'd need to add a check for the prereq tech or techs. And any other prereqs that might exist, since it bypasses them all.

You see, the canConstruct really means it - if it returns true then it can be built regardless of any prerequisites or other requirements (like allowing you to build a harbor on a hill surrounded by nothing but desert) since it is called before the DLL checks for any of them and it never runs those checks if the return was true. It will even allow you to build a building in a city multiple times if you don't check for that (in this case, this should be take care of by the maxed out check). This is why using the canConstruct callback is pretty rare - you have to duplicate any check that the DLL would do that is relevant to the building or it won't get checked for that.
 
Yeah, useful stuff for sure. :goodjob:
 
I can't seem to find the link to the Real OCC mod (although I've seen it around here before), but from I believe it uses SDK modding. So it shouldn't be too difficult provided you know how to:

One, compile a dll and

Two, use winmerge.

I assume the maker of real occ also made sure to comment things well, of course.
 
That's for sure an exaggeration :D.
But it is commented, and i'm also here to help, that would be true :).


-------
Surprise, surprise, i already merged RealOCC somewhen with RevDCM, and i searched here for the attachement, but couldn't find it :hmm:.
Whatever, the files are attached, just 2, and can be plugged in the respective folders in which they are in the attachement.
The merge additionally needs the line
PHP:
<load mod="RealOCC"/>
to be added before the line
PHP:
</bug>

in Assets\config\init.xml.

IIRC that's everything which is needed.
 

Attachments

That's for sure an exaggeration :D.
But it is commented, and i'm also here to help, that would be true :).


-------
Surprise, surprise, i already merged RealOCC somewhen with RevDCM, and i searched here for the attachement, but couldn't find it :hmm:.
Whatever, the files are attached, just 2, and can be plugged in the respective folders in which they are in the attachement.
The merge additionally needs the line
PHP:
<load mod="RealOCC"/>
to be added before the line
PHP:
</bug>

in Assets\config\init.xml.

IIRC that's everything which is needed.

I placed the line under the section
PHP:
<!-- Mods -->
and I did select One City Challenge option, but it still didn't work. The AIs were still building settlers. Also tried it the line above
PHP:
</bug>
with the same result.
 
Damn, forgot a part. And actually the easiest one :blush:.
In XML\PythonCallbackDefines.xml, you have to set the value for USE_CANNOT_FOUND_CITY_CALLBACK and USE_CANNOT_TRAIN_CALLBACK to 1.
-> the python did not work, because the game did not check for it. Changing the values will fix that.
 
Damn, forgot a part. And actually the easiest one :blush:.
In XML\PythonCallbackDefines.xml, you have to set the value for USE_CANNOT_FOUND_CITY_CALLBACK and USE_CANNOT_TRAIN_CALLBACK to 1.
-> the python did not work, because the game did not check for it. Changing the values will fix that.

you didn't include the XML\PythonCallbackDefines.xml in the zip.
 
Okay, attached.
The init.xml needs the line
PHP:
<load mod="RealAlwaysWar"/>
to be added right at the same point where the entry for RealOCC is.

And while i've already been on it, i've also changed the "original", because it had the bug in it that the option was essentially resetted ingame if you rerolled the map.
 

Attachments

el_hidalgo requested 2 projects, and now i finished them:

Renaissance

Spoiler :
renaissance_GWo.jpg




Hanseatic League

Spoiler :
hanseaticleague_3t9.jpg


Both modcomponents contain
- 2 XML files: the ProjectInfos.xml for the project entry, and a text XML for the custom text
- 1 Button
- 2 Python files: CvEventManager.py and CvGameUtils.py
Renaissance has 1 change in CvGameUtils, Hanseatic League 2. Both only 1 in CvEventManager.

Button image and text snipped are taken from wikipedia (links are included).


The big problem with projects is that they unlike buildings don't have a flavor tag. Without a flavor tag, and without XML effects, the projects appear to be totally worthless to the AI, so they'd normally not build any python project.
Due to that there are the changes in CvGameUtils, they are influencing the AI and forces it to build the projects under certain circumstances. They'll not be very clever, but they'll at least try it, and an AI might even get it if they are technology-wise ahead. Else they'll probably lose the project, because they're always changing the production in between. Oh well, but at least it somehow works.

Thanks to God-Emperor here, he gave me a hint for the right command.
 
Back
Top Bottom