MCPcopy Create free account
hub / github.com/SimHacker/micropolis / getBoatDistance

Method getBoatDistance

MicropolisCore/src/MicropolisEngine/src/simulate.cpp:1250–1269  ·  view source on GitHub ↗

* Compute distance to nearest boat from a given bridge. * @param pos Position of bridge. * @return Distance to nearest boat. */

Source from the content-addressed store, hash-verified

1248 * @return Distance to nearest boat.
1249 */
1250int Micropolis::getBoatDistance(const Position &pos)
1251{
1252 int sprDist;
1253 SimSprite *sprite;
1254
1255 int dist = 99999;
1256 int mx = pos.posX * 16 + 8;
1257 int my = pos.posY * 16 + 8;
1258
1259 for (sprite = spriteList; sprite != NULL; sprite = sprite->next) {
1260 if (sprite->type == SPRITE_SHIP && sprite->frame != 0) {
1261
1262 sprDist = absoluteValue(sprite->x + sprite->xHot - mx)
1263 + absoluteValue(sprite->y + sprite->yHot - my);
1264
1265 dist = min(dist, sprDist);
1266 }
1267 }
1268 return dist;
1269}
1270
1271
1272/**

Callers

nothing calls this directly

Calls 2

absoluteValueFunction · 0.85
minFunction · 0.85

Tested by

no test coverage detected