[TOT] The Test Of Time Patch Project

I'm working with JPetroski on a little project designed to be a testbed for Lua events & cooperative projects. We discussed the possibility of dividing the labour according to skillsets. I'm not much of a coder, though I would like to improve my skills. I'm very keen to really get into the possibilities of Lua. Sometimes it takes one person to jump in the water to encourage others to follow.
 
Yes I think between @Prof. Garfield and @Grishnach 's help, I'm firmly hooked on lua. I must say, @TheNamelessOne , that key stroke trigger was a brilliant idea... In Caesar, it will allow:

1. Mobile artillery that can receive munitions anywhere on the map
2. Fixed artillery that can receive munitions only on a certain terrain square (prepared site)
3. Any unit to act like an engineer in that they can change terrain on a key press which means it's easier/cleaner to disable city building or RR building or whatever building you don't want in the scenario
4. A zone of recruitment (if a unit is in a box and hits the key, another unit shows up and money is deducted)
5. A way of influencing the player to move certain units certain places (like if Caesar is in Italy in the winter as he typically was, and he hits a key, the Romans get money, or if a legion is at a base during the winter, and hits the key, the Romans get money but the legion loses all its movement points).

He's also trying to see if he can get a supply chain working to check and ensure that a sequence of cities are owned to allow munitions to show up down the line.

It seems like it is only limited by the imagination and I'm hoping that Grishnach's work on Caesar will allow others to take this up... There's fairly standard/complicated events in Caesar that he is working on translating now so hopefully it will be a help to other designers.

I know that you're busy, TNO, but you did mention that you have secretly implemented other lua features -- I'd really love to at least hear the gist of them so the creativity can start flowing and we can see if we can use that in this scenario and give others a sample to build from, as I am hoping to release this fairly soon (really all that is left before balance/playtest is the events and now adding a few interesting units that lua creates the need/desire for).

Thanks for all your hard work again!!!
 
Also... Not sure if you're up for suggestions for lua features, but a way to better manipulate diplomacy than the standard "don't let any civs ever talk and as soon as some trigger happens they're at war for the rest of the scenario" would be a most welcome addition for designers and espeically useful for @McMonkey and my project...

Something where we could force an alliance or force a peace if certain triggers were met.

Thank you.
 
Also... Not sure if you're up for suggestions for lua features, but a way to better manipulate diplomacy than the standard "don't let any civs ever talk and as soon as some trigger happens they're at war for the rest of the scenario" would be a most welcome addition for designers and espeically useful for @McMonkey and my project...

Something where we could force an alliance or force a peace if certain triggers were met.

Thank you.

Thanks for the praise *blushes a bit* :)

Just to jump in quickly- TNO's current lua implementation allows deep low level manipulation of treaties - essentially everything one could do via hex editing one can do in the code. But a human player could for example always break a lua enforced peace treaty anyway - it can be restored each turn of course. :)
 
Second, anti-tank values would be very helpful. The current knight/pikeman relation is far too limited in its applicability. Would it be possible to create a flag for units (anti-tank) that had double defense against other units that had a corresponding (tank) flag?
.

I wonder about that, what exactly determines what a HORSE is anyway that the pikeman can apply its 50% defense bonus. In the rules.file that 50% defense flag is there, but none that flags a "horse."

Is it dependent on the SLOT where the knight is and the pikeman?

If so then that means only those two slots can interact in that fashion( not withstanding the fact there are at least 4 other "horse type" units in a standard units.gif file)?
 
Also... Not sure if you're up for suggestions for lua features, but a way to better manipulate diplomacy than the standard "don't let any civs ever talk and as soon as some trigger happens they're at war for the rest of the scenario" would be a most welcome addition for designers and espeically useful for @McMonkey and my project...

Something where we could force an alliance or force a peace if certain triggers were met.

Thank you.
To build on this, a way to prevent the AI from sneak attacking each other despite a global No Negotiations Allowed mask would be wonderful. As PlutoRising currently stands, even with everyone set to begin the scenario with Peace or Alliance and all wars purged from events, the nukes will still start flying as soon as the scenario is loaded. So especially if the player leaves the sound on, the first hundred turns or so can be a huge slog.

And a question, is it possible to assign different events files to different .scn files within the same scenario/folder?
 
I wonder about that, what exactly determines what a HORSE is anyway that the pikeman can apply its 50% defense bonus. In the rules.file that 50% defense flag is there, but none that flags a "horse."

Is it dependent on the SLOT where the knight is and the pikeman?

If so then that means only those two slots can interact in that fashion( not withstanding the fact there are at least 4 other "horse type" units in a standard units.gif file)?

If my memory serves right (the pikeman flag is a bit weird) the game considers any land unit with 2 movement, 10 hitpoints and 1 firepower a horse (in vanilla, that'd be Horsemen, Chariots, Elephants, Knights, and Crusaders but not Dragoons, Cavalry, Engineers or the Howitzer.)

Apparently not even the MPS design team fully understood it, considering the units in Mars Now that have the pikeman flag are all clearly supposed to be counters to light vehicles or the rovers, of which only the Sojourner Rover matches all three criteria.
 
If my memory serves right (the pikeman flag is a bit weird) the game considers any land unit with 2 movement, 10 hitpoints and 1 firepower a horse (in vanilla, that'd be Horsemen, Chariots, Elephants, Knights, and Crusaders but not Dragoons, Cavalry, Engineers or the Howitzer.)

Apparently not even the MPS design team fully understood it, considering the units in Mars Now that have the pikeman flag are all clearly supposed to be counters to light vehicles or the rovers, of which only the Sojourner Rover matches all three criteria.

thanks usful information, works good for the default setup, but try and add/change units/stats...
 
@TheNamelessOne, terrific work! Your efforts have opened up so many opportunities for advanced scenarios. I've been experimenting quite a bit recently with TOTPP enhancements to rules.txt, as well as Lua scripts, testing out various ideas to see what's feasible.

I've noticed a couple things related to terrain that I'm hoping you can work into an upcoming release of TOTPP. You've already made huge improvements in this area (special thanks for allowing fertility to be set in a way the AI understands!) but the two following items seem like they may have slipped through the cracks. I think including them would really help fill out terrain support nicely.

1. Each terrain slot has a hardcoded value for how many turns it takes for a settler to build a road: For, Hil, Gla, Swa, and Jun are 4; Mou is 6; and all other land terrains -- including all of the additional Bbb through Fff slots -- are 2. Could you create a way for this to be customizable for all terrains within rules.txt?

2. The first three terrain slots (Drt, Pln, and Grs) are the only ones for which a road will add the first trade arrow (if the tile otherwise gives none). On all other terrain types, a road will add an additional arrow if the tile already produces at least one, but not the first arrow. Could this also be configurable for every terrain in rules.txt?

Then I've also run into a number of roadblocks in Lua scripts:

3. I see that I can call "city.shields" to both read and write the number of shields that have accumulated in a city's shield box, but similar support for a city's food box appears to be missing. Could support for reading and writing the number of bundles in the food box be added?

4. It seems that tile improvements are stored in a bitmask that is readable, but not writeable. So a Lua script can change a tile's terrain type, but not add or remove improvements on it (irrigation, roads, fortress, etc.). Could support for that be added? Also, while I can probably figure out how to interpret and set the bitmask appropriately, it doesn't seem like a very friendly format... I expect I'll end up writing separate functions to deal with it. Any chance you could also make the management of tile improvements a bit more user-friendly?

5. I played around a little bit with trying to analyze relationships between civilizations (tribes) -- my initial goal was to find out whether a tribe was at war with at least one other tribe in the game. But my calls to tribe.attitude, tribe.reputation, or tribe.treaties were returning something like "userdata: 04F1A010" or "attempt to call a userdata value" rather than the type of information I was looking for. Could you add support for this type of check into Lua, or if I'm doing something wrong, give me a code snippet that will work?

6. This last one is a "nice-to-have" and lower priority to me than the other things I've listed, but I had one idea that would require a new trigger for "onCityFounded" -- this would nicely parallel the existing "onCityDestroyed". I know that it's technically possible for me to find new cities at the end of every turn, if I keep my own copy of the city list in memory, and then run a check every turn to see if any cities exist in the game that aren't in my list. But that's pretty cumbersome, and also only lets me take action at the end of the turn on which a city is founded, rather than immediately.

Of course, none of these requests should in any way diminish the fantastic work you've already done! I'm sure you already have a long list of ideas for improvements, but I'm hoping that these are reasonable and can be worked into your list of priorities. Thanks again for your great work! Cheers!
 
I know that you're busy, TNO, but you did mention that you have secretly implemented other lua features -- I'd really love to at least hear the gist of them so the creativity can start flowing and we can see if we can use that in this scenario and give others a sample to build from, as I am hoping to release this fairly soon (really all that is left before balance/playtest is the events and now adding a few interesting units that lua creates the need/desire for).

Some things I think you will find a use for: I have added a lua function to load alternative terrain files for a map, allowing for in-game modification of graphics. It works really well, just call
Code:
civ.ui.loadTerrain(0, "terrain1-alt.bmp", "terrain2-alt.bmp")
and the map changes instantly. No more renaming graphic files and reloading. I've also implemented a trigger that fires when a unit is activated, either by the user, or by the game itself (including AI units). But these are things that aren't active in the current release yet. I will do a new release soon, it has already accumulated a decent amount of new features.

1. Each terrain slot has a hardcoded value for how many turns it takes for a settler to build a road: For, Hil, Gla, Swa, and Jun are 4; Mou is 6; and all other land terrains -- including all of the additional Bbb through Fff slots -- are 2. Could you create a way for this to be customizable for all terrains within rules.txt?

This isn't hard-coded, it depends on the terrain's move cost. 2 * movecost for roads, 4 * movecost for railroads.

2. The first three terrain slots (Drt, Pln, and Grs) are the only ones for which a road will add the first trade arrow (if the tile otherwise gives none). On all other terrain types, a road will add an additional arrow if the tile already produces at least one, but not the first arrow. Could this also be configurable for every terrain in rules.txt?

Yes this is correct, an arrow is added if terrain type <= 2 or if the yield is already > 0. This is a reasonable request, I might add a flag to make this configurable.

3. I see that I can call "city.shields" to both read and write the number of shields that have accumulated in a city's shield box, but similar support for a city's food box appears to be missing. Could support for reading and writing the number of bundles in the food box be added?

Done, implemented as city.food in the next release.

4. It seems that tile improvements are stored in a bitmask that is readable, but not writeable. So a Lua script can change a tile's terrain type, but not add or remove improvements on it (irrigation, roads, fortress, etc.). Could support for that be added? Also, while I can probably figure out how to interpret and set the bitmask appropriately, it doesn't seem like a very friendly format... I expect I'll end up writing separate functions to deal with it. Any chance you could also make the management of tile improvements a bit more user-friendly?

I've made the property settable. As for the format, I'm keeping this since it corresponds exactly to the savegame format, convenience functions can be written in Lua itself.

5. I played around a little bit with trying to analyze relationships between civilizations (tribes) -- my initial goal was to find out whether a tribe was at war with at least one other tribe in the game. But my calls to tribe.attitude, tribe.reputation, or tribe.treaties were returning something like "userdata: 04F1A010" or "attempt to call a userdata value" rather than the type of information I was looking for. Could you add support for this type of check into Lua, or if I'm doing something wrong, give me a code snippet that will work?

All three are tables, and should be indexed by a tribe. E.g.:
Code:
t1 = civ.getTribe(1)
t2 = civ.getTribe(2)
t1.attitude[t2]
t2.treaties[t1]

For the meaning of the treaties bitmask, please consult the saved game format again. These properties can also be set btw.

6. This last one is a "nice-to-have" and lower priority to me than the other things I've listed, but I had one idea that would require a new trigger for "onCityFounded" [...]

It's added in the next release.
 
Some things I think you will find a use for: I have added a lua function to load alternative terrain files for a map, allowing for in-game modification of graphics. It works really well, just call
Code:
civ.ui.loadTerrain(0, "terrain1-alt.bmp", "terrain2-alt.bmp")
and the map changes instantly. No more renaming graphic files and reloading. I've also implemented a trigger that fires when a unit is activated, either by the user, or by the game itself (including AI units). But these are things that aren't active in the current release yet. I will do a new release soon, it has already accumulated a decent amount of new features.

This sounds very promising - is it possible to change the rules file on the fly too? Typically the winter terrain comes with penalties to movement, and occasionally attack.

If not, I suppose perhaps the activation trigger you have above could accomplish the movement trigger (on activation, expend half the MPs). I'm not sure how to reduce attack (for example in Nemo's Red Front, aircraft have an attack of '0' during the winter).
 
Yes, this will be possible -- however, you will need to be careful to apply these modifications again in onLoad, otherwise the game will just use the rules from the text file. The same goes for the terrain graphics btw.
 
Hello!

That sounds just awesome! Looking very much forward to the next implementation! :)
Additional triggers are just perfect, I think these will allow extremely flexible implementations.

In terms of lua interface: Do you think it will in the end be possible in principle to map all the bytes of the save game structure, especially the city part, to lua functions? Like getting the number of specialists in a city, or the number of unhappy citizens (where I'm wondering if could this also be set or if it is reset dynamically?)
There are some aspects in a tiny, dummy "Rise and fall" testbed I started to set up some months ago which did not go very far because certain elements (esp in the cities part) could not be accessed ...

And about the global/rules part - is there a function to access the road multiplier currently in place? JPetroski and I could need that for the developing Gallic Wars scenario

And one final, more general topic, in terms of interfaces and graphics: Do you think it would be possible to modify the way graphics are read such that instead of having the generic graphics.dll one could place e.g. bitmaps in the scenario folder to replace the leader graphics? Or e.g. the graphics appearing on conquering a city etc?
Might it be possible to enhance the civ.ui.text function to a textAndImage function - I'm thinking about something like the OnConquest window or more specifically about something like the fantastic 1-frame videos in Catfish's War of the Ring scenario, without the effort to create videos each time ...
And would a "show choice" pop up be possible in principle? Like the "override the senate" question for example, one could specifiy 2 to X test lines and there could be a call back to a function processing the ID of the pressed choice or so ...
 
And a question, is it possible to assign different events files to different .scn files within the same scenario/folder?

I gave this more thought, and came up with a possible implemetation.

For example, earlier someone requested the ability to load both events.txt and events.lua. To build on this, one could have a single events.txt to form a base set of events using macros that we know work well, loaded for all .scn files that don't have its own assigned events.txt/.lua file. When the author finally does write more event scripts to fit a particular file, they could set a flag or parameter in @RULES2 telling the game whether or not to include the base events.txt when loading .scn files with its own events file assigned to it, or whether or not to override the base events.txt for a particular .scn file.

One way to assign event files to .scn files might be via file naming, such as "events-<name of 1st .scn file>.lua", "events-<name of 2nd .scn file>.txt", and so forth.

Personally, I think it might help reduce the intimidation factor for those new to LUA, as it may give some new authors more room to maneuver when learning to include LUA events, like via trial and error methods. :)
 
Thanks very much, TNO, great to hear that a number of my requests are scheduled for the next release! :clap: Looking forward to it!

This [turns to build a road] isn't hard-coded, it depends on the terrain's move cost. 2 * movecost for roads, 4 * movecost for railroads.
Well, look at that... it's hard to believe I never noticed that relationship before!
... is there a function to access the road multiplier currently in place? JPetroski and I could need that for the developing Gallic Wars scenario
For maximum flexibility, my first preference is actually still that these values could be customized for each terrain type in rules.txt, just like you can specify the number of turns to build irrigation or mining. If that's not feasible, and keeping the relationship to movement cost is necessary, then being able to change the global multipliers would be next best.

Essentially road-building (and railroad-building) feels like it's too easy, especially for Engineer-type units that work twice as quickly, and I'm looking for ways to slow this down and make it more of a strategic investment.

As for the format [tile improvements stored in a bitmask], I'm keeping this since it corresponds exactly to the savegame format, convenience functions can be written in Lua itself.
This can work... thanks for the reference link. (And thank you @Catfish for gathering and posting this info!) After studying that and doing some research into Lua bitwise operators, I think I worked out convenience functions for checking the existence of various tile improvements. Looking forward to write capability in the next release!

All three are tables, and should be indexed by a tribe... For the meaning of the treaties bitmask, please consult the saved game format again. These properties can also be set btw.
Ah, they're tables! I was treating them like functions and trying to call "t1.attitude(2)" or "t1.attitude(t2)". Your code worked fine and I'm all set with attitude and reputation. I'm still struggling a bit with the treaties bitmask though... for one thing, the savegame format documentation seems to be incomplete for this section, with some unknown values. I'll experiment with this some more, and try to put together some better examples and followup questions.

Do you think it will in the end be possible in principle to map all the bytes of the save game structure, especially the city part, to lua functions? Like getting the number of specialists in a city, or the number of unhappy citizens (where I'm wondering if could this also be set or if it is reset dynamically?)
Number of each type of citizen in a city, including the specialist types, would be really cool. I'm not sure about setting it... at least for the AI civs, wouldn't the game just recalculate and set it back to what it was? Even if it was read-only, though, I still think it's worthwhile to be able to access.

And would a "show choice" pop up be possible in principle? Like the "override the senate" question for example, one could specifiy 2 to X test lines and there could be a call back to a function processing the ID of the pressed choice or so ...
I second this! I've pictured it as an advanced version of "civ.ui.text" that allows you to define multiple options, forces the user to select one in order to continue (i.e., they can't close the popup or switch focus out of it to keep playing), and returns their selection back to the point in the Lua code where it was triggered.
 
If anyone wants to see the implementation of range attacks @Grishnach configured (naturally thanks to @TheNamelessOne having enabled the possibility in the first place), please check out the short youtube video I've added to the Caesar's Gallic Wars thread:

https://forums.civfanatics.com/threads/caesars-gallic-wars.628330/page-3#post-15061820

:thumbsup:
And thanks for the praise! :-D
Though I respectfully defer it to @TheNamelessOne - the real issue in my opinion is setting everything up so stuff like that can work!

Number of each type of citizen in a city, including the specialist types, would be really cool. I'm not sure about setting it... at least for the AI civs, wouldn't the game just recalculate and set it back to what it was? Even if it was read-only, though, I still think it's worthwhile to be able to access.

Oh yes, it will probably only be useful for the player and there will definitely be some issues with the automatic recalculation. Though perhaps the new triggers might even allow a way around that ...

But reading would definitely help as well, and could create a nice additional flavor to the whole specialist and/or unhappy citizens mechanic...

I second this! I've pictured it as an advanced version of "civ.ui.text" that allows you to define multiple options, forces the user to select one in order to continue (i.e., they can't close the popup or switch focus out of it to keep playing), and returns their selection back to the point in the Lua code where it was triggered.

Exactly - one could couple that to manipulation of treaties for example, where you declare war to one or the other of two warring civs or create a marriage alliance or what not.

And if you could then also switch the leader graphics you could have assination events or abdications or stuff like that. Or whatever comes to mind. :)
 
I'm interested in learning more about the "on activation" trigger for units.

Earlier, I'd asked if it were possible for cities to only build air units, or only ground units, as some can currently only build naval units.

I'm hoping "on activation" can be a useful workaround. But I need it to be able to do this: On activation, check for unit type, then check for if it is on a certain terrain type, and if both are true, delete unit (possibly with a return of gold equivalent to the units' cost).

For example, I'd like to rework "Over the Reich" to get rid of some major headaches found in playtesting (namely, it isn't fun to have to play with a notepad next to you to keep track of everything you discover while you individually control the army, then the industry, then the airforce). It would be much better if I could have simply a "Germany" civ rather than "Luftwaffe, Germany, and German Industry." But, I don't want certain cities building certain units. So I'm thinking, if the game will automatically delete a certain type of unit that happens to be on a certain type of square, then the player can build an Fw190 in Berlin all they want, but they'll never be able to use it (because Berlin will be built on a "city" square which will trigger the deletion as soon as it is selected). The player would instead have to build the unit in an airfield city, like III/JG2.

This would of course require the player to actually read the readme, but I think it expands possibilities for scenarios quite nicely! (No more need for house rules in Second Front Redux, for example).

Would this work in principle? I wonder if the game would crash?

Edit-the more I think about it, this would solve a HOST of problems with that scenario...
 
Last edited:
Isn't there an "on production" event trigger? You could probably use that to check if a unit was produced in the correct location and delete it otherwise.
 
Top Bottom