aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/system/AISystem.h
blob: d5f8a8ec8720fc6e37f1692139c59b7116a70912 (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
73
74
75
76
77
78
79
80
81
#pragma once

#include "api/AI.h"
#include "api/Rigidbody.h"

#include "System.h"
#include "api/Transform.h"
#include "types.h"

namespace crepe {

/**
 * \brief The AISystem is used to control the movement of entities using AI.
 *
 * The AISystem is used to control the movement of entities using AI. The AISystem can be used to
 * implement different behaviors such as seeking, fleeing, arriving, and path following.
 */
class AISystem : public System {
public:
	using System::System;

	//! Update the AI system
	void update() override;

private:
	/**
	 * \brief Calculate the total force to apply to the entity
	 *
	 * \param ai The AI component
	 * \param rigidbody The Rigidbody component
	 */
	vec2 calculate(AI & ai, const Rigidbody & rigidbody);
	/**
	 * \brief Accumulate the force to apply to the entity
	 *
	 * \param ai The AI component
	 * \param running_total The running total of the force
	 * \param force_to_add The force to add
	 * \return true if the force was added, false otherwise
	 */
	bool accumulate_force(const AI & ai, vec2 & running_total, vec2 & force_to_add);

	/**
	 * \brief Calculate the seek force
	 *
	 * \param ai The AI component
	 * \param rigidbody The Rigidbody component
	 * \param transform The Transform component
	 * \return The seek force
	 */
	vec2 seek(const AI & ai, const Rigidbody & rigidbody, const Transform & transform) const;
	/**
	 * \brief Calculate the flee force
	 *
	 * \param ai The AI component
	 * \param rigidbody The Rigidbody component
	 * \param transform The Transform component
	 * \return The flee force
	 */
	vec2 flee(const AI & ai, const Rigidbody & rigidbody, const Transform & transform) const;
	/**
	 * \brief Calculate the arrive force
	 *
	 * \param ai The AI component
	 * \param rigidbody The Rigidbody component
	 * \param transform The Transform component
	 * \return The arrive force
	 */
	vec2 arrive(const AI & ai, const Rigidbody & rigidbody, const Transform & transform) const;
	/**
	 * \brief Calculate the path follow force
	 *
	 * \param ai The AI component
	 * \param rigidbody The Rigidbody component
	 * \param transform The Transform component
	 * \return The path follow force
	 */
	vec2 path_follow(AI & ai, const Rigidbody & rigidbody, const Transform & transform);
};

} // namespace crepe