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 trigData
: TDynRecord
; // triggerdata; owned by trigger
73 function trigCenter (): TDFPoint
; inline;
76 property trigShotPanelGUID
: Integer read trigPanelGUID write trigPanelGUID
;
79 function g_Triggers_Create(Trigger
: TTrigger
; forceInternalIndex
: Integer=-1): DWORD
;
80 procedure g_Triggers_Update();
81 procedure g_Triggers_Press(ID
: DWORD
; ActivateType
: Byte; ActivateUID
: Word = 0);
82 function g_Triggers_PressR(X
, Y
: Integer; Width
, Height
: Word; UID
: Word;
83 ActivateType
: Byte; IgnoreList
: DWArray
= nil): DWArray
;
84 procedure g_Triggers_PressL(X1
, Y1
, X2
, Y2
: Integer; UID
: DWORD
; ActivateType
: Byte);
85 procedure g_Triggers_PressC(CX
, CY
: Integer; Radius
: Word; UID
: Word; ActivateType
: Byte; IgnoreTrigger
: Integer = -1);
86 procedure g_Triggers_OpenAll();
87 procedure g_Triggers_DecreaseSpawner(ID
: DWORD
);
88 procedure g_Triggers_Free();
89 procedure g_Triggers_SaveState(var Mem
: TBinMemoryWriter
);
90 procedure g_Triggers_LoadState(var Mem
: TBinMemoryReader
);
94 gTriggerClientID
: Integer = 0;
95 gTriggers
: array of TTrigger
;
96 gSecretsCount
: Integer = 0;
97 gMonstersSpawned
: array of LongInt = nil;
104 g_player
, g_map
, g_panel
, g_gfx
, g_game
, g_textures
,
105 g_console
, g_monsters
, g_items
, g_phys
, g_weapons
,
106 wadreader
, g_main
, SysUtils
, e_log
, g_language
,
107 g_options
, g_net
, g_netmsg
, utils
, xparser
;
110 TRIGGER_SIGNATURE
= $58475254; // 'TRGX'
114 function TTrigger
.trigCenter (): TDFPoint
; inline;
116 result
:= TDFPoint
.Create(x
+width
div 2, y
+height
div 2);
120 function FindTrigger (): DWORD
;
124 for i
:= 0 to High(gTriggers
) do
126 if gTriggers
[i
].TriggerType
= TRIGGER_NONE
then begin result
:= i
; exit
; end;
129 if (gTriggers
= nil) then
131 SetLength(gTriggers
, 8);
136 result
:= Length(gTriggers
);
137 SetLength(gTriggers
, result
+8);
138 for i
:= result
to High(gTriggers
) do gTriggers
[i
].TriggerType
:= TRIGGER_NONE
;
143 function tr_CloseDoor (PanelGUID
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
150 pan
:= g_Map_PanelByGUID(PanelGUID
);
151 if (pan
= nil) or not pan
.isGWall
then exit
; //!FIXME!TRIGANY!
152 PanelID
:= pan
.arrIdx
;
156 with gWalls
[PanelID
] do
158 if g_CollidePlayer(X
, Y
, Width
, Height
) or g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then Exit
;
163 g_Sound_PlayExAt('SOUND_GAME_DOORCLOSE', X
, Y
);
164 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOORCLOSE');
166 g_Map_EnableWallGUID(PanelGUID
);
173 if (gDoorMap
= nil) then exit
;
176 for a
:= 0 to High(gDoorMap
) do
178 for b
:= 0 to High(gDoorMap
[a
]) do
180 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
186 if (c
<> -1) then break
;
188 if (c
= -1) then exit
;
190 for b
:= 0 to High(gDoorMap
[c
]) do
192 with gWalls
[gDoorMap
[c
, b
]] do
194 if g_CollidePlayer(X
, Y
, Width
, Height
) or g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then exit
;
200 for b
:= 0 to High(gDoorMap
[c
]) do
202 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
204 with gWalls
[PanelID
] do
206 g_Sound_PlayExAt('SOUND_GAME_DOORCLOSE', X
, Y
);
207 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOORCLOSE');
214 for b
:= 0 to High(gDoorMap
[c
]) do
216 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
218 g_Map_EnableWall_XXX(gDoorMap
[c
, b
]);
226 procedure tr_CloseTrap (PanelGUID
: Integer; NoSound
: Boolean; d2d
: Boolean);
229 wx
, wy
, wh
, ww
: Integer;
233 function monsDamage (mon
: TMonster
): Boolean;
235 result
:= false; // don't stop
236 if g_Obj_Collide(wx
, wy
, ww
, wh
, @mon
.Obj
) then mon
.Damage(TRAP_DAMAGE
, 0, 0, 0, HIT_TRAP
);
240 pan
:= g_Map_PanelByGUID(PanelGUID
);
244 e_LogWritefln('tr_CloseTrap: pguid=%s; NO PANEL!', [PanelGUID], MSG_WARNING);
248 e_LogWritefln('tr_CloseTrap: pguid=%s; isGWall=%s; arrIdx=%s', [PanelGUID, pan.isGWall, pan.arrIdx]);
251 if (pan
= nil) or not pan
.isGWall
then exit
; //!FIXME!TRIGANY!
252 PanelID
:= pan
.arrIdx
;
256 with gWalls
[PanelID
] do
258 if (not NoSound
) and (not Enabled
) then
260 g_Sound_PlayExAt('SOUND_GAME_SWITCH1', X
, Y
);
261 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_SWITCH1');
265 wx
:= gWalls
[PanelID
].X
;
266 wy
:= gWalls
[PanelID
].Y
;
267 ww
:= gWalls
[PanelID
].Width
;
268 wh
:= gWalls
[PanelID
].Height
;
270 with gWalls
[PanelID
] do
272 if gPlayers
<> nil then
274 for a
:= 0 to High(gPlayers
) do
276 if (gPlayers
[a
] <> nil) and gPlayers
[a
].Live
and gPlayers
[a
].Collide(X
, Y
, Width
, Height
) then
278 gPlayers
[a
].Damage(TRAP_DAMAGE
, 0, 0, 0, HIT_TRAP
);
283 //g_Mons_ForEach(monsDamage);
284 g_Mons_ForEachAliveAt(wx
, wy
, ww
, wh
, monsDamage
);
286 if not Enabled
then g_Map_EnableWallGUID(PanelGUID
);
291 if (gDoorMap
= nil) then exit
;
294 for a
:= 0 to High(gDoorMap
) do
296 for b
:= 0 to High(gDoorMap
[a
]) do
298 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
304 if (c
<> -1) then break
;
306 if (c
= -1) then exit
;
310 for b
:= 0 to High(gDoorMap
[c
]) do
312 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
314 with gWalls
[PanelID
] do
316 g_Sound_PlayExAt('SOUND_GAME_SWITCH1', X
, Y
);
317 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_SWITCH1');
324 for b
:= 0 to High(gDoorMap
[c
]) do
326 wx
:= gWalls
[gDoorMap
[c
, b
]].X
;
327 wy
:= gWalls
[gDoorMap
[c
, b
]].Y
;
328 ww
:= gWalls
[gDoorMap
[c
, b
]].Width
;
329 wh
:= gWalls
[gDoorMap
[c
, b
]].Height
;
331 with gWalls
[gDoorMap
[c
, b
]] do
333 if gPlayers
<> nil then
335 for a
:= 0 to High(gPlayers
) do
337 if (gPlayers
[a
] <> nil) and gPlayers
[a
].Live
and gPlayers
[a
].Collide(X
, Y
, Width
, Height
) then
339 gPlayers
[a
].Damage(TRAP_DAMAGE
, 0, 0, 0, HIT_TRAP
);
344 //g_Mons_ForEach(monsDamage);
345 g_Mons_ForEachAliveAt(wx
, wy
, ww
, wh
, monsDamage
);
347 if gMonsters <> nil then
348 for a := 0 to High(gMonsters) do
349 if (gMonsters[a] <> nil) and gMonsters[a].Live and
350 g_Obj_Collide(X, Y, Width, Height, @gMonsters[a].Obj) then
351 gMonsters[a].Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
354 if not Enabled
then g_Map_EnableWall_XXX(gDoorMap
[c
, b
]);
361 function tr_OpenDoor (PanelGUID
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
368 pan
:= g_Map_PanelByGUID(PanelGUID
);
369 if (pan
= nil) or not pan
.isGWall
then exit
; //!FIXME!TRIGANY!
370 PanelID
:= pan
.arrIdx
;
374 with gWalls
[PanelID
] do
380 g_Sound_PlayExAt('SOUND_GAME_DOOROPEN', X
, Y
);
381 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOOROPEN');
383 g_Map_DisableWallGUID(PanelGUID
);
390 if (gDoorMap
= nil) then exit
;
393 for a
:= 0 to High(gDoorMap
) do
395 for b
:= 0 to High(gDoorMap
[a
]) do
397 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
403 if (c
<> -1) then break
;
405 if (c
= -1) then exit
;
409 for b
:= 0 to High(gDoorMap
[c
]) do
411 if gWalls
[gDoorMap
[c
, b
]].Enabled
then
413 with gWalls
[PanelID
] do
415 g_Sound_PlayExAt('SOUND_GAME_DOOROPEN', X
, Y
);
416 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOOROPEN');
423 for b
:= 0 to High(gDoorMap
[c
]) do
425 if gWalls
[gDoorMap
[c
, b
]].Enabled
then
427 g_Map_DisableWall_XXX(gDoorMap
[c
, b
]);
435 function tr_SetLift (PanelGUID
: Integer; d
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
443 pan
:= g_Map_PanelByGUID(PanelGUID
);
444 if (pan
= nil) or not pan
.isGLift
then exit
; //!FIXME!TRIGANY!
445 PanelID
:= pan
.arrIdx
;
447 if (gLifts
[PanelID
].PanelType
= PANEL_LIFTUP
) or (gLifts
[PanelID
].PanelType
= PANEL_LIFTDOWN
) then
452 else t
:= IfThen(gLifts
[PanelID
].LiftType
= 1, 0, 1);
455 else if (gLifts
[PanelID
].PanelType
= PANEL_LIFTLEFT
) or (gLifts
[PanelID
].PanelType
= PANEL_LIFTRIGHT
) then
460 else t
:= IfThen(gLifts
[PanelID
].LiftType
= 2, 3, 2);
466 with gLifts
[PanelID
] do
468 if (LiftType
<> t
) then
470 g_Map_SetLiftGUID(PanelGUID
, t
); //???
471 //if not NoSound then g_Sound_PlayExAt('SOUND_GAME_SWITCH0', X, Y);
478 if (gLiftMap
= nil) then exit
;
481 for a
:= 0 to High(gLiftMap
) do
483 for b
:= 0 to High(gLiftMap
[a
]) do
485 if (gLiftMap
[a
, b
] = DWORD(PanelID
)) then
491 if (c
<> -1) then break
;
493 if (c
= -1) then exit
;
496 for b := 0 to High(gLiftMap[c]) do
497 if gLifts[gLiftMap[c, b]].LiftType <> t then
499 with gLifts[PanelID] do
500 g_Sound_PlayExAt('SOUND_GAME_SWITCH0', X, Y);
504 for b
:= 0 to High(gLiftMap
[c
]) do
506 with gLifts
[gLiftMap
[c
, b
]] do
508 if (LiftType
<> t
) then
510 g_Map_SetLift_XXX(gLiftMap
[c
, b
], t
);
519 function tr_SpawnShot (ShotType
: Integer; wx
, wy
, dx
, dy
: Integer; ShotSound
: Boolean; ShotTarget
: Word): Integer;
527 TextureID
:= DWORD(-1);
528 snd
:= 'SOUND_WEAPON_FIREROCKET';
534 g_Weapon_pistol(wx
, wy
, dx
, dy
, 0, True);
535 snd
:= 'SOUND_WEAPON_FIREPISTOL';
539 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_BULLET
);
540 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL1
);
546 g_Weapon_mgun(wx
, wy
, dx
, dy
, 0, True);
547 if gSoundEffectsDF
then snd
:= 'SOUND_WEAPON_FIRECGUN'
548 else snd
:= 'SOUND_WEAPON_FIREPISTOL';
552 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_BULLET
);
553 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL1
);
557 TRIGGER_SHOT_SHOTGUN
:
559 g_Weapon_Shotgun(wx
, wy
, dx
, dy
, 0, True);
560 snd
:= 'SOUND_WEAPON_FIRESHOTGUN';
564 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
565 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL2
);
571 g_Weapon_DShotgun(wx
, wy
, dx
, dy
, 0, True);
572 snd
:= 'SOUND_WEAPON_FIRESHOTGUN2';
576 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
577 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
578 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL3
);
584 g_Weapon_ball1(wx
, wy
, dx
, dy
, 0, -1, True);
585 snd
:= 'SOUND_WEAPON_FIREBALL';
590 g_Weapon_Plasma(wx
, wy
, dx
, dy
, 0, -1, True);
591 snd
:= 'SOUND_WEAPON_FIREPLASMA';
596 g_Weapon_aplasma(wx
, wy
, dx
, dy
, 0, -1, True);
597 snd
:= 'SOUND_WEAPON_FIREPLASMA';
602 g_Weapon_ball2(wx
, wy
, dx
, dy
, 0, -1, True);
603 snd
:= 'SOUND_WEAPON_FIREBALL';
608 g_Weapon_ball7(wx
, wy
, dx
, dy
, 0, -1, True);
609 snd
:= 'SOUND_WEAPON_FIREBALL';
614 g_Weapon_manfire(wx
, wy
, dx
, dy
, 0, -1, True);
615 snd
:= 'SOUND_WEAPON_FIREBALL';
620 g_Weapon_revf(wx
, wy
, dx
, dy
, 0, ShotTarget
, -1, True);
621 snd
:= 'SOUND_WEAPON_FIREREV';
626 g_Weapon_Rocket(wx
, wy
, dx
, dy
, 0, -1, True);
627 snd
:= 'SOUND_WEAPON_FIREROCKET';
632 g_Weapon_BFGShot(wx
, wy
, dx
, dy
, 0, -1, True);
633 snd
:= 'SOUND_WEAPON_FIREBFG';
638 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_ROCKET') then
640 Anim
:= TAnimation
.Create(TextureID
, False, 6);
641 Anim
.Blending
:= False;
642 g_GFX_OnceAnim(wx
-64, wy
-64, Anim
);
646 g_Weapon_Explode(wx
, wy
, 60, 0);
647 snd
:= 'SOUND_WEAPON_EXPLODEROCKET';
650 TRIGGER_SHOT_BFGEXPL
:
652 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_BFG') then
654 Anim
:= TAnimation
.Create(TextureID
, False, 6);
655 Anim
.Blending
:= False;
656 g_GFX_OnceAnim(wx
-64, wy
-64, Anim
);
660 g_Weapon_BFG9000(wx
, wy
, 0);
661 snd
:= 'SOUND_WEAPON_EXPLODEBFG';
667 if g_Game_IsNet
and g_Game_IsServer
then
670 TRIGGER_SHOT_EXPL
: MH_SEND_Effect(wx
, wy
, Byte(ShotSound
), NET_GFX_EXPLODE
);
671 TRIGGER_SHOT_BFGEXPL
: MH_SEND_Effect(wx
, wy
, Byte(ShotSound
), NET_GFX_BFGEXPL
);
674 if Projectile
then MH_SEND_CreateShot(LastShotID
);
675 if ShotSound
then MH_SEND_Sound(wx
, wy
, snd
);
680 if ShotSound
then g_Sound_PlayExAt(snd
, wx
, wy
);
682 if Projectile
then Result
:= LastShotID
;
686 procedure MakeShot (var Trigger
: TTrigger
; wx
, wy
, dx
, dy
: Integer; TargetUID
: Word);
690 if (trigData
.trigShotAmmo
= 0) or ((trigData
.trigShotAmmo
> 0) and (ShotAmmoCount
> 0)) then
692 if (trigShotPanelGUID
<> -1) and (ShotPanelTime
= 0) then
694 g_Map_SwitchTextureGUID(ShotPanelType
, trigShotPanelGUID
);
695 ShotPanelTime
:= 4; // òèêîâ íà âñïûøêó âûñòðåëà
698 if (trigData
.trigShotIntSight
> 0) then ShotSightTimeout
:= 180; // ~= 5 ñåêóíä
700 if (ShotAmmoCount
> 0) then Dec(ShotAmmoCount
);
702 dx
+= Random(trigData
.trigShotAccuracy
)-Random(trigData
.trigShotAccuracy
);
703 dy
+= Random(trigData
.trigShotAccuracy
)-Random(trigData
.trigShotAccuracy
);
705 tr_SpawnShot(trigData
.trigShotType
, wx
, wy
, dx
, dy
, trigData
.trigShotSound
, TargetUID
);
709 if (trigData
.trigShotIntReload
> 0) and (ShotReloadTime
= 0) then
711 ShotReloadTime
:= trigData
.trigShotIntReload
; // òèêîâ íà ïåðåçàðÿäêó ïóøêè
718 procedure tr_MakeEffect (X
, Y
, VX
, VY
: Integer; T
, ST
, CR
, CG
, CB
: Byte; Silent
, Send
: Boolean);
723 if T
= TRIGGER_EFFECT_PARTICLE
then
726 TRIGGER_EFFECT_SLIQUID
:
728 if (CR
= 255) and (CG
= 0) and (CB
= 0) then g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 1, 0, 0, 0)
729 else if (CR
= 0) and (CG
= 255) and (CB
= 0) then g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 2, 0, 0, 0)
730 else if (CR
= 0) and (CG
= 0) and (CB
= 255) then g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 3, 0, 0, 0)
731 else g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 0, 0, 0, 0);
733 TRIGGER_EFFECT_LLIQUID
: g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 4, CR
, CG
, CB
);
734 TRIGGER_EFFECT_DLIQUID
: g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 5, CR
, CG
, CB
);
735 TRIGGER_EFFECT_BLOOD
: g_GFX_Blood(X
, Y
, 1, VX
, VY
, 0, 0, CR
, CG
, CB
);
736 TRIGGER_EFFECT_SPARK
: g_GFX_Spark(X
, Y
, 1, GetAngle2(VX
, VY
), 0, 0);
737 TRIGGER_EFFECT_BUBBLE
: g_GFX_Bubbles(X
, Y
, 1, 0, 0);
741 if T
= TRIGGER_EFFECT_ANIMATION
then
744 EFFECT_TELEPORT
: begin
745 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
747 Anim
:= TAnimation
.Create(FramesID
, False, 3);
748 if not Silent
then g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
749 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
752 if Send
and g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(X
, Y
, Byte(not Silent
), NET_GFX_TELE
);
754 EFFECT_RESPAWN
: begin
755 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
757 Anim
:= TAnimation
.Create(FramesID
, False, 4);
758 if not Silent
then g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
759 g_GFX_OnceAnim(X
-16, Y
-16, Anim
);
762 if Send
and g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(X
-16, Y
-16, Byte(not Silent
), NET_GFX_RESPAWN
);
765 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
767 Anim
:= TAnimation
.Create(FramesID
, False, 4);
768 if not Silent
then g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
769 g_GFX_OnceAnim(X
-32, Y
-128, Anim
);
772 if Send
and g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(X
-32, Y
-128, Byte(not Silent
), NET_GFX_FIRE
);
779 function tr_Teleport (ActivateUID
: Integer; TX
, TY
: Integer; TDir
: Integer; Silent
: Boolean; D2D
: Boolean): Boolean;
785 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then Exit
;
786 case g_GetUIDType(ActivateUID
) of
789 p
:= g_Player_Get(ActivateUID
);
790 if p
= nil then Exit
;
793 if p
.TeleportTo(TX
-(p
.Obj
.Rect
.Width
div 2), TY
-p
.Obj
.Rect
.Height
, Silent
, TDir
) then result
:= true;
797 if p
.TeleportTo(TX
, TY
, Silent
, TDir
) then result
:= true;
802 m
:= g_Monsters_ByUID(ActivateUID
);
803 if m
= nil then Exit
;
806 if m
.TeleportTo(TX
-(m
.Obj
.Rect
.Width
div 2), TY
-m
.Obj
.Rect
.Height
, Silent
, TDir
) then result
:= true;
810 if m
.TeleportTo(TX
, TY
, Silent
, TDir
) then result
:= true;
817 function tr_Push (ActivateUID
: Integer; VX
, VY
: Integer; ResetVel
: Boolean): Boolean;
823 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then exit
;
824 case g_GetUIDType(ActivateUID
) of
827 p
:= g_Player_Get(ActivateUID
);
828 if p
= nil then Exit
;
843 m
:= g_Monsters_ByUID(ActivateUID
);
844 if m
= nil then Exit
;
860 function tr_Message (MKind
: Integer; MText
: string; MSendTo
: Integer; MTime
: Integer; ActivateUID
: Integer): Boolean;
867 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then Exit
;
868 msg
:= b_Text_Format(MText
);
872 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
874 if g_Game_IsWatchedPlayer(ActivateUID
) then
876 if MKind
= 0 then g_Console_Add(msg
, True)
877 else if MKind
= 1 then g_Game_Message(msg
, MTime
);
881 p
:= g_Player_Get(ActivateUID
);
882 if g_Game_IsNet
and (p
.FClientID
>= 0) then
884 if MKind
= 0 then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, p
.FClientID
)
885 else if MKind
= 1 then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, p
.FClientID
);
891 1: // activator's team
893 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
895 p
:= g_Player_Get(ActivateUID
);
896 if g_Game_IsWatchedTeam(p
.Team
) then
898 if MKind
= 0 then g_Console_Add(msg
, True)
899 else if MKind
= 1 then g_Game_Message(msg
, MTime
);
904 for i
:= Low(gPlayers
) to High(gPlayers
) do
906 if (gPlayers
[i
].Team
= p
.Team
) and (gPlayers
[i
].FClientID
>= 0) then
908 if MKind
= 0 then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
909 else if MKind
= 1 then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
916 2: // activator's enemy team
918 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
920 p
:= g_Player_Get(ActivateUID
);
921 if g_Game_IsWatchedTeam(p
.Team
) then
923 if MKind
= 0 then g_Console_Add(msg
, True)
924 else if MKind
= 1 then g_Game_Message(msg
, MTime
);
929 for i
:= Low(gPlayers
) to High(gPlayers
) do
931 if (gPlayers
[i
].Team
<> p
.Team
) and (gPlayers
[i
].FClientID
>= 0) then
933 if MKind
= 0 then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
934 else if MKind
= 1 then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
943 if g_Game_IsWatchedTeam(TEAM_RED
) then
945 if MKind
= 0 then g_Console_Add(msg
, True)
946 else if MKind
= 1 then g_Game_Message(msg
, MTime
);
951 for i
:= Low(gPlayers
) to High(gPlayers
) do
953 if (gPlayers
[i
].Team
= TEAM_RED
) and (gPlayers
[i
].FClientID
>= 0) then
955 if MKind
= 0 then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
956 else if MKind
= 1 then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
964 if g_Game_IsWatchedTeam(TEAM_BLUE
) then
966 if MKind
= 0 then g_Console_Add(msg
, True)
967 else if MKind
= 1 then g_Game_Message(msg
, MTime
);
972 for i
:= Low(gPlayers
) to High(gPlayers
) do
974 if (gPlayers
[i
].Team
= TEAM_BLUE
) and (gPlayers
[i
].FClientID
>= 0) then
976 if MKind
= 0 then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
977 else if MKind
= 1 then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
985 if MKind
= 0 then g_Console_Add(msg
, True)
986 else if MKind
= 1 then g_Game_Message(msg
, MTime
);
990 if MKind
= 0 then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
)
991 else if MKind
= 1 then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
);
998 function tr_ShotAimCheck (var Trigger
: TTrigger
; Obj
: PObj
): Boolean;
1003 if TriggerType
<> TRIGGER_SHOT
then Exit
;
1004 result
:= (trigData
.trigShotAim
and TRIGGER_SHOT_AIM_ALLMAP
> 0)
1005 or g_Obj_Collide(X
, Y
, Width
, Height
, Obj
);
1006 if result
and (trigData
.trigShotAim
and TRIGGER_SHOT_AIM_TRACE
> 0) then
1008 result
:= g_TraceVector(trigData
.trigShotPos
.X
, trigData
.trigShotPos
.Y
,
1009 Obj
^.X
+ Obj
^.Rect
.X
+ (Obj
^.Rect
.Width
div 2),
1010 Obj
^.Y
+ Obj
^.Rect
.Y
+ (Obj
^.Rect
.Height
div 2));
1016 function ActivateTrigger (var Trigger
: TTrigger
; actType
: Byte): Boolean;
1022 idx
, k
, wx
, wy
, xd
, yd
: Integer;
1033 function monsShotTarget (mon
: TMonster
): Boolean;
1035 result
:= false; // don't stop
1036 if mon
.Live
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
1038 xd
:= mon
.GameX
+ mon
.Obj
.Rect
.Width
div 2;
1039 yd
:= mon
.GameY
+ mon
.Obj
.Rect
.Height
div 2;
1040 TargetUID
:= mon
.UID
;
1041 result
:= true; // stop
1045 function monsShotTargetMonPlr (mon
: TMonster
): Boolean;
1047 result
:= false; // don't stop
1048 if mon
.Live
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
1050 xd
:= mon
.GameX
+ mon
.Obj
.Rect
.Width
div 2;
1051 yd
:= mon
.GameY
+ mon
.Obj
.Rect
.Height
div 2;
1052 TargetUID
:= mon
.UID
;
1053 result
:= true; // stop
1057 function monShotTargetPlrMon (mon
: TMonster
): Boolean;
1059 result
:= false; // don't stop
1060 if mon
.Live
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
1062 xd
:= mon
.GameX
+ mon
.Obj
.Rect
.Width
div 2;
1063 yd
:= mon
.GameY
+ mon
.Obj
.Rect
.Height
div 2;
1064 TargetUID
:= mon
.UID
;
1065 result
:= true; // stop
1071 if g_Game_IsClient
then exit
;
1073 if not Trigger
.Enabled
then exit
;
1074 if (Trigger
.TimeOut
<> 0) and (actType
<> ACTIVATE_CUSTOM
) then exit
;
1075 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then exit
;
1079 coolDown
:= (actType
<> 0);
1086 g_Sound_PlayEx('SOUND_GAME_SWITCH0');
1087 if g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_SWITCH0');
1088 gExitByTrigger
:= True;
1089 g_Game_ExitLevel(trigData
.trigMapName
);
1098 Result
:= tr_Teleport(ActivateUID
,
1099 trigData
.trigTargetPoint
.X
, trigData
.trigTargetPoint
.Y
,
1100 trigData
.trigTlpDir
, trigData
.trigsilent_teleport
,
1101 trigData
.trigd2d_teleport
);
1107 Result
:= tr_OpenDoor(trigPanelGUID
, trigData
.trigNoSound
, trigData
.trigd2d_doors
);
1113 Result
:= tr_CloseDoor(trigPanelGUID
, trigData
.trigNoSound
, trigData
.trigd2d_doors
);
1117 TRIGGER_DOOR
, TRIGGER_DOOR5
:
1119 pan
:= g_Map_PanelByGUID(trigPanelGUID
);
1120 if (pan
<> nil) and pan
.isGWall
then
1122 if gWalls
[{trigPanelID}pan
.arrIdx
].Enabled
then
1124 result
:= tr_OpenDoor(trigPanelGUID
, trigData
.trigNoSound
, trigData
.trigd2d_doors
);
1125 if (TriggerType
= TRIGGER_DOOR5
) then DoorTime
:= 180;
1129 result
:= tr_CloseDoor(trigPanelGUID
, trigData
.trigNoSound
, trigData
.trigd2d_doors
);
1132 if result
then TimeOut
:= 18;
1136 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
:
1138 tr_CloseTrap(trigPanelGUID
, trigData
.trigNoSound
, trigData
.trigd2d_doors
);
1140 if TriggerType
= TRIGGER_TRAP
then
1154 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
:
1157 if PressTime
= -1 then PressTime
:= trigData
.trigWait
;
1158 if coolDown
then TimeOut
:= 18 else TimeOut
:= 0;
1163 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
1167 if gLMSRespawn
= LMS_RESPAWN_NONE
then
1169 g_Player_Get(ActivateUID
).GetSecret();
1170 Inc(gCoopSecretsFound
);
1171 if g_Game_IsNet
then MH_SEND_GameStats();
1177 Result
:= tr_SetLift(trigPanelGUID
, 0, trigData
.trigNoSound
, trigData
.trigd2d_doors
);
1180 if (not trigData
.trigNoSound
) and Result
then begin
1181 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1183 Y
+ (Height
div 2));
1184 if g_Game_IsServer
and g_Game_IsNet
then
1185 MH_SEND_Sound(X
+ (Width
div 2),
1187 'SOUND_GAME_SWITCH0');
1193 Result
:= tr_SetLift(trigPanelGUID
, 1, trigData
.trigNoSound
, trigData
.trigd2d_doors
);
1196 if (not trigData
.trigNoSound
) and Result
then begin
1197 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1199 Y
+ (Height
div 2));
1200 if g_Game_IsServer
and g_Game_IsNet
then
1201 MH_SEND_Sound(X
+ (Width
div 2),
1203 'SOUND_GAME_SWITCH0');
1209 Result
:= tr_SetLift(trigPanelGUID
, 3, trigData
.trigNoSound
, trigData
.trigd2d_doors
);
1215 if (not trigData
.trigNoSound
) and Result
then begin
1216 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1218 Y
+ (Height
div 2));
1219 if g_Game_IsServer
and g_Game_IsNet
then
1220 MH_SEND_Sound(X
+ (Width
div 2),
1222 'SOUND_GAME_SWITCH0');
1229 if trigData
.trigActivateOnce
then
1232 TriggerType
:= TRIGGER_NONE
;
1240 animonce
:= trigData
.trigAnimOnce
;
1246 if Sound
<> nil then
1248 if trigData
.trigSoundSwitch
and Sound
.IsPlaying() then
1249 begin // Íóæíî âûêëþ÷èòü, åñëè èãðàë
1251 SoundPlayCount
:= 0;
1254 else // (not Data.SoundSwitch) or (not Sound.IsPlaying())
1255 if (trigData
.trigPlayCount
> 0) or (not Sound
.IsPlaying()) then
1257 if trigData
.trigPlayCount
> 0 then
1258 SoundPlayCount
:= trigData
.trigPlayCount
1259 else // 0 - èãðàåì áåñêîíå÷íî
1260 SoundPlayCount
:= 1;
1263 if g_Game_IsNet
then MH_SEND_TriggerSound(Trigger
);
1267 TRIGGER_SPAWNMONSTER
:
1268 if (trigData
.trigMonType
in [MONSTER_DEMON
..MONSTER_MAN
]) then
1271 if (trigData
.trigMonDelay
> 0) and (actType
<> ACTIVATE_CUSTOM
) then
1273 AutoSpawn
:= not AutoSpawn
;
1275 // Àâòîñïàâíåð ïåðåêëþ÷åí - ìåíÿåì òåêñòóðó
1279 if ((trigData
.trigMonDelay
= 0) and (actType
<> ACTIVATE_CUSTOM
))
1280 or ((trigData
.trigMonDelay
> 0) and (actType
= ACTIVATE_CUSTOM
)) then
1281 for k
:= 1 to trigData
.trigMonCount
do
1283 if (actType
= ACTIVATE_CUSTOM
) and (trigData
.trigMonDelay
> 0) then
1284 SpawnCooldown
:= trigData
.trigMonDelay
;
1285 if (trigData
.trigMonMax
> 0) and (SpawnedCount
>= trigData
.trigMonMax
) then
1288 mon
:= g_Monsters_Create(trigData
.trigMonType
,
1289 trigData
.trigMonPos
.X
, trigData
.trigMonPos
.Y
,
1290 TDirection(trigData
.trigMonDir
), True);
1295 if (trigData
.trigMonHealth
> 0) then
1296 mon
.SetHealth(trigData
.trigMonHealth
);
1297 // Óñòàíàâëèâàåì ïîâåäåíèå:
1298 mon
.MonsterBehaviour
:= trigData
.trigMonBehav
;
1299 mon
.FNoRespawn
:= True;
1300 if g_Game_IsNet
then
1301 MH_SEND_MonsterSpawn(mon
.UID
);
1302 // Èäåì èñêàòü öåëü, åñëè íàäî:
1303 if trigData
.trigMonActive
then
1306 if trigData
.trigMonType
<> MONSTER_BARREL
then Inc(gTotalMonsters
);
1308 if g_Game_IsNet
then
1310 SetLength(gMonstersSpawned
, Length(gMonstersSpawned
)+1);
1311 gMonstersSpawned
[High(gMonstersSpawned
)] := mon
.UID
;
1314 if trigData
.trigMonMax
> 0 then
1316 mon
.SpawnTrigger
:= ID
;
1320 case trigData
.trigMonEffect
of
1321 EFFECT_TELEPORT
: begin
1322 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
1324 Anim
:= TAnimation
.Create(FramesID
, False, 3);
1325 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', trigData
.trigMonPos
.X
, trigData
.trigMonPos
.Y
);
1326 g_GFX_OnceAnim(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1327 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-32, Anim
);
1330 if g_Game_IsServer
and g_Game_IsNet
then
1331 MH_SEND_Effect(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1332 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-32, 1,
1335 EFFECT_RESPAWN
: begin
1336 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
1338 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1339 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', trigData
.trigMonPos
.X
, trigData
.trigMonPos
.Y
);
1340 g_GFX_OnceAnim(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-16,
1341 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-16, Anim
);
1344 if g_Game_IsServer
and g_Game_IsNet
then
1345 MH_SEND_Effect(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-16,
1346 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-16, 1,
1350 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
1352 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1353 g_Sound_PlayExAt('SOUND_FIRE', trigData
.trigMonPos
.X
, trigData
.trigMonPos
.Y
);
1354 g_GFX_OnceAnim(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1355 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+mon
.Obj
.Rect
.Height
-128, Anim
);
1358 if g_Game_IsServer
and g_Game_IsNet
then
1359 MH_SEND_Effect(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1360 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+mon
.Obj
.Rect
.Height
-128, 1,
1365 if g_Game_IsNet
then
1367 MH_SEND_GameStats();
1368 MH_SEND_CoopStats();
1375 // Åñëè àêòèâèðîâàí àâòîñïàâíåðîì, íå ìåíÿåì òåêñòóðó
1376 if actType
= ACTIVATE_CUSTOM
then
1381 if (trigData
.trigItemType
in [ITEM_MEDKIT_SMALL
..ITEM_MAX
]) then
1384 if (trigData
.trigItemDelay
> 0) and (actType
<> ACTIVATE_CUSTOM
) then
1386 AutoSpawn
:= not AutoSpawn
;
1388 // Àâòîñïàâíåð ïåðåêëþ÷åí - ìåíÿåì òåêñòóðó
1392 if ((trigData
.trigItemDelay
= 0) and (actType
<> ACTIVATE_CUSTOM
))
1393 or ((trigData
.trigItemDelay
> 0) and (actType
= ACTIVATE_CUSTOM
)) then
1394 if (not trigData
.trigItemOnlyDM
) or
1395 (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
1396 for k
:= 1 to trigData
.trigItemCount
do
1398 if (actType
= ACTIVATE_CUSTOM
) and (trigData
.trigItemDelay
> 0) then
1399 SpawnCooldown
:= trigData
.trigItemDelay
;
1400 if (trigData
.trigItemMax
> 0) and (SpawnedCount
>= trigData
.trigItemMax
) then
1403 iid
:= g_Items_Create(trigData
.trigItemPos
.X
, trigData
.trigItemPos
.Y
,
1404 trigData
.trigItemType
, trigData
.trigItemFalls
, False, True);
1408 if trigData
.trigItemMax
> 0 then
1410 it
:= g_Items_ByIdx(iid
);
1411 it
.SpawnTrigger
:= ID
;
1415 case trigData
.trigItemEffect
of
1416 EFFECT_TELEPORT
: begin
1417 it
:= g_Items_ByIdx(iid
);
1418 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
1420 Anim
:= TAnimation
.Create(FramesID
, False, 3);
1421 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', trigData
.trigItemPos
.X
, trigData
.trigItemPos
.Y
);
1422 g_GFX_OnceAnim(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1423 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-32, Anim
);
1426 if g_Game_IsServer
and g_Game_IsNet
then
1427 MH_SEND_Effect(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1428 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-32, 1,
1431 EFFECT_RESPAWN
: begin
1432 it
:= g_Items_ByIdx(iid
);
1433 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
1435 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1436 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', trigData
.trigItemPos
.X
, trigData
.trigItemPos
.Y
);
1437 g_GFX_OnceAnim(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-16,
1438 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-16, Anim
);
1441 if g_Game_IsServer
and g_Game_IsNet
then
1442 MH_SEND_Effect(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-16,
1443 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-16, 1,
1447 it
:= g_Items_ByIdx(iid
);
1448 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
1450 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1451 g_Sound_PlayExAt('SOUND_FIRE', trigData
.trigItemPos
.X
, trigData
.trigItemPos
.Y
);
1452 g_GFX_OnceAnim(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1453 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+it
.Obj
.Rect
.Height
-128, Anim
);
1456 if g_Game_IsServer
and g_Game_IsNet
then
1457 MH_SEND_Effect(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1458 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+it
.Obj
.Rect
.Height
-128, 1,
1463 if g_Game_IsNet
then
1464 MH_SEND_ItemSpawn(True, iid
);
1471 // Åñëè àêòèâèðîâàí àâòîñïàâíåðîì, íå ìåíÿåì òåêñòóðó
1472 if actType
= ACTIVATE_CUSTOM
then
1478 // Ìåíÿåì ìóçûêó, åñëè åñòü íà ÷òî:
1479 if (Trigger
.trigData
.trigMusicName
<> '') then
1481 gMusic
.SetByName(Trigger
.trigData
.trigMusicName
);
1482 gMusic
.SpecPause
:= True;
1486 if Trigger
.trigData
.trigMusicAction
= 1 then
1488 if gMusic
.SpecPause
then // Áûëà íà ïàóçå => èãðàòü
1489 gMusic
.SpecPause
:= False
1490 else // Èãðàëà => ñíà÷àëà
1491 gMusic
.SetPosition(0);
1496 gMusic
.SpecPause
:= True;
1504 if g_Game_IsNet
then MH_SEND_TriggerMusic
;
1509 pAngle
:= -DegToRad(trigData
.trigPushAngle
);
1510 Result
:= tr_Push(ActivateUID
,
1511 Floor(Cos(pAngle
)*trigData
.trigPushForce
),
1512 Floor(Sin(pAngle
)*trigData
.trigPushForce
),
1513 trigData
.trigResetVel
);
1520 // Ïðèáàâèòü èëè îòíÿòü î÷êî
1521 if (trigData
.trigScoreAction
in [0..1]) and (trigData
.trigScoreCount
> 0) then
1523 // Ñâîåé èëè ÷óæîé êîìàíäå
1524 if (trigData
.trigScoreTeam
in [0..1]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
1526 p
:= g_Player_Get(ActivateUID
);
1527 if ((trigData
.trigScoreAction
= 0) and (trigData
.trigScoreTeam
= 0) and (p
.Team
= TEAM_RED
))
1528 or ((trigData
.trigScoreAction
= 0) and (trigData
.trigScoreTeam
= 1) and (p
.Team
= TEAM_BLUE
)) then
1530 Inc(gTeamStat
[TEAM_RED
].Goals
, trigData
.trigScoreCount
); // Red Scores
1532 if trigData
.trigScoreCon
then
1533 if trigData
.trigScoreTeam
= 0 then
1535 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_OWN
], [p
.Name
, trigData
.trigScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1536 if g_Game_IsServer
and g_Game_IsNet
then
1537 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (trigData
.trigScoreCount
shl 16), '+r');
1540 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_ENEMY
], [p
.Name
, trigData
.trigScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1541 if g_Game_IsServer
and g_Game_IsNet
then
1542 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (trigData
.trigScoreCount
shl 16), '+re');
1545 if trigData
.trigScoreMsg
then
1547 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1548 if g_Game_IsServer
and g_Game_IsNet
then
1549 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_RED
);
1552 if ((trigData
.trigScoreAction
= 1) and (trigData
.trigScoreTeam
= 0) and (p
.Team
= TEAM_RED
))
1553 or ((trigData
.trigScoreAction
= 1) and (trigData
.trigScoreTeam
= 1) and (p
.Team
= TEAM_BLUE
)) then
1555 Dec(gTeamStat
[TEAM_RED
].Goals
, trigData
.trigScoreCount
); // Red Fouls
1557 if trigData
.trigScoreCon
then
1558 if trigData
.trigScoreTeam
= 0 then
1560 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_OWN
], [p
.Name
, trigData
.trigScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1561 if g_Game_IsServer
and g_Game_IsNet
then
1562 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (trigData
.trigScoreCount
shl 16), '-r');
1565 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_ENEMY
], [p
.Name
, trigData
.trigScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1566 if g_Game_IsServer
and g_Game_IsNet
then
1567 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (trigData
.trigScoreCount
shl 16), '-re');
1570 if trigData
.trigScoreMsg
then
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 ((trigData
.trigScoreAction
= 0) and (trigData
.trigScoreTeam
= 0) and (p
.Team
= TEAM_BLUE
))
1578 or ((trigData
.trigScoreAction
= 0) and (trigData
.trigScoreTeam
= 1) and (p
.Team
= TEAM_RED
)) then
1580 Inc(gTeamStat
[TEAM_BLUE
].Goals
, trigData
.trigScoreCount
); // Blue Scores
1582 if trigData
.trigScoreCon
then
1583 if trigData
.trigScoreTeam
= 0 then
1585 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_OWN
], [p
.Name
, trigData
.trigScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1586 if g_Game_IsServer
and g_Game_IsNet
then
1587 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (trigData
.trigScoreCount
shl 16), '+b');
1590 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_ENEMY
], [p
.Name
, trigData
.trigScoreCount
, _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 (trigData
.trigScoreCount
shl 16), '+be');
1595 if trigData
.trigScoreMsg
then
1597 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1598 if g_Game_IsServer
and g_Game_IsNet
then
1599 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_BLUE
);
1602 if ((trigData
.trigScoreAction
= 1) and (trigData
.trigScoreTeam
= 0) and (p
.Team
= TEAM_BLUE
))
1603 or ((trigData
.trigScoreAction
= 1) and (trigData
.trigScoreTeam
= 1) and (p
.Team
= TEAM_RED
)) then
1605 Dec(gTeamStat
[TEAM_BLUE
].Goals
, trigData
.trigScoreCount
); // Blue Fouls
1607 if trigData
.trigScoreCon
then
1608 if trigData
.trigScoreTeam
= 0 then
1610 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_OWN
], [p
.Name
, trigData
.trigScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1611 if g_Game_IsServer
and g_Game_IsNet
then
1612 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (trigData
.trigScoreCount
shl 16), '-b');
1615 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_ENEMY
], [p
.Name
, trigData
.trigScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1616 if g_Game_IsServer
and g_Game_IsNet
then
1617 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (trigData
.trigScoreCount
shl 16), '-be');
1620 if trigData
.trigScoreMsg
then
1622 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1623 if g_Game_IsServer
and g_Game_IsNet
then
1624 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_BLUE
);
1627 Result
:= (p
.Team
= TEAM_RED
) or (p
.Team
= TEAM_BLUE
);
1629 // Êàêîé-òî êîíêðåòíîé êîìàíäå
1630 if trigData
.trigScoreTeam
in [2..3] then
1632 if (trigData
.trigScoreAction
= 0) and (trigData
.trigScoreTeam
= 2) then
1634 Inc(gTeamStat
[TEAM_RED
].Goals
, trigData
.trigScoreCount
); // Red Scores
1636 if trigData
.trigScoreCon
then
1638 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_TEAM
], [_lc
[I_PLAYER_SCORE_RED
], trigData
.trigScoreCount
]), True);
1639 if g_Game_IsServer
and g_Game_IsNet
then
1640 MH_SEND_GameEvent(NET_EV_SCORE
, trigData
.trigScoreCount
shl 16, '+tr');
1643 if trigData
.trigScoreMsg
then
1645 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1646 if g_Game_IsServer
and g_Game_IsNet
then
1647 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_RED
);
1650 if (trigData
.trigScoreAction
= 1) and (trigData
.trigScoreTeam
= 2) then
1652 Dec(gTeamStat
[TEAM_RED
].Goals
, trigData
.trigScoreCount
); // Red Fouls
1654 if trigData
.trigScoreCon
then
1656 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_TEAM
], [_lc
[I_PLAYER_SCORE_RED
], trigData
.trigScoreCount
]), True);
1657 if g_Game_IsServer
and g_Game_IsNet
then
1658 MH_SEND_GameEvent(NET_EV_SCORE
, trigData
.trigScoreCount
shl 16, '-tr');
1661 if trigData
.trigScoreMsg
then
1663 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1664 if g_Game_IsServer
and g_Game_IsNet
then
1665 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_RED
);
1668 if (trigData
.trigScoreAction
= 0) and (trigData
.trigScoreTeam
= 3) then
1670 Inc(gTeamStat
[TEAM_BLUE
].Goals
, trigData
.trigScoreCount
); // Blue Scores
1672 if trigData
.trigScoreCon
then
1674 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_TEAM
], [_lc
[I_PLAYER_SCORE_BLUE
], trigData
.trigScoreCount
]), True);
1675 if g_Game_IsServer
and g_Game_IsNet
then
1676 MH_SEND_GameEvent(NET_EV_SCORE
, trigData
.trigScoreCount
shl 16, '+tb');
1679 if trigData
.trigScoreMsg
then
1681 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1682 if g_Game_IsServer
and g_Game_IsNet
then
1683 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_BLUE
);
1686 if (trigData
.trigScoreAction
= 1) and (trigData
.trigScoreTeam
= 3) then
1688 Dec(gTeamStat
[TEAM_BLUE
].Goals
, trigData
.trigScoreCount
); // Blue Fouls
1690 if trigData
.trigScoreCon
then
1692 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_TEAM
], [_lc
[I_PLAYER_SCORE_BLUE
], trigData
.trigScoreCount
]), True);
1693 if g_Game_IsServer
and g_Game_IsNet
then
1694 MH_SEND_GameEvent(NET_EV_SCORE
, trigData
.trigScoreCount
shl 16, '-tb');
1697 if trigData
.trigScoreMsg
then
1699 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1700 if g_Game_IsServer
and g_Game_IsNet
then
1701 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_BLUE
);
1708 if (trigData
.trigScoreAction
= 2) and (gGameSettings
.GoalLimit
> 0) then
1710 // Ñâîåé èëè ÷óæîé êîìàíäû
1711 if (trigData
.trigScoreTeam
in [0..1]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
1713 p
:= g_Player_Get(ActivateUID
);
1714 if ((trigData
.trigScoreTeam
= 0) and (p
.Team
= TEAM_RED
)) // Red Wins
1715 or ((trigData
.trigScoreTeam
= 1) and (p
.Team
= TEAM_BLUE
)) then
1716 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1718 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1720 if trigData
.trigScoreCon
then
1721 if trigData
.trigScoreTeam
= 0 then
1723 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1724 if g_Game_IsServer
and g_Game_IsNet
then
1725 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wr');
1728 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1729 if g_Game_IsServer
and g_Game_IsNet
then
1730 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wre');
1735 if ((trigData
.trigScoreTeam
= 0) and (p
.Team
= TEAM_BLUE
)) // Blue Wins
1736 or ((trigData
.trigScoreTeam
= 1) and (p
.Team
= TEAM_RED
)) then
1737 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1739 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1741 if trigData
.trigScoreCon
then
1742 if trigData
.trigScoreTeam
= 0 then
1744 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1745 if g_Game_IsServer
and g_Game_IsNet
then
1746 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wb');
1749 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1750 if g_Game_IsServer
and g_Game_IsNet
then
1751 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wbe');
1757 // Êàêîé-òî êîíêðåòíîé êîìàíäû
1758 if trigData
.trigScoreTeam
in [2..3] then
1760 if trigData
.trigScoreTeam
= 2 then // Red Wins
1761 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1763 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1766 if trigData
.trigScoreTeam
= 3 then // Blue Wins
1767 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1769 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1775 if (trigData
.trigScoreAction
= 3) and (gGameSettings
.GoalLimit
> 0) then
1777 // Ñâîåé èëè ÷óæîé êîìàíäû
1778 if (trigData
.trigScoreTeam
in [0..1]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
1780 p
:= g_Player_Get(ActivateUID
);
1781 if ((trigData
.trigScoreTeam
= 0) and (p
.Team
= TEAM_BLUE
)) // Red Wins
1782 or ((trigData
.trigScoreTeam
= 1) and (p
.Team
= TEAM_RED
)) then
1783 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1785 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1787 if trigData
.trigScoreCon
then
1788 if trigData
.trigScoreTeam
= 0 then
1790 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1791 if g_Game_IsServer
and g_Game_IsNet
then
1792 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wre');
1795 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1796 if g_Game_IsServer
and g_Game_IsNet
then
1797 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wr');
1802 if ((trigData
.trigScoreTeam
= 0) and (p
.Team
= TEAM_RED
)) // Blue Wins
1803 or ((trigData
.trigScoreTeam
= 1) and (p
.Team
= TEAM_BLUE
)) then
1804 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1806 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1808 if trigData
.trigScoreCon
then
1809 if trigData
.trigScoreTeam
= 0 then
1811 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1812 if g_Game_IsServer
and g_Game_IsNet
then
1813 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wbe');
1816 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1817 if g_Game_IsServer
and g_Game_IsNet
then
1818 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wb');
1824 // Êàêîé-òî êîíêðåòíîé êîìàíäû
1825 if trigData
.trigScoreTeam
in [2..3] then
1827 if trigData
.trigScoreTeam
= 3 then // Red Wins
1828 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1830 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1833 if trigData
.trigScoreTeam
= 2 then // Blue Wins
1834 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1836 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1841 if Result
then begin
1846 if g_Game_IsServer
and g_Game_IsNet
then
1853 Result
:= tr_Message(trigData
.trigMessageKind
, trigData
.trigMessageText
,
1854 trigData
.trigMessageSendTo
, trigData
.trigMessageTime
,
1859 TRIGGER_DAMAGE
, TRIGGER_HEALTH
:
1862 UIDType
:= g_GetUIDType(ActivateUID
);
1863 if (UIDType
= UID_PLAYER
) or (UIDType
= UID_MONSTER
) then
1869 // Âñïîìèíàåì, àêòèâèðîâàë ëè îí ìåíÿ ðàíüøå
1870 for idx
:= 0 to High(Activators
) do
1871 if Activators
[idx
].UID
= ActivateUID
then
1877 begin // Âèäèì åãî âïåðâûå
1879 SetLength(Activators
, Length(Activators
) + 1);
1880 k
:= High(Activators
);
1881 Activators
[k
].UID
:= ActivateUID
;
1883 begin // Óæå âèäåëè åãî
1884 // Åñëè èíòåðâàë îòêëþ÷¸í, íî îí âñ¸ åù¸ â çîíå ïîðàæåíèÿ, äà¸ì åìó âðåìÿ
1885 if (trigData
.trigDamageInterval
= 0) and (Activators
[k
].TimeOut
> 0) then
1886 Activators
[k
].TimeOut
:= 65535;
1887 // Òàéìàóò ïðîø¸ë - ðàáîòàåì
1888 Result
:= Activators
[k
].TimeOut
= 0;
1897 p
:= g_Player_Get(ActivateUID
);
1901 // Íàíîñèì óðîí èãðîêó
1902 if (TriggerType
= TRIGGER_DAMAGE
) and (trigData
.trigDamageValue
> 0) then
1903 p
.Damage(trigData
.trigDamageValue
, 0, 0, 0, HIT_SOME
);
1906 if (TriggerType
= TRIGGER_HEALTH
) and (trigData
.trigHealValue
> 0) then
1907 if p
.Heal(trigData
.trigHealValue
, not trigData
.trigHealMax
) and (not trigData
.trigHealSilent
) then
1909 g_Sound_PlayExAt('SOUND_ITEM_GETITEM', p
.Obj
.X
, p
.Obj
.Y
);
1910 if g_Game_IsServer
and g_Game_IsNet
then
1911 MH_SEND_Sound(p
.Obj
.X
, p
.Obj
.Y
, 'SOUND_ITEM_GETITEM');
1917 m
:= g_Monsters_ByUID(ActivateUID
);
1921 // Íàíîñèì óðîí ìîíñòðó
1922 if (TriggerType
= TRIGGER_DAMAGE
) and (trigData
.trigDamageValue
> 0) then
1923 m
.Damage(trigData
.trigDamageValue
, 0, 0, 0, HIT_SOME
);
1926 if (TriggerType
= TRIGGER_HEALTH
) and (trigData
.trigHealValue
> 0) then
1927 if m
.Heal(trigData
.trigHealValue
) and (not trigData
.trigHealSilent
) then
1929 g_Sound_PlayExAt('SOUND_ITEM_GETITEM', m
.Obj
.X
, m
.Obj
.Y
);
1930 if g_Game_IsServer
and g_Game_IsNet
then
1931 MH_SEND_Sound(m
.Obj
.X
, m
.Obj
.Y
, 'SOUND_ITEM_GETITEM');
1935 // Íàçíà÷àåì âðåìÿ ñëåäóþùåãî âîçäåéñòâèÿ
1936 if TriggerType
= TRIGGER_DAMAGE
then
1937 idx
:= trigData
.trigDamageInterval
1939 idx
:= trigData
.trigHealInterval
;
1942 Activators
[k
].TimeOut
:= idx
1944 Activators
[k
].TimeOut
:= 65535;
1952 if ShotSightTime
> 0 then
1955 // put this at the beginning so it doesn't trigger itself
1956 TimeOut
:= trigData
.trigShotWait
+ 1;
1958 wx
:= trigData
.trigShotPos
.X
;
1959 wy
:= trigData
.trigShotPos
.Y
;
1960 pAngle
:= -DegToRad(trigData
.trigShotAngle
);
1961 xd
:= wx
+ Round(Cos(pAngle
) * 32.0);
1962 yd
:= wy
+ Round(Sin(pAngle
) * 32.0);
1965 case trigData
.trigShotTarget
of
1966 TRIGGER_SHOT_TARGET_MON
: // monsters
1967 //TODO: accelerate this!
1968 g_Mons_ForEachAlive(monsShotTarget
);
1970 TRIGGER_SHOT_TARGET_PLR
: // players
1971 if gPlayers
<> nil then
1972 for idx
:= Low(gPlayers
) to High(gPlayers
) do
1973 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].Live
and
1974 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
1976 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
1977 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
1978 TargetUID
:= gPlayers
[idx
].UID
;
1982 TRIGGER_SHOT_TARGET_RED
: // red team
1983 if gPlayers
<> nil then
1984 for idx
:= Low(gPlayers
) to High(gPlayers
) do
1985 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].Live
and
1986 (gPlayers
[idx
].Team
= TEAM_RED
) and
1987 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
1989 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
1990 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
1991 TargetUID
:= gPlayers
[idx
].UID
;
1995 TRIGGER_SHOT_TARGET_BLUE
: // blue team
1996 if gPlayers
<> nil then
1997 for idx
:= Low(gPlayers
) to High(gPlayers
) do
1998 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].Live
and
1999 (gPlayers
[idx
].Team
= TEAM_BLUE
) and
2000 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2002 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2003 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2004 TargetUID
:= gPlayers
[idx
].UID
;
2008 TRIGGER_SHOT_TARGET_MONPLR
: // monsters then players
2010 //TODO: accelerate this!
2011 g_Mons_ForEachAlive(monsShotTargetMonPlr
);
2013 if (TargetUID
= 0) and (gPlayers
<> nil) then
2014 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2015 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].Live
and
2016 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2018 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2019 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2020 TargetUID
:= gPlayers
[idx
].UID
;
2025 TRIGGER_SHOT_TARGET_PLRMON
: // players then monsters
2027 if gPlayers
<> nil then
2028 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2029 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].Live
and
2030 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2032 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2033 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2034 TargetUID
:= gPlayers
[idx
].UID
;
2037 if TargetUID
= 0 then
2039 //TODO: accelerate this!
2040 g_Mons_ForEachAlive(monShotTargetPlrMon
);
2045 if (trigData
.trigShotTarget
<> TRIGGER_SHOT_TARGET_NONE
) or
2046 (trigData
.trigShotType
<> TRIGGER_SHOT_REV
) then
2047 TargetUID
:= ActivateUID
;
2051 if (trigData
.trigShotTarget
= TRIGGER_SHOT_TARGET_NONE
) or (TargetUID
> 0) or
2052 ((trigData
.trigShotTarget
> TRIGGER_SHOT_TARGET_NONE
) and (TargetUID
= 0)) then
2055 if (trigData
.trigShotIntSight
= 0) or
2056 (trigData
.trigShotTarget
= TRIGGER_SHOT_TARGET_NONE
) or
2057 (TargetUID
= ShotSightTarget
) then
2058 MakeShot(Trigger
, wx
, wy
, xd
, yd
, TargetUID
)
2061 ShotSightTime
:= trigData
.trigShotIntSight
;
2062 ShotSightTargetN
:= TargetUID
;
2063 if trigData
.trigShotType
= TRIGGER_SHOT_BFG
then
2065 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', wx
, wy
);
2066 if g_Game_IsNet
and g_Game_IsServer
then
2067 MH_SEND_Sound(wx
, wy
, 'SOUND_WEAPON_STARTFIREBFG');
2075 idx
:= trigData
.trigFXCount
;
2079 case trigData
.trigFXPos
of
2080 TRIGGER_EFFECT_POS_CENTER
:
2082 wx
:= X
+ Width
div 2;
2083 wy
:= Y
+ Height
div 2;
2085 TRIGGER_EFFECT_POS_AREA
:
2087 wx
:= X
+ Random(Width
);
2088 wy
:= Y
+ Random(Height
);
2091 wx
:= X
+ Width
div 2;
2092 wy
:= Y
+ Height
div 2;
2095 xd
:= trigData
.trigFXVelX
;
2096 yd
:= trigData
.trigFXVelY
;
2097 if trigData
.trigFXSpreadL
> 0 then xd
:= xd
- Random(trigData
.trigFXSpreadL
+ 1);
2098 if trigData
.trigFXSpreadR
> 0 then xd
:= xd
+ Random(trigData
.trigFXSpreadR
+ 1);
2099 if trigData
.trigFXSpreadU
> 0 then yd
:= yd
- Random(trigData
.trigFXSpreadU
+ 1);
2100 if trigData
.trigFXSpreadD
> 0 then yd
:= yd
+ Random(trigData
.trigFXSpreadD
+ 1);
2101 tr_MakeEffect(wx
, wy
, xd
, yd
,
2102 trigData
.trigFXType
, trigData
.trigFXSubType
,
2103 trigData
.trigFXColorR
, trigData
.trigFXColorG
, trigData
.trigFXColorB
, True, False);
2106 TimeOut
:= trigData
.trigFXWait
;
2111 if Result
{and (Trigger.TexturePanel <> -1)} then
2113 g_Map_SwitchTextureGUID(Trigger
.TexturePanelType
, Trigger
.TexturePanelGUID
, IfThen(animonce
, 2, 1));
2118 function g_Triggers_CreateWithMapIndex (Trigger
: TTrigger
; arridx
, mapidx
: Integer): DWORD
;
2120 triggers
: TDynField
;
2122 triggers
:= gCurrentMap
['trigger'];
2123 if (triggers
= nil) then raise Exception
.Create('LOAD: map has no triggers');
2124 if (mapidx
< 0) or (mapidx
>= triggers
.count
) then raise Exception
.Create('LOAD: invalid map trigger index');
2125 Trigger
.trigData
:= triggers
.item
[mapidx
];
2126 if (Trigger
.trigData
= nil) then raise Exception
.Create('LOAD: internal error in trigger loader');
2127 Trigger
.mapId
:= Trigger
.trigData
.id
;
2128 Trigger
.mapIndex
:= mapidx
;
2129 if (Trigger
.trigData
.trigRec
<> nil) then
2131 Trigger
.trigData
:= Trigger
.trigData
.trigRec
.clone();
2135 Trigger
.trigData
:= nil;
2137 result
:= g_Triggers_Create(Trigger
, arridx
);
2141 function g_Triggers_Create(Trigger
: TTrigger
; forceInternalIndex
: Integer=-1): DWORD
;
2144 fn
, mapw
: AnsiString;
2147 // Íå ñîçäàâàòü âûõîä, åñëè èãðà áåç âûõîäà:
2148 if (Trigger
.TriggerType
= TRIGGER_EXIT
) and
2149 (not LongBool(gGameSettings
.Options
and GAME_OPTION_ALLOWEXIT
)) then
2150 Trigger
.TriggerType
:= TRIGGER_NONE
;
2152 // Åñëè ìîíñòðû çàïðåùåíû, îòìåíÿåì òðèããåð:
2153 if (Trigger
.TriggerType
= TRIGGER_SPAWNMONSTER
) and
2154 (not LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
)) and
2155 (gGameSettings
.GameType
<> GT_SINGLE
) then
2156 Trigger
.TriggerType
:= TRIGGER_NONE
;
2158 // Ñ÷èòàåì êîëè÷åñòâî ñåêðåòîâ íà êàðòå:
2159 if Trigger
.TriggerType
= TRIGGER_SECRET
then
2160 gSecretsCount
:= gSecretsCount
+ 1;
2162 if (forceInternalIndex
< 0) then
2164 find_id
:= FindTrigger();
2168 olen
:= Length(gTriggers
);
2169 if (forceInternalIndex
>= olen
) then
2171 SetLength(gTriggers
, forceInternalIndex
+1);
2172 for f
:= olen
to High(gTriggers
) do gTriggers
[f
].TriggerType
:= TRIGGER_NONE
;
2174 find_id
:= DWORD(forceInternalIndex
);
2176 gTriggers
[find_id
] := Trigger
;
2178 //e_LogWritefln('created trigger with map index %s, findid=%s (%s)', [Trigger.mapIndex, find_id, Trigger.mapId]);
2181 writeln('trigger #', find_id, ': pos=(', Trigger.x, ',', Trigger.y, ')-(', Trigger.width, 'x', Trigger.height, ')',
2182 '; TexturePanel=', Trigger.TexturePanel,
2183 '; TexturePanelType=', Trigger.TexturePanelType,
2184 '; ShotPanelType=', Trigger.ShotPanelType,
2185 '; TriggerType=', Trigger.TriggerType,
2186 '; ActivateType=', Trigger.ActivateType,
2187 '; Keys=', Trigger.Keys,
2188 '; trigPanelId=', Trigger.trigPanelId,
2189 '; trigShotPanelId=', Trigger.trigShotPanelId
2193 with gTriggers
[find_id
] do
2196 // if this type of trigger exists both on the client and on the server
2197 // use an uniform numeration
2198 if Trigger
.TriggerType
= TRIGGER_SOUND
then
2200 Inc(gTriggerClientID
);
2201 ClientID
:= gTriggerClientID
;
2207 PlayerCollide
:= False;
2211 SoundPlayCount
:= 0;
2218 // Çàãðóæàåì çâóê, åñëè ýòî òðèããåð "Çâóê":
2219 if (Trigger
.TriggerType
= TRIGGER_SOUND
) and
2220 (Trigger
.trigData
.trigSoundName
<> '') then
2222 // Åùå íåò òàêîãî çâóêà:
2223 if not g_Sound_Exists(Trigger
.trigData
.trigSoundName
) then
2225 fn
:= g_ExtractWadName(Trigger
.trigData
.trigSoundName
);
2228 begin // Çâóê â ôàéëå ñ êàðòîé
2229 mapw
:= g_ExtractWadName(gMapInfo
.Map
);
2230 fn
:= mapw
+':'+g_ExtractFilePathName(Trigger
.trigData
.trigSoundName
);
2232 else // Çâóê â îòäåëüíîì ôàéëå
2233 fn
:= GameDir
+ '/wads/' + Trigger
.trigData
.trigSoundName
;
2235 if not g_Sound_CreateWADEx(Trigger
.trigData
.trigSoundName
, fn
) then
2236 g_FatalError(Format(_lc
[I_GAME_ERROR_TR_SOUND
], [fn
, Trigger
.trigData
.trigSoundName
]));
2239 // Ñîçäàåì îáúåêò çâóêà:
2240 with gTriggers
[find_id
] do
2242 Sound
:= TPlayableSound
.Create();
2243 if not Sound
.SetByName(Trigger
.trigData
.trigSoundName
) then
2251 // Çàãðóæàåì ìóçûêó, åñëè ýòî òðèããåð "Ìóçûêà":
2252 if (Trigger
.TriggerType
= TRIGGER_MUSIC
) and
2253 (Trigger
.trigData
.trigMusicName
<> '') then
2255 // Åùå íåò òàêîé ìóçûêè:
2256 if not g_Sound_Exists(Trigger
.trigData
.trigMusicName
) then
2258 fn
:= g_ExtractWadName(Trigger
.trigData
.trigMusicName
);
2261 begin // Ìóçûêà â ôàéëå ñ êàðòîé
2262 mapw
:= g_ExtractWadName(gMapInfo
.Map
);
2263 fn
:= mapw
+':'+g_ExtractFilePathName(Trigger
.trigData
.trigMusicName
);
2265 else // Ìóçûêà â ôàéëå ñ êàðòîé
2266 fn
:= GameDir
+'/wads/'+Trigger
.trigData
.trigMusicName
;
2268 if not g_Sound_CreateWADEx(Trigger
.trigData
.trigMusicName
, fn
, True) then
2269 g_FatalError(Format(_lc
[I_GAME_ERROR_TR_SOUND
], [fn
, Trigger
.trigData
.trigMusicName
]));
2273 // Çàãðóæàåì äàííûå òðèããåðà "Òóðåëü":
2274 if Trigger
.TriggerType
= TRIGGER_SHOT
then
2275 with gTriggers
[find_id
] do
2279 ShotSightTimeout
:= 0;
2280 ShotSightTarget
:= 0;
2281 ShotSightTargetN
:= 0;
2282 ShotAmmoCount
:= Trigger
.trigData
.trigShotAmmo
;
2283 ShotReloadTime
:= 0;
2290 // sorry; grid doesn't support recursive queries, so we have to do this
2292 TSimpleMonsterList
= specialize TSimpleList
<TMonster
>;
2295 tgMonsList
: TSimpleMonsterList
= nil;
2297 procedure g_Triggers_Update();
2300 Affected
: array of Integer;
2302 function monsNear (mon
: TMonster
): Boolean;
2304 result
:= false; // don't stop
2306 gTriggers[a].ActivateUID := mon.UID;
2307 ActivateTrigger(gTriggers[a], ACTIVATE_MONSTERCOLLIDE);
2309 tgMonsList
.append(mon
);
2316 if (tgMonsList
= nil) then tgMonsList
:= TSimpleMonsterList
.Create();
2318 if gTriggers
= nil then
2320 SetLength(Affected
, 0);
2322 for a
:= 0 to High(gTriggers
) do
2323 with gTriggers
[a
] do
2325 if TriggerType
<> TRIGGER_NONE
then
2327 // Óìåíüøàåì âðåìÿ äî çàêðûòèÿ äâåðè (îòêðûòèÿ ëîâóøêè)
2328 if DoorTime
> 0 then DoorTime
:= DoorTime
- 1;
2329 // Óìåíüøàåì âðåìÿ îæèäàíèÿ ïîñëå íàæàòèÿ
2330 if PressTime
> 0 then PressTime
:= PressTime
- 1;
2331 // Ïðîâåðÿåì èãðîêîâ è ìîíñòðîâ, êîòîðûõ ðàíåå çàïîìíèëè:
2332 if (TriggerType
= TRIGGER_DAMAGE
) or (TriggerType
= TRIGGER_HEALTH
) then
2334 for b
:= 0 to High(Activators
) do
2336 // Óìåíüøàåì âðåìÿ äî ïîâòîðíîãî âîçäåéñòâèÿ:
2337 if Activators
[b
].TimeOut
> 0 then
2339 Dec(Activators
[b
].TimeOut
);
2345 // Ñ÷èòàåì, ÷òî îáúåêò ïîêèíóë çîíó äåéñòâèÿ òðèããåðà
2346 if (trigData
.trigDamageInterval
= 0) and (Activators
[b
].TimeOut
< 65530) then Activators
[b
].TimeOut
:= 0;
2350 // Îáðàáàòûâàåì ñïàâíåðû
2351 if Enabled
and AutoSpawn
then
2353 if SpawnCooldown
= 0 then
2355 // Åñëè ïðèøëî âðåìÿ, ñïàâíèì ìîíñòðà
2356 if (TriggerType
= TRIGGER_SPAWNMONSTER
) and (trigData
.trigMonDelay
> 0) then
2359 ActivateTrigger(gTriggers
[a
], ACTIVATE_CUSTOM
);
2361 // Åñëè ïðèøëî âðåìÿ, ñïàâíèì ïðåäìåò
2362 if (TriggerType
= TRIGGER_SPAWNITEM
) and (trigData
.trigItemDelay
> 0) then
2365 ActivateTrigger(gTriggers
[a
], ACTIVATE_CUSTOM
);
2370 // Óìåíüøàåì âðåìÿ îæèäàíèÿ
2375 // Îáðàáàòûâàåì ñîáûòèÿ òðèããåðà "Òóðåëü"
2376 if TriggerType
= TRIGGER_SHOT
then
2378 if ShotPanelTime
> 0 then
2381 if ShotPanelTime
= 0 then g_Map_SwitchTextureGUID(ShotPanelType
, trigShotPanelGUID
);
2383 if ShotSightTime
> 0 then
2386 if ShotSightTime
= 0 then ShotSightTarget
:= ShotSightTargetN
;
2388 if ShotSightTimeout
> 0 then
2390 Dec(ShotSightTimeout
);
2391 if ShotSightTimeout
= 0 then ShotSightTarget
:= 0;
2393 if ShotReloadTime
> 0 then
2395 Dec(ShotReloadTime
);
2396 if ShotReloadTime
= 0 then ShotAmmoCount
:= trigData
.trigShotAmmo
;
2400 // Òðèããåð "Çâóê" óæå îòûãðàë, åñëè íóæíî åùå - ïåðåçàïóñêàåì
2401 if Enabled
and (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) then
2403 if (SoundPlayCount
> 0) and (not Sound
.IsPlaying()) then
2405 if trigData
.trigPlayCount
> 0 then SoundPlayCount
-= 1; // Åñëè 0 - èãðàåì çâóê áåñêîíå÷íî
2406 if trigData
.trigLocal
then
2408 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), trigData
.trigVolume
/255.0);
2412 Sound
.PlayPanVolume((trigData
.trigPan
-127.0)/128.0, trigData
.trigVolume
/255.0);
2414 if Sound
.IsPlaying() and g_Game_IsNet
and g_Game_IsServer
then MH_SEND_TriggerSound(gTriggers
[a
]);
2418 // Òðèããåð "Ëîâóøêà" - ïîðà îòêðûâàòü
2419 if (TriggerType
= TRIGGER_TRAP
) and (DoorTime
= 0) and (g_Map_PanelByGUID(trigPanelGUID
) <> nil) then
2421 tr_OpenDoor(trigPanelGUID
, trigData
.trigNoSound
, trigData
.trigd2d_doors
);
2425 // Òðèããåð "Äâåðü 5 ñåê" - ïîðà çàêðûâàòü
2426 if (TriggerType
= TRIGGER_DOOR5
) and (DoorTime
= 0) and (g_Map_PanelByGUID(trigPanelGUID
) <> nil) then
2428 pan
:= g_Map_PanelByGUID(trigPanelGUID
);
2429 if (pan
<> nil) and pan
.isGWall
then
2432 if {gWalls[trigPanelID].Enabled} pan
.Enabled
then
2438 // Ïîêà îòêðûòà - çàêðûâàåì
2439 if tr_CloseDoor(trigPanelGUID
, trigData
.trigNoSound
, trigData
.trigd2d_doors
) then DoorTime
:= -1;
2444 // Òðèããåð - ðàñøèðèòåëü èëè ïåðåêëþ÷àòåëü, è ïðîøëà çàäåðæêà, è íàæàëè íóæíîå ÷èñëî ðàç:
2445 if (TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
]) and
2446 (PressTime
= 0) and (PressCount
>= trigData
.trigCount
) then
2448 // Ñáðàñûâàåì çàäåðæêó àêòèâàöèè:
2450 // Ñáðàñûâàåì ñ÷åò÷èê íàæàòèé:
2451 if trigData
.trigCount
> 0 then PressCount
-= trigData
.trigCount
else PressCount
:= 0;
2453 // Îïðåäåëÿåì èçìåíÿåìûå èì òðèããåðû:
2454 for b
:= 0 to High(gTriggers
) do
2456 if g_Collide(trigData
.trigtX
, trigData
.trigtY
, trigData
.trigtWidth
, trigData
.trigtHeight
, gTriggers
[b
].X
, gTriggers
[b
].Y
,
2457 gTriggers
[b
].Width
, gTriggers
[b
].Height
) and
2458 ((b
<> a
) or (trigData
.trigWait
> 0)) then
2459 begin // Can be self-activated, if there is Data.Wait
2460 if (not trigData
.trigExtRandom
) or gTriggers
[b
].Enabled
then
2462 SetLength(Affected
, Length(Affected
) + 1);
2463 Affected
[High(Affected
)] := b
;
2469 // if we have panelid, assume that it will switch the moving platform
2470 pan
:= g_Map_PanelByGUID(trigPanelGUID
);
2471 if (pan
<> nil) then
2474 TRIGGER_PRESS
: pan
.movingActive
:= true; // what to do here?
2475 TRIGGER_ON
: pan
.movingActive
:= true;
2476 TRIGGER_OFF
: pan
.movingActive
:= false;
2477 TRIGGER_ONOFF
: pan
.movingActive
:= not pan
.movingActive
;
2481 // Âûáèðàåì îäèí èç òðèããåðîâ äëÿ ðàñøèðèòåëÿ, åñëè âêëþ÷åí ðàíäîì:
2482 if (TriggerType
= TRIGGER_PRESS
) and trigData
.trigExtRandom
then
2484 if (Length(Affected
) > 0) then
2486 b
:= Affected
[Random(Length(Affected
))];
2487 gTriggers
[b
].ActivateUID
:= gTriggers
[a
].ActivateUID
;
2488 ActivateTrigger(gTriggers
[b
], 0);
2491 else //  ïðîòèâíîì ñëó÷àå ðàáîòàåì êàê îáû÷íî:
2493 for i
:= 0 to High(Affected
) do
2499 gTriggers
[b
].ActivateUID
:= gTriggers
[a
].ActivateUID
;
2500 ActivateTrigger(gTriggers
[b
], 0);
2504 gTriggers
[b
].Enabled
:= True;
2508 gTriggers
[b
].Enabled
:= False;
2509 gTriggers
[b
].TimeOut
:= 0;
2510 if gTriggers
[b
].AutoSpawn
then
2512 gTriggers
[b
].AutoSpawn
:= False;
2513 gTriggers
[b
].SpawnCooldown
:= 0;
2518 gTriggers
[b
].Enabled
:= not gTriggers
[b
].Enabled
;
2519 if not gTriggers
[b
].Enabled
then
2521 gTriggers
[b
].TimeOut
:= 0;
2522 if gTriggers
[b
].AutoSpawn
then
2524 gTriggers
[b
].AutoSpawn
:= False;
2525 gTriggers
[b
].SpawnCooldown
:= 0;
2532 SetLength(Affected
, 0);
2535 // Óìåíüøàåì âðåìÿ äî âîçìîæíîñòè ïîâòîðíîé àêòèâàöèè:
2538 TimeOut
:= TimeOut
- 1;
2539 Continue
; // ×òîáû íå ïîòåðÿòü 1 åäèíèöó çàäåðæêè
2542 // Íèæå èäóò òèïû àêòèâàöèè, åñëè òðèããåð îòêëþ÷¸í - èä¸ì äàëüøå
2547 if ByteBool(ActivateType
and ACTIVATE_PLAYERCOLLIDE
) and
2549 if gPlayers
<> nil then
2550 for b
:= 0 to High(gPlayers
) do
2551 if gPlayers
[b
] <> nil then
2553 // Æèâ, åñòü íóæíûå êëþ÷è è îí ðÿäîì:
2554 if Live
and ((gTriggers
[a
].Keys
and GetKeys
) = gTriggers
[a
].Keys
) and
2555 Collide(X
, Y
, Width
, Height
) then
2557 gTriggers
[a
].ActivateUID
:= UID
;
2559 if (gTriggers
[a
].TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) and
2561 { Don't activate sound/music again if player is here }
2563 ActivateTrigger(gTriggers
[a
], ACTIVATE_PLAYERCOLLIDE
);
2566 { TODO 5 : àêòèâàöèÿ ìîíñòðàìè òðèããåðîâ ñ êëþ÷àìè }
2568 if ByteBool(ActivateType
and ACTIVATE_MONSTERCOLLIDE
) and
2569 ByteBool(ActivateType
and ACTIVATE_NOMONSTER
) and
2570 (TimeOut
= 0) and (Keys
= 0) then
2572 // Åñëè "Ìîíñòð áëèçêî" è "Ìîíñòðîâ íåò",
2573 // çàïóñêàåì òðèããåð íà ñòàðòå êàðòû è ñíèìàåì îáà ôëàãà
2574 ActivateType
:= ActivateType
and not (ACTIVATE_MONSTERCOLLIDE
or ACTIVATE_NOMONSTER
);
2575 gTriggers
[a
].ActivateUID
:= 0;
2576 ActivateTrigger(gTriggers
[a
], 0);
2580 if ByteBool(ActivateType
and ACTIVATE_MONSTERCOLLIDE
) and
2581 (TimeOut
= 0) and (Keys
= 0) then // Åñëè íå íóæíû êëþ÷è
2583 //g_Mons_ForEach(monsNear);
2586 g_Mons_ForEachAt(gTriggers
[a
].X
, gTriggers
[a
].Y
, gTriggers
[a
].Width
, gTriggers
[a
].Height
, monsNear
);
2587 for mon
in tgMonsList
do
2589 gTriggers
[a
].ActivateUID
:= mon
.UID
;
2590 ActivateTrigger(gTriggers
[a
], ACTIVATE_MONSTERCOLLIDE
);
2592 tgMonsList
.reset(); // just in case
2596 if ByteBool(ActivateType
and ACTIVATE_NOMONSTER
) and
2597 (TimeOut
= 0) and (Keys
= 0) then
2598 if not g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then
2600 gTriggers
[a
].ActivateUID
:= 0;
2601 ActivateTrigger(gTriggers
[a
], ACTIVATE_NOMONSTER
);
2605 PlayerCollide
:= g_CollidePlayer(X
, Y
, Width
, Height
);
2609 procedure g_Triggers_Press(ID
: DWORD
; ActivateType
: Byte; ActivateUID
: Word = 0);
2611 gTriggers
[ID
].ActivateUID
:= ActivateUID
;
2612 ActivateTrigger(gTriggers
[ID
], ActivateType
);
2615 function g_Triggers_PressR(X
, Y
: Integer; Width
, Height
: Word; UID
: Word;
2616 ActivateType
: Byte; IgnoreList
: DWArray
= nil): DWArray
;
2624 if gTriggers
= nil then Exit
;
2626 case g_GetUIDType(UID
) of
2630 p
:= g_Player_Get(UID
);
2639 for a
:= 0 to High(gTriggers
) do
2640 if (gTriggers
[a
].TriggerType
<> TRIGGER_NONE
) and
2641 (gTriggers
[a
].TimeOut
= 0) and
2642 (not InDWArray(a
, IgnoreList
)) and
2643 ((gTriggers
[a
].Keys
and k
) = gTriggers
[a
].Keys
) and
2644 ByteBool(gTriggers
[a
].ActivateType
and ActivateType
) then
2645 if g_Collide(X
, Y
, Width
, Height
,
2646 gTriggers
[a
].X
, gTriggers
[a
].Y
,
2647 gTriggers
[a
].Width
, gTriggers
[a
].Height
) then
2649 gTriggers
[a
].ActivateUID
:= UID
;
2650 if ActivateTrigger(gTriggers
[a
], ActivateType
) then
2652 SetLength(Result
, Length(Result
)+1);
2653 Result
[High(Result
)] := a
;
2658 procedure g_Triggers_PressL(X1
, Y1
, X2
, Y2
: Integer; UID
: DWORD
; ActivateType
: Byte);
2664 if gTriggers
= nil then Exit
;
2666 case g_GetUIDType(UID
) of
2670 p
:= g_Player_Get(UID
);
2679 for a
:= 0 to High(gTriggers
) do
2680 if (gTriggers
[a
].TriggerType
<> TRIGGER_NONE
) and
2681 (gTriggers
[a
].TimeOut
= 0) and
2682 ((gTriggers
[a
].Keys
and k
) = gTriggers
[a
].Keys
) and
2683 ByteBool(gTriggers
[a
].ActivateType
and ActivateType
) then
2684 if g_CollideLine(x1
, y1
, x2
, y2
, gTriggers
[a
].X
, gTriggers
[a
].Y
,
2685 gTriggers
[a
].Width
, gTriggers
[a
].Height
) then
2687 gTriggers
[a
].ActivateUID
:= UID
;
2688 ActivateTrigger(gTriggers
[a
], ActivateType
);
2692 procedure g_Triggers_PressC(CX
, CY
: Integer; Radius
: Word; UID
: Word; ActivateType
: Byte; IgnoreTrigger
: Integer = -1);
2699 if gTriggers
= nil then
2702 case g_GetUIDType(UID
) of
2706 p
:= g_Player_Get(UID
);
2715 rsq
:= Radius
* Radius
;
2717 for a
:= 0 to High(gTriggers
) do
2718 if (gTriggers
[a
].ID
<> DWORD(IgnoreTrigger
)) and
2719 (gTriggers
[a
].TriggerType
<> TRIGGER_NONE
) and
2720 (gTriggers
[a
].TimeOut
= 0) and
2721 ((gTriggers
[a
].Keys
and k
) = gTriggers
[a
].Keys
) and
2722 ByteBool(gTriggers
[a
].ActivateType
and ActivateType
) then
2723 with gTriggers
[a
] do
2724 if g_Collide(CX
-Radius
, CY
-Radius
, 2*Radius
, 2*Radius
,
2725 X
, Y
, Width
, Height
) then
2726 if ((Sqr(CX
-X
)+Sqr(CY
-Y
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê âåðõíåìó ëåâîìó óãëó
2727 ((Sqr(CX
-X
-Width
)+Sqr(CY
-Y
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê âåðõíåìó ïðàâîìó óãëó
2728 ((Sqr(CX
-X
-Width
)+Sqr(CY
-Y
-Height
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê íèæíåìó ïðàâîìó óãëó
2729 ((Sqr(CX
-X
)+Sqr(CY
-Y
-Height
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê íèæíåìó ëåâîìó óãëó
2730 ( (CX
> (X
-Radius
)) and (CX
< (X
+Width
+Radius
)) and
2731 (CY
> Y
) and (CY
< (Y
+Height
)) ) or // Öåíòð êðóãà íåäàëåêî îò âåðòèêàëüíûõ ãðàíèö ïðÿìîóãîëüíèêà
2732 ( (CY
> (Y
-Radius
)) and (CY
< (Y
+Height
+Radius
)) and
2733 (CX
> X
) and (CX
< (X
+Width
)) ) then // Öåíòð êðóãà íåäàëåêî îò ãîðèçîíòàëüíûõ ãðàíèö ïðÿìîóãîëüíèêà
2736 ActivateTrigger(gTriggers
[a
], ActivateType
);
2740 procedure g_Triggers_OpenAll();
2745 if gTriggers
= nil then Exit
;
2748 for a
:= 0 to High(gTriggers
) do
2750 with gTriggers
[a
] do
2752 if (TriggerType
= TRIGGER_OPENDOOR
) or
2753 (TriggerType
= TRIGGER_DOOR5
) or
2754 (TriggerType
= TRIGGER_DOOR
) then
2756 tr_OpenDoor(trigPanelGUID
, True, trigData
.trigd2d_doors
);
2757 if TriggerType
= TRIGGER_DOOR5
then DoorTime
:= 180;
2763 if b
then g_Sound_PlayEx('SOUND_GAME_DOOROPEN');
2766 procedure g_Triggers_DecreaseSpawner(ID
: DWORD
);
2768 if (gTriggers
<> nil) then
2769 if gTriggers
[ID
].SpawnedCount
> 0 then
2770 Dec(gTriggers
[ID
].SpawnedCount
);
2773 procedure g_Triggers_Free();
2777 for a
:= 0 to High(gTriggers
) do
2779 if (gTriggers
[a
].TriggerType
= TRIGGER_SOUND
) then
2781 if g_Sound_Exists(gTriggers
[a
].trigData
.trigSoundName
) then
2783 g_Sound_Delete(gTriggers
[a
].trigData
.trigSoundName
);
2785 gTriggers
[a
].Sound
.Free();
2787 if (gTriggers
[a
].Activators
<> nil) then
2789 SetLength(gTriggers
[a
].Activators
, 0);
2791 gTriggers
[a
].trigData
.Free();
2796 SetLength(gMonstersSpawned
, 0);
2799 procedure g_Triggers_SaveState(var Mem
: TBinMemoryWriter
);
2801 count
, act_count
, i
, j
: Integer;
2806 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðèããåðîâ
2807 count
:= Length(gTriggers
);
2809 Mem
:= TBinMemoryWriter
.Create((count
+1) * 200);
2811 // Êîëè÷åñòâî òðèããåðîâ:
2812 Mem
.WriteInt(count
);
2814 //e_LogWritefln('saving %s triggers (count=%s)', [Length(gTriggers), count]);
2816 if count
= 0 then exit
;
2818 for i
:= 0 to High(gTriggers
) do
2820 // Ñèãíàòóðà òðèããåðà:
2821 dw
:= TRIGGER_SIGNATURE
; // 'TRGX'
2824 Mem
.WriteByte(gTriggers
[i
].TriggerType
);
2825 if (gTriggers
[i
].TriggerType
= TRIGGER_NONE
) then continue
; // empty one
2826 // Ñïåöèàëüíûå äàííûå òðèããåðà: äà â æîïó, ïîòîì èç êàðòû îïÿòü âûòàùèì; ñîõðàíèì òîëüêî èíäåêñ
2827 //e_LogWritefln('=== trigger #%s saved ===', [gTriggers[i].mapIndex]);
2828 Mem
.WriteInt(gTriggers
[i
].mapIndex
);
2829 //p := @gTriggers[i].Data;
2830 //Mem.WriteMemory(p, SizeOf(TTriggerData));
2831 // Êîîðäèíàòû ëåâîãî âåðõíåãî óãëà:
2832 Mem
.WriteInt(gTriggers
[i
].X
);
2833 Mem
.WriteInt(gTriggers
[i
].Y
);
2835 Mem
.WriteWord(gTriggers
[i
].Width
);
2836 Mem
.WriteWord(gTriggers
[i
].Height
);
2837 // Âêëþ÷åí ëè òðèããåð:
2838 Mem
.WriteBoolean(gTriggers
[i
].Enabled
);
2839 // Òèï àêòèâàöèè òðèããåðà:
2840 Mem
.WriteByte(gTriggers
[i
].ActivateType
);
2841 // Êëþ÷è, íåîáõîäèìûå äëÿ àêòèâàöèè:
2842 Mem
.WriteByte(gTriggers
[i
].Keys
);
2843 // ID ïàíåëè, òåêñòóðà êîòîðîé èçìåíèòñÿ:
2844 Mem
.WriteInt(gTriggers
[i
].TexturePanelGUID
);
2846 Mem
.WriteWord(gTriggers
[i
].TexturePanelType
);
2847 // Âíóòðåííèé íîìåð äðóãîé ïàíåëè (ïî ñ÷àñòëèâîé ñëó÷àéíîñòè îí áóäåò ñîâïàäàòü ñ òåì, ÷òî ñîçäàíî ïðè çàãðóçêå êàðòû)
2848 Mem
.WriteInt(gTriggers
[i
].trigPanelGUID
);
2849 // Âðåìÿ äî âîçìîæíîñòè àêòèâàöèè:
2850 Mem
.WriteWord(gTriggers
[i
].TimeOut
);
2851 // UID òîãî, êòî àêòèâèðîâàë ýòîò òðèããåð:
2852 Mem
.WriteWord(gTriggers
[i
].ActivateUID
);
2853 // Ñïèñîê UID-îâ îáúåêòîâ, êîòîðûå íàõîäèëèñü ïîä âîçäåéñòâèåì:
2854 act_count
:= Length(gTriggers
[i
].Activators
);
2855 Mem
.WriteInt(act_count
);
2856 for j
:= 0 to act_count
-1 do
2859 Mem
.WriteWord(gTriggers
[i
].Activators
[j
].UID
);
2861 Mem
.WriteWord(gTriggers
[i
].Activators
[j
].TimeOut
);
2863 // Ñòîèò ëè èãðîê â îáëàñòè òðèããåðà:
2864 Mem
.WriteBoolean(gTriggers
[i
].PlayerCollide
);
2865 // Âðåìÿ äî çàêðûòèÿ äâåðè:
2866 Mem
.WriteInt(gTriggers
[i
].DoorTime
);
2867 // Çàäåðæêà àêòèâàöèè:
2868 Mem
.WriteInt(gTriggers
[i
].PressTime
);
2870 Mem
.WriteInt(gTriggers
[i
].PressCount
);
2872 Mem
.WriteBoolean(gTriggers
[i
].AutoSpawn
);
2873 // Çàäåðæêà ñïàâíåðà:
2874 Mem
.WriteInt(gTriggers
[i
].SpawnCooldown
);
2875 // Ñ÷åò÷èê ñîçäàíèÿ îáúåêòîâ:
2876 Mem
.WriteInt(gTriggers
[i
].SpawnedCount
);
2877 // Ñêîëüêî ðàç ïðîèãðàí çâóê:
2878 Mem
.WriteInt(gTriggers
[i
].SoundPlayCount
);
2879 // Ïðîèãðûâàåòñÿ ëè çâóê?
2880 if gTriggers
[i
].Sound
<> nil then
2881 b
:= gTriggers
[i
].Sound
.IsPlaying()
2884 Mem
.WriteBoolean(b
);
2887 // Ïîçèöèÿ ïðîèãðûâàíèÿ çâóêà:
2888 dw
:= gTriggers
[i
].Sound
.GetPosition();
2891 sg
:= gTriggers
[i
].Sound
.GetVolume();
2892 sg
:= sg
/ (gSoundLevel
/255.0);
2893 Mem
.WriteSingle(sg
);
2894 // Ñòåðåî ñìåùåíèå çâóêà:
2895 sg
:= gTriggers
[i
].Sound
.GetPan();
2896 Mem
.WriteSingle(sg
);
2901 procedure g_Triggers_LoadState(var Mem
: TBinMemoryReader
);
2903 count
, act_count
, i
, j
, a
: Integer;
2910 //tw: TStrTextWriter;
2917 // Êîëè÷åñòâî òðèããåðîâ:
2920 if (count
= 0) then exit
;
2922 for a
:= 0 to count
-1 do
2924 // Ñèãíàòóðà òðèããåðà:
2926 if (dw
<> TRIGGER_SIGNATURE
) then // 'TRGX'
2928 raise EBinSizeError
.Create('g_Triggers_LoadState: Wrong Trigger Signature');
2931 Mem
.ReadByte(Trig
.TriggerType
);
2932 // Ñïåöèàëüíûå äàííûå òðèããåðà: èíäåêñ â gCurrentMap.field['triggers']
2933 if (Trig
.TriggerType
= TRIGGER_NONE
) then continue
; // empty one
2934 Mem
.ReadInt(mapIndex
);
2937 Mem.ReadMemory(p, dw);
2938 if dw <> SizeOf(TTriggerData) then
2940 raise EBinSizeError.Create('g_Triggers_LoadState: Wrong TriggerData Size');
2942 Trig.Data := TTriggerData(p^);
2945 i
:= g_Triggers_CreateWithMapIndex(Trig
, a
, mapIndex
);
2947 if (gTriggers[i].trigData <> nil) then
2949 tw := TStrTextWriter.Create();
2951 gTriggers[i].trigData.writeTo(tw);
2952 e_LogWritefln('=== trigger #%s loaded ==='#10'%s'#10'---', [mapIndex, tw.str]);
2958 // Êîîðäèíàòû ëåâîãî âåðõíåãî óãëà:
2959 Mem
.ReadInt(gTriggers
[i
].X
);
2960 Mem
.ReadInt(gTriggers
[i
].Y
);
2962 Mem
.ReadWord(gTriggers
[i
].Width
);
2963 Mem
.ReadWord(gTriggers
[i
].Height
);
2964 // Âêëþ÷åí ëè òðèããåð:
2965 Mem
.ReadBoolean(gTriggers
[i
].Enabled
);
2966 // Òèï àêòèâàöèè òðèããåðà:
2967 Mem
.ReadByte(gTriggers
[i
].ActivateType
);
2968 // Êëþ÷è, íåîáõîäèìûå äëÿ àêòèâàöèè:
2969 Mem
.ReadByte(gTriggers
[i
].Keys
);
2970 // ID ïàíåëè, òåêñòóðà êîòîðîé èçìåíèòñÿ:
2971 Mem
.ReadInt(gTriggers
[i
].TexturePanelGUID
);
2973 Mem
.ReadWord(gTriggers
[i
].TexturePanelType
);
2974 // Âíóòðåííèé íîìåð äðóãîé ïàíåëè (ïî ñ÷àñòëèâîé ñëó÷àéíîñòè îí áóäåò ñîâïàäàòü ñ òåì, ÷òî ñîçäàíî ïðè çàãðóçêå êàðòû)
2975 Mem
.ReadInt(gTriggers
[i
].trigPanelGUID
);
2976 // Âðåìÿ äî âîçìîæíîñòè àêòèâàöèè:
2977 Mem
.ReadWord(gTriggers
[i
].TimeOut
);
2978 // UID òîãî, êòî àêòèâèðîâàë ýòîò òðèããåð:
2979 Mem
.ReadWord(gTriggers
[i
].ActivateUID
);
2980 // Ñïèñîê UID-îâ îáúåêòîâ, êîòîðûå íàõîäèëèñü ïîä âîçäåéñòâèåì:
2981 Mem
.ReadInt(act_count
);
2982 if act_count
> 0 then
2984 SetLength(gTriggers
[i
].Activators
, act_count
);
2985 for j
:= 0 to act_count
-1 do
2988 Mem
.ReadWord(gTriggers
[i
].Activators
[j
].UID
);
2990 Mem
.ReadWord(gTriggers
[i
].Activators
[j
].TimeOut
);
2993 // Ñòîèò ëè èãðîê â îáëàñòè òðèããåðà:
2994 Mem
.ReadBoolean(gTriggers
[i
].PlayerCollide
);
2995 // Âðåìÿ äî çàêðûòèÿ äâåðè:
2996 Mem
.ReadInt(gTriggers
[i
].DoorTime
);
2997 // Çàäåðæêà àêòèâàöèè:
2998 Mem
.ReadInt(gTriggers
[i
].PressTime
);
3000 Mem
.ReadInt(gTriggers
[i
].PressCount
);
3002 Mem
.ReadBoolean(gTriggers
[i
].AutoSpawn
);
3003 // Çàäåðæêà ñïàâíåðà:
3004 Mem
.ReadInt(gTriggers
[i
].SpawnCooldown
);
3005 // Ñ÷åò÷èê ñîçäàíèÿ îáúåêòîâ:
3006 Mem
.ReadInt(gTriggers
[i
].SpawnedCount
);
3007 // Ñêîëüêî ðàç ïðîèãðàí çâóê:
3008 Mem
.ReadInt(gTriggers
[i
].SoundPlayCount
);
3009 // Ïðîèãðûâàåòñÿ ëè çâóê?
3013 // Ïîçèöèÿ ïðîèãðûâàíèÿ çâóêà:
3016 Mem
.ReadSingle(vol
);
3017 // Ñòåðåî ñìåùåíèå çâóêà:
3018 Mem
.ReadSingle(pan
);
3019 // Çàïóñêàåì çâóê, åñëè åñòü:
3020 if gTriggers
[i
].Sound
<> nil then
3022 gTriggers
[i
].Sound
.PlayPanVolume(pan
, vol
);
3023 gTriggers
[i
].Sound
.Pause(True);
3024 gTriggers
[i
].Sound
.SetPosition(dw
);