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

[TOT] [TOTPP] The General Library

Discussion in 'Civ2 - Scenario Creation' started by Prof. Garfield, Jul 10, 2019.

  1. Prof. Garfield

    Prof. Garfield Deity Supporter

    Joined:
    Mar 6, 2004
    Messages:
    2,312
    Location:
    Ontario
    The General Library is a collection of relatively basic functions with wide potential use. The standard usage will be

    Code:
    gen.generalLibraryFunction(input1,input2)
    
    The General Library is currently under construction, so go to the last page of this thread to find the most recent version.

    If someone has a better name than "General Library" and gen., I'm open to it.

    You can contribute to the General Library in the following ways:

    1. Suggest functions for inclusion.

    Good candidates are functions that tell the end user most or all of what it does just by its usage specification line. For example,
    Code:
    gen.hasIrrigation(tile)-->boolean
    
    tells most of what you need to know about the function and how to use it. Maybe you need to check if farmland counts as irrigation, but otherwise it is obvious what the function does and how it is supposed to work.

    This is not a strict requirement. It may sometimes be desirable to include more complicated functionality in this Library, if it is likely to be used in a lot of places.

    If you make some suggestions, update the generalLibrary.lua file with the new functions, both in the List of Functions and by making a placeholder comment (with any extra details needed) in the implementation section.

    2. Testing functions

    Sometimes there will be a submission to the General Library that the author didn't have time (or desire) to test as thoroughly as it probably should have been. This will be noted in the function list.

    3. Submitting code

    If you have some time, you can implement some of the suggested functions for this library. Many of these will be relatively simple functions that would be good to practice on (and then test).

    Submission Guidelines:

    If you are working on the General Library, and someone else makes a submission before you finish, you must include all their changes into the version you post. If you don't want this to happen, make a post that you are modifying the events. In that case, it will be the other person's responsibility to merge the changes. If you have "claimed" the events for more than 4 days, we revert back to the earlier submission rule, unless you make an update. You can always comment out bad code and submit, if you want to return to it later.

    In the submission post, explain your changes. If you are proposing a function for inclusion (including if you have already written it), put its usage specification line in the post along with any other details necessary.

    EDIT: I will now keep this code in a GitHub Repository , and update it there. I will still accept submissions in this thread (or you can PM me a submission if you prefer), and merge them into the repository myself. Click the green "Clone or Download" button to download the code.
     

    Attached Files:

    Last edited: Oct 6, 2019
  2. Prof. Garfield

    Prof. Garfield Deity Supporter

    Joined:
    Mar 6, 2004
    Messages:
    2,312
    Location:
    Ontario
    New Functions proposed and completed (may need testing)
    -- applyWonderBonus(wonderObject or integer,tribeObject or integer)-->boolean
    -- checks if the bonus for the wonder should be applied for the tribe
    -- gen.wonderModifiedMoves(unit)-->integer
    -- returns the movement allowance of a unit after
    -- taking into account nuclear power, wonders
    -- returns atomic movement points
    -- maxMoves(unit)--> integer
    -- gen.maxMoves(unit) --> integer
    -- returns movement allowance for a unit after taking damage
    -- into account, multiplied by the road/rail multiplier
    -- Helper Function (provided as both local function and in table
    -- gen.moveRemaining(unit)
    -- returns gen.maxMoves-unit.moveSpent

    Existing proposal completed
    -- gen.isCoastal(unitType)-->boolean
     

    Attached Files:

  3. Prof. Garfield

    Prof. Garfield Deity Supporter

    Joined:
    Mar 6, 2004
    Messages:
    2,312
    Location:
    Ontario
    I've added the function gen.inPolygon(tile,tableOfCoordinates) to the General Library. This allows you to define a region by selecting tiles to be the corners of the polygon. You have to check if the tile is on the appropriate map yourself.

    This should make it much easier to define arbitrary regions. The order of the corners matter here, so beware.

    I've also added PolygonScript.lua to help the scenario creator define regions.

    I've also made a GitHub repository for the General Library (link in first post), so I'll update that rather than post files here. I'll still accept submissions in this thread, but I'll also take them by PM now, if anyone would prefer to do it that way (perhaps if they just made a small change). I'll probably only post if I add a big feature or do a lot of work at once.
     
  4. Prof. Garfield

    Prof. Garfield Deity Supporter

    Joined:
    Mar 6, 2004
    Messages:
    2,312
    Location:
    Ontario
    I've updated the Github repository.

    The general library now includes functions to check if a city can support more units, to re-home units supported by a city when captured (I did these in my Lua lessons), and functions to improve the automatic selection mechanism for the game (e.g. all units on a map must be told to wait before units on another map are activated).
     

Share This Page