Thanks. I have another question about this though. How would I best go about setting the new capture unit to be the Slave unit. The only way I can think of is to create a function to find the first unit that has IsSlave as true in the database and #defining that as a slave, but that is horribly hardcoded and reduces expandability in the future (if I want for instance multiple slave types). Is there a better way to do it?
Yes! Create a new XML column in the Units table using SQL. Observe how I achieve this with the Era table and duplicate with the Units table.
Code:
ALTER TABLE Eras ADD VassalageEnabled boolean;
---------------------------------------------------------------------------------------------
-- Eras
UPDATE Eras SET 'VassalageEnabled' = 1 WHERE Type = 'ERA_MEDIEVAL';
Now, you must locate where they read from the XML files in the DLL. For Units that is in UnitClasses.h/.cpp.
For this example I use the Range tag.
1. Create a new CvUnitEntry function: int GetRange() const;
2. Create a new CvUnitEntry member variable: int m_iRange;
3. Define GetRange() to return m_iRange
4. Be sure to include m_iRange in the constructor
5. Finally, in CvUnitEntry::CacheResults you include the line m_iRange = kResults.GetInt("Range"); which reads the data from the Range tag.
Yeah, I used two different examples. But this was just to show you how this is done.
Now I will do real code examples:
Code:
-- SQL File
ALTER TABLE Units ADD Slave boolean;
UPDATE Units SET 'Slave' = 1 WHERE Type = 'UNIT_SLAVE';
//------------------------------
// UnitClasses.h
bool IsSlave() const;
bool m_bSlave;
// UnitClasses.cpp
bool CvUnitEntry::IsSlave() const
{
return m_bSlave;
}
// CvUnitEntry::CacheResults
m_bSlave = kResults.GetBool("m_bSlave");
// ------------------------------------------
The most complicated part is understanding that CvUnit.h and CvUnitClasses.h are two different things. Unit definition information is loaded in CvUnitClasses, specific instances of units are used in CvUnit.
Now I will return to the Range() example for completeness.
In CvUnit.cpp they create another GetRange() function, which return the unit's class get range like follows:
Code:
// --------------------------------------------------------------------------------
int CvUnit::GetRange() const
{
VALIDATE_OBJECT
return (m_pUnitInfo->GetRange() + m_iExtraRange);
}
Hopefully this was helpful and you could take it from there.