All the relevent object.lua refs are in place - I'm just making sure that I can have three improvements.
-- gen.getTileProduction(tile,city) --> integer (food), integer(shields), integer(trade)
-- returns the tile production values, presuming that the city
-- given is the one working the tile
-- That is to say, returns the values that would be seen on the tile in the city window
-- Doesn't check if that city is actually working the tile
-- gen.computeBaseProduction(city)-->integer(food), integer(shields), integer(trade)
-- Computes the resources harvested by the city from the terrain
-- includes superhighway/supermarket/railroad bonus, but not factories/powerplants
-- gen.persistentRandom(key) --> number between 0 and 1
-- checks the persistentRandom table (within the state table)
-- for a value associated with key. If it exits, the value is
-- returned. If it does not exist, a random number between
-- 0 and 1 is generated, stored in the table under the key,
-- and also returned
-- example of use: WWII scenario with seasons
-- You may want to have some games where the 1941 spring starts
-- in April, and other games where it starts in May. When
-- determining whether to load winter or summer terrain stats during
-- 1941, you would use gen.persistentRandom("EarlySpring1941") < 0.5
-- as part of the season check in April, and load summer if the value is less than 0.5
-- and winter otherwise. This way, each when each player starts their
-- game that month, they will all either get winter or summer terrain
-- gen.clearPersistentRandom(key) --> void
-- sets the value associated with the key in the
-- persistentRandom table. This could either be for reuse of the key,
-- or to prevent the key from staying in the state table indefinitely
-- gen.getPersistentRandomTable() --> table
-- returns the persistentRandom table
<Your TOT Dir>\Template\LuaCore
<Your Scenario Directory>\LuaCore
local log = require("log")
function triggerEvents.unitDefeated(loser,winner,aggressor,victim,loserLocation,winnerVetStatus,loserVetStatus)
context[getContext()]["unitDefeated"](loser,winner,aggressor,victim,loserLocation,winnerVetStatus,loserVetStatus)
universal["unitDefeated"](loser,winner,aggressor,victim,loserLocation,winnerVetStatus,loserVetStatus)
legacy.doUnitKilledEvents(loser,winner)
log.onUnitKilled(winner,loser)
end
I'm using an attack bonus module in the scenario I sent you I believe.
My attack bonus is Guderian and some others giving bonuses to panzers that can move up to 8 spaces with roads, so I don't know that it would work well if he had to be on the same tile unfortunately.
Just wondering:
I'm using city co-ords for unit locations in "CanBuildSettings" - But how do I employ Lua to use the map landmass number? (in this case, zone 4)
The cities in the Canadian landmass can train Canadian troops - I'd like newly-settled cities in zone 4 to also be able to build them. Any tips?
-- isCanada(tile)-->bool
-- returns true if the tile is in landmass 4 (Canada), false Otherwise
local function isCanada(tile)
if tile.landmass == 4 then
return true
else
return false
end
end
local function isCanada(tile)
return tile.landmass == 4
end
--#gen.inPolygon(tile,tableOfCoordinates)-->bool
-- the table of coordinates defines the corners of the
-- polygon. Returns true if the tile is within the
-- polygon defined by the table of coordinates, and
-- false otherwise. Checking that the map is correct
-- must be done separately
-- the entry:
-- tableOfCoordinates.doesNotCrossThisX
-- sets an x coordinate that the polygon does not
-- cross. If absent, 0 is used,
-- meaning the polygon shouldn't cross the date line
local canadaPolygon = {--Table of coordinate defining the Canada Polygon}
local function inCanada(tile)
return gen.inPolygon(tile,canadaPolygon)
end
...f Time\Scenario\Hinge of Fate\LuaCore\generalLibrary.lua:2471: bad argument #1 to 'getTile' (number expected, got civ.city)
stack traceback:
[C]: in function 'civ.getTile'
...f Time\Scenario\Hinge of Fate\LuaCore\generalLibrary.lua:2471: in function 'generalLibrary.getTileId'
D:\Test of Time\Scenario\Hinge of Fate\LuaCore\canBuild.lua:180: in upvalue 'makeNewLocationParameters'
D:\Test of Time\Scenario\Hinge of Fate\LuaCore\canBuild.lua:207: in local 'postProcessParameters'
D:\Test of Time\Scenario\Hinge of Fate\LuaCore\canBuild.lua:240: in upvalue 'postProcessParameterTable'
D:\Test of Time\Scenario\Hinge of Fate\LuaCore\canBuild.lua:326: in function 'canBuild.supplyImprovementParameters'
...enario\Hinge of Fate\LuaRulesEvents\canBuildSettings.lua:342: in main chunk
[C]: in function 'require'
D:\Test of Time\Scenario\Hinge of Fate\events.lua:35: in main chunk
Can you help me understand what I'm doing wrong here on the canBuildSettings?
This works:
improvementBuild[object.iCivilianPopulation.id] = {location=britishHomeCities}
This does not work:
improvementBuild[object.iCivilianPopulation.id] = {location=britishHomeCities,germanHomeCites}
This also does not work (even though I would have thought it would):
improvementBuild[object.iCivilianPopulation.id] = {location={britishHomeCities,germanHomeCites}}
Instead I get this error:
This also does not work (even though I would have thought it would):
improvementBuild[object.iCivilianPopulation.id] = {location={britishHomeCities,germanHomeCites}}
local britishAndGermanHomeCities = {}
for __,loc in pairs(britishHomeCities) do
britishAndGermanHomeCities[#britishAndGermanHomeCities+1] = loc
end
for __,loc in pairs(germanHomeCities) do
britishAndGermanHomeCities[#britishAndGermanHomeCities+1] = loc
end
improvementBuild[object.iCivilianPopulation.id] = {location=britishAndGermanHomeCities}
-- gen.mergeTableValues(table,table,...) --> table
-- accepts an arbitrary number of tables as
-- arguments and returns a table with all
-- the values from all the tables.
-- Table keys are lost, and replaced by
-- integers starting at 1.
-- Duplicate values will appear multiple times
Believe it or not, I was working on the same functionality at the same time! So naturally I had to take a look at what you posted to see how it compared. You found a few corner cases like the city square one that I didn't realize, and you added support for a lot of non-standard ocean tile improvements. Very thorough job, congratulations.I just updated the template repository.
The beforeProduction event has been implemented and linked to the template, as has onCalculateCityYield.
The General Library now has functions to calculate a city's production from the land (which was necessary to have in order to allow terrain production changes to happen within the cityYield event).
...
I'm pretty sure I captured everything, but if you find an anomaly, please let me know. I never knew that a city square will count as having a mine if there is a mineBonus, but the irrigationBouns is 0. I only discovered this while testing on Imperialism. I think in the base game that would only come up for mountain terrain, and in Classic/MGE, I'm pretty sure the mountain had a food bonus of 1, even though it couldn't be irrigated.
Believe it or not, I was working on the same functionality at the same time! So naturally I had to take a look at what you posted to see how it compared. You found a few corner cases like the city square one that I didn't realize, and you added support for a lot of non-standard ocean tile improvements. Very thorough job, congratulations.
The only thing that I didn't find in your code was handling for pollution. That reduces the yield of a tile by 50%, and I think the reduction is rounded down, so the yield is rounded up. I'm not 100% sure about the timing, but I think this occurs as the very last adjustment for each tile element (food, shields, and trade). Let me know if I'm wrong though!
myVariable = "seventeen"
...drive_c\Test of Time\Template\LuaCore\generalLibrary.lua:2820:
You appear to have forgotten to put 'local' before 'myVariable' the first time you used it.
If you really did mean to make a global variable, write:
_global.myVariable
If you are trying to define a variable in the console, use the command:
console.restoreGlobal()
to restore access to global variables (locals don't work well in the console)
> civ.ui.text(myVariable)
...drive_c\Test of Time\Template\LuaCore\generalLibrary.lua:2791:
The variable name 'myVariable' doesn't match any available local variables.
Consider the following possibilities:
Is 'myVariable' misspelled?
Was 'myVariable' misspelled on the line where it was defined?
(That is, was 'local myVariable' misspelled?)
Was 'local myVariable' defined inside a lower level code block?
For example:
if x > 3 then
local myVariable = 3
else
local myVariable = x
end
print(myVariable)
If so, define 'myVariable' before the code block:
local myVariable = nil -- add this line
if x > 3 then
myVariable = 3 -- remove local from this line
else
myVariable = x -- remove local from this line
end
print(myVariable)
If you really did mean to access a global variable, write:
_global.myVariable
If you are trying to work in the console, use the command:
console.restoreGlobal()
to restore access to global variables (locals don't work well in the console)
console.onTurn()
console.beforeProduction()
console.afterProduction()
console.commands()
local legacy = require("legacyEventEngine")
local negotiationSettings = {}
local object = require("object")
function negotiationSettings.negotiation(talker,listener)
-- Britain can't initiate conversation with anyone
if talker == object.tBritain then
return false
end
-- No one can initiate conversation with britain
if listener == object.tBritain then
return false
end
-- Germany can't send an envoy to USSR
if talker == object.tGermany and listener == object.tUSSR then
return false
end
-- all other cases, they can talk, so return true
return true
end
return negotiationSettings