ScummVM API documentation
ai_pattern.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef SCUMM_HE_MOONBASE_AI_PATTERN_H
23#define SCUMM_HE_MOONBASE_AI_PATTERN_H
24
25namespace Scumm {
26
27const int NO_PATTERN = 0;
28const int PATTERN_FOUND = 1;
29
31private:
32 int _sourceHub;
33 int _unit;
34 int _power;
35 int _angle;
36
37public:
39 _sourceHub = 0;
40 _unit = 0;
41 _power = 0;
42 _angle = 0;
43 }
44
45 patternInstance(int sh, int unit, int power, int angle) {
46 setSourceHub(sh);
47 setUnit(unit);
48 setPower(power);
49 setAngle(angle);
50 }
51
52 void setSourceHub(int sh) { _sourceHub = sh; }
53 void setUnit(int unit) { _unit = unit; }
54
55 void setPower(int power) {
56 if (power < 300)
57 _power = 1;
58 else if (power < 480)
59 _power = 2;
60 else
61 _power = 3;
62 }
63
64 void setAngle(int angle) {
65 int tempAngle = angle % 360;
66
67 if ((tempAngle >= 0) && (tempAngle < 90))
68 _angle = 1;
69
70 if ((tempAngle >= 90) && (tempAngle < 180))
71 _angle = 2;
72
73 if ((tempAngle >= 180) && (tempAngle < 270))
74 _angle = 3;
75
76 if ((tempAngle >= 270))
77 _angle = 4;
78 }
79
80 int getSourceHub() const { return _sourceHub; }
81 int getUnit() const { return _unit; }
82 int getPowerIndex() const { return _power; }
83 int getAngleIndex() const { return _angle; }
84
85 static int comparePatterns(patternInstance *p1, patternInstance *p2) {
86 if (p1->getSourceHub() != p2->getSourceHub())
87 return 0;
88
89 if (p1->getUnit() != p2->getUnit())
90 return 0;
91
92 if (p1->getUnit() == -999)
93 return 0;
94
95 int temp = abs(p1->getPowerIndex() - p2->getPowerIndex());
96
97 if (temp > 1)
98 return 0;
99
100 temp = abs(p1->getAngleIndex() - p2->getAngleIndex());
101
102 if (temp > 1 && temp < 3)
103 return 0;
104
105 return 1;
106 }
107};
108
110private:
111 patternInstance *theList[10];
112 int listIndex;
113
114public:
115 patternList() {
116 for (int i = 0; i < 10; i++) {
117 theList[i] = new patternInstance();
118 }
119
120 listIndex = 0;
121 }
122 ~patternList() {
123 for (int i = 0; i < 10; i++) {
124 delete theList[i];
125 }
126 }
127
128 void addPattern(int sh, int unit, int power, int angle) {
129 theList[listIndex]->setSourceHub(sh);
130 theList[listIndex]->setUnit(unit);
131 theList[listIndex]->setPower(power);
132 theList[listIndex]->setAngle(angle);
133
134 listIndex++;
135
136 if (listIndex > 9)
137 listIndex = 0;
138 }
139
140 int evaluatePattern(int sh, int unit, int power, int angle) {
141 patternInstance *patternToMatch = new patternInstance(sh, unit, power, angle);
142 int matchCount = 0;
143
144 for (int i = 0; i < 9; i++) {
145 if (patternInstance::comparePatterns(theList[i], patternToMatch)) {
146 matchCount++;
147 }
148 }
149
150 delete patternToMatch;
151
152 if (matchCount > 2)
153 return PATTERN_FOUND;
154
155 return NO_PATTERN;
156 }
157};
158
159} // End of namespace Scumm
160
161#endif
Definition: ai_pattern.h:30
Definition: ai_pattern.h:109
Definition: actor.h:30