How do I get the team of APs Holy City?

Kailric

Jack of All Trades
Joined
Mar 25, 2008
Messages
3,100
Location
Marooned, Y'isrumgone
I am trying to get the team of the owner of the Holy City that is the same Religion as the AP, but I keep getting the error CvGame.cpp(9180) : error C2228: left of '.getTeam' must have class/struct/union type. Line 9180 is in bold in the code below. What do I need to do to convert hOwner to a team? I tired lots of ways below is just an example of one of the ways that doesn't work.



Code:
for (int iPlayer = 0; iPlayer < MAX_CIV_PLAYERS; ++iPlayer)
          {
     CvCity* pHolyCity = GC.getGameINLINE().getHolyCity(GC.getGameINLINE().getVoteSourceReligion((VoteSourceTypes)1));
     CvPlayer& kLoopPlayer = GET_PLAYER((PlayerTypes)iPlayer);
     PlayerTypes hOwner = (pHolyCity->getOwnerINLINE());
     TeamTypes tOwner;
     [B]tOwner = (hOwner.getTeam)[/B];

                  if (kLoopPlayer.isFullMember(kData.eVoteSource))
                  {
                        if (GET_TEAM(kLoopPlayer.getTeam()).canChangeWarPeace(tOwner))
                        {
                            GET_TEAM(kLoopPlayer.getTeam()).declareWar(tOwner, false, WARPLAN_DOGPILE);
                        }
                    }
          }
 
I get this error all the time. You just forgot your parentheses:

Code:
tOwner = (hOwner.getTeam[COLOR="Red"]()[/COLOR]);
 
I get this error all the time. You just forgot your parentheses:

Code:
tOwner = (hOwner.getTeam[COLOR="Red"]()[/COLOR]);

Thanks.. that was needed.. but there is still another problem.. I get two more errors now.
Code:
CvGame.cpp(9180) : error C2228: left of '.getTeam' must have class/struct/union type
        type is 'PlayerTypes'
CvGame.cpp(9184) : error C2039: 'canChangeWarPeace' : is not a member of 'CvPlayer'
        c:\Documents and Settings\Owner\Desktop\dll\CvGameCoreDLL\CvPlayer.h(29) : see declaration of 'CvPlayer'
CvGame.cpp(9186) : error C2039: 'declareWar' : is not a member of 'CvPlayer'
        c:\Documents and Settings\Owner\Desktop\dll\CvGameCoreDLL\CvPlayer.h(29) : see declaration of 'CvPlayer'

I have to "get" a team to declare war but I can't get the team that owns the Holy City of the AP.
 
I think the problem is here:


Code:
PlayerTypes hOwner = (pHolyCity->getOwnerINLINE());


PlayerTypes is an enum that just represents a player's ID. You're looking for an instance of the Player class, which is different. Try this:

Code:
CvPlayer* pOwner = GET_PLAYER((pHolyCity->getOwnerINLINE()));

Now make all of your references to pOwner instead of hOwner. Just make sure to check to see if the value is NULL before trying to use the value. Also, you should check to see if the player is alive (using the isAlive() method) just in case, because anytime you loop through players with MAX_CIV_PLAYERS, you are looping through all possible players (i.e. all 18 slots, whether they are filled are not filled).

Hope that helps.

-isau
 
Code:
for (int iPlayer = 0; iPlayer < MAX_CIV_PLAYERS; ++iPlayer)
          {
     CvCity* pHolyCity = GC.getGameINLINE().getHolyCity(GC.getGameINLINE().getVoteSourceReligion((VoteSourceTypes)1));
     CvPlayer& kLoopPlayer = GET_PLAYER((PlayerTypes)iPlayer);
    [I] //PlayerTypes hOwner = (pHolyCity->getOwnerINLINE());[/I]
       [B]CvPlayer& hOwner = GET_PLAYER(pHolyCity->getOwnerINLINE());[/B]
     TeamTypes tOwner;
     tOwner = (hOwner.getTeam);

                  if (kLoopPlayer.isFullMember(kData.eVoteSource))
                  {
                        if (GET_TEAM(kLoopPlayer.getTeam()).canChangeWarPeace(tOwner))
                        {
                            GET_TEAM(kLoopPlayer.getTeam()).declareWar(tOwner, false, WARPLAN_DOGPILE);
                        }
                    }
          }

KK, I just fixed it myself...

I replaced the above lined I commented out with the bold line, I just looked around in the code for something similar to what I was trying to do. Not sure why this worked but I just tested it in the game and it worked like a charm :goodjob:
 
Now make all of your references to pOwner instead of hOwner. Just make sure to check to see if the value is NULL before trying to use the value. Also, you should check to see if the player is alive (using the isAlive() method) just in case, because anytime you loop through players with MAX_CIV_PLAYERS, you are looping through all possible players (i.e. all 18 slots, whether they are filled are not filled).

Hope that helps.

-isau

Ahh thanks isau. I fixed it before I read your post but what way should work best.. the "&" or the "*".. I am just now learning some C++ and somewhat understand what "*" is but just looked up the "&" but they seem to be similar in effect. And thanks for the heads up on the MAX_CIV.. Is that also the case for the MAX_TEAMS ? .. is a Team alive?

edit: The canChangeWarPeace I bet checks if player is alive cause thats the way the example code is... but I did add a check for the city being null
 
* forms a pointer to an object. It basically answers the question "which one"? It's useful for situations where you have a bunch of objects and want to know which one to do something with. For example, in your code you are looping through a bunch of players. During each loop, you are pointing to each of these players and telling the code, "during this loop, use this player."

& can have several uses but the way you're using it here is kind of as a shortcut way of forming a pointer. Without getting too technical, in this context it lets you use . instead of ->


Unrelated to the discussion above, the reason your code needed to change from PlayerTypes to CvPlayer is that PlayerTypes is just an enum, not a real class. It's an ID that works the same way your social security number (or other ID number if you dont live in the US) references you. You can use the number to find you, but the number isn't literally you. The literal you would be CvPlayer.


--here's an edit with some additional examples:--

Code:
[B]ID Type                        Actual Object [/B]
PlayerTypes                   CvPlayer
TeamTypes                    CvTeam
UnitTypes                      CvUnit
PlotTypes                      CvPlot

Since you're working with the VoteInfo class, it might also be helpful to point out that all of the classes that end in 'Info' are XML classes. Pretty much all of these have an enum that you to access information about a particular piece of data in the XML.

Code:
[B]ID Type                        Actual Object [/B]
VoteTypes                     CvVoteInfo
TraitTypes                     CvTraitInfo
CivicTypes                      CvCivicInfo
EventTypes                    CvEventInfo
 
Back
Top Bottom