jarcast
Chieftain
I'm creating the uniques for a civ but I'm not sure I wrote the code correctly because of noobness.
The idea for the building is that starting from the Modern Era it gives +1 tourism per each trade route incoming or outgoing the city. I read various topics about the non-stacking tourism issue and tried to solve it following this, so i'd like to know if the syntax is right.
Regarding the unit, i gave it these promotions:
1) Civilian within: +1 production in the city where garrisoned
LUA
XML dummy building
2) Homeland Claimant: +25% combat strenght in originally owned territory
??? = I don't know how to code "or if the plot where the unit attacks was originally owned by the Player"
I read I have to make the game recording the history of the cities using these:
SerialEventCityCreated
SerialEventCityCaptured
SerialEventCityDestroyed
but I have no idea how to use them. Any suggestion?
EDIT: i solved the quaestio by myself: i found on the modiki there actually exists a function named "GetOriginalOwner". I presume that it should answer my question.
Let's add other irons in the fire: the UA.
1) Harbor-connected cities receive 20% Culture produced by the Capital.
2) Naval Units grants Science equal to 5% of their Production cost.
Thank you in advance
The idea for the building is that starting from the Modern Era it gives +1 tourism per each trade route incoming or outgoing the city. I read various topics about the non-stacking tourism issue and tried to solve it following this, so i'd like to know if the syntax is right.
Spoiler :
Code:
function toBits(num)
t={} -- will contain the bits
while num>0 do
local rest=math.fmod(num,2)
t[#t+1]=rest
num=(num-rest)/2
end
return t
end
function UBTourismFromTradeRoute(playerID)
local iCiv = GameInfoTypes["CIVILIZATION_TWOSICILIES"]
local pPlayer = Players[playerID]
local iBuildingA = GameInfoTypes.BUILDING_UNIQUE
local iBuildingB = GameInfoTypes.BUILDING_DUMMY
local bDummy1 = GameInfoTypes.BUILDING_DUMMY_TOURISM_1;
local bDummy2 = GameInfoTypes.BUILDING_DUMMY_TOURISM_2;
local bDummy4 = GameInfoTypes.BUILDING_DUMMY_TOURISM_4;
local bDummy8 = GameInfoTypes.BUILDING_DUMMY_TOURISM_8;
local bDummy16 = GameInfoTypes.BUILDING_DUMMY_TOURISM_16;
local OutgoingTR = player:GetTradeRoutes()
local IncomingTR = player:GetTradeRoutesToYou()
local num = ( #OutgoingTR + #IncomingTR)
if pPlayer:IsAlive() and pPlayer:GetCivilizationType() == iCiv then
if (iEraPrereq ~= nil and pTeam:GetCurrentEra() < iEraPrereq) then
for pCity in pPlayer:Cities() do
if city:IsHasBuilding(iBuildingA) then
pCity:SetNumRealBuilding(iBuildingB, num);
pCity:SetNumRealBuilding(bDummy1, t[1]);
pCity:SetNumRealBuilding(bDummy2, t[2]);
pCity:SetNumRealBuilding(bDummy4, t[3]);
pCity:SetNumRealBuilding(bDummy8, t[4]);
pCity:SetNumRealBuilding(bDummy16, t[5]);
pCity:SetNumRealBuilding(bDummy32, t[6]);
pCity:SetNumRealBuilding(bDummy64, t[7]);
pCity:SetNumRealBuilding(bDummy128, t[8]);
end
end
end
GameEvents.PlayerDoTurn.Add(UBTourismFromTradeRoute)
Regarding the unit, i gave it these promotions:
1) Civilian within: +1 production in the city where garrisoned
LUA
Spoiler :
Code:
function CivilianWithin(playerID)
local bBRIGANTE = GameInfoTypes.BUILDING_BRIG_PROD
local player = Players[playerID]
if (player:GetCivilizationType() == iCiv and player:IsAlive()) then
for city in player:Cities() do
if (city:GetNumBuilding(bBRIGANTE) > 0) then
city:SetNumRealBuilding(bBRIGANTE, 0);
end
if city:GetGarrisonedUnit():IsHasPromotion(GameInfoTypes["PROMOTION_CIVILIAN_WITHIN"]) then
city:SetNumRealBuilding(bBRIGANTE, 1);
end
end
end
end
end
GameEvents.PlayerDoTurn.Add(CivilianWithin)
XML dummy building
Spoiler :
Code:
<GameData>
<BuildingClasses>
<Row>
<Type>BUILDINGCLASS_BRIG_PROD</Type>
<DefaultBuilding>BUILDING_BRIG_PROD</DefaultBuilding>
<Description>@@@@</Description>
</Row>
</BuildingClasses>
<Buildings>
<Row>
<Type>BUILDING_BRIG_PROD</Type>
<BuildingClass>BUILDINGCLASS_BRIG_PROD</BuildingClass>
<Cost>-1</Cost>
<PrereqTech>NONE</PrereqTech>
<Description>####</Description>
<ArtDefineTag>ART_DEF_BUILDING_FORGE</ArtDefineTag>
<GreatWorkCount>-1</GreatWorkCount>
<NukeImmune>true</NukeImmune>
<HurryCostModifier>-1</HurryCostModifier>
<MinAreaSize>-1</MinAreaSize>>
<NeverCapture>true</NeverCapture>
<IconAtlas>CIV_###_ATLAS</IconAtlas>
<PortraitIndex>0</PortraitIndex>
</Row>
</Buildings>
<Building_YieldChanges>
<Row>
<BuildingType>BUILDING_BRIG_PROD</BuildingType>
<YieldType>YIELD_PRODUCTION</YieldType>
<Yield>1</Yield>
</Row>
</Building_YieldChanges>
</GameData>
2) Homeland Claimant: +25% combat strenght in originally owned territory
Spoiler :
Code:
function HomelandClaimant(iPlayer)
local pPlayer = Players[iPlayer]
for pUnit in pPlayer:Units() do
if pUnit:IsHasPromotion(GameInfoTypes["PROMOTION_HOMELAND_CLAIMANT") then
local unitplot = pUnit:GetPlot()
local iStrength = GameInfo.Units[pUnit:GetUnitType()].Combat
if (unitplot:Get[B][COLOR="Red"]Original[/COLOR][/B]Owner() == iPlayer [S]or [B]???[/B] [/S]) then
pUnit:SetBaseCombatStrength(iStrenght * 1.25)
end
end
end
end
GameEvents.PlayerDoTurn.Add(HomeClaimant)
I read I have to make the game recording the history of the cities using these:
SerialEventCityCreated
SerialEventCityCaptured
SerialEventCityDestroyed
but I have no idea how to use them. Any suggestion?
EDIT: i solved the quaestio by myself: i found on the modiki there actually exists a function named "GetOriginalOwner". I presume that it should answer my question.
Let's add other irons in the fire: the UA.
1) Harbor-connected cities receive 20% Culture produced by the Capital.
Spoiler :
Code:
function CultureSeaConnection(iPlayer)
if (player:GetCivilizationType() == GameInfo.Civilizations["CIVILIZATION_TWOSICILIES"].ID and player:IsAlive()) then
local pCapital = pPlayer:GetCapitalCity()
local iCulture = pCapital:GetCulturePerTurn()
for pcity in pPlayer:Cities() do
if (pcity:IsHasBuilding(GameInfoTypes["BUILDING_HARBOR"])) then
pCity:ChangeJONSCultureLevel(0.2 * iCulture)
end
end
end
2) Naval Units grants Science equal to 5% of their Production cost.
Spoiler :
Code:
function ScienceFromShip(iPlayer)
local pPlayer = Players[iPlayer]
if (player:GetCivilizationType() == iCiv and player:IsAlive()) then
local domain = pUnit:GetDomainType()
local sea = DomainTypes.DOMAIN_SEA
for pUnit in pPlayer:Units() do
if (domain == sea) then
local iprodcost = GameInfo.Units[pUnit:GetUnitType()].Cost
local iMod = ((GameInfo.GameSpeeds[Game.GetGameSpeedType()].BuildPercent)/100)
local ScienceBoost = 0.05 * iprodcost * iMod
local CurrenTech = pPlayer:GetCurrentResearch()
local fTeamID = pPlayer:GetTeam();
local fTeam = Teams[fTeamID];
local fTeamTechs = fTeam:GetTeamTechs();
fTeamTechs:ChangeResearchProgress(CurrenTech, ScienceBoost, iPlayer)
end
end
end
Thank you in advance