Modding feasibility question

johnpaulkenya

Chieftain
Joined
Sep 11, 2011
Messages
5
I'm making a mod for Civ 5 to change gameplay entirely. I want to set it up so that what used to be borders is now recognized as a Control Zone, wherein a player could construct buildings. Building construction requires a Unit to be consumed on the spot the building is to go up, so I imagine I'd have to make a button on the Unit, check to ensure they're inside a control zone, and then spawn in the building(which would then produce a resource or a unit). How feasible is it to do this?

Let me know if I can clarify that wot a bit...
 
How feasible is it to do this?

It isn't.

Look, we don't have the DLL yet. That means mod changes are limited to the existing XML stubs, and whatever you can cobble together from the existing Lua functions. And nothing you do will be recognized by the AI, so if your changes require any sort of adjustment in playstyle, AT ALL, then it won't work for the AI.

Once we have the DLL you'll be able to do far more, assuming you're an experienced C++ programmer, but even then what you described will require a huge number of changes on the AI's side. If you're not an experienced programmer, then just forget it.

In the case of your specific suggestion, we have ways to create Improvements from Units (the Great People improvements are a good example), but no way to have those improvements provide the sort of functions you describe. And we have very limited ability to add new improvement artwork, so you'd basically be stuck with the existing improvements' graphics. You could use a Lua event to make these improvements generate new units, and in theory you could use the save/load functionality to add a new UI interface that controls that mechanism, but again, the AI wouldn't understand how to do this.
 
Such thing is already done with the Work Boats and Great People, so I guess it should be pretty easy...

Edit: Looking at Spatzimaus' answer, seems I haven't fully understood what you meant....
 
Such thing is already done with the Work Boats and Great People, so I guess it should be pretty easy...

This find the method I was thinking, if I could find the method for Great People to create their unique building, couldn't I theoretically copy that to make all buildings necessary?
 
It's easy to add new "Builds" that consume the unit, the harder parts, as Spatzimaus noticed, are getting graphics for the new improvements, and adding new functions to them.
 
This find the method I was thinking, if I could find the method for Great People to create their unique building, couldn't I theoretically copy that to make all buildings necessary?

No. The problem is that the Units table can have entries that require a certain technology, or a certain building, but there's no corresponding entry for a certain Improvement. Without using Lua, you'd be limited to only those XML tables that already affect Improvements, and there just aren't many of those. With Lua you can do things like have an Improvement spawn a unit, but it'd have to be done in a fully automatic way (every X turns, build one). If you tried making it user-adjustable, then you run into the AI issue I mentioned, where the AI simply wouldn't understand.

And resources are much, much worse. A building can provide a resource, but it can't generate one. Improvements also can't generate resources, although Lua scripts that check for the existence of those improvements CAN. Now, both of these can be avoided through creative use of the Save and Load functions, but it's a lot more complex for improvements than it is for buildings because of the positional issues.

Then, you run into conflicts with other improvements. Does your custom Improvement add food/production/gold? If not, then the AI won't see its value. The AI player might place that improvement, but then he'd immediately destroy it to place a Trading Post or something, unless you removed all "normal" improvements altogether. And even then, it wouldn't understand the true value, and might try to replace improvement A with B instead of putting B on its own tile.
 
No. The problem is that the Units table can have entries that require a certain technology, or a certain building, but there's no corresponding entry for a certain Improvement. Without using Lua, you'd be limited to only those XML tables that already affect Improvements, and there just aren't many of those. With Lua you can do things like have an Improvement spawn a unit, but it'd have to be done in a fully automatic way (every X turns, build one). If you tried making it user-adjustable, then you run into the AI issue I mentioned, where the AI simply wouldn't understand.

And resources are much, much worse. A building can provide a resource, but it can't generate one. Improvements also can't generate resources, although Lua scripts that check for the existence of those improvements CAN. Now, both of these can be avoided through creative use of the Save and Load functions, but it's a lot more complex for improvements than it is for buildings because of the positional issues.

Then, you run into conflicts with other improvements. Does your custom Improvement add food/production/gold? If not, then the AI won't see its value. The AI player might place that improvement, but then he'd immediately destroy it to place a Trading Post or something, unless you removed all "normal" improvements altogether. And even then, it wouldn't understand the true value, and might try to replace improvement A with B instead of putting B on its own tile.

I can see this would be a bigger undertaking than I originally thought...if it's possible at all. Thanks for the explanation.

Are you aware of any way I could possibly make this playstyle work? If Civ5 isn't the answer, maybe there's a different game you know of I could try? Thanks again!
 
I can see this would be a bigger undertaking than I originally thought...if it's possible at all. Thanks for the explanation.

I'm not saying the idea isn't salvageable. For instance, take what I said about yields. If you were to create a NEW yield, you can manipulate its values easily enough. So let's say we create a new yield called Awesomeness; instead of +2, this Improvement provides +4 Awesomeness. Awesomeness does nothing, but that +4 might be enough that the AI won't want to replace it with a +2 Food improvement, because it can at least understand that +4 is bigger than +2. There goes that concern. Now, it might decide to replace that +4 with a different +4 Awesomeness improvement, but there's a little trick to avoiding that (make two Improvements. The buildable one has a lower yield. At the end of each turn, replace any instances of the lower one with an instance of the higher one. I do this in my own mod for the Monolith improvement.)
If you're trying to remove in-city Production of buildings and such, then you don't even need a new yield, just use Production for that.

Or the unit spawning. If it's purely automatic (every X turns, that improvement generates a new unit) then the AI can handle that almost as well as the human does; he might not understand WHY he wanted to build that improvement, but he'll get full benefit. And even if it's not automatic, you can hard-code some simplistic AI probabilities into the system; that's basically what I'm doing for my Mythology mod. The AI might not play it WELL, but it won't be absolutely terrible.

But it'd be a lot of work, regardless.
 
I'm looking over some Lua examples and it does seem doable. Hooks to make it so a unit is destroyed and a feature is put in his place, then I can hook into the start of a turn and check to see how many buildings of such exist and update resources that way.

The AI does present a more challenging issue. It looks like I can code in some AI routines in Lua, but these would be tricky (the AI has different goals than the Players) and take some research to get going.

I don't know if I'm ready to call this quits yet. I'm not averse to learning Lua (my previous attempt at this idea was C# but I realized I was in over my head) so I'll take a look deeper. Any Civ 5 Lua experts care to weigh in?
 
Hooks to make it so a unit is destroyed and a feature is put in his place,

Be very, very careful with this. Most of the Lua events don't trigger like you'd think they would. For instance, take SerialEventImprovementCreated. It triggers when an improvement is created, which makes it the obvious choice for something like this, right? Just one catch: it only triggers when you SEE an improvement be created. If the AI is producing the improvement somewhere else in the world, it won't trigger until you move one of your units to where he can see that tile.

Or SerialEventUnitCreated. It triggers whenever a unit is created, and unlike the ImprovementCreated event, it triggers even if a unit is created off in the fog of war someplace. Sounds great, right? Well, unfortunately it also triggers whenever a unit embarks, or whenever a unit disembarks, or whenever a unit enters a "transport" unit like a Carrier or Missile Destroyer, or whenever an air unit rebases... you get the idea.

The common thread to both of these is that they're UI-based; something's only important when there's the potential of changing the display on the active player's computer screen. This sort of inconsistency is a major flaw. The only events that consistently trigger exactly when you'd expect them to are the start-of-turn and end-of-turn events, or the various GameEvents options (like the SetUnitXY event for movement).

then I can hook into the start of a turn and check to see how many buildings of such exist and update resources that way.

It's not quite that simple, but go over into the mod components forum (I think) and look for the "Building Resources" mod. That mod leveraged the save/load functionality to allow buildings to create strategic resources without huge amounts of overhead.

It looks like I can code in some AI routines in Lua, but these would be tricky (the AI has different goals than the Players) and take some research to get going.

The problem with doing this is you can't integrate it into the existing Flavor system, which is the primary driver behind AI behavior. And that means you can't easily make one civilization act differently than another. For some things, this isn't really a problem. But in this case, you're asking to add some complex behavior.

For instance, the example I gave before: what do you do to prevent the AI from putting this improvement on the wrong tile, one that you need for its more mundane yields? What do you do to prevent the AI from destroying one of these improvements because it thinks some other one is better? The problem is that the AI's behavior is probabilistic, not absolute; no matter how high or low you set Flavor values, it'll still have a chance of doing really stupid things, unless you create a mechanism that makes those stupid things completely impossible. And those sort of limits are much harder to implement.

I'm not averse to learning Lua (my previous attempt at this idea was C# but I realized I was in over my head) so I'll take a look deeper.

Lua is not difficult. It's just a question of learning how to use the existing functions we've been handed to do the things you want, OR altering your design to work with the functions we do have. And that's a problem, because I think there are several points in your design that just won't work without significant changes.
 
Lua is not difficult. It's just a question of learning how to use the existing functions we've been handed to do the things you want, OR altering your design to work with the functions we do have. And that's a problem, because I think there are several points in your design that just won't work without significant changes.

I think I'll figure out a couple of essential functions and try to get them running.

If a design point doesn't work, I'll have to figure out the best compromise between that element and what's possible. I have a full design document and tables to reference, so well-researched changes won't be an issue to add in.

As far as the AI goes, I imagine I'd have to be very restrictive to ensure it creates buildings, units, and not destroy everything. The mod has a very board game feel to it, there usually aren't more than a few decisions available per turn. I'll have to see if I can get a rudimentary system going based on what we know already. Is there a reference to the Lua hooks anywhere? And the SQL ones too, for that matter?
 
Is there a reference to the Lua hooks anywhere? And the SQL ones too, for that matter?

SQL doesn't have hooks. It, and XML, can only deal with whatever schema are declared in the core game's files, or whatever tables you add yourself.

For Lua, just go to 2kGames' modding wiki; there's a link around here somewhere, and when I get home from work I can provide it if no one else has by that point. It shouldn't be hard to find with Google, though.

The thing to keep in mind, which I was trying to explain before, is that it's VERY difficult to add prohibitive behavior. Lua isn't structured to turn things OFF, only to turn things ON; you can add or subtract to existing values, or add more things that happen whenever a trigger event occurs, but you can't prevent most of the existing triggers (and their resulting events) from occurring. This has been improved with the recent addition of several new GameEvents, but it's still a major design consideration. It means that you simply can't stop the AI from doing certain behaviors; all you can really do is try and clean up the aftermath.

This is why I was saying that without the DLL most of this won't work; Lua just isn't well-suited to stopping the AI from taking a bad action before it happens. You can't prevent a unit from dying, only try to resurrect it afterwards. You can't stop a city from demanding an invalid resource, only force it to pick again. You can't stop a unit from attacking, only tweak the odds once the battle starts. You CAN prevent a nuke from exploding (by force-killing the unit before combat resolves), but only under a large number of limitations. You get the idea.
 
Back
Top Bottom