-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEngine_AIs.cpp
132 lines (118 loc) · 2.63 KB
/
Engine_AIs.cpp
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include "stdafx.h"
#include "Map.h"
#include <iostream>
#include "Constants.h"
#include "Player.h"
#include "Enumerations.h"
#include "GeneralFunctions.h"
#include "Enemy.h"
#include "Engine.h"
void Engine::EliteAI(float ElapsedTime, EnemyObject &enemy, Player &player)
{
float playerDistance = DistanceOf(enemy.GetPosition(), player.GetPosition());
float playerAngle = AngleOf(enemy.GetPosition(), player.GetPosition());
//Print("Vision Angle: " + StringConvert(enemy.flo_VisionAngle));
//Print("Player Angle: " + StringConvert(playerAngle));
//Print("Player Distance: " + StringConvert(playerDistance));
// Assign AI State
if (player.sta_Current.CurrentState == CS_DEAD)
{
enemy.ais_CurrentState = PATROL;
}
else
{
if (enemy.CheckLowHealth() == true)
{
enemy.ais_CurrentState = FLEE;
}
else if (enemy.CheckLOS(playerAngle, playerDistance) == true)
{
if (CheckWalls(enemy, player) == true)
{
if (enemy.CheckRange(playerDistance) == true)
{
enemy.ais_CurrentState = ATTACK;
}
else
{
enemy.ais_CurrentState = CHASE;
}
}
}
else
{
enemy.ais_CurrentState = PATROL;
}
}
// Execute Enemy Action
switch (enemy.ais_CurrentState)
{
case FLEE:
Flee(ElapsedTime, enemy, playerAngle);
//std::cout << "Flee" << std::endl;
break;
case ATTACK:
AttackPlayer(ElapsedTime, enemy, enemy.att_Stats.Attack[0], player);
//std::cout << "Attack" << std::endl;
break;
case CHASE:
Chase(ElapsedTime, enemy, playerAngle);
//std::cout << "Chase" << std::endl;
break;
case PATROL:
//std::cout << "Patrol" << std::endl;
sf::Vector2f point1;
point1.x = X_64(20);
point1.y = X_64(19);
sf::Vector2f point2;
point2.x = X_64(5);
point2.y = X_64(19);
Patrol(ElapsedTime, enemy, point1, point2);
break;
}
}
void Engine::GruntAI(float ElapsedTime, EnemyObject &enemy, Player player)
{
// Assign AI State
if (enemy.CheckLowHealth() == true)
{
enemy.ais_CurrentState = FLEE;
}
else if (enemy.CheckLOS(0,0) == true)
{
if (enemy.CheckRange(0) == true)
{
enemy.ais_CurrentState = ATTACK;
}
else
{
enemy.ais_CurrentState = CHASE;
}
}
else
{
enemy.ais_CurrentState = PATROL;
}
// Execute Enemy Action
switch (enemy.ais_CurrentState)
{
case FLEE:
std::cout << "ERROR: FLEEING" << std::endl;
break;
case ATTACK:
std::cout << "ERROR: ATTACKING" << std::endl;
break;
case CHASE:
std::cout << "ERROR: CHASEING" << std::endl;
break;
case PATROL:
sf::Vector2f point1;
point1.x = X_64(20);
point1.y = X_64(19);
sf::Vector2f point2;
point2.x = X_64(5);
point2.y = X_64(19);
//Patrol(ElapsedTime, enemy, point1, point2);
break;
}
}