[TOTPP] Prof. Garfield's Lua Code Thread

I'll do the changes you comment. Do you prefer to continue with pull requests or would it be better if I get read/write permissions to your repo? That way I can do things directly there.

I'll see about giving you read-write permission, might be a couple days. Work is rather exhausting at the moment, so I don't often want to do other stuff when I finish.

I can do that, for sure, no problem. One question, though, why don't you use symbolic links? I use that to ensure that I edit the same copy all the time. They are supported in windows since Vista (for NFTS partitions). You should have them as you use WINE, isn't it?

I'll have look into that. However, I do also have a preference for being able to distribute a module and be able to say that the user doesn't have to make changes inside of it.
 
I'll see about giving you read-write permission, might be a couple days. Work is rather exhausting at the moment, so I don't often want to do other stuff when I finish.

I'm very busy with work too. We have a red alert from a customer, and it's likely that I will work as much as possible this weekend. Thanks for your undertsanding.

I'll have look into that. However, I do also have a preference for being able to distribute a module and be able to say that the user doesn't have to make changes inside of it.
Understood - I'll do it.
 
First of all, thanks again for your impressive work and for your kind and detailed feedback. professor. I've gone ahead and fixed everything but point 3 (read from a separate file), on which I'll work next. I attach some screenshots for feedback.

Let's start with the units - I have specified the amount of units to be given out. Is this good? There is an option to limit the maximum number of characters to display in the list of units, so you can control if the unit list gets too long.

units.jpg


Then I did the money recurrent thing. So, to start with, you only have "Add ..." and "Cancel" options to start building the amount

money1.jpg


But as soon as you have build more than 0 amount to give out, you have the option to give the money

money2.jpg


(It's the yes, give 100!) As you keep adding money to the total amount, it may be possible that your options are reduced, because you can't give more than what you have in the treasury (250 in this example)

money3.jpg


We may even come to a point where we can say Yes or cancel

money4.jpg


Then, I did also the $MONEY to %MONEY conversion, fixel the camelCase and added one new option and one new escape characters (%UNITS) for the dialogs.

I'll work in having the options in a separate file, but your feedback is more than welcome.

I have not send a pull request for this, I'll do once that the point 3 - separate file - is addressed.
 
Thanks, this looks excellent.

Do the gift increments increase if you have a larger treasury? It would be a bit annoying to give 10,000 gold out in increments of 100. Or, maybe offer a multiply by 10 feature. Perhaps a subtract option, in case the player makes a mistake, so they don't have to go through the whole process again. If you used the recursive function that I suggested, perhaps you just feed the most recent increment as a 2nd argument, and offer to subtract the most recent addition.

Can we have a %RECEIVERADJECTIVE (or something similar) to substitute in the adjective of the receiving tribe?

Might be useful to have something like %UNLISTEDUNITS to provide a number of units not shown in %UNITS, so that the message can be a little more polished.

Thanks again for your work.
 
Thanks, this looks excellent.
Thanks!

Do the gift increments increase if you have a larger treasury? It would be a bit annoying to give 10,000 gold out in increments of 100. Or, maybe offer a multiply by 10 feature

Yes, in the default config there are entries for 500, 1000 and 5000. They are not shown because the are bigger than the current Roman treasure (250). You can always personalize the amounts with one of the options where you supply a table with the amounts (and the text to display)

Perhaps a subtract option, in case the player makes a mistake, so they don't have to go through the whole process again. If you used the recursive function that I suggested, perhaps you just feed the most recent increment as a 2nd argument, and offer to subtract the most recent addition.

I'll add that

Can we have a %RECEIVERADJECTIVE (or something similar) to substitute in the adjective of the receiving tribe?

Yes, I'll add that

Might be useful to have something like %UNLISTEDUNITS to provide a number of units not shown in %UNITS, so that the message can be a little more polished.

Yes, I'll add that.

Thanks again for your work.

My pleasure! :)
 
I'll do the changes you comment. Do you prefer to continue with pull requests or would it be better if I get read/write permissions to your repo? That way I can do things directly there.

I think I've done this, or at least sent you the invite for it. Let me know the result, just in case.

I'm very busy with work too. We have a red alert from a customer, and it's likely that I will work as much as possible this weekend. Thanks for your undertsanding.

I think we all understand that this is a hobby, and that real life can sometimes mess up your plans.
 
Thanks! Write access worked. I've merged all my fixes, which includes, apart from what I listed previously, the following ones.

* Added the subscract option (see screenshot after the text)
* Added the RECEIVERADJECTIVE to the %% text
* Added that the list of units always contain (and X of other types), if X > 0. I prefered this rather than the %UNITLISTEDUNITS because the string customized by the user of the events would have something as ugly as (and %UNITSLISTEDUNITS of other types) even if that was 0... But I am open to change this if you prefer other way.

So, that makes all the changes, but the reading from a file. I need a bit of guidance there.

I've been looking into your canBuild.lua and flag.lua - and I want to be sure I fully undertsand. The approach you did was to put the flags for canBuild in a separate file. My approach for diplomacy was to pass an "option" parameter to the main dialog function where you can customize any of the options. That way, in the events.lua itself you can customize whatever you want for that scenario.

What approach of those two you prefer and why? I am really open to change the way I've done it, I just want to know how and why :)

substract.jpg
 
* Added that the list of units always contain (and X of other types), if X > 0. I prefered this rather than the %UNITLISTEDUNITS because the string customized by the user of the events would have something as ugly as (and %UNITSLISTEDUNITS of other types) even if that was 0... But I am open to change this if you prefer other way.

Your way is better.

I've been looking into your canBuild.lua and flag.lua - and I want to be sure I fully undertsand. The approach you did was to put the flags for canBuild in a separate file. My approach for diplomacy was to pass an "option" parameter to the main dialog function where you can customize any of the options. That way, in the events.lua itself you can customize whatever you want for that scenario.

What approach of those two you prefer and why? I am really open to change the way I've done it, I just want to know how and why

I use the method of passing a parameter table to the function in the munitions module, so it is fine. This has the advantage of being able to change the parameters just before use.

I have a few reasons for using separate functions to provide parameter tables to modules.

1. Sometimes it is necessary, or at least convenient for organizing files. I don't know of another way (except global variables) to provide the state table to modules that are likely to be used in multiple files and modules, like flag, counter, and text. Even if not strictly 'necessary,' it might force certain parameter tables to be defined in inconvenient files, so that all the .lua files that need to 'require' those tables actually can require them.

2. Sometimes, there are a lot of parameters to feed in. In Over the Reich, I think my reaction functions had 3 lines of arguments to be filled in, which was annoying, and potentially error prone, both for the end result (even if it is used only once or twice), and for writing helper functions in the module. If you have to use a function many times, keeping track of the names (and order) of even one or two parameter tables can get a bit annoying.

3. It simplifies instructions about how to use the module (especially for those who don't have programming experience outside Civ II Lua). If I can provide a template file and have a couple lines at the bottom 'linking' the tables to the module, then the end user just has to have a 'require' line somewhere, and use the function with the 'obvious' arguments. Have a look at the munition module (and the usage instructions at the top), and then the munition module thread, where I offered some additional usage explanation to JPetroski, on stuff that seemed pretty obvious to me. I was happy to give the explanation, but it would probably have been less work to link parameters, if it were possible in that case.

Also, passing several tables would either mean separate files, or bundling multiple tables into a 'super' table to return, and then 'unpacked' into multiple tables in the events.lua file. (I tried returning multiple tables, but require doesn't seem to like that.)

* Added the subscract option (see screenshot after the text)

It's "subtract", not "substract".

Also, maybe send a message to the receiving player about the gift (if not already implemented). There is a function in text, displayNextOpportunity (might not be exact function name), that will do that automatically.
 
Is there a way to adjust tribe attitudes? I'm curious if, in a SP game, giving these gifts might in turn lead to better relations?
 
Yes, there is a way. I didn't do anything like that for this. You can gift money, tech or units to an AI through the standard diplomatic ways, isn't it? Anyway, if needed, I can add it.
 
Is there a way to adjust tribe attitudes? I'm curious if, in a SP game, giving these gifts might in turn lead to better relations?

Yes, there is a way. I didn't do anything like that for this. You can gift money, tech or units to an AI through the standard diplomatic ways, isn't it? Anyway, if needed, I can add it.

The standard diplomatic model seems adequate for dealing with the AI. If an alternate diplomacy model is needed for the AI, then it will probably be very specific to the scenario being built, and so a prebuilt solution won't be of much use. I guess improving attitudes after the gift of a city might make sense, but it also seems ripe for abuse. E.g. give away cities on a border or in a war zone, thus stopping your enemy from receiving them, and improving the attitude of the recipient to you. A human would see that as trying to entangle them into a war, and not take too kindly to that.
 
Sorry for the delay. I'm having a very high workload right now. Hope to resume working on the missing points this weekend.
 
No problem. I haven't had the chance to work on A Soaring Spirit anyway, and the diplomacy functions can be added in at the end.
 
Report: still alive, still with problems at work. Hopefully this long weekend (1st and 4th May I do not need to "work" normal hours, so I can catch up on old work) I'll get up to speed.
 
I updated the repository today. I introduced the "Help Key" module from Over the Reich (and also used by Napoleon), which I forgot to put in earlier. (Also, some work was done on A Soaring Spirit.)
 
Report: I've finished my huge load of work. I'll be out of computers for today and maybe tomorrow. By Sunday latest I'll return to my normal activity with regards to civ2 :)
 
@Prof. Garfield , I have found your munitions library to be very simple to work with now that I've tried it once with Germanicus and had an example to work with. Adding in additional features that I did not use in that scenario, but wanted to use in this one (such as payload) was extremely easy. To the extent that whenever you build one of these, you put in two examples (because people might not understand how to start a second feature) I think these are going to open the door for more designers.
 
Can I make a request for the diplomacy module? In Brown Man's Burden lua, gifting a unit deletes and recreates it at the particular square. The diplomacy module seems to have a list of destinations option (not utilized in BMB) where the code will go through the list, finding the first destination and then depositing the unit there.

What I really need to bring Cold War alive is an option that only allows a unit to move from one city that has improvement 30 to a city of another civ that has improvement 30, to represent shipping. I need the player to be able to choose which city to send it to from a list (in case the Russians want to support the North Vietnamese vs. the Egyptians for example). A limit (adjustable) on how many units can transfer from each city on each turn would also be necessary to prevent the entire Red Army from showing up for a turn in Vietnam.

I looked through the module and didn't see this there but apologies if I missed it.

Thanks,
 
Top Bottom