[GS] Builder - Combine/rewrite lua/sql?

Venemar

Chieftain
Joined
Feb 21, 2021
Messages
8
I'm using a builder mod off steam built with sql that makes builders ignore terrain, adds movement, a few more charges and some QoL improvements.

There's another mod I like that has the builder create a road as he moves, but that one is done in lua.

Is it possible to merge the two concepts into one? I'm learning a bit of sql as I go, but this lua is beyond me. Posting the relevant sections below. **edit to add** Would it be possible to have the build roads as he go be turned on/off so you can be selective about where the roads are placed?

SQL:

UPDATE Units SET BaseMoves = 4, BuildCharges = 6 WHERE UnitType = 'UNIT_BUILDER';
UPDATE Features SET AddCivic = 'CIVIC_STATE_WORKFORCE' WHERE FeatureType = 'FEATURE_FOREST';
UPDATE Features SET RemoveTech = NULL WHERE Removable = 1;
UPDATE Resource_Harvests SET PrereqTech = NULL;

-- Ignore Terrain Cost
INSERT INTO Types (Type, Kind) VALUES
('MODIFIER_BUILDER_IGNORE_TERRAIN_COST', 'KIND_MODIFIER');
INSERT INTO DynamicModifiers (ModifierType, CollectionType, EffectType) VALUES
('MODIFIER_BUILDER_IGNORE_TERRAIN_COST', 'COLLECTION_PLAYER_UNITS', 'EFFECT_ADJUST_UNIT_IGNORE_TERRAIN_COST');
INSERT INTO TraitModifiers (TraitType, ModifierId) VALUES
('TRAIT_LEADER_MAJOR_CIV', 'BUILDER_IGNORE_TERRAIN'),
('TRAIT_LEADER_MAJOR_CIV', 'BUILDER_IGNORE_RIVERS'),
('TRAIT_LEADER_MAJOR_CIV', 'BUILDER_IGNORE_EMBARK');
INSERT INTO Modifiers (ModifierId, ModifierType, Permanent, SubjectRequirementSetId) VALUES
('BUILDER_IGNORE_TERRAIN', 'MODIFIER_BUILDER_IGNORE_TERRAIN_COST', 1, 'BUILDER_SPEED_REQSET'),
('BUILDER_IGNORE_RIVERS', 'MODIFIER_PLAYER_UNITS_ADJUST_IGNORE_RIVERS', 1, 'BUILDER_SPEED_REQSET'),
('BUILDER_IGNORE_EMBARK', 'MODIFIER_PLAYER_UNITS_ADJUST_IGNORE_SHORES', 1, 'BUILDER_SPEED_REQSET');
INSERT INTO ModifierArguments (ModifierId, Name, Value) VALUES
('BUILDER_IGNORE_TERRAIN', 'Ignore', 1),
('BUILDER_IGNORE_TERRAIN', 'Type', 'ALL'),
('BUILDER_IGNORE_RIVERS', 'Ignore', 1),
('BUILDER_IGNORE_EMBARK', 'Ignore', 1);
INSERT INTO RequirementSets (RequirementSetId, RequirementSetType) VALUES
('BUILDER_SPEED_REQSET', 'REQUIREMENTSET_TEST_ALL');
INSERT INTO RequirementSetRequirements (RequirementSetId, RequirementId) VALUES
('BUILDER_SPEED_REQSET', 'REQUIRES_UNIT_IS_BUILDER');
INSERT INTO Requirements (RequirementId, RequirementType, Inverse) VALUES
('REQUIRES_UNIT_IS_BUILDER', 'REQUIREMENT_UNIT_TYPE_MATCHES', 0);
INSERT INTO RequirementArguments (RequirementId, Name, Value) VALUES
('REQUIRES_UNIT_IS_BUILDER', 'UnitType', 'UNIT_BUILDER');

Lua:

playerTraitsCache = {};
function OnUnitMoved(playerId:number, unitId:number, tileX, tileY)
local player = Players[playerId];
local unit = player:GetUnits():FindID(unitId);
local unitType = GameInfo.Units[unit:GetType()];

if (unitType.UnitType == "UNIT_BUILDER") then
print(tileX, tileY);

local plot = Map.GetPlot(tileX, tileY);

if (not plot:IsWater()) then
local buildingRouteType = GetPlayerRouteType(player);
local currentRouteType = plot:GetRouteType();

if currentRouteType == -1 or buildingRouteType.PlacementValue > GameInfo.Routes[currentRouteType].PlacementValue then
RouteBuilder.SetRouteType(plot, buildingRouteType.Index);
end
end
end
end
function getPlayerTraits(playerId: number)
local result = {};
local playerConfig = PlayerConfigurations[playerId];

-- Civ Trait
local playerCiv = playerConfig:GetCivilizationTypeName();
for row in GameInfo.CivilizationTraits() do
if (row.CivilizationType == playerCiv) then
result[row.TraitType] = true;
end
end

-- Leader Trait
local playerLeader = playerConfig:GetLeaderTypeName();
for row in GameInfo.LeaderTraits() do
if (row.LeaderType == playerLeader) then
result[row.TraitType] = true;
end
end

return result;
end
function GetPlayerRouteType(player)
local route = nil;
local playerEra = GameInfo.Eras[player:GetEra()];

for routeType in GameInfo.Routes() do
if route == nil then
route = routeType;
else
if (route.PlacementValue < routeType.PlacementValue) then
local canBuild = true;

-- Era requirement
local prereq_era = GameInfo.Eras[routeType.PrereqEra];
if prereq_era and playerEra.ChronologyIndex < prereq_era.ChronologyIndex then
canBuild = false;
end

-- Tech requirement
if canBuild and GameInfo.Routes_XP2 then
local routeXp2 = GameInfo.Routes_XP2[routeType.RouteType];

if (routeXp2 and routeXp2.PrereqTech) then
local playerTech = player:GetTechs();
local requiredTech = GameInfo.Technologies[routeXp2.PrereqTech];

if not playerTech:HasTech(requiredTech.Index) then
canBuild = false;
end
end
end

if (canBuild) then
route = routeType;
end
end
end
end

-- See if player has TRAIT_CIVILIZATION_SATRAPIES trait
local playerId = player:GetID();
if (not playerTraitsCache[playerId]) then
playerTraitsCache[playerId] = getPlayerTraits(playerId);
end

if (playerTraitsCache[playerId]["TRAIT_CIVILIZATION_SATRAPIES"]) then
-- See if there is a road with higher placement value
for routeType in GameInfo.Routes() do
if (routeType.PlacementValue == route.PlacementValue + 1) then
route = routeType;
break;
end
end
end

return route;
end
Events.UnitMoved.Add(OnUnitMoved);
 
Top Bottom