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
);
92 function tr_Message(MKind
: Integer; MText
: string; MSendTo
: Integer; MTime
: Integer; ActivateUID
: Integer): Boolean;
95 function tr_CloseDoor (PanelGUID: Integer; NoSound: Boolean; d2d: Boolean): Boolean;
96 function tr_OpenDoor (PanelGUID: Integer; NoSound: Boolean; d2d: Boolean): Boolean;
97 procedure tr_CloseTrap (PanelGUID: Integer; NoSound: Boolean; d2d: Boolean);
98 function tr_SetLift (PanelGUID: Integer; d: Integer; NoSound: Boolean; d2d: Boolean): Boolean;
100 function tr_Teleport (ActivateUID: Integer; TX, TY: Integer; TDir: Integer; Silent: Boolean; D2D: Boolean): Boolean;
101 function tr_Push (ActivateUID: Integer; VX, VY: Integer; ResetVel: Boolean): Boolean;
103 procedure tr_MakeEffect (X, Y, VX, VY: Integer; T, ST, CR, CG, CB: Byte; Silent, Send: Boolean);
104 function tr_SpawnShot (ShotType: Integer; wx, wy, dx, dy: Integer; ShotSound: Boolean; ShotTarget: Word): Integer;
108 gTriggerClientID
: Integer = 0;
109 gTriggers
: array of TTrigger
;
110 gSecretsCount
: Integer = 0;
111 gMonstersSpawned
: array of LongInt = nil;
117 g_player
, g_map
, g_panel
, g_gfx
, g_game
, g_textures
,
118 g_console
, g_monsters
, g_items
, g_phys
, g_weapons
,
119 wadreader
, g_main
, SysUtils
, e_log
, g_language
,
120 g_options
, g_net
, g_netmsg
, utils
, xparser
;
123 TRIGGER_SIGNATURE
= $58475254; // 'TRGX'
127 function TTrigger
.trigCenter (): TDFPoint
; inline;
129 result
:= TDFPoint
.Create(x
+width
div 2, y
+height
div 2);
133 function FindTrigger (): DWORD
;
137 for i
:= 0 to High(gTriggers
) do
139 if gTriggers
[i
].TriggerType
= TRIGGER_NONE
then begin result
:= i
; exit
; end;
142 if (gTriggers
= nil) then
144 SetLength(gTriggers
, 8);
149 result
:= Length(gTriggers
);
150 SetLength(gTriggers
, result
+8);
151 for i
:= result
to High(gTriggers
) do gTriggers
[i
].TriggerType
:= TRIGGER_NONE
;
156 function tr_CloseDoor (PanelGUID
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
163 pan
:= g_Map_PanelByGUID(PanelGUID
);
164 if (pan
= nil) or not pan
.isGWall
then exit
; //!FIXME!TRIGANY!
165 PanelID
:= pan
.arrIdx
;
169 with gWalls
[PanelID
] do
171 if g_CollidePlayer(X
, Y
, Width
, Height
) or g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then Exit
;
176 g_Sound_PlayExAt('SOUND_GAME_DOORCLOSE', X
, Y
);
177 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOORCLOSE');
179 g_Map_EnableWallGUID(PanelGUID
);
186 if (gDoorMap
= nil) then exit
;
189 for a
:= 0 to High(gDoorMap
) do
191 for b
:= 0 to High(gDoorMap
[a
]) do
193 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
199 if (c
<> -1) then break
;
201 if (c
= -1) then exit
;
203 for b
:= 0 to High(gDoorMap
[c
]) do
205 with gWalls
[gDoorMap
[c
, b
]] do
207 if g_CollidePlayer(X
, Y
, Width
, Height
) or g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then exit
;
213 for b
:= 0 to High(gDoorMap
[c
]) do
215 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
217 with gWalls
[PanelID
] do
219 g_Sound_PlayExAt('SOUND_GAME_DOORCLOSE', X
, Y
);
220 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOORCLOSE');
227 for b
:= 0 to High(gDoorMap
[c
]) do
229 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
231 g_Map_EnableWall_XXX(gDoorMap
[c
, b
]);
239 procedure tr_CloseTrap (PanelGUID
: Integer; NoSound
: Boolean; d2d
: Boolean);
242 wx
, wy
, wh
, ww
: Integer;
246 function monsDamage (mon
: TMonster
): Boolean;
248 result
:= false; // don't stop
249 if g_Obj_Collide(wx
, wy
, ww
, wh
, @mon
.Obj
) then mon
.Damage(TRAP_DAMAGE
, 0, 0, 0, HIT_TRAP
);
253 pan
:= g_Map_PanelByGUID(PanelGUID
);
254 if (pan
= nil) or not pan
.isGWall
then exit
; //!FIXME!TRIGANY!
255 PanelID
:= pan
.arrIdx
;
259 with gWalls
[PanelID
] do
261 if (not NoSound
) and (not Enabled
) then
263 g_Sound_PlayExAt('SOUND_GAME_SWITCH1', X
, Y
);
264 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_SWITCH1');
268 wx
:= gWalls
[PanelID
].X
;
269 wy
:= gWalls
[PanelID
].Y
;
270 ww
:= gWalls
[PanelID
].Width
;
271 wh
:= gWalls
[PanelID
].Height
;
273 with gWalls
[PanelID
] do
275 if gPlayers
<> nil then
277 for a
:= 0 to High(gPlayers
) do
279 if (gPlayers
[a
] <> nil) and gPlayers
[a
].Live
and gPlayers
[a
].Collide(X
, Y
, Width
, Height
) then
281 gPlayers
[a
].Damage(TRAP_DAMAGE
, 0, 0, 0, HIT_TRAP
);
286 //g_Mons_ForEach(monsDamage);
287 g_Mons_ForEachAliveAt(wx
, wy
, ww
, wh
, monsDamage
);
289 if not Enabled
then g_Map_EnableWallGUID(PanelGUID
);
294 if (gDoorMap
= nil) then exit
;
297 for a
:= 0 to High(gDoorMap
) do
299 for b
:= 0 to High(gDoorMap
[a
]) do
301 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
307 if (c
<> -1) then break
;
309 if (c
= -1) then exit
;
313 for b
:= 0 to High(gDoorMap
[c
]) do
315 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
317 with gWalls
[PanelID
] do
319 g_Sound_PlayExAt('SOUND_GAME_SWITCH1', X
, Y
);
320 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_SWITCH1');
327 for b
:= 0 to High(gDoorMap
[c
]) do
329 wx
:= gWalls
[gDoorMap
[c
, b
]].X
;
330 wy
:= gWalls
[gDoorMap
[c
, b
]].Y
;
331 ww
:= gWalls
[gDoorMap
[c
, b
]].Width
;
332 wh
:= gWalls
[gDoorMap
[c
, b
]].Height
;
334 with gWalls
[gDoorMap
[c
, b
]] do
336 if gPlayers
<> nil then
338 for a
:= 0 to High(gPlayers
) do
340 if (gPlayers
[a
] <> nil) and gPlayers
[a
].Live
and gPlayers
[a
].Collide(X
, Y
, Width
, Height
) then
342 gPlayers
[a
].Damage(TRAP_DAMAGE
, 0, 0, 0, HIT_TRAP
);
347 //g_Mons_ForEach(monsDamage);
348 g_Mons_ForEachAliveAt(wx
, wy
, ww
, wh
, monsDamage
);
350 if gMonsters <> nil then
351 for a := 0 to High(gMonsters) do
352 if (gMonsters[a] <> nil) and gMonsters[a].Live and
353 g_Obj_Collide(X, Y, Width, Height, @gMonsters[a].Obj) then
354 gMonsters[a].Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
357 if not Enabled
then g_Map_EnableWall_XXX(gDoorMap
[c
, b
]);
364 function tr_OpenDoor (PanelGUID
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
371 pan
:= g_Map_PanelByGUID(PanelGUID
);
372 if (pan
= nil) or not pan
.isGWall
then exit
; //!FIXME!TRIGANY!
373 PanelID
:= pan
.arrIdx
;
377 with gWalls
[PanelID
] do
383 g_Sound_PlayExAt('SOUND_GAME_DOOROPEN', X
, Y
);
384 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOOROPEN');
386 g_Map_DisableWallGUID(PanelGUID
);
393 if (gDoorMap
= nil) then exit
;
396 for a
:= 0 to High(gDoorMap
) do
398 for b
:= 0 to High(gDoorMap
[a
]) do
400 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
406 if (c
<> -1) then break
;
408 if (c
= -1) then exit
;
412 for b
:= 0 to High(gDoorMap
[c
]) do
414 if gWalls
[gDoorMap
[c
, b
]].Enabled
then
416 with gWalls
[PanelID
] do
418 g_Sound_PlayExAt('SOUND_GAME_DOOROPEN', X
, Y
);
419 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOOROPEN');
426 for b
:= 0 to High(gDoorMap
[c
]) do
428 if gWalls
[gDoorMap
[c
, b
]].Enabled
then
430 g_Map_DisableWall_XXX(gDoorMap
[c
, b
]);
438 function tr_SetLift (PanelGUID
: Integer; d
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
446 pan
:= g_Map_PanelByGUID(PanelGUID
);
447 if (pan
= nil) or not pan
.isGLift
then exit
; //!FIXME!TRIGANY!
448 PanelID
:= pan
.arrIdx
;
450 if (gLifts
[PanelID
].PanelType
= PANEL_LIFTUP
) or (gLifts
[PanelID
].PanelType
= PANEL_LIFTDOWN
) then
455 else t
:= IfThen(gLifts
[PanelID
].LiftType
= 1, 0, 1);
458 else if (gLifts
[PanelID
].PanelType
= PANEL_LIFTLEFT
) or (gLifts
[PanelID
].PanelType
= PANEL_LIFTRIGHT
) then
463 else t
:= IfThen(gLifts
[PanelID
].LiftType
= 2, 3, 2);
469 with gLifts
[PanelID
] do
471 if (LiftType
<> t
) then
473 g_Map_SetLiftGUID(PanelGUID
, t
); //???
474 //if not NoSound then g_Sound_PlayExAt('SOUND_GAME_SWITCH0', X, Y);
481 if (gLiftMap
= nil) then exit
;
484 for a
:= 0 to High(gLiftMap
) do
486 for b
:= 0 to High(gLiftMap
[a
]) do
488 if (gLiftMap
[a
, b
] = DWORD(PanelID
)) then
494 if (c
<> -1) then break
;
496 if (c
= -1) then exit
;
499 for b := 0 to High(gLiftMap[c]) do
500 if gLifts[gLiftMap[c, b]].LiftType <> t then
502 with gLifts[PanelID] do
503 g_Sound_PlayExAt('SOUND_GAME_SWITCH0', X, Y);
507 for b
:= 0 to High(gLiftMap
[c
]) do
509 with gLifts
[gLiftMap
[c
, b
]] do
511 if (LiftType
<> t
) then
513 g_Map_SetLift_XXX(gLiftMap
[c
, b
], t
);
522 function tr_SpawnShot (ShotType
: Integer; wx
, wy
, dx
, dy
: Integer; ShotSound
: Boolean; ShotTarget
: Word): Integer;
530 TextureID
:= DWORD(-1);
531 snd
:= 'SOUND_WEAPON_FIREROCKET';
537 g_Weapon_pistol(wx
, wy
, dx
, dy
, 0, True);
538 snd
:= 'SOUND_WEAPON_FIREPISTOL';
542 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_BULLET
);
543 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL1
);
549 g_Weapon_mgun(wx
, wy
, dx
, dy
, 0, True);
550 if gSoundEffectsDF
then snd
:= 'SOUND_WEAPON_FIRECGUN'
551 else snd
:= 'SOUND_WEAPON_FIREPISTOL';
555 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_BULLET
);
556 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL1
);
560 TRIGGER_SHOT_SHOTGUN
:
562 g_Weapon_Shotgun(wx
, wy
, dx
, dy
, 0, True);
563 snd
:= 'SOUND_WEAPON_FIRESHOTGUN';
567 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
568 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL2
);
574 g_Weapon_DShotgun(wx
, wy
, dx
, dy
, 0, True);
575 snd
:= 'SOUND_WEAPON_FIRESHOTGUN2';
579 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
580 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
581 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL3
);
587 g_Weapon_ball1(wx
, wy
, dx
, dy
, 0, -1, True);
588 snd
:= 'SOUND_WEAPON_FIREBALL';
593 g_Weapon_Plasma(wx
, wy
, dx
, dy
, 0, -1, True);
594 snd
:= 'SOUND_WEAPON_FIREPLASMA';
599 g_Weapon_aplasma(wx
, wy
, dx
, dy
, 0, -1, True);
600 snd
:= 'SOUND_WEAPON_FIREPLASMA';
605 g_Weapon_ball2(wx
, wy
, dx
, dy
, 0, -1, True);
606 snd
:= 'SOUND_WEAPON_FIREBALL';
611 g_Weapon_ball7(wx
, wy
, dx
, dy
, 0, -1, True);
612 snd
:= 'SOUND_WEAPON_FIREBALL';
617 g_Weapon_manfire(wx
, wy
, dx
, dy
, 0, -1, True);
618 snd
:= 'SOUND_WEAPON_FIREBALL';
623 g_Weapon_revf(wx
, wy
, dx
, dy
, 0, ShotTarget
, -1, True);
624 snd
:= 'SOUND_WEAPON_FIREREV';
629 g_Weapon_Rocket(wx
, wy
, dx
, dy
, 0, -1, True);
630 snd
:= 'SOUND_WEAPON_FIREROCKET';
635 g_Weapon_BFGShot(wx
, wy
, dx
, dy
, 0, -1, True);
636 snd
:= 'SOUND_WEAPON_FIREBFG';
641 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_ROCKET') then
643 Anim
:= TAnimation
.Create(TextureID
, False, 6);
644 Anim
.Blending
:= False;
645 g_GFX_OnceAnim(wx
-64, wy
-64, Anim
);
649 g_Weapon_Explode(wx
, wy
, 60, 0);
650 snd
:= 'SOUND_WEAPON_EXPLODEROCKET';
653 TRIGGER_SHOT_BFGEXPL
:
655 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_BFG') then
657 Anim
:= TAnimation
.Create(TextureID
, False, 6);
658 Anim
.Blending
:= False;
659 g_GFX_OnceAnim(wx
-64, wy
-64, Anim
);
663 g_Weapon_BFG9000(wx
, wy
, 0);
664 snd
:= 'SOUND_WEAPON_EXPLODEBFG';
670 if g_Game_IsNet
and g_Game_IsServer
then
673 TRIGGER_SHOT_EXPL
: MH_SEND_Effect(wx
, wy
, Byte(ShotSound
), NET_GFX_EXPLODE
);
674 TRIGGER_SHOT_BFGEXPL
: MH_SEND_Effect(wx
, wy
, Byte(ShotSound
), NET_GFX_BFGEXPL
);
677 if Projectile
then MH_SEND_CreateShot(LastShotID
);
678 if ShotSound
then MH_SEND_Sound(wx
, wy
, snd
);
683 if ShotSound
then g_Sound_PlayExAt(snd
, wx
, wy
);
685 if Projectile
then Result
:= LastShotID
;
689 procedure MakeShot (var Trigger
: TTrigger
; wx
, wy
, dx
, dy
: Integer; TargetUID
: Word);
693 if (trigData
.trigShotAmmo
= 0) or ((trigData
.trigShotAmmo
> 0) and (ShotAmmoCount
> 0)) then
695 if (trigShotPanelGUID
<> -1) and (ShotPanelTime
= 0) then
697 g_Map_SwitchTextureGUID(ShotPanelType
, trigShotPanelGUID
);
698 ShotPanelTime
:= 4; // òèêîâ íà âñïûøêó âûñòðåëà
701 if (trigData
.trigShotIntSight
> 0) then ShotSightTimeout
:= 180; // ~= 5 ñåêóíä
703 if (ShotAmmoCount
> 0) then Dec(ShotAmmoCount
);
705 dx
+= Random(trigData
.trigShotAccuracy
)-Random(trigData
.trigShotAccuracy
);
706 dy
+= Random(trigData
.trigShotAccuracy
)-Random(trigData
.trigShotAccuracy
);
708 tr_SpawnShot(trigData
.trigShotType
, wx
, wy
, dx
, dy
, trigData
.trigShotSound
, TargetUID
);
712 if (trigData
.trigShotIntReload
> 0) and (ShotReloadTime
= 0) then
714 ShotReloadTime
:= trigData
.trigShotIntReload
; // òèêîâ íà ïåðåçàðÿäêó ïóøêè
721 procedure tr_MakeEffect (X
, Y
, VX
, VY
: Integer; T
, ST
, CR
, CG
, CB
: Byte; Silent
, Send
: Boolean);
726 if T
= TRIGGER_EFFECT_PARTICLE
then
729 TRIGGER_EFFECT_SLIQUID
:
731 if (CR
= 255) and (CG
= 0) and (CB
= 0) then g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 1, 0, 0, 0)
732 else if (CR
= 0) and (CG
= 255) and (CB
= 0) then g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 2, 0, 0, 0)
733 else if (CR
= 0) and (CG
= 0) and (CB
= 255) then g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 3, 0, 0, 0)
734 else g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 0, 0, 0, 0);
736 TRIGGER_EFFECT_LLIQUID
: g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 4, CR
, CG
, CB
);
737 TRIGGER_EFFECT_DLIQUID
: g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 5, CR
, CG
, CB
);
738 TRIGGER_EFFECT_BLOOD
: g_GFX_Blood(X
, Y
, 1, VX
, VY
, 0, 0, CR
, CG
, CB
);
739 TRIGGER_EFFECT_SPARK
: g_GFX_Spark(X
, Y
, 1, GetAngle2(VX
, VY
), 0, 0);
740 TRIGGER_EFFECT_BUBBLE
: g_GFX_Bubbles(X
, Y
, 1, 0, 0);
744 if T
= TRIGGER_EFFECT_ANIMATION
then
747 EFFECT_TELEPORT
: begin
748 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
750 Anim
:= TAnimation
.Create(FramesID
, False, 3);
751 if not Silent
then g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
752 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
755 if Send
and g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(X
, Y
, Byte(not Silent
), NET_GFX_TELE
);
757 EFFECT_RESPAWN
: begin
758 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
760 Anim
:= TAnimation
.Create(FramesID
, False, 4);
761 if not Silent
then g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
762 g_GFX_OnceAnim(X
-16, Y
-16, Anim
);
765 if Send
and g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(X
-16, Y
-16, Byte(not Silent
), NET_GFX_RESPAWN
);
768 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
770 Anim
:= TAnimation
.Create(FramesID
, False, 4);
771 if not Silent
then g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
772 g_GFX_OnceAnim(X
-32, Y
-128, Anim
);
775 if Send
and g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(X
-32, Y
-128, Byte(not Silent
), NET_GFX_FIRE
);
782 function tr_Teleport (ActivateUID
: Integer; TX
, TY
: Integer; TDir
: Integer; Silent
: Boolean; D2D
: Boolean): Boolean;
788 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then Exit
;
789 case g_GetUIDType(ActivateUID
) of
792 p
:= g_Player_Get(ActivateUID
);
793 if p
= nil then Exit
;
796 if p
.TeleportTo(TX
-(p
.Obj
.Rect
.Width
div 2), TY
-p
.Obj
.Rect
.Height
, Silent
, TDir
) then result
:= true;
800 if p
.TeleportTo(TX
, TY
, Silent
, TDir
) then result
:= true;
805 m
:= g_Monsters_ByUID(ActivateUID
);
806 if m
= nil then Exit
;
809 if m
.TeleportTo(TX
-(m
.Obj
.Rect
.Width
div 2), TY
-m
.Obj
.Rect
.Height
, Silent
, TDir
) then result
:= true;
813 if m
.TeleportTo(TX
, TY
, Silent
, TDir
) then result
:= true;
820 function tr_Push (ActivateUID
: Integer; VX
, VY
: Integer; ResetVel
: Boolean): Boolean;
826 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then exit
;
827 case g_GetUIDType(ActivateUID
) of
830 p
:= g_Player_Get(ActivateUID
);
831 if p
= nil then Exit
;
846 m
:= g_Monsters_ByUID(ActivateUID
);
847 if m
= nil then Exit
;
863 function tr_Message (MKind
: Integer; MText
: string; MSendTo
: Integer; MTime
: Integer; ActivateUID
: Integer): Boolean;
870 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then Exit
;
871 msg
:= b_Text_Format(MText
);
875 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
877 if g_Game_IsWatchedPlayer(ActivateUID
) then
879 if MKind
= 0 then g_Console_Add(msg
, True)
880 else if MKind
= 1 then g_Game_Message(msg
, MTime
);
884 p
:= g_Player_Get(ActivateUID
);
885 if g_Game_IsNet
and (p
.FClientID
>= 0) then
887 if MKind
= 0 then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, p
.FClientID
)
888 else if MKind
= 1 then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, p
.FClientID
);
894 1: // activator's team
896 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
898 p
:= g_Player_Get(ActivateUID
);
899 if g_Game_IsWatchedTeam(p
.Team
) then
901 if MKind
= 0 then g_Console_Add(msg
, True)
902 else if MKind
= 1 then g_Game_Message(msg
, MTime
);
907 for i
:= Low(gPlayers
) to High(gPlayers
) do
909 if (gPlayers
[i
].Team
= p
.Team
) and (gPlayers
[i
].FClientID
>= 0) then
911 if MKind
= 0 then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
912 else if MKind
= 1 then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
919 2: // activator's enemy team
921 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
923 p
:= g_Player_Get(ActivateUID
);
924 if g_Game_IsWatchedTeam(p
.Team
) then
926 if MKind
= 0 then g_Console_Add(msg
, True)
927 else if MKind
= 1 then g_Game_Message(msg
, MTime
);
932 for i
:= Low(gPlayers
) to High(gPlayers
) do
934 if (gPlayers
[i
].Team
<> p
.Team
) and (gPlayers
[i
].FClientID
>= 0) then
936 if MKind
= 0 then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
937 else if MKind
= 1 then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
946 if g_Game_IsWatchedTeam(TEAM_RED
) then
948 if MKind
= 0 then g_Console_Add(msg
, True)
949 else if MKind
= 1 then g_Game_Message(msg
, MTime
);
954 for i
:= Low(gPlayers
) to High(gPlayers
) do
956 if (gPlayers
[i
].Team
= TEAM_RED
) and (gPlayers
[i
].FClientID
>= 0) then
958 if MKind
= 0 then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
959 else if MKind
= 1 then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
967 if g_Game_IsWatchedTeam(TEAM_BLUE
) then
969 if MKind
= 0 then g_Console_Add(msg
, True)
970 else if MKind
= 1 then g_Game_Message(msg
, MTime
);
975 for i
:= Low(gPlayers
) to High(gPlayers
) do
977 if (gPlayers
[i
].Team
= TEAM_BLUE
) and (gPlayers
[i
].FClientID
>= 0) then
979 if MKind
= 0 then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
980 else if MKind
= 1 then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
988 if MKind
= 0 then g_Console_Add(msg
, True)
989 else if MKind
= 1 then g_Game_Message(msg
, MTime
);
993 if MKind
= 0 then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
)
994 else if MKind
= 1 then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
);
1001 function tr_ShotAimCheck (var Trigger
: TTrigger
; Obj
: PObj
): Boolean;
1006 if TriggerType
<> TRIGGER_SHOT
then Exit
;
1007 result
:= (trigData
.trigShotAim
and TRIGGER_SHOT_AIM_ALLMAP
> 0)
1008 or g_Obj_Collide(X
, Y
, Width
, Height
, Obj
);
1009 if result
and (trigData
.trigShotAim
and TRIGGER_SHOT_AIM_TRACE
> 0) then
1011 result
:= g_TraceVector(trigData
.trigShotPos
.X
, trigData
.trigShotPos
.Y
,
1012 Obj
^.X
+ Obj
^.Rect
.X
+ (Obj
^.Rect
.Width
div 2),
1013 Obj
^.Y
+ Obj
^.Rect
.Y
+ (Obj
^.Rect
.Height
div 2));
1019 function ActivateTrigger (var Trigger
: TTrigger
; actType
: Byte): Boolean;
1025 idx
, k
, wx
, wy
, xd
, yd
: Integer;
1036 function monsShotTarget (mon
: TMonster
): Boolean;
1038 result
:= false; // don't stop
1039 if mon
.Live
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
1041 xd
:= mon
.GameX
+ mon
.Obj
.Rect
.Width
div 2;
1042 yd
:= mon
.GameY
+ mon
.Obj
.Rect
.Height
div 2;
1043 TargetUID
:= mon
.UID
;
1044 result
:= true; // stop
1048 function monsShotTargetMonPlr (mon
: TMonster
): Boolean;
1050 result
:= false; // don't stop
1051 if mon
.Live
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
1053 xd
:= mon
.GameX
+ mon
.Obj
.Rect
.Width
div 2;
1054 yd
:= mon
.GameY
+ mon
.Obj
.Rect
.Height
div 2;
1055 TargetUID
:= mon
.UID
;
1056 result
:= true; // stop
1060 function monShotTargetPlrMon (mon
: TMonster
): Boolean;
1062 result
:= false; // don't stop
1063 if mon
.Live
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
1065 xd
:= mon
.GameX
+ mon
.Obj
.Rect
.Width
div 2;
1066 yd
:= mon
.GameY
+ mon
.Obj
.Rect
.Height
div 2;
1067 TargetUID
:= mon
.UID
;
1068 result
:= true; // stop
1074 if g_Game_IsClient
then exit
;
1076 if not Trigger
.Enabled
then exit
;
1077 if (Trigger
.TimeOut
<> 0) and (actType
<> ACTIVATE_CUSTOM
) then exit
;
1078 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then exit
;
1082 coolDown
:= (actType
<> 0);
1089 g_Sound_PlayEx('SOUND_GAME_SWITCH0');
1090 if g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_SWITCH0');
1091 gExitByTrigger
:= True;
1092 g_Game_ExitLevel(trigData
.trigMapName
);
1101 Result
:= tr_Teleport(ActivateUID
,
1102 trigData
.trigTargetPoint
.X
, trigData
.trigTargetPoint
.Y
,
1103 trigData
.trigTlpDir
, trigData
.trigsilent_teleport
,
1104 trigData
.trigd2d_teleport
);
1110 Result
:= tr_OpenDoor(trigPanelGUID
, trigData
.trigNoSound
, trigData
.trigd2d_doors
);
1116 Result
:= tr_CloseDoor(trigPanelGUID
, trigData
.trigNoSound
, trigData
.trigd2d_doors
);
1120 TRIGGER_DOOR
, TRIGGER_DOOR5
:
1122 pan
:= g_Map_PanelByGUID(trigPanelGUID
);
1123 if (pan
<> nil) and pan
.isGWall
then
1125 if gWalls
[{trigPanelID}pan
.arrIdx
].Enabled
then
1127 result
:= tr_OpenDoor(trigPanelGUID
, trigData
.trigNoSound
, trigData
.trigd2d_doors
);
1128 if (TriggerType
= TRIGGER_DOOR5
) then DoorTime
:= 180;
1132 result
:= tr_CloseDoor(trigPanelGUID
, trigData
.trigNoSound
, trigData
.trigd2d_doors
);
1135 if result
then TimeOut
:= 18;
1139 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
:
1141 tr_CloseTrap(trigPanelGUID
, trigData
.trigNoSound
, trigData
.trigd2d_doors
);
1143 if TriggerType
= TRIGGER_TRAP
then
1157 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
:
1160 if PressTime
= -1 then PressTime
:= trigData
.trigWait
;
1161 if coolDown
then TimeOut
:= 18 else TimeOut
:= 0;
1166 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
1170 if gLMSRespawn
= LMS_RESPAWN_NONE
then
1172 g_Player_Get(ActivateUID
).GetSecret();
1173 Inc(gCoopSecretsFound
);
1174 if g_Game_IsNet
then MH_SEND_GameStats();
1180 Result
:= tr_SetLift(trigPanelGUID
, 0, trigData
.trigNoSound
, trigData
.trigd2d_doors
);
1183 if (not trigData
.trigNoSound
) and Result
then begin
1184 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1186 Y
+ (Height
div 2));
1187 if g_Game_IsServer
and g_Game_IsNet
then
1188 MH_SEND_Sound(X
+ (Width
div 2),
1190 'SOUND_GAME_SWITCH0');
1196 Result
:= tr_SetLift(trigPanelGUID
, 1, trigData
.trigNoSound
, trigData
.trigd2d_doors
);
1199 if (not trigData
.trigNoSound
) and Result
then begin
1200 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1202 Y
+ (Height
div 2));
1203 if g_Game_IsServer
and g_Game_IsNet
then
1204 MH_SEND_Sound(X
+ (Width
div 2),
1206 'SOUND_GAME_SWITCH0');
1212 Result
:= tr_SetLift(trigPanelGUID
, 3, trigData
.trigNoSound
, trigData
.trigd2d_doors
);
1218 if (not trigData
.trigNoSound
) and Result
then begin
1219 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1221 Y
+ (Height
div 2));
1222 if g_Game_IsServer
and g_Game_IsNet
then
1223 MH_SEND_Sound(X
+ (Width
div 2),
1225 'SOUND_GAME_SWITCH0');
1232 if trigData
.trigActivateOnce
then
1235 TriggerType
:= TRIGGER_NONE
;
1243 animonce
:= trigData
.trigAnimOnce
;
1249 if Sound
<> nil then
1251 if trigData
.trigSoundSwitch
and Sound
.IsPlaying() then
1252 begin // Íóæíî âûêëþ÷èòü, åñëè èãðàë
1254 SoundPlayCount
:= 0;
1257 else // (not Data.SoundSwitch) or (not Sound.IsPlaying())
1258 if (trigData
.trigPlayCount
> 0) or (not Sound
.IsPlaying()) then
1260 if trigData
.trigPlayCount
> 0 then
1261 SoundPlayCount
:= trigData
.trigPlayCount
1262 else // 0 - èãðàåì áåñêîíå÷íî
1263 SoundPlayCount
:= 1;
1266 if g_Game_IsNet
then MH_SEND_TriggerSound(Trigger
);
1270 TRIGGER_SPAWNMONSTER
:
1271 if (trigData
.trigMonType
in [MONSTER_DEMON
..MONSTER_MAN
]) then
1274 if (trigData
.trigMonDelay
> 0) and (actType
<> ACTIVATE_CUSTOM
) then
1276 AutoSpawn
:= not AutoSpawn
;
1278 // Àâòîñïàâíåð ïåðåêëþ÷åí - ìåíÿåì òåêñòóðó
1282 if ((trigData
.trigMonDelay
= 0) and (actType
<> ACTIVATE_CUSTOM
))
1283 or ((trigData
.trigMonDelay
> 0) and (actType
= ACTIVATE_CUSTOM
)) then
1284 for k
:= 1 to trigData
.trigMonCount
do
1286 if (actType
= ACTIVATE_CUSTOM
) and (trigData
.trigMonDelay
> 0) then
1287 SpawnCooldown
:= trigData
.trigMonDelay
;
1288 if (trigData
.trigMonMax
> 0) and (SpawnedCount
>= trigData
.trigMonMax
) then
1291 mon
:= g_Monsters_Create(trigData
.trigMonType
,
1292 trigData
.trigMonPos
.X
, trigData
.trigMonPos
.Y
,
1293 TDirection(trigData
.trigMonDir
), True);
1298 if (trigData
.trigMonHealth
> 0) then
1299 mon
.SetHealth(trigData
.trigMonHealth
);
1300 // Óñòàíàâëèâàåì ïîâåäåíèå:
1301 mon
.MonsterBehaviour
:= trigData
.trigMonBehav
;
1302 mon
.FNoRespawn
:= True;
1303 if g_Game_IsNet
then
1304 MH_SEND_MonsterSpawn(mon
.UID
);
1305 // Èäåì èñêàòü öåëü, åñëè íàäî:
1306 if trigData
.trigMonActive
then
1309 if trigData
.trigMonType
<> MONSTER_BARREL
then Inc(gTotalMonsters
);
1311 if g_Game_IsNet
then
1313 SetLength(gMonstersSpawned
, Length(gMonstersSpawned
)+1);
1314 gMonstersSpawned
[High(gMonstersSpawned
)] := mon
.UID
;
1317 if trigData
.trigMonMax
> 0 then
1319 mon
.SpawnTrigger
:= ID
;
1323 case trigData
.trigMonEffect
of
1324 EFFECT_TELEPORT
: begin
1325 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
1327 Anim
:= TAnimation
.Create(FramesID
, False, 3);
1328 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', trigData
.trigMonPos
.X
, trigData
.trigMonPos
.Y
);
1329 g_GFX_OnceAnim(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1330 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-32, Anim
);
1333 if g_Game_IsServer
and g_Game_IsNet
then
1334 MH_SEND_Effect(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1335 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-32, 1,
1338 EFFECT_RESPAWN
: begin
1339 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
1341 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1342 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', trigData
.trigMonPos
.X
, trigData
.trigMonPos
.Y
);
1343 g_GFX_OnceAnim(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-16,
1344 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-16, Anim
);
1347 if g_Game_IsServer
and g_Game_IsNet
then
1348 MH_SEND_Effect(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-16,
1349 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-16, 1,
1353 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
1355 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1356 g_Sound_PlayExAt('SOUND_FIRE', trigData
.trigMonPos
.X
, trigData
.trigMonPos
.Y
);
1357 g_GFX_OnceAnim(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1358 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+mon
.Obj
.Rect
.Height
-128, Anim
);
1361 if g_Game_IsServer
and g_Game_IsNet
then
1362 MH_SEND_Effect(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1363 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+mon
.Obj
.Rect
.Height
-128, 1,
1368 if g_Game_IsNet
then
1370 MH_SEND_GameStats();
1371 MH_SEND_CoopStats();
1378 // Åñëè àêòèâèðîâàí àâòîñïàâíåðîì, íå ìåíÿåì òåêñòóðó
1379 if actType
= ACTIVATE_CUSTOM
then
1384 if (trigData
.trigItemType
in [ITEM_MEDKIT_SMALL
..ITEM_MAX
]) then
1387 if (trigData
.trigItemDelay
> 0) and (actType
<> ACTIVATE_CUSTOM
) then
1389 AutoSpawn
:= not AutoSpawn
;
1391 // Àâòîñïàâíåð ïåðåêëþ÷åí - ìåíÿåì òåêñòóðó
1395 if ((trigData
.trigItemDelay
= 0) and (actType
<> ACTIVATE_CUSTOM
))
1396 or ((trigData
.trigItemDelay
> 0) and (actType
= ACTIVATE_CUSTOM
)) then
1397 if (not trigData
.trigItemOnlyDM
) or
1398 (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
1399 for k
:= 1 to trigData
.trigItemCount
do
1401 if (actType
= ACTIVATE_CUSTOM
) and (trigData
.trigItemDelay
> 0) then
1402 SpawnCooldown
:= trigData
.trigItemDelay
;
1403 if (trigData
.trigItemMax
> 0) and (SpawnedCount
>= trigData
.trigItemMax
) then
1406 iid
:= g_Items_Create(trigData
.trigItemPos
.X
, trigData
.trigItemPos
.Y
,
1407 trigData
.trigItemType
, trigData
.trigItemFalls
, False, True);
1411 if trigData
.trigItemMax
> 0 then
1413 it
:= g_Items_ByIdx(iid
);
1414 it
.SpawnTrigger
:= ID
;
1418 case trigData
.trigItemEffect
of
1419 EFFECT_TELEPORT
: begin
1420 it
:= g_Items_ByIdx(iid
);
1421 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
1423 Anim
:= TAnimation
.Create(FramesID
, False, 3);
1424 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', trigData
.trigItemPos
.X
, trigData
.trigItemPos
.Y
);
1425 g_GFX_OnceAnim(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1426 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-32, Anim
);
1429 if g_Game_IsServer
and g_Game_IsNet
then
1430 MH_SEND_Effect(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1431 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-32, 1,
1434 EFFECT_RESPAWN
: begin
1435 it
:= g_Items_ByIdx(iid
);
1436 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
1438 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1439 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', trigData
.trigItemPos
.X
, trigData
.trigItemPos
.Y
);
1440 g_GFX_OnceAnim(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-16,
1441 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-16, Anim
);
1444 if g_Game_IsServer
and g_Game_IsNet
then
1445 MH_SEND_Effect(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-16,
1446 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-16, 1,
1450 it
:= g_Items_ByIdx(iid
);
1451 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
1453 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1454 g_Sound_PlayExAt('SOUND_FIRE', trigData
.trigItemPos
.X
, trigData
.trigItemPos
.Y
);
1455 g_GFX_OnceAnim(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1456 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+it
.Obj
.Rect
.Height
-128, Anim
);
1459 if g_Game_IsServer
and g_Game_IsNet
then
1460 MH_SEND_Effect(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1461 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+it
.Obj
.Rect
.Height
-128, 1,
1466 if g_Game_IsNet
then
1467 MH_SEND_ItemSpawn(True, iid
);
1474 // Åñëè àêòèâèðîâàí àâòîñïàâíåðîì, íå ìåíÿåì òåêñòóðó
1475 if actType
= ACTIVATE_CUSTOM
then
1481 // Ìåíÿåì ìóçûêó, åñëè åñòü íà ÷òî:
1482 if (Trigger
.trigData
.trigMusicName
<> '') then
1484 gMusic
.SetByName(Trigger
.trigData
.trigMusicName
);
1485 gMusic
.SpecPause
:= True;
1489 if Trigger
.trigData
.trigMusicAction
= 1 then
1491 if gMusic
.SpecPause
then // Áûëà íà ïàóçå => èãðàòü
1492 gMusic
.SpecPause
:= False
1493 else // Èãðàëà => ñíà÷àëà
1494 gMusic
.SetPosition(0);
1499 gMusic
.SpecPause
:= True;
1507 if g_Game_IsNet
then MH_SEND_TriggerMusic
;
1512 pAngle
:= -DegToRad(trigData
.trigPushAngle
);
1513 Result
:= tr_Push(ActivateUID
,
1514 Floor(Cos(pAngle
)*trigData
.trigPushForce
),
1515 Floor(Sin(pAngle
)*trigData
.trigPushForce
),
1516 trigData
.trigResetVel
);
1523 // Ïðèáàâèòü èëè îòíÿòü î÷êî
1524 if (trigData
.trigScoreAction
in [0..1]) and (trigData
.trigScoreCount
> 0) then
1526 // Ñâîåé èëè ÷óæîé êîìàíäå
1527 if (trigData
.trigScoreTeam
in [0..1]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
1529 p
:= g_Player_Get(ActivateUID
);
1530 if ((trigData
.trigScoreAction
= 0) and (trigData
.trigScoreTeam
= 0) and (p
.Team
= TEAM_RED
))
1531 or ((trigData
.trigScoreAction
= 0) and (trigData
.trigScoreTeam
= 1) and (p
.Team
= TEAM_BLUE
)) then
1533 Inc(gTeamStat
[TEAM_RED
].Goals
, trigData
.trigScoreCount
); // Red Scores
1535 if trigData
.trigScoreCon
then
1536 if trigData
.trigScoreTeam
= 0 then
1538 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_OWN
], [p
.Name
, trigData
.trigScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1539 if g_Game_IsServer
and g_Game_IsNet
then
1540 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (trigData
.trigScoreCount
shl 16), '+r');
1543 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_ENEMY
], [p
.Name
, trigData
.trigScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1544 if g_Game_IsServer
and g_Game_IsNet
then
1545 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (trigData
.trigScoreCount
shl 16), '+re');
1548 if trigData
.trigScoreMsg
then
1550 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1551 if g_Game_IsServer
and g_Game_IsNet
then
1552 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_RED
);
1555 if ((trigData
.trigScoreAction
= 1) and (trigData
.trigScoreTeam
= 0) and (p
.Team
= TEAM_RED
))
1556 or ((trigData
.trigScoreAction
= 1) and (trigData
.trigScoreTeam
= 1) and (p
.Team
= TEAM_BLUE
)) then
1558 Dec(gTeamStat
[TEAM_RED
].Goals
, trigData
.trigScoreCount
); // Red Fouls
1560 if trigData
.trigScoreCon
then
1561 if trigData
.trigScoreTeam
= 0 then
1563 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_OWN
], [p
.Name
, trigData
.trigScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1564 if g_Game_IsServer
and g_Game_IsNet
then
1565 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (trigData
.trigScoreCount
shl 16), '-r');
1568 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_ENEMY
], [p
.Name
, trigData
.trigScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1569 if g_Game_IsServer
and g_Game_IsNet
then
1570 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (trigData
.trigScoreCount
shl 16), '-re');
1573 if trigData
.trigScoreMsg
then
1575 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1576 if g_Game_IsServer
and g_Game_IsNet
then
1577 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_RED
);
1580 if ((trigData
.trigScoreAction
= 0) and (trigData
.trigScoreTeam
= 0) and (p
.Team
= TEAM_BLUE
))
1581 or ((trigData
.trigScoreAction
= 0) and (trigData
.trigScoreTeam
= 1) and (p
.Team
= TEAM_RED
)) then
1583 Inc(gTeamStat
[TEAM_BLUE
].Goals
, trigData
.trigScoreCount
); // Blue Scores
1585 if trigData
.trigScoreCon
then
1586 if trigData
.trigScoreTeam
= 0 then
1588 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_OWN
], [p
.Name
, trigData
.trigScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1589 if g_Game_IsServer
and g_Game_IsNet
then
1590 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (trigData
.trigScoreCount
shl 16), '+b');
1593 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_ENEMY
], [p
.Name
, trigData
.trigScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1594 if g_Game_IsServer
and g_Game_IsNet
then
1595 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (trigData
.trigScoreCount
shl 16), '+be');
1598 if trigData
.trigScoreMsg
then
1600 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1601 if g_Game_IsServer
and g_Game_IsNet
then
1602 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_BLUE
);
1605 if ((trigData
.trigScoreAction
= 1) and (trigData
.trigScoreTeam
= 0) and (p
.Team
= TEAM_BLUE
))
1606 or ((trigData
.trigScoreAction
= 1) and (trigData
.trigScoreTeam
= 1) and (p
.Team
= TEAM_RED
)) then
1608 Dec(gTeamStat
[TEAM_BLUE
].Goals
, trigData
.trigScoreCount
); // Blue Fouls
1610 if trigData
.trigScoreCon
then
1611 if trigData
.trigScoreTeam
= 0 then
1613 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_OWN
], [p
.Name
, trigData
.trigScoreCount
, _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 (trigData
.trigScoreCount
shl 16), '-b');
1618 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_ENEMY
], [p
.Name
, trigData
.trigScoreCount
, _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 (trigData
.trigScoreCount
shl 16), '-be');
1623 if trigData
.trigScoreMsg
then
1625 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1626 if g_Game_IsServer
and g_Game_IsNet
then
1627 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_BLUE
);
1630 Result
:= (p
.Team
= TEAM_RED
) or (p
.Team
= TEAM_BLUE
);
1632 // Êàêîé-òî êîíêðåòíîé êîìàíäå
1633 if trigData
.trigScoreTeam
in [2..3] then
1635 if (trigData
.trigScoreAction
= 0) and (trigData
.trigScoreTeam
= 2) then
1637 Inc(gTeamStat
[TEAM_RED
].Goals
, trigData
.trigScoreCount
); // Red Scores
1639 if trigData
.trigScoreCon
then
1641 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_TEAM
], [_lc
[I_PLAYER_SCORE_RED
], trigData
.trigScoreCount
]), True);
1642 if g_Game_IsServer
and g_Game_IsNet
then
1643 MH_SEND_GameEvent(NET_EV_SCORE
, trigData
.trigScoreCount
shl 16, '+tr');
1646 if trigData
.trigScoreMsg
then
1648 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1649 if g_Game_IsServer
and g_Game_IsNet
then
1650 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_RED
);
1653 if (trigData
.trigScoreAction
= 1) and (trigData
.trigScoreTeam
= 2) then
1655 Dec(gTeamStat
[TEAM_RED
].Goals
, trigData
.trigScoreCount
); // Red Fouls
1657 if trigData
.trigScoreCon
then
1659 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_TEAM
], [_lc
[I_PLAYER_SCORE_RED
], trigData
.trigScoreCount
]), True);
1660 if g_Game_IsServer
and g_Game_IsNet
then
1661 MH_SEND_GameEvent(NET_EV_SCORE
, trigData
.trigScoreCount
shl 16, '-tr');
1664 if trigData
.trigScoreMsg
then
1666 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1667 if g_Game_IsServer
and g_Game_IsNet
then
1668 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_RED
);
1671 if (trigData
.trigScoreAction
= 0) and (trigData
.trigScoreTeam
= 3) then
1673 Inc(gTeamStat
[TEAM_BLUE
].Goals
, trigData
.trigScoreCount
); // Blue Scores
1675 if trigData
.trigScoreCon
then
1677 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_TEAM
], [_lc
[I_PLAYER_SCORE_BLUE
], trigData
.trigScoreCount
]), True);
1678 if g_Game_IsServer
and g_Game_IsNet
then
1679 MH_SEND_GameEvent(NET_EV_SCORE
, trigData
.trigScoreCount
shl 16, '+tb');
1682 if trigData
.trigScoreMsg
then
1684 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1685 if g_Game_IsServer
and g_Game_IsNet
then
1686 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_BLUE
);
1689 if (trigData
.trigScoreAction
= 1) and (trigData
.trigScoreTeam
= 3) then
1691 Dec(gTeamStat
[TEAM_BLUE
].Goals
, trigData
.trigScoreCount
); // Blue Fouls
1693 if trigData
.trigScoreCon
then
1695 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_TEAM
], [_lc
[I_PLAYER_SCORE_BLUE
], trigData
.trigScoreCount
]), True);
1696 if g_Game_IsServer
and g_Game_IsNet
then
1697 MH_SEND_GameEvent(NET_EV_SCORE
, trigData
.trigScoreCount
shl 16, '-tb');
1700 if trigData
.trigScoreMsg
then
1702 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1703 if g_Game_IsServer
and g_Game_IsNet
then
1704 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_BLUE
);
1711 if (trigData
.trigScoreAction
= 2) and (gGameSettings
.GoalLimit
> 0) then
1713 // Ñâîåé èëè ÷óæîé êîìàíäû
1714 if (trigData
.trigScoreTeam
in [0..1]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
1716 p
:= g_Player_Get(ActivateUID
);
1717 if ((trigData
.trigScoreTeam
= 0) and (p
.Team
= TEAM_RED
)) // Red Wins
1718 or ((trigData
.trigScoreTeam
= 1) and (p
.Team
= TEAM_BLUE
)) then
1719 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1721 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1723 if trigData
.trigScoreCon
then
1724 if trigData
.trigScoreTeam
= 0 then
1726 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1727 if g_Game_IsServer
and g_Game_IsNet
then
1728 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wr');
1731 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1732 if g_Game_IsServer
and g_Game_IsNet
then
1733 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wre');
1738 if ((trigData
.trigScoreTeam
= 0) and (p
.Team
= TEAM_BLUE
)) // Blue Wins
1739 or ((trigData
.trigScoreTeam
= 1) and (p
.Team
= TEAM_RED
)) then
1740 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1742 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1744 if trigData
.trigScoreCon
then
1745 if trigData
.trigScoreTeam
= 0 then
1747 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1748 if g_Game_IsServer
and g_Game_IsNet
then
1749 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wb');
1752 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1753 if g_Game_IsServer
and g_Game_IsNet
then
1754 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wbe');
1760 // Êàêîé-òî êîíêðåòíîé êîìàíäû
1761 if trigData
.trigScoreTeam
in [2..3] then
1763 if trigData
.trigScoreTeam
= 2 then // Red Wins
1764 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1766 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1769 if trigData
.trigScoreTeam
= 3 then // Blue Wins
1770 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1772 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1778 if (trigData
.trigScoreAction
= 3) and (gGameSettings
.GoalLimit
> 0) then
1780 // Ñâîåé èëè ÷óæîé êîìàíäû
1781 if (trigData
.trigScoreTeam
in [0..1]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
1783 p
:= g_Player_Get(ActivateUID
);
1784 if ((trigData
.trigScoreTeam
= 0) and (p
.Team
= TEAM_BLUE
)) // Red Wins
1785 or ((trigData
.trigScoreTeam
= 1) and (p
.Team
= TEAM_RED
)) then
1786 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1788 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1790 if trigData
.trigScoreCon
then
1791 if trigData
.trigScoreTeam
= 0 then
1793 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1794 if g_Game_IsServer
and g_Game_IsNet
then
1795 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wre');
1798 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1799 if g_Game_IsServer
and g_Game_IsNet
then
1800 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wr');
1805 if ((trigData
.trigScoreTeam
= 0) and (p
.Team
= TEAM_RED
)) // Blue Wins
1806 or ((trigData
.trigScoreTeam
= 1) and (p
.Team
= TEAM_BLUE
)) then
1807 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1809 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1811 if trigData
.trigScoreCon
then
1812 if trigData
.trigScoreTeam
= 0 then
1814 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1815 if g_Game_IsServer
and g_Game_IsNet
then
1816 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wbe');
1819 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1820 if g_Game_IsServer
and g_Game_IsNet
then
1821 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wb');
1827 // Êàêîé-òî êîíêðåòíîé êîìàíäû
1828 if trigData
.trigScoreTeam
in [2..3] then
1830 if trigData
.trigScoreTeam
= 3 then // Red Wins
1831 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1833 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1836 if trigData
.trigScoreTeam
= 2 then // Blue Wins
1837 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1839 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1844 if Result
then begin
1849 if g_Game_IsServer
and g_Game_IsNet
then
1856 Result
:= tr_Message(trigData
.trigMessageKind
, trigData
.trigMessageText
,
1857 trigData
.trigMessageSendTo
, trigData
.trigMessageTime
,
1862 TRIGGER_DAMAGE
, TRIGGER_HEALTH
:
1865 UIDType
:= g_GetUIDType(ActivateUID
);
1866 if (UIDType
= UID_PLAYER
) or (UIDType
= UID_MONSTER
) then
1872 // Âñïîìèíàåì, àêòèâèðîâàë ëè îí ìåíÿ ðàíüøå
1873 for idx
:= 0 to High(Activators
) do
1874 if Activators
[idx
].UID
= ActivateUID
then
1880 begin // Âèäèì åãî âïåðâûå
1882 SetLength(Activators
, Length(Activators
) + 1);
1883 k
:= High(Activators
);
1884 Activators
[k
].UID
:= ActivateUID
;
1886 begin // Óæå âèäåëè åãî
1887 // Åñëè èíòåðâàë îòêëþ÷¸í, íî îí âñ¸ åù¸ â çîíå ïîðàæåíèÿ, äà¸ì åìó âðåìÿ
1888 if (trigData
.trigDamageInterval
= 0) and (Activators
[k
].TimeOut
> 0) then
1889 Activators
[k
].TimeOut
:= 65535;
1890 // Òàéìàóò ïðîø¸ë - ðàáîòàåì
1891 Result
:= Activators
[k
].TimeOut
= 0;
1900 p
:= g_Player_Get(ActivateUID
);
1904 // Íàíîñèì óðîí èãðîêó
1905 if (TriggerType
= TRIGGER_DAMAGE
) and (trigData
.trigDamageValue
> 0) then
1906 p
.Damage(trigData
.trigDamageValue
, 0, 0, 0, HIT_SOME
);
1909 if (TriggerType
= TRIGGER_HEALTH
) and (trigData
.trigHealValue
> 0) then
1910 if p
.Heal(trigData
.trigHealValue
, not trigData
.trigHealMax
) and (not trigData
.trigHealSilent
) then
1912 g_Sound_PlayExAt('SOUND_ITEM_GETITEM', p
.Obj
.X
, p
.Obj
.Y
);
1913 if g_Game_IsServer
and g_Game_IsNet
then
1914 MH_SEND_Sound(p
.Obj
.X
, p
.Obj
.Y
, 'SOUND_ITEM_GETITEM');
1920 m
:= g_Monsters_ByUID(ActivateUID
);
1924 // Íàíîñèì óðîí ìîíñòðó
1925 if (TriggerType
= TRIGGER_DAMAGE
) and (trigData
.trigDamageValue
> 0) then
1926 m
.Damage(trigData
.trigDamageValue
, 0, 0, 0, HIT_SOME
);
1929 if (TriggerType
= TRIGGER_HEALTH
) and (trigData
.trigHealValue
> 0) then
1930 if m
.Heal(trigData
.trigHealValue
) and (not trigData
.trigHealSilent
) then
1932 g_Sound_PlayExAt('SOUND_ITEM_GETITEM', m
.Obj
.X
, m
.Obj
.Y
);
1933 if g_Game_IsServer
and g_Game_IsNet
then
1934 MH_SEND_Sound(m
.Obj
.X
, m
.Obj
.Y
, 'SOUND_ITEM_GETITEM');
1938 // Íàçíà÷àåì âðåìÿ ñëåäóþùåãî âîçäåéñòâèÿ
1939 if TriggerType
= TRIGGER_DAMAGE
then
1940 idx
:= trigData
.trigDamageInterval
1942 idx
:= trigData
.trigHealInterval
;
1945 Activators
[k
].TimeOut
:= idx
1947 Activators
[k
].TimeOut
:= 65535;
1955 if ShotSightTime
> 0 then
1958 // put this at the beginning so it doesn't trigger itself
1959 TimeOut
:= trigData
.trigShotWait
+ 1;
1961 wx
:= trigData
.trigShotPos
.X
;
1962 wy
:= trigData
.trigShotPos
.Y
;
1963 pAngle
:= -DegToRad(trigData
.trigShotAngle
);
1964 xd
:= wx
+ Round(Cos(pAngle
) * 32.0);
1965 yd
:= wy
+ Round(Sin(pAngle
) * 32.0);
1968 case trigData
.trigShotTarget
of
1969 TRIGGER_SHOT_TARGET_MON
: // monsters
1970 //TODO: accelerate this!
1971 g_Mons_ForEachAlive(monsShotTarget
);
1973 TRIGGER_SHOT_TARGET_PLR
: // players
1974 if gPlayers
<> nil then
1975 for idx
:= Low(gPlayers
) to High(gPlayers
) do
1976 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].Live
and
1977 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
1979 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
1980 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
1981 TargetUID
:= gPlayers
[idx
].UID
;
1985 TRIGGER_SHOT_TARGET_RED
: // red team
1986 if gPlayers
<> nil then
1987 for idx
:= Low(gPlayers
) to High(gPlayers
) do
1988 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].Live
and
1989 (gPlayers
[idx
].Team
= TEAM_RED
) and
1990 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
1992 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
1993 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
1994 TargetUID
:= gPlayers
[idx
].UID
;
1998 TRIGGER_SHOT_TARGET_BLUE
: // blue team
1999 if gPlayers
<> nil then
2000 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2001 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].Live
and
2002 (gPlayers
[idx
].Team
= TEAM_BLUE
) and
2003 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2005 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2006 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2007 TargetUID
:= gPlayers
[idx
].UID
;
2011 TRIGGER_SHOT_TARGET_MONPLR
: // monsters then players
2013 //TODO: accelerate this!
2014 g_Mons_ForEachAlive(monsShotTargetMonPlr
);
2016 if (TargetUID
= 0) and (gPlayers
<> nil) then
2017 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2018 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].Live
and
2019 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2021 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2022 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2023 TargetUID
:= gPlayers
[idx
].UID
;
2028 TRIGGER_SHOT_TARGET_PLRMON
: // players then monsters
2030 if gPlayers
<> nil then
2031 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2032 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].Live
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
;
2040 if TargetUID
= 0 then
2042 //TODO: accelerate this!
2043 g_Mons_ForEachAlive(monShotTargetPlrMon
);
2048 if (trigData
.trigShotTarget
<> TRIGGER_SHOT_TARGET_NONE
) or
2049 (trigData
.trigShotType
<> TRIGGER_SHOT_REV
) then
2050 TargetUID
:= ActivateUID
;
2054 if (trigData
.trigShotTarget
= TRIGGER_SHOT_TARGET_NONE
) or (TargetUID
> 0) or
2055 ((trigData
.trigShotTarget
> TRIGGER_SHOT_TARGET_NONE
) and (TargetUID
= 0)) then
2058 if (trigData
.trigShotIntSight
= 0) or
2059 (trigData
.trigShotTarget
= TRIGGER_SHOT_TARGET_NONE
) or
2060 (TargetUID
= ShotSightTarget
) then
2061 MakeShot(Trigger
, wx
, wy
, xd
, yd
, TargetUID
)
2064 ShotSightTime
:= trigData
.trigShotIntSight
;
2065 ShotSightTargetN
:= TargetUID
;
2066 if trigData
.trigShotType
= TRIGGER_SHOT_BFG
then
2068 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', wx
, wy
);
2069 if g_Game_IsNet
and g_Game_IsServer
then
2070 MH_SEND_Sound(wx
, wy
, 'SOUND_WEAPON_STARTFIREBFG');
2078 idx
:= trigData
.trigFXCount
;
2082 case trigData
.trigFXPos
of
2083 TRIGGER_EFFECT_POS_CENTER
:
2085 wx
:= X
+ Width
div 2;
2086 wy
:= Y
+ Height
div 2;
2088 TRIGGER_EFFECT_POS_AREA
:
2090 wx
:= X
+ Random(Width
);
2091 wy
:= Y
+ Random(Height
);
2094 wx
:= X
+ Width
div 2;
2095 wy
:= Y
+ Height
div 2;
2098 xd
:= trigData
.trigFXVelX
;
2099 yd
:= trigData
.trigFXVelY
;
2100 if trigData
.trigFXSpreadL
> 0 then xd
:= xd
- Random(trigData
.trigFXSpreadL
+ 1);
2101 if trigData
.trigFXSpreadR
> 0 then xd
:= xd
+ Random(trigData
.trigFXSpreadR
+ 1);
2102 if trigData
.trigFXSpreadU
> 0 then yd
:= yd
- Random(trigData
.trigFXSpreadU
+ 1);
2103 if trigData
.trigFXSpreadD
> 0 then yd
:= yd
+ Random(trigData
.trigFXSpreadD
+ 1);
2104 tr_MakeEffect(wx
, wy
, xd
, yd
,
2105 trigData
.trigFXType
, trigData
.trigFXSubType
,
2106 trigData
.trigFXColorR
, trigData
.trigFXColorG
, trigData
.trigFXColorB
, True, False);
2109 TimeOut
:= trigData
.trigFXWait
;
2114 if Result
{and (Trigger.TexturePanel <> -1)} then
2116 g_Map_SwitchTextureGUID(Trigger
.TexturePanelType
, Trigger
.TexturePanelGUID
, IfThen(animonce
, 2, 1));
2121 function g_Triggers_CreateWithMapIndex (Trigger
: TTrigger
; arridx
, mapidx
: Integer): DWORD
;
2123 triggers
: TDynField
;
2125 triggers
:= gCurrentMap
['trigger'];
2126 if (triggers
= nil) then raise Exception
.Create('LOAD: map has no triggers');
2127 if (mapidx
< 0) or (mapidx
>= triggers
.count
) then raise Exception
.Create('LOAD: invalid map trigger index');
2128 Trigger
.trigData
:= triggers
.item
[mapidx
];
2129 if (Trigger
.trigData
= nil) then raise Exception
.Create('LOAD: internal error in trigger loader');
2130 Trigger
.mapId
:= Trigger
.trigData
.id
;
2131 Trigger
.mapIndex
:= mapidx
;
2132 if (Trigger
.trigData
.trigRec
<> nil) then
2134 Trigger
.trigData
:= Trigger
.trigData
.trigRec
.clone();
2138 Trigger
.trigData
:= nil;
2140 result
:= g_Triggers_Create(Trigger
, arridx
);
2144 function g_Triggers_Create(Trigger
: TTrigger
; forceInternalIndex
: Integer=-1): DWORD
;
2147 fn
, mapw
: AnsiString;
2150 // Íå ñîçäàâàòü âûõîä, åñëè èãðà áåç âûõîäà:
2151 if (Trigger
.TriggerType
= TRIGGER_EXIT
) and
2152 (not LongBool(gGameSettings
.Options
and GAME_OPTION_ALLOWEXIT
)) then
2153 Trigger
.TriggerType
:= TRIGGER_NONE
;
2155 // Åñëè ìîíñòðû çàïðåùåíû, îòìåíÿåì òðèããåð:
2156 if (Trigger
.TriggerType
= TRIGGER_SPAWNMONSTER
) and
2157 (not LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
)) and
2158 (gGameSettings
.GameType
<> GT_SINGLE
) then
2159 Trigger
.TriggerType
:= TRIGGER_NONE
;
2161 // Ñ÷èòàåì êîëè÷åñòâî ñåêðåòîâ íà êàðòå:
2162 if Trigger
.TriggerType
= TRIGGER_SECRET
then
2163 gSecretsCount
:= gSecretsCount
+ 1;
2165 if (forceInternalIndex
< 0) then
2167 find_id
:= FindTrigger();
2171 olen
:= Length(gTriggers
);
2172 if (forceInternalIndex
>= olen
) then
2174 SetLength(gTriggers
, forceInternalIndex
+1);
2175 for f
:= olen
to High(gTriggers
) do gTriggers
[f
].TriggerType
:= TRIGGER_NONE
;
2177 find_id
:= DWORD(forceInternalIndex
);
2179 gTriggers
[find_id
] := Trigger
;
2181 //e_LogWritefln('created trigger with map index %s, findid=%s (%s)', [Trigger.mapIndex, find_id, Trigger.mapId]);
2184 writeln('trigger #', find_id, ': pos=(', Trigger.x, ',', Trigger.y, ')-(', Trigger.width, 'x', Trigger.height, ')',
2185 '; TexturePanel=', Trigger.TexturePanel,
2186 '; TexturePanelType=', Trigger.TexturePanelType,
2187 '; ShotPanelType=', Trigger.ShotPanelType,
2188 '; TriggerType=', Trigger.TriggerType,
2189 '; ActivateType=', Trigger.ActivateType,
2190 '; Keys=', Trigger.Keys,
2191 '; trigPanelId=', Trigger.trigPanelId,
2192 '; trigShotPanelId=', Trigger.trigShotPanelId
2196 with gTriggers
[find_id
] do
2199 // if this type of trigger exists both on the client and on the server
2200 // use an uniform numeration
2201 if Trigger
.TriggerType
= TRIGGER_SOUND
then
2203 Inc(gTriggerClientID
);
2204 ClientID
:= gTriggerClientID
;
2210 PlayerCollide
:= False;
2214 SoundPlayCount
:= 0;
2221 // Çàãðóæàåì çâóê, åñëè ýòî òðèããåð "Çâóê":
2222 if (Trigger
.TriggerType
= TRIGGER_SOUND
) and
2223 (Trigger
.trigData
.trigSoundName
<> '') then
2225 // Åùå íåò òàêîãî çâóêà:
2226 if not g_Sound_Exists(Trigger
.trigData
.trigSoundName
) then
2228 fn
:= g_ExtractWadName(Trigger
.trigData
.trigSoundName
);
2231 begin // Çâóê â ôàéëå ñ êàðòîé
2232 mapw
:= g_ExtractWadName(gMapInfo
.Map
);
2233 fn
:= mapw
+':'+g_ExtractFilePathName(Trigger
.trigData
.trigSoundName
);
2235 else // Çâóê â îòäåëüíîì ôàéëå
2236 fn
:= GameDir
+ '/wads/' + Trigger
.trigData
.trigSoundName
;
2238 if not g_Sound_CreateWADEx(Trigger
.trigData
.trigSoundName
, fn
) then
2239 g_FatalError(Format(_lc
[I_GAME_ERROR_TR_SOUND
], [fn
, Trigger
.trigData
.trigSoundName
]));
2242 // Ñîçäàåì îáúåêò çâóêà:
2243 with gTriggers
[find_id
] do
2245 Sound
:= TPlayableSound
.Create();
2246 if not Sound
.SetByName(Trigger
.trigData
.trigSoundName
) then
2254 // Çàãðóæàåì ìóçûêó, åñëè ýòî òðèããåð "Ìóçûêà":
2255 if (Trigger
.TriggerType
= TRIGGER_MUSIC
) and
2256 (Trigger
.trigData
.trigMusicName
<> '') then
2258 // Åùå íåò òàêîé ìóçûêè:
2259 if not g_Sound_Exists(Trigger
.trigData
.trigMusicName
) then
2261 fn
:= g_ExtractWadName(Trigger
.trigData
.trigMusicName
);
2264 begin // Ìóçûêà â ôàéëå ñ êàðòîé
2265 mapw
:= g_ExtractWadName(gMapInfo
.Map
);
2266 fn
:= mapw
+':'+g_ExtractFilePathName(Trigger
.trigData
.trigMusicName
);
2268 else // Ìóçûêà â ôàéëå ñ êàðòîé
2269 fn
:= GameDir
+'/wads/'+Trigger
.trigData
.trigMusicName
;
2271 if not g_Sound_CreateWADEx(Trigger
.trigData
.trigMusicName
, fn
, True) then
2272 g_FatalError(Format(_lc
[I_GAME_ERROR_TR_SOUND
], [fn
, Trigger
.trigData
.trigMusicName
]));
2276 // Çàãðóæàåì äàííûå òðèããåðà "Òóðåëü":
2277 if Trigger
.TriggerType
= TRIGGER_SHOT
then
2278 with gTriggers
[find_id
] do
2282 ShotSightTimeout
:= 0;
2283 ShotSightTarget
:= 0;
2284 ShotSightTargetN
:= 0;
2285 ShotAmmoCount
:= Trigger
.trigData
.trigShotAmmo
;
2286 ShotReloadTime
:= 0;
2293 // sorry; grid doesn't support recursive queries, so we have to do this
2295 TSimpleMonsterList
= specialize TSimpleList
<TMonster
>;
2298 tgMonsList
: TSimpleMonsterList
= nil;
2300 procedure g_Triggers_Update();
2303 Affected
: array of Integer;
2305 function monsNear (mon
: TMonster
): Boolean;
2307 result
:= false; // don't stop
2309 gTriggers[a].ActivateUID := mon.UID;
2310 ActivateTrigger(gTriggers[a], ACTIVATE_MONSTERCOLLIDE);
2312 tgMonsList
.append(mon
);
2319 if (tgMonsList
= nil) then tgMonsList
:= TSimpleMonsterList
.Create();
2321 if gTriggers
= nil then
2323 SetLength(Affected
, 0);
2325 for a
:= 0 to High(gTriggers
) do
2326 with gTriggers
[a
] do
2328 if TriggerType
<> TRIGGER_NONE
then
2330 // Óìåíüøàåì âðåìÿ äî çàêðûòèÿ äâåðè (îòêðûòèÿ ëîâóøêè)
2331 if DoorTime
> 0 then DoorTime
:= DoorTime
- 1;
2332 // Óìåíüøàåì âðåìÿ îæèäàíèÿ ïîñëå íàæàòèÿ
2333 if PressTime
> 0 then PressTime
:= PressTime
- 1;
2334 // Ïðîâåðÿåì èãðîêîâ è ìîíñòðîâ, êîòîðûõ ðàíåå çàïîìíèëè:
2335 if (TriggerType
= TRIGGER_DAMAGE
) or (TriggerType
= TRIGGER_HEALTH
) then
2337 for b
:= 0 to High(Activators
) do
2339 // Óìåíüøàåì âðåìÿ äî ïîâòîðíîãî âîçäåéñòâèÿ:
2340 if Activators
[b
].TimeOut
> 0 then
2342 Dec(Activators
[b
].TimeOut
);
2348 // Ñ÷èòàåì, ÷òî îáúåêò ïîêèíóë çîíó äåéñòâèÿ òðèããåðà
2349 if (trigData
.trigDamageInterval
= 0) and (Activators
[b
].TimeOut
< 65530) then Activators
[b
].TimeOut
:= 0;
2353 // Îáðàáàòûâàåì ñïàâíåðû
2354 if Enabled
and AutoSpawn
then
2356 if SpawnCooldown
= 0 then
2358 // Åñëè ïðèøëî âðåìÿ, ñïàâíèì ìîíñòðà
2359 if (TriggerType
= TRIGGER_SPAWNMONSTER
) and (trigData
.trigMonDelay
> 0) then
2362 ActivateTrigger(gTriggers
[a
], ACTIVATE_CUSTOM
);
2364 // Åñëè ïðèøëî âðåìÿ, ñïàâíèì ïðåäìåò
2365 if (TriggerType
= TRIGGER_SPAWNITEM
) and (trigData
.trigItemDelay
> 0) then
2368 ActivateTrigger(gTriggers
[a
], ACTIVATE_CUSTOM
);
2373 // Óìåíüøàåì âðåìÿ îæèäàíèÿ
2378 // Îáðàáàòûâàåì ñîáûòèÿ òðèããåðà "Òóðåëü"
2379 if TriggerType
= TRIGGER_SHOT
then
2381 if ShotPanelTime
> 0 then
2384 if ShotPanelTime
= 0 then g_Map_SwitchTextureGUID(ShotPanelType
, trigShotPanelGUID
);
2386 if ShotSightTime
> 0 then
2389 if ShotSightTime
= 0 then ShotSightTarget
:= ShotSightTargetN
;
2391 if ShotSightTimeout
> 0 then
2393 Dec(ShotSightTimeout
);
2394 if ShotSightTimeout
= 0 then ShotSightTarget
:= 0;
2396 if ShotReloadTime
> 0 then
2398 Dec(ShotReloadTime
);
2399 if ShotReloadTime
= 0 then ShotAmmoCount
:= trigData
.trigShotAmmo
;
2403 // Òðèããåð "Çâóê" óæå îòûãðàë, åñëè íóæíî åùå - ïåðåçàïóñêàåì
2404 if Enabled
and (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) then
2406 if (SoundPlayCount
> 0) and (not Sound
.IsPlaying()) then
2408 if trigData
.trigPlayCount
> 0 then SoundPlayCount
-= 1; // Åñëè 0 - èãðàåì çâóê áåñêîíå÷íî
2409 if trigData
.trigLocal
then
2411 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), trigData
.trigVolume
/255.0);
2415 Sound
.PlayPanVolume((trigData
.trigPan
-127.0)/128.0, trigData
.trigVolume
/255.0);
2417 if Sound
.IsPlaying() and g_Game_IsNet
and g_Game_IsServer
then MH_SEND_TriggerSound(gTriggers
[a
]);
2421 // Òðèããåð "Ëîâóøêà" - ïîðà îòêðûâàòü
2422 if (TriggerType
= TRIGGER_TRAP
) and (DoorTime
= 0) and (g_Map_PanelByGUID(trigPanelGUID
) <> nil) then
2424 tr_OpenDoor(trigPanelGUID
, trigData
.trigNoSound
, trigData
.trigd2d_doors
);
2428 // Òðèããåð "Äâåðü 5 ñåê" - ïîðà çàêðûâàòü
2429 if (TriggerType
= TRIGGER_DOOR5
) and (DoorTime
= 0) and (g_Map_PanelByGUID(trigPanelGUID
) <> nil) then
2431 pan
:= g_Map_PanelByGUID(trigPanelGUID
);
2432 if (pan
<> nil) and pan
.isGWall
then
2435 if {gWalls[trigPanelID].Enabled} pan
.Enabled
then
2441 // Ïîêà îòêðûòà - çàêðûâàåì
2442 if tr_CloseDoor(trigPanelGUID
, trigData
.trigNoSound
, trigData
.trigd2d_doors
) then DoorTime
:= -1;
2447 // Òðèããåð - ðàñøèðèòåëü èëè ïåðåêëþ÷àòåëü, è ïðîøëà çàäåðæêà, è íàæàëè íóæíîå ÷èñëî ðàç:
2448 if (TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
]) and
2449 (PressTime
= 0) and (PressCount
>= trigData
.trigCount
) then
2451 // Ñáðàñûâàåì çàäåðæêó àêòèâàöèè:
2453 // Ñáðàñûâàåì ñ÷åò÷èê íàæàòèé:
2454 if trigData
.trigCount
> 0 then PressCount
-= trigData
.trigCount
else PressCount
:= 0;
2456 // Îïðåäåëÿåì èçìåíÿåìûå èì òðèããåðû:
2457 for b
:= 0 to High(gTriggers
) do
2459 if g_Collide(trigData
.trigtX
, trigData
.trigtY
, trigData
.trigtWidth
, trigData
.trigtHeight
, gTriggers
[b
].X
, gTriggers
[b
].Y
,
2460 gTriggers
[b
].Width
, gTriggers
[b
].Height
) and
2461 ((b
<> a
) or (trigData
.trigWait
> 0)) then
2462 begin // Can be self-activated, if there is Data.Wait
2463 if (not trigData
.trigExtRandom
) or gTriggers
[b
].Enabled
then
2465 SetLength(Affected
, Length(Affected
) + 1);
2466 Affected
[High(Affected
)] := b
;
2471 // if we have panelid, assume that it will switch the moving platform
2472 if (trigPanelGUID
>= 0) then
2476 // Âûáèðàåì îäèí èç òðèããåðîâ äëÿ ðàñøèðèòåëÿ, åñëè âêëþ÷åí ðàíäîì:
2477 if (TriggerType
= TRIGGER_PRESS
) and trigData
.trigExtRandom
then
2479 if (Length(Affected
) > 0) then
2481 b
:= Affected
[Random(Length(Affected
))];
2482 gTriggers
[b
].ActivateUID
:= gTriggers
[a
].ActivateUID
;
2483 ActivateTrigger(gTriggers
[b
], 0);
2486 else //  ïðîòèâíîì ñëó÷àå ðàáîòàåì êàê îáû÷íî:
2488 for i
:= 0 to High(Affected
) do
2494 gTriggers
[b
].ActivateUID
:= gTriggers
[a
].ActivateUID
;
2495 ActivateTrigger(gTriggers
[b
], 0);
2499 gTriggers
[b
].Enabled
:= True;
2503 gTriggers
[b
].Enabled
:= False;
2504 gTriggers
[b
].TimeOut
:= 0;
2505 if gTriggers
[b
].AutoSpawn
then
2507 gTriggers
[b
].AutoSpawn
:= False;
2508 gTriggers
[b
].SpawnCooldown
:= 0;
2513 gTriggers
[b
].Enabled
:= not gTriggers
[b
].Enabled
;
2514 if not gTriggers
[b
].Enabled
then
2516 gTriggers
[b
].TimeOut
:= 0;
2517 if gTriggers
[b
].AutoSpawn
then
2519 gTriggers
[b
].AutoSpawn
:= False;
2520 gTriggers
[b
].SpawnCooldown
:= 0;
2527 SetLength(Affected
, 0);
2530 // Óìåíüøàåì âðåìÿ äî âîçìîæíîñòè ïîâòîðíîé àêòèâàöèè:
2533 TimeOut
:= TimeOut
- 1;
2534 Continue
; // ×òîáû íå ïîòåðÿòü 1 åäèíèöó çàäåðæêè
2537 // Íèæå èäóò òèïû àêòèâàöèè, åñëè òðèããåð îòêëþ÷¸í - èä¸ì äàëüøå
2542 if ByteBool(ActivateType
and ACTIVATE_PLAYERCOLLIDE
) and
2544 if gPlayers
<> nil then
2545 for b
:= 0 to High(gPlayers
) do
2546 if gPlayers
[b
] <> nil then
2548 // Æèâ, åñòü íóæíûå êëþ÷è è îí ðÿäîì:
2549 if Live
and ((gTriggers
[a
].Keys
and GetKeys
) = gTriggers
[a
].Keys
) and
2550 Collide(X
, Y
, Width
, Height
) then
2552 gTriggers
[a
].ActivateUID
:= UID
;
2554 if (gTriggers
[a
].TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) and
2556 { Don't activate sound/music again if player is here }
2558 ActivateTrigger(gTriggers
[a
], ACTIVATE_PLAYERCOLLIDE
);
2561 { TODO 5 : àêòèâàöèÿ ìîíñòðàìè òðèããåðîâ ñ êëþ÷àìè }
2563 if ByteBool(ActivateType
and ACTIVATE_MONSTERCOLLIDE
) and
2564 ByteBool(ActivateType
and ACTIVATE_NOMONSTER
) and
2565 (TimeOut
= 0) and (Keys
= 0) then
2567 // Åñëè "Ìîíñòð áëèçêî" è "Ìîíñòðîâ íåò",
2568 // çàïóñêàåì òðèããåð íà ñòàðòå êàðòû è ñíèìàåì îáà ôëàãà
2569 ActivateType
:= ActivateType
and not (ACTIVATE_MONSTERCOLLIDE
or ACTIVATE_NOMONSTER
);
2570 gTriggers
[a
].ActivateUID
:= 0;
2571 ActivateTrigger(gTriggers
[a
], 0);
2575 if ByteBool(ActivateType
and ACTIVATE_MONSTERCOLLIDE
) and
2576 (TimeOut
= 0) and (Keys
= 0) then // Åñëè íå íóæíû êëþ÷è
2578 //g_Mons_ForEach(monsNear);
2581 g_Mons_ForEachAt(gTriggers
[a
].X
, gTriggers
[a
].Y
, gTriggers
[a
].Width
, gTriggers
[a
].Height
, monsNear
);
2582 for mon
in tgMonsList
do
2584 gTriggers
[a
].ActivateUID
:= mon
.UID
;
2585 ActivateTrigger(gTriggers
[a
], ACTIVATE_MONSTERCOLLIDE
);
2587 tgMonsList
.reset(); // just in case
2591 if ByteBool(ActivateType
and ACTIVATE_NOMONSTER
) and
2592 (TimeOut
= 0) and (Keys
= 0) then
2593 if not g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then
2595 gTriggers
[a
].ActivateUID
:= 0;
2596 ActivateTrigger(gTriggers
[a
], ACTIVATE_NOMONSTER
);
2600 PlayerCollide
:= g_CollidePlayer(X
, Y
, Width
, Height
);
2604 procedure g_Triggers_Press(ID
: DWORD
; ActivateType
: Byte; ActivateUID
: Word = 0);
2606 gTriggers
[ID
].ActivateUID
:= ActivateUID
;
2607 ActivateTrigger(gTriggers
[ID
], ActivateType
);
2610 function g_Triggers_PressR(X
, Y
: Integer; Width
, Height
: Word; UID
: Word;
2611 ActivateType
: Byte; IgnoreList
: DWArray
= nil): DWArray
;
2619 if gTriggers
= nil then Exit
;
2621 case g_GetUIDType(UID
) of
2625 p
:= g_Player_Get(UID
);
2634 for a
:= 0 to High(gTriggers
) do
2635 if (gTriggers
[a
].TriggerType
<> TRIGGER_NONE
) and
2636 (gTriggers
[a
].TimeOut
= 0) and
2637 (not InDWArray(a
, IgnoreList
)) and
2638 ((gTriggers
[a
].Keys
and k
) = gTriggers
[a
].Keys
) and
2639 ByteBool(gTriggers
[a
].ActivateType
and ActivateType
) then
2640 if g_Collide(X
, Y
, Width
, Height
,
2641 gTriggers
[a
].X
, gTriggers
[a
].Y
,
2642 gTriggers
[a
].Width
, gTriggers
[a
].Height
) then
2644 gTriggers
[a
].ActivateUID
:= UID
;
2645 if ActivateTrigger(gTriggers
[a
], ActivateType
) then
2647 SetLength(Result
, Length(Result
)+1);
2648 Result
[High(Result
)] := a
;
2653 procedure g_Triggers_PressL(X1
, Y1
, X2
, Y2
: Integer; UID
: DWORD
; ActivateType
: Byte);
2659 if gTriggers
= nil then Exit
;
2661 case g_GetUIDType(UID
) of
2665 p
:= g_Player_Get(UID
);
2674 for a
:= 0 to High(gTriggers
) do
2675 if (gTriggers
[a
].TriggerType
<> TRIGGER_NONE
) and
2676 (gTriggers
[a
].TimeOut
= 0) and
2677 ((gTriggers
[a
].Keys
and k
) = gTriggers
[a
].Keys
) and
2678 ByteBool(gTriggers
[a
].ActivateType
and ActivateType
) then
2679 if g_CollideLine(x1
, y1
, x2
, y2
, gTriggers
[a
].X
, gTriggers
[a
].Y
,
2680 gTriggers
[a
].Width
, gTriggers
[a
].Height
) then
2682 gTriggers
[a
].ActivateUID
:= UID
;
2683 ActivateTrigger(gTriggers
[a
], ActivateType
);
2687 procedure g_Triggers_PressC(CX
, CY
: Integer; Radius
: Word; UID
: Word; ActivateType
: Byte; IgnoreTrigger
: Integer = -1);
2694 if gTriggers
= nil then
2697 case g_GetUIDType(UID
) of
2701 p
:= g_Player_Get(UID
);
2710 rsq
:= Radius
* Radius
;
2712 for a
:= 0 to High(gTriggers
) do
2713 if (gTriggers
[a
].ID
<> DWORD(IgnoreTrigger
)) and
2714 (gTriggers
[a
].TriggerType
<> TRIGGER_NONE
) and
2715 (gTriggers
[a
].TimeOut
= 0) and
2716 ((gTriggers
[a
].Keys
and k
) = gTriggers
[a
].Keys
) and
2717 ByteBool(gTriggers
[a
].ActivateType
and ActivateType
) then
2718 with gTriggers
[a
] do
2719 if g_Collide(CX
-Radius
, CY
-Radius
, 2*Radius
, 2*Radius
,
2720 X
, Y
, Width
, Height
) then
2721 if ((Sqr(CX
-X
)+Sqr(CY
-Y
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê âåðõíåìó ëåâîìó óãëó
2722 ((Sqr(CX
-X
-Width
)+Sqr(CY
-Y
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê âåðõíåìó ïðàâîìó óãëó
2723 ((Sqr(CX
-X
-Width
)+Sqr(CY
-Y
-Height
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê íèæíåìó ïðàâîìó óãëó
2724 ((Sqr(CX
-X
)+Sqr(CY
-Y
-Height
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê íèæíåìó ëåâîìó óãëó
2725 ( (CX
> (X
-Radius
)) and (CX
< (X
+Width
+Radius
)) and
2726 (CY
> Y
) and (CY
< (Y
+Height
)) ) or // Öåíòð êðóãà íåäàëåêî îò âåðòèêàëüíûõ ãðàíèö ïðÿìîóãîëüíèêà
2727 ( (CY
> (Y
-Radius
)) and (CY
< (Y
+Height
+Radius
)) and
2728 (CX
> X
) and (CX
< (X
+Width
)) ) then // Öåíòð êðóãà íåäàëåêî îò ãîðèçîíòàëüíûõ ãðàíèö ïðÿìîóãîëüíèêà
2731 ActivateTrigger(gTriggers
[a
], ActivateType
);
2735 procedure g_Triggers_OpenAll();
2740 if gTriggers
= nil then Exit
;
2743 for a
:= 0 to High(gTriggers
) do
2745 with gTriggers
[a
] do
2747 if (TriggerType
= TRIGGER_OPENDOOR
) or
2748 (TriggerType
= TRIGGER_DOOR5
) or
2749 (TriggerType
= TRIGGER_DOOR
) then
2751 tr_OpenDoor(trigPanelGUID
, True, trigData
.trigd2d_doors
);
2752 if TriggerType
= TRIGGER_DOOR5
then DoorTime
:= 180;
2758 if b
then g_Sound_PlayEx('SOUND_GAME_DOOROPEN');
2761 procedure g_Triggers_DecreaseSpawner(ID
: DWORD
);
2763 if (gTriggers
<> nil) then
2764 if gTriggers
[ID
].SpawnedCount
> 0 then
2765 Dec(gTriggers
[ID
].SpawnedCount
);
2768 procedure g_Triggers_Free();
2772 for a
:= 0 to High(gTriggers
) do
2774 if (gTriggers
[a
].TriggerType
= TRIGGER_SOUND
) then
2776 if g_Sound_Exists(gTriggers
[a
].trigData
.trigSoundName
) then
2778 g_Sound_Delete(gTriggers
[a
].trigData
.trigSoundName
);
2780 gTriggers
[a
].Sound
.Free();
2782 if (gTriggers
[a
].Activators
<> nil) then
2784 SetLength(gTriggers
[a
].Activators
, 0);
2786 gTriggers
[a
].trigData
.Free();
2791 SetLength(gMonstersSpawned
, 0);
2794 procedure g_Triggers_SaveState(var Mem
: TBinMemoryWriter
);
2796 count
, act_count
, i
, j
: Integer;
2801 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðèããåðîâ
2802 count
:= Length(gTriggers
);
2804 Mem
:= TBinMemoryWriter
.Create((count
+1) * 200);
2806 // Êîëè÷åñòâî òðèããåðîâ:
2807 Mem
.WriteInt(count
);
2809 //e_LogWritefln('saving %s triggers (count=%s)', [Length(gTriggers), count]);
2811 if count
= 0 then exit
;
2813 for i
:= 0 to High(gTriggers
) do
2815 // Ñèãíàòóðà òðèããåðà:
2816 dw
:= TRIGGER_SIGNATURE
; // 'TRGX'
2819 Mem
.WriteByte(gTriggers
[i
].TriggerType
);
2820 if (gTriggers
[i
].TriggerType
= TRIGGER_NONE
) then continue
; // empty one
2821 // Ñïåöèàëüíûå äàííûå òðèããåðà: äà â æîïó, ïîòîì èç êàðòû îïÿòü âûòàùèì; ñîõðàíèì òîëüêî èíäåêñ
2822 //e_LogWritefln('=== trigger #%s saved ===', [gTriggers[i].mapIndex]);
2823 Mem
.WriteInt(gTriggers
[i
].mapIndex
);
2824 //p := @gTriggers[i].Data;
2825 //Mem.WriteMemory(p, SizeOf(TTriggerData));
2826 // Êîîðäèíàòû ëåâîãî âåðõíåãî óãëà:
2827 Mem
.WriteInt(gTriggers
[i
].X
);
2828 Mem
.WriteInt(gTriggers
[i
].Y
);
2830 Mem
.WriteWord(gTriggers
[i
].Width
);
2831 Mem
.WriteWord(gTriggers
[i
].Height
);
2832 // Âêëþ÷åí ëè òðèããåð:
2833 Mem
.WriteBoolean(gTriggers
[i
].Enabled
);
2834 // Òèï àêòèâàöèè òðèããåðà:
2835 Mem
.WriteByte(gTriggers
[i
].ActivateType
);
2836 // Êëþ÷è, íåîáõîäèìûå äëÿ àêòèâàöèè:
2837 Mem
.WriteByte(gTriggers
[i
].Keys
);
2838 // ID ïàíåëè, òåêñòóðà êîòîðîé èçìåíèòñÿ:
2839 Mem
.WriteInt(gTriggers
[i
].TexturePanelGUID
);
2841 Mem
.WriteWord(gTriggers
[i
].TexturePanelType
);
2842 // Âíóòðåííèé íîìåð äðóãîé ïàíåëè (ïî ñ÷àñòëèâîé ñëó÷àéíîñòè îí áóäåò ñîâïàäàòü ñ òåì, ÷òî ñîçäàíî ïðè çàãðóçêå êàðòû)
2843 Mem
.WriteInt(gTriggers
[i
].trigPanelGUID
);
2844 // Âðåìÿ äî âîçìîæíîñòè àêòèâàöèè:
2845 Mem
.WriteWord(gTriggers
[i
].TimeOut
);
2846 // UID òîãî, êòî àêòèâèðîâàë ýòîò òðèããåð:
2847 Mem
.WriteWord(gTriggers
[i
].ActivateUID
);
2848 // Ñïèñîê UID-îâ îáúåêòîâ, êîòîðûå íàõîäèëèñü ïîä âîçäåéñòâèåì:
2849 act_count
:= Length(gTriggers
[i
].Activators
);
2850 Mem
.WriteInt(act_count
);
2851 for j
:= 0 to act_count
-1 do
2854 Mem
.WriteWord(gTriggers
[i
].Activators
[j
].UID
);
2856 Mem
.WriteWord(gTriggers
[i
].Activators
[j
].TimeOut
);
2858 // Ñòîèò ëè èãðîê â îáëàñòè òðèããåðà:
2859 Mem
.WriteBoolean(gTriggers
[i
].PlayerCollide
);
2860 // Âðåìÿ äî çàêðûòèÿ äâåðè:
2861 Mem
.WriteInt(gTriggers
[i
].DoorTime
);
2862 // Çàäåðæêà àêòèâàöèè:
2863 Mem
.WriteInt(gTriggers
[i
].PressTime
);
2865 Mem
.WriteInt(gTriggers
[i
].PressCount
);
2867 Mem
.WriteBoolean(gTriggers
[i
].AutoSpawn
);
2868 // Çàäåðæêà ñïàâíåðà:
2869 Mem
.WriteInt(gTriggers
[i
].SpawnCooldown
);
2870 // Ñ÷åò÷èê ñîçäàíèÿ îáúåêòîâ:
2871 Mem
.WriteInt(gTriggers
[i
].SpawnedCount
);
2872 // Ñêîëüêî ðàç ïðîèãðàí çâóê:
2873 Mem
.WriteInt(gTriggers
[i
].SoundPlayCount
);
2874 // Ïðîèãðûâàåòñÿ ëè çâóê?
2875 if gTriggers
[i
].Sound
<> nil then
2876 b
:= gTriggers
[i
].Sound
.IsPlaying()
2879 Mem
.WriteBoolean(b
);
2882 // Ïîçèöèÿ ïðîèãðûâàíèÿ çâóêà:
2883 dw
:= gTriggers
[i
].Sound
.GetPosition();
2886 sg
:= gTriggers
[i
].Sound
.GetVolume();
2887 sg
:= sg
/ (gSoundLevel
/255.0);
2888 Mem
.WriteSingle(sg
);
2889 // Ñòåðåî ñìåùåíèå çâóêà:
2890 sg
:= gTriggers
[i
].Sound
.GetPan();
2891 Mem
.WriteSingle(sg
);
2896 procedure g_Triggers_LoadState(var Mem
: TBinMemoryReader
);
2898 count
, act_count
, i
, j
, a
: Integer;
2905 //tw: TStrTextWriter;
2912 // Êîëè÷åñòâî òðèããåðîâ:
2915 if (count
= 0) then exit
;
2917 for a
:= 0 to count
-1 do
2919 // Ñèãíàòóðà òðèããåðà:
2921 if (dw
<> TRIGGER_SIGNATURE
) then // 'TRGX'
2923 raise EBinSizeError
.Create('g_Triggers_LoadState: Wrong Trigger Signature');
2926 Mem
.ReadByte(Trig
.TriggerType
);
2927 // Ñïåöèàëüíûå äàííûå òðèããåðà: èíäåêñ â gCurrentMap.field['triggers']
2928 if (Trig
.TriggerType
= TRIGGER_NONE
) then continue
; // empty one
2929 Mem
.ReadInt(mapIndex
);
2932 Mem.ReadMemory(p, dw);
2933 if dw <> SizeOf(TTriggerData) then
2935 raise EBinSizeError.Create('g_Triggers_LoadState: Wrong TriggerData Size');
2937 Trig.Data := TTriggerData(p^);
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(act_count
);
2977 if act_count
> 0 then
2979 SetLength(gTriggers
[i
].Activators
, act_count
);
2980 for j
:= 0 to act_count
-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
);