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 trigDataRec
: TDynRecord
; // triggerdata; owned by trigger (cloned)
71 {$INCLUDE ../shared/mapdef_tgc_def.inc}
74 function trigCenter (): TDFPoint
; inline;
77 function g_Triggers_Create(Trigger
: TTrigger
; forceInternalIndex
: Integer=-1): DWORD
;
78 procedure g_Triggers_Update();
79 procedure g_Triggers_Press(ID
: DWORD
; ActivateType
: Byte; ActivateUID
: Word = 0);
80 function g_Triggers_PressR(X
, Y
: Integer; Width
, Height
: Word; UID
: Word;
81 ActivateType
: Byte; IgnoreList
: DWArray
= nil): DWArray
;
82 procedure g_Triggers_PressL(X1
, Y1
, X2
, Y2
: Integer; UID
: DWORD
; ActivateType
: Byte);
83 procedure g_Triggers_PressC(CX
, CY
: Integer; Radius
: Word; UID
: Word; ActivateType
: Byte; IgnoreTrigger
: Integer = -1);
84 procedure g_Triggers_OpenAll();
85 procedure g_Triggers_DecreaseSpawner(ID
: DWORD
);
86 procedure g_Triggers_Free();
87 procedure g_Triggers_SaveState(var Mem
: TBinMemoryWriter
);
88 procedure g_Triggers_LoadState(var Mem
: TBinMemoryReader
);
92 gTriggerClientID
: Integer = 0;
93 gTriggers
: array of TTrigger
;
94 gSecretsCount
: Integer = 0;
95 gMonstersSpawned
: array of LongInt = nil;
102 g_player
, g_map
, g_panel
, g_gfx
, g_game
, g_textures
,
103 g_console
, g_monsters
, g_items
, g_phys
, g_weapons
,
104 wadreader
, g_main
, SysUtils
, e_log
, g_language
,
105 g_options
, g_net
, g_netmsg
, utils
, xparser
;
108 TRIGGER_SIGNATURE
= $58475254; // 'TRGX'
111 {$INCLUDE ../shared/mapdef_tgc_impl.inc}
113 function TTrigger
.trigCenter (): TDFPoint
; inline;
115 result
:= TDFPoint
.Create(x
+width
div 2, y
+height
div 2);
119 function FindTrigger (): DWORD
;
123 for i
:= 0 to High(gTriggers
) do
125 if gTriggers
[i
].TriggerType
= TRIGGER_NONE
then begin result
:= i
; exit
; end;
128 if (gTriggers
= nil) then
130 SetLength(gTriggers
, 8);
135 result
:= Length(gTriggers
);
136 SetLength(gTriggers
, result
+8);
137 for i
:= result
to High(gTriggers
) do gTriggers
[i
].TriggerType
:= TRIGGER_NONE
;
142 function tr_CloseDoor (PanelGUID
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
149 pan
:= g_Map_PanelByGUID(PanelGUID
);
150 if (pan
= nil) or not pan
.isGWall
then exit
; //!FIXME!TRIGANY!
151 PanelID
:= pan
.arrIdx
;
155 with gWalls
[PanelID
] do
157 if g_CollidePlayer(X
, Y
, Width
, Height
) or g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then Exit
;
162 g_Sound_PlayExAt('SOUND_GAME_DOORCLOSE', X
, Y
);
163 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOORCLOSE');
165 g_Map_EnableWallGUID(PanelGUID
);
172 if (gDoorMap
= nil) then exit
;
175 for a
:= 0 to High(gDoorMap
) do
177 for b
:= 0 to High(gDoorMap
[a
]) do
179 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
185 if (c
<> -1) then break
;
187 if (c
= -1) then exit
;
189 for b
:= 0 to High(gDoorMap
[c
]) do
191 with gWalls
[gDoorMap
[c
, b
]] do
193 if g_CollidePlayer(X
, Y
, Width
, Height
) or g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then exit
;
199 for b
:= 0 to High(gDoorMap
[c
]) do
201 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
203 with gWalls
[PanelID
] do
205 g_Sound_PlayExAt('SOUND_GAME_DOORCLOSE', X
, Y
);
206 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOORCLOSE');
213 for b
:= 0 to High(gDoorMap
[c
]) do
215 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
217 g_Map_EnableWall_XXX(gDoorMap
[c
, b
]);
225 procedure tr_CloseTrap (PanelGUID
: Integer; NoSound
: Boolean; d2d
: Boolean);
228 wx
, wy
, wh
, ww
: Integer;
232 function monsDamage (mon
: TMonster
): Boolean;
234 result
:= false; // don't stop
235 if g_Obj_Collide(wx
, wy
, ww
, wh
, @mon
.Obj
) then mon
.Damage(TRAP_DAMAGE
, 0, 0, 0, HIT_TRAP
);
239 pan
:= g_Map_PanelByGUID(PanelGUID
);
243 e_LogWritefln('tr_CloseTrap: pguid=%s; NO PANEL!', [PanelGUID], MSG_WARNING);
247 e_LogWritefln('tr_CloseTrap: pguid=%s; isGWall=%s; arrIdx=%s', [PanelGUID, pan.isGWall, pan.arrIdx]);
250 if (pan
= nil) or not pan
.isGWall
then exit
; //!FIXME!TRIGANY!
251 PanelID
:= pan
.arrIdx
;
255 with gWalls
[PanelID
] do
257 if (not NoSound
) and (not Enabled
) then
259 g_Sound_PlayExAt('SOUND_GAME_SWITCH1', X
, Y
);
260 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_SWITCH1');
264 wx
:= gWalls
[PanelID
].X
;
265 wy
:= gWalls
[PanelID
].Y
;
266 ww
:= gWalls
[PanelID
].Width
;
267 wh
:= gWalls
[PanelID
].Height
;
269 with gWalls
[PanelID
] do
271 if gPlayers
<> nil then
273 for a
:= 0 to High(gPlayers
) do
275 if (gPlayers
[a
] <> nil) and gPlayers
[a
].alive
and gPlayers
[a
].Collide(X
, Y
, Width
, Height
) then
277 gPlayers
[a
].Damage(TRAP_DAMAGE
, 0, 0, 0, HIT_TRAP
);
282 //g_Mons_ForEach(monsDamage);
283 g_Mons_ForEachAliveAt(wx
, wy
, ww
, wh
, monsDamage
);
285 if not Enabled
then g_Map_EnableWallGUID(PanelGUID
);
290 if (gDoorMap
= nil) then exit
;
293 for a
:= 0 to High(gDoorMap
) do
295 for b
:= 0 to High(gDoorMap
[a
]) do
297 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
303 if (c
<> -1) then break
;
305 if (c
= -1) then exit
;
309 for b
:= 0 to High(gDoorMap
[c
]) do
311 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
313 with gWalls
[PanelID
] do
315 g_Sound_PlayExAt('SOUND_GAME_SWITCH1', X
, Y
);
316 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_SWITCH1');
323 for b
:= 0 to High(gDoorMap
[c
]) do
325 wx
:= gWalls
[gDoorMap
[c
, b
]].X
;
326 wy
:= gWalls
[gDoorMap
[c
, b
]].Y
;
327 ww
:= gWalls
[gDoorMap
[c
, b
]].Width
;
328 wh
:= gWalls
[gDoorMap
[c
, b
]].Height
;
330 with gWalls
[gDoorMap
[c
, b
]] do
332 if gPlayers
<> nil then
334 for a
:= 0 to High(gPlayers
) do
336 if (gPlayers
[a
] <> nil) and gPlayers
[a
].alive
and gPlayers
[a
].Collide(X
, Y
, Width
, Height
) then
338 gPlayers
[a
].Damage(TRAP_DAMAGE
, 0, 0, 0, HIT_TRAP
);
343 //g_Mons_ForEach(monsDamage);
344 g_Mons_ForEachAliveAt(wx
, wy
, ww
, wh
, monsDamage
);
346 if gMonsters <> nil then
347 for a := 0 to High(gMonsters) do
348 if (gMonsters[a] <> nil) and gMonsters[a].alive and
349 g_Obj_Collide(X, Y, Width, Height, @gMonsters[a].Obj) then
350 gMonsters[a].Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
353 if not Enabled
then g_Map_EnableWall_XXX(gDoorMap
[c
, b
]);
360 function tr_OpenDoor (PanelGUID
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
367 pan
:= g_Map_PanelByGUID(PanelGUID
);
368 if (pan
= nil) or not pan
.isGWall
then exit
; //!FIXME!TRIGANY!
369 PanelID
:= pan
.arrIdx
;
373 with gWalls
[PanelID
] do
379 g_Sound_PlayExAt('SOUND_GAME_DOOROPEN', X
, Y
);
380 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOOROPEN');
382 g_Map_DisableWallGUID(PanelGUID
);
389 if (gDoorMap
= nil) then exit
;
392 for a
:= 0 to High(gDoorMap
) do
394 for b
:= 0 to High(gDoorMap
[a
]) do
396 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
402 if (c
<> -1) then break
;
404 if (c
= -1) then exit
;
408 for b
:= 0 to High(gDoorMap
[c
]) do
410 if gWalls
[gDoorMap
[c
, b
]].Enabled
then
412 with gWalls
[PanelID
] do
414 g_Sound_PlayExAt('SOUND_GAME_DOOROPEN', X
, Y
);
415 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOOROPEN');
422 for b
:= 0 to High(gDoorMap
[c
]) do
424 if gWalls
[gDoorMap
[c
, b
]].Enabled
then
426 g_Map_DisableWall_XXX(gDoorMap
[c
, b
]);
434 function tr_SetLift (PanelGUID
: Integer; d
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
442 pan
:= g_Map_PanelByGUID(PanelGUID
);
443 if (pan
= nil) or not pan
.isGLift
then exit
; //!FIXME!TRIGANY!
444 PanelID
:= pan
.arrIdx
;
446 if (gLifts
[PanelID
].PanelType
= PANEL_LIFTUP
) or (gLifts
[PanelID
].PanelType
= PANEL_LIFTDOWN
) then
451 else t
:= IfThen(gLifts
[PanelID
].LiftType
= 1, 0, 1);
454 else if (gLifts
[PanelID
].PanelType
= PANEL_LIFTLEFT
) or (gLifts
[PanelID
].PanelType
= PANEL_LIFTRIGHT
) then
459 else t
:= IfThen(gLifts
[PanelID
].LiftType
= 2, 3, 2);
465 with gLifts
[PanelID
] do
467 if (LiftType
<> t
) then
469 g_Map_SetLiftGUID(PanelGUID
, t
); //???
470 //if not NoSound then g_Sound_PlayExAt('SOUND_GAME_SWITCH0', X, Y);
477 if (gLiftMap
= nil) then exit
;
480 for a
:= 0 to High(gLiftMap
) do
482 for b
:= 0 to High(gLiftMap
[a
]) do
484 if (gLiftMap
[a
, b
] = DWORD(PanelID
)) then
490 if (c
<> -1) then break
;
492 if (c
= -1) then exit
;
495 for b := 0 to High(gLiftMap[c]) do
496 if gLifts[gLiftMap[c, b]].LiftType <> t then
498 with gLifts[PanelID] do
499 g_Sound_PlayExAt('SOUND_GAME_SWITCH0', X, Y);
503 for b
:= 0 to High(gLiftMap
[c
]) do
505 with gLifts
[gLiftMap
[c
, b
]] do
507 if (LiftType
<> t
) then
509 g_Map_SetLift_XXX(gLiftMap
[c
, b
], t
);
518 function tr_SpawnShot (ShotType
: Integer; wx
, wy
, dx
, dy
: Integer; ShotSound
: Boolean; ShotTarget
: Word): Integer;
526 TextureID
:= DWORD(-1);
527 snd
:= 'SOUND_WEAPON_FIREROCKET';
533 g_Weapon_pistol(wx
, wy
, dx
, dy
, 0, True);
534 snd
:= 'SOUND_WEAPON_FIREPISTOL';
538 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_BULLET
);
539 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL1
);
545 g_Weapon_mgun(wx
, wy
, dx
, dy
, 0, True);
546 if gSoundEffectsDF
then snd
:= 'SOUND_WEAPON_FIRECGUN'
547 else snd
:= 'SOUND_WEAPON_FIREPISTOL';
551 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_BULLET
);
552 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL1
);
556 TRIGGER_SHOT_SHOTGUN
:
558 g_Weapon_Shotgun(wx
, wy
, dx
, dy
, 0, True);
559 snd
:= 'SOUND_WEAPON_FIRESHOTGUN';
563 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
564 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL2
);
570 g_Weapon_DShotgun(wx
, wy
, dx
, dy
, 0, True);
571 snd
:= 'SOUND_WEAPON_FIRESHOTGUN2';
575 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
576 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
577 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL3
);
583 g_Weapon_ball1(wx
, wy
, dx
, dy
, 0, -1, True);
584 snd
:= 'SOUND_WEAPON_FIREBALL';
589 g_Weapon_Plasma(wx
, wy
, dx
, dy
, 0, -1, True);
590 snd
:= 'SOUND_WEAPON_FIREPLASMA';
595 g_Weapon_aplasma(wx
, wy
, dx
, dy
, 0, -1, True);
596 snd
:= 'SOUND_WEAPON_FIREPLASMA';
601 g_Weapon_ball2(wx
, wy
, dx
, dy
, 0, -1, True);
602 snd
:= 'SOUND_WEAPON_FIREBALL';
607 g_Weapon_ball7(wx
, wy
, dx
, dy
, 0, -1, True);
608 snd
:= 'SOUND_WEAPON_FIREBALL';
613 g_Weapon_manfire(wx
, wy
, dx
, dy
, 0, -1, True);
614 snd
:= 'SOUND_WEAPON_FIREBALL';
619 g_Weapon_revf(wx
, wy
, dx
, dy
, 0, ShotTarget
, -1, True);
620 snd
:= 'SOUND_WEAPON_FIREREV';
625 g_Weapon_Rocket(wx
, wy
, dx
, dy
, 0, -1, True);
626 snd
:= 'SOUND_WEAPON_FIREROCKET';
631 g_Weapon_BFGShot(wx
, wy
, dx
, dy
, 0, -1, True);
632 snd
:= 'SOUND_WEAPON_FIREBFG';
637 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_ROCKET') then
639 Anim
:= TAnimation
.Create(TextureID
, False, 6);
640 Anim
.Blending
:= False;
641 g_GFX_OnceAnim(wx
-64, wy
-64, Anim
);
645 g_Weapon_Explode(wx
, wy
, 60, 0);
646 snd
:= 'SOUND_WEAPON_EXPLODEROCKET';
649 TRIGGER_SHOT_BFGEXPL
:
651 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_BFG') then
653 Anim
:= TAnimation
.Create(TextureID
, False, 6);
654 Anim
.Blending
:= False;
655 g_GFX_OnceAnim(wx
-64, wy
-64, Anim
);
659 g_Weapon_BFG9000(wx
, wy
, 0);
660 snd
:= 'SOUND_WEAPON_EXPLODEBFG';
666 if g_Game_IsNet
and g_Game_IsServer
then
669 TRIGGER_SHOT_EXPL
: MH_SEND_Effect(wx
, wy
, Byte(ShotSound
), NET_GFX_EXPLODE
);
670 TRIGGER_SHOT_BFGEXPL
: MH_SEND_Effect(wx
, wy
, Byte(ShotSound
), NET_GFX_BFGEXPL
);
673 if Projectile
then MH_SEND_CreateShot(LastShotID
);
674 if ShotSound
then MH_SEND_Sound(wx
, wy
, snd
);
679 if ShotSound
then g_Sound_PlayExAt(snd
, wx
, wy
);
681 if Projectile
then Result
:= LastShotID
;
685 procedure MakeShot (var Trigger
: TTrigger
; wx
, wy
, dx
, dy
: Integer; TargetUID
: Word);
689 if (tgcAmmo
= 0) or ((tgcAmmo
> 0) and (ShotAmmoCount
> 0)) then
691 if (trigPanelGUID
<> -1) and (ShotPanelTime
= 0) then
693 g_Map_SwitchTextureGUID(ShotPanelType
, trigPanelGUID
);
694 ShotPanelTime
:= 4; // òèêîâ íà âñïûøêó âûñòðåëà
697 if (tgcSight
> 0) then ShotSightTimeout
:= 180; // ~= 5 ñåêóíä
699 if (ShotAmmoCount
> 0) then Dec(ShotAmmoCount
);
701 dx
+= Random(tgcAccuracy
)-Random(tgcAccuracy
);
702 dy
+= Random(tgcAccuracy
)-Random(tgcAccuracy
);
704 tr_SpawnShot(tgcShotType
, wx
, wy
, dx
, dy
, not tgcQuiet
, TargetUID
);
708 if (tgcReload
> 0) and (ShotReloadTime
= 0) then
710 ShotReloadTime
:= tgcReload
; // òèêîâ íà ïåðåçàðÿäêó ïóøêè
717 procedure tr_MakeEffect (X
, Y
, VX
, VY
: Integer; T
, ST
, CR
, CG
, CB
: Byte; Silent
, Send
: Boolean);
722 if T
= TRIGGER_EFFECT_PARTICLE
then
725 TRIGGER_EFFECT_SLIQUID
:
727 if (CR
= 255) and (CG
= 0) and (CB
= 0) then g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 1, 0, 0, 0)
728 else if (CR
= 0) and (CG
= 255) and (CB
= 0) then g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 2, 0, 0, 0)
729 else if (CR
= 0) and (CG
= 0) and (CB
= 255) then g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 3, 0, 0, 0)
730 else g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 0, 0, 0, 0);
732 TRIGGER_EFFECT_LLIQUID
: g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 4, CR
, CG
, CB
);
733 TRIGGER_EFFECT_DLIQUID
: g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 5, CR
, CG
, CB
);
734 TRIGGER_EFFECT_BLOOD
: g_GFX_Blood(X
, Y
, 1, VX
, VY
, 0, 0, CR
, CG
, CB
);
735 TRIGGER_EFFECT_SPARK
: g_GFX_Spark(X
, Y
, 1, GetAngle2(VX
, VY
), 0, 0);
736 TRIGGER_EFFECT_BUBBLE
: g_GFX_Bubbles(X
, Y
, 1, 0, 0);
740 if T
= TRIGGER_EFFECT_ANIMATION
then
743 EFFECT_TELEPORT
: begin
744 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
746 Anim
:= TAnimation
.Create(FramesID
, False, 3);
747 if not Silent
then g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
748 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
751 if Send
and g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(X
, Y
, Byte(not Silent
), NET_GFX_TELE
);
753 EFFECT_RESPAWN
: begin
754 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
756 Anim
:= TAnimation
.Create(FramesID
, False, 4);
757 if not Silent
then g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
758 g_GFX_OnceAnim(X
-16, Y
-16, Anim
);
761 if Send
and g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(X
-16, Y
-16, Byte(not Silent
), NET_GFX_RESPAWN
);
764 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
766 Anim
:= TAnimation
.Create(FramesID
, False, 4);
767 if not Silent
then g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
768 g_GFX_OnceAnim(X
-32, Y
-128, Anim
);
771 if Send
and g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(X
-32, Y
-128, Byte(not Silent
), NET_GFX_FIRE
);
778 function tr_Teleport (ActivateUID
: Integer; TX
, TY
: Integer; TDir
: Integer; Silent
: Boolean; D2D
: Boolean): Boolean;
784 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then Exit
;
785 case g_GetUIDType(ActivateUID
) of
788 p
:= g_Player_Get(ActivateUID
);
789 if p
= nil then Exit
;
792 if p
.TeleportTo(TX
-(p
.Obj
.Rect
.Width
div 2), TY
-p
.Obj
.Rect
.Height
, Silent
, TDir
) then result
:= true;
796 if p
.TeleportTo(TX
, TY
, Silent
, TDir
) then result
:= true;
801 m
:= g_Monsters_ByUID(ActivateUID
);
802 if m
= nil then Exit
;
805 if m
.TeleportTo(TX
-(m
.Obj
.Rect
.Width
div 2), TY
-m
.Obj
.Rect
.Height
, Silent
, TDir
) then result
:= true;
809 if m
.TeleportTo(TX
, TY
, Silent
, TDir
) then result
:= true;
816 function tr_Push (ActivateUID
: Integer; VX
, VY
: Integer; ResetVel
: Boolean): Boolean;
822 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then exit
;
823 case g_GetUIDType(ActivateUID
) of
826 p
:= g_Player_Get(ActivateUID
);
827 if p
= nil then Exit
;
842 m
:= g_Monsters_ByUID(ActivateUID
);
843 if m
= nil then Exit
;
859 function tr_Message (MKind
: Integer; MText
: string; MSendTo
: Integer; MTime
: Integer; ActivateUID
: Integer): Boolean;
866 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then Exit
;
867 msg
:= b_Text_Format(MText
);
869 TRIGGER_MESSAGE_DEST_ME
: // activator
871 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
873 if g_Game_IsWatchedPlayer(ActivateUID
) then
875 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
876 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
880 p
:= g_Player_Get(ActivateUID
);
881 if g_Game_IsNet
and (p
.FClientID
>= 0) then
883 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, p
.FClientID
)
884 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, p
.FClientID
);
890 TRIGGER_MESSAGE_DEST_MY_TEAM
: // activator's team
892 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
894 p
:= g_Player_Get(ActivateUID
);
895 if g_Game_IsWatchedTeam(p
.Team
) then
897 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
898 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
903 for i
:= Low(gPlayers
) to High(gPlayers
) do
905 if (gPlayers
[i
].Team
= p
.Team
) and (gPlayers
[i
].FClientID
>= 0) then
907 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
908 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
915 TRIGGER_MESSAGE_DEST_ENEMY_TEAM
: // activator's enemy team
917 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
919 p
:= g_Player_Get(ActivateUID
);
920 if g_Game_IsWatchedTeam(p
.Team
) then
922 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
923 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
928 for i
:= Low(gPlayers
) to High(gPlayers
) do
930 if (gPlayers
[i
].Team
<> p
.Team
) and (gPlayers
[i
].FClientID
>= 0) then
932 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
933 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
940 TRIGGER_MESSAGE_DEST_RED_TEAM
: // red team
942 if g_Game_IsWatchedTeam(TEAM_RED
) then
944 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
945 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
950 for i
:= Low(gPlayers
) to High(gPlayers
) do
952 if (gPlayers
[i
].Team
= TEAM_RED
) and (gPlayers
[i
].FClientID
>= 0) then
954 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
955 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
961 TRIGGER_MESSAGE_DEST_BLUE_TEAM
: // blue team
963 if g_Game_IsWatchedTeam(TEAM_BLUE
) then
965 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
966 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
971 for i
:= Low(gPlayers
) to High(gPlayers
) do
973 if (gPlayers
[i
].Team
= TEAM_BLUE
) and (gPlayers
[i
].FClientID
>= 0) then
975 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
976 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
982 TRIGGER_MESSAGE_DEST_EVERYONE
: // everyone
984 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
985 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
989 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
)
990 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
);
997 function tr_ShotAimCheck (var Trigger
: TTrigger
; Obj
: PObj
): Boolean;
1002 if TriggerType
<> TRIGGER_SHOT
then Exit
;
1003 result
:= (tgcAim
and TRIGGER_SHOT_AIM_ALLMAP
> 0)
1004 or g_Obj_Collide(X
, Y
, Width
, Height
, Obj
);
1005 if result
and (tgcAim
and TRIGGER_SHOT_AIM_TRACE
> 0) then
1007 result
:= g_TraceVector(tgcTX
, tgcTY
,
1008 Obj
^.X
+ Obj
^.Rect
.X
+ (Obj
^.Rect
.Width
div 2),
1009 Obj
^.Y
+ Obj
^.Rect
.Y
+ (Obj
^.Rect
.Height
div 2));
1015 function ActivateTrigger (var Trigger
: TTrigger
; actType
: Byte): Boolean;
1021 idx
, k
, wx
, wy
, xd
, yd
: Integer;
1032 function monsShotTarget (mon
: TMonster
): Boolean;
1034 result
:= false; // don't stop
1035 if mon
.alive
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
1037 xd
:= mon
.GameX
+ mon
.Obj
.Rect
.Width
div 2;
1038 yd
:= mon
.GameY
+ mon
.Obj
.Rect
.Height
div 2;
1039 TargetUID
:= mon
.UID
;
1040 result
:= true; // stop
1044 function monsShotTargetMonPlr (mon
: TMonster
): Boolean;
1046 result
:= false; // don't stop
1047 if mon
.alive
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
1049 xd
:= mon
.GameX
+ mon
.Obj
.Rect
.Width
div 2;
1050 yd
:= mon
.GameY
+ mon
.Obj
.Rect
.Height
div 2;
1051 TargetUID
:= mon
.UID
;
1052 result
:= true; // stop
1056 function monShotTargetPlrMon (mon
: TMonster
): Boolean;
1058 result
:= false; // don't stop
1059 if mon
.alive
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
1061 xd
:= mon
.GameX
+ mon
.Obj
.Rect
.Width
div 2;
1062 yd
:= mon
.GameY
+ mon
.Obj
.Rect
.Height
div 2;
1063 TargetUID
:= mon
.UID
;
1064 result
:= true; // stop
1070 if g_Game_IsClient
then exit
;
1072 if not Trigger
.Enabled
then exit
;
1073 if (Trigger
.TimeOut
<> 0) and (actType
<> ACTIVATE_CUSTOM
) then exit
;
1074 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then exit
;
1078 coolDown
:= (actType
<> 0);
1085 g_Sound_PlayEx('SOUND_GAME_SWITCH0');
1086 if g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_SWITCH0');
1087 gExitByTrigger
:= True;
1088 g_Game_ExitLevel(tgcMap
);
1097 Result
:= tr_Teleport(ActivateUID
,
1098 tgcTarget
.X
, tgcTarget
.Y
,
1099 tgcDirection
, tgcSilent
,
1106 Result
:= tr_OpenDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
1112 Result
:= tr_CloseDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
1116 TRIGGER_DOOR
, TRIGGER_DOOR5
:
1118 pan
:= g_Map_PanelByGUID(trigPanelGUID
);
1119 if (pan
<> nil) and pan
.isGWall
then
1121 if gWalls
[{trigPanelID}pan
.arrIdx
].Enabled
then
1123 result
:= tr_OpenDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
1124 if (TriggerType
= TRIGGER_DOOR5
) then DoorTime
:= 180;
1128 result
:= tr_CloseDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
1131 if result
then TimeOut
:= 18;
1135 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
:
1137 tr_CloseTrap(trigPanelGUID
, tgcSilent
, tgcD2d
);
1139 if TriggerType
= TRIGGER_TRAP
then
1153 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
:
1156 if PressTime
= -1 then PressTime
:= tgcWait
;
1157 if coolDown
then TimeOut
:= 18 else TimeOut
:= 0;
1162 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
1166 if gLMSRespawn
= LMS_RESPAWN_NONE
then
1168 g_Player_Get(ActivateUID
).GetSecret();
1169 Inc(gCoopSecretsFound
);
1170 if g_Game_IsNet
then MH_SEND_GameStats();
1176 Result
:= tr_SetLift(trigPanelGUID
, 0, tgcSilent
, tgcD2d
);
1179 if (not tgcSilent
) and Result
then begin
1180 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1182 Y
+ (Height
div 2));
1183 if g_Game_IsServer
and g_Game_IsNet
then
1184 MH_SEND_Sound(X
+ (Width
div 2),
1186 'SOUND_GAME_SWITCH0');
1192 Result
:= tr_SetLift(trigPanelGUID
, 1, tgcSilent
, tgcD2d
);
1195 if (not tgcSilent
) and Result
then begin
1196 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1198 Y
+ (Height
div 2));
1199 if g_Game_IsServer
and g_Game_IsNet
then
1200 MH_SEND_Sound(X
+ (Width
div 2),
1202 'SOUND_GAME_SWITCH0');
1208 Result
:= tr_SetLift(trigPanelGUID
, 3, tgcSilent
, tgcD2d
);
1214 if (not tgcSilent
) and Result
then begin
1215 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1217 Y
+ (Height
div 2));
1218 if g_Game_IsServer
and g_Game_IsNet
then
1219 MH_SEND_Sound(X
+ (Width
div 2),
1221 'SOUND_GAME_SWITCH0');
1228 if tgcActivateOnce
then
1231 TriggerType
:= TRIGGER_NONE
;
1239 animonce
:= tgcAnimateOnce
;
1245 if Sound
<> nil then
1247 if tgcSoundSwitch
and Sound
.IsPlaying() then
1248 begin // Íóæíî âûêëþ÷èòü, åñëè èãðàë
1250 SoundPlayCount
:= 0;
1253 else // (not Data.SoundSwitch) or (not Sound.IsPlaying())
1254 if (tgcPlayCount
> 0) or (not Sound
.IsPlaying()) then
1256 if tgcPlayCount
> 0 then
1257 SoundPlayCount
:= tgcPlayCount
1258 else // 0 - èãðàåì áåñêîíå÷íî
1259 SoundPlayCount
:= 1;
1262 if g_Game_IsNet
then MH_SEND_TriggerSound(Trigger
);
1266 TRIGGER_SPAWNMONSTER
:
1267 if (tgcSpawnMonsType
in [MONSTER_DEMON
..MONSTER_MAN
]) then
1270 if (tgcDelay
> 0) and (actType
<> ACTIVATE_CUSTOM
) then
1272 AutoSpawn
:= not AutoSpawn
;
1274 // Àâòîñïàâíåð ïåðåêëþ÷åí - ìåíÿåì òåêñòóðó
1278 if ((tgcDelay
= 0) and (actType
<> ACTIVATE_CUSTOM
))
1279 or ((tgcDelay
> 0) and (actType
= ACTIVATE_CUSTOM
)) then
1280 for k
:= 1 to tgcMonsCount
do
1282 if (actType
= ACTIVATE_CUSTOM
) and (tgcDelay
> 0) then
1283 SpawnCooldown
:= tgcDelay
;
1284 if (tgcMax
> 0) and (SpawnedCount
>= tgcMax
) then
1287 mon
:= g_Monsters_Create(tgcSpawnMonsType
,
1289 TDirection(tgcDirection
), True);
1294 if (tgcHealth
> 0) then
1295 mon
.SetHealth(tgcHealth
);
1296 // Óñòàíàâëèâàåì ïîâåäåíèå:
1297 mon
.MonsterBehaviour
:= tgcBehaviour
;
1298 mon
.FNoRespawn
:= True;
1299 if g_Game_IsNet
then
1300 MH_SEND_MonsterSpawn(mon
.UID
);
1301 // Èäåì èñêàòü öåëü, åñëè íàäî:
1305 if tgcSpawnMonsType
<> MONSTER_BARREL
then Inc(gTotalMonsters
);
1307 if g_Game_IsNet
then
1309 SetLength(gMonstersSpawned
, Length(gMonstersSpawned
)+1);
1310 gMonstersSpawned
[High(gMonstersSpawned
)] := mon
.UID
;
1315 mon
.SpawnTrigger
:= ID
;
1320 EFFECT_TELEPORT
: begin
1321 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
1323 Anim
:= TAnimation
.Create(FramesID
, False, 3);
1324 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', tgcTX
, tgcTY
);
1325 g_GFX_OnceAnim(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1326 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-32, Anim
);
1329 if g_Game_IsServer
and g_Game_IsNet
then
1330 MH_SEND_Effect(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1331 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-32, 1,
1334 EFFECT_RESPAWN
: begin
1335 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
1337 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1338 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', tgcTX
, tgcTY
);
1339 g_GFX_OnceAnim(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-16,
1340 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-16, Anim
);
1343 if g_Game_IsServer
and g_Game_IsNet
then
1344 MH_SEND_Effect(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-16,
1345 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-16, 1,
1349 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
1351 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1352 g_Sound_PlayExAt('SOUND_FIRE', tgcTX
, tgcTY
);
1353 g_GFX_OnceAnim(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1354 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+mon
.Obj
.Rect
.Height
-128, Anim
);
1357 if g_Game_IsServer
and g_Game_IsNet
then
1358 MH_SEND_Effect(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1359 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+mon
.Obj
.Rect
.Height
-128, 1,
1364 if g_Game_IsNet
then
1366 MH_SEND_GameStats();
1367 MH_SEND_CoopStats();
1374 // Åñëè àêòèâèðîâàí àâòîñïàâíåðîì, íå ìåíÿåì òåêñòóðó
1375 if actType
= ACTIVATE_CUSTOM
then
1380 if (tgcSpawnItemType
in [ITEM_MEDKIT_SMALL
..ITEM_MAX
]) then
1383 if (tgcDelay
> 0) and (actType
<> ACTIVATE_CUSTOM
) then
1385 AutoSpawn
:= not AutoSpawn
;
1387 // Àâòîñïàâíåð ïåðåêëþ÷åí - ìåíÿåì òåêñòóðó
1391 if ((tgcDelay
= 0) and (actType
<> ACTIVATE_CUSTOM
))
1392 or ((tgcDelay
> 0) and (actType
= ACTIVATE_CUSTOM
)) then
1393 if (not tgcDmonly
) or
1394 (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
1395 for k
:= 1 to tgcItemCount
do
1397 if (actType
= ACTIVATE_CUSTOM
) and (tgcDelay
> 0) then
1398 SpawnCooldown
:= tgcDelay
;
1399 if (tgcMax
> 0) and (SpawnedCount
>= tgcMax
) then
1402 iid
:= g_Items_Create(tgcTX
, tgcTY
,
1403 tgcSpawnItemType
, tgcGravity
, False, True);
1409 it
:= g_Items_ByIdx(iid
);
1410 it
.SpawnTrigger
:= ID
;
1415 EFFECT_TELEPORT
: begin
1416 it
:= g_Items_ByIdx(iid
);
1417 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
1419 Anim
:= TAnimation
.Create(FramesID
, False, 3);
1420 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', tgcTX
, tgcTY
);
1421 g_GFX_OnceAnim(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1422 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-32, Anim
);
1425 if g_Game_IsServer
and g_Game_IsNet
then
1426 MH_SEND_Effect(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1427 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-32, 1,
1430 EFFECT_RESPAWN
: begin
1431 it
:= g_Items_ByIdx(iid
);
1432 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
1434 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1435 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', tgcTX
, tgcTY
);
1436 g_GFX_OnceAnim(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-16,
1437 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-16, Anim
);
1440 if g_Game_IsServer
and g_Game_IsNet
then
1441 MH_SEND_Effect(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-16,
1442 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-16, 1,
1446 it
:= g_Items_ByIdx(iid
);
1447 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
1449 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1450 g_Sound_PlayExAt('SOUND_FIRE', tgcTX
, tgcTY
);
1451 g_GFX_OnceAnim(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1452 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+it
.Obj
.Rect
.Height
-128, Anim
);
1455 if g_Game_IsServer
and g_Game_IsNet
then
1456 MH_SEND_Effect(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1457 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+it
.Obj
.Rect
.Height
-128, 1,
1462 if g_Game_IsNet
then
1463 MH_SEND_ItemSpawn(True, iid
);
1470 // Åñëè àêòèâèðîâàí àâòîñïàâíåðîì, íå ìåíÿåì òåêñòóðó
1471 if actType
= ACTIVATE_CUSTOM
then
1477 // Ìåíÿåì ìóçûêó, åñëè åñòü íà ÷òî:
1478 if (Trigger
.tgcMusicName
<> '') then
1480 gMusic
.SetByName(Trigger
.tgcMusicName
);
1481 gMusic
.SpecPause
:= True;
1485 case Trigger
.tgcMusicAction
of
1486 TRIGGER_MUSIC_ACTION_STOP
: // Âûêëþ÷èòü
1487 gMusic
.SpecPause
:= True; // Ïàóçà
1488 TRIGGER_MUSIC_ACTION_PLAY
: // Âêëþ÷èòü
1489 if gMusic
.SpecPause
then // Áûëà íà ïàóçå => èãðàòü
1490 gMusic
.SpecPause
:= False
1491 else // Èãðàëà => ñíà÷àëà
1492 gMusic
.SetPosition(0);
1500 if g_Game_IsNet
then MH_SEND_TriggerMusic
;
1505 pAngle
:= -DegToRad(tgcAngle
);
1506 Result
:= tr_Push(ActivateUID
,
1507 Floor(Cos(pAngle
)*tgcForce
),
1508 Floor(Sin(pAngle
)*tgcForce
),
1516 // Ïðèáàâèòü èëè îòíÿòü î÷êî
1517 if (tgcScoreAction
in [TRIGGER_SCORE_ACTION_ADD
, TRIGGER_SCORE_ACTION_SUB
]) and (tgcScoreCount
> 0) then
1519 // Ñâîåé èëè ÷óæîé êîìàíäå
1520 if (tgcScoreTeam
in [TRIGGER_SCORE_TEAM_MINE_RED
, TRIGGER_SCORE_TEAM_MINE_BLUE
]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
1522 p
:= g_Player_Get(ActivateUID
);
1523 if ((tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_RED
))
1524 or ((tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_BLUE
)) then
1526 Inc(gTeamStat
[TEAM_RED
].Goals
, tgcScoreCount
); // Red Scores
1530 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1532 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_OWN
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1533 if g_Game_IsServer
and g_Game_IsNet
then
1534 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '+r');
1537 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_ENEMY
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1538 if g_Game_IsServer
and g_Game_IsNet
then
1539 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '+re');
1545 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1546 if g_Game_IsServer
and g_Game_IsNet
then
1547 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_RED
);
1550 if ((tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_RED
))
1551 or ((tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_BLUE
)) then
1553 Dec(gTeamStat
[TEAM_RED
].Goals
, tgcScoreCount
); // Red Fouls
1557 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1559 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_OWN
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1560 if g_Game_IsServer
and g_Game_IsNet
then
1561 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '-r');
1564 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_ENEMY
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1565 if g_Game_IsServer
and g_Game_IsNet
then
1566 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '-re');
1572 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1573 if g_Game_IsServer
and g_Game_IsNet
then
1574 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_RED
);
1577 if ((tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_BLUE
))
1578 or ((tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_RED
)) then
1580 Inc(gTeamStat
[TEAM_BLUE
].Goals
, tgcScoreCount
); // Blue Scores
1584 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1586 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_OWN
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1587 if g_Game_IsServer
and g_Game_IsNet
then
1588 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '+b');
1591 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_ENEMY
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1592 if g_Game_IsServer
and g_Game_IsNet
then
1593 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '+be');
1599 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1600 if g_Game_IsServer
and g_Game_IsNet
then
1601 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_BLUE
);
1604 if ((tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_BLUE
))
1605 or ((tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_RED
)) then
1607 Dec(gTeamStat
[TEAM_BLUE
].Goals
, tgcScoreCount
); // Blue Fouls
1611 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1613 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_OWN
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1614 if g_Game_IsServer
and g_Game_IsNet
then
1615 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '-b');
1618 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_ENEMY
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1619 if g_Game_IsServer
and g_Game_IsNet
then
1620 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '-be');
1626 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1627 if g_Game_IsServer
and g_Game_IsNet
then
1628 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_BLUE
);
1631 Result
:= (p
.Team
= TEAM_RED
) or (p
.Team
= TEAM_BLUE
);
1633 // Êàêîé-òî êîíêðåòíîé êîìàíäå
1634 if tgcScoreTeam
in [TRIGGER_SCORE_TEAM_FORCE_RED
, TRIGGER_SCORE_TEAM_FORCE_BLUE
] then
1636 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_RED
) then
1638 Inc(gTeamStat
[TEAM_RED
].Goals
, tgcScoreCount
); // Red Scores
1642 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_TEAM
], [_lc
[I_PLAYER_SCORE_RED
], tgcScoreCount
]), True);
1643 if g_Game_IsServer
and g_Game_IsNet
then
1644 MH_SEND_GameEvent(NET_EV_SCORE
, tgcScoreCount
shl 16, '+tr');
1649 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1650 if g_Game_IsServer
and g_Game_IsNet
then
1651 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_RED
);
1654 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_RED
) then
1656 Dec(gTeamStat
[TEAM_RED
].Goals
, tgcScoreCount
); // Red Fouls
1660 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_TEAM
], [_lc
[I_PLAYER_SCORE_RED
], tgcScoreCount
]), True);
1661 if g_Game_IsServer
and g_Game_IsNet
then
1662 MH_SEND_GameEvent(NET_EV_SCORE
, tgcScoreCount
shl 16, '-tr');
1667 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1668 if g_Game_IsServer
and g_Game_IsNet
then
1669 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_RED
);
1672 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_BLUE
) then
1674 Inc(gTeamStat
[TEAM_BLUE
].Goals
, tgcScoreCount
); // Blue Scores
1678 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_TEAM
], [_lc
[I_PLAYER_SCORE_BLUE
], tgcScoreCount
]), True);
1679 if g_Game_IsServer
and g_Game_IsNet
then
1680 MH_SEND_GameEvent(NET_EV_SCORE
, tgcScoreCount
shl 16, '+tb');
1685 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1686 if g_Game_IsServer
and g_Game_IsNet
then
1687 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_BLUE
);
1690 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_BLUE
) then
1692 Dec(gTeamStat
[TEAM_BLUE
].Goals
, tgcScoreCount
); // Blue Fouls
1696 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_TEAM
], [_lc
[I_PLAYER_SCORE_BLUE
], tgcScoreCount
]), True);
1697 if g_Game_IsServer
and g_Game_IsNet
then
1698 MH_SEND_GameEvent(NET_EV_SCORE
, tgcScoreCount
shl 16, '-tb');
1703 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1704 if g_Game_IsServer
and g_Game_IsNet
then
1705 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_BLUE
);
1712 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_WIN
) and (gGameSettings
.GoalLimit
> 0) then
1714 // Ñâîåé èëè ÷óæîé êîìàíäû
1715 if (tgcScoreTeam
in [TRIGGER_SCORE_TEAM_MINE_RED
, TRIGGER_SCORE_TEAM_MINE_BLUE
]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
1717 p
:= g_Player_Get(ActivateUID
);
1718 if ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_RED
)) // Red Wins
1719 or ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_BLUE
)) then
1721 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1723 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1727 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1729 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1730 if g_Game_IsServer
and g_Game_IsNet
then
1731 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wr');
1734 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1735 if g_Game_IsServer
and g_Game_IsNet
then
1736 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wre');
1743 if ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_BLUE
)) // Blue Wins
1744 or ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_RED
)) then
1746 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1748 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1752 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1754 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1755 if g_Game_IsServer
and g_Game_IsNet
then
1756 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wb');
1759 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1760 if g_Game_IsServer
and g_Game_IsNet
then
1761 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wbe');
1769 // Êàêîé-òî êîíêðåòíîé êîìàíäû
1770 if tgcScoreTeam
in [TRIGGER_SCORE_TEAM_FORCE_RED
, TRIGGER_SCORE_TEAM_FORCE_BLUE
] then
1772 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_RED
) then // Red Wins
1774 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1776 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1780 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_BLUE
) then // Blue Wins
1782 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1784 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1791 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_LOOSE
) and (gGameSettings
.GoalLimit
> 0) then
1793 // Ñâîåé èëè ÷óæîé êîìàíäû
1794 if (tgcScoreTeam
in [TRIGGER_SCORE_TEAM_MINE_RED
, TRIGGER_SCORE_TEAM_MINE_BLUE
]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
1796 p
:= g_Player_Get(ActivateUID
);
1797 if ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_BLUE
)) // Red Wins
1798 or ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_RED
)) then
1799 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1801 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1804 if tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
then
1806 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1807 if g_Game_IsServer
and g_Game_IsNet
then
1808 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wre');
1811 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1812 if g_Game_IsServer
and g_Game_IsNet
then
1813 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wr');
1818 if ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_RED
)) // Blue Wins
1819 or ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_BLUE
)) then
1820 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1822 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1825 if tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
then
1827 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1828 if g_Game_IsServer
and g_Game_IsNet
then
1829 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wbe');
1832 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1833 if g_Game_IsServer
and g_Game_IsNet
then
1834 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wb');
1840 // Êàêîé-òî êîíêðåòíîé êîìàíäû
1841 if tgcScoreTeam
in [TRIGGER_SCORE_TEAM_FORCE_BLUE
, TRIGGER_SCORE_TEAM_FORCE_RED
] then
1843 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_BLUE
) then // Red Wins
1845 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1847 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1851 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_RED
) then // Blue Wins
1853 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1855 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1861 if Result
then begin
1866 if g_Game_IsServer
and g_Game_IsNet
then
1873 Result
:= tr_Message(tgcKind
, tgcText
,
1874 tgcMsgDest
, tgcMsgTime
,
1879 TRIGGER_DAMAGE
, TRIGGER_HEALTH
:
1882 UIDType
:= g_GetUIDType(ActivateUID
);
1883 if (UIDType
= UID_PLAYER
) or (UIDType
= UID_MONSTER
) then
1889 // Âñïîìèíàåì, àêòèâèðîâàë ëè îí ìåíÿ ðàíüøå
1890 for idx
:= 0 to High(Activators
) do
1891 if Activators
[idx
].UID
= ActivateUID
then
1897 begin // Âèäèì åãî âïåðâûå
1899 SetLength(Activators
, Length(Activators
) + 1);
1900 k
:= High(Activators
);
1901 Activators
[k
].UID
:= ActivateUID
;
1903 begin // Óæå âèäåëè åãî
1904 // Åñëè èíòåðâàë îòêëþ÷¸í, íî îí âñ¸ åù¸ â çîíå ïîðàæåíèÿ, äà¸ì åìó âðåìÿ
1905 if (tgcInterval
= 0) and (Activators
[k
].TimeOut
> 0) then
1906 Activators
[k
].TimeOut
:= 65535;
1907 // Òàéìàóò ïðîø¸ë - ðàáîòàåì
1908 Result
:= Activators
[k
].TimeOut
= 0;
1917 p
:= g_Player_Get(ActivateUID
);
1921 // Íàíîñèì óðîí èãðîêó
1922 if (TriggerType
= TRIGGER_DAMAGE
) and (tgcAmount
> 0) then
1923 p
.Damage(tgcAmount
, 0, 0, 0, HIT_SOME
);
1926 if (TriggerType
= TRIGGER_HEALTH
) and (tgcAmount
> 0) then
1927 if p
.Heal(tgcAmount
, not tgcHealMax
) and (not tgcSilent
) then
1929 g_Sound_PlayExAt('SOUND_ITEM_GETITEM', p
.Obj
.X
, p
.Obj
.Y
);
1930 if g_Game_IsServer
and g_Game_IsNet
then
1931 MH_SEND_Sound(p
.Obj
.X
, p
.Obj
.Y
, 'SOUND_ITEM_GETITEM');
1937 m
:= g_Monsters_ByUID(ActivateUID
);
1941 // Íàíîñèì óðîí ìîíñòðó
1942 if (TriggerType
= TRIGGER_DAMAGE
) and (tgcAmount
> 0) then
1943 m
.Damage(tgcAmount
, 0, 0, 0, HIT_SOME
);
1946 if (TriggerType
= TRIGGER_HEALTH
) and (tgcAmount
> 0) then
1947 if m
.Heal(tgcAmount
) and (not tgcSilent
) then
1949 g_Sound_PlayExAt('SOUND_ITEM_GETITEM', m
.Obj
.X
, m
.Obj
.Y
);
1950 if g_Game_IsServer
and g_Game_IsNet
then
1951 MH_SEND_Sound(m
.Obj
.X
, m
.Obj
.Y
, 'SOUND_ITEM_GETITEM');
1955 // Íàçíà÷àåì âðåìÿ ñëåäóþùåãî âîçäåéñòâèÿ
1959 Activators
[k
].TimeOut
:= idx
1961 Activators
[k
].TimeOut
:= 65535;
1969 if ShotSightTime
> 0 then
1972 // put this at the beginning so it doesn't trigger itself
1973 TimeOut
:= tgcWait
+ 1;
1977 pAngle
:= -DegToRad(tgcAngle
);
1978 xd
:= wx
+ Round(Cos(pAngle
) * 32.0);
1979 yd
:= wy
+ Round(Sin(pAngle
) * 32.0);
1982 case tgcShotTarget
of
1983 TRIGGER_SHOT_TARGET_MON
: // monsters
1984 //TODO: accelerate this!
1985 g_Mons_ForEachAlive(monsShotTarget
);
1987 TRIGGER_SHOT_TARGET_PLR
: // players
1988 if gPlayers
<> nil then
1989 for idx
:= Low(gPlayers
) to High(gPlayers
) do
1990 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
1991 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
1993 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
1994 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
1995 TargetUID
:= gPlayers
[idx
].UID
;
1999 TRIGGER_SHOT_TARGET_RED
: // red team
2000 if gPlayers
<> nil then
2001 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2002 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2003 (gPlayers
[idx
].Team
= TEAM_RED
) and
2004 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2006 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2007 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2008 TargetUID
:= gPlayers
[idx
].UID
;
2012 TRIGGER_SHOT_TARGET_BLUE
: // blue team
2013 if gPlayers
<> nil then
2014 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2015 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2016 (gPlayers
[idx
].Team
= TEAM_BLUE
) and
2017 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2019 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2020 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2021 TargetUID
:= gPlayers
[idx
].UID
;
2025 TRIGGER_SHOT_TARGET_MONPLR
: // monsters then players
2027 //TODO: accelerate this!
2028 g_Mons_ForEachAlive(monsShotTargetMonPlr
);
2030 if (TargetUID
= 0) and (gPlayers
<> nil) then
2031 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2032 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2033 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2035 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2036 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2037 TargetUID
:= gPlayers
[idx
].UID
;
2042 TRIGGER_SHOT_TARGET_PLRMON
: // players then monsters
2044 if gPlayers
<> nil then
2045 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2046 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2047 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2049 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2050 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2051 TargetUID
:= gPlayers
[idx
].UID
;
2054 if TargetUID
= 0 then
2056 //TODO: accelerate this!
2057 g_Mons_ForEachAlive(monShotTargetPlrMon
);
2062 if (tgcShotTarget
<> TRIGGER_SHOT_TARGET_NONE
) or
2063 (tgcShotType
<> TRIGGER_SHOT_REV
) then
2064 TargetUID
:= ActivateUID
;
2068 if (tgcShotTarget
= TRIGGER_SHOT_TARGET_NONE
) or (TargetUID
> 0) or
2069 ((tgcShotTarget
> TRIGGER_SHOT_TARGET_NONE
) and (TargetUID
= 0)) then
2072 if (tgcSight
= 0) or
2073 (tgcShotTarget
= TRIGGER_SHOT_TARGET_NONE
) or
2074 (TargetUID
= ShotSightTarget
) then
2075 MakeShot(Trigger
, wx
, wy
, xd
, yd
, TargetUID
)
2078 ShotSightTime
:= tgcSight
;
2079 ShotSightTargetN
:= TargetUID
;
2080 if tgcShotType
= TRIGGER_SHOT_BFG
then
2082 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', wx
, wy
);
2083 if g_Game_IsNet
and g_Game_IsServer
then
2084 MH_SEND_Sound(wx
, wy
, 'SOUND_WEAPON_STARTFIREBFG');
2097 TRIGGER_EFFECT_POS_CENTER
:
2099 wx
:= X
+ Width
div 2;
2100 wy
:= Y
+ Height
div 2;
2102 TRIGGER_EFFECT_POS_AREA
:
2104 wx
:= X
+ Random(Width
);
2105 wy
:= Y
+ Random(Height
);
2108 wx
:= X
+ Width
div 2;
2109 wy
:= Y
+ Height
div 2;
2114 if tgcSpreadL
> 0 then xd
-= Random(tgcSpreadL
+1);
2115 if tgcSpreadR
> 0 then xd
+= Random(tgcSpreadR
+1);
2116 if tgcSpreadU
> 0 then yd
-= Random(tgcSpreadU
+1);
2117 if tgcSpreadD
> 0 then yd
+= Random(tgcSpreadD
+1);
2118 tr_MakeEffect(wx
, wy
, xd
, yd
,
2119 tgcFXType
, tgcFXSubType
,
2120 tgcFXRed
, tgcFXGreen
, tgcFXBlue
, True, False);
2128 if Result
{and (Trigger.TexturePanel <> -1)} then
2130 g_Map_SwitchTextureGUID(Trigger
.TexturePanelType
, Trigger
.TexturePanelGUID
, IfThen(animonce
, 2, 1));
2135 function g_Triggers_CreateWithMapIndex (Trigger
: TTrigger
; arridx
, mapidx
: Integer): DWORD
;
2137 triggers
: TDynField
;
2139 triggers
:= gCurrentMap
['trigger'];
2140 if (triggers
= nil) then raise Exception
.Create('LOAD: map has no triggers');
2141 if (mapidx
< 0) or (mapidx
>= triggers
.count
) then raise Exception
.Create('LOAD: invalid map trigger index');
2142 Trigger
.trigDataRec
:= triggers
.itemAt
[mapidx
];
2143 if (Trigger
.trigDataRec
= nil) then raise Exception
.Create('LOAD: internal error in trigger loader');
2144 Trigger
.mapId
:= Trigger
.trigDataRec
.id
;
2145 Trigger
.mapIndex
:= mapidx
;
2146 if (Trigger
.trigDataRec
.trigRec
<> nil) then
2148 Trigger
.trigDataRec
:= Trigger
.trigDataRec
.trigRec
.clone(nil);
2152 Trigger
.trigDataRec
:= nil;
2154 result
:= g_Triggers_Create(Trigger
, arridx
);
2158 function g_Triggers_Create(Trigger
: TTrigger
; forceInternalIndex
: Integer=-1): DWORD
;
2161 fn
, mapw
: AnsiString;
2164 // Íå ñîçäàâàòü âûõîä, åñëè èãðà áåç âûõîäà
2165 if (Trigger
.TriggerType
= TRIGGER_EXIT
) and
2166 (not LongBool(gGameSettings
.Options
and GAME_OPTION_ALLOWEXIT
)) then
2167 Trigger
.TriggerType
:= TRIGGER_NONE
;
2169 // Åñëè ìîíñòðû çàïðåùåíû, îòìåíÿåì òðèããåð
2170 if (Trigger
.TriggerType
= TRIGGER_SPAWNMONSTER
) and
2171 (not LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
)) and
2172 (gGameSettings
.GameType
<> GT_SINGLE
) then
2173 Trigger
.TriggerType
:= TRIGGER_NONE
;
2175 // Ñ÷èòàåì êîëè÷åñòâî ñåêðåòîâ íà êàðòå
2176 if Trigger
.TriggerType
= TRIGGER_SECRET
then gSecretsCount
+= 1;
2178 if (forceInternalIndex
< 0) then
2180 find_id
:= FindTrigger();
2184 olen
:= Length(gTriggers
);
2185 if (forceInternalIndex
>= olen
) then
2187 SetLength(gTriggers
, forceInternalIndex
+1);
2188 for f
:= olen
to High(gTriggers
) do gTriggers
[f
].TriggerType
:= TRIGGER_NONE
;
2190 find_id
:= DWORD(forceInternalIndex
);
2192 gTriggers
[find_id
] := Trigger
;
2194 with gTriggers
[find_id
] do
2197 // if this type of trigger exists both on the client and on the server
2198 // use an uniform numeration
2199 if Trigger
.TriggerType
= TRIGGER_SOUND
then
2201 Inc(gTriggerClientID
);
2202 ClientID
:= gTriggerClientID
;
2210 PlayerCollide
:= False;
2214 SoundPlayCount
:= 0;
2221 // update cached trigger variables
2222 trigUpdateCacheData(gTriggers
[find_id
], gTriggers
[find_id
].trigDataRec
);
2224 // Çàãðóæàåì çâóê, åñëè ýòî òðèããåð "Çâóê"
2225 if (Trigger
.TriggerType
= TRIGGER_SOUND
) and (Trigger
.tgcSoundName
<> '') then
2227 // Åùå íåò òàêîãî çâóêà
2228 if not g_Sound_Exists(Trigger
.tgcSoundName
) then
2230 fn
:= g_ExtractWadName(Trigger
.tgcSoundName
);
2232 begin // Çâóê â ôàéëå ñ êàðòîé
2233 mapw
:= g_ExtractWadName(gMapInfo
.Map
);
2234 fn
:= mapw
+':'+g_ExtractFilePathName(Trigger
.tgcSoundName
);
2236 else // Çâóê â îòäåëüíîì ôàéëå
2238 fn
:= GameDir
+ '/wads/' + Trigger
.tgcSoundName
;
2241 if not g_Sound_CreateWADEx(Trigger
.tgcSoundName
, fn
) then
2243 g_FatalError(Format(_lc
[I_GAME_ERROR_TR_SOUND
], [fn
, Trigger
.tgcSoundName
]));
2247 // Ñîçäàåì îáúåêò çâóêà
2248 with gTriggers
[find_id
] do
2250 Sound
:= TPlayableSound
.Create();
2251 if not Sound
.SetByName(Trigger
.tgcSoundName
) then
2259 // Çàãðóæàåì ìóçûêó, åñëè ýòî òðèããåð "Ìóçûêà"
2260 if (Trigger
.TriggerType
= TRIGGER_MUSIC
) and (Trigger
.tgcMusicName
<> '') then
2262 // Åùå íåò òàêîé ìóçûêè
2263 if not g_Sound_Exists(Trigger
.tgcMusicName
) then
2265 fn
:= g_ExtractWadName(Trigger
.tgcMusicName
);
2268 begin // Ìóçûêà â ôàéëå ñ êàðòîé
2269 mapw
:= g_ExtractWadName(gMapInfo
.Map
);
2270 fn
:= mapw
+':'+g_ExtractFilePathName(Trigger
.tgcMusicName
);
2272 else // Ìóçûêà â ôàéëå ñ êàðòîé
2274 fn
:= GameDir
+'/wads/'+Trigger
.tgcMusicName
;
2277 if not g_Sound_CreateWADEx(Trigger
.tgcMusicName
, fn
, True) then
2279 g_FatalError(Format(_lc
[I_GAME_ERROR_TR_SOUND
], [fn
, Trigger
.tgcMusicName
]));
2284 // Çàãðóæàåì äàííûå òðèããåðà "Òóðåëü"
2285 if Trigger
.TriggerType
= TRIGGER_SHOT
then
2287 with gTriggers
[find_id
] do
2291 ShotSightTimeout
:= 0;
2292 ShotSightTarget
:= 0;
2293 ShotSightTargetN
:= 0;
2294 ShotAmmoCount
:= Trigger
.tgcAmmo
;
2295 ShotReloadTime
:= 0;
2303 // sorry; grid doesn't support recursive queries, so we have to do this
2305 TSimpleMonsterList
= specialize TSimpleList
<TMonster
>;
2308 tgMonsList
: TSimpleMonsterList
= nil;
2310 procedure g_Triggers_Update();
2313 Affected
: array of Integer;
2315 function monsNear (mon
: TMonster
): Boolean;
2317 result
:= false; // don't stop
2319 gTriggers[a].ActivateUID := mon.UID;
2320 ActivateTrigger(gTriggers[a], ACTIVATE_MONSTERCOLLIDE);
2322 tgMonsList
.append(mon
);
2329 if (tgMonsList
= nil) then tgMonsList
:= TSimpleMonsterList
.Create();
2331 if gTriggers
= nil then
2333 SetLength(Affected
, 0);
2335 for a
:= 0 to High(gTriggers
) do
2336 with gTriggers
[a
] do
2338 if TriggerType
<> TRIGGER_NONE
then
2340 // Óìåíüøàåì âðåìÿ äî çàêðûòèÿ äâåðè (îòêðûòèÿ ëîâóøêè)
2341 if DoorTime
> 0 then DoorTime
:= DoorTime
- 1;
2342 // Óìåíüøàåì âðåìÿ îæèäàíèÿ ïîñëå íàæàòèÿ
2343 if PressTime
> 0 then PressTime
:= PressTime
- 1;
2344 // Ïðîâåðÿåì èãðîêîâ è ìîíñòðîâ, êîòîðûõ ðàíåå çàïîìíèëè:
2345 if (TriggerType
= TRIGGER_DAMAGE
) or (TriggerType
= TRIGGER_HEALTH
) then
2347 for b
:= 0 to High(Activators
) do
2349 // Óìåíüøàåì âðåìÿ äî ïîâòîðíîãî âîçäåéñòâèÿ:
2350 if Activators
[b
].TimeOut
> 0 then
2352 Dec(Activators
[b
].TimeOut
);
2358 // Ñ÷èòàåì, ÷òî îáúåêò ïîêèíóë çîíó äåéñòâèÿ òðèããåðà
2359 if (tgcInterval
= 0) and (Activators
[b
].TimeOut
< 65530) then Activators
[b
].TimeOut
:= 0;
2363 // Îáðàáàòûâàåì ñïàâíåðû
2364 if Enabled
and AutoSpawn
then
2366 if SpawnCooldown
= 0 then
2368 // Åñëè ïðèøëî âðåìÿ, ñïàâíèì ìîíñòðà
2369 if (TriggerType
= TRIGGER_SPAWNMONSTER
) and (tgcDelay
> 0) then
2372 ActivateTrigger(gTriggers
[a
], ACTIVATE_CUSTOM
);
2374 // Åñëè ïðèøëî âðåìÿ, ñïàâíèì ïðåäìåò
2375 if (TriggerType
= TRIGGER_SPAWNITEM
) and (tgcDelay
> 0) then
2378 ActivateTrigger(gTriggers
[a
], ACTIVATE_CUSTOM
);
2383 // Óìåíüøàåì âðåìÿ îæèäàíèÿ
2388 // Îáðàáàòûâàåì ñîáûòèÿ òðèããåðà "Òóðåëü"
2389 if TriggerType
= TRIGGER_SHOT
then
2391 if ShotPanelTime
> 0 then
2394 if ShotPanelTime
= 0 then g_Map_SwitchTextureGUID(ShotPanelType
, trigPanelGUID
);
2396 if ShotSightTime
> 0 then
2399 if ShotSightTime
= 0 then ShotSightTarget
:= ShotSightTargetN
;
2401 if ShotSightTimeout
> 0 then
2403 Dec(ShotSightTimeout
);
2404 if ShotSightTimeout
= 0 then ShotSightTarget
:= 0;
2406 if ShotReloadTime
> 0 then
2408 Dec(ShotReloadTime
);
2409 if ShotReloadTime
= 0 then ShotAmmoCount
:= tgcAmmo
;
2413 // Òðèããåð "Çâóê" óæå îòûãðàë, åñëè íóæíî åùå - ïåðåçàïóñêàåì
2414 if Enabled
and (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) then
2416 if (SoundPlayCount
> 0) and (not Sound
.IsPlaying()) then
2418 if tgcPlayCount
> 0 then SoundPlayCount
-= 1; // Åñëè 0 - èãðàåì çâóê áåñêîíå÷íî
2421 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0);
2425 Sound
.PlayPanVolume((tgcPan
-127.0)/128.0, tgcVolume
/255.0);
2427 if Sound
.IsPlaying() and g_Game_IsNet
and g_Game_IsServer
then MH_SEND_TriggerSound(gTriggers
[a
]);
2431 // Òðèããåð "Ëîâóøêà" - ïîðà îòêðûâàòü
2432 if (TriggerType
= TRIGGER_TRAP
) and (DoorTime
= 0) and (g_Map_PanelByGUID(trigPanelGUID
) <> nil) then
2434 tr_OpenDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
2438 // Òðèããåð "Äâåðü 5 ñåê" - ïîðà çàêðûâàòü
2439 if (TriggerType
= TRIGGER_DOOR5
) and (DoorTime
= 0) and (g_Map_PanelByGUID(trigPanelGUID
) <> nil) then
2441 pan
:= g_Map_PanelByGUID(trigPanelGUID
);
2442 if (pan
<> nil) and pan
.isGWall
then
2445 if {gWalls[trigPanelID].Enabled} pan
.Enabled
then
2451 // Ïîêà îòêðûòà - çàêðûâàåì
2452 if tr_CloseDoor(trigPanelGUID
, tgcSilent
, tgcD2d
) then DoorTime
:= -1;
2457 // Òðèããåð - ðàñøèðèòåëü èëè ïåðåêëþ÷àòåëü, è ïðîøëà çàäåðæêà, è íàæàëè íóæíîå ÷èñëî ðàç:
2458 if (TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
]) and
2459 (PressTime
= 0) and (PressCount
>= tgcPressCount
) then
2461 // Ñáðàñûâàåì çàäåðæêó àêòèâàöèè:
2463 // Ñáðàñûâàåì ñ÷åò÷èê íàæàòèé:
2464 if tgcPressCount
> 0 then PressCount
-= tgcPressCount
else PressCount
:= 0;
2466 // Îïðåäåëÿåì èçìåíÿåìûå èì òðèããåðû:
2467 for b
:= 0 to High(gTriggers
) do
2469 if g_Collide(tgcTX
, tgcTY
, tgcTWidth
, tgcTHeight
, gTriggers
[b
].X
, gTriggers
[b
].Y
,
2470 gTriggers
[b
].Width
, gTriggers
[b
].Height
) and
2471 ((b
<> a
) or (tgcWait
> 0)) then
2472 begin // Can be self-activated, if there is Data.Wait
2473 if (not tgcExtRandom
) or gTriggers
[b
].Enabled
then
2475 SetLength(Affected
, Length(Affected
) + 1);
2476 Affected
[High(Affected
)] := b
;
2482 // if we have panelid, assume that it will switch the moving platform
2483 pan
:= g_Map_PanelByGUID(trigPanelGUID
);
2484 if (pan
<> nil) then
2487 TRIGGER_PRESS
: pan
.movingActive
:= true; // what to do here?
2488 TRIGGER_ON
: pan
.movingActive
:= true;
2489 TRIGGER_OFF
: pan
.movingActive
:= false;
2490 TRIGGER_ONOFF
: pan
.movingActive
:= not pan
.movingActive
;
2492 if not tgcSilent
and (Length(tgcSound
) > 0) then
2494 g_Sound_PlayExAt(tgcSound
, X
, Y
);
2495 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, tgcSound
);
2499 // Âûáèðàåì îäèí èç òðèããåðîâ äëÿ ðàñøèðèòåëÿ, åñëè âêëþ÷åí ðàíäîì:
2500 if (TriggerType
= TRIGGER_PRESS
) and tgcExtRandom
then
2502 if (Length(Affected
) > 0) then
2504 b
:= Affected
[Random(Length(Affected
))];
2505 gTriggers
[b
].ActivateUID
:= gTriggers
[a
].ActivateUID
;
2506 ActivateTrigger(gTriggers
[b
], 0);
2509 else //  ïðîòèâíîì ñëó÷àå ðàáîòàåì êàê îáû÷íî:
2511 for i
:= 0 to High(Affected
) do
2517 gTriggers
[b
].ActivateUID
:= gTriggers
[a
].ActivateUID
;
2518 ActivateTrigger(gTriggers
[b
], 0);
2522 gTriggers
[b
].Enabled
:= True;
2526 gTriggers
[b
].Enabled
:= False;
2527 gTriggers
[b
].TimeOut
:= 0;
2528 if gTriggers
[b
].AutoSpawn
then
2530 gTriggers
[b
].AutoSpawn
:= False;
2531 gTriggers
[b
].SpawnCooldown
:= 0;
2536 gTriggers
[b
].Enabled
:= not gTriggers
[b
].Enabled
;
2537 if not gTriggers
[b
].Enabled
then
2539 gTriggers
[b
].TimeOut
:= 0;
2540 if gTriggers
[b
].AutoSpawn
then
2542 gTriggers
[b
].AutoSpawn
:= False;
2543 gTriggers
[b
].SpawnCooldown
:= 0;
2550 SetLength(Affected
, 0);
2553 // Óìåíüøàåì âðåìÿ äî âîçìîæíîñòè ïîâòîðíîé àêòèâàöèè:
2556 TimeOut
:= TimeOut
- 1;
2557 Continue
; // ×òîáû íå ïîòåðÿòü 1 åäèíèöó çàäåðæêè
2560 // Íèæå èäóò òèïû àêòèâàöèè, åñëè òðèããåð îòêëþ÷¸í - èä¸ì äàëüøå
2565 if ByteBool(ActivateType
and ACTIVATE_PLAYERCOLLIDE
) and
2567 if gPlayers
<> nil then
2568 for b
:= 0 to High(gPlayers
) do
2569 if gPlayers
[b
] <> nil then
2571 // Æèâ, åñòü íóæíûå êëþ÷è è îí ðÿäîì:
2572 if alive
and ((gTriggers
[a
].Keys
and GetKeys
) = gTriggers
[a
].Keys
) and
2573 Collide(X
, Y
, Width
, Height
) then
2575 gTriggers
[a
].ActivateUID
:= UID
;
2577 if (gTriggers
[a
].TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) and
2579 { Don't activate sound/music again if player is here }
2581 ActivateTrigger(gTriggers
[a
], ACTIVATE_PLAYERCOLLIDE
);
2584 { TODO 5 : àêòèâàöèÿ ìîíñòðàìè òðèããåðîâ ñ êëþ÷àìè }
2586 if ByteBool(ActivateType
and ACTIVATE_MONSTERCOLLIDE
) and
2587 ByteBool(ActivateType
and ACTIVATE_NOMONSTER
) and
2588 (TimeOut
= 0) and (Keys
= 0) then
2590 // Åñëè "Ìîíñòð áëèçêî" è "Ìîíñòðîâ íåò",
2591 // çàïóñêàåì òðèããåð íà ñòàðòå êàðòû è ñíèìàåì îáà ôëàãà
2592 ActivateType
:= ActivateType
and not (ACTIVATE_MONSTERCOLLIDE
or ACTIVATE_NOMONSTER
);
2593 gTriggers
[a
].ActivateUID
:= 0;
2594 ActivateTrigger(gTriggers
[a
], 0);
2598 if ByteBool(ActivateType
and ACTIVATE_MONSTERCOLLIDE
) and
2599 (TimeOut
= 0) and (Keys
= 0) then // Åñëè íå íóæíû êëþ÷è
2601 //g_Mons_ForEach(monsNear);
2604 g_Mons_ForEachAt(gTriggers
[a
].X
, gTriggers
[a
].Y
, gTriggers
[a
].Width
, gTriggers
[a
].Height
, monsNear
);
2605 for mon
in tgMonsList
do
2607 gTriggers
[a
].ActivateUID
:= mon
.UID
;
2608 ActivateTrigger(gTriggers
[a
], ACTIVATE_MONSTERCOLLIDE
);
2610 tgMonsList
.reset(); // just in case
2614 if ByteBool(ActivateType
and ACTIVATE_NOMONSTER
) and
2615 (TimeOut
= 0) and (Keys
= 0) then
2616 if not g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then
2618 gTriggers
[a
].ActivateUID
:= 0;
2619 ActivateTrigger(gTriggers
[a
], ACTIVATE_NOMONSTER
);
2623 PlayerCollide
:= g_CollidePlayer(X
, Y
, Width
, Height
);
2627 procedure g_Triggers_Press(ID
: DWORD
; ActivateType
: Byte; ActivateUID
: Word = 0);
2629 if (ID
>= Length(gTriggers
)) then exit
;
2630 gTriggers
[ID
].ActivateUID
:= ActivateUID
;
2631 ActivateTrigger(gTriggers
[ID
], ActivateType
);
2634 function g_Triggers_PressR(X
, Y
: Integer; Width
, Height
: Word; UID
: Word;
2635 ActivateType
: Byte; IgnoreList
: DWArray
= nil): DWArray
;
2643 if gTriggers
= nil then Exit
;
2645 case g_GetUIDType(UID
) of
2649 p
:= g_Player_Get(UID
);
2658 for a
:= 0 to High(gTriggers
) do
2659 if (gTriggers
[a
].TriggerType
<> TRIGGER_NONE
) and
2660 (gTriggers
[a
].TimeOut
= 0) and
2661 (not InDWArray(a
, IgnoreList
)) and
2662 ((gTriggers
[a
].Keys
and k
) = gTriggers
[a
].Keys
) and
2663 ByteBool(gTriggers
[a
].ActivateType
and ActivateType
) then
2664 if g_Collide(X
, Y
, Width
, Height
,
2665 gTriggers
[a
].X
, gTriggers
[a
].Y
,
2666 gTriggers
[a
].Width
, gTriggers
[a
].Height
) then
2668 gTriggers
[a
].ActivateUID
:= UID
;
2669 if ActivateTrigger(gTriggers
[a
], ActivateType
) then
2671 SetLength(Result
, Length(Result
)+1);
2672 Result
[High(Result
)] := a
;
2677 procedure g_Triggers_PressL(X1
, Y1
, X2
, Y2
: Integer; UID
: DWORD
; ActivateType
: Byte);
2683 if gTriggers
= nil then Exit
;
2685 case g_GetUIDType(UID
) of
2689 p
:= g_Player_Get(UID
);
2698 for a
:= 0 to High(gTriggers
) do
2699 if (gTriggers
[a
].TriggerType
<> TRIGGER_NONE
) and
2700 (gTriggers
[a
].TimeOut
= 0) and
2701 ((gTriggers
[a
].Keys
and k
) = gTriggers
[a
].Keys
) and
2702 ByteBool(gTriggers
[a
].ActivateType
and ActivateType
) then
2703 if g_CollideLine(x1
, y1
, x2
, y2
, gTriggers
[a
].X
, gTriggers
[a
].Y
,
2704 gTriggers
[a
].Width
, gTriggers
[a
].Height
) then
2706 gTriggers
[a
].ActivateUID
:= UID
;
2707 ActivateTrigger(gTriggers
[a
], ActivateType
);
2711 procedure g_Triggers_PressC(CX
, CY
: Integer; Radius
: Word; UID
: Word; ActivateType
: Byte; IgnoreTrigger
: Integer = -1);
2718 if gTriggers
= nil then
2721 case g_GetUIDType(UID
) of
2725 p
:= g_Player_Get(UID
);
2734 rsq
:= Radius
* Radius
;
2736 for a
:= 0 to High(gTriggers
) do
2737 if (gTriggers
[a
].ID
<> DWORD(IgnoreTrigger
)) and
2738 (gTriggers
[a
].TriggerType
<> TRIGGER_NONE
) and
2739 (gTriggers
[a
].TimeOut
= 0) and
2740 ((gTriggers
[a
].Keys
and k
) = gTriggers
[a
].Keys
) and
2741 ByteBool(gTriggers
[a
].ActivateType
and ActivateType
) then
2742 with gTriggers
[a
] do
2743 if g_Collide(CX
-Radius
, CY
-Radius
, 2*Radius
, 2*Radius
,
2744 X
, Y
, Width
, Height
) then
2745 if ((Sqr(CX
-X
)+Sqr(CY
-Y
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê âåðõíåìó ëåâîìó óãëó
2746 ((Sqr(CX
-X
-Width
)+Sqr(CY
-Y
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê âåðõíåìó ïðàâîìó óãëó
2747 ((Sqr(CX
-X
-Width
)+Sqr(CY
-Y
-Height
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê íèæíåìó ïðàâîìó óãëó
2748 ((Sqr(CX
-X
)+Sqr(CY
-Y
-Height
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê íèæíåìó ëåâîìó óãëó
2749 ( (CX
> (X
-Radius
)) and (CX
< (X
+Width
+Radius
)) and
2750 (CY
> Y
) and (CY
< (Y
+Height
)) ) or // Öåíòð êðóãà íåäàëåêî îò âåðòèêàëüíûõ ãðàíèö ïðÿìîóãîëüíèêà
2751 ( (CY
> (Y
-Radius
)) and (CY
< (Y
+Height
+Radius
)) and
2752 (CX
> X
) and (CX
< (X
+Width
)) ) then // Öåíòð êðóãà íåäàëåêî îò ãîðèçîíòàëüíûõ ãðàíèö ïðÿìîóãîëüíèêà
2755 ActivateTrigger(gTriggers
[a
], ActivateType
);
2759 procedure g_Triggers_OpenAll();
2764 if gTriggers
= nil then Exit
;
2767 for a
:= 0 to High(gTriggers
) do
2769 with gTriggers
[a
] do
2771 if (TriggerType
= TRIGGER_OPENDOOR
) or
2772 (TriggerType
= TRIGGER_DOOR5
) or
2773 (TriggerType
= TRIGGER_DOOR
) then
2775 tr_OpenDoor(trigPanelGUID
, True, tgcD2d
);
2776 if TriggerType
= TRIGGER_DOOR5
then DoorTime
:= 180;
2782 if b
then g_Sound_PlayEx('SOUND_GAME_DOOROPEN');
2785 procedure g_Triggers_DecreaseSpawner(ID
: DWORD
);
2787 if (gTriggers
<> nil) then
2788 if gTriggers
[ID
].SpawnedCount
> 0 then
2789 Dec(gTriggers
[ID
].SpawnedCount
);
2793 procedure g_Triggers_Free ();
2797 for a
:= 0 to High(gTriggers
) do
2799 if (gTriggers
[a
].TriggerType
= TRIGGER_SOUND
) then
2801 if g_Sound_Exists(gTriggers
[a
].tgcSoundName
) then
2803 g_Sound_Delete(gTriggers
[a
].tgcSoundName
);
2805 gTriggers
[a
].Sound
.Free();
2807 if (gTriggers
[a
].Activators
<> nil) then
2809 SetLength(gTriggers
[a
].Activators
, 0);
2811 gTriggers
[a
].trigDataRec
.Free();
2816 SetLength(gMonstersSpawned
, 0);
2820 procedure g_Triggers_SaveState(var Mem
: TBinMemoryWriter
);
2822 count
, actCount
, i
, j
: Integer;
2827 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðèããåðîâ
2828 count
:= Length(gTriggers
);
2829 Mem
:= TBinMemoryWriter
.Create((count
+1)*200);
2831 // Êîëè÷åñòâî òðèããåðîâ
2832 Mem
.WriteInt(count
);
2833 if (count
= 0) then exit
;
2835 for i
:= 0 to High(gTriggers
) do
2837 // Ñèãíàòóðà òðèããåðà
2838 dw
:= TRIGGER_SIGNATURE
; // 'TRGX'
2841 Mem
.WriteByte(gTriggers
[i
].TriggerType
);
2842 if (gTriggers
[i
].TriggerType
= TRIGGER_NONE
) then continue
; // empty one
2843 // Ñïåöèàëüíûå äàííûå òðèããåðà: ïîòîì èç êàðòû îïÿòü âûòàùèì; ñîõðàíèì òîëüêî èíäåêñ
2844 Mem
.WriteInt(gTriggers
[i
].mapIndex
);
2845 // Êîîðäèíàòû ëåâîãî âåðõíåãî óãëà
2846 Mem
.WriteInt(gTriggers
[i
].X
);
2847 Mem
.WriteInt(gTriggers
[i
].Y
);
2849 Mem
.WriteWord(gTriggers
[i
].Width
);
2850 Mem
.WriteWord(gTriggers
[i
].Height
);
2851 // Âêëþ÷åí ëè òðèããåð
2852 Mem
.WriteBoolean(gTriggers
[i
].Enabled
);
2853 // Òèï àêòèâàöèè òðèããåðà
2854 Mem
.WriteByte(gTriggers
[i
].ActivateType
);
2855 // Êëþ÷è, íåîáõîäèìûå äëÿ àêòèâàöèè
2856 Mem
.WriteByte(gTriggers
[i
].Keys
);
2857 // ID ïàíåëè, òåêñòóðà êîòîðîé èçìåíèòñÿ
2858 Mem
.WriteInt(gTriggers
[i
].TexturePanelGUID
);
2860 Mem
.WriteWord(gTriggers
[i
].TexturePanelType
);
2861 // Âíóòðåííèé íîìåð äðóãîé ïàíåëè (ïî ñ÷àñòëèâîé ñëó÷àéíîñòè îí áóäåò ñîâïàäàòü ñ òåì, ÷òî ñîçäàíî ïðè çàãðóçêå êàðòû)
2862 Mem
.WriteInt(gTriggers
[i
].trigPanelGUID
);
2863 // Âðåìÿ äî âîçìîæíîñòè àêòèâàöèè
2864 Mem
.WriteWord(gTriggers
[i
].TimeOut
);
2865 // UID òîãî, êòî àêòèâèðîâàë ýòîò òðèããåð
2866 Mem
.WriteWord(gTriggers
[i
].ActivateUID
);
2867 // Ñïèñîê UID-îâ îáúåêòîâ, êîòîðûå íàõîäèëèñü ïîä âîçäåéñòâèåì
2868 actCount
:= Length(gTriggers
[i
].Activators
);
2869 Mem
.WriteInt(actCount
);
2870 for j
:= 0 to actCount
-1 do
2873 Mem
.WriteWord(gTriggers
[i
].Activators
[j
].UID
);
2875 Mem
.WriteWord(gTriggers
[i
].Activators
[j
].TimeOut
);
2877 // Ñòîèò ëè èãðîê â îáëàñòè òðèããåðà
2878 Mem
.WriteBoolean(gTriggers
[i
].PlayerCollide
);
2879 // Âðåìÿ äî çàêðûòèÿ äâåðè
2880 Mem
.WriteInt(gTriggers
[i
].DoorTime
);
2881 // Çàäåðæêà àêòèâàöèè
2882 Mem
.WriteInt(gTriggers
[i
].PressTime
);
2884 Mem
.WriteInt(gTriggers
[i
].PressCount
);
2886 Mem
.WriteBoolean(gTriggers
[i
].AutoSpawn
);
2887 // Çàäåðæêà ñïàâíåðà
2888 Mem
.WriteInt(gTriggers
[i
].SpawnCooldown
);
2889 // Ñ÷åò÷èê ñîçäàíèÿ îáúåêòîâ
2890 Mem
.WriteInt(gTriggers
[i
].SpawnedCount
);
2891 // Ñêîëüêî ðàç ïðîèãðàí çâóê
2892 Mem
.WriteInt(gTriggers
[i
].SoundPlayCount
);
2893 // Ïðîèãðûâàåòñÿ ëè çâóê?
2894 if (gTriggers
[i
].Sound
<> nil) then b
:= gTriggers
[i
].Sound
.IsPlaying() else b
:= false;
2895 Mem
.WriteBoolean(b
);
2898 // Ïîçèöèÿ ïðîèãðûâàíèÿ çâóêà
2899 dw
:= gTriggers
[i
].Sound
.GetPosition();
2902 sg
:= gTriggers
[i
].Sound
.GetVolume();
2903 sg
:= sg
/ (gSoundLevel
/255.0);
2904 Mem
.WriteSingle(sg
);
2905 // Ñòåðåî ñìåùåíèå çâóêà
2906 sg
:= gTriggers
[i
].Sound
.GetPan();
2907 Mem
.WriteSingle(sg
);
2913 procedure g_Triggers_LoadState (var Mem
: TBinMemoryReader
);
2915 count
, actCount
, i
, j
, a
: Integer;
2922 if (Mem
= nil) then exit
;
2926 // Êîëè÷åñòâî òðèããåðîâ
2928 if (count
= 0) then exit
;
2930 for a
:= 0 to count
-1 do
2932 // Ñèãíàòóðà òðèããåðà
2933 Mem
.ReadDWORD(dw
); // 'TRGX'
2934 if (dw
<> TRIGGER_SIGNATURE
) then raise EBinSizeError
.Create('g_Triggers_LoadState: Wrong Trigger Signature');
2936 Mem
.ReadByte(Trig
.TriggerType
);
2937 // Ñïåöèàëüíûå äàííûå òðèããåðà: èíäåêñ â gCurrentMap.field['triggers']
2938 if (Trig
.TriggerType
= TRIGGER_NONE
) then continue
; // empty one
2939 Mem
.ReadInt(mapIndex
);
2940 i
:= g_Triggers_CreateWithMapIndex(Trig
, a
, mapIndex
);
2942 if (gTriggers[i].trigData <> nil) then
2944 tw := TStrTextWriter.Create();
2946 gTriggers[i].trigData.writeTo(tw);
2947 e_LogWritefln('=== trigger #%s loaded ==='#10'%s'#10'---', [mapIndex, tw.str]);
2953 // Êîîðäèíàòû ëåâîãî âåðõíåãî óãëà:
2954 Mem
.ReadInt(gTriggers
[i
].X
);
2955 Mem
.ReadInt(gTriggers
[i
].Y
);
2957 Mem
.ReadWord(gTriggers
[i
].Width
);
2958 Mem
.ReadWord(gTriggers
[i
].Height
);
2959 // Âêëþ÷åí ëè òðèããåð:
2960 Mem
.ReadBoolean(gTriggers
[i
].Enabled
);
2961 // Òèï àêòèâàöèè òðèããåðà:
2962 Mem
.ReadByte(gTriggers
[i
].ActivateType
);
2963 // Êëþ÷è, íåîáõîäèìûå äëÿ àêòèâàöèè:
2964 Mem
.ReadByte(gTriggers
[i
].Keys
);
2965 // ID ïàíåëè, òåêñòóðà êîòîðîé èçìåíèòñÿ:
2966 Mem
.ReadInt(gTriggers
[i
].TexturePanelGUID
);
2968 Mem
.ReadWord(gTriggers
[i
].TexturePanelType
);
2969 // Âíóòðåííèé íîìåð äðóãîé ïàíåëè (ïî ñ÷àñòëèâîé ñëó÷àéíîñòè îí áóäåò ñîâïàäàòü ñ òåì, ÷òî ñîçäàíî ïðè çàãðóçêå êàðòû)
2970 Mem
.ReadInt(gTriggers
[i
].trigPanelGUID
);
2971 // Âðåìÿ äî âîçìîæíîñòè àêòèâàöèè:
2972 Mem
.ReadWord(gTriggers
[i
].TimeOut
);
2973 // UID òîãî, êòî àêòèâèðîâàë ýòîò òðèããåð:
2974 Mem
.ReadWord(gTriggers
[i
].ActivateUID
);
2975 // Ñïèñîê UID-îâ îáúåêòîâ, êîòîðûå íàõîäèëèñü ïîä âîçäåéñòâèåì:
2976 Mem
.ReadInt(actCount
);
2977 if actCount
> 0 then
2979 SetLength(gTriggers
[i
].Activators
, actCount
);
2980 for j
:= 0 to actCount
-1 do
2983 Mem
.ReadWord(gTriggers
[i
].Activators
[j
].UID
);
2985 Mem
.ReadWord(gTriggers
[i
].Activators
[j
].TimeOut
);
2988 // Ñòîèò ëè èãðîê â îáëàñòè òðèããåðà:
2989 Mem
.ReadBoolean(gTriggers
[i
].PlayerCollide
);
2990 // Âðåìÿ äî çàêðûòèÿ äâåðè:
2991 Mem
.ReadInt(gTriggers
[i
].DoorTime
);
2992 // Çàäåðæêà àêòèâàöèè:
2993 Mem
.ReadInt(gTriggers
[i
].PressTime
);
2995 Mem
.ReadInt(gTriggers
[i
].PressCount
);
2997 Mem
.ReadBoolean(gTriggers
[i
].AutoSpawn
);
2998 // Çàäåðæêà ñïàâíåðà:
2999 Mem
.ReadInt(gTriggers
[i
].SpawnCooldown
);
3000 // Ñ÷åò÷èê ñîçäàíèÿ îáúåêòîâ:
3001 Mem
.ReadInt(gTriggers
[i
].SpawnedCount
);
3002 // Ñêîëüêî ðàç ïðîèãðàí çâóê:
3003 Mem
.ReadInt(gTriggers
[i
].SoundPlayCount
);
3004 // Ïðîèãðûâàåòñÿ ëè çâóê?
3008 // Ïîçèöèÿ ïðîèãðûâàíèÿ çâóêà:
3011 Mem
.ReadSingle(vol
);
3012 // Ñòåðåî ñìåùåíèå çâóêà:
3013 Mem
.ReadSingle(pan
);
3014 // Çàïóñêàåì çâóê, åñëè åñòü:
3015 if gTriggers
[i
].Sound
<> nil then
3017 gTriggers
[i
].Sound
.PlayPanVolume(pan
, vol
);
3018 gTriggers
[i
].Sound
.Pause(True);
3019 gTriggers
[i
].Sound
.SetPosition(dw
);