 |
|  |
 |
|
Martin Gühmann
|
 |
Berlin, Germany
Mar 2001 time: 06:29
|
|
quote: Originally posted by E
I added the bit of code to the CanBuildUnit and CanBuildWonder in the citydata.cpp. I think that adding the code here wil mean that I don't have to change Unitdata.cpp, Player.Cpp, or Wonderutil.cpp. |
So far your CityData.cpp seems to be ok, and the note about the other files is correct.
quote: Originally posted by E
If all is well I think I'll have to look how to add the code to the terrain improvement file (including my IsRestrictedTo code). Of course unless tere are other things you've found. |
Of course you have to modify terrainutil.cpp.
quote: Originally posted by E
1) inotice that #include citydata.h is in player.cpp. Does this allow the classes of citydata to be accessed in the player.cpp like it would in citydata.cpp? |
No, that does not mean it. You can access the members of the class within a function, because this function is a member of the according class itsself.
However it does allow you to create and use opject of class CityData in player.cpp.
quote: Originally posted by E
2) I notice you've guys have done lots of work on the server to the code, including changes to the citydata.cpp. I havent gotten into the server and don't think i could figure it out anytime soon. Could you post the modified citydata.cpp so I can update it with my stuff or are willing to post my changes when you post stuff (I'dh ate to get on the server and screw things up) |
So you mean I should submit your modifications as my own to the resperitory and get the honor, the glory, the fame ... and the blame for it? 
Come on this isn't so difficult. The first thing you do with Tortoise is to check out the respiratory. Then you download the files (as default it copies the files into an empty folder) and then you have a work copy. Then you do your modifications on the work copy. When you are done you check the update option, to see whether there are any new versions of files. Once you have updated your work copy you can commit your files. And if there was a change of your file in the respiratory and there are no conflict the files are easily merged. Otherwise you have to resolve the conflict by hand.
-Martin
|
|
|  |
 |
|  |
 |
|  |
 |
|  |
 |
|
E
|
 |
July 24,2005 Ctp2 Tiles in sig!
May 1999 time: 21:29
|
|
code:
if(irec->GetNumNeedsCityGood() > 0) {
sint32 s;
bool found = false;
for(s = 0; s < irec->GetNumNeedsCityGood(); s++) {
if(irec->GetNeedsCityGoodIndex(s) == m_collectingResources || m_buyingResources) {
found = true;
break;
}
}
if(!found)
return FALSE;
}
Just a random questioni n the possibility of adding strategic goods. I was thinking of making an attribute NeedsCityGood which means that the city must either have the good in its radius or is receiving the good from trade in order to let that city build a unit.
Now I'm NOT looking to make it like Civ3 where you need road connections etc, because if only certain cities can build units it makes not only the good strategic but the cities strategic (unless you trade the good within the empire).
But I'm not sure m_buyingResources and m_collectingResources pertains to goods. I haven't mapped out how this class is being filled (not sure if it counts food, prod, gold) but I think its goods. If this is the case then I'd like to add this code along with my already finished stuff.
Last edited by E on 20-04-2005 at 23:53
|
|
|  |
 |
|
Martin Gühmann
|
 |
Berlin, Germany
Mar 2001 time: 06:29
|
|
quote: Originally posted by E
1) Is this for only the player.cpp file or all code that uses this function? I'm thinking its all of it. |
Well you should be more specific about this. I assume you mean whether this holds for all function in the player.cpp file or to other files as well. I guess it is a question related to the this pointer.
Only non static member functions have a this pointer. So you cannot access this in static functions. Static functions are member of the class, non static functions are member of an object, on that a pointer and point including the this pointer. And therefore static functions don't have a this pointer.
Of course any non static function of class Player can be implemented in any file of the project you want, so you could implement each function of Player in a different *.cpp file, so only a function of Player specified by Player:: can have a this pointer on a opject of type Player.
quote: Originally posted by E
2) DynamicArray. I assume this is an array that is constantl updated and changed, but whats thedifference between an array and a dynamic array? |
No, that's wrong. A dynamic arry is an array that increases its size when if it is full and another element should be added. I think it shrinks also in size if possible. However the STL offer better containers, espeacilly those that don't leak.
quote: Originally posted by E 3) m_owner is part of the player index which I assume means it just tracks players. What does the player index do or better yet where do I find out what the player index does and how do I know when I find it? |
No m_owner is a player index. It is used to access data that requires a player index, for instance because it is saved in an array with player index dependency. To use this in a non static function of Player to access from the list of players is stupid, because you just get the this pointer and you have the this pointer anyway, whether you write it into the code explecitly or or by just calling functions or other members of the object.
quote: Originally posted by E
4) *m_civilisation is a dynamic array that stores thecivilisation of player from the looks of this. So I think this is what I need instead of m_owner, BUT why is it dynamic?
it has this:
code:
Civilisation *GetCivilisation(void) { return (m_civilisation) ; }
void GetPluralCivName(MBCHAR *s) ;
void GetSingularCivName(MBCHAR *s) ;
MBCHAR *GetLeaderName(void) ;
But it looks like its under the player Index, but then I see class Selected Item. So I got a little lost trying to map where get Civ should be, but I'm still guessing m_civilisation (and I think its yet another there on how to try a CivOnly code too) |
Well for the civ specific code you should find a GetCivName function or create one of your own if necessary, but for that later, when you have finished this project.
quote: Originally posted by E
SOOOOOO based on what I've seen and if I had to guess I'd say the code should look like:
code:
if(irec->GetCultureOnlyIndex(s) == g_player[m_civilisation]->GetCityStyle()) {
removing the GetCivilisation because m_civilisation does it now. |
No you are from at first you assume m_civilisation is a DynamicArray, but then you use it as index. Probably it is rather a pointer on something. And is returned by GetCivilisation. So reguess again. 
-Martin
|
|
|  |
 |
|
E
|
 |
July 24,2005 Ctp2 Tiles in sig!
May 1999 time: 21:29
|
|
quote: Originally posted by Martin Gühmann
Maybe Player has a member m_owner, but if you are in a Player member function you don't need to get a pointer on a Player object if it points on the same address in the memory as the this pointer.
|
Wait, relooking this again. Are saying that with the Player::CanBuildUnit I don't need g_player just:
code:
if(irec->GetCultureOnlyIndex(s) == m_owner->GetCivilisation()->GetCityStyle()) {
but in player I do see instances of g-player[m_owmer] like in the same function Player::CanBuildUnit
code:
n = g_player[m_owner]->m_all_units->Num();
for(i = 0; i < n; i++) {
if(m_all_units->Access(i).GetDBRec()->GetSlaveRaids())
return FALSE;
}
Last edited by E on 27-04-2005 at 08:21
|
|
|  |
 |
|
Martin Gühmann
|
 |
Berlin, Germany
Mar 2001 time: 06:29
|
|
quote: Originally posted by E
Wait, relooking this again. Are saying that with the Player::CanBuildUnit I don't need g_player just:
code:
if(irec->GetCultureOnlyIndex(s) == m_owner->GetCivilisation()->GetCityStyle()) {
|
No, that doesn't even compile. m_owner is a player index, and not a pointer on a player. You can only use it in arrays or functions that needs to access a player from a list, like g_player is such a list. And it is implemented as the simplest list like construct a plain array.
quote: Originally posted by E
but in player I do see instances of g-player[m_owmer] like in the same function Player::CanBuildUnit
code:
n = g_player[m_owner]->m_all_units->Num();
for(i = 0; i < n; i++) {
if(m_all_units->Access(i).GetDBRec()->GetSlaveRaids())
return FALSE;
}
|
It is nice that you look at other people's code, but you shouldn't think that it is correct just because a programmer wrote it or the way as it is programmed it is the best one. In fact you find a lot of incorrect code in the CTP2 source and bad style code.
One think for instance is that you find in the source code some goto commands. It is actual very frowned upon. If it is used it may be a sign of very good, clever and intellegent way of programming. But this is rather the seldom case. More frequent it is a sign of a very bad way of programming. And in the CTP2 gotos I saw so far are all of the latter type.
The bit of code above, is a not very ellegant way of programming, because g_player[m_owner] is equal to the this pointer at least it should be equal to the this pointer.
So you do an operation to access a array to retrieve a pointer that you want then to use, that is one additional operation than if you use the this pointer directly.
Of course you can rely on the optimizer of your compiler, but that is again a bad style of programming, at least if it is so simple like here to do the optimization yourself.
And of course the is a final point if you aren't so familiar with the code then prbably you don't know that g_player[m_owner] is the this pointer, so he could think here is another object of type player accessed. But this isn't true.
So this point is about making the code easier to understand and that is also the point about the goto, with the goto it is hard to see where it brings you to.
And now you should get it with the this pointer, this is important. And of course use your C++ for Dummies. 
-Martin
|
|
|  |
 |
|  |
All times are GMT. The time now is 05:29. Apolyton Time is 00:29. |
top of page
|
|
|
Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is ON
vB code is ON
Smilies are ON
[IMG] code is ON
|
|
|
|
|
|