Custom Civ Traits -- questions

MerakSpielman

Warlord
Joined
Oct 27, 2005
Messages
217
I thought it would be simple to make a trait that added a production bonus to a certain type of unit.

This is what I have so far:

Code:
	<Table name="Trait_UnitCombatProductionModifiers">
		<Column name="TraitType" type="text" reference="Traits(Type)"/>
		<Column name="CombatClass" type="text" reference="UnitCombatInfos(Type)"/>
		<Column name="Modifier" type="integer"/>
	</Table>
	
	<Traits>
		<Row>
			<Type>TRAIT_ELVEN_ARCHERY</Type>
			<Description>TXT_KEY_TRAIT_ELVEN_ARCHERY</Description>
			<ShortDescription>TXT_KEY_TRAIT_ELVEN_ARCHERY_SHORT</ShortDescription>
		</Row>
	</Traits>

	<Trait_UnitCombatProductionModifiers>
		<Row>
			<TraitType>TRAIT_ELVEN_ARCHERY</TraitType>
			<CombatClass>UNITCLASS_ARCHER</CombatClass>
			<Modifier>50</Modifier>
		</Row>
	</Trait_UnitCombatProductionModifiers>

Of course it doesn't work... I imagine when it's calculating production time, it doesn't take into account my new table Trait_UnitCombatProductionModifiers.

So where does it do the production modifier calculations? How can I add this?

As a workaround it would be fairly simple to make a new building, say an Archery Range, that did what I want. But I hate workarounds because I don't learn as much.

Any suggestions?


question 2:

Where is it listed that the ChuNoKu have an extra attack every turn? I wanted to make a unit that was similar, but that particular piece of information is hidden somewhere I can't find. Comparing ChuNoKu to Crossbowmen wasn't very helpful - attacks per turn isn't anywhere on the unit table.
 
I started looking through the LUA files... but they don't do any of the logic. They just place elements.

They contain lots of calls to other things, like:

Events.ActivePlayerTurnStart.Add( OnTurnStart );

and hundreds of other exampels.

What is being called, though, and where is it? Are these things hidden in source code?

I want to modify actual calculations and logic... where do I find this?
 
(from that thread)
Not right now. Once the DLL code is released, it will be possible to program new effects altogether in C++.

... I'm a fairly sharp C++ programmer. Is this actually going to happen??
 
Yes, it is. If you're an experienced C++ coder, congratulations - there's a LOT you will be able to accomplish. One good thing to do in C++ is actually not to touch much logic but to add new possible tags to the XML that would do something.
 
:)

I'm also decent with XML and SQL.

LUA is completely new to me, but doesn't look too hard.



Any news on when it's being released?
 
Lua does take some getting used to, but for an experienced programmer it won't be long at all until you're writing functional code in it. So go experiment ;)

There hasn't been an official date given for the release of the C++ code, but based on what happened with Civ4, I'd expect it in January.
 
Has anybody compiled a list of the functions we know about from the LUA files? That's something I might do if nobody has done it yet.
 
Look at the tutorials + reference section, there's a thread for the events ;).

And:
Moderator Action: Moved to the main forum.
Only finished threads and files go into the subforums, questions and working threads belong to the main forum ;).
 
(chuckles)

Seems I have a knack for wanting to change things that can't be changed yet.

I wanted to add a "Plant Forest" worker action. But the only tags we have are for removing features, not adding them.

I just spent the last hour reading the UnitPanel.lua file, which handles the display of worker actions (and other things). All it does is determine which things to place, and where, based on the unit selected, the terrain, the features, the technologies, and so on. So I could create a Plant Forest action. I could make a button for it. But I'm not sure I could make the button actually DO anything.

Or maybe it's easier than I think... maybe I just need to pass in a negative number somewhere to have it remove negative one forests or something...

edit: nah don't see anything like that... Hmm.....

edit2: Where's the code for what happens when a worker button (or promotion button, for that matter) are actually pressed? Has to be a function call tied to those buttons somewhere... I see where they're positioned and formatted...

(I think I'm just stream-of-conscious-ing my thoughts at this point, pay no attention)
 
edit2: Where's the code for what happens when a worker button (or promotion button, for that matter) are actually pressed? Has to be a function call tied to those buttons somewhere... I see where they're positioned and formatted...

Well that was anticlimactic...

Code:
function OnUnitActionClicked( action )

		Game.HandleAction( action );

end

If you click an action, we call Game.HandleAction... which doubtless has all kinds of nice code to determine what the action actually does. Wish I could see it...
 
So I thought I would give this a shot.. is the following code correct for adding a new trait?

<Table name="Trait_YieldChangesTerrain">
<Column name="TraitType" type="text" reference="Traits(Type)"/>
<Column name="YieldType" type="text" reference="Yields(Type)"/>
<Column name="TerrainType" type="text" reference="Terrains(Type)"/>
<Column name="Yield" type="integer"/>
</Table>

Or is any addition of new tables currently an impossibility?
 
(chuckles)

Seems I have a knack for wanting to change things that can't be changed yet.

I wanted to add a "Plant Forest" worker action. But the only tags we have are for removing features, not adding them.

I just spent the last hour reading the UnitPanel.lua file, which handles the display of worker actions (and other things). All it does is determine which things to place, and where, based on the unit selected, the terrain, the features, the technologies, and so on. So I could create a Plant Forest action. I could make a button for it. But I'm not sure I could make the button actually DO anything.

[...]
edit2: Where's the code for what happens when a worker button (or promotion button, for that matter) are actually pressed? Has to be a function call tied to those buttons somewhere... I see where they're positioned and formatted...

(I think I'm just stream-of-conscious-ing my thoughts at this point, pay no attention)

It should be possible to add such a plant forest button. Take a look at my "dig command" mod. I added a button with custom behaviour there. It's not very elegant but I don't know how to do better without C++ modding.

Hope this helps :)
 
I recall Civ 4 having a plant forest button when a tech was reasearched or something of the sort you may want to check there.
 
I thought it would be simple to make a trait that added a production bonus to a certain type of unit.
It is, but you need to look at the Civ5Units.xml structure for the way to accomplish it.

Also, you can't do it sweepingly with UnitClass assignment - you need to do it unit by unit like this:
Code:
	<Unit_ProductionTraits>
		<Row>
			<UnitType>UNIT_ARCHER#1</UnitType>
			<TraitType>TRAIT_ELVEN_ARCHERY</TraitType>
			<Trait>50</Trait>
		</Row>
		<Row>
			<UnitType>UNIT_ARCHER#2</UnitType>
			<TraitType>TRAIT_ELVEN_ARCHERY</TraitType>
			<Trait>50</Trait>
		</Row>
		... etc. etc. ...
	</Unit_ProductionTraits>


Where is it listed that the ChuNoKu have an extra attack every turn? I wanted to make a unit that was similar, but that particular piece of information is hidden somewhere I can't find. Comparing ChuNoKu to Crossbowmen wasn't very helpful - attacks per turn isn't anywhere on the unit table.
Once again you need to turn to Civ5Units.xml - and this time look under Unit_FreePromotions (where ChuKoNu's also get assigned the free promotion PROMOTION_SECOND_ATTACK).
 
It should be possible to add such a plant forest button. Take a look at my "dig command" mod. I added a button with custom behaviour there. It's not very elegant but I don't know how to do better without C++ modding.

Hope this helps :)

I don't see anyplace in the xmls for adding "features" to terrain -- only removing them. If those tags existed, it would be simple as pie.
 
I don't see anyplace in the xmls for adding "features" to terrain -- only removing them. If those tags existed, it would be simple as pie.

I never said anything about XML. But you can indeed put a custom button in via UnitPanel.lua and execute any lua-function you like when it's clicked. So as I said it's less elegant than modding it via XML but if you really want a plant-forest-button you should be able to add it.
 
What lua function would it need to activate? Those are hardcoded too aren't they?
 
What lua function would it need to activate? Those are hardcoded too aren't they?

If by it you mean the button then no. You can define your own (lua-)function when/after adding a new button. If you are interested in doing this look at the dig command mod. It essentially consists of a different UnitPanel.lua and you can find the changes i made by searching for cfe.dig .
 
Back
Top Bottom