Banning Weapons Other Than Nukes

I actually haven't been using an INI file. I've just been putting a copy of the CvGameUtils in the CustomAssets folder, along with XML defining the resolutions. I'm not sure how to write INI.
 
JoshW said:
I actually haven't been using an INI file. I've just been putting a copy of the CvGameUtils in the CustomAssets folder, along with XML defining the resolutions. I'm not sure how to write INI.

Ah. I'm talking about the "C:\Documents and Settings\<YourComputerLoginName>\My Documents\My Games\Sid Meier's Civilization 4\CivilizationIV.ini" file. It has different settings that should prove to be of great help when modding, as well as other things. Of particular, those options I've shown help put out a bunch of logs that are VERY helpful for modders. The "HidePythonExceptions" is one where you either like it or you don't. It pops up the error message right on the screen so you don't have to go digging through the logs, but sometimes it gets annoying.
 
Thus far with this file I have received no errors and the interface is there, however the mod just doesn't work. Passing the resolution has no effect. I have attached the python file.
 

Attachments

JoshW said:
Thus far with this file I have received no errors and the interface is there, however the mod just doesn't work. Passing the resolution has no effect. I have attached the python file.

Code:
def cannotTrain(self,argsList,iVote,szBannedUnit):

cannotTrain (and the rest of the functions in this file) is called directly from the SDK. The way that boost (the library used to communicate between the c++ and python) does arguments is it passes all the arguments into one big object, and sends that object. The object on the python side is typically called argsList, which is a tuple. It's the array of arguments. The next four lines of the function actually take those arguments and put names to them.

So, the iVote variables and szBannedUnit variables are both declared on the fly in the for loop declarations. No need to put them into the argument list, as they're local variables.

Code:
Python:
for iVote in range(gc.getNumVoteInfos()):

C++
for (int i = 0; i < GC.getNumVoteInfos(); ++iVote)

The scope of iVote variables work a bit different in python, but don't worry about that.

---

Code:
for szBannedUnit in self.m_dResolutionUnitBans(iVote):

Because m_dResolutionUnitBans is a dictionary (python's version of a map), it needs the [] brackets to get the data of a certain key. So, it should be...

Code:
for szBannedUnit in self.m_dResolutionUnitBans[b][[/b]iVote[b]][/b]:

---

After fixing those, here is what I have for that function:

Code:
def cannotTrain(self,argsList):
	pCity = argsList[0]
	eUnit = argsList[1]
	bContinue = argsList[2]
	bTestVisible = argsList[3]
	if not bTestVisible:
		for iVote in range(gc.getNumVoteInfos()):
			if gc.getGame().isVotePassed(iVote):
				if self.m_dResolutionUnitBans.has_key(iVote):
					for szBannedUnit in self.m_dResolutionUnitBans[iVote]:
						if gc.getInfoTypeForString(szBannedUnit) == eUnit:
							return True

---

One more fun (read: "annoying") thing with python is that if you have a tuple with only one element, you need a comma at the end. There's some syntactical reason why it's necessary but I forget what it is. So, that will mean you'll have to change the __init__ method:

Code:
def __init__(self): 
	self.m_dResolutionUnitBans = {
		gc.getInfoTypeForString("VOTE_NO_NUKES") : ("UNIT_BOMBER",)
		}

Note the comma after "UNIT_BOMBER". If you have two units in there, you won't need to have a comma after the last one. So you can have:

Code:
def __init__(self): 
	self.m_dResolutionUnitBans = {
		gc.getInfoTypeForString("VOTE_NO_NUKES") : ("UNIT_BOMBER","UNIT_STEALTH_BOMBER")
		}

With these changes, I was successfully able to disable a bomber from being built once the vote was passed.
 
Well I finally finished the mod, thanks to the help of several posters. Gerikes, I couldn't have done it without you. :D :goodjob:

The mod introduces three new resolutions:
1. One which disables production of weapons that cause collateral damage:
Bombers, Stealth Bombers, Artillery, Cannon, Battleship
2. One which disables production of invisible units:
Spies, Submarines
3. One which disables production of weapons that are primarily used offensively:
Tanks, Modern Armor, Panzer, Gunship, Cavalry, etc.

Each one requires a different percentage of votes however:
#2 - 51%
#1 - 65%
#3 - 75%

Enjoy!

http://forums.civfanatics.com/uploads/98311/1156356765.zip
 
nice work, JoshW.

Now i'm curious...

Is there a way that this could be worked, so as to limit a civ's entire military output?
Think back to Germany, after WW1 ended.
The rest of the world put a limit on the amount of military might that Germany could rebuild.
Obviously they broke this, but for game purposes, this could be a great thing to limit a civ. Say for X number of turns, Civ X can only build x amount of combat units in total.

Would this be possible to do by altering your current mod at all?
 
Thanks Ragman, but the credit really belongs to Gerikes. As to the idea of imposing arms limits on a Civ, there are some problems with that for me :

1) I barely knew how to do the present mod -- I don't really know that much about python.
2) I think that that kind of specificity, "X number of X units, for X Civ, for X turns" would involve a substantial interface addition to the game that I simply don't know how to do.
3) I think that doing that kind of thing would involve modding the SDK code, which doesn't really work for me because I have a Mac and no way to test it.

Also, in my last post where I uploaded the Mod I neglected to give credit to:

TheFourGuardian

for the additional inclusion of resolutions which can force any global civic, not just the bottom ones. So this is me giving credit.

Some additional questions for the viewers are:
-Does anyone think that the AI knows what these nonproliferation resolutions mean, in the sense that they might vote "no" for them?
-Are there mechanisms in the python code for disbanding units.....
 
JoshW said:
-Does anyone think that the AI knows what these nonproliferation resolutions mean, in the sense that they might vote "no" for them?

The AI votes for the Nonproliferation resolutions only based on the nukes it has. The python you've added will not change how it feels on the issue. You would need to change the SDK to do this.

-Are there mechanisms in the python code for disbanding units.....

I believe pUnit.scrap() disbands a unit.
 
The AI seems to base a lot of its decisions upon their opinion of the leader suggesting them it seems to me.

I also find that if you don't get elected Secretary-General and all the civics are available, the AI starts picking crazy ones that usually win and it sends your society into a tailspin when you're suddenly forced into a civic that lost its value after the Middle Ages.
 
I have edited the CvGameUtils file once more. Now you have the option of not only banning production of a weapon but of erasing all such weapons from the map. Nonproliferation (ban on production) comes in one resolution, and abolition (destruction of all such units) in another. If both are passed you have true disarmament of all such weapons.

The only caveat is that since I wasn't able to get the abolition code to work in the Eventsmanager file, it has been put right next to the nonproliferation code in the CannotTrain function in CvGameUtils. This means that the abolished units won't go away until you check one of your cities. I'm not sure how to get it to work any other way. Suggestions appreciated.

The mod is available here:

http://forums.civfanatics.com/uploads/98311/1156472901.zip
 
This looks to be a cool mod, the vanilla UN is way bare and these new things to vote on will help fix that. :)

Only thing, could you please upload your files to the File Database so they can be easyly found by searching the FD. :thanx:
 
Back
Top Bottom