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