summaryrefslogtreecommitdiff
path: root/sim/src/BaseBattle.cpp
blob: 916a9f81cc806a5af46ed5f169da38c3c23bf965 (plain)
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
#include "BaseBattle.h"

#include <algorithm>

#include <entt/entity/registry.hpp>
#include <entt/signal/dispatcher.hpp>

#include <kurator/engine/Context.h>
#include <kurator/campaign/Scenario.h>
#include <kurator/sim.h>
#include <kurator/sim/components.h>
#include <kurator/sim/FloatingMovement.h>
#include <kurator/sim/systems.h>
#include <kurator/sim/TurretControl.h>
#include <kurator/universe/UniqueIdentifier.h>

#include "Builder.h"
#include "RandomSpawner.h"


namespace kurator
{
namespace sim
{


BaseBattle::BaseBattle(const campaign::Scenario& scenario)
{
	load_scenario(state, scenario);
	manager.extend(state.registry);
}


engine::Context
BaseBattle::context()
{
	return state;
}


engine::ConstContext
BaseBattle::const_context() const
{
	return state;
}


void
BaseBattle::update(engine::Context& ctx)
{
	pick_random_targets();
	keep_at_range(ctx);
	FloatingMovement::update(ctx);
	TurretControl::update(ctx);
	kill_off_dead(ctx);
	manager.update(ctx);
}


void
BaseBattle::pick_random_targets()
{
	auto view = state.registry.view<Team, AIState>();
	for (auto&& [entity, team, ai] : view.each()) {
		if (!state.registry.valid(ai.target))
			ai.target = manager.random(team.id);
	}
}


}  // namespace sim
}  // namespace kurator