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