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, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
24 SysUtils
, Variants
, Classes
,
25 MAPDEF
, e_graphics
, g_basic
,
26 xdynrec
, hashtable
, exoma
;
45 TexturePanelGUID
: Integer;
46 //TexturePanelType: Word;
50 Activators
: array of TActivator
;
51 PlayerCollide
: Boolean;
55 SoundPlayCount
: Integer;
57 Sound
: TPlayableSound
;
63 SpawnCooldown
: Integer;
64 SpawnedCount
: Integer;
65 //ShotPanelType: Word;
66 ShotPanelTime
: Integer;
67 ShotSightTime
: Integer;
68 ShotSightTimeout
: Integer;
69 ShotSightTarget
: Word;
70 ShotSightTargetN
: Word;
72 ShotReloadTime
: Integer;
74 mapId
: AnsiString
; // trigger id, from map
75 mapIndex
: Integer; // index in fields['trigger'], used in save/load
76 trigPanelGUID
: Integer;
78 trigDataRec
: TDynRecord
; // triggerdata; owned by trigger (cloned)
79 exoInit
, exoThink
, exoCheck
, exoAction
: TExprBase
;
81 userVars
: THashStrVariant
;
83 {$INCLUDE ../shared/mapdef_tgc_def.inc}
86 function trigCenter (): TDFPoint
; inline;
89 function g_Triggers_Create (aTrigger
: TTrigger
; trec
: TDynRecord
; forceInternalIndex
: Integer=-1): DWORD
;
90 procedure g_Triggers_Update();
91 procedure g_Triggers_Press(ID
: DWORD
; ActivateType
: Byte; ActivateUID
: Word = 0);
92 function g_Triggers_PressR(X
, Y
: Integer; Width
, Height
: Word; UID
: Word;
93 ActivateType
: Byte; IgnoreList
: DWArray
= nil): DWArray
;
94 procedure g_Triggers_PressL(X1
, Y1
, X2
, Y2
: Integer; UID
: DWORD
; ActivateType
: Byte);
95 procedure g_Triggers_PressC(CX
, CY
: Integer; Radius
: Word; UID
: Word; ActivateType
: Byte; IgnoreTrigger
: Integer = -1);
96 procedure g_Triggers_OpenAll();
97 procedure g_Triggers_DecreaseSpawner(ID
: DWORD
);
98 procedure g_Triggers_Free();
99 procedure g_Triggers_SaveState (st
: TStream
);
100 procedure g_Triggers_LoadState (st
: TStream
);
104 gTriggerClientID
: Integer;
105 gTriggers
: array of TTrigger
;
106 gSecretsCount
: Integer;
107 gMonstersSpawned
: array of LongInt;
114 g_player
, g_map
, g_panel
, g_gfx
, g_game
, g_textures
,
115 g_console
, g_monsters
, g_items
, g_phys
, g_weapons
,
116 wadreader
, g_main
, e_log
, g_language
, e_res
,
117 g_options
, g_net
, g_netmsg
, utils
, xparser
, xstreams
;
120 TRIGGER_SIGNATURE
= $58475254; // 'TRGX'
124 prevSoundUpdateMs
: UInt64
;
126 {$INCLUDE ../shared/mapdef_tgc_impl.inc}
129 // ////////////////////////////////////////////////////////////////////////// //
131 TTrigScope
= class(TExprScope
)
134 monsprops
: TPropHash
;
135 platprops
: TPropHash
;
141 constructor Create ();
142 destructor Destroy (); override;
144 function getObj (const aname
: AnsiString
): TObject
; override;
145 function getField (obj
: TObject
; const afldname
: AnsiString
): Variant
; override;
146 procedure setField (obj
: TObject
; const afldname
: AnsiString
; var aval
: Variant
); override;
150 // ////////////////////////////////////////////////////////////////////////// //
152 TMyConstList
= class(TExprConstList
)
154 function valid (const cname
: AnsiString
): Boolean; override;
155 function get (const cname
: AnsiString
; out v
: Variant
): Boolean; override;
159 // ////////////////////////////////////////////////////////////////////////// //
160 function TMyConstList
.valid (const cname
: AnsiString
): Boolean;
162 //writeln('CHECK: ''', cname, '''');
164 (cname
= 'player') or
169 function TMyConstList
.get (const cname
: AnsiString
; out v
: Variant
): Boolean;
174 //if (cname = 'answer') then begin v := LongInt(42); result := true; exit; end;
176 if (gCurrentMap
= nil) then exit
;
177 for eidx
:= 0 to gCurrentMap
.mapdef
.ebsTypeCount
-1 do
179 ebs
:= gCurrentMap
.mapdef
.ebsTypeAt
[eidx
];
180 if ebs
.has
[cname
] then
182 //writeln('FOUND: ''', cname, '''');
191 // ////////////////////////////////////////////////////////////////////////// //
192 constructor TTrigScope
.Create ();
194 plrprops
:= TPropHash
.Create(TPlayer
, 'e');
195 monsprops
:= TPropHash
.Create(TMonster
, 'e');
196 platprops
:= TPropHash
.Create(TPanel
, 'e');
201 destructor TTrigScope
.Destroy ();
210 function TTrigScope
.getObj (const aname
: AnsiString
): TObject
;
212 if (aname
= 'player') then result
:= gPlayers
[0] //FIXME
213 else if (aname
= 'self') or (aname
= 'this') then result
:= TObject(Pointer(PtrUInt(1)))
214 else result
:= inherited getObj(aname
);
218 function TTrigScope
.getField (obj
: TObject
; const afldname
: AnsiString
): Variant
;
220 if (obj
= gPlayers
[0]) then
222 if plrprops
.get(obj
, afldname
, result
) then exit
;
224 else if (obj
= TObject(Pointer(PtrUInt(1)))) then
226 if (me
<> nil) and (me
.userVars
<> nil) then
228 if me
.userVars
.get(afldname
, result
) then exit
;
231 result
:= inherited getField(obj
, afldname
);
235 procedure TTrigScope
.setField (obj
: TObject
; const afldname
: AnsiString
; var aval
: Variant
);
237 if (obj
= gPlayers
[0]) then
239 if plrprops
.put(obj
, afldname
, aval
) then exit
;
241 else if (obj
= TObject(Pointer(PtrUInt(1)))) then
245 if (Length(afldname
) > 4) and (afldname
[1] = 'u') and (afldname
[2] = 's') and
246 (afldname
[3] = 'e') and (afldname
[4] = 'r') then
248 if (me
.userVars
= nil) then me
.userVars
:= THashStrVariant
.Create();
249 me
.userVars
.put(afldname
, aval
);
254 inherited setField(obj
, afldname
, aval
);
258 // ////////////////////////////////////////////////////////////////////////// //
261 tgclist
: TMyConstList
;
264 // ////////////////////////////////////////////////////////////////////////// //
265 function TTrigger
.trigCenter (): TDFPoint
; inline;
267 result
:= TDFPoint
.Create(x
+width
div 2, y
+height
div 2);
271 function FindTrigger (): DWORD
;
275 olen
:= Length(gTriggers
);
277 for i
:= 0 to olen
-1 do
279 if gTriggers
[i
].TriggerType
= TRIGGER_NONE
then begin result
:= i
; exit
; end;
282 SetLength(gTriggers
, olen
+8);
285 for i
:= result
to High(gTriggers
) do
287 gTriggers
[i
].TriggerType
:= TRIGGER_NONE
;
288 gTriggers
[i
].trigDataRec
:= nil;
289 gTriggers
[i
].exoInit
:= nil;
290 gTriggers
[i
].exoThink
:= nil;
291 gTriggers
[i
].exoCheck
:= nil;
292 gTriggers
[i
].exoAction
:= nil;
293 gTriggers
[i
].userVars
:= nil;
298 function tr_CloseDoor (PanelGUID
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
305 pan
:= g_Map_PanelByGUID(PanelGUID
);
306 if (pan
= nil) or not pan
.isGWall
then exit
; //!FIXME!TRIGANY!
307 PanelID
:= pan
.arrIdx
;
311 with gWalls
[PanelID
] do
313 if g_CollidePlayer(X
, Y
, Width
, Height
) or g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then Exit
;
318 {$IFDEF ENABLE_SOUND}
319 g_Sound_PlayExAt('SOUND_GAME_DOORCLOSE', X
, Y
);
321 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOORCLOSE');
323 g_Map_EnableWallGUID(PanelGUID
);
330 if (gDoorMap
= nil) then exit
;
333 for a
:= 0 to High(gDoorMap
) do
335 for b
:= 0 to High(gDoorMap
[a
]) do
337 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
343 if (c
<> -1) then break
;
345 if (c
= -1) then exit
;
347 for b
:= 0 to High(gDoorMap
[c
]) do
349 with gWalls
[gDoorMap
[c
, b
]] do
351 if g_CollidePlayer(X
, Y
, Width
, Height
) or g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then exit
;
357 for b
:= 0 to High(gDoorMap
[c
]) do
359 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
361 with gWalls
[PanelID
] do
363 {$IFDEF ENABLE_SOUND}
364 g_Sound_PlayExAt('SOUND_GAME_DOORCLOSE', X
, Y
);
366 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOORCLOSE');
373 for b
:= 0 to High(gDoorMap
[c
]) do
375 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
377 g_Map_EnableWall_XXX(gDoorMap
[c
, b
]);
385 procedure tr_CloseTrap (PanelGUID
: Integer; NoSound
: Boolean; d2d
: Boolean);
388 wx
, wy
, wh
, ww
: Integer;
392 function monsDamage (mon
: TMonster
): Boolean;
394 result
:= false; // don't stop
395 if g_Obj_Collide(wx
, wy
, ww
, wh
, @mon
.Obj
) then mon
.Damage(TRAP_DAMAGE
, 0, 0, 0, HIT_TRAP
);
399 pan
:= g_Map_PanelByGUID(PanelGUID
);
403 e_LogWritefln('tr_CloseTrap: pguid=%s; NO PANEL!', [PanelGUID], MSG_WARNING);
407 e_LogWritefln('tr_CloseTrap: pguid=%s; isGWall=%s; arrIdx=%s', [PanelGUID, pan.isGWall, pan.arrIdx]);
410 if (pan
= nil) or not pan
.isGWall
then exit
; //!FIXME!TRIGANY!
411 PanelID
:= pan
.arrIdx
;
415 with gWalls
[PanelID
] do
417 if (not NoSound
) and (not Enabled
) then
419 {$IFDEF ENABLE_SOUND}
420 g_Sound_PlayExAt('SOUND_GAME_SWITCH1', X
, Y
);
422 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_SWITCH1');
426 wx
:= gWalls
[PanelID
].X
;
427 wy
:= gWalls
[PanelID
].Y
;
428 ww
:= gWalls
[PanelID
].Width
;
429 wh
:= gWalls
[PanelID
].Height
;
431 with gWalls
[PanelID
] do
433 if gPlayers
<> nil then
435 for a
:= 0 to High(gPlayers
) do
437 if (gPlayers
[a
] <> nil) and gPlayers
[a
].alive
and gPlayers
[a
].Collide(X
, Y
, Width
, Height
) then
439 gPlayers
[a
].Damage(TRAP_DAMAGE
, 0, 0, 0, HIT_TRAP
);
444 //g_Mons_ForEach(monsDamage);
445 g_Mons_ForEachAliveAt(wx
, wy
, ww
, wh
, monsDamage
);
447 if not Enabled
then g_Map_EnableWallGUID(PanelGUID
);
452 if (gDoorMap
= nil) then exit
;
455 for a
:= 0 to High(gDoorMap
) do
457 for b
:= 0 to High(gDoorMap
[a
]) do
459 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
465 if (c
<> -1) then break
;
467 if (c
= -1) then exit
;
471 for b
:= 0 to High(gDoorMap
[c
]) do
473 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
475 with gWalls
[PanelID
] do
477 {$IFDEF ENABLE_SOUND}
478 g_Sound_PlayExAt('SOUND_GAME_SWITCH1', X
, Y
);
480 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_SWITCH1');
487 for b
:= 0 to High(gDoorMap
[c
]) do
489 wx
:= gWalls
[gDoorMap
[c
, b
]].X
;
490 wy
:= gWalls
[gDoorMap
[c
, b
]].Y
;
491 ww
:= gWalls
[gDoorMap
[c
, b
]].Width
;
492 wh
:= gWalls
[gDoorMap
[c
, b
]].Height
;
494 with gWalls
[gDoorMap
[c
, b
]] do
496 if gPlayers
<> nil then
498 for a
:= 0 to High(gPlayers
) do
500 if (gPlayers
[a
] <> nil) and gPlayers
[a
].alive
and gPlayers
[a
].Collide(X
, Y
, Width
, Height
) then
502 gPlayers
[a
].Damage(TRAP_DAMAGE
, 0, 0, 0, HIT_TRAP
);
507 //g_Mons_ForEach(monsDamage);
508 g_Mons_ForEachAliveAt(wx
, wy
, ww
, wh
, monsDamage
);
510 if gMonsters <> nil then
511 for a := 0 to High(gMonsters) do
512 if (gMonsters[a] <> nil) and gMonsters[a].alive and
513 g_Obj_Collide(X, Y, Width, Height, @gMonsters[a].Obj) then
514 gMonsters[a].Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
517 if not Enabled
then g_Map_EnableWall_XXX(gDoorMap
[c
, b
]);
524 function tr_OpenDoor (PanelGUID
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
531 pan
:= g_Map_PanelByGUID(PanelGUID
);
532 if (pan
= nil) or not pan
.isGWall
then exit
; //!FIXME!TRIGANY!
533 PanelID
:= pan
.arrIdx
;
537 with gWalls
[PanelID
] do
543 {$IFDEF ENABLE_SOUND}
544 g_Sound_PlayExAt('SOUND_GAME_DOOROPEN', X
, Y
);
546 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOOROPEN');
548 g_Map_DisableWallGUID(PanelGUID
);
555 if (gDoorMap
= nil) then exit
;
558 for a
:= 0 to High(gDoorMap
) do
560 for b
:= 0 to High(gDoorMap
[a
]) do
562 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
568 if (c
<> -1) then break
;
570 if (c
= -1) then exit
;
574 for b
:= 0 to High(gDoorMap
[c
]) do
576 if gWalls
[gDoorMap
[c
, b
]].Enabled
then
578 with gWalls
[PanelID
] do
580 {$IFDEF ENABLE_SOUND}
581 g_Sound_PlayExAt('SOUND_GAME_DOOROPEN', X
, Y
);
583 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOOROPEN');
590 for b
:= 0 to High(gDoorMap
[c
]) do
592 if gWalls
[gDoorMap
[c
, b
]].Enabled
then
594 g_Map_DisableWall_XXX(gDoorMap
[c
, b
]);
602 function tr_SetLift (PanelGUID
: Integer; d
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
610 pan
:= g_Map_PanelByGUID(PanelGUID
);
611 if (pan
= nil) or not pan
.isGLift
then exit
; //!FIXME!TRIGANY!
612 PanelID
:= pan
.arrIdx
;
614 if (gLifts
[PanelID
].PanelType
= PANEL_LIFTUP
) or (gLifts
[PanelID
].PanelType
= PANEL_LIFTDOWN
) then
618 1: t
:= LIFTTYPE_DOWN
;
619 else t
:= IfThen(gLifts
[PanelID
].LiftType
= LIFTTYPE_DOWN
, LIFTTYPE_UP
, LIFTTYPE_DOWN
);
622 else if (gLifts
[PanelID
].PanelType
= PANEL_LIFTLEFT
) or (gLifts
[PanelID
].PanelType
= PANEL_LIFTRIGHT
) then
625 0: t
:= LIFTTYPE_LEFT
;
626 1: t
:= LIFTTYPE_RIGHT
;
627 else t
:= IfThen(gLifts
[PanelID
].LiftType
= LIFTTYPE_LEFT
, LIFTTYPE_RIGHT
, LIFTTYPE_LEFT
);
633 with gLifts
[PanelID
] do
635 if (LiftType
<> t
) then
637 g_Map_SetLiftGUID(PanelGUID
, t
); //???
638 //if not NoSound then g_Sound_PlayExAt('SOUND_GAME_SWITCH0', X, Y);
645 if (gLiftMap
= nil) then exit
;
648 for a
:= 0 to High(gLiftMap
) do
650 for b
:= 0 to High(gLiftMap
[a
]) do
652 if (gLiftMap
[a
, b
] = DWORD(PanelID
)) then
658 if (c
<> -1) then break
;
660 if (c
= -1) then exit
;
663 for b := 0 to High(gLiftMap[c]) do
664 if gLifts[gLiftMap[c, b]].LiftType <> t then
666 with gLifts[PanelID] do
667 g_Sound_PlayExAt('SOUND_GAME_SWITCH0', X, Y);
671 for b
:= 0 to High(gLiftMap
[c
]) do
673 with gLifts
[gLiftMap
[c
, b
]] do
675 if (LiftType
<> t
) then
677 g_Map_SetLift_XXX(gLiftMap
[c
, b
], t
);
686 function tr_SpawnShot (ShotType
: Integer; wx
, wy
, dx
, dy
: Integer; ShotSound
: Boolean; ShotTarget
: Word): SizeInt
;
693 TextureID
:= DWORD(-1);
694 snd
:= 'SOUND_WEAPON_FIREROCKET';
699 g_Weapon_pistol(wx
, wy
, dx
, dy
, 0, True);
700 snd
:= 'SOUND_WEAPON_FIREPISTOL';
703 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_BULLET
);
704 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL1
);
710 g_Weapon_mgun(wx
, wy
, dx
, dy
, 0, True);
711 {$IFDEF ENABLE_SOUND}
712 // XXX: this sound must be choosen by client
713 if gSoundEffectsDF
then snd
:= 'SOUND_WEAPON_FIRECGUN'
714 else snd
:= 'SOUND_WEAPON_FIREPISTOL';
716 snd
:= 'SOUND_WEAPON_FIRECGUN';
720 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_BULLET
);
721 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL1
);
725 TRIGGER_SHOT_SHOTGUN
:
727 g_Weapon_Shotgun(wx
, wy
, dx
, dy
, 0, True);
728 snd
:= 'SOUND_WEAPON_FIRESHOTGUN';
731 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
732 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL2
);
738 g_Weapon_DShotgun(wx
, wy
, dx
, dy
, 0, True);
739 snd
:= 'SOUND_WEAPON_FIRESHOTGUN2';
742 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
743 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
744 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL3
);
750 Result
:= g_Weapon_ball1(wx
, wy
, dx
, dy
, 0, -1, True, False);
751 snd
:= 'SOUND_WEAPON_FIREBALL';
756 Result
:= g_Weapon_Plasma(wx
, wy
, dx
, dy
, 0, -1, True, False);
757 snd
:= 'SOUND_WEAPON_FIREPLASMA';
762 Result
:= g_Weapon_aplasma(wx
, wy
, dx
, dy
, 0, -1, True, False);
763 snd
:= 'SOUND_WEAPON_FIREPLASMA';
768 Result
:= g_Weapon_ball2(wx
, wy
, dx
, dy
, 0, -1, True, False);
769 snd
:= 'SOUND_WEAPON_FIREBALL';
774 Result
:= g_Weapon_ball7(wx
, wy
, dx
, dy
, 0, -1, True, False);
775 snd
:= 'SOUND_WEAPON_FIREBALL';
780 Result
:= g_Weapon_manfire(wx
, wy
, dx
, dy
, 0, -1, True, False);
781 snd
:= 'SOUND_WEAPON_FIREBALL';
786 Result
:= g_Weapon_revf(wx
, wy
, dx
, dy
, 0, ShotTarget
, -1, True);
787 snd
:= 'SOUND_WEAPON_FIREREV';
792 Result
:= g_Weapon_Rocket(wx
, wy
, dx
, dy
, 0, -1, True, False);
793 snd
:= 'SOUND_WEAPON_FIREROCKET';
798 Result
:= g_Weapon_BFGShot(wx
, wy
, dx
, dy
, 0, -1, True, False);
799 snd
:= 'SOUND_WEAPON_FIREBFG';
804 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_ROCKET') then
806 Anim
:= TAnimation
.Create(TextureID
, False, 6);
807 Anim
.Blending
:= False;
808 g_GFX_OnceAnim(wx
-64, wy
-64, Anim
);
811 g_Weapon_Explode(wx
, wy
, 60, 0);
812 snd
:= 'SOUND_WEAPON_EXPLODEROCKET';
815 TRIGGER_SHOT_BFGEXPL
:
817 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_BFG') then
819 Anim
:= TAnimation
.Create(TextureID
, False, 6);
820 Anim
.Blending
:= False;
821 g_GFX_OnceAnim(wx
-64, wy
-64, Anim
);
824 g_Weapon_BFG9000(wx
, wy
, 0);
825 snd
:= 'SOUND_WEAPON_EXPLODEBFG';
830 Result
:= g_Weapon_flame(wx
, wy
, dx
, dy
, 0, -1, True, False);
831 snd
:= 'SOUND_GAME_BURNING';
837 if g_Game_IsNet
and g_Game_IsServer
then
840 TRIGGER_SHOT_EXPL
: MH_SEND_Effect(wx
, wy
, Byte(ShotSound
), NET_GFX_EXPLODE
);
841 TRIGGER_SHOT_BFGEXPL
: MH_SEND_Effect(wx
, wy
, Byte(ShotSound
), NET_GFX_BFGEXPL
);
843 if Result
<> -1 then MH_SEND_CreateProj(Result
);
844 if ShotSound
then MH_SEND_Sound(wx
, wy
, snd
);
849 {$IFDEF ENABLE_SOUND}
851 g_Sound_PlayExAt(snd
, wx
, wy
);
856 procedure MakeShot (var Trigger
: TTrigger
; wx
, wy
, dx
, dy
: Integer; TargetUID
: Word);
860 if (tgcAmmo
= 0) or ((tgcAmmo
> 0) and (ShotAmmoCount
> 0)) then
862 if (trigPanelGUID
<> -1) and (ShotPanelTime
= 0) then
864 g_Map_SwitchTextureGUID({ShotPanelType,} trigPanelGUID
);
865 ShotPanelTime
:= 4; // òèêîâ íà âñïûøêó âûñòðåëà
868 if (tgcSight
> 0) then ShotSightTimeout
:= 180; // ~= 5 ñåêóíä
870 if (ShotAmmoCount
> 0) then Dec(ShotAmmoCount
);
872 dx
+= Random(tgcAccuracy
)-Random(tgcAccuracy
);
873 dy
+= Random(tgcAccuracy
)-Random(tgcAccuracy
);
875 tr_SpawnShot(tgcShotType
, wx
, wy
, dx
, dy
, tgcShotSound
, TargetUID
);
879 if (tgcReload
> 0) and (ShotReloadTime
= 0) then
881 ShotReloadTime
:= tgcReload
; // òèêîâ íà ïåðåçàðÿäêó ïóøêè
888 procedure tr_MakeEffect (X
, Y
, VX
, VY
: Integer; T
, ST
, CR
, CG
, CB
: Byte; Silent
, Send
: Boolean);
893 if T
= TRIGGER_EFFECT_PARTICLE
then
896 TRIGGER_EFFECT_SLIQUID
:
898 if (CR
= 255) and (CG
= 0) and (CB
= 0) then g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 1, 0, 0, 0)
899 else if (CR
= 0) and (CG
= 255) and (CB
= 0) then g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 2, 0, 0, 0)
900 else if (CR
= 0) and (CG
= 0) and (CB
= 255) then g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 3, 0, 0, 0)
901 else g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 0, 0, 0, 0);
903 TRIGGER_EFFECT_LLIQUID
: g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 4, CR
, CG
, CB
);
904 TRIGGER_EFFECT_DLIQUID
: g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 5, CR
, CG
, CB
);
905 TRIGGER_EFFECT_BLOOD
: g_GFX_Blood(X
, Y
, 1, VX
, VY
, 0, 0, CR
, CG
, CB
);
906 TRIGGER_EFFECT_SPARK
: g_GFX_Spark(X
, Y
, 1, GetAngle2(VX
, VY
), 0, 0);
907 TRIGGER_EFFECT_BUBBLE
: g_Game_Effect_Bubbles(X
, Y
, 1, 0, 0, Silent
);
911 if T
= TRIGGER_EFFECT_ANIMATION
then
914 EFFECT_TELEPORT
: begin
915 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
917 Anim
:= TAnimation
.Create(FramesID
, False, 3);
918 {$IFDEF ENABLE_SOUND}
919 if not Silent
then g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
921 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
924 if Send
and g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(X
-32, Y
-32, Byte(not Silent
), NET_GFX_TELE
);
926 EFFECT_RESPAWN
: begin
927 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
929 Anim
:= TAnimation
.Create(FramesID
, False, 4);
930 {$IFDEF ENABLE_SOUND}
931 if not Silent
then g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
933 g_GFX_OnceAnim(X
-16, Y
-16, Anim
);
936 if Send
and g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(X
-16, Y
-16, Byte(not Silent
), NET_GFX_RESPAWN
);
939 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
941 Anim
:= TAnimation
.Create(FramesID
, False, 4);
942 {$IFDEF ENABLE_SOUND}
943 if not Silent
then g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
945 g_GFX_OnceAnim(X
-32, Y
-128, Anim
);
948 if Send
and g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(X
-32, Y
-128, Byte(not Silent
), NET_GFX_FIRE
);
955 function tr_Teleport (ActivateUID
: Integer; TX
, TY
: Integer; TDir
: Integer; Silent
: Boolean; D2D
: Boolean): Boolean;
961 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then Exit
;
962 case g_GetUIDType(ActivateUID
) of
965 p
:= g_Player_Get(ActivateUID
);
966 if p
= nil then Exit
;
969 if p
.TeleportTo(TX
-(p
.Obj
.Rect
.Width
div 2), TY
-p
.Obj
.Rect
.Height
, Silent
, TDir
) then result
:= true;
973 if p
.TeleportTo(TX
, TY
, Silent
, TDir
) then result
:= true;
978 m
:= g_Monsters_ByUID(ActivateUID
);
979 if m
= nil then Exit
;
982 if m
.TeleportTo(TX
-(m
.Obj
.Rect
.Width
div 2), TY
-m
.Obj
.Rect
.Height
, Silent
, TDir
) then result
:= true;
986 if m
.TeleportTo(TX
, TY
, Silent
, TDir
) then result
:= true;
993 function tr_Push (ActivateUID
: Integer; VX
, VY
: Integer; ResetVel
: Boolean): Boolean;
999 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then exit
;
1000 case g_GetUIDType(ActivateUID
) of
1003 p
:= g_Player_Get(ActivateUID
);
1004 if p
= nil then Exit
;
1019 m
:= g_Monsters_ByUID(ActivateUID
);
1020 if m
= nil then Exit
;
1036 function tr_Message (MKind
: Integer; MText
: string; MSendTo
: Integer; MTime
: Integer; ActivateUID
: Integer): Boolean;
1043 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then Exit
;
1044 msg
:= b_Text_Format(MText
);
1046 TRIGGER_MESSAGE_DEST_ME
: // activator
1048 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
1050 if g_Game_IsWatchedPlayer(ActivateUID
) then
1052 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
1053 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
1057 p
:= g_Player_Get(ActivateUID
);
1058 if g_Game_IsNet
and (p
.FClientID
>= 0) then
1060 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, p
.FClientID
)
1061 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, p
.FClientID
);
1067 TRIGGER_MESSAGE_DEST_MY_TEAM
: // activator's team
1069 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
1071 p
:= g_Player_Get(ActivateUID
);
1072 if g_Game_IsWatchedTeam(p
.Team
) then
1074 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
1075 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
1078 if g_Game_IsNet
then
1080 for i
:= Low(gPlayers
) to High(gPlayers
) do
1082 if (gPlayers
[i
].Team
= p
.Team
) and (gPlayers
[i
].FClientID
>= 0) then
1084 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
1085 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
1092 TRIGGER_MESSAGE_DEST_ENEMY_TEAM
: // activator's enemy team
1094 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
1096 p
:= g_Player_Get(ActivateUID
);
1097 if g_Game_IsWatchedTeam(p
.Team
) then
1099 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
1100 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
1103 if g_Game_IsNet
then
1105 for i
:= Low(gPlayers
) to High(gPlayers
) do
1107 if (gPlayers
[i
].Team
<> p
.Team
) and (gPlayers
[i
].FClientID
>= 0) then
1109 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
1110 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
1117 TRIGGER_MESSAGE_DEST_RED_TEAM
: // red team
1119 if g_Game_IsWatchedTeam(TEAM_RED
) then
1121 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
1122 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
1125 if g_Game_IsNet
then
1127 for i
:= Low(gPlayers
) to High(gPlayers
) do
1129 if (gPlayers
[i
].Team
= TEAM_RED
) and (gPlayers
[i
].FClientID
>= 0) then
1131 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
1132 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
1138 TRIGGER_MESSAGE_DEST_BLUE_TEAM
: // blue team
1140 if g_Game_IsWatchedTeam(TEAM_BLUE
) then
1142 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
1143 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
1146 if g_Game_IsNet
then
1148 for i
:= Low(gPlayers
) to High(gPlayers
) do
1150 if (gPlayers
[i
].Team
= TEAM_BLUE
) and (gPlayers
[i
].FClientID
>= 0) then
1152 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
1153 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
1159 TRIGGER_MESSAGE_DEST_EVERYONE
: // everyone
1161 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
1162 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
1164 if g_Game_IsNet
then
1166 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
)
1167 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
);
1174 function tr_ShotAimCheck (var Trigger
: TTrigger
; Obj
: PObj
): Boolean;
1179 if TriggerType
<> TRIGGER_SHOT
then Exit
;
1180 result
:= (tgcAim
and TRIGGER_SHOT_AIM_ALLMAP
> 0)
1181 or g_Obj_Collide(X
, Y
, Width
, Height
, Obj
);
1182 if result
and (tgcAim
and TRIGGER_SHOT_AIM_TRACE
> 0) then
1184 result
:= g_TraceVector(tgcTX
, tgcTY
,
1185 Obj
^.X
+ Obj
^.Rect
.X
+ (Obj
^.Rect
.Width
div 2),
1186 Obj
^.Y
+ Obj
^.Rect
.Y
+ (Obj
^.Rect
.Height
div 2));
1192 function ActivateTrigger (var Trigger
: TTrigger
; actType
: Byte): Boolean;
1198 idx
, k
, wx
, wy
, xd
, yd
: Integer;
1209 function monsShotTarget (mon
: TMonster
): Boolean;
1211 result
:= false; // don't stop
1212 if mon
.alive
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
1214 xd
:= mon
.GameX
+ mon
.Obj
.Rect
.Width
div 2;
1215 yd
:= mon
.GameY
+ mon
.Obj
.Rect
.Height
div 2;
1216 TargetUID
:= mon
.UID
;
1217 result
:= true; // stop
1221 function monsShotTargetMonPlr (mon
: TMonster
): Boolean;
1223 result
:= false; // don't stop
1224 if mon
.alive
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
1226 xd
:= mon
.GameX
+ mon
.Obj
.Rect
.Width
div 2;
1227 yd
:= mon
.GameY
+ mon
.Obj
.Rect
.Height
div 2;
1228 TargetUID
:= mon
.UID
;
1229 result
:= true; // stop
1233 function monShotTargetPlrMon (mon
: TMonster
): Boolean;
1235 result
:= false; // don't stop
1236 if mon
.alive
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
1238 xd
:= mon
.GameX
+ mon
.Obj
.Rect
.Width
div 2;
1239 yd
:= mon
.GameY
+ mon
.Obj
.Rect
.Height
div 2;
1240 TargetUID
:= mon
.UID
;
1241 result
:= true; // stop
1249 if g_Game_IsClient
then exit
;
1251 if not Trigger
.Enabled
then exit
;
1252 if (Trigger
.TimeOut
<> 0) and (actType
<> ACTIVATE_CUSTOM
) then exit
;
1253 if (gLMSRespawn
> LMS_RESPAWN_NONE
) then exit
;
1255 if (Trigger
.exoCheck
<> nil) then
1257 //conwritefln('exocheck: [%s]', [Trigger.exoCheck.toString()]);
1259 tgscope
.me
:= @Trigger
;
1260 tvval
:= Trigger
.exoCheck
.value(tgscope
);
1262 if not Boolean(tvval
) then exit
;
1267 conwritefln('trigger exocheck error: %s [%s]', [e
.message, Trigger
.exoCheck
.toString()]);
1275 coolDown
:= (actType
<> 0);
1277 if (Trigger
.exoAction
<> nil) then
1279 //conwritefln('exoactivate: [%s]', [Trigger.exoAction.toString()]);
1281 tgscope
.me
:= @Trigger
;
1282 Trigger
.exoAction
.value(tgscope
);
1288 conwritefln('trigger exoactivate error: %s [%s]', [e
.message, Trigger
.exoAction
.toString()]);
1299 {$IFDEF ENABLE_SOUND}
1300 g_Sound_PlayEx('SOUND_GAME_SWITCH0');
1302 if g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_SWITCH0');
1303 gExitByTrigger
:= True;
1304 g_Game_ExitLevel(tgcMap
);
1313 Result
:= tr_Teleport(ActivateUID
,
1314 tgcTarget
.X
, tgcTarget
.Y
,
1315 tgcDirection
, tgcSilent
,
1322 Result
:= tr_OpenDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
1328 Result
:= tr_CloseDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
1332 TRIGGER_DOOR
, TRIGGER_DOOR5
:
1334 pan
:= g_Map_PanelByGUID(trigPanelGUID
);
1335 if (pan
<> nil) and pan
.isGWall
then
1337 if gWalls
[{trigPanelID}pan
.arrIdx
].Enabled
then
1339 result
:= tr_OpenDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
1340 if (TriggerType
= TRIGGER_DOOR5
) then DoorTime
:= 180;
1344 result
:= tr_CloseDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
1347 if result
then TimeOut
:= 18;
1351 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
:
1353 tr_CloseTrap(trigPanelGUID
, tgcSilent
, tgcD2d
);
1355 if TriggerType
= TRIGGER_TRAP
then
1369 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
:
1372 if PressTime
= -1 then PressTime
:= tgcWait
;
1373 if coolDown
then TimeOut
:= 18 else TimeOut
:= 0;
1378 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
1382 p
:= g_Player_Get(ActivateUID
);
1384 Inc(gCoopSecretsFound
);
1385 if g_Game_IsNet
then
1387 MH_SEND_GameStats();
1388 MH_SEND_GameEvent(NET_EV_SECRET
, p
.UID
, '');
1394 Result
:= tr_SetLift(trigPanelGUID
, 0, tgcSilent
, tgcD2d
);
1397 if (not tgcSilent
) and Result
then begin
1398 {$IFDEF ENABLE_SOUND}
1399 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1401 Y
+ (Height
div 2));
1403 if g_Game_IsServer
and g_Game_IsNet
then
1404 MH_SEND_Sound(X
+ (Width
div 2),
1406 'SOUND_GAME_SWITCH0');
1412 Result
:= tr_SetLift(trigPanelGUID
, 1, tgcSilent
, tgcD2d
);
1415 if (not tgcSilent
) and Result
then begin
1416 {$IFDEF ENABLE_SOUND}
1417 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1419 Y
+ (Height
div 2));
1421 if g_Game_IsServer
and g_Game_IsNet
then
1422 MH_SEND_Sound(X
+ (Width
div 2),
1424 'SOUND_GAME_SWITCH0');
1430 Result
:= tr_SetLift(trigPanelGUID
, 3, tgcSilent
, tgcD2d
);
1436 if (not tgcSilent
) and Result
then begin
1437 {$IFDEF ENABLE_SOUND}
1438 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1440 Y
+ (Height
div 2));
1442 if g_Game_IsServer
and g_Game_IsNet
then
1443 MH_SEND_Sound(X
+ (Width
div 2),
1445 'SOUND_GAME_SWITCH0');
1452 if tgcActivateOnce
then
1455 TriggerType
:= TRIGGER_NONE
;
1463 animonce
:= tgcAnimateOnce
;
1469 {$IFDEF ENABLE_SOUND}
1470 if Sound
<> nil then
1472 if tgcSoundSwitch
and Sound
.IsPlaying() then
1473 begin // Íóæíî âûêëþ÷èòü, åñëè èãðàë
1475 SoundPlayCount
:= 0;
1478 else // (not Data.SoundSwitch) or (not Sound.IsPlaying())
1479 if (tgcPlayCount
> 0) or (not Sound
.IsPlaying()) then
1481 if tgcPlayCount
> 0 then
1482 SoundPlayCount
:= tgcPlayCount
1483 else // 0 - èãðàåì áåñêîíå÷íî
1484 SoundPlayCount
:= 1;
1487 if g_Game_IsNet
then
1488 MH_SEND_TriggerSound(ClientID
, Sound
.IsPlaying(), Sound
.GetPosition(), SoundPlayCount
);
1491 if tgcSoundSwitch
and SoundPlay
then
1494 SoundPlayCount
:= 0;
1497 else if (tgcPlayCount
> 0) or not SoundPlay
then
1499 if tgcPlayCount
> 0 then
1500 SoundPlayCount
:= tgcPlayCount
1502 SoundPlayCount
:= 1;
1505 if g_Game_IsNet
then
1506 MH_SEND_TriggerSound(ClientID
, SoundPlay
, SoundPos
, SoundPlayCount
);
1510 TRIGGER_SPAWNMONSTER
:
1511 if (tgcSpawnMonsType
in [MONSTER_DEMON
..MONSTER_MAN
]) then
1514 if (tgcDelay
> 0) and (actType
<> ACTIVATE_CUSTOM
) then
1516 AutoSpawn
:= not AutoSpawn
;
1518 // Àâòîñïàâíåð ïåðåêëþ÷åí - ìåíÿåì òåêñòóðó
1522 if ((tgcDelay
= 0) and (actType
<> ACTIVATE_CUSTOM
))
1523 or ((tgcDelay
> 0) and (actType
= ACTIVATE_CUSTOM
)) then
1524 for k
:= 1 to tgcMonsCount
do
1526 if (actType
= ACTIVATE_CUSTOM
) and (tgcDelay
> 0) then
1527 SpawnCooldown
:= -1; // Çàäåðæêà âûñòàâèòñÿ ìîíñòðîì ïðè óíè÷òîæåíèè
1528 if (tgcMax
> 0) and (SpawnedCount
>= tgcMax
) then
1531 mon
:= g_Monsters_Create(tgcSpawnMonsType
,
1533 TDirection(tgcDirection
), True);
1538 if (tgcHealth
> 0) then
1539 mon
.SetHealth(tgcHealth
);
1540 // Óñòàíàâëèâàåì ïîâåäåíèå:
1541 mon
.MonsterBehaviour
:= tgcBehaviour
;
1542 mon
.FNoRespawn
:= True;
1543 if g_Game_IsNet
then
1544 MH_SEND_MonsterSpawn(mon
.UID
);
1545 // Èäåì èñêàòü öåëü, åñëè íàäî:
1549 if tgcSpawnMonsType
<> MONSTER_BARREL
then Inc(gTotalMonsters
);
1551 if g_Game_IsNet
then
1553 SetLength(gMonstersSpawned
, Length(gMonstersSpawned
)+1);
1554 gMonstersSpawned
[High(gMonstersSpawned
)] := mon
.UID
;
1557 mon
.SpawnTrigger
:= ID
;
1558 if tgcMax
> 0 then Inc(SpawnedCount
);
1561 EFFECT_TELEPORT
: begin
1562 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
1564 Anim
:= TAnimation
.Create(FramesID
, False, 3);
1565 {$IFDEF ENABLE_SOUND}
1566 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', tgcTX
, tgcTY
);
1568 g_GFX_OnceAnim(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1569 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-32, Anim
);
1572 if g_Game_IsServer
and g_Game_IsNet
then
1573 MH_SEND_Effect(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1574 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-32, 1,
1577 EFFECT_RESPAWN
: begin
1578 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
1580 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1581 {$IFDEF ENABLE_SOUND}
1582 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', tgcTX
, tgcTY
);
1584 g_GFX_OnceAnim(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-16,
1585 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-16, Anim
);
1588 if g_Game_IsServer
and g_Game_IsNet
then
1589 MH_SEND_Effect(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-16,
1590 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-16, 1,
1594 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
1596 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1597 {$IFDEF ENABLE_SOUND}
1598 g_Sound_PlayExAt('SOUND_FIRE', tgcTX
, tgcTY
);
1600 g_GFX_OnceAnim(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1601 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+mon
.Obj
.Rect
.Height
-128, Anim
);
1604 if g_Game_IsServer
and g_Game_IsNet
then
1605 MH_SEND_Effect(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1606 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+mon
.Obj
.Rect
.Height
-128, 1,
1611 if g_Game_IsNet
then
1613 MH_SEND_GameStats();
1614 MH_SEND_CoopStats();
1621 // Åñëè àêòèâèðîâàí àâòîñïàâíåðîì, íå ìåíÿåì òåêñòóðó
1622 if actType
= ACTIVATE_CUSTOM
then
1627 if (tgcSpawnItemType
in [ITEM_MEDKIT_SMALL
..ITEM_MAX
]) then
1630 if (tgcDelay
> 0) and (actType
<> ACTIVATE_CUSTOM
) then
1632 AutoSpawn
:= not AutoSpawn
;
1634 // Àâòîñïàâíåð ïåðåêëþ÷åí - ìåíÿåì òåêñòóðó
1638 if ((tgcDelay
= 0) and (actType
<> ACTIVATE_CUSTOM
))
1639 or ((tgcDelay
> 0) and (actType
= ACTIVATE_CUSTOM
)) then
1640 if (not tgcDmonly
) or
1641 (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
1642 for k
:= 1 to tgcItemCount
do
1644 if (actType
= ACTIVATE_CUSTOM
) and (tgcDelay
> 0) then
1645 SpawnCooldown
:= -1; // Çàäåðæêà âûñòàâèòñÿ èòåìîì ïðè óíè÷òîæåíèè
1646 if (tgcMax
> 0) and (SpawnedCount
>= tgcMax
) then
1649 iid
:= g_Items_Create(tgcTX
, tgcTY
,
1650 tgcSpawnItemType
, tgcGravity
, False, True);
1654 it
:= g_Items_ByIdx(iid
);
1655 it
.SpawnTrigger
:= ID
;
1656 if tgcMax
> 0 then Inc(SpawnedCount
);
1659 EFFECT_TELEPORT
: begin
1660 it
:= g_Items_ByIdx(iid
);
1661 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
1663 Anim
:= TAnimation
.Create(FramesID
, False, 3);
1664 {$IFDEF ENABLE_SOUND}
1665 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', tgcTX
, tgcTY
);
1667 g_GFX_OnceAnim(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1668 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-32, Anim
);
1671 if g_Game_IsServer
and g_Game_IsNet
then
1672 MH_SEND_Effect(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1673 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-32, 1,
1676 EFFECT_RESPAWN
: begin
1677 it
:= g_Items_ByIdx(iid
);
1678 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
1680 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1681 {$IFDEF ENABLE_SOUND}
1682 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', tgcTX
, tgcTY
);
1684 g_GFX_OnceAnim(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-16,
1685 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-16, Anim
);
1688 if g_Game_IsServer
and g_Game_IsNet
then
1689 MH_SEND_Effect(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-16,
1690 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-16, 1,
1694 it
:= g_Items_ByIdx(iid
);
1695 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
1697 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1698 {$IFDEF ENABLE_SOUND}
1699 g_Sound_PlayExAt('SOUND_FIRE', tgcTX
, tgcTY
);
1701 g_GFX_OnceAnim(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1702 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+it
.Obj
.Rect
.Height
-128, Anim
);
1705 if g_Game_IsServer
and g_Game_IsNet
then
1706 MH_SEND_Effect(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1707 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+it
.Obj
.Rect
.Height
-128, 1,
1712 if g_Game_IsNet
then
1713 MH_SEND_ItemSpawn(True, iid
);
1720 // Åñëè àêòèâèðîâàí àâòîñïàâíåðîì, íå ìåíÿåì òåêñòóðó
1721 if actType
= ACTIVATE_CUSTOM
then
1727 // Ìåíÿåì ìóçûêó, åñëè åñòü íà ÷òî:
1728 if (Trigger
.tgcMusicName
<> '') then
1730 {$IFDEF ENABLE_SOUND}
1731 gMusic
.SetByName(Trigger
.tgcMusicName
);
1732 gMusic
.SpecPause
:= True;
1735 gMusicName
:= Trigger
.tgcMusicName
;
1739 case Trigger
.tgcMusicAction
of
1740 {$IFDEF ENABLE_SOUND}
1741 TRIGGER_MUSIC_ACTION_STOP
: // Âûêëþ÷èòü
1742 gMusic
.SpecPause
:= True; // Ïàóçà
1743 TRIGGER_MUSIC_ACTION_PLAY
: // Âêëþ÷èòü
1744 if gMusic
.SpecPause
then // Áûëà íà ïàóçå => èãðàòü
1745 gMusic
.SpecPause
:= False
1746 else // Èãðàëà => ñíà÷àëà
1747 gMusic
.SetPosition(0);
1749 TRIGGER_MUSIC_ACTION_STOP
:
1750 gMusicPause
:= True;
1751 TRIGGER_MUSIC_ACTION_PLAY
:
1753 gMusicPause
:= False
1765 {$IFDEF ENABLE_SOUND}
1766 if g_Game_IsNet
then
1767 MH_SEND_TriggerMusic(gMusic
.Name
, gMusic
.IsPlaying
, gMusic
.GetPosition
, gMusic
.SpecPause
or gMusic
.IsPaused
, ID
);
1769 if g_Game_IsNet
then
1770 MH_SEND_TriggerMusic(gMusicName
, gMusicPlay
, gMusicPos
, gMusicPause
or not gMusicPlay
);
1776 pAngle
:= -DegToRad(tgcAngle
);
1777 Result
:= tr_Push(ActivateUID
,
1778 Floor(Cos(pAngle
)*tgcForce
),
1779 Floor(Sin(pAngle
)*tgcForce
),
1787 // Ïðèáàâèòü èëè îòíÿòü î÷êî
1788 if (tgcScoreAction
in [TRIGGER_SCORE_ACTION_ADD
, TRIGGER_SCORE_ACTION_SUB
]) and (tgcScoreCount
> 0) then
1790 // Ñâîåé èëè ÷óæîé êîìàíäå
1791 if (tgcScoreTeam
in [TRIGGER_SCORE_TEAM_MINE_RED
, TRIGGER_SCORE_TEAM_MINE_BLUE
]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
1793 p
:= g_Player_Get(ActivateUID
);
1794 if ((tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_RED
))
1795 or ((tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_BLUE
)) then
1797 Inc(gTeamStat
[TEAM_RED
].Score
, tgcScoreCount
); // Red Scores
1801 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1803 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_OWN
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1804 if g_Game_IsServer
and g_Game_IsNet
then
1805 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '+r');
1808 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_ENEMY
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1809 if g_Game_IsServer
and g_Game_IsNet
then
1810 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '+re');
1816 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1817 if g_Game_IsServer
and g_Game_IsNet
then
1818 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_RED
);
1821 if ((tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_RED
))
1822 or ((tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_BLUE
)) then
1824 Dec(gTeamStat
[TEAM_RED
].Score
, tgcScoreCount
); // Red Fouls
1828 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1830 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_OWN
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1831 if g_Game_IsServer
and g_Game_IsNet
then
1832 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '-r');
1835 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_ENEMY
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1836 if g_Game_IsServer
and g_Game_IsNet
then
1837 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '-re');
1843 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1844 if g_Game_IsServer
and g_Game_IsNet
then
1845 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_RED
);
1848 if ((tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_BLUE
))
1849 or ((tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_RED
)) then
1851 Inc(gTeamStat
[TEAM_BLUE
].Score
, tgcScoreCount
); // Blue Scores
1855 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1857 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_OWN
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1858 if g_Game_IsServer
and g_Game_IsNet
then
1859 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '+b');
1862 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_ENEMY
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1863 if g_Game_IsServer
and g_Game_IsNet
then
1864 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '+be');
1870 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1871 if g_Game_IsServer
and g_Game_IsNet
then
1872 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_BLUE
);
1875 if ((tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_BLUE
))
1876 or ((tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_RED
)) then
1878 Dec(gTeamStat
[TEAM_BLUE
].Score
, tgcScoreCount
); // Blue Fouls
1882 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1884 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_OWN
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1885 if g_Game_IsServer
and g_Game_IsNet
then
1886 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '-b');
1889 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_ENEMY
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1890 if g_Game_IsServer
and g_Game_IsNet
then
1891 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '-be');
1897 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1898 if g_Game_IsServer
and g_Game_IsNet
then
1899 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_BLUE
);
1902 Result
:= (p
.Team
= TEAM_RED
) or (p
.Team
= TEAM_BLUE
);
1904 // Êàêîé-òî êîíêðåòíîé êîìàíäå
1905 if tgcScoreTeam
in [TRIGGER_SCORE_TEAM_FORCE_RED
, TRIGGER_SCORE_TEAM_FORCE_BLUE
] then
1907 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_RED
) then
1909 Inc(gTeamStat
[TEAM_RED
].Score
, tgcScoreCount
); // Red Scores
1913 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_TEAM
], [_lc
[I_PLAYER_SCORE_RED
], tgcScoreCount
]), True);
1914 if g_Game_IsServer
and g_Game_IsNet
then
1915 MH_SEND_GameEvent(NET_EV_SCORE
, tgcScoreCount
shl 16, '+tr');
1920 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1921 if g_Game_IsServer
and g_Game_IsNet
then
1922 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_RED
);
1925 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_RED
) then
1927 Dec(gTeamStat
[TEAM_RED
].Score
, tgcScoreCount
); // Red Fouls
1931 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_TEAM
], [_lc
[I_PLAYER_SCORE_RED
], tgcScoreCount
]), True);
1932 if g_Game_IsServer
and g_Game_IsNet
then
1933 MH_SEND_GameEvent(NET_EV_SCORE
, tgcScoreCount
shl 16, '-tr');
1938 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1939 if g_Game_IsServer
and g_Game_IsNet
then
1940 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_RED
);
1943 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_BLUE
) then
1945 Inc(gTeamStat
[TEAM_BLUE
].Score
, tgcScoreCount
); // Blue Scores
1949 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_TEAM
], [_lc
[I_PLAYER_SCORE_BLUE
], tgcScoreCount
]), True);
1950 if g_Game_IsServer
and g_Game_IsNet
then
1951 MH_SEND_GameEvent(NET_EV_SCORE
, tgcScoreCount
shl 16, '+tb');
1956 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1957 if g_Game_IsServer
and g_Game_IsNet
then
1958 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_BLUE
);
1961 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_BLUE
) then
1963 Dec(gTeamStat
[TEAM_BLUE
].Score
, tgcScoreCount
); // Blue Fouls
1967 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_TEAM
], [_lc
[I_PLAYER_SCORE_BLUE
], tgcScoreCount
]), True);
1968 if g_Game_IsServer
and g_Game_IsNet
then
1969 MH_SEND_GameEvent(NET_EV_SCORE
, tgcScoreCount
shl 16, '-tb');
1974 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1975 if g_Game_IsServer
and g_Game_IsNet
then
1976 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_BLUE
);
1983 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_WIN
) and (gGameSettings
.ScoreLimit
> 0) then
1985 // Ñâîåé èëè ÷óæîé êîìàíäû
1986 if (tgcScoreTeam
in [TRIGGER_SCORE_TEAM_MINE_RED
, TRIGGER_SCORE_TEAM_MINE_BLUE
]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
1988 p
:= g_Player_Get(ActivateUID
);
1989 if ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_RED
)) // Red Wins
1990 or ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_BLUE
)) then
1992 if gTeamStat
[TEAM_RED
].Score
< SmallInt(gGameSettings
.ScoreLimit
) then
1994 gTeamStat
[TEAM_RED
].Score
:= gGameSettings
.ScoreLimit
;
1998 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
2000 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
2001 if g_Game_IsServer
and g_Game_IsNet
then
2002 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wr');
2005 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
2006 if g_Game_IsServer
and g_Game_IsNet
then
2007 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wre');
2014 if ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_BLUE
)) // Blue Wins
2015 or ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_RED
)) then
2017 if gTeamStat
[TEAM_BLUE
].Score
< SmallInt(gGameSettings
.ScoreLimit
) then
2019 gTeamStat
[TEAM_BLUE
].Score
:= gGameSettings
.ScoreLimit
;
2023 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
2025 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
2026 if g_Game_IsServer
and g_Game_IsNet
then
2027 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wb');
2030 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
2031 if g_Game_IsServer
and g_Game_IsNet
then
2032 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wbe');
2040 // Êàêîé-òî êîíêðåòíîé êîìàíäû
2041 if tgcScoreTeam
in [TRIGGER_SCORE_TEAM_FORCE_RED
, TRIGGER_SCORE_TEAM_FORCE_BLUE
] then
2043 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_RED
) then // Red Wins
2045 if gTeamStat
[TEAM_RED
].Score
< SmallInt(gGameSettings
.ScoreLimit
) then
2047 gTeamStat
[TEAM_RED
].Score
:= gGameSettings
.ScoreLimit
;
2051 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_BLUE
) then // Blue Wins
2053 if gTeamStat
[TEAM_BLUE
].Score
< SmallInt(gGameSettings
.ScoreLimit
) then
2055 gTeamStat
[TEAM_BLUE
].Score
:= gGameSettings
.ScoreLimit
;
2062 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_LOOSE
) and (gGameSettings
.ScoreLimit
> 0) then
2064 // Ñâîåé èëè ÷óæîé êîìàíäû
2065 if (tgcScoreTeam
in [TRIGGER_SCORE_TEAM_MINE_RED
, TRIGGER_SCORE_TEAM_MINE_BLUE
]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
2067 p
:= g_Player_Get(ActivateUID
);
2068 if ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_BLUE
)) // Red Wins
2069 or ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_RED
)) then
2070 if gTeamStat
[TEAM_RED
].Score
< SmallInt(gGameSettings
.ScoreLimit
) then
2072 gTeamStat
[TEAM_RED
].Score
:= gGameSettings
.ScoreLimit
;
2075 if tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
then
2077 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
2078 if g_Game_IsServer
and g_Game_IsNet
then
2079 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wre');
2082 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
2083 if g_Game_IsServer
and g_Game_IsNet
then
2084 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wr');
2089 if ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_RED
)) // Blue Wins
2090 or ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_BLUE
)) then
2091 if gTeamStat
[TEAM_BLUE
].Score
< SmallInt(gGameSettings
.ScoreLimit
) then
2093 gTeamStat
[TEAM_BLUE
].Score
:= gGameSettings
.ScoreLimit
;
2096 if tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
then
2098 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
2099 if g_Game_IsServer
and g_Game_IsNet
then
2100 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wbe');
2103 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
2104 if g_Game_IsServer
and g_Game_IsNet
then
2105 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wb');
2111 // Êàêîé-òî êîíêðåòíîé êîìàíäû
2112 if tgcScoreTeam
in [TRIGGER_SCORE_TEAM_FORCE_BLUE
, TRIGGER_SCORE_TEAM_FORCE_RED
] then
2114 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_BLUE
) then // Red Wins
2116 if gTeamStat
[TEAM_RED
].Score
< SmallInt(gGameSettings
.ScoreLimit
) then
2118 gTeamStat
[TEAM_RED
].Score
:= gGameSettings
.ScoreLimit
;
2122 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_RED
) then // Blue Wins
2124 if gTeamStat
[TEAM_BLUE
].Score
< SmallInt(gGameSettings
.ScoreLimit
) then
2126 gTeamStat
[TEAM_BLUE
].Score
:= gGameSettings
.ScoreLimit
;
2132 if Result
then begin
2137 if g_Game_IsServer
and g_Game_IsNet
then
2144 Result
:= tr_Message(tgcKind
, tgcText
,
2145 tgcMsgDest
, tgcMsgTime
,
2150 TRIGGER_DAMAGE
, TRIGGER_HEALTH
:
2153 UIDType
:= g_GetUIDType(ActivateUID
);
2154 if (UIDType
= UID_PLAYER
) or (UIDType
= UID_MONSTER
) then
2160 // Âñïîìèíàåì, àêòèâèðîâàë ëè îí ìåíÿ ðàíüøå
2161 for idx
:= 0 to High(Activators
) do
2162 if Activators
[idx
].UID
= ActivateUID
then
2168 begin // Âèäèì åãî âïåðâûå
2170 SetLength(Activators
, Length(Activators
) + 1);
2171 k
:= High(Activators
);
2172 Activators
[k
].UID
:= ActivateUID
;
2174 begin // Óæå âèäåëè åãî
2175 // Åñëè èíòåðâàë îòêëþ÷¸í, íî îí âñ¸ åù¸ â çîíå ïîðàæåíèÿ, äà¸ì åìó âðåìÿ
2176 if (tgcInterval
= 0) and (Activators
[k
].TimeOut
> 0) then
2177 Activators
[k
].TimeOut
:= 65535;
2178 // Òàéìàóò ïðîø¸ë - ðàáîòàåì
2179 Result
:= Activators
[k
].TimeOut
= 0;
2188 p
:= g_Player_Get(ActivateUID
);
2192 // Íàíîñèì óðîí èãðîêó
2193 if (TriggerType
= TRIGGER_DAMAGE
) and (tgcAmount
> 0) then
2195 // Êèñëîòíûé óðîí íå íàíîñèòñÿ êîãäà åñòü êîñòþì
2196 // "Âîäÿíîé" óðîí íå íàíîñèòñÿ êîãäà åñòü êèñëîðîä
2197 if not (((tgcKind
= HIT_ACID
) and (p
.FPowerups
[MR_SUIT
] > gTime
)) or
2198 ((tgcKind
= HIT_WATER
) and (p
.Air
> 0))) then
2199 p
.Damage(tgcAmount
, 0, 0, 0, tgcKind
);
2200 if (tgcKind
= HIT_FLAME
) then p
.CatchFire(0);
2204 if (TriggerType
= TRIGGER_HEALTH
) and (tgcAmount
> 0) then
2205 if p
.Heal(tgcAmount
, not tgcHealMax
) and (not tgcSilent
) then
2207 {$IFDEF ENABLE_SOUND}
2208 g_Sound_PlayExAt('SOUND_ITEM_GETITEM', p
.Obj
.X
, p
.Obj
.Y
);
2210 if g_Game_IsServer
and g_Game_IsNet
then
2211 MH_SEND_Sound(p
.Obj
.X
, p
.Obj
.Y
, 'SOUND_ITEM_GETITEM');
2217 m
:= g_Monsters_ByUID(ActivateUID
);
2221 // Íàíîñèì óðîí ìîíñòðó
2222 if (TriggerType
= TRIGGER_DAMAGE
) and (tgcAmount
> 0) then
2224 m
.Damage(tgcAmount
, 0, 0, 0, tgcKind
);
2225 if (tgcKind
= HIT_FLAME
) then m
.CatchFire(0);
2229 if (TriggerType
= TRIGGER_HEALTH
) and (tgcAmount
> 0) then
2230 if m
.Heal(tgcAmount
) and (not tgcSilent
) then
2232 {$IFDEF ENABLE_SOUND}
2233 g_Sound_PlayExAt('SOUND_ITEM_GETITEM', m
.Obj
.X
, m
.Obj
.Y
);
2235 if g_Game_IsServer
and g_Game_IsNet
then
2236 MH_SEND_Sound(m
.Obj
.X
, m
.Obj
.Y
, 'SOUND_ITEM_GETITEM');
2240 // Íàçíà÷àåì âðåìÿ ñëåäóþùåãî âîçäåéñòâèÿ
2244 Activators
[k
].TimeOut
:= idx
2246 Activators
[k
].TimeOut
:= 65535;
2254 if ShotSightTime
> 0 then
2257 // put this at the beginning so it doesn't trigger itself
2258 TimeOut
:= tgcWait
+ 1;
2262 pAngle
:= -DegToRad(tgcAngle
);
2263 xd
:= wx
+ Round(Cos(pAngle
) * 32.0);
2264 yd
:= wy
+ Round(Sin(pAngle
) * 32.0);
2267 case tgcShotTarget
of
2268 TRIGGER_SHOT_TARGET_MON
: // monsters
2269 //TODO: accelerate this!
2270 g_Mons_ForEachAlive(monsShotTarget
);
2272 TRIGGER_SHOT_TARGET_PLR
: // players
2273 if gPlayers
<> nil then
2274 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2275 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2276 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2278 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2279 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2280 TargetUID
:= gPlayers
[idx
].UID
;
2284 TRIGGER_SHOT_TARGET_RED
: // red team
2285 if gPlayers
<> nil then
2286 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2287 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2288 (gPlayers
[idx
].Team
= TEAM_RED
) and
2289 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2291 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2292 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2293 TargetUID
:= gPlayers
[idx
].UID
;
2297 TRIGGER_SHOT_TARGET_BLUE
: // blue team
2298 if gPlayers
<> nil then
2299 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2300 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2301 (gPlayers
[idx
].Team
= TEAM_BLUE
) and
2302 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2304 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2305 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2306 TargetUID
:= gPlayers
[idx
].UID
;
2310 TRIGGER_SHOT_TARGET_MONPLR
: // monsters then players
2312 //TODO: accelerate this!
2313 g_Mons_ForEachAlive(monsShotTargetMonPlr
);
2315 if (TargetUID
= 0) and (gPlayers
<> nil) then
2316 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2317 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2318 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2320 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2321 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2322 TargetUID
:= gPlayers
[idx
].UID
;
2327 TRIGGER_SHOT_TARGET_PLRMON
: // players then monsters
2329 if gPlayers
<> nil then
2330 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2331 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2332 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2334 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2335 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2336 TargetUID
:= gPlayers
[idx
].UID
;
2339 if TargetUID
= 0 then
2341 //TODO: accelerate this!
2342 g_Mons_ForEachAlive(monShotTargetPlrMon
);
2347 if (tgcShotTarget
<> TRIGGER_SHOT_TARGET_NONE
) or
2348 (tgcShotType
<> TRIGGER_SHOT_REV
) then
2349 TargetUID
:= ActivateUID
;
2353 if (tgcShotTarget
= TRIGGER_SHOT_TARGET_NONE
) or (TargetUID
> 0) or
2354 ((tgcShotTarget
> TRIGGER_SHOT_TARGET_NONE
) and (TargetUID
= 0)) then
2357 if (tgcSight
= 0) or
2358 (tgcShotTarget
= TRIGGER_SHOT_TARGET_NONE
) or
2359 (TargetUID
= ShotSightTarget
) then
2360 MakeShot(Trigger
, wx
, wy
, xd
, yd
, TargetUID
)
2363 ShotSightTime
:= tgcSight
;
2364 ShotSightTargetN
:= TargetUID
;
2365 if tgcShotType
= TRIGGER_SHOT_BFG
then
2367 {$IFDEF ENABLE_SOUND}
2368 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', wx
, wy
);
2370 if g_Game_IsNet
and g_Game_IsServer
then
2371 MH_SEND_Sound(wx
, wy
, 'SOUND_WEAPON_STARTFIREBFG');
2384 TRIGGER_EFFECT_POS_CENTER
:
2386 wx
:= X
+ Width
div 2;
2387 wy
:= Y
+ Height
div 2;
2389 TRIGGER_EFFECT_POS_AREA
:
2391 wx
:= X
+ Random(Width
);
2392 wy
:= Y
+ Random(Height
);
2395 wx
:= X
+ Width
div 2;
2396 wy
:= Y
+ Height
div 2;
2401 if tgcSpreadL
> 0 then xd
-= Random(tgcSpreadL
+1);
2402 if tgcSpreadR
> 0 then xd
+= Random(tgcSpreadR
+1);
2403 if tgcSpreadU
> 0 then yd
-= Random(tgcSpreadU
+1);
2404 if tgcSpreadD
> 0 then yd
+= Random(tgcSpreadD
+1);
2405 tr_MakeEffect(wx
, wy
, xd
, yd
,
2406 tgcFXType
, tgcFXSubType
,
2407 tgcFXRed
, tgcFXGreen
, tgcFXBlue
, True, True);
2416 if Result
{and (Trigger.TexturePanel <> -1)} then
2418 g_Map_SwitchTextureGUID({Trigger.TexturePanelType,} Trigger
.TexturePanelGUID
, IfThen(animonce
, 2, 1));
2423 function g_Triggers_CreateWithMapIndex (aTrigger
: TTrigger
; arridx
, mapidx
: Integer): DWORD
;
2425 triggers
: TDynField
;
2427 triggers
:= gCurrentMap
['trigger'];
2428 if (triggers
= nil) then raise Exception
.Create('LOAD: map has no triggers');
2429 if (mapidx
< 0) or (mapidx
>= triggers
.count
) then raise Exception
.Create('LOAD: invalid map trigger index');
2430 aTrigger
.mapIndex
:= mapidx
;
2431 result
:= g_Triggers_Create(aTrigger
, triggers
.itemAt
[mapidx
], arridx
);
2435 function g_Triggers_Create (aTrigger
: TTrigger
; trec
: TDynRecord
; forceInternalIndex
: Integer=-1): DWORD
;
2442 if (tgscope
= nil) then tgscope
:= TTrigScope
.Create();
2443 if (tgclist
= nil) then tgclist
:= TMyConstList
.Create();
2445 // Íå ñîçäàâàòü âûõîä, åñëè èãðà áåç âûõîäà
2446 if (aTrigger
.TriggerType
= TRIGGER_EXIT
) and
2447 (not (TGameOption
.ALLOW_EXIT
in gGameSettings
.Options
)) then
2449 aTrigger
.TriggerType
:= TRIGGER_NONE
;
2452 // Åñëè ìîíñòðû çàïðåùåíû, îòìåíÿåì òðèããåð
2453 if (aTrigger
.TriggerType
= TRIGGER_SPAWNMONSTER
) and
2454 (not (TGameOption
.MONSTERS
in gGameSettings
.Options
)) and
2455 (gGameSettings
.GameType
<> GT_SINGLE
) then
2457 aTrigger
.TriggerType
:= TRIGGER_NONE
;
2460 // Ñ÷èòàåì êîëè÷åñòâî ñåêðåòîâ íà êàðòå
2461 if (aTrigger
.TriggerType
= TRIGGER_SECRET
) then gSecretsCount
+= 1;
2463 if (forceInternalIndex
< 0) then
2465 find_id
:= FindTrigger();
2469 olen
:= Length(gTriggers
);
2470 if (forceInternalIndex
>= olen
) then
2472 SetLength(gTriggers
, forceInternalIndex
+1);
2473 for f
:= olen
to High(gTriggers
) do
2475 gTriggers
[f
].TriggerType
:= TRIGGER_NONE
;
2476 gTriggers
[f
].trigDataRec
:= nil;
2477 gTriggers
[f
].exoInit
:= nil;
2478 gTriggers
[f
].exoThink
:= nil;
2479 gTriggers
[f
].exoCheck
:= nil;
2480 gTriggers
[f
].exoAction
:= nil;
2481 gTriggers
[f
].userVars
:= nil;
2484 f
:= forceInternalIndex
;
2485 gTriggers
[f
].trigDataRec
.Free();
2486 gTriggers
[f
].exoInit
.Free();
2487 gTriggers
[f
].exoThink
.Free();
2488 gTriggers
[f
].exoCheck
.Free();
2489 gTriggers
[f
].exoAction
.Free();
2490 gTriggers
[f
].userVars
.Free();
2491 gTriggers
[f
].trigDataRec
:= nil;
2492 gTriggers
[f
].exoInit
:= nil;
2493 gTriggers
[f
].exoThink
:= nil;
2494 gTriggers
[f
].exoCheck
:= nil;
2495 gTriggers
[f
].exoAction
:= nil;
2496 gTriggers
[f
].userVars
:= nil;
2497 find_id
:= DWORD(forceInternalIndex
);
2499 gTriggers
[find_id
] := aTrigger
;
2500 ptg
:= @gTriggers
[find_id
];
2502 ptg
.mapId
:= trec
.id
;
2503 // clone trigger data
2504 if (trec
.trigRec
= nil) then
2506 ptg
.trigDataRec
:= nil;
2508 if (ptg
.TriggerType
<> TRIGGER_SECRET
) then
2510 e_LogWritefln('trigger of type %s has no triggerdata; wtf?!', [ptg
.TriggerType
], TMsgType
.Warning
);
2515 ptg
.trigDataRec
:= trec
.trigRec
.clone(nil);
2521 // if this type of trigger exists both on the client and on the server
2522 // use an uniform numeration
2524 if (ptg
.TriggerType
= TRIGGER_SOUND
) then
2526 Inc(gTriggerClientID
);
2527 ClientID
:= gTriggerClientID
;
2531 PlayerCollide
:= False;
2535 SoundPlayCount
:= 0;
2536 {$IFDEF ENABLE_SOUND}
2547 // update cached trigger variables
2548 trigUpdateCacheData(ptg
^, ptg
.trigDataRec
);
2550 ptg
.userVars
:= nil;
2553 ptg
.exoThink
:= TExprBase
.parseStatList(tgclist
, VarToStr(trec
.user
['exoma_think']));
2555 on e
: TExomaParseException
do
2557 conwritefln('*** ERROR parsing exoma_think (%s,%s): %s [%s]', [e
.tokLine
, e
.tokCol
, e
.message, VarToStr(trec
.user
['exoma_think'])]);
2558 ptg
.exoThink
:= nil;
2562 ptg
.exoCheck
:= TExprBase
.parse(tgclist
, VarToStr(trec
.user
['exoma_check']));
2564 on e
: TExomaParseException
do
2566 conwritefln('*** ERROR parsing exoma_check (%s,%s): %s [%s]', [e
.tokLine
, e
.tokCol
, e
.message, VarToStr(trec
.user
['exoma_check'])]);
2567 ptg
.exoCheck
:= nil;
2571 ptg
.exoAction
:= TExprBase
.parseStatList(tgclist
, VarToStr(trec
.user
['exoma_action']));
2573 on e
: TExomaParseException
do
2575 conwritefln('*** ERROR parsing exoma_action (%s,%s): %s [%s]', [e
.tokLine
, e
.tokCol
, e
.message, VarToStr(trec
.user
['exoma_action'])]);
2576 ptg
.exoAction
:= nil;
2580 ptg
.exoInit
:= TExprBase
.parseStatList(tgclist
, VarToStr(trec
.user
['exoma_init']));
2582 on e
: TExomaParseException
do
2584 conwritefln('*** ERROR parsing exoma_init (%s,%s): %s [%s]', [e
.tokLine
, e
.tokCol
, e
.message, VarToStr(trec
.user
['exoma_init'])]);
2589 if (forceInternalIndex
< 0) and (ptg
.exoInit
<> nil) then
2591 //conwritefln('executing trigger init: [%s]', [gTriggers[find_id].exoInit.toString()]);
2594 ptg
.exoInit
.value(tgscope
);
2598 conwritefln('*** trigger exoactivate error: %s', [ptg
.exoInit
.toString()]);
2603 {$IFDEF ENABLE_SOUND}
2604 // Çàãðóæàåì çâóê, åñëè ýòî òðèããåð "Çâóê"
2605 if (ptg
.TriggerType
= TRIGGER_SOUND
) and (ptg
.tgcSoundName
<> '') then
2607 // Åùå íåò òàêîãî çâóêà
2608 if not g_Sound_Exists(ptg
.tgcSoundName
) then
2610 fn
:= e_GetResourcePath(WadDirs
, ptg
.tgcSoundName
, g_ExtractWadName(gMapInfo
.Map
));
2611 //e_LogWritefln('loading trigger sound ''%s''', [fn]);
2612 if not g_Sound_CreateWADEx(ptg
.tgcSoundName
, fn
) then
2613 g_FatalError(Format(_lc
[I_GAME_ERROR_TR_SOUND
], [fn
, ptg
.tgcSoundName
]));
2616 // Ñîçäàåì îáúåêò çâóêà
2619 Sound
:= TPlayableSound
.Create();
2620 if not Sound
.SetByName(ptg
.tgcSoundName
) then
2625 // Çàãðóæàåì ìóçûêó, åñëè ýòî òðèããåð "Ìóçûêà"
2626 if (ptg
.TriggerType
= TRIGGER_MUSIC
) and (ptg
.tgcMusicName
<> '') then
2628 // Åùå íåò òàêîé ìóçûêè
2629 if not g_Sound_Exists(ptg
.tgcMusicName
) then
2631 fn
:= e_GetResourcePath(WadDirs
, ptg
.tgcMusicName
, g_ExtractWadName(gMapInfo
.Map
));
2632 if not g_Sound_CreateWADEx(ptg
.tgcMusicName
, fn
, True) then
2633 g_FatalError(Format(_lc
[I_GAME_ERROR_TR_SOUND
], [fn
, ptg
.tgcMusicName
]));
2638 // Çàãðóæàåì äàííûå òðèããåðà "Òóðåëü"
2639 if (ptg
.TriggerType
= TRIGGER_SHOT
) then
2645 ShotSightTimeout
:= 0;
2646 ShotSightTarget
:= 0;
2647 ShotSightTargetN
:= 0;
2648 ShotAmmoCount
:= ptg
.tgcAmmo
;
2649 ShotReloadTime
:= 0;
2657 // sorry; grid doesn't support recursive queries, so we have to do this
2659 TSimpleMonsterList
= specialize TSimpleList
<TMonster
>;
2662 tgMonsList
: TSimpleMonsterList
;
2664 procedure g_Triggers_Update();
2667 Affected
: array of Integer;
2670 function monsNear (mon
: TMonster
): Boolean;
2672 result
:= false; // don't stop
2674 gTriggers[a].ActivateUID := mon.UID;
2675 ActivateTrigger(gTriggers[a], ACTIVATE_MONSTERCOLLIDE);
2677 tgMonsList
.append(mon
);
2684 if (tgMonsList
= nil) then tgMonsList
:= TSimpleMonsterList
.Create();
2686 if gTriggers
= nil then Exit
;
2687 if gLMSRespawn
> LMS_RESPAWN_NONE
then Exit
; // don't update triggers at all
2689 ms
:= GetTickCount64();
2691 SetLength(Affected
, 0);
2693 for a
:= 0 to High(gTriggers
) do
2694 with gTriggers
[a
] do
2696 if TriggerType
<> TRIGGER_NONE
then
2698 // Óìåíüøàåì âðåìÿ äî çàêðûòèÿ äâåðè (îòêðûòèÿ ëîâóøêè)
2699 if DoorTime
> 0 then DoorTime
:= DoorTime
- 1;
2700 // Óìåíüøàåì âðåìÿ îæèäàíèÿ ïîñëå íàæàòèÿ
2701 if PressTime
> 0 then PressTime
:= PressTime
- 1;
2702 // Ïðîâåðÿåì èãðîêîâ è ìîíñòðîâ, êîòîðûõ ðàíåå çàïîìíèëè:
2703 if (TriggerType
= TRIGGER_DAMAGE
) or (TriggerType
= TRIGGER_HEALTH
) then
2705 for b
:= 0 to High(Activators
) do
2707 // Óìåíüøàåì âðåìÿ äî ïîâòîðíîãî âîçäåéñòâèÿ:
2708 if Activators
[b
].TimeOut
> 0 then
2710 Dec(Activators
[b
].TimeOut
);
2716 // Ñ÷èòàåì, ÷òî îáúåêò ïîêèíóë çîíó äåéñòâèÿ òðèããåðà
2717 if (tgcInterval
= 0) and (Activators
[b
].TimeOut
< 65530) then Activators
[b
].TimeOut
:= 0;
2721 // Îáðàáàòûâàåì ñïàâíåðû
2722 if Enabled
and AutoSpawn
then
2724 if SpawnCooldown
= 0 then
2726 // Åñëè ïðèøëî âðåìÿ, ñïàâíèì ìîíñòðà
2727 if (TriggerType
= TRIGGER_SPAWNMONSTER
) and (tgcDelay
> 0) then
2730 ActivateTrigger(gTriggers
[a
], ACTIVATE_CUSTOM
);
2732 // Åñëè ïðèøëî âðåìÿ, ñïàâíèì ïðåäìåò
2733 if (TriggerType
= TRIGGER_SPAWNITEM
) and (tgcDelay
> 0) then
2736 ActivateTrigger(gTriggers
[a
], ACTIVATE_CUSTOM
);
2741 // Óìåíüøàåì âðåìÿ îæèäàíèÿ
2746 // Îáðàáàòûâàåì ñîáûòèÿ òðèããåðà "Òóðåëü"
2747 if TriggerType
= TRIGGER_SHOT
then
2749 if ShotPanelTime
> 0 then
2752 if ShotPanelTime
= 0 then g_Map_SwitchTextureGUID({ShotPanelType,} trigPanelGUID
);
2754 if ShotSightTime
> 0 then
2757 if ShotSightTime
= 0 then ShotSightTarget
:= ShotSightTargetN
;
2759 if ShotSightTimeout
> 0 then
2761 Dec(ShotSightTimeout
);
2762 if ShotSightTimeout
= 0 then ShotSightTarget
:= 0;
2764 if ShotReloadTime
> 0 then
2766 Dec(ShotReloadTime
);
2767 if ShotReloadTime
= 0 then ShotAmmoCount
:= tgcAmmo
;
2771 // Òðèããåð "Çâóê" óæå îòûãðàë, åñëè íóæíî åùå - ïåðåçàïóñêàåì
2772 {$IFDEF ENABLE_SOUND}
2773 if Enabled
and (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) then
2775 if (SoundPlayCount
> 0) and (not Sound
.IsPlaying()) then
2777 if tgcPlayCount
> 0 then Dec(SoundPlayCount
); (* looped sound if zero *)
2779 Sound
.PlayVolumeAtRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
2781 Sound
.PlayPanVolume((tgcPan
- 127.0) / 128.0, tgcVolume
/ 255.0);
2782 if Sound
.IsPlaying() and g_Game_IsNet
and g_Game_IsServer
then
2783 MH_SEND_TriggerSound(ClientID
, Sound
.IsPlaying(), Sound
.GetPosition(), SoundPlayCount
);
2787 if Enabled
and (TriggerType
= TRIGGER_SOUND
) then
2790 SoundPos
:= SoundPos
+ (ms
- prevSoundUpdateMs
);
2791 // XXX: Sound never stopped automatically due to unknown length
2792 // so SoundPlayCount never updated and sound played only once.
2793 if (SoundPlayCount
> 0) and (not SoundPlay
) then
2795 if tgcPlayCount
> 0 then
2796 Dec(SoundPlayCount
);
2797 if SoundPlay
and g_Game_IsNet
and g_Game_IsServer
then
2798 MH_SEND_TriggerSound(ClientID
, SoundPlay
, SoundPos
, SoundPlayCount
)
2803 // Òðèããåð "Ëîâóøêà" - ïîðà îòêðûâàòü
2804 if (TriggerType
= TRIGGER_TRAP
) and (DoorTime
= 0) and (g_Map_PanelByGUID(trigPanelGUID
) <> nil) then
2806 tr_OpenDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
2810 // Òðèããåð "Äâåðü 5 ñåê" - ïîðà çàêðûâàòü
2811 if (TriggerType
= TRIGGER_DOOR5
) and (DoorTime
= 0) and (g_Map_PanelByGUID(trigPanelGUID
) <> nil) then
2813 pan
:= g_Map_PanelByGUID(trigPanelGUID
);
2814 if (pan
<> nil) and pan
.isGWall
then
2817 if {gWalls[trigPanelID].Enabled} pan
.Enabled
then
2823 // Ïîêà îòêðûòà - çàêðûâàåì
2824 if tr_CloseDoor(trigPanelGUID
, tgcSilent
, tgcD2d
) then DoorTime
:= -1;
2829 // Òðèããåð - ðàñøèðèòåëü èëè ïåðåêëþ÷àòåëü, è ïðîøëà çàäåðæêà, è íàæàëè íóæíîå ÷èñëî ðàç:
2830 if (TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
]) and
2831 (PressTime
= 0) and (PressCount
>= tgcPressCount
) then
2833 // Ñáðàñûâàåì çàäåðæêó àêòèâàöèè:
2835 // Ñáðàñûâàåì ñ÷åò÷èê íàæàòèé:
2836 if tgcPressCount
> 0 then PressCount
-= tgcPressCount
else PressCount
:= 0;
2838 // Îïðåäåëÿåì èçìåíÿåìûå èì òðèããåðû:
2839 for b
:= 0 to High(gTriggers
) do
2841 if g_Collide(tgcTX
, tgcTY
, tgcTWidth
, tgcTHeight
, gTriggers
[b
].X
, gTriggers
[b
].Y
,
2842 gTriggers
[b
].Width
, gTriggers
[b
].Height
) and
2843 ((b
<> a
) or (tgcWait
> 0)) then
2844 begin // Can be self-activated, if there is Data.Wait
2845 if (not tgcExtRandom
) or gTriggers
[b
].Enabled
then
2847 SetLength(Affected
, Length(Affected
) + 1);
2848 Affected
[High(Affected
)] := b
;
2854 // if we have panelid, assume that it will switch the moving platform
2855 pan
:= g_Map_PanelByGUID(trigPanelGUID
);
2856 if (pan
<> nil) then
2859 TRIGGER_PRESS
: pan
.movingActive
:= true; // what to do here?
2860 TRIGGER_ON
: pan
.movingActive
:= true;
2861 TRIGGER_OFF
: pan
.movingActive
:= false;
2862 TRIGGER_ONOFF
: pan
.movingActive
:= not pan
.movingActive
;
2864 if not tgcSilent
and (Length(tgcSound
) > 0) then
2866 {$IFDEF ENABLE_SOUND}
2867 g_Sound_PlayExAt(tgcSound
, X
, Y
);
2869 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, tgcSound
);
2873 // Âûáèðàåì îäèí èç òðèããåðîâ äëÿ ðàñøèðèòåëÿ, åñëè âêëþ÷åí ðàíäîì:
2874 if (TriggerType
= TRIGGER_PRESS
) and tgcExtRandom
then
2876 if (Length(Affected
) > 0) then
2878 b
:= Affected
[Random(Length(Affected
))];
2879 gTriggers
[b
].ActivateUID
:= gTriggers
[a
].ActivateUID
;
2880 ActivateTrigger(gTriggers
[b
], 0);
2883 else //  ïðîòèâíîì ñëó÷àå ðàáîòàåì êàê îáû÷íî:
2885 for i
:= 0 to High(Affected
) do
2891 gTriggers
[b
].ActivateUID
:= gTriggers
[a
].ActivateUID
;
2892 ActivateTrigger(gTriggers
[b
], 0);
2896 gTriggers
[b
].Enabled
:= True;
2900 gTriggers
[b
].Enabled
:= False;
2901 gTriggers
[b
].TimeOut
:= 0;
2902 if gTriggers
[b
].AutoSpawn
then
2904 gTriggers
[b
].AutoSpawn
:= False;
2905 gTriggers
[b
].SpawnCooldown
:= 0;
2910 gTriggers
[b
].Enabled
:= not gTriggers
[b
].Enabled
;
2911 if not gTriggers
[b
].Enabled
then
2913 gTriggers
[b
].TimeOut
:= 0;
2914 if gTriggers
[b
].AutoSpawn
then
2916 gTriggers
[b
].AutoSpawn
:= False;
2917 gTriggers
[b
].SpawnCooldown
:= 0;
2924 SetLength(Affected
, 0);
2927 // Óìåíüøàåì âðåìÿ äî âîçìîæíîñòè ïîâòîðíîé àêòèâàöèè:
2930 TimeOut
:= TimeOut
- 1;
2931 Continue
; // ×òîáû íå ïîòåðÿòü 1 åäèíèöó çàäåðæêè
2934 // Íèæå èäóò òèïû àêòèâàöèè, åñëè òðèããåð îòêëþ÷¸í - èä¸ì äàëüøå
2939 if ByteBool(ActivateType
and ACTIVATE_PLAYERCOLLIDE
) and
2941 if gPlayers
<> nil then
2942 for b
:= 0 to High(gPlayers
) do
2943 if gPlayers
[b
] <> nil then
2945 // Æèâ, åñòü íóæíûå êëþ÷è è îí ðÿäîì:
2946 if alive
and ((gTriggers
[a
].Keys
and GetKeys
) = gTriggers
[a
].Keys
) and
2947 Collide(X
, Y
, Width
, Height
) then
2949 gTriggers
[a
].ActivateUID
:= UID
;
2951 if (gTriggers
[a
].TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) and
2953 { Don't activate sound/music again if player is here }
2955 ActivateTrigger(gTriggers
[a
], ACTIVATE_PLAYERCOLLIDE
);
2958 { TODO 5 : àêòèâàöèÿ ìîíñòðàìè òðèããåðîâ ñ êëþ÷àìè }
2960 if ByteBool(ActivateType
and ACTIVATE_MONSTERCOLLIDE
) and
2961 ByteBool(ActivateType
and ACTIVATE_NOMONSTER
) and
2962 (TimeOut
= 0) and (Keys
= 0) then
2964 // Åñëè "Ìîíñòð áëèçêî" è "Ìîíñòðîâ íåò",
2965 // çàïóñêàåì òðèããåð íà ñòàðòå êàðòû è ñíèìàåì îáà ôëàãà
2966 ActivateType
:= ActivateType
and not (ACTIVATE_MONSTERCOLLIDE
or ACTIVATE_NOMONSTER
);
2967 gTriggers
[a
].ActivateUID
:= 0;
2968 ActivateTrigger(gTriggers
[a
], 0);
2972 if ByteBool(ActivateType
and ACTIVATE_MONSTERCOLLIDE
) and
2973 (TimeOut
= 0) and (Keys
= 0) then // Åñëè íå íóæíû êëþ÷è
2975 //g_Mons_ForEach(monsNear);
2978 g_Mons_ForEachAt(gTriggers
[a
].X
, gTriggers
[a
].Y
, gTriggers
[a
].Width
, gTriggers
[a
].Height
, monsNear
);
2979 for mon
in tgMonsList
do
2981 gTriggers
[a
].ActivateUID
:= mon
.UID
;
2982 ActivateTrigger(gTriggers
[a
], ACTIVATE_MONSTERCOLLIDE
);
2984 tgMonsList
.reset(); // just in case
2988 if ByteBool(ActivateType
and ACTIVATE_NOMONSTER
) and
2989 (TimeOut
= 0) and (Keys
= 0) then
2990 if not g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then
2992 gTriggers
[a
].ActivateUID
:= 0;
2993 ActivateTrigger(gTriggers
[a
], ACTIVATE_NOMONSTER
);
2997 PlayerCollide
:= g_CollidePlayer(X
, Y
, Width
, Height
);
3000 prevSoundUpdateMs
:= ms
;
3003 procedure g_Triggers_Press(ID
: DWORD
; ActivateType
: Byte; ActivateUID
: Word = 0);
3005 if (ID
>= Length(gTriggers
)) then exit
;
3006 gTriggers
[ID
].ActivateUID
:= ActivateUID
;
3007 ActivateTrigger(gTriggers
[ID
], ActivateType
);
3010 function g_Triggers_PressR(X
, Y
: Integer; Width
, Height
: Word; UID
: Word;
3011 ActivateType
: Byte; IgnoreList
: DWArray
= nil): DWArray
;
3019 if gTriggers
= nil then Exit
;
3021 case g_GetUIDType(UID
) of
3025 p
:= g_Player_Get(UID
);
3033 for a
:= 0 to High(gTriggers
) do
3034 if (gTriggers
[a
].TriggerType
<> TRIGGER_NONE
) and
3035 (gTriggers
[a
].TimeOut
= 0) and
3036 (not InDWArray(a
, IgnoreList
)) and
3037 ((gTriggers
[a
].Keys
and k
) = gTriggers
[a
].Keys
) and
3038 ByteBool(gTriggers
[a
].ActivateType
and ActivateType
) then
3039 if g_Collide(X
, Y
, Width
, Height
,
3040 gTriggers
[a
].X
, gTriggers
[a
].Y
,
3041 gTriggers
[a
].Width
, gTriggers
[a
].Height
) then
3043 gTriggers
[a
].ActivateUID
:= UID
;
3044 if ActivateTrigger(gTriggers
[a
], ActivateType
) then
3046 SetLength(Result
, Length(Result
)+1);
3047 Result
[High(Result
)] := a
;
3052 procedure g_Triggers_PressL(X1
, Y1
, X2
, Y2
: Integer; UID
: DWORD
; ActivateType
: Byte);
3058 if gTriggers
= nil then Exit
;
3060 case g_GetUIDType(UID
) of
3064 p
:= g_Player_Get(UID
);
3073 for a
:= 0 to High(gTriggers
) do
3074 if (gTriggers
[a
].TriggerType
<> TRIGGER_NONE
) and
3075 (gTriggers
[a
].TimeOut
= 0) and
3076 ((gTriggers
[a
].Keys
and k
) = gTriggers
[a
].Keys
) and
3077 ByteBool(gTriggers
[a
].ActivateType
and ActivateType
) then
3078 if g_CollideLine(x1
, y1
, x2
, y2
, gTriggers
[a
].X
, gTriggers
[a
].Y
,
3079 gTriggers
[a
].Width
, gTriggers
[a
].Height
) then
3081 gTriggers
[a
].ActivateUID
:= UID
;
3082 ActivateTrigger(gTriggers
[a
], ActivateType
);
3086 procedure g_Triggers_PressC(CX
, CY
: Integer; Radius
: Word; UID
: Word; ActivateType
: Byte; IgnoreTrigger
: Integer = -1);
3093 if gTriggers
= nil then
3096 case g_GetUIDType(UID
) of
3100 p
:= g_Player_Get(UID
);
3109 rsq
:= Radius
* Radius
;
3111 for a
:= 0 to High(gTriggers
) do
3112 if (gTriggers
[a
].ID
<> DWORD(IgnoreTrigger
)) and
3113 (gTriggers
[a
].TriggerType
<> TRIGGER_NONE
) and
3114 (gTriggers
[a
].TimeOut
= 0) and
3115 ((gTriggers
[a
].Keys
and k
) = gTriggers
[a
].Keys
) and
3116 ByteBool(gTriggers
[a
].ActivateType
and ActivateType
) then
3117 with gTriggers
[a
] do
3118 if g_Collide(CX
-Radius
, CY
-Radius
, 2*Radius
, 2*Radius
,
3119 X
, Y
, Width
, Height
) then
3120 if ((Sqr(CX
-X
)+Sqr(CY
-Y
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê âåðõíåìó ëåâîìó óãëó
3121 ((Sqr(CX
-X
-Width
)+Sqr(CY
-Y
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê âåðõíåìó ïðàâîìó óãëó
3122 ((Sqr(CX
-X
-Width
)+Sqr(CY
-Y
-Height
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê íèæíåìó ïðàâîìó óãëó
3123 ((Sqr(CX
-X
)+Sqr(CY
-Y
-Height
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê íèæíåìó ëåâîìó óãëó
3124 ( (CX
> (X
-Radius
)) and (CX
< (X
+Width
+Radius
)) and
3125 (CY
> Y
) and (CY
< (Y
+Height
)) ) or // Öåíòð êðóãà íåäàëåêî îò âåðòèêàëüíûõ ãðàíèö ïðÿìîóãîëüíèêà
3126 ( (CY
> (Y
-Radius
)) and (CY
< (Y
+Height
+Radius
)) and
3127 (CX
> X
) and (CX
< (X
+Width
)) ) then // Öåíòð êðóãà íåäàëåêî îò ãîðèçîíòàëüíûõ ãðàíèö ïðÿìîóãîëüíèêà
3130 ActivateTrigger(gTriggers
[a
], ActivateType
);
3134 procedure g_Triggers_OpenAll();
3139 if gTriggers
= nil then Exit
;
3142 for a
:= 0 to High(gTriggers
) do
3144 with gTriggers
[a
] do
3146 if (TriggerType
= TRIGGER_OPENDOOR
) or
3147 (TriggerType
= TRIGGER_DOOR5
) or
3148 (TriggerType
= TRIGGER_DOOR
) then
3150 tr_OpenDoor(trigPanelGUID
, True, tgcD2d
);
3151 if TriggerType
= TRIGGER_DOOR5
then DoorTime
:= 180;
3157 {$IFDEF ENABLE_SOUND}
3158 if b
then g_Sound_PlayEx('SOUND_GAME_DOOROPEN');
3162 procedure g_Triggers_DecreaseSpawner(ID
: DWORD
);
3164 if (gTriggers
<> nil) then
3166 if gTriggers
[ID
].tgcMax
> 0 then
3168 if gTriggers
[ID
].SpawnedCount
> 0 then
3169 Dec(gTriggers
[ID
].SpawnedCount
);
3171 if gTriggers
[ID
].tgcDelay
> 0 then
3173 if gTriggers
[ID
].SpawnCooldown
< 0 then
3174 gTriggers
[ID
].SpawnCooldown
:= gTriggers
[ID
].tgcDelay
;
3179 procedure g_Triggers_Free ();
3183 FreeAndNil(tgscope
);
3184 FreeAndNil(tgclist
);
3185 FreeAndNil(tgMonsList
);
3187 for a
:= 0 to High(gTriggers
) do
3189 if (gTriggers
[a
].TriggerType
= TRIGGER_SOUND
) then
3191 {$IFDEF ENABLE_SOUND}
3192 if g_Sound_Exists(gTriggers
[a
].tgcSoundName
) then
3194 g_Sound_Delete(gTriggers
[a
].tgcSoundName
);
3196 gTriggers
[a
].Sound
.Free();
3198 gTriggers
[a
].SoundPlay
:= False;
3199 gTriggers
[a
].SoundPos
:= 0;
3202 if (gTriggers
[a
].Activators
<> nil) then
3204 SetLength(gTriggers
[a
].Activators
, 0);
3206 gTriggers
[a
].trigDataRec
.Free();
3208 gTriggers
[a
].exoThink
.Free();
3209 gTriggers
[a
].exoCheck
.Free();
3210 gTriggers
[a
].exoAction
.Free();
3211 gTriggers
[a
].userVars
.Free();
3216 SetLength(gMonstersSpawned
, 0);
3220 procedure g_Triggers_SaveState (st
: TStream
);
3222 count
, actCount
: SizeUInt
;
3225 kv
: THashStrVariant
.PEntry
;
3228 // Êîëè÷åñòâî òðèããåðîâ
3229 count
:= Length(gTriggers
); // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðèããåðîâ
3230 st
.WriteDWordLE(count
);
3231 if count
= 0 then Exit
;
3233 for i
:= 0 to High(gTriggers
) do
3235 // Ñèãíàòóðà òðèããåðà
3236 utils
.writeSign(st
, 'TRGX');
3240 st
.WriteByte(gTriggers
[i
].TriggerType
);
3241 if gTriggers
[i
].TriggerType
= TRIGGER_NONE
then
3242 Continue
; // empty one
3244 // Ñïåöèàëüíûå äàííûå òðèããåðà: ïîòîì èç êàðòû îïÿòü âûòàùèì; ñîõðàíèì òîëüêî èíäåêñ
3245 st
.WriteInt32LE(gTriggers
[i
].mapIndex
);
3246 // Êîîðäèíàòû ëåâîãî âåðõíåãî óãëà
3247 st
.WriteInt32LE(gTriggers
[i
].X
);
3248 st
.WriteInt32LE(gTriggers
[i
].Y
);
3250 st
.WriteWordLE(gTriggers
[i
].Width
);
3251 st
.WriteWordLE(gTriggers
[i
].Height
);
3253 st
.WriteBool(gTriggers
[i
].Enabled
); // Âêëþ÷åí ëè òðèããåð
3254 st
.WriteByte(gTriggers
[i
].ActivateType
); // Òèï àêòèâàöèè òðèããåðà
3255 st
.WriteByte(gTriggers
[i
].Keys
); // Êëþ÷è, íåîáõîäèìûå äëÿ àêòèâàöèè
3256 st
.WriteInt32LE(gTriggers
[i
].TexturePanelGUID
); // ID ïàíåëè, òåêñòóðà êîòîðîé èçìåíèòñÿ
3257 //st.WriteWordLE(gTriggers[i].TexturePanelType); // Òèï ýòîé ïàíåëè
3259 // Âíóòðåííèé íîìåð äðóãîé ïàíåëè (ïî ñ÷àñòëèâîé ñëó÷àéíîñòè îí áóäåò ñîâïàäàòü ñ òåì, ÷òî ñîçäàíî ïðè çàãðóçêå êàðòû)
3260 st
.WriteInt32LE(gTriggers
[i
].trigPanelGUID
);
3262 st
.WriteWordLE(gTriggers
[i
].TimeOut
); // Âðåìÿ äî âîçìîæíîñòè àêòèâàöèè
3263 st
.WriteWordLE(gTriggers
[i
].ActivateUID
); // UID òîãî, êòî àêòèâèðîâàë ýòîò òðèããåð
3265 // Ñïèñîê UID-îâ îáúåêòîâ, êîòîðûå íàõîäèëèñü ïîä âîçäåéñòâèåì
3266 actCount
:= Length(gTriggers
[i
].Activators
);
3267 st
.WriteDWordLE(actCount
);
3268 for j
:= 0 to actCount
-1 do
3270 st
.WriteWordLE(gTriggers
[i
].Activators
[j
].UID
); // UID îáúåêòà
3271 st
.WriteWordLE(gTriggers
[i
].Activators
[j
].TimeOut
); // Âðåìÿ îæèäàíèÿ
3274 st
.WriteBool(gTriggers
[i
].PlayerCollide
); // Ñòîèò ëè èãðîê â îáëàñòè òðèããåðà
3275 st
.WriteInt32LE(gTriggers
[i
].DoorTime
); // Âðåìÿ äî çàêðûòèÿ äâåðè
3276 st
.WriteInt32LE(gTriggers
[i
].PressTime
); // Çàäåðæêà àêòèâàöèè
3277 st
.WriteInt32LE(gTriggers
[i
].PressCount
); // Ñ÷åò÷èê íàæàòèé
3278 st
.WriteBool(gTriggers
[i
].AutoSpawn
); // Ñïàâíåð àêòèâåí
3279 st
.WriteInt32LE(gTriggers
[i
].SpawnCooldown
); // Çàäåðæêà ñïàâíåðà
3280 st
.WriteInt32LE(gTriggers
[i
].SpawnedCount
); // Ñ÷åò÷èê ñîçäàíèÿ îáúåêòîâ
3281 st
.WriteInt32LE(gTriggers
[i
].SoundPlayCount
); // Ñêîëüêî ðàç ïðîèãðàí çâóê
3283 {$IFDEF ENABLE_SOUND}
3284 // Ïðîèãðûâàåòñÿ ëè çâóê?
3285 // BEWARE: Short-circuit evaluation matters here!
3286 b
:= (gTriggers
[i
].Sound
<> nil) and gTriggers
[i
].Sound
.IsPlaying();
3290 st
.WriteDWordLE(gTriggers
[i
].Sound
.GetPosition()); // Ïîçèöèÿ ïðîèãðûâàíèÿ çâóêà
3291 st
.WriteSingle(gTriggers
[i
].Sound
.GetVolume() / (gSoundLevel
/ 255.0)); // Ãðîìêîñòü çâóêà
3292 st
.WriteSingle(gTriggers
[i
].Sound
.GetPan()); // Ñòåðåî ñìåùåíèå çâóêà
3295 st
.WriteBool(gTriggers
[i
].SoundPlay
);
3296 if gTriggers
[i
].SoundPlay
then
3298 st
.WriteDWordLE(gTriggers
[i
].SoundPos
);
3299 // st.WriteSingle(gTriggers[i].tgcVolume / 255.0);
3300 // st.WriteSingle((gTriggers[i].tgcPan - 127) / 128.0);
3301 st
.WriteSingle(1.0);
3302 st
.WriteSingle(0.0);
3307 if gTriggers
[i
].userVars
= nil then
3313 st
.WriteDWordLE(gTriggers
[i
].userVars
.count
); // FIXME: check for overflow
3314 for kv
in gTriggers
[i
].userVars
.byKeyValue
do
3316 //writeln('<', kv.key, '>:<', VarToStr(kv.value), '>');
3317 utils
.writeStr(st
, kv
.key
);
3318 t
:= LongInt(varType(kv
.value
));
3321 varString
: utils
.writeStr(st
, AnsiString(kv
.value
));
3322 varBoolean
: st
.WriteByte(Byte(kv
.value
));
3323 varShortInt
: st
.WriteInt32LE(kv
.value
); // FIXME: must be WriteInt8().
3324 varSmallint
: st
.WriteInt32LE(kv
.value
); // FIXME: must be WriteInt16LE().
3325 varInteger
: st
.WriteInt32LE(kv
.value
);
3326 //varInt64: Mem.WriteInt(Integer(kv.value));
3327 varByte
: st
.WriteInt32LE(kv
.value
); // FIXME: must be WriteByte().
3328 varWord
: st
.WriteInt32LE(kv
.value
); // FIXME: must be WriteWordLE().
3329 varLongWord
: st
.WriteInt32LE(kv
.value
); // FIXME: must be WriteDWordLE().
3331 else Raise Exception
.CreateFmt('cannot save uservar ''%s''', [kv
.key
]);
3339 procedure g_Triggers_LoadState (st
: TStream
);
3341 count
, actCount
, i
, j
, k
, uvcount
: SizeUInt
;
3353 // Êîëè÷åñòâî òðèããåðîâ
3354 count
:= st
.ReadDWordLE();
3355 if count
= 0 then Exit
;
3356 if count
> 1024*1024 then
3357 Raise XStreamError
.Create('invalid trigger count');
3359 for k
:= 0 to count
-1 do
3361 // Ñèãíàòóðà òðèããåðà
3362 if not utils
.checkSign(st
, 'TRGX') then
3363 Raise XStreamError
.Create('invalid trigger signature');
3364 if st
.ReadByte() <> 0 then
3365 Raise XStreamError
.Create('invalid trigger version');
3368 Trig
.TriggerType
:= st
.ReadByte();
3369 if Trig
.TriggerType
= TRIGGER_NONE
then
3370 Continue
; // empty one
3372 // Ñïåöèàëüíûå äàííûå òðèããåðà: èíäåêñ â gCurrentMap.field['triggers']
3373 mapIndex
:= st
.ReadInt32LE();
3374 i
:= g_Triggers_CreateWithMapIndex(Trig
, k
, mapIndex
);
3375 // Êîîðäèíàòû ëåâîãî âåðõíåãî óãëà
3376 gTriggers
[i
].X
:= st
.ReadInt32LE();
3377 gTriggers
[i
].Y
:= st
.ReadInt32LE();
3379 gTriggers
[i
].Width
:= st
.ReadWordLE();
3380 gTriggers
[i
].Height
:= st
.ReadWordLE();
3382 gTriggers
[i
].Enabled
:= st
.ReadBool(); // Âêëþ÷åí ëè òðèããåð
3383 gTriggers
[i
].ActivateType
:= st
.ReadByte(); // Òèï àêòèâàöèè òðèããåðà
3384 gTriggers
[i
].Keys
:= st
.ReadByte(); // Êëþ÷è, íåîáõîäèìûå äëÿ àêòèâàöèè
3385 gTriggers
[i
].TexturePanelGUID
:= st
.ReadInt32LE(); // ID ïàíåëè, òåêñòóðà êîòîðîé èçìåíèòñÿ
3386 //st.ReadWord(gTriggers[i].TexturePanelType); // Òèï ýòîé ïàíåëè
3388 // Âíóòðåííèé íîìåð äðóãîé ïàíåëè (ïî ñ÷àñòëèâîé ñëó÷àéíîñòè îí áóäåò ñîâïàäàòü ñ òåì, ÷òî ñîçäàíî ïðè çàãðóçêå êàðòû)
3389 gTriggers
[i
].trigPanelGUID
:= st
.ReadInt32LE();
3391 gTriggers
[i
].TimeOut
:= st
.ReadWordLE(); // Âðåìÿ äî âîçìîæíîñòè àêòèâàöèè
3392 gTriggers
[i
].ActivateUID
:= st
.ReadWordLE(); // UID òîãî, êòî àêòèâèðîâàë ýòîò òðèããåð
3394 // Ñïèñîê UID-îâ îáúåêòîâ, êîòîðûå íàõîäèëèñü ïîä âîçäåéñòâèåì
3395 actCount
:= st
.ReadDWordLE();
3396 if actCount
> 1024*1024 then
3397 Raise XStreamError
.Create('invalid activated object count');
3398 if actCount
> 0 then
3400 SetLength(gTriggers
[i
].Activators
, actCount
);
3401 for j
:= 0 to actCount
-1 do
3403 gTriggers
[i
].Activators
[j
].UID
:= st
.ReadWordLE(); // UID îáúåêòà
3404 gTriggers
[i
].Activators
[j
].TimeOut
:= st
.ReadWordLE(); // Âðåìÿ îæèäàíèÿ
3408 gTriggers
[i
].PlayerCollide
:= st
.ReadBool(); // Ñòîèò ëè èãðîê â îáëàñòè òðèããåðà
3409 gTriggers
[i
].DoorTime
:= st
.ReadInt32LE(); // Âðåìÿ äî çàêðûòèÿ äâåðè
3410 gTriggers
[i
].PressTime
:= st
.ReadInt32LE(); // Çàäåðæêà àêòèâàöèè
3411 gTriggers
[i
].PressCount
:= st
.ReadInt32LE(); // Ñ÷åò÷èê íàæàòèé
3412 gTriggers
[i
].AutoSpawn
:= st
.ReadBool(); // Ñïàâíåð àêòèâåí
3413 gTriggers
[i
].SpawnCooldown
:= st
.ReadInt32LE(); // Çàäåðæêà ñïàâíåðà
3414 gTriggers
[i
].SpawnedCount
:= st
.ReadInt32LE(); // Ñ÷åò÷èê ñîçäàíèÿ îáúåêòîâ
3415 gTriggers
[i
].SoundPlayCount
:= st
.ReadInt32LE(); // Ñêîëüêî ðàç ïðîèãðàí çâóê
3417 // Ïðîèãðûâàåòñÿ ëè çâóê?
3418 if st
.ReadBool() then
3420 dw
:= st
.ReadDWordLE(); // Ïîçèöèÿ ïðîèãðûâàíèÿ çâóêà
3421 vol
:= st
.ReadSingle(); // Ãðîìêîñòü çâóêà
3422 pan
:= st
.ReadSingle(); // Ñòåðåî ñìåùåíèå çâóêà
3424 {$IFDEF ENABLE_SOUND}
3425 // Çàïóñêàåì çâóê, åñëè åñòü
3426 if gTriggers
[i
].Sound
<> nil then
3428 gTriggers
[i
].Sound
.PlayPanVolume(pan
, vol
);
3429 gTriggers
[i
].Sound
.Pause(True);
3430 gTriggers
[i
].Sound
.SetPosition(dw
);
3433 gTriggers
[i
].SoundPlay
:= False;
3434 gTriggers
[i
].SoundPos
:= dw
;
3435 // ignore volume and pan
3440 FreeAndNil(gTriggers
[i
].userVars
);
3441 uvcount
:= st
.ReadDWordLE();
3442 if uvcount
> 1024*1024 then
3443 Raise XStreamError
.Create('invalid number of user vars in trigger');
3446 gTriggers
[i
].userVars
:= THashStrVariant
.Create();
3450 uvname
:= utils
.readStr(st
);
3451 vt
:= st
.ReadInt32LE();
3453 varString
: vv
:= utils
.readStr(st
);
3454 varBoolean
: vv
:= st
.ReadBool();
3455 varShortInt
: vv
:= ShortInt(st
.ReadInt32LE()); // FIXME: must be ReadInt8().
3456 varSmallint
: vv
:= SmallInt(st
.ReadInt32LE()); // FIXME: must be ReadInt16LE().
3457 varInteger
: vv
:= LongInt(st
.ReadInt32LE());
3458 varByte
: vv
:= Byte(st
.ReadInt32LE()); // FIXME: must be ReadByte().
3459 varWord
: vv
:= Word(st
.ReadInt32LE()); // FIXME: must be ReadWordLE().
3460 varLongWord
: vv
:= LongWord(st
.ReadInt32LE()); // FIXME: must be ReadDWordLE().
3461 else Raise Exception
.CreateFmt('cannot load uservar ''%s''', [uvname
]);
3463 gTriggers
[i
].userVars
.put(uvname
, vv
);
3471 prevSoundUpdateMs
:= GetTickCount64();