How to set a unit's civilopedia text by hand?

stmartin

aka. poyuzhe
Joined
Aug 4, 2007
Messages
640
Location
Shanghai
The game loads all civilopedia text from XML by game start, but this time I need to change the civilopedia text during game.

I defined functions in CvUnitInfo, to set its civilopedia text, it's like this:

Code:
void CvUnitInfo::setCivilopedia(const wchar* szText)
{
[INDENT]m_szCivilopediaKey = szText;[/INDENT]
}

Now when I want to call this function, I don't know what argument to pass to it! Tried hard coding with "TXT_KEY_XXX", no avail. Tried call gDLL->getText("TXT_KEY_XXX"), no t working. Tried call GC.getDefineSTRING("xxxx"), not working too.

Any idea how to get this work?
 
So what kind of example can you provide of what you would do with this? Your approach may not be quite ideal, so it'd be nice to know what the final goal is.

Since that variable doesn't already exist, just setting it doesn't mean much of anything at all. So it would be nice to see where it is actually implemented at. But assuming that the implementation is working:


Other places that take a const wchar* input which you may have used (or can find examples on how to use them) would be pPopup.setText(szText) or pPopup.addPythonButton(szText, szArt). Note that szArt is const char* instead of const wchar* though.

Without looking up such examples, I would say you need to make your string unicode for it to work.
 
If you look at CvInfoBase::getCivilopedia(), it seems that the civilopedia entry is cached the first time it is read. If you want to get your function to update this you will need to also set m_szCachedCivilopedia to the getText of your new entry.

Try...

Code:
void CvUnitInfo::setCivilopedia(const wchar* szText)
{

    m_szCivilopediaKey = szText;
    m_szCachedCivilopedia = gDLL->getText(szText)

}

... and call the function using your new XML definition.

From what I understand you have a text key like TXT_KEY_XXX which is defined in the XML as returning something like "xxxx", ie gDLL->getText("TXT_KEY_XXX") returns "xxxx".

You can now use pUnit.setCivilopedia("TXT_KEY_YYY") and the DLL will change the key to TXT_KEY_YYY and then look at the XML and set the unit's civilopedia entry correspondingly (eg to "yyyy").

If you only want to change the entry and not the key you would only have to set the value of m_szCachedCivilopedia to szText.

Hope that helps.

~Ted
 
Oh, now I feel a bit of a dolt. I looked in CvUnit for the function, missed the INFO bit of the tag there :facepalm:

So you are changing the "flavor text" in the Pedia at a certain point in the game then? I'm actually not quite certain how you would access that variable within CvUnitInfo. Hopefully DutchTed is right, or your original approach happens to be on the right track.

All I know is that inside of any CvUnitInfo object there is a nested CvHotKeyInfo, with a subnested CvInfoBase object. It is that third nest which actually holds the contents of the <Civilopedia> XML tag.

Possibly you need to have something along the lines of:

Code:
void CvUnitInfo::setCivilopediaKey(const wchar* szText)
{
	CvHotkeyInfo::setCivilopediaKey(szText);
}
.
.
.
void CvHotkeyInfo::setCivilopediaKey(const wchar* szText)
{
	CvInfoBase::setCivilopediaKey(szText);
}
.
.
.
void CvInfoBase::setCivilopediaKey(const wchar* szText)
{
	m_szCivilopediaKey = szText;
	m_szCachedCivilopedia.clear();
}


At least that is how the ::read(XML) function winds up routing things. The last line there where you run .clear() will make the cache re-load itself when asked for once again (that loading is why the pedia takes so long to load if you have lots of units/buildings/whatever section on the first time in, but not again after that)
 
I am kind of curious about how this would be used in the game. As a player, I would not expect the pedia text to change. If I looked at it one time, and then looked at it later and it was different, I would be confused. I do not expect a real-world encyclopedia to change during runtime.
 
Thanks xienwolf and DutchTed:)

It was my bad, I declared the function wrong: the argument should be const wchar* as I put it in the first post, but in my original attempt I declared the argument to be wchar*. Now I changed the declaration, I can just pass gDLL->getText("TXT_KEY_XXXX") as parameter, it works like breeze.

As to why I want to do some strange thing like this, it's simple: I want to dynamically conjure a new hero info type out of thing air. So HoTK players can create and nurture their very own hero. To do this I need to set all the info tags manually, include type, name, civilopedia, button and so on. And because I'm creating a brand new info, I don't need to worry about cache.
 
It would be interesting if you had some kind of python routine to "chronicle the actions of a hero" so that you can look in the pedia and see "history" of the game you are currently playing :)

^^^^ That would be phenomenally cool, say during turn 234 Unit So-and-so was taken down to 0.1 hit points but survived, later you could see in the civilopedia that "Turn 234 (or it's year equivalent): Unit So-and-so overcame the odds and defeated the army of Leader Such-and-such at the battle of Whose-its-ville and despite being brought to death's door, Unit So-and-so went on to fight and win many more battles". It would be like the combat log though with Flavor Text
 
So HoTK players can create and nurture their very own hero. To do this I need to set all the info tags manually, include type, name, civilopedia, button and so on. And because I'm creating a brand new info, I don't need to worry about cache.

:lol: a bit like the sims.
But a very cool idea :cool:.
 
It would be interesting if you had some kind of python routine to "chronicle the actions of a hero" so that you can look in the pedia and see "history" of the game you are currently playing :)

Awesome idea.:D I think I'll do it.:lol:
 
Top Bottom