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 |
|
594
|
26 |
procedure AddTrigger(id, Ticks, Lives: Longword);
|
593
|
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;
|
594
|
35 |
Lives: Longword;
|
|
36 |
TicksPerLife: LongWord;
|
589
|
37 |
Next: PTrigger;
|
|
38 |
end;
|
|
39 |
var TriggerList: PTrigger = nil;
|
|
40 |
|
594
|
41 |
procedure AddTrigger(id, Ticks, Lives: Longword);
|
589
|
42 |
var tmp: PTrigger;
|
|
43 |
begin
|
594
|
44 |
if (Ticks = 0) or (Lives = 0) then exit;
|
593
|
45 |
{$IFDEF DEBUGFILE}AddFileLog('Add trigger: ' + inttostr(id));{$ENDIF}
|
589
|
46 |
new(tmp);
|
|
47 |
FillChar(tmp^, sizeof(TGear), 0);
|
|
48 |
|
|
49 |
tmp^.id:= id;
|
593
|
50 |
tmp^.Ticks:= Ticks;
|
594
|
51 |
tmp^.TicksPerLife:= Ticks;
|
|
52 |
tmp^.Lives:= Lives;
|
589
|
53 |
if TriggerList <> nil then tmp^.Next:= TriggerList;
|
|
54 |
TriggerList:= tmp
|
|
55 |
end;
|
|
56 |
|
593
|
57 |
procedure TickTriggerT(Trigger: PTrigger);
|
|
58 |
begin
|
|
59 |
AddGear(1024, -140, gtTarget, 0, _0, _0, 0)
|
|
60 |
end;
|
|
61 |
|
|
62 |
procedure TickTrigger(id: Longword);
|
594
|
63 |
var t, pt, nt: PTrigger;
|
589
|
64 |
begin
|
593
|
65 |
t:= TriggerList;
|
594
|
66 |
pt:= nil;
|
593
|
67 |
|
|
68 |
while (t <> nil) do
|
|
69 |
begin
|
594
|
70 |
nt:= t^.Next;
|
|
71 |
if (t^.id = id) then
|
593
|
72 |
begin
|
|
73 |
dec(t^.Ticks);
|
|
74 |
if (t^.Ticks = 0) then
|
|
75 |
begin
|
|
76 |
TickTriggerT(t);
|
594
|
77 |
dec(t^.Lives);
|
|
78 |
t^.Ticks:= t^.TicksPerLife;
|
|
79 |
if (t^.Lives = 0) then
|
|
80 |
begin
|
|
81 |
if t = TriggerList then TriggerList:= nt
|
|
82 |
else pt^.Next:= nt;
|
|
83 |
Dispose(t)
|
|
84 |
end
|
593
|
85 |
end
|
594
|
86 |
end;
|
|
87 |
pt:= t;
|
|
88 |
t:= nt
|
593
|
89 |
end
|
589
|
90 |
end;
|
|
91 |
|
|
92 |
end. |