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

#include <entt/entt.hpp>

#include <kurator/engine/Point.h>
#include <kurator/sim/ai.h>
#include <kurator/sim/components.h>
#include <kurator/sim/FloatingMovement.h>
#include <kurator/sim/HitPoints.h>
#include <kurator/sim/weapons.h>
#include <kurator/universe/ShipType.h>
#include <kurator/universe/TurretType.h>

#include "Spawner.h"


namespace kurator
{
namespace sim
{


using engine::Point;


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);
	registry.emplace<AIShip>(entity);
	registry.emplace<HitPoints>(entity, ship_type);
	return entity;
}


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


}  // namespace sim
}  // namespace kurator