| 1214 | void AIUnit::SetWatch() |
| 1215 | { |
| 1216 | // cosider engaging target |
| 1217 | AIGroup* grp = GetGroup(); |
| 1218 | if (!IsPlayer() && _targetAssigned && !grp->CommandSent(this, Command::Attack) && |
| 1219 | !grp->CommandSent(this, Command::AttackAndFire) && !grp->CommandSent(this, Command::GetOut) && |
| 1220 | !grp->CommandSent(this, Command::GetIn) && (_targetAssigned == _targetEngage || !IsKeepingFormation())) |
| 1221 | { |
| 1222 | EntityAI* veh = GetVehicle(); |
| 1223 | FireResult result; |
| 1224 | Vector3 pos; |
| 1225 | if (veh->AttackThink(result, pos)) |
| 1226 | { |
| 1227 | // check if we are ready to fire |
| 1228 | // if not, we probably will have to attack |
| 1229 | float ttl = GetTimeToLive(); |
| 1230 | FireResult fResult; |
| 1231 | veh->WhatFireResult(fResult, *_targetAssigned, ttl); |
| 1232 | if (result.CleanSurplus() > fResult.CleanSurplus() * 1.2 + 200) |
| 1233 | { |
| 1234 | // some good attack position found |
| 1235 | // issue auto attack command |
| 1236 | |
| 1237 | Command cmd; |
| 1238 | cmd._message = Command::Attack; |
| 1239 | cmd._targetE = _targetAssigned; |
| 1240 | cmd._destination = pos; |
| 1241 | |
| 1242 | // automatic attack command |
| 1243 | grp->NotifyAutoCommand(cmd, this); |
| 1244 | } |
| 1245 | } |
| 1246 | } |
| 1247 | |
| 1248 | // consider formation and watch mode |
| 1249 | switch (_watchMode) |
| 1250 | { |
| 1251 | case WMAround: |
| 1252 | { |
| 1253 | float time = Glob.time - _watchDirSet; |
| 1254 | Matrix3 rotY(MRotationY, time * ((H_PI * 2) / 30)); |
| 1255 | _watchDir = rotY * _watchDir; |
| 1256 | _watchDir[1] = 0; |
| 1257 | _watchDir.Normalize(); |
| 1258 | _watchDirSet = Glob.time; |
| 1259 | _watchDirHead = _watchDir; |
| 1260 | } |
| 1261 | break; |
| 1262 | case WMPos: |
| 1263 | { |
| 1264 | _watchDir = _watchPos - GetVehicle()->CameraPosition(); |
| 1265 | _watchDir.Normalize(); |
| 1266 | _watchDirHead = _watchDir; |
| 1267 | } |
| 1268 | break; |
| 1269 | case WMTgt: |
| 1270 | if (_watchTgt) |
| 1271 | { |
| 1272 | _watchPos = _watchTgt->AimingPosition(); |
| 1273 | _watchDir = _watchPos - GetVehicle()->CameraPosition(); |
nothing calls this directly
no test coverage detected