The Spanish Civil War v4 for ToT + ToTPP + Lua - Development Thread

Pablostuka

King
Joined
Mar 27, 2002
Messages
805
Location
Galway, IE
Just to point that this opinion is a very important one (at least in compare with mine, while Pablostuka has deeper experience) :
Something to be kept in mind to find the best solution(s) considering various nowadays limits.
Of course, @tootall_2012 has a very valid point, but I lack of "beautiful" ways to mark the borders in the main map. I do not have spare terrains, custom resources or units, can't use pollution (as I'm using it for something else), rivers or anything. So only the topp landmarks (labels) are left.

I'd like to know more opinions on this, I don't really see the foreign borders being so needed in this scenario.
 
Joined
Feb 11, 2012
Messages
834
I don’t see adding a visible border on the main map as an absolute must have but merely as a useful visual aide, i.e. you don’t have to go back and forth between maps to figure out where the borders are.

But as you say as all of the fighting should occur within the borders of Spain itself my observation might be moot.
 

JPetroski

Deity
SLeague Staff
Joined
Jan 24, 2011
Messages
4,614
Oh please do, I'll be honoured! I can share with you my terrain files and Lua code whenever you need.

I think the idea could even be expanded to "supply" wherein certain units heal, attack, move, or defend at different rates depending on if the ground on the hidden "supply" map is going. I can't remember if someone else was doing this already (Dadais, perhaps?) but in any event, lua really is something, isn't it?

The challenge, as always, is getting the AI to use it, though in some respects a simple "isHuman" check could at least prevent "bugs" and make the AI a little more challenging if they aren't equally affected.
 

Pablostuka

King
Joined
Mar 27, 2002
Messages
805
Location
Galway, IE
Hi all,

Let me show you another proof of concept (PoC) Lua code I worked on yesterday and part of today. This time I rewrote @Prof. Garfield 's LST LuaCore/helpKey.lua to meet my own reporting needs. I know I should avoid modifying the LuaCore code but this time I had to as I wanted enhanced unit reporting capabilities.

This is the existing LST help key info, which is already amazing and gives the info available in the Civilopedia plus the current hit points and nearest friendly city:

1662562683986.png

And this is my new Unit Status report (helpkey). I'm still struggling with font alignment but it's the best I could get for now, will continue fine tuning it. It's completely dynamic text, nothing is hardcoded except some fixed labels. I have a section for the specific unit info, then two sections related to the unit type:
1662562738096.png

How it works: I modified both helpKey and helpKeySettings to be able to define a table of images for each unit type. Also I have an object for a brief text description of each unit type.

1662563499918.png


As you know, my scenario caters for specific unit IDs in case of ships or leaders (I implemented this for my espionage module), so if a specific unit ID (dependiing on their domain) has been defined in the different parameter tables, I will show the unit name, in this case the ship name.

1662563240613.png

All these centered headers which split the sections gave me some headaches. I had to code some lpad, rpad and pad functions and define separators and max chars per line, and it's still not perfect because of the different character width, but hey, it is what it is.

For the different columnar info, I'm using @Knighttime 's convertTableToColumnText functionality included in the LST text module, playing around with different tables and alignments in the different sections of the page.

Now the fun part: the unit Location text will change depending on the unit domain, and current unit situation, e.g. if it's in a city or outside it. I programmed a quick function to return the relative direction respect of the closest city (irrespective of friendly or enemy city) and I really like it in-game.
The distances shown are quite accurate, as my map is done in a way that each tile is roughly 10x10 km in real life, so it's easy to convert to actual distances.

1662563138744.png

For planes, we get different texts too:
1662563992199.png

Also if it's not an "unique unit", then I just show the unit id.
1662564066523.png

Ground units:
1662564145840.png

For damaged units, the status and strenght changes:
1662564459642.png

That's all for now!

Pablo
 

Attachments

  • 1662563023158.png
    1662563023158.png
    15.9 KB · Views: 6

Prof. Garfield

Deity
Supporter
Joined
Mar 6, 2004
Messages
4,003
Location
Ontario
Let me show you another proof of concept (PoC) Lua code I worked on yesterday and part of today. This time I rewrote @Prof. Garfield 's LST LuaCore/helpKey.lua to meet my own reporting needs. I know I should avoid modifying the LuaCore code but this time I had to as I wanted enhanced unit reporting capabilities.
HelpKey needs a good re-write anyway. It was some of the earliest code I wrote, and it was written before a lot of information was available through Lua. (E.g. we can now get terrain production and determine whether enemy units on a square are visible.)

The main reason I have for discouraging modification of LuaCore files is that I can tell someone to replace those files for bug fixes and extra features, without worrying that some of their work will be erased. If someone does need to modify the file, it suggests some deficiency that I might want to correct, so I'd like to know about it. I may also want to advise the scenario designer that there is a way to achieve what they want without modification. You clearly have enough expertise to "safely" change the Lua core if you need to.
 

Pablostuka

King
Joined
Mar 27, 2002
Messages
805
Location
Galway, IE
You clearly have enough expertise to "safely" change the Lua core if you need to.
I never used Lua before, but I usually work with Python, so the learning curve is not steep. I might send you some functions if you want to include them in the general library once I polish them a bit.
 

Prof. Garfield

Deity
Supporter
Joined
Mar 6, 2004
Messages
4,003
Location
Ontario
BTW @Prof. Garfield any idea on how to quickly deal with the Ñ/ñ characters? when read directly from the Rules.txt it's correctly displayed, however when used in Lua code, it's not. Do I need to work with ASCII codes? Thanks
In the console, I can use
Code:
civ.ui.text(string.char(209)..string.char(241))
civ.ui.text("Ñ/ñ") -- cut and pasted directly from your post
and it prints those characters. (Found the numbers in the LuaCore\characterTable.lua file compiled by @Knighttime )
When I cut and paste your characters into gVim and run civ.ui.text("Ñ/ñ") as a script, it gives different characters.

This isn't something I've had to deal with, so I don't have more information at present.
 

Dadais

King
Joined
Oct 20, 2010
Messages
795
Location
France
HelpKey needs a good re-write anyway. It was some of the earliest code I wrote, and it was written before a lot of information was available through Lua. (E.g. we can now get terrain production and determine whether enemy units on a square are visible.)

The main reason I have for discouraging modification of LuaCore files is that I can tell someone to replace those files for bug fixes and extra features, without worrying that some of their work will be erased. If someone does need to modify the file, it suggests some deficiency that I might want to correct, so I'd like to know about it. I may also want to advise the scenario designer that there is a way to achieve what they want without modification. You clearly have enough expertise to "safely" change the Lua core if you need to.

I haven't looked far into your Lua Core structure but,
can't @Pablostuka copy/past your function elsewhere to then alter it.

He then just can call this new own function without any worry about upgrading your files ?
 

Pablostuka

King
Joined
Mar 27, 2002
Messages
805
Location
Galway, IE
In the console, I can use
Code:
civ.ui.text(string.char(209)..string.char(241))
civ.ui.text("Ñ/ñ") -- cut and pasted directly from your post
and it prints those characters. (Found the numbers in the LuaCore\characterTable.lua file compiled by @Knighttime )
When I cut and paste your characters into gVim and run civ.ui.text("Ñ/ñ") as a script, it gives different characters.

This isn't something I've had to deal with, so I don't have more information at present.
Thanks, I'll try string.char and concatenation! Good idea
 

Pablostuka

King
Joined
Mar 27, 2002
Messages
805
Location
Galway, IE

I haven't looked far into your Lua Core structure but,
can't @Pablostuka copy/past your function elsewhere to then alter it.

He then just can call this new own function without any worry about upgrading your files ?
I could do a copy and name it differently, change event files, etc. I might do that. Before the release I'll do a good clean up!
 

Pablostuka

King
Joined
Mar 27, 2002
Messages
805
Location
Galway, IE
In the console, I can use
Code:
civ.ui.text(string.char(209)..string.char(241))
You're a genius, thanks! This was really annoying me and i was able to fix it.

The text in my object module:

1662626118267.png


Before it was showing weird characters:

1662625251096.png


Now it's good:

1662625272272.png


I coded this little parsing function in Lua inside a module with generic stuff I called functionsSCW. Maybe @Dadais can adapt it to French accents if he needs it somehow, or anybody else with the need to use special characters in their texts, as Lua doesn't like them at all. Just modify the table and include the ascii codes and symbols (these can be sourced from https://www.ascii-code.com/)

SQL:
local function parseSpanishChars(text)
  
    -- I'm not including "diéresis" (¨) as I don't think I need it here :)
    local spanishCharacters = {
        [0] = {code=209,character="Ñ"},
        [1] = {code=241,character="ñ"},
        [2] = {code=193,character="Á"},
        [3] = {code=201,character="É"},
        [4] = {code=205,character="Í"},
        [5] = {code=211,character="Ó"},
        [6] = {code=218,character="Ú"},
        [7] = {code=225,character="á"},
        [8] = {code=233,character="é"},
        [9] = {code=237,character="í"},
        [10] = {code=243,character="ó"},
        [11] = {code=250,character="ú"},
        [12] = {code=161,character="¡"},
        [13] = {code=191,character="¿"}}
  
    for i=0,13 do
        -- Global Substitution (https://www.lua.org/pil/20.1.html)
        text = string.gsub(text,spanishCharacters[i].character,string.char(spanishCharacters[i].code))
    end
    return text
end
functionsSCW.parseSpanishChars = parseSpanishChars

To be honest with you, with some additional work this could be standarized and enhanced to map all extended ASCII codes (as present in the LST file LuaCore/characterTable.lua) so any special characters found in texts can be parsed and replaced to the character codes before displayed to screen. This could be implemented in the LST text module functions to any text input. Do you see any benefit in this @Prof. Garfield ?

Now I'll deal with enhancing the string.upper function as it also doesn't handle these special characters. I'll also code a generic initCap function...the default string manipulation in Lua is quite poor!

Pablo
 
Last edited:

Prof. Garfield

Deity
Supporter
Joined
Mar 6, 2004
Messages
4,003
Location
Ontario
To be honest with you, with some additional work this could be standarized and enhanced to map all extended ASCII codes (as present in the LST file LuaCore/characterTable.lua) so any special characters found in texts can be parsed and replaced to the character codes before displayed to screen. This could be implemented in the LST text module functions to any text input. Do you see any benefit in this @Prof. Garfield ?
This would be very useful, and I'd definitely put it into the text module. I was thinking of something similar, having a function to substitute, say, %N~ for Ñ. This discussion should probably be moved to a separate thread.

I think there is some sort of weird encoding issue going on with the text editor. When I copied Ñ directly to the console, civ.ui.text displayed it properly. Lua also obviously understands these special characters, since string.char works. Also, Lua apparently understands the characters written into the text editor enough to find and substitute them in your code.

Now I'll deal with enhancing the string.upper function as it also doesn't handle these special characters. I'll also code a generic initCap function...the default string manipulation in Lua is quite poor!
Yes. I believe Lua was first developed for (presumably English speaking) engineers at a Brazilian Oil Company, which explains a few things like indices starting at 1 instead of 0. They probably weren't interested in doing lots of string manipulations. I think I also read somewhere that Lua doesn't have regular expressions since the code for that is larger than the entire core Lua code base.
 

Pablostuka

King
Joined
Mar 27, 2002
Messages
805
Location
Galway, IE
Hi, so now I'm quite happy with how everything looks, despite the current limitations on text and image alignments that I can't really do anything about it.

This:
Became this:
1662649655717.png


To fill the empty space under the image, I'm adding extra royalty-free images (trick: it's the same image file! :) ) which includes the original unit graphic, in the same fashion as the Civilopedia. I also added some extra fields (type and class for ships, all taken from my parameter table), and rewrote the text description so I have a standard size that fits well the screen. Also any text using "special Spanish" characters are fixed too.

I'll leave it there...
 

Pablostuka

King
Joined
Mar 27, 2002
Messages
805
Location
Galway, IE
This would be very useful, and I'd definitely put it into the text module. I was thinking of something similar, having a function to substitute, say, %N~ for Ñ. This discussion should probably be moved to a separate thread.

I think there is some sort of weird encoding issue going on with the text editor. When I copied Ñ directly to the console, civ.ui.text displayed it properly. Lua also obviously understands these special characters, since string.char works. Also, Lua apparently understands the characters written into the text editor enough to find and substitute them in your code.
I'll drop you a PM with what I've coded so far and then you can pick whatever you want :)
 

Pablostuka

King
Joined
Mar 27, 2002
Messages
805
Location
Galway, IE
Hi, so now I'm quite happy with how everything looks, despite the current limitations on text and image alignments that I can't really do anything about it.

This:

Became this:
View attachment 638852

To fill the empty space under the image, I'm adding extra royalty-free images (trick: it's the same image file! :) ) which includes the original unit graphic, in the same fashion as the Civilopedia. I also added some extra fields (type and class for ships, all taken from my parameter table), and rewrote the text description so I have a standard size that fits well the screen. Also any text using "special Spanish" characters are fixed too.

I'll leave it there...
BTW for the Republican Jaime I BB it looks good too. I really like the ability to define a single ship by using the unit.id, therefore only needing a single unit slot for each ship class (unit type). In WW2 scenarios this allows to have a single unit slot for the Bismarck class and have specific events, texts, etc for the Tirpitz :) I hope somebody else uses the idea!

If for some reason the ship is created by events later on (so it doesn't exist on scenario start therefore the unit ID is unknown), what I'll do is to dinamically add the data to my parametrised table by events after createUnit(). To persist the unit ID, I'll use the counter module to save these ids as counters for the ships I plan to create via events.

1662652448954.png


Pablo
 

Prof. Garfield

Deity
Supporter
Joined
Mar 6, 2004
Messages
4,003
Location
Ontario
I think there is some sort of weird encoding issue going on with the text editor. When I copied Ñ directly to the console, civ.ui.text displayed it properly. Lua also obviously understands these special characters, since string.char works. Also, Lua apparently understands the characters written into the text editor enough to find and substitute them in your code.
I'm pretty sure this is an issue of the text editor not saving 8 bit ASCII by default.

If I have a text file (gVim in Linux Mint in my case)
Code:
--a
civ.ui.text("Ññ") 
print(string.len("Ññ"))
Running the file will show the incorrect characters and tell me the string length is 4.

If I open the file in a hex editor, and change the a in the first line to character Ñ (61->D1), and save, gVim now shows me what the characters actually are
Code:
--Ñ
civ.ui.text("Ã<91>ñ") 
print(string.len("Ã<91>ñ"))
And I can copy and paste in the correct characters and have them work properly without any fuss.
 

Pablostuka

King
Joined
Mar 27, 2002
Messages
805
Location
Galway, IE
I'm pretty sure this is an issue of the text editor not saving 8 bit ASCII by default.

If I have a text file (gVim in Linux Mint in my case)
Code:
--a
civ.ui.text("Ññ")
print(string.len("Ññ"))
Running the file will show the incorrect characters and tell me the string length is 4.

If I open the file in a hex editor, and change the a in the first line to character Ñ (61->D1), and save, gVim now shows me what the characters actually are
Code:
--Ñ
civ.ui.text("Ã<91>ñ")
print(string.len("Ã<91>ñ"))
And I can copy and paste in the correct characters and have them work properly without any fuss.
Yup. If the special character is directly read from the Rules.txt file it's displayed correctly, the issue is when present on Lua strings. From my rules.txt:

1662660611241.png

Anyway, the code I wrote works just fine and also helps me to learn better this language.
 

Pablostuka

King
Joined
Mar 27, 2002
Messages
805
Location
Galway, IE
Just quick update: I'm implementing individual unit functionality on commanders for both sides, pretty much in the same fashion as I did with the ships, by using Lua tables with multiple fields. I'm not including all commanders which took part in the war, only the most relevant/famous historically, and I'm trying to get the numbers balanced on both sides..

Commander units in my scenario will have, apart from extra info attributes to display on event texts and reports (same as you saw with ships), special attributes (traits) which will provide different bonuses in-combat. Here I'm being inspired by the Paradox games Hearts of Iron/Darkest Hour, on which all commanders had specific traits (mountaineer, desert fox, panzer leader, trickster, old guard, engineer, etc). These traits will affect battle involving units located on tiles under their influence. It's different from the LST traits module by @Prof. Garfield as the latter affects unit types, not individual unit ids from the same type.

1662849112004.png


My tables are indexed by an integer starting with 0, the same way as the ship tables, because this way my espionage module picks a random element from the table (yes, spies will also provide reports on enemy commanders!)

Once I finish implementing this, I'll show you some PoC screenshots of what I'm doing. In the meantime enjoy the commander unit graphics by @Fairline:

1662848924427.png
 

Dadais

King
Joined
Oct 20, 2010
Messages
795
Location
France
Just quick update: I'm implementing individual unit functionality on commanders for both sides, pretty much in the same fashion as I did with the ships, by using Lua tables with multiple fields. I'm not including all commanders which took part in the war, only the most relevant/famous historically, and I'm trying to get the numbers balanced on both sides..

Commander units in my scenario will have, apart from extra info attributes to display on event texts and reports (same as you saw with ships), special attributes (traits) which will provide different bonuses in-combat. Here I'm being inspired by the Paradox games Hearts of Iron/Darkest Hour, on which all commanders had specific traits (mountaineer, desert fox, panzer leader, trickster, old guard, engineer, etc). These traits will affect battle involving units located on tiles under their influence. It's different from the LST traits module by @Prof. Garfield as the latter affects unit types, not individual unit ids from the same type.

View attachment 639076

My tables are indexed by an integer starting with 0, the same way as the ship tables, because this way my espionage module picks a random element from the table (yes, spies will also provide reports on enemy commanders!)

Once I finish implementing this, I'll show you some PoC screenshots of what I'm doing. In the meantime enjoy the commander unit graphics by @Fairline:

View attachment 639075
It looks very much like my "stuff" table for units in the TES scenario.

Why didnt you use directly unitsID as the key of your table and added an integer ?
 
Top Bottom