31 lines
1.0 KiB
C++
31 lines
1.0 KiB
C++
#include "AdvanceExecutor.h"
|
|
|
|
#include <QVector2D>
|
|
|
|
#include "AdvanceBehavior.h"
|
|
#include "BehaviorKind.h"
|
|
#include "EntityAdmin.h"
|
|
#include "FactionComponent.h"
|
|
#include "MovementIntentComponent.h"
|
|
#include "PositionComponent.h"
|
|
#include "SelectedBehaviorComponent.h"
|
|
#include "tracing.h"
|
|
|
|
void AdvanceExecutor::execute(EntityAdmin& admin)
|
|
{
|
|
TRACE();
|
|
admin.forEach<AdvanceBehavior, SelectedBehaviorComponent, PositionComponent,
|
|
FactionComponent, MovementIntentComponent>(
|
|
[](entt::entity /*e*/, const AdvanceBehavior& /*advance*/,
|
|
const SelectedBehaviorComponent& selected, const PositionComponent& pos,
|
|
const FactionComponent& faction, MovementIntentComponent& intent)
|
|
{
|
|
if (selected.winner != BehaviorKind::Advance) { return; }
|
|
|
|
const QVector2D target = faction.isEnemy
|
|
? QVector2D(-10000.0f, pos.value.y())
|
|
: QVector2D(pos.value.x() + 1000.0f, pos.value.y());
|
|
intent = MovementIntentComponent{true, target};
|
|
});
|
|
}
|