author | Xeli |
Fri, 01 Jul 2011 08:46:47 +0200 | |
branch | hedgeroid |
changeset 5385 | a864a0aeed96 |
parent 5244 | 1b408b965c01 |
child 5422 | 0daf3d8e4b70 |
permissions | -rw-r--r-- |
71 | 1 |
(* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
4977
c89cca0a8785
Try to make AI aware of dud mines by clearing gstAttacking on dud, and adding some rules on mine health/damage/dud probability to AI weighting.
nemo
parents:
4976
diff
changeset
|
3 |
* Copyright (c) 2005-2011 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 |
|
4368 | 23 |
uses SDLh, uConsts, uFloat, uTypes; |
369 | 24 |
|
3370 | 25 |
const MAXBONUS = 1024; |
26 |
||
64 | 27 |
type TTarget = record |
28 |
Point: TPoint; |
|
371 | 29 |
Score: LongInt; |
64 | 30 |
end; |
31 |
TTargets = record |
|
32 |
Count: Longword; |
|
1799 | 33 |
ar: array[0..Pred(cMaxHHs)] of TTarget; |
4 | 34 |
end; |
80 | 35 |
TJumpType = (jmpNone, jmpHJump, jmpLJump); |
75 | 36 |
TGoInfo = record |
37 |
Ticks: Longword; |
|
80 | 38 |
FallPix: Longword; |
39 |
JumpType: TJumpType; |
|
75 | 40 |
end; |
3370 | 41 |
TBonus = record |
42 |
X, Y: LongInt; |
|
43 |
Radius: LongInt; |
|
44 |
Score: LongInt; |
|
45 |
end; |
|
64 | 46 |
|
3038 | 47 |
procedure initModule; |
48 |
procedure freeModule; |
|
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2695
diff
changeset
|
49 |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
50 |
procedure FillTargets; |
3370 | 51 |
procedure FillBonuses(isAfterAttack: boolean; filter: TGearsType = []); |
371 | 52 |
procedure AwareOfExplosion(x, y, r: LongInt); |
53 |
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
|
54 |
function TestCollExcludingMe(Me: PGear; x, y, r: LongInt): boolean; |
371 | 55 |
function TestColl(x, y, r: LongInt): boolean; |
56 |
function RateExplosion(Me: PGear; x, y, r: LongInt): LongInt; |
|
57 |
function RateShove(Me: PGear; x, y, r, power: LongInt): LongInt; |
|
509 | 58 |
function RateShotgun(Me: PGear; x, y: LongInt): LongInt; |
369 | 59 |
function HHGo(Gear, AltGear: PGear; var GoInfo: TGoInfo): boolean; |
371 | 60 |
function AIrndSign(num: LongInt): LongInt; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
61 |
|
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
62 |
var ThinkingHH: PGear; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
63 |
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
|
64 |
|
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2695
diff
changeset
|
65 |
bonuses: record |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
66 |
Count: Longword; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
67 |
ar: array[0..Pred(MAXBONUS)] of TBonus; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
68 |
end; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2695
diff
changeset
|
69 |
|
3370 | 70 |
implementation |
4403 | 71 |
uses uCollisions, uVariables, uUtils, uDebug; |
3370 | 72 |
|
73 |
const KillScore = 200; |
|
74 |
||
75 |
var friendlyfactor: LongInt = 300; |
|
76 |
KnownExplosion: record |
|
77 |
X, Y, Radius: LongInt |
|
3697 | 78 |
end = (X: 0; Y: 0; Radius: 0); |
4 | 79 |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
80 |
procedure FillTargets; |
547 | 81 |
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
|
82 |
f, e: Longword; |
4 | 83 |
begin |
84 |
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
|
85 |
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
|
86 |
e:= 0; |
547 | 87 |
for t:= 0 to Pred(TeamsCount) do |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
88 |
with TeamsArray[t]^ do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
89 |
if not hasGone then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
90 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
91 |
for i:= 0 to cMaxHHIndex do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
92 |
if (Hedgehogs[i].Gear <> nil) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
93 |
and (Hedgehogs[i].Gear <> ThinkingHH) then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
94 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
95 |
with Targets.ar[Targets.Count], Hedgehogs[i] do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
96 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
97 |
Point.X:= hwRound(Gear^.X); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
98 |
Point.Y:= hwRound(Gear^.Y); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
99 |
if Clan <> CurrentTeam^.Clan then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
100 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
101 |
Score:= Gear^.Health; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
102 |
inc(e) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
103 |
end else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
104 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
105 |
Score:= -Gear^.Health; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
106 |
inc(f) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
107 |
end |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
108 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
109 |
inc(Targets.Count) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
110 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
111 |
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
|
112 |
|
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
|
113 |
if e > f then friendlyfactor:= 300 + (e - f) * 30 |
922 | 114 |
else friendlyfactor:= max(30, 300 - f * 80 div e) |
4 | 115 |
end; |
116 |
||
3370 | 117 |
procedure FillBonuses(isAfterAttack: boolean; filter: TGearsType); |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
118 |
var Gear: PGear; |
549 | 119 |
MyClan: PClan; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
120 |
|
371 | 121 |
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
|
122 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
123 |
bonuses.ar[bonuses.Count].x:= x; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
124 |
bonuses.ar[bonuses.Count].y:= y; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
125 |
bonuses.ar[bonuses.Count].Radius:= r; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
126 |
bonuses.ar[bonuses.Count].Score:= s; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
127 |
inc(bonuses.Count); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
128 |
TryDo(bonuses.Count <= MAXBONUS, 'Bonuses overflow', true) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
129 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
130 |
|
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
131 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
132 |
bonuses.Count:= 0; |
4372 | 133 |
MyClan:= ThinkingHH^.Hedgehog^.Team^.Clan; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
134 |
Gear:= GearsList; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
135 |
while Gear <> nil do |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
136 |
begin |
5244
1b408b965c01
Don't stick to enemies when there are more than 2 clans
unc0rr
parents:
4977
diff
changeset
|
137 |
if (filter = []) or (Gear^.Kind in filter) then |
3370 | 138 |
case Gear^.Kind of |
139 |
gtCase: AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 33, 25); |
|
140 |
gtFlame: if (Gear^.State and gsttmpFlag) <> 0 then |
|
141 |
AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 20, -50); |
|
4977
c89cca0a8785
Try to make AI aware of dud mines by clearing gstAttacking on dud, and adding some rules on mine health/damage/dud probability to AI weighting.
nemo
parents:
4976
diff
changeset
|
142 |
// avoid mines unless they are very likely to be duds, or are duds. also avoid if they are about to blow |
c89cca0a8785
Try to make AI aware of dud mines by clearing gstAttacking on dud, and adding some rules on mine health/damage/dud probability to AI weighting.
nemo
parents:
4976
diff
changeset
|
143 |
gtMine: if ((Gear^.State and gstAttacking) = 0) and |
c89cca0a8785
Try to make AI aware of dud mines by clearing gstAttacking on dud, and adding some rules on mine health/damage/dud probability to AI weighting.
nemo
parents:
4976
diff
changeset
|
144 |
(((cMineDudPercent < 90) and (Gear^.Health <> 0)) or |
c89cca0a8785
Try to make AI aware of dud mines by clearing gstAttacking on dud, and adding some rules on mine health/damage/dud probability to AI weighting.
nemo
parents:
4976
diff
changeset
|
145 |
((Gear^.Health = 0) and (Gear^.Damage > 30))) then |
c89cca0a8785
Try to make AI aware of dud mines by clearing gstAttacking on dud, and adding some rules on mine health/damage/dud probability to AI weighting.
nemo
parents:
4976
diff
changeset
|
146 |
AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 50, -50) |
c89cca0a8785
Try to make AI aware of dud mines by clearing gstAttacking on dud, and adding some rules on mine health/damage/dud probability to AI weighting.
nemo
parents:
4976
diff
changeset
|
147 |
else if (Gear^.State and gstAttacking) <> 0 then |
c89cca0a8785
Try to make AI aware of dud mines by clearing gstAttacking on dud, and adding some rules on mine health/damage/dud probability to AI weighting.
nemo
parents:
4976
diff
changeset
|
148 |
AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 100, -50); // mine is on |
3370 | 149 |
gtDynamite: AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 150, -75); |
150 |
gtHedgehog: begin |
|
151 |
if Gear^.Damage >= Gear^.Health then |
|
152 |
AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 60, -25) |
|
153 |
else |
|
154 |
if isAfterAttack and (ThinkingHH^.Hedgehog <> Gear^.Hedgehog) then |
|
5244
1b408b965c01
Don't stick to enemies when there are more than 2 clans
unc0rr
parents:
4977
diff
changeset
|
155 |
if (ClansCount > 2) or (MyClan = Gear^.Hedgehog^.Team^.Clan) then |
3370 | 156 |
AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 150, -3) // hedgehog-friend |
157 |
else |
|
158 |
AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 100, 3) |
|
159 |
end; |
|
160 |
end; |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
161 |
Gear:= Gear^.NextGear |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
162 |
end; |
71 | 163 |
if isAfterAttack and (KnownExplosion.Radius > 0) then |
164 |
with KnownExplosion do |
|
74 | 165 |
AddBonus(X, Y, Radius + 10, -Radius); |
71 | 166 |
end; |
167 |
||
371 | 168 |
procedure AwareOfExplosion(x, y, r: LongInt); |
71 | 169 |
begin |
170 |
KnownExplosion.X:= x; |
|
171 |
KnownExplosion.Y:= y; |
|
172 |
KnownExplosion.Radius:= r |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
173 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
174 |
|
371 | 175 |
function RatePlace(Gear: PGear): LongInt; |
176 |
var i, r: LongInt; |
|
2695 | 177 |
rate: LongInt; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
178 |
begin |
2695 | 179 |
rate:= 0; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
180 |
for i:= 0 to Pred(bonuses.Count) do |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
181 |
with bonuses.ar[i] do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
182 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
183 |
r:= hwRound(Distance(Gear^.X - int2hwFloat(X), Gear^.Y - int2hwFloat(Y))); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
184 |
if r < Radius then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
185 |
inc(rate, Score * (Radius - r)) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
186 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
187 |
RatePlace:= rate; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
188 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
189 |
|
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
|
190 |
// 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
|
191 |
// 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
|
192 |
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
|
193 |
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
|
194 |
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
|
195 |
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
|
196 |
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
|
197 |
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
|
198 |
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
|
199 |
// We are still inside the hog. Skip radius test |
3697 | 200 |
if ((((x-MeX)*(x-MeX)) + ((y-MeY)*(y-MeY))) < 256) and |
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
|
201 |
((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
|
202 |
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
|
203 |
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
|
204 |
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
|
205 |
|
371 | 206 |
function TestColl(x, y, r: LongInt): boolean; |
369 | 207 |
var b: boolean; |
4 | 208 |
begin |
1753 | 209 |
b:= (((x-r) and LAND_WIDTH_MASK) = 0)and(((y-r) and LAND_HEIGHT_MASK) = 0) and (Land[y-r, x-r] <> 0); |
369 | 210 |
if b then exit(true); |
1753 | 211 |
b:=(((x-r) and LAND_WIDTH_MASK) = 0)and(((y+r) and LAND_HEIGHT_MASK) = 0) and (Land[y+r, x-r] <> 0); |
369 | 212 |
if b then exit(true); |
1753 | 213 |
b:=(((x+r) and LAND_WIDTH_MASK) = 0)and(((y-r) and LAND_HEIGHT_MASK) = 0) and (Land[y-r, x+r] <> 0); |
369 | 214 |
if b then exit(true); |
1753 | 215 |
TestColl:=(((x+r) and LAND_WIDTH_MASK) = 0)and(((y+r) and LAND_HEIGHT_MASK) = 0) and (Land[y+r, x+r] <> 0) |
4 | 216 |
end; |
217 |
||
371 | 218 |
function RateExplosion(Me: PGear; x, y, r: LongInt): LongInt; |
2695 | 219 |
var i, dmg, rate: LongInt; |
4 | 220 |
begin |
2695 | 221 |
rate:= 0; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
222 |
// add our virtual position |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
223 |
with Targets.ar[Targets.Count] do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
224 |
begin |
369 | 225 |
Point.x:= hwRound(Me^.X); |
226 |
Point.y:= hwRound(Me^.Y); |
|
227 |
Score:= - ThinkingHH^.Health |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
228 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
229 |
// rate explosion |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
230 |
for i:= 0 to Targets.Count do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
231 |
with Targets.ar[i] do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
232 |
begin |
1141 | 233 |
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
|
234 |
if dmg > 0 then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
235 |
begin |
1141 | 236 |
dmg:= min(dmg div 2, r); |
509 | 237 |
if dmg >= abs(Score) then |
2695 | 238 |
if Score > 0 then inc(rate, KillScore) |
239 |
else dec(rate, KillScore * friendlyfactor div 100) |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
240 |
else |
2695 | 241 |
if Score > 0 then inc(rate, dmg) |
242 |
else dec(rate, dmg * friendlyfactor div 100) |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
243 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
244 |
end; |
2695 | 245 |
RateExplosion:= rate * 1024; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
246 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
247 |
|
371 | 248 |
function RateShove(Me: PGear; x, y, r, power: LongInt): LongInt; |
2695 | 249 |
var i, dmg, rate: LongInt; |
79 | 250 |
begin |
3407 | 251 |
Me:= Me; // avoid compiler hint |
2695 | 252 |
rate:= 0; |
433 | 253 |
for i:= 0 to Pred(Targets.Count) do |
79 | 254 |
with Targets.ar[i] do |
255 |
begin |
|
498 | 256 |
dmg:= r - hwRound(DistanceI(Point.x - x, Point.y - y)); |
79 | 257 |
if dmg > 0 then |
258 |
begin |
|
509 | 259 |
if power >= abs(Score) then |
2695 | 260 |
if Score > 0 then inc(rate, KillScore) |
261 |
else dec(rate, KillScore * friendlyfactor div 100) |
|
79 | 262 |
else |
2695 | 263 |
if Score > 0 then inc(rate, power) |
264 |
else dec(rate, power * friendlyfactor div 100) |
|
79 | 265 |
end; |
266 |
end; |
|
2695 | 267 |
RateShove:= rate * 1024 |
79 | 268 |
end; |
269 |
||
509 | 270 |
function RateShotgun(Me: PGear; x, y: LongInt): LongInt; |
1941 | 271 |
const |
272 |
REUSE_BONUS = 1.35; |
|
2695 | 273 |
var i, dmg, rate: LongInt; |
509 | 274 |
begin |
2695 | 275 |
rate:= 0; |
509 | 276 |
// add our virtual position |
277 |
with Targets.ar[Targets.Count] do |
|
278 |
begin |
|
279 |
Point.x:= hwRound(Me^.X); |
|
280 |
Point.y:= hwRound(Me^.Y); |
|
281 |
Score:= - ThinkingHH^.Health |
|
282 |
end; |
|
283 |
// rate shot |
|
284 |
for i:= 0 to Targets.Count do |
|
285 |
with Targets.ar[i] do |
|
286 |
begin |
|
287 |
dmg:= min(cHHRadius + cShotgunRadius - hwRound(DistanceI(Point.x - x, Point.y - y)), 25); |
|
1941 | 288 |
dmg := round(dmg * REUSE_BONUS); |
509 | 289 |
if dmg > 0 then |
290 |
begin |
|
1941 | 291 |
if dmg >= abs(Score) then dmg := KillScore; |
2695 | 292 |
if Score > 0 then inc(rate, dmg) |
293 |
else dec(rate, dmg * friendlyfactor div 100); |
|
509 | 294 |
end; |
295 |
end; |
|
2695 | 296 |
RateShotgun:= rate * 1024; |
509 | 297 |
end; |
298 |
||
369 | 299 |
function HHJump(Gear: PGear; JumpType: TJumpType; var GoInfo: TGoInfo): boolean; |
371 | 300 |
var bX, bY: LongInt; |
2695 | 301 |
bRes: boolean; |
80 | 302 |
begin |
2695 | 303 |
bRes:= false; |
80 | 304 |
GoInfo.Ticks:= 0; |
305 |
GoInfo.FallPix:= 0; |
|
306 |
GoInfo.JumpType:= jmpNone; |
|
369 | 307 |
bX:= hwRound(Gear^.X); |
308 |
bY:= hwRound(Gear^.Y); |
|
80 | 309 |
case JumpType of |
2695 | 310 |
jmpNone: exit(bRes); |
80 | 311 |
jmpHJump: if not TestCollisionYwithGear(Gear, -1) then |
312 |
begin |
|
369 | 313 |
Gear^.dY:= -_0_2; |
314 |
SetLittle(Gear^.dX); |
|
542 | 315 |
Gear^.State:= Gear^.State or gstMoving or gstHHJumping; |
2695 | 316 |
end else exit(bRes); |
80 | 317 |
jmpLJump: begin |
318 |
if not TestCollisionYwithGear(Gear, -1) then |
|
498 | 319 |
if not TestCollisionXwithXYShift(Gear, _0, -2, hwSign(Gear^.dX)) then Gear^.Y:= Gear^.Y - int2hwFloat(2) else |
320 |
if not TestCollisionXwithXYShift(Gear, _0, -1, hwSign(Gear^.dX)) then Gear^.Y:= Gear^.Y - _1; |
|
369 | 321 |
if not (TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) |
80 | 322 |
or TestCollisionYwithGear(Gear, -1)) then |
323 |
begin |
|
433 | 324 |
Gear^.dY:= -_0_15; |
498 | 325 |
Gear^.dX:= SignAs(_0_15, Gear^.dX); |
542 | 326 |
Gear^.State:= Gear^.State or gstMoving or gstHHJumping |
2695 | 327 |
end else exit(bRes) |
80 | 328 |
end |
329 |
end; |
|
2376 | 330 |
|
80 | 331 |
repeat |
2695 | 332 |
if not (hwRound(Gear^.Y) + cHHRadius < cWaterLine) then exit(bRes); |
542 | 333 |
if (Gear^.State and gstMoving) <> 0 then |
80 | 334 |
begin |
335 |
if (GoInfo.Ticks = 350) then |
|
433 | 336 |
if (not (hwAbs(Gear^.dX) > cLittle)) and (Gear^.dY < -_0_02) then |
80 | 337 |
begin |
369 | 338 |
Gear^.dY:= -_0_25; |
498 | 339 |
Gear^.dX:= SignAs(_0_02, Gear^.dX) |
80 | 340 |
end; |
369 | 341 |
if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then SetLittle(Gear^.dX); |
342 |
Gear^.X:= Gear^.X + Gear^.dX; |
|
80 | 343 |
inc(GoInfo.Ticks); |
369 | 344 |
Gear^.dY:= Gear^.dY + cGravity; |
2695 | 345 |
if Gear^.dY > _0_4 then exit(bRes); |
498 | 346 |
if (Gear^.dY.isNegative)and TestCollisionYwithGear(Gear, -1) then Gear^.dY:= _0; |
369 | 347 |
Gear^.Y:= Gear^.Y + Gear^.dY; |
348 |
if (not Gear^.dY.isNegative)and TestCollisionYwithGear(Gear, 1) then |
|
80 | 349 |
begin |
542 | 350 |
Gear^.State:= Gear^.State and not (gstMoving or gstHHJumping); |
498 | 351 |
Gear^.dY:= _0; |
80 | 352 |
case JumpType of |
498 | 353 |
jmpHJump: if bY - hwRound(Gear^.Y) > 5 then |
80 | 354 |
begin |
2695 | 355 |
bRes:= true; |
80 | 356 |
GoInfo.JumpType:= jmpHJump; |
357 |
inc(GoInfo.Ticks, 300 + 300) // 300 before jump, 300 after |
|
358 |
end; |
|
498 | 359 |
jmpLJump: if abs(bX - hwRound(Gear^.X)) > 30 then |
80 | 360 |
begin |
2695 | 361 |
bRes:= true; |
80 | 362 |
GoInfo.JumpType:= jmpLJump; |
363 |
inc(GoInfo.Ticks, 300 + 300) // 300 before jump, 300 after |
|
364 |
end; |
|
365 |
end; |
|
2695 | 366 |
exit(bRes) |
80 | 367 |
end; |
368 |
end; |
|
369 | 369 |
until false |
80 | 370 |
end; |
371 |
||
369 | 372 |
function HHGo(Gear, AltGear: PGear; var GoInfo: TGoInfo): boolean; |
371 | 373 |
var pX, pY: LongInt; |
2695 | 374 |
bRes: boolean; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
375 |
begin |
2695 | 376 |
bRes:= false; |
80 | 377 |
AltGear^:= Gear^; |
378 |
||
75 | 379 |
GoInfo.Ticks:= 0; |
80 | 380 |
GoInfo.FallPix:= 0; |
381 |
GoInfo.JumpType:= jmpNone; |
|
4 | 382 |
repeat |
369 | 383 |
pX:= hwRound(Gear^.X); |
384 |
pY:= hwRound(Gear^.Y); |
|
375 | 385 |
if pY + cHHRadius >= cWaterLine then exit(false); |
542 | 386 |
if (Gear^.State and gstMoving) <> 0 then |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
387 |
begin |
75 | 388 |
inc(GoInfo.Ticks); |
369 | 389 |
Gear^.dY:= Gear^.dY + cGravity; |
390 |
if Gear^.dY > _0_4 then |
|
75 | 391 |
begin |
80 | 392 |
Goinfo.FallPix:= 0; |
568 | 393 |
HHJump(AltGear, jmpLJump, GoInfo); // try ljump instead of fall with damage |
2695 | 394 |
exit(bRes) |
75 | 395 |
end; |
369 | 396 |
Gear^.Y:= Gear^.Y + Gear^.dY; |
397 |
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
|
398 |
if TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
399 |
begin |
1519
7b6adbe5266a
More delay after jump, less delay after small fall for hedgehog
unc0rr
parents:
1352
diff
changeset
|
400 |
inc(GoInfo.Ticks, 410); |
542 | 401 |
Gear^.State:= Gear^.State and not (gstMoving or gstHHJumping); |
498 | 402 |
Gear^.dY:= _0; |
2695 | 403 |
bRes:= true; |
82 | 404 |
HHJump(AltGear, jmpLJump, GoInfo); // try ljump instead of fall |
2695 | 405 |
exit(bRes) |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
406 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
407 |
continue |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
408 |
end; |
3894 | 409 |
if (Gear^.Message and gmLeft )<>0 then Gear^.dX:= -cLittle else |
410 |
if (Gear^.Message and gmRight )<>0 then Gear^.dX:= cLittle else exit(bRes); |
|
369 | 411 |
if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
412 |
begin |
498 | 413 |
if not (TestCollisionXwithXYShift(Gear, _0, -6, hwSign(Gear^.dX)) |
414 |
or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1; |
|
415 |
if not (TestCollisionXwithXYShift(Gear, _0, -5, hwSign(Gear^.dX)) |
|
416 |
or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1; |
|
417 |
if not (TestCollisionXwithXYShift(Gear, _0, -4, hwSign(Gear^.dX)) |
|
418 |
or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1; |
|
419 |
if not (TestCollisionXwithXYShift(Gear, _0, -3, hwSign(Gear^.dX)) |
|
420 |
or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1; |
|
421 |
if not (TestCollisionXwithXYShift(Gear, _0, -2, hwSign(Gear^.dX)) |
|
422 |
or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1; |
|
423 |
if not (TestCollisionXwithXYShift(Gear, _0, -1, hwSign(Gear^.dX)) |
|
424 |
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
|
425 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
426 |
|
369 | 427 |
if not TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then |
75 | 428 |
begin |
498 | 429 |
Gear^.X:= Gear^.X + int2hwFloat(hwSign(Gear^.dX)); |
75 | 430 |
inc(GoInfo.Ticks, cHHStepTicks) |
431 |
end; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
432 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
433 |
begin |
498 | 434 |
Gear^.Y:= Gear^.Y + _1; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
435 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
436 |
begin |
498 | 437 |
Gear^.Y:= Gear^.Y + _1; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
438 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
439 |
begin |
498 | 440 |
Gear^.Y:= Gear^.Y + _1; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
441 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
442 |
begin |
498 | 443 |
Gear^.Y:= Gear^.Y + _1; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
444 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
445 |
begin |
498 | 446 |
Gear^.Y:= Gear^.Y + _1; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
447 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
448 |
begin |
498 | 449 |
Gear^.Y:= Gear^.Y + _1; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
450 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
451 |
begin |
498 | 452 |
Gear^.Y:= Gear^.Y - _6; |
453 |
Gear^.dY:= _0; |
|
542 | 454 |
Gear^.State:= Gear^.State or gstMoving |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
455 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
456 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
457 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
458 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
459 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
460 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
461 |
end; |
542 | 462 |
if (pX <> hwRound(Gear^.X)) and ((Gear^.State and gstMoving) = 0) then |
375 | 463 |
exit(true); |
542 | 464 |
until (pX = hwRound(Gear^.X)) and (pY = hwRound(Gear^.Y)) and ((Gear^.State and gstMoving) = 0); |
375 | 465 |
HHJump(AltGear, jmpHJump, GoInfo); |
2695 | 466 |
HHGo:= bRes; |
4 | 467 |
end; |
468 |
||
371 | 469 |
function AIrndSign(num: LongInt): LongInt; |
136 | 470 |
begin |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
471 |
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
|
472 |
else AIrndSign:= - num |
2376 | 473 |
end; |
136 | 474 |
|
3038 | 475 |
procedure initModule; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2695
diff
changeset
|
476 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
477 |
friendlyfactor:= 300; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
478 |
KnownExplosion.X:= 0; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
479 |
KnownExplosion.Y:= 0; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
480 |
KnownExplosion.Radius:= 0; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2695
diff
changeset
|
481 |
end; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2695
diff
changeset
|
482 |
|
3038 | 483 |
procedure freeModule; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2695
diff
changeset
|
484 |
begin |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2695
diff
changeset
|
485 |
|
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2695
diff
changeset
|
486 |
end; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2695
diff
changeset
|
487 |
|
4 | 488 |
end. |