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}
21 SysUtils
, Variants
, Classes
,
22 MAPDEF
, e_graphics
, g_basic
, g_sound
,
23 xdynrec
, hashtable
, exoma
;
42 TexturePanelGUID
: Integer;
43 //TexturePanelType: Word;
47 Activators
: array of TActivator
;
48 PlayerCollide
: Boolean;
52 SoundPlayCount
: Integer;
53 Sound
: TPlayableSound
;
55 SpawnCooldown
: Integer;
56 SpawnedCount
: Integer;
57 //ShotPanelType: Word;
58 ShotPanelTime
: Integer;
59 ShotSightTime
: Integer;
60 ShotSightTimeout
: Integer;
61 ShotSightTarget
: Word;
62 ShotSightTargetN
: Word;
64 ShotReloadTime
: Integer;
66 mapId
: AnsiString; // trigger id, from map
67 mapIndex
: Integer; // index in fields['trigger'], used in save/load
68 trigPanelGUID
: Integer;
70 trigDataRec
: TDynRecord
; // triggerdata; owned by trigger (cloned)
71 exoInit
, exoThink
, exoCheck
, exoAction
: TExprBase
;
73 userVars
: THashStrVariant
;
75 {$INCLUDE ../shared/mapdef_tgc_def.inc}
78 function trigCenter (): TDFPoint
; inline;
81 function g_Triggers_Create (aTrigger
: TTrigger
; trec
: TDynRecord
; forceInternalIndex
: Integer=-1): DWORD
;
82 procedure g_Triggers_Update();
83 procedure g_Triggers_Press(ID
: DWORD
; ActivateType
: Byte; ActivateUID
: Word = 0);
84 function g_Triggers_PressR(X
, Y
: Integer; Width
, Height
: Word; UID
: Word;
85 ActivateType
: Byte; IgnoreList
: DWArray
= nil): DWArray
;
86 procedure g_Triggers_PressL(X1
, Y1
, X2
, Y2
: Integer; UID
: DWORD
; ActivateType
: Byte);
87 procedure g_Triggers_PressC(CX
, CY
: Integer; Radius
: Word; UID
: Word; ActivateType
: Byte; IgnoreTrigger
: Integer = -1);
88 procedure g_Triggers_OpenAll();
89 procedure g_Triggers_DecreaseSpawner(ID
: DWORD
);
90 procedure g_Triggers_Free();
91 procedure g_Triggers_SaveState (st
: TStream
);
92 procedure g_Triggers_LoadState (st
: TStream
);
96 gTriggerClientID
: Integer = 0;
97 gTriggers
: array of TTrigger
;
98 gSecretsCount
: Integer = 0;
99 gMonstersSpawned
: array of LongInt = nil;
106 g_player
, g_map
, g_panel
, g_gfx
, g_game
, g_textures
,
107 g_console
, g_monsters
, g_items
, g_phys
, g_weapons
,
108 wadreader
, g_main
, e_log
, g_language
, e_res
,
109 g_options
, g_net
, g_netmsg
, utils
, xparser
, xstreams
;
112 TRIGGER_SIGNATURE
= $58475254; // 'TRGX'
115 {$INCLUDE ../shared/mapdef_tgc_impl.inc}
118 // ////////////////////////////////////////////////////////////////////////// //
120 TTrigScope
= class(TExprScope
)
123 monsprops
: TPropHash
;
124 platprops
: TPropHash
;
130 constructor Create ();
131 destructor Destroy (); override;
133 function getObj (const aname
: AnsiString): TObject
; override;
134 function getField (obj
: TObject
; const afldname
: AnsiString): Variant; override;
135 procedure setField (obj
: TObject
; const afldname
: AnsiString; var aval
: Variant); override;
139 // ////////////////////////////////////////////////////////////////////////// //
141 TMyConstList
= class(TExprConstList
)
143 function valid (const cname
: AnsiString): Boolean; override;
144 function get (const cname
: AnsiString; out v
: Variant): Boolean; override;
148 // ////////////////////////////////////////////////////////////////////////// //
149 function TMyConstList
.valid (const cname
: AnsiString): Boolean;
151 //writeln('CHECK: ''', cname, '''');
153 (cname
= 'player') or
158 function TMyConstList
.get (const cname
: AnsiString; out v
: Variant): Boolean;
163 //if (cname = 'answer') then begin v := LongInt(42); result := true; exit; end;
165 if (gCurrentMap
= nil) then exit
;
166 for eidx
:= 0 to gCurrentMap
.mapdef
.ebsTypeCount
-1 do
168 ebs
:= gCurrentMap
.mapdef
.ebsTypeAt
[eidx
];
169 if ebs
.has
[cname
] then
171 //writeln('FOUND: ''', cname, '''');
180 // ////////////////////////////////////////////////////////////////////////// //
181 constructor TTrigScope
.Create ();
183 plrprops
:= TPropHash
.Create(TPlayer
, 'e');
184 monsprops
:= TPropHash
.Create(TMonster
, 'e');
185 platprops
:= TPropHash
.Create(TPanel
, 'e');
190 destructor TTrigScope
.Destroy ();
199 function TTrigScope
.getObj (const aname
: AnsiString): TObject
;
201 if (aname
= 'player') then result
:= gPlayers
[0] //FIXME
202 else if (aname
= 'self') or (aname
= 'this') then result
:= TObject(Pointer(PtrUInt(1)))
203 else result
:= inherited getObj(aname
);
207 function TTrigScope
.getField (obj
: TObject
; const afldname
: AnsiString): Variant;
209 if (obj
= gPlayers
[0]) then
211 if plrprops
.get(obj
, afldname
, result
) then exit
;
213 else if (obj
= TObject(Pointer(PtrUInt(1)))) then
215 if (me
<> nil) and (me
.userVars
<> nil) then
217 if me
.userVars
.get(afldname
, result
) then exit
;
220 result
:= inherited getField(obj
, afldname
);
224 procedure TTrigScope
.setField (obj
: TObject
; const afldname
: AnsiString; var aval
: Variant);
226 if (obj
= gPlayers
[0]) then
228 if plrprops
.put(obj
, afldname
, aval
) then exit
;
230 else if (obj
= TObject(Pointer(PtrUInt(1)))) then
234 if (Length(afldname
) > 4) and (afldname
[1] = 'u') and (afldname
[2] = 's') and
235 (afldname
[3] = 'e') and (afldname
[4] = 'r') then
237 if (me
.userVars
= nil) then me
.userVars
:= THashStrVariant
.Create();
238 me
.userVars
.put(afldname
, aval
);
243 inherited setField(obj
, afldname
, aval
);
247 // ////////////////////////////////////////////////////////////////////////// //
249 tgscope
: TTrigScope
= nil;
250 tgclist
: TMyConstList
= nil;
253 // ////////////////////////////////////////////////////////////////////////// //
254 function TTrigger
.trigCenter (): TDFPoint
; inline;
256 result
:= TDFPoint
.Create(x
+width
div 2, y
+height
div 2);
260 function FindTrigger (): DWORD
;
264 olen
:= Length(gTriggers
);
266 for i
:= 0 to olen
-1 do
268 if gTriggers
[i
].TriggerType
= TRIGGER_NONE
then begin result
:= i
; exit
; end;
271 SetLength(gTriggers
, olen
+8);
274 for i
:= result
to High(gTriggers
) do
276 gTriggers
[i
].TriggerType
:= TRIGGER_NONE
;
277 gTriggers
[i
].trigDataRec
:= nil;
278 gTriggers
[i
].exoInit
:= nil;
279 gTriggers
[i
].exoThink
:= nil;
280 gTriggers
[i
].exoCheck
:= nil;
281 gTriggers
[i
].exoAction
:= nil;
282 gTriggers
[i
].userVars
:= nil;
287 function tr_CloseDoor (PanelGUID
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
294 pan
:= g_Map_PanelByGUID(PanelGUID
);
295 if (pan
= nil) or not pan
.isGWall
then exit
; //!FIXME!TRIGANY!
296 PanelID
:= pan
.arrIdx
;
300 with gWalls
[PanelID
] do
302 if g_CollidePlayer(X
, Y
, Width
, Height
) or g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then Exit
;
307 g_Sound_PlayExAt('SOUND_GAME_DOORCLOSE', X
, Y
);
308 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOORCLOSE');
310 g_Map_EnableWallGUID(PanelGUID
);
317 if (gDoorMap
= nil) then exit
;
320 for a
:= 0 to High(gDoorMap
) do
322 for b
:= 0 to High(gDoorMap
[a
]) do
324 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
330 if (c
<> -1) then break
;
332 if (c
= -1) then exit
;
334 for b
:= 0 to High(gDoorMap
[c
]) do
336 with gWalls
[gDoorMap
[c
, b
]] do
338 if g_CollidePlayer(X
, Y
, Width
, Height
) or g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then exit
;
344 for b
:= 0 to High(gDoorMap
[c
]) do
346 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
348 with gWalls
[PanelID
] do
350 g_Sound_PlayExAt('SOUND_GAME_DOORCLOSE', X
, Y
);
351 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOORCLOSE');
358 for b
:= 0 to High(gDoorMap
[c
]) do
360 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
362 g_Map_EnableWall_XXX(gDoorMap
[c
, b
]);
370 procedure tr_CloseTrap (PanelGUID
: Integer; NoSound
: Boolean; d2d
: Boolean);
373 wx
, wy
, wh
, ww
: Integer;
377 function monsDamage (mon
: TMonster
): Boolean;
379 result
:= false; // don't stop
380 if g_Obj_Collide(wx
, wy
, ww
, wh
, @mon
.Obj
) then mon
.Damage(TRAP_DAMAGE
, 0, 0, 0, HIT_TRAP
);
384 pan
:= g_Map_PanelByGUID(PanelGUID
);
388 e_LogWritefln('tr_CloseTrap: pguid=%s; NO PANEL!', [PanelGUID], MSG_WARNING);
392 e_LogWritefln('tr_CloseTrap: pguid=%s; isGWall=%s; arrIdx=%s', [PanelGUID, pan.isGWall, pan.arrIdx]);
395 if (pan
= nil) or not pan
.isGWall
then exit
; //!FIXME!TRIGANY!
396 PanelID
:= pan
.arrIdx
;
400 with gWalls
[PanelID
] do
402 if (not NoSound
) and (not Enabled
) then
404 g_Sound_PlayExAt('SOUND_GAME_SWITCH1', X
, Y
);
405 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_SWITCH1');
409 wx
:= gWalls
[PanelID
].X
;
410 wy
:= gWalls
[PanelID
].Y
;
411 ww
:= gWalls
[PanelID
].Width
;
412 wh
:= gWalls
[PanelID
].Height
;
414 with gWalls
[PanelID
] do
416 if gPlayers
<> nil then
418 for a
:= 0 to High(gPlayers
) do
420 if (gPlayers
[a
] <> nil) and gPlayers
[a
].alive
and gPlayers
[a
].Collide(X
, Y
, Width
, Height
) then
422 gPlayers
[a
].Damage(TRAP_DAMAGE
, 0, 0, 0, HIT_TRAP
);
427 //g_Mons_ForEach(monsDamage);
428 g_Mons_ForEachAliveAt(wx
, wy
, ww
, wh
, monsDamage
);
430 if not Enabled
then g_Map_EnableWallGUID(PanelGUID
);
435 if (gDoorMap
= nil) then exit
;
438 for a
:= 0 to High(gDoorMap
) do
440 for b
:= 0 to High(gDoorMap
[a
]) do
442 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
448 if (c
<> -1) then break
;
450 if (c
= -1) then exit
;
454 for b
:= 0 to High(gDoorMap
[c
]) do
456 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
458 with gWalls
[PanelID
] do
460 g_Sound_PlayExAt('SOUND_GAME_SWITCH1', X
, Y
);
461 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_SWITCH1');
468 for b
:= 0 to High(gDoorMap
[c
]) do
470 wx
:= gWalls
[gDoorMap
[c
, b
]].X
;
471 wy
:= gWalls
[gDoorMap
[c
, b
]].Y
;
472 ww
:= gWalls
[gDoorMap
[c
, b
]].Width
;
473 wh
:= gWalls
[gDoorMap
[c
, b
]].Height
;
475 with gWalls
[gDoorMap
[c
, b
]] do
477 if gPlayers
<> nil then
479 for a
:= 0 to High(gPlayers
) do
481 if (gPlayers
[a
] <> nil) and gPlayers
[a
].alive
and gPlayers
[a
].Collide(X
, Y
, Width
, Height
) then
483 gPlayers
[a
].Damage(TRAP_DAMAGE
, 0, 0, 0, HIT_TRAP
);
488 //g_Mons_ForEach(monsDamage);
489 g_Mons_ForEachAliveAt(wx
, wy
, ww
, wh
, monsDamage
);
491 if gMonsters <> nil then
492 for a := 0 to High(gMonsters) do
493 if (gMonsters[a] <> nil) and gMonsters[a].alive and
494 g_Obj_Collide(X, Y, Width, Height, @gMonsters[a].Obj) then
495 gMonsters[a].Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
498 if not Enabled
then g_Map_EnableWall_XXX(gDoorMap
[c
, b
]);
505 function tr_OpenDoor (PanelGUID
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
512 pan
:= g_Map_PanelByGUID(PanelGUID
);
513 if (pan
= nil) or not pan
.isGWall
then exit
; //!FIXME!TRIGANY!
514 PanelID
:= pan
.arrIdx
;
518 with gWalls
[PanelID
] do
524 g_Sound_PlayExAt('SOUND_GAME_DOOROPEN', X
, Y
);
525 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOOROPEN');
527 g_Map_DisableWallGUID(PanelGUID
);
534 if (gDoorMap
= nil) then exit
;
537 for a
:= 0 to High(gDoorMap
) do
539 for b
:= 0 to High(gDoorMap
[a
]) do
541 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
547 if (c
<> -1) then break
;
549 if (c
= -1) then exit
;
553 for b
:= 0 to High(gDoorMap
[c
]) do
555 if gWalls
[gDoorMap
[c
, b
]].Enabled
then
557 with gWalls
[PanelID
] do
559 g_Sound_PlayExAt('SOUND_GAME_DOOROPEN', X
, Y
);
560 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOOROPEN');
567 for b
:= 0 to High(gDoorMap
[c
]) do
569 if gWalls
[gDoorMap
[c
, b
]].Enabled
then
571 g_Map_DisableWall_XXX(gDoorMap
[c
, b
]);
579 function tr_SetLift (PanelGUID
: Integer; d
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
587 pan
:= g_Map_PanelByGUID(PanelGUID
);
588 if (pan
= nil) or not pan
.isGLift
then exit
; //!FIXME!TRIGANY!
589 PanelID
:= pan
.arrIdx
;
591 if (gLifts
[PanelID
].PanelType
= PANEL_LIFTUP
) or (gLifts
[PanelID
].PanelType
= PANEL_LIFTDOWN
) then
595 1: t
:= LIFTTYPE_DOWN
;
596 else t
:= IfThen(gLifts
[PanelID
].LiftType
= LIFTTYPE_DOWN
, LIFTTYPE_UP
, LIFTTYPE_DOWN
);
599 else if (gLifts
[PanelID
].PanelType
= PANEL_LIFTLEFT
) or (gLifts
[PanelID
].PanelType
= PANEL_LIFTRIGHT
) then
602 0: t
:= LIFTTYPE_LEFT
;
603 1: t
:= LIFTTYPE_RIGHT
;
604 else t
:= IfThen(gLifts
[PanelID
].LiftType
= LIFTTYPE_LEFT
, LIFTTYPE_RIGHT
, LIFTTYPE_LEFT
);
610 with gLifts
[PanelID
] do
612 if (LiftType
<> t
) then
614 g_Map_SetLiftGUID(PanelGUID
, t
); //???
615 //if not NoSound then g_Sound_PlayExAt('SOUND_GAME_SWITCH0', X, Y);
622 if (gLiftMap
= nil) then exit
;
625 for a
:= 0 to High(gLiftMap
) do
627 for b
:= 0 to High(gLiftMap
[a
]) do
629 if (gLiftMap
[a
, b
] = DWORD(PanelID
)) then
635 if (c
<> -1) then break
;
637 if (c
= -1) then exit
;
640 for b := 0 to High(gLiftMap[c]) do
641 if gLifts[gLiftMap[c, b]].LiftType <> t then
643 with gLifts[PanelID] do
644 g_Sound_PlayExAt('SOUND_GAME_SWITCH0', X, Y);
648 for b
:= 0 to High(gLiftMap
[c
]) do
650 with gLifts
[gLiftMap
[c
, b
]] do
652 if (LiftType
<> t
) then
654 g_Map_SetLift_XXX(gLiftMap
[c
, b
], t
);
663 function tr_SpawnShot (ShotType
: Integer; wx
, wy
, dx
, dy
: Integer; ShotSound
: Boolean; ShotTarget
: Word): Integer;
671 TextureID
:= DWORD(-1);
672 snd
:= 'SOUND_WEAPON_FIREROCKET';
678 g_Weapon_pistol(wx
, wy
, dx
, dy
, 0, True);
679 snd
:= 'SOUND_WEAPON_FIREPISTOL';
683 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_BULLET
);
684 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL1
);
690 g_Weapon_mgun(wx
, wy
, dx
, dy
, 0, True);
691 if gSoundEffectsDF
then snd
:= 'SOUND_WEAPON_FIRECGUN'
692 else snd
:= 'SOUND_WEAPON_FIREPISTOL';
696 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_BULLET
);
697 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL1
);
701 TRIGGER_SHOT_SHOTGUN
:
703 g_Weapon_Shotgun(wx
, wy
, dx
, dy
, 0, True);
704 snd
:= 'SOUND_WEAPON_FIRESHOTGUN';
708 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
709 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL2
);
715 g_Weapon_DShotgun(wx
, wy
, dx
, dy
, 0, True);
716 snd
:= 'SOUND_WEAPON_FIRESHOTGUN2';
720 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
721 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
722 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL3
);
728 g_Weapon_ball1(wx
, wy
, dx
, dy
, 0, -1, True);
729 snd
:= 'SOUND_WEAPON_FIREBALL';
734 g_Weapon_Plasma(wx
, wy
, dx
, dy
, 0, -1, True);
735 snd
:= 'SOUND_WEAPON_FIREPLASMA';
740 g_Weapon_aplasma(wx
, wy
, dx
, dy
, 0, -1, True);
741 snd
:= 'SOUND_WEAPON_FIREPLASMA';
746 g_Weapon_ball2(wx
, wy
, dx
, dy
, 0, -1, True);
747 snd
:= 'SOUND_WEAPON_FIREBALL';
752 g_Weapon_ball7(wx
, wy
, dx
, dy
, 0, -1, True);
753 snd
:= 'SOUND_WEAPON_FIREBALL';
758 g_Weapon_manfire(wx
, wy
, dx
, dy
, 0, -1, True);
759 snd
:= 'SOUND_WEAPON_FIREBALL';
764 g_Weapon_revf(wx
, wy
, dx
, dy
, 0, ShotTarget
, -1, True);
765 snd
:= 'SOUND_WEAPON_FIREREV';
770 g_Weapon_Rocket(wx
, wy
, dx
, dy
, 0, -1, True);
771 snd
:= 'SOUND_WEAPON_FIREROCKET';
776 g_Weapon_BFGShot(wx
, wy
, dx
, dy
, 0, -1, True);
777 snd
:= 'SOUND_WEAPON_FIREBFG';
782 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_ROCKET') then
784 Anim
:= TAnimation
.Create(TextureID
, False, 6);
785 Anim
.Blending
:= False;
786 g_GFX_OnceAnim(wx
-64, wy
-64, Anim
);
790 g_Weapon_Explode(wx
, wy
, 60, 0);
791 snd
:= 'SOUND_WEAPON_EXPLODEROCKET';
794 TRIGGER_SHOT_BFGEXPL
:
796 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_BFG') then
798 Anim
:= TAnimation
.Create(TextureID
, False, 6);
799 Anim
.Blending
:= False;
800 g_GFX_OnceAnim(wx
-64, wy
-64, Anim
);
804 g_Weapon_BFG9000(wx
, wy
, 0);
805 snd
:= 'SOUND_WEAPON_EXPLODEBFG';
810 g_Weapon_flame(wx
, wy
, dx
, dy
, 0, -1, True);
811 snd
:= 'SOUND_GAME_BURNING';
817 if g_Game_IsNet
and g_Game_IsServer
then
820 TRIGGER_SHOT_EXPL
: MH_SEND_Effect(wx
, wy
, Byte(ShotSound
), NET_GFX_EXPLODE
);
821 TRIGGER_SHOT_BFGEXPL
: MH_SEND_Effect(wx
, wy
, Byte(ShotSound
), NET_GFX_BFGEXPL
);
824 if Projectile
then MH_SEND_CreateShot(LastShotID
);
825 if ShotSound
then MH_SEND_Sound(wx
, wy
, snd
);
830 if ShotSound
then g_Sound_PlayExAt(snd
, wx
, wy
);
832 if Projectile
then Result
:= LastShotID
;
836 procedure MakeShot (var Trigger
: TTrigger
; wx
, wy
, dx
, dy
: Integer; TargetUID
: Word);
840 if (tgcAmmo
= 0) or ((tgcAmmo
> 0) and (ShotAmmoCount
> 0)) then
842 if (trigPanelGUID
<> -1) and (ShotPanelTime
= 0) then
844 g_Map_SwitchTextureGUID({ShotPanelType,} trigPanelGUID
);
845 ShotPanelTime
:= 4; // òèêîâ íà âñïûøêó âûñòðåëà
848 if (tgcSight
> 0) then ShotSightTimeout
:= 180; // ~= 5 ñåêóíä
850 if (ShotAmmoCount
> 0) then Dec(ShotAmmoCount
);
852 dx
+= Random(tgcAccuracy
)-Random(tgcAccuracy
);
853 dy
+= Random(tgcAccuracy
)-Random(tgcAccuracy
);
855 tr_SpawnShot(tgcShotType
, wx
, wy
, dx
, dy
, tgcShotSound
, TargetUID
);
859 if (tgcReload
> 0) and (ShotReloadTime
= 0) then
861 ShotReloadTime
:= tgcReload
; // òèêîâ íà ïåðåçàðÿäêó ïóøêè
868 procedure tr_MakeEffect (X
, Y
, VX
, VY
: Integer; T
, ST
, CR
, CG
, CB
: Byte; Silent
, Send
: Boolean);
873 if T
= TRIGGER_EFFECT_PARTICLE
then
876 TRIGGER_EFFECT_SLIQUID
:
878 if (CR
= 255) and (CG
= 0) and (CB
= 0) then g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 1, 0, 0, 0)
879 else if (CR
= 0) and (CG
= 255) and (CB
= 0) then g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 2, 0, 0, 0)
880 else if (CR
= 0) and (CG
= 0) and (CB
= 255) then g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 3, 0, 0, 0)
881 else g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 0, 0, 0, 0);
883 TRIGGER_EFFECT_LLIQUID
: g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 4, CR
, CG
, CB
);
884 TRIGGER_EFFECT_DLIQUID
: g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 5, CR
, CG
, CB
);
885 TRIGGER_EFFECT_BLOOD
: g_GFX_Blood(X
, Y
, 1, VX
, VY
, 0, 0, CR
, CG
, CB
);
886 TRIGGER_EFFECT_SPARK
: g_GFX_Spark(X
, Y
, 1, GetAngle2(VX
, VY
), 0, 0);
887 TRIGGER_EFFECT_BUBBLE
: g_GFX_Bubbles(X
, Y
, 1, 0, 0);
891 if T
= TRIGGER_EFFECT_ANIMATION
then
894 EFFECT_TELEPORT
: begin
895 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
897 Anim
:= TAnimation
.Create(FramesID
, False, 3);
898 if not Silent
then g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
899 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
902 if Send
and g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(X
, Y
, Byte(not Silent
), NET_GFX_TELE
);
904 EFFECT_RESPAWN
: begin
905 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
907 Anim
:= TAnimation
.Create(FramesID
, False, 4);
908 if not Silent
then g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
909 g_GFX_OnceAnim(X
-16, Y
-16, Anim
);
912 if Send
and g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(X
-16, Y
-16, Byte(not Silent
), NET_GFX_RESPAWN
);
915 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
917 Anim
:= TAnimation
.Create(FramesID
, False, 4);
918 if not Silent
then g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
919 g_GFX_OnceAnim(X
-32, Y
-128, Anim
);
922 if Send
and g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(X
-32, Y
-128, Byte(not Silent
), NET_GFX_FIRE
);
929 function tr_Teleport (ActivateUID
: Integer; TX
, TY
: Integer; TDir
: Integer; Silent
: Boolean; D2D
: Boolean): Boolean;
935 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then Exit
;
936 case g_GetUIDType(ActivateUID
) of
939 p
:= g_Player_Get(ActivateUID
);
940 if p
= nil then Exit
;
943 if p
.TeleportTo(TX
-(p
.Obj
.Rect
.Width
div 2), TY
-p
.Obj
.Rect
.Height
, Silent
, TDir
) then result
:= true;
947 if p
.TeleportTo(TX
, TY
, Silent
, TDir
) then result
:= true;
952 m
:= g_Monsters_ByUID(ActivateUID
);
953 if m
= nil then Exit
;
956 if m
.TeleportTo(TX
-(m
.Obj
.Rect
.Width
div 2), TY
-m
.Obj
.Rect
.Height
, Silent
, TDir
) then result
:= true;
960 if m
.TeleportTo(TX
, TY
, Silent
, TDir
) then result
:= true;
967 function tr_Push (ActivateUID
: Integer; VX
, VY
: Integer; ResetVel
: Boolean): Boolean;
973 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then exit
;
974 case g_GetUIDType(ActivateUID
) of
977 p
:= g_Player_Get(ActivateUID
);
978 if p
= nil then Exit
;
993 m
:= g_Monsters_ByUID(ActivateUID
);
994 if m
= nil then Exit
;
1010 function tr_Message (MKind
: Integer; MText
: string; MSendTo
: Integer; MTime
: Integer; ActivateUID
: Integer): Boolean;
1017 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then Exit
;
1018 msg
:= b_Text_Format(MText
);
1020 TRIGGER_MESSAGE_DEST_ME
: // activator
1022 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
1024 if g_Game_IsWatchedPlayer(ActivateUID
) then
1026 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
1027 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
1031 p
:= g_Player_Get(ActivateUID
);
1032 if g_Game_IsNet
and (p
.FClientID
>= 0) then
1034 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, p
.FClientID
)
1035 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, p
.FClientID
);
1041 TRIGGER_MESSAGE_DEST_MY_TEAM
: // activator's team
1043 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
1045 p
:= g_Player_Get(ActivateUID
);
1046 if g_Game_IsWatchedTeam(p
.Team
) then
1048 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
1049 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
1052 if g_Game_IsNet
then
1054 for i
:= Low(gPlayers
) to High(gPlayers
) do
1056 if (gPlayers
[i
].Team
= p
.Team
) and (gPlayers
[i
].FClientID
>= 0) then
1058 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
1059 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
1066 TRIGGER_MESSAGE_DEST_ENEMY_TEAM
: // activator's enemy team
1068 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
1070 p
:= g_Player_Get(ActivateUID
);
1071 if g_Game_IsWatchedTeam(p
.Team
) then
1073 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
1074 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
1077 if g_Game_IsNet
then
1079 for i
:= Low(gPlayers
) to High(gPlayers
) do
1081 if (gPlayers
[i
].Team
<> p
.Team
) and (gPlayers
[i
].FClientID
>= 0) then
1083 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
1084 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
1091 TRIGGER_MESSAGE_DEST_RED_TEAM
: // red team
1093 if g_Game_IsWatchedTeam(TEAM_RED
) then
1095 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
1096 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
1099 if g_Game_IsNet
then
1101 for i
:= Low(gPlayers
) to High(gPlayers
) do
1103 if (gPlayers
[i
].Team
= TEAM_RED
) and (gPlayers
[i
].FClientID
>= 0) then
1105 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
1106 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
1112 TRIGGER_MESSAGE_DEST_BLUE_TEAM
: // blue team
1114 if g_Game_IsWatchedTeam(TEAM_BLUE
) then
1116 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
1117 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
1120 if g_Game_IsNet
then
1122 for i
:= Low(gPlayers
) to High(gPlayers
) do
1124 if (gPlayers
[i
].Team
= TEAM_BLUE
) and (gPlayers
[i
].FClientID
>= 0) then
1126 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
1127 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
1133 TRIGGER_MESSAGE_DEST_EVERYONE
: // everyone
1135 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
1136 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
1138 if g_Game_IsNet
then
1140 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
)
1141 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
);
1148 function tr_ShotAimCheck (var Trigger
: TTrigger
; Obj
: PObj
): Boolean;
1153 if TriggerType
<> TRIGGER_SHOT
then Exit
;
1154 result
:= (tgcAim
and TRIGGER_SHOT_AIM_ALLMAP
> 0)
1155 or g_Obj_Collide(X
, Y
, Width
, Height
, Obj
);
1156 if result
and (tgcAim
and TRIGGER_SHOT_AIM_TRACE
> 0) then
1158 result
:= g_TraceVector(tgcTX
, tgcTY
,
1159 Obj
^.X
+ Obj
^.Rect
.X
+ (Obj
^.Rect
.Width
div 2),
1160 Obj
^.Y
+ Obj
^.Rect
.Y
+ (Obj
^.Rect
.Height
div 2));
1166 function ActivateTrigger (var Trigger
: TTrigger
; actType
: Byte): Boolean;
1172 idx
, k
, wx
, wy
, xd
, yd
: Integer;
1183 function monsShotTarget (mon
: TMonster
): Boolean;
1185 result
:= false; // don't stop
1186 if mon
.alive
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
1188 xd
:= mon
.GameX
+ mon
.Obj
.Rect
.Width
div 2;
1189 yd
:= mon
.GameY
+ mon
.Obj
.Rect
.Height
div 2;
1190 TargetUID
:= mon
.UID
;
1191 result
:= true; // stop
1195 function monsShotTargetMonPlr (mon
: TMonster
): Boolean;
1197 result
:= false; // don't stop
1198 if mon
.alive
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
1200 xd
:= mon
.GameX
+ mon
.Obj
.Rect
.Width
div 2;
1201 yd
:= mon
.GameY
+ mon
.Obj
.Rect
.Height
div 2;
1202 TargetUID
:= mon
.UID
;
1203 result
:= true; // stop
1207 function monShotTargetPlrMon (mon
: TMonster
): Boolean;
1209 result
:= false; // don't stop
1210 if mon
.alive
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
1212 xd
:= mon
.GameX
+ mon
.Obj
.Rect
.Width
div 2;
1213 yd
:= mon
.GameY
+ mon
.Obj
.Rect
.Height
div 2;
1214 TargetUID
:= mon
.UID
;
1215 result
:= true; // stop
1223 if g_Game_IsClient
then exit
;
1225 if not Trigger
.Enabled
then exit
;
1226 if (Trigger
.TimeOut
<> 0) and (actType
<> ACTIVATE_CUSTOM
) then exit
;
1227 if (gLMSRespawn
> LMS_RESPAWN_NONE
) then exit
;
1229 if (Trigger
.exoCheck
<> nil) then
1231 //conwritefln('exocheck: [%s]', [Trigger.exoCheck.toString()]);
1233 tgscope
.me
:= @Trigger
;
1234 tvval
:= Trigger
.exoCheck
.value(tgscope
);
1236 if not Boolean(tvval
) then exit
;
1237 except on e
: Exception
do
1240 conwritefln('trigger exocheck error: %s [%s]', [e
.message, Trigger
.exoCheck
.toString()]);
1248 coolDown
:= (actType
<> 0);
1250 if (Trigger
.exoAction
<> nil) then
1252 //conwritefln('exoactivate: [%s]', [Trigger.exoAction.toString()]);
1254 tgscope
.me
:= @Trigger
;
1255 Trigger
.exoAction
.value(tgscope
);
1257 except on e
: Exception
do
1260 conwritefln('trigger exoactivate error: %s [%s]', [e
.message, Trigger
.exoAction
.toString()]);
1271 g_Sound_PlayEx('SOUND_GAME_SWITCH0');
1272 if g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_SWITCH0');
1273 gExitByTrigger
:= True;
1274 g_Game_ExitLevel(tgcMap
);
1283 Result
:= tr_Teleport(ActivateUID
,
1284 tgcTarget
.X
, tgcTarget
.Y
,
1285 tgcDirection
, tgcSilent
,
1292 Result
:= tr_OpenDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
1298 Result
:= tr_CloseDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
1302 TRIGGER_DOOR
, TRIGGER_DOOR5
:
1304 pan
:= g_Map_PanelByGUID(trigPanelGUID
);
1305 if (pan
<> nil) and pan
.isGWall
then
1307 if gWalls
[{trigPanelID}pan
.arrIdx
].Enabled
then
1309 result
:= tr_OpenDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
1310 if (TriggerType
= TRIGGER_DOOR5
) then DoorTime
:= 180;
1314 result
:= tr_CloseDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
1317 if result
then TimeOut
:= 18;
1321 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
:
1323 tr_CloseTrap(trigPanelGUID
, tgcSilent
, tgcD2d
);
1325 if TriggerType
= TRIGGER_TRAP
then
1339 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
:
1342 if PressTime
= -1 then PressTime
:= tgcWait
;
1343 if coolDown
then TimeOut
:= 18 else TimeOut
:= 0;
1348 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
1352 p
:= g_Player_Get(ActivateUID
);
1354 Inc(gCoopSecretsFound
);
1355 if g_Game_IsNet
then
1357 MH_SEND_GameStats();
1358 MH_SEND_GameEvent(NET_EV_SECRET
, p
.UID
, '');
1364 Result
:= tr_SetLift(trigPanelGUID
, 0, tgcSilent
, tgcD2d
);
1367 if (not tgcSilent
) and Result
then begin
1368 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1370 Y
+ (Height
div 2));
1371 if g_Game_IsServer
and g_Game_IsNet
then
1372 MH_SEND_Sound(X
+ (Width
div 2),
1374 'SOUND_GAME_SWITCH0');
1380 Result
:= tr_SetLift(trigPanelGUID
, 1, tgcSilent
, tgcD2d
);
1383 if (not tgcSilent
) and Result
then begin
1384 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1386 Y
+ (Height
div 2));
1387 if g_Game_IsServer
and g_Game_IsNet
then
1388 MH_SEND_Sound(X
+ (Width
div 2),
1390 'SOUND_GAME_SWITCH0');
1396 Result
:= tr_SetLift(trigPanelGUID
, 3, tgcSilent
, tgcD2d
);
1402 if (not tgcSilent
) and Result
then begin
1403 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1405 Y
+ (Height
div 2));
1406 if g_Game_IsServer
and g_Game_IsNet
then
1407 MH_SEND_Sound(X
+ (Width
div 2),
1409 'SOUND_GAME_SWITCH0');
1416 if tgcActivateOnce
then
1419 TriggerType
:= TRIGGER_NONE
;
1427 animonce
:= tgcAnimateOnce
;
1433 if Sound
<> nil then
1435 if tgcSoundSwitch
and Sound
.IsPlaying() then
1436 begin // Íóæíî âûêëþ÷èòü, åñëè èãðàë
1438 SoundPlayCount
:= 0;
1441 else // (not Data.SoundSwitch) or (not Sound.IsPlaying())
1442 if (tgcPlayCount
> 0) or (not Sound
.IsPlaying()) then
1444 if tgcPlayCount
> 0 then
1445 SoundPlayCount
:= tgcPlayCount
1446 else // 0 - èãðàåì áåñêîíå÷íî
1447 SoundPlayCount
:= 1;
1450 if g_Game_IsNet
then MH_SEND_TriggerSound(Trigger
);
1454 TRIGGER_SPAWNMONSTER
:
1455 if (tgcSpawnMonsType
in [MONSTER_DEMON
..MONSTER_MAN
]) then
1458 if (tgcDelay
> 0) and (actType
<> ACTIVATE_CUSTOM
) then
1460 AutoSpawn
:= not AutoSpawn
;
1462 // Àâòîñïàâíåð ïåðåêëþ÷åí - ìåíÿåì òåêñòóðó
1466 if ((tgcDelay
= 0) and (actType
<> ACTIVATE_CUSTOM
))
1467 or ((tgcDelay
> 0) and (actType
= ACTIVATE_CUSTOM
)) then
1468 for k
:= 1 to tgcMonsCount
do
1470 if (actType
= ACTIVATE_CUSTOM
) and (tgcDelay
> 0) then
1471 SpawnCooldown
:= -1; // Çàäåðæêà âûñòàâèòñÿ ìîíñòðîì ïðè óíè÷òîæåíèè
1472 if (tgcMax
> 0) and (SpawnedCount
>= tgcMax
) then
1475 mon
:= g_Monsters_Create(tgcSpawnMonsType
,
1477 TDirection(tgcDirection
), True);
1482 if (tgcHealth
> 0) then
1483 mon
.SetHealth(tgcHealth
);
1484 // Óñòàíàâëèâàåì ïîâåäåíèå:
1485 mon
.MonsterBehaviour
:= tgcBehaviour
;
1486 mon
.FNoRespawn
:= True;
1487 if g_Game_IsNet
then
1488 MH_SEND_MonsterSpawn(mon
.UID
);
1489 // Èäåì èñêàòü öåëü, åñëè íàäî:
1493 if tgcSpawnMonsType
<> MONSTER_BARREL
then Inc(gTotalMonsters
);
1495 if g_Game_IsNet
then
1497 SetLength(gMonstersSpawned
, Length(gMonstersSpawned
)+1);
1498 gMonstersSpawned
[High(gMonstersSpawned
)] := mon
.UID
;
1501 mon
.SpawnTrigger
:= ID
;
1502 if tgcMax
> 0 then Inc(SpawnedCount
);
1505 EFFECT_TELEPORT
: begin
1506 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
1508 Anim
:= TAnimation
.Create(FramesID
, False, 3);
1509 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', tgcTX
, tgcTY
);
1510 g_GFX_OnceAnim(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1511 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-32, Anim
);
1514 if g_Game_IsServer
and g_Game_IsNet
then
1515 MH_SEND_Effect(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1516 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-32, 1,
1519 EFFECT_RESPAWN
: begin
1520 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
1522 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1523 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', tgcTX
, tgcTY
);
1524 g_GFX_OnceAnim(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-16,
1525 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-16, Anim
);
1528 if g_Game_IsServer
and g_Game_IsNet
then
1529 MH_SEND_Effect(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-16,
1530 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-16, 1,
1534 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
1536 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1537 g_Sound_PlayExAt('SOUND_FIRE', tgcTX
, tgcTY
);
1538 g_GFX_OnceAnim(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1539 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+mon
.Obj
.Rect
.Height
-128, Anim
);
1542 if g_Game_IsServer
and g_Game_IsNet
then
1543 MH_SEND_Effect(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1544 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+mon
.Obj
.Rect
.Height
-128, 1,
1549 if g_Game_IsNet
then
1551 MH_SEND_GameStats();
1552 MH_SEND_CoopStats();
1559 // Åñëè àêòèâèðîâàí àâòîñïàâíåðîì, íå ìåíÿåì òåêñòóðó
1560 if actType
= ACTIVATE_CUSTOM
then
1565 if (tgcSpawnItemType
in [ITEM_MEDKIT_SMALL
..ITEM_MAX
]) then
1568 if (tgcDelay
> 0) and (actType
<> ACTIVATE_CUSTOM
) then
1570 AutoSpawn
:= not AutoSpawn
;
1572 // Àâòîñïàâíåð ïåðåêëþ÷åí - ìåíÿåì òåêñòóðó
1576 if ((tgcDelay
= 0) and (actType
<> ACTIVATE_CUSTOM
))
1577 or ((tgcDelay
> 0) and (actType
= ACTIVATE_CUSTOM
)) then
1578 if (not tgcDmonly
) or
1579 (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
1580 for k
:= 1 to tgcItemCount
do
1582 if (actType
= ACTIVATE_CUSTOM
) and (tgcDelay
> 0) then
1583 SpawnCooldown
:= -1; // Çàäåðæêà âûñòàâèòñÿ èòåìîì ïðè óíè÷òîæåíèè
1584 if (tgcMax
> 0) and (SpawnedCount
>= tgcMax
) then
1587 iid
:= g_Items_Create(tgcTX
, tgcTY
,
1588 tgcSpawnItemType
, tgcGravity
, False, True);
1592 it
:= g_Items_ByIdx(iid
);
1593 it
.SpawnTrigger
:= ID
;
1594 if tgcMax
> 0 then Inc(SpawnedCount
);
1597 EFFECT_TELEPORT
: begin
1598 it
:= g_Items_ByIdx(iid
);
1599 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
1601 Anim
:= TAnimation
.Create(FramesID
, False, 3);
1602 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', tgcTX
, tgcTY
);
1603 g_GFX_OnceAnim(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1604 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-32, Anim
);
1607 if g_Game_IsServer
and g_Game_IsNet
then
1608 MH_SEND_Effect(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1609 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-32, 1,
1612 EFFECT_RESPAWN
: begin
1613 it
:= g_Items_ByIdx(iid
);
1614 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
1616 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1617 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', tgcTX
, tgcTY
);
1618 g_GFX_OnceAnim(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-16,
1619 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-16, Anim
);
1622 if g_Game_IsServer
and g_Game_IsNet
then
1623 MH_SEND_Effect(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-16,
1624 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-16, 1,
1628 it
:= g_Items_ByIdx(iid
);
1629 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
1631 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1632 g_Sound_PlayExAt('SOUND_FIRE', tgcTX
, tgcTY
);
1633 g_GFX_OnceAnim(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1634 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+it
.Obj
.Rect
.Height
-128, Anim
);
1637 if g_Game_IsServer
and g_Game_IsNet
then
1638 MH_SEND_Effect(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1639 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+it
.Obj
.Rect
.Height
-128, 1,
1644 if g_Game_IsNet
then
1645 MH_SEND_ItemSpawn(True, iid
);
1652 // Åñëè àêòèâèðîâàí àâòîñïàâíåðîì, íå ìåíÿåì òåêñòóðó
1653 if actType
= ACTIVATE_CUSTOM
then
1659 // Ìåíÿåì ìóçûêó, åñëè åñòü íà ÷òî:
1660 if (Trigger
.tgcMusicName
<> '') then
1662 gMusic
.SetByName(Trigger
.tgcMusicName
);
1663 gMusic
.SpecPause
:= True;
1667 case Trigger
.tgcMusicAction
of
1668 TRIGGER_MUSIC_ACTION_STOP
: // Âûêëþ÷èòü
1669 gMusic
.SpecPause
:= True; // Ïàóçà
1670 TRIGGER_MUSIC_ACTION_PLAY
: // Âêëþ÷èòü
1671 if gMusic
.SpecPause
then // Áûëà íà ïàóçå => èãðàòü
1672 gMusic
.SpecPause
:= False
1673 else // Èãðàëà => ñíà÷àëà
1674 gMusic
.SetPosition(0);
1682 if g_Game_IsNet
then MH_SEND_TriggerMusic
;
1687 pAngle
:= -DegToRad(tgcAngle
);
1688 Result
:= tr_Push(ActivateUID
,
1689 Floor(Cos(pAngle
)*tgcForce
),
1690 Floor(Sin(pAngle
)*tgcForce
),
1698 // Ïðèáàâèòü èëè îòíÿòü î÷êî
1699 if (tgcScoreAction
in [TRIGGER_SCORE_ACTION_ADD
, TRIGGER_SCORE_ACTION_SUB
]) and (tgcScoreCount
> 0) then
1701 // Ñâîåé èëè ÷óæîé êîìàíäå
1702 if (tgcScoreTeam
in [TRIGGER_SCORE_TEAM_MINE_RED
, TRIGGER_SCORE_TEAM_MINE_BLUE
]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
1704 p
:= g_Player_Get(ActivateUID
);
1705 if ((tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_RED
))
1706 or ((tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_BLUE
)) then
1708 Inc(gTeamStat
[TEAM_RED
].Goals
, tgcScoreCount
); // Red Scores
1712 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1714 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_OWN
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1715 if g_Game_IsServer
and g_Game_IsNet
then
1716 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '+r');
1719 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_ENEMY
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1720 if g_Game_IsServer
and g_Game_IsNet
then
1721 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '+re');
1727 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1728 if g_Game_IsServer
and g_Game_IsNet
then
1729 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_RED
);
1732 if ((tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_RED
))
1733 or ((tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_BLUE
)) then
1735 Dec(gTeamStat
[TEAM_RED
].Goals
, tgcScoreCount
); // Red Fouls
1739 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1741 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_OWN
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1742 if g_Game_IsServer
and g_Game_IsNet
then
1743 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '-r');
1746 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_ENEMY
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1747 if g_Game_IsServer
and g_Game_IsNet
then
1748 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '-re');
1754 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1755 if g_Game_IsServer
and g_Game_IsNet
then
1756 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_RED
);
1759 if ((tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_BLUE
))
1760 or ((tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_RED
)) then
1762 Inc(gTeamStat
[TEAM_BLUE
].Goals
, tgcScoreCount
); // Blue Scores
1766 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1768 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_OWN
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1769 if g_Game_IsServer
and g_Game_IsNet
then
1770 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '+b');
1773 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_ENEMY
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1774 if g_Game_IsServer
and g_Game_IsNet
then
1775 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '+be');
1781 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1782 if g_Game_IsServer
and g_Game_IsNet
then
1783 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_BLUE
);
1786 if ((tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_BLUE
))
1787 or ((tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_RED
)) then
1789 Dec(gTeamStat
[TEAM_BLUE
].Goals
, tgcScoreCount
); // Blue Fouls
1793 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1795 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_OWN
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1796 if g_Game_IsServer
and g_Game_IsNet
then
1797 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '-b');
1800 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_ENEMY
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1801 if g_Game_IsServer
and g_Game_IsNet
then
1802 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '-be');
1808 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1809 if g_Game_IsServer
and g_Game_IsNet
then
1810 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_BLUE
);
1813 Result
:= (p
.Team
= TEAM_RED
) or (p
.Team
= TEAM_BLUE
);
1815 // Êàêîé-òî êîíêðåòíîé êîìàíäå
1816 if tgcScoreTeam
in [TRIGGER_SCORE_TEAM_FORCE_RED
, TRIGGER_SCORE_TEAM_FORCE_BLUE
] then
1818 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_RED
) then
1820 Inc(gTeamStat
[TEAM_RED
].Goals
, tgcScoreCount
); // Red Scores
1824 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_TEAM
], [_lc
[I_PLAYER_SCORE_RED
], tgcScoreCount
]), True);
1825 if g_Game_IsServer
and g_Game_IsNet
then
1826 MH_SEND_GameEvent(NET_EV_SCORE
, tgcScoreCount
shl 16, '+tr');
1831 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1832 if g_Game_IsServer
and g_Game_IsNet
then
1833 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_RED
);
1836 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_RED
) then
1838 Dec(gTeamStat
[TEAM_RED
].Goals
, tgcScoreCount
); // Red Fouls
1842 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_TEAM
], [_lc
[I_PLAYER_SCORE_RED
], tgcScoreCount
]), True);
1843 if g_Game_IsServer
and g_Game_IsNet
then
1844 MH_SEND_GameEvent(NET_EV_SCORE
, tgcScoreCount
shl 16, '-tr');
1849 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1850 if g_Game_IsServer
and g_Game_IsNet
then
1851 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_RED
);
1854 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_BLUE
) then
1856 Inc(gTeamStat
[TEAM_BLUE
].Goals
, tgcScoreCount
); // Blue Scores
1860 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_TEAM
], [_lc
[I_PLAYER_SCORE_BLUE
], tgcScoreCount
]), True);
1861 if g_Game_IsServer
and g_Game_IsNet
then
1862 MH_SEND_GameEvent(NET_EV_SCORE
, tgcScoreCount
shl 16, '+tb');
1867 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1868 if g_Game_IsServer
and g_Game_IsNet
then
1869 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_BLUE
);
1872 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_BLUE
) then
1874 Dec(gTeamStat
[TEAM_BLUE
].Goals
, tgcScoreCount
); // Blue Fouls
1878 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_TEAM
], [_lc
[I_PLAYER_SCORE_BLUE
], tgcScoreCount
]), True);
1879 if g_Game_IsServer
and g_Game_IsNet
then
1880 MH_SEND_GameEvent(NET_EV_SCORE
, tgcScoreCount
shl 16, '-tb');
1885 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1886 if g_Game_IsServer
and g_Game_IsNet
then
1887 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_BLUE
);
1894 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_WIN
) and (gGameSettings
.GoalLimit
> 0) then
1896 // Ñâîåé èëè ÷óæîé êîìàíäû
1897 if (tgcScoreTeam
in [TRIGGER_SCORE_TEAM_MINE_RED
, TRIGGER_SCORE_TEAM_MINE_BLUE
]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
1899 p
:= g_Player_Get(ActivateUID
);
1900 if ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_RED
)) // Red Wins
1901 or ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_BLUE
)) then
1903 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1905 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1909 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1911 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1912 if g_Game_IsServer
and g_Game_IsNet
then
1913 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wr');
1916 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1917 if g_Game_IsServer
and g_Game_IsNet
then
1918 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wre');
1925 if ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_BLUE
)) // Blue Wins
1926 or ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_RED
)) then
1928 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1930 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1934 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1936 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1937 if g_Game_IsServer
and g_Game_IsNet
then
1938 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wb');
1941 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1942 if g_Game_IsServer
and g_Game_IsNet
then
1943 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wbe');
1951 // Êàêîé-òî êîíêðåòíîé êîìàíäû
1952 if tgcScoreTeam
in [TRIGGER_SCORE_TEAM_FORCE_RED
, TRIGGER_SCORE_TEAM_FORCE_BLUE
] then
1954 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_RED
) then // Red Wins
1956 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1958 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1962 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_BLUE
) then // Blue Wins
1964 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1966 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1973 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_LOOSE
) and (gGameSettings
.GoalLimit
> 0) then
1975 // Ñâîåé èëè ÷óæîé êîìàíäû
1976 if (tgcScoreTeam
in [TRIGGER_SCORE_TEAM_MINE_RED
, TRIGGER_SCORE_TEAM_MINE_BLUE
]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
1978 p
:= g_Player_Get(ActivateUID
);
1979 if ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_BLUE
)) // Red Wins
1980 or ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_RED
)) then
1981 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1983 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1986 if tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
then
1988 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1989 if g_Game_IsServer
and g_Game_IsNet
then
1990 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wre');
1993 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1994 if g_Game_IsServer
and g_Game_IsNet
then
1995 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wr');
2000 if ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_RED
)) // Blue Wins
2001 or ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_BLUE
)) then
2002 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
2004 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
2007 if tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
then
2009 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
2010 if g_Game_IsServer
and g_Game_IsNet
then
2011 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wbe');
2014 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
2015 if g_Game_IsServer
and g_Game_IsNet
then
2016 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wb');
2022 // Êàêîé-òî êîíêðåòíîé êîìàíäû
2023 if tgcScoreTeam
in [TRIGGER_SCORE_TEAM_FORCE_BLUE
, TRIGGER_SCORE_TEAM_FORCE_RED
] then
2025 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_BLUE
) then // Red Wins
2027 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
2029 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
2033 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_RED
) then // Blue Wins
2035 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
2037 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
2043 if Result
then begin
2048 if g_Game_IsServer
and g_Game_IsNet
then
2055 Result
:= tr_Message(tgcKind
, tgcText
,
2056 tgcMsgDest
, tgcMsgTime
,
2061 TRIGGER_DAMAGE
, TRIGGER_HEALTH
:
2064 UIDType
:= g_GetUIDType(ActivateUID
);
2065 if (UIDType
= UID_PLAYER
) or (UIDType
= UID_MONSTER
) then
2071 // Âñïîìèíàåì, àêòèâèðîâàë ëè îí ìåíÿ ðàíüøå
2072 for idx
:= 0 to High(Activators
) do
2073 if Activators
[idx
].UID
= ActivateUID
then
2079 begin // Âèäèì åãî âïåðâûå
2081 SetLength(Activators
, Length(Activators
) + 1);
2082 k
:= High(Activators
);
2083 Activators
[k
].UID
:= ActivateUID
;
2085 begin // Óæå âèäåëè åãî
2086 // Åñëè èíòåðâàë îòêëþ÷¸í, íî îí âñ¸ åù¸ â çîíå ïîðàæåíèÿ, äà¸ì åìó âðåìÿ
2087 if (tgcInterval
= 0) and (Activators
[k
].TimeOut
> 0) then
2088 Activators
[k
].TimeOut
:= 65535;
2089 // Òàéìàóò ïðîø¸ë - ðàáîòàåì
2090 Result
:= Activators
[k
].TimeOut
= 0;
2099 p
:= g_Player_Get(ActivateUID
);
2103 // Íàíîñèì óðîí èãðîêó
2104 if (TriggerType
= TRIGGER_DAMAGE
) and (tgcAmount
> 0) then
2106 // Êèñëîòíûé óðîí íå íàíîñèòñÿ êîãäà åñòü êîñòþì
2107 // "Âîäÿíîé" óðîí íå íàíîñèòñÿ êîãäà åñòü êèñëîðîä
2108 if not (((tgcKind
= HIT_ACID
) and (p
.FMegaRulez
[MR_SUIT
] > gTime
)) or
2109 ((tgcKind
= HIT_WATER
) and (p
.Air
> 0))) then
2110 p
.Damage(tgcAmount
, 0, 0, 0, tgcKind
);
2111 if (tgcKind
= HIT_FLAME
) then p
.CatchFire(0);
2115 if (TriggerType
= TRIGGER_HEALTH
) and (tgcAmount
> 0) then
2116 if p
.Heal(tgcAmount
, not tgcHealMax
) and (not tgcSilent
) then
2118 g_Sound_PlayExAt('SOUND_ITEM_GETITEM', p
.Obj
.X
, p
.Obj
.Y
);
2119 if g_Game_IsServer
and g_Game_IsNet
then
2120 MH_SEND_Sound(p
.Obj
.X
, p
.Obj
.Y
, 'SOUND_ITEM_GETITEM');
2126 m
:= g_Monsters_ByUID(ActivateUID
);
2130 // Íàíîñèì óðîí ìîíñòðó
2131 if (TriggerType
= TRIGGER_DAMAGE
) and (tgcAmount
> 0) then
2133 m
.Damage(tgcAmount
, 0, 0, 0, tgcKind
);
2134 if (tgcKind
= HIT_FLAME
) then m
.CatchFire(0);
2138 if (TriggerType
= TRIGGER_HEALTH
) and (tgcAmount
> 0) then
2139 if m
.Heal(tgcAmount
) and (not tgcSilent
) then
2141 g_Sound_PlayExAt('SOUND_ITEM_GETITEM', m
.Obj
.X
, m
.Obj
.Y
);
2142 if g_Game_IsServer
and g_Game_IsNet
then
2143 MH_SEND_Sound(m
.Obj
.X
, m
.Obj
.Y
, 'SOUND_ITEM_GETITEM');
2147 // Íàçíà÷àåì âðåìÿ ñëåäóþùåãî âîçäåéñòâèÿ
2151 Activators
[k
].TimeOut
:= idx
2153 Activators
[k
].TimeOut
:= 65535;
2161 if ShotSightTime
> 0 then
2164 // put this at the beginning so it doesn't trigger itself
2165 TimeOut
:= tgcWait
+ 1;
2169 pAngle
:= -DegToRad(tgcAngle
);
2170 xd
:= wx
+ Round(Cos(pAngle
) * 32.0);
2171 yd
:= wy
+ Round(Sin(pAngle
) * 32.0);
2174 case tgcShotTarget
of
2175 TRIGGER_SHOT_TARGET_MON
: // monsters
2176 //TODO: accelerate this!
2177 g_Mons_ForEachAlive(monsShotTarget
);
2179 TRIGGER_SHOT_TARGET_PLR
: // players
2180 if gPlayers
<> nil then
2181 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2182 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2183 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2185 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2186 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2187 TargetUID
:= gPlayers
[idx
].UID
;
2191 TRIGGER_SHOT_TARGET_RED
: // red team
2192 if gPlayers
<> nil then
2193 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2194 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2195 (gPlayers
[idx
].Team
= TEAM_RED
) and
2196 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2198 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2199 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2200 TargetUID
:= gPlayers
[idx
].UID
;
2204 TRIGGER_SHOT_TARGET_BLUE
: // blue team
2205 if gPlayers
<> nil then
2206 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2207 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2208 (gPlayers
[idx
].Team
= TEAM_BLUE
) and
2209 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2211 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2212 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2213 TargetUID
:= gPlayers
[idx
].UID
;
2217 TRIGGER_SHOT_TARGET_MONPLR
: // monsters then players
2219 //TODO: accelerate this!
2220 g_Mons_ForEachAlive(monsShotTargetMonPlr
);
2222 if (TargetUID
= 0) and (gPlayers
<> nil) then
2223 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2224 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2225 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2227 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2228 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2229 TargetUID
:= gPlayers
[idx
].UID
;
2234 TRIGGER_SHOT_TARGET_PLRMON
: // players then monsters
2236 if gPlayers
<> nil then
2237 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2238 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2239 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2241 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2242 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2243 TargetUID
:= gPlayers
[idx
].UID
;
2246 if TargetUID
= 0 then
2248 //TODO: accelerate this!
2249 g_Mons_ForEachAlive(monShotTargetPlrMon
);
2254 if (tgcShotTarget
<> TRIGGER_SHOT_TARGET_NONE
) or
2255 (tgcShotType
<> TRIGGER_SHOT_REV
) then
2256 TargetUID
:= ActivateUID
;
2260 if (tgcShotTarget
= TRIGGER_SHOT_TARGET_NONE
) or (TargetUID
> 0) or
2261 ((tgcShotTarget
> TRIGGER_SHOT_TARGET_NONE
) and (TargetUID
= 0)) then
2264 if (tgcSight
= 0) or
2265 (tgcShotTarget
= TRIGGER_SHOT_TARGET_NONE
) or
2266 (TargetUID
= ShotSightTarget
) then
2267 MakeShot(Trigger
, wx
, wy
, xd
, yd
, TargetUID
)
2270 ShotSightTime
:= tgcSight
;
2271 ShotSightTargetN
:= TargetUID
;
2272 if tgcShotType
= TRIGGER_SHOT_BFG
then
2274 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', wx
, wy
);
2275 if g_Game_IsNet
and g_Game_IsServer
then
2276 MH_SEND_Sound(wx
, wy
, 'SOUND_WEAPON_STARTFIREBFG');
2289 TRIGGER_EFFECT_POS_CENTER
:
2291 wx
:= X
+ Width
div 2;
2292 wy
:= Y
+ Height
div 2;
2294 TRIGGER_EFFECT_POS_AREA
:
2296 wx
:= X
+ Random(Width
);
2297 wy
:= Y
+ Random(Height
);
2300 wx
:= X
+ Width
div 2;
2301 wy
:= Y
+ Height
div 2;
2306 if tgcSpreadL
> 0 then xd
-= Random(tgcSpreadL
+1);
2307 if tgcSpreadR
> 0 then xd
+= Random(tgcSpreadR
+1);
2308 if tgcSpreadU
> 0 then yd
-= Random(tgcSpreadU
+1);
2309 if tgcSpreadD
> 0 then yd
+= Random(tgcSpreadD
+1);
2310 tr_MakeEffect(wx
, wy
, xd
, yd
,
2311 tgcFXType
, tgcFXSubType
,
2312 tgcFXRed
, tgcFXGreen
, tgcFXBlue
, True, False);
2321 if Result
{and (Trigger.TexturePanel <> -1)} then
2323 g_Map_SwitchTextureGUID({Trigger.TexturePanelType,} Trigger
.TexturePanelGUID
, IfThen(animonce
, 2, 1));
2328 function g_Triggers_CreateWithMapIndex (aTrigger
: TTrigger
; arridx
, mapidx
: Integer): DWORD
;
2330 triggers
: TDynField
;
2332 triggers
:= gCurrentMap
['trigger'];
2333 if (triggers
= nil) then raise Exception
.Create('LOAD: map has no triggers');
2334 if (mapidx
< 0) or (mapidx
>= triggers
.count
) then raise Exception
.Create('LOAD: invalid map trigger index');
2335 aTrigger
.mapIndex
:= mapidx
;
2336 result
:= g_Triggers_Create(aTrigger
, triggers
.itemAt
[mapidx
], arridx
);
2340 function g_Triggers_Create (aTrigger
: TTrigger
; trec
: TDynRecord
; forceInternalIndex
: Integer=-1): DWORD
;
2347 if (tgscope
= nil) then tgscope
:= TTrigScope
.Create();
2348 if (tgclist
= nil) then tgclist
:= TMyConstList
.Create();
2350 // Íå ñîçäàâàòü âûõîä, åñëè èãðà áåç âûõîäà
2351 if (aTrigger
.TriggerType
= TRIGGER_EXIT
) and
2352 (not LongBool(gGameSettings
.Options
and GAME_OPTION_ALLOWEXIT
)) then
2354 aTrigger
.TriggerType
:= TRIGGER_NONE
;
2357 // Åñëè ìîíñòðû çàïðåùåíû, îòìåíÿåì òðèããåð
2358 if (aTrigger
.TriggerType
= TRIGGER_SPAWNMONSTER
) and
2359 (not LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
)) and
2360 (gGameSettings
.GameType
<> GT_SINGLE
) then
2362 aTrigger
.TriggerType
:= TRIGGER_NONE
;
2365 // Ñ÷èòàåì êîëè÷åñòâî ñåêðåòîâ íà êàðòå
2366 if (aTrigger
.TriggerType
= TRIGGER_SECRET
) then gSecretsCount
+= 1;
2368 if (forceInternalIndex
< 0) then
2370 find_id
:= FindTrigger();
2374 olen
:= Length(gTriggers
);
2375 if (forceInternalIndex
>= olen
) then
2377 SetLength(gTriggers
, forceInternalIndex
+1);
2378 for f
:= olen
to High(gTriggers
) do
2380 gTriggers
[f
].TriggerType
:= TRIGGER_NONE
;
2381 gTriggers
[f
].trigDataRec
:= nil;
2382 gTriggers
[f
].exoInit
:= nil;
2383 gTriggers
[f
].exoThink
:= nil;
2384 gTriggers
[f
].exoCheck
:= nil;
2385 gTriggers
[f
].exoAction
:= nil;
2386 gTriggers
[f
].userVars
:= nil;
2389 f
:= forceInternalIndex
;
2390 gTriggers
[f
].trigDataRec
.Free();
2391 gTriggers
[f
].exoInit
.Free();
2392 gTriggers
[f
].exoThink
.Free();
2393 gTriggers
[f
].exoCheck
.Free();
2394 gTriggers
[f
].exoAction
.Free();
2395 gTriggers
[f
].userVars
.Free();
2396 gTriggers
[f
].trigDataRec
:= nil;
2397 gTriggers
[f
].exoInit
:= nil;
2398 gTriggers
[f
].exoThink
:= nil;
2399 gTriggers
[f
].exoCheck
:= nil;
2400 gTriggers
[f
].exoAction
:= nil;
2401 gTriggers
[f
].userVars
:= nil;
2402 find_id
:= DWORD(forceInternalIndex
);
2404 gTriggers
[find_id
] := aTrigger
;
2405 ptg
:= @gTriggers
[find_id
];
2407 ptg
.mapId
:= trec
.id
;
2408 // clone trigger data
2409 if (trec
.trigRec
= nil) then
2411 ptg
.trigDataRec
:= nil;
2413 if (ptg
.TriggerType
<> TRIGGER_SECRET
) then
2415 e_LogWritefln('trigger of type %s has no triggerdata; wtf?!', [ptg
.TriggerType
], TMsgType
.Warning
);
2420 ptg
.trigDataRec
:= trec
.trigRec
.clone(nil);
2426 // if this type of trigger exists both on the client and on the server
2427 // use an uniform numeration
2429 if (ptg
.TriggerType
= TRIGGER_SOUND
) then
2431 Inc(gTriggerClientID
);
2432 ClientID
:= gTriggerClientID
;
2436 PlayerCollide
:= False;
2440 SoundPlayCount
:= 0;
2447 // update cached trigger variables
2448 trigUpdateCacheData(ptg
^, ptg
.trigDataRec
);
2450 ptg
.userVars
:= nil;
2453 ptg
.exoThink
:= TExprBase
.parseStatList(tgclist
, VarToStr(trec
.user
['exoma_think']));
2455 on e
: TExomaParseException
do
2457 conwritefln('*** ERROR parsing exoma_think (%s,%s): %s [%s]', [e
.tokLine
, e
.tokCol
, e
.message, VarToStr(trec
.user
['exoma_think'])]);
2458 ptg
.exoThink
:= nil;
2464 ptg
.exoCheck
:= TExprBase
.parse(tgclist
, VarToStr(trec
.user
['exoma_check']));
2466 on e
: TExomaParseException
do
2468 conwritefln('*** ERROR parsing exoma_check (%s,%s): %s [%s]', [e
.tokLine
, e
.tokCol
, e
.message, VarToStr(trec
.user
['exoma_check'])]);
2469 ptg
.exoCheck
:= nil;
2475 ptg
.exoAction
:= TExprBase
.parseStatList(tgclist
, VarToStr(trec
.user
['exoma_action']));
2477 on e
: TExomaParseException
do
2479 conwritefln('*** ERROR parsing exoma_action (%s,%s): %s [%s]', [e
.tokLine
, e
.tokCol
, e
.message, VarToStr(trec
.user
['exoma_action'])]);
2480 ptg
.exoAction
:= nil;
2486 ptg
.exoInit
:= TExprBase
.parseStatList(tgclist
, VarToStr(trec
.user
['exoma_init']));
2488 on e
: TExomaParseException
do
2490 conwritefln('*** ERROR parsing exoma_init (%s,%s): %s [%s]', [e
.tokLine
, e
.tokCol
, e
.message, VarToStr(trec
.user
['exoma_init'])]);
2497 if (forceInternalIndex
< 0) and (ptg
.exoInit
<> nil) then
2499 //conwritefln('executing trigger init: [%s]', [gTriggers[find_id].exoInit.toString()]);
2502 ptg
.exoInit
.value(tgscope
);
2506 conwritefln('*** trigger exoactivate error: %s', [ptg
.exoInit
.toString()]);
2511 // Çàãðóæàåì çâóê, åñëè ýòî òðèããåð "Çâóê"
2512 if (ptg
.TriggerType
= TRIGGER_SOUND
) and (ptg
.tgcSoundName
<> '') then
2514 // Åùå íåò òàêîãî çâóêà
2515 if not g_Sound_Exists(ptg
.tgcSoundName
) then
2517 fn
:= e_GetResourcePath(WadDirs
, ptg
.tgcSoundName
, g_ExtractWadName(gMapInfo
.Map
));
2518 //e_LogWritefln('loading trigger sound ''%s''', [fn]);
2519 if not g_Sound_CreateWADEx(ptg
.tgcSoundName
, fn
) then
2521 g_FatalError(Format(_lc
[I_GAME_ERROR_TR_SOUND
], [fn
, ptg
.tgcSoundName
]));
2525 // Ñîçäàåì îáúåêò çâóêà
2528 Sound
:= TPlayableSound
.Create();
2529 if not Sound
.SetByName(ptg
.tgcSoundName
) then
2537 // Çàãðóæàåì ìóçûêó, åñëè ýòî òðèããåð "Ìóçûêà"
2538 if (ptg
.TriggerType
= TRIGGER_MUSIC
) and (ptg
.tgcMusicName
<> '') then
2540 // Åùå íåò òàêîé ìóçûêè
2541 if not g_Sound_Exists(ptg
.tgcMusicName
) then
2543 fn
:= e_GetResourcePath(WadDirs
, ptg
.tgcMusicName
, g_ExtractWadName(gMapInfo
.Map
));
2544 if not g_Sound_CreateWADEx(ptg
.tgcMusicName
, fn
, True) then
2546 g_FatalError(Format(_lc
[I_GAME_ERROR_TR_SOUND
], [fn
, ptg
.tgcMusicName
]));
2551 // Çàãðóæàåì äàííûå òðèããåðà "Òóðåëü"
2552 if (ptg
.TriggerType
= TRIGGER_SHOT
) then
2558 ShotSightTimeout
:= 0;
2559 ShotSightTarget
:= 0;
2560 ShotSightTargetN
:= 0;
2561 ShotAmmoCount
:= ptg
.tgcAmmo
;
2562 ShotReloadTime
:= 0;
2570 // sorry; grid doesn't support recursive queries, so we have to do this
2572 TSimpleMonsterList
= specialize TSimpleList
<TMonster
>;
2575 tgMonsList
: TSimpleMonsterList
= nil;
2577 procedure g_Triggers_Update();
2580 Affected
: array of Integer;
2582 function monsNear (mon
: TMonster
): Boolean;
2584 result
:= false; // don't stop
2586 gTriggers[a].ActivateUID := mon.UID;
2587 ActivateTrigger(gTriggers[a], ACTIVATE_MONSTERCOLLIDE);
2589 tgMonsList
.append(mon
);
2596 if (tgMonsList
= nil) then tgMonsList
:= TSimpleMonsterList
.Create();
2598 if gTriggers
= nil then Exit
;
2599 if gLMSRespawn
> LMS_RESPAWN_NONE
then Exit
; // don't update triggers at all
2601 SetLength(Affected
, 0);
2603 for a
:= 0 to High(gTriggers
) do
2604 with gTriggers
[a
] do
2606 if TriggerType
<> TRIGGER_NONE
then
2608 // Óìåíüøàåì âðåìÿ äî çàêðûòèÿ äâåðè (îòêðûòèÿ ëîâóøêè)
2609 if DoorTime
> 0 then DoorTime
:= DoorTime
- 1;
2610 // Óìåíüøàåì âðåìÿ îæèäàíèÿ ïîñëå íàæàòèÿ
2611 if PressTime
> 0 then PressTime
:= PressTime
- 1;
2612 // Ïðîâåðÿåì èãðîêîâ è ìîíñòðîâ, êîòîðûõ ðàíåå çàïîìíèëè:
2613 if (TriggerType
= TRIGGER_DAMAGE
) or (TriggerType
= TRIGGER_HEALTH
) then
2615 for b
:= 0 to High(Activators
) do
2617 // Óìåíüøàåì âðåìÿ äî ïîâòîðíîãî âîçäåéñòâèÿ:
2618 if Activators
[b
].TimeOut
> 0 then
2620 Dec(Activators
[b
].TimeOut
);
2626 // Ñ÷èòàåì, ÷òî îáúåêò ïîêèíóë çîíó äåéñòâèÿ òðèããåðà
2627 if (tgcInterval
= 0) and (Activators
[b
].TimeOut
< 65530) then Activators
[b
].TimeOut
:= 0;
2631 // Îáðàáàòûâàåì ñïàâíåðû
2632 if Enabled
and AutoSpawn
then
2634 if SpawnCooldown
= 0 then
2636 // Åñëè ïðèøëî âðåìÿ, ñïàâíèì ìîíñòðà
2637 if (TriggerType
= TRIGGER_SPAWNMONSTER
) and (tgcDelay
> 0) then
2640 ActivateTrigger(gTriggers
[a
], ACTIVATE_CUSTOM
);
2642 // Åñëè ïðèøëî âðåìÿ, ñïàâíèì ïðåäìåò
2643 if (TriggerType
= TRIGGER_SPAWNITEM
) and (tgcDelay
> 0) then
2646 ActivateTrigger(gTriggers
[a
], ACTIVATE_CUSTOM
);
2651 // Óìåíüøàåì âðåìÿ îæèäàíèÿ
2656 // Îáðàáàòûâàåì ñîáûòèÿ òðèããåðà "Òóðåëü"
2657 if TriggerType
= TRIGGER_SHOT
then
2659 if ShotPanelTime
> 0 then
2662 if ShotPanelTime
= 0 then g_Map_SwitchTextureGUID({ShotPanelType,} trigPanelGUID
);
2664 if ShotSightTime
> 0 then
2667 if ShotSightTime
= 0 then ShotSightTarget
:= ShotSightTargetN
;
2669 if ShotSightTimeout
> 0 then
2671 Dec(ShotSightTimeout
);
2672 if ShotSightTimeout
= 0 then ShotSightTarget
:= 0;
2674 if ShotReloadTime
> 0 then
2676 Dec(ShotReloadTime
);
2677 if ShotReloadTime
= 0 then ShotAmmoCount
:= tgcAmmo
;
2681 // Òðèããåð "Çâóê" óæå îòûãðàë, åñëè íóæíî åùå - ïåðåçàïóñêàåì
2682 if Enabled
and (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) then
2684 if (SoundPlayCount
> 0) and (not Sound
.IsPlaying()) then
2686 if tgcPlayCount
> 0 then Dec(SoundPlayCount
); (* looped sound if zero *)
2688 Sound
.PlayVolumeAtRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
2690 Sound
.PlayPanVolume((tgcPan
- 127.0) / 128.0, tgcVolume
/ 255.0);
2691 if Sound
.IsPlaying() and g_Game_IsNet
and g_Game_IsServer
then
2692 MH_SEND_TriggerSound(gTriggers
[a
])
2696 // Òðèããåð "Ëîâóøêà" - ïîðà îòêðûâàòü
2697 if (TriggerType
= TRIGGER_TRAP
) and (DoorTime
= 0) and (g_Map_PanelByGUID(trigPanelGUID
) <> nil) then
2699 tr_OpenDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
2703 // Òðèããåð "Äâåðü 5 ñåê" - ïîðà çàêðûâàòü
2704 if (TriggerType
= TRIGGER_DOOR5
) and (DoorTime
= 0) and (g_Map_PanelByGUID(trigPanelGUID
) <> nil) then
2706 pan
:= g_Map_PanelByGUID(trigPanelGUID
);
2707 if (pan
<> nil) and pan
.isGWall
then
2710 if {gWalls[trigPanelID].Enabled} pan
.Enabled
then
2716 // Ïîêà îòêðûòà - çàêðûâàåì
2717 if tr_CloseDoor(trigPanelGUID
, tgcSilent
, tgcD2d
) then DoorTime
:= -1;
2722 // Òðèããåð - ðàñøèðèòåëü èëè ïåðåêëþ÷àòåëü, è ïðîøëà çàäåðæêà, è íàæàëè íóæíîå ÷èñëî ðàç:
2723 if (TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
]) and
2724 (PressTime
= 0) and (PressCount
>= tgcPressCount
) then
2726 // Ñáðàñûâàåì çàäåðæêó àêòèâàöèè:
2728 // Ñáðàñûâàåì ñ÷åò÷èê íàæàòèé:
2729 if tgcPressCount
> 0 then PressCount
-= tgcPressCount
else PressCount
:= 0;
2731 // Îïðåäåëÿåì èçìåíÿåìûå èì òðèããåðû:
2732 for b
:= 0 to High(gTriggers
) do
2734 if g_Collide(tgcTX
, tgcTY
, tgcTWidth
, tgcTHeight
, gTriggers
[b
].X
, gTriggers
[b
].Y
,
2735 gTriggers
[b
].Width
, gTriggers
[b
].Height
) and
2736 ((b
<> a
) or (tgcWait
> 0)) then
2737 begin // Can be self-activated, if there is Data.Wait
2738 if (not tgcExtRandom
) or gTriggers
[b
].Enabled
then
2740 SetLength(Affected
, Length(Affected
) + 1);
2741 Affected
[High(Affected
)] := b
;
2747 // if we have panelid, assume that it will switch the moving platform
2748 pan
:= g_Map_PanelByGUID(trigPanelGUID
);
2749 if (pan
<> nil) then
2752 TRIGGER_PRESS
: pan
.movingActive
:= true; // what to do here?
2753 TRIGGER_ON
: pan
.movingActive
:= true;
2754 TRIGGER_OFF
: pan
.movingActive
:= false;
2755 TRIGGER_ONOFF
: pan
.movingActive
:= not pan
.movingActive
;
2757 if not tgcSilent
and (Length(tgcSound
) > 0) then
2759 g_Sound_PlayExAt(tgcSound
, X
, Y
);
2760 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, tgcSound
);
2764 // Âûáèðàåì îäèí èç òðèããåðîâ äëÿ ðàñøèðèòåëÿ, åñëè âêëþ÷åí ðàíäîì:
2765 if (TriggerType
= TRIGGER_PRESS
) and tgcExtRandom
then
2767 if (Length(Affected
) > 0) then
2769 b
:= Affected
[Random(Length(Affected
))];
2770 gTriggers
[b
].ActivateUID
:= gTriggers
[a
].ActivateUID
;
2771 ActivateTrigger(gTriggers
[b
], 0);
2774 else //  ïðîòèâíîì ñëó÷àå ðàáîòàåì êàê îáû÷íî:
2776 for i
:= 0 to High(Affected
) do
2782 gTriggers
[b
].ActivateUID
:= gTriggers
[a
].ActivateUID
;
2783 ActivateTrigger(gTriggers
[b
], 0);
2787 gTriggers
[b
].Enabled
:= True;
2791 gTriggers
[b
].Enabled
:= False;
2792 gTriggers
[b
].TimeOut
:= 0;
2793 if gTriggers
[b
].AutoSpawn
then
2795 gTriggers
[b
].AutoSpawn
:= False;
2796 gTriggers
[b
].SpawnCooldown
:= 0;
2801 gTriggers
[b
].Enabled
:= not gTriggers
[b
].Enabled
;
2802 if not gTriggers
[b
].Enabled
then
2804 gTriggers
[b
].TimeOut
:= 0;
2805 if gTriggers
[b
].AutoSpawn
then
2807 gTriggers
[b
].AutoSpawn
:= False;
2808 gTriggers
[b
].SpawnCooldown
:= 0;
2815 SetLength(Affected
, 0);
2818 // Óìåíüøàåì âðåìÿ äî âîçìîæíîñòè ïîâòîðíîé àêòèâàöèè:
2821 TimeOut
:= TimeOut
- 1;
2822 Continue
; // ×òîáû íå ïîòåðÿòü 1 åäèíèöó çàäåðæêè
2825 // Íèæå èäóò òèïû àêòèâàöèè, åñëè òðèããåð îòêëþ÷¸í - èä¸ì äàëüøå
2830 if ByteBool(ActivateType
and ACTIVATE_PLAYERCOLLIDE
) and
2832 if gPlayers
<> nil then
2833 for b
:= 0 to High(gPlayers
) do
2834 if gPlayers
[b
] <> nil then
2836 // Æèâ, åñòü íóæíûå êëþ÷è è îí ðÿäîì:
2837 if alive
and ((gTriggers
[a
].Keys
and GetKeys
) = gTriggers
[a
].Keys
) and
2838 Collide(X
, Y
, Width
, Height
) then
2840 gTriggers
[a
].ActivateUID
:= UID
;
2842 if (gTriggers
[a
].TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) and
2844 { Don't activate sound/music again if player is here }
2846 ActivateTrigger(gTriggers
[a
], ACTIVATE_PLAYERCOLLIDE
);
2849 { TODO 5 : àêòèâàöèÿ ìîíñòðàìè òðèããåðîâ ñ êëþ÷àìè }
2851 if ByteBool(ActivateType
and ACTIVATE_MONSTERCOLLIDE
) and
2852 ByteBool(ActivateType
and ACTIVATE_NOMONSTER
) and
2853 (TimeOut
= 0) and (Keys
= 0) then
2855 // Åñëè "Ìîíñòð áëèçêî" è "Ìîíñòðîâ íåò",
2856 // çàïóñêàåì òðèããåð íà ñòàðòå êàðòû è ñíèìàåì îáà ôëàãà
2857 ActivateType
:= ActivateType
and not (ACTIVATE_MONSTERCOLLIDE
or ACTIVATE_NOMONSTER
);
2858 gTriggers
[a
].ActivateUID
:= 0;
2859 ActivateTrigger(gTriggers
[a
], 0);
2863 if ByteBool(ActivateType
and ACTIVATE_MONSTERCOLLIDE
) and
2864 (TimeOut
= 0) and (Keys
= 0) then // Åñëè íå íóæíû êëþ÷è
2866 //g_Mons_ForEach(monsNear);
2869 g_Mons_ForEachAt(gTriggers
[a
].X
, gTriggers
[a
].Y
, gTriggers
[a
].Width
, gTriggers
[a
].Height
, monsNear
);
2870 for mon
in tgMonsList
do
2872 gTriggers
[a
].ActivateUID
:= mon
.UID
;
2873 ActivateTrigger(gTriggers
[a
], ACTIVATE_MONSTERCOLLIDE
);
2875 tgMonsList
.reset(); // just in case
2879 if ByteBool(ActivateType
and ACTIVATE_NOMONSTER
) and
2880 (TimeOut
= 0) and (Keys
= 0) then
2881 if not g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then
2883 gTriggers
[a
].ActivateUID
:= 0;
2884 ActivateTrigger(gTriggers
[a
], ACTIVATE_NOMONSTER
);
2888 PlayerCollide
:= g_CollidePlayer(X
, Y
, Width
, Height
);
2892 procedure g_Triggers_Press(ID
: DWORD
; ActivateType
: Byte; ActivateUID
: Word = 0);
2894 if (ID
>= Length(gTriggers
)) then exit
;
2895 gTriggers
[ID
].ActivateUID
:= ActivateUID
;
2896 ActivateTrigger(gTriggers
[ID
], ActivateType
);
2899 function g_Triggers_PressR(X
, Y
: Integer; Width
, Height
: Word; UID
: Word;
2900 ActivateType
: Byte; IgnoreList
: DWArray
= nil): DWArray
;
2908 if gTriggers
= nil then Exit
;
2910 case g_GetUIDType(UID
) of
2914 p
:= g_Player_Get(UID
);
2923 for a
:= 0 to High(gTriggers
) do
2924 if (gTriggers
[a
].TriggerType
<> TRIGGER_NONE
) and
2925 (gTriggers
[a
].TimeOut
= 0) and
2926 (not InDWArray(a
, IgnoreList
)) and
2927 ((gTriggers
[a
].Keys
and k
) = gTriggers
[a
].Keys
) and
2928 ByteBool(gTriggers
[a
].ActivateType
and ActivateType
) then
2929 if g_Collide(X
, Y
, Width
, Height
,
2930 gTriggers
[a
].X
, gTriggers
[a
].Y
,
2931 gTriggers
[a
].Width
, gTriggers
[a
].Height
) then
2933 gTriggers
[a
].ActivateUID
:= UID
;
2934 if ActivateTrigger(gTriggers
[a
], ActivateType
) then
2936 SetLength(Result
, Length(Result
)+1);
2937 Result
[High(Result
)] := a
;
2942 procedure g_Triggers_PressL(X1
, Y1
, X2
, Y2
: Integer; UID
: DWORD
; ActivateType
: Byte);
2948 if gTriggers
= nil then Exit
;
2950 case g_GetUIDType(UID
) of
2954 p
:= g_Player_Get(UID
);
2963 for a
:= 0 to High(gTriggers
) do
2964 if (gTriggers
[a
].TriggerType
<> TRIGGER_NONE
) and
2965 (gTriggers
[a
].TimeOut
= 0) and
2966 ((gTriggers
[a
].Keys
and k
) = gTriggers
[a
].Keys
) and
2967 ByteBool(gTriggers
[a
].ActivateType
and ActivateType
) then
2968 if g_CollideLine(x1
, y1
, x2
, y2
, gTriggers
[a
].X
, gTriggers
[a
].Y
,
2969 gTriggers
[a
].Width
, gTriggers
[a
].Height
) then
2971 gTriggers
[a
].ActivateUID
:= UID
;
2972 ActivateTrigger(gTriggers
[a
], ActivateType
);
2976 procedure g_Triggers_PressC(CX
, CY
: Integer; Radius
: Word; UID
: Word; ActivateType
: Byte; IgnoreTrigger
: Integer = -1);
2983 if gTriggers
= nil then
2986 case g_GetUIDType(UID
) of
2990 p
:= g_Player_Get(UID
);
2999 rsq
:= Radius
* Radius
;
3001 for a
:= 0 to High(gTriggers
) do
3002 if (gTriggers
[a
].ID
<> DWORD(IgnoreTrigger
)) and
3003 (gTriggers
[a
].TriggerType
<> TRIGGER_NONE
) and
3004 (gTriggers
[a
].TimeOut
= 0) and
3005 ((gTriggers
[a
].Keys
and k
) = gTriggers
[a
].Keys
) and
3006 ByteBool(gTriggers
[a
].ActivateType
and ActivateType
) then
3007 with gTriggers
[a
] do
3008 if g_Collide(CX
-Radius
, CY
-Radius
, 2*Radius
, 2*Radius
,
3009 X
, Y
, Width
, Height
) then
3010 if ((Sqr(CX
-X
)+Sqr(CY
-Y
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê âåðõíåìó ëåâîìó óãëó
3011 ((Sqr(CX
-X
-Width
)+Sqr(CY
-Y
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê âåðõíåìó ïðàâîìó óãëó
3012 ((Sqr(CX
-X
-Width
)+Sqr(CY
-Y
-Height
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê íèæíåìó ïðàâîìó óãëó
3013 ((Sqr(CX
-X
)+Sqr(CY
-Y
-Height
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê íèæíåìó ëåâîìó óãëó
3014 ( (CX
> (X
-Radius
)) and (CX
< (X
+Width
+Radius
)) and
3015 (CY
> Y
) and (CY
< (Y
+Height
)) ) or // Öåíòð êðóãà íåäàëåêî îò âåðòèêàëüíûõ ãðàíèö ïðÿìîóãîëüíèêà
3016 ( (CY
> (Y
-Radius
)) and (CY
< (Y
+Height
+Radius
)) and
3017 (CX
> X
) and (CX
< (X
+Width
)) ) then // Öåíòð êðóãà íåäàëåêî îò ãîðèçîíòàëüíûõ ãðàíèö ïðÿìîóãîëüíèêà
3020 ActivateTrigger(gTriggers
[a
], ActivateType
);
3024 procedure g_Triggers_OpenAll();
3029 if gTriggers
= nil then Exit
;
3032 for a
:= 0 to High(gTriggers
) do
3034 with gTriggers
[a
] do
3036 if (TriggerType
= TRIGGER_OPENDOOR
) or
3037 (TriggerType
= TRIGGER_DOOR5
) or
3038 (TriggerType
= TRIGGER_DOOR
) then
3040 tr_OpenDoor(trigPanelGUID
, True, tgcD2d
);
3041 if TriggerType
= TRIGGER_DOOR5
then DoorTime
:= 180;
3047 if b
then g_Sound_PlayEx('SOUND_GAME_DOOROPEN');
3050 procedure g_Triggers_DecreaseSpawner(ID
: DWORD
);
3052 if (gTriggers
<> nil) then
3054 if gTriggers
[ID
].tgcMax
> 0 then
3056 if gTriggers
[ID
].SpawnedCount
> 0 then
3057 Dec(gTriggers
[ID
].SpawnedCount
);
3059 if gTriggers
[ID
].tgcDelay
> 0 then
3061 if gTriggers
[ID
].SpawnCooldown
< 0 then
3062 gTriggers
[ID
].SpawnCooldown
:= gTriggers
[ID
].tgcDelay
;
3067 procedure g_Triggers_Free ();
3071 for a
:= 0 to High(gTriggers
) do
3073 if (gTriggers
[a
].TriggerType
= TRIGGER_SOUND
) then
3075 if g_Sound_Exists(gTriggers
[a
].tgcSoundName
) then
3077 g_Sound_Delete(gTriggers
[a
].tgcSoundName
);
3079 gTriggers
[a
].Sound
.Free();
3081 if (gTriggers
[a
].Activators
<> nil) then
3083 SetLength(gTriggers
[a
].Activators
, 0);
3085 gTriggers
[a
].trigDataRec
.Free();
3087 gTriggers
[a
].exoThink
.Free();
3088 gTriggers
[a
].exoCheck
.Free();
3089 gTriggers
[a
].exoAction
.Free();
3090 gTriggers
[a
].userVars
.Free();
3095 SetLength(gMonstersSpawned
, 0);
3099 procedure g_Triggers_SaveState (st
: TStream
);
3101 count
, actCount
, i
, j
: Integer;
3104 kv
: THashStrVariant
.PEntry
;
3107 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðèããåðîâ
3108 count
:= Length(gTriggers
);
3110 // Êîëè÷åñòâî òðèããåðîâ
3111 utils
.writeInt(st
, LongInt(count
));
3112 if (count
= 0) then exit
;
3114 for i
:= 0 to High(gTriggers
) do
3116 // Ñèãíàòóðà òðèããåðà
3117 utils
.writeSign(st
, 'TRGX');
3118 utils
.writeInt(st
, Byte(0));
3120 utils
.writeInt(st
, Byte(gTriggers
[i
].TriggerType
));
3121 if (gTriggers
[i
].TriggerType
= TRIGGER_NONE
) then continue
; // empty one
3122 // Ñïåöèàëüíûå äàííûå òðèããåðà: ïîòîì èç êàðòû îïÿòü âûòàùèì; ñîõðàíèì òîëüêî èíäåêñ
3123 utils
.writeInt(st
, LongInt(gTriggers
[i
].mapIndex
));
3124 // Êîîðäèíàòû ëåâîãî âåðõíåãî óãëà
3125 utils
.writeInt(st
, LongInt(gTriggers
[i
].X
));
3126 utils
.writeInt(st
, LongInt(gTriggers
[i
].Y
));
3128 utils
.writeInt(st
, Word(gTriggers
[i
].Width
));
3129 utils
.writeInt(st
, Word(gTriggers
[i
].Height
));
3130 // Âêëþ÷åí ëè òðèããåð
3131 utils
.writeBool(st
, gTriggers
[i
].Enabled
);
3132 // Òèï àêòèâàöèè òðèããåðà
3133 utils
.writeInt(st
, Byte(gTriggers
[i
].ActivateType
));
3134 // Êëþ÷è, íåîáõîäèìûå äëÿ àêòèâàöèè
3135 utils
.writeInt(st
, Byte(gTriggers
[i
].Keys
));
3136 // ID ïàíåëè, òåêñòóðà êîòîðîé èçìåíèòñÿ
3137 utils
.writeInt(st
, LongInt(gTriggers
[i
].TexturePanelGUID
));
3139 //Mem.WriteWord(gTriggers[i].TexturePanelType);
3140 // Âíóòðåííèé íîìåð äðóãîé ïàíåëè (ïî ñ÷àñòëèâîé ñëó÷àéíîñòè îí áóäåò ñîâïàäàòü ñ òåì, ÷òî ñîçäàíî ïðè çàãðóçêå êàðòû)
3141 utils
.writeInt(st
, LongInt(gTriggers
[i
].trigPanelGUID
));
3142 // Âðåìÿ äî âîçìîæíîñòè àêòèâàöèè
3143 utils
.writeInt(st
, Word(gTriggers
[i
].TimeOut
));
3144 // UID òîãî, êòî àêòèâèðîâàë ýòîò òðèããåð
3145 utils
.writeInt(st
, Word(gTriggers
[i
].ActivateUID
));
3146 // Ñïèñîê UID-îâ îáúåêòîâ, êîòîðûå íàõîäèëèñü ïîä âîçäåéñòâèåì
3147 actCount
:= Length(gTriggers
[i
].Activators
);
3148 utils
.writeInt(st
, LongInt(actCount
));
3149 for j
:= 0 to actCount
-1 do
3152 utils
.writeInt(st
, Word(gTriggers
[i
].Activators
[j
].UID
));
3154 utils
.writeInt(st
, Word(gTriggers
[i
].Activators
[j
].TimeOut
));
3156 // Ñòîèò ëè èãðîê â îáëàñòè òðèããåðà
3157 utils
.writeBool(st
, gTriggers
[i
].PlayerCollide
);
3158 // Âðåìÿ äî çàêðûòèÿ äâåðè
3159 utils
.writeInt(st
, LongInt(gTriggers
[i
].DoorTime
));
3160 // Çàäåðæêà àêòèâàöèè
3161 utils
.writeInt(st
, LongInt(gTriggers
[i
].PressTime
));
3163 utils
.writeInt(st
, LongInt(gTriggers
[i
].PressCount
));
3165 utils
.writeBool(st
, gTriggers
[i
].AutoSpawn
);
3166 // Çàäåðæêà ñïàâíåðà
3167 utils
.writeInt(st
, LongInt(gTriggers
[i
].SpawnCooldown
));
3168 // Ñ÷åò÷èê ñîçäàíèÿ îáúåêòîâ
3169 utils
.writeInt(st
, LongInt(gTriggers
[i
].SpawnedCount
));
3170 // Ñêîëüêî ðàç ïðîèãðàí çâóê
3171 utils
.writeInt(st
, LongInt(gTriggers
[i
].SoundPlayCount
));
3172 // Ïðîèãðûâàåòñÿ ëè çâóê?
3173 if (gTriggers
[i
].Sound
<> nil) then b
:= gTriggers
[i
].Sound
.IsPlaying() else b
:= false;
3174 utils
.writeBool(st
, b
);
3177 // Ïîçèöèÿ ïðîèãðûâàíèÿ çâóêà
3178 utils
.writeInt(st
, LongWord(gTriggers
[i
].Sound
.GetPosition()));
3180 sg
:= gTriggers
[i
].Sound
.GetVolume();
3181 sg
:= sg
/(gSoundLevel
/255.0);
3182 //Mem.WriteSingle(sg);
3183 st
.WriteBuffer(sg
, sizeof(sg
)); // sorry
3184 // Ñòåðåî ñìåùåíèå çâóêà
3185 sg
:= gTriggers
[i
].Sound
.GetPan();
3186 //Mem.WriteSingle(sg);
3187 st
.WriteBuffer(sg
, sizeof(sg
)); // sorry
3190 if (gTriggers
[i
].userVars
= nil) then
3192 utils
.writeInt(st
, LongInt(0));
3196 utils
.writeInt(st
, LongInt(gTriggers
[i
].userVars
.count
)); //FIXME: check for overflow
3197 for kv
in gTriggers
[i
].userVars
.byKeyValue
do
3199 //writeln('<', kv.key, '>:<', VarToStr(kv.value), '>');
3200 utils
.writeStr(st
, kv
.key
);
3201 t
:= LongInt(varType(kv
.value
));
3202 utils
.writeInt(st
, LongInt(t
));
3204 varString
: utils
.writeStr(st
, AnsiString(kv
.value
));
3205 varBoolean
: utils
.writeBool(st
, Boolean(kv
.value
));
3206 varShortInt
: utils
.writeInt(st
, LongInt(kv
.value
));
3207 varSmallint
: utils
.writeInt(st
, LongInt(kv
.value
));
3208 varInteger
: utils
.writeInt(st
, LongInt(kv
.value
));
3209 //varInt64: Mem.WriteInt(Integer(kv.value));
3210 varByte
: utils
.writeInt(st
, LongInt(kv
.value
));
3211 varWord
: utils
.writeInt(st
, LongInt(kv
.value
));
3212 varLongWord
: utils
.writeInt(st
, LongInt(kv
.value
));
3214 else raise Exception
.CreateFmt('cannot save uservar ''%s''', [kv
.key
]);
3222 procedure g_Triggers_LoadState (st
: TStream
);
3224 count
, actCount
, i
, j
, a
: Integer;
3233 uvname
: AnsiString = '';
3234 ustr
: AnsiString = '';
3242 // Êîëè÷åñòâî òðèããåðîâ
3243 count
:= utils
.readLongInt(st
);
3244 if (count
= 0) then exit
;
3245 if (count
< 0) or (count
> 1024*1024) then raise XStreamError
.Create('invalid trigger count');
3247 for a
:= 0 to count
-1 do
3249 // Ñèãíàòóðà òðèããåðà
3250 if not utils
.checkSign(st
, 'TRGX') then raise XStreamError
.Create('invalid trigger signature');
3251 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid trigger version');
3253 Trig
.TriggerType
:= utils
.readByte(st
);
3254 if (Trig
.TriggerType
= TRIGGER_NONE
) then continue
; // empty one
3255 // Ñïåöèàëüíûå äàííûå òðèããåðà: èíäåêñ â gCurrentMap.field['triggers']
3256 mapIndex
:= utils
.readLongInt(st
);
3257 i
:= g_Triggers_CreateWithMapIndex(Trig
, a
, mapIndex
);
3258 // Êîîðäèíàòû ëåâîãî âåðõíåãî óãëà
3259 gTriggers
[i
].X
:= utils
.readLongInt(st
);
3260 gTriggers
[i
].Y
:= utils
.readLongInt(st
);
3262 gTriggers
[i
].Width
:= utils
.readWord(st
);
3263 gTriggers
[i
].Height
:= utils
.readWord(st
);
3264 // Âêëþ÷åí ëè òðèããåð
3265 gTriggers
[i
].Enabled
:= utils
.readBool(st
);
3266 // Òèï àêòèâàöèè òðèããåðà
3267 gTriggers
[i
].ActivateType
:= utils
.readByte(st
);
3268 // Êëþ÷è, íåîáõîäèìûå äëÿ àêòèâàöèè
3269 gTriggers
[i
].Keys
:= utils
.readByte(st
);
3270 // ID ïàíåëè, òåêñòóðà êîòîðîé èçìåíèòñÿ
3271 gTriggers
[i
].TexturePanelGUID
:= utils
.readLongInt(st
);
3273 //Mem.ReadWord(gTriggers[i].TexturePanelType);
3274 // Âíóòðåííèé íîìåð äðóãîé ïàíåëè (ïî ñ÷àñòëèâîé ñëó÷àéíîñòè îí áóäåò ñîâïàäàòü ñ òåì, ÷òî ñîçäàíî ïðè çàãðóçêå êàðòû)
3275 gTriggers
[i
].trigPanelGUID
:= utils
.readLongInt(st
);
3276 // Âðåìÿ äî âîçìîæíîñòè àêòèâàöèè
3277 gTriggers
[i
].TimeOut
:= utils
.readWord(st
);
3278 // UID òîãî, êòî àêòèâèðîâàë ýòîò òðèããåð
3279 gTriggers
[i
].ActivateUID
:= utils
.readWord(st
);
3280 // Ñïèñîê UID-îâ îáúåêòîâ, êîòîðûå íàõîäèëèñü ïîä âîçäåéñòâèåì
3281 actCount
:= utils
.readLongInt(st
);
3282 if (actCount
< 0) or (actCount
> 1024*1024) then raise XStreamError
.Create('invalid activated object count');
3283 if (actCount
> 0) then
3285 SetLength(gTriggers
[i
].Activators
, actCount
);
3286 for j
:= 0 to actCount
-1 do
3289 gTriggers
[i
].Activators
[j
].UID
:= utils
.readWord(st
);
3291 gTriggers
[i
].Activators
[j
].TimeOut
:= utils
.readWord(st
);
3294 // Ñòîèò ëè èãðîê â îáëàñòè òðèããåðà
3295 gTriggers
[i
].PlayerCollide
:= utils
.readBool(st
);
3296 // Âðåìÿ äî çàêðûòèÿ äâåðè
3297 gTriggers
[i
].DoorTime
:= utils
.readLongInt(st
);
3298 // Çàäåðæêà àêòèâàöèè
3299 gTriggers
[i
].PressTime
:= utils
.readLongInt(st
);
3301 gTriggers
[i
].PressCount
:= utils
.readLongInt(st
);
3303 gTriggers
[i
].AutoSpawn
:= utils
.readBool(st
);
3304 // Çàäåðæêà ñïàâíåðà
3305 gTriggers
[i
].SpawnCooldown
:= utils
.readLongInt(st
);
3306 // Ñ÷åò÷èê ñîçäàíèÿ îáúåêòîâ
3307 gTriggers
[i
].SpawnedCount
:= utils
.readLongInt(st
);
3308 // Ñêîëüêî ðàç ïðîèãðàí çâóê
3309 gTriggers
[i
].SoundPlayCount
:= utils
.readLongInt(st
);
3310 // Ïðîèãðûâàåòñÿ ëè çâóê?
3311 b
:= utils
.readBool(st
);
3314 // Ïîçèöèÿ ïðîèãðûâàíèÿ çâóêà
3315 dw
:= utils
.readLongWord(st
);
3317 //Mem.ReadSingle(vol);
3318 st
.ReadBuffer(vol
, sizeof(vol
)); // sorry
3319 // Ñòåðåî ñìåùåíèå çâóêà
3320 //Mem.ReadSingle(pan);
3321 st
.ReadBuffer(pan
, sizeof(pan
)); // sorry
3322 // Çàïóñêàåì çâóê, åñëè åñòü
3323 if (gTriggers
[i
].Sound
<> nil) then
3325 gTriggers
[i
].Sound
.PlayPanVolume(pan
, vol
);
3326 gTriggers
[i
].Sound
.Pause(True);
3327 gTriggers
[i
].Sound
.SetPosition(dw
);
3331 gTriggers
[i
].userVars
.Free();
3332 gTriggers
[i
].userVars
:= nil;
3333 uvcount
:= utils
.readLongInt(st
);
3334 if (uvcount
< 0) or (uvcount
> 1024*1024) then raise XStreamError
.Create('invalid number of user vars in trigger');
3335 if (uvcount
> 0) then
3337 gTriggers
[i
].userVars
:= THashStrVariant
.Create();
3339 while (uvcount
> 0) do
3342 uvname
:= utils
.readStr(st
);
3343 vt
:= utils
.readLongInt(st
);
3345 varString
: begin ustr
:= utils
.readStr(st
); vv
:= ustr
; end;
3346 varBoolean
: begin ubool
:= utils
.readBool(st
); vv
:= ubool
; end;
3347 varShortInt
: begin uint
:= utils
.readLongInt(st
); vv
:= ShortInt(uint
); end;
3348 varSmallint
: begin uint
:= utils
.readLongInt(st
); vv
:= SmallInt(uint
); end;
3349 varInteger
: begin uint
:= utils
.readLongInt(st
); vv
:= LongInt(uint
); end;
3350 varByte
: begin uint
:= utils
.readLongInt(st
); vv
:= Byte(uint
); end;
3351 varWord
: begin uint
:= utils
.readLongInt(st
); vv
:= Word(uint
); end;
3352 varLongWord
: begin uint
:= utils
.readLongInt(st
); vv
:= LongWord(uint
); end;
3353 else raise Exception
.CreateFmt('cannot load uservar ''%s''', [uvname
]);
3355 gTriggers
[i
].userVars
.put(uvname
, vv
);