Heroes 2 - get them by Technology - DIY

Arian

No more ghostbusting!!
Joined
May 10, 2008
Messages
2,088
Location
The Netherlands
Heroes 2 - get them by Technology - Do It Yourself

Here's a little modcomp based on the existing Heroes modcomp: http://forums.civfanatics.com/showthread.php?t=310628 by Edgecrusher
This modcomp is Python/XML only. There's no download, just do it yourself.

What does it?

This modcomp creates a unit ("the Hero") when a civilization researches a certain technology.

How does it work?

In CvEventManager.py extra code should be added to "onTechAcquired" and "onUnitKilled".
There are basically two creation-variants ("onTechAcquired"):
1. Create naval hero, if not possible create land hero
2. Create land hero only

And a Hero killed message in "onUnitKilled"

How can I use this?

Well, DIY.
1. Add a hero (XML, artinfo, unitinfo and textinfo). I'm sure there's a tutorial somewhere how to do this. Plenty of Heroes in the DL-database!
2. Plug-in the appropriate code for the Hero(es)

THE CODE
1. Create naval hero, if not possible create land hero:
This code tries to create a naval hero, but only if there's a coastal city present in the civ. Otherwise the land hero is created.

PHP:
	def onTechAcquired(self, argsList):
		'Tech Acquired'
		iTechType, iTeam, iPlayer, bAnnounce = argsList

## Hero Egypt: The Great Papyrusboat/Narmer ##
    
		if iTechType == gc.getInfoTypeForString("TECH_BOATING"):
			TheCivForTheUnit = gc.getInfoTypeForString("CIVILIZATION_EGYPT")
			pPlayer = gc.getPlayer(iPlayer)
			pPID = pPlayer.getID()
			myName = pPlayer.getCivilizationType ()
			if myName == TheCivForTheUnit:
				pCity= pPlayer.getCapitalCity()
				if pCity.isNone(): 
					return
				iX = pCity.getX()
				iY = pCity.getY()
				myUnit = gc.getUnitInfo(gc.getInfoTypeForString("UNIT_HERO_EGYPT")) 
				if myUnit.getDomainType ()==gc.getInfoTypeForString('DOMAIN_SEA'):
					flag_coastal_city = False
					for iCity in range(pPlayer.getNumCities () ): 
						ppCity = pPlayer.getCity(iCity) 
						if ppCity.isNone():continue 
						if ppCity.getOwner()<>pPID:continue 
						CurX = ppCity.getX() 
						CurY = ppCity.getY()
						for iXLoop in range(CurX - 1, CurX + 2, 1): 
							for iYLoop in range(CurY - 1, CurY + 2, 1): 
								CheckedPlot = CyMap().plot(iXLoop, iYLoop) 
								if CheckedPlot.isWater() and not CheckedPlot.isLake(): 
									iX = ppCity.getX() 
									iY = ppCity.getY()
									flag_coastal_city = True
									break  

				if flag_coastal_city == True:
					newUnit = pPlayer.initUnit(gc.getInfoTypeForString( 'UNIT_HERO_EGYPT' ), iX, iY, UnitAITypes.UNITAI_GENERAL, DirectionTypes.NO_DIRECTION)
					newUnit.setName("The Great Papyrusboat")
					CyInterface().addMessage(pPID,false,15,CyTranslator().getText("TXT_KEY_UNIT_HERO_EMERGE_EGYPT",()),'',0,'Art/Interface/Buttons/Heroes/HeroEgypt.dds',ColorTypes(11), iX, iY, True,True)

				else:
					newUnit = pPlayer.initUnit(gc.getInfoTypeForString( 'UNIT_HERO_EGYPT_LAND' ), iX, iY, UnitAITypes.UNITAI_GENERAL, DirectionTypes.NO_DIRECTION)
					newUnit.setName("Narmer")
					CyInterface().addMessage(pPID,false,15,CyTranslator().getText("TXT_KEY_UNIT_HERO_EMERGE_EGYPT_LAND",()),'',0,'Art/Interface/Buttons/Heroes/HeroEgypt.dds',ColorTypes(11), iX, iY, True,True)


				## Display message
				## CyInterface().addMessage(pPID,false,15,CyTranslator().getText("TXT_KEY_UNIT_HERO_EMERGE_EGYPT",()),'',0,'Art/Interface/Buttons/Heroes/HeroEgypt.dds',ColorTypes(11), iX, iY, True,True)

		# Show tech splash when applicable
		if (iPlayer > -1 and bAnnounce and not CyInterface().noTechSplash()):
			if (gc.getGame().isFinalInitialized() and not gc.getGame().GetWorldBuilderMode()):
				if ((not gc.getGame().isNetworkMultiPlayer()) and (iPlayer == gc.getGame().getActivePlayer())):
					popupInfo = CyPopupInfo()
					popupInfo.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_PYTHON_SCREEN)
					popupInfo.setData1(iTechType)
					popupInfo.setText(u"showTechSplash")
					popupInfo.addPopup(iPlayer)

2. Create land hero only:
This one simply creates the land hero in the civs capital. No further checks needed.

PHP:
	def onTechAcquired(self, argsList):
		'Tech Acquired'
		iTechType, iTeam, iPlayer, bAnnounce = argsList

## Hero Germany: Red Baron ##
    
		if iTechType == gc.getInfoTypeForString("TECH_AERONAUTICS"):
			TheCivForTheUnit = gc.getInfoTypeForString("CIVILIZATION_GERMANY")
			pPlayer = gc.getPlayer(iPlayer)
			pPID = pPlayer.getID()
			myName = pPlayer.getCivilizationType ()
			if myName == TheCivForTheUnit:
				pCity= pPlayer.getCapitalCity()
				if pCity.isNone(): 
					return
				iX = pCity.getX()
				iY = pCity.getY()
				newUnit = pPlayer.initUnit(gc.getInfoTypeForString( 'UNIT_HERO_GERMANY' ), iX, iY, UnitAITypes.UNITAI_GENERAL, DirectionTypes.NO_DIRECTION)
				newUnit.setName("The Red Baron")

				## Display message
				CyInterface().addMessage(pPID,false,15,CyTranslator().getText("TXT_KEY_UNIT_HERO_EMERGE_GERMANY",()),'',0,'Art/Interface/Buttons/Heroes/HeroGermany.dds',ColorTypes(11), iX, iY, True,True)

		# Show tech splash when applicable
		if (iPlayer > -1 and bAnnounce and not CyInterface().noTechSplash()):
			if (gc.getGame().isFinalInitialized() and not gc.getGame().GetWorldBuilderMode()):
				if ((not gc.getGame().isNetworkMultiPlayer()) and (iPlayer == gc.getGame().getActivePlayer())):
					popupInfo = CyPopupInfo()
					popupInfo.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_PYTHON_SCREEN)
					popupInfo.setData1(iTechType)
					popupInfo.setText(u"showTechSplash")
					popupInfo.addPopup(iPlayer)

3. Display a message that a hero has died:

PHP:
	def onUnitKilled(self, argsList):
		'Unit Killed'
		unit, iAttacker = argsList
		iPlayer = unit.getOwner()
		player = PyPlayer(iPlayer)
		attacker = PyPlayer(iAttacker)
		unittype = unit.getUnitType ()

## Hero Egypt killed: Great Papyrusboat ##

		if unittype == gc.getInfoTypeForString("UNIT_HERO_EGYPT"): 
			CyInterface().addMessage(unit.getOwner(),False,15,CyTranslator().getText("TXT_KEY_UNIT_HERO_KILLED_EGYPT",()),'',0,'Art/Interface/Buttons/Heroes/HeroEgyptKilled.dds',ColorTypes(11), unit.getX(), unit.getY(), True,True)  

## Hero Egypt killed: Narmer ##

		if unittype == gc.getInfoTypeForString("UNIT_HERO_EGYPT_LAND"): 
			CyInterface().addMessage(unit.getOwner(),False,15,CyTranslator().getText("TXT_KEY_UNIT_HERO_KILLED_EGYPT_LAND",()),'',0,'Art/Interface/Buttons/Heroes/HeroEgyptKilled.dds',ColorTypes(11), unit.getX(), unit.getY(), True,True)  

## Hero Germany killed: Red Baron ##

		if unittype == gc.getInfoTypeForString("UNIT_HERO_GERMANY"): 
			CyInterface().addMessage(unit.getOwner(),False,15,CyTranslator().getText("TXT_KEY_UNIT_HERO_KILLED_GERMANY",()),'',0,'Art/Interface/Buttons/Heroes/HeroGermanyKilled.dds',ColorTypes(11), unit.getX(), unit.getY(), True,True)  

		if (not self.__LOG_UNITKILLED):
			return
		CvUtil.pyPrint('Player %d Civilization %s Unit %s was killed by Player %d' 
			%(player.getID(), player.getCivilizationName(), PyInfo.UnitInfo(unit.getUnitType()).getDescription(), attacker.getID()))

4. Text entries

HTML:
<!-- Hero Egypt: The Great Papyrusboat / Narmer -->
	<TEXT>
		<Tag>TXT_KEY_UNIT_HERO_EGYPT</Tag>
		<English>Great Papyrusboat</English>
	</TEXT>
	<TEXT>
		<Tag>TXT_KEY_UNIT_HERO_EGYPT_LAND</Tag>
		<English>Narmer</English>
	</TEXT>
	<TEXT>
		<Tag>TXT_KEY_UNIT_HERO_EGYPT_PEDIA</Tag>
		<English>The slow flowing Nile was ideal for transportation and from earliest times Egyptians built boats for transportation, fishing and enjoyment. Their importance in every day life is reflected in the role they played in mythology and religion.
As there was very little wood available, the first vessels were made of bundled papyrus reeds. Simple rafts in the beginning, they grew into sizable ships and were, as Thor Heyerdahl proved with his ocean crossing, seaworthy. They had a sickle shaped hull and often masts and sometimes deckhouses.
Small papyrus rafts served the population throughout much of Egypt's history, for as long as the raw material was readily available. They were cheap to make and did not require great expertise to build. Papyrus died out in Egypt and was reintroduced in the 20th century.</English>
	</TEXT>
	<TEXT>
		<Tag>TXT_KEY_UNIT_HERO_EGYPT_LAND_PEDIA</Tag>
		<English>Narmer was an Egyptian Pharaoh who ruled in the 31st century BC. Thought to be the successor to the predynastic Kings Scorpion or "Selk" and/or Ka, he is considered by some to be the unifier of Egypt and founder of the First dynasty, and therefore the first king of all Egypt. There is a growing consensus that Scorpion and Narmer are identical, but no identification with any early king can yet be definitively proven. Narmer's name is represented phonetically by the hieroglyphic sign for a catfish (n'r) and that of a chisel (mr). Modern variants of his name include "Hor Narmeru" or "Hor Merinar" (Horus, beloved of Nar, hence perhaps Meni (Mn)?), but scholarly convention favours "Narmer". - WIKI</English>
	</TEXT>
	<TEXT>
		<Tag>TXT_KEY_UNIT_HERO_EGYPT_STRATEGY</Tag>
		<English>The [COLOR_UNIT_TEXT]Great Papyrusboat[COLOR_REVERT] is the [COLOR_ALT_HIGHLIGHT_TEXT]Egyptian Hero[COLOR_REVERT]. Only one can be acquired per game. The [COLOR_UNIT_TEXT]Great Papyrusboat[COLOR_REVERT] can carry two [COLOR_UNIT_TEXT]units[COLOR_REVERT] and gets a 50% combat bonus against [COLOR_UNIT_TEXT]naval units[COLOR_REVERT].</English>
	</TEXT>
	<TEXT>
		<Tag>TXT_KEY_UNIT_HERO_EGYPT_LAND_STRATEGY</Tag>
		<English>[COLOR_UNIT_TEXT]Narmer[COLOR_REVERT] is the [COLOR_ALT_HIGHLIGHT_TEXT]Egyptian Land Hero[COLOR_REVERT]. Only one can be acquired per game. [COLOR_UNIT_TEXT]Narmer[COLOR_REVERT] has 50% extra strength against [COLOR_UNIT_TEXT]melee[COLOR_REVERT], [COLOR_UNIT_TEXT]archery[COLOR_REVERT] and [COLOR_UNIT_TEXT]mounted[COLOR_REVERT] units.</English>
	</TEXT>
	<TEXT>
		<Tag>TXT_KEY_UNIT_HERO_EGYPT_HELP</Tag>
		<English>[ICON_BULLET]When killed, 2[ICON_PRODUCTION] to nearest city[NEWLINE][ICON_BULLET]Can not be upgraded[NEWLINE][ICON_BULLET]Emerges when the [COLOR_ALT_HIGHLIGHT_TEXT]Egyptian Empire[COLOR_REVERT] finishes research on [COLOR_HIGHLIGHT_TEXT]Boating[COLOR_REVERT]</English>
	</TEXT>
	<TEXT>
		<Tag>TXT_KEY_UNIT_HERO_EGYPT_LAND_HELP</Tag>
		<English>[ICON_BULLET]When killed, 2[ICON_PRODUCTION] to nearest city[NEWLINE][ICON_BULLET]Can not be upgraded[NEWLINE][ICON_BULLET]Emerges when the [COLOR_ALT_HIGHLIGHT_TEXT]Egyptian Empire[COLOR_REVERT] finishes research on [COLOR_HIGHLIGHT_TEXT]Boating[COLOR_REVERT] but no coastal city is available</English>
	</TEXT>
	<TEXT>
		<Tag>TXT_KEY_UNIT_HERO_EMERGE_EGYPT</Tag>
		<English>The Great Papyrusboat has been built by the Egyptian Empire!!</English>
	</TEXT>
	<TEXT>
		<Tag>TXT_KEY_UNIT_HERO_EMERGE_EGYPT_LAND</Tag>
		<English>Narmer has emerged for the Egyptian Empire!!</English>
	</TEXT>
	<TEXT>
		<Tag>TXT_KEY_UNIT_HERO_KILLED_EGYPT</Tag>
		<English>The Great Egyptian Papyrusboat has been sunk in combat!!</English>
	</TEXT>
	<TEXT>
		<Tag>TXT_KEY_UNIT_HERO_KILLED_EGYPT_LAND</Tag>
		<English>Narmer of Egypt has been killed in combat!!</English>
	</TEXT>

<!-- Hero Germany: Red Baron -->
	<TEXT>
		<Tag>TXT_KEY_UNIT_HERO_GERMANY</Tag>
		<English>Red Baron</English>
	</TEXT>
	<TEXT>
		<Tag>TXT_KEY_UNIT_HERO_GERMANY_PEDIA</Tag>
		<English>Manfred Albrecht Freiherr von Richthofen (2 May 1892 – 21 April 1918) was a German fighter pilot known as the "Red Baron". He was the most successful flying ace of World War I, being officially credited with 80 confirmed air combat victories. Richthofen was a member of an aristocratic family with many famous relatives. - WIKI</English>
	</TEXT>
	<TEXT>
		<Tag>TXT_KEY_UNIT_HERO_GERMANY_STRATEGY</Tag>
		<English>The [COLOR_UNIT_TEXT]Red Baron[COLOR_REVERT] is the [COLOR_ALT_HIGHLIGHT_TEXT]German Hero[COLOR_REVERT]. Only one can be acquired per game. The [COLOR_UNIT_TEXT]Red Baron[COLOR_REVERT] is an early aircraft unit. He will defend you skies against [COLOR_UNIT_TEXT]Airships[COLOR_REVERT].</English>
	</TEXT>
	<TEXT>
		<Tag>TXT_KEY_UNIT_HERO_GERMANY_HELP</Tag>
		<English>[ICON_BULLET]Can not be upgraded[NEWLINE][ICON_BULLET]Emerges when the [COLOR_ALT_HIGHLIGHT_TEXT]German Empire[COLOR_REVERT] finishes research on [COLOR_HIGHLIGHT_TEXT]Aeronautics[COLOR_REVERT]</English>
	</TEXT>
	<TEXT>
		<Tag>TXT_KEY_UNIT_HERO_EMERGE_GERMANY</Tag>
		<English>The Red Baron has emerged for the German Empire!!</English>
	</TEXT>
	<TEXT>
		<Tag>TXT_KEY_UNIT_HERO_KILLED_GERMANY</Tag>
		<English>The Red Baron has been shot down!!</English>
	</TEXT>

NOTES

1. No hero will be spawned when a colony is created.

SCREENSHOTS

Spoiler :
papyrusboatemerges.jpg

Naval hero for Egypt emerges

narmeremerges.jpg

Land hero for Egypt emerges because no coastal city is available

civ4redbaron01.jpg

The German Red Baron emerges

civ4redbaronpedia.jpg

Pedia entry for the Red Baron

civ4heroesexamples.jpg

Heroes can have their own class...

civ4heroespromos.jpg

..and their own promotions

SUGGESTIONS

Create a unitcombat for Heroes and give them unique promotions.

BUGS

None I hope.

CREDITS

Edgecrusher: idea and inspiration
The_J: Python, this modcomp would never have seen the light without him
All unitmakers whose work can be used to create the Heroes
Arian: assembled and tested the modcomp
 
Probably yeah, but I don't have a "clean" CvEventManager.py (and I feel lazy ;))

See thats one of the reasons why people need to use the CvEventManager.py and STOP:gripe: making there own in mods, even though it makes things easier for THEIR mod. Its just easier for when things like this happen.:p Of course this is just MY opinion.
 
See thats one of the reasons why people need to use the CvEventManager.py and STOP:gripe: making there own in mods, even though it makes things easier for THEIR mod. Its just easier for when things like this happen.:p Of course this is just MY opinion.

I take it you like this modcomp :D
 
What would be really cool was if someone could combine this with some kind of "stack-bonus" - for example +10% stregth/defence/... for all units in a stack if the hero unit is in the stack. That way you could implement leaders/generals with bonusses.

\Skodkim
 
Back
Top Bottom