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 > Miscellaneous > Archive > CtP2-Creation/AI/Mods/Scenarios-Archive > Does anybody know how the GetNearestWater function work?
Show a Printable Version | Email This Page to Someone! | Receive updates to this thread | Report this to Apolyton news!

bottom of page
  
Author
Thread    < Last Thread     Next Thread > Post New Thread     Post A Reply
Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:31
Post  Old Post 14-10-2003 03:14 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#1 Report this post to a moderator
Does anybody know how the GetNearestWater function work? Support Apolyton buy from Amazon

Acording to the slic documentation it takes two arguments. I was able to verify this. Also according to the slic documentation both arguments are location variables. Unfortunatly if I give it two locations I get a bounce message windows box in SlicDebug mode: Wrong Type of Argument.

OK while I was writing I had to test something and I figured out something more, so my question is at least anwered partly:

If I use something like this I get the windows bounce messege:

location_t MGLoc;
GetNearestWater(army[0].location, MGLoc);

But if I use this, I don't get a bounce message:

location_t MGLoc;
GetNearestWater(army[0].location, MGLoc.location);

The only problem is the function know returns the distance to that tile but it doesn't fill the location variable.

-Martin

Peter Triggs is offline Peter Triggs
Prince
Gone Fishin, Canada
Jan 2000
time: 05:31
  Old Post 14-10-2003 04:53
Edit/Delete Message Reply w/Quote
#2 Report this post to a moderator
Lose 30 kilos (of popups)

You got further than me. My notes just say "Must be broken, keeps giving 'wrong type of argument' errors."

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:31
Post  Old Post 14-10-2003 20:44 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#3 Report this post to a moderator
Browse Apolyton AD-FREE

Well at least I can use it for determining the direction of the water tile. And it can be used to know whether the location is a water tile or not:

if(GetNearestWater(army[0].location, MGLoc.location) > 0){
// --> army[0].location is land
}
if(GetNearestWater(army[0].location, MGLoc.location) == 0){
// --> army[0].location is sea
}

-Martin

J Bytheway is offline J Bytheway
Emperor
England
Jul 2001
time: 05:31
  Old Post 15-10-2003 18:47 Visit J Bytheway's homepage!
Edit/Delete Message Reply w/Quote
#4 Report this post to a moderator
Support Apolyton, buy Alpha Centauri

How do you determine the direction of the water tile? You said it returned the distance - did you mean that? If you can obtain the direction you can iterate to find the nearest water tile (or at least something close to it).

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:31
Post  Old Post 15-10-2003 19:16 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#5 Report this post to a moderator
Support Apolyton or Terrorists Win

quote:
Originally posted by J Bytheway
How do you determine the direction of the water tile? You said it returned the distance - did you mean that? If you can obtain the direction you can iterate to find the nearest water tile (or at least something close to it).


It does return the Distance as advertised. If you look on the distance of the neigbour tiles, you can find the direction, becaus ethe neighbor that lies in the same direction is close to the water tile. Well I already had before a function that can find the direction of one tile respective of another tile. So the function looks like this:

code:
//////////////////////////////////////////////////////// //MG_GetWaterDirection // // // //Parameter: location_t startLoc // // // //Return Value: // //The direction in that the nearest water tile of // //startLoc lies. Or if startLoc is a water tile it // //returns 8. // // // //Remarks: // //none // //////////////////////////////////////////////////////// int_f MG_GetWaterDirection(location_t startLoc){ location_t MGLoc; location_t MGStartLoc; location_t MGDummyLoc; MGStartLoc = startLoc; int_t MGDistance; int_t MGNewDistance; int_t MGDirection; int_t j; //GetNearestWater should fill MGDummyLoc with location of the nearest water tile //but in fact it is not filled, the function returns only the distance of that tile. MGDistance = GetNearestWater(MGStartLoc.location, MGDummyLoc.location); if(MGDistance == 0){ return 8; } for(j = 0; j < 8; j = j + 1){ GetNeighbor(MGStartLoc, j, MGLoc); MGNewDistance = GetNearestWater(MGLoc.location, MGDummyLoc.location); if(MGNewDistance < MGDistance){ MGDistance = MGNewDistance; MGDirection = j; } } return MGDirection; }


-Martin

J Bytheway is offline J Bytheway
Emperor
England
Jul 2001
time: 05:31
  Old Post 15-10-2003 23:16 Visit J Bytheway's homepage!
Edit/Delete Message Reply w/Quote
#6 Report this post to a moderator
Suffering from ads?

Clever . So you can write a function to obtain a nearest water tile by repeating the above process until you reach water. Of course, this is likely to be relatively slow, but perhaps not too bad. You could of course save the information in an array for any tile you need to calculate so that you never repeat the calculation for that tile, but it probably wouldn't be worthwhile to.

Immortal Wombat is offline Immortal Wombat
Prince
in perpetuity
Dec 2000
time: 05:31
  Old Post 15-10-2003 23:17 Visit Immortal Wombat's homepage!
Edit/Delete Message Reply w/Quote
#7 Report this post to a moderator
Help yourself to an AD-FREE life

code:
location_t TheWatersEdge; Functional_GetNearestWater(location_t startLoc) { // assuming there is water on the map... location_t theLoc; location_t theOtherLoc; int_t i; theLoc = startLoc; while(GetNearestWater(army[0].location, MGLoc.location) > 0){ i = MG_GetWaterDirection(theLoc); GetNeighbor(theLoc,i,theOtherLoc); theLoc = theOtherLoc; } TheWatersEdge = theLoc; }

Immortal Wombat is offline Immortal Wombat
Prince
in perpetuity
Dec 2000
time: 05:31
  Old Post 15-10-2003 23:20 Visit Immortal Wombat's homepage!
Edit/Delete Message Reply w/Quote
#8 Report this post to a moderator
Increase Your PM Length

x=-post

J Bytheway is offline J Bytheway
Emperor
England
Jul 2001
time: 05:31
  Old Post 15-10-2003 23:22 Visit J Bytheway's homepage!
Edit/Delete Message Reply w/Quote
#9 Report this post to a moderator
Support Apolyton buy from Amazon

Indeed - I just came back to raise the question of what happens when there is no water, but you beat me to it .

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:31
Post  Old Post 16-10-2003 20:21 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#10 Report this post to a moderator
Enter the AD-FREE zone

quote:
Originally posted by J Bytheway
Indeed - I just came back to raise the question of what happens when there is no water, but you beat me to it .


In that case GetNearestWater(army[0].location, MGLoc.location) returns 0 and not -1 as I expected. So it is not the best way to figure out wheather you have to do it with a land or a sea tile.

-Martin

Immortal Wombat is offline Immortal Wombat
Prince
in perpetuity
Dec 2000
time: 05:31
  Old Post 17-10-2003 03:21 Visit Immortal Wombat's homepage!
Edit/Delete Message Reply w/Quote
#11 Report this post to a moderator
Browse Apolyton AD-FREE

Do a terrain check on a known land tile (like under a city) beforehand.

J Bytheway is offline J Bytheway
Emperor
England
Jul 2001
time: 05:31
  Old Post 17-10-2003 19:08 Visit J Bytheway's homepage!
Edit/Delete Message Reply w/Quote
#12 Report this post to a moderator
Increase Your PM Length

Under a city might not be the best choice - I can concieve of scenarios that start you with sea cities rather than land ones.

I thought that there was a function to check terrain types - I know I used one in CTP1, surely that must be a faster way to check whether a tile is water or not.

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:31
Post  Old Post 17-10-2003 19:56 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#13 Report this post to a moderator
Inflate your Upload Space

quote:
Originally posted by J Bytheway
Under a city might not be the best choice - I can concieve of scenarios that start you with sea cities rather than land ones.

I thought that there was a function to check terrain types - I know I used one in CTP1, surely that must be a faster way to check whether a tile is water or not.


So there is such a function in CTP1. If this is true and the function is still in CTP2 than Peter and I weren't able to find it.

-Martin

J Bytheway is offline J Bytheway
Emperor
England
Jul 2001
time: 05:31
  Old Post 18-10-2003 16:02 Visit J Bytheway's homepage!
Edit/Delete Message Reply w/Quote
#14 Report this post to a moderator
Suffering from ads?

If I were using my own computer I'd have a look now and see what it was, but I can't. I'll try and remeber to do so the next time I can and get back to you.

J Bytheway is offline J Bytheway
Emperor
England
Jul 2001
time: 05:31
  Old Post 19-10-2003 16:04 Visit J Bytheway's homepage!
Edit/Delete Message Reply w/Quote
#15 Report this post to a moderator
Support Apolyton, buy Civilization 2

Yep, there was, and it was called TerrainType. e.g. I used

code:
if (TerrainType(city.location) == 13)

to test for space cities. I doubt that you could have missed that if it still existed, though.

There was also an IsUnderseaCity(city) function, which might be useful if it still exists, and an IsSpaceCity - but that one didn't work - hence the above workaround.

Peter Triggs is offline Peter Triggs
Prince
Gone Fishin, Canada
Jan 2000
time: 05:31
  Old Post 19-10-2003 17:22
Edit/Delete Message Reply w/Quote
#16 Report this post to a moderator
Avatar Enlargement: We've got the solution

Ahh, now I remember:

code:
int_f CTC_IsSeaTerrain(location_t theLoc){ location_t tmpLoc; tmpLoc=theLoc; if ((9 < TerrainType(tmpLoc) && TerrainType(tmpLoc) < 17) || TerrainType(tmpLoc)==22 || TerrainType(tmpLoc) ==23 ){ return 1; } return 0; }

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

quote:
Originally posted by J Bytheway
Yep, there was, and it was called TerrainType. e.g. I used
code:
if (TerrainType(city.location) == 13)

to test for space cities. I doubt that you could have missed that if it still existed, though.


Well here is my MG_IsLand function:

code:
int_f MG_IsLand(location_t theLoc){ location_t MGLoc; MGLoc = theloc; return((TerrainType(MGLoc)<=9) ||((TerrainType(MGLoc)>=18) && (TerrainType(MGLoc)<=21)) ); }


As you can see I use the TerrainType as well. But that was not that I was looking for. For instance if I change the order of the terrains in the terrain.txt this function above wouldn't work.

quote:
Originally posted by J Bytheway
There was also an IsUnderseaCity(city) function, which might be useful if it still exists, and an IsSpaceCity - but that one didn't work - hence the above workaround.


There is also a IsUnderSeaCity function and I think also a IsSpaceCity function. Well I haven't tested it. But I doubt that the IsUnderSeaCity function works, because whenever undersea tunnels are under a city the terrain is considered as land tile and therefore also the undersea cities, that's the cause of the sea city sprite bug. Well in that case even a build in IsLand function wouldn't work.

-Martin

J Bytheway is offline J Bytheway
Emperor
England
Jul 2001
time: 05:31
  Old Post 19-10-2003 21:36 Visit J Bytheway's homepage!
Edit/Delete Message Reply w/Quote
#18 Report this post to a moderator
Support Apolyton, buy Galactic Civilizations

Hmm... I see the problem.

Perhaps you should try GetNearestWater on a sea city tile and see whether it returns 1 or 0 - If it is being treated as land as you say then it might return 1 and then you can indeed test whether there is any water on the map by using GetNearestWater on the capital city.

Immortal Wombat is offline Immortal Wombat
Prince
in perpetuity
Dec 2000
time: 05:31
  Old Post 20-10-2003 02:12 Visit Immortal Wombat's homepage!
Edit/Delete Message Reply w/Quote
#19 Report this post to a moderator
Support Apolyton, buy Civilization: The Boardgame

You can in place of numbers use the DB-references in that function:

code:
if(TerrainType(tmpLoc) == TerrainDB(TERRAIN_PLAINS)){

For instance. Although in fact the converse would be better, checking it's not a sea terrain rather than is a land terrain, because land terrains are more likely to be added as dummys in scenarios, and AFAIK nobody has ever published anything with an added sea terrain.

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:31
Post  Old Post 29-10-2003 01:27 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#20 Report this post to a moderator
Support Apolyton buy from Amazon

Looks like GetNearestWater scans the whole map for water tiles and returns finally the shortest distance.

-Martin

  < Last Thread     Next Thread > Post New Thread     Post A Reply
All times are GMT. The time now is 05:31.
Apolyton Time is 00:31.
    top of page
Rate This Thread:
archivepost
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.0657 seconds (91.93% PHP - 8.07% MySQL) with 31 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