Player's name

pashaintel

Chieftain
Joined
Nov 22, 2008
Messages
22
Hi. Can anybody help me? I don't know how I can get Player's name, for example, Peter in SDK code. I write:
CvWstring pname;
pname = GC.getGameINLINE().getName(),
but it don't give result.
Please write here the full code...
 
You need to get it from the CvPlayer object. Something like this:

Code:
GC.getPlayerINLINE(ePlayer).getName()
 
ePlayer is the # of the player whose name you want. You can use 0 to get it started. This will work for the human player as long as they aren't playing a scenario with set civilizations. Where are you using this? With some contextual information, I or someone else may be able to help.
 
ePlayer is the # of the player whose name you want. You can use 0 to get it started. This will work for the human player as long as they aren't playing a scenario with set civilizations. Where are you using this? With some contextual information, I or someone else may be able to help.

I have Beyond The Sword 3.17. I want to add function of adding(sorry for my english) some bonuses to every player in MP. I want to add happy, my friend do health and etc. The code must be in CvCity.cpp. I can't to get LeaderName(or PlayerName ???) and compare with string value. For example:

int iT;
CvWString fplname;
CvWString splname;
fplname = "Peter";
splname = "Leo";
for (iT = 0 to MAX_PLAYERS, iT++)
{
if (GC.getPlayerINLINE().getName() == fplname )
{
...my code
}
}
I tried to write the function in different variants, but always got mistakes.For example:
1)CvCity.cpp(4295) : error C2065: 'ePlayer' : undeclared identifier how to declare?
2)CvCity.cpp(4295) : error C2228: left of '.getName' must have class/struct/union type what is it?
3)CvCity.cpp|4295|error C2039: 'getPlayer' : is not a member of 'CvGlobals'.
 
So it seems you want the city to receive a bonus if it is owned by some "friend" of yours, right? First, you can't just compare the names in C++ like that as you're not actually comparing the letters--you're comparing the memory addresses where they are stored.

You'd be better off using a player number for testing this. I don't know how you're getting the name of the friend into the game (are you hard-coding it into the DLL directly?), but to get the owner's player # you use CvCity::getOwner(). That returns an int that you can compare using ==.
 
You'd be better off using a player number for testing this.
It's not a good variant for us :( . But what you can say about this code:

const CvWString & CvCity::getLeaderName(PlayerTypes eID, uint uiForm) const
{
FASSERT_BOUNDS(0, MAX_PLAYERS, eID, "CvInitCore::getLeaderName");
if ( checkBounds(eID, 0, MAX_PLAYERS) )
{
m_szTemp = gDLL->getObjectText(CvString(m_aszLeaderName[eID]).GetCString(), uiForm, true);
}
else
{
m_szTemp = "";
}

return m_szTemp;
}

bool CvCity::checkBounds( int iValue, int iLower, int iUpper ) const
{
if (iValue >= iLower)
{
if (iValue < iUpper)
{
return true;
}
}
return false;
}

void CvCity::setLeaderName(PlayerTypes eID, const CvWString & szLeaderName)
{
FASSERT_BOUNDS(0, MAX_PLAYERS, eID, "CvInitCore::setLeaderName");
if ( checkBounds(eID, 0, MAX_PLAYERS) )
{
CvWString szName = szLeaderName;
gDLL->stripSpecialCharacters(szName);

m_aszLeaderName[eID] = szName;
}
}


Can i use anything from it? and how to compare szLeaderName( or m_aszLeaderName) with our names? Is it really possible?
 
When posting code, use
Code:
 tags so its readable with indentation. You need to create a CvWString from your desired name and compare it to getLeaderName() I believe. You may get lucky and be able to do something like this:

[code]
bool CvCity::isFavoredLeader()
{
    CvWString friend("friend's name")
    return m_aszLeaderName[eID] == friend;
}
 
Oh, I don't know what to do. If anybody have really working code, please help me. I will wait. I don't believe that I am alone who try to do it.
 
bool CvCity::isFavoredLeader()
{
CvWString friend("friend's name")
return m_aszLeaderName[eID] == friend;
}

CvCity.cpp(4319) : error C2059: syntax error : 'friend '
 
You're missing a semicolon on the friend declaration line. The "const" at the end of the first line tells C++ that this function will not modify the CvCity object and must be placed in the declaration of the function in CvCity.h to match.

Code:
bool CvCity::isFavoredLeader() [COLOR="Green"][B]const[/B][/COLOR]
{
    CvWString friend("friend's name")[COLOR="Green"][B];[/B][/COLOR]
    return m_aszLeaderName[eID] == friend;
}
 
Looking at CvCity.h (and its .cpp file), I don't see m_aszLeaderName anywhere. I thought it odd that all leader names would be available in every city. Where are you getting that from? As I said, you'll need to go from the city to its owner (CvPlayer).

Code:
bool CvCity::isFavoredLeader() const
{
    CvWString friend("friend's name");
    return friend == GET_PLAYER(getOwnerINLINE()).getName();
}

Perhaps "isOwnerFavored" is a better name for this function, but that's beside the point.
 
Ignoring for the moment that hardcoding names into the SDK is very much a bad thing to do, you can achieve what you need by changing your loop to:

Code:
int iT;
CvWString fplname;
CvWString splname;
fplname = "Peter";
splname = "Leo";
for (iT = 0; iT < MAX_PLAYERS; iT++)
{
    CvWString name(GC.getPlayerINLINE(iT).getName());
    if (name == fplname )
    {
         ...my code
    }
    else if (name == splname )
    {
         ...my code
    }
}

This is inefficient and inflexible, but it should work.
 
Unfortunately, it don't work:

CvCity.cpp(4309) : error C2039: 'getPlayerINLINE' : is not a member of 'CvGlobals'
d:\¨&#1025; &#1025;&#1032;&#1072;&#1083;\sid meier's civilization 4\beyond the sword\mods\experiments\cvgamecoredll\CvGlobals.h(134) : see declaration of 'CvGlobals'
CvCity.cpp(4309) : error C2228: left of '.getName' must have class/struct/union type
Process terminated with status 2 (0 minutes, 8 seconds)
2 errors, 0 warnings
 
Oh? YES!!!!!! I did it!!
EmperorFool and falconne! Great thanks for help. There is really working code:

Code:
CvWString fplname;
fplname = "Peter";
    CvWString name(GET_PLAYER(getOwnerINLINE()).getName());
    if (name == fplname )
    {
      ...  my code ...;
    }
 
Top Bottom