Apolyton Archive  |  Preserved copy of the Apolyton Civilization Site and its forums as they stood in September 2005. Read-only; nothing here can be posted to or replied to.  |  Forum index |  About this archive |  The 1998–2001 UBB forums
Today on Apolyton WARDELL INTERVIEW PROMO A.C.S. HISTORY CHAPTER 4 GET CIV4 /w FREE PLUS! A.C.S. PHOTO GALLERY GET A.O.M. V1.1
Apolyton Civilization Forums
main| civ2| civ3| civ4| smac| ctp2| ron| moo3| galciv| galciv2| alt| about|
ApolytonPLUS | register | search | faq | new posts | pm (-/-) | upload | members
hall of fame new! | civgroups | civgroups news | interviews | the column | radio | chat | directory | news | store | PLUS
Apolyton Civilization Forums : Powered by vBulletin version 2.0.3 Apolyton Civilization Forums > Call To Power II > CtP2-Source Code Project > PROJECT: Good Specific Terrain Improvements
Show a Printable Version | Email This Page to Someone! | Receive updates to this thread | Report this to Apolyton news!
CivGroups
CTP2 Source Code Project (59): Not a Member - Join

bottom of page
  
Author
Thread   
Pages (4): [ 1   2   3   4   ]
< Last Thread     Next Thread > Post New Thread     Post A Reply
E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:29
  Old Post 09-04-2005 23:37 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#61 Report this post to a moderator
Enter the AD-FREE zone

I see so i the city data one I just need M+citystyle. I'll make the changes...

Bytheway I saw this in citydata.h

code:
#ifdef CTP1_TRADE Resources m_resources; Resources m_localResources; #else Resources m_collectingResources; Resources m_sellingResources; Resources m_buyingResources; #endif


If I read it right, then these identify if a city has a resource(good) so I could do a code for Civ3-like need resource flag for cities only using this (andit'll probably be similar to my code) but I'm getting ahead of myself so I'll post citydata stuff first (cdb is already done)


I think the lecture was great and I guess if you had to add anything it would be all the mistakes or stuff you had to teach me which are probably usual beginner mistakes

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:29
  Old Post 10-04-2005 00:38 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#62 Report this post to a moderator
Support Apolyton, buy Civilization III: Complete

Citydata.cpp

CityData::CanBuildBuilding

code:
#if !defined(ACTIVISION_ORIGINAL) if(irec->GetNumGovernmentType() > 0) { sint32 i; bool found = false; for(i = 0; i < irec->GetNumGovernmentType(); i++) { if(irec->GetGovernmentTypeIndex(i) == g_player[m_owner]->m_government_type) { found = true; break; } } if(!found) return FALSE; } if(irec->GetNumCityStyleOnly() > 0) { sint32 s; bool found = false; for(s = 0; s < irec->GetNumCityStyleOnly(); s++) { if(irec->GetCityStyleOnlyIndex(s) == m_citystyle) { found = true; break; } } if(!found) return FALSE; } if(irec->GetNumCultureOnly() > 0) { sint32 s; bool found = false; for(s = 0; s < irec->GetNumCultureOnly(); s++) { if(irec->GetCultureOnlyIndex(s) == g_player[m_owner]->GetCivilisation()->GetCityStyle()) { found = true; break; } } if(!found) return FALSE; } #endif



attached are also the Cdbs, I added the nobarbarian cdb to keep consistent (although if i understand the server right it lets people do modification of individual lines and allows you to sort based on revision, like DOORS, am I right?)

Attachment: cdbs.zip
This has been downloaded 1 time(s).

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:29
Post  Old Post 10-04-2005 21:51 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#63 Report this post to a moderator
Suffering from ads?

quote:
Originally posted by E
attached are also the Cdbs, I added the nobarbarian cdb to keep consistent


The cdbs seem to be correct. The only thing that might be reconsidered is the name of this:

code:
Bit(Int) PopCostsToBuild //added for future use to deduct more than one pop for units


I am not quite confident with it but so far I have no better idea. So we leave it as it is.

quote:
Originally posted by E
(although if i understand the server right it lets people do modification of individual lines and allows you to sort based on revision, like DOORS, am I right?)


Maybe I can anwer the question if you can tell me what DOORS is or are.

Appart from that the code fragment you posted above is correct in CityData::CanBuildBuilding. So let's go to the next file.

-Martin

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:29
  Old Post 10-04-2005 22:53 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#64 Report this post to a moderator
Support Apolyton, buy Call to Power 2

quote:
Originally posted by Martin Gühmann


The cdbs seem to be correct. The only thing that might be reconsidered is the name of this:

code:
Bit(Int) PopCostsToBuild //added for future use to deduct more than one pop for units


I am not quite confident with it but so far I have no better idea. So we leave it as it is.



Yeah i basically want to make it optional for modder to have units cost more than 1 pop point to build. I think its a small change in the build code by adding a line where the PopCost subtracts 1.


quote:

Maybe I can anwer the question if you can tell me what DOORS is or are.


We use DOORS at work, itlike a spread sheet but you can sort on only certain stuff that applies to what you want. So I assume that you can make builds off of certain revisions and it pastes in between lines of code.

quote:

Appart from that the code fragment you posted above is correct in CityData::CanBuildBuilding. So let's go to the next file.

-Martin


Great! I think I can keep almost everything in citydata (wonder, unit) instead of going to the player and the wonder.cpp because it looks like citydata does the same check for government type if a player can build a unit or if a city can build a unit.

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:29
  Old Post 14-04-2005 10:03 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#65 Report this post to a moderator
Support Apolyton buy from Amazon

Martin,

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.

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.

I have a few questions though:

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?

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)

thanks.

Attachment: citydata.zip
This has been downloaded 2 time(s).

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:29
Post  Old Post 14-04-2005 21:55 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#66 Report this post to a moderator
Help yourself to an AD-FREE life

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 is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:29
  Old Post 14-04-2005 22:18 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#67 Report this post to a moderator
Help yourself to an AD-FREE life

I also found this bit in advances:

code:
g_player[m_owner] && g_theCivilisationPool->IsValid(*g_player[m_owner]->m_civilisation


I think I can use it to compare a CivOnly attribute to the m_civilisation? Should I plug it in there?


quote:
Originally posted by Martin Gühmann
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.


If understand my C++ for dummies right, then by objects you mean it lets me use m_citystyle without having to do -> and get. right?

If so, can I just add #include citydata.h to terrutil.cpp so I don't have to make any changes to my code?


quote:

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.


Ok you've been warned I'm going to give it a shot but expect annoying questions

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:29
Post  Old Post 14-04-2005 22:43 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#68 Report this post to a moderator
Enter the AD-FREE zone

quote:
Originally posted by E
I also found this bit in advances:

code:
g_player[m_owner] && g_theCivilisationPool->IsValid(*g_player[m_owner]->m_civilisation


I think I can use it to compare a CivOnly attribute to the m_civilisation? Should I plug it in there?


If you can tell me were you ripped off this piece of code and where you want to insert it. And why.

quote:
Originally posted by E
If understand my C++ for dummies right, then by objects you mean it lets me use m_citystyle without having to do -> and get. right?


If m_citystyle is member of the same class like the function in that you indent to use it then you are right.

quote:
Originally posted by E
If so, can I just add #include citydata.h to terrutil.cpp so I don't have to make any changes to my code?


No, in terrainutil.cpp there aren't any member functions of CityData or do you see any functions with CityData:: there. And even if you have such a function there, it doesn't need to be a member function of an object of type CityData, as it can be static as well.

quote:
Originally posted by E
Ok you've been warned I'm going to give it a shot but expect annoying questions


Better ask before before you break anything.

-Martin

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:29
  Old Post 15-04-2005 09:25 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#69 Report this post to a moderator
Support Apolyton or Terrorists Win

quote:
Originally posted by Martin Gühmann
No, in terrainutil.cpp there aren't any member functions of CityData or do you see any functions with CityData:: there. And even if you have such a function there, it doesn't need to be a member function of an object of type CityData, as it can be static as well.
-Martin


Ok I added the code to terr_util, and I rememered that I don't need to check citystyle because the game doesn't check citydata at all and since I call g_player than I think my code will be alright. Its in CanPlayerBuild and I kept the IsRestrictedToGood at CanPlayerBuildAt.

If it looks good then I'll make my attempt at putting into the svn

Last edited by E on 16-04-2005 at 02:04

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:29
Post  Old Post 15-04-2005 20:49 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#70 Report this post to a moderator
Browse Apolyton AD-FREE

quote:
Originally posted by E
Ok I added the code to terr_util, and I rememered that I don't need to check citystyle because the game doesn't check citydata at all and since I call g_player than I think my code will be alright. Its in CanPlayerBuild and I kept the IsRestrictedToGood at CanPlayerBuildAt.


Well first you should get the whitespace usage in the terrainutil_CanPlayerBuildAt description. You added also a brief description in the "Modifications from the original Activision code:" section in this file, fine. But IIRC in the last version of CityData that piece of information was missing.

Now let's come to the stuff that keeps the file from compiling. m_owner is a member of CityData and inaccessable from a global function like terrainutil_CanPlayerBuild. But the answer on the question how you can replace it should be located inside this function.

Oh and by the way the function returns a bool and not a BOOL.

quote:
Originally posted by E
If it looks good then I'll make my attempt at putting into the svn


I think the best is you get a work copy from the server and merge in your changes manually, otherwise you have to deal with the Toirtoise merger and with the amount of changes in the file on the server that will be a hazzle.

And I think if you just overwrite the file in your work copy with the file attached here, it won't merge but will overwrite the file on the server.

And as we have removed the ACTIVISION_ORIGINAL stuff you have now to do the preprocessor task. So replacing the old code with the new code.

-Martin

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:29
  Old Post 15-04-2005 21:48 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#71 Report this post to a moderator
Support Apolyton, buy Civilization: The Boardgame

quote:
Originally posted by Martin Gühmann


Well first you should get the whitespace usage in the terrainutil_CanPlayerBuildAt description. You added also a brief description in the "Modifications from the original Activision code:" section in this file, fine. But IIRC in the last version of CityData that piece of information was missing.

Now let's come to the stuff that keeps the file from compiling. m_owner is a member of CityData and inaccessable from a global function like terrainutil_CanPlayerBuild. But the answer on the question how you can replace it should be located inside this function.

Oh and by the way the function returns a bool and not a BOOL.

-Martin


code:
g_player[pl]


I think I got it!

but your whitespace comment was confusing did you mean to get rid of the whitespace?

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:29
Post  Old Post 15-04-2005 22:07 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#72 Report this post to a moderator
Inflate your Upload Space

quote:
Originally posted by E
I think I got it!


I agree.

quote:
Originally posted by E
but your whitespace comment was confusing did you mean to get rid of the whitespace?


How much sense does this make. Getting rid of all white space together. Leaving the whole code in a single line. Of course not.

I was after this:

code:
//---------------------------------------------------------------------------- // // Name : terrainutil_CanPlayerBuildAt // // Description: Checks terrain improvement properties to see if it can build // on a tile only if it has a good // // Parameters : sint32 pl : Variable for player // const MapPoint &pos : Variable for tile on map // const TerrainImprovementRecord *rec :Varriable for improvement flag // Globals : g_theWorld : The game world properties // g_player : Player properties // // Returns : bool : Returns true if an improvement can be built // on a tile // false if the improvement cannot // // Remark(s) : A new improvement attribute IsRestrictedToGood was // added by E. Modders will define this in tileimp.txt as // IsRestrictedToGood: X. The flag adds an additional option // in order to restrict ceratin improvements to goods, adding // new options and bonuses. // // //----------------------------------------------------------------------------


It is a mixture of spaces and tabs. But everything inside this block should be spaces.

And at the end of this function is a closing brace without the right indent.

-Martin

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:29
  Old Post 15-04-2005 22:48 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#73 Report this post to a moderator
Support Apolyton, pre-order Civilization IV

ok, yeah I saw that too after I went in, strange it didn't look that way before...I guess I had it on a wordwrap or something...

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:29
  Old Post 16-04-2005 02:05 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#74 Report this post to a moderator
Get a bigger avatar today!

fixed the whitespace and the }

Attachment: terrainutil.zip
This has been downloaded 3 time(s).

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:29
Post  Old Post 16-04-2005 02:28 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#75 Report this post to a moderator
Avatar Enlargement: We've got the solution

Well I think we can test it on a compiler. So that means that you have to get it onto the server. I guess you have now all the files form the server. Then go to the trunk directory. You should be familiar with the subdirectory structure.

Go to the according files and insert your changes there. Possibly that can be done more confortable with a merge tool, but we don't want to make it too complicated for the start.

The files you have to merge manually are terrainutil.cpp, CityData.cpp and terrimprove.cdb. I think you can overwrite the rest of the *.cdb with yours without any problem. Maybe you like to add also to the *.cdb files such a nice description on the top like Fromafar did it with the terrimprove.cdb.

And of course let me have a final look before you commit the files. And of course you have now to strip the ACTIVISION_ORIGINAL stuff manually.

OK and finally some remarks to the descriptions, you don't need to mention this word 'variable' I know that this knd of stuff is variable. And a sint32 pl is not a player's attribute it is the players index, the thing that I need to acces the player in the list of players.

-Martin

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:29
  Old Post 19-04-2005 02:23 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#76 Report this post to a moderator
Support Apolyton, buy Galactic Civilizations

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 is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:29
Post  Old Post 19-04-2005 22:36 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#77 Report this post to a moderator
Remove this text

Well today I am just able to have a brief look at the files, E. One thing I should point out is the CultureOnly check in CityData::CanBuildUnit, since this method calls Player::CanBuildUnit, you should put it into Player::CanBuildUnit as it is Player-dependent and not City-dependent.

OK let's see whether I can look closer on the files, tomorrow. By the way you don't need to attach the files in the files in the Altered Source Files thread. You have to submit them anyway to the server. Therefore you can post them into the discussion where the belong into. Well and to your question tomorrow, if noone else answers it.

-Martin

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:29
  Old Post 20-04-2005 23:56 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#78 Report this post to a moderator
Support Apolyton, pre-order Civilization IV

Thanks, Martin. i suspect as much on the player stuff so I'll make the changes.

As for the code above, everything I saw in citydata.h and citydata.cpp seems to confirm that this is the class/object where the goods that a city can trade or in its radius is kept.

I think my check is okay but not sure how resources/goods are called from the DB.

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:29
  Old Post 21-04-2005 10:01 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#79 Report this post to a moderator
Support Apolyton buy from Amazon

Ok here's the added Player.cpp and updated CityData.cpp. I'm feeling confident with tortoise so if its good I shouldn't have a problem updating it.



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; }


I added the || as an or if I'm not mistaken I think that makes it work better. As far as my looking around the code is I think its right, but I'm not familar with the resource DB so thats where I may have a problem.

Attachment: 2005.04.20.e-files.zip
This has been downloaded 2 time(s).

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:29
Post  Old Post 21-04-2005 20:17 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#80 Report this post to a moderator
Remove this text

E, you shouldn't stop making changes until the stuff you already have done is right. The more you do now the more errors you can do. And I doupt that I can have a close look on the files, today. And maybe this holds for tomorrow as well.

This line is definatly wrong:

code:
if(irec->GetNeedsCityGoodIndex(s) == m_collectingResources || m_buyingResources) {


Either m_collectingResources and m_buyingResources are booleans or they are arrays and I think they are rather arrays than booleans. But without the source code here I can't tell you for sure. In both cases you can't compare them like this. Well you can but then you get nonsense.

If they are booleans you can only use them to decide whether you should do the NeedsCityGood check or not.

If they are arrays you have of course to compare each array element of the arrays m_buyingResources and m_collectingResources with each element of NeedsCityGood. And I am not sure whether NeedsCityGood should be an array.

-Martin

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:29
  Old Post 21-04-2005 22:40 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#81 Report this post to a moderator
Support Apolyton, pre-order Civilization IV

THanks Martin,
I did not put the NeedsCityGood in the files I posted. I plan on finishing that first then do this new code, so I'm following your advice

I'll look into other ways to compare the tool, but I just really want to see if the city either has the good in the radius or is receiving it from trade.

code:
if(irec->GetNumNeedsCityGood() > 0) { sint32 s; bool found = false; for(s = 0; s < irec->GetNumNeedsCityGood(); s++) { if(irec->GetNeedsCityGoodIndex(s) == m_collectingResources[resource]) { found = true; break; } else { if(irec->GetNeedsCityGoodIndex(s) == m_buyingResources[resource]) { found = true; break; } } if(!found) return FALSE; }

Last edited by E on 22-04-2005 at 01:21

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:29
Post  Old Post 22-04-2005 15:48 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#82 Report this post to a moderator
Support Apolyton

And still it doesn't work, resource is not defined and is not variable, so you compare each good in the NeedsCityGood array with a random value if you define resource at least, so it will prduce nonsence or crash.

-Martin

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:29
  Old Post 22-04-2005 19:49 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#83 Report this post to a moderator
Support Apolyton, buy Alpha Centauri

ok. I'll take a break on NeedsCityGood.

As for the file I uploaded it does NOT have NeedsCityGood in it, but just the other stuff we;ve been working on. I know you can't check it today or so but I'd like to get that one done first and then I'll come back to this NeedsCityGood

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:29
Post  Old Post 22-04-2005 22:36 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#84 Report this post to a moderator
Browse Apolyton AD-FREE

quote:
Originally posted by E
I know you can't check it today or so but I'd like to get that one done first and then I'll come back to this NeedsCityGood


Actual I was able to check.

I don't touch now the *.cdb last time they were ok and I think they still compile, but there is some stuff we have definatly to talk about.

Then your descriptions have to get preciser. For instance a sint32 is a number and a number can't describe all the properties of a player, in the instance in question it is an index of an player in the global list of players g_player.

Then this line in a Player member function:

code:
if(irec->GetCultureOnlyIndex(s) == g_player[m_owner]->GetCivilisation()->GetCityStyle()) {


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.

Then you forgot to remove a #else in terrainutil_CanPlayerBuildAt. Otherwise the stuff seems to be fine, and check again your description, somewhere there was a city even it should be a unit or player, no idea which one.

-Martin

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:29
  Old Post 24-04-2005 00:33 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#85 Report this post to a moderator
Get a bigger avatar today!

Should I remove the [m_owner] then? it sounds like what your saying...

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:29
Post  Old Post 24-04-2005 00:58 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#86 Report this post to a moderator
Remove this text

quote:
Originally posted by E
Should I remove the [m_owner] then? it sounds like what your saying...


Not quite. So again what is g_player? It is an array of pointers on objects of type player.

So now find the right answer.

-Martin

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:29
  Old Post 24-04-2005 22:50 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#87 Report this post to a moderator
Get a bigger avatar today!

Ok I've gone through player.h and I think I have, but I have a few questions:

1) Is this for only the player.cpp file or all code that uses this function? I'm thinking its all of it.

2) DynamicArray. I assume this is an array that is constantl updated and changed, but whats thedifference between an array and a dynamic array?

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?

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)

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.

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:29
Post  Old Post 25-04-2005 16:54 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#88 Report this post to a moderator
Full PM-box? Change here!

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 is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:29
  Old Post 27-04-2005 05:10 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#89 Report this post to a moderator
Inflate your Upload Space

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 is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:29
Post  Old Post 27-04-2005 13:03 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#90 Report this post to a moderator
Lose 30 kilos (of popups)

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

 
Pages (4): [ 1   2   3   4   ]
< Last Thread     Next Thread > Post New Thread     Post A Reply
All times are GMT. The time now is 05:29.
Apolyton Time is 00:29.
    top of page
Rate This Thread:
Forum Jump:
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
 




Contact Us - Apolyton Civilization Site - Support Us!

Building a better Apolyton through better information. Click here and take our poll!
Non-US visitors, click here!

Powered by: vBulletin Version 2.0.3
Copyright ©2000, 2001, Jelsoft Enterprises Limited.

Page generated in 0.0869 seconds (93.06% PHP - 6.94% MySQL) with 36 queries
Page Loading Time:

Support Apolyton: Amazon USA | Amazon UK | Amazon DE | Amazon FR |
Support Apolyton and get FREE PLUS, Buy from Chips&Bits: Galactic Civilizations | Galactic Civilizations: Deluxe Edition | Call to Power 2 | Civilization: The Boardgame | GURPS/ Alpha Centauri | Alpha Centauri | Civilization IV | Civilization III: Complete |


Front Page | Civilization IV | Civilization III | Civilization II | Call to Power II | Alpha Centauri | Master of Orion III
Rise of Nations | Galactic Civilizations | Galactic Civilizations II | Misc
Alt.Civs | Civ I | C:CtP I | About | News | Directory | Apolyton Store | Forums | Chat | Columns | Interviews | Newsletter
Scenario League | CSC | Clash of Civs | Spanish Site | CtP Maps | Cradle of Civ | WesW's Ctp1/2 Site | Civ3 Haven

apolyton.net | apolyton.com | civilization2.net | civilization3.net | civilization4.net | civilizationiv.info | calltopower.net | galciv.net | galciv2.net | moo3.net