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