HOW TO add replacement

MaxRiga

Emperor
Joined
Feb 1, 2004
Messages
1,274
Location
Riga/Montreal
how to make unit replacement after the technology ( or year ) discovered/passed. If the unit is upgradeable then it automatically removes after the next level is reached ( warrier-pikeman etc ). So, warriors are unavailable for construction when we have pikeman. So, how to make a unit unavailable without upgrades?
 
I think you're misunderstanding the tags used in this forum. The idea of this forum is to post new threads, where the post explicitly has a tutorial, reference or guide already contained within it, either in the first post or the first post and next few replies (if it's longer). If the tag is HOWTO or [HOWTO] or whatever, a person will open that expecting a guide on how to do whatever the topic is, not a question about it. Typically, people might respond to that thread if they have questions on the tutorial, guide or reference in that thread.

If you have questions that you can't find answers for in a quick search, you can start a new thread in the main Civ4 - Creation and Customization forum.
 
Zulu_WRONG_FORUM_animation.gif
 
either in the first post or the first post and next few replies (if it's longer).

right, i was expecting an answer as second post and there is ur and catastrofy guy second :))) so, when some1 answered who knows HOW that whould be pretty much right place for HOW TO :))))

has any1 tried <obsolute>tech_something implontated into civunits schema?
 
MaxRiga said:
right, i was expecting an answer as second post and there is ur and catastrofy guy second :))) so, when some1 answered who knows HOW that whould be pretty much right place for HOW TO :))))

has any1 tried <obsolute>tech_something implontated into civunits schema?

Well, it's a neat idea, the problem is, what if someone doesn't answer it? Then there's a HOW TO with no howto in it. Besides, normally references and guides make up a more big-picture idea (how to add a XML entry, not how to make an XML entry that does a certain thing. You can use one as an example, but the idea is to show how to do the big picture thing).

As for your actual question though, the cleanest way is probably to add another XML entry. Unfortunately, that takes some XML modding. Another way is to change the python CvGameUtils class. It has a canTrain cannotTrain function, which if you wanted to could check most anything, since it gives you the CyCity object (which you can get the owner from), and the enumerated value of the unit (it's UnitTypes number) in question. Doing it in just python, you could make a list of technologies that obsoletes the unit, and then check if the player has any of those technologies.

Edit: I Mixed up canTrain and cannotTrain. To make a unit untrainable, you'd want cannotTrain.
 
MaxRiga said:
unfortunately i'm not familiar with programming .. could u pleado you mind to help me with this some how? my mod really needs it :)

Well, if you were familiar with python, I could give you an idea on how to get started, but creating something, coding it and then making sure it works, even on something small, is already long enough.

In CvGameUtils.py, under def cannotTrain, for a very quick-and-dirty way of doing this, you would have:

Code:
def cannotTrain(self,argsList):
		pCity = argsList[0]
		eUnit = argsList[1]
		bContinue = argsList[2]
		bTestVisible = argsList[3]

		[b]# Begin edit for obsolete units [/b]
		# A dictionary for obsolete units.
		# The first entry is the unit.
		# The second entry is a list of techs that obsolete it.
		obsoleteDict = {
		"UNIT_WARRIOR": ["TECH_MYSTICISM"],
		"UNIT_ARCHER": ["TECH_MYSTICISM", "TECH_MEDITATION"] # No comma for last.

		}

		# Gets the type of unit we are currently checking
		szUnitType = gc.getUnitInfo(eUnit).getType()

		# Checks if that unit has techs that make it obsolete
		# by seeing if it's name appears in the obsolete dictionary.
		if  szUnitType in obsoleteList:
			# If it does, get the list of techs by giving the dictionary
			# the unit name as a key.
			obsList = obsoleteDict[szUnitType]

			# Go through each technology and determine if
			# the player has it.
			for szTech in obsList:
				# Get the tech number...
				eTech = gc.getInfoTypeForString(szTech)
				if gc.getTeam(pCity.getTeam()).isHasTech(eTech):
					# If the player has that tech, return True
					# to say that the unit cannot be built.
					return True

		# Return False, since the unit is not obsolete, and thus can be
		# built.
		[b]# End edit for obsolete units [/b]

		return False

}

Does this code even work? I don't know. I just typed it into the browser. You can try it out, and if it does what you want, great! If not, you can at least look at what I did and make an attempt to figure it out for yourself (hey, you gotta' learn some python if you want to make mods do more what you want!)

Note that this will only mean that units that are obsolete cannot be trained (or if they are in the process of being trained, cannot continue training). I'm not sure how this affects units that can upgrade while training. Also note that you wouldn't get any message saying WHY a unit cannot be built, and that getting the unit help (by hovering over it's icon) will not display when it becomes obsolete.
 
Back
Top Bottom