Server Help

Bot Questions - random warping

The Cubbies - Tue Sep 26, 2006 2:13 pm
Post subject: random warping
I have a function that has the bot warp a player to a random spot on the map. As I have it now, the spot it chooses could have a tile on it. I want to avoid these areas. Is there a way to determine before warping if that spot has a tile? I looked though the map.cpp but couldn't really find what I was looking for. (I'm using Merv).
D1st0rt - Tue Sep 26, 2006 3:46 pm
Post subject:
Code: Show/Hide
if(map[getLinear(x, y)] == vieNoTile) //from the MapTileFormat enum defined in map.h

should do the trick
Mine GO BOOM - Tue Sep 26, 2006 4:22 pm
Post subject:
Ships are not 16x16, so you need to actually check a box worth around the location you want to warp to, one extra tile in all 8 directions.
Code: Show/Hide
x x x
x S x
x x x

The Cubbies - Tue Sep 26, 2006 4:42 pm
Post subject:
I had already tried Distort's method before posting and I got this error:

spawn.obj : error LNK2001: unresolved external symbol "unsigned long __cdecl getLinear(unsigned long,unsigned long)" (?getLinear@@YAKKK@Z)

I was confused by it, so I posted this topic. I just realized that I needed to #include "..\map.cpp" Sorry for the annoyance.
Bak - Tue Sep 26, 2006 4:55 pm
Post subject:
Lemme try this...

Code: Show/Hide
const int mapSize = 1024;
const int clearTiles[] = {   0 /* blank */,
                     170 /* flag */,
                     171 /* safe zone */,
                     172 /* soccer goal */,
                     173, 174, 175 /* fly over */,
                     176, 177, 178, 179, 180, 181, 182, 183, 184 /* fly under opaque */,
                     185, 186, 187, 188, 189, 190 /* fly under transparent */ };

int xTile, yTile;

for(bool foundGoodTile = false; !foundGoodTile;)
{
   // pick a random tile not on the border
   xTile = 1 + rand() % (mapSize - 2);
   yTile = 1 + rand() % (mapSize - 2);
   
   // check if there's any walls near it
   for (int dy = -1; dy <= 1; ++dy) for (int dx = -1; dx <= 1; ++dx)
   {
      int curXTile = xTile + dx;
      int curYTile = yTile + dy;
      int curIndex = curXTile + mapSize * curYTile;
      bool isClear = false;
      foundGoodTile = true; // this spot is good unless we prove otherwise
      
      for (unsigned int c = 0; c < sizeof(clearTiles) / sizeof(clearTiles[0]); ++c)
      {
         if (clearTiles[c] == map[curIndex])
         {
            isClear = true;
            break;
         }
      }
      
      if (!isClear) // this spot is no good, jump out of both for loops and try a new spot
      {
         foundGoodTile = false;
         goto end_checking_walls;
      }
   }
   
   end_checking_walls: ;
}

sendPrivate(p, "*warpto " + (String)xTile + " " + (String)yTile);

Mine GO BOOM - Tue Sep 26, 2006 4:57 pm
Post subject:
The Cubbies wrote:
I just realized that I needed to #include "..\map.cpp"

You shouldn't directly include another source file. The point of having seperate files is that you can compile them into individual object files, and then the linker combinds them. Including it directly just involves your compiler having to recompile the exact same things everytime your file changes. Add the file to your project instead. Once you get up in the tens or hundreds of thousands of lines of code, you'll notice a big difference.
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group