Help on modifying starting techs based on Handicap

T.c.w7468

...
Joined
Jan 23, 2008
Messages
88
Location
US
I'm very very new to modding Python/SDK, so forgive me if I sound really dumb; I tried looking for a solution through search, but I didn't find anything... perhaps I don't know what to search for...

Hello, I'm trying to make it so that on lower difficulties, rather than having a number of specific technologies given to you, a certain number of random starting technologies (from Fishing, Hunting, Wheel, Mining, Agriculture, Mysticism) are selected randomly in addition to the default civilization starting technologies. (For instance, in Settler difficulty, China would start with Wheel and Agriculture, as well as 2 or 3 other technologies from the rest of the list).

The way it is now, it seems like there is a boolean array m_pbFreeTechs that reads from the XML which techs to mark as true in this array, however I want to modify it to select techs in the way specified above, rather than reading a tech-list from the xml. However, I am not sure how to implement this (where to put the code, for instance) and I am also not sure how to safely remove the code that reads the XML.

Any help would be greatly appreciated:)
 
Removing the XML is easy, just go to HandicapInfos.xml and remove them.

Applying the free techs however, will require coding.
In pseudocode form:

On Game Start, CvEventManager
A) Loop through all teams
B) Based on team leader or highest/lowest member handicap:
C) Check if human or AI:
D) Grant X free techs based on handicap

Granting free techs:
Use a for loop with X iterations:
A) Define an empty list to store eligible ones
B) Loop through all techs:
C) Add all techs which player can currently research into the list
D) Select a random tech and grant it.
 
Oh, sorry I just noticed this, I found the solution independently and forgot to check this thread. Thanks for helping though:) (and I apologise for any trouble answering me may have caused)

Just in case someone from the future is wondering what the fix is here's the code (it may not be the most efficient, and my variable naming is pathetic, but it works...)

In python: CvEventManager.py in onGameStart, import random is required

Code:
## Random starting technologies start##
                
                inTech = []
                
                inTech.append(gc.getInfoTypeForString("TECH_FISHING"))
                inTech.append(gc.getInfoTypeForString("TECH_THE_WHEEL"))
                inTech.append(gc.getInfoTypeForString("TECH_AGRICULTURE"))
                inTech.append(gc.getInfoTypeForString("TECH_HUNTING"))
                inTech.append(gc.getInfoTypeForString("TECH_MINING"))
                inTech.append(gc.getInfoTypeForString("TECH_MYSTICISM"))
                
                onTech = []
                
		if (gc.getGame().getGameTurnYear() == gc.getDefineINT("START_YEAR") and not gc.getGame().isOption(GameOptionTypes.GAMEOPTION_ADVANCED_START)):
			for iPlayer in range(gc.getMAX_PLAYERS()):
				player = gc.getPlayer(iPlayer)
				if (player.isAlive() and player.isHuman()):
					handicap = player.getHandicapType()
					team = gc.getTeam(player.getTeam())
					for iTech in range (gc.getNumTechInfos()):
						for jTech in range (len(inTech)):
							if ((iTech == inTech[jTech]) and not (gc.getCivilizationInfo(player.getCivilizationType()).isCivilizationFreeTechs(iTech))):
								onTech.append(iTech)
					extras = 0
					if (handicap == gc.getInfoTypeForString("HANDICAP_SETTLER")):
						extras = 3
					elif (handicap == gc.getInfoTypeForString("HANDICAP_CHIEFTAIN")):
						extras = 2
					elif (handicap == gc.getInfoTypeForString("HANDICAP_WARLORD")):
						extras = 1
					else:
						extras = 0
					if (extras > 0):
						if (extras > len(onTech)):
							extras = len(onTech)
						if (extras == len (onTech)):
							for kTech in range(len(onTech)):
								 team.setHasTech (onTech[kTech], True, iPlayer, False, False)
						else:
							random.shuffle(onTech)
							for kTech in range(extras):
								team.setHasTech (onTech[kTech], True, iPlayer, False, False)								

## Random starting technologies end##

If you plan on regenerating the map, this is also required in the SDK (if using BULL, before it autosaves) (side effect is the Dawn of Man screen shows every time that you regenerate, but this should be trivial):

CvGame.cpp, in CvGame::regenerateMap()

Code:
    CvEventReporter::getInstance().gameStart();
 
Back
Top Bottom