author | unc0rr |
Thu, 07 Aug 2008 07:21:18 +0000 | |
changeset 1158 | d03d12ef8971 |
parent 1141 | 44d4d6aaecb5 |
child 1352 | 405ad07cf875 |
permissions | -rw-r--r-- |
71 | 1 |
(* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
883 | 3 |
* Copyright (c) 2005-2008 Andrey Korotaev <unC0Rr@gmail.com> |
71 | 4 |
* |
183 | 5 |
* This program is free software; you can redistribute it and/or modify |
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
71 | 8 |
* |
183 | 9 |
* This program is distributed in the hope that it will be useful, |
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
71 | 13 |
* |
183 | 14 |
* You should have received a copy of the GNU General Public License |
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
71 | 17 |
*) |
18 |
||
4 | 19 |
unit uAIMisc; |
20 |
interface |
|
351 | 21 |
uses SDLh, uConsts, uGears, uFloat; |
80 | 22 |
{$INCLUDE options.inc} |
369 | 23 |
|
64 | 24 |
type TTarget = record |
25 |
Point: TPoint; |
|
371 | 26 |
Score: LongInt; |
64 | 27 |
end; |
28 |
TTargets = record |
|
29 |
Count: Longword; |
|
30 |
ar: array[0..cMaxHHIndex*5] of TTarget; |
|
4 | 31 |
end; |
80 | 32 |
TJumpType = (jmpNone, jmpHJump, jmpLJump); |
75 | 33 |
TGoInfo = record |
34 |
Ticks: Longword; |
|
80 | 35 |
FallPix: Longword; |
36 |
JumpType: TJumpType; |
|
75 | 37 |
end; |
64 | 38 |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
39 |
procedure FillTargets; |
70 | 40 |
procedure FillBonuses(isAfterAttack: boolean); |
371 | 41 |
procedure AwareOfExplosion(x, y, r: LongInt); |
42 |
function RatePlace(Gear: PGear): LongInt; |
|
43 |
function TestColl(x, y, r: LongInt): boolean; |
|
44 |
function RateExplosion(Me: PGear; x, y, r: LongInt): LongInt; |
|
45 |
function RateShove(Me: PGear; x, y, r, power: LongInt): LongInt; |
|
509 | 46 |
function RateShotgun(Me: PGear; x, y: LongInt): LongInt; |
369 | 47 |
function HHGo(Gear, AltGear: PGear; var GoInfo: TGoInfo): boolean; |
371 | 48 |
function AIrndSign(num: LongInt): LongInt; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
49 |
|
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
50 |
var ThinkingHH: PGear; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
51 |
Targets: TTargets; |
921
8dd71d960cbc
If there's more hedgehogs in AI's team than in others, then it will be less afraid to give damage to friend hedgehog
unc0rr
parents:
883
diff
changeset
|
52 |
|
4 | 53 |
implementation |
922 | 54 |
uses uTeams, uMisc, uLand, uCollisions; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
55 |
const KillScore = 200; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
56 |
MAXBONUS = 1024; |
1001 | 57 |
friendlyfactor: LongInt = 300; |
369 | 58 |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
59 |
type TBonus = record |
371 | 60 |
X, Y: LongInt; |
61 |
Radius: LongInt; |
|
62 |
Score: LongInt; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
63 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
64 |
var bonuses: record |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
65 |
Count: Longword; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
66 |
ar: array[0..Pred(MAXBONUS)] of TBonus; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
67 |
end; |
71 | 68 |
KnownExplosion: record |
371 | 69 |
X, Y, Radius: LongInt |
71 | 70 |
end = (X: 0; Y: 0; Radius: 0); |
4 | 71 |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
72 |
procedure FillTargets; |
547 | 73 |
var i, t: Longword; |
921
8dd71d960cbc
If there's more hedgehogs in AI's team than in others, then it will be less afraid to give damage to friend hedgehog
unc0rr
parents:
883
diff
changeset
|
74 |
f, e: Longword; |
4 | 75 |
begin |
76 |
Targets.Count:= 0; |
|
921
8dd71d960cbc
If there's more hedgehogs in AI's team than in others, then it will be less afraid to give damage to friend hedgehog
unc0rr
parents:
883
diff
changeset
|
77 |
f:= 0; |
8dd71d960cbc
If there's more hedgehogs in AI's team than in others, then it will be less afraid to give damage to friend hedgehog
unc0rr
parents:
883
diff
changeset
|
78 |
e:= 0; |
547 | 79 |
for t:= 0 to Pred(TeamsCount) do |
921
8dd71d960cbc
If there's more hedgehogs in AI's team than in others, then it will be less afraid to give damage to friend hedgehog
unc0rr
parents:
883
diff
changeset
|
80 |
with TeamsArray[t]^ do |
8dd71d960cbc
If there's more hedgehogs in AI's team than in others, then it will be less afraid to give damage to friend hedgehog
unc0rr
parents:
883
diff
changeset
|
81 |
begin |
8dd71d960cbc
If there's more hedgehogs in AI's team than in others, then it will be less afraid to give damage to friend hedgehog
unc0rr
parents:
883
diff
changeset
|
82 |
for i:= 0 to cMaxHHIndex do |
8dd71d960cbc
If there's more hedgehogs in AI's team than in others, then it will be less afraid to give damage to friend hedgehog
unc0rr
parents:
883
diff
changeset
|
83 |
if (Hedgehogs[i].Gear <> nil) |
8dd71d960cbc
If there's more hedgehogs in AI's team than in others, then it will be less afraid to give damage to friend hedgehog
unc0rr
parents:
883
diff
changeset
|
84 |
and (Hedgehogs[i].Gear <> ThinkingHH) then |
8dd71d960cbc
If there's more hedgehogs in AI's team than in others, then it will be less afraid to give damage to friend hedgehog
unc0rr
parents:
883
diff
changeset
|
85 |
begin |
8dd71d960cbc
If there's more hedgehogs in AI's team than in others, then it will be less afraid to give damage to friend hedgehog
unc0rr
parents:
883
diff
changeset
|
86 |
with Targets.ar[Targets.Count], Hedgehogs[i] do |
8dd71d960cbc
If there's more hedgehogs in AI's team than in others, then it will be less afraid to give damage to friend hedgehog
unc0rr
parents:
883
diff
changeset
|
87 |
begin |
8dd71d960cbc
If there's more hedgehogs in AI's team than in others, then it will be less afraid to give damage to friend hedgehog
unc0rr
parents:
883
diff
changeset
|
88 |
Point.X:= hwRound(Gear^.X); |
8dd71d960cbc
If there's more hedgehogs in AI's team than in others, then it will be less afraid to give damage to friend hedgehog
unc0rr
parents:
883
diff
changeset
|
89 |
Point.Y:= hwRound(Gear^.Y); |
8dd71d960cbc
If there's more hedgehogs in AI's team than in others, then it will be less afraid to give damage to friend hedgehog
unc0rr
parents:
883
diff
changeset
|
90 |
if Clan <> CurrentTeam^.Clan then |
8dd71d960cbc
If there's more hedgehogs in AI's team than in others, then it will be less afraid to give damage to friend hedgehog
unc0rr
parents:
883
diff
changeset
|
91 |
begin |
8dd71d960cbc
If there's more hedgehogs in AI's team than in others, then it will be less afraid to give damage to friend hedgehog
unc0rr
parents:
883
diff
changeset
|
92 |
Score:= Gear^.Health; |
8dd71d960cbc
If there's more hedgehogs in AI's team than in others, then it will be less afraid to give damage to friend hedgehog
unc0rr
parents:
883
diff
changeset
|
93 |
inc(e) |
8dd71d960cbc
If there's more hedgehogs in AI's team than in others, then it will be less afraid to give damage to friend hedgehog
unc0rr
parents:
883
diff
changeset
|
94 |
end else |
8dd71d960cbc
If there's more hedgehogs in AI's team than in others, then it will be less afraid to give damage to friend hedgehog
unc0rr
parents:
883
diff
changeset
|
95 |
begin |
8dd71d960cbc
If there's more hedgehogs in AI's team than in others, then it will be less afraid to give damage to friend hedgehog
unc0rr
parents:
883
diff
changeset
|
96 |
Score:= -Gear^.Health; |
8dd71d960cbc
If there's more hedgehogs in AI's team than in others, then it will be less afraid to give damage to friend hedgehog
unc0rr
parents:
883
diff
changeset
|
97 |
inc(f) |
8dd71d960cbc
If there's more hedgehogs in AI's team than in others, then it will be less afraid to give damage to friend hedgehog
unc0rr
parents:
883
diff
changeset
|
98 |
end |
8dd71d960cbc
If there's more hedgehogs in AI's team than in others, then it will be less afraid to give damage to friend hedgehog
unc0rr
parents:
883
diff
changeset
|
99 |
end; |
8dd71d960cbc
If there's more hedgehogs in AI's team than in others, then it will be less afraid to give damage to friend hedgehog
unc0rr
parents:
883
diff
changeset
|
100 |
inc(Targets.Count) |
8dd71d960cbc
If there's more hedgehogs in AI's team than in others, then it will be less afraid to give damage to friend hedgehog
unc0rr
parents:
883
diff
changeset
|
101 |
end; |
8dd71d960cbc
If there's more hedgehogs in AI's team than in others, then it will be less afraid to give damage to friend hedgehog
unc0rr
parents:
883
diff
changeset
|
102 |
end; |
8dd71d960cbc
If there's more hedgehogs in AI's team than in others, then it will be less afraid to give damage to friend hedgehog
unc0rr
parents:
883
diff
changeset
|
103 |
|
8dd71d960cbc
If there's more hedgehogs in AI's team than in others, then it will be less afraid to give damage to friend hedgehog
unc0rr
parents:
883
diff
changeset
|
104 |
if e > f then friendlyfactor:= 300 + (e - f) * 30 |
922 | 105 |
else friendlyfactor:= max(30, 300 - f * 80 div e) |
4 | 106 |
end; |
107 |
||
70 | 108 |
procedure FillBonuses(isAfterAttack: boolean); |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
109 |
var Gear: PGear; |
549 | 110 |
MyClan: PClan; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
111 |
|
371 | 112 |
procedure AddBonus(x, y: LongInt; r: Longword; s: LongInt); |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
113 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
114 |
bonuses.ar[bonuses.Count].x:= x; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
115 |
bonuses.ar[bonuses.Count].y:= y; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
116 |
bonuses.ar[bonuses.Count].Radius:= r; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
117 |
bonuses.ar[bonuses.Count].Score:= s; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
118 |
inc(bonuses.Count); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
119 |
TryDo(bonuses.Count <= MAXBONUS, 'Bonuses overflow', true) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
120 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
121 |
|
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
122 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
123 |
bonuses.Count:= 0; |
549 | 124 |
MyClan:= PHedgehog(ThinkingHH^.Hedgehog)^.Team^.Clan; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
125 |
Gear:= GearsList; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
126 |
while Gear <> nil do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
127 |
begin |
369 | 128 |
case Gear^.Kind of |
129 |
gtCase: AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 33, 25); |
|
130 |
gtMine: if (Gear^.State and gstAttacking) = 0 then AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 50, -50) |
|
131 |
else AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 100, -50); // mine is on |
|
132 |
gtDynamite: AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 150, -75); |
|
70 | 133 |
gtHedgehog: begin |
369 | 134 |
if Gear^.Damage >= Gear^.Health then AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 60, -25) else |
135 |
if isAfterAttack and (ThinkingHH^.Hedgehog <> Gear^.Hedgehog) then |
|
549 | 136 |
if (MyClan = PHedgehog(Gear^.Hedgehog)^.Team^.Clan) then AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 150, -3) // hedgehog-friend |
137 |
else AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 100, 3) |
|
70 | 138 |
end; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
139 |
end; |
369 | 140 |
Gear:= Gear^.NextGear |
71 | 141 |
end; |
142 |
if isAfterAttack and (KnownExplosion.Radius > 0) then |
|
143 |
with KnownExplosion do |
|
74 | 144 |
AddBonus(X, Y, Radius + 10, -Radius); |
71 | 145 |
end; |
146 |
||
371 | 147 |
procedure AwareOfExplosion(x, y, r: LongInt); |
71 | 148 |
begin |
149 |
KnownExplosion.X:= x; |
|
150 |
KnownExplosion.Y:= y; |
|
151 |
KnownExplosion.Radius:= r |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
152 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
153 |
|
371 | 154 |
function RatePlace(Gear: PGear): LongInt; |
155 |
var i, r: LongInt; |
|
156 |
Result: LongInt; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
157 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
158 |
Result:= 0; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
159 |
for i:= 0 to Pred(bonuses.Count) do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
160 |
with bonuses.ar[i] do |
70 | 161 |
begin |
498 | 162 |
r:= hwRound(Distance(Gear^.X - int2hwFloat(X), Gear^.Y - int2hwFloat(Y))); |
70 | 163 |
if r < Radius then |
164 |
inc(Result, Score * (Radius - r)) |
|
165 |
end; |
|
369 | 166 |
RatePlace:= Result |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
167 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
168 |
|
371 | 169 |
function TestColl(x, y, r: LongInt): boolean; |
369 | 170 |
var b: boolean; |
4 | 171 |
begin |
369 | 172 |
b:= (((x-r) and $FFFFF800) = 0)and(((y-r) and $FFFFFC00) = 0) and (Land[y-r, x-r] <> 0); |
173 |
if b then exit(true); |
|
174 |
b:=(((x-r) and $FFFFF800) = 0)and(((y+r) and $FFFFFC00) = 0) and (Land[y+r, x-r] <> 0); |
|
175 |
if b then exit(true); |
|
176 |
b:=(((x+r) and $FFFFF800) = 0)and(((y-r) and $FFFFFC00) = 0) and (Land[y-r, x+r] <> 0); |
|
177 |
if b then exit(true); |
|
178 |
TestColl:=(((x+r) and $FFFFF800) = 0)and(((y+r) and $FFFFFC00) = 0) and (Land[y+r, x+r] <> 0) |
|
4 | 179 |
end; |
180 |
||
371 | 181 |
function RateExplosion(Me: PGear; x, y, r: LongInt): LongInt; |
182 |
var i, dmg, Result: LongInt; |
|
4 | 183 |
begin |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
184 |
Result:= 0; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
185 |
// add our virtual position |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
186 |
with Targets.ar[Targets.Count] do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
187 |
begin |
369 | 188 |
Point.x:= hwRound(Me^.X); |
189 |
Point.y:= hwRound(Me^.Y); |
|
190 |
Score:= - ThinkingHH^.Health |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
191 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
192 |
// rate explosion |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
193 |
for i:= 0 to Targets.Count do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
194 |
with Targets.ar[i] do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
195 |
begin |
1141 | 196 |
dmg:= r + cHHRadius div 2 - hwRound(DistanceI(Point.x - x, Point.y - y)); |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
197 |
if dmg > 0 then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
198 |
begin |
1141 | 199 |
dmg:= min(dmg div 2, r); |
509 | 200 |
if dmg >= abs(Score) then |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
201 |
if Score > 0 then inc(Result, KillScore) |
921
8dd71d960cbc
If there's more hedgehogs in AI's team than in others, then it will be less afraid to give damage to friend hedgehog
unc0rr
parents:
883
diff
changeset
|
202 |
else dec(Result, KillScore * friendlyfactor div 100) |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
203 |
else |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
204 |
if Score > 0 then inc(Result, dmg) |
921
8dd71d960cbc
If there's more hedgehogs in AI's team than in others, then it will be less afraid to give damage to friend hedgehog
unc0rr
parents:
883
diff
changeset
|
205 |
else dec(Result, dmg * friendlyfactor div 100) |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
206 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
207 |
end; |
369 | 208 |
RateExplosion:= Result * 1024 |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
209 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
210 |
|
371 | 211 |
function RateShove(Me: PGear; x, y, r, power: LongInt): LongInt; |
212 |
var i, dmg, Result: LongInt; |
|
79 | 213 |
begin |
214 |
Result:= 0; |
|
433 | 215 |
for i:= 0 to Pred(Targets.Count) do |
79 | 216 |
with Targets.ar[i] do |
217 |
begin |
|
498 | 218 |
dmg:= r - hwRound(DistanceI(Point.x - x, Point.y - y)); |
79 | 219 |
if dmg > 0 then |
220 |
begin |
|
509 | 221 |
if power >= abs(Score) then |
79 | 222 |
if Score > 0 then inc(Result, KillScore) |
921
8dd71d960cbc
If there's more hedgehogs in AI's team than in others, then it will be less afraid to give damage to friend hedgehog
unc0rr
parents:
883
diff
changeset
|
223 |
else dec(Result, KillScore * friendlyfactor div 100) |
79 | 224 |
else |
225 |
if Score > 0 then inc(Result, power) |
|
921
8dd71d960cbc
If there's more hedgehogs in AI's team than in others, then it will be less afraid to give damage to friend hedgehog
unc0rr
parents:
883
diff
changeset
|
226 |
else dec(Result, power * friendlyfactor div 100) |
79 | 227 |
end; |
228 |
end; |
|
369 | 229 |
RateShove:= Result * 1024 |
79 | 230 |
end; |
231 |
||
509 | 232 |
function RateShotgun(Me: PGear; x, y: LongInt): LongInt; |
233 |
var i, dmg, Result: LongInt; |
|
234 |
begin |
|
235 |
Result:= 0; |
|
236 |
// add our virtual position |
|
237 |
with Targets.ar[Targets.Count] do |
|
238 |
begin |
|
239 |
Point.x:= hwRound(Me^.X); |
|
240 |
Point.y:= hwRound(Me^.Y); |
|
241 |
Score:= - ThinkingHH^.Health |
|
242 |
end; |
|
243 |
// rate shot |
|
244 |
for i:= 0 to Targets.Count do |
|
245 |
with Targets.ar[i] do |
|
246 |
begin |
|
247 |
dmg:= min(cHHRadius + cShotgunRadius - hwRound(DistanceI(Point.x - x, Point.y - y)), 25); |
|
248 |
if dmg > 0 then |
|
249 |
begin |
|
250 |
if dmg >= abs(Score) then |
|
251 |
if Score > 0 then inc(Result, KillScore) |
|
921
8dd71d960cbc
If there's more hedgehogs in AI's team than in others, then it will be less afraid to give damage to friend hedgehog
unc0rr
parents:
883
diff
changeset
|
252 |
else dec(Result, KillScore * friendlyfactor div 100) |
509 | 253 |
else |
254 |
if Score > 0 then inc(Result, dmg) |
|
921
8dd71d960cbc
If there's more hedgehogs in AI's team than in others, then it will be less afraid to give damage to friend hedgehog
unc0rr
parents:
883
diff
changeset
|
255 |
else dec(Result, dmg * friendlyfactor div 100) |
509 | 256 |
end; |
257 |
end; |
|
258 |
RateShotgun:= Result * 1024 |
|
259 |
end; |
|
260 |
||
369 | 261 |
function HHJump(Gear: PGear; JumpType: TJumpType; var GoInfo: TGoInfo): boolean; |
371 | 262 |
var bX, bY: LongInt; |
369 | 263 |
Result: boolean; |
80 | 264 |
begin |
265 |
Result:= false; |
|
266 |
GoInfo.Ticks:= 0; |
|
267 |
GoInfo.FallPix:= 0; |
|
268 |
GoInfo.JumpType:= jmpNone; |
|
369 | 269 |
bX:= hwRound(Gear^.X); |
270 |
bY:= hwRound(Gear^.Y); |
|
80 | 271 |
case JumpType of |
369 | 272 |
jmpNone: exit(Result); |
80 | 273 |
jmpHJump: if not TestCollisionYwithGear(Gear, -1) then |
274 |
begin |
|
369 | 275 |
Gear^.dY:= -_0_2; |
276 |
SetLittle(Gear^.dX); |
|
542 | 277 |
Gear^.State:= Gear^.State or gstMoving or gstHHJumping; |
369 | 278 |
end else exit(Result); |
80 | 279 |
jmpLJump: begin |
280 |
if not TestCollisionYwithGear(Gear, -1) then |
|
498 | 281 |
if not TestCollisionXwithXYShift(Gear, _0, -2, hwSign(Gear^.dX)) then Gear^.Y:= Gear^.Y - int2hwFloat(2) else |
282 |
if not TestCollisionXwithXYShift(Gear, _0, -1, hwSign(Gear^.dX)) then Gear^.Y:= Gear^.Y - _1; |
|
369 | 283 |
if not (TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) |
80 | 284 |
or TestCollisionYwithGear(Gear, -1)) then |
285 |
begin |
|
433 | 286 |
Gear^.dY:= -_0_15; |
498 | 287 |
Gear^.dX:= SignAs(_0_15, Gear^.dX); |
542 | 288 |
Gear^.State:= Gear^.State or gstMoving or gstHHJumping |
369 | 289 |
end else exit(Result) |
80 | 290 |
end |
291 |
end; |
|
292 |
||
293 |
repeat |
|
498 | 294 |
if not (hwRound(Gear^.Y) + cHHRadius < cWaterLine) then exit(Result); |
542 | 295 |
if (Gear^.State and gstMoving) <> 0 then |
80 | 296 |
begin |
297 |
if (GoInfo.Ticks = 350) then |
|
433 | 298 |
if (not (hwAbs(Gear^.dX) > cLittle)) and (Gear^.dY < -_0_02) then |
80 | 299 |
begin |
369 | 300 |
Gear^.dY:= -_0_25; |
498 | 301 |
Gear^.dX:= SignAs(_0_02, Gear^.dX) |
80 | 302 |
end; |
369 | 303 |
if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then SetLittle(Gear^.dX); |
304 |
Gear^.X:= Gear^.X + Gear^.dX; |
|
80 | 305 |
inc(GoInfo.Ticks); |
369 | 306 |
Gear^.dY:= Gear^.dY + cGravity; |
307 |
if Gear^.dY > _0_4 then exit(Result); |
|
498 | 308 |
if (Gear^.dY.isNegative)and TestCollisionYwithGear(Gear, -1) then Gear^.dY:= _0; |
369 | 309 |
Gear^.Y:= Gear^.Y + Gear^.dY; |
310 |
if (not Gear^.dY.isNegative)and TestCollisionYwithGear(Gear, 1) then |
|
80 | 311 |
begin |
542 | 312 |
Gear^.State:= Gear^.State and not (gstMoving or gstHHJumping); |
498 | 313 |
Gear^.dY:= _0; |
80 | 314 |
case JumpType of |
498 | 315 |
jmpHJump: if bY - hwRound(Gear^.Y) > 5 then |
80 | 316 |
begin |
317 |
Result:= true; |
|
318 |
GoInfo.JumpType:= jmpHJump; |
|
319 |
inc(GoInfo.Ticks, 300 + 300) // 300 before jump, 300 after |
|
320 |
end; |
|
498 | 321 |
jmpLJump: if abs(bX - hwRound(Gear^.X)) > 30 then |
80 | 322 |
begin |
323 |
Result:= true; |
|
324 |
GoInfo.JumpType:= jmpLJump; |
|
325 |
inc(GoInfo.Ticks, 300 + 300) // 300 before jump, 300 after |
|
326 |
end; |
|
327 |
end; |
|
369 | 328 |
exit(Result) |
80 | 329 |
end; |
330 |
end; |
|
369 | 331 |
until false |
80 | 332 |
end; |
333 |
||
369 | 334 |
function HHGo(Gear, AltGear: PGear; var GoInfo: TGoInfo): boolean; |
371 | 335 |
var pX, pY: LongInt; |
369 | 336 |
Result: boolean; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
337 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
338 |
Result:= false; |
80 | 339 |
AltGear^:= Gear^; |
340 |
||
75 | 341 |
GoInfo.Ticks:= 0; |
80 | 342 |
GoInfo.FallPix:= 0; |
343 |
GoInfo.JumpType:= jmpNone; |
|
4 | 344 |
repeat |
369 | 345 |
pX:= hwRound(Gear^.X); |
346 |
pY:= hwRound(Gear^.Y); |
|
375 | 347 |
if pY + cHHRadius >= cWaterLine then exit(false); |
542 | 348 |
if (Gear^.State and gstMoving) <> 0 then |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
349 |
begin |
75 | 350 |
inc(GoInfo.Ticks); |
369 | 351 |
Gear^.dY:= Gear^.dY + cGravity; |
352 |
if Gear^.dY > _0_4 then |
|
75 | 353 |
begin |
80 | 354 |
Goinfo.FallPix:= 0; |
568 | 355 |
HHJump(AltGear, jmpLJump, GoInfo); // try ljump instead of fall with damage |
369 | 356 |
exit(Result) |
75 | 357 |
end; |
369 | 358 |
Gear^.Y:= Gear^.Y + Gear^.dY; |
359 |
if hwRound(Gear^.Y) > pY then inc(GoInfo.FallPix); |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
360 |
if TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
361 |
begin |
75 | 362 |
inc(GoInfo.Ticks, 300); |
542 | 363 |
Gear^.State:= Gear^.State and not (gstMoving or gstHHJumping); |
498 | 364 |
Gear^.dY:= _0; |
75 | 365 |
Result:= true; |
82 | 366 |
HHJump(AltGear, jmpLJump, GoInfo); // try ljump instead of fall |
369 | 367 |
exit(Result) |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
368 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
369 |
continue |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
370 |
end; |
369 | 371 |
if (Gear^.Message and gm_Left )<>0 then Gear^.dX:= -cLittle else |
372 |
if (Gear^.Message and gm_Right )<>0 then Gear^.dX:= cLittle else exit(Result); |
|
373 |
if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
374 |
begin |
498 | 375 |
if not (TestCollisionXwithXYShift(Gear, _0, -6, hwSign(Gear^.dX)) |
376 |
or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1; |
|
377 |
if not (TestCollisionXwithXYShift(Gear, _0, -5, hwSign(Gear^.dX)) |
|
378 |
or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1; |
|
379 |
if not (TestCollisionXwithXYShift(Gear, _0, -4, hwSign(Gear^.dX)) |
|
380 |
or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1; |
|
381 |
if not (TestCollisionXwithXYShift(Gear, _0, -3, hwSign(Gear^.dX)) |
|
382 |
or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1; |
|
383 |
if not (TestCollisionXwithXYShift(Gear, _0, -2, hwSign(Gear^.dX)) |
|
384 |
or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1; |
|
385 |
if not (TestCollisionXwithXYShift(Gear, _0, -1, hwSign(Gear^.dX)) |
|
386 |
or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
387 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
388 |
|
369 | 389 |
if not TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then |
75 | 390 |
begin |
498 | 391 |
Gear^.X:= Gear^.X + int2hwFloat(hwSign(Gear^.dX)); |
75 | 392 |
inc(GoInfo.Ticks, cHHStepTicks) |
393 |
end; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
394 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
395 |
begin |
498 | 396 |
Gear^.Y:= Gear^.Y + _1; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
397 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
398 |
begin |
498 | 399 |
Gear^.Y:= Gear^.Y + _1; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
400 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
401 |
begin |
498 | 402 |
Gear^.Y:= Gear^.Y + _1; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
403 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
404 |
begin |
498 | 405 |
Gear^.Y:= Gear^.Y + _1; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
406 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
407 |
begin |
498 | 408 |
Gear^.Y:= Gear^.Y + _1; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
409 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
410 |
begin |
498 | 411 |
Gear^.Y:= Gear^.Y + _1; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
412 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
413 |
begin |
498 | 414 |
Gear^.Y:= Gear^.Y - _6; |
415 |
Gear^.dY:= _0; |
|
542 | 416 |
Gear^.State:= Gear^.State or gstMoving |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
417 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
418 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
419 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
420 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
421 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
422 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
423 |
end; |
542 | 424 |
if (pX <> hwRound(Gear^.X)) and ((Gear^.State and gstMoving) = 0) then |
375 | 425 |
exit(true); |
542 | 426 |
until (pX = hwRound(Gear^.X)) and (pY = hwRound(Gear^.Y)) and ((Gear^.State and gstMoving) = 0); |
375 | 427 |
HHJump(AltGear, jmpHJump, GoInfo); |
428 |
HHGo:= Result |
|
4 | 429 |
end; |
430 |
||
371 | 431 |
function AIrndSign(num: LongInt): LongInt; |
136 | 432 |
begin |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
433 |
if random(2) = 0 then AIrndSign:= num |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
434 |
else AIrndSign:= - num |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
435 |
end; |
136 | 436 |
|
4 | 437 |
end. |