Announcement

Collapse
No announcement yet.

Does anybody know how the GetNearestWater function work?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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!"

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

    Comment


    • #3
      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!"

      Comment


      • #4
        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).

        Comment


        • #5
          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!"

          Comment


          • #6
            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.

            Comment


            • #7
              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

              Comment


              • #8
                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

                Comment


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

                  Comment


                  • #10
                    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!"

                    Comment


                    • #11
                      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

                      Comment


                      • #12
                        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.

                        Comment


                        • #13
                          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!"

                          Comment


                          • #14
                            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.

                            Comment


                            • #15
                              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.

                              Comment

                              Working...
                              X