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 21-01-2005 01:10 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#1 Report this post to a moderator
PROJECT: Good Specific Terrain Improvements Support Apolyton buy from Amazon

Martin has been helping me (in the other forum) on how to code Cities that can only settle on specific types of terrain. I might be almost done with that, so my next attempt is along the same lines. Its to add a flag that makes it so that the player can only build terrain improvements on tiles with certain goods. I feel this will give the modder the ability to add some unique improvements and add different bonuses to a game.


I know I have to add a spot in the terrutil.cdb, but terrainutil.cpp will be my coding challenging

code:
bool terrainutil_CanPlayerBuildAt(const TerrainImprovementRecord *rec, sint32 pl, const MapPoint &pos) { sint32 i; I think I need to define a variable here 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) { bool haveAlliance = AgreementMatrix.s_agreements.HasAgreement(pl, cell->GetOwner(), PROPOSAL_TREATY_ALLIANCE); 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; } } I think this is the code I should base it on: for(i = 0; i < rec->GetNumCantBuildOn(); i++) { if(rec->GetCantBuildOnIndex(i) == cell->GetTerrain()) { return FALSE; } } } but something like this: for(r = 0; r < g_theResourceDB->Get(resource); r++) { if(rec->GetBuildGoodOnIndex(r) == cell->GetTerrain()) { return FALSE; //changed, thanks J } } return true; }




this is just my working start, but comment if interested....

Last edited by E on 21-01-2005 at 21:52

J Bytheway is offline J Bytheway
Emperor
England
Jul 2001
time: 05:29
  Old Post 21-01-2005 19:18 Visit J Bytheway's homepage!
Edit/Delete Message Reply w/Quote
#2 Report this post to a moderator
Full PM-box? Change here!

If you do things that way around you must remember to return false if the program gets through the whole for loop without returning true.

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

Thanks J. I need to check on how goods are linked. I don't think I can use the SLIC HasGood function here can I?

The Big Mc is offline The Big Mc
King
Of the universe / England
Oct 2001
time: 05:29
  Old Post 21-01-2005 21:45 Visit The Big Mc's homepage!
Edit/Delete Message Reply w/Quote
#4 Report this post to a moderator
Increase the size of your Attachments

NO but you can rip off the code

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:29
  Old Post 21-01-2005 21:51 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#5 Report this post to a moderator
Full PM-box? Change here!

BigMC you know where the code is? just checking before I run a HasGood search in XP....

PS I've looked throught the mapgenfiles once or twice. My C++ is very weak but it made some sense. I think we might have to look into it (with help) if we are ever going to get the new terrains (and ctp2 to accept them better) added in there...

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

quote:
Originally posted by J Bytheway
If you do things that way around you must remember to return false if the program gets through the whole for loop without returning true.


E, John means the return after the for loop not within the for loop. And by the way the function should return a bool and not a BOOL, these are two different things, even if they can be converted into each other easiliy. Nevertheless that is at least a bad style of programming. At least Activision is to blame in this case.

quote:
Originally posted by E
I know I have to add a spot in the terrutil.cdb, but terrainutil.cpp will be my coding challenging


Actual the file is called terrimprove.cdb, there is no terrutil.cdb.

Another thing I wonder about, is why the function does not contain Fromafar's changes.

Now let's come to the for loop you have added. The counting variable is called r. Why do you use an additional counting variable if the the counting variable i is already there and is not needed to store its value. And I see again Activision did it like that in the code as well. However it wastes a little bit of memory, for bytes to be precise.

What really wrong with your for loop is, is that it tries to go through the whole good database. But now you access the BuildGoodOn array, not a good idea if the good database has less entries then your BuildGoodOn array.

So you have to figure out the size of the BuildGoodOn array.

Another question is how to assure backwards compatibility. What happens if your new flag is not present. Actual I would name it IsRestrictedToGood, your name sounds to me like the good is built on an improvement. This is more clear, as it means that you can only build it on the given good.

However there is still a problem in the logic.

quote:
Originally posted by E
BigMC you know where the code is? just checking before I run a HasGood search in XP....


You would already know it, if you have done it. But of course you can guess where you find it, but of course I don't tell you this.

But still we have to think about the logic, it should return true; if all the original critera are met, and your new flag is not present in the database record, if it is present, it should only return true if the previous critera are met and the good at the location is the right one. However the function does not do this right now.

-Martin

The Big Mc is offline The Big Mc
King
Of the universe / England
Oct 2001
time: 05:29
  Old Post 22-01-2005 06:13 Visit The Big Mc's homepage!
Edit/Delete Message Reply w/Quote
#7 Report this post to a moderator
Support Apolyton, buy Civilization: The Boardgame

the 6 lines of code you are after are in the fill *"$^&*(^%$£" martin also mentioned the locations of these files in the new slicfunc thread oh and so everybody knows about it you
.
Could
Please
post it on the forums .

however martin will not let me tell you were to find it but follow the clues I gave you.

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

No problem BigMc, I'm good at the search but just wondering if you ran across it recently....

I'm looking at these codes to steal...


#1

code:
C3TerrDB.cpp return g_theResourceDB->Get(type_good)->GetGold(); if (g_theTerrainDB->Get(tt)->HasGood(tg))


or this one...

#2
code:
SlicFunc.cpp SFN_ERROR Slic_HasGood::Call(SlicArgList *args) { if(args->m_numArgs != 1) return SFN_ERROR_NUM_ARGS; MapPoint pos; if(!args->GetPos(0, pos)) return SFN_ERROR_TYPE_ARGS; sint32 good; if(!g_theWorld->GetGood(pos, good)) { m_result.m_int = -1; } else { m_result.m_int = good;} return SFN_ERROR_OK; }


and this one...

#3
code:
wldgen.cpp BOOL hasGood = GetGood(pos, good);


#4
code:
cell.cpp sint32 Cell::GetGoodsIndex(sint32 &val) const { val = (m_env & k_MASK_ENV_GOOD); if (val == 0) { return FALSE; } else { val >>= k_SHIFT_ENV_GOOD; val--; while(val >= 0 && (g_theTerrainDB->Get(m_terrain_type)->GetNumResources() <= val)) { val--; } if(val < 0) return FALSE; return TRUE; } }



I'm thinking #1 might be the one I'll have to tweak...

Last edited by E on 22-01-2005 at 08:58

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

code:
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; }} for(i = 0; i < rec->GetNumCantBuildOn(); i++) { if(rec->GetCantBuildOnIndex(i) == cell->GetTerrain()) { return false; }} for(i = 0; i < rec->GetNumIsRestrictedToGood(); i++) { if(rec->GetIsRestrictedToGoodIndex(i) == cell->GetGood()) { return true; }} } return true; }


I found the code with FROMAFAR's changes and its really big! Iposted it all so you can get the flow. The code I added is in bold of course. I ripped off the Cantbuildon as you can see and used the cell.cpp GetGood function. I think it works similar to HasGood (as seen in the previous post)

My logic may have to be double checked though...

The Big Mc is offline The Big Mc
King
Of the universe / England
Oct 2001
time: 05:29
  Old Post 22-01-2005 16:53 Visit The Big Mc's homepage!
Edit/Delete Message Reply w/Quote
#10 Report this post to a moderator
Help yourself to an AD-FREE life

you got the one from slicfunc.cpp then.

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

quote:
Originally posted by The Big Mc
you got the one from slicfunc.cpp then.


Actual it is not the one you can find in slicfunc.cpp. Actual it even doesn't exist. But I would go for the one in HasGood slic function as well.

However this function returns TRUE or FALSE whether there is a good on the given position. To retrieve the good's index you have use the variable that you passed as second argument to the function, in the example called "good". This good variable is passed to the function by reverence instead by value. You see this in the function definition, that includes the ampersand "&" in front of the parameter name.

So you have to call the GetGood function first and then check whether the index stored in the good variable is the same as the current GetIsRestrictedToGoodIndex.

And of course you only have to access the good's db index once, that means that you call the GetGood function before the for loop once.

Now to the logic, the function still returns true whether the tile improvement is restricted to a certain good or not. So you have to put it into a contitioned if block, that is only entered if the size of the RestrictedToGood array is greater than zero. And of course if the for loop is finished without returning true and given it has been entered before, the function should return false, so another return false; belongs into the conditioned if block after the for loop.

And another remark about the layout, actual I only talked about open braces, not about closing braces. The closing braces should have the same indetion like the coresponding if or for or while, so that you don't have to search for them, for the open ones that is clear that they are close to the accoring if, for etc.

-Martin

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

code:
sint32 good; if(!g_theWorld->GetGood(pos, good)) { m_result.m_int = -1; } else { m_result.m_int = good;} for(i = 0; i < rec->GetNumIsRestrictedToGood(); i++) { if(rec->GetIsRestrictedToGoodIndex(i) == good ) { return true; }}


I've added some of your comments but I still have to look at how to incorporate the logic

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

You just need to call the GetGood function, ifs and else ifs, you can use then the good variable.

And think again about the logic and correct the layout and post the whole function again. Well at least the lower else block.

-Martin

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

dp

-Martin

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

code:
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; } } sint32 good; if(cell->GetGood(good)>0 { (g_theWorld->GetGood(good)&& g_theWorld->GetGood(rec->GetIndex(good)) } else { return false; } if (i >0; i < rec->GetNumIsRestrictedToGood(); i++) { if(rec->GetIsRestrictedToGoodIndex(i) != GetGood(good)) { return false; } } for(i = 0; i < rec->GetNumCantBuildOn(); i++) { if(rec->GetCantBuildOnIndex(i) == cell->GetTerrain()) { return false; } } } return true; }



The [b]bold[/b[ stuff is the only thing I changed. My thinking here is:
I defined the variable good, then checked to see if the tile has a good. And then get the index for that good. Then I used the variable 'i' to get the index to see if the improvement is restricted to that type of good. If they are NOT equal then it retuns false and then checks the CantBuildOn...


Is this right? Do goods have an index number, how do I define names (I remember the txt uses Desert_Good_One or something like that)

Last edited by E on 25-01-2005 at 10:25

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

The attempt before was better, now you have restricted every tile improvements to goods and actual you just want to restrict those tile improvements that have at least one. That means that if the number of IsRestrictedToGood is greater then 0, that means IsRestrictedToGood is present in the database record, you want to continue with your code, that checks whether the right good is at the location. So you want to continue with your code, and if your for loop does not return true means that the right good is not present at the given location and therefore you cannot build the tile improvement at the given location, therefore the function must then and only then return false.

-Martin

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

Martin et al,

I guess my logic is whats messing it up...

Should I put the can't build on FIRST as a check and then an 'else' statement to provide for the next check. Or is there something else I should use an 'else-if' or a '&&' ????



But here is another try going back to my original code.

code:
for(i = 0; i < rec->GetNumCantBuildOn(); i++) { if(rec->GetCantBuildOnIndex(i) == cell->GetTerrain()) { return false; } } sint32 good; if(g_theWorld->GetGood(good)) { m_result.m_int = -1; } else { m_result.m_int = good;} elseif(i = 0; i < rec->GetNumIsRestrictedToGood(); i++) { if(rec->GetIsRestrictedToGoodIndex(i) == GetGood(good) ) { return true; } } } return true; }

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:29
  Old Post 01-02-2005 02:08 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#18 Report this post to a moderator
Suffering from ads?

Martin and J,

Is this any closer?

code:
for(i = 0; i < rec->GetNumCantBuildOn(); i++) { if(rec->GetCantBuildOnIndex(i) == cell->GetTerrain()) { return false; } } sint32 good; if(g_theWorld->GetGood(good)) { m_result.m_int = -1; } else { m_result.m_int = good;} elseif(i = 0; i < rec->GetNumIsRestrictedToGood(); i++) { if(rec->GetIsRestrictedToGoodIndex(i) == GetGood(good) ) { return true; } } } return true; }

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:29
Post  Old Post 01-02-2005 02:47 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#19 Report this post to a moderator
Got spare money?

Not today E, I have to prepare a talk for tomorrow. So don't expect a comprehensive answer. First where does the code fragment starts. Second what does "elseif" combined with for loop syntax in the code, "elseif" is a slic token in c++ it is called "else if". Third what does this m_result.m_int slic related c++ code piece there. And fourth get the indention right so that I can see something there.

-Martin

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

Ok here is another shot. I thik my logic flaw was that I tried to check if you could build on a good first as opposed to checking the tile first. So I assumed that what I need ed to do was "improve" the can't build on code by adding another search function after you checked if it is restricted or not. I think my bools line up now and the logic flows...


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

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

code:
} 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; }} for(i = 0; i < rec->GetNumCantBuildOn(); i++) { if(rec->GetCantBuildOnIndex(i) == cell->GetTerrain()) { return false; }} for(i = 0; i < rec->GetNumIsRestrictedToGood(); i++) { if(rec->GetIsRestrictedToGoodIndex(i) == cell->GetGood()) { return true; }} } return true; }


Better start from here again, of course afterwards you got the indention right . Now you have to make sure that your new code is executed if and only if the tile improvement is restricted at least to one good. You should know how to get this number, as you use it in your new code. And to achieve this if and only if condition you surround your new code by braces, one open brace before '{' and one closing brace '{' afterwards. And before the open brace you put an if with the according condition.

And before the for loop you have to retrieve the good's database index that you can find on the terrain, and to do this you use the GetGood function from the world object. And in slic you have an instance how it is used:

code:
SlicFunc.cpp SFN_ERROR Slic_HasGood::Call(SlicArgList *args) { if(args->m_numArgs != 1) return SFN_ERROR_NUM_ARGS; MapPoint pos; if(!args->GetPos(0, pos)) return SFN_ERROR_TYPE_ARGS; sint32 good; if(!g_theWorld->GetGood(pos, good)) { m_result.m_int = -1; } else { m_result.m_int = good; } return SFN_ERROR_OK; }


The GetGood function gets two arguments, a map point and an integer, both arguments are passed by refference not by value. That means the good variable used inside the function is the same instead of a copy, like outside the function, that means the function can assign a value to the good variable that can be used outside, quasi a second return value.

So first thing you have to do here is to retrieve the good's index. Maybe you should also check the return value of the GetGood function and if it is false you should leave the function with a return false.

And finally once you have done the for loop in your new and it didn't return true, the function must return false, but only if it executed your new code.

-Martin

Last edited by Martin Gühmann on 12-02-2005 at 21:10

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:29
  Old Post 12-02-2005 05:21 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#22 Report this post to a moderator
Suffering from ads?

Notes on some code I need to look at...

code:
sint32 Cell::GetGoodsIndex(sint32 &val) const { val = (m_env & k_MASK_ENV_GOOD); if (val == 0) { return FALSE; } else { val >>= k_SHIFT_ENV_GOOD; val--; while(val >= 0 && (g_theTerrainDB->Get(m_terrain_type)->GetNumResources() <= val)) { val--; } if(val < 0) return FALSE; return TRUE; } }


code:
BOOL World::GetGood(const MapPoint &pos, sint32 &good) const { sint32 i; Cell *c = GetCell(pos); if (c->GetGoodsIndex(i)) { good= g_theTerrainDB->Get(c->m_terrain_type)->GetResourcesIndex(i); return TRUE; } else { return FALSE; } }

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:29
Post  Old Post 12-02-2005 21:09 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#23 Report this post to a moderator
Tired of ads?

The first function returns TRUE or FALSE whether the Cell has a good or not. The val argument is filled with a number between -1 and 3, -1 if the location has no good, 0 if the location has the good that is refferenced by the first Ressource entry in the according database record of the terrain. And respectively for the goods referenced by the higher array members.

The second function retrieves the good's database index of the good that is found on the given position. It returns TRUE if there is a good on the given location otherwise FALSE. The argument good is filled with the found good's database index.

The second function is the function you have to use, since you are interested in the good's database index and not in the good's terrain member index.

-Martin

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

from terrainutil.cpp terrainutil_CanPlayerBuildAt

code:
sint32 good; if(cell->GetGood(good)>0 { (g_theWorld->GetGood(good)&& g_theWorld->GetGood(rec->GetIndex(good)) } else { return false; } Cell *c = GetCell(pos); if (c->GetGoodsIndex(good)) { good= g_theTerrainDB->Get(c->m_terrain_type)->GetResourcesIndex(good); return true; } else { return false; } if (i = 0; i < rec->GetNumIsRestrictedToGood(); i++) { if(rec->GetIsRestrictedToGoodIndex(i) == GetGoodsIndex(good)) { return true; } } for(i = 0; i < rec->GetNumCantBuildOn(); i++) { if(rec->GetCantBuildOnIndex(i) != cell->GetTerrain()) { return true; } } } return false; }


In BOLD is my code as usual.

1) I used the GetGood function to identify if the spot the player is trying to build has a good or not. I have to admit here that its kind of fuzzy how the system checks here, I really don't "see" in the code how the system knows which tilethe player is building on, is that an event or something?

2) I created a variable good and if the tilehas a good it returns its index value, if not false. This is another C++ question, I don't have the braces around the other code will the progran stop running at the first false or check all conditions?

3)In the GetGoodIndex part if it returns true for a value good, will it stop runing the program or run to the next function? Should I remove the else {return false} and make it that if it returns true it does the nex function?

4) finally I have it check for the value in GetRestiictedtoGood value and if it equals the same as good value its true. This is similar to my last code so I think thats close (my only dount is on the good variable)

5) Finally, if the IsRestrictedtoGood flag is not there how do I know it will still run the program?

Sorry for the questions this time but I'm trying to get a bit more of an understanding...

Last edited by E on 14-02-2005 at 09:52

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

Well E the code is something else then I told you...

quote:
Originally posted by E
1) I used the GetGood function to identify if the spot the player is trying to build has a good or not. I have to admit here that its kind of fuzzy how the system checks here, I really don't "see" in the code how the system knows which tilethe player is building on, is that an event or something?


That's simple check the parameter list of the function you are modifying, it is the parameter const MapPoint &pos. And you don't need to understand the logic inside the function you just need to know what you can do with these functions. And actual I already told you that you only need the GetGood function from the world and no GetGoodsIndex function, this function is used of the GetGood function, there is no need to mess around with it.

quote:
Originally posted by E
2) I created a variable good and if the tilehas a good it returns its index value, if not false. This is another C++ question, I don't have the braces around the other code will the progran stop running at the first false or check all conditions?


That's stupid the function should return true if the player is allowed to build the given tarrain improvement at the given place and false if he isn't allowed to do so. There is no room for an index there. However it doesn't return there anything because it doesn't has a return statement and the final colon is missing. And this first if-else pair causes the function to return false if there is no good at the place always.

quote:
Originally posted by E
3)In the GetGoodIndex part if it returns true for a value good, will it stop runing the program or run to the next function? Should I remove the else {return false} and make it that if it returns true it does the nex function?


You should remove this GetGoodsIndex function alltogether, you don't need it at all as I said above.

quote:
Originally posted by E
4) finally I have it check for the value in GetRestiictedtoGood value and if it equals the same as good value its true. This is similar to my last code so I think thats close (my only dount is on the good variable)


I still have no idea what you want with this if-for-loop hybrid synthax. That doesn't do anything it even doesn't compile. However once you changed this if-for-hybrid stuff into a real for loop you have to compare each RestrictedToGood index to the good index you have retrieved before and stored in the good variable, don't use this GetGoodsIndex function, it doesn't even compile since it is a member of Cell.

quote:
Originally posted by E
5) Finally, if the IsRestrictedtoGood flag is not there how do I know it will still run the program?


That is a pretty good question and if I remember correctly the answer is in this thread, but here again: You have this GetNumIsRestrictedToGood function. This function returns the number of goods to that your improvement is restricted. For a tile improvement without any restrictions it returns 0. So all you have to do is to use an

if(){
}

statement. If this function I refered above returns a number bigger than 0 then your new code is executed. otherwise it isn't executed. And of course leave the original code as it is, don't mess with this around and of course you new code is insereted after the original code.

-Martin

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

from terrainutil.cpp terrainutil_CanPlayerBuildAt

code:
sint32 good; if(cell->GetGood(good)>0 { (g_theWorld->GetGood(good)&& g_theWorld->GetGood(rec->GetIndex(good)) } else { return false; } if (i = 0; i < rec->GetNumIsRestrictedToGood(); i++) { if(rec->GetIsRestrictedToGoodIndex(i) == GetGood(good)) { return true; } } for(i = 0; i < rec->GetNumCantBuildOn(); i++) { if(rec->GetCantBuildOnIndex(i) != cell->GetTerrain()) { return true; } } } return false; }


I have to re-look this but I'll make quick changes for now.

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

code:
} 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; } } sint32 good; if (g_theWorld->GetGood(good)) { good= g_theTerrainDB->Get(c->m_terrain_type)->GetResourcesIndex(good); return true; } else { return false; } for(i = 0; i < rec->GetNumIsRestrictedToGood(); i++) { if(rec->GetIsRestrictedToGood(i) == GetGood(good)) { return true; } } for(i = 0; i < rec->GetNumCantBuildOn(); i++) { if(rec->GetCantBuildOnIndex(i) != cell->GetTerrain()) { return true; } } } return false; }


Martin, in Bold is mine. I've gotten rid of the Goods index, but if GetGood is more detailed than I think, then I'm guessing I have to remove the bold-italics as well and ONLY call the GetGood. I think this is what you said but I'm just checking first.

I also added the "for" loop, but I'm a little stumped on the good versus no good code. I think I may still have the problem of no-good means you cant build at all. Should I add an "else" in here or is there something else I need to add?

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

quote:
Originally posted by E
Martin, in Bold is mine.


That's not quite true, as it stands now this below is more or less your code.

code:
sint32 good; if (g_theWorld->GetGood(good)) { good= g_theTerrainDB->Get(c->m_terrain_type)->GetResourcesIndex(good); return true; } else { return false; } for(i = 0; i < rec->GetNumIsRestrictedToGood(); i++) { if(rec->GetIsRestrictedToGood(i) == GetGood(good)) { return true; } } for(i = 0; i < rec->GetNumCantBuildOn(); i++) { if(rec->GetCantBuildOnIndex(i) != cell->GetTerrain()) { return true; } } } return false; }


quote:
Originally posted by E
I've gotten rid of the Goods index, but if GetGood is more detailed than I think, then I'm guessing I have to remove the bold-italics as well and ONLY call the GetGood. I think this is what you said but I'm just checking first.


You are right the is something in that doesn't belong into it.

code:
sint32 good; if (g_theWorld->GetGood(good)) [b][i]{ good= g_theTerrainDB->Get(c->m_terrain_type)->GetResourcesIndex(good); return true; } else { return false; }


First the GetGood function fills the good variable with a number the good's database index, therefore there is no need to reasign anything to it again. So get rid of the content inside of the if-block and replace it with your for-loop:

code:
for(i = 0; i < rec->GetNumIsRestrictedToGood(); i++) { if(rec->GetIsRestrictedToGood(i) == GetGood(good)) { return true; } }


And after this for loop still inside the if-block you add an return false; because if this piece of code is reached the for-loop was executed and no match was found that means you aren't allowed to construct the tileimprovement.

Second the GetGood function takes two arguments, one is the position and the second one is the good.

And now to the last part of your code, I didn't tell you that you should modify the return values. So restore the original return vales. Inside that for loop it was return false; The final return was a return true; And please change back the equality operator from != now to == as it was.

For now just complete the task and then we do the final part.

-Martin

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:29
  Old Post 23-02-2005 00:33 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#29 Report this post to a moderator
Full PM-box? Change here!

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



just a quick correction and I'll come back to the rest of your message for the last changes

Last edited by E on 28-02-2005 at 07:11

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

quote:
Originally posted by E
just a quick correction and I'll come back to the rest of your message for the last changes


Yes the rest must be still incooperated. However here is still a small one: Within your for-loop you try to compare the IsRestrictedToGood members with the actual good on your tile. At first the good variable's value contains already the good index at the given terrain, therefore there is no need to call a GetGood function again. Just compare it with good.

-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.0765 seconds (93.03% PHP - 6.97% 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