589
|
1 |
(*
|
|
2 |
* Hedgewars, a worms-like game
|
|
3 |
* Copyright (c) 2007 Andrey Korotaev <unC0Rr@gmail.com>
|
|
4 |
*
|
|
5 |
* This program is free software; you can redistribute it and/or modify
|
|
6 |
* it under the terms of the GNU General Public License as published by
|
|
7 |
* the Free Software Foundation; version 2 of the License
|
|
8 |
*
|
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
* GNU General Public License for more details.
|
|
13 |
*
|
|
14 |
* You should have received a copy of the GNU General Public License
|
|
15 |
* along with this program; if not, write to the Free Software
|
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
17 |
*)
|
|
18 |
|
|
19 |
unit uTriggers;
|
|
20 |
|
|
21 |
interface
|
|
22 |
uses SDLh, uConsts;
|
|
23 |
{$INCLUDE options.inc}
|
593
|
24 |
const trigTurns = $80000001;
|
589
|
25 |
|
593
|
26 |
procedure AddTrigger(id, Ticks: Longword);
|
|
27 |
procedure TickTrigger(id: Longword);
|
589
|
28 |
|
|
29 |
implementation
|
593
|
30 |
uses uGears, uFloat, uMisc;
|
589
|
31 |
type PTrigger = ^TTrigger;
|
|
32 |
TTrigger = record
|
|
33 |
id: Longword;
|
593
|
34 |
Ticks: Longword;
|
589
|
35 |
Next: PTrigger;
|
|
36 |
end;
|
|
37 |
var TriggerList: PTrigger = nil;
|
|
38 |
|
593
|
39 |
procedure AddTrigger(id, Ticks: Longword);
|
589
|
40 |
var tmp: PTrigger;
|
|
41 |
begin
|
593
|
42 |
if (Ticks = 0) then exit;
|
|
43 |
{$IFDEF DEBUGFILE}AddFileLog('Add trigger: ' + inttostr(id));{$ENDIF}
|
589
|
44 |
new(tmp);
|
|
45 |
FillChar(tmp^, sizeof(TGear), 0);
|
|
46 |
|
|
47 |
tmp^.id:= id;
|
593
|
48 |
tmp^.Ticks:= Ticks;
|
589
|
49 |
if TriggerList <> nil then tmp^.Next:= TriggerList;
|
|
50 |
TriggerList:= tmp
|
|
51 |
end;
|
|
52 |
|
593
|
53 |
procedure TickTriggerT(Trigger: PTrigger);
|
|
54 |
begin
|
|
55 |
AddGear(1024, -140, gtTarget, 0, _0, _0, 0)
|
|
56 |
end;
|
|
57 |
|
|
58 |
procedure TickTrigger(id: Longword);
|
|
59 |
var t, tt: PTrigger;
|
589
|
60 |
begin
|
593
|
61 |
t:= TriggerList;
|
|
62 |
|
|
63 |
while (t <> nil) do
|
|
64 |
begin
|
|
65 |
if t^.id = id then
|
|
66 |
begin
|
|
67 |
tt:= t;
|
|
68 |
dec(t^.Ticks);
|
|
69 |
if (t^.Ticks = 0) then
|
|
70 |
begin
|
|
71 |
TickTriggerT(t);
|
|
72 |
if t = TriggerList then TriggerList:= t^.Next
|
|
73 |
else tt^.Next:= t^.Next;
|
|
74 |
Dispose(t)
|
|
75 |
end
|
|
76 |
else t:= t^.Next
|
|
77 |
end else t:= t^.Next
|
|
78 |
end
|
589
|
79 |
end;
|
|
80 |
|
|
81 |
end. |