Danmacsch
Geheimekabinetsminister
Hi,
I'm having some trouble with my lua code and hope some one can help me.
The first problem I have is with the following code. It's suppose to detect for each of the player's cities when a citadel is founded and then build the dummy building BUILDING_CORSICAN_CITADEL_TOURISM in the respective city. I think this works. What I would also like to add - and don't know how to - is the following:
1) when constructing more citadels in a city's area, the number of dummy buildings should rise accordingly.
2) restrict the code to citadels constructed on a tile within the empire's territory.
3) if the tile on which the citadel is constructed is annexed by another civilization the number of dummy buildings is decreased.
The next problem that I have is somewhat similar. It's with the following code. I'm trying to detect if a tile in a city's area has a citadel constructed AND then also if there's a specific unit (my civ's UU which has a unique promotion) garrisoned on the citadel. If this is the case, then the dummy building BUILDING_CORSICAN_FOODCULTURE_BONUS should be build in the respective city. This doesn't seem to work at all and I don't know why.
1) If more citadels with the specific unit garrisoned on it is within a city's area, the number of dummy buildings should rise accordingly.
2) If the unit is removed from the citadel the number of dummy buildings should fall accordingly.
The last thing (for now) is something that I haven't really tested yet, so I don't know if it actually works. A part of my civs UA is that when a lost city is completely re-captured a great general should appear.
Bear in mind this is the first time I'm used lua, so please don't assumed I know very much
I'm having some trouble with my lua code and hope some one can help me.
The first problem I have is with the following code. It's suppose to detect for each of the player's cities when a citadel is founded and then build the dummy building BUILDING_CORSICAN_CITADEL_TOURISM in the respective city. I think this works. What I would also like to add - and don't know how to - is the following:
1) when constructing more citadels in a city's area, the number of dummy buildings should rise accordingly.
2) restrict the code to citadels constructed on a tile within the empire's territory.
3) if the tile on which the citadel is constructed is annexed by another civilization the number of dummy buildings is decreased.
Spoiler :
Lua code:
Relevant sql:
Code:
function CitadelTourism(playerID)
local player = Players[playerID]
if player:IsAlive() and player:GetCivilizationType() == civilizationID then
for city in player:Cities() do
local cityPlot = 0, city:GetNumCityPlots() -1, 1
local plot = city:GetCityIndexPlot(cityPlot)
if plot:GetOwner() == civilisationID then
if plot:GetImprovementType() == GameInfoTypes["IMPROVEMENT_CITADEL"] then
city:SetNumRealBuilding(GameInfoTypes["BUILDING_CORSICAN_CITADEL_TOURISM"], 1)
end
end
end
end
end
GameEvents.PlayerDoTurn.Add(CitadelTourism)
Code:
INSERT INTO BuildingClasses
(Type, DefaultBuilding, Description)
VALUES ('BUILDINGCLASS_CORSICAN_CITADEL_TOURISM', 'BUILDING_CORSICAN_CITADEL_TOURISM', 'TXT_KEY_BUILDING_CORSICAN_CITADEL_TOURISM'),
('BUILDINGCLASS_CORSICAN_FOODCULTURE_BONUS', 'BUILDING_CORSICAN_FOODCULTURE_BONUS', 'TXT_KEY_BUILDING_CORSICAN_FOODCULTURE_BONUS');
--==========================================================================================================================
-- Buildings
--==========================================================================================================================
INSERT INTO Buildings
(Type, SpecialistType, SpecialistCount, GoldMaintenance, PrereqTech, BuildingClass, Cost, FaithCost, Happiness, NukeImmune, MinAreaSize, NeverCapture, Description, Civilopedia, Help, Strategy, PortraitIndex, IconAtlas)
SELECT ('BUILDING_CASEDDU'), 'SPECIALIST_CORSICAN_GENERAL', 3, 1, PrereqTech, BuildingClass, 200, -1, 1, NukeImmune, MinAreaSize, 1, ('TXT_KEY_BUILDING_CASEDDU_DESC'), ('TXT_KEY_BUILDINGS_CASEDDU_PEDIA'), ('TXT_KEY_BUILDING_CASEDDU_HELP'), ('TXT_KEY_BUILDINGS_CASEDDU_STRATEGY'), 3, ('CORSICA_ATLAS')
FROM Buildings WHERE (Type = 'BUILDING_THEATRE');
INSERT INTO Buildings
(Type, BuildingClass, EnhancedYieldTech, TechEnhancedTourism, GreatWorkCount, Cost, FaithCost, PrereqTech, Description, Help)
Values ('BUILDING_CORSICAN_CITADEL_TOURISM', 'BUILDINGCLASS_CORSICAN_CITADEL_TOURISM' 'TECH_PRINTING_PRESS', 2, -1, -1, -1, null, 'TXT_KEY_BUILDING_CORSICAN_CITADEL_TOURISM', 'TXT_KEY_BUILDING_CORSICAN_CITADEL_TOURISM_HELP'),
('BUILDING_CORSICAN_FOODCULTURE_BONUS', 'BUILDINGCLASS_CORSICAN_FOODCULTURE_BONUS' null, 0, -1, -1, -1, null, 'TXT_KEY_BUILDING_CORSICAN_FOODCULTURE_BONUS', 'TXT_KEY_BUILDING_CORSICAN_FOODCULTURE_BONUS_HELP');
The next problem that I have is somewhat similar. It's with the following code. I'm trying to detect if a tile in a city's area has a citadel constructed AND then also if there's a specific unit (my civ's UU which has a unique promotion) garrisoned on the citadel. If this is the case, then the dummy building BUILDING_CORSICAN_FOODCULTURE_BONUS should be build in the respective city. This doesn't seem to work at all and I don't know why.
1) If more citadels with the specific unit garrisoned on it is within a city's area, the number of dummy buildings should rise accordingly.
2) If the unit is removed from the citadel the number of dummy buildings should fall accordingly.
Spoiler :
Lua code:
Relevant sql (see the first spoiler for the rest):
Code:
function CityFoodCultureBonus(playerID)
local player = Players[playerID]
if player:IsAlive() and player:GetCivilizationType() == civilizationID then
for city in player:Cities() do
local cityPlot = 0, city:GetNumCityPlots() -1, 1
local plot = city:GetCityIndexPlot(cityPlot)
if plot:GetOwner() == civilisationID then
if plot:GetImprovementType() == GameInfoTypes["IMPROVEMENT_CITADEL"] and unit:IsHasPromotion(GameInfoTypes["PROMOTION_PAOLI_TROOP"]) then
city:SetNumRealBuilding(GameInfoTypes["BUILDING_CORSICAN_FOODCULTURE_BONUS"], 1)
end
end
end
end
end
GameEvents.PlayerDoTurn.Add(CityFoodCultureBonus)
Code:
--==========================================================================================================================
-- Building_YieldChanges
--==========================================================================================================================
INSERT INTO Building_YieldChanges
(BuildingType, YieldType, Yield)
VALUES ('BUILDING_CORSICAN_FOODCULTURE_BONUS', 'YIELD_FOOD', 2),
('BUILDING_CORSICAN_FOODCULTURE_BONUS', 'YIELD_CULTURE', 4);
The last thing (for now) is something that I haven't really tested yet, so I don't know if it actually works. A part of my civs UA is that when a lost city is completely re-captured a great general should appear.
Spoiler :
Code:
function CityRecaptureGreatGeneral(playerID)
if GameEvents.CityCaptureComplete(civilisationID) then
player:AddFreeUnit(GameInfoTypes['UNIT_GREAT_GENERAL'], 1)
end
end
Bear in mind this is the first time I'm used lua, so please don't assumed I know very much