Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 330 vs 331 for /trunk/Source Code/Scenes/WarScene/WarSceneAISceneImpl.cpp

Diff revisions: vs.
  @@ -34,26 +34,38 @@
34 34
35 35 WarSceneAISceneImpl::~WarSceneAISceneImpl()
36 36 {
37 - for(GOAPAction*& action : actionSetPtr()) {
38 - MemoryManager::SAFE_DELETE( action );
39 - }
40 - actionSetPtr().clear();
37 + MemoryManager::DELETE_VECTOR(actionSetPtr());
41 38 }
42 39
43 40 void WarSceneAISceneImpl::registerAction(GOAPAction* const action) {
44 41 WarSceneAction* const warAction = dynamic_cast<WarSceneAction*>(action);
45 42 warAction->setParentAIScene(this);
46 - switch(warAction->actionType()){
47 - case ACTION_APPROACH_FLAG : AISceneImpl::registerAction(New ApproachFlag(*warAction)); return;
48 - case ACTION_CAPTURE_FLAG : AISceneImpl::registerAction(New CaptureFlag(*warAction)); return;
49 - case ACTION_RETURN_FLAG : AISceneImpl::registerAction(New ReturnFlag(*warAction)); return;
50 - case ACTION_RECOVER_FLAG : AISceneImpl::registerAction(New RecoverFlag(*warAction)); return;
51 - case ACTION_KILL_ENEMY : AISceneImpl::registerAction(New KillEnemy(*warAction)); return;
52 - case ACTION_RETURN_TO_BASE: AISceneImpl::registerAction(New ReturnHome(*warAction)); return;
53 - case ACTION_PROTECT_FLAG_CARRIER : AISceneImpl::registerAction(New ProtectFlagCarrier(*warAction)); return;
43 +
44 + switch(warAction->actionType()) {
45 + case ACTION_APPROACH_FLAG :
46 + AISceneImpl::registerAction(MemoryManager_NEW ApproachFlag(*warAction));
47 + return;
48 + case ACTION_CAPTURE_FLAG :
49 + AISceneImpl::registerAction(MemoryManager_NEW CaptureFlag(*warAction));
50 + return;
51 + case ACTION_RETURN_FLAG :
52 + AISceneImpl::registerAction(MemoryManager_NEW ReturnFlag(*warAction));
53 + return;
54 + case ACTION_RECOVER_FLAG :
55 + AISceneImpl::registerAction(MemoryManager_NEW RecoverFlag(*warAction));
56 + return;
57 + case ACTION_KILL_ENEMY :
58 + AISceneImpl::registerAction(MemoryManager_NEW KillEnemy(*warAction));
59 + return;
60 + case ACTION_RETURN_TO_BASE:
61 + AISceneImpl::registerAction(MemoryManager_NEW ReturnHome(*warAction));
62 + return;
63 + case ACTION_PROTECT_FLAG_CARRIER :
64 + AISceneImpl::registerAction(MemoryManager_NEW ProtectFlagCarrier(*warAction));
65 + return;
54 66 };
55 67
56 - AISceneImpl::registerAction(New WarSceneAction(*warAction));
68 + AISceneImpl::registerAction(MemoryManager_NEW WarSceneAction(*warAction));
57 69 }
58 70
59 71 void WarSceneAISceneImpl::init() {
  @@ -184,13 +196,15 @@
184 196 D_PRINT_FN("Starting protect flag action [ %d ]", _entity->getGUID());
185 197 assert(_workingMemory._flagCarrier.value() != nullptr);
186 198 _entity->updateDestination(_workingMemory._flagCarrier.value()->getPosition());
187 - WorkingMemory::_flagProtectors[currentTeam->getTeamID()].value(WorkingMemory::_flagProtectors[currentTeam->getTeamID()].value() + 1);
199 + U8 temp = WorkingMemory::_flagProtectors[currentTeam->getTeamID()].value() + 1;
200 + WorkingMemory::_flagProtectors[currentTeam->getTeamID()].value(temp);
188 201 } break;
189 202 case ACTION_RECOVER_FLAG: {
190 203 D_PRINT_FN("Starting recover flag action [ %d ]", _entity->getGUID());
191 204 assert(_workingMemory._enemyFlagCarrier.value() != nullptr);
192 205 _entity->updateDestination(_workingMemory._enemyFlagCarrier.value()->getPosition());
193 - WorkingMemory::_flagRetrievers[currentTeam->getTeamID()].value(WorkingMemory::_flagRetrievers[currentTeam->getTeamID()].value() + 1);
206 + U8 temp = WorkingMemory::_flagRetrievers[currentTeam->getTeamID()].value() + 1;
207 + WorkingMemory::_flagRetrievers[currentTeam->getTeamID()].value(temp);
194 208 } break;
195 209 default : {
196 210 D_PRINT_FN("Starting normal action [ %d ]", _entity->getGUID());
  @@ -248,10 +262,12 @@
248 262 pComp->setScale(prevScale * targetNode->getComponent<PhysicsComponent>()->getScale());
249 263 } break;
250 264 case ACTION_PROTECT_FLAG_CARRIER: {
251 - WorkingMemory::_flagProtectors[currentTeam->getTeamID()].value(WorkingMemory::_flagProtectors[currentTeam->getTeamID()].value() - 1);
265 + U8 temp = WorkingMemory::_flagProtectors[currentTeam->getTeamID()].value() - 1;
266 + WorkingMemory::_flagProtectors[currentTeam->getTeamID()].value(temp);
252 267 } break;
253 268 case ACTION_RECOVER_FLAG: {
254 - WorkingMemory::_flagRetrievers[currentTeam->getTeamID()].value(WorkingMemory::_flagRetrievers[currentTeam->getTeamID()].value() - 1);
269 + U8 temp = WorkingMemory::_flagRetrievers[currentTeam->getTeamID()].value() - 1;
270 + WorkingMemory::_flagRetrievers[currentTeam->getTeamID()].value(temp);
255 271 } break;
256 272 default : {
257 273 PRINT_FN("Normal action over [ %d ]", _entity->getGUID());
  @@ -301,8 +317,9 @@
301 317 const SceneGraphNode* const ownFlag = _workingMemory._flags[currentTeam->getTeamID()].value();
302 318 const BoundingBox& ownFlagBB = ownFlag->getBoundingBoxConst();
303 319 // Our flag is in its original position and the 2 flags are touching
320 + const vec3<F32>& flagPos = ownFlag->getComponent<PhysicsComponent>()->getPosition();
304 321 state = (enemyFlag->getBoundingBoxConst().Collision(ownFlagBB) &&
305 - ownFlag->getComponent<PhysicsComponent>()->getPosition().distanceSquared(_initialFlagPositions[currentTeam->getTeamID()]) < g_ATTACK_RADIUS);
322 + flagPos.distanceSquared(_initialFlagPositions[currentTeam->getTeamID()]) < g_ATTACK_RADIUS);
306 323 } break;
307 324 case ACTION_PROTECT_FLAG_CARRIER: {
308 325 if (_entity->destinationReached()) {
  @@ -315,7 +332,8 @@
315 332 }
316 333 }break;
317 334 case ACTION_RETURN_TO_BASE: {
318 - state = _entity->getPosition().distanceSquared(_initialFlagPositions[currentTeam->getTeamID()]) < g_ATTACK_RADIUS * g_ATTACK_RADIUS;
335 + state = _entity->getPosition().distanceSquared(_initialFlagPositions[currentTeam->getTeamID()]) <
336 + g_ATTACK_RADIUS * g_ATTACK_RADIUS;
319 337 if (!state && _entity->destinationReached()) {
320 338 _entity->updateDestination(_initialFlagPositions[currentTeam->getTeamID()]);
321 339 }
  @@ -350,15 +368,21 @@
350 368
351 369 void WarSceneAISceneImpl::updatePositions() {
352 370 if (_workingMemory._flags[0].value() != nullptr && _workingMemory._flags[1].value() != nullptr) {
353 - _workingMemory._teamFlagPosition[0].value(_visualSensor->getNodePosition(g_flagContainer, _workingMemory._flags[0].value()->getGUID()));
354 - _workingMemory._teamFlagPosition[1].value(_visualSensor->getNodePosition(g_flagContainer, _workingMemory._flags[1].value()->getGUID()));
355 -
356 - _workingMemory._enemyFlagNear.value(_workingMemory._teamFlagPosition[1 - _entity->getTeamID()].value().distanceSquared(_entity->getPosition()) < g_ATTACK_RADIUS * g_ATTACK_RADIUS);
357 - _workingMemory._friendlyFlagNear.value(_workingMemory._teamFlagPosition[_entity->getTeamID()].value().distanceSquared(_entity->getPosition()) < g_ATTACK_RADIUS * g_ATTACK_RADIUS);
371 + _workingMemory._teamFlagPosition[0].value(_visualSensor->getNodePosition(g_flagContainer,
372 + _workingMemory._flags[0].value()->getGUID()));
373 + _workingMemory._teamFlagPosition[1].value(_visualSensor->getNodePosition(g_flagContainer,
374 + _workingMemory._flags[1].value()->getGUID()));
375 +
376 + const vec3<F32>& flag1Pos = _workingMemory._teamFlagPosition[1 - _entity->getTeamID()].value();
377 + const vec3<F32>& flag2Pos = _workingMemory._teamFlagPosition[1 - _entity->getTeamID()].value();
378 + F32 radiusSq = g_ATTACK_RADIUS * g_ATTACK_RADIUS;
379 + _workingMemory._enemyFlagNear.value(flag1Pos.distanceSquared(_entity->getPosition()) < radiusSq);
380 + _workingMemory._friendlyFlagNear.value(flag2Pos.distanceSquared(_entity->getPosition()) < radiusSq);
358 381 }
359 382
360 383 if (_workingMemory._currentTargetEntity.value()) {
361 - _workingMemory._currentTargetPosition.value( _workingMemory._currentTargetEntity.value()->getComponent<PhysicsComponent>()->getPosition());
384 + PhysicsComponent* pComp = _workingMemory._currentTargetEntity.value()->getComponent<PhysicsComponent>();
385 + _workingMemory._currentTargetPosition.value(pComp->getPosition());
362 386 }
363 387 }
364 388
  @@ -441,7 +465,8 @@
441 465 GOAPValue newVal = step->second;
442 466 GOAPValue oldVal = worldState().getVariable(crtFact);
443 467 if (oldVal != newVal) {
444 - PRINT_FN("\t\t [%d] Changing \"%s\" from \"%s\" to \"%s\"", _entity->getGUID(), WarSceneFactName(crtFact), GOAPValueName(oldVal), GOAPValueName(newVal));
468 + PRINT_FN("\t\t [%d] Changing \"%s\" from \"%s\" to \"%s\"",
469 + _entity->getGUID(), WarSceneFactName(crtFact), GOAPValueName(oldVal), GOAPValueName(newVal));
445 470 }
446 471 worldState().setVariable(crtFact, newVal);
447 472 return true;
  @@ -454,16 +479,22 @@
454 479
455 480 void WarSceneAISceneImpl::printWorkingMemory() const {
456 481 PRINT_FN("--------------- Working memory state for [ %d ] BEGIN ----------------------------", _entity->getGUID());
457 - PRINT_FN(" Team Counts - 0: %d | 1: %d", _workingMemory._teamCount[0].value(), _workingMemory._teamCount[1].value());
458 - PRINT_FN(" Current position: - [ %4.1f , %4.1f, %4.1f]", _entity->getPosition().x, _entity->getPosition().y, _entity->getPosition().z);
459 - PRINT_FN(" Flag Protectors - 0: %d | 1: %d", _workingMemory._flagProtectors[0].value(), _workingMemory._flagProtectors[1].value());
460 - PRINT_FN(" Flag Retrievers - 0: %d | 1: %d", _workingMemory._flagRetrievers[0].value(), _workingMemory._flagRetrievers[1].value());
461 - PRINT_FN(" Flag Positions - 0 : [ %4.1f , %4.1f, %4.1f] | 1 : [ %4.1f , %4.1f, %4.1f]", _workingMemory._teamFlagPosition[0].value().x,
462 - _workingMemory._teamFlagPosition[0].value().y,
463 - _workingMemory._teamFlagPosition[0].value().z,
464 - _workingMemory._teamFlagPosition[1].value().x,
465 - _workingMemory._teamFlagPosition[1].value().y,
466 - _workingMemory._teamFlagPosition[1].value().z);
482 + PRINT_FN(" Team Counts - 0: %d | 1: %d", _workingMemory._teamCount[0].value(),
483 + _workingMemory._teamCount[1].value());
484 + PRINT_FN(" Current position: - [ %4.1f , %4.1f, %4.1f]", _entity->getPosition().x,
485 + _entity->getPosition().y,
486 + _entity->getPosition().z);
487 + PRINT_FN(" Flag Protectors - 0: %d | 1: %d", _workingMemory._flagProtectors[0].value(),
488 + _workingMemory._flagProtectors[1].value());
489 + PRINT_FN(" Flag Retrievers - 0: %d | 1: %d", _workingMemory._flagRetrievers[0].value(),
490 + _workingMemory._flagRetrievers[1].value());
491 + PRINT_FN(" Flag Positions - 0 : [ %4.1f , %4.1f, %4.1f] | 1 : [ %4.1f , %4.1f, %4.1f]",
492 + _workingMemory._teamFlagPosition[0].value().x,
493 + _workingMemory._teamFlagPosition[0].value().y,
494 + _workingMemory._teamFlagPosition[0].value().z,
495 + _workingMemory._teamFlagPosition[1].value().x,
496 + _workingMemory._teamFlagPosition[1].value().y,
497 + _workingMemory._teamFlagPosition[1].value().z);
467 498
468 499 if (_workingMemory._flagCarrier.value()) {
469 500 PRINT_FN(" Flag carrier : [ %d ] ", _workingMemory._flagCarrier.value()->getGUID());