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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
#include "maresciallo.h"
#include "assets.h"
#include "game.h"
#include "PID.h"
void initMaresciallo(Entity * entity, Game * game) {
entity->model = &game->assets.models[MARESCIALLO_ASSET];
entity->collisionModel = entityCreateCollisionModel(*entity->model);
entity->transformedCollisionModel = entityCreateCollisionModel(*entity->model);
setEntityRadius(entity);
// Allocate data.
entity->data = KF_MALLOC(sizeof(Maresciallo));
if (entity->data == NULL) {
ALLOCATION_ERROR;
return;
}
Maresciallo * data = (Maresciallo*)entity->data;
PIDConfig flyAwayPID = (PIDConfig){
.kP = 100, // 1.1
.kI = 0.0,
.kD = 0.0,
.angleMode = false,
.doClamp = true,
.min = 0.0,
.max = 210.0
};
data->flyAway = (EntityFlyToPointInfo){
.controller.speedPID = createPID(flyAwayPID),
.controlType = ENTITY_FLY_TO_POINT_PID,
.rotationSpeed = 0.0,
.applyRotation = true
};
}
void closeMaresciallo(Entity * entity) {
if (entity->data != NULL)
KF_FREE(entity->data);
entityFreeCollisionModel(entity->collisionModel);
entityFreeCollisionModel(entity->transformedCollisionModel);
}
void getAwayMaresciallo(Game * game, Entity * entity) {
Maresciallo * data = (Maresciallo*)entity->data;
Entity * player = getEntityFromWorld(game->world, 0);
// Get target.
Vector3 target = Vector3Subtract(entity->position, player->position);
target = Vector3Normalize(target);
target = Vector3Scale(target, MARESCIALLO_CIRCLE_AT_DIS);
target = Vector3Add(player->position, target);
// Fucking get away from the smelly player.
entityFlyToPoint(entity, target, &data->flyAway);
}
void circlePlayerMaresciallo(Game * game, Entity * entity) {
float t = GetFrameTime();
Maresciallo * data = (Maresciallo*)entity->data;
Entity * player = getEntityFromWorld(game->world, 0);
Quaternion toEntity = QuaternionFromVector3ToVector3(player->position, entity->position);
Quaternion next = toEntity;
next = QuaternionIdentity();
Vector3 target = Vector3Subtract(entity->position, player->position);
target = Vector3RotateByQuaternion(target, next);
entity->position = Vector3Add(player->position, target);
}
void updateMaresciallo(Game * game, Entity * entity) {
entityUpdateLastValues(entity);
Maresciallo * data = (Maresciallo*)entity->data;
Entity * player = getEntityFromWorld(game->world, 0);
// Fly away if to close to player.
if (Vector3Distance(entity->position, player->position) < MARESCIALLO_CIRCLE_AT_DIS - 1) {
getAwayMaresciallo(game, entity);
} else {
circlePlayerMaresciallo(game, entity);
}
entityCheckTransformedCollisionModel(entity);
}
void drawMaresciallo(Game * game, Entity * entity) {
entityDraw(entity);
}
|