[TOT] [TOTPP] Legacy Event Engine Development Thread

Prof. Garfield

Deity
Supporter
Joined
Mar 6, 2004
Messages
4,365
Location
Ontario
The purpose of the Legacy Event Engine is to allow Test of Time events written in the original "macro language" to be used in scenarios that take advantage of the Lua Events System made available with the Test of Time Patch Project.

When complete, this will allow older scenarios to be updated with Lua exclusive events without having to re-write all the existing events. This is also intended to allow scenario creators familiar with the old macro system easier access to the new Lua features, since they can write many events in the old macro system and will only have to use Lua when experimenting with new features.

To further facilitate the integration, I plan to allow the flag system used by the legacy events to also be accessed by events written in Lua.

When the legacy event engine is complete, it will come with a sample events.lua file that will have all the necessary code to integrate with the engine already inserted.

This engine intends to mimic the behaviour of the old macro system closely, so that old scenarios can be converted without having to extensively re-test all the events.

Current state of the project:

Unit killed and city taken triggers work. Text actions also work.

The macro text to Lua table converter seems to be working fine (there might be bugs that will require testing to discover), and currently converts the legacy events at the time the game is loaded, so that changes can easily be made to the events for testing purposes.

Attached is the scenario folder I'm working in.
 

Attachments

  • MacroConverter.zip
    28.6 KB · Views: 208
Progress report:

Everything theoretically implemented. Must now run tests to debug. First round of tests will have to be done to make sure a game can be played for a while without having errors. I'll have to do that myself to fix the bugs as they come up.

Second round of tests will involve finding bugs rarely encountered, and making sure that the events actually do the "correct" thing. Having help for the second round of testing will be very welcome. Some of it will simply be playing scenarios where you are very familiar with the events that are supposed to happen, and so can report any discrepancies. Something that would also be helpful and that someone could start now if they are so inclined is to make a "testing suite" scenario. That is, a scenario with a wide variety of events that can easily be triggered for testing and comparison purposes.

Remarks about existing implementation:

Bestow improvement is probably different from the original implementation. I rank cities as population + 2*wonders+3 if capital. If the "correct" implementation is believed to be necessary, some investigation into the bestow improvement will have to be conducted. I exclude cities that already have the improvement, and the trigger does nothing if the wonder is already built.

I'm not sure if I got the negotiator action and negotiations triggers exactly correct. That will involve some testing also. I don't suppose it is too critical, since someone updating a scenario could simply re-implement the negotiation part of the events in lua.

The reputation event might also be wrong. I wasn't sure which of these to use. I suppose that can be checked during event testing.

attitude (get/set)
tribe.attitude[otherTribe] -> integer

Returns the tribe's attitude to `otherTribe`.


reputation (get/set)
tribe.reputation[otherTribe] -> integer

Returns the tribe's reputation with `otherTribe`.

Will also have to make sure that the event to change unit transport abilities is persistent.
 

Attachments

  • LegacyEventsConverter.zip
    16.4 KB · Views: 173
Not too much progress since last update. Mostly tracked down a bug with the flags. It turns out that

Code:
not a == b

Is not equivalent to

Code:
a ~= b

So, I ignored the "simple" part of the code to put print statements in all the more complicated parts...
 

Attachments

  • EventConverterUpdate.zip
    16.7 KB · Views: 137
I don't think I've done much since last time, but in case I made some corrections while testing, here are the updated files.
 

Attachments

  • LegacyEventEngine-07-20.zip
    16.8 KB · Views: 192
You've been quite busy since I was last active! This is an interesting development. Has anyone reached out with scenarios they're thinking about converting?

Once OTR wraps up maybe I can try and see if I can convert Germanicus. Perhaps someone bumbling through the process would provide useful insight to you?
 
You've been quite busy since I was last active! This is an interesting development. Has anyone reached out with scenarios they're thinking about converting?

Once OTR wraps up maybe I can try and see if I can convert Germanicus. Perhaps someone bumbling through the process would provide useful insight to you?

I didn't actually do that much work on it since June. I started playing Sealion to see if I could catch some bugs, but then stopped (I did catch bugs in the Sealion evens though). I've committed to writing the events for Techumseh's Burma once I finish up some of my other projects, though I think he's been going through his events.txt file and making corrections, so it might end up using the converter, at least in part.

I think it would be useful to convert Germanicus. If the engine is working properly, the process should be relatively painless. Much of the effort would involve tracking down bugs in the converter. If Germanicus could be enhanced by Lua features, then it would be a very good candidate, since it can be improved as well.
 
@techumseh

This should convert the Burma events to use Lua. This particular configuration will convert the events at the time the scenario is loaded, so you can save changes to the events and easily load and try again. This ability to change things can be dangerous (I think adding or removing an event would mess with all delayed events, since I store some information according to the number of the event.) Major changes to the events may require you to start the scenario over from the beginning.

Everyone:

What holds true for Burma holds true for all scenarios (at least those that have 'correct' events -- incorrect events will give you error messages that will hopefully give you an idea of how to correct the events). Here are the instructions:

0. Use the latest TOTPP version (15.1). Also, don't have any files from this module in the lua folder or the main TOT directory (I had some trouble today since I had a copy of getLegacyEvents.lua in the main TOT folder, and that was getting called with 'require' instead of the one in the scenario folder).
1. Save your scenario folder (just in case)
2. Rename the file events.txt to eventsToImport.txt
3. Extract the contents of the zip file to the scenario folder. (This will overwrite events.txt as an empty file)
4. Start a new scenario and use Lua event scripting option.
5. Play and/or test the scenario. Report errors or bugs, so I can check if the problem is in the converter.
 

Attachments

  • ConvertToLuaAtRuntime.zip
    17 KB · Views: 181
I tried this and I'm getting this issue:

Code:
D:\Test of Time\Scenario\Germanicus\getLegacyEvents.lua:369: Event file 1 at line number 28 doesn't have an open action.
stack traceback:
    [C]: in function 'error'
    D:\Test of Time\Scenario\Germanicus\getLegacyEvents.lua:369: in main chunk
    [C]: in function 'require'
    D:\Test of Time\Scenario\Germanicus\legacyEventEngine.lua:16: in main chunk
    [C]: in function 'require'
    D:\Test of Time\Scenario\Germanicus\events.lua:25: in main chunk

I'm not really sure what this means.
 
Event file 1 at line number 28 doesn't have an open action.

Check line 28 of the event file you are trying to convert. This error means that the converter received parameters for an action, but that no action was specified on a previous line. E.g. something like veteran=true without a CREATEUNIT line before it.
 
Thanks - I was able to correct the error (I didn't have an "@"). Now I get this one:


Edit--looks like I forgot "endlocations" on another event - I have to hand it to you, even if I wasn't planning on converting a scenario to lua, this would still be a nifty way to check my work!!!
 
OK, so I got it working... Now for a really stupid question...

Does this not write a new lua file with the converted events? And if not, how could I add lua features to the scenario now? Specifically, I want to add your munitions library to the events, but I see no events to add them to?
 
It can write a table that will work with the engine (I have to run, so I'll give instructions later, but it's documented in one of the files), but you can simply convert the events every time the scenario is loaded also, and it should be fine. You put in your own events into the supplied events.lua file.

Here's a template that I've been trying to work on for events. It's still in the under construction phase, so there may be bugs. But it should link various libraries I've made together.
 

Attachments

  • Template.zip
    77.4 KB · Views: 175
I had a look through and so far it looks great - the .object. is going to take the place of all the 'Aliases' eh? Probably makes sense. I also like your attempt at standardizing the language.

I might take a stab at fixing Germanicus this weekend, time permitting. I'm a little annoyed that my "best" scenario has had critical event errors for 8 years or so that went completely unnoticed. Time to fix that, and also to get the munitions into the game.
 
It can write a table that will work with the engine (I have to run, so I'll give instructions later, but it's documented in one of the files), but you can simply convert the events every time the scenario is loaded also, and it should be fine. You put in your own events into the supplied events.lua file.

The legacy event engine works by converting the imported events into a lua table, and checking the table whenever an event trigger occurs to see if any of the events in the table should be executed. The 'legacy' functions perform the events. If you want events to happen before the legacy events, then put your code before the corresponding 'legacy' function in events.lua, whereas if you want them to occur after the legacy events, put your lua code after the legacy function.

The current default is for the Legacy Event Engine to read and convert the macro events file every time the scenario is loaded. If you want to generate a lua table, change this line in getLegacyEvents.lua from

Code:
local writeTextFile=false
to
Code:
local writeTextFile=true
This will cause a file XXXXXXXXlegacyEvents.lua to be written, with the prefix depending on the time the file was written.

To use that file, instead of getLegacyEvents.lua, change the following line in legacyEventEngine.lua
Code:
local legacyEventTableName = "getLegacyEvents"
to the name of the file written by getLegacyEvents.lua (omitting the .lua part).
 
This seems to be working (for the first few events at least) with a conversion of Germanicus on the Rhine.

Is there anything specific you think I should look for in terms of potential issues/bugs? It's unclear if this is "finished" or if you anticipate certain event structures won't work?

For what it's worth, using this, I was able to convert the scenario and add in a select few lua events in a matter of hours, so now I just want to have a playthrough to see if I notice anything wrong and then I can release the scenario. I'm very pleased with the relative ease of use and this might be a good stepping stone for many (if a designer can write "traditional" events in macro.txt, convert them with this program, and just add a few lua-specific events, I'll bet we see much more widespread use).
 
This seems to be working (for the first few events at least) with a conversion of Germanicus on the Rhine.

Is there anything specific you think I should look for in terms of potential issues/bugs? It's unclear if this is "finished" or if you anticipate certain event structures won't work?

There's nothing I 'expect' to go wrong, but this just hasn't been tested very thoroughly, and the code is rather complicated. I played far enough into Techumseh's Sea Lion to start the invasion of Britain, and it seemed to work (though I fixed a lot of bugs along the way). The only bug I know about is a diplomacy bug, but I think that is a bug in TOTPP, rather than my implementation of the Macro.

Unless someone wants to write a 'testing' scenario, where all the different possible events are tested, the way this module will 'finished' is for people to convert and play scenarios, and report any bugs.

For what it's worth, using this, I was able to convert the scenario and add in a select few lua events in a matter of hours, so now I just want to have a playthrough to see if I notice anything wrong and then I can release the scenario. I'm very pleased with the relative ease of use and this might be a good stepping stone for many (if a designer can write "traditional" events in macro.txt, convert them with this program, and just add a few lua-specific events, I'll bet we see much more widespread use).

That's good to know. I had a similar experience with Imperialism II when testing my canBuild module. The conversion itself presented no problems (though I didn't actually test the events, since that wasn't what I was interested in).
 
Top Bottom