MCPcopy Create free account
hub / github.com/OpenDUNE/OpenDUNE / Unit_Deviate

Function Unit_Deviate

src/unit.c:1241–1277  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

1239 * @return True if and only if the unit beacame deviated.
1240 */
1241bool 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.

Callers 1

Map_DeviateAreaFunction · 0.85

Calls 4

Tools_Random_256Function · 0.85
Unit_UpdateMapFunction · 0.85
Unit_SetActionFunction · 0.85
Unit_UntargetMeFunction · 0.85

Tested by

no test coverage detected