[TOTPP] Lua Scenario Template Feature Requests

Prof. Garfield

Deity
Supporter
Joined
Mar 6, 2004
Messages
4,365
Location
Ontario
If anyone has any ideas for features that you would like included in the Lua Scenario Template, please ask for them here.

My reason for asking now is that I'd like to work on the documentation/how to program guide for the template, and I'd like the the template to be "finished" (for lack of a better word). When I've tried to document before, the template has changed rendering some work obsolete, so I just stopped. I don't need the template to be "completed" in the sense that I'll only ever make bugfixes, but I want it to be in a state where I can be confident that large portions of documentation won't be invalidated by future changes.

To this end, I would like to make a list of features to build into the template in the near future. If there is some feature (or features) that you want in the template, please let me know. If you're not sure if a feature is in the template, ask anyway. For those of you using the template already, if you think something is confusing or poorly organised, please say so (this is likely to be especially helpful).

To Do Before Documenting

Individual "cosmic" parameters
For example, different units can have different road/rail bonuses. (changeRules module makes this more feasible than before.)
Completed.

Land/Air Cargo
Straightforward system for Land/Air units to carry cargo. Will use onEnterTile execution point.
Completed.

Diplomacy Module Re-Work
I will want to look over the diplomacy module, especially the code for static treaties, since it seems to cause some confusion.

City Famine Detection


Already Exists in Template


Useful to do, Minimal Foreseen Documentation Impact


Help Key Module Rebuild
Update the help key module with better formatting, information about tile production, and visible enemy units on a square.

Multiple Use Airlift/Transporter
Add a simple setting (and the code behind it) to allow airports/transporters to be used more than once in a turn, or to forbid their use entirely.



Not Sure If I Want to Implement
(Feel free to make the case in the comments.)

Forbid Tile Entry
This would require creating a new execution point, and undoing any attempted moves into a tile before any other event happens (especially onEnterTile). It is unclear how the AI would handle such code either. I'm inclined to wait for TNO's return and ask for the game to be changed to forbid entry in the first place instead of implementing this.



Notes for Documentation Work

Working examples of functions/code are helpful.
 
Last edited:
Maybe you could include the function that a certain 'leader' unit can give an attack or defence bonus for other units who shares a square together.

The range attack function should also be included if possible. Until know I didn't use it but I will be sure to use it in a future 30YW scenario.

Would it be possible to include a working example for each function too? For me the main problem is that I'm not familiar with programming so it's for me difficult to understand how to use the functions without an example.
 
Maybe you could include the function that a certain 'leader' unit can give an attack or defence bonus for other units who shares a square together.

I just added leader bonuses to the template. leaderBonusSettings.lua has a couple of examples that I tested with.

The range attack function should also be included if possible. Until know I didn't use it but I will be sure to use it in a future 30YW scenario.
munitions.lua/munitionsSettings.lua is already in the template. I can provide a few examples (here, here, or by PM) if you have specific questions.

Would it be possible to include a working example for each function too? For me the main problem is that I'm not familiar with programming so it's for me difficult to understand how to use the functions without an example.
I'll keep that in mind when documenting. Of course, if you ever see a function that looks like it could be useful, but don't know how to use it, feel free to ask.
 
If there is some feature (or features) that you want in the template, please let me know.

Looking at the Function Reference and also the template, I don't believe there is something for this but if I missed it, let me know...

I think we could use some sort of espionage module. For my purposes, it wouldn't really need to be more than having an "initiation" phase of some sort (and I'm not sure the functions allow this?), a "choice" phase, and a "consequence" phase. I'd just like more control over what could be done, especially with Cold War.

The "choice" phase would just be a menu (when isHuman is true, anyway) which I've used plenty, and the consequence is also something I could build out, but I really don't know how to construct the initiation phase at all. It might be a good (or at least, another) reason to work on that forbid tile entry since you'd think that would require knowing where a unit is heading (such as a spy).

Would it be possible to include a working example for each function too? For me the main problem is that I'm not familiar with programming so it's for me difficult to understand how to use the functions without an example.

For me this was always 100% an issue too and a big part of the reason for building out Boudicca. I think most designers would agree we are able to replicate and tweak stuff (I mean that's all we do) but sometimes following instructions to create isn't the way our brains work, at least not without some major adjustment.
 
I think we could use some sort of espionage module. For my purposes, it wouldn't really need to be more than having an "initiation" phase of some sort (and I'm not sure the functions allow this?), a "choice" phase, and a "consequence" phase. I'd just like more control over what could be done, especially with Cold War.

The "choice" phase would just be a menu (when isHuman is true, anyway) which I've used plenty, and the consequence is also something I could build out, but I really don't know how to construct the initiation phase at all. It might be a good (or at least, another) reason to work on that forbid tile entry since you'd think that would require knowing where a unit is heading (such as a spy).

Do you mean to create a substitute for the diplomat/spy functions of "Investigate City", "Steal Technology", "Incite Revolt", etc? That is, you want to be able to move a diplomat/spy 'into' a city, and get some sort of menu?

I don't know how to achieve that. I just tested, and the onKeyPress event happens after the game initiates the spy functions menu. So, while I could check each square if a diplomat/spy has a goto order for an adjacent city, the closest thing I can think of at the moment is asking the player if they want to do spy functions whenever a diplomat is adjacent to a foreign city. This might make sense in some circumstances, but I'd argue that sort of thing should be built on a case by case basis in individual scenarios.
 
Do you mean to create a substitute for the diplomat/spy functions of "Investigate City", "Steal Technology", "Incite Revolt", etc? That is, you want to be able to move a diplomat/spy 'into' a city, and get some sort of menu?

I suppose what would be truly useful is a function that basically asks:

If a certain type of unit is within a certain number of tiles of a city (or certain type of unit) and certain parameters are set (that the designer could specify with simple "AND" statements) then have as sequence either happen automatically (in the case of the AI) or allow a key press to initiate a menu (in the case of a human player).

It doesn't necessarily have to be with espionage, but if you can write a function that simply checks how close a unit type is to something else then a few things are achievable:

1. launching air strikes from carriers by the AI
2. launching first strikes from nuclear submarines by the AI
3. having AA guns fire missiles at targets
4. Enhanced Espionage
5. Basically anything else that someone can come up with

Basically I'm just looking for the if trigger or function that will let me tell how close something is to something else that I specify - perhaps onActivate would work for this for the AI and keypress for the human?
 
For me this was always 100% an issue too and a big part of the reason for building out Boudicca. I think most designers would agree we are able to replicate and tweak stuff (I mean that's all we do) but sometimes following instructions to create isn't the way our brains work, at least not without some major adjustment.

Currently I'm understanding more and more the basics of lua which allows me to replicate and changing very easy codes from other scenarios. I too used codes from your scenarios. For example the code for changing leader names I've copied from your Cold War scenario. Also the codes for changing the cities ownership are from your Cold War scenario.

It's the possibilities of lua, which encourages me trying to understand more of this programming language. Without lua, the Reformation scenario wouldn't be able in it's current version.
 
suppose what would be truly useful is a function that basically asks:

If a certain type of unit is within a certain number of tiles of a city (or certain type of unit) and certain parameters are set (that the designer could specify with simple "AND" statements) then have as sequence either happen automatically (in the case of the AI) or allow a key press to initiate a menu (in the case of a human player).

It doesn't necessarily have to be with espionage, but if you can write a function that simply checks how close a unit type is to something else then a few things are achievable:

1. launching air strikes from carriers by the AI
2. launching first strikes from nuclear submarines by the AI
3. having AA guns fire missiles at targets
4. Enhanced Espionage
5. Basically anything else that someone can come up with

Basically I'm just looking for the if trigger or function that will let me tell how close something is to something else that I specify - perhaps onActivate would work for this for the AI and keypress for the human?
I'm incline to think that "is activeUnit near X" events are best programmed on a case by case basis. To implement it in a generic way would require checking every 'nearby' tile to a unit every time it activates, and this could get expensive quickly. If some event has a radius of 10 squares (not too unreasonable for air strikes/nukes), you're now checking some 441 tiles every time a unit moves, even an AI unit. If a designer has a few of these checks, it could conceivably cause some lag.

Another aspect is that the specific details of a particular use case might reduce the burden considerably. If you're checking for 'nearby' cities, you don't have to check every nearby tile, you could just go through the city list and check distances. You're probably not going to have more than 400 cities, and, if you expand the range to 15 tiles, you're not going to have to check 961 tiles. At the very least, if you have to make multiple checks, the checks can be be done at the same time, rather than one at a time.

I do have tools in the General Library to make it easy to get nearby tiles:
Code:
--#gen.getAdjacentTiles(tile)-->tableOfTiles
--#gen.cityRadiusTiles(cityOrTileOrCoordTable) --> table
--#gen.getTilesInRadius(centre,radius,minRadius=0,maps=nil) --> table
--#gen.nearbyUnits(center,radius,maps={0,1,2,3}) --> iterator providing units

As always, if you have a specific task, I can help you with that.
 
Hi! I need to ask what is the lastest version of Lua? I can't play Hinge of Fate and the version of Lua it says to download is deep in the thread, and I'd like to make sure I had the most up to date version, and if there's a quick way to find it, and how to look for the next update if it's there.

As you know, am a failed mod designer....for the moment, I wanted to get building icons and was distracted by the sexy of AOE2's campaigns for the last 15 months or so. So I'm out of the loop on the last update and I want to make sure I have the most recent templates.

With that said, I'll tell you what I want and why see what you can do, and if it's worth your time:

1. The ability to add the spy capacity to units the same way you can attach engineer abilities to settler units via TOT's original structure. Like in the American Kingdoms mod most of th4e civs use a very generic, light skinned spy unit that could be plausible as a couple of different ethnicities but the black supremacist faction around New Orleans only has access to a diplomat unit. This coding would allow multiple spies designed for various things. Regular spies, special spies, commando units, suddenly you could have all of them. Conversely, adding the sabotage option to diplomats would solve most of my issues.
2, The same for the partisan effect to units at will. That way you can have both guerrilla resistors/refugees like Colonization 4 And you could have special duty artillery fire units (think catapult rounds and/or siege towers from Ceasar's Gaulic Wars) that have relatively low attack but get the X8 bonus when attacking units with a movement of zero.
3. If possible, a thing that will make all cities of on a certain map fix to alternate sets. This would be most useful for Scenarios that involve multiple realms like the vanilla Sci Fi scenario where three of those realms (near Fausta obit, the dirt plant and the remains of the gas giant infrastructure) can basically all look the same because they have to be carefully domed in colonies and then on the main planet, they can all have their own flavor.
4. Units that have the k generation effect that usually generate arrows or artillery will change what they generate based on terrain. I was thinking you could do the effect of Reich vulnerable infrastructure via deployable units. If you had say a fishing unit, if it were on an ocean tile with special resources (vanilla fish or whales), it would generate say 2 units of a "food harvest", instead of one.
5. An effect that would delete all food above the granary threshold for the player alone
6. an effect where the destroying the granary wipes all the food out
7. Every time a city suffers a famine and decreases in size, half of the units in the city are deleted at random, and if there's only one left, that unit is deleted 5 6 and 7 means it is possible to starve a garrison into surrender and an AI with enough cheap units to swarm can force a player city into surrender. So it's possible to do a siege without assault.
8. If possible, can you make an effect to remove the only use once per turn effect for airports/transporters? Or make the number variable?
9. And an effect to delete a wonder from a city when it's destroyed/disbanded so someone can rebuild it somewhere else.
 
Hi! I need to ask what is the lastest version of Lua? I can't play Hinge of Fate and the version of Lua it says to download is deep in the thread, and I'd like to make sure I had the most up to date version, and if there's a quick way to find it, and how to look for the next update if it's there.

TOTPP v0.18.4 is here:


(TNO updates the first post of the thread with a link, as well as his signature).

I'm ill at the moment, so explanations on how to do these things will have to come later.

1. The ability to add the spy capacity to units the same way you can attach engineer abilities to settler units via TOT's original structure. Like in the American Kingdoms mod most of th4e civs use a very generic, light skinned spy unit that could be plausible as a couple of different ethnicities but the black supremacist faction around New Orleans only has access to a diplomat unit. This coding would allow multiple spies designed for various things. Regular spies, special spies, commando units, suddenly you could have all of them. Conversely, adding the sabotage option to diplomats would solve most of my issues.
This can't be done with Lua. I'm not as familiar with the ins and outs of test of time rules, so I can't say for sure it is impossible with that.
2, The same for the partisan effect to units at will. That way you can have both guerrilla resistors/refugees like Colonization 4 And you could have special duty artillery fire units (think catapult rounds and/or siege towers from Ceasar's Gaulic Wars) that have relatively low attack but get the X8 bonus when attacking units with a movement of zero.
This can be done, and without too much difficulty.

3. If possible, a thing that will make all cities of on a certain map fix to alternate sets. This would be most useful for Scenarios that involve multiple realms like the vanilla Sci Fi scenario where three of those realms (near Fausta obit, the dirt plant and the remains of the gas giant infrastructure) can basically all look the same because they have to be carefully domed in colonies and then on the main planet, they can all have their own flavor.
I don't know the answer to this one.
4. Units that have the k generation effect that usually generate arrows or artillery will change what they generate based on terrain. I was thinking you could do the effect of Reich vulnerable infrastructure via deployable units. If you had say a fishing unit, if it were on an ocean tile with special resources (vanilla fish or whales), it would generate say 2 units of a "food harvest", instead of one.
You can definitely change what kind of unit is generated by a k press based on terrain, though I don't remember if the munitions module in the template will do this for you, so you might have to write the entire event. Adding extra resources to be gathered from a tile is a bit trickier. The +1 food harvest won't be shown on the tile, but you can modify the total harvest of a city if that square is being worked.

5. An effect that would delete all food above the granary threshold for the player alone
This is very easy to do. You can change city.food whenever you like.

6. an effect where the destroying the granary wipes all the food out
If you have a way of detecting when the granary is destroyed, then this is easy.

7. Every time a city suffers a famine and decreases in size, half of the units in the city are deleted at random, and if there's only one left, that unit is deleted 5 6 and 7 means it is possible to starve a garrison into surrender and an AI with enough cheap units to swarm can force a player city into surrender. So it's possible to do a siege without assault.
I don't know how easy it will be to detect when a city suffers a famine, but I'm sure something could be worked out. Once you detect the famine, destroying units at random is not very difficult.

8. If possible, can you make an effect to remove the only use once per turn effect for airports/transporters? Or make the number variable?
Lua can turn 'off' the bit that tells the game that a city has performed an airlift/transport for the current turn. Having a limited number is a bit trickier, but the cityData module should make it fairly easy to keep a count.
9. And an effect to delete a wonder from a city when it's destroyed/disbanded so someone can rebuild it somewhere else.
You can remove a wonder from being destroyed and make it buildable again simply by setting the city field to nil, i.e.
Code:
object.wSomeWonder.city = nil
 
I didn't realise that this is the feature request thread, and not the general template thread.

7. Detecting a famine is a reasonable thing to want to do. I'll make sure there is something suitable.
8. Allowing multiple airlifts (or forbidding them entirely) is pretty general purpose, and is suitable for simpleSettings.lua.
 
2, The same for the partisan effect to units at will. That way you can have both guerrilla resistors/refugees like Colonization 4 And you could have special duty artillery fire units (think catapult rounds and/or siege towers from Ceasar's Gaulic Wars) that have relatively low attack but get the X8 bonus when attacking units with a movement of zero.
There are a number of way to achieve this sort of thing. Here is one way to give a 4x bonus for "siege engines" attacking "fortifications"

In setTraits.lua, assign the "fortification" and "siegeEngine" traits to appropriate unit types.
Code:
traits.assign({object.uStockade, object.uFortress},"fortification")
traits.assign({object.uCatapult, object.uCannon},"siegeEngine")

In registerCombatModifiers.lua, register a combat modification rule giving an attack multiplier of 4 when "siegeEngine" units attack "fortification" units.

Code:
combatMod.registerCombatModificationRule({
    attacker = "siegeEngine",
    defender = "fortification",
    aCustomMult = 4,
})
4. Units that have the k generation effect that usually generate arrows or artillery will change what they generate based on terrain. I was thinking you could do the effect of Reich vulnerable infrastructure via deployable units. If you had say a fishing unit, if it were on an ocean tile with special resources (vanilla fish or whales), it would generate say 2 units of a "food harvest", instead of one.
I've checked munitionsSettings.lua, and you can change the "munition" generated based on whatever you like. There is an option
Code:
-- generateUnitFunction = nil or function(unit)-->table of unit
--      This function creates the unit or units to be generated
--      and returns a table containing those units
--      Ignore any specifications prefixed with * if this is used
--      nil means use other specifications
This would be a simple function for a bomber that would attack with torpedoes if it is over the sea, and bombs if it over land:
Code:
local function bomberMunition(bomber)
    if bomber.location.type == 10 then
        return {object.uTorpedo}
    else
        return {object.uBomb}
    end
end
5. An effect that would delete all food above the granary threshold for the player alone
Code:
discreteEvents.onCityProcessed(function(city)
    if city.owner.isHuman then
        local foodBoxSize = (city.size+1)*civ.cosmic.foodRows
        city.food = math.min(city.food, foodBoxSize//2)
    end
end)
 
I'm coming back with unit graphic change ingame with no user action needed :

1. A limit is the unitType name which can't be written.

2. Is it still possible to alter its graphics using the sprites system (which shall be regulary updated ingame) ?
The idea would be to change the graphic files used by the .spr file,
then altering unitType values,
and end by activating each altered unit to raz their sprite ?
 
2. Is it still possible to alter its graphics using the sprites system (which shall be regulary updated ingame) ?
The idea would be to change the graphic files used by the .spr file,
then altering unitType values,
and end by activating each altered unit to raz their sprite ?
A similar idea of overwriting files has been proposed for sound effects (e.g. changing the unit movement sound). I really don't like the idea of normalising scenarios overwriting files, since a mistake (or malicious actor -- though I consider it to be unlikely) could potentially do some damage.

When I write scripts that write files, I prefix them with an integer derived from the date, rather than overwriting existing files. These scripts are also not meant to be run by the scenario user, just the designer. The only exception (which made me feel a bit uncomfortable) was the custom music patch, which I wrote in such a way that the player could download it from my repository, rather than passing a version around with each scenario, and the Template would work fine if there was no custom music patch. Fortunately, with TOTPP 18, I was able to re-write the patch so that overwriting files is not necessary.

By all means, try it out. I'd be interested to see an example script. I don't know anything about sprites, so I can't do much without doing some research. I can't see myself adding something like this to the template. With 189 unit types, I don't see recycling unit types as valuable enough to override files. Especially since there is always the batch file method, which is much easier to verify that it is doing what is advertised.
 
Good stuff

Hey thanks for clearing all that up! I don't know if I did a bad in well you said

I didn't realize this was feature request thread, and not the general template thread.
I don't understand the difference but if you explain it, I will do my best to respect it once I understand it. You've always been solid by me and I want to return the favor.
 
Top Bottom