Thread Tools
Old October 13, 2003, 18:14   #1
Martin Gühmann
staff
Call to Power II Democracy GameCall to Power Democracy GameCTP2 Source Code Project
Super Moderator
 
Martin Gühmann's Avatar
 
Local Time: 12:31
Local Date: November 2, 2010
Join Date: Mar 2001
Location: Tübingen, Germany
Posts: 6,206
Does anybody know how the GetNearestWater function work?
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
__________________
Civ2 military advisor: "No complaints, Sir!"
Martin Gühmann is offline  
Old October 13, 2003, 19:53   #2
Peter Triggs
CTP2 Source Code ProjectCivilization IV Creators
King
 
Local Time: 10:31
Local Date: November 2, 2010
Join Date: Jan 2000
Location: Gone Fishin, Canada
Posts: 1,059
You got further than me. My notes just say "Must be broken, keeps giving 'wrong type of argument' errors."
Peter Triggs is offline  
Old October 14, 2003, 11:44   #3
Martin Gühmann
staff
Call to Power II Democracy GameCall to Power Democracy GameCTP2 Source Code Project
Super Moderator
 
Martin Gühmann's Avatar
 
Local Time: 12:31
Local Date: November 2, 2010
Join Date: Mar 2001
Location: Tübingen, Germany
Posts: 6,206
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
__________________
Civ2 military advisor: "No complaints, Sir!"
Martin Gühmann is offline  
Old October 15, 2003, 09:47   #4
J Bytheway
Call to Power PBEMCall to Power II Democracy GameCTP2 Source Code Project
Emperor
 
J Bytheway's Avatar
 
Local Time: 11:31
Local Date: November 2, 2010
Join Date: Jul 2001
Location: England
Posts: 3,826
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).
J Bytheway is offline  
Old October 15, 2003, 10:16   #5
Martin Gühmann
staff
Call to Power II Democracy GameCall to Power Democracy GameCTP2 Source Code Project
Super Moderator
 
Martin Gühmann's Avatar
 
Local Time: 12:31
Local Date: November 2, 2010
Join Date: Mar 2001
Location: Tübingen, Germany
Posts: 6,206
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
__________________
Civ2 military advisor: "No complaints, Sir!"
Martin Gühmann is offline  
Old October 15, 2003, 14:16   #6
J Bytheway
Call to Power PBEMCall to Power II Democracy GameCTP2 Source Code Project
Emperor
 
J Bytheway's Avatar
 
Local Time: 11:31
Local Date: November 2, 2010
Join Date: Jul 2001
Location: England
Posts: 3,826
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.
J Bytheway is offline  
Old October 15, 2003, 14:17   #7
Immortal Wombat
Apolytoners Hall of Fame
Prince
 
Immortal Wombat's Avatar
 
Local Time: 11:31
Local Date: November 2, 2010
Join Date: Dec 2000
Location: in perpetuity
Posts: 4,962
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;
}
__________________
Concrete, Abstract, or Squoingy?
"I don't believe in giving scripting languages because the only additional power they give users is the power to create bugs." - Mike Breitkreutz, Firaxis
Immortal Wombat is offline  
Old October 15, 2003, 14:20   #8
Immortal Wombat
Apolytoners Hall of Fame
Prince
 
Immortal Wombat's Avatar
 
Local Time: 11:31
Local Date: November 2, 2010
Join Date: Dec 2000
Location: in perpetuity
Posts: 4,962
x=-post
__________________
Concrete, Abstract, or Squoingy?
"I don't believe in giving scripting languages because the only additional power they give users is the power to create bugs." - Mike Breitkreutz, Firaxis
Immortal Wombat is offline  
Old October 15, 2003, 14:22   #9
J Bytheway
Call to Power PBEMCall to Power II Democracy GameCTP2 Source Code Project
Emperor
 
J Bytheway's Avatar
 
Local Time: 11:31
Local Date: November 2, 2010
Join Date: Jul 2001
Location: England
Posts: 3,826
Indeed - I just came back to raise the question of what happens when there is no water, but you beat me to it .
J Bytheway is offline  
Old October 16, 2003, 11:21   #10
Martin Gühmann
staff
Call to Power II Democracy GameCall to Power Democracy GameCTP2 Source Code Project
Super Moderator
 
Martin Gühmann's Avatar
 
Local Time: 12:31
Local Date: November 2, 2010
Join Date: Mar 2001
Location: Tübingen, Germany
Posts: 6,206
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
__________________
Civ2 military advisor: "No complaints, Sir!"
Martin Gühmann is offline  
Old October 16, 2003, 18:21   #11
Immortal Wombat
Apolytoners Hall of Fame
Prince
 
Immortal Wombat's Avatar
 
Local Time: 11:31
Local Date: November 2, 2010
Join Date: Dec 2000
Location: in perpetuity
Posts: 4,962
Do a terrain check on a known land tile (like under a city) beforehand.
__________________
Concrete, Abstract, or Squoingy?
"I don't believe in giving scripting languages because the only additional power they give users is the power to create bugs." - Mike Breitkreutz, Firaxis
Immortal Wombat is offline  
Old October 17, 2003, 10:08   #12
J Bytheway
Call to Power PBEMCall to Power II Democracy GameCTP2 Source Code Project
Emperor
 
J Bytheway's Avatar
 
Local Time: 11:31
Local Date: November 2, 2010
Join Date: Jul 2001
Location: England
Posts: 3,826
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.
J Bytheway is offline  
Old October 17, 2003, 10:56   #13
Martin Gühmann
staff
Call to Power II Democracy GameCall to Power Democracy GameCTP2 Source Code Project
Super Moderator
 
Martin Gühmann's Avatar
 
Local Time: 12:31
Local Date: November 2, 2010
Join Date: Mar 2001
Location: Tübingen, Germany
Posts: 6,206
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
__________________
Civ2 military advisor: "No complaints, Sir!"
Martin Gühmann is offline  
Old October 18, 2003, 07:02   #14
J Bytheway
Call to Power PBEMCall to Power II Democracy GameCTP2 Source Code Project
Emperor
 
J Bytheway's Avatar
 
Local Time: 11:31
Local Date: November 2, 2010
Join Date: Jul 2001
Location: England
Posts: 3,826
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  
Old October 19, 2003, 07:04   #15
J Bytheway
Call to Power PBEMCall to Power II Democracy GameCTP2 Source Code Project
Emperor
 
J Bytheway's Avatar
 
Local Time: 11:31
Local Date: November 2, 2010
Join Date: Jul 2001
Location: England
Posts: 3,826
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.
J Bytheway is offline  
Old October 19, 2003, 08:22   #16
Peter Triggs
CTP2 Source Code ProjectCivilization IV Creators
King
 
Local Time: 10:31
Local Date: November 2, 2010
Join Date: Jan 2000
Location: Gone Fishin, Canada
Posts: 1,059
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;

}
Peter Triggs is offline  
Old October 19, 2003, 10:10   #17
Martin Gühmann
staff
Call to Power II Democracy GameCall to Power Democracy GameCTP2 Source Code Project
Super Moderator
 
Martin Gühmann's Avatar
 
Local Time: 12:31
Local Date: November 2, 2010
Join Date: Mar 2001
Location: Tübingen, Germany
Posts: 6,206
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
__________________
Civ2 military advisor: "No complaints, Sir!"
Martin Gühmann is offline  
Old October 19, 2003, 12:36   #18
J Bytheway
Call to Power PBEMCall to Power II Democracy GameCTP2 Source Code Project
Emperor
 
J Bytheway's Avatar
 
Local Time: 11:31
Local Date: November 2, 2010
Join Date: Jul 2001
Location: England
Posts: 3,826
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.
J Bytheway is offline  
Old October 19, 2003, 17:12   #19
Immortal Wombat
Apolytoners Hall of Fame
Prince
 
Immortal Wombat's Avatar
 
Local Time: 11:31
Local Date: November 2, 2010
Join Date: Dec 2000
Location: in perpetuity
Posts: 4,962
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.
__________________
Concrete, Abstract, or Squoingy?
"I don't believe in giving scripting languages because the only additional power they give users is the power to create bugs." - Mike Breitkreutz, Firaxis
Immortal Wombat is offline  
Old October 28, 2003, 16:27   #20
Martin Gühmann
staff
Call to Power II Democracy GameCall to Power Democracy GameCTP2 Source Code Project
Super Moderator
 
Martin Gühmann's Avatar
 
Local Time: 12:31
Local Date: November 2, 2010
Join Date: Mar 2001
Location: Tübingen, Germany
Posts: 6,206
Looks like GetNearestWater scans the whole map for water tiles and returns finally the shortest distance.

-Martin
__________________
Civ2 military advisor: "No complaints, Sir!"
Martin Gühmann is offline  
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 06:31.


Design by Vjacheslav Trushkin, color scheme by ColorizeIt!.
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Apolyton Civilization Site | Copyright © The Apolyton Team