* Moves the given unit. * * @param unit The Unit to move. * @param distance The maximum distance to pass through. * @return ??. */
| 1284 | * @return ??. |
| 1285 | */ |
| 1286 | bool Unit_Move(Unit *unit, uint16 distance) |
| 1287 | { |
| 1288 | const UnitInfo *ui; |
| 1289 | uint16 d; |
| 1290 | uint16 packed; |
| 1291 | tile32 newPosition; |
| 1292 | bool ret; |
| 1293 | tile32 currentDestination; |
| 1294 | bool isSpiceBloom = false; |
| 1295 | bool isSpecialBloom = false; |
| 1296 | |
| 1297 | if (unit == NULL || !unit->o.flags.s.used) return false; |
| 1298 | |
| 1299 | ui = &g_table_unitInfo[unit->o.type]; |
| 1300 | |
| 1301 | newPosition = Tile_MoveByDirection(unit->o.position, unit->orientation[0].current, distance); |
| 1302 | |
| 1303 | if ((newPosition.x == unit->o.position.x) && (newPosition.y == unit->o.position.y)) return false; |
| 1304 | |
| 1305 | if (!Tile_IsValid(newPosition)) { |
| 1306 | if (!ui->flags.mustStayInMap) { |
| 1307 | Unit_Remove(unit); |
| 1308 | return true; |
| 1309 | } |
| 1310 | |
| 1311 | if (unit->o.flags.s.byScenario && unit->o.linkedID == 0xFF && unit->o.script.variables[4] == 0) { |
| 1312 | Unit_Remove(unit); |
| 1313 | return true; |
| 1314 | } |
| 1315 | |
| 1316 | newPosition = unit->o.position; |
| 1317 | Unit_SetOrientation(unit, unit->orientation[0].current + (Tools_Random_256() & 0xF), false, 0); |
| 1318 | } |
| 1319 | |
| 1320 | unit->wobbleIndex = 0; |
| 1321 | if (ui->flags.canWobble && unit->o.flags.s.isWobbling) { |
| 1322 | unit->wobbleIndex = Tools_Random_256() & 7; |
| 1323 | } |
| 1324 | |
| 1325 | d = Tile_GetDistance(newPosition, unit->currentDestination); |
| 1326 | packed = Tile_PackTile(newPosition); |
| 1327 | |
| 1328 | if (ui->flags.isTracked && d < 48) { |
| 1329 | Unit *u; |
| 1330 | u = Unit_Get_ByPackedTile(packed); |
| 1331 | |
| 1332 | /* Driving over a foot unit */ |
| 1333 | if (u != NULL && g_table_unitInfo[u->o.type].movementType == MOVEMENT_FOOT && u->o.flags.s.allocated) { |
| 1334 | if (u == g_unitSelected) Unit_Select(NULL); |
| 1335 | |
| 1336 | Unit_UntargetMe(u); |
| 1337 | u->o.script.variables[1] = 1; |
| 1338 | Unit_SetAction(u, ACTION_DIE); |
| 1339 | } else { |
| 1340 | uint16 type = Map_GetLandscapeType(packed); |
| 1341 | /* Produce tracks in the sand */ |
| 1342 | if ((type == LST_NORMAL_SAND || type == LST_ENTIRELY_DUNE) && g_map[packed].overlayTileID == 0) { |
| 1343 | uint8 animationID = Orientation_Orientation256ToOrientation8(unit->orientation[0].current); |
no test coverage detected