summaryrefslogtreecommitdiff
path: root/sim/src/sim.cpp
blob: 4cb74677a5f9ed0ede717a11885a69a8d71ffcf7 (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
#include <kurator/sim.h>

#include <kurator/campaign/Scenario.h>
#include <kurator/sim/components.h>
#include <kurator/sim/State.h>
#include <kurator/sim/System.h>
#include <kurator/universe/UniqueIdentifier.h>

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


namespace kurator
{
namespace sim
{


State
load_scenario(const campaign::Scenario& scenario)
{
	State ctx {};
	RandomSpawner spawner {scenario.last_team(), scenario.radius, 0.1};
	Builder build {ctx.registry, spawner};
	for (const auto& ship : scenario.ships) {
		const auto entity = build(ship.loadout.type, ship.team);
		ctx.registry.emplace<universe::UniqueIdentifier>(entity, ship.identifier);
		auto& state = ctx.registry.get<AIState>(entity);
		for (const auto& turret_type : ship.loadout.turrets) {
			build(turret_type, entity);
			state.keep_at_range = std::min(state.keep_at_range, turret_type.optimal_range);
		}
	}
	return ctx;
}


System
base_simulation_systems(State& ctx)
{
	return BaseSimulation{ctx};
}


}  // namespace sim
}  // namespace kurator