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