112 if not Pop(ticks, Actions, Me^) then |
112 if not Pop(ticks, Actions, Me^) then |
113 begin |
113 begin |
114 isThinking:= false; |
114 isThinking:= false; |
115 exit |
115 exit |
116 end; |
116 end; |
|
117 if ((Me.State and gstAttacked) = 0) then TestAmmos(Actions, Me); |
|
118 |
117 AddAction(Actions, Me.Message, aim_push, 250); |
119 AddAction(Actions, Me.Message, aim_push, 250); |
118 AddAction(Actions, aia_WaitX, round(Me.X), 0); |
120 if (Me.Message and gm_Left) <> 0 then AddAction(Actions, aia_WaitXL, round(Me.X), 0) |
|
121 else AddAction(Actions, aia_WaitXR, round(Me.X), 0); |
119 AddAction(Actions, Me.Message, aim_release, 0); |
122 AddAction(Actions, Me.Message, aim_release, 0); |
120 steps:= 0; |
123 steps:= 0; |
121 |
124 |
122 while not PosInThinkStack(Me) do |
125 while not PosInThinkStack(Me) do |
123 begin |
126 begin |
124 if SDL_GetTicks - AIThinkStart > 3 then |
127 if SDL_GetTicks - AIThinkStart > 3 then |
125 begin |
128 begin |
126 writetoconsole(inttostr(SDL_GetTicks - AIThinkStart) + ' '); |
|
127 dec(Actions.Count, 3); |
129 dec(Actions.Count, 3); |
128 Push(ticks, Actions, Me^, Me^.Message); |
130 Push(ticks, Actions, Me^, Me^.Message); |
129 exit |
131 exit |
130 end; |
132 end; |
131 |
133 |
132 CanGo:= HHGo(Me, @AltMe, GoInfo); |
134 CanGo:= HHGo(Me, @AltMe, GoInfo); |
133 inc(ticks, GoInfo.Ticks); |
135 inc(ticks, GoInfo.Ticks); |
134 if ticks > maxticks then break; |
136 if ticks > maxticks then break; |
135 |
137 |
136 if (BotLevel < 5) and (GoInfo.JumpType = jmpHJump) then // hjump support |
138 if (BotLevel < 5) and (GoInfo.JumpType = jmpHJump) then // hjump support |
155 BestActions.Score:= 1; |
157 BestActions.Score:= 1; |
156 isThinking:= false; |
158 isThinking:= false; |
157 exit |
159 exit |
158 end |
160 end |
159 else if Rate < BaseRate then break; |
161 else if Rate < BaseRate then break; |
|
162 if GoInfo.FallPix >= FallPixForBranching then |
|
163 Push(ticks, Actions, Me^, Me^.Message xor 3); // aia_Left xor 3 = aia_Right |
|
164 |
160 if ((Me.State and gstAttacked) = 0) |
165 if ((Me.State and gstAttacked) = 0) |
161 and ((steps mod 4) = 0) then TestAmmos(Actions, Me); |
166 and ((steps mod 4) = 0) then TestAmmos(Actions, Me); |
162 if GoInfo.FallPix >= FallPixForBranching then |
|
163 Push(ticks, Actions, Me^, Me^.Message xor 3); // aia_Left xor 3 = aia_Right |
|
164 end; |
167 end; |
165 until false |
168 until false |
166 end; |
169 end; |
167 |
170 |
168 procedure Think(Me: PGear); |
171 procedure Think(Me: PGear); |
169 var BackMe, WalkMe: TGear; |
172 var BackMe, WalkMe: TGear; |
170 // StartTicks: Longword; |
|
171 begin |
173 begin |
172 AIThinkStart:= SDL_GetTicks; |
174 AIThinkStart:= SDL_GetTicks; |
173 BackMe:= Me^; |
175 BackMe:= Me^; |
174 WalkMe:= BackMe; |
176 WalkMe:= BackMe; |
175 if (Me.State and gstAttacked) = 0 then |
177 if (Me.State and gstAttacked) = 0 then |
181 if BestActions.Score < -1023 then |
183 if BestActions.Score < -1023 then |
182 begin |
184 begin |
183 BestActions.Count:= 0; |
185 BestActions.Count:= 0; |
184 AddAction(BestActions, aia_Skip, 0, 250); |
186 AddAction(BestActions, aia_Skip, 0, 250); |
185 end; |
187 end; |
186 Me.State:= Me.State and not gstHHThinking |
|
187 end |
188 end |
188 end else |
189 end else |
189 else begin |
190 else begin |
190 FillBonuses(true); |
191 FillBonuses(true); |
191 Walk(@WalkMe) |
192 Walk(@WalkMe); |
|
193 AddAction(BestActions, aia_Wait, GameTicks + 100, 100); |
192 end |
194 end |
193 end; |
195 end; |
194 |
196 |
195 procedure StartThink(Me: PGear); |
197 procedure StartThink(Me: PGear); |
196 var a: TAmmoType; |
198 var a: TAmmoType; |
217 CanUseAmmo[a]:= Assigned(AmmoTests[a]) and HHHasAmmo(PHedgehog(Me.Hedgehog), a); |
219 CanUseAmmo[a]:= Assigned(AmmoTests[a]) and HHHasAmmo(PHedgehog(Me.Hedgehog), a); |
218 |
220 |
219 BestActions.Count:= 0; |
221 BestActions.Count:= 0; |
220 BestActions.Pos:= 0; |
222 BestActions.Pos:= 0; |
221 BestActions.Score:= 0; |
223 BestActions.Score:= 0; |
|
224 AddAction(BestActions, aia_Wait, GameTicks + 1500{ + Longword(random(1000))}, 1500); |
222 tmp:= random(2) + 1; |
225 tmp:= random(2) + 1; |
223 Push(0, BestActions, Me^, tmp); |
226 Push(0, BestActions, Me^, tmp); |
224 Push(0, BestActions, Me^, tmp xor 3); |
227 Push(0, BestActions, Me^, tmp xor 3); |
|
228 BestActions.Count:= 0; |
225 BestActions.Score:= Low(integer); |
229 BestActions.Score:= Low(integer); |
226 |
230 |
227 Think(Me) |
231 Think(Me) |
228 end; |
232 end; |
229 |
233 |
230 procedure ProcessBot(FrameNo: Longword); |
234 procedure ProcessBot(FrameNo: Longword); |
231 const LastFrameNo: Longword = 0; |
235 const LastFrameNo: Longword = 0; |
232 begin |
236 begin |
233 if FrameNo = LastFrameNo then exit; |
|
234 LastFrameNo:= FrameNo; |
|
235 with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do |
237 with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do |
236 if (Gear <> nil) |
238 if (Gear <> nil) |
237 and ((Gear.State and gstHHDriven) <> 0) |
239 and ((Gear.State and gstHHDriven) <> 0) |
238 and (TurnTimeLeft < cHedgehogTurnTime - 50) then |
240 and (TurnTimeLeft < cHedgehogTurnTime - 50) then |
239 if not isThinking then |
241 if not isThinking then |
240 if (BestActions.Pos >= BestActions.Count) then StartThink(Gear) |
242 if (BestActions.Pos >= BestActions.Count) then StartThink(Gear) |
241 else ProcessAction(BestActions, Gear) |
243 else ProcessAction(BestActions, Gear) |
242 else Think(Gear) |
244 else if FrameNo <> LastFrameNo then |
|
245 begin |
|
246 LastFrameNo:= FrameNo; |
|
247 Think(Gear) |
|
248 end; |
243 end; |
249 end; |
244 |
250 |
245 end. |
251 end. |