* Initiate the first movement of a Unit when the pathfinder has found a route. * * @param unit The Unit to operate on. * @return True if movement was initiated (not blocked etc). */
| 1057 | * @return True if movement was initiated (not blocked etc). |
| 1058 | */ |
| 1059 | bool Unit_StartMovement(Unit *unit) |
| 1060 | { |
| 1061 | const UnitInfo *ui; |
| 1062 | int8 orientation; |
| 1063 | uint16 packed; |
| 1064 | uint16 type; |
| 1065 | tile32 position; |
| 1066 | uint16 speed; |
| 1067 | int16 score; |
| 1068 | |
| 1069 | if (unit == NULL) return false; |
| 1070 | |
| 1071 | ui = &g_table_unitInfo[unit->o.type]; |
| 1072 | |
| 1073 | orientation = (int8)((unit->orientation[0].current + 16) & 0xE0); |
| 1074 | |
| 1075 | Unit_SetOrientation(unit, orientation, true, 0); |
| 1076 | Unit_SetOrientation(unit, orientation, false, 1); |
| 1077 | |
| 1078 | position = Tile_MoveByOrientation(unit->o.position, orientation); |
| 1079 | |
| 1080 | packed = Tile_PackTile(position); |
| 1081 | |
| 1082 | unit->distanceToDestination = 0x7FFF; |
| 1083 | |
| 1084 | score = Unit_GetTileEnterScore(unit, packed, orientation / 32); |
| 1085 | |
| 1086 | if (score > 255 || score == -1) return false; |
| 1087 | |
| 1088 | type = Map_GetLandscapeType(packed); |
| 1089 | if (type == LST_STRUCTURE) type = LST_CONCRETE_SLAB; |
| 1090 | |
| 1091 | speed = g_table_landscapeInfo[type].movementSpeed[ui->movementType]; |
| 1092 | |
| 1093 | if (unit->o.type == UNIT_SABOTEUR && type == LST_WALL) speed = 255; |
| 1094 | unit->o.flags.s.isSmoking = false; |
| 1095 | |
| 1096 | /* ENHANCEMENT -- the flag is never set to false in original Dune2; in result, once the wobbling starts, it never stops. */ |
| 1097 | if (g_dune2_enhanced) { |
| 1098 | unit->o.flags.s.isWobbling = g_table_landscapeInfo[type].letUnitWobble; |
| 1099 | } else { |
| 1100 | if (g_table_landscapeInfo[type].letUnitWobble) unit->o.flags.s.isWobbling = true; |
| 1101 | } |
| 1102 | |
| 1103 | if ((ui->o.hitpoints / 2) > unit->o.hitpoints && ui->movementType != MOVEMENT_WINGER) speed -= speed / 4; |
| 1104 | |
| 1105 | Unit_SetSpeed(unit, speed); |
| 1106 | |
| 1107 | if (ui->movementType != MOVEMENT_SLITHER) { |
| 1108 | tile32 positionOld; |
| 1109 | |
| 1110 | positionOld = unit->o.position; |
| 1111 | unit->o.position = position; |
| 1112 | |
| 1113 | Unit_UpdateMap(1, unit); |
| 1114 | |
| 1115 | unit->o.position = positionOld; |
| 1116 | } |
no test coverage detected