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 MAPDEF
, e_graphics
, g_basic
, g_sound
,
41 TexturePanelGUID
: Integer;
42 TexturePanelType
: Word;
46 Activators
: array of TActivator
;
47 PlayerCollide
: Boolean;
51 SoundPlayCount
: Integer;
52 Sound
: TPlayableSound
;
54 SpawnCooldown
: Integer;
55 SpawnedCount
: Integer;
57 ShotPanelTime
: Integer;
58 ShotSightTime
: Integer;
59 ShotSightTimeout
: Integer;
60 ShotSightTarget
: Word;
61 ShotSightTargetN
: Word;
63 ShotReloadTime
: Integer;
65 mapId
: AnsiString; // trigger id, from map
66 mapIndex
: Integer; // index in fields['trigger'], used in save/load
67 trigPanelGUID
: Integer;
69 //TrigData: TTriggerData;
70 trigDataRec
: TDynRecord
; // triggerdata; owned by trigger
72 {$INCLUDE ../shared/mapdef_tgc_def.inc}
75 function trigCenter (): TDFPoint
; inline;
78 property trigShotPanelGUID
: Integer read trigPanelGUID write trigPanelGUID
;
81 function g_Triggers_Create(Trigger
: TTrigger
; forceInternalIndex
: Integer=-1): DWORD
;
82 procedure g_Triggers_Update();
83 procedure g_Triggers_Press(ID
: DWORD
; ActivateType
: Byte; ActivateUID
: Word = 0);
84 function g_Triggers_PressR(X
, Y
: Integer; Width
, Height
: Word; UID
: Word;
85 ActivateType
: Byte; IgnoreList
: DWArray
= nil): DWArray
;
86 procedure g_Triggers_PressL(X1
, Y1
, X2
, Y2
: Integer; UID
: DWORD
; ActivateType
: Byte);
87 procedure g_Triggers_PressC(CX
, CY
: Integer; Radius
: Word; UID
: Word; ActivateType
: Byte; IgnoreTrigger
: Integer = -1);
88 procedure g_Triggers_OpenAll();
89 procedure g_Triggers_DecreaseSpawner(ID
: DWORD
);
90 procedure g_Triggers_Free();
91 procedure g_Triggers_SaveState(var Mem
: TBinMemoryWriter
);
92 procedure g_Triggers_LoadState(var Mem
: TBinMemoryReader
);
96 gTriggerClientID
: Integer = 0;
97 gTriggers
: array of TTrigger
;
98 gSecretsCount
: Integer = 0;
99 gMonstersSpawned
: array of LongInt = nil;
106 g_player
, g_map
, g_panel
, g_gfx
, g_game
, g_textures
,
107 g_console
, g_monsters
, g_items
, g_phys
, g_weapons
,
108 wadreader
, g_main
, SysUtils
, e_log
, g_language
,
109 g_options
, g_net
, g_netmsg
, utils
, xparser
;
112 TRIGGER_SIGNATURE
= $58475254; // 'TRGX'
115 {$INCLUDE ../shared/mapdef_tgc_impl.inc}
117 function TTrigger
.trigCenter (): TDFPoint
; inline;
119 result
:= TDFPoint
.Create(x
+width
div 2, y
+height
div 2);
123 function FindTrigger (): DWORD
;
127 for i
:= 0 to High(gTriggers
) do
129 if gTriggers
[i
].TriggerType
= TRIGGER_NONE
then begin result
:= i
; exit
; end;
132 if (gTriggers
= nil) then
134 SetLength(gTriggers
, 8);
139 result
:= Length(gTriggers
);
140 SetLength(gTriggers
, result
+8);
141 for i
:= result
to High(gTriggers
) do gTriggers
[i
].TriggerType
:= TRIGGER_NONE
;
146 function tr_CloseDoor (PanelGUID
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
153 pan
:= g_Map_PanelByGUID(PanelGUID
);
154 if (pan
= nil) or not pan
.isGWall
then exit
; //!FIXME!TRIGANY!
155 PanelID
:= pan
.arrIdx
;
159 with gWalls
[PanelID
] do
161 if g_CollidePlayer(X
, Y
, Width
, Height
) or g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then Exit
;
166 g_Sound_PlayExAt('SOUND_GAME_DOORCLOSE', X
, Y
);
167 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOORCLOSE');
169 g_Map_EnableWallGUID(PanelGUID
);
176 if (gDoorMap
= nil) then exit
;
179 for a
:= 0 to High(gDoorMap
) do
181 for b
:= 0 to High(gDoorMap
[a
]) do
183 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
189 if (c
<> -1) then break
;
191 if (c
= -1) then exit
;
193 for b
:= 0 to High(gDoorMap
[c
]) do
195 with gWalls
[gDoorMap
[c
, b
]] do
197 if g_CollidePlayer(X
, Y
, Width
, Height
) or g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then exit
;
203 for b
:= 0 to High(gDoorMap
[c
]) do
205 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
207 with gWalls
[PanelID
] do
209 g_Sound_PlayExAt('SOUND_GAME_DOORCLOSE', X
, Y
);
210 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOORCLOSE');
217 for b
:= 0 to High(gDoorMap
[c
]) do
219 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
221 g_Map_EnableWall_XXX(gDoorMap
[c
, b
]);
229 procedure tr_CloseTrap (PanelGUID
: Integer; NoSound
: Boolean; d2d
: Boolean);
232 wx
, wy
, wh
, ww
: Integer;
236 function monsDamage (mon
: TMonster
): Boolean;
238 result
:= false; // don't stop
239 if g_Obj_Collide(wx
, wy
, ww
, wh
, @mon
.Obj
) then mon
.Damage(TRAP_DAMAGE
, 0, 0, 0, HIT_TRAP
);
243 pan
:= g_Map_PanelByGUID(PanelGUID
);
247 e_LogWritefln('tr_CloseTrap: pguid=%s; NO PANEL!', [PanelGUID], MSG_WARNING);
251 e_LogWritefln('tr_CloseTrap: pguid=%s; isGWall=%s; arrIdx=%s', [PanelGUID, pan.isGWall, pan.arrIdx]);
254 if (pan
= nil) or not pan
.isGWall
then exit
; //!FIXME!TRIGANY!
255 PanelID
:= pan
.arrIdx
;
259 with gWalls
[PanelID
] do
261 if (not NoSound
) and (not Enabled
) then
263 g_Sound_PlayExAt('SOUND_GAME_SWITCH1', X
, Y
);
264 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_SWITCH1');
268 wx
:= gWalls
[PanelID
].X
;
269 wy
:= gWalls
[PanelID
].Y
;
270 ww
:= gWalls
[PanelID
].Width
;
271 wh
:= gWalls
[PanelID
].Height
;
273 with gWalls
[PanelID
] do
275 if gPlayers
<> nil then
277 for a
:= 0 to High(gPlayers
) do
279 if (gPlayers
[a
] <> nil) and gPlayers
[a
].alive
and gPlayers
[a
].Collide(X
, Y
, Width
, Height
) then
281 gPlayers
[a
].Damage(TRAP_DAMAGE
, 0, 0, 0, HIT_TRAP
);
286 //g_Mons_ForEach(monsDamage);
287 g_Mons_ForEachAliveAt(wx
, wy
, ww
, wh
, monsDamage
);
289 if not Enabled
then g_Map_EnableWallGUID(PanelGUID
);
294 if (gDoorMap
= nil) then exit
;
297 for a
:= 0 to High(gDoorMap
) do
299 for b
:= 0 to High(gDoorMap
[a
]) do
301 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
307 if (c
<> -1) then break
;
309 if (c
= -1) then exit
;
313 for b
:= 0 to High(gDoorMap
[c
]) do
315 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
317 with gWalls
[PanelID
] do
319 g_Sound_PlayExAt('SOUND_GAME_SWITCH1', X
, Y
);
320 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_SWITCH1');
327 for b
:= 0 to High(gDoorMap
[c
]) do
329 wx
:= gWalls
[gDoorMap
[c
, b
]].X
;
330 wy
:= gWalls
[gDoorMap
[c
, b
]].Y
;
331 ww
:= gWalls
[gDoorMap
[c
, b
]].Width
;
332 wh
:= gWalls
[gDoorMap
[c
, b
]].Height
;
334 with gWalls
[gDoorMap
[c
, b
]] do
336 if gPlayers
<> nil then
338 for a
:= 0 to High(gPlayers
) do
340 if (gPlayers
[a
] <> nil) and gPlayers
[a
].alive
and gPlayers
[a
].Collide(X
, Y
, Width
, Height
) then
342 gPlayers
[a
].Damage(TRAP_DAMAGE
, 0, 0, 0, HIT_TRAP
);
347 //g_Mons_ForEach(monsDamage);
348 g_Mons_ForEachAliveAt(wx
, wy
, ww
, wh
, monsDamage
);
350 if gMonsters <> nil then
351 for a := 0 to High(gMonsters) do
352 if (gMonsters[a] <> nil) and gMonsters[a].alive and
353 g_Obj_Collide(X, Y, Width, Height, @gMonsters[a].Obj) then
354 gMonsters[a].Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
357 if not Enabled
then g_Map_EnableWall_XXX(gDoorMap
[c
, b
]);
364 function tr_OpenDoor (PanelGUID
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
371 pan
:= g_Map_PanelByGUID(PanelGUID
);
372 if (pan
= nil) or not pan
.isGWall
then exit
; //!FIXME!TRIGANY!
373 PanelID
:= pan
.arrIdx
;
377 with gWalls
[PanelID
] do
383 g_Sound_PlayExAt('SOUND_GAME_DOOROPEN', X
, Y
);
384 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOOROPEN');
386 g_Map_DisableWallGUID(PanelGUID
);
393 if (gDoorMap
= nil) then exit
;
396 for a
:= 0 to High(gDoorMap
) do
398 for b
:= 0 to High(gDoorMap
[a
]) do
400 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
406 if (c
<> -1) then break
;
408 if (c
= -1) then exit
;
412 for b
:= 0 to High(gDoorMap
[c
]) do
414 if gWalls
[gDoorMap
[c
, b
]].Enabled
then
416 with gWalls
[PanelID
] do
418 g_Sound_PlayExAt('SOUND_GAME_DOOROPEN', X
, Y
);
419 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOOROPEN');
426 for b
:= 0 to High(gDoorMap
[c
]) do
428 if gWalls
[gDoorMap
[c
, b
]].Enabled
then
430 g_Map_DisableWall_XXX(gDoorMap
[c
, b
]);
438 function tr_SetLift (PanelGUID
: Integer; d
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
446 pan
:= g_Map_PanelByGUID(PanelGUID
);
447 if (pan
= nil) or not pan
.isGLift
then exit
; //!FIXME!TRIGANY!
448 PanelID
:= pan
.arrIdx
;
450 if (gLifts
[PanelID
].PanelType
= PANEL_LIFTUP
) or (gLifts
[PanelID
].PanelType
= PANEL_LIFTDOWN
) then
455 else t
:= IfThen(gLifts
[PanelID
].LiftType
= 1, 0, 1);
458 else if (gLifts
[PanelID
].PanelType
= PANEL_LIFTLEFT
) or (gLifts
[PanelID
].PanelType
= PANEL_LIFTRIGHT
) then
463 else t
:= IfThen(gLifts
[PanelID
].LiftType
= 2, 3, 2);
469 with gLifts
[PanelID
] do
471 if (LiftType
<> t
) then
473 g_Map_SetLiftGUID(PanelGUID
, t
); //???
474 //if not NoSound then g_Sound_PlayExAt('SOUND_GAME_SWITCH0', X, Y);
481 if (gLiftMap
= nil) then exit
;
484 for a
:= 0 to High(gLiftMap
) do
486 for b
:= 0 to High(gLiftMap
[a
]) do
488 if (gLiftMap
[a
, b
] = DWORD(PanelID
)) then
494 if (c
<> -1) then break
;
496 if (c
= -1) then exit
;
499 for b := 0 to High(gLiftMap[c]) do
500 if gLifts[gLiftMap[c, b]].LiftType <> t then
502 with gLifts[PanelID] do
503 g_Sound_PlayExAt('SOUND_GAME_SWITCH0', X, Y);
507 for b
:= 0 to High(gLiftMap
[c
]) do
509 with gLifts
[gLiftMap
[c
, b
]] do
511 if (LiftType
<> t
) then
513 g_Map_SetLift_XXX(gLiftMap
[c
, b
], t
);
522 function tr_SpawnShot (ShotType
: Integer; wx
, wy
, dx
, dy
: Integer; ShotSound
: Boolean; ShotTarget
: Word): Integer;
530 TextureID
:= DWORD(-1);
531 snd
:= 'SOUND_WEAPON_FIREROCKET';
537 g_Weapon_pistol(wx
, wy
, dx
, dy
, 0, True);
538 snd
:= 'SOUND_WEAPON_FIREPISTOL';
542 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_BULLET
);
543 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL1
);
549 g_Weapon_mgun(wx
, wy
, dx
, dy
, 0, True);
550 if gSoundEffectsDF
then snd
:= 'SOUND_WEAPON_FIRECGUN'
551 else snd
:= 'SOUND_WEAPON_FIREPISTOL';
555 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_BULLET
);
556 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL1
);
560 TRIGGER_SHOT_SHOTGUN
:
562 g_Weapon_Shotgun(wx
, wy
, dx
, dy
, 0, True);
563 snd
:= 'SOUND_WEAPON_FIRESHOTGUN';
567 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
568 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL2
);
574 g_Weapon_DShotgun(wx
, wy
, dx
, dy
, 0, True);
575 snd
:= 'SOUND_WEAPON_FIRESHOTGUN2';
579 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
580 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
581 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL3
);
587 g_Weapon_ball1(wx
, wy
, dx
, dy
, 0, -1, True);
588 snd
:= 'SOUND_WEAPON_FIREBALL';
593 g_Weapon_Plasma(wx
, wy
, dx
, dy
, 0, -1, True);
594 snd
:= 'SOUND_WEAPON_FIREPLASMA';
599 g_Weapon_aplasma(wx
, wy
, dx
, dy
, 0, -1, True);
600 snd
:= 'SOUND_WEAPON_FIREPLASMA';
605 g_Weapon_ball2(wx
, wy
, dx
, dy
, 0, -1, True);
606 snd
:= 'SOUND_WEAPON_FIREBALL';
611 g_Weapon_ball7(wx
, wy
, dx
, dy
, 0, -1, True);
612 snd
:= 'SOUND_WEAPON_FIREBALL';
617 g_Weapon_manfire(wx
, wy
, dx
, dy
, 0, -1, True);
618 snd
:= 'SOUND_WEAPON_FIREBALL';
623 g_Weapon_revf(wx
, wy
, dx
, dy
, 0, ShotTarget
, -1, True);
624 snd
:= 'SOUND_WEAPON_FIREREV';
629 g_Weapon_Rocket(wx
, wy
, dx
, dy
, 0, -1, True);
630 snd
:= 'SOUND_WEAPON_FIREROCKET';
635 g_Weapon_BFGShot(wx
, wy
, dx
, dy
, 0, -1, True);
636 snd
:= 'SOUND_WEAPON_FIREBFG';
641 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_ROCKET') then
643 Anim
:= TAnimation
.Create(TextureID
, False, 6);
644 Anim
.Blending
:= False;
645 g_GFX_OnceAnim(wx
-64, wy
-64, Anim
);
649 g_Weapon_Explode(wx
, wy
, 60, 0);
650 snd
:= 'SOUND_WEAPON_EXPLODEROCKET';
653 TRIGGER_SHOT_BFGEXPL
:
655 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_BFG') then
657 Anim
:= TAnimation
.Create(TextureID
, False, 6);
658 Anim
.Blending
:= False;
659 g_GFX_OnceAnim(wx
-64, wy
-64, Anim
);
663 g_Weapon_BFG9000(wx
, wy
, 0);
664 snd
:= 'SOUND_WEAPON_EXPLODEBFG';
670 if g_Game_IsNet
and g_Game_IsServer
then
673 TRIGGER_SHOT_EXPL
: MH_SEND_Effect(wx
, wy
, Byte(ShotSound
), NET_GFX_EXPLODE
);
674 TRIGGER_SHOT_BFGEXPL
: MH_SEND_Effect(wx
, wy
, Byte(ShotSound
), NET_GFX_BFGEXPL
);
677 if Projectile
then MH_SEND_CreateShot(LastShotID
);
678 if ShotSound
then MH_SEND_Sound(wx
, wy
, snd
);
683 if ShotSound
then g_Sound_PlayExAt(snd
, wx
, wy
);
685 if Projectile
then Result
:= LastShotID
;
689 procedure MakeShot (var Trigger
: TTrigger
; wx
, wy
, dx
, dy
: Integer; TargetUID
: Word);
693 if (tgcAmmo
= 0) or ((tgcAmmo
> 0) and (ShotAmmoCount
> 0)) then
695 if (trigShotPanelGUID
<> -1) and (ShotPanelTime
= 0) then
697 g_Map_SwitchTextureGUID(ShotPanelType
, trigShotPanelGUID
);
698 ShotPanelTime
:= 4; // òèêîâ íà âñïûøêó âûñòðåëà
701 if (tgcSight
> 0) then ShotSightTimeout
:= 180; // ~= 5 ñåêóíä
703 if (ShotAmmoCount
> 0) then Dec(ShotAmmoCount
);
705 dx
+= Random(tgcAccuracy
)-Random(tgcAccuracy
);
706 dy
+= Random(tgcAccuracy
)-Random(tgcAccuracy
);
708 tr_SpawnShot(tgcShotType
, wx
, wy
, dx
, dy
, not tgcQuiet
, TargetUID
);
712 if (tgcReload
> 0) and (ShotReloadTime
= 0) then
714 ShotReloadTime
:= tgcReload
; // òèêîâ íà ïåðåçàðÿäêó ïóøêè
721 procedure tr_MakeEffect (X
, Y
, VX
, VY
: Integer; T
, ST
, CR
, CG
, CB
: Byte; Silent
, Send
: Boolean);
726 if T
= TRIGGER_EFFECT_PARTICLE
then
729 TRIGGER_EFFECT_SLIQUID
:
731 if (CR
= 255) and (CG
= 0) and (CB
= 0) then g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 1, 0, 0, 0)
732 else if (CR
= 0) and (CG
= 255) and (CB
= 0) then g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 2, 0, 0, 0)
733 else if (CR
= 0) and (CG
= 0) and (CB
= 255) then g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 3, 0, 0, 0)
734 else g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 0, 0, 0, 0);
736 TRIGGER_EFFECT_LLIQUID
: g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 4, CR
, CG
, CB
);
737 TRIGGER_EFFECT_DLIQUID
: g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 5, CR
, CG
, CB
);
738 TRIGGER_EFFECT_BLOOD
: g_GFX_Blood(X
, Y
, 1, VX
, VY
, 0, 0, CR
, CG
, CB
);
739 TRIGGER_EFFECT_SPARK
: g_GFX_Spark(X
, Y
, 1, GetAngle2(VX
, VY
), 0, 0);
740 TRIGGER_EFFECT_BUBBLE
: g_GFX_Bubbles(X
, Y
, 1, 0, 0);
744 if T
= TRIGGER_EFFECT_ANIMATION
then
747 EFFECT_TELEPORT
: begin
748 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
750 Anim
:= TAnimation
.Create(FramesID
, False, 3);
751 if not Silent
then g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
752 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
755 if Send
and g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(X
, Y
, Byte(not Silent
), NET_GFX_TELE
);
757 EFFECT_RESPAWN
: begin
758 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
760 Anim
:= TAnimation
.Create(FramesID
, False, 4);
761 if not Silent
then g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
762 g_GFX_OnceAnim(X
-16, Y
-16, Anim
);
765 if Send
and g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(X
-16, Y
-16, Byte(not Silent
), NET_GFX_RESPAWN
);
768 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
770 Anim
:= TAnimation
.Create(FramesID
, False, 4);
771 if not Silent
then g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
772 g_GFX_OnceAnim(X
-32, Y
-128, Anim
);
775 if Send
and g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(X
-32, Y
-128, Byte(not Silent
), NET_GFX_FIRE
);
782 function tr_Teleport (ActivateUID
: Integer; TX
, TY
: Integer; TDir
: Integer; Silent
: Boolean; D2D
: Boolean): Boolean;
788 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then Exit
;
789 case g_GetUIDType(ActivateUID
) of
792 p
:= g_Player_Get(ActivateUID
);
793 if p
= nil then Exit
;
796 if p
.TeleportTo(TX
-(p
.Obj
.Rect
.Width
div 2), TY
-p
.Obj
.Rect
.Height
, Silent
, TDir
) then result
:= true;
800 if p
.TeleportTo(TX
, TY
, Silent
, TDir
) then result
:= true;
805 m
:= g_Monsters_ByUID(ActivateUID
);
806 if m
= nil then Exit
;
809 if m
.TeleportTo(TX
-(m
.Obj
.Rect
.Width
div 2), TY
-m
.Obj
.Rect
.Height
, Silent
, TDir
) then result
:= true;
813 if m
.TeleportTo(TX
, TY
, Silent
, TDir
) then result
:= true;
820 function tr_Push (ActivateUID
: Integer; VX
, VY
: Integer; ResetVel
: Boolean): Boolean;
826 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then exit
;
827 case g_GetUIDType(ActivateUID
) of
830 p
:= g_Player_Get(ActivateUID
);
831 if p
= nil then Exit
;
846 m
:= g_Monsters_ByUID(ActivateUID
);
847 if m
= nil then Exit
;
863 function tr_Message (MKind
: Integer; MText
: string; MSendTo
: Integer; MTime
: Integer; ActivateUID
: Integer): Boolean;
870 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then Exit
;
871 msg
:= b_Text_Format(MText
);
873 TRIGGER_MESSAGE_DEST_ME
: // activator
875 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
877 if g_Game_IsWatchedPlayer(ActivateUID
) then
879 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
880 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
884 p
:= g_Player_Get(ActivateUID
);
885 if g_Game_IsNet
and (p
.FClientID
>= 0) then
887 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, p
.FClientID
)
888 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, p
.FClientID
);
894 TRIGGER_MESSAGE_DEST_MY_TEAM
: // activator's team
896 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
898 p
:= g_Player_Get(ActivateUID
);
899 if g_Game_IsWatchedTeam(p
.Team
) then
901 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
902 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
907 for i
:= Low(gPlayers
) to High(gPlayers
) do
909 if (gPlayers
[i
].Team
= p
.Team
) and (gPlayers
[i
].FClientID
>= 0) then
911 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
912 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
919 TRIGGER_MESSAGE_DEST_ENEMY_TEAM
: // activator's enemy team
921 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
923 p
:= g_Player_Get(ActivateUID
);
924 if g_Game_IsWatchedTeam(p
.Team
) then
926 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
927 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
932 for i
:= Low(gPlayers
) to High(gPlayers
) do
934 if (gPlayers
[i
].Team
<> p
.Team
) and (gPlayers
[i
].FClientID
>= 0) then
936 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
937 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
944 TRIGGER_MESSAGE_DEST_RED_TEAM
: // red team
946 if g_Game_IsWatchedTeam(TEAM_RED
) then
948 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
949 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
954 for i
:= Low(gPlayers
) to High(gPlayers
) do
956 if (gPlayers
[i
].Team
= TEAM_RED
) and (gPlayers
[i
].FClientID
>= 0) then
958 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
959 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
965 TRIGGER_MESSAGE_DEST_BLUE_TEAM
: // blue team
967 if g_Game_IsWatchedTeam(TEAM_BLUE
) then
969 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
970 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
975 for i
:= Low(gPlayers
) to High(gPlayers
) do
977 if (gPlayers
[i
].Team
= TEAM_BLUE
) and (gPlayers
[i
].FClientID
>= 0) then
979 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
980 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
986 TRIGGER_MESSAGE_DEST_EVERYONE
: // everyone
988 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
989 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
993 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
)
994 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
);
1001 function tr_ShotAimCheck (var Trigger
: TTrigger
; Obj
: PObj
): Boolean;
1006 if TriggerType
<> TRIGGER_SHOT
then Exit
;
1007 result
:= (tgcAim
and TRIGGER_SHOT_AIM_ALLMAP
> 0)
1008 or g_Obj_Collide(X
, Y
, Width
, Height
, Obj
);
1009 if result
and (tgcAim
and TRIGGER_SHOT_AIM_TRACE
> 0) then
1011 result
:= g_TraceVector(tgcTX
, tgcTY
,
1012 Obj
^.X
+ Obj
^.Rect
.X
+ (Obj
^.Rect
.Width
div 2),
1013 Obj
^.Y
+ Obj
^.Rect
.Y
+ (Obj
^.Rect
.Height
div 2));
1019 function ActivateTrigger (var Trigger
: TTrigger
; actType
: Byte): Boolean;
1025 idx
, k
, wx
, wy
, xd
, yd
: Integer;
1036 function monsShotTarget (mon
: TMonster
): Boolean;
1038 result
:= false; // don't stop
1039 if mon
.alive
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
1041 xd
:= mon
.GameX
+ mon
.Obj
.Rect
.Width
div 2;
1042 yd
:= mon
.GameY
+ mon
.Obj
.Rect
.Height
div 2;
1043 TargetUID
:= mon
.UID
;
1044 result
:= true; // stop
1048 function monsShotTargetMonPlr (mon
: TMonster
): Boolean;
1050 result
:= false; // don't stop
1051 if mon
.alive
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
1053 xd
:= mon
.GameX
+ mon
.Obj
.Rect
.Width
div 2;
1054 yd
:= mon
.GameY
+ mon
.Obj
.Rect
.Height
div 2;
1055 TargetUID
:= mon
.UID
;
1056 result
:= true; // stop
1060 function monShotTargetPlrMon (mon
: TMonster
): Boolean;
1062 result
:= false; // don't stop
1063 if mon
.alive
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
1065 xd
:= mon
.GameX
+ mon
.Obj
.Rect
.Width
div 2;
1066 yd
:= mon
.GameY
+ mon
.Obj
.Rect
.Height
div 2;
1067 TargetUID
:= mon
.UID
;
1068 result
:= true; // stop
1074 if g_Game_IsClient
then exit
;
1076 if not Trigger
.Enabled
then exit
;
1077 if (Trigger
.TimeOut
<> 0) and (actType
<> ACTIVATE_CUSTOM
) then exit
;
1078 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then exit
;
1082 coolDown
:= (actType
<> 0);
1089 g_Sound_PlayEx('SOUND_GAME_SWITCH0');
1090 if g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_SWITCH0');
1091 gExitByTrigger
:= True;
1092 g_Game_ExitLevel(tgcMap
);
1101 Result
:= tr_Teleport(ActivateUID
,
1102 tgcTarget
.X
, tgcTarget
.Y
,
1103 tgcDirection
, tgcSilent
,
1110 Result
:= tr_OpenDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
1116 Result
:= tr_CloseDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
1120 TRIGGER_DOOR
, TRIGGER_DOOR5
:
1122 pan
:= g_Map_PanelByGUID(trigPanelGUID
);
1123 if (pan
<> nil) and pan
.isGWall
then
1125 if gWalls
[{trigPanelID}pan
.arrIdx
].Enabled
then
1127 result
:= tr_OpenDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
1128 if (TriggerType
= TRIGGER_DOOR5
) then DoorTime
:= 180;
1132 result
:= tr_CloseDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
1135 if result
then TimeOut
:= 18;
1139 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
:
1141 tr_CloseTrap(trigPanelGUID
, tgcSilent
, tgcD2d
);
1143 if TriggerType
= TRIGGER_TRAP
then
1157 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
:
1160 if PressTime
= -1 then PressTime
:= tgcWait
;
1161 if coolDown
then TimeOut
:= 18 else TimeOut
:= 0;
1166 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
1170 if gLMSRespawn
= LMS_RESPAWN_NONE
then
1172 g_Player_Get(ActivateUID
).GetSecret();
1173 Inc(gCoopSecretsFound
);
1174 if g_Game_IsNet
then MH_SEND_GameStats();
1180 Result
:= tr_SetLift(trigPanelGUID
, 0, tgcSilent
, tgcD2d
);
1183 if (not tgcSilent
) and Result
then begin
1184 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1186 Y
+ (Height
div 2));
1187 if g_Game_IsServer
and g_Game_IsNet
then
1188 MH_SEND_Sound(X
+ (Width
div 2),
1190 'SOUND_GAME_SWITCH0');
1196 Result
:= tr_SetLift(trigPanelGUID
, 1, tgcSilent
, tgcD2d
);
1199 if (not tgcSilent
) and Result
then begin
1200 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1202 Y
+ (Height
div 2));
1203 if g_Game_IsServer
and g_Game_IsNet
then
1204 MH_SEND_Sound(X
+ (Width
div 2),
1206 'SOUND_GAME_SWITCH0');
1212 Result
:= tr_SetLift(trigPanelGUID
, 3, tgcSilent
, tgcD2d
);
1218 if (not tgcSilent
) and Result
then begin
1219 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1221 Y
+ (Height
div 2));
1222 if g_Game_IsServer
and g_Game_IsNet
then
1223 MH_SEND_Sound(X
+ (Width
div 2),
1225 'SOUND_GAME_SWITCH0');
1232 if tgcActivateOnce
then
1235 TriggerType
:= TRIGGER_NONE
;
1243 animonce
:= tgcAnimateOnce
;
1249 if Sound
<> nil then
1251 if tgcSoundSwitch
and Sound
.IsPlaying() then
1252 begin // Íóæíî âûêëþ÷èòü, åñëè èãðàë
1254 SoundPlayCount
:= 0;
1257 else // (not Data.SoundSwitch) or (not Sound.IsPlaying())
1258 if (tgcPlayCount
> 0) or (not Sound
.IsPlaying()) then
1260 if tgcPlayCount
> 0 then
1261 SoundPlayCount
:= tgcPlayCount
1262 else // 0 - èãðàåì áåñêîíå÷íî
1263 SoundPlayCount
:= 1;
1266 if g_Game_IsNet
then MH_SEND_TriggerSound(Trigger
);
1270 TRIGGER_SPAWNMONSTER
:
1271 if (tgcSpawnMonsType
in [MONSTER_DEMON
..MONSTER_MAN
]) then
1274 if (tgcDelay
> 0) and (actType
<> ACTIVATE_CUSTOM
) then
1276 AutoSpawn
:= not AutoSpawn
;
1278 // Àâòîñïàâíåð ïåðåêëþ÷åí - ìåíÿåì òåêñòóðó
1282 if ((tgcDelay
= 0) and (actType
<> ACTIVATE_CUSTOM
))
1283 or ((tgcDelay
> 0) and (actType
= ACTIVATE_CUSTOM
)) then
1284 for k
:= 1 to tgcMonsCount
do
1286 if (actType
= ACTIVATE_CUSTOM
) and (tgcDelay
> 0) then
1287 SpawnCooldown
:= tgcDelay
;
1288 if (tgcMax
> 0) and (SpawnedCount
>= tgcMax
) then
1291 mon
:= g_Monsters_Create(tgcSpawnMonsType
,
1293 TDirection(tgcDirection
), True);
1298 if (tgcHealth
> 0) then
1299 mon
.SetHealth(tgcHealth
);
1300 // Óñòàíàâëèâàåì ïîâåäåíèå:
1301 mon
.MonsterBehaviour
:= tgcBehaviour
;
1302 mon
.FNoRespawn
:= True;
1303 if g_Game_IsNet
then
1304 MH_SEND_MonsterSpawn(mon
.UID
);
1305 // Èäåì èñêàòü öåëü, åñëè íàäî:
1309 if tgcSpawnMonsType
<> MONSTER_BARREL
then Inc(gTotalMonsters
);
1311 if g_Game_IsNet
then
1313 SetLength(gMonstersSpawned
, Length(gMonstersSpawned
)+1);
1314 gMonstersSpawned
[High(gMonstersSpawned
)] := mon
.UID
;
1319 mon
.SpawnTrigger
:= ID
;
1324 EFFECT_TELEPORT
: begin
1325 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
1327 Anim
:= TAnimation
.Create(FramesID
, False, 3);
1328 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', tgcTX
, tgcTY
);
1329 g_GFX_OnceAnim(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1330 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-32, Anim
);
1333 if g_Game_IsServer
and g_Game_IsNet
then
1334 MH_SEND_Effect(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1335 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-32, 1,
1338 EFFECT_RESPAWN
: begin
1339 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
1341 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1342 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', tgcTX
, tgcTY
);
1343 g_GFX_OnceAnim(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-16,
1344 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-16, Anim
);
1347 if g_Game_IsServer
and g_Game_IsNet
then
1348 MH_SEND_Effect(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-16,
1349 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-16, 1,
1353 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
1355 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1356 g_Sound_PlayExAt('SOUND_FIRE', tgcTX
, tgcTY
);
1357 g_GFX_OnceAnim(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1358 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+mon
.Obj
.Rect
.Height
-128, Anim
);
1361 if g_Game_IsServer
and g_Game_IsNet
then
1362 MH_SEND_Effect(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1363 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+mon
.Obj
.Rect
.Height
-128, 1,
1368 if g_Game_IsNet
then
1370 MH_SEND_GameStats();
1371 MH_SEND_CoopStats();
1378 // Åñëè àêòèâèðîâàí àâòîñïàâíåðîì, íå ìåíÿåì òåêñòóðó
1379 if actType
= ACTIVATE_CUSTOM
then
1384 if (tgcSpawnItemType
in [ITEM_MEDKIT_SMALL
..ITEM_MAX
]) then
1387 if (tgcDelay
> 0) and (actType
<> ACTIVATE_CUSTOM
) then
1389 AutoSpawn
:= not AutoSpawn
;
1391 // Àâòîñïàâíåð ïåðåêëþ÷åí - ìåíÿåì òåêñòóðó
1395 if ((tgcDelay
= 0) and (actType
<> ACTIVATE_CUSTOM
))
1396 or ((tgcDelay
> 0) and (actType
= ACTIVATE_CUSTOM
)) then
1397 if (not tgcDmonly
) or
1398 (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
1399 for k
:= 1 to tgcItemCount
do
1401 if (actType
= ACTIVATE_CUSTOM
) and (tgcDelay
> 0) then
1402 SpawnCooldown
:= tgcDelay
;
1403 if (tgcMax
> 0) and (SpawnedCount
>= tgcMax
) then
1406 iid
:= g_Items_Create(tgcTX
, tgcTY
,
1407 tgcSpawnItemType
, tgcGravity
, False, True);
1413 it
:= g_Items_ByIdx(iid
);
1414 it
.SpawnTrigger
:= ID
;
1419 EFFECT_TELEPORT
: begin
1420 it
:= g_Items_ByIdx(iid
);
1421 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
1423 Anim
:= TAnimation
.Create(FramesID
, False, 3);
1424 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', tgcTX
, tgcTY
);
1425 g_GFX_OnceAnim(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1426 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-32, Anim
);
1429 if g_Game_IsServer
and g_Game_IsNet
then
1430 MH_SEND_Effect(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1431 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-32, 1,
1434 EFFECT_RESPAWN
: begin
1435 it
:= g_Items_ByIdx(iid
);
1436 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
1438 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1439 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', tgcTX
, tgcTY
);
1440 g_GFX_OnceAnim(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-16,
1441 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-16, Anim
);
1444 if g_Game_IsServer
and g_Game_IsNet
then
1445 MH_SEND_Effect(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-16,
1446 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-16, 1,
1450 it
:= g_Items_ByIdx(iid
);
1451 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
1453 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1454 g_Sound_PlayExAt('SOUND_FIRE', tgcTX
, tgcTY
);
1455 g_GFX_OnceAnim(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1456 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+it
.Obj
.Rect
.Height
-128, Anim
);
1459 if g_Game_IsServer
and g_Game_IsNet
then
1460 MH_SEND_Effect(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1461 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+it
.Obj
.Rect
.Height
-128, 1,
1466 if g_Game_IsNet
then
1467 MH_SEND_ItemSpawn(True, iid
);
1474 // Åñëè àêòèâèðîâàí àâòîñïàâíåðîì, íå ìåíÿåì òåêñòóðó
1475 if actType
= ACTIVATE_CUSTOM
then
1481 // Ìåíÿåì ìóçûêó, åñëè åñòü íà ÷òî:
1482 if (Trigger
.tgcMusicName
<> '') then
1484 gMusic
.SetByName(Trigger
.tgcMusicName
);
1485 gMusic
.SpecPause
:= True;
1489 case Trigger
.tgcMusicAction
of
1490 TRIGGER_MUSIC_ACTION_STOP
: // Âûêëþ÷èòü
1491 gMusic
.SpecPause
:= True; // Ïàóçà
1492 TRIGGER_MUSIC_ACTION_PLAY
: // Âêëþ÷èòü
1493 if gMusic
.SpecPause
then // Áûëà íà ïàóçå => èãðàòü
1494 gMusic
.SpecPause
:= False
1495 else // Èãðàëà => ñíà÷àëà
1496 gMusic
.SetPosition(0);
1504 if g_Game_IsNet
then MH_SEND_TriggerMusic
;
1509 pAngle
:= -DegToRad(tgcAngle
);
1510 Result
:= tr_Push(ActivateUID
,
1511 Floor(Cos(pAngle
)*tgcForce
),
1512 Floor(Sin(pAngle
)*tgcForce
),
1520 // Ïðèáàâèòü èëè îòíÿòü î÷êî
1521 if (tgcScoreAction
in [TRIGGER_SCORE_ACTION_ADD
, TRIGGER_SCORE_ACTION_SUB
]) and (tgcScoreCount
> 0) then
1523 // Ñâîåé èëè ÷óæîé êîìàíäå
1524 if (tgcScoreTeam
in [TRIGGER_SCORE_TEAM_MINE_RED
, TRIGGER_SCORE_TEAM_MINE_BLUE
]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
1526 p
:= g_Player_Get(ActivateUID
);
1527 if ((tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_RED
))
1528 or ((tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_BLUE
)) then
1530 Inc(gTeamStat
[TEAM_RED
].Goals
, tgcScoreCount
); // Red Scores
1534 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1536 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_OWN
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1537 if g_Game_IsServer
and g_Game_IsNet
then
1538 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '+r');
1541 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_ENEMY
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1542 if g_Game_IsServer
and g_Game_IsNet
then
1543 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '+re');
1549 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1550 if g_Game_IsServer
and g_Game_IsNet
then
1551 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_RED
);
1554 if ((tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_RED
))
1555 or ((tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_BLUE
)) then
1557 Dec(gTeamStat
[TEAM_RED
].Goals
, tgcScoreCount
); // Red Fouls
1561 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1563 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_OWN
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1564 if g_Game_IsServer
and g_Game_IsNet
then
1565 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '-r');
1568 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_ENEMY
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1569 if g_Game_IsServer
and g_Game_IsNet
then
1570 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '-re');
1576 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1577 if g_Game_IsServer
and g_Game_IsNet
then
1578 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_RED
);
1581 if ((tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_BLUE
))
1582 or ((tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_RED
)) then
1584 Inc(gTeamStat
[TEAM_BLUE
].Goals
, tgcScoreCount
); // Blue Scores
1588 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1590 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_OWN
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1591 if g_Game_IsServer
and g_Game_IsNet
then
1592 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '+b');
1595 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_ENEMY
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1596 if g_Game_IsServer
and g_Game_IsNet
then
1597 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '+be');
1603 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1604 if g_Game_IsServer
and g_Game_IsNet
then
1605 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_BLUE
);
1608 if ((tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_BLUE
))
1609 or ((tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_RED
)) then
1611 Dec(gTeamStat
[TEAM_BLUE
].Goals
, tgcScoreCount
); // Blue Fouls
1615 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1617 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_OWN
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1618 if g_Game_IsServer
and g_Game_IsNet
then
1619 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '-b');
1622 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_ENEMY
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1623 if g_Game_IsServer
and g_Game_IsNet
then
1624 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '-be');
1630 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1631 if g_Game_IsServer
and g_Game_IsNet
then
1632 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_BLUE
);
1635 Result
:= (p
.Team
= TEAM_RED
) or (p
.Team
= TEAM_BLUE
);
1637 // Êàêîé-òî êîíêðåòíîé êîìàíäå
1638 if tgcScoreTeam
in [TRIGGER_SCORE_TEAM_FORCE_RED
, TRIGGER_SCORE_TEAM_FORCE_BLUE
] then
1640 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_RED
) then
1642 Inc(gTeamStat
[TEAM_RED
].Goals
, tgcScoreCount
); // Red Scores
1646 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_TEAM
], [_lc
[I_PLAYER_SCORE_RED
], tgcScoreCount
]), True);
1647 if g_Game_IsServer
and g_Game_IsNet
then
1648 MH_SEND_GameEvent(NET_EV_SCORE
, tgcScoreCount
shl 16, '+tr');
1653 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1654 if g_Game_IsServer
and g_Game_IsNet
then
1655 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_RED
);
1658 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_RED
) then
1660 Dec(gTeamStat
[TEAM_RED
].Goals
, tgcScoreCount
); // Red Fouls
1664 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_TEAM
], [_lc
[I_PLAYER_SCORE_RED
], tgcScoreCount
]), True);
1665 if g_Game_IsServer
and g_Game_IsNet
then
1666 MH_SEND_GameEvent(NET_EV_SCORE
, tgcScoreCount
shl 16, '-tr');
1671 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1672 if g_Game_IsServer
and g_Game_IsNet
then
1673 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_RED
);
1676 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_BLUE
) then
1678 Inc(gTeamStat
[TEAM_BLUE
].Goals
, tgcScoreCount
); // Blue Scores
1682 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_TEAM
], [_lc
[I_PLAYER_SCORE_BLUE
], tgcScoreCount
]), True);
1683 if g_Game_IsServer
and g_Game_IsNet
then
1684 MH_SEND_GameEvent(NET_EV_SCORE
, tgcScoreCount
shl 16, '+tb');
1689 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1690 if g_Game_IsServer
and g_Game_IsNet
then
1691 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_BLUE
);
1694 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_BLUE
) then
1696 Dec(gTeamStat
[TEAM_BLUE
].Goals
, tgcScoreCount
); // Blue Fouls
1700 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_TEAM
], [_lc
[I_PLAYER_SCORE_BLUE
], tgcScoreCount
]), True);
1701 if g_Game_IsServer
and g_Game_IsNet
then
1702 MH_SEND_GameEvent(NET_EV_SCORE
, tgcScoreCount
shl 16, '-tb');
1707 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1708 if g_Game_IsServer
and g_Game_IsNet
then
1709 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_BLUE
);
1716 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_WIN
) and (gGameSettings
.GoalLimit
> 0) then
1718 // Ñâîåé èëè ÷óæîé êîìàíäû
1719 if (tgcScoreTeam
in [TRIGGER_SCORE_TEAM_MINE_RED
, TRIGGER_SCORE_TEAM_MINE_BLUE
]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
1721 p
:= g_Player_Get(ActivateUID
);
1722 if ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_RED
)) // Red Wins
1723 or ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_BLUE
)) then
1725 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1727 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1731 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1733 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1734 if g_Game_IsServer
and g_Game_IsNet
then
1735 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wr');
1738 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1739 if g_Game_IsServer
and g_Game_IsNet
then
1740 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wre');
1747 if ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_BLUE
)) // Blue Wins
1748 or ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_RED
)) then
1750 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1752 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1756 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1758 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1759 if g_Game_IsServer
and g_Game_IsNet
then
1760 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wb');
1763 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1764 if g_Game_IsServer
and g_Game_IsNet
then
1765 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wbe');
1773 // Êàêîé-òî êîíêðåòíîé êîìàíäû
1774 if tgcScoreTeam
in [TRIGGER_SCORE_TEAM_FORCE_RED
, TRIGGER_SCORE_TEAM_FORCE_BLUE
] then
1776 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_RED
) then // Red Wins
1778 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1780 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1784 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_BLUE
) then // Blue Wins
1786 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1788 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1795 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_LOOSE
) and (gGameSettings
.GoalLimit
> 0) then
1797 // Ñâîåé èëè ÷óæîé êîìàíäû
1798 if (tgcScoreTeam
in [TRIGGER_SCORE_TEAM_MINE_RED
, TRIGGER_SCORE_TEAM_MINE_BLUE
]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
1800 p
:= g_Player_Get(ActivateUID
);
1801 if ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_BLUE
)) // Red Wins
1802 or ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_RED
)) then
1803 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1805 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1808 if tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
then
1810 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1811 if g_Game_IsServer
and g_Game_IsNet
then
1812 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wre');
1815 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1816 if g_Game_IsServer
and g_Game_IsNet
then
1817 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wr');
1822 if ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_RED
)) // Blue Wins
1823 or ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_BLUE
)) then
1824 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1826 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1829 if tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
then
1831 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1832 if g_Game_IsServer
and g_Game_IsNet
then
1833 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wbe');
1836 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1837 if g_Game_IsServer
and g_Game_IsNet
then
1838 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wb');
1844 // Êàêîé-òî êîíêðåòíîé êîìàíäû
1845 if tgcScoreTeam
in [TRIGGER_SCORE_TEAM_FORCE_BLUE
, TRIGGER_SCORE_TEAM_FORCE_RED
] then
1847 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_BLUE
) then // Red Wins
1849 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1851 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1855 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_RED
) then // Blue Wins
1857 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1859 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1865 if Result
then begin
1870 if g_Game_IsServer
and g_Game_IsNet
then
1877 Result
:= tr_Message(tgcKind
, tgcText
,
1878 tgcMsgDest
, tgcMsgTime
,
1883 TRIGGER_DAMAGE
, TRIGGER_HEALTH
:
1886 UIDType
:= g_GetUIDType(ActivateUID
);
1887 if (UIDType
= UID_PLAYER
) or (UIDType
= UID_MONSTER
) then
1893 // Âñïîìèíàåì, àêòèâèðîâàë ëè îí ìåíÿ ðàíüøå
1894 for idx
:= 0 to High(Activators
) do
1895 if Activators
[idx
].UID
= ActivateUID
then
1901 begin // Âèäèì åãî âïåðâûå
1903 SetLength(Activators
, Length(Activators
) + 1);
1904 k
:= High(Activators
);
1905 Activators
[k
].UID
:= ActivateUID
;
1907 begin // Óæå âèäåëè åãî
1908 // Åñëè èíòåðâàë îòêëþ÷¸í, íî îí âñ¸ åù¸ â çîíå ïîðàæåíèÿ, äà¸ì åìó âðåìÿ
1909 if (tgcInterval
= 0) and (Activators
[k
].TimeOut
> 0) then
1910 Activators
[k
].TimeOut
:= 65535;
1911 // Òàéìàóò ïðîø¸ë - ðàáîòàåì
1912 Result
:= Activators
[k
].TimeOut
= 0;
1921 p
:= g_Player_Get(ActivateUID
);
1925 // Íàíîñèì óðîí èãðîêó
1926 if (TriggerType
= TRIGGER_DAMAGE
) and (tgcAmount
> 0) then
1927 p
.Damage(tgcAmount
, 0, 0, 0, HIT_SOME
);
1930 if (TriggerType
= TRIGGER_HEALTH
) and (tgcAmount
> 0) then
1931 if p
.Heal(tgcAmount
, not tgcHealMax
) and (not tgcSilent
) then
1933 g_Sound_PlayExAt('SOUND_ITEM_GETITEM', p
.Obj
.X
, p
.Obj
.Y
);
1934 if g_Game_IsServer
and g_Game_IsNet
then
1935 MH_SEND_Sound(p
.Obj
.X
, p
.Obj
.Y
, 'SOUND_ITEM_GETITEM');
1941 m
:= g_Monsters_ByUID(ActivateUID
);
1945 // Íàíîñèì óðîí ìîíñòðó
1946 if (TriggerType
= TRIGGER_DAMAGE
) and (tgcAmount
> 0) then
1947 m
.Damage(tgcAmount
, 0, 0, 0, HIT_SOME
);
1950 if (TriggerType
= TRIGGER_HEALTH
) and (tgcAmount
> 0) then
1951 if m
.Heal(tgcAmount
) and (not tgcSilent
) then
1953 g_Sound_PlayExAt('SOUND_ITEM_GETITEM', m
.Obj
.X
, m
.Obj
.Y
);
1954 if g_Game_IsServer
and g_Game_IsNet
then
1955 MH_SEND_Sound(m
.Obj
.X
, m
.Obj
.Y
, 'SOUND_ITEM_GETITEM');
1959 // Íàçíà÷àåì âðåìÿ ñëåäóþùåãî âîçäåéñòâèÿ
1963 Activators
[k
].TimeOut
:= idx
1965 Activators
[k
].TimeOut
:= 65535;
1973 if ShotSightTime
> 0 then
1976 // put this at the beginning so it doesn't trigger itself
1977 TimeOut
:= tgcWait
+ 1;
1981 pAngle
:= -DegToRad(tgcAngle
);
1982 xd
:= wx
+ Round(Cos(pAngle
) * 32.0);
1983 yd
:= wy
+ Round(Sin(pAngle
) * 32.0);
1986 case tgcShotTarget
of
1987 TRIGGER_SHOT_TARGET_MON
: // monsters
1988 //TODO: accelerate this!
1989 g_Mons_ForEachAlive(monsShotTarget
);
1991 TRIGGER_SHOT_TARGET_PLR
: // players
1992 if gPlayers
<> nil then
1993 for idx
:= Low(gPlayers
) to High(gPlayers
) do
1994 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
1995 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
1997 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
1998 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
1999 TargetUID
:= gPlayers
[idx
].UID
;
2003 TRIGGER_SHOT_TARGET_RED
: // red team
2004 if gPlayers
<> nil then
2005 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2006 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2007 (gPlayers
[idx
].Team
= TEAM_RED
) and
2008 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2010 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2011 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2012 TargetUID
:= gPlayers
[idx
].UID
;
2016 TRIGGER_SHOT_TARGET_BLUE
: // blue team
2017 if gPlayers
<> nil then
2018 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2019 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2020 (gPlayers
[idx
].Team
= TEAM_BLUE
) and
2021 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2023 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2024 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2025 TargetUID
:= gPlayers
[idx
].UID
;
2029 TRIGGER_SHOT_TARGET_MONPLR
: // monsters then players
2031 //TODO: accelerate this!
2032 g_Mons_ForEachAlive(monsShotTargetMonPlr
);
2034 if (TargetUID
= 0) and (gPlayers
<> nil) then
2035 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2036 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2037 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2039 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2040 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2041 TargetUID
:= gPlayers
[idx
].UID
;
2046 TRIGGER_SHOT_TARGET_PLRMON
: // players then monsters
2048 if gPlayers
<> nil then
2049 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2050 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2051 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2053 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2054 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2055 TargetUID
:= gPlayers
[idx
].UID
;
2058 if TargetUID
= 0 then
2060 //TODO: accelerate this!
2061 g_Mons_ForEachAlive(monShotTargetPlrMon
);
2066 if (tgcShotTarget
<> TRIGGER_SHOT_TARGET_NONE
) or
2067 (tgcShotType
<> TRIGGER_SHOT_REV
) then
2068 TargetUID
:= ActivateUID
;
2072 if (tgcShotTarget
= TRIGGER_SHOT_TARGET_NONE
) or (TargetUID
> 0) or
2073 ((tgcShotTarget
> TRIGGER_SHOT_TARGET_NONE
) and (TargetUID
= 0)) then
2076 if (tgcSight
= 0) or
2077 (tgcShotTarget
= TRIGGER_SHOT_TARGET_NONE
) or
2078 (TargetUID
= ShotSightTarget
) then
2079 MakeShot(Trigger
, wx
, wy
, xd
, yd
, TargetUID
)
2082 ShotSightTime
:= tgcSight
;
2083 ShotSightTargetN
:= TargetUID
;
2084 if tgcShotType
= TRIGGER_SHOT_BFG
then
2086 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', wx
, wy
);
2087 if g_Game_IsNet
and g_Game_IsServer
then
2088 MH_SEND_Sound(wx
, wy
, 'SOUND_WEAPON_STARTFIREBFG');
2101 TRIGGER_EFFECT_POS_CENTER
:
2103 wx
:= X
+ Width
div 2;
2104 wy
:= Y
+ Height
div 2;
2106 TRIGGER_EFFECT_POS_AREA
:
2108 wx
:= X
+ Random(Width
);
2109 wy
:= Y
+ Random(Height
);
2112 wx
:= X
+ Width
div 2;
2113 wy
:= Y
+ Height
div 2;
2118 if tgcSpreadL
> 0 then xd
-= Random(tgcSpreadL
+1);
2119 if tgcSpreadR
> 0 then xd
+= Random(tgcSpreadR
+1);
2120 if tgcSpreadU
> 0 then yd
-= Random(tgcSpreadU
+1);
2121 if tgcSpreadD
> 0 then yd
+= Random(tgcSpreadD
+1);
2122 tr_MakeEffect(wx
, wy
, xd
, yd
,
2123 tgcFXType
, tgcFXSubType
,
2124 tgcFXRed
, tgcFXGreen
, tgcFXBlue
, True, False);
2132 if Result
{and (Trigger.TexturePanel <> -1)} then
2134 g_Map_SwitchTextureGUID(Trigger
.TexturePanelType
, Trigger
.TexturePanelGUID
, IfThen(animonce
, 2, 1));
2139 function g_Triggers_CreateWithMapIndex (Trigger
: TTrigger
; arridx
, mapidx
: Integer): DWORD
;
2141 triggers
: TDynField
;
2143 triggers
:= gCurrentMap
['trigger'];
2144 if (triggers
= nil) then raise Exception
.Create('LOAD: map has no triggers');
2145 if (mapidx
< 0) or (mapidx
>= triggers
.count
) then raise Exception
.Create('LOAD: invalid map trigger index');
2146 Trigger
.trigDataRec
:= triggers
.itemAt
[mapidx
];
2147 if (Trigger
.trigDataRec
= nil) then raise Exception
.Create('LOAD: internal error in trigger loader');
2148 Trigger
.mapId
:= Trigger
.trigDataRec
.id
;
2149 Trigger
.mapIndex
:= mapidx
;
2150 if (Trigger
.trigDataRec
.trigRec
<> nil) then
2152 Trigger
.trigDataRec
:= Trigger
.trigDataRec
.trigRec
.clone(nil);
2156 Trigger
.trigDataRec
:= nil;
2158 result
:= g_Triggers_Create(Trigger
, arridx
);
2162 function g_Triggers_Create(Trigger
: TTrigger
; forceInternalIndex
: Integer=-1): DWORD
;
2165 fn
, mapw
: AnsiString;
2168 // Íå ñîçäàâàòü âûõîä, åñëè èãðà áåç âûõîäà
2169 if (Trigger
.TriggerType
= TRIGGER_EXIT
) and
2170 (not LongBool(gGameSettings
.Options
and GAME_OPTION_ALLOWEXIT
)) then
2171 Trigger
.TriggerType
:= TRIGGER_NONE
;
2173 // Åñëè ìîíñòðû çàïðåùåíû, îòìåíÿåì òðèããåð
2174 if (Trigger
.TriggerType
= TRIGGER_SPAWNMONSTER
) and
2175 (not LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
)) and
2176 (gGameSettings
.GameType
<> GT_SINGLE
) then
2177 Trigger
.TriggerType
:= TRIGGER_NONE
;
2179 // Ñ÷èòàåì êîëè÷åñòâî ñåêðåòîâ íà êàðòå
2180 if Trigger
.TriggerType
= TRIGGER_SECRET
then gSecretsCount
+= 1;
2182 if (forceInternalIndex
< 0) then
2184 find_id
:= FindTrigger();
2188 olen
:= Length(gTriggers
);
2189 if (forceInternalIndex
>= olen
) then
2191 SetLength(gTriggers
, forceInternalIndex
+1);
2192 for f
:= olen
to High(gTriggers
) do gTriggers
[f
].TriggerType
:= TRIGGER_NONE
;
2194 find_id
:= DWORD(forceInternalIndex
);
2196 gTriggers
[find_id
] := Trigger
;
2198 with gTriggers
[find_id
] do
2201 // if this type of trigger exists both on the client and on the server
2202 // use an uniform numeration
2203 if Trigger
.TriggerType
= TRIGGER_SOUND
then
2205 Inc(gTriggerClientID
);
2206 ClientID
:= gTriggerClientID
;
2214 PlayerCollide
:= False;
2218 SoundPlayCount
:= 0;
2225 // update cached trigger variables
2226 trigUpdateCacheData(gTriggers
[find_id
], gTriggers
[find_id
].trigDataRec
);
2228 // Çàãðóæàåì çâóê, åñëè ýòî òðèããåð "Çâóê"
2229 if (Trigger
.TriggerType
= TRIGGER_SOUND
) and (Trigger
.tgcSoundName
<> '') then
2231 // Åùå íåò òàêîãî çâóêà
2232 if not g_Sound_Exists(Trigger
.tgcSoundName
) then
2234 fn
:= g_ExtractWadName(Trigger
.tgcSoundName
);
2236 begin // Çâóê â ôàéëå ñ êàðòîé
2237 mapw
:= g_ExtractWadName(gMapInfo
.Map
);
2238 fn
:= mapw
+':'+g_ExtractFilePathName(Trigger
.tgcSoundName
);
2240 else // Çâóê â îòäåëüíîì ôàéëå
2242 fn
:= GameDir
+ '/wads/' + Trigger
.tgcSoundName
;
2245 if not g_Sound_CreateWADEx(Trigger
.tgcSoundName
, fn
) then
2247 g_FatalError(Format(_lc
[I_GAME_ERROR_TR_SOUND
], [fn
, Trigger
.tgcSoundName
]));
2251 // Ñîçäàåì îáúåêò çâóêà
2252 with gTriggers
[find_id
] do
2254 Sound
:= TPlayableSound
.Create();
2255 if not Sound
.SetByName(Trigger
.tgcSoundName
) then
2263 // Çàãðóæàåì ìóçûêó, åñëè ýòî òðèããåð "Ìóçûêà"
2264 if (Trigger
.TriggerType
= TRIGGER_MUSIC
) and (Trigger
.tgcMusicName
<> '') then
2266 // Åùå íåò òàêîé ìóçûêè
2267 if not g_Sound_Exists(Trigger
.tgcMusicName
) then
2269 fn
:= g_ExtractWadName(Trigger
.tgcMusicName
);
2272 begin // Ìóçûêà â ôàéëå ñ êàðòîé
2273 mapw
:= g_ExtractWadName(gMapInfo
.Map
);
2274 fn
:= mapw
+':'+g_ExtractFilePathName(Trigger
.tgcMusicName
);
2276 else // Ìóçûêà â ôàéëå ñ êàðòîé
2278 fn
:= GameDir
+'/wads/'+Trigger
.tgcMusicName
;
2281 if not g_Sound_CreateWADEx(Trigger
.tgcMusicName
, fn
, True) then
2283 g_FatalError(Format(_lc
[I_GAME_ERROR_TR_SOUND
], [fn
, Trigger
.tgcMusicName
]));
2288 // Çàãðóæàåì äàííûå òðèããåðà "Òóðåëü"
2289 if Trigger
.TriggerType
= TRIGGER_SHOT
then
2291 with gTriggers
[find_id
] do
2295 ShotSightTimeout
:= 0;
2296 ShotSightTarget
:= 0;
2297 ShotSightTargetN
:= 0;
2298 ShotAmmoCount
:= Trigger
.tgcAmmo
;
2299 ShotReloadTime
:= 0;
2307 // sorry; grid doesn't support recursive queries, so we have to do this
2309 TSimpleMonsterList
= specialize TSimpleList
<TMonster
>;
2312 tgMonsList
: TSimpleMonsterList
= nil;
2314 procedure g_Triggers_Update();
2317 Affected
: array of Integer;
2319 function monsNear (mon
: TMonster
): Boolean;
2321 result
:= false; // don't stop
2323 gTriggers[a].ActivateUID := mon.UID;
2324 ActivateTrigger(gTriggers[a], ACTIVATE_MONSTERCOLLIDE);
2326 tgMonsList
.append(mon
);
2333 if (tgMonsList
= nil) then tgMonsList
:= TSimpleMonsterList
.Create();
2335 if gTriggers
= nil then
2337 SetLength(Affected
, 0);
2339 for a
:= 0 to High(gTriggers
) do
2340 with gTriggers
[a
] do
2342 if TriggerType
<> TRIGGER_NONE
then
2344 // Óìåíüøàåì âðåìÿ äî çàêðûòèÿ äâåðè (îòêðûòèÿ ëîâóøêè)
2345 if DoorTime
> 0 then DoorTime
:= DoorTime
- 1;
2346 // Óìåíüøàåì âðåìÿ îæèäàíèÿ ïîñëå íàæàòèÿ
2347 if PressTime
> 0 then PressTime
:= PressTime
- 1;
2348 // Ïðîâåðÿåì èãðîêîâ è ìîíñòðîâ, êîòîðûõ ðàíåå çàïîìíèëè:
2349 if (TriggerType
= TRIGGER_DAMAGE
) or (TriggerType
= TRIGGER_HEALTH
) then
2351 for b
:= 0 to High(Activators
) do
2353 // Óìåíüøàåì âðåìÿ äî ïîâòîðíîãî âîçäåéñòâèÿ:
2354 if Activators
[b
].TimeOut
> 0 then
2356 Dec(Activators
[b
].TimeOut
);
2362 // Ñ÷èòàåì, ÷òî îáúåêò ïîêèíóë çîíó äåéñòâèÿ òðèããåðà
2363 if (tgcInterval
= 0) and (Activators
[b
].TimeOut
< 65530) then Activators
[b
].TimeOut
:= 0;
2367 // Îáðàáàòûâàåì ñïàâíåðû
2368 if Enabled
and AutoSpawn
then
2370 if SpawnCooldown
= 0 then
2372 // Åñëè ïðèøëî âðåìÿ, ñïàâíèì ìîíñòðà
2373 if (TriggerType
= TRIGGER_SPAWNMONSTER
) and (tgcDelay
> 0) then
2376 ActivateTrigger(gTriggers
[a
], ACTIVATE_CUSTOM
);
2378 // Åñëè ïðèøëî âðåìÿ, ñïàâíèì ïðåäìåò
2379 if (TriggerType
= TRIGGER_SPAWNITEM
) and (tgcDelay
> 0) then
2382 ActivateTrigger(gTriggers
[a
], ACTIVATE_CUSTOM
);
2387 // Óìåíüøàåì âðåìÿ îæèäàíèÿ
2392 // Îáðàáàòûâàåì ñîáûòèÿ òðèããåðà "Òóðåëü"
2393 if TriggerType
= TRIGGER_SHOT
then
2395 if ShotPanelTime
> 0 then
2398 if ShotPanelTime
= 0 then g_Map_SwitchTextureGUID(ShotPanelType
, trigShotPanelGUID
);
2400 if ShotSightTime
> 0 then
2403 if ShotSightTime
= 0 then ShotSightTarget
:= ShotSightTargetN
;
2405 if ShotSightTimeout
> 0 then
2407 Dec(ShotSightTimeout
);
2408 if ShotSightTimeout
= 0 then ShotSightTarget
:= 0;
2410 if ShotReloadTime
> 0 then
2412 Dec(ShotReloadTime
);
2413 if ShotReloadTime
= 0 then ShotAmmoCount
:= tgcAmmo
;
2417 // Òðèããåð "Çâóê" óæå îòûãðàë, åñëè íóæíî åùå - ïåðåçàïóñêàåì
2418 if Enabled
and (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) then
2420 if (SoundPlayCount
> 0) and (not Sound
.IsPlaying()) then
2422 if tgcPlayCount
> 0 then SoundPlayCount
-= 1; // Åñëè 0 - èãðàåì çâóê áåñêîíå÷íî
2425 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0);
2429 Sound
.PlayPanVolume((tgcPan
-127.0)/128.0, tgcVolume
/255.0);
2431 if Sound
.IsPlaying() and g_Game_IsNet
and g_Game_IsServer
then MH_SEND_TriggerSound(gTriggers
[a
]);
2435 // Òðèããåð "Ëîâóøêà" - ïîðà îòêðûâàòü
2436 if (TriggerType
= TRIGGER_TRAP
) and (DoorTime
= 0) and (g_Map_PanelByGUID(trigPanelGUID
) <> nil) then
2438 tr_OpenDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
2442 // Òðèããåð "Äâåðü 5 ñåê" - ïîðà çàêðûâàòü
2443 if (TriggerType
= TRIGGER_DOOR5
) and (DoorTime
= 0) and (g_Map_PanelByGUID(trigPanelGUID
) <> nil) then
2445 pan
:= g_Map_PanelByGUID(trigPanelGUID
);
2446 if (pan
<> nil) and pan
.isGWall
then
2449 if {gWalls[trigPanelID].Enabled} pan
.Enabled
then
2455 // Ïîêà îòêðûòà - çàêðûâàåì
2456 if tr_CloseDoor(trigPanelGUID
, tgcSilent
, tgcD2d
) then DoorTime
:= -1;
2461 // Òðèããåð - ðàñøèðèòåëü èëè ïåðåêëþ÷àòåëü, è ïðîøëà çàäåðæêà, è íàæàëè íóæíîå ÷èñëî ðàç:
2462 if (TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
]) and
2463 (PressTime
= 0) and (PressCount
>= tgcPressCount
) then
2465 // Ñáðàñûâàåì çàäåðæêó àêòèâàöèè:
2467 // Ñáðàñûâàåì ñ÷åò÷èê íàæàòèé:
2468 if tgcPressCount
> 0 then PressCount
-= tgcPressCount
else PressCount
:= 0;
2470 // Îïðåäåëÿåì èçìåíÿåìûå èì òðèããåðû:
2471 for b
:= 0 to High(gTriggers
) do
2473 if g_Collide(tgcTX
, tgcTY
, tgcTWidth
, tgcTHeight
, gTriggers
[b
].X
, gTriggers
[b
].Y
,
2474 gTriggers
[b
].Width
, gTriggers
[b
].Height
) and
2475 ((b
<> a
) or (tgcWait
> 0)) then
2476 begin // Can be self-activated, if there is Data.Wait
2477 if (not tgcExtRandom
) or gTriggers
[b
].Enabled
then
2479 SetLength(Affected
, Length(Affected
) + 1);
2480 Affected
[High(Affected
)] := b
;
2486 // if we have panelid, assume that it will switch the moving platform
2487 pan
:= g_Map_PanelByGUID(trigPanelGUID
);
2488 if (pan
<> nil) then
2491 TRIGGER_PRESS
: pan
.movingActive
:= true; // what to do here?
2492 TRIGGER_ON
: pan
.movingActive
:= true;
2493 TRIGGER_OFF
: pan
.movingActive
:= false;
2494 TRIGGER_ONOFF
: pan
.movingActive
:= not pan
.movingActive
;
2496 if not tgcSilent
and (Length(tgcSound
) > 0) then
2498 g_Sound_PlayExAt(tgcSound
, X
, Y
);
2499 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, tgcSound
);
2503 // Âûáèðàåì îäèí èç òðèããåðîâ äëÿ ðàñøèðèòåëÿ, åñëè âêëþ÷åí ðàíäîì:
2504 if (TriggerType
= TRIGGER_PRESS
) and tgcExtRandom
then
2506 if (Length(Affected
) > 0) then
2508 b
:= Affected
[Random(Length(Affected
))];
2509 gTriggers
[b
].ActivateUID
:= gTriggers
[a
].ActivateUID
;
2510 ActivateTrigger(gTriggers
[b
], 0);
2513 else //  ïðîòèâíîì ñëó÷àå ðàáîòàåì êàê îáû÷íî:
2515 for i
:= 0 to High(Affected
) do
2521 gTriggers
[b
].ActivateUID
:= gTriggers
[a
].ActivateUID
;
2522 ActivateTrigger(gTriggers
[b
], 0);
2526 gTriggers
[b
].Enabled
:= True;
2530 gTriggers
[b
].Enabled
:= False;
2531 gTriggers
[b
].TimeOut
:= 0;
2532 if gTriggers
[b
].AutoSpawn
then
2534 gTriggers
[b
].AutoSpawn
:= False;
2535 gTriggers
[b
].SpawnCooldown
:= 0;
2540 gTriggers
[b
].Enabled
:= not gTriggers
[b
].Enabled
;
2541 if not gTriggers
[b
].Enabled
then
2543 gTriggers
[b
].TimeOut
:= 0;
2544 if gTriggers
[b
].AutoSpawn
then
2546 gTriggers
[b
].AutoSpawn
:= False;
2547 gTriggers
[b
].SpawnCooldown
:= 0;
2554 SetLength(Affected
, 0);
2557 // Óìåíüøàåì âðåìÿ äî âîçìîæíîñòè ïîâòîðíîé àêòèâàöèè:
2560 TimeOut
:= TimeOut
- 1;
2561 Continue
; // ×òîáû íå ïîòåðÿòü 1 åäèíèöó çàäåðæêè
2564 // Íèæå èäóò òèïû àêòèâàöèè, åñëè òðèããåð îòêëþ÷¸í - èä¸ì äàëüøå
2569 if ByteBool(ActivateType
and ACTIVATE_PLAYERCOLLIDE
) and
2571 if gPlayers
<> nil then
2572 for b
:= 0 to High(gPlayers
) do
2573 if gPlayers
[b
] <> nil then
2575 // Æèâ, åñòü íóæíûå êëþ÷è è îí ðÿäîì:
2576 if alive
and ((gTriggers
[a
].Keys
and GetKeys
) = gTriggers
[a
].Keys
) and
2577 Collide(X
, Y
, Width
, Height
) then
2579 gTriggers
[a
].ActivateUID
:= UID
;
2581 if (gTriggers
[a
].TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) and
2583 { Don't activate sound/music again if player is here }
2585 ActivateTrigger(gTriggers
[a
], ACTIVATE_PLAYERCOLLIDE
);
2588 { TODO 5 : àêòèâàöèÿ ìîíñòðàìè òðèããåðîâ ñ êëþ÷àìè }
2590 if ByteBool(ActivateType
and ACTIVATE_MONSTERCOLLIDE
) and
2591 ByteBool(ActivateType
and ACTIVATE_NOMONSTER
) and
2592 (TimeOut
= 0) and (Keys
= 0) then
2594 // Åñëè "Ìîíñòð áëèçêî" è "Ìîíñòðîâ íåò",
2595 // çàïóñêàåì òðèããåð íà ñòàðòå êàðòû è ñíèìàåì îáà ôëàãà
2596 ActivateType
:= ActivateType
and not (ACTIVATE_MONSTERCOLLIDE
or ACTIVATE_NOMONSTER
);
2597 gTriggers
[a
].ActivateUID
:= 0;
2598 ActivateTrigger(gTriggers
[a
], 0);
2602 if ByteBool(ActivateType
and ACTIVATE_MONSTERCOLLIDE
) and
2603 (TimeOut
= 0) and (Keys
= 0) then // Åñëè íå íóæíû êëþ÷è
2605 //g_Mons_ForEach(monsNear);
2608 g_Mons_ForEachAt(gTriggers
[a
].X
, gTriggers
[a
].Y
, gTriggers
[a
].Width
, gTriggers
[a
].Height
, monsNear
);
2609 for mon
in tgMonsList
do
2611 gTriggers
[a
].ActivateUID
:= mon
.UID
;
2612 ActivateTrigger(gTriggers
[a
], ACTIVATE_MONSTERCOLLIDE
);
2614 tgMonsList
.reset(); // just in case
2618 if ByteBool(ActivateType
and ACTIVATE_NOMONSTER
) and
2619 (TimeOut
= 0) and (Keys
= 0) then
2620 if not g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then
2622 gTriggers
[a
].ActivateUID
:= 0;
2623 ActivateTrigger(gTriggers
[a
], ACTIVATE_NOMONSTER
);
2627 PlayerCollide
:= g_CollidePlayer(X
, Y
, Width
, Height
);
2631 procedure g_Triggers_Press(ID
: DWORD
; ActivateType
: Byte; ActivateUID
: Word = 0);
2633 if (ID
>= Length(gTriggers
)) then exit
;
2634 gTriggers
[ID
].ActivateUID
:= ActivateUID
;
2635 ActivateTrigger(gTriggers
[ID
], ActivateType
);
2638 function g_Triggers_PressR(X
, Y
: Integer; Width
, Height
: Word; UID
: Word;
2639 ActivateType
: Byte; IgnoreList
: DWArray
= nil): DWArray
;
2647 if gTriggers
= nil then Exit
;
2649 case g_GetUIDType(UID
) of
2653 p
:= g_Player_Get(UID
);
2662 for a
:= 0 to High(gTriggers
) do
2663 if (gTriggers
[a
].TriggerType
<> TRIGGER_NONE
) and
2664 (gTriggers
[a
].TimeOut
= 0) and
2665 (not InDWArray(a
, IgnoreList
)) and
2666 ((gTriggers
[a
].Keys
and k
) = gTriggers
[a
].Keys
) and
2667 ByteBool(gTriggers
[a
].ActivateType
and ActivateType
) then
2668 if g_Collide(X
, Y
, Width
, Height
,
2669 gTriggers
[a
].X
, gTriggers
[a
].Y
,
2670 gTriggers
[a
].Width
, gTriggers
[a
].Height
) then
2672 gTriggers
[a
].ActivateUID
:= UID
;
2673 if ActivateTrigger(gTriggers
[a
], ActivateType
) then
2675 SetLength(Result
, Length(Result
)+1);
2676 Result
[High(Result
)] := a
;
2681 procedure g_Triggers_PressL(X1
, Y1
, X2
, Y2
: Integer; UID
: DWORD
; ActivateType
: Byte);
2687 if gTriggers
= nil then Exit
;
2689 case g_GetUIDType(UID
) of
2693 p
:= g_Player_Get(UID
);
2702 for a
:= 0 to High(gTriggers
) do
2703 if (gTriggers
[a
].TriggerType
<> TRIGGER_NONE
) and
2704 (gTriggers
[a
].TimeOut
= 0) and
2705 ((gTriggers
[a
].Keys
and k
) = gTriggers
[a
].Keys
) and
2706 ByteBool(gTriggers
[a
].ActivateType
and ActivateType
) then
2707 if g_CollideLine(x1
, y1
, x2
, y2
, gTriggers
[a
].X
, gTriggers
[a
].Y
,
2708 gTriggers
[a
].Width
, gTriggers
[a
].Height
) then
2710 gTriggers
[a
].ActivateUID
:= UID
;
2711 ActivateTrigger(gTriggers
[a
], ActivateType
);
2715 procedure g_Triggers_PressC(CX
, CY
: Integer; Radius
: Word; UID
: Word; ActivateType
: Byte; IgnoreTrigger
: Integer = -1);
2722 if gTriggers
= nil then
2725 case g_GetUIDType(UID
) of
2729 p
:= g_Player_Get(UID
);
2738 rsq
:= Radius
* Radius
;
2740 for a
:= 0 to High(gTriggers
) do
2741 if (gTriggers
[a
].ID
<> DWORD(IgnoreTrigger
)) and
2742 (gTriggers
[a
].TriggerType
<> TRIGGER_NONE
) and
2743 (gTriggers
[a
].TimeOut
= 0) and
2744 ((gTriggers
[a
].Keys
and k
) = gTriggers
[a
].Keys
) and
2745 ByteBool(gTriggers
[a
].ActivateType
and ActivateType
) then
2746 with gTriggers
[a
] do
2747 if g_Collide(CX
-Radius
, CY
-Radius
, 2*Radius
, 2*Radius
,
2748 X
, Y
, Width
, Height
) then
2749 if ((Sqr(CX
-X
)+Sqr(CY
-Y
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê âåðõíåìó ëåâîìó óãëó
2750 ((Sqr(CX
-X
-Width
)+Sqr(CY
-Y
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê âåðõíåìó ïðàâîìó óãëó
2751 ((Sqr(CX
-X
-Width
)+Sqr(CY
-Y
-Height
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê íèæíåìó ïðàâîìó óãëó
2752 ((Sqr(CX
-X
)+Sqr(CY
-Y
-Height
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê íèæíåìó ëåâîìó óãëó
2753 ( (CX
> (X
-Radius
)) and (CX
< (X
+Width
+Radius
)) and
2754 (CY
> Y
) and (CY
< (Y
+Height
)) ) or // Öåíòð êðóãà íåäàëåêî îò âåðòèêàëüíûõ ãðàíèö ïðÿìîóãîëüíèêà
2755 ( (CY
> (Y
-Radius
)) and (CY
< (Y
+Height
+Radius
)) and
2756 (CX
> X
) and (CX
< (X
+Width
)) ) then // Öåíòð êðóãà íåäàëåêî îò ãîðèçîíòàëüíûõ ãðàíèö ïðÿìîóãîëüíèêà
2759 ActivateTrigger(gTriggers
[a
], ActivateType
);
2763 procedure g_Triggers_OpenAll();
2768 if gTriggers
= nil then Exit
;
2771 for a
:= 0 to High(gTriggers
) do
2773 with gTriggers
[a
] do
2775 if (TriggerType
= TRIGGER_OPENDOOR
) or
2776 (TriggerType
= TRIGGER_DOOR5
) or
2777 (TriggerType
= TRIGGER_DOOR
) then
2779 tr_OpenDoor(trigPanelGUID
, True, tgcD2d
);
2780 if TriggerType
= TRIGGER_DOOR5
then DoorTime
:= 180;
2786 if b
then g_Sound_PlayEx('SOUND_GAME_DOOROPEN');
2789 procedure g_Triggers_DecreaseSpawner(ID
: DWORD
);
2791 if (gTriggers
<> nil) then
2792 if gTriggers
[ID
].SpawnedCount
> 0 then
2793 Dec(gTriggers
[ID
].SpawnedCount
);
2797 procedure g_Triggers_Free ();
2801 for a
:= 0 to High(gTriggers
) do
2803 if (gTriggers
[a
].TriggerType
= TRIGGER_SOUND
) then
2805 if g_Sound_Exists(gTriggers
[a
].tgcSoundName
) then
2807 g_Sound_Delete(gTriggers
[a
].tgcSoundName
);
2809 gTriggers
[a
].Sound
.Free();
2811 if (gTriggers
[a
].Activators
<> nil) then
2813 SetLength(gTriggers
[a
].Activators
, 0);
2815 gTriggers
[a
].trigDataRec
.Free();
2820 SetLength(gMonstersSpawned
, 0);
2824 procedure g_Triggers_SaveState(var Mem
: TBinMemoryWriter
);
2826 count
, actCount
, i
, j
: Integer;
2831 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðèããåðîâ
2832 count
:= Length(gTriggers
);
2833 Mem
:= TBinMemoryWriter
.Create((count
+1)*200);
2835 // Êîëè÷åñòâî òðèããåðîâ
2836 Mem
.WriteInt(count
);
2837 if (count
= 0) then exit
;
2839 for i
:= 0 to High(gTriggers
) do
2841 // Ñèãíàòóðà òðèããåðà
2842 dw
:= TRIGGER_SIGNATURE
; // 'TRGX'
2845 Mem
.WriteByte(gTriggers
[i
].TriggerType
);
2846 if (gTriggers
[i
].TriggerType
= TRIGGER_NONE
) then continue
; // empty one
2847 // Ñïåöèàëüíûå äàííûå òðèããåðà: ïîòîì èç êàðòû îïÿòü âûòàùèì; ñîõðàíèì òîëüêî èíäåêñ
2848 Mem
.WriteInt(gTriggers
[i
].mapIndex
);
2849 // Êîîðäèíàòû ëåâîãî âåðõíåãî óãëà
2850 Mem
.WriteInt(gTriggers
[i
].X
);
2851 Mem
.WriteInt(gTriggers
[i
].Y
);
2853 Mem
.WriteWord(gTriggers
[i
].Width
);
2854 Mem
.WriteWord(gTriggers
[i
].Height
);
2855 // Âêëþ÷åí ëè òðèããåð
2856 Mem
.WriteBoolean(gTriggers
[i
].Enabled
);
2857 // Òèï àêòèâàöèè òðèããåðà
2858 Mem
.WriteByte(gTriggers
[i
].ActivateType
);
2859 // Êëþ÷è, íåîáõîäèìûå äëÿ àêòèâàöèè
2860 Mem
.WriteByte(gTriggers
[i
].Keys
);
2861 // ID ïàíåëè, òåêñòóðà êîòîðîé èçìåíèòñÿ
2862 Mem
.WriteInt(gTriggers
[i
].TexturePanelGUID
);
2864 Mem
.WriteWord(gTriggers
[i
].TexturePanelType
);
2865 // Âíóòðåííèé íîìåð äðóãîé ïàíåëè (ïî ñ÷àñòëèâîé ñëó÷àéíîñòè îí áóäåò ñîâïàäàòü ñ òåì, ÷òî ñîçäàíî ïðè çàãðóçêå êàðòû)
2866 Mem
.WriteInt(gTriggers
[i
].trigPanelGUID
);
2867 // Âðåìÿ äî âîçìîæíîñòè àêòèâàöèè
2868 Mem
.WriteWord(gTriggers
[i
].TimeOut
);
2869 // UID òîãî, êòî àêòèâèðîâàë ýòîò òðèããåð
2870 Mem
.WriteWord(gTriggers
[i
].ActivateUID
);
2871 // Ñïèñîê UID-îâ îáúåêòîâ, êîòîðûå íàõîäèëèñü ïîä âîçäåéñòâèåì
2872 actCount
:= Length(gTriggers
[i
].Activators
);
2873 Mem
.WriteInt(actCount
);
2874 for j
:= 0 to actCount
-1 do
2877 Mem
.WriteWord(gTriggers
[i
].Activators
[j
].UID
);
2879 Mem
.WriteWord(gTriggers
[i
].Activators
[j
].TimeOut
);
2881 // Ñòîèò ëè èãðîê â îáëàñòè òðèããåðà
2882 Mem
.WriteBoolean(gTriggers
[i
].PlayerCollide
);
2883 // Âðåìÿ äî çàêðûòèÿ äâåðè
2884 Mem
.WriteInt(gTriggers
[i
].DoorTime
);
2885 // Çàäåðæêà àêòèâàöèè
2886 Mem
.WriteInt(gTriggers
[i
].PressTime
);
2888 Mem
.WriteInt(gTriggers
[i
].PressCount
);
2890 Mem
.WriteBoolean(gTriggers
[i
].AutoSpawn
);
2891 // Çàäåðæêà ñïàâíåðà
2892 Mem
.WriteInt(gTriggers
[i
].SpawnCooldown
);
2893 // Ñ÷åò÷èê ñîçäàíèÿ îáúåêòîâ
2894 Mem
.WriteInt(gTriggers
[i
].SpawnedCount
);
2895 // Ñêîëüêî ðàç ïðîèãðàí çâóê
2896 Mem
.WriteInt(gTriggers
[i
].SoundPlayCount
);
2897 // Ïðîèãðûâàåòñÿ ëè çâóê?
2898 if (gTriggers
[i
].Sound
<> nil) then b
:= gTriggers
[i
].Sound
.IsPlaying() else b
:= false;
2899 Mem
.WriteBoolean(b
);
2902 // Ïîçèöèÿ ïðîèãðûâàíèÿ çâóêà
2903 dw
:= gTriggers
[i
].Sound
.GetPosition();
2906 sg
:= gTriggers
[i
].Sound
.GetVolume();
2907 sg
:= sg
/ (gSoundLevel
/255.0);
2908 Mem
.WriteSingle(sg
);
2909 // Ñòåðåî ñìåùåíèå çâóêà
2910 sg
:= gTriggers
[i
].Sound
.GetPan();
2911 Mem
.WriteSingle(sg
);
2917 procedure g_Triggers_LoadState (var Mem
: TBinMemoryReader
);
2919 count
, actCount
, i
, j
, a
: Integer;
2926 if (Mem
= nil) then exit
;
2930 // Êîëè÷åñòâî òðèããåðîâ
2932 if (count
= 0) then exit
;
2934 for a
:= 0 to count
-1 do
2936 // Ñèãíàòóðà òðèããåðà
2937 Mem
.ReadDWORD(dw
); // 'TRGX'
2938 if (dw
<> TRIGGER_SIGNATURE
) then raise EBinSizeError
.Create('g_Triggers_LoadState: Wrong Trigger Signature');
2940 Mem
.ReadByte(Trig
.TriggerType
);
2941 // Ñïåöèàëüíûå äàííûå òðèããåðà: èíäåêñ â gCurrentMap.field['triggers']
2942 if (Trig
.TriggerType
= TRIGGER_NONE
) then continue
; // empty one
2943 Mem
.ReadInt(mapIndex
);
2944 i
:= g_Triggers_CreateWithMapIndex(Trig
, a
, mapIndex
);
2946 if (gTriggers[i].trigData <> nil) then
2948 tw := TStrTextWriter.Create();
2950 gTriggers[i].trigData.writeTo(tw);
2951 e_LogWritefln('=== trigger #%s loaded ==='#10'%s'#10'---', [mapIndex, tw.str]);
2957 // Êîîðäèíàòû ëåâîãî âåðõíåãî óãëà:
2958 Mem
.ReadInt(gTriggers
[i
].X
);
2959 Mem
.ReadInt(gTriggers
[i
].Y
);
2961 Mem
.ReadWord(gTriggers
[i
].Width
);
2962 Mem
.ReadWord(gTriggers
[i
].Height
);
2963 // Âêëþ÷åí ëè òðèããåð:
2964 Mem
.ReadBoolean(gTriggers
[i
].Enabled
);
2965 // Òèï àêòèâàöèè òðèããåðà:
2966 Mem
.ReadByte(gTriggers
[i
].ActivateType
);
2967 // Êëþ÷è, íåîáõîäèìûå äëÿ àêòèâàöèè:
2968 Mem
.ReadByte(gTriggers
[i
].Keys
);
2969 // ID ïàíåëè, òåêñòóðà êîòîðîé èçìåíèòñÿ:
2970 Mem
.ReadInt(gTriggers
[i
].TexturePanelGUID
);
2972 Mem
.ReadWord(gTriggers
[i
].TexturePanelType
);
2973 // Âíóòðåííèé íîìåð äðóãîé ïàíåëè (ïî ñ÷àñòëèâîé ñëó÷àéíîñòè îí áóäåò ñîâïàäàòü ñ òåì, ÷òî ñîçäàíî ïðè çàãðóçêå êàðòû)
2974 Mem
.ReadInt(gTriggers
[i
].trigPanelGUID
);
2975 // Âðåìÿ äî âîçìîæíîñòè àêòèâàöèè:
2976 Mem
.ReadWord(gTriggers
[i
].TimeOut
);
2977 // UID òîãî, êòî àêòèâèðîâàë ýòîò òðèããåð:
2978 Mem
.ReadWord(gTriggers
[i
].ActivateUID
);
2979 // Ñïèñîê UID-îâ îáúåêòîâ, êîòîðûå íàõîäèëèñü ïîä âîçäåéñòâèåì:
2980 Mem
.ReadInt(actCount
);
2981 if actCount
> 0 then
2983 SetLength(gTriggers
[i
].Activators
, actCount
);
2984 for j
:= 0 to actCount
-1 do
2987 Mem
.ReadWord(gTriggers
[i
].Activators
[j
].UID
);
2989 Mem
.ReadWord(gTriggers
[i
].Activators
[j
].TimeOut
);
2992 // Ñòîèò ëè èãðîê â îáëàñòè òðèããåðà:
2993 Mem
.ReadBoolean(gTriggers
[i
].PlayerCollide
);
2994 // Âðåìÿ äî çàêðûòèÿ äâåðè:
2995 Mem
.ReadInt(gTriggers
[i
].DoorTime
);
2996 // Çàäåðæêà àêòèâàöèè:
2997 Mem
.ReadInt(gTriggers
[i
].PressTime
);
2999 Mem
.ReadInt(gTriggers
[i
].PressCount
);
3001 Mem
.ReadBoolean(gTriggers
[i
].AutoSpawn
);
3002 // Çàäåðæêà ñïàâíåðà:
3003 Mem
.ReadInt(gTriggers
[i
].SpawnCooldown
);
3004 // Ñ÷åò÷èê ñîçäàíèÿ îáúåêòîâ:
3005 Mem
.ReadInt(gTriggers
[i
].SpawnedCount
);
3006 // Ñêîëüêî ðàç ïðîèãðàí çâóê:
3007 Mem
.ReadInt(gTriggers
[i
].SoundPlayCount
);
3008 // Ïðîèãðûâàåòñÿ ëè çâóê?
3012 // Ïîçèöèÿ ïðîèãðûâàíèÿ çâóêà:
3015 Mem
.ReadSingle(vol
);
3016 // Ñòåðåî ñìåùåíèå çâóêà:
3017 Mem
.ReadSingle(pan
);
3018 // Çàïóñêàåì çâóê, åñëè åñòü:
3019 if gTriggers
[i
].Sound
<> nil then
3021 gTriggers
[i
].Sound
.PlayPanVolume(pan
, vol
);
3022 gTriggers
[i
].Sound
.Pause(True);
3023 gTriggers
[i
].Sound
.SetPosition(dw
);