1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

[TOTPP] Prof. Garfield's Lua Code Thread

Discussion in 'Civ2 - Scenario League' started by Prof. Garfield, Apr 11, 2020.

  1. Prof. Garfield

    Prof. Garfield Deity Supporter

    Joined:
    Mar 6, 2004
    Messages:
    3,026
    Location:
    Ontario
    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'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.
     
  2. old_hand

    old_hand Chieftain

    Joined:
    Apr 11, 2020
    Messages:
    51
    Gender:
    Male
    Location:
    Madrid
    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.

    Understood - I'll do it.
     
  3. old_hand

    old_hand Chieftain

    Joined:
    Apr 11, 2020
    Messages:
    51
    Gender:
    Male
    Location:
    Madrid
    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.
     
    Prof. Garfield likes this.
  4. Prof. Garfield

    Prof. Garfield Deity Supporter

    Joined:
    Mar 6, 2004
    Messages:
    3,026
    Location:
    Ontario
    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.
     
  5. old_hand

    old_hand Chieftain

    Joined:
    Apr 11, 2020
    Messages:
    51
    Gender:
    Male
    Location:
    Madrid
    Thanks!

    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)

    I'll add that

    Yes, I'll add that

    Yes, I'll add that.

    My pleasure! :)
     
  6. Prof. Garfield

    Prof. Garfield Deity Supporter

    Joined:
    Mar 6, 2004
    Messages:
    3,026
    Location:
    Ontario
    I think I've done this, or at least sent you the invite for it. Let me know the result, just in case.

    I think we all understand that this is a hobby, and that real life can sometimes mess up your plans.
     
  7. old_hand

    old_hand Chieftain

    Joined:
    Apr 11, 2020
    Messages:
    51
    Gender:
    Male
    Location:
    Madrid
    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
     
    Prof. Garfield likes this.
  8. Prof. Garfield

    Prof. Garfield Deity Supporter

    Joined:
    Mar 6, 2004
    Messages:
    3,026
    Location:
    Ontario
    Your way is better.

    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.)

    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.
     
  9. JPetroski

    JPetroski Deity

    Joined:
    Jan 24, 2011
    Messages:
    3,173
    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?
     
  10. old_hand

    old_hand Chieftain

    Joined:
    Apr 11, 2020
    Messages:
    51
    Gender:
    Male
    Location:
    Madrid
    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.
     
  11. Prof. Garfield

    Prof. Garfield Deity Supporter

    Joined:
    Mar 6, 2004
    Messages:
    3,026
    Location:
    Ontario
    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.
     
  12. old_hand

    old_hand Chieftain

    Joined:
    Apr 11, 2020
    Messages:
    51
    Gender:
    Male
    Location:
    Madrid
    Sorry for the delay. I'm having a very high workload right now. Hope to resume working on the missing points this weekend.
     
  13. Prof. Garfield

    Prof. Garfield Deity Supporter

    Joined:
    Mar 6, 2004
    Messages:
    3,026
    Location:
    Ontario
    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.
     
  14. old_hand

    old_hand Chieftain

    Joined:
    Apr 11, 2020
    Messages:
    51
    Gender:
    Male
    Location:
    Madrid
    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.
     
  15. Prof. Garfield

    Prof. Garfield Deity Supporter

    Joined:
    Mar 6, 2004
    Messages:
    3,026
    Location:
    Ontario
    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.)
     
  16. old_hand

    old_hand Chieftain

    Joined:
    Apr 11, 2020
    Messages:
    51
    Gender:
    Male
    Location:
    Madrid
    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 :)
     
  17. JPetroski

    JPetroski Deity

    Joined:
    Jan 24, 2011
    Messages:
    3,173
    @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.
     
  18. Prof. Garfield

    Prof. Garfield Deity Supporter

    Joined:
    Mar 6, 2004
    Messages:
    3,026
    Location:
    Ontario
    I've updated the repository with whatever incremental fixes I've made over the past month or so.
     
  19. JPetroski

    JPetroski Deity

    Joined:
    Jan 24, 2011
    Messages:
    3,173
    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,
     
  20. Prof. Garfield

    Prof. Garfield Deity Supporter

    Joined:
    Mar 6, 2004
    Messages:
    3,026
    Location:
    Ontario
    Can you please send me a copy of your scenario? It is easier to test on a 'target'.
     

Share This Page