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

Function Unit_Deviation_Decrease

src/unit.c:1174–1210  ·  view source on GitHub ↗

* Decrease deviation counter for the given unit. * * @param unit The Unit to decrease counter for. * @param amount The amount to decrease. * @return True if and only if the unit lost deviation. */

Source from the content-addressed store, hash-verified

1172 * @return True if and only if the unit lost deviation.
1173 */
1174bool Unit_Deviation_Decrease(Unit *unit, uint16 amount)
1175{
1176 const UnitInfo *ui;
1177
1178 if (unit == NULL || unit->deviated == 0) return false;
1179
1180 ui = &g_table_unitInfo[unit->o.type];
1181
1182 if (!ui->flags.isNormalUnit) return false;
1183
1184 if (amount == 0) {
1185 amount = g_table_houseInfo[unit->o.houseID].toughness;
1186 }
1187
1188 if (unit->deviated > amount) {
1189 unit->deviated -= amount;
1190 return false;
1191 }
1192
1193 unit->deviated = 0;
1194
1195 unit->o.flags.s.bulletIsBig = true;
1196 Unit_UpdateMap(2, unit);
1197 unit->o.flags.s.bulletIsBig = false;
1198
1199 if (unit->o.houseID == g_playerHouseID) {
1200 Unit_SetAction(unit, ui->o.actionsPlayer[3]);
1201 } else {
1202 Unit_SetAction(unit, ui->actionAI);
1203 }
1204
1205 Unit_UntargetMe(unit);
1206 unit->targetAttack = 0;
1207 unit->targetMove = 0;
1208
1209 return true;
1210}
1211
1212/**
1213 * Remove fog arount the given unit.

Callers 5

GameLoop_UnitFunction · 0.85
Unit_StartMovementFunction · 0.85
Unit_DamageFunction · 0.85
Script_Unit_FireFunction · 0.85

Calls 3

Unit_UpdateMapFunction · 0.85
Unit_SetActionFunction · 0.85
Unit_UntargetMeFunction · 0.85

Tested by

no test coverage detected