C++/Lua Request Thread

thanks a lot, since I managed to work around it I'll wait until I have another issue with it, something weird to me is that interfacemodes, lets say you create a new one, it gets the id 24 (-1 is error, 0 is debug, and the first game value is 1 and it goes all the way to 23) but once it gets assigned to a variable to use (lua or dll) it uses id minus 1 (they are probably dropping the debug one somewhere and I never found it). So whenever I was setting or testing for my id as-is, everything went wrong (a trade route interfacemode is 23 so I guess that's why the button showed on caravans).

I feel xml/sql should be loaded first, then dll (because it can have inits that depend on the modified tables) then lua, but I dont know how it goes.

I also solved this differently, but is there a way to include a lua file into the VFS but not have it execute? I wanted to add a new file for UI Generic Popup to include (it includes files dynamically when it loads), and that loaded, but then the game would try to also load the custom lua on its own, and failed since it doesnt have includes on its own.
 
Could I have some help? I need some Lua coding done for a civ and the person who does my Lua is working on a different project with me (April Design Challenge). Just send me a PM if you're interested in helping with my first (or second :p) civ.
 
Hi all. I want to create my own take on a Civ4 inspired corporation mod whereby there are Corporate Headquarters (World Wonders) and Corporate Branches (Buildings). Unfortunately, from what I can gather, only parts of it can be achieved by XML and I'm assuming the rest is LUA, which I have very little experience with. I'm looking for three scripts or maybe just some guidance to get me started for the following:


  1. Making a World Wonder require a certain Great Person Improvement to be within city limits in order to be constructed.
  2. Making a World Wonder allow all nations to create a new type of associated building.
  3. Making a World Wonder generate a certain amount of gold a turn for every associate building built in the world.
Any assistance would be greatly appreciated.
 
Still looking for some help with this. I managed to do my UA and UU Lua myself but I have no idea how to start with this.

Passive or "Spread" pressure?
 
Well, I believe some modified DLLs have a few to reduce passive pressure, but you don't want that. So, we'll have to rely on some spread pressure. I think if the city has a majority religion, it'll spawn an inquisitor that'll automatically delete some of the heresy spawned by the prophet and missionaries. The question would be how to detect the missionary spread religion action.... Let me do some testing. However, if you can find any custom civilization that has that ability similar to yours. I believe we can "adopt" some of its coding to match your characteristic.
 
My DLL and the CP have added a column to the buildings table that acts similar to the spy reducing one for religious spread from units - see "Global - Counter Religion"
 
I'd like to increase the amount of HP healed per turn as part of a trait for a custom civilization.

According to whoward 69...

City healing is ...
CITY_HIT_POINTS_HEALED_PER_TURN (a global define)
plus 1 if a major capital
plus (additional defense from buildings / 500)
plus (additional defense from buildings * defense mod / 500)

So a major capital with walls and a castle will heal
20 + 1 + ((500 + 700) / 500) = 23 hit points per turn

A city with walls in a civ with the Red Fort will heal
20 + (500/500) + (500 * 25/100 / 500) = 21 hit points per turn

(in practice, due to rounding down, the defense mod part is irrelevant to the calculations)

So there's no way (via XML) to give extra healing to a city without also increasing it's defense dramatically.

But you can easily do it in Lua. Hook the PlayerDoTurn event, and just use pCity:ChangeDamage(-iTraitHealing)

(You don't need to check for final damage < 0 as ChangeDamage() caps the value between 0 and CityMaxHitPoints already)

We would like the formula for city healing to be...

For the capital city (with walls and castle)
20 + 1 + ((500 + 700) / 100) = 33 hit points per turn

For other cities (with walls and castle)

20 + ((500 + 700) / 100) = 32 hit points per turn

Thanks for any help.

The discussion thread for this idea is here http://forums.civfanatics.com/showthread.php?t=565541
 
I'd like to increase the amount of HP healed per turn as part of a trait for a custom civilization.

According to whoward 69...

City healing is ...
CITY_HIT_POINTS_HEALED_PER_TURN (a global define)
plus 1 if a major capital
plus (additional defense from buildings / 500)
plus (additional defense from buildings * defense mod / 500)

So a major capital with walls and a castle will heal
20 + 1 + ((500 + 700) / 500) = 23 hit points per turn

A city with walls in a civ with the Red Fort will heal
20 + (500/500) + (500 * 25/100 / 500) = 21 hit points per turn

(in practice, due to rounding down, the defense mod part is irrelevant to the calculations)

So there's no way (via XML) to give extra healing to a city without also increasing it's defense dramatically.

But you can easily do it in Lua. Hook the PlayerDoTurn event, and just use pCity:ChangeDamage(-iTraitHealing)

(You don't need to check for final damage < 0 as ChangeDamage() caps the value between 0 and CityMaxHitPoints already)

We would like the formula for city healing to be...

For the capital city (with walls and castle)
20 + 1 + ((500 + 700) / 100) = 33 hit points per turn

For other cities (with walls and castle)

20 + ((500 + 700) / 100) = 32 hit points per turn

Thanks for any help.

The discussion thread for this idea is here http://forums.civfanatics.com/showthread.php?t=565541
Based on what I understood you were actually asking for
Code:
local iRequiredCivilization = GameInfoTypes.CIVILIZATION_SOMETHING_OR_OTHER
local iSpecialBuildingDefenseHealDivisor = 100
local iStandardBuildingDefenseHealDivisor = 500
local iRatioExtraToStandardHealAmounts = 1 - (iSpecialBuildingDefenseHealDivisor/iStandardBuildingDefenseHealDivisor)


function CityExtraHealAbility(iPlayer)
	local pPlayer = Players[iPlayer]
	if pPlayer:GetCivilizationType() == iRequiredCivilization then
		for pCity in pPlayer:Cities() do
			local iCityDefense = pCity:GetBuildingDefense()
			local iExtraHealingAmount =  math.ceil((iCityDefense/SpecialBuildingDefenseHealDivisor) * iRatioExtraToStandardHealAmounts)
			pCity:ChangeDamage(-iExtraHealingAmount)
		end
	end
end
GameEvents.PlayerDoTurn.Add(CityExtraHealAbility)
  1. The coded healing is extra to what is normal, and in the example of a city with Walls and Castles, will add an extra 10 city healing
  2. You don't want to add an extra 32 or 33 healing, I don't think, so what you need is the difference between normal and total healing amount you are after
 
Based on what I understood you were actually asking for
Code:
local iRequiredCivilization = GameInfoTypes.CIVILIZATION_SOMETHING_OR_OTHER
local iSpecialBuildingDefenseHealDivisor = 100
local iStandardBuildingDefenseHealDivisor = 500
local iRatioExtraToStandardHealAmounts = 1 - (iSpecialBuildingDefenseHealDivisor/iStandardBuildingDefenseHealDivisor)


function CityExtraHealAbility(iPlayer)
	local pPlayer = Players[iPlayer]
	if pPlayer:GetCivilizationType() == iRequiredCivilization then
		for pCity in pPlayer:Cities() do
			local iCityDefense = pCity:GetBuildingDefense()
			local iExtraHealingAmount =  math.ceil((iCityDefense/SpecialBuildingDefenseHealDivisor) * iRatioExtraToStandardHealAmounts)
			pCity:ChangeDamage(-iExtraHealingAmount)
		end
	end
end
GameEvents.PlayerDoTurn.Add(CityExtraHealAbility)
  1. The coded healing is extra to what is normal, and in the example of a city with Walls and Castles, will add an extra 10 city healing
  2. You don't want to add an extra 32 or 33 healing, I don't think, so what you need is the difference between normal and total healing amount you are after

We will test it out. Thank you LeeS.
 
Would it be possible to have a UA that would do something around the lines of

On a Great Prophet spawning to have a dummy building spawn in the birth city that would last for 1 turn to give a boost in faith to the civilization on that turn alone?
 
It's the C++/Lua request thread, which pretty much covers all of the coding languages used by the game ... but regardless ... go ahead and ask, we have Java, C# and other developers here.
 
Would it be possible to have a UA that would do something around the lines of

On a Great Prophet spawning to have a dummy building spawn in the birth city that would last for 1 turn to give a boost in faith to the civilization on that turn alone?
It would actually be easier to directly adjust the player's Faith Score as soon as the Great Prophet is born.

You will have to change "CIVILIZATION_SOMETHING" to the correct tag being used for your civilization, as well as the amount stated for "iFaithOneShot"
Code:
local iFaithOneShot = 50
local iRequiredCiv = GameInfoTypes.CIVILIZATION_SOMETHING
local iGreatProphet = GameInfoTypes.UNIT_PROPHET


function GreatProphetCreated(PlayerID, UnitID, hexVec, unitType, cultureType, civID, primaryColor, secondaryColor, unitFlagIndex, fogState)
	--print("function GreatProphetCreated was executed")
	local pPlayer = Players[PlayerID]
	if pPlayer:GetCivilizationType() == iRequiredCiv then
		local pUnit = pPlayer:GetUnitByID(UnitID)
		if pUnit:GetUnitType() == iGreatProphet then
			pPlayer:ChangeFaith(iFaithOneShot)
		end
	end
end
function OnLoadScreenClose()
	--we use this to delay the sign-up to SerialEventUnitCreated until after all
	--	units have been placed from a saved game
	--this keeps the SerialEventUnitCreated from firing twice for the same unit
	for iSlot = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
		local iSlotStatus = PreGame.GetSlotStatus(iSlot)
		if (iSlotStatus == SlotStatus.SS_TAKEN or iSlotStatus == SlotStatus.SS_COMPUTER) then
			if (PreGame.GetCivilization(iSlot) == iRequiredCiv) then
				print("during OnLoadScreenClose the addition of game events was executed")
				Events.SerialEventUnitCreated.Add(GreatProphetCreated) 
				break
			end
		end
	end
	print("The correct Civilization was not in play, so no game events were added")
end
Events.LoadScreenClose.Add(OnLoadScreenClose)
 
It's the C++/Lua request thread, which pretty much covers all of the coding languages used by the game ... but regardless ... go ahead and ask, we have Java, C# and other developers here.

Oh it's okay? Sweet! Wait you have devs in this thread? That's cool!

Anyway what I need help with this:

UA: Rumlar Bar&#305;&#351;: Upon a buildings completion, it's :c5production: Production can over flow into the next unit's Production.* +5% :c5strength: Combat Strength against cities per each ongoing trade route you have. *(10-15% maybe?).

Basically when you're building a building a percentage of the production used in building that building is put it into a reserve that is used up in kickstarting the production of the next unit built, note that this effect it stackable. So if we took 20% production away from a building and built four buildings in a row before we built a unit. That unit is going to have 80% more production thrown into it.

The next part of the UA is pretty obvious, your armies gained strength against cities based on the number of trade routes you have. How big is the bonus per trade route? I don't know, both that and the percentage taken away from building production needs to be tested and tweaked in their own time.

But now the question is, how do I code this? There's something else I need help with, but I don't have it on hand with me so I'll ask when I acquire it.
 
Anyone knows if there's a way to see how many Attacks a unit has left? I know there's IsOutOfAttacks(), but that returns a bool value, which isn't really what I'm looking for.

Otherwise, a way to grant a unit an Attack which doesn't cost Move points, would be ideal, but I guess that's not really possible, right?
 
Try giving it a +1 Move promotion after attacking, through PostCombatRandomPromotion.

Otherwise, if you use any DLL with RED Combat Events, just replenish the moves (+60 = +1 move) after an attack with GameEvents.CombatEnded.
I don't think the +1 moves promotion will take effect until the next turn, though. They never seem to for me. Though a promotion with extra attacks might work. Then at the beginning of every turn, you just take the promotion away from any units that have it.

----------------------------------------------------------------------------------------------------

Danmacsh,

The promotion in any of these scenarios needs to be a new one added to the game, and that cannot be normally accessed (CannotBeChosen), so as not to take away a 'real' promotion that a unit has earned.
 
I don't think the +1 moves promotion will take effect until the next turn, though.

Argh, that's true. It doesn't.

Try my method AND this script (it is generic, so any promotion that gives Movement will also replenish that much):
Code:
function PromoReplenishMoves(iPlayer, iUnit, ePromotion)
	local iMovesChange = GameInfo.UnitPromotions[ePromotion].MovesChange
	if iMovesChange > 0 then
		local pPlayer = Players[iPlayer]
		local pUnit = pPlayer:GetUnitByID(iUnit)
		pUnit:ChangeMoves(iMovesChange * 60)
	end
end

GameEvents.UnitPromoted.Add(PromoReplenishMoves)

If you do, then, as LeeS pointed out, you'll need to REMOVE them on turn starting, with this:
Code:
local eDanPromo = GameInfoTypes["PROMOTION_YOUR_PROMOTION"]
local eDanCiv = GameInfoTypes["CIVILIZATION_YOUR_CIV"]

function RemovePromoMoves(iPlayer)
	local pPlayer = Players[iPlayer]
	if pPlayer:GetCivilizationType == eDanCiv then
		for pUnit in pPlayer:Units() do
			if pUnit:IsHasPromotion(eDanPromo) then
				pUnit:SetHasPromotion(eDanPromo, false)
			end
		end
	end
end

GameEvents.PlayerDoTurn.Add(RemovePromoMoves)

If you want, I can make a faster* way to remove the Promotions, integrating both scripts, but the genericness of the first script would deride a bit.

*Less computing load.
 
Back
Top Bottom