author | unc0rr |
Tue, 11 Jul 2006 21:04:05 +0000 | |
changeset 75 | d2b737858ff7 |
parent 74 | 42257fee61ae |
child 80 | 3c3dc6a148ca |
permissions | -rw-r--r-- |
71 | 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 |
||
4 | 34 |
unit uAIActions; |
35 |
interface |
|
64 | 36 |
uses uGears; |
75 | 37 |
const MAXACTIONS = 96; |
64 | 38 |
aia_none = 0; |
4 | 39 |
aia_Left = 1; |
40 |
aia_Right = 2; |
|
41 |
aia_Timer = 3; |
|
70 | 42 |
aia_attack = 4; |
43 |
aia_Up = 5; |
|
44 |
aia_Down = 6; |
|
4 | 45 |
|
46 |
aia_Weapon = $80000000; |
|
47 |
aia_WaitX = $80000001; |
|
48 |
aia_WaitY = $80000002; |
|
49 |
aia_LookLeft = $80000003; |
|
50 |
aia_LookRight = $80000004; |
|
71 | 51 |
aia_AwareExpl = $80000005; |
4 | 52 |
|
53 |
aim_push = $80000000; |
|
54 |
aim_release = $80000001; |
|
55 |
ai_specmask = $80000000; |
|
56 |
||
64 | 57 |
type TAction = record |
4 | 58 |
Action, Param: Longword; |
71 | 59 |
X, Y: integer; |
4 | 60 |
Time: Longword; |
61 |
end; |
|
64 | 62 |
TActions = record |
63 |
Count, Pos: Longword; |
|
64 |
actions: array[0..Pred(MAXACTIONS)] of TAction; |
|
65 |
Score: integer; |
|
66 |
end; |
|
4 | 67 |
|
71 | 68 |
procedure AddAction(var Actions: TActions; Action, Param, TimeDelta: Longword; const X: integer = 0; Y: integer = 0); |
64 | 69 |
procedure ProcessAction(var Actions: TActions; Me: PGear); |
4 | 70 |
|
71 |
implementation |
|
71 | 72 |
uses uMisc, uTeams, uConsts, uConsole, uAIMisc; |
4 | 73 |
|
70 | 74 |
const ActionIdToStr: array[0..6] of string[16] = ( |
4 | 75 |
{aia_none} '', |
76 |
{aia_Left} 'left', |
|
77 |
{aia_Right} 'right', |
|
78 |
{aia_Timer} 'timer', |
|
79 |
{aia_attack} 'attack', |
|
80 |
{aia_Up} 'up', |
|
81 |
{aia_Down} 'down' |
|
64 | 82 |
); |
4 | 83 |
|
71 | 84 |
procedure AddAction(var Actions: TActions; Action, Param, TimeDelta: Longword; const X: integer = 0; Y: integer = 0); |
4 | 85 |
begin |
64 | 86 |
with Actions do |
87 |
begin |
|
88 |
actions[Count].Action:= Action; |
|
89 |
actions[Count].Param:= Param; |
|
71 | 90 |
actions[Count].X:= X; |
91 |
actions[Count].Y:= Y; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
92 |
if Count > 0 then actions[Count].Time:= TimeDelta |
64 | 93 |
else actions[Count].Time:= GameTicks + TimeDelta; |
94 |
inc(Count); |
|
95 |
TryDo(Count < MAXACTIONS, 'AI: actions overflow', true); |
|
96 |
end |
|
4 | 97 |
end; |
98 |
||
99 |
procedure SetWeapon(weap: Longword); |
|
100 |
begin |
|
101 |
with CurrentTeam^ do |
|
102 |
with Hedgehogs[CurrHedgehog] do |
|
70 | 103 |
while Ammo[CurSlot, CurAmmo].AmmoType <> TAmmoType(weap) do |
4 | 104 |
ParseCommand('/slot ' + chr(49 + Ammoz[TAmmoType(weap)].Slot)); |
105 |
end; |
|
106 |
||
64 | 107 |
procedure ProcessAction(var Actions: TActions; Me: PGear); |
4 | 108 |
var s: shortstring; |
109 |
begin |
|
64 | 110 |
if Actions.Pos >= Actions.Count then exit; |
111 |
with Actions.actions[Actions.Pos] do |
|
4 | 112 |
begin |
113 |
if Time > GameTicks then exit; |
|
114 |
if (Action and ai_specmask) <> 0 then |
|
115 |
case Action of |
|
116 |
aia_Weapon: SetWeapon(Param); |
|
64 | 117 |
aia_WaitX: if round(Me.X) = Param then Time:= GameTicks |
118 |
else exit; |
|
119 |
aia_WaitY: if round(Me.Y) = Param then Time:= GameTicks |
|
120 |
else exit; |
|
121 |
aia_LookLeft: if Me.dX >= 0 then |
|
122 |
begin |
|
123 |
ParseCommand('+left'); |
|
124 |
exit |
|
125 |
end else ParseCommand('-left'); |
|
126 |
aia_LookRight: if Me.dX < 0 then |
|
127 |
begin |
|
128 |
ParseCommand('+right'); |
|
129 |
exit |
|
130 |
end else ParseCommand('-right'); |
|
71 | 131 |
aia_AwareExpl: AwareOfExplosion(X, Y, Param); |
4 | 132 |
end else |
133 |
begin |
|
134 |
s:= ActionIdToStr[Action]; |
|
135 |
if (Param and ai_specmask) <> 0 then |
|
136 |
case Param of |
|
137 |
aim_push: s:= '+' + s; |
|
138 |
aim_release: s:= '-' + s; |
|
139 |
end |
|
140 |
else if Param <> 0 then s:= s + ' ' + inttostr(Param); |
|
141 |
ParseCommand(s) |
|
142 |
end |
|
143 |
end; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
144 |
inc(Actions.Pos); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
145 |
if Actions.Pos <= Actions.Count then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
146 |
inc(Actions.actions[Actions.Pos].Time, GameTicks) |
4 | 147 |
end; |
148 |
||
149 |
end. |