Snaitf's Upgradable Buildings Demo

Snaitf

Chieftain
Joined
Nov 28, 2005
Messages
76
Although this can be played as a stand-alone mod, it's really meant to be a reference for modders looking for this functionality to their mods.

2 new buildings, Barracks II and Barracks III

Barracks II [+5 exp] requires Barracks, and when Barracks II is built, Barracks is removed from city

Barracks III [+6 exp] requires Barracks II, and when Barracks III is built, Barracks II is removed from city

XML changes are enclosed between

<!-- Start Modification Block -->
...
<!-- End Modification Block -->

and Python changes enclosed between

## Start Modification Block ##
...
## End Modification Block ##

This was requested, so I'm hoping more people will find it helpfull...
 

Attachments

I would like to get you (and Rufus as well because of his extensive activities on this forum) acquainted with the 'Modswitcher' by TDB ( http://forums.civfanatics.com/showthread.php?t=140188 ) This little prog, currently still in an immature form, will allow a large audience to combine different mods together without the hassle of modding the scripts by hand!

I think TDB could use either a little help or at least some encouragement for his activities, because this prog feels like the missing link in the current game to me.

Eventually, I hope we can come to some kind of standardized modding using a program like TDB's which would greatly anhance playability of mods on the game.

BTW i posted this here because Snaitf explicitely mentions the reference usage of his mod, which i like btw. I would like to see some different names for the Barracks II etc though, but i guess this kind of modding is easy for anyone(?)

KR R.
 
I think it would be simpler to merely have a Barracks II and Barracks III buildings that each added +1 exp respectively. II requiring a Barracks and III requiring a II. This also prevents the user from building another Barracks.
 
Mylon said:
I think it would be simpler to merely have a Barracks II and Barracks III buildings that each added +1 exp respectively. II requiring a Barracks and III requiring a II. This also prevents the user from building another Barracks.


I agree, this would be easier, but the original request specifically asked for a building that replaces the original, not just another building. And I just wanted to see if I could do it ;) But I'm stuck and can't figure out how to dis-allow the building of the original one again, any suggestions? :confused:
 
Roetghoer said:
BTW i posted this here because Snaitf explicitely mentions the reference usage of his mod, which i like btw. I would like to see some different names for the Barracks II etc though, but i guess this kind of modding is easy for anyone(?)KR R.

Thanks, and yea, the I just chose those names quickly as this was mainly for instructional use, maybes something like "Upgrade Barracks (II)" or something, to give it the feel that the production is going towards actually adding-on to original building as opposed to just felling like your producting a seperate building...
 
Snaitf said:
I agree, this would be easier, but the original request specifically asked for a building that replaces the original, not just another building.

Yeah, this 'solution' had already occurred to me, but in the scenario I'm creating there are between 3 and 5 versions of every building type, along with a 7th era uber-building in that line.

Imagine having 5 barracks buildings on your building list. Now add five warehouse (granaries) buildings. Now add 5 different versions of the justice system (courthouse). Add to that...starting to get the picture? It becomes a cluttered mess for the player. And I don't even know if the game will insist on drawing all 5 barracks/warehouses/whatever on the map itself....

The problem with being able to build lower-end barracks and stacking them in the city didn't occur to me. I can, however, see a somewhat sloppy way to fix it: add in all instances of that building type to the 'remove' command in the code. Like this:

Code:
		if (gc.getBuildingInfo(iBuildingType).getType() == "BUILDING_BARRACKS_III"):
			for i in range(gc.getNumBuildingInfos()):
				if (gc.getBuildingInfo(i).getType() == "BUILDING_BARRACKS"):
					pCity.setHasRealBuilding(i, False)
				if (gc.getBuildingInfo(i).getType() == "BUILDING_BARRACKS_II"):
					pCity.setHasRealBuilding(i, False)

And so on. If you build a lower-end barracks while you have an upper-end barracks in the city, you'll destroy the upper-end barracks. I'm not sure what the if/elsif/else structure is like in Python, so forgive the crude example.

My only concern is that the AI may think it appropriate to replace a Barracks V with a Barracks II - again, and again, and again.

The best solution would be one that obsoletes all lower-class buildings in that city unless the higher-class building is actively destroyed. I would just obsolete the buildings with advancing tech, but that means until you build (in this example) a new barracks your city has *no* barracks - which is silly.

Thanks for the example code, btw. It's exactly what I was looking for.

Max
 
If I knew how to prevent a building from being built I would love to do so for the case of power plants to shorten the build menu. I don't know how to do this short of using a tech to obsolete the building, but that would be a global change.

I've been wanting to include additional power plants (solar and fusion), but not at the cost of lenghtening the build menu further.
 
I notice that during the build command loop it gets a list of all buildable buildings for that city. I wonder if we can alter that list directly for a particular city? That would solve all of the problems in one fell blow.

Max
 
I agree, this would be easier, but the original request specifically asked for a building that replaces the original, not just another building. And I just wanted to see if I could do it But I'm stuck and can't figure out how to dis-allow the building of the original one again, any suggestions?

this would be cluttery and difficult probably...
you could institute a trigger wherein if Barracks II was built a tech (Obsolecense) was researched, which obsoleted Barracks I. you could repeat this, tho the tech tree would get cluttered. unfortunately, you cant have it researched again w/B3 and have it obsolete B2...unless you can put a tech so that it isnt on the screen somehow...
 
maxpublic said:
I notice that during the build command loop it gets a list of all buildable buildings for that city. I wonder if we can alter that list directly for a particular city? That would solve all of the problems in one fell blow.Max

I've thought of this also, but unfortunaltey the CyCity class has no setCanConstruct function, maybe a much more expreienced coder out there knows how we could add something like this?:mischief:

Another work around that would probobly work (in english):

when building is being produced
check to see if it is a barracks​
check to see if barracks II or barracks III is present​
force production of something different​

however, this is very sloppy, and would require alot of code for all the buildings you want to add, and would still let the original barracks be selectable. It would just change the production if you already have the upgraded version...
 
Ah thats nice upgradable buildings is a cool idea!

Thanks to your demonstartion snaitf I can now implement some building upgrades for my own mod! :P. That barracks idea like barracks II, III giving +1 extra xp is a awesome idea.

Perhaps making them require a technology or a unit reaching a certain level or something I could....
Barracks II - Requires a unit to reach level 3
Barracks III - Requires a unit to reach level 4 + tech
etc..
 
jbfballrb said:
this would be cluttery and difficult probably...
you could institute a trigger wherein if Barracks II was built a tech (Obsolecense) was researched, which obsoleted Barracks I. you could repeat this, tho the tech tree would get cluttered. unfortunately, you cant have it researched again w/B3 and have it obsolete B2...unless you can put a tech so that it isnt on the screen somehow...

Problem with this is that it would affect ALL cities, if you build a Barracks II in city A, but city B never had a Barracks, then Barracks becomes obsolete and city B can never build a Barracks at all :(
 
Snaitf said:
I've thought of this also, but unfortunaltey the CyCity class has no setCanConstruct function, maybe a much more expreienced coder out there knows how we could add something like this?:mischief:

Another work around that would probobly work (in english):

when building is being produced
check to see if it is a barracks​
check to see if barracks II or barracks III is present​
force production of something different​

however, this is very sloppy, and would require alot of code for all the buildings you want to add, and would still let the original barracks be selectable. It would just change the production if you already have the upgraded version...

Instead of using CyCity directly, have it call a similar function through PyCity (which would at its base call the CyCity function) and then alter the PyCity function to do the check.

The only unfortunate thing is that you're going to have to add all the PyCity functions which the Main Interface uses to the PyCity class.

BTW, you could probably make it more elegant by having some "MadeObsolete" dictionary where each building will "be made obsolete" by a dictionary of buildings. For example,

Code:
def PyCity.canConstruct:
  if obsolete_dict.has_key (building):
    obsbuildings = obsolete_dict[building]
    for i in range (len (obsbuildings)):
      if (self.city.hasBuilding (obsbuilding[i])):
        return False
  return True

Req
 
After having messed around wiht the xml files, I have found this for stopping constuction (note that they are not covered in the API, and I really dont know the syntax):
Code:
	def cannotConstruct(self,argsList):
		pCity = argsList[0]
		eBuilding = argsList[1]
		bContinue = argsList[2]
		bTestVisible = argsList[3]
		bIgnoreCost = argsList[4]
		return False
in the CvGameUntils.py

In this file there exists alot of canXXXX, cannotXXXX, so if someone would like to mess more around with it, to find the syntax.

More important, I think the Desert War mod uses something like this...
 
I did a cursory run through the code and I see where it accesses the argument list to find what buildings it can construct, but I don't see how the argument list itself is generated. If we could find that little bit of code (assuming we have access to it) then all our problems are solved.

Edit: did a cursory test. It appears the AI will build Barracks I, then build Barracks II, which destroys Barracks I. It'll then build Barracks I again, which destroys Barracks II. And so on.

Max
 
Is it possible to make it require a high level unit?

ie. If you have a level 4 unit you can move it to a city with Barracks I and use the unit to build (like a great person) or upgrage to a Barracks II which gives more experience. Sort of like putting verterans on desk duty to teach the new troops.

Might make it more valuable than just a new building.
 
Back
Top Bottom