1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
22 SysUtils
, Variants
, Classes
,
23 MAPDEF
, e_graphics
, g_basic
, g_sound
,
24 xdynrec
, hashtable
, exoma
;
43 TexturePanelGUID
: Integer;
44 //TexturePanelType: Word;
48 Activators
: array of TActivator
;
49 PlayerCollide
: Boolean;
53 SoundPlayCount
: Integer;
54 Sound
: TPlayableSound
;
56 SpawnCooldown
: Integer;
57 SpawnedCount
: Integer;
58 //ShotPanelType: Word;
59 ShotPanelTime
: Integer;
60 ShotSightTime
: Integer;
61 ShotSightTimeout
: Integer;
62 ShotSightTarget
: Word;
63 ShotSightTargetN
: Word;
65 ShotReloadTime
: Integer;
67 mapId
: AnsiString; // trigger id, from map
68 mapIndex
: Integer; // index in fields['trigger'], used in save/load
69 trigPanelGUID
: Integer;
71 trigDataRec
: TDynRecord
; // triggerdata; owned by trigger (cloned)
72 exoInit
, exoThink
, exoCheck
, exoAction
: TExprBase
;
74 userVars
: THashStrVariant
;
76 {$INCLUDE ../shared/mapdef_tgc_def.inc}
79 function trigCenter (): TDFPoint
; inline;
82 function g_Triggers_Create (aTrigger
: TTrigger
; trec
: TDynRecord
; forceInternalIndex
: Integer=-1): DWORD
;
83 procedure g_Triggers_Update();
84 procedure g_Triggers_Press(ID
: DWORD
; ActivateType
: Byte; ActivateUID
: Word = 0);
85 function g_Triggers_PressR(X
, Y
: Integer; Width
, Height
: Word; UID
: Word;
86 ActivateType
: Byte; IgnoreList
: DWArray
= nil): DWArray
;
87 procedure g_Triggers_PressL(X1
, Y1
, X2
, Y2
: Integer; UID
: DWORD
; ActivateType
: Byte);
88 procedure g_Triggers_PressC(CX
, CY
: Integer; Radius
: Word; UID
: Word; ActivateType
: Byte; IgnoreTrigger
: Integer = -1);
89 procedure g_Triggers_OpenAll();
90 procedure g_Triggers_DecreaseSpawner(ID
: DWORD
);
91 procedure g_Triggers_Free();
92 procedure g_Triggers_SaveState (st
: TStream
);
93 procedure g_Triggers_LoadState (st
: TStream
);
97 gTriggerClientID
: Integer = 0;
98 gTriggers
: array of TTrigger
;
99 gSecretsCount
: Integer = 0;
100 gMonstersSpawned
: array of LongInt = nil;
107 g_player
, g_map
, g_panel
, g_gfx
, g_game
, g_textures
,
108 g_console
, g_monsters
, g_items
, g_phys
, g_weapons
,
109 wadreader
, g_main
, e_log
, g_language
,
110 g_options
, g_net
, g_netmsg
, utils
, xparser
, xstreams
;
113 TRIGGER_SIGNATURE
= $58475254; // 'TRGX'
116 {$INCLUDE ../shared/mapdef_tgc_impl.inc}
119 // ////////////////////////////////////////////////////////////////////////// //
121 TTrigScope
= class(TExprScope
)
124 monsprops
: TPropHash
;
125 platprops
: TPropHash
;
131 constructor Create ();
132 destructor Destroy (); override;
134 function getObj (const aname
: AnsiString): TObject
; override;
135 function getField (obj
: TObject
; const afldname
: AnsiString): Variant; override;
136 procedure setField (obj
: TObject
; const afldname
: AnsiString; var aval
: Variant); override;
140 // ////////////////////////////////////////////////////////////////////////// //
142 TMyConstList
= class(TExprConstList
)
144 function valid (const cname
: AnsiString): Boolean; override;
145 function get (const cname
: AnsiString; out v
: Variant): Boolean; override;
149 // ////////////////////////////////////////////////////////////////////////// //
150 function TMyConstList
.valid (const cname
: AnsiString): Boolean;
152 //writeln('CHECK: ''', cname, '''');
154 (cname
= 'player') or
159 function TMyConstList
.get (const cname
: AnsiString; out v
: Variant): Boolean;
164 //if (cname = 'answer') then begin v := LongInt(42); result := true; exit; end;
166 if (gCurrentMap
= nil) then exit
;
167 for eidx
:= 0 to gCurrentMap
.mapdef
.ebsTypeCount
-1 do
169 ebs
:= gCurrentMap
.mapdef
.ebsTypeAt
[eidx
];
170 if ebs
.has
[cname
] then
172 //writeln('FOUND: ''', cname, '''');
181 // ////////////////////////////////////////////////////////////////////////// //
182 constructor TTrigScope
.Create ();
184 plrprops
:= TPropHash
.Create(TPlayer
, 'e');
185 monsprops
:= TPropHash
.Create(TMonster
, 'e');
186 platprops
:= TPropHash
.Create(TPanel
, 'e');
191 destructor TTrigScope
.Destroy ();
200 function TTrigScope
.getObj (const aname
: AnsiString): TObject
;
202 if (aname
= 'player') then result
:= gPlayers
[0] //FIXME
203 else if (aname
= 'self') or (aname
= 'this') then result
:= TObject(Pointer(PtrUInt(1)))
204 else result
:= inherited getObj(aname
);
208 function TTrigScope
.getField (obj
: TObject
; const afldname
: AnsiString): Variant;
210 if (obj
= gPlayers
[0]) then
212 if plrprops
.get(obj
, afldname
, result
) then exit
;
214 else if (obj
= TObject(Pointer(PtrUInt(1)))) then
216 if (me
<> nil) and (me
.userVars
<> nil) then
218 if me
.userVars
.get(afldname
, result
) then exit
;
221 result
:= inherited getField(obj
, afldname
);
225 procedure TTrigScope
.setField (obj
: TObject
; const afldname
: AnsiString; var aval
: Variant);
227 if (obj
= gPlayers
[0]) then
229 if plrprops
.put(obj
, afldname
, aval
) then exit
;
231 else if (obj
= TObject(Pointer(PtrUInt(1)))) then
235 if (Length(afldname
) > 4) and (afldname
[1] = 'u') and (afldname
[2] = 's') and
236 (afldname
[3] = 'e') and (afldname
[4] = 'r') then
238 if (me
.userVars
= nil) then me
.userVars
:= THashStrVariant
.Create();
239 me
.userVars
.put(afldname
, aval
);
244 inherited setField(obj
, afldname
, aval
);
248 // ////////////////////////////////////////////////////////////////////////// //
250 tgscope
: TTrigScope
= nil;
251 tgclist
: TMyConstList
= nil;
254 // ////////////////////////////////////////////////////////////////////////// //
255 function TTrigger
.trigCenter (): TDFPoint
; inline;
257 result
:= TDFPoint
.Create(x
+width
div 2, y
+height
div 2);
261 function FindTrigger (): DWORD
;
265 olen
:= Length(gTriggers
);
267 for i
:= 0 to olen
-1 do
269 if gTriggers
[i
].TriggerType
= TRIGGER_NONE
then begin result
:= i
; exit
; end;
272 SetLength(gTriggers
, olen
+8);
275 for i
:= result
to High(gTriggers
) do
277 gTriggers
[i
].TriggerType
:= TRIGGER_NONE
;
278 gTriggers
[i
].trigDataRec
:= nil;
279 gTriggers
[i
].exoInit
:= nil;
280 gTriggers
[i
].exoThink
:= nil;
281 gTriggers
[i
].exoCheck
:= nil;
282 gTriggers
[i
].exoAction
:= nil;
283 gTriggers
[i
].userVars
:= nil;
288 function tr_CloseDoor (PanelGUID
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
295 pan
:= g_Map_PanelByGUID(PanelGUID
);
296 if (pan
= nil) or not pan
.isGWall
then exit
; //!FIXME!TRIGANY!
297 PanelID
:= pan
.arrIdx
;
301 with gWalls
[PanelID
] do
303 if g_CollidePlayer(X
, Y
, Width
, Height
) or g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then Exit
;
308 g_Sound_PlayExAt('SOUND_GAME_DOORCLOSE', X
, Y
);
309 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOORCLOSE');
311 g_Map_EnableWallGUID(PanelGUID
);
318 if (gDoorMap
= nil) then exit
;
321 for a
:= 0 to High(gDoorMap
) do
323 for b
:= 0 to High(gDoorMap
[a
]) do
325 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
331 if (c
<> -1) then break
;
333 if (c
= -1) then exit
;
335 for b
:= 0 to High(gDoorMap
[c
]) do
337 with gWalls
[gDoorMap
[c
, b
]] do
339 if g_CollidePlayer(X
, Y
, Width
, Height
) or g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then exit
;
345 for b
:= 0 to High(gDoorMap
[c
]) do
347 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
349 with gWalls
[PanelID
] do
351 g_Sound_PlayExAt('SOUND_GAME_DOORCLOSE', X
, Y
);
352 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOORCLOSE');
359 for b
:= 0 to High(gDoorMap
[c
]) do
361 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
363 g_Map_EnableWall_XXX(gDoorMap
[c
, b
]);
371 procedure tr_CloseTrap (PanelGUID
: Integer; NoSound
: Boolean; d2d
: Boolean);
374 wx
, wy
, wh
, ww
: Integer;
378 function monsDamage (mon
: TMonster
): Boolean;
380 result
:= false; // don't stop
381 if g_Obj_Collide(wx
, wy
, ww
, wh
, @mon
.Obj
) then mon
.Damage(TRAP_DAMAGE
, 0, 0, 0, HIT_TRAP
);
385 pan
:= g_Map_PanelByGUID(PanelGUID
);
389 e_LogWritefln('tr_CloseTrap: pguid=%s; NO PANEL!', [PanelGUID], MSG_WARNING);
393 e_LogWritefln('tr_CloseTrap: pguid=%s; isGWall=%s; arrIdx=%s', [PanelGUID, pan.isGWall, pan.arrIdx]);
396 if (pan
= nil) or not pan
.isGWall
then exit
; //!FIXME!TRIGANY!
397 PanelID
:= pan
.arrIdx
;
401 with gWalls
[PanelID
] do
403 if (not NoSound
) and (not Enabled
) then
405 g_Sound_PlayExAt('SOUND_GAME_SWITCH1', X
, Y
);
406 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_SWITCH1');
410 wx
:= gWalls
[PanelID
].X
;
411 wy
:= gWalls
[PanelID
].Y
;
412 ww
:= gWalls
[PanelID
].Width
;
413 wh
:= gWalls
[PanelID
].Height
;
415 with gWalls
[PanelID
] do
417 if gPlayers
<> nil then
419 for a
:= 0 to High(gPlayers
) do
421 if (gPlayers
[a
] <> nil) and gPlayers
[a
].alive
and gPlayers
[a
].Collide(X
, Y
, Width
, Height
) then
423 gPlayers
[a
].Damage(TRAP_DAMAGE
, 0, 0, 0, HIT_TRAP
);
428 //g_Mons_ForEach(monsDamage);
429 g_Mons_ForEachAliveAt(wx
, wy
, ww
, wh
, monsDamage
);
431 if not Enabled
then g_Map_EnableWallGUID(PanelGUID
);
436 if (gDoorMap
= nil) then exit
;
439 for a
:= 0 to High(gDoorMap
) do
441 for b
:= 0 to High(gDoorMap
[a
]) do
443 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
449 if (c
<> -1) then break
;
451 if (c
= -1) then exit
;
455 for b
:= 0 to High(gDoorMap
[c
]) do
457 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
459 with gWalls
[PanelID
] do
461 g_Sound_PlayExAt('SOUND_GAME_SWITCH1', X
, Y
);
462 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_SWITCH1');
469 for b
:= 0 to High(gDoorMap
[c
]) do
471 wx
:= gWalls
[gDoorMap
[c
, b
]].X
;
472 wy
:= gWalls
[gDoorMap
[c
, b
]].Y
;
473 ww
:= gWalls
[gDoorMap
[c
, b
]].Width
;
474 wh
:= gWalls
[gDoorMap
[c
, b
]].Height
;
476 with gWalls
[gDoorMap
[c
, b
]] do
478 if gPlayers
<> nil then
480 for a
:= 0 to High(gPlayers
) do
482 if (gPlayers
[a
] <> nil) and gPlayers
[a
].alive
and gPlayers
[a
].Collide(X
, Y
, Width
, Height
) then
484 gPlayers
[a
].Damage(TRAP_DAMAGE
, 0, 0, 0, HIT_TRAP
);
489 //g_Mons_ForEach(monsDamage);
490 g_Mons_ForEachAliveAt(wx
, wy
, ww
, wh
, monsDamage
);
492 if gMonsters <> nil then
493 for a := 0 to High(gMonsters) do
494 if (gMonsters[a] <> nil) and gMonsters[a].alive and
495 g_Obj_Collide(X, Y, Width, Height, @gMonsters[a].Obj) then
496 gMonsters[a].Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
499 if not Enabled
then g_Map_EnableWall_XXX(gDoorMap
[c
, b
]);
506 function tr_OpenDoor (PanelGUID
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
513 pan
:= g_Map_PanelByGUID(PanelGUID
);
514 if (pan
= nil) or not pan
.isGWall
then exit
; //!FIXME!TRIGANY!
515 PanelID
:= pan
.arrIdx
;
519 with gWalls
[PanelID
] do
525 g_Sound_PlayExAt('SOUND_GAME_DOOROPEN', X
, Y
);
526 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOOROPEN');
528 g_Map_DisableWallGUID(PanelGUID
);
535 if (gDoorMap
= nil) then exit
;
538 for a
:= 0 to High(gDoorMap
) do
540 for b
:= 0 to High(gDoorMap
[a
]) do
542 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
548 if (c
<> -1) then break
;
550 if (c
= -1) then exit
;
554 for b
:= 0 to High(gDoorMap
[c
]) do
556 if gWalls
[gDoorMap
[c
, b
]].Enabled
then
558 with gWalls
[PanelID
] do
560 g_Sound_PlayExAt('SOUND_GAME_DOOROPEN', X
, Y
);
561 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOOROPEN');
568 for b
:= 0 to High(gDoorMap
[c
]) do
570 if gWalls
[gDoorMap
[c
, b
]].Enabled
then
572 g_Map_DisableWall_XXX(gDoorMap
[c
, b
]);
580 function tr_SetLift (PanelGUID
: Integer; d
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
588 pan
:= g_Map_PanelByGUID(PanelGUID
);
589 if (pan
= nil) or not pan
.isGLift
then exit
; //!FIXME!TRIGANY!
590 PanelID
:= pan
.arrIdx
;
592 if (gLifts
[PanelID
].PanelType
= PANEL_LIFTUP
) or (gLifts
[PanelID
].PanelType
= PANEL_LIFTDOWN
) then
597 else t
:= IfThen(gLifts
[PanelID
].LiftType
= 1, 0, 1);
600 else if (gLifts
[PanelID
].PanelType
= PANEL_LIFTLEFT
) or (gLifts
[PanelID
].PanelType
= PANEL_LIFTRIGHT
) then
605 else t
:= IfThen(gLifts
[PanelID
].LiftType
= 2, 3, 2);
611 with gLifts
[PanelID
] do
613 if (LiftType
<> t
) then
615 g_Map_SetLiftGUID(PanelGUID
, t
); //???
616 //if not NoSound then g_Sound_PlayExAt('SOUND_GAME_SWITCH0', X, Y);
623 if (gLiftMap
= nil) then exit
;
626 for a
:= 0 to High(gLiftMap
) do
628 for b
:= 0 to High(gLiftMap
[a
]) do
630 if (gLiftMap
[a
, b
] = DWORD(PanelID
)) then
636 if (c
<> -1) then break
;
638 if (c
= -1) then exit
;
641 for b := 0 to High(gLiftMap[c]) do
642 if gLifts[gLiftMap[c, b]].LiftType <> t then
644 with gLifts[PanelID] do
645 g_Sound_PlayExAt('SOUND_GAME_SWITCH0', X, Y);
649 for b
:= 0 to High(gLiftMap
[c
]) do
651 with gLifts
[gLiftMap
[c
, b
]] do
653 if (LiftType
<> t
) then
655 g_Map_SetLift_XXX(gLiftMap
[c
, b
], t
);
664 function tr_SpawnShot (ShotType
: Integer; wx
, wy
, dx
, dy
: Integer; ShotSound
: Boolean; ShotTarget
: Word): Integer;
672 TextureID
:= DWORD(-1);
673 snd
:= 'SOUND_WEAPON_FIREROCKET';
679 g_Weapon_pistol(wx
, wy
, dx
, dy
, 0, True);
680 snd
:= 'SOUND_WEAPON_FIREPISTOL';
684 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_BULLET
);
685 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL1
);
691 g_Weapon_mgun(wx
, wy
, dx
, dy
, 0, True);
692 if gSoundEffectsDF
then snd
:= 'SOUND_WEAPON_FIRECGUN'
693 else snd
:= 'SOUND_WEAPON_FIREPISTOL';
697 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_BULLET
);
698 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL1
);
702 TRIGGER_SHOT_SHOTGUN
:
704 g_Weapon_Shotgun(wx
, wy
, dx
, dy
, 0, True);
705 snd
:= 'SOUND_WEAPON_FIRESHOTGUN';
709 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
710 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL2
);
716 g_Weapon_DShotgun(wx
, wy
, dx
, dy
, 0, True);
717 snd
:= 'SOUND_WEAPON_FIRESHOTGUN2';
721 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
722 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
723 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL3
);
729 g_Weapon_ball1(wx
, wy
, dx
, dy
, 0, -1, True);
730 snd
:= 'SOUND_WEAPON_FIREBALL';
735 g_Weapon_Plasma(wx
, wy
, dx
, dy
, 0, -1, True);
736 snd
:= 'SOUND_WEAPON_FIREPLASMA';
741 g_Weapon_aplasma(wx
, wy
, dx
, dy
, 0, -1, True);
742 snd
:= 'SOUND_WEAPON_FIREPLASMA';
747 g_Weapon_ball2(wx
, wy
, dx
, dy
, 0, -1, True);
748 snd
:= 'SOUND_WEAPON_FIREBALL';
753 g_Weapon_ball7(wx
, wy
, dx
, dy
, 0, -1, True);
754 snd
:= 'SOUND_WEAPON_FIREBALL';
759 g_Weapon_manfire(wx
, wy
, dx
, dy
, 0, -1, True);
760 snd
:= 'SOUND_WEAPON_FIREBALL';
765 g_Weapon_revf(wx
, wy
, dx
, dy
, 0, ShotTarget
, -1, True);
766 snd
:= 'SOUND_WEAPON_FIREREV';
771 g_Weapon_Rocket(wx
, wy
, dx
, dy
, 0, -1, True);
772 snd
:= 'SOUND_WEAPON_FIREROCKET';
777 g_Weapon_BFGShot(wx
, wy
, dx
, dy
, 0, -1, True);
778 snd
:= 'SOUND_WEAPON_FIREBFG';
783 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_ROCKET') then
785 Anim
:= TAnimation
.Create(TextureID
, False, 6);
786 Anim
.Blending
:= False;
787 g_GFX_OnceAnim(wx
-64, wy
-64, Anim
);
791 g_Weapon_Explode(wx
, wy
, 60, 0);
792 snd
:= 'SOUND_WEAPON_EXPLODEROCKET';
795 TRIGGER_SHOT_BFGEXPL
:
797 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_BFG') then
799 Anim
:= TAnimation
.Create(TextureID
, False, 6);
800 Anim
.Blending
:= False;
801 g_GFX_OnceAnim(wx
-64, wy
-64, Anim
);
805 g_Weapon_BFG9000(wx
, wy
, 0);
806 snd
:= 'SOUND_WEAPON_EXPLODEBFG';
812 if g_Game_IsNet
and g_Game_IsServer
then
815 TRIGGER_SHOT_EXPL
: MH_SEND_Effect(wx
, wy
, Byte(ShotSound
), NET_GFX_EXPLODE
);
816 TRIGGER_SHOT_BFGEXPL
: MH_SEND_Effect(wx
, wy
, Byte(ShotSound
), NET_GFX_BFGEXPL
);
819 if Projectile
then MH_SEND_CreateShot(LastShotID
);
820 if ShotSound
then MH_SEND_Sound(wx
, wy
, snd
);
825 if ShotSound
then g_Sound_PlayExAt(snd
, wx
, wy
);
827 if Projectile
then Result
:= LastShotID
;
831 procedure MakeShot (var Trigger
: TTrigger
; wx
, wy
, dx
, dy
: Integer; TargetUID
: Word);
835 if (tgcAmmo
= 0) or ((tgcAmmo
> 0) and (ShotAmmoCount
> 0)) then
837 if (trigPanelGUID
<> -1) and (ShotPanelTime
= 0) then
839 g_Map_SwitchTextureGUID({ShotPanelType,} trigPanelGUID
);
840 ShotPanelTime
:= 4; // òèêîâ íà âñïûøêó âûñòðåëà
843 if (tgcSight
> 0) then ShotSightTimeout
:= 180; // ~= 5 ñåêóíä
845 if (ShotAmmoCount
> 0) then Dec(ShotAmmoCount
);
847 dx
+= Random(tgcAccuracy
)-Random(tgcAccuracy
);
848 dy
+= Random(tgcAccuracy
)-Random(tgcAccuracy
);
850 tr_SpawnShot(tgcShotType
, wx
, wy
, dx
, dy
, not tgcQuiet
, TargetUID
);
854 if (tgcReload
> 0) and (ShotReloadTime
= 0) then
856 ShotReloadTime
:= tgcReload
; // òèêîâ íà ïåðåçàðÿäêó ïóøêè
863 procedure tr_MakeEffect (X
, Y
, VX
, VY
: Integer; T
, ST
, CR
, CG
, CB
: Byte; Silent
, Send
: Boolean);
868 if T
= TRIGGER_EFFECT_PARTICLE
then
871 TRIGGER_EFFECT_SLIQUID
:
873 if (CR
= 255) and (CG
= 0) and (CB
= 0) then g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 1, 0, 0, 0)
874 else if (CR
= 0) and (CG
= 255) and (CB
= 0) then g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 2, 0, 0, 0)
875 else if (CR
= 0) and (CG
= 0) and (CB
= 255) then g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 3, 0, 0, 0)
876 else g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 0, 0, 0, 0);
878 TRIGGER_EFFECT_LLIQUID
: g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 4, CR
, CG
, CB
);
879 TRIGGER_EFFECT_DLIQUID
: g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 5, CR
, CG
, CB
);
880 TRIGGER_EFFECT_BLOOD
: g_GFX_Blood(X
, Y
, 1, VX
, VY
, 0, 0, CR
, CG
, CB
);
881 TRIGGER_EFFECT_SPARK
: g_GFX_Spark(X
, Y
, 1, GetAngle2(VX
, VY
), 0, 0);
882 TRIGGER_EFFECT_BUBBLE
: g_GFX_Bubbles(X
, Y
, 1, 0, 0);
886 if T
= TRIGGER_EFFECT_ANIMATION
then
889 EFFECT_TELEPORT
: begin
890 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
892 Anim
:= TAnimation
.Create(FramesID
, False, 3);
893 if not Silent
then g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
894 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
897 if Send
and g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(X
, Y
, Byte(not Silent
), NET_GFX_TELE
);
899 EFFECT_RESPAWN
: begin
900 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
902 Anim
:= TAnimation
.Create(FramesID
, False, 4);
903 if not Silent
then g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
904 g_GFX_OnceAnim(X
-16, Y
-16, Anim
);
907 if Send
and g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(X
-16, Y
-16, Byte(not Silent
), NET_GFX_RESPAWN
);
910 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
912 Anim
:= TAnimation
.Create(FramesID
, False, 4);
913 if not Silent
then g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
914 g_GFX_OnceAnim(X
-32, Y
-128, Anim
);
917 if Send
and g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(X
-32, Y
-128, Byte(not Silent
), NET_GFX_FIRE
);
924 function tr_Teleport (ActivateUID
: Integer; TX
, TY
: Integer; TDir
: Integer; Silent
: Boolean; D2D
: Boolean): Boolean;
930 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then Exit
;
931 case g_GetUIDType(ActivateUID
) of
934 p
:= g_Player_Get(ActivateUID
);
935 if p
= nil then Exit
;
938 if p
.TeleportTo(TX
-(p
.Obj
.Rect
.Width
div 2), TY
-p
.Obj
.Rect
.Height
, Silent
, TDir
) then result
:= true;
942 if p
.TeleportTo(TX
, TY
, Silent
, TDir
) then result
:= true;
947 m
:= g_Monsters_ByUID(ActivateUID
);
948 if m
= nil then Exit
;
951 if m
.TeleportTo(TX
-(m
.Obj
.Rect
.Width
div 2), TY
-m
.Obj
.Rect
.Height
, Silent
, TDir
) then result
:= true;
955 if m
.TeleportTo(TX
, TY
, Silent
, TDir
) then result
:= true;
962 function tr_Push (ActivateUID
: Integer; VX
, VY
: Integer; ResetVel
: Boolean): Boolean;
968 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then exit
;
969 case g_GetUIDType(ActivateUID
) of
972 p
:= g_Player_Get(ActivateUID
);
973 if p
= nil then Exit
;
988 m
:= g_Monsters_ByUID(ActivateUID
);
989 if m
= nil then Exit
;
1005 function tr_Message (MKind
: Integer; MText
: string; MSendTo
: Integer; MTime
: Integer; ActivateUID
: Integer): Boolean;
1012 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then Exit
;
1013 msg
:= b_Text_Format(MText
);
1015 TRIGGER_MESSAGE_DEST_ME
: // activator
1017 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
1019 if g_Game_IsWatchedPlayer(ActivateUID
) then
1021 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
1022 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
1026 p
:= g_Player_Get(ActivateUID
);
1027 if g_Game_IsNet
and (p
.FClientID
>= 0) then
1029 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, p
.FClientID
)
1030 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, p
.FClientID
);
1036 TRIGGER_MESSAGE_DEST_MY_TEAM
: // activator's team
1038 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
1040 p
:= g_Player_Get(ActivateUID
);
1041 if g_Game_IsWatchedTeam(p
.Team
) then
1043 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
1044 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
1047 if g_Game_IsNet
then
1049 for i
:= Low(gPlayers
) to High(gPlayers
) do
1051 if (gPlayers
[i
].Team
= p
.Team
) and (gPlayers
[i
].FClientID
>= 0) then
1053 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
1054 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
1061 TRIGGER_MESSAGE_DEST_ENEMY_TEAM
: // activator's enemy team
1063 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
1065 p
:= g_Player_Get(ActivateUID
);
1066 if g_Game_IsWatchedTeam(p
.Team
) then
1068 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
1069 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
1072 if g_Game_IsNet
then
1074 for i
:= Low(gPlayers
) to High(gPlayers
) do
1076 if (gPlayers
[i
].Team
<> p
.Team
) and (gPlayers
[i
].FClientID
>= 0) then
1078 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
1079 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
1086 TRIGGER_MESSAGE_DEST_RED_TEAM
: // red team
1088 if g_Game_IsWatchedTeam(TEAM_RED
) then
1090 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
1091 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
1094 if g_Game_IsNet
then
1096 for i
:= Low(gPlayers
) to High(gPlayers
) do
1098 if (gPlayers
[i
].Team
= TEAM_RED
) and (gPlayers
[i
].FClientID
>= 0) then
1100 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
1101 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
1107 TRIGGER_MESSAGE_DEST_BLUE_TEAM
: // blue team
1109 if g_Game_IsWatchedTeam(TEAM_BLUE
) then
1111 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
1112 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
1115 if g_Game_IsNet
then
1117 for i
:= Low(gPlayers
) to High(gPlayers
) do
1119 if (gPlayers
[i
].Team
= TEAM_BLUE
) and (gPlayers
[i
].FClientID
>= 0) then
1121 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
1122 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
1128 TRIGGER_MESSAGE_DEST_EVERYONE
: // everyone
1130 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
1131 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
1133 if g_Game_IsNet
then
1135 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
)
1136 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
);
1143 function tr_ShotAimCheck (var Trigger
: TTrigger
; Obj
: PObj
): Boolean;
1148 if TriggerType
<> TRIGGER_SHOT
then Exit
;
1149 result
:= (tgcAim
and TRIGGER_SHOT_AIM_ALLMAP
> 0)
1150 or g_Obj_Collide(X
, Y
, Width
, Height
, Obj
);
1151 if result
and (tgcAim
and TRIGGER_SHOT_AIM_TRACE
> 0) then
1153 result
:= g_TraceVector(tgcTX
, tgcTY
,
1154 Obj
^.X
+ Obj
^.Rect
.X
+ (Obj
^.Rect
.Width
div 2),
1155 Obj
^.Y
+ Obj
^.Rect
.Y
+ (Obj
^.Rect
.Height
div 2));
1161 function ActivateTrigger (var Trigger
: TTrigger
; actType
: Byte): Boolean;
1167 idx
, k
, wx
, wy
, xd
, yd
: Integer;
1178 function monsShotTarget (mon
: TMonster
): Boolean;
1180 result
:= false; // don't stop
1181 if mon
.alive
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
1183 xd
:= mon
.GameX
+ mon
.Obj
.Rect
.Width
div 2;
1184 yd
:= mon
.GameY
+ mon
.Obj
.Rect
.Height
div 2;
1185 TargetUID
:= mon
.UID
;
1186 result
:= true; // stop
1190 function monsShotTargetMonPlr (mon
: TMonster
): Boolean;
1192 result
:= false; // don't stop
1193 if mon
.alive
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
1195 xd
:= mon
.GameX
+ mon
.Obj
.Rect
.Width
div 2;
1196 yd
:= mon
.GameY
+ mon
.Obj
.Rect
.Height
div 2;
1197 TargetUID
:= mon
.UID
;
1198 result
:= true; // stop
1202 function monShotTargetPlrMon (mon
: TMonster
): Boolean;
1204 result
:= false; // don't stop
1205 if mon
.alive
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
1207 xd
:= mon
.GameX
+ mon
.Obj
.Rect
.Width
div 2;
1208 yd
:= mon
.GameY
+ mon
.Obj
.Rect
.Height
div 2;
1209 TargetUID
:= mon
.UID
;
1210 result
:= true; // stop
1218 if g_Game_IsClient
then exit
;
1220 if not Trigger
.Enabled
then exit
;
1221 if (Trigger
.TimeOut
<> 0) and (actType
<> ACTIVATE_CUSTOM
) then exit
;
1222 if (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then exit
;
1224 if (Trigger
.exoCheck
<> nil) then
1226 //conwritefln('exocheck: [%s]', [Trigger.exoCheck.toString()]);
1228 tgscope
.me
:= @Trigger
;
1229 tvval
:= Trigger
.exoCheck
.value(tgscope
);
1231 if not Boolean(tvval
) then exit
;
1232 except on e
: Exception
do
1235 conwritefln('trigger exocheck error: %s [%s]', [e
.message, Trigger
.exoCheck
.toString()]);
1243 coolDown
:= (actType
<> 0);
1245 if (Trigger
.exoAction
<> nil) then
1247 //conwritefln('exoactivate: [%s]', [Trigger.exoAction.toString()]);
1249 tgscope
.me
:= @Trigger
;
1250 Trigger
.exoAction
.value(tgscope
);
1252 except on e
: Exception
do
1255 conwritefln('trigger exoactivate error: %s [%s]', [e
.message, Trigger
.exoAction
.toString()]);
1266 g_Sound_PlayEx('SOUND_GAME_SWITCH0');
1267 if g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_SWITCH0');
1268 gExitByTrigger
:= True;
1269 g_Game_ExitLevel(tgcMap
);
1278 Result
:= tr_Teleport(ActivateUID
,
1279 tgcTarget
.X
, tgcTarget
.Y
,
1280 tgcDirection
, tgcSilent
,
1287 Result
:= tr_OpenDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
1293 Result
:= tr_CloseDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
1297 TRIGGER_DOOR
, TRIGGER_DOOR5
:
1299 pan
:= g_Map_PanelByGUID(trigPanelGUID
);
1300 if (pan
<> nil) and pan
.isGWall
then
1302 if gWalls
[{trigPanelID}pan
.arrIdx
].Enabled
then
1304 result
:= tr_OpenDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
1305 if (TriggerType
= TRIGGER_DOOR5
) then DoorTime
:= 180;
1309 result
:= tr_CloseDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
1312 if result
then TimeOut
:= 18;
1316 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
:
1318 tr_CloseTrap(trigPanelGUID
, tgcSilent
, tgcD2d
);
1320 if TriggerType
= TRIGGER_TRAP
then
1334 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
:
1337 if PressTime
= -1 then PressTime
:= tgcWait
;
1338 if coolDown
then TimeOut
:= 18 else TimeOut
:= 0;
1343 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
1347 if gLMSRespawn
= LMS_RESPAWN_NONE
then
1349 g_Player_Get(ActivateUID
).GetSecret();
1350 Inc(gCoopSecretsFound
);
1351 if g_Game_IsNet
then MH_SEND_GameStats();
1357 Result
:= tr_SetLift(trigPanelGUID
, 0, tgcSilent
, tgcD2d
);
1360 if (not tgcSilent
) and Result
then begin
1361 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1363 Y
+ (Height
div 2));
1364 if g_Game_IsServer
and g_Game_IsNet
then
1365 MH_SEND_Sound(X
+ (Width
div 2),
1367 'SOUND_GAME_SWITCH0');
1373 Result
:= tr_SetLift(trigPanelGUID
, 1, tgcSilent
, tgcD2d
);
1376 if (not tgcSilent
) and Result
then begin
1377 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1379 Y
+ (Height
div 2));
1380 if g_Game_IsServer
and g_Game_IsNet
then
1381 MH_SEND_Sound(X
+ (Width
div 2),
1383 'SOUND_GAME_SWITCH0');
1389 Result
:= tr_SetLift(trigPanelGUID
, 3, tgcSilent
, tgcD2d
);
1395 if (not tgcSilent
) and Result
then begin
1396 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1398 Y
+ (Height
div 2));
1399 if g_Game_IsServer
and g_Game_IsNet
then
1400 MH_SEND_Sound(X
+ (Width
div 2),
1402 'SOUND_GAME_SWITCH0');
1409 if tgcActivateOnce
then
1412 TriggerType
:= TRIGGER_NONE
;
1420 animonce
:= tgcAnimateOnce
;
1426 if Sound
<> nil then
1428 if tgcSoundSwitch
and Sound
.IsPlaying() then
1429 begin // Íóæíî âûêëþ÷èòü, åñëè èãðàë
1431 SoundPlayCount
:= 0;
1434 else // (not Data.SoundSwitch) or (not Sound.IsPlaying())
1435 if (tgcPlayCount
> 0) or (not Sound
.IsPlaying()) then
1437 if tgcPlayCount
> 0 then
1438 SoundPlayCount
:= tgcPlayCount
1439 else // 0 - èãðàåì áåñêîíå÷íî
1440 SoundPlayCount
:= 1;
1443 if g_Game_IsNet
then MH_SEND_TriggerSound(Trigger
);
1447 TRIGGER_SPAWNMONSTER
:
1448 if (tgcSpawnMonsType
in [MONSTER_DEMON
..MONSTER_MAN
]) then
1451 if (tgcDelay
> 0) and (actType
<> ACTIVATE_CUSTOM
) then
1453 AutoSpawn
:= not AutoSpawn
;
1455 // Àâòîñïàâíåð ïåðåêëþ÷åí - ìåíÿåì òåêñòóðó
1459 if ((tgcDelay
= 0) and (actType
<> ACTIVATE_CUSTOM
))
1460 or ((tgcDelay
> 0) and (actType
= ACTIVATE_CUSTOM
)) then
1461 for k
:= 1 to tgcMonsCount
do
1463 if (actType
= ACTIVATE_CUSTOM
) and (tgcDelay
> 0) then
1464 SpawnCooldown
:= tgcDelay
;
1465 if (tgcMax
> 0) and (SpawnedCount
>= tgcMax
) then
1468 mon
:= g_Monsters_Create(tgcSpawnMonsType
,
1470 TDirection(tgcDirection
), True);
1475 if (tgcHealth
> 0) then
1476 mon
.SetHealth(tgcHealth
);
1477 // Óñòàíàâëèâàåì ïîâåäåíèå:
1478 mon
.MonsterBehaviour
:= tgcBehaviour
;
1479 mon
.FNoRespawn
:= True;
1480 if g_Game_IsNet
then
1481 MH_SEND_MonsterSpawn(mon
.UID
);
1482 // Èäåì èñêàòü öåëü, åñëè íàäî:
1486 if tgcSpawnMonsType
<> MONSTER_BARREL
then Inc(gTotalMonsters
);
1488 if g_Game_IsNet
then
1490 SetLength(gMonstersSpawned
, Length(gMonstersSpawned
)+1);
1491 gMonstersSpawned
[High(gMonstersSpawned
)] := mon
.UID
;
1496 mon
.SpawnTrigger
:= ID
;
1501 EFFECT_TELEPORT
: begin
1502 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
1504 Anim
:= TAnimation
.Create(FramesID
, False, 3);
1505 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', tgcTX
, tgcTY
);
1506 g_GFX_OnceAnim(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1507 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-32, Anim
);
1510 if g_Game_IsServer
and g_Game_IsNet
then
1511 MH_SEND_Effect(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1512 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-32, 1,
1515 EFFECT_RESPAWN
: begin
1516 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
1518 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1519 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', tgcTX
, tgcTY
);
1520 g_GFX_OnceAnim(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-16,
1521 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-16, Anim
);
1524 if g_Game_IsServer
and g_Game_IsNet
then
1525 MH_SEND_Effect(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-16,
1526 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-16, 1,
1530 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
1532 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1533 g_Sound_PlayExAt('SOUND_FIRE', tgcTX
, tgcTY
);
1534 g_GFX_OnceAnim(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1535 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+mon
.Obj
.Rect
.Height
-128, Anim
);
1538 if g_Game_IsServer
and g_Game_IsNet
then
1539 MH_SEND_Effect(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1540 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+mon
.Obj
.Rect
.Height
-128, 1,
1545 if g_Game_IsNet
then
1547 MH_SEND_GameStats();
1548 MH_SEND_CoopStats();
1555 // Åñëè àêòèâèðîâàí àâòîñïàâíåðîì, íå ìåíÿåì òåêñòóðó
1556 if actType
= ACTIVATE_CUSTOM
then
1561 if (tgcSpawnItemType
in [ITEM_MEDKIT_SMALL
..ITEM_MAX
]) then
1564 if (tgcDelay
> 0) and (actType
<> ACTIVATE_CUSTOM
) then
1566 AutoSpawn
:= not AutoSpawn
;
1568 // Àâòîñïàâíåð ïåðåêëþ÷åí - ìåíÿåì òåêñòóðó
1572 if ((tgcDelay
= 0) and (actType
<> ACTIVATE_CUSTOM
))
1573 or ((tgcDelay
> 0) and (actType
= ACTIVATE_CUSTOM
)) then
1574 if (not tgcDmonly
) or
1575 (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
1576 for k
:= 1 to tgcItemCount
do
1578 if (actType
= ACTIVATE_CUSTOM
) and (tgcDelay
> 0) then
1579 SpawnCooldown
:= tgcDelay
;
1580 if (tgcMax
> 0) and (SpawnedCount
>= tgcMax
) then
1583 iid
:= g_Items_Create(tgcTX
, tgcTY
,
1584 tgcSpawnItemType
, tgcGravity
, False, True);
1590 it
:= g_Items_ByIdx(iid
);
1591 it
.SpawnTrigger
:= ID
;
1596 EFFECT_TELEPORT
: begin
1597 it
:= g_Items_ByIdx(iid
);
1598 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
1600 Anim
:= TAnimation
.Create(FramesID
, False, 3);
1601 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', tgcTX
, tgcTY
);
1602 g_GFX_OnceAnim(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1603 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-32, Anim
);
1606 if g_Game_IsServer
and g_Game_IsNet
then
1607 MH_SEND_Effect(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1608 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-32, 1,
1611 EFFECT_RESPAWN
: begin
1612 it
:= g_Items_ByIdx(iid
);
1613 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
1615 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1616 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', tgcTX
, tgcTY
);
1617 g_GFX_OnceAnim(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-16,
1618 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-16, Anim
);
1621 if g_Game_IsServer
and g_Game_IsNet
then
1622 MH_SEND_Effect(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-16,
1623 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-16, 1,
1627 it
:= g_Items_ByIdx(iid
);
1628 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
1630 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1631 g_Sound_PlayExAt('SOUND_FIRE', tgcTX
, tgcTY
);
1632 g_GFX_OnceAnim(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1633 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+it
.Obj
.Rect
.Height
-128, Anim
);
1636 if g_Game_IsServer
and g_Game_IsNet
then
1637 MH_SEND_Effect(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1638 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+it
.Obj
.Rect
.Height
-128, 1,
1643 if g_Game_IsNet
then
1644 MH_SEND_ItemSpawn(True, iid
);
1651 // Åñëè àêòèâèðîâàí àâòîñïàâíåðîì, íå ìåíÿåì òåêñòóðó
1652 if actType
= ACTIVATE_CUSTOM
then
1658 // Ìåíÿåì ìóçûêó, åñëè åñòü íà ÷òî:
1659 if (Trigger
.tgcMusicName
<> '') then
1661 gMusic
.SetByName(Trigger
.tgcMusicName
);
1662 gMusic
.SpecPause
:= True;
1666 case Trigger
.tgcMusicAction
of
1667 TRIGGER_MUSIC_ACTION_STOP
: // Âûêëþ÷èòü
1668 gMusic
.SpecPause
:= True; // Ïàóçà
1669 TRIGGER_MUSIC_ACTION_PLAY
: // Âêëþ÷èòü
1670 if gMusic
.SpecPause
then // Áûëà íà ïàóçå => èãðàòü
1671 gMusic
.SpecPause
:= False
1672 else // Èãðàëà => ñíà÷àëà
1673 gMusic
.SetPosition(0);
1681 if g_Game_IsNet
then MH_SEND_TriggerMusic
;
1686 pAngle
:= -DegToRad(tgcAngle
);
1687 Result
:= tr_Push(ActivateUID
,
1688 Floor(Cos(pAngle
)*tgcForce
),
1689 Floor(Sin(pAngle
)*tgcForce
),
1697 // Ïðèáàâèòü èëè îòíÿòü î÷êî
1698 if (tgcScoreAction
in [TRIGGER_SCORE_ACTION_ADD
, TRIGGER_SCORE_ACTION_SUB
]) and (tgcScoreCount
> 0) then
1700 // Ñâîåé èëè ÷óæîé êîìàíäå
1701 if (tgcScoreTeam
in [TRIGGER_SCORE_TEAM_MINE_RED
, TRIGGER_SCORE_TEAM_MINE_BLUE
]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
1703 p
:= g_Player_Get(ActivateUID
);
1704 if ((tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_RED
))
1705 or ((tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_BLUE
)) then
1707 Inc(gTeamStat
[TEAM_RED
].Goals
, tgcScoreCount
); // Red Scores
1711 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1713 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_OWN
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1714 if g_Game_IsServer
and g_Game_IsNet
then
1715 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '+r');
1718 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_ENEMY
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1719 if g_Game_IsServer
and g_Game_IsNet
then
1720 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '+re');
1726 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1727 if g_Game_IsServer
and g_Game_IsNet
then
1728 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_RED
);
1731 if ((tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_RED
))
1732 or ((tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_BLUE
)) then
1734 Dec(gTeamStat
[TEAM_RED
].Goals
, tgcScoreCount
); // Red Fouls
1738 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1740 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_OWN
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1741 if g_Game_IsServer
and g_Game_IsNet
then
1742 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '-r');
1745 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_ENEMY
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1746 if g_Game_IsServer
and g_Game_IsNet
then
1747 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '-re');
1753 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1754 if g_Game_IsServer
and g_Game_IsNet
then
1755 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_RED
);
1758 if ((tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_BLUE
))
1759 or ((tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_RED
)) then
1761 Inc(gTeamStat
[TEAM_BLUE
].Goals
, tgcScoreCount
); // Blue Scores
1765 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1767 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_OWN
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1768 if g_Game_IsServer
and g_Game_IsNet
then
1769 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '+b');
1772 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_ENEMY
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1773 if g_Game_IsServer
and g_Game_IsNet
then
1774 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '+be');
1780 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1781 if g_Game_IsServer
and g_Game_IsNet
then
1782 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_BLUE
);
1785 if ((tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_BLUE
))
1786 or ((tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_RED
)) then
1788 Dec(gTeamStat
[TEAM_BLUE
].Goals
, tgcScoreCount
); // Blue Fouls
1792 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1794 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_OWN
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1795 if g_Game_IsServer
and g_Game_IsNet
then
1796 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '-b');
1799 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_ENEMY
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1800 if g_Game_IsServer
and g_Game_IsNet
then
1801 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '-be');
1807 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1808 if g_Game_IsServer
and g_Game_IsNet
then
1809 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_BLUE
);
1812 Result
:= (p
.Team
= TEAM_RED
) or (p
.Team
= TEAM_BLUE
);
1814 // Êàêîé-òî êîíêðåòíîé êîìàíäå
1815 if tgcScoreTeam
in [TRIGGER_SCORE_TEAM_FORCE_RED
, TRIGGER_SCORE_TEAM_FORCE_BLUE
] then
1817 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_RED
) then
1819 Inc(gTeamStat
[TEAM_RED
].Goals
, tgcScoreCount
); // Red Scores
1823 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_TEAM
], [_lc
[I_PLAYER_SCORE_RED
], tgcScoreCount
]), True);
1824 if g_Game_IsServer
and g_Game_IsNet
then
1825 MH_SEND_GameEvent(NET_EV_SCORE
, tgcScoreCount
shl 16, '+tr');
1830 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1831 if g_Game_IsServer
and g_Game_IsNet
then
1832 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_RED
);
1835 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_RED
) then
1837 Dec(gTeamStat
[TEAM_RED
].Goals
, tgcScoreCount
); // Red Fouls
1841 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_TEAM
], [_lc
[I_PLAYER_SCORE_RED
], tgcScoreCount
]), True);
1842 if g_Game_IsServer
and g_Game_IsNet
then
1843 MH_SEND_GameEvent(NET_EV_SCORE
, tgcScoreCount
shl 16, '-tr');
1848 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1849 if g_Game_IsServer
and g_Game_IsNet
then
1850 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_RED
);
1853 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_BLUE
) then
1855 Inc(gTeamStat
[TEAM_BLUE
].Goals
, tgcScoreCount
); // Blue Scores
1859 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_TEAM
], [_lc
[I_PLAYER_SCORE_BLUE
], tgcScoreCount
]), True);
1860 if g_Game_IsServer
and g_Game_IsNet
then
1861 MH_SEND_GameEvent(NET_EV_SCORE
, tgcScoreCount
shl 16, '+tb');
1866 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1867 if g_Game_IsServer
and g_Game_IsNet
then
1868 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_BLUE
);
1871 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_BLUE
) then
1873 Dec(gTeamStat
[TEAM_BLUE
].Goals
, tgcScoreCount
); // Blue Fouls
1877 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_TEAM
], [_lc
[I_PLAYER_SCORE_BLUE
], tgcScoreCount
]), True);
1878 if g_Game_IsServer
and g_Game_IsNet
then
1879 MH_SEND_GameEvent(NET_EV_SCORE
, tgcScoreCount
shl 16, '-tb');
1884 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1885 if g_Game_IsServer
and g_Game_IsNet
then
1886 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_BLUE
);
1893 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_WIN
) and (gGameSettings
.GoalLimit
> 0) then
1895 // Ñâîåé èëè ÷óæîé êîìàíäû
1896 if (tgcScoreTeam
in [TRIGGER_SCORE_TEAM_MINE_RED
, TRIGGER_SCORE_TEAM_MINE_BLUE
]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
1898 p
:= g_Player_Get(ActivateUID
);
1899 if ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_RED
)) // Red Wins
1900 or ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_BLUE
)) then
1902 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1904 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1908 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1910 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1911 if g_Game_IsServer
and g_Game_IsNet
then
1912 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wr');
1915 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1916 if g_Game_IsServer
and g_Game_IsNet
then
1917 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wre');
1924 if ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_BLUE
)) // Blue Wins
1925 or ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_RED
)) then
1927 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1929 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1933 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1935 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1936 if g_Game_IsServer
and g_Game_IsNet
then
1937 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wb');
1940 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1941 if g_Game_IsServer
and g_Game_IsNet
then
1942 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wbe');
1950 // Êàêîé-òî êîíêðåòíîé êîìàíäû
1951 if tgcScoreTeam
in [TRIGGER_SCORE_TEAM_FORCE_RED
, TRIGGER_SCORE_TEAM_FORCE_BLUE
] then
1953 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_RED
) then // Red Wins
1955 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1957 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1961 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_BLUE
) then // Blue Wins
1963 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1965 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1972 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_LOOSE
) and (gGameSettings
.GoalLimit
> 0) then
1974 // Ñâîåé èëè ÷óæîé êîìàíäû
1975 if (tgcScoreTeam
in [TRIGGER_SCORE_TEAM_MINE_RED
, TRIGGER_SCORE_TEAM_MINE_BLUE
]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
1977 p
:= g_Player_Get(ActivateUID
);
1978 if ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_BLUE
)) // Red Wins
1979 or ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_RED
)) then
1980 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1982 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1985 if tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
then
1987 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1988 if g_Game_IsServer
and g_Game_IsNet
then
1989 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wre');
1992 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1993 if g_Game_IsServer
and g_Game_IsNet
then
1994 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wr');
1999 if ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_RED
)) // Blue Wins
2000 or ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_BLUE
)) then
2001 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
2003 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
2006 if tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
then
2008 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
2009 if g_Game_IsServer
and g_Game_IsNet
then
2010 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wbe');
2013 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
2014 if g_Game_IsServer
and g_Game_IsNet
then
2015 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wb');
2021 // Êàêîé-òî êîíêðåòíîé êîìàíäû
2022 if tgcScoreTeam
in [TRIGGER_SCORE_TEAM_FORCE_BLUE
, TRIGGER_SCORE_TEAM_FORCE_RED
] then
2024 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_BLUE
) then // Red Wins
2026 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
2028 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
2032 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_RED
) then // Blue Wins
2034 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
2036 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
2042 if Result
then begin
2047 if g_Game_IsServer
and g_Game_IsNet
then
2054 Result
:= tr_Message(tgcKind
, tgcText
,
2055 tgcMsgDest
, tgcMsgTime
,
2060 TRIGGER_DAMAGE
, TRIGGER_HEALTH
:
2063 UIDType
:= g_GetUIDType(ActivateUID
);
2064 if (UIDType
= UID_PLAYER
) or (UIDType
= UID_MONSTER
) then
2070 // Âñïîìèíàåì, àêòèâèðîâàë ëè îí ìåíÿ ðàíüøå
2071 for idx
:= 0 to High(Activators
) do
2072 if Activators
[idx
].UID
= ActivateUID
then
2078 begin // Âèäèì åãî âïåðâûå
2080 SetLength(Activators
, Length(Activators
) + 1);
2081 k
:= High(Activators
);
2082 Activators
[k
].UID
:= ActivateUID
;
2084 begin // Óæå âèäåëè åãî
2085 // Åñëè èíòåðâàë îòêëþ÷¸í, íî îí âñ¸ åù¸ â çîíå ïîðàæåíèÿ, äà¸ì åìó âðåìÿ
2086 if (tgcInterval
= 0) and (Activators
[k
].TimeOut
> 0) then
2087 Activators
[k
].TimeOut
:= 65535;
2088 // Òàéìàóò ïðîø¸ë - ðàáîòàåì
2089 Result
:= Activators
[k
].TimeOut
= 0;
2098 p
:= g_Player_Get(ActivateUID
);
2102 // Íàíîñèì óðîí èãðîêó
2103 if (TriggerType
= TRIGGER_DAMAGE
) and (tgcAmount
> 0) then
2104 p
.Damage(tgcAmount
, 0, 0, 0, HIT_SOME
);
2107 if (TriggerType
= TRIGGER_HEALTH
) and (tgcAmount
> 0) then
2108 if p
.Heal(tgcAmount
, not tgcHealMax
) and (not tgcSilent
) then
2110 g_Sound_PlayExAt('SOUND_ITEM_GETITEM', p
.Obj
.X
, p
.Obj
.Y
);
2111 if g_Game_IsServer
and g_Game_IsNet
then
2112 MH_SEND_Sound(p
.Obj
.X
, p
.Obj
.Y
, 'SOUND_ITEM_GETITEM');
2118 m
:= g_Monsters_ByUID(ActivateUID
);
2122 // Íàíîñèì óðîí ìîíñòðó
2123 if (TriggerType
= TRIGGER_DAMAGE
) and (tgcAmount
> 0) then
2124 m
.Damage(tgcAmount
, 0, 0, 0, HIT_SOME
);
2127 if (TriggerType
= TRIGGER_HEALTH
) and (tgcAmount
> 0) then
2128 if m
.Heal(tgcAmount
) and (not tgcSilent
) then
2130 g_Sound_PlayExAt('SOUND_ITEM_GETITEM', m
.Obj
.X
, m
.Obj
.Y
);
2131 if g_Game_IsServer
and g_Game_IsNet
then
2132 MH_SEND_Sound(m
.Obj
.X
, m
.Obj
.Y
, 'SOUND_ITEM_GETITEM');
2136 // Íàçíà÷àåì âðåìÿ ñëåäóþùåãî âîçäåéñòâèÿ
2140 Activators
[k
].TimeOut
:= idx
2142 Activators
[k
].TimeOut
:= 65535;
2150 if ShotSightTime
> 0 then
2153 // put this at the beginning so it doesn't trigger itself
2154 TimeOut
:= tgcWait
+ 1;
2158 pAngle
:= -DegToRad(tgcAngle
);
2159 xd
:= wx
+ Round(Cos(pAngle
) * 32.0);
2160 yd
:= wy
+ Round(Sin(pAngle
) * 32.0);
2163 case tgcShotTarget
of
2164 TRIGGER_SHOT_TARGET_MON
: // monsters
2165 //TODO: accelerate this!
2166 g_Mons_ForEachAlive(monsShotTarget
);
2168 TRIGGER_SHOT_TARGET_PLR
: // players
2169 if gPlayers
<> nil then
2170 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2171 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2172 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2174 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2175 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2176 TargetUID
:= gPlayers
[idx
].UID
;
2180 TRIGGER_SHOT_TARGET_RED
: // red team
2181 if gPlayers
<> nil then
2182 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2183 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2184 (gPlayers
[idx
].Team
= TEAM_RED
) and
2185 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2187 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2188 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2189 TargetUID
:= gPlayers
[idx
].UID
;
2193 TRIGGER_SHOT_TARGET_BLUE
: // blue team
2194 if gPlayers
<> nil then
2195 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2196 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2197 (gPlayers
[idx
].Team
= TEAM_BLUE
) and
2198 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2200 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2201 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2202 TargetUID
:= gPlayers
[idx
].UID
;
2206 TRIGGER_SHOT_TARGET_MONPLR
: // monsters then players
2208 //TODO: accelerate this!
2209 g_Mons_ForEachAlive(monsShotTargetMonPlr
);
2211 if (TargetUID
= 0) and (gPlayers
<> nil) then
2212 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2213 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2214 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2216 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2217 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2218 TargetUID
:= gPlayers
[idx
].UID
;
2223 TRIGGER_SHOT_TARGET_PLRMON
: // players then monsters
2225 if gPlayers
<> nil then
2226 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2227 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2228 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2230 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2231 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2232 TargetUID
:= gPlayers
[idx
].UID
;
2235 if TargetUID
= 0 then
2237 //TODO: accelerate this!
2238 g_Mons_ForEachAlive(monShotTargetPlrMon
);
2243 if (tgcShotTarget
<> TRIGGER_SHOT_TARGET_NONE
) or
2244 (tgcShotType
<> TRIGGER_SHOT_REV
) then
2245 TargetUID
:= ActivateUID
;
2249 if (tgcShotTarget
= TRIGGER_SHOT_TARGET_NONE
) or (TargetUID
> 0) or
2250 ((tgcShotTarget
> TRIGGER_SHOT_TARGET_NONE
) and (TargetUID
= 0)) then
2253 if (tgcSight
= 0) or
2254 (tgcShotTarget
= TRIGGER_SHOT_TARGET_NONE
) or
2255 (TargetUID
= ShotSightTarget
) then
2256 MakeShot(Trigger
, wx
, wy
, xd
, yd
, TargetUID
)
2259 ShotSightTime
:= tgcSight
;
2260 ShotSightTargetN
:= TargetUID
;
2261 if tgcShotType
= TRIGGER_SHOT_BFG
then
2263 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', wx
, wy
);
2264 if g_Game_IsNet
and g_Game_IsServer
then
2265 MH_SEND_Sound(wx
, wy
, 'SOUND_WEAPON_STARTFIREBFG');
2278 TRIGGER_EFFECT_POS_CENTER
:
2280 wx
:= X
+ Width
div 2;
2281 wy
:= Y
+ Height
div 2;
2283 TRIGGER_EFFECT_POS_AREA
:
2285 wx
:= X
+ Random(Width
);
2286 wy
:= Y
+ Random(Height
);
2289 wx
:= X
+ Width
div 2;
2290 wy
:= Y
+ Height
div 2;
2295 if tgcSpreadL
> 0 then xd
-= Random(tgcSpreadL
+1);
2296 if tgcSpreadR
> 0 then xd
+= Random(tgcSpreadR
+1);
2297 if tgcSpreadU
> 0 then yd
-= Random(tgcSpreadU
+1);
2298 if tgcSpreadD
> 0 then yd
+= Random(tgcSpreadD
+1);
2299 tr_MakeEffect(wx
, wy
, xd
, yd
,
2300 tgcFXType
, tgcFXSubType
,
2301 tgcFXRed
, tgcFXGreen
, tgcFXBlue
, True, False);
2310 if Result
{and (Trigger.TexturePanel <> -1)} then
2312 g_Map_SwitchTextureGUID({Trigger.TexturePanelType,} Trigger
.TexturePanelGUID
, IfThen(animonce
, 2, 1));
2317 function g_Triggers_CreateWithMapIndex (aTrigger
: TTrigger
; arridx
, mapidx
: Integer): DWORD
;
2319 triggers
: TDynField
;
2321 triggers
:= gCurrentMap
['trigger'];
2322 if (triggers
= nil) then raise Exception
.Create('LOAD: map has no triggers');
2323 if (mapidx
< 0) or (mapidx
>= triggers
.count
) then raise Exception
.Create('LOAD: invalid map trigger index');
2324 aTrigger
.mapIndex
:= mapidx
;
2325 result
:= g_Triggers_Create(aTrigger
, triggers
.itemAt
[mapidx
], arridx
);
2329 function g_Triggers_Create (aTrigger
: TTrigger
; trec
: TDynRecord
; forceInternalIndex
: Integer=-1): DWORD
;
2332 fn
, mapw
: AnsiString;
2336 if (tgscope
= nil) then tgscope
:= TTrigScope
.Create();
2337 if (tgclist
= nil) then tgclist
:= TMyConstList
.Create();
2339 // Íå ñîçäàâàòü âûõîä, åñëè èãðà áåç âûõîäà
2340 if (aTrigger
.TriggerType
= TRIGGER_EXIT
) and
2341 (not LongBool(gGameSettings
.Options
and GAME_OPTION_ALLOWEXIT
)) then
2343 aTrigger
.TriggerType
:= TRIGGER_NONE
;
2346 // Åñëè ìîíñòðû çàïðåùåíû, îòìåíÿåì òðèããåð
2347 if (aTrigger
.TriggerType
= TRIGGER_SPAWNMONSTER
) and
2348 (not LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
)) and
2349 (gGameSettings
.GameType
<> GT_SINGLE
) then
2351 aTrigger
.TriggerType
:= TRIGGER_NONE
;
2354 // Ñ÷èòàåì êîëè÷åñòâî ñåêðåòîâ íà êàðòå
2355 if (aTrigger
.TriggerType
= TRIGGER_SECRET
) then gSecretsCount
+= 1;
2357 if (forceInternalIndex
< 0) then
2359 find_id
:= FindTrigger();
2363 olen
:= Length(gTriggers
);
2364 if (forceInternalIndex
>= olen
) then
2366 SetLength(gTriggers
, forceInternalIndex
+1);
2367 for f
:= olen
to High(gTriggers
) do
2369 gTriggers
[f
].TriggerType
:= TRIGGER_NONE
;
2370 gTriggers
[f
].trigDataRec
:= nil;
2371 gTriggers
[f
].exoInit
:= nil;
2372 gTriggers
[f
].exoThink
:= nil;
2373 gTriggers
[f
].exoCheck
:= nil;
2374 gTriggers
[f
].exoAction
:= nil;
2375 gTriggers
[f
].userVars
:= nil;
2378 f
:= forceInternalIndex
;
2379 gTriggers
[f
].trigDataRec
.Free();
2380 gTriggers
[f
].exoInit
.Free();
2381 gTriggers
[f
].exoThink
.Free();
2382 gTriggers
[f
].exoCheck
.Free();
2383 gTriggers
[f
].exoAction
.Free();
2384 gTriggers
[f
].userVars
.Free();
2385 gTriggers
[f
].trigDataRec
:= nil;
2386 gTriggers
[f
].exoInit
:= nil;
2387 gTriggers
[f
].exoThink
:= nil;
2388 gTriggers
[f
].exoCheck
:= nil;
2389 gTriggers
[f
].exoAction
:= nil;
2390 gTriggers
[f
].userVars
:= nil;
2391 find_id
:= DWORD(forceInternalIndex
);
2393 gTriggers
[find_id
] := aTrigger
;
2394 ptg
:= @gTriggers
[find_id
];
2396 ptg
.mapId
:= trec
.id
;
2397 // clone trigger data
2398 if (trec
.trigRec
= nil) then
2400 ptg
.trigDataRec
:= nil;
2402 if (ptg
.TriggerType
<> TRIGGER_SECRET
) then
2404 e_LogWritefln('trigger of type %s has no triggerdata; wtf?!', [ptg
.TriggerType
], TMsgType
.Warning
);
2409 ptg
.trigDataRec
:= trec
.trigRec
.clone(nil);
2415 // if this type of trigger exists both on the client and on the server
2416 // use an uniform numeration
2418 if (ptg
.TriggerType
= TRIGGER_SOUND
) then
2420 Inc(gTriggerClientID
);
2421 ClientID
:= gTriggerClientID
;
2425 PlayerCollide
:= False;
2429 SoundPlayCount
:= 0;
2436 // update cached trigger variables
2437 trigUpdateCacheData(ptg
^, ptg
.trigDataRec
);
2439 ptg
.userVars
:= nil;
2442 ptg
.exoThink
:= TExprBase
.parseStatList(tgclist
, VarToStr(trec
.user
['exoma_think']));
2444 on e
: TExomaParseException
do
2446 conwritefln('*** ERROR parsing exoma_think (%s,%s): %s [%s]', [e
.tokLine
, e
.tokCol
, e
.message, VarToStr(trec
.user
['exoma_think'])]);
2447 ptg
.exoThink
:= nil;
2453 ptg
.exoCheck
:= TExprBase
.parse(tgclist
, VarToStr(trec
.user
['exoma_check']));
2455 on e
: TExomaParseException
do
2457 conwritefln('*** ERROR parsing exoma_check (%s,%s): %s [%s]', [e
.tokLine
, e
.tokCol
, e
.message, VarToStr(trec
.user
['exoma_check'])]);
2458 ptg
.exoCheck
:= nil;
2464 ptg
.exoAction
:= TExprBase
.parseStatList(tgclist
, VarToStr(trec
.user
['exoma_action']));
2466 on e
: TExomaParseException
do
2468 conwritefln('*** ERROR parsing exoma_action (%s,%s): %s [%s]', [e
.tokLine
, e
.tokCol
, e
.message, VarToStr(trec
.user
['exoma_action'])]);
2469 ptg
.exoAction
:= nil;
2475 ptg
.exoInit
:= TExprBase
.parseStatList(tgclist
, VarToStr(trec
.user
['exoma_init']));
2477 on e
: TExomaParseException
do
2479 conwritefln('*** ERROR parsing exoma_init (%s,%s): %s [%s]', [e
.tokLine
, e
.tokCol
, e
.message, VarToStr(trec
.user
['exoma_init'])]);
2486 if (forceInternalIndex
< 0) and (ptg
.exoInit
<> nil) then
2488 //conwritefln('executing trigger init: [%s]', [gTriggers[find_id].exoInit.toString()]);
2491 ptg
.exoInit
.value(tgscope
);
2495 conwritefln('*** trigger exoactivate error: %s', [ptg
.exoInit
.toString()]);
2500 // Çàãðóæàåì çâóê, åñëè ýòî òðèããåð "Çâóê"
2501 if (ptg
.TriggerType
= TRIGGER_SOUND
) and (ptg
.tgcSoundName
<> '') then
2503 // Åùå íåò òàêîãî çâóêà
2504 if not g_Sound_Exists(ptg
.tgcSoundName
) then
2506 fn
:= g_ExtractWadName(ptg
.tgcSoundName
);
2508 begin // Çâóê â ôàéëå ñ êàðòîé
2509 mapw
:= g_ExtractWadName(gMapInfo
.Map
);
2510 fn
:= mapw
+':'+g_ExtractFilePathName(ptg
.tgcSoundName
);
2512 else // Çâóê â îòäåëüíîì ôàéëå
2514 fn
:= GameDir
+ '/wads/' + ptg
.tgcSoundName
;
2517 //e_LogWritefln('loading trigger sound ''%s''', [fn]);
2518 if not g_Sound_CreateWADEx(ptg
.tgcSoundName
, fn
) then
2520 g_FatalError(Format(_lc
[I_GAME_ERROR_TR_SOUND
], [fn
, ptg
.tgcSoundName
]));
2524 // Ñîçäàåì îáúåêò çâóêà
2527 Sound
:= TPlayableSound
.Create();
2528 if not Sound
.SetByName(ptg
.tgcSoundName
) then
2536 // Çàãðóæàåì ìóçûêó, åñëè ýòî òðèããåð "Ìóçûêà"
2537 if (ptg
.TriggerType
= TRIGGER_MUSIC
) and (ptg
.tgcMusicName
<> '') then
2539 // Åùå íåò òàêîé ìóçûêè
2540 if not g_Sound_Exists(ptg
.tgcMusicName
) then
2542 fn
:= g_ExtractWadName(ptg
.tgcMusicName
);
2545 begin // Ìóçûêà â ôàéëå ñ êàðòîé
2546 mapw
:= g_ExtractWadName(gMapInfo
.Map
);
2547 fn
:= mapw
+':'+g_ExtractFilePathName(ptg
.tgcMusicName
);
2549 else // Ìóçûêà â ôàéëå ñ êàðòîé
2551 fn
:= GameDir
+'/wads/'+ptg
.tgcMusicName
;
2554 if not g_Sound_CreateWADEx(ptg
.tgcMusicName
, fn
, True) then
2556 g_FatalError(Format(_lc
[I_GAME_ERROR_TR_SOUND
], [fn
, ptg
.tgcMusicName
]));
2561 // Çàãðóæàåì äàííûå òðèããåðà "Òóðåëü"
2562 if (ptg
.TriggerType
= TRIGGER_SHOT
) then
2568 ShotSightTimeout
:= 0;
2569 ShotSightTarget
:= 0;
2570 ShotSightTargetN
:= 0;
2571 ShotAmmoCount
:= ptg
.tgcAmmo
;
2572 ShotReloadTime
:= 0;
2580 // sorry; grid doesn't support recursive queries, so we have to do this
2582 TSimpleMonsterList
= specialize TSimpleList
<TMonster
>;
2585 tgMonsList
: TSimpleMonsterList
= nil;
2587 procedure g_Triggers_Update();
2590 Affected
: array of Integer;
2592 function monsNear (mon
: TMonster
): Boolean;
2594 result
:= false; // don't stop
2596 gTriggers[a].ActivateUID := mon.UID;
2597 ActivateTrigger(gTriggers[a], ACTIVATE_MONSTERCOLLIDE);
2599 tgMonsList
.append(mon
);
2606 if (tgMonsList
= nil) then tgMonsList
:= TSimpleMonsterList
.Create();
2608 if gTriggers
= nil then
2610 SetLength(Affected
, 0);
2612 for a
:= 0 to High(gTriggers
) do
2613 with gTriggers
[a
] do
2615 if TriggerType
<> TRIGGER_NONE
then
2617 // Óìåíüøàåì âðåìÿ äî çàêðûòèÿ äâåðè (îòêðûòèÿ ëîâóøêè)
2618 if DoorTime
> 0 then DoorTime
:= DoorTime
- 1;
2619 // Óìåíüøàåì âðåìÿ îæèäàíèÿ ïîñëå íàæàòèÿ
2620 if PressTime
> 0 then PressTime
:= PressTime
- 1;
2621 // Ïðîâåðÿåì èãðîêîâ è ìîíñòðîâ, êîòîðûõ ðàíåå çàïîìíèëè:
2622 if (TriggerType
= TRIGGER_DAMAGE
) or (TriggerType
= TRIGGER_HEALTH
) then
2624 for b
:= 0 to High(Activators
) do
2626 // Óìåíüøàåì âðåìÿ äî ïîâòîðíîãî âîçäåéñòâèÿ:
2627 if Activators
[b
].TimeOut
> 0 then
2629 Dec(Activators
[b
].TimeOut
);
2635 // Ñ÷èòàåì, ÷òî îáúåêò ïîêèíóë çîíó äåéñòâèÿ òðèããåðà
2636 if (tgcInterval
= 0) and (Activators
[b
].TimeOut
< 65530) then Activators
[b
].TimeOut
:= 0;
2640 // Îáðàáàòûâàåì ñïàâíåðû
2641 if Enabled
and AutoSpawn
then
2643 if SpawnCooldown
= 0 then
2645 // Åñëè ïðèøëî âðåìÿ, ñïàâíèì ìîíñòðà
2646 if (TriggerType
= TRIGGER_SPAWNMONSTER
) and (tgcDelay
> 0) then
2649 ActivateTrigger(gTriggers
[a
], ACTIVATE_CUSTOM
);
2651 // Åñëè ïðèøëî âðåìÿ, ñïàâíèì ïðåäìåò
2652 if (TriggerType
= TRIGGER_SPAWNITEM
) and (tgcDelay
> 0) then
2655 ActivateTrigger(gTriggers
[a
], ACTIVATE_CUSTOM
);
2660 // Óìåíüøàåì âðåìÿ îæèäàíèÿ
2665 // Îáðàáàòûâàåì ñîáûòèÿ òðèããåðà "Òóðåëü"
2666 if TriggerType
= TRIGGER_SHOT
then
2668 if ShotPanelTime
> 0 then
2671 if ShotPanelTime
= 0 then g_Map_SwitchTextureGUID({ShotPanelType,} trigPanelGUID
);
2673 if ShotSightTime
> 0 then
2676 if ShotSightTime
= 0 then ShotSightTarget
:= ShotSightTargetN
;
2678 if ShotSightTimeout
> 0 then
2680 Dec(ShotSightTimeout
);
2681 if ShotSightTimeout
= 0 then ShotSightTarget
:= 0;
2683 if ShotReloadTime
> 0 then
2685 Dec(ShotReloadTime
);
2686 if ShotReloadTime
= 0 then ShotAmmoCount
:= tgcAmmo
;
2690 // Òðèããåð "Çâóê" óæå îòûãðàë, åñëè íóæíî åùå - ïåðåçàïóñêàåì
2691 if Enabled
and (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) then
2693 if (SoundPlayCount
> 0) and (not Sound
.IsPlaying()) then
2695 if tgcPlayCount
> 0 then SoundPlayCount
-= 1; // Åñëè 0 - èãðàåì çâóê áåñêîíå÷íî
2698 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0);
2702 Sound
.PlayPanVolume((tgcPan
-127.0)/128.0, tgcVolume
/255.0);
2704 if Sound
.IsPlaying() and g_Game_IsNet
and g_Game_IsServer
then MH_SEND_TriggerSound(gTriggers
[a
]);
2708 // Òðèããåð "Ëîâóøêà" - ïîðà îòêðûâàòü
2709 if (TriggerType
= TRIGGER_TRAP
) and (DoorTime
= 0) and (g_Map_PanelByGUID(trigPanelGUID
) <> nil) then
2711 tr_OpenDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
2715 // Òðèããåð "Äâåðü 5 ñåê" - ïîðà çàêðûâàòü
2716 if (TriggerType
= TRIGGER_DOOR5
) and (DoorTime
= 0) and (g_Map_PanelByGUID(trigPanelGUID
) <> nil) then
2718 pan
:= g_Map_PanelByGUID(trigPanelGUID
);
2719 if (pan
<> nil) and pan
.isGWall
then
2722 if {gWalls[trigPanelID].Enabled} pan
.Enabled
then
2728 // Ïîêà îòêðûòà - çàêðûâàåì
2729 if tr_CloseDoor(trigPanelGUID
, tgcSilent
, tgcD2d
) then DoorTime
:= -1;
2734 // Òðèããåð - ðàñøèðèòåëü èëè ïåðåêëþ÷àòåëü, è ïðîøëà çàäåðæêà, è íàæàëè íóæíîå ÷èñëî ðàç:
2735 if (TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
]) and
2736 (PressTime
= 0) and (PressCount
>= tgcPressCount
) then
2738 // Ñáðàñûâàåì çàäåðæêó àêòèâàöèè:
2740 // Ñáðàñûâàåì ñ÷åò÷èê íàæàòèé:
2741 if tgcPressCount
> 0 then PressCount
-= tgcPressCount
else PressCount
:= 0;
2743 // Îïðåäåëÿåì èçìåíÿåìûå èì òðèããåðû:
2744 for b
:= 0 to High(gTriggers
) do
2746 if g_Collide(tgcTX
, tgcTY
, tgcTWidth
, tgcTHeight
, gTriggers
[b
].X
, gTriggers
[b
].Y
,
2747 gTriggers
[b
].Width
, gTriggers
[b
].Height
) and
2748 ((b
<> a
) or (tgcWait
> 0)) then
2749 begin // Can be self-activated, if there is Data.Wait
2750 if (not tgcExtRandom
) or gTriggers
[b
].Enabled
then
2752 SetLength(Affected
, Length(Affected
) + 1);
2753 Affected
[High(Affected
)] := b
;
2759 // if we have panelid, assume that it will switch the moving platform
2760 pan
:= g_Map_PanelByGUID(trigPanelGUID
);
2761 if (pan
<> nil) then
2764 TRIGGER_PRESS
: pan
.movingActive
:= true; // what to do here?
2765 TRIGGER_ON
: pan
.movingActive
:= true;
2766 TRIGGER_OFF
: pan
.movingActive
:= false;
2767 TRIGGER_ONOFF
: pan
.movingActive
:= not pan
.movingActive
;
2769 if not tgcSilent
and (Length(tgcSound
) > 0) then
2771 g_Sound_PlayExAt(tgcSound
, X
, Y
);
2772 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, tgcSound
);
2776 // Âûáèðàåì îäèí èç òðèããåðîâ äëÿ ðàñøèðèòåëÿ, åñëè âêëþ÷åí ðàíäîì:
2777 if (TriggerType
= TRIGGER_PRESS
) and tgcExtRandom
then
2779 if (Length(Affected
) > 0) then
2781 b
:= Affected
[Random(Length(Affected
))];
2782 gTriggers
[b
].ActivateUID
:= gTriggers
[a
].ActivateUID
;
2783 ActivateTrigger(gTriggers
[b
], 0);
2786 else //  ïðîòèâíîì ñëó÷àå ðàáîòàåì êàê îáû÷íî:
2788 for i
:= 0 to High(Affected
) do
2794 gTriggers
[b
].ActivateUID
:= gTriggers
[a
].ActivateUID
;
2795 ActivateTrigger(gTriggers
[b
], 0);
2799 gTriggers
[b
].Enabled
:= True;
2803 gTriggers
[b
].Enabled
:= False;
2804 gTriggers
[b
].TimeOut
:= 0;
2805 if gTriggers
[b
].AutoSpawn
then
2807 gTriggers
[b
].AutoSpawn
:= False;
2808 gTriggers
[b
].SpawnCooldown
:= 0;
2813 gTriggers
[b
].Enabled
:= not gTriggers
[b
].Enabled
;
2814 if not gTriggers
[b
].Enabled
then
2816 gTriggers
[b
].TimeOut
:= 0;
2817 if gTriggers
[b
].AutoSpawn
then
2819 gTriggers
[b
].AutoSpawn
:= False;
2820 gTriggers
[b
].SpawnCooldown
:= 0;
2827 SetLength(Affected
, 0);
2830 // Óìåíüøàåì âðåìÿ äî âîçìîæíîñòè ïîâòîðíîé àêòèâàöèè:
2833 TimeOut
:= TimeOut
- 1;
2834 Continue
; // ×òîáû íå ïîòåðÿòü 1 åäèíèöó çàäåðæêè
2837 // Íèæå èäóò òèïû àêòèâàöèè, åñëè òðèããåð îòêëþ÷¸í - èä¸ì äàëüøå
2842 if ByteBool(ActivateType
and ACTIVATE_PLAYERCOLLIDE
) and
2844 if gPlayers
<> nil then
2845 for b
:= 0 to High(gPlayers
) do
2846 if gPlayers
[b
] <> nil then
2848 // Æèâ, åñòü íóæíûå êëþ÷è è îí ðÿäîì:
2849 if alive
and ((gTriggers
[a
].Keys
and GetKeys
) = gTriggers
[a
].Keys
) and
2850 Collide(X
, Y
, Width
, Height
) then
2852 gTriggers
[a
].ActivateUID
:= UID
;
2854 if (gTriggers
[a
].TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) and
2856 { Don't activate sound/music again if player is here }
2858 ActivateTrigger(gTriggers
[a
], ACTIVATE_PLAYERCOLLIDE
);
2861 { TODO 5 : àêòèâàöèÿ ìîíñòðàìè òðèããåðîâ ñ êëþ÷àìè }
2863 if ByteBool(ActivateType
and ACTIVATE_MONSTERCOLLIDE
) and
2864 ByteBool(ActivateType
and ACTIVATE_NOMONSTER
) and
2865 (TimeOut
= 0) and (Keys
= 0) then
2867 // Åñëè "Ìîíñòð áëèçêî" è "Ìîíñòðîâ íåò",
2868 // çàïóñêàåì òðèããåð íà ñòàðòå êàðòû è ñíèìàåì îáà ôëàãà
2869 ActivateType
:= ActivateType
and not (ACTIVATE_MONSTERCOLLIDE
or ACTIVATE_NOMONSTER
);
2870 gTriggers
[a
].ActivateUID
:= 0;
2871 ActivateTrigger(gTriggers
[a
], 0);
2875 if ByteBool(ActivateType
and ACTIVATE_MONSTERCOLLIDE
) and
2876 (TimeOut
= 0) and (Keys
= 0) then // Åñëè íå íóæíû êëþ÷è
2878 //g_Mons_ForEach(monsNear);
2881 g_Mons_ForEachAt(gTriggers
[a
].X
, gTriggers
[a
].Y
, gTriggers
[a
].Width
, gTriggers
[a
].Height
, monsNear
);
2882 for mon
in tgMonsList
do
2884 gTriggers
[a
].ActivateUID
:= mon
.UID
;
2885 ActivateTrigger(gTriggers
[a
], ACTIVATE_MONSTERCOLLIDE
);
2887 tgMonsList
.reset(); // just in case
2891 if ByteBool(ActivateType
and ACTIVATE_NOMONSTER
) and
2892 (TimeOut
= 0) and (Keys
= 0) then
2893 if not g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then
2895 gTriggers
[a
].ActivateUID
:= 0;
2896 ActivateTrigger(gTriggers
[a
], ACTIVATE_NOMONSTER
);
2900 PlayerCollide
:= g_CollidePlayer(X
, Y
, Width
, Height
);
2904 procedure g_Triggers_Press(ID
: DWORD
; ActivateType
: Byte; ActivateUID
: Word = 0);
2906 if (ID
>= Length(gTriggers
)) then exit
;
2907 gTriggers
[ID
].ActivateUID
:= ActivateUID
;
2908 ActivateTrigger(gTriggers
[ID
], ActivateType
);
2911 function g_Triggers_PressR(X
, Y
: Integer; Width
, Height
: Word; UID
: Word;
2912 ActivateType
: Byte; IgnoreList
: DWArray
= nil): DWArray
;
2920 if gTriggers
= nil then Exit
;
2922 case g_GetUIDType(UID
) of
2926 p
:= g_Player_Get(UID
);
2935 for a
:= 0 to High(gTriggers
) do
2936 if (gTriggers
[a
].TriggerType
<> TRIGGER_NONE
) and
2937 (gTriggers
[a
].TimeOut
= 0) and
2938 (not InDWArray(a
, IgnoreList
)) and
2939 ((gTriggers
[a
].Keys
and k
) = gTriggers
[a
].Keys
) and
2940 ByteBool(gTriggers
[a
].ActivateType
and ActivateType
) then
2941 if g_Collide(X
, Y
, Width
, Height
,
2942 gTriggers
[a
].X
, gTriggers
[a
].Y
,
2943 gTriggers
[a
].Width
, gTriggers
[a
].Height
) then
2945 gTriggers
[a
].ActivateUID
:= UID
;
2946 if ActivateTrigger(gTriggers
[a
], ActivateType
) then
2948 SetLength(Result
, Length(Result
)+1);
2949 Result
[High(Result
)] := a
;
2954 procedure g_Triggers_PressL(X1
, Y1
, X2
, Y2
: Integer; UID
: DWORD
; ActivateType
: Byte);
2960 if gTriggers
= nil then Exit
;
2962 case g_GetUIDType(UID
) of
2966 p
:= g_Player_Get(UID
);
2975 for a
:= 0 to High(gTriggers
) do
2976 if (gTriggers
[a
].TriggerType
<> TRIGGER_NONE
) and
2977 (gTriggers
[a
].TimeOut
= 0) and
2978 ((gTriggers
[a
].Keys
and k
) = gTriggers
[a
].Keys
) and
2979 ByteBool(gTriggers
[a
].ActivateType
and ActivateType
) then
2980 if g_CollideLine(x1
, y1
, x2
, y2
, gTriggers
[a
].X
, gTriggers
[a
].Y
,
2981 gTriggers
[a
].Width
, gTriggers
[a
].Height
) then
2983 gTriggers
[a
].ActivateUID
:= UID
;
2984 ActivateTrigger(gTriggers
[a
], ActivateType
);
2988 procedure g_Triggers_PressC(CX
, CY
: Integer; Radius
: Word; UID
: Word; ActivateType
: Byte; IgnoreTrigger
: Integer = -1);
2995 if gTriggers
= nil then
2998 case g_GetUIDType(UID
) of
3002 p
:= g_Player_Get(UID
);
3011 rsq
:= Radius
* Radius
;
3013 for a
:= 0 to High(gTriggers
) do
3014 if (gTriggers
[a
].ID
<> DWORD(IgnoreTrigger
)) and
3015 (gTriggers
[a
].TriggerType
<> TRIGGER_NONE
) and
3016 (gTriggers
[a
].TimeOut
= 0) and
3017 ((gTriggers
[a
].Keys
and k
) = gTriggers
[a
].Keys
) and
3018 ByteBool(gTriggers
[a
].ActivateType
and ActivateType
) then
3019 with gTriggers
[a
] do
3020 if g_Collide(CX
-Radius
, CY
-Radius
, 2*Radius
, 2*Radius
,
3021 X
, Y
, Width
, Height
) then
3022 if ((Sqr(CX
-X
)+Sqr(CY
-Y
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê âåðõíåìó ëåâîìó óãëó
3023 ((Sqr(CX
-X
-Width
)+Sqr(CY
-Y
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê âåðõíåìó ïðàâîìó óãëó
3024 ((Sqr(CX
-X
-Width
)+Sqr(CY
-Y
-Height
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê íèæíåìó ïðàâîìó óãëó
3025 ((Sqr(CX
-X
)+Sqr(CY
-Y
-Height
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê íèæíåìó ëåâîìó óãëó
3026 ( (CX
> (X
-Radius
)) and (CX
< (X
+Width
+Radius
)) and
3027 (CY
> Y
) and (CY
< (Y
+Height
)) ) or // Öåíòð êðóãà íåäàëåêî îò âåðòèêàëüíûõ ãðàíèö ïðÿìîóãîëüíèêà
3028 ( (CY
> (Y
-Radius
)) and (CY
< (Y
+Height
+Radius
)) and
3029 (CX
> X
) and (CX
< (X
+Width
)) ) then // Öåíòð êðóãà íåäàëåêî îò ãîðèçîíòàëüíûõ ãðàíèö ïðÿìîóãîëüíèêà
3032 ActivateTrigger(gTriggers
[a
], ActivateType
);
3036 procedure g_Triggers_OpenAll();
3041 if gTriggers
= nil then Exit
;
3044 for a
:= 0 to High(gTriggers
) do
3046 with gTriggers
[a
] do
3048 if (TriggerType
= TRIGGER_OPENDOOR
) or
3049 (TriggerType
= TRIGGER_DOOR5
) or
3050 (TriggerType
= TRIGGER_DOOR
) then
3052 tr_OpenDoor(trigPanelGUID
, True, tgcD2d
);
3053 if TriggerType
= TRIGGER_DOOR5
then DoorTime
:= 180;
3059 if b
then g_Sound_PlayEx('SOUND_GAME_DOOROPEN');
3062 procedure g_Triggers_DecreaseSpawner(ID
: DWORD
);
3064 if (gTriggers
<> nil) then
3065 if gTriggers
[ID
].SpawnedCount
> 0 then
3066 Dec(gTriggers
[ID
].SpawnedCount
);
3070 procedure g_Triggers_Free ();
3074 for a
:= 0 to High(gTriggers
) do
3076 if (gTriggers
[a
].TriggerType
= TRIGGER_SOUND
) then
3078 if g_Sound_Exists(gTriggers
[a
].tgcSoundName
) then
3080 g_Sound_Delete(gTriggers
[a
].tgcSoundName
);
3082 gTriggers
[a
].Sound
.Free();
3084 if (gTriggers
[a
].Activators
<> nil) then
3086 SetLength(gTriggers
[a
].Activators
, 0);
3088 gTriggers
[a
].trigDataRec
.Free();
3090 gTriggers
[a
].exoThink
.Free();
3091 gTriggers
[a
].exoCheck
.Free();
3092 gTriggers
[a
].exoAction
.Free();
3093 gTriggers
[a
].userVars
.Free();
3098 SetLength(gMonstersSpawned
, 0);
3102 procedure g_Triggers_SaveState (st
: TStream
);
3104 count
, actCount
, i
, j
: Integer;
3107 kv
: THashStrVariant
.PEntry
;
3110 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðèããåðîâ
3111 count
:= Length(gTriggers
);
3113 // Êîëè÷åñòâî òðèããåðîâ
3114 utils
.writeInt(st
, LongInt(count
));
3115 if (count
= 0) then exit
;
3117 for i
:= 0 to High(gTriggers
) do
3119 // Ñèãíàòóðà òðèããåðà
3120 utils
.writeSign(st
, 'TRGX');
3121 utils
.writeInt(st
, Byte(0));
3123 utils
.writeInt(st
, Byte(gTriggers
[i
].TriggerType
));
3124 if (gTriggers
[i
].TriggerType
= TRIGGER_NONE
) then continue
; // empty one
3125 // Ñïåöèàëüíûå äàííûå òðèããåðà: ïîòîì èç êàðòû îïÿòü âûòàùèì; ñîõðàíèì òîëüêî èíäåêñ
3126 utils
.writeInt(st
, LongInt(gTriggers
[i
].mapIndex
));
3127 // Êîîðäèíàòû ëåâîãî âåðõíåãî óãëà
3128 utils
.writeInt(st
, LongInt(gTriggers
[i
].X
));
3129 utils
.writeInt(st
, LongInt(gTriggers
[i
].Y
));
3131 utils
.writeInt(st
, Word(gTriggers
[i
].Width
));
3132 utils
.writeInt(st
, Word(gTriggers
[i
].Height
));
3133 // Âêëþ÷åí ëè òðèããåð
3134 utils
.writeBool(st
, gTriggers
[i
].Enabled
);
3135 // Òèï àêòèâàöèè òðèããåðà
3136 utils
.writeInt(st
, Byte(gTriggers
[i
].ActivateType
));
3137 // Êëþ÷è, íåîáõîäèìûå äëÿ àêòèâàöèè
3138 utils
.writeInt(st
, Byte(gTriggers
[i
].Keys
));
3139 // ID ïàíåëè, òåêñòóðà êîòîðîé èçìåíèòñÿ
3140 utils
.writeInt(st
, LongInt(gTriggers
[i
].TexturePanelGUID
));
3142 //Mem.WriteWord(gTriggers[i].TexturePanelType);
3143 // Âíóòðåííèé íîìåð äðóãîé ïàíåëè (ïî ñ÷àñòëèâîé ñëó÷àéíîñòè îí áóäåò ñîâïàäàòü ñ òåì, ÷òî ñîçäàíî ïðè çàãðóçêå êàðòû)
3144 utils
.writeInt(st
, LongInt(gTriggers
[i
].trigPanelGUID
));
3145 // Âðåìÿ äî âîçìîæíîñòè àêòèâàöèè
3146 utils
.writeInt(st
, Word(gTriggers
[i
].TimeOut
));
3147 // UID òîãî, êòî àêòèâèðîâàë ýòîò òðèããåð
3148 utils
.writeInt(st
, Word(gTriggers
[i
].ActivateUID
));
3149 // Ñïèñîê UID-îâ îáúåêòîâ, êîòîðûå íàõîäèëèñü ïîä âîçäåéñòâèåì
3150 actCount
:= Length(gTriggers
[i
].Activators
);
3151 utils
.writeInt(st
, LongInt(actCount
));
3152 for j
:= 0 to actCount
-1 do
3155 utils
.writeInt(st
, Word(gTriggers
[i
].Activators
[j
].UID
));
3157 utils
.writeInt(st
, Word(gTriggers
[i
].Activators
[j
].TimeOut
));
3159 // Ñòîèò ëè èãðîê â îáëàñòè òðèããåðà
3160 utils
.writeBool(st
, gTriggers
[i
].PlayerCollide
);
3161 // Âðåìÿ äî çàêðûòèÿ äâåðè
3162 utils
.writeInt(st
, LongInt(gTriggers
[i
].DoorTime
));
3163 // Çàäåðæêà àêòèâàöèè
3164 utils
.writeInt(st
, LongInt(gTriggers
[i
].PressTime
));
3166 utils
.writeInt(st
, LongInt(gTriggers
[i
].PressCount
));
3168 utils
.writeBool(st
, gTriggers
[i
].AutoSpawn
);
3169 // Çàäåðæêà ñïàâíåðà
3170 utils
.writeInt(st
, LongInt(gTriggers
[i
].SpawnCooldown
));
3171 // Ñ÷åò÷èê ñîçäàíèÿ îáúåêòîâ
3172 utils
.writeInt(st
, LongInt(gTriggers
[i
].SpawnedCount
));
3173 // Ñêîëüêî ðàç ïðîèãðàí çâóê
3174 utils
.writeInt(st
, LongInt(gTriggers
[i
].SoundPlayCount
));
3175 // Ïðîèãðûâàåòñÿ ëè çâóê?
3176 if (gTriggers
[i
].Sound
<> nil) then b
:= gTriggers
[i
].Sound
.IsPlaying() else b
:= false;
3177 utils
.writeBool(st
, b
);
3180 // Ïîçèöèÿ ïðîèãðûâàíèÿ çâóêà
3181 utils
.writeInt(st
, LongWord(gTriggers
[i
].Sound
.GetPosition()));
3183 sg
:= gTriggers
[i
].Sound
.GetVolume();
3184 sg
:= sg
/(gSoundLevel
/255.0);
3185 //Mem.WriteSingle(sg);
3186 st
.WriteBuffer(sg
, sizeof(sg
)); // sorry
3187 // Ñòåðåî ñìåùåíèå çâóêà
3188 sg
:= gTriggers
[i
].Sound
.GetPan();
3189 //Mem.WriteSingle(sg);
3190 st
.WriteBuffer(sg
, sizeof(sg
)); // sorry
3193 if (gTriggers
[i
].userVars
= nil) then
3195 utils
.writeInt(st
, LongInt(0));
3199 utils
.writeInt(st
, LongInt(gTriggers
[i
].userVars
.count
)); //FIXME: check for overflow
3200 for kv
in gTriggers
[i
].userVars
.byKeyValue
do
3202 //writeln('<', kv.key, '>:<', VarToStr(kv.value), '>');
3203 utils
.writeStr(st
, kv
.key
);
3204 t
:= LongInt(varType(kv
.value
));
3205 utils
.writeInt(st
, LongInt(t
));
3207 varString
: utils
.writeStr(st
, AnsiString(kv
.value
));
3208 varBoolean
: utils
.writeBool(st
, Boolean(kv
.value
));
3209 varShortInt
: utils
.writeInt(st
, LongInt(kv
.value
));
3210 varSmallint
: utils
.writeInt(st
, LongInt(kv
.value
));
3211 varInteger
: utils
.writeInt(st
, LongInt(kv
.value
));
3212 //varInt64: Mem.WriteInt(Integer(kv.value));
3213 varByte
: utils
.writeInt(st
, LongInt(kv
.value
));
3214 varWord
: utils
.writeInt(st
, LongInt(kv
.value
));
3215 varLongWord
: utils
.writeInt(st
, LongInt(kv
.value
));
3217 else raise Exception
.CreateFmt('cannot save uservar ''%s''', [kv
.key
]);
3225 procedure g_Triggers_LoadState (st
: TStream
);
3227 count
, actCount
, i
, j
, a
: Integer;
3236 uvname
: AnsiString = '';
3237 ustr
: AnsiString = '';
3245 // Êîëè÷åñòâî òðèããåðîâ
3246 count
:= utils
.readLongInt(st
);
3247 if (count
= 0) then exit
;
3248 if (count
< 0) or (count
> 1024*1024) then raise XStreamError
.Create('invalid trigger count');
3250 for a
:= 0 to count
-1 do
3252 // Ñèãíàòóðà òðèããåðà
3253 if not utils
.checkSign(st
, 'TRGX') then raise XStreamError
.Create('invalid trigger signature');
3254 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid trigger version');
3256 Trig
.TriggerType
:= utils
.readByte(st
);
3257 if (Trig
.TriggerType
= TRIGGER_NONE
) then continue
; // empty one
3258 // Ñïåöèàëüíûå äàííûå òðèããåðà: èíäåêñ â gCurrentMap.field['triggers']
3259 mapIndex
:= utils
.readLongInt(st
);
3260 i
:= g_Triggers_CreateWithMapIndex(Trig
, a
, mapIndex
);
3261 // Êîîðäèíàòû ëåâîãî âåðõíåãî óãëà
3262 gTriggers
[i
].X
:= utils
.readLongInt(st
);
3263 gTriggers
[i
].Y
:= utils
.readLongInt(st
);
3265 gTriggers
[i
].Width
:= utils
.readWord(st
);
3266 gTriggers
[i
].Height
:= utils
.readWord(st
);
3267 // Âêëþ÷åí ëè òðèããåð
3268 gTriggers
[i
].Enabled
:= utils
.readBool(st
);
3269 // Òèï àêòèâàöèè òðèããåðà
3270 gTriggers
[i
].ActivateType
:= utils
.readByte(st
);
3271 // Êëþ÷è, íåîáõîäèìûå äëÿ àêòèâàöèè
3272 gTriggers
[i
].Keys
:= utils
.readByte(st
);
3273 // ID ïàíåëè, òåêñòóðà êîòîðîé èçìåíèòñÿ
3274 gTriggers
[i
].TexturePanelGUID
:= utils
.readLongInt(st
);
3276 //Mem.ReadWord(gTriggers[i].TexturePanelType);
3277 // Âíóòðåííèé íîìåð äðóãîé ïàíåëè (ïî ñ÷àñòëèâîé ñëó÷àéíîñòè îí áóäåò ñîâïàäàòü ñ òåì, ÷òî ñîçäàíî ïðè çàãðóçêå êàðòû)
3278 gTriggers
[i
].trigPanelGUID
:= utils
.readLongInt(st
);
3279 // Âðåìÿ äî âîçìîæíîñòè àêòèâàöèè
3280 gTriggers
[i
].TimeOut
:= utils
.readWord(st
);
3281 // UID òîãî, êòî àêòèâèðîâàë ýòîò òðèããåð
3282 gTriggers
[i
].ActivateUID
:= utils
.readWord(st
);
3283 // Ñïèñîê UID-îâ îáúåêòîâ, êîòîðûå íàõîäèëèñü ïîä âîçäåéñòâèåì
3284 actCount
:= utils
.readLongInt(st
);
3285 if (actCount
< 0) or (actCount
> 1024*1024) then raise XStreamError
.Create('invalid activated object count');
3286 if (actCount
> 0) then
3288 SetLength(gTriggers
[i
].Activators
, actCount
);
3289 for j
:= 0 to actCount
-1 do
3292 gTriggers
[i
].Activators
[j
].UID
:= utils
.readWord(st
);
3294 gTriggers
[i
].Activators
[j
].TimeOut
:= utils
.readWord(st
);
3297 // Ñòîèò ëè èãðîê â îáëàñòè òðèããåðà
3298 gTriggers
[i
].PlayerCollide
:= utils
.readBool(st
);
3299 // Âðåìÿ äî çàêðûòèÿ äâåðè
3300 gTriggers
[i
].DoorTime
:= utils
.readLongInt(st
);
3301 // Çàäåðæêà àêòèâàöèè
3302 gTriggers
[i
].PressTime
:= utils
.readLongInt(st
);
3304 gTriggers
[i
].PressCount
:= utils
.readLongInt(st
);
3306 gTriggers
[i
].AutoSpawn
:= utils
.readBool(st
);
3307 // Çàäåðæêà ñïàâíåðà
3308 gTriggers
[i
].SpawnCooldown
:= utils
.readLongInt(st
);
3309 // Ñ÷åò÷èê ñîçäàíèÿ îáúåêòîâ
3310 gTriggers
[i
].SpawnedCount
:= utils
.readLongInt(st
);
3311 // Ñêîëüêî ðàç ïðîèãðàí çâóê
3312 gTriggers
[i
].SoundPlayCount
:= utils
.readLongInt(st
);
3313 // Ïðîèãðûâàåòñÿ ëè çâóê?
3314 b
:= utils
.readBool(st
);
3317 // Ïîçèöèÿ ïðîèãðûâàíèÿ çâóêà
3318 dw
:= utils
.readLongWord(st
);
3320 //Mem.ReadSingle(vol);
3321 st
.ReadBuffer(vol
, sizeof(vol
)); // sorry
3322 // Ñòåðåî ñìåùåíèå çâóêà
3323 //Mem.ReadSingle(pan);
3324 st
.ReadBuffer(pan
, sizeof(pan
)); // sorry
3325 // Çàïóñêàåì çâóê, åñëè åñòü
3326 if (gTriggers
[i
].Sound
<> nil) then
3328 gTriggers
[i
].Sound
.PlayPanVolume(pan
, vol
);
3329 gTriggers
[i
].Sound
.Pause(True);
3330 gTriggers
[i
].Sound
.SetPosition(dw
);
3334 gTriggers
[i
].userVars
.Free();
3335 gTriggers
[i
].userVars
:= nil;
3336 uvcount
:= utils
.readLongInt(st
);
3337 if (uvcount
< 0) or (uvcount
> 1024*1024) then raise XStreamError
.Create('invalid number of user vars in trigger');
3338 if (uvcount
> 0) then
3340 gTriggers
[i
].userVars
:= THashStrVariant
.Create();
3342 while (uvcount
> 0) do
3345 uvname
:= utils
.readStr(st
);
3346 vt
:= utils
.readLongInt(st
);
3348 varString
: begin ustr
:= utils
.readStr(st
); vv
:= ustr
; end;
3349 varBoolean
: begin ubool
:= utils
.readBool(st
); vv
:= ubool
; end;
3350 varShortInt
: begin uint
:= utils
.readLongInt(st
); vv
:= ShortInt(uint
); end;
3351 varSmallint
: begin uint
:= utils
.readLongInt(st
); vv
:= SmallInt(uint
); end;
3352 varInteger
: begin uint
:= utils
.readLongInt(st
); vv
:= LongInt(uint
); end;
3353 varByte
: begin uint
:= utils
.readLongInt(st
); vv
:= Byte(uint
); end;
3354 varWord
: begin uint
:= utils
.readLongInt(st
); vv
:= Word(uint
); end;
3355 varLongWord
: begin uint
:= utils
.readLongInt(st
); vv
:= LongWord(uint
); end;
3356 else raise Exception
.CreateFmt('cannot load uservar ''%s''', [uvname
]);
3358 gTriggers
[i
].userVars
.put(uvname
, vv
);