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

#include <entt/entity/registry.hpp>

#include <kurator/sim/components.h>
#include <kurator/sim/Point.h>
#include <kurator/universe/ShipType.h>
#include <kurator/universe/TurretType.h>

#include "Spawner.h"


namespace kurator
{
namespace sim
{


Builder::Builder(entt::registry& _registry, Spawner& _spawner) :
	registry {_registry},
	spawner {_spawner}
{
}


entt::entity
Builder::operator()(const universe::ShipType& ship_type, const int team) const
{
	const auto entity = registry.create();
	registry.emplace<universe::ShipType>(entity, ship_type);
	registry.emplace<Team>(entity, team);
	registry.emplace<Transform>(entity, spawner.get(team));
	registry.emplace<FloatingMovement>(
		entity,
		ship_type.max_speed,
		ship_type.max_speed * 2.0,
		ship_type.max_speed * 3.0,
		100.0);
	registry.emplace<AIState>(entity, Point{0.0, 0.0});
	registry.emplace<HitPoints>(entity, ship_type.base_health_points);
	return entity;
}


entt::entity
Builder::operator()(const universe::TurretType& turret_type, const entt::entity& owner) const
{
	const auto entity = registry.create();
	registry.emplace<universe::TurretType>(entity, turret_type);
	registry.emplace<TurretControl>(entity, 0.0, owner);
	registry.emplace<Transform>(entity, Point{0.0, 0.0}, 0.0, owner);
	return entity;
}


}  // namespace sim
}  // namespace kurator