Getting Military units to build a specific improvement

Iamblichos

Prince
Joined
Aug 17, 2015
Messages
360
Location
Dallas, TX
Is there a way to get all military units of a specific civ to build a specific improvement? I see the Unit:CanBuild function but I assume this applies to units that have a workrate value?
 
If developers didn't get Romans to utilize their glorious legions building improvements. I don't believe there is a LUA code for it. The only thing that could resemble what you're requesting is that any "idle" military unit standing for some turns can cause an improvement of your specific to pop up and can be modified based on terrain, whether or not there is an improvement, and feature.
 
Well I want to give all military units the ability to construct a specific Mongolian improvement without having to update the database and setting every military unit with WorkRate = X where X is some value I assign, along with updating Unit_Builds. I was hoping to use DLL hook GameEvents.PlayerCanBuild.Add(function(iPlayer, iUnit, iX, iY, iBuild) return true end, along with unit:CanBuild() == iBuild. But I'm not sure that would work.
 
whoward69's dll has a mod component which has these units building improvements and founding cities as they ought.

Links at

HTML:
http://www.picknmixmods.com/

Craig, which mod are you thinking of? I don't see where he's done something similar. I see the Herdsman mod, but that assigns special units to have a) a WorkRate, and b) a Unit_Build assignment. That's a lot more specific than what I want to do if this is what you are thinking of. I'm looking to give all military units the ability to make '1' improvement for a civ that nobody else can build (i.e. it is civ specific). I thought maybe being able to handle this in LUA.
 
I think that Unit.CanBuild will do the trick, though I haven't needed to use that one myself. However, the issue that Enginseer and Craig_Sutter are talking about is getting the *AI* to actually build the things, i.e., having split military and civilian behaviors, which won't happen without a DLL based on whoward69's.
 
Player and Unit CanBuild event handlers are ONLY called as an additional check to see if something can be built on a plot. If the unit can't build the thing, they will never get called, so every unit that can possibly build the thing will have to a) have a workrate and b) have an associated build. However, SQL can be used to make such updates in only two lines.
 
Player and Unit CanBuild event handlers are ONLY called as an additional check to see if something can be built on a plot. If the unit can't build the thing, they will never get called, so every unit that can possibly build the thing will have to a) have a workrate and b) have an associated build. However, SQL can be used to make such updates in only two lines.
Just for clarification (though it may only be me that's confused), your idea is rather than make unique versions of every unit for the civ (still not completely awful with SQL, but more than a couple lines), just give every unit the ability, and then turn it off with Lua where it's not wanted?
 
Sure I can handle it with an sql update, no problem. And the Improvements SpecificCivRequired = 1 column will do the trick from blocking military units from other civs from building it, but I admit my OCD gets the best of me as that doesn't seem very clean to me...I settled on giving the Kahn and the Keshik the ability to build the improvement and changed their AI and Flavor behavior (instead of doing that for every military unit). Thanks a bunch for the replies.
 
Player and Unit CanBuild event handlers are ONLY called as an additional check to see if something can be built on a plot. If the unit can't build the thing, they will never get called, so every unit that can possibly build the thing will have to a) have a workrate and b) have an associated build. However, SQL can be used to make such updates in only two lines.

That was my findings too from trying it, and looking at other lua examples of those event handlers, it was clear that was a check as you describe. Thank you.
 
Just for clarification, rather than make unique versions of every unit for the civ , just give every unit the ability, and then turn it off with Lua where it's not wanted?
-Yep-
 
Just for clarification (though it may only be me that's confused), your idea is rather than make unique versions of every unit for the civ (still not completely awful with SQL, but more than a couple lines), just give every unit the ability, and then turn it off with Lua where it's not wanted?

Pretty close, what I was trying to do is do a check if Mongolia was in the game and then do a 'for unit in player:Units() do' and then give Mongolian units the ability to do a build, but there's no function to hook it up as described by whoward. FYI, I'm using Community Patch DLL.
 
No, when I said "your" idea I was referring to whoward69's.

You still use CanBuild, just in the opposite way to turn it off for all other civs rather than on for yours.
 
Thanks for the recommendation! I think I might give that a shot. It's not as clean as I'd like, but that'll do it.
 
I believe you can do it without using Lua - in the Improvements table there are columns called SpecificCivRequired and CivilizationType. They are used for the existing unique improvements like Kasbah, Feitoria, Chateau etc. So you can achieve your goal by doing the following:

1. Give all military units a WorkRate.
2. Give them the Build that builds your improvement.
3. Set that improvement as available only to a specific civ by using SpecificCivRequired and CivilizationType.

(As whoward69 noticed, for points 1 and 2 you only need a few lines of SQL code.)
 
Following this thread as I have a similar question; what's the most efficient method to allow military units from a specific Civ to repair improvements? I guess it's possible to create a unique version of all military units with the repair build and a workrate and then in lua covert all regular units to it's repairing-able counterpart. But that just doesn't seem very efficient. I'm I overlooking some obvious method?
 
I believe you can do it without using Lua - in the Improvements table there are columns called SpecificCivRequired and CivilizationType. They are used for the existing unique improvements like Kasbah, Feitoria, Chateau etc. So you can achieve your goal by doing the following:

1. Give all military units a WorkRate.
2. Give them the Build that builds your improvement.
3. Set that improvement as available only to a specific civ by using SpecificCivRequired and CivilizationType.

(As whoward69 noticed, for points 1 and 2 you only need a few lines of SQL code.)
Thanks, yes I indicated in my first post that I already knew how to accomplish this. This also requires a few more edits though in Unit_AITypes and Unit_Flavors, if you want the AI to be able to have interest in doing the improvements. Not interested in doing in that for several reasons, namely ALL civ military units will behave this way even if they are a different civ. They might be blocked from making the SpecificCivRequired improvement, but I don't find that to be all that clean of a method. I opted, to change those tables for two units, but a better way might be to modify the DLL for a Trait that can enable such behavior without it grabbing all military units for all civs at all times and at all places.
 
This also requires a few more edits though in Unit_AITypes and Unit_Flavors, if you want the AI to be able to have interest in doing the improvements.

Changing those values will have no effect on military units attempting to perform work actions, as, without a DLL mod, the AI never considers units with a combat value for tile improvement duties.
 
Changing those values will have no effect on military units attempting to perform work actions, as, without a DLL mod, the AI never considers units with a combat value for tile improvement duties.

Are you sure? In my sim games with the CPP, the AI Keshik and Khan were building the unique improvement I assigned to them. I don't know if that DLL has any writes in there for such actions, but the improvements were built.
 
Back
Top Bottom