|
1 (* |
|
2 * Hedgewars, a worms-like game |
|
3 * Copyright (c) 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com> |
|
4 * |
|
5 * Distributed under the terms of the BSD-modified licence: |
|
6 * |
|
7 * Permission is hereby granted, free of charge, to any person obtaining a copy |
|
8 * of this software and associated documentation files (the "Software"), to deal |
|
9 * with the Software without restriction, including without limitation the |
|
10 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
|
11 * sell copies of the Software, and to permit persons to whom the Software is |
|
12 * furnished to do so, subject to the following conditions: |
|
13 * |
|
14 * 1. Redistributions of source code must retain the above copyright notice, |
|
15 * this list of conditions and the following disclaimer. |
|
16 * 2. Redistributions in binary form must reproduce the above copyright notice, |
|
17 * this list of conditions and the following disclaimer in the documentation |
|
18 * and/or other materials provided with the distribution. |
|
19 * 3. The name of the author may not be used to endorse or promote products |
|
20 * derived from this software without specific prior written permission. |
|
21 * |
|
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
|
23 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
|
24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
|
25 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
|
28 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
|
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
|
30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|
31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
32 *) |
|
33 |
1 unit uAIActions; |
34 unit uAIActions; |
2 interface |
35 interface |
3 uses uGears; |
36 uses uGears; |
4 const MAXACTIONS = 256; |
37 const MAXACTIONS = 256; |
5 aia_none = 0; |
38 aia_none = 0; |
13 aia_Weapon = $80000000; |
46 aia_Weapon = $80000000; |
14 aia_WaitX = $80000001; |
47 aia_WaitX = $80000001; |
15 aia_WaitY = $80000002; |
48 aia_WaitY = $80000002; |
16 aia_LookLeft = $80000003; |
49 aia_LookLeft = $80000003; |
17 aia_LookRight = $80000004; |
50 aia_LookRight = $80000004; |
|
51 aia_AwareExpl = $80000005; |
18 |
52 |
19 aim_push = $80000000; |
53 aim_push = $80000000; |
20 aim_release = $80000001; |
54 aim_release = $80000001; |
21 ai_specmask = $80000000; |
55 ai_specmask = $80000000; |
22 |
56 |
23 type TAction = record |
57 type TAction = record |
24 Action, Param: Longword; |
58 Action, Param: Longword; |
|
59 X, Y: integer; |
25 Time: Longword; |
60 Time: Longword; |
26 end; |
61 end; |
27 TActions = record |
62 TActions = record |
28 Count, Pos: Longword; |
63 Count, Pos: Longword; |
29 actions: array[0..Pred(MAXACTIONS)] of TAction; |
64 actions: array[0..Pred(MAXACTIONS)] of TAction; |
30 Score: integer; |
65 Score: integer; |
31 end; |
66 end; |
32 |
67 |
33 procedure AddAction(var Actions: TActions; Action, Param, TimeDelta: Longword); |
68 procedure AddAction(var Actions: TActions; Action, Param, TimeDelta: Longword; const X: integer = 0; Y: integer = 0); |
34 procedure ProcessAction(var Actions: TActions; Me: PGear); |
69 procedure ProcessAction(var Actions: TActions; Me: PGear); |
35 |
70 |
36 implementation |
71 implementation |
37 uses uMisc, uTeams, uConsts, uConsole; |
72 uses uMisc, uTeams, uConsts, uConsole, uAIMisc; |
38 |
73 |
39 const ActionIdToStr: array[0..6] of string[16] = ( |
74 const ActionIdToStr: array[0..6] of string[16] = ( |
40 {aia_none} '', |
75 {aia_none} '', |
41 {aia_Left} 'left', |
76 {aia_Left} 'left', |
42 {aia_Right} 'right', |
77 {aia_Right} 'right', |
44 {aia_attack} 'attack', |
79 {aia_attack} 'attack', |
45 {aia_Up} 'up', |
80 {aia_Up} 'up', |
46 {aia_Down} 'down' |
81 {aia_Down} 'down' |
47 ); |
82 ); |
48 |
83 |
49 procedure AddAction(var Actions: TActions; Action, Param, TimeDelta: Longword); |
84 procedure AddAction(var Actions: TActions; Action, Param, TimeDelta: Longword; const X: integer = 0; Y: integer = 0); |
50 begin |
85 begin |
51 with Actions do |
86 with Actions do |
52 begin |
87 begin |
53 actions[Count].Action:= Action; |
88 actions[Count].Action:= Action; |
54 actions[Count].Param:= Param; |
89 actions[Count].Param:= Param; |
|
90 actions[Count].X:= X; |
|
91 actions[Count].Y:= Y; |
55 if Count > 0 then actions[Count].Time:= TimeDelta |
92 if Count > 0 then actions[Count].Time:= TimeDelta |
56 else actions[Count].Time:= GameTicks + TimeDelta; |
93 else actions[Count].Time:= GameTicks + TimeDelta; |
57 inc(Count); |
94 inc(Count); |
58 TryDo(Count < MAXACTIONS, 'AI: actions overflow', true); |
95 TryDo(Count < MAXACTIONS, 'AI: actions overflow', true); |
59 end |
96 end |
89 aia_LookRight: if Me.dX < 0 then |
126 aia_LookRight: if Me.dX < 0 then |
90 begin |
127 begin |
91 ParseCommand('+right'); |
128 ParseCommand('+right'); |
92 exit |
129 exit |
93 end else ParseCommand('-right'); |
130 end else ParseCommand('-right'); |
|
131 aia_AwareExpl: AwareOfExplosion(X, Y, Param); |
94 end else |
132 end else |
95 begin |
133 begin |
96 s:= ActionIdToStr[Action]; |
134 s:= ActionIdToStr[Action]; |
97 if (Param and ai_specmask) <> 0 then |
135 if (Param and ai_specmask) <> 0 then |
98 case Param of |
136 case Param of |