MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / SelectInterestingTarget

Function SelectInterestingTarget

engine/Poseidon/AI/AIUnitImpl.cpp:1157–1214  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1155Target* SelectInterestingTarget(AIUnit* unit, Target* thn)
1156{
1157 Vector3Val uPos = unit->Position();
1158 AIGroup* grp = unit->GetGroup();
1159 if (!grp)
1160 {
1161 return nullptr;
1162 }
1163 if (!grp->GetCenter())
1164 {
1165 return nullptr;
1166 }
1167 // find something known that is near
1168 const TargetList& list = grp->GetTargetList();
1169 // never select target less interesting than certain limit
1170 float thnInteresting = 20;
1171 float thnDist = 50;
1172 if (thn)
1173 {
1174 // increase old target interest to maintain some stability
1175 thnInteresting = HowMuchInteresting(unit, thn) * 3.0f;
1176 thnDist = uPos.Distance(thn->position);
1177 }
1178 for (int i = 0; i < list.Size(); i++)
1179 {
1180 Target* tgt = list[i];
1181 if (tgt->idExact == unit->GetPerson())
1182 {
1183 continue;
1184 }
1185 if (tgt->idExact == unit->GetVehicleIn())
1186 {
1187 continue;
1188 }
1189 if (!tgt->IsKnownBy(unit))
1190 {
1191 continue;
1192 }
1193 if (tgt->type->IsKindOf(GWorld->Preloaded(VTypeStatic)))
1194 {
1195 continue;
1196 }
1197 if (tgt->idExact && tgt->idExact->Static())
1198 {
1199 continue;
1200 }
1201
1202 float tgtDist = tgt->position.Distance(uPos);
1203 float tgtInteresting = HowMuchInteresting(unit, tgt);
1204 if (tgtInteresting * thnDist > thnInteresting * tgtDist)
1205 {
1206 thn = tgt;
1207 thnDist = tgtDist;
1208 thnInteresting = tgtInteresting;
1209 }
1210 }
1211 return thn;
1212}
1213
1214void AIUnit::SetWatch()

Callers 1

SetWatchMethod · 0.85

Calls 11

HowMuchInterestingFunction · 0.85
GetPersonMethod · 0.80
GetVehicleInMethod · 0.80
IsKnownByMethod · 0.80
IsKindOfMethod · 0.80
PositionMethod · 0.45
GetGroupMethod · 0.45
GetCenterMethod · 0.45
DistanceMethod · 0.45
SizeMethod · 0.45
PreloadedMethod · 0.45

Tested by

no test coverage detected