Subversion Repository Public Repository

Divide-Framework

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
#include "Headers/WarSceneAISceneImpl.h"
#include "AI/Sensors/Headers/VisualSensor.h"
#include "AI/ActionInterface/Headers/AITeam.h"

#include "Managers/Headers/AIManager.h"
#include "Core/Math/Headers/Transform.h"
#include "Graphs/Headers/SceneGraphNode.h"
#include "Dynamics/Entities/Units/Headers/NPC.h"

namespace Divide {
    namespace AI {

static const D32 g_ATTACK_RADIUS = 5;
static const U32 g_myTeamContainer = 0;
static const U32 g_enemyTeamContainer = 1;
static const U32 g_flagContainer = 2;

PositionFact     WorkingMemory::_teamFlagPosition[2];
SmallCounterFact WorkingMemory::_teamCount[2];
SGNNodeFact      WorkingMemory::_flags[2];
SmallCounterFact WorkingMemory::_flagProtectors[2];
SmallCounterFact WorkingMemory::_flagRetrievers[2];
vec3<F32> WarSceneAISceneImpl::_initialFlagPositions[2];

WarSceneAISceneImpl::WarSceneAISceneImpl() : AISceneImpl(),
                                            _tickCount(0),
                                            _orderRequestTryCount(0),
                                            _visualSensorUpdateCounter(0),
                                            _deltaTime(0ULL),
                                            _visualSensor(nullptr),
                                            _audioSensor(nullptr)
{
}

WarSceneAISceneImpl::~WarSceneAISceneImpl()
{
    MemoryManager::DELETE_VECTOR(actionSetPtr());
}

void WarSceneAISceneImpl::registerAction(GOAPAction* const action) {
    WarSceneAction* const warAction = dynamic_cast<WarSceneAction*>(action);
    warAction->setParentAIScene(this);

    switch(warAction->actionType()) {
        case ACTION_APPROACH_FLAG : 
            AISceneImpl::registerAction(MemoryManager_NEW ApproachFlag(*warAction));
            return;
        case ACTION_CAPTURE_FLAG  : 
            AISceneImpl::registerAction(MemoryManager_NEW CaptureFlag(*warAction));
            return;
        case ACTION_RETURN_FLAG   : 
            AISceneImpl::registerAction(MemoryManager_NEW ReturnFlag(*warAction));
            return;
        case ACTION_RECOVER_FLAG  : 
            AISceneImpl::registerAction(MemoryManager_NEW RecoverFlag(*warAction));
            return;
		case ACTION_KILL_ENEMY    : 
            AISceneImpl::registerAction(MemoryManager_NEW KillEnemy(*warAction));
            return;
		case ACTION_RETURN_TO_BASE: 
            AISceneImpl::registerAction(MemoryManager_NEW ReturnHome(*warAction));
            return;
        case ACTION_PROTECT_FLAG_CARRIER : 
            AISceneImpl::registerAction(MemoryManager_NEW ProtectFlagCarrier(*warAction));
            return;
    };

    AISceneImpl::registerAction(MemoryManager_NEW WarSceneAction(*warAction));
}

void WarSceneAISceneImpl::init() {

    _visualSensor = dynamic_cast<VisualSensor*>(_entity->getSensor(VISUAL_SENSOR));
    //_audioSensor = dynamic_cast<AudioSensor*>(_entity->getSensor(AUDIO_SENSOR));
    DIVIDE_ASSERT(_visualSensor != nullptr, "WarSceneAISceneImpl error: No visual sensor found for current AI entity!");
    //DIVIDE_ASSERT(_audioSensor != nullptr, "WarSceneAISceneImpl error: No audio sensor found for current AI entity!");

    AITeam* currentTeam = _entity->getTeam();
    AITeam* enemyTeam = AIManager::getInstance().getTeamByID(currentTeam->getEnemyTeamID(0));
    const AITeam::TeamMap& teamAgents = currentTeam->getTeamMembers();
    const AITeam::TeamMap& enemyMembers = enemyTeam->getTeamMembers();

	for (const AITeam::TeamMap::value_type& member : teamAgents) {
        _visualSensor->followSceneGraphNode( g_myTeamContainer, member.second->getUnitRef()->getBoundNode() );
    }

	for (const AITeam::TeamMap::value_type& enemy : enemyMembers) {
        _visualSensor->followSceneGraphNode( g_enemyTeamContainer, enemy.second->getUnitRef()->getBoundNode() );
    }
        
    _visualSensor->followSceneGraphNode(g_flagContainer, WorkingMemory::_flags[0].value());
    _visualSensor->followSceneGraphNode(g_flagContainer, WorkingMemory::_flags[1].value());

    _initialFlagPositions[0].set(WorkingMemory::_flags[0].value()->getComponent<PhysicsComponent>()->getPosition());
    _initialFlagPositions[1].set(WorkingMemory::_flags[1].value()->getComponent<PhysicsComponent>()->getPosition());
}

void WarSceneAISceneImpl::requestOrders() {
    const vectorImpl<Order* >& orders = _entity->getTeam()->requestOrders();
    U8 priority[WarSceneOrder::ORDER_PLACEHOLDER];
    memset(priority, 0, sizeof(U8) * WarSceneOrder::ORDER_PLACEHOLDER);

    resetActiveGoals();
	printWorkingMemory();

    for (Order* const order : orders) {
        WarSceneOrder::WarOrder orderId = static_cast<WarSceneOrder::WarOrder>(dynamic_cast<WarSceneOrder*>(order)->getId());
        switch (orderId) {
            case WarSceneOrder::ORDER_FIND_ENEMY_FLAG : {
                if (!_workingMemory._hasEnemyFlag.value()  &&
				    !_workingMemory._enemyFlagNear.value() &&
					!_workingMemory._teamMateHasFlag.value()) {
                    priority[orderId] = 240;
                }
            } break;
            case WarSceneOrder::ORDER_CAPTURE_ENEMY_FLAG : {
				if (!_workingMemory._hasEnemyFlag.value() &&
					 _workingMemory._enemyFlagNear.value() && 
				    !_workingMemory._teamMateHasFlag.value()) {
                    priority[orderId] =  245;
                }
            } break;
            case WarSceneOrder::ORDER_RETURN_ENEMY_FLAG : {
                if (_workingMemory._hasEnemyFlag.value()) {
                    priority[orderId] = 250;
                }
            } break;
            case WarSceneOrder::ORDER_PROTECT_FLAG_CARRIER : {
                if (!_workingMemory._hasEnemyFlag.value() && 
					 _workingMemory._teamMateHasFlag.value()) {
                    priority[orderId] = WorkingMemory::_flagProtectors[_entity->getTeamID()].value() > 2 ? 125 : 220;
                }
            } break;
            case WarSceneOrder::ORDER_RETRIEVE_FLAG : {
                if (_workingMemory._enemyHasFlag.value() &&
				   !_workingMemory._hasEnemyFlag.value()) {
					priority[orderId] = WorkingMemory::_flagRetrievers[_entity->getTeamID()].value() > 1 ? 125 : 200;
					if (_workingMemory._friendlyFlagNear.value()) {
                        priority[orderId] += 2;
                    }
					if (_workingMemory._enemyFlagNear.value()) {
						priority[orderId] -= 2;
					}
                }
            } break;
        } 
    }

	for (GOAPGoal& goal : goalList()) {
        if (goal.getName().compare("Find enemy flag") == 0) {
			goal.relevancy(std::max(priority[WarSceneOrder::ORDER_FIND_ENEMY_FLAG], priority[WarSceneOrder::ORDER_PROTECT_FLAG_CARRIER]));
        }
        if (goal.getName().compare("Capture enemy flag") == 0) {
            goal.relevancy(priority[WarSceneOrder::ORDER_CAPTURE_ENEMY_FLAG]);
        }
        if (goal.getName().compare("Return enemy flag") == 0) {
            goal.relevancy(priority[WarSceneOrder::ORDER_RETURN_ENEMY_FLAG]);
        }
        if (goal.getName().compare("Retrieve flag") == 0) {
            goal.relevancy(priority[WarSceneOrder::ORDER_RETRIEVE_FLAG]);
        }
    }
	GOAPGoal* goal = findRelevantGoal();
	if (goal != nullptr) {
		D_PRINT_FN("Current goal for [%d ]: [ %s ]", _entity->getGUID(), goal->getName().c_str());
		if (replanGoal()) {
			D_PRINT_FN("The Plan for [ %d ] involves [ %d ] actions.", _entity->getGUID(), getActiveGoal()->getCurrentPlan().size());
			printPlan();
		}
		else {
			PRINT_FN("Invalid [ %d ]", _entity->getGUID());
		}
    }
}

bool WarSceneAISceneImpl::preAction(ActionType type, const WarSceneAction* warAction) {
    const AITeam* const currentTeam = _entity->getTeam();
    DIVIDE_ASSERT(currentTeam != nullptr, "WarScene error: INVALID TEAM FOR INPUT UPDATE");

    switch (type) {
        case ACTION_APPROACH_FLAG : {
			D_PRINT_FN("Starting approach flag action [ %d ]", _entity->getGUID());
			_entity->updateDestination(_workingMemory._teamFlagPosition[1 - currentTeam->getTeamID()].value());
        } break;
        case ACTION_CAPTURE_FLAG : {
			D_PRINT_FN("Starting capture flag action [ %d ]", _entity->getGUID());
        } break;
		case ACTION_RETURN_TO_BASE: {
			D_PRINT_FN("Starting return to base action [ %d ]", _entity->getGUID());
			_entity->updateDestination(_workingMemory._teamFlagPosition[currentTeam->getTeamID()].value());
		} break;
        case ACTION_RETURN_FLAG : {
			D_PRINT_FN("Starting return flag action [ %d ]", _entity->getGUID());
        } break;
		case ACTION_PROTECT_FLAG_CARRIER: {
			D_PRINT_FN("Starting protect flag action [ %d ]", _entity->getGUID());
			assert(_workingMemory._flagCarrier.value() != nullptr);
			_entity->updateDestination(_workingMemory._flagCarrier.value()->getPosition());
            U8 temp = WorkingMemory::_flagProtectors[currentTeam->getTeamID()].value() + 1;
			WorkingMemory::_flagProtectors[currentTeam->getTeamID()].value(temp);
		} break;
		case ACTION_RECOVER_FLAG: {
			D_PRINT_FN("Starting recover flag action [ %d ]", _entity->getGUID());
			assert(_workingMemory._enemyFlagCarrier.value() != nullptr);
			_entity->updateDestination(_workingMemory._enemyFlagCarrier.value()->getPosition());
            U8 temp = WorkingMemory::_flagRetrievers[currentTeam->getTeamID()].value() + 1;
			WorkingMemory::_flagRetrievers[currentTeam->getTeamID()].value(temp);
		} break;
        default : {
			D_PRINT_FN("Starting normal action [ %d ]", _entity->getGUID());
        } break;
    };
        
    return true;
}

bool WarSceneAISceneImpl::postAction(ActionType type, const WarSceneAction* warAction) {
    const AITeam* const currentTeam = _entity->getTeam();
    DIVIDE_ASSERT(currentTeam != nullptr, "WarScene error: INVALID TEAM FOR INPUT UPDATE");

    switch (type) {
        case ACTION_APPROACH_FLAG : {
			D_PRINT_FN("Approach flag action over [ %d ]", _entity->getGUID());
        } break;
        case ACTION_CAPTURE_FLAG : {
			D_PRINT_FN("Capture flag action over [ %d ]", _entity->getGUID());
			assert(!_workingMemory._hasEnemyFlag.value());
			assert(!_workingMemory._teamMateHasFlag.value());

            U8 flag = 1 - currentTeam->getTeamID();
            PhysicsComponent* pComp = _workingMemory._flags[flag].value()->getComponent<PhysicsComponent>();
            vec3<F32> prevScale(pComp->getScale());

            SceneGraphNode* targetNode = _entity->getUnitRef()->getBoundNode();
            _workingMemory._flags[flag].value()->attachToNode(targetNode);
            pComp->setPosition(vec3<F32>(0.0f, 0.75f, 1.5f));
            pComp->setScale(prevScale / targetNode->getComponent<PhysicsComponent>()->getScale());

			_workingMemory._hasEnemyFlag.value(true);
			for (const AITeam::TeamMap::value_type& member : currentTeam->getTeamMembers()) {
                _entity->sendMessage( member.second, HAVE_FLAG, _entity );
            }
			const AITeam* const enemyTeam = AIManager::getInstance().getTeamByID(currentTeam->getEnemyTeamID(0));
			for (const AITeam::TeamMap::value_type& enemy : enemyTeam->getTeamMembers()) {
                _entity->sendMessage( enemy.second, ENEMY_HAS_FLAG, _entity );
            }
        } break;
		case ACTION_RETURN_TO_BASE: {
			PRINT_FN("Return to base action over [ %d ]", _entity->getGUID());
		} break;

        case ACTION_RETURN_FLAG : {
			PRINT_FN("Return flag action over [ %d ]", _entity->getGUID());

            U8 flag = 1 - currentTeam->getTeamID();
            PhysicsComponent* pComp = _workingMemory._flags[flag].value()->getComponent<PhysicsComponent>();
            vec3<F32> prevScale(pComp->getScale());

            SceneGraphNode* targetNode = _workingMemory._flags[flag].value()->getParent();
            _workingMemory._flags[flag].value()->attachToRoot();
            pComp->setPosition(_initialFlagPositions[flag]);
            pComp->setScale(prevScale * targetNode->getComponent<PhysicsComponent>()->getScale());
        } break;
		case ACTION_PROTECT_FLAG_CARRIER: {
            U8 temp = WorkingMemory::_flagProtectors[currentTeam->getTeamID()].value() - 1;
			WorkingMemory::_flagProtectors[currentTeam->getTeamID()].value(temp);
		} break;
		case ACTION_RECOVER_FLAG: {
            U8 temp = WorkingMemory::_flagRetrievers[currentTeam->getTeamID()].value() - 1;
			WorkingMemory::_flagRetrievers[currentTeam->getTeamID()].value(temp);
		} break;
        default : {
			PRINT_FN("Normal action over [ %d ]", _entity->getGUID());
        } break;
    };

	PRINT_FN("   %s [ %d ]", warAction->name().c_str(), _entity->getGUID());
    for(GOAPAction::operationsIterator o = warAction->effects().begin(); o != warAction->effects().end(); o++) {
        performActionStep(o);
    }
    PRINT_F("\n");
    return advanceGoal();
}

bool WarSceneAISceneImpl::checkCurrentActionComplete(const GOAPAction* planStep) {
    assert(planStep != nullptr);
    const WarSceneAction& warAction = *dynamic_cast<const WarSceneAction*>(planStep);

	if (_workingMemory._teamMateHasFlag.value() && (warAction.actionType() == ACTION_APPROACH_FLAG || 
		                                            warAction.actionType() == ACTION_CAPTURE_FLAG ||
													warAction.actionType() == ACTION_RETURN_FLAG)) {
		invalidateCurrentPlan();
		return false;
	}

    const AITeam* const currentTeam = _entity->getTeam();
    DIVIDE_ASSERT(currentTeam != nullptr, "WarScene error: INVALID TEAM FOR INPUT UPDATE");
    const SceneGraphNode* const currentNode = _entity->getUnitRef()->getBoundNode();
    const SceneGraphNode* const enemyFlag = _workingMemory._flags[1 - currentTeam->getTeamID()].value();

    bool state = false;
    const BoundingBox& bb1 = currentNode->getBoundingBoxConst();
    switch (warAction.actionType()) {
        case ACTION_APPROACH_FLAG : {
            state = enemyFlag->getBoundingBoxConst().Collision(bb1);
			if (!state && _entity->destinationReached()) {
				_entity->updateDestination(_workingMemory._teamFlagPosition[1 - currentTeam->getTeamID()].value());
			}
        } break;
        case ACTION_CAPTURE_FLAG : {
            state = enemyFlag->getBoundingBoxConst().Collision(bb1);
			if (!state && _entity->destinationReached()) {
				_entity->updateDestination(_workingMemory._teamFlagPosition[1 - currentTeam->getTeamID()].value());
			}
        } break;
        case ACTION_RETURN_FLAG : {
            const SceneGraphNode* const ownFlag = _workingMemory._flags[currentTeam->getTeamID()].value();
            const BoundingBox& ownFlagBB = ownFlag->getBoundingBoxConst();
            // Our flag is in its original position and the 2 flags are touching
            const vec3<F32>& flagPos = ownFlag->getComponent<PhysicsComponent>()->getPosition();
            state = (enemyFlag->getBoundingBoxConst().Collision(ownFlagBB) && 
                     flagPos.distanceSquared(_initialFlagPositions[currentTeam->getTeamID()]) < g_ATTACK_RADIUS);
        } break;
		case ACTION_PROTECT_FLAG_CARRIER: {
			if (_entity->destinationReached()) {
				_entity->updateDestination(_workingMemory._flagCarrier.value()->getPosition(), true);
			}
		} break;
		case ACTION_RECOVER_FLAG: {
			if (_entity->destinationReached()) {
				_entity->updateDestination(_workingMemory._enemyFlagCarrier.value()->getPosition());
			}
		}break;
		case ACTION_RETURN_TO_BASE: {
			state = _entity->getPosition().distanceSquared(_initialFlagPositions[currentTeam->getTeamID()]) <
                    g_ATTACK_RADIUS * g_ATTACK_RADIUS;
			if (!state && _entity->destinationReached()) {
				_entity->updateDestination(_initialFlagPositions[currentTeam->getTeamID()]);
			}
		} break;
        default : {
			PRINT_FN("Normal action check [ %d ]", _entity->getGUID());
        } break;
    };
    if (state) {
        return warAction.postAction();
    }
    return state;
}

void WarSceneAISceneImpl::processMessage(AIEntity* sender, AIMsg msg, const cdiggins::any& msg_content) {
    switch(msg){
        case HAVE_FLAG : {
            _workingMemory._teamMateHasFlag.value(true);
            _workingMemory._flagCarrier.value(sender);
        } break;
        case ENEMY_HAS_FLAG: {
            _workingMemory._enemyHasFlag.value(true);
            _workingMemory._enemyFlagCarrier.value(sender);
			worldState().setVariable(GOAPFact(EnemyHasFlag), GOAPValue(true));
        } break;
    };

    if (msg == HAVE_FLAG || msg == ENEMY_HAS_FLAG) {
        invalidateCurrentPlan();
    }
}

void WarSceneAISceneImpl::updatePositions() {
	if (_workingMemory._flags[0].value() != nullptr && _workingMemory._flags[1].value() != nullptr) {
        _workingMemory._teamFlagPosition[0].value(_visualSensor->getNodePosition(g_flagContainer, 
                                                                                 _workingMemory._flags[0].value()->getGUID()));
        _workingMemory._teamFlagPosition[1].value(_visualSensor->getNodePosition(g_flagContainer, 
                                                                                 _workingMemory._flags[1].value()->getGUID()));

        const vec3<F32>& flag1Pos = _workingMemory._teamFlagPosition[1 - _entity->getTeamID()].value();
        const vec3<F32>& flag2Pos = _workingMemory._teamFlagPosition[1 - _entity->getTeamID()].value();
        F32 radiusSq = g_ATTACK_RADIUS * g_ATTACK_RADIUS;
        _workingMemory._enemyFlagNear.value(flag1Pos.distanceSquared(_entity->getPosition()) < radiusSq);
        _workingMemory._friendlyFlagNear.value(flag2Pos.distanceSquared(_entity->getPosition()) < radiusSq);
    }

    if (_workingMemory._currentTargetEntity.value()) {
        PhysicsComponent* pComp = _workingMemory._currentTargetEntity.value()->getComponent<PhysicsComponent>();
        _workingMemory._currentTargetPosition.value(pComp->getPosition());
    }
}

void WarSceneAISceneImpl::processInput(const U64 deltaTime) {
    if (!_entity) {
        return;
    }

    _deltaTime += deltaTime;
    
    if (_deltaTime > getUsToSec(1.5)) {//wait 1 and a half seconds at the destination
        _deltaTime = 0;
    }
}

void WarSceneAISceneImpl::processData(const U64 deltaTime) {
    if (!_entity) {
        return;
    }
    AIManager& aiMgr = AIManager::getInstance();

    if (!aiMgr.getNavMesh(_entity->getAgentRadiusCategory())) {
        return;
    }

    updatePositions();

    if (_workingMemory._staticDataUpdated) {
        if (!getActiveGoal()) {
            if (!goalList().empty() && _orderRequestTryCount < 3) {
                requestOrders();
                _orderRequestTryCount++;
            }
        } else {
            _orderRequestTryCount = 0;
            checkCurrentActionComplete(getActiveAction());
        }   
    }
}

void WarSceneAISceneImpl::update(const U64 deltaTime, NPC* unitRef) {
    U8 visualSensorUpdateFreq = 10;
    _visualSensorUpdateCounter = (_visualSensorUpdateCounter + 1) % (visualSensorUpdateFreq + 1);
    // Update sensor information
    if (_visualSensor && _visualSensorUpdateCounter == visualSensorUpdateFreq) {
        _visualSensor->update(deltaTime);
    }
    if (_audioSensor) {
        _audioSensor->update(deltaTime);
    }
    
    if (!_workingMemory._staticDataUpdated) {
        AITeam* team1 = AIManager::getInstance().getTeamByID(0);
        if (team1 != nullptr) {
            const AITeam::TeamMap& team1Members = team1->getTeamMembers();
            _workingMemory._teamCount[0].value(static_cast<U8>(team1Members.size()));
        }
        AITeam* team2 = AIManager::getInstance().getTeamByID(1);
        if (team2 != nullptr) {
            const AITeam::TeamMap& team2Members = team2->getTeamMembers();
            _workingMemory._teamCount[1].value(static_cast<U8>(team2Members.size()));
        }
        _workingMemory._staticDataUpdated = true;
    }
    
    if (!_workingMemory._currentTargetEntity.value()) {
        _workingMemory._currentTargetEntity.value(_visualSensor->getClosestNode(g_enemyTeamContainer));
    } 
}

bool WarSceneAISceneImpl::performAction(const GOAPAction* planStep) {
    if(planStep == nullptr) {
        return false;
    }
    return dynamic_cast<const WarSceneAction*>(planStep)->preAction();
}

bool WarSceneAISceneImpl::performActionStep(GOAPAction::operationsIterator step) {
    GOAPFact crtFact = step->first;
    GOAPValue newVal = step->second;
    GOAPValue oldVal = worldState().getVariable(crtFact);
    if (oldVal != newVal) {
		PRINT_FN("\t\t [%d] Changing \"%s\" from \"%s\" to \"%s\"", 
                 _entity->getGUID(), WarSceneFactName(crtFact), GOAPValueName(oldVal), GOAPValueName(newVal));
    }
    worldState().setVariable(crtFact, newVal);
    return true;
}

bool WarSceneAISceneImpl::printActionStats(const GOAPAction* planStep) const {
	PRINT_FN("Action [ %s ] [ %d ]", planStep->name().c_str(), _entity->getGUID());
	return true;
}

void WarSceneAISceneImpl::printWorkingMemory() const {
	PRINT_FN("--------------- Working memory state for [ %d ] BEGIN ----------------------------", _entity->getGUID());
	PRINT_FN("        Team Counts - 0: %d | 1: %d", _workingMemory._teamCount[0].value(),
                                                    _workingMemory._teamCount[1].value());
	PRINT_FN("        Current position: - [ %4.1f , %4.1f, %4.1f]", _entity->getPosition().x,
                                                                    _entity->getPosition().y,
                                                                    _entity->getPosition().z);
	PRINT_FN("        Flag Protectors - 0: %d | 1: %d", _workingMemory._flagProtectors[0].value(), 
                                                        _workingMemory._flagProtectors[1].value());
	PRINT_FN("        Flag Retrievers - 0: %d | 1: %d", _workingMemory._flagRetrievers[0].value(), 
                                                        _workingMemory._flagRetrievers[1].value());
	PRINT_FN("        Flag Positions - 0 : [ %4.1f , %4.1f, %4.1f] | 1 : [ %4.1f , %4.1f, %4.1f]",  
                                                                                     _workingMemory._teamFlagPosition[0].value().x,
																					 _workingMemory._teamFlagPosition[0].value().y,
																					 _workingMemory._teamFlagPosition[0].value().z,
																					 _workingMemory._teamFlagPosition[1].value().x,
																					 _workingMemory._teamFlagPosition[1].value().y,
																					 _workingMemory._teamFlagPosition[1].value().z);
	
	if (_workingMemory._flagCarrier.value()) {
		PRINT_FN("        Flag carrier : [ %d ] ", _workingMemory._flagCarrier.value()->getGUID());
	}
	if (_workingMemory._enemyFlagCarrier.value()) {
		PRINT_FN("        Enemy flag carrier : [ %d ] ", _workingMemory._enemyFlagCarrier.value()->getGUID());
	}
	PRINT_FN("        Health : [ %d ]", _workingMemory._health.value());
	if (_workingMemory._currentTargetEntity.value()) {
		PRINT_FN("        Current target : [ %d ] ", _workingMemory._currentTargetEntity.value()->getGUID());
	}
	PRINT_FN("        Current target position: - [ %4.1f , %4.1f, %4.1f]",  _workingMemory._currentTargetPosition.value().x,
																	_workingMemory._currentTargetPosition.value().y,
																	_workingMemory._currentTargetPosition.value().z);
	PRINT_FN("        Has enemy flag: [ %s ]", _workingMemory._hasEnemyFlag.value() ? "true" : "false");
	PRINT_FN("        Enemy has flag: [ %s ]", _workingMemory._enemyHasFlag.value() ? "true" : "false");
	PRINT_FN("        Teammate has flag: [ %s ]", _workingMemory._teamMateHasFlag.value() ? "true" : "false");
	PRINT_FN("        Enemy flag near: [ %s ]", _workingMemory._enemyFlagNear.value() ? "true" : "false");
	PRINT_FN("        Friendly flag near: [ %s ]", _workingMemory._friendlyFlagNear.value() ? "true" : "false");

	for (std::pair<GOAPFact, GOAPValue> var : worldStateConst().vars_){
		PRINT_FN("        World state fact [ %s ] : [ %s ]", WarSceneFactName(var.first), var.second ? "true" : "false");
	}
	PRINT_FN("--------------- Working memory state for [ %d ] END ----------------------------", _entity->getGUID());
}
    }; //namespace AI
}; //namespace Divide

Commits for Divide-Framework/trunk/Source Code/Scenes/WarScene/WarSceneAISceneImpl.cpp

Diff revisions: vs.
Revision Author Commited Message
331 Diff Diff IonutCava picture IonutCava Sat 06 Dec, 2014 20:53:45 +0000

[Ionut]
- Limited line length to 132 characters to improve readability and diff-comparisons
- Refactored memory allocation/deallocation functions
- Fixed a few compatibility issues with HashMap.h
- Fixed a bug in GPU Skinning shaders (cast a float to int)

326 Diff Diff IonutCava picture IonutCava Tue 30 Sep, 2014 21:11:32 +0000

[Ionut]
- Fixed more memory leaks
- Simplified Task interface and timing System
- Improved compatibility between Boost, STL and EASTL with random combinations of vectors, strings and maps
- Simplified Light class by removing the “slot” member
- Random optimizations

325 Diff Diff IonutCava picture IonutCava Wed 17 Sep, 2014 20:06:13 +0000

[Ionut]
- Reworked transform system:
— Parent transform chain system moved from Transform class to the PhysicsComponent
— PhysicsComponent now returns all transform values needed both global and local (still needs heavy optimization and caching)

- Reworked SceneGraph node management:
— Proper ref counting of SceneNodes and proper removing of resource (ResourceCache is now empty on destruction, as it should be)
— Removed parent transform tracking as that’s the PhysicsComponent’s responsibility
— Only nodes loaded via the ResourceCache are allowed to be added to the SceneGraph (added proper loaders for Impostors, Sky, etc)

- Optimized some of the math classes (mat4, mat3)

322 Diff Diff IonutCava picture IonutCava Sat 06 Sep, 2014 20:33:47 +0000

[Ionut]
- Refactored most of Boost related code to be C++11 based
— Boost is only used for ThreadPool, Mutex handling, XML parsing and networking (ASIO)
— Function binds, threads, regex, NonCopyable base, Hashing algorithms and more are now using C++11 libraries
- Replaced all FOR_EACH calls with standard, range, “for” calls

320 Diff Diff IonutCava picture IonutCava Sun 31 Aug, 2014 21:45:33 +0000

[Ionut]
- More AI work (entity captures flag and returns it to base)

318 Diff Diff IonutCava picture IonutCava Sat 30 Aug, 2014 17:35:53 +0000

[Ionut]
- Wrapped the entire code in a “Divide” namespace
- VertexBuffers now call “shrink_to_fit” on all internal data storage
- Improved some vector performance by preferring “emplace_back” instead of “push_back” + proepr usage of reserve / resize
- Wrapped OIS specific types and classes in Divide::Input namespace
- Added the messageBox.layout file (forgot it in the previous few commits)

317 Diff Diff IonutCava picture IonutCava Tue 26 Aug, 2014 22:08:06 +0000

[Ionut]
- More AI Work

316 Diff Diff IonutCava picture IonutCava Mon 25 Aug, 2014 22:04:03 +0000

[Ionut]
- Cleaned up AI classes
- Added basic Order <-> Goal system

315 Diff Diff IonutCava picture IonutCava Mon 25 Aug, 2014 15:23:33 +0000

[Ionut]
- Update ReCast to the latest version available on GitHub
- Improved nav mesh target point selection
- Added basic “go to enemy flag” logic for the WarScene teams

314 IonutCava picture IonutCava Sun 24 Aug, 2014 19:54:33 +0000

[Ionut]
- More AI work
- Added some needed audio dlls