Thanks again FramedArchitect, this works perfectly. I have now uploaded my mod. If anyone wants to check it out you can download it here.
Thanks again FramedArchitect, this works perfectly. I have now uploaded my mod. If anyone wants to check it out you can download it here.
local IMPROVEMENT_CITADEL_ID = GameInfoTypes.IMPROVEMENT_CITADEL
local TestCityCanConstruct = {}
local function OnCityCanConstruct(iPlayer, iCity, buildingTypeID)
if TestCityCanConstruct[buildingTypeID] then
return TestCityCanConstruct[buildingTypeID](iPlayer, iCity)
end
return true
end
GameEvents.CityCanConstruct.Add(OnCityCanConstruct)
TestCityCanConstruct[GameInfoTypes.BUILDING_MY_NEW_BUILDING] = function(iPlayer, iCity)
local player = Players[iPlayer]
local city = player:GetCityByID(iCity)
local totalPlots = city:GetNumCityPlots()
for i = 0, totalPlots - 1 do
local plot = city:GetCityIndexPlot(i)
if plot and plot:GetOwner() == iPlayer and plot:GetImprovementType() == IMPROVEMENT_CITADEL_ID and plot:GetWorkingCity() == city then
return true
end
end
return false
end
Sure thing. Although we'll have to ask Gedemon to change the title of the Tutorial.Pazyryk, would you be willing to update this with DLL information as well (adding tags through SQL, then loading them using the DLL)? If I wrote the section?
It may be worth writing a separate tutorial, however, since Lua -> DLL modding is a big step for many, just like XML -> XML+Lua is a big step. If you do feel free to copy anything from this thread.
I wanted to make a separate table in the database to hold the stacking classes in my DLL, but when I've started to look at how to implement that, I've sundenly decided that 2 columns in an existing table was more than enough !
-- Add VassalageEnabled (boolean), default false, into the Eras table
ALTER TABLE Eras ADD VassalageEnabled boolean DEFAULT 0;
-- Update the Medieval Era to now include VassalageEnabled. This is equivalent to <VassalageEnabled>true</VassalageEnabled>
UPDATE Eras SET 'VassalageEnabled' = 1 WHERE Type = 'ERA_MEDIEVAL';
// public:
bool getVassalageEnabled() const;
// protected:
bool m_bVassalageEnabled;
// CvEraInfo::CacheResults()
// This code reads in from your XML value and stores it in the m_bVassalageEnabled variable
m_bVassalageEnabled = kResults.GetBool("VassalageEnabled");
// This function returns the VassalageEnabled
bool CvEraInfo::getVassalageEnabled() const
{
return m_bVassalageEnabled;
}
// This code will grant the user the ability to use vassalage upon entering the era which grants Vassalage (meaning all you have to do is change which era does this in the XML.
if(pEraInfo->getVassalageEnabled())
{
if(!GC.getGame().isOption(GAMEOPTION_NO_VASSALAGE))
{
changeVassalageTradingAllowedCount(1);
// Send notification to team
PlayerTypes ePlayer;
for(int iPlayerLoop = 0; iPlayerLoop < MAX_MAJOR_CIVS; iPlayerLoop++)
{
ePlayer = (PlayerTypes) iPlayerLoop;
if(GET_PLAYER(ePlayer).getTeam() != GetID())
{
continue;
}
if(GET_PLAYER(ePlayer).GetID() == GC.getGame().getActivePlayer())
{
CvNotifications* pNotifications = GET_PLAYER(ePlayer).GetNotifications();
if(pNotifications)
{
CvEraInfo* pkEraInfo = GC.getEraInfo(eNewValue) ;
const char* szEra = pkEraInfo->GetTextKey();
CvString strBuffer = GetLocalizedText("TXT_KEY_NOTIFICATION_VASSALAGE_ALLOWED", szEra);
CvString strSummary = GetLocalizedText("TXT_KEY_NOTIFICATION_SUMMARY_VASSALAGE_ALLOWED");
pNotifications->Add(NOTIFICATION_GENERIC, strBuffer, strSummary, -1, -1, 0);
}
}
}
}
}
You have to be very careful about this sort of thing. The game engine will run this test many times in a turn, which could impact game speed.
But here's some code that ought to do what you want (not tested):
Code:local IMPROVEMENT_CITADEL_ID = GameInfoTypes.IMPROVEMENT_CITADEL local TestCityCanConstruct = {} local function OnCityCanConstruct(iPlayer, iCity, buildingTypeID) if TestCityCanConstruct[buildingTypeID] then return TestCityCanConstruct[buildingTypeID](iPlayer, iCity) end return true end GameEvents.CityCanConstruct.Add(OnCityCanConstruct) TestCityCanConstruct[GameInfoTypes.BUILDING_MY_NEW_BUILDING] = function(iPlayer, iCity) local player = Players[iPlayer] local city = player:GetCityByID(iCity) local totalPlots = city:GetNumCityPlots() for i = 0, totalPlots - 1 do local plot = city:GetCityIndexPlot(i) if plot and plot:GetOwner() == iPlayer and plot:GetImprovementType() == IMPROVEMENT_CITADEL_ID and plot:GetWorkingCity() == city then return true end end return false end
It's coded so that you can easily add other building tests (as separate functions) as I did for BUILDING_MY_NEW_BUILDING.
Note that this doesn't run exactly like Civ5 resource checks. The problem is that "working city" does not equal "owning city". There is actually no way to get owning city in Lua, unfortunately. If you want the building to be allowed for all cities that have the cititel in their 3-plot radius, just remove "and plot:GetWorkingCity() == city" from above code.
print("OnCityCanConstruct: ", iPlayer, iCity, buildingTypeID)
print("Loading my Lua file XXX")