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

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

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


namespace kurator
{
namespace sim
{


void
load_scenario(State& ctx, const campaign::Scenario& scenario)
{
	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);
		}
	}
}


}  // namespace sim
}  // namespace kurator