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 28-02-2005 07:08 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#31 Report this post to a moderator
Get a bigger avatar today!

Ok, I think I got all of your editing...

code:
sint32 good; if (g_theWorld->GetGood(pos, good)){ for(i = 0; i < rec->GetNumIsRestrictedToGood(); i++) { if(rec->GetIsRestrictedToGood(i) == good) { return false; } } } for(i = 0; i < rec->GetNumCantBuildOn(); i++) { if(rec->GetCantBuildOnIndex(i) == cell->GetTerrain()) { return false; } } } return true; }

Last edited by E on 01-03-2005 at 04:07

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

Well, actual I didn't tell you anything about replacing the return true; statement inside your for-loop by a return false; statement. I told you something else. To be precise it was about adding an return false; after your for-loop but still inside your if-block.

Now we have to think about the logic, precisely how should this work. Should it work like this that the original code is executed if there is no IsRestrictedToGood defined. Or should it executed so that the terrain must match and the good must match if IsRestrictedToGood is defined?

-Martin

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:29
  Old Post 01-03-2005 09:18 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#33 Report this post to a moderator
Help yourself to an AD-FREE life

code:
sint32 good; if (g_theWorld->GetGood(pos, good)){ for(i = 0; i < rec->GetNumIsRestrictedToGood(); i++) { if(rec->GetIsRestrictedToGood(i) == good) { return true; } return false; } } for(i = 0; i < rec->GetNumCantBuildOn(); i++) { if(rec->GetCantBuildOnIndex(i) == cell->GetTerrain()) { return false; } } } return true; }

Ok, I think i understood that we added a return false to apply only to the if statement, hadnt seen that before so I might have goofed it.

As for the logic, I tend to say which is easier to do?

But if its about the same effort I'd tend towards:
"the original code is executed if there is no IsRestrictedToGood defined"

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

quote:
Originally posted by E
As for the logic, I tend to say which is easier to do?


Well that's not the question here. The question is what makes the best sense.

quote:
Originally posted by E
But if its about the same effort I'd tend towards:
"the original code is executed if there is no IsRestrictedToGood defined"


And otherwise your code is executed. I think this makes more sense as well. It is stupid to restrict it to a good that appears only on terrain on that you cannot construct the tileimprovement itsself.

First you have to change the order of your code and NumCantBuildOn code. I think the NumCantBuildOn is executed more often. Then surround the original code with an if-block and your code with an else-block. And the condition for your if is that the number of IsRestrictedToGood is zero or less. (Just to cover all possible and nonpossible cases. )

-Martin

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

Ok, I'll give it a shot...


code:
//---------------------------------------------------------------------------- // // Name : 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 // sint32 good : Variable for good // // 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. // // //---------------------------------------------------------------------------- bool terrainutil_CanPlayerBuildAt(const TerrainImprovementRecord *rec, sint32 pl, const MapPoint &pos) { sint32 i; Assert(rec != NULL); if(rec == NULL) return false; Assert(pl >= 0); Assert(pl < k_MAX_PLAYERS); if(pl < 0 || pl >= k_MAX_PLAYERS) return false; Assert(g_player[pl]); if(!g_player[pl]) return false; Cell *cell = g_theWorld->GetCell(pos); Assert(cell); if(!cell) return false; if(cell->GetOwner() == -1) { if(rec->GetIntBorderRadius()) { if(!g_player[pl]->IsVisible(pos)) { return false; } } else { return false; } } if(cell->GetOwner() >= 0 && cell->GetOwner() != pl) { #if defined(ACTIVISION_ORIGINAL) // Non-standard syntax bool haveAlliance = AgreementMatrix.s_agreements.HasAgreement(pl, cell->GetOwner(), PROPOSAL_TREATY_ALLIANCE); #else bool const haveAlliance = AgreementMatrix::s_agreements.HasAgreement(pl, cell->GetOwner(), PROPOSAL_TREATY_ALLIANCE); #endif if(cell->GetOwner() > 0 && haveAlliance) { if(rec->GetClassRoad() || (g_player[pl]->GetGaiaController() && g_player[pl]->GetGaiaController()->GaiaControllerTileImp(rec->GetIndex()))) { } else { return false; } } else { return false; } } if(g_theWorld->GetCity(pos).IsValid()) return false; if(rec->GetClassTerraform()) { sint32 terr; if(!rec->GetTerraformTerrainIndex(terr)) return false; if(cell->GetTerrain() == terr) return false; const TerrainRecord *tfrom = g_theTerrainDB->Get(cell->GetTerrain()); const TerrainRecord *tto = g_theTerrainDB->Get(terr); if(tfrom->GetRemoveAdvanceIndex() < 0 || tto->GetAddAdvanceIndex() < 0) return false; if(!g_player[pl]->HasAdvance(tfrom->GetRemoveAdvanceIndex()) || !g_player[pl]->HasAdvance(tto->GetAddAdvanceIndex())) { return false; } } else { const TerrainImprovementRecord::Effect *eff; eff = terrainutil_GetTerrainEffect(rec, cell->GetTerrain()); if(!eff) return false; if(!g_player[pl]->HasAdvance(eff->GetEnableAdvanceIndex())) return false; sint32 a; for(a = 0; a < eff->GetNumObsoleteAdvance(); a++) { if(g_player[pl]->HasAdvance(eff->GetObsoleteAdvanceIndex(a))) { return false; } } #if defined(ACTIVISION_ORIGINAL) // Non-standard syntax for(i = 0; i < rec->GetNumCantBuildOn(); i++) { if(rec->GetCantBuildOnIndex(i) == cell->GetTerrain()) { return FALSE; } } } #else // Is restricted to code added by E 2-Mar-2005 for(i = 0; i < rec->GetNumCantBuildOn(); i++) { if(rec->GetCantBuildOnIndex(i) == cell->GetTerrain()) { return false; } } } sint32 good; if (g_theWorld->GetGood(pos, good)){ for(i > 0; i < rec->GetNumIsRestrictedToGood(); i++) { if(rec->GetIsRestrictedToGood(i) == good) { return true; } return false; } } #endif return true; }

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

OK, let's start the function's name is terrainutil_CanPlayerBuildAt and not CanPlayerBuildAt and it returns a bool and not a BOOL.

Then there is no parameter called good.

The first word after Remark(s): should be capitalized as it is the case with all the other colon instances.

Replace all the tabs by spaces in the comment block so that the appearance is the same in all editors with equal distance letters.

Now to the code, actual I didn't tell you to add the preprocessor derectives, yet. But this is needed anyway until we have our server in a good condition.

Remove this // Non-standard syntax comment, as the original code is standart syntax, at least it looks like. Then the last closing brace is one too much in the #if-#else-block, move it outside just above the final return.

Then this line is wrong in your last version it was right:

code:
for(i > 0; i < rec->GetNumIsRestrictedToGood(); i++) {


You should get the indention right so that you see where you miss a brace and where is one too much.

And finally put the new but original code into an if-block and your code into an else-block.

And for the condition of the if read this thread, it is not only in my last post.

-Martin

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

Ok, I in corporated your changes....

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. // // //---------------------------------------------------------------------------- bool terrainutil_CanPlayerBuildAt(const TerrainImprovementRecord *rec, sint32 pl, const MapPoint &pos) { sint32 i; Assert(rec != NULL); if(rec == NULL) return false; Assert(pl >= 0); Assert(pl < k_MAX_PLAYERS); if(pl < 0 || pl >= k_MAX_PLAYERS) return false; Assert(g_player[pl]); if(!g_player[pl]) return false; Cell *cell = g_theWorld->GetCell(pos); Assert(cell); if(!cell) return false; if(cell->GetOwner() == -1) { if(rec->GetIntBorderRadius()) { if(!g_player[pl]->IsVisible(pos)) { return false; } } else { return false; } } if(cell->GetOwner() >= 0 && cell->GetOwner() != pl) { #if defined(ACTIVISION_ORIGINAL) bool haveAlliance = AgreementMatrix.s_agreements.HasAgreement(pl, cell->GetOwner(), PROPOSAL_TREATY_ALLIANCE); #else bool const haveAlliance = AgreementMatrix::s_agreements.HasAgreement(pl, cell->GetOwner(), PROPOSAL_TREATY_ALLIANCE); #endif if(cell->GetOwner() > 0 && haveAlliance) { if(rec->GetClassRoad() || (g_player[pl]->GetGaiaController() && g_player[pl]->GetGaiaController()->GaiaControllerTileImp(rec->GetIndex()))) { } else { return false; } } else { return false; } } if(g_theWorld->GetCity(pos).IsValid()) return false; if(rec->GetClassTerraform()) { sint32 terr; if(!rec->GetTerraformTerrainIndex(terr)) return false; if(cell->GetTerrain() == terr) return false; const TerrainRecord *tfrom = g_theTerrainDB->Get(cell->GetTerrain()); const TerrainRecord *tto = g_theTerrainDB->Get(terr); if(tfrom->GetRemoveAdvanceIndex() < 0 || tto->GetAddAdvanceIndex() < 0) return false; if(!g_player[pl]->HasAdvance(tfrom->GetRemoveAdvanceIndex()) || !g_player[pl]->HasAdvance(tto->GetAddAdvanceIndex())) { return false; } } else { const TerrainImprovementRecord::Effect *eff; eff = terrainutil_GetTerrainEffect(rec, cell->GetTerrain()); if(!eff) return false; if(!g_player[pl]->HasAdvance(eff->GetEnableAdvanceIndex())) return false; sint32 a; for(a = 0; a < eff->GetNumObsoleteAdvance(); a++) { if(g_player[pl]->HasAdvance(eff->GetObsoleteAdvanceIndex(a))) { return false; } } #if defined(ACTIVISION_ORIGINAL) // Non-standard syntax for(i = 0; i < rec->GetNumCantBuildOn(); i++) { if(rec->GetCantBuildOnIndex(i) == cell->GetTerrain()) { return FALSE; } } } #else // Is restricted to code added by E 2-Mar-2005 for(i = 0; i < rec->GetNumCantBuildOn(); i++) { if(rec->GetCantBuildOnIndex(i) == cell->GetTerrain()) { return false; } else { sint32 good; if (g_theWorld->GetGood(pos, good)){ for(i = 0; i > rec->GetNumIsRestrictedToGood(); i++) { if(rec->GetIsRestrictedToGood(i) == good) { return true; } return false; } } } } #endif return true; }


I think I got the BOLD part right. Not sure I understood the less than your looking for. Also I think I added an else like you said was needed...

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:29
Post  Old Post 07-03-2005 02:58 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#38 Report this post to a moderator
Support Apolyton, buy Civilization III: Complete

quote:
Originally posted by E
I think I got the BOLD part right. Not sure I understood the less than your looking for.


Well that's true for the bold part, that wasn't so difficuilt, but for rest... Just to make it clear, you have to type the code on your own.

quote:
Originally posted by E
Also I think I added an else like you said was needed...


I didn't say that an else was needed inside of the for-loop, I told you to move your part of the new code into an else-block and the original part into an corresponding if-block.

And since I have so often repeated the condition of this if, I leave it up to you to reread the according posts.

And two other things I told you as well were to remove this second Non-standard syntax comment and to move the final closing brace inside the #if-#else-block just below of this block.

OK again in four point:

1. if-else, original code - your code
2. Figure out the condition of the if.
3. Remove second "// Non-standard syntax" comment
4. Closing brace

-Martin

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

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. // // //---------------------------------------------------------------------------- bool terrainutil_CanPlayerBuildAt(const TerrainImprovementRecord *rec, sint32 pl, const MapPoint &pos) { sint32 i; Assert(rec != NULL); if(rec == NULL) return false; Assert(pl >= 0); Assert(pl < k_MAX_PLAYERS); if(pl < 0 || pl >= k_MAX_PLAYERS) return false; Assert(g_player[pl]); if(!g_player[pl]) return false; Cell *cell = g_theWorld->GetCell(pos); Assert(cell); if(!cell) return false; if(cell->GetOwner() == -1) { if(rec->GetIntBorderRadius()) { if(!g_player[pl]->IsVisible(pos)) { return false; } } else { return false; } } if(cell->GetOwner() >= 0 && cell->GetOwner() != pl) { #if defined(ACTIVISION_ORIGINAL) bool haveAlliance = AgreementMatrix.s_agreements.HasAgreement(pl, cell->GetOwner(), PROPOSAL_TREATY_ALLIANCE); #else bool const haveAlliance = AgreementMatrix::s_agreements.HasAgreement(pl, cell->GetOwner(), PROPOSAL_TREATY_ALLIANCE); #endif if(cell->GetOwner() > 0 && haveAlliance) { if(rec->GetClassRoad() || (g_player[pl]->GetGaiaController() && g_player[pl]->GetGaiaController()->GaiaControllerTileImp(rec->GetIndex()))) { } else { return false; } } else { return false; } } if(g_theWorld->GetCity(pos).IsValid()) return false; if(rec->GetClassTerraform()) { sint32 terr; if(!rec->GetTerraformTerrainIndex(terr)) return false; if(cell->GetTerrain() == terr) return false; const TerrainRecord *tfrom = g_theTerrainDB->Get(cell->GetTerrain()); const TerrainRecord *tto = g_theTerrainDB->Get(terr); if(tfrom->GetRemoveAdvanceIndex() < 0 || tto->GetAddAdvanceIndex() < 0) return false; if(!g_player[pl]->HasAdvance(tfrom->GetRemoveAdvanceIndex()) || !g_player[pl]->HasAdvance(tto->GetAddAdvanceIndex())) { return false; } } else { const TerrainImprovementRecord::Effect *eff; eff = terrainutil_GetTerrainEffect(rec, cell->GetTerrain()); if(!eff) return false; if(!g_player[pl]->HasAdvance(eff->GetEnableAdvanceIndex())) return false; sint32 a; for(a = 0; a < eff->GetNumObsoleteAdvance(); a++) { if(g_player[pl]->HasAdvance(eff->GetObsoleteAdvanceIndex(a))) { return false; } } #if defined(ACTIVISION_ORIGINAL) for(i = 0; i < rec->GetNumCantBuildOn(); i++) { if(rec->GetCantBuildOnIndex(i) == cell->GetTerrain()) { return false; } } } #else // Is restricted to code added by E 2-Mar-2005 if(rec->IsRestrictedToGood){ for(i = 0; i < rec->GetNumCantBuildOn(); i++) { if(rec->GetCantBuildOnIndex(i) == cell->GetTerrain()) { return false; } } } else{ sint32 good; if (g_theWorld->GetGood(pos, good)){ for(i = -1; i > rec->GetNumIsRestrictedToGood(); i++) { if(rec->GetIsRestrictedToGood(i) == good) { return true; } return false; } } } #endif return true; }


I think where I'm confsed on your if-else statement is that I'm not clear if you are asking for a #if and #else or an if and else for the code. It just didn't come across if its a comment thing or a coding thing.

But I'm hoping I got you this time.

Last edited by E on 12-03-2005 at 01:25

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:29
Post  Old Post 09-03-2005 22:03 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#40 Report this post to a moderator
Get a bigger avatar today!

quote:
Originally posted by E
But I'm hoping I got you this time.


No, you didn't got me.

quote:
Originally posted by E
I think where I'm confsed on your if-else statement is that I'm not clear if you are asking for a #if and #else or an if and else for the code. It just didn't come across if its a comment thing or a coding thing.


Again the precompiler statements start all with a #. The precompiler is a text replacement tool or in this case a text selection tool. That means if the condition behind the #if is true the following text is used otherwise it is cut out and the text following the #else is used.

Now do the following: Form two versions of the following code fragment one that the preprocessor generates if the statement defined(ACTIVISION_ORIGINAL) is true and one if this statement is false. And finally post these two code fragments. You have to get this!

code:
#if defined(ACTIVISION_ORIGINAL) for(i = 0; i < rec->GetNumCantBuildOn(); i++) { if(rec->GetCantBuildOnIndex(i) == cell->GetTerrain()) { return false; } } } #else // Is restricted to code added by E 2-Mar-2005 sint32 good; if (g_theWorld->GetGood(pos, good)){ for(i = -1; i > rec->GetNumIsRestrictedToGood(); i++) { if(rec->GetIsRestrictedToGood(i) == good) { return true; } return false; } } } #endif return true; }


Now let's come to the code that is selected by the preprocessor and finally compiled:

I marked some stuff here. Last time I told you to move out the final closing brace in the coresponding preprocessor blocks under the preprocessor derectives. This time I made them bold. This is just duplicated code and actual not really changed.

Now I marked two other things that were already all right. The first one is the -1, fortunatly the GetIsRestrictedToGood has a guard against invalid array access, otherwise you would crash the game. Unfortunatly returns the function in this case 0 and that is not so good if the good on the according map the first one in the good database.

The second one is this bigger operator. Well you didn't turn this into an endless loop, but it will run for a long time, not a very good idea. To make this clear I never have told you modify any for-loops.

Now again what we want to do, if the number of IsRestrictedToGood is 0 then the original code should be executed. Otherwise your new code has to be executed. That means you have to use an if-statement and an else-statement. And don't mix these up with the preprocessor derectives they start with a #.

And now I am more precise as I actual intended. You should do something like this:

code:
#if defined(ACTIVISION_ORIGINAL) //Original code no need to change it //Except the final closing brace #else if(/*Condition you have to figure out and it was given often enough in this thread*/){ //Original code } else{ //Your new code } #endif


So here again in brief I copy the remaining things from the last list:

1. if-else, original code - your code
2. Figure out the condition of the if.
3. Closing brace
4. Fix the stuf you have broken.
5. And do the preprocessor execise.

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

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. // // //---------------------------------------------------------------------------- bool terrainutil_CanPlayerBuildAt(const TerrainImprovementRecord *rec, sint32 pl, const MapPoint &pos) { sint32 i; Assert(rec != NULL); if(rec == NULL) return false; Assert(pl >= 0); Assert(pl < k_MAX_PLAYERS); if(pl < 0 || pl >= k_MAX_PLAYERS) return false; Assert(g_player[pl]); if(!g_player[pl]) return false; Cell *cell = g_theWorld->GetCell(pos); Assert(cell); if(!cell) return false; if(cell->GetOwner() == -1) { if(rec->GetIntBorderRadius()) { if(!g_player[pl]->IsVisible(pos)) { return false; } } else { return false; } } if(cell->GetOwner() >= 0 && cell->GetOwner() != pl) { #if defined(ACTIVISION_ORIGINAL) bool haveAlliance = AgreementMatrix.s_agreements.HasAgreement(pl, cell->GetOwner(), PROPOSAL_TREATY_ALLIANCE); #else bool const haveAlliance = AgreementMatrix::s_agreements.HasAgreement(pl, cell->GetOwner(), PROPOSAL_TREATY_ALLIANCE); #endif if(cell->GetOwner() > 0 && haveAlliance) { if(rec->GetClassRoad() || (g_player[pl]->GetGaiaController() && g_player[pl]->GetGaiaController()->GaiaControllerTileImp(rec->GetIndex()))) { } else { return false; } } else { return false; } } if(g_theWorld->GetCity(pos).IsValid()) return false; if(rec->GetClassTerraform()) { sint32 terr; if(!rec->GetTerraformTerrainIndex(terr)) return false; if(cell->GetTerrain() == terr) return false; const TerrainRecord *tfrom = g_theTerrainDB->Get(cell->GetTerrain()); const TerrainRecord *tto = g_theTerrainDB->Get(terr); if(tfrom->GetRemoveAdvanceIndex() < 0 || tto->GetAddAdvanceIndex() < 0) return false; if(!g_player[pl]->HasAdvance(tfrom->GetRemoveAdvanceIndex()) || !g_player[pl]->HasAdvance(tto->GetAddAdvanceIndex())) { return false; } } else { const TerrainImprovementRecord::Effect *eff; eff = terrainutil_GetTerrainEffect(rec, cell->GetTerrain()); if(!eff) return false; if(!g_player[pl]->HasAdvance(eff->GetEnableAdvanceIndex())) return false; sint32 a; for(a = 0; a < eff->GetNumObsoleteAdvance(); a++) { if(g_player[pl]->HasAdvance(eff->GetObsoleteAdvanceIndex(a))) { return false; } } #if defined(ACTIVISION_ORIGINAL) for(i = 0; i < rec->GetNumCantBuildOn(); i++) { if(rec->GetCantBuildOnIndex(i) == cell->GetTerrain()) { return FALSE; } } } #else // Is restricted to code added by E 2-Mar-2005 if(rec->IsRestrictedToGood){ for(i = 0; i < rec->GetNumCantBuildOn(); i++) { if(rec->GetCantBuildOnIndex(i) == cell->GetTerrain()) { return false; } else { sint32 good; if (g_theWorld->GetGood(pos, good)){ for(i = 1; i > rec->GetNumIsRestrictedToGood(); i++) { if(rec->GetIsRestrictedToGood(i) == good) { return true; } return false; } } } } #endif return true; }


checking on the preprocesor stuff

Last edited by E on 12-03-2005 at 03:20

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

First thing you have to still to do the preprocessor exercise. Then the else block is again inside the for-loop of the original code. Then you didn't fix your for-loop, well you removed the - in front of the 1. So you start now to check the second element of the good's list. Not a good idea especially if this list just contain one element. Then you didn't replaced that > operator by an smaller operator to restore the state you already had. The function still needs ages to check whether the condition is right.

Then the final closing brace in the preprocessor blocks is still there and not outside, I even marked it last time.

Well at least you added the if in comparision to the correspnding else at the right place. But the condition is wrong. You should check whether the number of the elements of IsRestrictedToGood is 0, that can't be so difficuilt to get this you use the right function already in your code, and you got it right for the culture only stuff.

And finally or better to this first, get the indention right, that helps you as well.

OK, here the list in brief:

1. Indention
2. Do the preprocessor exercise
3. Move out the closing brace that is too much in the preprocessor blocks
4. Find the correct condition for the if
5. Put the else block onto the right level and correct the indention first!
6. Fix the for loop, it does'n start at one and it is a smaller than a greater

-Martin

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:29
  Old Post 13-03-2005 07:20 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#43 Report this post to a moderator
Increase Your PM Length

oops wrong thread...

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:29
  Old Post 15-03-2005 10:12 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#44 Report this post to a moderator
Browse Apolyton AD-FREE

Taking another crack at 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. // // //---------------------------------------------------------------------------- bool terrainutil_CanPlayerBuildAt(const TerrainImprovementRecord *rec, sint32 pl, const MapPoint &pos) { sint32 i; Assert(rec != NULL); if(rec == NULL) return false; Assert(pl >= 0); Assert(pl < k_MAX_PLAYERS); if(pl < 0 || pl >= k_MAX_PLAYERS) return false; Assert(g_player[pl]); if(!g_player[pl]) return false; Cell *cell = g_theWorld->GetCell(pos); Assert(cell); if(!cell) return false; if(cell->GetOwner() == -1) { if(rec->GetIntBorderRadius()) { if(!g_player[pl]->IsVisible(pos)) { return false; } } else { return false; } } if(cell->GetOwner() >= 0 && cell->GetOwner() != pl) { #if defined(ACTIVISION_ORIGINAL) bool haveAlliance = AgreementMatrix.s_agreements.HasAgreement(pl, cell->GetOwner(), PROPOSAL_TREATY_ALLIANCE); #else bool const haveAlliance = AgreementMatrix::s_agreements.HasAgreement(pl, cell->GetOwner(), PROPOSAL_TREATY_ALLIANCE); #endif if(cell->GetOwner() > 0 && haveAlliance) { if(rec->GetClassRoad() || (g_player[pl]->GetGaiaController() && g_player[pl]->GetGaiaController()->GaiaControllerTileImp(rec->GetIndex()))) { } else { return false; } } else { return false; } } if(g_theWorld->GetCity(pos).IsValid()) return false; if(rec->GetClassTerraform()) { sint32 terr; if(!rec->GetTerraformTerrainIndex(terr)) return false; if(cell->GetTerrain() == terr) return false; const TerrainRecord *tfrom = g_theTerrainDB->Get(cell->GetTerrain()); const TerrainRecord *tto = g_theTerrainDB->Get(terr); if(tfrom->GetRemoveAdvanceIndex() < 0 || tto->GetAddAdvanceIndex() < 0) return false; if(!g_player[pl]->HasAdvance(tfrom->GetRemoveAdvanceIndex()) || !g_player[pl]->HasAdvance(tto->GetAddAdvanceIndex())) { return false; } } else { const TerrainImprovementRecord::Effect *eff; eff = terrainutil_GetTerrainEffect(rec, cell->GetTerrain()); if(!eff) return false; if(!g_player[pl]->HasAdvance(eff->GetEnableAdvanceIndex())) return false; sint32 a; for(a = 0; a < eff->GetNumObsoleteAdvance(); a++) { if(g_player[pl]->HasAdvance(eff->GetObsoleteAdvanceIndex(a))) { return false; } } #if defined (ACTIVISION_ORIGINAL) for(i = 0; i < rec->GetNumCantBuildOn(); i++) { if(rec->GetCantBuildOnIndex(i) == cell->GetTerrain()) { return FALSE; } } #else // Is restricted to code added by E 2-Mar-2005 if(rec->IsRestrictedToGood = 0) { for(i = 0; i < rec->GetNumCantBuildOn(); i++) { if(rec->GetCantBuildOnIndex(i) == cell->GetTerrain()) { return false; } } } else { sint32 good; if (g_theWorld->GetGood(pos, good)) { for(i = 0; i < rec->GetNumIsRestrictedToGood(); i++) { if(rec->GetIsRestrictedToGood(i) == good) { return true; } return false; } } } #endif return true; }



I was going to put: if(rec->IsRestrictedToGood > 0) like in the culture code, but I re-read one of your lines that said if IsRestrictedToGood is 0 then it should execute the original. I'm not sure you intended me to put an '=' there to do it, butI put it out there to find out why its '=' or if it should be a '>' like the other code how does it execute the first code only?

Last edited by E on 16-03-2005 at 01:44

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:29
Post  Old Post 15-03-2005 23:02 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#45 Report this post to a moderator
Get a bigger avatar today!

quote:
Originally posted by E
I was going to put: if(rec->IsRestrictedToGood > 0) like in the culture code, but I re-read one of your lines that said if IsRestrictedToGood is 0 then it should execute the original.


Actual I said something about the number of IsRestrictedToGood that's something else. I thought it is obviously in order to get the number of IsRestrictedToGood, to use the function that has the first syllable of number in its name.

quote:
Originally posted by E
I'm not sure you intended me to put an '=' there to do it, butI put it out there to find out why its '=' or if it should be a '>' like the other code how does it execute the first code only?


Actual I neither intended you to put an '=' nor a '>' but a '=='. First is an assignment the second is a bigger and the third is an equal.

The first operator assignes the value of the right variable to the left variable. Or in other words the value of the left variable becomes the value of the right variable.

Bigger is an operator that checks whether the right variable is bigger than the left variable. If it is the case it returns true otherwise false. And the third the equal checks whether the varaiables on both sides have (or contain) the same value(s).

The last two operators return a boolean value, true or false.

Since we have here an alternative, on the one hand the code that is present in the original and on the other hand the code code you wrote, we have to do a decission, between the codes.

Internally the IsRestrictedToGood items are stored in an array. So what happens if there is not a single IsRestrictedToGood defined. The answer is that array is empty and its size is therefore zero.

Now two the code:
First thing is that you changed the preprocessor derectives, as we want to replace here original code we have to go with the #if-#else-#endif derectives. As it was in the last version. Well you removed the closing brace that was too much inside the preprocessor blocks, but you didn't add it outside just above the final return.

Then the indention is not fixed.

Another thing I just notice is that the return false inside your code is at the wrong place. It is inside the for-loop but, it should be outside, just right below the for-loop. So move it down one line.

And you have to edit the description, especially you have to add some line breaks and replace the tabs by spaces. For the line breaks orientate you on the lines with the: ---- The text should not end to much behind the end of the ------.

-Martin

-Martin

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

code:
#if defined (ACTIVISION_ORIGINAL) for(i = 0; i < rec->GetNumCantBuildOn(); i++) { if(rec->GetCantBuildOnIndex(i) == cell->GetTerrain()) { return FALSE; } } } #else // Is restricted to code added by E 2-Mar-2005 if(rec->IsRestrictedToGood == 0) { for(i = 0; i < rec->GetNumCantBuildOn(); i++) { if(rec->GetCantBuildOnIndex(i) == cell->GetTerrain()) { return false; } } } else { sint32 good; if (g_theWorld->GetGood(pos, good)) { for(i = 0; i < rec->GetNumIsRestrictedToGood(); i++) { if(rec->GetIsRestrictedToGood(i) == good) { return true; } } return false; } } #endif

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:29
  Old Post 24-03-2005 03:05 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#47 Report this post to a moderator
Avatar Enlargement: We've got the solution

Martin, is this finished yet?

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:29
Post  Old Post 24-03-2005 03:50 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#48 Report this post to a moderator
Get a bigger avatar today!

quote:
Originally posted by E
Martin, is this finished yet?


Not quite, first I cannot see what is under and above the block of code you posted. Last time there was a closing brace missing right above the final return, outside of the precompiler block. Now you have one too much in the ACTIVISION_ORIGINAL block.

And then you have to get the indention right, the return true; inside your for-loop has one tab too much and the return false; under the for-loop has one tab too less.

Other than that it seems to be OK.

-Martin

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:29
Post  Old Post 26-03-2005 04:24 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#49 Report this post to a moderator
Support Apolyton, buy GURPS/ Alpha Centauri

OK let's start about the zip file: It contains a folder called Ctp2_code, if you unzip it on a Linux system you have a problem. A Unix file system is case sensitive and the consequence is Ctp2_code != ctp2_code. Well that doesn't matter when you submit it to the repository. Another thing I wonder about is why in the archive are two copies of each *.cdb, same file, same directory, same size.

unit.cdb seems to be ok, but why is SettleImprovement outcommented. However if it wouldn't be outcommented then there would be a problem, a unit could only settle one definite type of improvement, or do you want to add some random effects? Otherwise the is no sense to make it an array. By the EnableAdvance isn't an array, either.

terrimprove.cbd is not OK.

Let's start with the harmless stuff. If you add Wonder and Urban to Class you should also add it to Excludes. You don't know what modders want to do.

What's that:

quote:

Record Resource[0] PlantGood //added by E for future imp that places a good instead
Record Resource[1] PlantGood //added by E for future imp that places a good instead
Record Resource[2] PlantGood //added by E for future imp that places a good instead
Record Resource[3] PlantGood //added by E for future imp that places a good instead
Record Resource[4] PlantGood //added by E for future imp that places a good instead


I thought you wanted to use an integer, that can have the values 0-3 indicating the index in the according terrain database array.

That are are Resource database record and this array notation is probably invalid syntax.

Then what do you want to do here? Do you want to allow a maximum of four goods to that a tileimp can be restricted to? Why not all goods in the database?

quote:

Record Resource[0..4] IsRestrictedToGood //added by E -- can only build imps if tile has good


wonder.cdb is ok.
advance.cdb seems to be compilable. However CantTrade and CantCapture suggests that normally advances can trade. This is of course wrong they should be CantBeTraded and CantBeCaptured.

And Bridges is at the wrong place it, belongs into the tileimp.txt and should be something like BridgeAdvance, like EnablingAdvance. Probably mot every modder likes it that you need the same advance for building bridges on grassland and for building bridges in the swamp.

Now to the source files. But only in brief for today.
wonder_util.cpp

Spend the description of wonderutil_IsAvailable a conluding new free line. So that it looks better. The description what you have done at the start of the file is missing.

The code for CityStyleOnly should be modelled like the one above for GovernmentType, otherwise the CityStyleOnly precedes CultureOnly only.

m_government_type is not a member of wonderutil, it isn't possible wonderutil isn't a class. And there aren't global, either. The same holds for m_founder and GetCivilisation.

terrainutil.cpp isn't correct either, check the description at the top of the file, check the description of the function you have modified. Get the indention right, and insert at the right place a closing brace, you have erased in the meantime.

So that must be enough for today. It is late and I should go to bed.

-Martin

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:29
  Old Post 28-03-2005 08:43 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#50 Report this post to a moderator
Support Apolyton, buy Galactic Civilizations: Deluxe Edition

Looking at cdb I saw stuff like this:

code:
Struct SlaveRaidsData { Float Chance, DeathChance Int Timer, Amount Record Sound Sound Record SpecialEffect Effect } Bit(Struct SlaveRaidsData) SlaveRaids


Do the Bit make it optional. I'd like to add a bit for the POW code and create unit x number of turns.

I know a lot of this has been SLIC'd but if its easier for modders I think its better and it allows SLIC time to be spent on newer ideas.

I'm working on fixing the code and postingit soon (bytheway not sure why my zip duplicated the cdbs I though it wouldn't show)

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

quote:
Originally posted by Martin Gühmann
. The description what you have done at the start of the file is missing.

m_government_type is not a member of wonderutil, it isn't possible wonderutil isn't a class. And there aren't global, either. The same holds for m_founder and GetCivilisation.

terrainutil.cpp isn't correct either, check the description at the top of the file, check the description of the function you have modified. Get the indention right, and insert at the right place a closing brace, you have erased in the meantime.

So that must be enough for today. It is late and I should go to bed.

-Martin


Should I add an Init_Player like in player.cpp to establish the m_govt_type OR should I use the global g_player to get info about the player and then compare it?

I think I got the rest...

Attachment: 2005.03.28.restrict.only.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 29-03-2005 22:52 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#52 Report this post to a moderator
Help yourself to an AD-FREE life

OK, let's see and have a look on the *.cdb files:

advace.cdb is OK.
building.cdb is OK.
wonder.cdb is OK.
government.cdb is OK.

Now to the problematic files:

terrimprove.cdb:

code:
Struct Effect { Record Terrain[] Terrain Bit(Int) BonusFood Bit(Int) BonusProduction Bit(Int) BonusGold Bit(Int) MoveCost #Added by Martin Gühmann for Trade redirection Bit(Int) Freight Bit Radar Bit CantPillage //futureUse added by E to prevent pillage of certain imps Bit NeedsWorker //futureUse - can't build unless IsWorker unit is on square Bit NeedsWaterSupply //futureUse -- can only build on rivers or adjacent to other IsWaterSupply imps Bit Airport Bit ListeningPost Bit Endgame Bit(Int) VisionRange Bit(Int) RadarRange Bit(Float) DefenseBonus Record Resource[] PlantGood //added by E for future imp that places a good instead Record Advance EnableAdvance Record Advance[] ObsoleteAdvance Int ProductionCost Int ProductionTime Int TilesetIndex }


Now to the problematic line:

code:
Record Resource[] PlantGood //added by E for future imp


How many goods do you want to plant on a certain spot. 1, 2, 20, all you can find in the database? I guess this is a little bit utopic. A spot can only contain only one good, so it must not be an array.

Second problem, what happens if you specify a good that you can't plant on the spot. Should the game crash? Or should nothing happen, should the resources spent for the tileimp be wasted? Of course neither should the game crash nor should the PW wasted.

So again PlantGood should be an integer and not a database entry in the good database, nor should be an array in of entries in the good database. It should be just a plain integer like ProductionCost, ProductionTime or TilesetIndex. But in comparision to those it should be optional like BonusFood, BonusProduction or BonusGold.

It should now be obvious how this line should look.

To the next wrong line in this file:

code:
Record Sound Sound Record Terrain[] CantBuildOn Record Government[] GovernmentsModified Record CityStyle[] CultureOnly //added by E -- can only build imps if civ has certain citystyle Record Government[] GovernmentType //added by E --- a copy of unit Government type code Record Resource[0..4] IsRestrictedToGood //added by E -- can only build imps if tile has good Bit(Struct Effect) Effect Struct Effect[] TerrainEffect


The line in particular:

code:
Record Resource[0..4] IsRestrictedToGood //added by E -- can only build imps if tile has good


Come on you don't want to restrict the maximum number of goods to that a terrain improvement can be restricted to four. It should be a free array like GovernmentType, CultureOnly or CantBuildOn.

Now let's come to unit.cdb:

code:
Record Advance EnableAdvance Record Advance[0..5] ObsoleteAdvance Record Government[] GovernmentsModified Record Unit[] UpgradeTo //FutureUse to create Upgrade Paths, cost based on difference ShieldCost x Gold? Record Terrain[] CanSettleOn //added by E restricts settling to certain terrains Record CityStyle[] CultureOnly //added by E -- can only build units if civ has certain citystyle Record CityStyle[] CityStyleOnly //added by E--can only build units at cities with certain citystyle Record TerrainImprovement[] SettleImprovement // future use - for units to make specific imps like forts


The first line that is wrong is:

code:
Record Unit[] UpgradeTo //FutureUse to create Upgrade Paths, cost based on difference ShieldCost x Gold?


UpgradeTo is an array, but you cannot upgrade one unit to one unit type on the one hand and to another different unit type at the same time. For instance a unit can't be a settler and a diplomat at the same time. That's impossible. However you rethink it yourself anyways. But again this is a single unit record like EnableAdvance is a single advance record. And therefore it isn't an array, either.

Well wether SettleImprovement should be an array of records or an single record is a design issure.

The following flag name is missleading:

code:
Bit(Int) CostPopToBuild //added for future use


It reminds me of BuildingRemovesAPop, probably a better name would be PopCostsToBuild, maybe PopCosts is enough to make it clear.

That was the *.cdb part.

In Player.cpp, the function Player::CanBuildUnit is not correct, you forgot to remove the first ACTIVISION_ORIGINAL right at the start of the function, it even hasn't a coresponding matching #endif.

CityData.cpp:

code:
//---------------------------------------------------------------------------- // // Name : CityData::CanBuildBuilding // // Description: Checks whether the city can build the building specified by // type. // // Parameters : type: The building type for that is checked whether the city // can build it. // // Globals : g_player: The list of players // g_theBuildingDB: The building database // g_slicEngine: The slic engine // g_theWorld: The world prperties // // Returns : Whether the city can build the building specified by type. // // Remark(s) : CityStyleOnly added by E. Limits certain buildings to be built // only at certain cities of certain styles. // GovernmentType flag for Buidings limits Buildings to govt type. // CultureOnly flag added by E. It allows only civilizations with // the same CityStyle as CultureOnly's style to build that building. //---------------------------------------------------------------------------- BOOL CityData::CanBuildBuilding(sint32 type) const { if(g_exclusions->IsBuildingExcluded(type)) return FALSE; const BuildingRecord* irec = g_theBuildingDB->Get(type); Assert(irec != NULL); if (!irec) return FALSE; if(!g_player[m_owner]->HasAdvance(irec->GetEnableAdvanceIndex()) && irec->GetEnableAdvanceIndex() >= 0) { return FALSE; } sint32 o; for(o = 0; o < irec->GetNumObsoleteAdvance(); o++) { if(g_player[m_owner]->HasAdvance(irec->GetObsoleteAdvanceIndex(o))) return FALSE; } MapPoint pos; m_home_city.GetPos(pos); if(g_theWorld->IsWater(pos)) { if(irec->GetCantBuildInSea()) return FALSE; } else { if(irec->GetCantBuildOnLand()) return FALSE; } if (irec->GetCoastalBuilding()) { if(!g_theWorld->IsNextToWater(pos.x, pos.y)) return FALSE; } if(m_built_improvements & uint64((uint64)1 << (uint64)type)) { return FALSE; } if((irec->GetNuclearPlant() && wonderutil_GetNukesEliminated(g_theWonderTracker->GetBuiltWonders()))) { return FALSE; } if(irec->GetNumPrerequisiteBuilding() > 0) { for(o = 0; o < irec->GetNumPrerequisiteBuilding(); o++) { sint32 b = irec->GetPrerequisiteBuildingIndex(o); if(!(GetEffectiveBuildings() & ((uint64)1 << (uint64)b))) return FALSE; } } #if !defined(ACTIVISION_ORIGINAL) if(irec->GetNumGovernmentType() > 0) { sint32 i; bool found = false; for(i = 0; i < irec->GetNumGovernmentType(); i++) { if(irec->GetGovernmentTypeIndex(i) == m_government_type) { found = true; break; } } if(!found) return FALSE; } if(irec->GetNumCityStyleOnly() > 0) { sint32 s; for(s = 0; s < irec->GetNumCityStyleOnly(); s++) { if(irec->GetCityStyleOnlyIndex(s) == g_player[m_founder]->m_citystyle) { return TRUE; } } return FALSE } if(irec->GetNumCultureOnly() > 0) { sint32 s; for(s = 0; s < irec->GetNumCultureOnly(); s++) { if(irec->GetCultureOnlyIndex(s) == GetCivilisation()->GetCityStyle()) { return TRUE; } } return FALSE; } #endif return g_slicEngine->CallMod(mod_CanCityBuildBuilding, TRUE, m_home_city.m_id, irec->GetIndex()); }


In this function we have a typo in the description of the function. In the line of the g_theWorld. Just because I saw it and "prperties" is also one of my favourites. And so I realize that it is actual my typo. But fix it anyway. Now to the more important stuff.

The code about CityStyleOnly should be modelled like the one for GovernmentType.

Again m_government_type is a member of player. So you need the accoring function of the Player class. The same hold for GetCivilisation. The according player is the owner of the city. And for the CityStyleOnly part you have to compare it against the city style of the city not against the city style of the founder. The city style of the city itsself can be changed by the cheat editor. The same is true for the code in the CanBuildUnit code and there as well the code should be modelled like the code of GovernmentType.

Well that isn't everthing, but for today it is enough.

-Martin

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

quote:
[SIZE=1] Originally posted by Martin Gühmann
The code about CityStyleOnly should be modelled like the one for GovernmentType.

Again m_government_type is a member of player. So you need the accoring function of the Player class. The same hold for GetCivilisation. The according player is the owner of the city. And for the CityStyleOnly part you have to compare it against the city style of the city not against the city style of the founder. The city style of the city itsself can be changed by the cheat editor. The same is true for the code in the CanBuildUnit code and there as well the code should be modelled like the code of GovernmentType.

Well that isn't everthing, but for today it is enough.

-Martin


I understood most of your correections. As for UpgradeTo, I leave it as you suggested but as I dug into the cdbs again I think it might later be better at a "struc" so the moder could define how much the upgrade cost is as opposed to adding a calculation (and it could make the cost in PW and/or gold)

It was a bit unclear to me about "function of the player class" kind of new terms to me but I took a stab at it. Like wise the modelling after govt type, not sure which you wanted modelled but I look for the differences and changed to what govt type had, but I don't really understand what the difference is. anyways here's the code:


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; for(s = 0; s < irec->GetNumCityStyleOnly(); s++) { if(irec->GetCityStyleOnlyIndex(s) == g_player[m_founder]->m_citystyle) { found = true; break; } } if(!found) return FALSE; } if(irec->GetNumCultureOnly() > 0) { sint32 s; 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

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

Well, I suppose the piece of code belongs into the function I have posted above.

I don't check this now deeply. But the part about CityStyleOnl is still wrong. First the Player class does not has a m_CityStyle member. And getting the founder's style isn't a good idea, either. Since I can place cities with the cheat editor of whatever style I whish.

So again you have to use the m_cityStyle member of the CityData class. For the CityData class check the citydata.h and there you find the keyword class and behind it CityData. In brief a class is some kind of container. It contains fields like m_cityData and methods like AddShieldsToBuilding. In the past I mixed up the terms function and method. Maybe you can define methods as member functions. But we don't have to go to deeply into the termology.

OK, and another aspect. To be precise a class is not a container but the contruction plan of such a container.

And an object is an instace of such a class.

Now each city has its CityData the container of all the pieces of information about a concret city. And of course its methods to manipulate the pieces of information.

-Martin

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:29
  Old Post 07-04-2005 20:55 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#55 Report this post to a moderator
Tired of ads?

Martin, I checked out the *.h files for citydata and player and found the m_citystyle (in citydata.h) and m_civilization (in player.h). Now that I can find where to get the m_ stuff do you have an example for it so I know what it should look like or is the government type a good enough example?


also would it be something like g_CivilizationData to use these classes in CivilzationData.h:

code:
//---------------------------------------------------------------------------- // Class declarations //---------------------------------------------------------------------------- #endif // _MSC_VER class CivilisationData : public GAMEOBJ { public: PLAYER_INDEX m_owner ; uint8 m_cityname_count[k_MAX_CITY_NAMES] ; CIV_INDEX m_civ ; GENDER m_gender; sint32 m_cityStyle; MBCHAR m_leader_name[k_MAX_NAME_LEN], m_personality_description[k_MAX_NAME_LEN], m_civilisation_name[k_MAX_NAME_LEN], m_country_name[k_MAX_NAME_LEN], m_singular_name[k_MAX_NAME_LEN] ;


I'm mainly interested in m_civilisation_name and m_citystyle

Last edited by E on 08-04-2005 at 04:24

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:29
Post  Old Post 08-04-2005 19:20 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#56 Report this post to a moderator
Get a bigger avatar today!

quote:
Originally posted by E
Martin, I checked out the *.h files for citydata and player and found the m_citystyle (in citydata.h) and m_civilization (in player.h). Now that I can find where to get the m_ stuff do you have an example for it so I know what it should look like or is the government type a good enough example?


As it is a member variable you can use the this pointer to access it, if you are inside of a member function of CityData in this case.

The syntax would be something like this (explicitely):

this->m_citystyle;

Implicitely it is just:

m_citystyle;

The way as it is done in all the files.

quote:
Originally posted by E
also would it be something like g_CivilizationData to use these classes in CivilzationData.h:
code:
//---------------------------------------------------------------------------- // Class declarations //---------------------------------------------------------------------------- #endif // _MSC_VER class CivilisationData : public GAMEOBJ { public: PLAYER_INDEX m_owner ; uint8 m_cityname_count[k_MAX_CITY_NAMES] ; CIV_INDEX m_civ ; GENDER m_gender; sint32 m_cityStyle; MBCHAR m_leader_name[k_MAX_NAME_LEN], m_personality_description[k_MAX_NAME_LEN], m_civilisation_name[k_MAX_NAME_LEN], m_country_name[k_MAX_NAME_LEN], m_singular_name[k_MAX_NAME_LEN] ;


I'm mainly interested in m_civilisation_name and m_citystyle


I think the stuff you are looking for is rather called g_theCivilisationDB of class something, and it should have a method to retrieve the StringID of the civ name, and once you have this you can compare it with the entry in Unit.txt easily.

-Martin

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:29
  Old Post 08-04-2005 21:09 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#57 Report this post to a moderator
Got spare money?

Martin so i should have something like this for the citystyle:

g_citydata->m_citystyle

I haven't seen a g_citydata in the code before...

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

quote:
Originally posted by E
Martin so i should have something like this for the citystyle:

g_citydata->m_citystyle

I haven't seen a g_citydata in the code before...


No, this doesn't work. And there is no g_citydata either. Or any other global CityData object. Each city has its own CityData object, if you are inside such an object you can simply use m_citystyle. If you are outside of a CityData member function you have to get such an CityData object first from that you can retrieve the m_citydata then.

-Martin

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:29
  Old Post 08-04-2005 23:03 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#59 Report this post to a moderator
Browse Apolyton AD-FREE

hmmm...
ok a little confused on how to grab objects (unless its GetCity)

I think your saying that I have to use a GetCity()->m_citystyle to get inside the object and then use the m_array stuff.

I'll check my C++ for dummies. Any good examples in the code where I could identify the differences in object, class, function

This is good stuff you may want to add it to your C++ Lecture....

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

quote:
Originally posted by E
I think your saying that I have to use a GetCity()->m_citystyle to get inside the object and then use the m_array stuff.


If you are in a method belonging to the CityData object you don't need anything with Get or this. So first complete the CityData::CanBuildBuilding method and of course the *.cdb files.


quote:
Originally posted by E
This is good stuff you may want to add it to your C++ Lecture....


Maybe I should continue this lecture.

-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.0877 seconds (95.39% PHP - 4.61% 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