int CvPlayer::getProductionNeeded(BuildingTypes eBuilding) const
{
int iProductionNeeded;
CvBuildingEntry* pkBuildingInfo = GC.getBuildingInfo(eBuilding);
if(pkBuildingInfo == NULL)
{
//This should never happen.
return 1;
}
iProductionNeeded = pkBuildingInfo->GetProductionCost();
if (pkBuildingInfo->GetNumCityCostMod() > 0 && getNumCities() > 0)
{
iProductionNeeded += (pkBuildingInfo->GetNumCityCostMod() * getNumCities());
}
if (isMinorCiv())
{
iProductionNeeded *= GC.getMINOR_CIV_PRODUCTION_PERCENT();
iProductionNeeded /= 100;
}
iProductionNeeded *= GC.getBUILDING_PRODUCTION_PERCENT();
iProductionNeeded /= 100;
iProductionNeeded *= GC.getGame().getGameSpeedInfo().getConstructPercent();
iProductionNeeded /= 100;
iProductionNeeded *= GC.getGame().getStartEraInfo().getConstructPercent();
iProductionNeeded /= 100;
/// Accessor: what is the cost of researching this tech (taking all modifiers into account)
int CvTeamTechs::GetResearchCost (TechTypes eTech) const
{
CvAssertMsg(eTech != NO_TECH, "Tech is not assigned a valid value");
CvTechEntry* pkTechInfo = GC.getTechInfo(eTech);
if(pkTechInfo == NULL)
{
return 0;
}
int iCost = pkTechInfo->GetResearchCost();
CvHandicapInfo* pkHandicapInfo = GC.getHandicapInfo(m_pTeam->getHandicapType());
if(pkHandicapInfo)
{
iCost *= pkHandicapInfo->getResearchPercent();
iCost /= 100;
}
iCost *= GC.getMap().getWorldInfo().getResearchPercent();
iCost /= 100;
iCost *= GC.getGame().getGameSpeedInfo().getResearchPercent();
iCost /= 100;
iCost *= GC.getGame().getStartEraInfo().getResearchPercent();
iCost /= 100;
iCost *= std::max(0, ((GC.getTECH_COST_EXTRA_TEAM_MEMBER_MODIFIER() * (m_pTeam->getNumMembers() - 1)) + 100));
iCost /= 100;
return std::max(1, iCost);
}
Via the CvHandicapInfo data - this is the difficulty the player has selected. If your code needs to differentiate human/AI players, use the isHuman() method on the CvPlayer objectthough it's not clear to me how it identifies whether you're a human or not
function UnrestEventOccurs()
for i = 0, pCity:GetNumCityPlots() - 1, 1 do
local pPlot = pCity:GetCityIndexPlot (i)
local PlotOccupationNum = pPlot:GetNumUnits()
if pPlot:IsMountain(0) and pPlot: IsCity(0) and pPlot:IsImpassible(false) and pPlot:IsWater(0) and PlotOccupationNum < 1 then --is plot not a mountain/city/impassible/water/occupied?
table.insert(openPlots, pPlot) --(Thanks Gedemon!)
end
end
Shuffle(openPlots) --(Thanks Gedemon!)
if RevoltOccurs() = true and pCity:GetResistanceTurns() == 0 then --makes sure city is not already resisting, don't want to add more resistance to already resisting city
pCity:ChangeResistanceTurns(1) --gives city 1 turn of resistance
end
if RebellionOccurs() = true then
local openPlots = {}
for n, pPlot in pairs(openPlots) do --spawn units (between 1 to 5 depending upon city size)
for i= NumRebel, 0, -1 do
BARBARIAN:InitUnit(SelectedUnitType, pPlot:GetX(), p:GetY(), UNITAI_ATTACK)
end
if RevolutionOccurs() = true then
Controls.RevolutionPopup:SetHide(false) --triggers revolution popup
RevCS:AcquireCity:(pCity, false, true)
if city:GetResistanceTurns() > 0 then --prevents new city from having resistance for City State (Thanks Gedemon)
city:ChangeResistanceTurns(-city:GetResistanceTurns())
end
if not player:IsHuman() then --prevents City State from Razing or Puppeting (Thanks Gedemon)
city:SetPuppet(false)
if city:IsRazing() then
city:DoTask(TaskTypes.TASK_UNRAZE, -1, -1, -1)
end
end
if city:IsOccupied() then --prevents new city being "occupied" by City State (Thanks Gedemon)
city:SetOccupied(false)
end
for CivilWar = true do
pPlayerTeam:Declarewar(RevCS) --war between revolution and player
pPlayerTeam:CanChangeWarPeace(RevCS) = false --disallow peace
for n, pPlot in pairs(openPlots) do --spawn units (between 2 to 6 depending upon city size)
for i= NumRebel + 1, 0, -1 do
RevCS:InitUnit(SelectedUnitType, pPlot:GetX(), p:GetY(), UNITAI_DEFENSE)
end
end
CivilWar = false
end
for Independence = true do
pPlayer:ForcePeace(RevCS) --forces the player to be at peace with the new City State
pPlayer:DoMinorLiberationByMajor(RevCS) --New City State will be happy with player for being granted independence rather than civil war
RevCS:WasResurrectedThisTurnBy(pPlayer)
for n, pPlot in pairs(openPlots) do --spawn units (between 0 to 4 depending upon city size)
for i= NumRebel - 1, 0, -1 do
RevCS:InitUnit(SelectedUnitType, pPlot:GetX(), p:GetY(), UNITAI_DEFENSE)
end
end
Independence = false
end
Hey all! I'm working on my first mod and was wondering if anyone wouldn't mind looking over some of my lua and giving me some constructive feedback. This is my first experience with lua, so I'm sure that I'm missing some things or making rookie mistakes. Appreciate it!
pPlot:IsMountain(0)
pPlot: IsCity(0)
pPlot:IsImpassible(false)
pPlot:IsImpassable() == false
not pPlot:IsImpassable()
local PlotOccupationNum = pPlot:GetNumUnits()
if RevoltOccurs() == true and ...
if RevoltOccurs() and ...
for n, pPlot in pairs(openPlots) do
for _, pPlot in pairs(openPlots) do
for CivilWar = true do
pPlayerTeam:Declarewar(RevCS)
pPlayerTeam:CanChangeWarPeace(RevCS) = false --disallow peace
pPlayer:ForcePeace(RevCS)
pPlayer:DoMinorLiberationByMajor(RevCS)
RevCS:WasResurrectedThisTurnBy(pPlayer)
for Independence = true do
--[..] snipped code
Independence = false
end
I've been using Whoward's Cheatsheets (though I've also added the Lua methods introduced in VMC manually)What cheatsheet/documentation is available for beginners like me.
I'm currently interested in trying to add some new variables to City-State interactions, particularly when meeting them for the first time; however from looking through the base code, the idea on how to implement this feature is a bit over my head (I can work .Lua okay, but translating C++ from the .DLL to .Lua is currently beyond me).
Basically what I'm hoping for is that when a player meets a City-State for the first time, the player receives an additional bonus based on whether they're the first player to meet the City-State or not, but also based on it's Trait.
A rundown of what I had in mind:
Cultured City-States - provide 20 Culture to the first player that meets them (10 to everyone else).
Maritime City-States - provide a +1 Population increase in the nearest City of the first player that meets them (ala the Goody Hut; also everyone else would get nothing or perhaps a slight one-time Food boost in their nearest City, maybe 25%).
Mercantile City-States - provide twice as much Gold when meeting them (60 Gold for first player, 30 for everyone else).
Militaristic City-States - provide +10 Experience Points to the closest Combat Unit owned by the first player to meet them (+5 XP for the closest unit for everyone else).
I'm hoping that these effects would bring the other 4 types of City-States in line with the Religious City-States, which provide a Faith yield when first meeting them.
If anyone can rig something like this up for me, that'd be great!
-- Runs when one team meets another
function onTeamMeet(iTeamThatWasMet, iTeamThatDiscovered)
-- do stuff here
end
GameEvents.TeamMeet.Add(onTeamMeet)
pMinorPlayer:GetMinorCivTrait()
pPlayer:ChangeGold(..)
pPlayer:ChangeJONSCulture(..)
pCity:ChangeFood(..) -- can always be the capital city or the nearest city can be found by looping over all of a player's cities
pCity:ChangePopulation(..) -- can always be the capital city or the nearest city can be found by looping over all of a player's cities
pUnit:ChangeExperience(..) -- finding the nearest unit can be done by looping over all of a player's units
MINOR_CIV_CONTACT_GOLD_FIRST
MINOR_CIV_CONTACT_GOLD_OTHER
Hi! I'm new to modding and am making my first civ.
[..]
Also, part of my civ's UA is giving +35% Combat Strength (through a promotion) to units standing on a tile that belongs to a city that follows the civ's religion.
[..]
local bHasCreatedReligino = pPlayer:HasCreatedReligion() -- should be called before pPlayer:GetReligionCreatedByPlayer()
local eReligion = pPlayer:GetReligionCreatedByPlayer() -- note that this will return 0 for a "pantheon religion" (unsure what the behaviour would be if the player has not created a religion)
local eReligion = pCity:GetReligiousMajority() -- note that this will return 0 for a "pantheon religion" (and I assume -1 if there is no majority religion)
local pPlot = pUnit:GetPlot()
local iCity = pPlot:GetCityPurchaseID()
GameEvents.PlayerDoTurn(..) -- loop over all units, and give/remove the promotion (less laggy option, but only applies at the start of a player's turn)
GameEvents.UnitSetXY(..) -- give/remove the promotion for a single unit (laggy option, as this fires for every unit that moves, but does apply instantly)
local civilisationID = GameInfoTypes["CIVILIZATION_SERTAO"]
local UAPromotion = GameInfoTypes["PROMOTION_SERTAO_RELIGION_PROMOTION"]
local HasCreatedReligion = player:HasCreatedReligion()
local PlayerReligion = player:GetReligionCreatedByPlayer()
local CityReligion = City:GetReligiousMajority()
local Unit = player:GetUnitByID(UnitID)
local Plot = Unit:GetPlot()
local City = Plot:GetCityPurchaseID()
--
function IsCivActive(civilisationID)
for iSlot = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
local slotStatus = PreGame.GetSlotStatus(iSlot)
if (slotStatus == SlotStatus["SS_TAKEN"] or slotStatus == SlotStatus["SS_COMPUTER"]) then
if PreGame.GetCivilization(iSlot) == civilisationID then
return true
end
end
end
return false
end
--
function CombatBonus(PlayerID, UnitID)
local player = Players[PlayerID]
if player:GetCivilizationType() == civilisationID then
if HasCreatedReligion then
if PlayerReligion == CityReligion then
Unit:SetHasPromotion(UAPromotion, true)
else
Unit:SetHasPromotion(UAPromotion, false)
end
end
end
end
--
if IsCivActive(civilisationID) then
GameEvents.UnitSetXY.Add(CombatBonus)
end