Overlord Scenario Playtest Thread

Status
Not open for further replies.
From the function reference

researchCost (get)
tribe.researchCost -> integer

Returns the research cost of the tribe.


researchProgress (get/set)
tribe.researchProgress -> integer

Returns the progress towards the current research (range between 0 and tribe.researchCost).


researching (get/set)
tribe.researching -> tech

You can check what each player is researching, and how close they are to completion. If you want to give cash as soon as research starts, then check every turn (or after production) whether tribe.researching is the appropriate tech, and use gen.justOnce to give the bonus on the first turn that research goal is detected.

Alternatively, you can give a small bonus of a few units each turn that the technology is being researched, so the buildup is a bit more gradual.

Thanks, Prof!
These are all amazing options...:)

Lua truly is a marvel for designers. I do like the last option with armies being amassed gradually...I think I will go with that route.

This code would be entered into "afterProduction", I am guessing? Could you be kind enough to sketch out a quick event outline for me?

PS
I know you are busy, dude - and all these questions are a pest, but I am eager to learn from the wizard...!
 
Here are a couple (untested) options

Code:
local param = require("parameters.lua") -- stick the money bonus as a key in parameters.lua, so all parameters are in one place
-- in the afterProduction
if tribe == object.tGermans then -- Only run this code on the German turn
    if object.tGermans.researching == object.aBarbarossaTech then
        gen.justOnce("GermanBarbarossaBonus",function()
            object.tGermans.money = object.tGermans.money+param.barbarossaBonus
            end)
    end
end
counter.define("BarbarossaPrep",0) -- this line can be in object.lua to keep all counters together
local param = require("parameters.lua") -- stick the max prep turns in parameters.lua, so all parameters are in one place
-- in the afterProduction event
if tribe == object.tGermans then -- only run this code on the german turn
    if object.tGermans.researching == object.aBarbarossaTech and
        counter.value("BarbarossaPrep") < param.barbarossaPrepMaxTurns then
        -- since counter was defined to start at 0, we use < and not <=
        -- to make the event happen a limited number of times
        -- create some units, or whatever
        -- gen.createUnit is available, as is civlua.createUnit
        counter.add("BarbarossaPrep",1) -- increment the counter by 1
    end
end
-- instead of counters, can use
-- gen.limitedExecutions(key,maxTimes,limitedFunction)--> void
if tribe == object.tGermans then -- Only run this code on the German turn
    if object.tGermans.researching == object.aBarbarossaTech then
        gen.limitedExecutions("GermanBarbarossaBonus",param.barbarossaPrepMaxTurns,
            function()
                -- do whatever bonuses you want to happen each turn
            end)
    end
end
 
@Prof. Garfield
My sincere thanks, sir - I will be delighted to test these codes. Doing this now.

Now that I think of it, the timer set up here could be used to actually represent the attack too...
For big attacks like the Barbarossa event, it could mean the time used to research is the time during which the attack is carried out...
A text pop up could be made for when the tech is selected, and inform the player what is going on, or alternively, what the AI is about unleash.

When the tech is researched, it could be declared the campaign is over. For WW2 operations like Barbarossa, Stalingrad, Torch and Overlord, this could be a perfect system.

This simplifies the hassle of campaign events from macro...Lua has so many CIV2 possibilities, that keep expanding.
 
Last edited:
@Prof. Garfield
I am going with the gradual unit buildup method. I can create a text event to explain industry is working overtime to crank out units.

As per your instructions I added code to parameters.lua, at the top of the file, as follows...Checking if this has been done correctly?

Code:
-- This file is meant to group scenario parameters, so that there is a single
-- place where important values are recorded.  It is recommended that you define
-- a parameter value in one place and always refer to that place, so that if
-- you decide to make a change, only one value has to be changed instead of
-- searching for every possible place that value is relevant.

local param = require("parameters.lua") -- stick the max prep turns in parameters.lua, so all parameters are in one place
param.barbarossaPrepMaxTurns = 12
local gen = require("generalLibrary")
local text = require("text")
local eventTools = require("eventTools")
-- declare if map is flat or round
gen.declareMapFlat()
--gen.declareMapRound()

I then added your code test to the afterproduction.lua, again, making sure this is the right method...?

Code:
local afterProdEvents = {}

function afterProdEvents.afterProduction(turn,tribe)
   -- civ.ui.text("After Production for turn "..tostring(turn).." and tribe "..tribe.name)



-- in the afterProduction event
if tribe == object.tGermans then -- only run this code on the german turn
    if object.tGermans.researching == object.aBarbarossaTech and
        counter.value("BarbarossaPrep") < param.barbarossaPrepMaxTurns then
        -- since counter was defined to start at 0, we use < and not <=
        -- to make the event happen a limited number of times
        -- create some units, or whatever
        -- gen.createUnit is available, as is civlua.createUnit
        counter.add("BarbarossaPrep",1) -- increment the counter by 1
    end
end

end
return afterProdEvents

So, I understand I would need to link these to unit spawn event code, either via a trigger in onproduction.lua, or in the legacy events...?
I would add the suffix "BarbarossaPrep" to the legacy events somewhere, I recall. I will go back and check you post on that...

I am close to understanding how this system stitches together...Once I do, I will be less of a nuisance, I promise. :)
 
As per your instructions I added code to parameters.lua, at the top of the file, as follows...Checking if this has been done correctly?
This line shouldn't be in parameters.lua, but rather in the files that need access to parameters.lua for their data.
Code:
local param = require("parameters.lua") -- stick the max prep turns in parameters.lua, so all parameters are in one place

Code:
param.barbarossaPrepMaxTurns = 12
should be after
Code:
local param = {}
which is already in that file, but further down.

So, I understand I would need to link these to unit spawn event code, either via a trigger in onproduction.lua, or in the legacy events...?
I would add the suffix "BarbarossaPrep" to the legacy events somewhere, I recall. I will go back and check you post on that...
The key you use for the lua trigger doesn't have to be the same as for the counter, but I don't think it would cause problems if it is.

Code:
-- Lua Trigger
-- Allows Lua to trigger events in the Legacy Event Engine directly
-- usage:
-- @IF
-- lua
-- triggername=myluatrigger
-- @AND
-- ...
--
-- legacy.luaTrigger("myluatrigger","triggerAttackerNameOrNil","triggerDefenderNameOrNil","triggerReceiverNameOrNil")
--
 
Hi there, @Prof. Garfield
I have made the adjustment - And moved the line to where you indicated, at the very bottom of parameters.lua, as shown here:

Code:
local param = {}

param.barbarossaPrepMaxTurns = 12

return param

I'm ready to try and trigger events in the legacy engine...I have a chunk of macro code here for spawning a tank:

Code:
@IF
RECEIVEDTECHNOLOGY
technology=90
receiver=German Reich
@THEN
JUSTONCE
CREATEUNIT
unit=Panzer III
owner=German Reich
veteran=yes
homecity=None
locations
16,36
endlocations
@ENDIF

Do I combine the above with the code below:

Code:
-- @IF
-- lua
-- triggername=myluatrigger
-- @AND

And what file to do I enter this text to? Kind of lost here...

I am aware I will have to update the Obejct file with tiles for the above spawned unit.

PS
Thanks in advance for your patience here.
 
In the legacy events text file, you would have this event

Code:
@IF
LUA
triggername=BarbarossaTanks
@THEN
JUSTONCE
CREATEUNIT
unit=Panzer III
owner=German Reich
veteran=yes
homecity=None
locations
16,36
endlocations
@ENDIF

I don't remember if the triggername was case sensitive, but we'll assume it is. So, somewhere in your lua files, you will want this event to happen. At that place, you use
Code:
legacy.luaTrigger("BarbarossaTanks",nil,nil,nil)
Since the actions don't depend on trigger attacker, trigger defender or trigger receiver, the other arguments are nil (in fact, they don't even have to be written in, so you could just have legacy.luaTrigger("BarbarossaTanks)). This will check all the events for events with 'lua' triggers that have triggername set to BarbarossaTanks.
 
When you say "somewhere in my lua files", could you indicate where?
Or do you mean if I created specific lua files for an event like Barbarossa?
I mean somewhere in your lua code, you will define the conditions under which this event or events will happen, such as the afterProduction events we discussed above. At that point, you include the line legacy.luaTrigger("LuaTriggerName",nil,nil,nil).
 
@Prof. Garfield

So this is what is in my "afterProduction" lua file, using the conditions of tech research and linked in the parameters.lua file, (setting max of 12 turns to provide a unit or two per turn)

Code:
local afterProdEvents = {}

local param = require("parameters.lua") -- stick the max prep turns in parameters.lua, so all parameters are in one place

function afterProdEvents.afterProduction(turn,tribe)
   -- civ.ui.text("After Production for turn "..tostring(turn).." and tribe "..tribe.name)

-- in the afterProduction event
if tribe == object.tGermans then -- only run this code on the german turn
    if object.tGermans.researching == object.aBarbarossaTech and
        counter.value("BarbarossaPrep") < param.barbarossaPrepMaxTurns then
        counter.add("BarbarossaPrep",1) -- increment the counter by 1
    legacy.luaTrigger("BarbarossaPanzers")
        end
    end
end

end
return afterProdEvents

Hopefully, I have not utterly botched things.
 

Attachments

  • afterProduction.zip
    493 bytes · Views: 45
@Prof. Garfield - I am wondering if I could request your guidance here.

I removed all the parameters/afterproduction.lua items, as I am rethinking a new invasion method,
I loved the idea of an attack based on research time limits and units in stages, but I am not getting anywhere trying to make it work.

I'm at the point where I either try a simplified idea, or just ditch the campaigns altogether. I'm not at the Lua skill level to implement them.

Although, now when I try to load my save, I am getting this Lua error:

N:\CIV2 TOT\1_OVERLORDS 1940\LuaCore\generalLibrary.lua:2729: The Global table doesn't have a value associated with counter.
stack traceback:
[C]: in function 'error'
N:\CIV2 TOT\1_OVERLORDS 1940\LuaCore\generalLibrary.lua:2729: in metamethod '__index'
N:\CIV2 TOT\1_OVERLORDS 1940\LuaParameterFiles\object.lua:372: in main chunk
[C]: in function 'require'
...TOT\1_OVERLORDS 1940\LuaRulesEvents\canBuildSettings.lua:2: in main chunk
[C]: in function 'require'
N:\CIV2 TOT\1_OVERLORDS 1940\events.lua:35: in main chunk


I assume Lua info is now written to the save. Any advice on how to fix this?
Also with the GoTo bug fixed, I might remove the polygon map info too if possible. Can that be done?

EDIT:
Fixed - It was a rouge counter line left over in Obect.lua...:)
 
Last edited:
Although, now when I try to load my save, I am getting this Lua error:

Looks like you need a line

local counter = require("counter")

in one of your files, I think object.lua, but possibly canBuildSettings.lua.

I assume Lua info is now written to the save. Any advice on how to fix this?

Try putting this into the console, and then save the game.
Code:
civ.scen.onSave(function() return "return {}" end)
The newly saved game should have an 'empty' state table.
Also with the GoTo bug fixed, I might remove the polygon map info too if possible. Can that be done?

Perform the same procedure as you did to make the dozens of 'continents', but this time just define only a few large polygons for the actual continents. If you just want all land to be continent 1, run the attached script and save the game.
 

Attachments

  • oneContinent.lua.zip
    347 bytes · Views: 44
In the next few days, If I came up with a really scaled back simplified event idea for these invasions, can I post it in the Lua sticky thread for advice?

Sure.
 
UPDATE!

After some weighing up options, I am going to remake the scenario. The current Lua content was sort of tacked onto this old version.
It opened my eyes to many possibilities. So, encouraged by my update of Imperialism III, I am going to give Overlords the same treatment.

Rebuilding the guts of the scenario from the ground up will allow me to keep track of things and minimize bugs and laborious edits.

My plan is to keep the map, recreate a fresh new improved tech tree, and a more mixed units roster. I think the new list is tasty.
I'd like an emphasis on useful national units being recruited at certain zones, using Lua the excellent CanBuildSettings.

New terrain tiles and city GFX will be created also.

The new roster:
Update_Units.png


I'll keep everyone posted, and maybe open a new thread when the update is ready.
 
Last edited:
Status
Not open for further replies.
Top Bottom