Inflow (Wealth) implementation (Experimental/Proposal)#862
Inflow (Wealth) implementation (Experimental/Proposal)#862stavrosfa wants to merge 3 commits intoC7-Game:Developmentfrom
Conversation
C7/Lua/rules/civ3/inflows.lua
Outdated
| local useful_shields = context.input | ||
| local known_techs = context.techs | ||
| local double_effect = any(known_techs, | ||
| function(x) |
There was a problem hiding this comment.
Could this lambda be pulled out to a named function? The formatting here otherwise makes this a little weird to read
C7/Lua/rules/civ3/inflows.lua
Outdated
| end | ||
| ) | ||
| local ratio = rules().ShieldCostPerGold | ||
| return math.max(1, useful_shields / (double_effect and (ratio / 2) or ratio)) |
There was a problem hiding this comment.
Sorry for the lua nits, feel free to ignore this
But would doing local ratio = double_effect and (rules().ShieldCostPerGold / 2) or rules().ShieldCostPerGold make sense?
C7/Lua/rules/civ3/inflows.lua
Outdated
| return math.max(1, useful_shields / (double_effect and (ratio / 2) or ratio)) | ||
| end | ||
|
|
||
| -- example |
There was a problem hiding this comment.
For this and the one below, what would this be an example of? Could you document the idea in the code?
There was a problem hiding this comment.
I have made this look more like it should now, and added a comment to document the usage of this. let me know if it's enough, or I should add more.
Since it makes sense to me as I wrote it, I might be missing the bigger picture.
C7/Lua/rules/civ3/inflows.lua
Outdated
| return extra_science_calculation(context) | ||
| end, | ||
| }, | ||
| -- example |
There was a problem hiding this comment.
ditto with these examples - I know the PR has some details, but if we document here too it avoids having to go through git blame
C7Engine/C7GameData/City.cs
Outdated
| } | ||
|
|
||
| public int GetCulturePerTurn() { | ||
| public int GetCulturePerTurn(bool bonus = true) { |
There was a problem hiding this comment.
what's this bonus parameter?
There was a problem hiding this comment.
Sorry, that was a leftover from a test and it was quicker to do it like this. It's been removed.
C7/Lua/rules/civ3/inflows.lua
Outdated
| -- example | ||
| local function extra_culture_calculation(context) | ||
| local city_culture = context.input | ||
| return math.max(1, city_culture/2) |
There was a problem hiding this comment.
Should these default to doing nothing?
There was a problem hiding this comment.
Yeah, it was there purely as an example instead of trying to explain it with words
|
Cool! Implementing wealth is nice, though I think we'd want the culture/science modifiers off by default. |
Added some extra functionality. Some guardrails for Lua not to call directly methods that might call themselves again in an endless loop.
stavrosfa
left a comment
There was a problem hiding this comment.
Thanks. I 've pushed a commit that should resemble more the final product than this.
C7Engine/C7GameData/City.cs
Outdated
| } | ||
|
|
||
| public int GetCulturePerTurn() { | ||
| public int GetCulturePerTurn(bool bonus = true) { |
There was a problem hiding this comment.
Sorry, that was a leftover from a test and it was quicker to do it like this. It's been removed.
C7/Lua/rules/civ3/inflows.lua
Outdated
| return math.max(1, useful_shields / (double_effect and (ratio / 2) or ratio)) | ||
| end | ||
|
|
||
| -- example |
There was a problem hiding this comment.
I have made this look more like it should now, and added a comment to document the usage of this. let me know if it's enough, or I should add more.
Since it makes sense to me as I wrote it, I might be missing the bigger picture.
C7/Lua/rules/civ3/inflows.lua
Outdated
| -- example | ||
| local function extra_culture_calculation(context) | ||
| local city_culture = context.input | ||
| return math.max(1, city_culture/2) |
There was a problem hiding this comment.
Yeah, it was there purely as an example instead of trying to explain it with words
|
I have added some extra functionality (corruption, happiness, etc). I think there is an issue with how we generally calculate these values, I 've opened an issue here, but the new implementation is wokring on top as it should. When this is fixed, we should be 100% there. On the code side, I decided to change the ScriptContext to include the Player and the city, as a simple integer was too simple and limiting. The risk to recursively call lua that calls c# is still tehre, but I have tried to add some guardrails for lua to not call c# methods that directly call themselves, by splitting the methods that calculate the base value and the ones that take the lua result into account, and also add the [MoonSharpHidden] annotation to those that call lua directly. We could add some kind of enum to pass around c# and lua to let the game know which layer is calling these methods, and when it's lua we should skip some parts, but it's clanky. Let me know if you have any feedback on this. |
This PR is a product of a discussion we had in discord regarding the implementation of "Wealth". Check it out here
There is a lot of boiler plate code because a new type of producable items was introduced.
I ended up calling it Inflow, not that it's a good name, but I spent at least 2 hours searching for a proper term, in the end I just went with something.
This type/category is meant to host items like "Wealth". The wealth producable is fully implemented. I have included 2 other examples with dummy code, I hope you will get the idea.
The point is to have stuff like wealth, that add to the city (and perhaps in the future globally), so in my examples you can see another item called "Cultivation" that is boosting the city's culture based on its current value, and another called "Expertise" that boosts science based on the city's beakers. So it's like Wealth but for Culture and Science.
These are fully exposed to the lua layer so it can do whatever it's instructed, so no need to hardcode anything in C#. We could add more restrictions like after what tech each is available and so on, this is I guess a more minimalistic example as I have simply hardcoded CanProduce() to true.
The triggers that call Lua eventually is in the Player and City classes. All 3 triggers send an integer so that Lua can use to calculate what it should do. At first I was passing the city object, but I had some infinite loop issues where I was calling from lua the method that was calling it in C#, so again, for now and for the sake of simplicity I pass an int to base the calcualtions on. This can change in the future.
If it's any easier for you to understand, I kind of tried to follow the way Terraform/TerraformImprovement is implemented and integrated with Lua.
FInal thing, this is not the "final" implementation, there are many things to be done for this to be actually merged, this is more of a POC.
Let me know what you think or if you have any questions.
@WildWeazel I hope you will like this!
Cheers!