57 StopMessages(Gear^.Message); |
57 StopMessages(Gear^.Message); |
58 |
58 |
59 BestActions.Count:= 0; |
59 BestActions.Count:= 0; |
60 BestActions.Pos:= 0 |
60 BestActions.Pos:= 0 |
61 end; |
61 end; |
|
62 |
|
63 |
|
64 |
|
65 const cBranchStackSize = 12; |
|
66 type TStackEntry = record |
|
67 WastedTicks: Longword; |
|
68 MadeActions: TActions; |
|
69 Hedgehog: TGear; |
|
70 end; |
|
71 |
|
72 var Stack: record |
|
73 Count: Longword; |
|
74 States: array[0..Pred(cBranchStackSize)] of TStackEntry; |
|
75 end; |
|
76 |
|
77 function Push(Ticks: Longword; const Actions: TActions; const Me: TGear; Dir: integer): boolean; |
|
78 var bRes: boolean; |
|
79 begin |
|
80 bRes:= (Stack.Count < cBranchStackSize) and (Actions.Count < MAXACTIONS - 5); |
|
81 if bRes then |
|
82 with Stack.States[Stack.Count] do |
|
83 begin |
|
84 WastedTicks:= Ticks; |
|
85 MadeActions:= Actions; |
|
86 Hedgehog:= Me; |
|
87 Hedgehog.Message:= Dir; |
|
88 inc(Stack.Count) |
|
89 end; |
|
90 Push:= bRes |
|
91 end; |
|
92 |
|
93 procedure Pop(var Ticks: Longword; var Actions: TActions; var Me: TGear); |
|
94 begin |
|
95 dec(Stack.Count); |
|
96 with Stack.States[Stack.Count] do |
|
97 begin |
|
98 Ticks:= WastedTicks; |
|
99 Actions:= MadeActions; |
|
100 Me:= Hedgehog |
|
101 end |
|
102 end; |
|
103 |
|
104 |
62 |
105 |
63 procedure TestAmmos(var Actions: TActions; Me: PGear; isMoved: boolean); |
106 procedure TestAmmos(var Actions: TActions; Me: PGear; isMoved: boolean); |
64 var BotLevel: Byte; |
107 var BotLevel: Byte; |
65 ap: TAttackParams; |
108 ap: TAttackParams; |
66 Score, i: LongInt; |
109 Score, i: LongInt; |
129 end |
172 end |
130 end; |
173 end; |
131 |
174 |
132 procedure Walk(Me: PGear); |
175 procedure Walk(Me: PGear); |
133 const FallPixForBranching = cHHRadius * 2 + 8; |
176 const FallPixForBranching = cHHRadius * 2 + 8; |
134 cBranchStackSize = 12; |
|
135 |
|
136 type TStackEntry = record |
|
137 WastedTicks: Longword; |
|
138 MadeActions: TActions; |
|
139 Hedgehog: TGear; |
|
140 end; |
|
141 |
|
142 var Stack: record |
|
143 Count: Longword; |
|
144 States: array[0..Pred(cBranchStackSize)] of TStackEntry; |
|
145 end; |
|
146 |
|
147 function Push(Ticks: Longword; const Actions: TActions; const Me: TGear; Dir: integer): boolean; |
|
148 var bRes: boolean; |
|
149 begin |
|
150 bRes:= (Stack.Count < cBranchStackSize) and (Actions.Count < MAXACTIONS - 5); |
|
151 if bRes then |
|
152 with Stack.States[Stack.Count] do |
|
153 begin |
|
154 WastedTicks:= Ticks; |
|
155 MadeActions:= Actions; |
|
156 Hedgehog:= Me; |
|
157 Hedgehog.Message:= Dir; |
|
158 inc(Stack.Count) |
|
159 end; |
|
160 Push:= bRes |
|
161 end; |
|
162 |
|
163 procedure Pop(var Ticks: Longword; var Actions: TActions; var Me: TGear); |
|
164 begin |
|
165 dec(Stack.Count); |
|
166 with Stack.States[Stack.Count] do |
|
167 begin |
|
168 Ticks:= WastedTicks; |
|
169 Actions:= MadeActions; |
|
170 Me:= Hedgehog |
|
171 end |
|
172 end; |
|
173 |
|
174 var Actions: TActions; |
177 var Actions: TActions; |
175 ticks, maxticks, steps, tmp: Longword; |
178 ticks, maxticks, steps, tmp: Longword; |
176 BaseRate, BestRate, Rate: integer; |
179 BaseRate, BestRate, Rate: integer; |
177 GoInfo: TGoInfo; |
180 GoInfo: TGoInfo; |
178 CanGo: boolean; |
181 CanGo: boolean; |
179 AltMe: TGear; |
182 AltMe: TGear; |
180 BotLevel: Byte; |
183 BotLevel: Byte; |
|
184 a: TAmmoType; |
181 begin |
185 begin |
182 ticks:= 0; // avoid compiler hint |
186 ticks:= 0; // avoid compiler hint |
183 Actions.Count:= 0; |
187 Actions.Count:= 0; |
184 Actions.Pos:= 0; |
188 Actions.Pos:= 0; |
185 Actions.Score:= 0; |
189 Actions.Score:= 0; |
186 Stack.Count:= 0; |
190 Stack.Count:= 0; |
|
191 |
|
192 for a:= Low(TAmmoType) to High(TAmmoType) do |
|
193 CanUseAmmo[a]:= Assigned(AmmoTests[a].proc) and HHHasAmmo(Me^.Hedgehog^, a); |
|
194 |
187 BotLevel:= Me^.Hedgehog^.BotLevel; |
195 BotLevel:= Me^.Hedgehog^.BotLevel; |
188 |
196 |
189 tmp:= random(2) + 1; |
197 tmp:= random(2) + 1; |
190 Push(0, Actions, Me^, tmp); |
198 Push(0, Actions, Me^, tmp); |
191 Push(0, Actions, Me^, tmp xor 3); |
199 Push(0, Actions, Me^, tmp xor 3); |
287 Think:= 0; |
295 Think:= 0; |
288 InterlockedDecrement(hasThread) |
296 InterlockedDecrement(hasThread) |
289 end; |
297 end; |
290 |
298 |
291 procedure StartThink(Me: PGear); |
299 procedure StartThink(Me: PGear); |
292 var a: TAmmoType; |
|
293 begin |
300 begin |
294 if ((Me^.State and (gstAttacking or gstHHJumping or gstMoving)) <> 0) |
301 if ((Me^.State and (gstAttacking or gstHHJumping or gstMoving)) <> 0) |
295 or isInMultiShoot then exit; |
302 or isInMultiShoot then exit; |
296 |
303 |
297 //DeleteCI(Me); // this might break demo |
304 //DeleteCI(Me); // this might break demo |
311 OutError('AI: no targets!?', false); |
318 OutError('AI: no targets!?', false); |
312 exit |
319 exit |
313 end; |
320 end; |
314 |
321 |
315 FillBonuses((Me^.State and gstAttacked) <> 0); |
322 FillBonuses((Me^.State and gstAttacked) <> 0); |
316 for a:= Low(TAmmoType) to High(TAmmoType) do |
|
317 CanUseAmmo[a]:= Assigned(AmmoTests[a].proc) and HHHasAmmo(Me^.Hedgehog^, a); |
|
318 AddFileLog('Enter Think Thread'); |
323 AddFileLog('Enter Think Thread'); |
319 BeginThread(@Think, Me, ThinkThread) |
324 BeginThread(@Think, Me, ThinkThread) |
320 end; |
325 end; |
321 |
326 |
322 procedure ProcessBot; |
327 procedure ProcessBot; |