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-Creation/AI/Mods/Scenarios > Limiting City placement/terrain specific cities
Show a Printable Version | Email This Page to Someone! | Receive updates to this thread | Report this to Apolyton news!

bottom of page
  
Author
Thread   
Pages (2): [ 1   2   ]
< 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:34
  Old Post 25-01-2005 09:55 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#31 Report this post to a moderator
Increase Your PM Length

quote:
Originally posted by Martin Gühmann

That's a good question, and in fact the is a difference. Everything within the braces following the if are under the condition of the if. If the following is not included within braces, only the statement directly following is conditioned by the if.


Of course for readibility you would only indent the code dependent on the if.


From the looks of things, I think that means I SHOULD add braces, right? It looks like you said that without braces it will only execute the first else if and not the other ones...did I get that right?


quote:

And the first brace was in the original code on the line start. And should also be there if you give it a new line like in the rest of the file.


Does this mean the first brace after the BOOL has to be in #if statement or keep it before it and just create a space?


Also I notice Unitdata.cpp has A LOT of white space between functions. Is that just wordpad or should I clean it up a bit (for practice?)


thanks, I can almost see the finish line

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

quote:
Originally posted by E
From the looks of things, I think that means I SHOULD add braces, right? It looks like you said that without braces it will only execute the first else if and not the other ones...did I get that right?


No, that's wrong, basicly it means you can leave it as it is. Whether an "else if" doesn't depent on the braces it depends on the fact whether the "if" statement or "else if" statement was true and therefore the following code within the braces or the very next statement were executed. An if can only controll one statement and if it should control more then one stetement you have to put all the following statements into a block, so that it can controll the block as a whole.

quote:
Originally posted by E
Does this mean the first brace after the BOOL has to be in #if statement or keep it before it and just create a space?


No, it doesn't mean this. If you put this under the #if then you have also to put the last closing brace associated to the function into the block and of course you have to do it for the original code and for your code as well. And actual I just requested that you put the final return uder the preprocessor, because in the original code it is not a return FALSE; but a return TRUE;

quote:
Originally posted by E
Also I notice Unitdata.cpp has A LOT of white space between functions. Is that just wordpad or should I clean it up a bit (for practice?)


Yes all the files by Activision have such a huge amount of white space in it, I guess this is caused by the comment removement. However this is Activision original code and every space, tab and new line belongs to it. If you change this we have a hard time to detect the differences, if we do a automatic search for instance with UltraEdit or other but free tools, because they only mark the line differences, well there are also better tools. But nevertheless white space modification is also a code modification.

Talking about white space modification, the very first brace of the function, the very first brace of the function that you put outside of ACTIVISION_ORIGINAL is seperated in the original code by two new lines from the function parameter list and is at the beginning of the line.

quote:
Originally posted by E
thanks, I can almost see the finish line


Yes, but we want a perfect victory. And in my opinion, readibility of code is also very imprortant, even if it might also be a matter of taste, how to this and that in particular but there are also some conventions.

-Martin

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

Great! then I think I made all the necessary changes and will post them later. and readability is important, and if I'm learning I want to atleast learn the right way

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

However you aren't at the end, yet.

To assure that we are talking about the same code I post it here:

code:
//---------------------------------------------------------------------------- // // Name : CanSettleOn by E // // Description: Adds additional check for a flag to see what terrain // types the unit can settle on // //---------------------------------------------------------------------------- BOOL UDUnitTypeCanSettle(sint32 unit_type, const MapPoint &pos) { #if defined(ACTIVISION_ORIGINAL) sint32 searching = TRUE; const UnitRecord *rec = g_theUnitDB->Get(unit_type); sint32 t = rec->GetSettleCityTypeIndex(); if (t < 0) { return FALSE; } if (g_theUnitDB->Get(t)->GetHasPopAndCanBuild() == FALSE) { return FALSE; } if (g_theWorld->HasCity(pos)) return FALSE; if (rec->GetSettleLand() && g_theWorld->IsLand(pos)) searching = FALSE; else if (rec->GetSettleMountain() && g_theWorld->IsMountain(pos)) searching = FALSE; else if (rec->GetSettleWater() && g_theWorld->IsWater(pos)) searching = FALSE; else if (rec->GetSettleSpace() && g_theWorld->IsSpace(pos)) searching = FALSE; if (searching) return TRUE; #else sint32 i; const UnitRecord *rec = g_theUnitDB->Get(unit_type); sint32 t = rec->GetSettleCityTypeIndex(); if (t < 0) { return FALSE; } else if (g_theUnitDB->Get(t)->GetHasPopAndCanBuild() == TRUE) { return FALSE; } for(i = 0; i < rec->GetNumCanSettleOn(); i++) { if(rec->GetCanSettleOnIndex(i) == cell->GetTerrain()) { return TRUE; } } if (g_theWorld->HasCity(pos)) return FALSE; else if (rec->GetSettleLand() && g_theWorld->IsLand(pos)) return TRUE; else if (rec->GetSettleMountain() && g_theWorld->IsMountain(pos)) return TRUE; else if (rec->GetSettleWater() && g_theWorld->IsWater(pos)) return TRUE; else if (rec->GetSettleSpace() && g_theWorld->IsSpace(pos)) return TRUE; return FALSE; #endif }


And for comparision the original code so that this is also clear.

code:
BOOL UDUnitTypeCanSettle(sint32 unit_type, const MapPoint &pos) { sint32 searching = TRUE; const UnitRecord *rec = g_theUnitDB->Get(unit_type); sint32 t = rec->GetSettleCityTypeIndex(); if (t < 0) { return FALSE; } if (g_theUnitDB->Get(t)->GetHasPopAndCanBuild() == FALSE) { return FALSE; } if (g_theWorld->HasCity(pos)) return FALSE; if (rec->GetSettleLand() && g_theWorld->IsLand(pos)) searching = FALSE; else if (rec->GetSettleMountain() && g_theWorld->IsMountain(pos)) searching = FALSE; else if (rec->GetSettleWater() && g_theWorld->IsWater(pos)) searching = FALSE; else if (rec->GetSettleSpace() && g_theWorld->IsSpace(pos)) searching = FALSE; if (searching) return FALSE; return TRUE; }


Now in your version, if I compile it with ACTIVISION_ORIGINAL defined, the function returns TRUE if the terrain requirements aren't met instead of returning FALSE, now the function return behaviour is undefined if the requirements are met. Again if ACTIVISION_ORIGINAL is defined then the precomiler strips all the fragments that aren't under the defined(ACTIVISION_ORIGINAL) condition, to illustrate what the preprocessor with your code does if ACTIVISION_ORIGINAL is defined the resulting code:

code:
BOOL UDUnitTypeCanSettle(sint32 unit_type, const MapPoint &pos) { sint32 searching = TRUE; const UnitRecord *rec = g_theUnitDB->Get(unit_type); sint32 t = rec->GetSettleCityTypeIndex(); if (t < 0) { return FALSE; } if (g_theUnitDB->Get(t)->GetHasPopAndCanBuild() == FALSE) { return FALSE; } if (g_theWorld->HasCity(pos)) return FALSE; if (rec->GetSettleLand() && g_theWorld->IsLand(pos)) searching = FALSE; else if (rec->GetSettleMountain() && g_theWorld->IsMountain(pos)) searching = FALSE; else if (rec->GetSettleWater() && g_theWorld->IsWater(pos)) searching = FALSE; else if (rec->GetSettleSpace() && g_theWorld->IsSpace(pos)) searching = FALSE; if (searching) return TRUE; }


And that is not the same code as above, you changed the return under the searching condition so that it returns TRUE, even if it was in the original code return FALSE. And you forget the final return.

And of course to demostrate what the preprocessor does with the code if ACTIVISION_ORIGINAL is not defined, the code:

code:
BOOL UDUnitTypeCanSettle(sint32 unit_type, const MapPoint &pos) { sint32 i; const UnitRecord *rec = g_theUnitDB->Get(unit_type); sint32 t = rec->GetSettleCityTypeIndex(); if (t < 0) { return FALSE; } else if (g_theUnitDB->Get(t)->GetHasPopAndCanBuild() == TRUE) { return FALSE; } for(i = 0; i < rec->GetNumCanSettleOn(); i++) { if(rec->GetCanSettleOnIndex(i) == cell->GetTerrain()) { return TRUE; } } if (g_theWorld->HasCity(pos)) return FALSE; else if (rec->GetSettleLand() && g_theWorld->IsLand(pos)) return TRUE; else if (rec->GetSettleMountain() && g_theWorld->IsMountain(pos)) return TRUE; else if (rec->GetSettleWater() && g_theWorld->IsWater(pos)) return TRUE; else if (rec->GetSettleSpace() && g_theWorld->IsSpace(pos)) return TRUE; return FALSE; }


And this piece of code is finally compiled if ACTIVISION_ORIGINAL is not defined, the other piece of code is ignored. First thing is that the first "else if" and its code block in this fragment is still indented by one two much. And actual I wonder why you changed it into an "else if", however in this case it doesn't matter, because the function is left anyway if code associated to one of these ifs or else ifs is executed. Within the block of the for loop you have a new line too much, better use a new line two seperate the code of the for loop from the following if-else ifs.

And another thing I have overlooked is that you check whether the position has a city, IIRC this should be just accessing a bool and not a whole for loop with some iterations and multiple evaluations of a condition. Therefore the best is to check for a city first before the for loop.

For readability you should seperate the final return from the rest of the code as well, so that we all can see it more easilly.

And again the first open brace of the function, the one at the very top, wasn't indented in the original code, no extra spaces, and actual I didn't request reinsert the additional new line.

And finally a request for the function description, please fill in all the rest of the fields like in the other functions: Name, Description, Parameter, Globals, Returns and Remark(s), of course if you need help to do this ask. And please even if Fromafar does this, don't seperate this desription by new lines from the function. Microsoft Visual C++ displays this information, when you hoover the mouse cursor over the function in other pieces of the code.

-Martin

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:34
  Old Post 27-01-2005 06:33 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#35 Report this post to a moderator
Increase Your PM Length

I'm embarrassed by putting true instead of false..(stupid brain)...

Ok, I think I incorporated all changes and I think I understood your request about not doing like Fromafar, I'm assuming that means sticking it in-between lines of code and that you prefer that they appear before the code...right?

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

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:34
Post  Old Post 28-01-2005 04:56 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#36 Report this post to a moderator
Increase the size of your Attachments

Well we are getting closer, but still we aren't at the end.

Let's start with some nit-picking about the layout, and you thought I would need a lot of patience with you, but for me its seems rather the way around.

1. In the original code the first line within the function buddy was indented by two spaces and one tab, well for me it would also be enough if it would be just one tab, at least so that all tree lines look at least so that they have the same indention:

code:
sint32 searching = TRUE; const UnitRecord *rec = g_theUnitDB->Get(unit_type); sint32 t = rec->GetSettleCityTypeIndex();


The above is the code in your file, correct the indention of the first line.

2. Another point is the layout of the second if statement in your code:

code:
if (t < 0) { return FALSE; } if (g_theUnitDB->Get(t)->GetHasPopAndCanBuild() == TRUE) { return FALSE; } if (g_theWorld->HasCity(pos)) return FALSE;


The second if is not ok, it has now the same indention like the surounding ifs, but not the following two lines, both lines have a tab too much. (Be happy that I don't nit-picking for the white space I don't see, the one at the end of the lines. )

3. Now let's come to the stuff that breaks your code:

code:
for(i = 0; i < rec->GetNumCanSettleOn(); i++) { if(rec->GetCanSettleOnIndex(i) == cell->GetTerrain()) { return TRUE; } } else if (rec->GetSettleLand() && g_theWorld->IsLand(pos)) return TRUE; else if (rec->GetSettleMountain() && g_theWorld->IsMountain(pos)) return TRUE; else if (rec->GetSettleWater() && g_theWorld->IsWater(pos)) return TRUE; else if (rec->GetSettleSpace() && g_theWorld->IsSpace(pos)) return TRUE;


After the for loop you continue with an else if, but there is no corresponding if, well you may think that this if is before the for loop where you moved, but then you forgot to turn the first else if into an if. Remember if you start with an if, the next conditioned expression may be an if again or an else if, but you can never start such a sequense with an else if. Even in normal language you cannot use else without refering to something else. Here in C++ and in slic as well its another condition.

4. And now again to the original code:

code:
if (rec->GetSettleLand() && g_theWorld->IsLand(pos)) searching = FALSE; else if (rec->GetSettleMountain() && g_theWorld->IsMountain(pos)) searching = FALSE; else if (rec->GetSettleWater() && g_theWorld->IsWater(pos)) searching = FALSE; else if (rec->GetSettleSpace() && g_theWorld->IsSpace(pos)) searching = FALSE; if (searching) return FALSE; #else


You changed back the last but one return, but still you forgot the final return TRUE;

For comparision the original code:

code:
if (rec->GetSettleLand() && g_theWorld->IsLand(pos)) searching = FALSE; else if (rec->GetSettleMountain() && g_theWorld->IsMountain(pos)) searching = FALSE; else if (rec->GetSettleWater() && g_theWorld->IsWater(pos)) searching = FALSE; else if (rec->GetSettleSpace() && g_theWorld->IsSpace(pos)) searching = FALSE; if (searching) return FALSE; return TRUE; }


And note it has the final return true.

And now to the function description:

code:
//---------------------------------------------------------------------------- // // Name : CanSettleOn by E // // Description: Adds additional check for a flag to see what terrain // types the unit can settle on // // Parameters : Settler : the units that can settle // // Globals : g_theWorld : terrain properties database // // Returns : sint32 : terrain index value // // Remark(s) : Modders will define this in Unit.txt as CanSettleOn: X // // //---------------------------------------------------------------------------- BOOL UDUnitTypeCanSettle(sint32 unit_type, const MapPoint &pos)


Actual I meant to remove the two lines between the comment block and the function head, so that VC displays the description whenever I hover the mouse cursor over the function in other pieces of the code.

What's the name of the function? Definatly it isn't CanSettleOn that some kind of property the function now checks for.

Into the description belongs the answer of the question: What does this function? Well it's nice that the function now checks for an additional flag, but that is not what it does, but rather how it does. This belongs rather into the remarks that it has been modified. And what has been done.

Parameters of the function: None of the parameters is called Settlers, we have one called unit_type and one called pos. And now tell me what use they have, before you post the next files , because I think you should think about it first.

Globals: Take a close look on the function and count the globals in it. You should find two globals in it. g_theWorld isn't a terrain properties database, it rather describes the world you are playing, the map, number of continents etc.

Returns: The return type is a BOOL, and therefore something else than a terrain index value. So let's see whether you have understood what the function does. So write it down.

Remarks: Here you can tell everything you like to tell, what you have done, what is the use of your new flag, how to use it, etc.

OK, that should be all for now.

-Martin

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:34
  Old Post 29-01-2005 08:38 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#37 Report this post to a moderator
Enter the AD-FREE zone

Okay, I'll try this...

code:
//---------------------------------------------------------------------------- // // Name : UDUnitTypeCanSettle // // Description: checks unit properties to see if it can settle a city on a tile // // // Parameters : GetNumCanSettleOn() : checks for terrain type that // unit can settle // // Globals : g_theUnitDB : Unit properties database // // Returns : BOOL : returns TRUE if terrain is the same as // CanSettleOn // // Remark(s) : Modders will define this in Unit.txt as CanSettleOn: X // //---------------------------------------------------------------------------- BOOL UDUnitTypeCanSettle(sint32 unit_type, const MapPoint &pos)

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

OK let's start: Name is fine, also Description, even if I would formulate it differently. Parameters is wrong GetNumCanSettleOn() is something that the function uses, but nothing that is passed to the function. If you want to use a function somewhere in the code then you have to know, what are the inputs and what are the outputs (return values, filled variables passed by refference). And what these outputs represent. From outside I am just interested in what the function does and not how the function does it. If you want to talk about the new CanSettleOn flag use the remarks for it.

Now to answer the question what the parameters are, take a look on the line of code after the comment block, the parameters of the function can be found within the parentheses. The names of these parameters should be self-explanatory.

For Globals: You added the g_theUnitDB to the description, but in return you removed the other global, actual I just told you to correct its description, but not to remove it entirely.

For Returns: A BOOL is correct but the description is to restricted, it doesn't only return TRUE if your flag is set and the terrain is right. It's wider, the function name should, should sum it up.

Remarks: As you want to tell the people so much about you have done, you should extend it a little bit.

And one remark in general, I know there are people who continue with small letters after a collon, but I prefere it to continue with a capital. Of course there are exception for instance g_theUnitDB is a case sensitive name and therefore can't be changed. However you have to do a decision, either you use capitals after a colon or not. As you use a mixed style.

And if you have to insert linebreaks put the start of the next line under the start of the line before, like you did in your earlier description attemp. And another note is to use for these comment blocks spaces instead of tabs. Tabs don't have on every editor the same length, some uses eight spaces and others uses four spaces. I hope you switched to EditPlus 2 in the meantime.

And nice that you removed the two new lines.

-Martin

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

Here's to hope

code:
//---------------------------------------------------------------------------- // // Name : UDUnitTypeCanSettle // // Description: Checks unit properties to see if it can settle a city on a tile // // Parameters : sint32 unit_type : Variable for the type of unit // const MapPoint &pos : Variable for tile on map // // Globals : g_theWorld : Terrain properties database // g_theUnitDB : Unit properties DB // // Returns : BOOL : Returns TRUE if an unit-type can Settle on a tile // FALSE if the unit cannot settle a city there // // Remark(s) : Enables a new unit attribute CanSettleOn. // Modders will define this in Unit.txt as CanSettleOn: X. // THe flag adds an additional option in order to restrict where cities can be built. // // //----------------------------------------------------------------------------

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:34
Post  Old Post 05-02-2005 20:36 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#40 Report this post to a moderator
Support Apolyton or Terrorists Win

Hi think we have it now approximatly.

One point to the lay out: Better use spaces instead of tabs in such a comment block, here we have a ceratin layout that is messed up if you change the indent a tab represents. For instance you can select in EditPlus2 whether it should display the tabs four spaces or eight spaces long. Eight spaces is the default setting for new created syntaces, and four is the setting for C++ code.

Parameters look all right now, even if I would describe it differently, but it seems you have understood that.

For globals: g_theWorld is actual much more than a terrain property database, actual it contains data about the map, each tile, the world rules, etc. So better call it: The game world properties. I think I should avoid the word database in this case. But it is right that it is not easy to describe it. And therefore we see some too limited descriptions for it in the code.

The Returns description seems also OK, in particular I liked the layout in your post, so that the FALSE starts in the same column directly under the TRUE.

And for the Remark(s): The second and the third line are OK, but I would be more specific in the first line, namly that it instead enables a new unit attribute, a new unit atrribute was added, and in particular by you. So that we have the piece of information about the author of the addition there.

-Martin

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:34
  Old Post 11-02-2005 10:25 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#41 Report this post to a moderator
Tired of ads?

Thanks Martin for all your help. HopefullY I'm not so difficult next time

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:34
Post  Old Post 11-02-2005 19:34 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#42 Report this post to a moderator
Suffering from ads?

You aren't quite finished. However the code in UnitData.cpp is now fine, except that I would add at least a tab in the Orignal version of the code in the line: "sint32 searching = TRUE;" And maybe you should replace all the remaining tabs in the function description by spaces. Depending on the tab length it may look different in each editor. And maybe you should take a look again on the description at the start of the file you added.

Well actual the real problem with the files you have posted is that I cannot find CanSettleOn in unit.cdb that means your code doesn't compile at all.

-Martin

Attachment: des.jpg
This has been downloaded 72 time(s).

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

thanks Martin,
my error in th cdb is that I had it as Cant instead of Can

ANd I did change everything to spaces now

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

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

I didn't check whether it compiles as I don't have the time to do it, but it seems to be finished. However I would give the BOOL an indent of two spaces, like the globals have:

code:
// Globals : g_theWorld : The game world properties // g_theUnitDB : Unit properties // // Returns :BOOL : Returns TRUE if an unit-type can Settle on a tile


However this is up to you whether you change it. So go to your next project.

-Martin

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

Thanks Martin, I will make the change in the altered files...

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

OK, here is the final version:

code:
BOOL UDUnitTypeCanSettle(sint32 unit_type, const MapPoint &pos) { #if defined(ACTIVISION_ORIGINAL) sint32 searching = TRUE; const UnitRecord *rec = g_theUnitDB->Get(unit_type); sint32 t = rec->GetSettleCityTypeIndex(); if (t < 0) { return FALSE; } if (g_theUnitDB->Get(t)->GetHasPopAndCanBuild() == FALSE) { return FALSE; } if (g_theWorld->HasCity(pos)) return FALSE; if (rec->GetSettleLand() && g_theWorld->IsLand(pos)) searching = FALSE; else if (rec->GetSettleMountain() && g_theWorld->IsMountain(pos)) searching = FALSE; else if (rec->GetSettleWater() && g_theWorld->IsWater(pos)) searching = FALSE; else if (rec->GetSettleSpace() && g_theWorld->IsSpace(pos)) searching = FALSE; if (searching) return FALSE; return TRUE; #else sint32 i; const UnitRecord *rec = g_theUnitDB->Get(unit_type); sint32 t = rec->GetSettleCityTypeIndex(); if (t < 0) { return FALSE; } if (g_theUnitDB->Get(t)->GetHasPopAndCanBuild() == FALSE) { return FALSE; } if (g_theWorld->HasCity(pos)) return FALSE; for(i = 0; i < rec->GetNumCanSettleOn(); i++) { if(rec->GetCanSettleOnIndex(i) == g_theWorld->GetCell(pos)->GetTerrain()) { return TRUE; } } if (rec->GetSettleLand() && g_theWorld->IsLand(pos)) return TRUE; else if (rec->GetSettleMountain() && g_theWorld->IsMountain(pos)) return TRUE; else if (rec->GetSettleWater() && g_theWorld->IsWater(pos)) return TRUE; else if (rec->GetSettleSpace() && g_theWorld->IsSpace(pos)) return TRUE; return FALSE; #endif }


In bolt the changes. The first change is a change that replaces a TRUE by a FALSE, and restores the original code at that place.

The consequence of this non-original code was that all the units with the flag HasPopAndCanBuild can't settle a city even if they meet all the other criteria. unfortunatly all and only all settle units have this flag. The consequence is that no settler was able to settle.

The other change is a chnge to make the code compile, in this function there is no pointer on a Cell object defined with the name cell. To get such a pointer you can use g_theWorld->GetCell(pos) if pos is a valid MapPint object.

Since I was modifying this file anyway I corrected the comments a little bit.

In unit.cdb I replaced

Int UnitUpkeep by
Bit(Int) GoldHunger

The name GoldHunger makes it coherent with the other hunger flags, ShieldHunger and FoodHunger, and the Bit makes it optional so that you don't have to add it, to unit.txt so that CTP2 doesn't complain about it if it is missing.

-Martin

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

Thanks Martin! And GoldHunger is something I need to get back on and just a initial look its going to affect a lot of files and I think there should be a modification to the display so that you can know your unit cost...

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

concerning the Bug that the game uses urban planners as the starting unit and not settlers, I think it has something to do with CanSettle and the game looks to see if a unit has a Settle: (terrain) flag and identifies that as a settler and my CansettleOn flag is excluded. as a possibility should we make a reference here:

code:
armydata.cpp BOOL ArmyData::CanSettle(const MapPoint &pos) const { sint32 i; for (i=0; iIsValid(m_array[i])); if( g_theUnitPool->IsValid(m_array[i]) && g_theUnitDB->Get(m_array[i].GetType())->GetSettle() && m_array[i].CanPerformSpecialAction()) return TRUE; } return FALSE; }


or here:
code:
unit.cpp BOOL Unit::CanSettle(const MapPoint &pos) const { return GetData()->CanSettle(pos); }


or do you think it could be elsewhere or defined differently?

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

I think you have to do something with the first code fragment and for the second one you need to have a deeper look at the CanSettle function there, if it is one of UnitData. But actual there is a third place that might be valuable to investigate.

-Martin

J Bytheway is offline J Bytheway
Emperor
England
Jul 2001
time: 05:34
  Old Post 07-03-2005 21:28 Visit J Bytheway's homepage!
Edit/Delete Message Reply w/Quote
#50 Report this post to a moderator
Inflate your Upload Space

I think it might be worthwhile to allow the unit(s) given at game start to be specified elsewhere (Probably in DiffDB.txt), so that modders can avoid worrying about this sort of problem, and only fall back on the existing system if that specification is absent.

This would also allow "deathmatch" style scenarios to be more easily designed where the players used only military units and not settlers. I'm sure there are other applications too.

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

J, good point, I'll check out DiffDB when I can.

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

So E, is your compiler up and running so that we can fix this?

-Martin

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:34
  Old Post 07-06-2005 11:17 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#53 Report this post to a moderator
Support Apolyton or Terrorists Win

Unfortunately No. I haven't devted enough time yet. I did look at my program and a little confused on how to compile since I haven't done it before (well along time ago with Turbo Pascal doesn't count).

I was looking for a main.cpp to use to compile, most stuff in my book are only 3 or 4 file programs. Any hints on what I need to do? Do I have load all files into the project (it does one at a time I think) or is there a main file somewhere that rund what to include and know what directories to go to?

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

quote:
Originally posted by E
I was looking for a main.cpp to use to compile, most stuff in my book are only 3 or 4 file programs. Any hints on what I need to do? Do I have load all files into the project (it does one at a time I think) or is there a main file somewhere that rund what to include and know what directories to go to?


No need for a main.cpp. If you have have installed some "demo" version of MS VC++ (and not VBasic as you told me) then you just need to double click on the file civctp.dsw and the Visual Studio opens this project file. And then you can use the IDE to edit the files and of course to compile and link the files.

Of course to compile and link the files you need DirectX installed.

-Martin

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

Martin,
The program I'm using is Dev C++ 4.9.8.0 It did open up the civctp.dsw so hopefully this weekend I'll get time to mess around with compiling.

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

quote:
Originally posted by E
Martin,
The program I'm using is Dev C++ 4.9.8.0 It did open up the civctp.dsw so hopefully this weekend I'll get time to mess around with compiling.


That will be a hard piece of work. So far we were only be able to compile the source code on VC++ 6 and 7. As the compiler used by DevC++ is a gcc windows port we can expect some problems as the Linux guys have as well.

Well you should open then a thread about compiling with DevC++ in the source code forum.

-Martin

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

hmmm I'll try to scrounge a copy ov VC++ then...

but I wil give DevC++ a shotthis weekend.

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

Well actual our goal is to make the game to compile on as many compilers as possible, so we need this as well. But one problem I see are the differences between intel and AT&T assembler code. Probably not a problem that can't be solved, but actual I prefere a system independent solution for these assempler pieces.

-Martin

 
Pages (2): [ 1   2   ]
< Last Thread     Next Thread > Post New Thread     Post A Reply
All times are GMT. The time now is 05:34.
Apolyton Time is 00:34.
    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.0748 seconds (93.99% PHP - 6.01% MySQL) with 30 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