author | unc0rr |
Sat, 22 Sep 2007 09:49:55 +0000 | |
changeset 605 | 2651c3fe4567 |
parent 595 | 5ee863f2f568 |
child 610 | 9b5a6200f667 |
permissions | -rw-r--r-- |
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 |
|
595
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
26 |
type TTrigAction = (taSpawnGear); |
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
27 |
|
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
28 |
procedure AddTriggerSpawner(id, Ticks, Lives: Longword; X, Y: LongInt; GearType: TGearType; GearTriggerId: Longword); |
593 | 29 |
procedure TickTrigger(id: Longword); |
589 | 30 |
|
31 |
implementation |
|
593 | 32 |
uses uGears, uFloat, uMisc; |
589 | 33 |
type PTrigger = ^TTrigger; |
34 |
TTrigger = record |
|
35 |
id: Longword; |
|
593 | 36 |
Ticks: Longword; |
594 | 37 |
Lives: Longword; |
38 |
TicksPerLife: LongWord; |
|
595
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
39 |
Action: TTrigAction; |
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
40 |
X, Y: LongInt; |
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
41 |
SpawnGearType: TGearType; |
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
42 |
SpawnGearTriggerId: Longword; |
589 | 43 |
Next: PTrigger; |
44 |
end; |
|
45 |
var TriggerList: PTrigger = nil; |
|
46 |
||
595
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
47 |
procedure AddTriggerSpawner(id, Ticks, Lives: Longword; X, Y: LongInt; GearType: TGearType; GearTriggerId: Longword); |
589 | 48 |
var tmp: PTrigger; |
49 |
begin |
|
594 | 50 |
if (Ticks = 0) or (Lives = 0) then exit; |
595
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
51 |
{$IFDEF DEBUGFILE}AddFileLog('Add spawner trigger: ' + inttostr(id) + ', gear triggers ' + inttostr(GearTriggerId));{$ENDIF} |
589 | 52 |
new(tmp); |
595
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
53 |
FillChar(tmp^, sizeof(TTrigger), 0); |
589 | 54 |
|
55 |
tmp^.id:= id; |
|
593 | 56 |
tmp^.Ticks:= Ticks; |
594 | 57 |
tmp^.TicksPerLife:= Ticks; |
58 |
tmp^.Lives:= Lives; |
|
595
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
59 |
tmp^.Action:= taSpawnGear; |
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
60 |
tmp^.X:= X; |
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
61 |
tmp^.Y:= Y; |
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
62 |
tmp^.SpawnGearType:= GearType; |
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
63 |
tmp^.SpawnGearTriggerId:= GearTriggerId; |
589 | 64 |
if TriggerList <> nil then tmp^.Next:= TriggerList; |
65 |
TriggerList:= tmp |
|
66 |
end; |
|
67 |
||
593 | 68 |
procedure TickTriggerT(Trigger: PTrigger); |
69 |
begin |
|
595
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
70 |
with Trigger^ do |
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
71 |
case Action of |
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
72 |
taSpawnGear: AddGear(X, Y, SpawnGearType, 0, _0, _0, 0)^.TriggerId:= SpawnGearTriggerId; |
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
73 |
end |
593 | 74 |
end; |
75 |
||
76 |
procedure TickTrigger(id: Longword); |
|
594 | 77 |
var t, pt, nt: PTrigger; |
589 | 78 |
begin |
593 | 79 |
t:= TriggerList; |
594 | 80 |
pt:= nil; |
593 | 81 |
|
82 |
while (t <> nil) do |
|
83 |
begin |
|
594 | 84 |
nt:= t^.Next; |
85 |
if (t^.id = id) then |
|
593 | 86 |
begin |
87 |
dec(t^.Ticks); |
|
88 |
if (t^.Ticks = 0) then |
|
89 |
begin |
|
90 |
TickTriggerT(t); |
|
594 | 91 |
dec(t^.Lives); |
92 |
t^.Ticks:= t^.TicksPerLife; |
|
93 |
if (t^.Lives = 0) then |
|
94 |
begin |
|
95 |
if t = TriggerList then TriggerList:= nt |
|
96 |
else pt^.Next:= nt; |
|
97 |
Dispose(t) |
|
98 |
end |
|
593 | 99 |
end |
594 | 100 |
end; |
101 |
pt:= t; |
|
102 |
t:= nt |
|
593 | 103 |
end |
589 | 104 |
end; |
105 |
||
106 |
end. |