* Deviate the given unit. * * @param unit The Unit to deviate. * @param probability The probability for deviation to succeed. * @param houseID House controlling the deviator. * @return True if and only if the unit beacame deviated. */
| 1239 | * @return True if and only if the unit beacame deviated. |
| 1240 | */ |
| 1241 | bool Unit_Deviate(Unit *unit, uint16 probability, uint8 houseID) |
| 1242 | { |
| 1243 | const UnitInfo *ui; |
| 1244 | |
| 1245 | if (unit == NULL) return false; |
| 1246 | |
| 1247 | ui = &g_table_unitInfo[unit->o.type]; |
| 1248 | |
| 1249 | if (!ui->flags.isNormalUnit) return false; |
| 1250 | if (unit->deviated != 0) return false; |
| 1251 | if (ui->flags.isNotDeviatable) return false; |
| 1252 | |
| 1253 | if (probability == 0) probability = g_table_houseInfo[unit->o.houseID].toughness; |
| 1254 | |
| 1255 | if (unit->o.houseID != g_playerHouseID) { |
| 1256 | probability -= probability / 8; |
| 1257 | } |
| 1258 | |
| 1259 | if (Tools_Random_256() >= probability) return false; |
| 1260 | |
| 1261 | unit->deviated = 120; |
| 1262 | unit->deviatedHouse = houseID; |
| 1263 | |
| 1264 | Unit_UpdateMap(2, unit); |
| 1265 | |
| 1266 | if (g_playerHouseID == unit->deviatedHouse) { |
| 1267 | Unit_SetAction(unit, ui->o.actionsPlayer[3]); |
| 1268 | } else { |
| 1269 | Unit_SetAction(unit, ui->actionAI); |
| 1270 | } |
| 1271 | |
| 1272 | Unit_UntargetMe(unit); |
| 1273 | unit->targetAttack = 0; |
| 1274 | unit->targetMove = 0; |
| 1275 | |
| 1276 | return true; |
| 1277 | } |
| 1278 | |
| 1279 | /** |
| 1280 | * Moves the given unit. |
no test coverage detected