author | unc0rr |
Fri, 23 Jun 2006 20:02:41 +0000 | |
changeset 70 | 82d93eeecebe |
parent 66 | 9643d75baf1e |
child 71 | 5f56c6979496 |
permissions | -rw-r--r-- |
4 | 1 |
unit uAIActions; |
2 |
interface |
|
64 | 3 |
uses uGears; |
4 |
const MAXACTIONS = 256; |
|
5 |
aia_none = 0; |
|
4 | 6 |
aia_Left = 1; |
7 |
aia_Right = 2; |
|
8 |
aia_Timer = 3; |
|
70 | 9 |
aia_attack = 4; |
10 |
aia_Up = 5; |
|
11 |
aia_Down = 6; |
|
4 | 12 |
|
13 |
aia_Weapon = $80000000; |
|
14 |
aia_WaitX = $80000001; |
|
15 |
aia_WaitY = $80000002; |
|
16 |
aia_LookLeft = $80000003; |
|
17 |
aia_LookRight = $80000004; |
|
18 |
||
19 |
aim_push = $80000000; |
|
20 |
aim_release = $80000001; |
|
21 |
ai_specmask = $80000000; |
|
22 |
||
64 | 23 |
type TAction = record |
4 | 24 |
Action, Param: Longword; |
25 |
Time: Longword; |
|
26 |
end; |
|
64 | 27 |
TActions = record |
28 |
Count, Pos: Longword; |
|
29 |
actions: array[0..Pred(MAXACTIONS)] of TAction; |
|
30 |
Score: integer; |
|
31 |
end; |
|
4 | 32 |
|
64 | 33 |
procedure AddAction(var Actions: TActions; Action, Param, TimeDelta: Longword); |
34 |
procedure ProcessAction(var Actions: TActions; Me: PGear); |
|
4 | 35 |
|
36 |
implementation |
|
64 | 37 |
uses uMisc, uTeams, uConsts, uConsole; |
4 | 38 |
|
70 | 39 |
const ActionIdToStr: array[0..6] of string[16] = ( |
4 | 40 |
{aia_none} '', |
41 |
{aia_Left} 'left', |
|
42 |
{aia_Right} 'right', |
|
43 |
{aia_Timer} 'timer', |
|
44 |
{aia_attack} 'attack', |
|
45 |
{aia_Up} 'up', |
|
46 |
{aia_Down} 'down' |
|
64 | 47 |
); |
4 | 48 |
|
64 | 49 |
procedure AddAction(var Actions: TActions; Action, Param, TimeDelta: Longword); |
4 | 50 |
begin |
64 | 51 |
with Actions do |
52 |
begin |
|
53 |
actions[Count].Action:= Action; |
|
54 |
actions[Count].Param:= Param; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
55 |
if Count > 0 then actions[Count].Time:= TimeDelta |
64 | 56 |
else actions[Count].Time:= GameTicks + TimeDelta; |
57 |
inc(Count); |
|
58 |
TryDo(Count < MAXACTIONS, 'AI: actions overflow', true); |
|
59 |
end |
|
4 | 60 |
end; |
61 |
||
62 |
procedure SetWeapon(weap: Longword); |
|
63 |
begin |
|
64 |
with CurrentTeam^ do |
|
65 |
with Hedgehogs[CurrHedgehog] do |
|
70 | 66 |
while Ammo[CurSlot, CurAmmo].AmmoType <> TAmmoType(weap) do |
4 | 67 |
ParseCommand('/slot ' + chr(49 + Ammoz[TAmmoType(weap)].Slot)); |
68 |
end; |
|
69 |
||
64 | 70 |
procedure ProcessAction(var Actions: TActions; Me: PGear); |
4 | 71 |
var s: shortstring; |
72 |
begin |
|
64 | 73 |
if Actions.Pos >= Actions.Count then exit; |
74 |
with Actions.actions[Actions.Pos] do |
|
4 | 75 |
begin |
76 |
if Time > GameTicks then exit; |
|
77 |
if (Action and ai_specmask) <> 0 then |
|
78 |
case Action of |
|
79 |
aia_Weapon: SetWeapon(Param); |
|
64 | 80 |
aia_WaitX: if round(Me.X) = Param then Time:= GameTicks |
81 |
else exit; |
|
82 |
aia_WaitY: if round(Me.Y) = Param then Time:= GameTicks |
|
83 |
else exit; |
|
84 |
aia_LookLeft: if Me.dX >= 0 then |
|
85 |
begin |
|
86 |
ParseCommand('+left'); |
|
87 |
exit |
|
88 |
end else ParseCommand('-left'); |
|
89 |
aia_LookRight: if Me.dX < 0 then |
|
90 |
begin |
|
91 |
ParseCommand('+right'); |
|
92 |
exit |
|
93 |
end else ParseCommand('-right'); |
|
4 | 94 |
end else |
95 |
begin |
|
96 |
s:= ActionIdToStr[Action]; |
|
97 |
if (Param and ai_specmask) <> 0 then |
|
98 |
case Param of |
|
99 |
aim_push: s:= '+' + s; |
|
100 |
aim_release: s:= '-' + s; |
|
101 |
end |
|
102 |
else if Param <> 0 then s:= s + ' ' + inttostr(Param); |
|
103 |
ParseCommand(s) |
|
104 |
end |
|
105 |
end; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
106 |
inc(Actions.Pos); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
107 |
if Actions.Pos <= Actions.Count then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
108 |
inc(Actions.actions[Actions.Pos].Time, GameTicks) |
4 | 109 |
end; |
110 |
||
111 |
end. |