author | nemo |
Sun, 24 Jan 2010 16:25:10 +0000 | |
changeset 2708 | 84bf57349d46 |
parent 2695 | ed789a7ef68d |
child 2716 | b9ca1bfca24f |
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 |
||
2599 | 19 |
{$INCLUDE "options.inc"} |
2587
0dfa56a8513c
fix a segfault in the iphone simulator by moving options.inc at the beginning of the file
koda
parents:
2376
diff
changeset
|
20 |
|
4 | 21 |
unit uAIMisc; |
22 |
interface |
|
351 | 23 |
uses SDLh, uConsts, uGears, uFloat; |
369 | 24 |
|
64 | 25 |
type TTarget = record |
26 |
Point: TPoint; |
|
371 | 27 |
Score: LongInt; |
64 | 28 |
end; |
29 |
TTargets = record |
|
30 |
Count: Longword; |
|
1799 | 31 |
ar: array[0..Pred(cMaxHHs)] of TTarget; |
4 | 32 |
end; |
80 | 33 |
TJumpType = (jmpNone, jmpHJump, jmpLJump); |
75 | 34 |
TGoInfo = record |
35 |
Ticks: Longword; |
|
80 | 36 |
FallPix: Longword; |
37 |
JumpType: TJumpType; |
|
75 | 38 |
end; |
64 | 39 |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
40 |
procedure FillTargets; |
70 | 41 |
procedure FillBonuses(isAfterAttack: boolean); |
371 | 42 |
procedure AwareOfExplosion(x, y, r: LongInt); |
43 |
function RatePlace(Gear: PGear): LongInt; |
|
2616
6e2b341dc408
AI fire w/o moving for artillery. Needs testing, but seems to work quickly and w/o AI screwups.
nemo
parents:
2599
diff
changeset
|
44 |
function TestCollExcludingMe(Me: PGear; x, y, r: LongInt): boolean; |
371 | 45 |
function TestColl(x, y, r: LongInt): boolean; |
46 |
function RateExplosion(Me: PGear; x, y, r: LongInt): LongInt; |
|
47 |
function RateShove(Me: PGear; x, y, r, power: LongInt): LongInt; |
|
509 | 48 |
function RateShotgun(Me: PGear; x, y: LongInt): LongInt; |
369 | 49 |
function HHGo(Gear, AltGear: PGear; var GoInfo: TGoInfo): boolean; |
371 | 50 |
function AIrndSign(num: LongInt): LongInt; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
51 |
|
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
52 |
var ThinkingHH: PGear; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
53 |
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
|
54 |
|
4 | 55 |
implementation |
922 | 56 |
uses uTeams, uMisc, uLand, uCollisions; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
57 |
const KillScore = 200; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
58 |
MAXBONUS = 1024; |
1001 | 59 |
friendlyfactor: LongInt = 300; |
369 | 60 |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
61 |
type TBonus = record |
371 | 62 |
X, Y: LongInt; |
63 |
Radius: LongInt; |
|
64 |
Score: LongInt; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
65 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
66 |
var bonuses: record |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
67 |
Count: Longword; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
68 |
ar: array[0..Pred(MAXBONUS)] of TBonus; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
69 |
end; |
71 | 70 |
KnownExplosion: record |
371 | 71 |
X, Y, Radius: LongInt |
71 | 72 |
end = (X: 0; Y: 0; Radius: 0); |
4 | 73 |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
74 |
procedure FillTargets; |
547 | 75 |
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
|
76 |
f, e: Longword; |
4 | 77 |
begin |
78 |
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
|
79 |
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
|
80 |
e:= 0; |
547 | 81 |
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
|
82 |
with TeamsArray[t]^ do |
1352
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
83 |
if not hasGone then |
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
|
84 |
begin |
1352
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
85 |
for i:= 0 to cMaxHHIndex do |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
86 |
if (Hedgehogs[i].Gear <> nil) |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
87 |
and (Hedgehogs[i].Gear <> ThinkingHH) then |
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
|
88 |
begin |
1352
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
89 |
with Targets.ar[Targets.Count], Hedgehogs[i] do |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
90 |
begin |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
91 |
Point.X:= hwRound(Gear^.X); |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
92 |
Point.Y:= hwRound(Gear^.Y); |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
93 |
if Clan <> CurrentTeam^.Clan then |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
94 |
begin |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
95 |
Score:= Gear^.Health; |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
96 |
inc(e) |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
97 |
end else |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
98 |
begin |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
99 |
Score:= -Gear^.Health; |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
100 |
inc(f) |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
101 |
end |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
102 |
end; |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
103 |
inc(Targets.Count) |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
104 |
end; |
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
|
105 |
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
|
106 |
|
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
|
107 |
if e > f then friendlyfactor:= 300 + (e - f) * 30 |
922 | 108 |
else friendlyfactor:= max(30, 300 - f * 80 div e) |
4 | 109 |
end; |
110 |
||
70 | 111 |
procedure FillBonuses(isAfterAttack: boolean); |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
112 |
var Gear: PGear; |
549 | 113 |
MyClan: PClan; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
114 |
|
371 | 115 |
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
|
116 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
117 |
bonuses.ar[bonuses.Count].x:= x; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
118 |
bonuses.ar[bonuses.Count].y:= y; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
119 |
bonuses.ar[bonuses.Count].Radius:= r; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
120 |
bonuses.ar[bonuses.Count].Score:= s; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
121 |
inc(bonuses.Count); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
122 |
TryDo(bonuses.Count <= MAXBONUS, 'Bonuses overflow', true) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
123 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
124 |
|
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
125 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
126 |
bonuses.Count:= 0; |
549 | 127 |
MyClan:= PHedgehog(ThinkingHH^.Hedgehog)^.Team^.Clan; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
128 |
Gear:= GearsList; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
129 |
while Gear <> nil do |
1352
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
130 |
begin |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
131 |
case Gear^.Kind of |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
132 |
gtCase: AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 33, 25); |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
133 |
gtMine: if (Gear^.State and gstAttacking) = 0 then |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
134 |
AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 50, -50) |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
135 |
else |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
136 |
AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 100, -50); // mine is on |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
137 |
gtDynamite: AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 150, -75); |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
138 |
gtHedgehog: begin |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
139 |
if Gear^.Damage >= Gear^.Health then |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
140 |
AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 60, -25) |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
141 |
else |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
142 |
if isAfterAttack and (ThinkingHH^.Hedgehog <> Gear^.Hedgehog) then |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
143 |
if (MyClan = PHedgehog(Gear^.Hedgehog)^.Team^.Clan) then |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
144 |
AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 150, -3) // hedgehog-friend |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
145 |
else |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
146 |
AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 100, 3) |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
147 |
end; |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
148 |
end; |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
149 |
Gear:= Gear^.NextGear |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
150 |
end; |
71 | 151 |
if isAfterAttack and (KnownExplosion.Radius > 0) then |
152 |
with KnownExplosion do |
|
74 | 153 |
AddBonus(X, Y, Radius + 10, -Radius); |
71 | 154 |
end; |
155 |
||
371 | 156 |
procedure AwareOfExplosion(x, y, r: LongInt); |
71 | 157 |
begin |
158 |
KnownExplosion.X:= x; |
|
159 |
KnownExplosion.Y:= y; |
|
160 |
KnownExplosion.Radius:= r |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
161 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
162 |
|
371 | 163 |
function RatePlace(Gear: PGear): LongInt; |
164 |
var i, r: LongInt; |
|
2695 | 165 |
rate: LongInt; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
166 |
begin |
2695 | 167 |
rate:= 0; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
168 |
for i:= 0 to Pred(bonuses.Count) do |
1352
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
169 |
with bonuses.ar[i] do |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
170 |
begin |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
171 |
r:= hwRound(Distance(Gear^.X - int2hwFloat(X), Gear^.Y - int2hwFloat(Y))); |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
172 |
if r < Radius then |
2695 | 173 |
inc(rate, Score * (Radius - r)) |
1352
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1141
diff
changeset
|
174 |
end; |
2695 | 175 |
RatePlace:= rate; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
176 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
177 |
|
2616
6e2b341dc408
AI fire w/o moving for artillery. Needs testing, but seems to work quickly and w/o AI screwups.
nemo
parents:
2599
diff
changeset
|
178 |
// Wrapper to test various approaches. If it works reasonably, will just replace. |
6e2b341dc408
AI fire w/o moving for artillery. Needs testing, but seems to work quickly and w/o AI screwups.
nemo
parents:
2599
diff
changeset
|
179 |
// Right now, converting to hwFloat is a tad inefficient since the x/y were hwFloat to begin with... |
6e2b341dc408
AI fire w/o moving for artillery. Needs testing, but seems to work quickly and w/o AI screwups.
nemo
parents:
2599
diff
changeset
|
180 |
function TestCollExcludingMe(Me: PGear; x, y, r: LongInt): boolean; |
6e2b341dc408
AI fire w/o moving for artillery. Needs testing, but seems to work quickly and w/o AI screwups.
nemo
parents:
2599
diff
changeset
|
181 |
var MeX, MeY: LongInt; |
6e2b341dc408
AI fire w/o moving for artillery. Needs testing, but seems to work quickly and w/o AI screwups.
nemo
parents:
2599
diff
changeset
|
182 |
begin |
6e2b341dc408
AI fire w/o moving for artillery. Needs testing, but seems to work quickly and w/o AI screwups.
nemo
parents:
2599
diff
changeset
|
183 |
if ((x and LAND_WIDTH_MASK) = 0) and ((y and LAND_HEIGHT_MASK) = 0) then |
6e2b341dc408
AI fire w/o moving for artillery. Needs testing, but seems to work quickly and w/o AI screwups.
nemo
parents:
2599
diff
changeset
|
184 |
begin |
6e2b341dc408
AI fire w/o moving for artillery. Needs testing, but seems to work quickly and w/o AI screwups.
nemo
parents:
2599
diff
changeset
|
185 |
MeX:= hwRound(Me^.X); |
6e2b341dc408
AI fire w/o moving for artillery. Needs testing, but seems to work quickly and w/o AI screwups.
nemo
parents:
2599
diff
changeset
|
186 |
MeY:= hwRound(Me^.Y); |
6e2b341dc408
AI fire w/o moving for artillery. Needs testing, but seems to work quickly and w/o AI screwups.
nemo
parents:
2599
diff
changeset
|
187 |
// We are still inside the hog. Skip radius test |
6e2b341dc408
AI fire w/o moving for artillery. Needs testing, but seems to work quickly and w/o AI screwups.
nemo
parents:
2599
diff
changeset
|
188 |
if ((((x-MeX)*(x-MeX)) + ((y-MeY)*(y-MeY))) < 256) and |
6e2b341dc408
AI fire w/o moving for artillery. Needs testing, but seems to work quickly and w/o AI screwups.
nemo
parents:
2599
diff
changeset
|
189 |
((Land[y, x] and $FF00) = 0) then exit(false); |
6e2b341dc408
AI fire w/o moving for artillery. Needs testing, but seems to work quickly and w/o AI screwups.
nemo
parents:
2599
diff
changeset
|
190 |
end; |
6e2b341dc408
AI fire w/o moving for artillery. Needs testing, but seems to work quickly and w/o AI screwups.
nemo
parents:
2599
diff
changeset
|
191 |
exit(TestColl(x, y, r)) |
6e2b341dc408
AI fire w/o moving for artillery. Needs testing, but seems to work quickly and w/o AI screwups.
nemo
parents:
2599
diff
changeset
|
192 |
end; |
6e2b341dc408
AI fire w/o moving for artillery. Needs testing, but seems to work quickly and w/o AI screwups.
nemo
parents:
2599
diff
changeset
|
193 |
|
371 | 194 |
function TestColl(x, y, r: LongInt): boolean; |
369 | 195 |
var b: boolean; |
4 | 196 |
begin |
1753 | 197 |
b:= (((x-r) and LAND_WIDTH_MASK) = 0)and(((y-r) and LAND_HEIGHT_MASK) = 0) and (Land[y-r, x-r] <> 0); |
369 | 198 |
if b then exit(true); |
1753 | 199 |
b:=(((x-r) and LAND_WIDTH_MASK) = 0)and(((y+r) and LAND_HEIGHT_MASK) = 0) and (Land[y+r, x-r] <> 0); |
369 | 200 |
if b then exit(true); |
1753 | 201 |
b:=(((x+r) and LAND_WIDTH_MASK) = 0)and(((y-r) and LAND_HEIGHT_MASK) = 0) and (Land[y-r, x+r] <> 0); |
369 | 202 |
if b then exit(true); |
1753 | 203 |
TestColl:=(((x+r) and LAND_WIDTH_MASK) = 0)and(((y+r) and LAND_HEIGHT_MASK) = 0) and (Land[y+r, x+r] <> 0) |
4 | 204 |
end; |
205 |
||
371 | 206 |
function RateExplosion(Me: PGear; x, y, r: LongInt): LongInt; |
2695 | 207 |
var i, dmg, rate: LongInt; |
4 | 208 |
begin |
2695 | 209 |
rate:= 0; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
210 |
// add our virtual position |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
211 |
with Targets.ar[Targets.Count] do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
212 |
begin |
369 | 213 |
Point.x:= hwRound(Me^.X); |
214 |
Point.y:= hwRound(Me^.Y); |
|
215 |
Score:= - ThinkingHH^.Health |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
216 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
217 |
// rate explosion |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
218 |
for i:= 0 to Targets.Count do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
219 |
with Targets.ar[i] do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
220 |
begin |
1141 | 221 |
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
|
222 |
if dmg > 0 then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
223 |
begin |
1141 | 224 |
dmg:= min(dmg div 2, r); |
509 | 225 |
if dmg >= abs(Score) then |
2695 | 226 |
if Score > 0 then inc(rate, KillScore) |
227 |
else dec(rate, KillScore * friendlyfactor div 100) |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
228 |
else |
2695 | 229 |
if Score > 0 then inc(rate, dmg) |
230 |
else dec(rate, dmg * friendlyfactor div 100) |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
231 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
232 |
end; |
2695 | 233 |
RateExplosion:= rate * 1024; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
234 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
235 |
|
371 | 236 |
function RateShove(Me: PGear; x, y, r, power: LongInt): LongInt; |
2695 | 237 |
var i, dmg, rate: LongInt; |
79 | 238 |
begin |
2695 | 239 |
rate:= 0; |
433 | 240 |
for i:= 0 to Pred(Targets.Count) do |
79 | 241 |
with Targets.ar[i] do |
242 |
begin |
|
498 | 243 |
dmg:= r - hwRound(DistanceI(Point.x - x, Point.y - y)); |
79 | 244 |
if dmg > 0 then |
245 |
begin |
|
509 | 246 |
if power >= abs(Score) then |
2695 | 247 |
if Score > 0 then inc(rate, KillScore) |
248 |
else dec(rate, KillScore * friendlyfactor div 100) |
|
79 | 249 |
else |
2695 | 250 |
if Score > 0 then inc(rate, power) |
251 |
else dec(rate, power * friendlyfactor div 100) |
|
79 | 252 |
end; |
253 |
end; |
|
2695 | 254 |
RateShove:= rate * 1024 |
79 | 255 |
end; |
256 |
||
509 | 257 |
function RateShotgun(Me: PGear; x, y: LongInt): LongInt; |
1941 | 258 |
const |
259 |
REUSE_BONUS = 1.35; |
|
2695 | 260 |
var i, dmg, rate: LongInt; |
509 | 261 |
begin |
2695 | 262 |
rate:= 0; |
509 | 263 |
// add our virtual position |
264 |
with Targets.ar[Targets.Count] do |
|
265 |
begin |
|
266 |
Point.x:= hwRound(Me^.X); |
|
267 |
Point.y:= hwRound(Me^.Y); |
|
268 |
Score:= - ThinkingHH^.Health |
|
269 |
end; |
|
270 |
// rate shot |
|
271 |
for i:= 0 to Targets.Count do |
|
272 |
with Targets.ar[i] do |
|
273 |
begin |
|
274 |
dmg:= min(cHHRadius + cShotgunRadius - hwRound(DistanceI(Point.x - x, Point.y - y)), 25); |
|
1941 | 275 |
dmg := round(dmg * REUSE_BONUS); |
509 | 276 |
if dmg > 0 then |
277 |
begin |
|
1941 | 278 |
if dmg >= abs(Score) then dmg := KillScore; |
2695 | 279 |
if Score > 0 then inc(rate, dmg) |
280 |
else dec(rate, dmg * friendlyfactor div 100); |
|
509 | 281 |
end; |
282 |
end; |
|
2695 | 283 |
RateShotgun:= rate * 1024; |
509 | 284 |
end; |
285 |
||
369 | 286 |
function HHJump(Gear: PGear; JumpType: TJumpType; var GoInfo: TGoInfo): boolean; |
371 | 287 |
var bX, bY: LongInt; |
2695 | 288 |
bRes: boolean; |
80 | 289 |
begin |
2695 | 290 |
bRes:= false; |
80 | 291 |
GoInfo.Ticks:= 0; |
292 |
GoInfo.FallPix:= 0; |
|
293 |
GoInfo.JumpType:= jmpNone; |
|
369 | 294 |
bX:= hwRound(Gear^.X); |
295 |
bY:= hwRound(Gear^.Y); |
|
80 | 296 |
case JumpType of |
2695 | 297 |
jmpNone: exit(bRes); |
80 | 298 |
jmpHJump: if not TestCollisionYwithGear(Gear, -1) then |
299 |
begin |
|
369 | 300 |
Gear^.dY:= -_0_2; |
301 |
SetLittle(Gear^.dX); |
|
542 | 302 |
Gear^.State:= Gear^.State or gstMoving or gstHHJumping; |
2695 | 303 |
end else exit(bRes); |
80 | 304 |
jmpLJump: begin |
305 |
if not TestCollisionYwithGear(Gear, -1) then |
|
498 | 306 |
if not TestCollisionXwithXYShift(Gear, _0, -2, hwSign(Gear^.dX)) then Gear^.Y:= Gear^.Y - int2hwFloat(2) else |
307 |
if not TestCollisionXwithXYShift(Gear, _0, -1, hwSign(Gear^.dX)) then Gear^.Y:= Gear^.Y - _1; |
|
369 | 308 |
if not (TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) |
80 | 309 |
or TestCollisionYwithGear(Gear, -1)) then |
310 |
begin |
|
433 | 311 |
Gear^.dY:= -_0_15; |
498 | 312 |
Gear^.dX:= SignAs(_0_15, Gear^.dX); |
542 | 313 |
Gear^.State:= Gear^.State or gstMoving or gstHHJumping |
2695 | 314 |
end else exit(bRes) |
80 | 315 |
end |
316 |
end; |
|
2376 | 317 |
|
80 | 318 |
repeat |
2695 | 319 |
if not (hwRound(Gear^.Y) + cHHRadius < cWaterLine) then exit(bRes); |
542 | 320 |
if (Gear^.State and gstMoving) <> 0 then |
80 | 321 |
begin |
322 |
if (GoInfo.Ticks = 350) then |
|
433 | 323 |
if (not (hwAbs(Gear^.dX) > cLittle)) and (Gear^.dY < -_0_02) then |
80 | 324 |
begin |
369 | 325 |
Gear^.dY:= -_0_25; |
498 | 326 |
Gear^.dX:= SignAs(_0_02, Gear^.dX) |
80 | 327 |
end; |
369 | 328 |
if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then SetLittle(Gear^.dX); |
329 |
Gear^.X:= Gear^.X + Gear^.dX; |
|
80 | 330 |
inc(GoInfo.Ticks); |
369 | 331 |
Gear^.dY:= Gear^.dY + cGravity; |
2695 | 332 |
if Gear^.dY > _0_4 then exit(bRes); |
498 | 333 |
if (Gear^.dY.isNegative)and TestCollisionYwithGear(Gear, -1) then Gear^.dY:= _0; |
369 | 334 |
Gear^.Y:= Gear^.Y + Gear^.dY; |
335 |
if (not Gear^.dY.isNegative)and TestCollisionYwithGear(Gear, 1) then |
|
80 | 336 |
begin |
542 | 337 |
Gear^.State:= Gear^.State and not (gstMoving or gstHHJumping); |
498 | 338 |
Gear^.dY:= _0; |
80 | 339 |
case JumpType of |
498 | 340 |
jmpHJump: if bY - hwRound(Gear^.Y) > 5 then |
80 | 341 |
begin |
2695 | 342 |
bRes:= true; |
80 | 343 |
GoInfo.JumpType:= jmpHJump; |
344 |
inc(GoInfo.Ticks, 300 + 300) // 300 before jump, 300 after |
|
345 |
end; |
|
498 | 346 |
jmpLJump: if abs(bX - hwRound(Gear^.X)) > 30 then |
80 | 347 |
begin |
2695 | 348 |
bRes:= true; |
80 | 349 |
GoInfo.JumpType:= jmpLJump; |
350 |
inc(GoInfo.Ticks, 300 + 300) // 300 before jump, 300 after |
|
351 |
end; |
|
352 |
end; |
|
2695 | 353 |
exit(bRes) |
80 | 354 |
end; |
355 |
end; |
|
369 | 356 |
until false |
80 | 357 |
end; |
358 |
||
369 | 359 |
function HHGo(Gear, AltGear: PGear; var GoInfo: TGoInfo): boolean; |
371 | 360 |
var pX, pY: LongInt; |
2695 | 361 |
bRes: boolean; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
362 |
begin |
2695 | 363 |
bRes:= false; |
80 | 364 |
AltGear^:= Gear^; |
365 |
||
75 | 366 |
GoInfo.Ticks:= 0; |
80 | 367 |
GoInfo.FallPix:= 0; |
368 |
GoInfo.JumpType:= jmpNone; |
|
4 | 369 |
repeat |
369 | 370 |
pX:= hwRound(Gear^.X); |
371 |
pY:= hwRound(Gear^.Y); |
|
375 | 372 |
if pY + cHHRadius >= cWaterLine then exit(false); |
542 | 373 |
if (Gear^.State and gstMoving) <> 0 then |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
374 |
begin |
75 | 375 |
inc(GoInfo.Ticks); |
369 | 376 |
Gear^.dY:= Gear^.dY + cGravity; |
377 |
if Gear^.dY > _0_4 then |
|
75 | 378 |
begin |
80 | 379 |
Goinfo.FallPix:= 0; |
568 | 380 |
HHJump(AltGear, jmpLJump, GoInfo); // try ljump instead of fall with damage |
2695 | 381 |
exit(bRes) |
75 | 382 |
end; |
369 | 383 |
Gear^.Y:= Gear^.Y + Gear^.dY; |
384 |
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
|
385 |
if TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
386 |
begin |
1519
7b6adbe5266a
More delay after jump, less delay after small fall for hedgehog
unc0rr
parents:
1352
diff
changeset
|
387 |
inc(GoInfo.Ticks, 410); |
542 | 388 |
Gear^.State:= Gear^.State and not (gstMoving or gstHHJumping); |
498 | 389 |
Gear^.dY:= _0; |
2695 | 390 |
bRes:= true; |
82 | 391 |
HHJump(AltGear, jmpLJump, GoInfo); // try ljump instead of fall |
2695 | 392 |
exit(bRes) |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
393 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
394 |
continue |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
395 |
end; |
369 | 396 |
if (Gear^.Message and gm_Left )<>0 then Gear^.dX:= -cLittle else |
2695 | 397 |
if (Gear^.Message and gm_Right )<>0 then Gear^.dX:= cLittle else exit(bRes); |
369 | 398 |
if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
399 |
begin |
498 | 400 |
if not (TestCollisionXwithXYShift(Gear, _0, -6, hwSign(Gear^.dX)) |
401 |
or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1; |
|
402 |
if not (TestCollisionXwithXYShift(Gear, _0, -5, hwSign(Gear^.dX)) |
|
403 |
or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1; |
|
404 |
if not (TestCollisionXwithXYShift(Gear, _0, -4, hwSign(Gear^.dX)) |
|
405 |
or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1; |
|
406 |
if not (TestCollisionXwithXYShift(Gear, _0, -3, hwSign(Gear^.dX)) |
|
407 |
or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1; |
|
408 |
if not (TestCollisionXwithXYShift(Gear, _0, -2, hwSign(Gear^.dX)) |
|
409 |
or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1; |
|
410 |
if not (TestCollisionXwithXYShift(Gear, _0, -1, hwSign(Gear^.dX)) |
|
411 |
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
|
412 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
413 |
|
369 | 414 |
if not TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then |
75 | 415 |
begin |
498 | 416 |
Gear^.X:= Gear^.X + int2hwFloat(hwSign(Gear^.dX)); |
75 | 417 |
inc(GoInfo.Ticks, cHHStepTicks) |
418 |
end; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
419 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
420 |
begin |
498 | 421 |
Gear^.Y:= Gear^.Y + _1; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
422 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
423 |
begin |
498 | 424 |
Gear^.Y:= Gear^.Y + _1; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
425 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
426 |
begin |
498 | 427 |
Gear^.Y:= Gear^.Y + _1; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
428 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
429 |
begin |
498 | 430 |
Gear^.Y:= Gear^.Y + _1; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
431 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
432 |
begin |
498 | 433 |
Gear^.Y:= Gear^.Y + _1; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
434 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
435 |
begin |
498 | 436 |
Gear^.Y:= Gear^.Y + _1; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
437 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
438 |
begin |
498 | 439 |
Gear^.Y:= Gear^.Y - _6; |
440 |
Gear^.dY:= _0; |
|
542 | 441 |
Gear^.State:= Gear^.State or gstMoving |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
442 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
443 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
444 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
445 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
446 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
447 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
448 |
end; |
542 | 449 |
if (pX <> hwRound(Gear^.X)) and ((Gear^.State and gstMoving) = 0) then |
375 | 450 |
exit(true); |
542 | 451 |
until (pX = hwRound(Gear^.X)) and (pY = hwRound(Gear^.Y)) and ((Gear^.State and gstMoving) = 0); |
375 | 452 |
HHJump(AltGear, jmpHJump, GoInfo); |
2695 | 453 |
HHGo:= bRes; |
4 | 454 |
end; |
455 |
||
371 | 456 |
function AIrndSign(num: LongInt): LongInt; |
136 | 457 |
begin |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
458 |
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
|
459 |
else AIrndSign:= - num |
2376 | 460 |
end; |
136 | 461 |
|
4 | 462 |
end. |