| 702 | } |
| 703 | |
| 704 | Target* AIGroup::AddTarget(EntityAI* object, float accuracy, float sideAccuracy, float delay, const Vector3* pos, |
| 705 | AIUnit* sensor, float sensorDelay) |
| 706 | { |
| 707 | // check if target is already in list |
| 708 | Target* target = nullptr; |
| 709 | for (int i = 0; i < _targetList.Size(); i++) |
| 710 | { |
| 711 | Target* t = _targetList[i]; |
| 712 | if (t->idExact == object) |
| 713 | { |
| 714 | // set new accuracy |
| 715 | target = t; |
| 716 | break; |
| 717 | } |
| 718 | } |
| 719 | |
| 720 | if (!target) |
| 721 | { |
| 722 | target = new Target(this); |
| 723 | _targetList.Add(target); |
| 724 | target->idExact = object; |
| 725 | target->side = TSideUnknown; |
| 726 | target->sideChecked = false; |
| 727 | target->type = GWorld->Preloaded(VTypeAllVehicles); |
| 728 | target->timeReported = TIME_MIN; |
| 729 | target->isKnown = false; |
| 730 | } |
| 731 | if (!target->isKnown) |
| 732 | { |
| 733 | target->isKnown = true; |
| 734 | if (!pos) |
| 735 | { |
| 736 | Vector3 apos = object->AimingPosition(); |
| 737 | // introduce some random error |
| 738 | if (accuracy < 1) |
| 739 | { |
| 740 | float randomX = GRandGen.RandomValue() * 200 - 100; |
| 741 | float randomZ = GRandGen.RandomValue() * 200 - 100; |
| 742 | // y above ground should be correct |
| 743 | float aboveGround = GLandscape->SurfaceYAboveWater(apos.X(), apos.Z()) - apos.Y(); |
| 744 | apos[0] += randomX; |
| 745 | apos[2] += randomZ; |
| 746 | apos[1] = GLandscape->SurfaceYAboveWater(apos[0], apos[2]) + aboveGround; |
| 747 | } |
| 748 | target->position = apos; |
| 749 | } |
| 750 | else |
| 751 | { |
| 752 | target->position = *pos; |
| 753 | } |
| 754 | target->speed = VZero; // speed not known |
| 755 | if (sensor) |
| 756 | { |
| 757 | target->lastSeen = Glob.time - 40 + sensorDelay; |
| 758 | target->delaySensor = Glob.time + sensorDelay; |
| 759 | target->delay = Glob.time + delay; |
| 760 | target->idSensor = sensor->GetPerson(); |
| 761 | } |
nothing calls this directly
no test coverage detected