New yield type

TheChanger

Warlord
Joined
Jul 2, 2010
Messages
281
Location
Australia
Ok, so im on a mission to add a new yield type to civ for the Naeralith Reborn mod.

I have successfully added the yield to the XML and the font icon for it, however it currently does *nothing*. i know there is a lot that needs to be done to make a new fully functional yield like faith, but i have no idea exactly what to do or where to start.

Ideally id like this yield (its called Pigments) to be calculated exactly like culture or faith, and even be able to use it to purchase units and buildings with. Logically id need to start somewhere with Lua to get the game to add up all the pigments for the civ, but again, i have no idea where to start looking. ive been through all the lua files i could find, doing searched for culture, food, faith and gold to see if i could find out which file to start on but to no avail.

ANY help or suggestion would be greatly appreciated!
 
I did something similar with "Reform" in my Government Buildings mod - it's not too bad getting it all going, but making it useable is another thing!
 
Adding a new yield is certainly a very interesting idea. How far along this are you? Did you manage to make the yield be produced?

I cant seem to get terrains to produce it. seems theres some lua work involved in that as well. i have been able to get specialists to produce it though. haven't tried buildings or improvements yet.

I did something similar with "Reform" in my Government Buildings mod - it's not too bad getting it all going, but making it useable is another thing!

Would you be able to link me to the thread/download on this please so i can have a look how you did it?
 
I cant seem to get terrains to produce it. seems theres some lua work involved in that as well. i have been able to get specialists to produce it though. haven't tried buildings or improvements yet.



Would you be able to link me to the thread/download on this please so i can have a look how you did it?

Here's the link: http://steamcommunity.com/sharedfiles/filedetails/?id=78618328

It may give you some ideas, though creating a sum total is a bit ? - I'd played with the GetTotalYield(Yields.YIELD_REFORM) (or something similar to that), but kept getting an odd mix of my Reform yield and a city's production yield.

Hope it helps though :)
 
I'm surprised Spatzimaus hasn't commented on this thread. He added "favor" as a yield (before G&K's faith). He also has commented several places that is was a ton of work and incredibly complex. And that is from a very sophisticated modder.

For the sake of getting your mod up and running, I'd suggest you think of alternatives to making it into a "true" yield. If you just want something that accrues on a civ-wide level (that is added to by buildings or whatnot) you can do that. You can display this value on the Top Panel easily enough, and have Lua interact with it in any way you want. It just won't be a plot yield. I know that's not 100% of what you want but it might be 70%.

Another more radical idea is to "swap out" an existing yield for your pigment. Faith is the obvious one but culture or science could work too (with some overhaul of policy or tech system). That would seem fitting from what I read of the Naeralith setting. What I mean by "swap out" is to leave the yield as it is presently coded, but change UI to show it as Pigments. And of course you would have to overhaul the yield system that you have usurped.
 
I'm surprised Spatzimaus hasn't commented on this thread.

Since my mod's on hold for now, I don't spend quite so much time on these boards at the moment, since I'm not actually playing Civ5. Plus, GW2 had a beta this last weekend, and I was a bit busy.

While you can add a new yield to the XML, the game just can't use it correctly by default. You see, the game uses special metatables for many of its internal mechanics, and those tables are NOT modified by mods. In this case, there's a YieldTypes table used by all of the Lua functions (instead of accessing GameInfo.Yields, which IS modified), and you have no way of adding your new yield to that table. As a result, any Lua function that involves yields (pretty much anything related to the UI or savegames) won't be able to recognize your new yield at all. Some of these can be fixed with minimal effort, but in the end I had to create an entire Lua structure to manage this extra yield at a sufficient level.

For instance, the game stores how much gold, culture, and research your civilization has accumulated, and how much food or production each city has at the moment. Whenever you save a game, that information is preserved automatically, so reloading an old savegame will automatically return you to the correct values. But any new Yields you add won't work that way; you'll have to create a new mechanism that keeps track of how much of your yield each player has, and ensure that information is both saved to every savegame (and remember, there are four separate ways to save a game) AND reloaded correctly whenever a game is loaded. While there are several mod components out there that help with this issue, it's still not a minor problem, and adds quite a bit of overhead.

Now, the XML will still work for your new yield; it just won't go anywhere with it. This does mean that you can check the XML to see how much of your yield a building produces when adjusting end-of-turn values; the only thing to remember is that you'll have to manually check all possible XML sources of that yield (meaning Policies, techs, terrains, improvements, etc.); if it's a new yield you have full control over you can obviously trim this list down to only those things you know generate that yield. But again, it's a lot of work.

Also note that these metatables also exist for things like Terrain types, Resource types, Plot types, and so on, so you can't easily add a new one of those either, but Yields are so interwoven with all of the game's mechanisms that the failings of the system are much more apparent there.

So, yeah. While it appears trivial to add a new yield, the simple fact is that the game just isn't built to allow that. If you're an experienced programmer, or at least know where all of the traps are, then it's just a time-consuming problem, not particularly difficult. It took me a good three months to get it all working, but someone using my code as a template could probably do so much more quickly, although they'd still have to be a good programmer to know where to deviate from my bits.
 
Thanks for that Insight Spatzimaus, i thought it'd be complex at a lua level but i clearly had no idea just HOW complex it would be. This kind of thing is most definitely far beyond my capabilities, but i think Alzara who im working with on Naeralith could probably be able to understand much more than me and it might be possible for him to do.

Its disappointing to hear that terrain types and plot types follow a similar structure as we had planned to add a new set of 'dead' or 'barren' terrain that is also partly related to the pigments yield...

It took me a good three months to get it all working, but someone using my code as a template could probably do so much more quickly, although they'd still have to be a good programmer to know where to deviate from my bits.

Holy cow, 3 months! O_O thats pretty intense. also you mention someone using your code as a template... would it be ok then if Alzara (cause i obviously wont know what on earth is going on :p) were to take a look at your code and use it as a template? obviously we would credit you
 
For the sake of getting your mod up and running, I'd suggest you think of alternatives to making it into a "true" yield. If you just want something that accrues on a civ-wide level (that is added to by buildings or whatnot) you can do that. You can display this value on the Top Panel easily enough, and have Lua interact with it in any way you want. It just won't be a plot yield. I know that's not 100% of what you want but it might be 70%.

This is definatley something im going to suggest to Alzara if we cannot get a true yield. We can work around not having pigments as a plot yield, we'll just have to alter design a bit. out of curiosity, have you done or do you intend to do this sort of thing in in your mod?

Another more radical idea is to "swap out" an existing yield for your pigment. Faith is the obvious one but culture or science could work too (with some overhaul of policy or tech system). That would seem fitting from what I read of the Naeralith setting. What I mean by "swap out" is to leave the yield as it is presently coded, but change UI to show it as Pigments. And of course you would have to overhaul the yield system that you have usurped.

i guess it is possible, but we really do have a rather extensive religious system in mind that is going to take advantage of the faith yield. and i don't particularly think getting rid of culture would work either...
 
out of curiosity, have you done or do you intend to do this sort of thing in in your mod?

Nothing that resembles a "yield", but I do track a lot of mod-specific stuff that gets displayed in the top panel. One example: Great People points are tallied on a civ-wide basis. To to this, I disabled the core GP point system by setting GP value to zero for everything (specialists and wonders). Then I encoded my own GP point counting system in Lua, which checks every turn (and on combat) for things that should contribute. It displays the mod-specific GP points in the top panel and spawns GPs by my own rules. As always, you have to consider AI in this kind of thing because it doesn't see the GP value for specialists anymore. In my case, this was OK because I boosted yield values enough to make the AI use them appropriately.

My mod tracks all this information using my TableSaverLoader. It's pretty easy to use: it just preserves whatever Lua tables you want through game exit/reload.
 
Pazyryk, that is VERY interesting, thank you! so using this you can tally points produced by great people and buildings, and even from unit actions such as combat? is the only limit terrain and improvements that dont get tallied?
 
Holy cow, 3 months! O_O thats pretty intense. also you mention someone using your code as a template... would it be ok then if Alzara (cause i obviously wont know what on earth is going on ) were to take a look at your code and use it as a template?

We've had this discussion before. Learning how to do something specific by looking through my code is not a problem; copying the design verbatim, not so much. (Since it looks like you've developed your own design now for what your new yield will do, that part shouldn't be a problem any more.) The Favor system alone took that long to get right because the devil's in the details of this sort of thing, and coding something like this is not only intricate, it's ANNOYING. You'll start hundreds of test games, play for one turn, and read through pages of debug text just to see which parts are working correctly. Given how many different game systems are affected, the time required gets ridiculous, and you won't get things right on the first try; I went through four or five release versions where I thought it was working until a playtester found a mistake.

As he's mentioned, I used Pazyryk's TableSaverLoader for this new yield, to handle the save/load issues, which saved me a ton of headaches. (I'd love to say it saved me TIME, but it was the third system I'd tried.) I had to tweak its integration a bit, but what I used is still very close to his design. You'll still need to figure out where to store the data (I used the MapModData structure to store all variables, but there are other options), and a lot of the UI bits are specific to my own design. It's best if you create a series of access functions (Set/Get sorts of things) for every variable, so that if you need to change how the variables are stored you can do so without rewriting dozens of UI functions.

And there are three other things to keep in mind:

1> I never released a version of my mod that was compatible with 674, let alone G&K. Patch 674 broke all combat-related parts of my mods, including the battle-related part of my Favor system, although in my internal version I've already fixed that, more or less. (Given how long I spent getting my mods to work, you can understand why I'm a bit upset about Firaxis breaking it all.)

2> My changes are spread across multiple mods, with my UI changes placed inside IF statements so that Favor is not displayed if you didn't load the Mythology mod. If you're doing this within a single mod then that sort of thing isn't necessary. A lot of what I did was built around that sort of situation, where I needed it to consider the possibility that some of the variables involved weren't being used.

3> If it were possible to cleanly separate this single mechanism, then I'd release it as a Mod Component that anyone could use, but unfortunately it's interwoven through dozens of functions. Besides the obvious headache of the amount of work involved, this also means your mod, like mine, will be incompatible with most other UI-altering mods because you'll have your own versions of TopPanel, CityView, and so on. If you're doing a total conversion fantasy mod then you'd probably be altering all those UI bits anyway, but it's just something to keep in mind.
 
We've had this discussion before

heh i know, that's why i was tenuous about even bothering to ask :p

1> I never released a version of my mod that was compatible with 674, let alone G&K.
thats not a problem. like you said its not like we plan to try repicate favor. pigments will function very differently im sure, so being able to look through your code would be more of a starting point than anything, just to give us an idea of what sort of things need to happen.

2> My changes are spread across multiple mods
i dont think this will be too much of a hassle, but thanks for the heads up

3> If it were possible to cleanly separate this single mechanism, then I'd release it as a Mod Component that anyone could use
thats understandable. Maybe ill chat to Al about seeing if we can formulate a standalone yield mod first and create a tutorial on it before we actually integrate it into Naeralith. i know this would be something a lot of other modders would be able to use.

and honestly, incompatibility issues are pretty much guaranteed with a total conversion mod :p


As he's mentioned, I used Pazyryk's TableSaverLoader for this new yield, to handle the save/load issues, which saved me a ton of headaches.
Yeh That TableSaverLoader looks like a huge help!

You'll start hundreds of test games, play for one turn, and read through pages of debug text just to see which parts are working correctly.
Ah the life of a modder :p i swear the number of times ive loaded civ to test something far outweighs the number of times ive actually loaded civ to play a game :p

Thanks again for this assistance Spatzimaus. I went to your mod forum but couldnt find any download link. im guessing you've taken it down for the time being due to G&K and Firaxis's updates?
 
Ah the life of a modder :p i swear the number of times ive loaded civ to test something far outweighs the number of times ive actually loaded civ to play a game :p

Want to know the sad part? I've never actually played a complete game of my own Mythology mod. My longest game went about halfway through before I stopped to fix the list of broken things I'd encountered; hundreds of test games, and not a single game played for fun. It was ALMOST to the point where all of the pieces were in play and working. I mean literally less than a week away from having the last bit of functionality added, after six months of work; sure, there'd still be tweaking to be done, but I'd have something I could play straight through without major issues.

And then Firaxis goes and breaks the event structure underlying about half my features in a way that can't be fixed with the tools we have, to say nothing of their expansion overlapping so much with my mod that I still haven't figured out how I'll integrate the two. (I haven't even bought the expansion because of this.) So until we get the DLL, and I do a lot more work to fix what they broke, I'll never actually be able to experience the thing I'd made; adding Favor was a lot of work, but I didn't mind too much, because I thought I'd get the mod I wanted out of it in the end. The whole reason I modded in the first place was that I wanted something I would enjoy playing long after they stopped releasing expansions and such.

Anyway, I'll try to point you towards the various bits necessary to add new yields, but without a working baseline it's hard to give correct answers.
 
Different but also difficult experience for me. I let my ambition get out of control. Last December I had all but given up (even after making TableSaverLoader and 1000s of lines of actual mod code). I still get frustrated because a playable mod always seems many months away. (I've been designing this since April 2009. Started coding in earnest a year ago.)

The one thing that saved it back in December was to break up the project into phases, each one building on the last but only tackling a limited amount of material. Phase 1 is really only a prototype, but the most difficult because I had to create AI for my new Great People (which are the central element of my mod). Phase 2 is working toward what could be called (generously speaking) an alpha. Phase 3 and after are intended to be actual enjoyable games, each one adding content on the existing systems. This has really helped me to prioritize and "pick my battles". I really only had one "monster" to fight (the Great Person AI) but it was so central to the mod that I thought it was worth it. There are many other monsters that I have simply walked away from (the title of this thread being one).
 
Back
Top Bottom