39 lines
1.3 KiB
C++
39 lines
1.3 KiB
C++
#include "DeliverScrapExecutor.h"
|
|
|
|
#include <QVector2D>
|
|
|
|
#include "BehaviorKind.h"
|
|
#include "Building.h"
|
|
#include "BuildingSystem.h"
|
|
#include "DeliverScrapBehavior.h"
|
|
#include "EntityAdmin.h"
|
|
#include "MovementIntentComponent.h"
|
|
#include "PositionComponent.h"
|
|
#include "SelectedBehaviorComponent.h"
|
|
#include "tracing.h"
|
|
|
|
void DeliverScrapExecutor::execute(EntityAdmin& admin, const BuildingSystem& buildings)
|
|
{
|
|
TRACE();
|
|
admin.forEach<DeliverScrapBehavior, SelectedBehaviorComponent, PositionComponent,
|
|
MovementIntentComponent>(
|
|
[&](entt::entity /*e*/, const DeliverScrapBehavior& deliver,
|
|
const SelectedBehaviorComponent& selected, const PositionComponent& pos,
|
|
MovementIntentComponent& intent)
|
|
{
|
|
if (selected.winner != BehaviorKind::DeliverScrap) { return; }
|
|
|
|
QVector2D dest = pos.value;
|
|
if (deliver.deliveryBay != kInvalidBuildingId)
|
|
{
|
|
const Building* bay = buildings.findBuilding(deliver.deliveryBay);
|
|
if (bay)
|
|
{
|
|
dest = QVector2D(bay->anchor.x() + bay->footprint.width() / 2.0f,
|
|
bay->anchor.y() + bay->footprint.height() / 2.0f);
|
|
}
|
|
}
|
|
intent = MovementIntentComponent{true, dest};
|
|
});
|
|
}
|