1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
22 SysUtils
, Variants
, Classes
,
23 MAPDEF
, e_graphics
, g_basic
, g_sound
,
24 xdynrec
, hashtable
, exoma
;
43 TexturePanelGUID
: Integer;
44 //TexturePanelType: Word;
48 Activators
: array of TActivator
;
49 PlayerCollide
: Boolean;
53 SoundPlayCount
: Integer;
54 Sound
: TPlayableSound
;
56 SpawnCooldown
: Integer;
57 SpawnedCount
: Integer;
58 //ShotPanelType: Word;
59 ShotPanelTime
: Integer;
60 ShotSightTime
: Integer;
61 ShotSightTimeout
: Integer;
62 ShotSightTarget
: Word;
63 ShotSightTargetN
: Word;
65 ShotReloadTime
: Integer;
67 mapId
: AnsiString; // trigger id, from map
68 mapIndex
: Integer; // index in fields['trigger'], used in save/load
69 trigPanelGUID
: Integer;
71 trigDataRec
: TDynRecord
; // triggerdata; owned by trigger (cloned)
72 exoInit
, exoThink
, exoCheck
, exoAction
: TExprBase
;
74 userVars
: THashStrVariant
;
76 {$INCLUDE ../shared/mapdef_tgc_def.inc}
79 function trigCenter (): TDFPoint
; inline;
82 function g_Triggers_Create (aTrigger
: TTrigger
; trec
: TDynRecord
; forceInternalIndex
: Integer=-1): DWORD
;
83 procedure g_Triggers_Update();
84 procedure g_Triggers_Press(ID
: DWORD
; ActivateType
: Byte; ActivateUID
: Word = 0);
85 function g_Triggers_PressR(X
, Y
: Integer; Width
, Height
: Word; UID
: Word;
86 ActivateType
: Byte; IgnoreList
: DWArray
= nil): DWArray
;
87 procedure g_Triggers_PressL(X1
, Y1
, X2
, Y2
: Integer; UID
: DWORD
; ActivateType
: Byte);
88 procedure g_Triggers_PressC(CX
, CY
: Integer; Radius
: Word; UID
: Word; ActivateType
: Byte; IgnoreTrigger
: Integer = -1);
89 procedure g_Triggers_OpenAll();
90 procedure g_Triggers_DecreaseSpawner(ID
: DWORD
);
91 procedure g_Triggers_Free();
92 procedure g_Triggers_SaveState (st
: TStream
);
93 procedure g_Triggers_LoadState (st
: TStream
);
97 gTriggerClientID
: Integer = 0;
98 gTriggers
: array of TTrigger
;
99 gSecretsCount
: Integer = 0;
100 gMonstersSpawned
: array of LongInt = nil;
107 g_player
, g_map
, g_panel
, g_gfx
, g_game
, g_textures
,
108 g_console
, g_monsters
, g_items
, g_phys
, g_weapons
,
109 wadreader
, g_main
, e_log
, g_language
,
110 g_options
, g_net
, g_netmsg
, utils
, xparser
, xstreams
;
113 TRIGGER_SIGNATURE
= $58475254; // 'TRGX'
116 {$INCLUDE ../shared/mapdef_tgc_impl.inc}
119 // ////////////////////////////////////////////////////////////////////////// //
121 TTrigScope
= class(TExprScope
)
124 monsprops
: TPropHash
;
125 platprops
: TPropHash
;
131 constructor Create ();
132 destructor Destroy (); override;
134 function getObj (const aname
: AnsiString): TObject
; override;
135 function getField (obj
: TObject
; const afldname
: AnsiString): Variant; override;
136 procedure setField (obj
: TObject
; const afldname
: AnsiString; var aval
: Variant); override;
140 // ////////////////////////////////////////////////////////////////////////// //
142 TMyConstList
= class(TExprConstList
)
144 function valid (const cname
: AnsiString): Boolean; override;
145 function get (const cname
: AnsiString; out v
: Variant): Boolean; override;
149 // ////////////////////////////////////////////////////////////////////////// //
150 function TMyConstList
.valid (const cname
: AnsiString): Boolean;
152 //writeln('CHECK: ''', cname, '''');
154 (cname
= 'player') or
159 function TMyConstList
.get (const cname
: AnsiString; out v
: Variant): Boolean;
164 //if (cname = 'answer') then begin v := LongInt(42); result := true; exit; end;
166 if (gCurrentMap
= nil) then exit
;
167 for eidx
:= 0 to gCurrentMap
.mapdef
.ebsTypeCount
-1 do
169 ebs
:= gCurrentMap
.mapdef
.ebsTypeAt
[eidx
];
170 if ebs
.has
[cname
] then
172 //writeln('FOUND: ''', cname, '''');
181 // ////////////////////////////////////////////////////////////////////////// //
182 constructor TTrigScope
.Create ();
184 plrprops
:= TPropHash
.Create(TPlayer
, 'e');
185 monsprops
:= TPropHash
.Create(TMonster
, 'e');
186 platprops
:= TPropHash
.Create(TPanel
, 'e');
191 destructor TTrigScope
.Destroy ();
200 function TTrigScope
.getObj (const aname
: AnsiString): TObject
;
202 if (aname
= 'player') then result
:= gPlayers
[0] //FIXME
203 else if (aname
= 'self') or (aname
= 'this') then result
:= TObject(Pointer(PtrUInt(1)))
204 else result
:= inherited getObj(aname
);
208 function TTrigScope
.getField (obj
: TObject
; const afldname
: AnsiString): Variant;
210 if (obj
= gPlayers
[0]) then
212 if plrprops
.get(obj
, afldname
, result
) then exit
;
214 else if (obj
= TObject(Pointer(PtrUInt(1)))) then
216 if (me
<> nil) and (me
.userVars
<> nil) then
218 if me
.userVars
.get(afldname
, result
) then exit
;
221 result
:= inherited getField(obj
, afldname
);
225 procedure TTrigScope
.setField (obj
: TObject
; const afldname
: AnsiString; var aval
: Variant);
227 if (obj
= gPlayers
[0]) then
229 if plrprops
.put(obj
, afldname
, aval
) then exit
;
231 else if (obj
= TObject(Pointer(PtrUInt(1)))) then
235 if (Length(afldname
) > 4) and (afldname
[1] = 'u') and (afldname
[2] = 's') and
236 (afldname
[3] = 'e') and (afldname
[4] = 'r') then
238 if (me
.userVars
= nil) then me
.userVars
:= THashStrVariant
.Create();
239 me
.userVars
.put(afldname
, aval
);
244 inherited setField(obj
, afldname
, aval
);
248 // ////////////////////////////////////////////////////////////////////////// //
250 tgscope
: TTrigScope
= nil;
251 tgclist
: TMyConstList
= nil;
254 // ////////////////////////////////////////////////////////////////////////// //
255 function TTrigger
.trigCenter (): TDFPoint
; inline;
257 result
:= TDFPoint
.Create(x
+width
div 2, y
+height
div 2);
261 function FindTrigger (): DWORD
;
265 olen
:= Length(gTriggers
);
267 for i
:= 0 to olen
-1 do
269 if gTriggers
[i
].TriggerType
= TRIGGER_NONE
then begin result
:= i
; exit
; end;
272 SetLength(gTriggers
, olen
+8);
275 for i
:= result
to High(gTriggers
) do
277 gTriggers
[i
].TriggerType
:= TRIGGER_NONE
;
278 gTriggers
[i
].trigDataRec
:= nil;
279 gTriggers
[i
].exoInit
:= nil;
280 gTriggers
[i
].exoThink
:= nil;
281 gTriggers
[i
].exoCheck
:= nil;
282 gTriggers
[i
].exoAction
:= nil;
283 gTriggers
[i
].userVars
:= nil;
288 function tr_CloseDoor (PanelGUID
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
295 pan
:= g_Map_PanelByGUID(PanelGUID
);
296 if (pan
= nil) or not pan
.isGWall
then exit
; //!FIXME!TRIGANY!
297 PanelID
:= pan
.arrIdx
;
301 with gWalls
[PanelID
] do
303 if g_CollidePlayer(X
, Y
, Width
, Height
) or g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then Exit
;
308 g_Sound_PlayExAt('SOUND_GAME_DOORCLOSE', X
, Y
);
309 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOORCLOSE');
311 g_Map_EnableWallGUID(PanelGUID
);
318 if (gDoorMap
= nil) then exit
;
321 for a
:= 0 to High(gDoorMap
) do
323 for b
:= 0 to High(gDoorMap
[a
]) do
325 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
331 if (c
<> -1) then break
;
333 if (c
= -1) then exit
;
335 for b
:= 0 to High(gDoorMap
[c
]) do
337 with gWalls
[gDoorMap
[c
, b
]] do
339 if g_CollidePlayer(X
, Y
, Width
, Height
) or g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then exit
;
345 for b
:= 0 to High(gDoorMap
[c
]) do
347 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
349 with gWalls
[PanelID
] do
351 g_Sound_PlayExAt('SOUND_GAME_DOORCLOSE', X
, Y
);
352 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOORCLOSE');
359 for b
:= 0 to High(gDoorMap
[c
]) do
361 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
363 g_Map_EnableWall_XXX(gDoorMap
[c
, b
]);
371 procedure tr_CloseTrap (PanelGUID
: Integer; NoSound
: Boolean; d2d
: Boolean);
374 wx
, wy
, wh
, ww
: Integer;
378 function monsDamage (mon
: TMonster
): Boolean;
380 result
:= false; // don't stop
381 if g_Obj_Collide(wx
, wy
, ww
, wh
, @mon
.Obj
) then mon
.Damage(TRAP_DAMAGE
, 0, 0, 0, HIT_TRAP
);
385 pan
:= g_Map_PanelByGUID(PanelGUID
);
389 e_LogWritefln('tr_CloseTrap: pguid=%s; NO PANEL!', [PanelGUID], MSG_WARNING);
393 e_LogWritefln('tr_CloseTrap: pguid=%s; isGWall=%s; arrIdx=%s', [PanelGUID, pan.isGWall, pan.arrIdx]);
396 if (pan
= nil) or not pan
.isGWall
then exit
; //!FIXME!TRIGANY!
397 PanelID
:= pan
.arrIdx
;
401 with gWalls
[PanelID
] do
403 if (not NoSound
) and (not Enabled
) then
405 g_Sound_PlayExAt('SOUND_GAME_SWITCH1', X
, Y
);
406 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_SWITCH1');
410 wx
:= gWalls
[PanelID
].X
;
411 wy
:= gWalls
[PanelID
].Y
;
412 ww
:= gWalls
[PanelID
].Width
;
413 wh
:= gWalls
[PanelID
].Height
;
415 with gWalls
[PanelID
] do
417 if gPlayers
<> nil then
419 for a
:= 0 to High(gPlayers
) do
421 if (gPlayers
[a
] <> nil) and gPlayers
[a
].alive
and gPlayers
[a
].Collide(X
, Y
, Width
, Height
) then
423 gPlayers
[a
].Damage(TRAP_DAMAGE
, 0, 0, 0, HIT_TRAP
);
428 //g_Mons_ForEach(monsDamage);
429 g_Mons_ForEachAliveAt(wx
, wy
, ww
, wh
, monsDamage
);
431 if not Enabled
then g_Map_EnableWallGUID(PanelGUID
);
436 if (gDoorMap
= nil) then exit
;
439 for a
:= 0 to High(gDoorMap
) do
441 for b
:= 0 to High(gDoorMap
[a
]) do
443 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
449 if (c
<> -1) then break
;
451 if (c
= -1) then exit
;
455 for b
:= 0 to High(gDoorMap
[c
]) do
457 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
459 with gWalls
[PanelID
] do
461 g_Sound_PlayExAt('SOUND_GAME_SWITCH1', X
, Y
);
462 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_SWITCH1');
469 for b
:= 0 to High(gDoorMap
[c
]) do
471 wx
:= gWalls
[gDoorMap
[c
, b
]].X
;
472 wy
:= gWalls
[gDoorMap
[c
, b
]].Y
;
473 ww
:= gWalls
[gDoorMap
[c
, b
]].Width
;
474 wh
:= gWalls
[gDoorMap
[c
, b
]].Height
;
476 with gWalls
[gDoorMap
[c
, b
]] do
478 if gPlayers
<> nil then
480 for a
:= 0 to High(gPlayers
) do
482 if (gPlayers
[a
] <> nil) and gPlayers
[a
].alive
and gPlayers
[a
].Collide(X
, Y
, Width
, Height
) then
484 gPlayers
[a
].Damage(TRAP_DAMAGE
, 0, 0, 0, HIT_TRAP
);
489 //g_Mons_ForEach(monsDamage);
490 g_Mons_ForEachAliveAt(wx
, wy
, ww
, wh
, monsDamage
);
492 if gMonsters <> nil then
493 for a := 0 to High(gMonsters) do
494 if (gMonsters[a] <> nil) and gMonsters[a].alive and
495 g_Obj_Collide(X, Y, Width, Height, @gMonsters[a].Obj) then
496 gMonsters[a].Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
499 if not Enabled
then g_Map_EnableWall_XXX(gDoorMap
[c
, b
]);
506 function tr_OpenDoor (PanelGUID
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
513 pan
:= g_Map_PanelByGUID(PanelGUID
);
514 if (pan
= nil) or not pan
.isGWall
then exit
; //!FIXME!TRIGANY!
515 PanelID
:= pan
.arrIdx
;
519 with gWalls
[PanelID
] do
525 g_Sound_PlayExAt('SOUND_GAME_DOOROPEN', X
, Y
);
526 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOOROPEN');
528 g_Map_DisableWallGUID(PanelGUID
);
535 if (gDoorMap
= nil) then exit
;
538 for a
:= 0 to High(gDoorMap
) do
540 for b
:= 0 to High(gDoorMap
[a
]) do
542 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
548 if (c
<> -1) then break
;
550 if (c
= -1) then exit
;
554 for b
:= 0 to High(gDoorMap
[c
]) do
556 if gWalls
[gDoorMap
[c
, b
]].Enabled
then
558 with gWalls
[PanelID
] do
560 g_Sound_PlayExAt('SOUND_GAME_DOOROPEN', X
, Y
);
561 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOOROPEN');
568 for b
:= 0 to High(gDoorMap
[c
]) do
570 if gWalls
[gDoorMap
[c
, b
]].Enabled
then
572 g_Map_DisableWall_XXX(gDoorMap
[c
, b
]);
580 function tr_SetLift (PanelGUID
: Integer; d
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
588 pan
:= g_Map_PanelByGUID(PanelGUID
);
589 if (pan
= nil) or not pan
.isGLift
then exit
; //!FIXME!TRIGANY!
590 PanelID
:= pan
.arrIdx
;
592 if (gLifts
[PanelID
].PanelType
= PANEL_LIFTUP
) or (gLifts
[PanelID
].PanelType
= PANEL_LIFTDOWN
) then
596 1: t
:= LIFTTYPE_DOWN
;
597 else t
:= IfThen(gLifts
[PanelID
].LiftType
= LIFTTYPE_DOWN
, LIFTTYPE_UP
, LIFTTYPE_DOWN
);
600 else if (gLifts
[PanelID
].PanelType
= PANEL_LIFTLEFT
) or (gLifts
[PanelID
].PanelType
= PANEL_LIFTRIGHT
) then
603 0: t
:= LIFTTYPE_LEFT
;
604 1: t
:= LIFTTYPE_RIGHT
;
605 else t
:= IfThen(gLifts
[PanelID
].LiftType
= LIFTTYPE_LEFT
, LIFTTYPE_RIGHT
, LIFTTYPE_LEFT
);
611 with gLifts
[PanelID
] do
613 if (LiftType
<> t
) then
615 g_Map_SetLiftGUID(PanelGUID
, t
); //???
616 //if not NoSound then g_Sound_PlayExAt('SOUND_GAME_SWITCH0', X, Y);
623 if (gLiftMap
= nil) then exit
;
626 for a
:= 0 to High(gLiftMap
) do
628 for b
:= 0 to High(gLiftMap
[a
]) do
630 if (gLiftMap
[a
, b
] = DWORD(PanelID
)) then
636 if (c
<> -1) then break
;
638 if (c
= -1) then exit
;
641 for b := 0 to High(gLiftMap[c]) do
642 if gLifts[gLiftMap[c, b]].LiftType <> t then
644 with gLifts[PanelID] do
645 g_Sound_PlayExAt('SOUND_GAME_SWITCH0', X, Y);
649 for b
:= 0 to High(gLiftMap
[c
]) do
651 with gLifts
[gLiftMap
[c
, b
]] do
653 if (LiftType
<> t
) then
655 g_Map_SetLift_XXX(gLiftMap
[c
, b
], t
);
664 function tr_SpawnShot (ShotType
: Integer; wx
, wy
, dx
, dy
: Integer; ShotSound
: Boolean; ShotTarget
: Word): Integer;
672 TextureID
:= DWORD(-1);
673 snd
:= 'SOUND_WEAPON_FIREROCKET';
679 g_Weapon_pistol(wx
, wy
, dx
, dy
, 0, True);
680 snd
:= 'SOUND_WEAPON_FIREPISTOL';
684 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_BULLET
);
685 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL1
);
691 g_Weapon_mgun(wx
, wy
, dx
, dy
, 0, True);
692 if gSoundEffectsDF
then snd
:= 'SOUND_WEAPON_FIRECGUN'
693 else snd
:= 'SOUND_WEAPON_FIREPISTOL';
697 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_BULLET
);
698 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL1
);
702 TRIGGER_SHOT_SHOTGUN
:
704 g_Weapon_Shotgun(wx
, wy
, dx
, dy
, 0, True);
705 snd
:= 'SOUND_WEAPON_FIRESHOTGUN';
709 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
710 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL2
);
716 g_Weapon_DShotgun(wx
, wy
, dx
, dy
, 0, True);
717 snd
:= 'SOUND_WEAPON_FIRESHOTGUN2';
721 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
722 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
723 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL3
);
729 g_Weapon_ball1(wx
, wy
, dx
, dy
, 0, -1, True);
730 snd
:= 'SOUND_WEAPON_FIREBALL';
735 g_Weapon_Plasma(wx
, wy
, dx
, dy
, 0, -1, True);
736 snd
:= 'SOUND_WEAPON_FIREPLASMA';
741 g_Weapon_aplasma(wx
, wy
, dx
, dy
, 0, -1, True);
742 snd
:= 'SOUND_WEAPON_FIREPLASMA';
747 g_Weapon_ball2(wx
, wy
, dx
, dy
, 0, -1, True);
748 snd
:= 'SOUND_WEAPON_FIREBALL';
753 g_Weapon_ball7(wx
, wy
, dx
, dy
, 0, -1, True);
754 snd
:= 'SOUND_WEAPON_FIREBALL';
759 g_Weapon_manfire(wx
, wy
, dx
, dy
, 0, -1, True);
760 snd
:= 'SOUND_WEAPON_FIREBALL';
765 g_Weapon_revf(wx
, wy
, dx
, dy
, 0, ShotTarget
, -1, True);
766 snd
:= 'SOUND_WEAPON_FIREREV';
771 g_Weapon_Rocket(wx
, wy
, dx
, dy
, 0, -1, True);
772 snd
:= 'SOUND_WEAPON_FIREROCKET';
777 g_Weapon_BFGShot(wx
, wy
, dx
, dy
, 0, -1, True);
778 snd
:= 'SOUND_WEAPON_FIREBFG';
783 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_ROCKET') then
785 Anim
:= TAnimation
.Create(TextureID
, False, 6);
786 Anim
.Blending
:= False;
787 g_GFX_OnceAnim(wx
-64, wy
-64, Anim
);
791 g_Weapon_Explode(wx
, wy
, 60, 0);
792 snd
:= 'SOUND_WEAPON_EXPLODEROCKET';
795 TRIGGER_SHOT_BFGEXPL
:
797 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_BFG') then
799 Anim
:= TAnimation
.Create(TextureID
, False, 6);
800 Anim
.Blending
:= False;
801 g_GFX_OnceAnim(wx
-64, wy
-64, Anim
);
805 g_Weapon_BFG9000(wx
, wy
, 0);
806 snd
:= 'SOUND_WEAPON_EXPLODEBFG';
811 g_Weapon_flame(wx
, wy
, dx
, dy
, 0, -1, True);
812 snd
:= 'SOUND_GAME_BURNING';
818 if g_Game_IsNet
and g_Game_IsServer
then
821 TRIGGER_SHOT_EXPL
: MH_SEND_Effect(wx
, wy
, Byte(ShotSound
), NET_GFX_EXPLODE
);
822 TRIGGER_SHOT_BFGEXPL
: MH_SEND_Effect(wx
, wy
, Byte(ShotSound
), NET_GFX_BFGEXPL
);
825 if Projectile
then MH_SEND_CreateShot(LastShotID
);
826 if ShotSound
then MH_SEND_Sound(wx
, wy
, snd
);
831 if ShotSound
then g_Sound_PlayExAt(snd
, wx
, wy
);
833 if Projectile
then Result
:= LastShotID
;
837 procedure MakeShot (var Trigger
: TTrigger
; wx
, wy
, dx
, dy
: Integer; TargetUID
: Word);
841 if (tgcAmmo
= 0) or ((tgcAmmo
> 0) and (ShotAmmoCount
> 0)) then
843 if (trigPanelGUID
<> -1) and (ShotPanelTime
= 0) then
845 g_Map_SwitchTextureGUID({ShotPanelType,} trigPanelGUID
);
846 ShotPanelTime
:= 4; // òèêîâ íà âñïûøêó âûñòðåëà
849 if (tgcSight
> 0) then ShotSightTimeout
:= 180; // ~= 5 ñåêóíä
851 if (ShotAmmoCount
> 0) then Dec(ShotAmmoCount
);
853 dx
+= Random(tgcAccuracy
)-Random(tgcAccuracy
);
854 dy
+= Random(tgcAccuracy
)-Random(tgcAccuracy
);
856 tr_SpawnShot(tgcShotType
, wx
, wy
, dx
, dy
, tgcShotSound
, TargetUID
);
860 if (tgcReload
> 0) and (ShotReloadTime
= 0) then
862 ShotReloadTime
:= tgcReload
; // òèêîâ íà ïåðåçàðÿäêó ïóøêè
869 procedure tr_MakeEffect (X
, Y
, VX
, VY
: Integer; T
, ST
, CR
, CG
, CB
: Byte; Silent
, Send
: Boolean);
874 if T
= TRIGGER_EFFECT_PARTICLE
then
877 TRIGGER_EFFECT_SLIQUID
:
879 if (CR
= 255) and (CG
= 0) and (CB
= 0) then g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 1, 0, 0, 0)
880 else if (CR
= 0) and (CG
= 255) and (CB
= 0) then g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 2, 0, 0, 0)
881 else if (CR
= 0) and (CG
= 0) and (CB
= 255) then g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 3, 0, 0, 0)
882 else g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 0, 0, 0, 0);
884 TRIGGER_EFFECT_LLIQUID
: g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 4, CR
, CG
, CB
);
885 TRIGGER_EFFECT_DLIQUID
: g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 5, CR
, CG
, CB
);
886 TRIGGER_EFFECT_BLOOD
: g_GFX_Blood(X
, Y
, 1, VX
, VY
, 0, 0, CR
, CG
, CB
);
887 TRIGGER_EFFECT_SPARK
: g_GFX_Spark(X
, Y
, 1, GetAngle2(VX
, VY
), 0, 0);
888 TRIGGER_EFFECT_BUBBLE
: g_GFX_Bubbles(X
, Y
, 1, 0, 0);
892 if T
= TRIGGER_EFFECT_ANIMATION
then
895 EFFECT_TELEPORT
: begin
896 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
898 Anim
:= TAnimation
.Create(FramesID
, False, 3);
899 if not Silent
then g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
900 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
903 if Send
and g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(X
, Y
, Byte(not Silent
), NET_GFX_TELE
);
905 EFFECT_RESPAWN
: begin
906 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
908 Anim
:= TAnimation
.Create(FramesID
, False, 4);
909 if not Silent
then g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
910 g_GFX_OnceAnim(X
-16, Y
-16, Anim
);
913 if Send
and g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(X
-16, Y
-16, Byte(not Silent
), NET_GFX_RESPAWN
);
916 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
918 Anim
:= TAnimation
.Create(FramesID
, False, 4);
919 if not Silent
then g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
920 g_GFX_OnceAnim(X
-32, Y
-128, Anim
);
923 if Send
and g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(X
-32, Y
-128, Byte(not Silent
), NET_GFX_FIRE
);
930 function tr_Teleport (ActivateUID
: Integer; TX
, TY
: Integer; TDir
: Integer; Silent
: Boolean; D2D
: Boolean): Boolean;
936 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then Exit
;
937 case g_GetUIDType(ActivateUID
) of
940 p
:= g_Player_Get(ActivateUID
);
941 if p
= nil then Exit
;
944 if p
.TeleportTo(TX
-(p
.Obj
.Rect
.Width
div 2), TY
-p
.Obj
.Rect
.Height
, Silent
, TDir
) then result
:= true;
948 if p
.TeleportTo(TX
, TY
, Silent
, TDir
) then result
:= true;
953 m
:= g_Monsters_ByUID(ActivateUID
);
954 if m
= nil then Exit
;
957 if m
.TeleportTo(TX
-(m
.Obj
.Rect
.Width
div 2), TY
-m
.Obj
.Rect
.Height
, Silent
, TDir
) then result
:= true;
961 if m
.TeleportTo(TX
, TY
, Silent
, TDir
) then result
:= true;
968 function tr_Push (ActivateUID
: Integer; VX
, VY
: Integer; ResetVel
: Boolean): Boolean;
974 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then exit
;
975 case g_GetUIDType(ActivateUID
) of
978 p
:= g_Player_Get(ActivateUID
);
979 if p
= nil then Exit
;
994 m
:= g_Monsters_ByUID(ActivateUID
);
995 if m
= nil then Exit
;
1011 function tr_Message (MKind
: Integer; MText
: string; MSendTo
: Integer; MTime
: Integer; ActivateUID
: Integer): Boolean;
1018 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then Exit
;
1019 msg
:= b_Text_Format(MText
);
1021 TRIGGER_MESSAGE_DEST_ME
: // activator
1023 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
1025 if g_Game_IsWatchedPlayer(ActivateUID
) then
1027 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
1028 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
1032 p
:= g_Player_Get(ActivateUID
);
1033 if g_Game_IsNet
and (p
.FClientID
>= 0) then
1035 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, p
.FClientID
)
1036 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, p
.FClientID
);
1042 TRIGGER_MESSAGE_DEST_MY_TEAM
: // activator's team
1044 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
1046 p
:= g_Player_Get(ActivateUID
);
1047 if g_Game_IsWatchedTeam(p
.Team
) then
1049 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
1050 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
1053 if g_Game_IsNet
then
1055 for i
:= Low(gPlayers
) to High(gPlayers
) do
1057 if (gPlayers
[i
].Team
= p
.Team
) and (gPlayers
[i
].FClientID
>= 0) then
1059 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
1060 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
1067 TRIGGER_MESSAGE_DEST_ENEMY_TEAM
: // activator's enemy 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_RED_TEAM
: // red team
1094 if g_Game_IsWatchedTeam(TEAM_RED
) then
1096 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
1097 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
1100 if g_Game_IsNet
then
1102 for i
:= Low(gPlayers
) to High(gPlayers
) do
1104 if (gPlayers
[i
].Team
= TEAM_RED
) and (gPlayers
[i
].FClientID
>= 0) then
1106 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
1107 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
1113 TRIGGER_MESSAGE_DEST_BLUE_TEAM
: // blue team
1115 if g_Game_IsWatchedTeam(TEAM_BLUE
) then
1117 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
1118 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
1121 if g_Game_IsNet
then
1123 for i
:= Low(gPlayers
) to High(gPlayers
) do
1125 if (gPlayers
[i
].Team
= TEAM_BLUE
) and (gPlayers
[i
].FClientID
>= 0) then
1127 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
1128 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
1134 TRIGGER_MESSAGE_DEST_EVERYONE
: // everyone
1136 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
1137 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
1139 if g_Game_IsNet
then
1141 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
)
1142 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
);
1149 function tr_ShotAimCheck (var Trigger
: TTrigger
; Obj
: PObj
): Boolean;
1154 if TriggerType
<> TRIGGER_SHOT
then Exit
;
1155 result
:= (tgcAim
and TRIGGER_SHOT_AIM_ALLMAP
> 0)
1156 or g_Obj_Collide(X
, Y
, Width
, Height
, Obj
);
1157 if result
and (tgcAim
and TRIGGER_SHOT_AIM_TRACE
> 0) then
1159 result
:= g_TraceVector(tgcTX
, tgcTY
,
1160 Obj
^.X
+ Obj
^.Rect
.X
+ (Obj
^.Rect
.Width
div 2),
1161 Obj
^.Y
+ Obj
^.Rect
.Y
+ (Obj
^.Rect
.Height
div 2));
1167 function ActivateTrigger (var Trigger
: TTrigger
; actType
: Byte): Boolean;
1173 idx
, k
, wx
, wy
, xd
, yd
: Integer;
1184 function monsShotTarget (mon
: TMonster
): Boolean;
1186 result
:= false; // don't stop
1187 if mon
.alive
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
1189 xd
:= mon
.GameX
+ mon
.Obj
.Rect
.Width
div 2;
1190 yd
:= mon
.GameY
+ mon
.Obj
.Rect
.Height
div 2;
1191 TargetUID
:= mon
.UID
;
1192 result
:= true; // stop
1196 function monsShotTargetMonPlr (mon
: TMonster
): Boolean;
1198 result
:= false; // don't stop
1199 if mon
.alive
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
1201 xd
:= mon
.GameX
+ mon
.Obj
.Rect
.Width
div 2;
1202 yd
:= mon
.GameY
+ mon
.Obj
.Rect
.Height
div 2;
1203 TargetUID
:= mon
.UID
;
1204 result
:= true; // stop
1208 function monShotTargetPlrMon (mon
: TMonster
): Boolean;
1210 result
:= false; // don't stop
1211 if mon
.alive
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
1213 xd
:= mon
.GameX
+ mon
.Obj
.Rect
.Width
div 2;
1214 yd
:= mon
.GameY
+ mon
.Obj
.Rect
.Height
div 2;
1215 TargetUID
:= mon
.UID
;
1216 result
:= true; // stop
1224 if g_Game_IsClient
then exit
;
1226 if not Trigger
.Enabled
then exit
;
1227 if (Trigger
.TimeOut
<> 0) and (actType
<> ACTIVATE_CUSTOM
) then exit
;
1228 if (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then exit
;
1230 if (Trigger
.exoCheck
<> nil) then
1232 //conwritefln('exocheck: [%s]', [Trigger.exoCheck.toString()]);
1234 tgscope
.me
:= @Trigger
;
1235 tvval
:= Trigger
.exoCheck
.value(tgscope
);
1237 if not Boolean(tvval
) then exit
;
1238 except on e
: Exception
do
1241 conwritefln('trigger exocheck error: %s [%s]', [e
.message, Trigger
.exoCheck
.toString()]);
1249 coolDown
:= (actType
<> 0);
1251 if (Trigger
.exoAction
<> nil) then
1253 //conwritefln('exoactivate: [%s]', [Trigger.exoAction.toString()]);
1255 tgscope
.me
:= @Trigger
;
1256 Trigger
.exoAction
.value(tgscope
);
1258 except on e
: Exception
do
1261 conwritefln('trigger exoactivate error: %s [%s]', [e
.message, Trigger
.exoAction
.toString()]);
1272 g_Sound_PlayEx('SOUND_GAME_SWITCH0');
1273 if g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_SWITCH0');
1274 gExitByTrigger
:= True;
1275 g_Game_ExitLevel(tgcMap
);
1284 Result
:= tr_Teleport(ActivateUID
,
1285 tgcTarget
.X
, tgcTarget
.Y
,
1286 tgcDirection
, tgcSilent
,
1293 Result
:= tr_OpenDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
1299 Result
:= tr_CloseDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
1303 TRIGGER_DOOR
, TRIGGER_DOOR5
:
1305 pan
:= g_Map_PanelByGUID(trigPanelGUID
);
1306 if (pan
<> nil) and pan
.isGWall
then
1308 if gWalls
[{trigPanelID}pan
.arrIdx
].Enabled
then
1310 result
:= tr_OpenDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
1311 if (TriggerType
= TRIGGER_DOOR5
) then DoorTime
:= 180;
1315 result
:= tr_CloseDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
1318 if result
then TimeOut
:= 18;
1322 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
:
1324 tr_CloseTrap(trigPanelGUID
, tgcSilent
, tgcD2d
);
1326 if TriggerType
= TRIGGER_TRAP
then
1340 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
:
1343 if PressTime
= -1 then PressTime
:= tgcWait
;
1344 if coolDown
then TimeOut
:= 18 else TimeOut
:= 0;
1349 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
1353 if gLMSRespawn
= LMS_RESPAWN_NONE
then
1355 g_Player_Get(ActivateUID
).GetSecret();
1356 Inc(gCoopSecretsFound
);
1357 if g_Game_IsNet
then MH_SEND_GameStats();
1363 Result
:= tr_SetLift(trigPanelGUID
, 0, tgcSilent
, tgcD2d
);
1366 if (not tgcSilent
) and Result
then begin
1367 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1369 Y
+ (Height
div 2));
1370 if g_Game_IsServer
and g_Game_IsNet
then
1371 MH_SEND_Sound(X
+ (Width
div 2),
1373 'SOUND_GAME_SWITCH0');
1379 Result
:= tr_SetLift(trigPanelGUID
, 1, tgcSilent
, tgcD2d
);
1382 if (not tgcSilent
) and Result
then begin
1383 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1385 Y
+ (Height
div 2));
1386 if g_Game_IsServer
and g_Game_IsNet
then
1387 MH_SEND_Sound(X
+ (Width
div 2),
1389 'SOUND_GAME_SWITCH0');
1395 Result
:= tr_SetLift(trigPanelGUID
, 3, tgcSilent
, tgcD2d
);
1401 if (not tgcSilent
) and Result
then begin
1402 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1404 Y
+ (Height
div 2));
1405 if g_Game_IsServer
and g_Game_IsNet
then
1406 MH_SEND_Sound(X
+ (Width
div 2),
1408 'SOUND_GAME_SWITCH0');
1415 if tgcActivateOnce
then
1418 TriggerType
:= TRIGGER_NONE
;
1426 animonce
:= tgcAnimateOnce
;
1432 if Sound
<> nil then
1434 if tgcSoundSwitch
and Sound
.IsPlaying() then
1435 begin // Íóæíî âûêëþ÷èòü, åñëè èãðàë
1437 SoundPlayCount
:= 0;
1440 else // (not Data.SoundSwitch) or (not Sound.IsPlaying())
1441 if (tgcPlayCount
> 0) or (not Sound
.IsPlaying()) then
1443 if tgcPlayCount
> 0 then
1444 SoundPlayCount
:= tgcPlayCount
1445 else // 0 - èãðàåì áåñêîíå÷íî
1446 SoundPlayCount
:= 1;
1449 if g_Game_IsNet
then MH_SEND_TriggerSound(Trigger
);
1453 TRIGGER_SPAWNMONSTER
:
1454 if (tgcSpawnMonsType
in [MONSTER_DEMON
..MONSTER_MAN
]) then
1457 if (tgcDelay
> 0) and (actType
<> ACTIVATE_CUSTOM
) then
1459 AutoSpawn
:= not AutoSpawn
;
1461 // Àâòîñïàâíåð ïåðåêëþ÷åí - ìåíÿåì òåêñòóðó
1465 if ((tgcDelay
= 0) and (actType
<> ACTIVATE_CUSTOM
))
1466 or ((tgcDelay
> 0) and (actType
= ACTIVATE_CUSTOM
)) then
1467 for k
:= 1 to tgcMonsCount
do
1469 if (actType
= ACTIVATE_CUSTOM
) and (tgcDelay
> 0) then
1470 SpawnCooldown
:= tgcDelay
;
1471 if (tgcMax
> 0) and (SpawnedCount
>= tgcMax
) then
1474 mon
:= g_Monsters_Create(tgcSpawnMonsType
,
1476 TDirection(tgcDirection
), True);
1481 if (tgcHealth
> 0) then
1482 mon
.SetHealth(tgcHealth
);
1483 // Óñòàíàâëèâàåì ïîâåäåíèå:
1484 mon
.MonsterBehaviour
:= tgcBehaviour
;
1485 mon
.FNoRespawn
:= True;
1486 if g_Game_IsNet
then
1487 MH_SEND_MonsterSpawn(mon
.UID
);
1488 // Èäåì èñêàòü öåëü, åñëè íàäî:
1492 if tgcSpawnMonsType
<> MONSTER_BARREL
then Inc(gTotalMonsters
);
1494 if g_Game_IsNet
then
1496 SetLength(gMonstersSpawned
, Length(gMonstersSpawned
)+1);
1497 gMonstersSpawned
[High(gMonstersSpawned
)] := mon
.UID
;
1502 mon
.SpawnTrigger
:= ID
;
1507 EFFECT_TELEPORT
: begin
1508 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
1510 Anim
:= TAnimation
.Create(FramesID
, False, 3);
1511 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', tgcTX
, tgcTY
);
1512 g_GFX_OnceAnim(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1513 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-32, Anim
);
1516 if g_Game_IsServer
and g_Game_IsNet
then
1517 MH_SEND_Effect(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1518 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-32, 1,
1521 EFFECT_RESPAWN
: begin
1522 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
1524 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1525 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', tgcTX
, tgcTY
);
1526 g_GFX_OnceAnim(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-16,
1527 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-16, Anim
);
1530 if g_Game_IsServer
and g_Game_IsNet
then
1531 MH_SEND_Effect(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-16,
1532 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-16, 1,
1536 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
1538 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1539 g_Sound_PlayExAt('SOUND_FIRE', tgcTX
, tgcTY
);
1540 g_GFX_OnceAnim(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1541 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+mon
.Obj
.Rect
.Height
-128, Anim
);
1544 if g_Game_IsServer
and g_Game_IsNet
then
1545 MH_SEND_Effect(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1546 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+mon
.Obj
.Rect
.Height
-128, 1,
1551 if g_Game_IsNet
then
1553 MH_SEND_GameStats();
1554 MH_SEND_CoopStats();
1561 // Åñëè àêòèâèðîâàí àâòîñïàâíåðîì, íå ìåíÿåì òåêñòóðó
1562 if actType
= ACTIVATE_CUSTOM
then
1567 if (tgcSpawnItemType
in [ITEM_MEDKIT_SMALL
..ITEM_MAX
]) then
1570 if (tgcDelay
> 0) and (actType
<> ACTIVATE_CUSTOM
) then
1572 AutoSpawn
:= not AutoSpawn
;
1574 // Àâòîñïàâíåð ïåðåêëþ÷åí - ìåíÿåì òåêñòóðó
1578 if ((tgcDelay
= 0) and (actType
<> ACTIVATE_CUSTOM
))
1579 or ((tgcDelay
> 0) and (actType
= ACTIVATE_CUSTOM
)) then
1580 if (not tgcDmonly
) or
1581 (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
1582 for k
:= 1 to tgcItemCount
do
1584 if (actType
= ACTIVATE_CUSTOM
) and (tgcDelay
> 0) then
1585 SpawnCooldown
:= tgcDelay
;
1586 if (tgcMax
> 0) and (SpawnedCount
>= tgcMax
) then
1589 iid
:= g_Items_Create(tgcTX
, tgcTY
,
1590 tgcSpawnItemType
, tgcGravity
, False, True);
1596 it
:= g_Items_ByIdx(iid
);
1597 it
.SpawnTrigger
:= ID
;
1602 EFFECT_TELEPORT
: begin
1603 it
:= g_Items_ByIdx(iid
);
1604 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
1606 Anim
:= TAnimation
.Create(FramesID
, False, 3);
1607 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', tgcTX
, tgcTY
);
1608 g_GFX_OnceAnim(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, Anim
);
1612 if g_Game_IsServer
and g_Game_IsNet
then
1613 MH_SEND_Effect(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1614 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-32, 1,
1617 EFFECT_RESPAWN
: begin
1618 it
:= g_Items_ByIdx(iid
);
1619 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
1621 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1622 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', tgcTX
, tgcTY
);
1623 g_GFX_OnceAnim(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, Anim
);
1627 if g_Game_IsServer
and g_Game_IsNet
then
1628 MH_SEND_Effect(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-16,
1629 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-16, 1,
1633 it
:= g_Items_ByIdx(iid
);
1634 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
1636 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1637 g_Sound_PlayExAt('SOUND_FIRE', tgcTX
, tgcTY
);
1638 g_GFX_OnceAnim(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, Anim
);
1642 if g_Game_IsServer
and g_Game_IsNet
then
1643 MH_SEND_Effect(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1644 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+it
.Obj
.Rect
.Height
-128, 1,
1649 if g_Game_IsNet
then
1650 MH_SEND_ItemSpawn(True, iid
);
1657 // Åñëè àêòèâèðîâàí àâòîñïàâíåðîì, íå ìåíÿåì òåêñòóðó
1658 if actType
= ACTIVATE_CUSTOM
then
1664 // Ìåíÿåì ìóçûêó, åñëè åñòü íà ÷òî:
1665 if (Trigger
.tgcMusicName
<> '') then
1667 gMusic
.SetByName(Trigger
.tgcMusicName
);
1668 gMusic
.SpecPause
:= True;
1672 case Trigger
.tgcMusicAction
of
1673 TRIGGER_MUSIC_ACTION_STOP
: // Âûêëþ÷èòü
1674 gMusic
.SpecPause
:= True; // Ïàóçà
1675 TRIGGER_MUSIC_ACTION_PLAY
: // Âêëþ÷èòü
1676 if gMusic
.SpecPause
then // Áûëà íà ïàóçå => èãðàòü
1677 gMusic
.SpecPause
:= False
1678 else // Èãðàëà => ñíà÷àëà
1679 gMusic
.SetPosition(0);
1687 if g_Game_IsNet
then MH_SEND_TriggerMusic
;
1692 pAngle
:= -DegToRad(tgcAngle
);
1693 Result
:= tr_Push(ActivateUID
,
1694 Floor(Cos(pAngle
)*tgcForce
),
1695 Floor(Sin(pAngle
)*tgcForce
),
1703 // Ïðèáàâèòü èëè îòíÿòü î÷êî
1704 if (tgcScoreAction
in [TRIGGER_SCORE_ACTION_ADD
, TRIGGER_SCORE_ACTION_SUB
]) and (tgcScoreCount
> 0) then
1706 // Ñâîåé èëè ÷óæîé êîìàíäå
1707 if (tgcScoreTeam
in [TRIGGER_SCORE_TEAM_MINE_RED
, TRIGGER_SCORE_TEAM_MINE_BLUE
]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
1709 p
:= g_Player_Get(ActivateUID
);
1710 if ((tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_RED
))
1711 or ((tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_BLUE
)) then
1713 Inc(gTeamStat
[TEAM_RED
].Goals
, tgcScoreCount
); // Red Scores
1717 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1719 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_OWN
], [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), '+r');
1724 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_ENEMY
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1725 if g_Game_IsServer
and g_Game_IsNet
then
1726 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '+re');
1732 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1733 if g_Game_IsServer
and g_Game_IsNet
then
1734 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_RED
);
1737 if ((tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_RED
))
1738 or ((tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_BLUE
)) then
1740 Dec(gTeamStat
[TEAM_RED
].Goals
, tgcScoreCount
); // Red Fouls
1744 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1746 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_OWN
], [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), '-r');
1751 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_ENEMY
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1752 if g_Game_IsServer
and g_Game_IsNet
then
1753 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '-re');
1759 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1760 if g_Game_IsServer
and g_Game_IsNet
then
1761 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_RED
);
1764 if ((tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_BLUE
))
1765 or ((tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_RED
)) then
1767 Inc(gTeamStat
[TEAM_BLUE
].Goals
, tgcScoreCount
); // Blue Scores
1771 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1773 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_OWN
], [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), '+b');
1778 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_ENEMY
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1779 if g_Game_IsServer
and g_Game_IsNet
then
1780 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '+be');
1786 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1787 if g_Game_IsServer
and g_Game_IsNet
then
1788 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_BLUE
);
1791 if ((tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_BLUE
))
1792 or ((tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_RED
)) then
1794 Dec(gTeamStat
[TEAM_BLUE
].Goals
, tgcScoreCount
); // Blue Fouls
1798 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1800 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_OWN
], [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), '-b');
1805 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_ENEMY
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1806 if g_Game_IsServer
and g_Game_IsNet
then
1807 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '-be');
1813 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1814 if g_Game_IsServer
and g_Game_IsNet
then
1815 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_BLUE
);
1818 Result
:= (p
.Team
= TEAM_RED
) or (p
.Team
= TEAM_BLUE
);
1820 // Êàêîé-òî êîíêðåòíîé êîìàíäå
1821 if tgcScoreTeam
in [TRIGGER_SCORE_TEAM_FORCE_RED
, TRIGGER_SCORE_TEAM_FORCE_BLUE
] then
1823 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_RED
) then
1825 Inc(gTeamStat
[TEAM_RED
].Goals
, tgcScoreCount
); // Red Scores
1829 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_TEAM
], [_lc
[I_PLAYER_SCORE_RED
], tgcScoreCount
]), True);
1830 if g_Game_IsServer
and g_Game_IsNet
then
1831 MH_SEND_GameEvent(NET_EV_SCORE
, tgcScoreCount
shl 16, '+tr');
1836 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1837 if g_Game_IsServer
and g_Game_IsNet
then
1838 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_RED
);
1841 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_RED
) then
1843 Dec(gTeamStat
[TEAM_RED
].Goals
, tgcScoreCount
); // Red Fouls
1847 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_TEAM
], [_lc
[I_PLAYER_SCORE_RED
], tgcScoreCount
]), True);
1848 if g_Game_IsServer
and g_Game_IsNet
then
1849 MH_SEND_GameEvent(NET_EV_SCORE
, tgcScoreCount
shl 16, '-tr');
1854 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1855 if g_Game_IsServer
and g_Game_IsNet
then
1856 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_RED
);
1859 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_BLUE
) then
1861 Inc(gTeamStat
[TEAM_BLUE
].Goals
, tgcScoreCount
); // Blue Scores
1865 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_TEAM
], [_lc
[I_PLAYER_SCORE_BLUE
], tgcScoreCount
]), True);
1866 if g_Game_IsServer
and g_Game_IsNet
then
1867 MH_SEND_GameEvent(NET_EV_SCORE
, tgcScoreCount
shl 16, '+tb');
1872 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1873 if g_Game_IsServer
and g_Game_IsNet
then
1874 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_BLUE
);
1877 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_BLUE
) then
1879 Dec(gTeamStat
[TEAM_BLUE
].Goals
, tgcScoreCount
); // Blue Fouls
1883 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_TEAM
], [_lc
[I_PLAYER_SCORE_BLUE
], tgcScoreCount
]), True);
1884 if g_Game_IsServer
and g_Game_IsNet
then
1885 MH_SEND_GameEvent(NET_EV_SCORE
, tgcScoreCount
shl 16, '-tb');
1890 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1891 if g_Game_IsServer
and g_Game_IsNet
then
1892 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_BLUE
);
1899 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_WIN
) and (gGameSettings
.GoalLimit
> 0) then
1901 // Ñâîåé èëè ÷óæîé êîìàíäû
1902 if (tgcScoreTeam
in [TRIGGER_SCORE_TEAM_MINE_RED
, TRIGGER_SCORE_TEAM_MINE_BLUE
]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
1904 p
:= g_Player_Get(ActivateUID
);
1905 if ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_RED
)) // Red Wins
1906 or ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_BLUE
)) then
1908 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1910 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1914 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1916 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [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
, 'wr');
1921 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1922 if g_Game_IsServer
and g_Game_IsNet
then
1923 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wre');
1930 if ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_BLUE
)) // Blue Wins
1931 or ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_RED
)) then
1933 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1935 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1939 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1941 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [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
, 'wb');
1946 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1947 if g_Game_IsServer
and g_Game_IsNet
then
1948 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wbe');
1956 // Êàêîé-òî êîíêðåòíîé êîìàíäû
1957 if tgcScoreTeam
in [TRIGGER_SCORE_TEAM_FORCE_RED
, TRIGGER_SCORE_TEAM_FORCE_BLUE
] then
1959 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_RED
) then // Red Wins
1961 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1963 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1967 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_BLUE
) then // Blue Wins
1969 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1971 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1978 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_LOOSE
) and (gGameSettings
.GoalLimit
> 0) then
1980 // Ñâîåé èëè ÷óæîé êîìàíäû
1981 if (tgcScoreTeam
in [TRIGGER_SCORE_TEAM_MINE_RED
, TRIGGER_SCORE_TEAM_MINE_BLUE
]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
1983 p
:= g_Player_Get(ActivateUID
);
1984 if ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_BLUE
)) // Red Wins
1985 or ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_RED
)) then
1986 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1988 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1991 if tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
then
1993 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [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
, 'wre');
1998 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1999 if g_Game_IsServer
and g_Game_IsNet
then
2000 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wr');
2005 if ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_RED
)) // Blue Wins
2006 or ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_BLUE
)) then
2007 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
2009 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
2012 if tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
then
2014 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [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
, 'wbe');
2019 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
2020 if g_Game_IsServer
and g_Game_IsNet
then
2021 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wb');
2027 // Êàêîé-òî êîíêðåòíîé êîìàíäû
2028 if tgcScoreTeam
in [TRIGGER_SCORE_TEAM_FORCE_BLUE
, TRIGGER_SCORE_TEAM_FORCE_RED
] then
2030 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_BLUE
) then // Red Wins
2032 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
2034 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
2038 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_RED
) then // Blue Wins
2040 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
2042 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
2048 if Result
then begin
2053 if g_Game_IsServer
and g_Game_IsNet
then
2060 Result
:= tr_Message(tgcKind
, tgcText
,
2061 tgcMsgDest
, tgcMsgTime
,
2066 TRIGGER_DAMAGE
, TRIGGER_HEALTH
:
2069 UIDType
:= g_GetUIDType(ActivateUID
);
2070 if (UIDType
= UID_PLAYER
) or (UIDType
= UID_MONSTER
) then
2076 // Âñïîìèíàåì, àêòèâèðîâàë ëè îí ìåíÿ ðàíüøå
2077 for idx
:= 0 to High(Activators
) do
2078 if Activators
[idx
].UID
= ActivateUID
then
2084 begin // Âèäèì åãî âïåðâûå
2086 SetLength(Activators
, Length(Activators
) + 1);
2087 k
:= High(Activators
);
2088 Activators
[k
].UID
:= ActivateUID
;
2090 begin // Óæå âèäåëè åãî
2091 // Åñëè èíòåðâàë îòêëþ÷¸í, íî îí âñ¸ åù¸ â çîíå ïîðàæåíèÿ, äà¸ì åìó âðåìÿ
2092 if (tgcInterval
= 0) and (Activators
[k
].TimeOut
> 0) then
2093 Activators
[k
].TimeOut
:= 65535;
2094 // Òàéìàóò ïðîø¸ë - ðàáîòàåì
2095 Result
:= Activators
[k
].TimeOut
= 0;
2104 p
:= g_Player_Get(ActivateUID
);
2108 // Íàíîñèì óðîí èãðîêó
2109 if (TriggerType
= TRIGGER_DAMAGE
) and (tgcAmount
> 0) then
2110 p
.Damage(tgcAmount
, 0, 0, 0, HIT_SOME
);
2113 if (TriggerType
= TRIGGER_HEALTH
) and (tgcAmount
> 0) then
2114 if p
.Heal(tgcAmount
, not tgcHealMax
) and (not tgcSilent
) then
2116 g_Sound_PlayExAt('SOUND_ITEM_GETITEM', p
.Obj
.X
, p
.Obj
.Y
);
2117 if g_Game_IsServer
and g_Game_IsNet
then
2118 MH_SEND_Sound(p
.Obj
.X
, p
.Obj
.Y
, 'SOUND_ITEM_GETITEM');
2124 m
:= g_Monsters_ByUID(ActivateUID
);
2128 // Íàíîñèì óðîí ìîíñòðó
2129 if (TriggerType
= TRIGGER_DAMAGE
) and (tgcAmount
> 0) then
2130 m
.Damage(tgcAmount
, 0, 0, 0, HIT_SOME
);
2133 if (TriggerType
= TRIGGER_HEALTH
) and (tgcAmount
> 0) then
2134 if m
.Heal(tgcAmount
) and (not tgcSilent
) then
2136 g_Sound_PlayExAt('SOUND_ITEM_GETITEM', m
.Obj
.X
, m
.Obj
.Y
);
2137 if g_Game_IsServer
and g_Game_IsNet
then
2138 MH_SEND_Sound(m
.Obj
.X
, m
.Obj
.Y
, 'SOUND_ITEM_GETITEM');
2142 // Íàçíà÷àåì âðåìÿ ñëåäóþùåãî âîçäåéñòâèÿ
2146 Activators
[k
].TimeOut
:= idx
2148 Activators
[k
].TimeOut
:= 65535;
2156 if ShotSightTime
> 0 then
2159 // put this at the beginning so it doesn't trigger itself
2160 TimeOut
:= tgcWait
+ 1;
2164 pAngle
:= -DegToRad(tgcAngle
);
2165 xd
:= wx
+ Round(Cos(pAngle
) * 32.0);
2166 yd
:= wy
+ Round(Sin(pAngle
) * 32.0);
2169 case tgcShotTarget
of
2170 TRIGGER_SHOT_TARGET_MON
: // monsters
2171 //TODO: accelerate this!
2172 g_Mons_ForEachAlive(monsShotTarget
);
2174 TRIGGER_SHOT_TARGET_PLR
: // players
2175 if gPlayers
<> nil then
2176 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2177 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2178 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2180 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2181 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2182 TargetUID
:= gPlayers
[idx
].UID
;
2186 TRIGGER_SHOT_TARGET_RED
: // red team
2187 if gPlayers
<> nil then
2188 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2189 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2190 (gPlayers
[idx
].Team
= TEAM_RED
) and
2191 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2193 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2194 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2195 TargetUID
:= gPlayers
[idx
].UID
;
2199 TRIGGER_SHOT_TARGET_BLUE
: // blue team
2200 if gPlayers
<> nil then
2201 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2202 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2203 (gPlayers
[idx
].Team
= TEAM_BLUE
) and
2204 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2206 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2207 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2208 TargetUID
:= gPlayers
[idx
].UID
;
2212 TRIGGER_SHOT_TARGET_MONPLR
: // monsters then players
2214 //TODO: accelerate this!
2215 g_Mons_ForEachAlive(monsShotTargetMonPlr
);
2217 if (TargetUID
= 0) and (gPlayers
<> nil) then
2218 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2219 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2220 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2222 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2223 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2224 TargetUID
:= gPlayers
[idx
].UID
;
2229 TRIGGER_SHOT_TARGET_PLRMON
: // players then monsters
2231 if gPlayers
<> nil then
2232 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2233 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2234 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2236 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2237 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2238 TargetUID
:= gPlayers
[idx
].UID
;
2241 if TargetUID
= 0 then
2243 //TODO: accelerate this!
2244 g_Mons_ForEachAlive(monShotTargetPlrMon
);
2249 if (tgcShotTarget
<> TRIGGER_SHOT_TARGET_NONE
) or
2250 (tgcShotType
<> TRIGGER_SHOT_REV
) then
2251 TargetUID
:= ActivateUID
;
2255 if (tgcShotTarget
= TRIGGER_SHOT_TARGET_NONE
) or (TargetUID
> 0) or
2256 ((tgcShotTarget
> TRIGGER_SHOT_TARGET_NONE
) and (TargetUID
= 0)) then
2259 if (tgcSight
= 0) or
2260 (tgcShotTarget
= TRIGGER_SHOT_TARGET_NONE
) or
2261 (TargetUID
= ShotSightTarget
) then
2262 MakeShot(Trigger
, wx
, wy
, xd
, yd
, TargetUID
)
2265 ShotSightTime
:= tgcSight
;
2266 ShotSightTargetN
:= TargetUID
;
2267 if tgcShotType
= TRIGGER_SHOT_BFG
then
2269 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', wx
, wy
);
2270 if g_Game_IsNet
and g_Game_IsServer
then
2271 MH_SEND_Sound(wx
, wy
, 'SOUND_WEAPON_STARTFIREBFG');
2284 TRIGGER_EFFECT_POS_CENTER
:
2286 wx
:= X
+ Width
div 2;
2287 wy
:= Y
+ Height
div 2;
2289 TRIGGER_EFFECT_POS_AREA
:
2291 wx
:= X
+ Random(Width
);
2292 wy
:= Y
+ Random(Height
);
2295 wx
:= X
+ Width
div 2;
2296 wy
:= Y
+ Height
div 2;
2301 if tgcSpreadL
> 0 then xd
-= Random(tgcSpreadL
+1);
2302 if tgcSpreadR
> 0 then xd
+= Random(tgcSpreadR
+1);
2303 if tgcSpreadU
> 0 then yd
-= Random(tgcSpreadU
+1);
2304 if tgcSpreadD
> 0 then yd
+= Random(tgcSpreadD
+1);
2305 tr_MakeEffect(wx
, wy
, xd
, yd
,
2306 tgcFXType
, tgcFXSubType
,
2307 tgcFXRed
, tgcFXGreen
, tgcFXBlue
, True, False);
2316 if Result
{and (Trigger.TexturePanel <> -1)} then
2318 g_Map_SwitchTextureGUID({Trigger.TexturePanelType,} Trigger
.TexturePanelGUID
, IfThen(animonce
, 2, 1));
2323 function g_Triggers_CreateWithMapIndex (aTrigger
: TTrigger
; arridx
, mapidx
: Integer): DWORD
;
2325 triggers
: TDynField
;
2327 triggers
:= gCurrentMap
['trigger'];
2328 if (triggers
= nil) then raise Exception
.Create('LOAD: map has no triggers');
2329 if (mapidx
< 0) or (mapidx
>= triggers
.count
) then raise Exception
.Create('LOAD: invalid map trigger index');
2330 aTrigger
.mapIndex
:= mapidx
;
2331 result
:= g_Triggers_Create(aTrigger
, triggers
.itemAt
[mapidx
], arridx
);
2335 function g_Triggers_Create (aTrigger
: TTrigger
; trec
: TDynRecord
; forceInternalIndex
: Integer=-1): DWORD
;
2338 fn
, mapw
: AnsiString;
2342 if (tgscope
= nil) then tgscope
:= TTrigScope
.Create();
2343 if (tgclist
= nil) then tgclist
:= TMyConstList
.Create();
2345 // Íå ñîçäàâàòü âûõîä, åñëè èãðà áåç âûõîäà
2346 if (aTrigger
.TriggerType
= TRIGGER_EXIT
) and
2347 (not LongBool(gGameSettings
.Options
and GAME_OPTION_ALLOWEXIT
)) then
2349 aTrigger
.TriggerType
:= TRIGGER_NONE
;
2352 // Åñëè ìîíñòðû çàïðåùåíû, îòìåíÿåì òðèããåð
2353 if (aTrigger
.TriggerType
= TRIGGER_SPAWNMONSTER
) and
2354 (not LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
)) and
2355 (gGameSettings
.GameType
<> GT_SINGLE
) then
2357 aTrigger
.TriggerType
:= TRIGGER_NONE
;
2360 // Ñ÷èòàåì êîëè÷åñòâî ñåêðåòîâ íà êàðòå
2361 if (aTrigger
.TriggerType
= TRIGGER_SECRET
) then gSecretsCount
+= 1;
2363 if (forceInternalIndex
< 0) then
2365 find_id
:= FindTrigger();
2369 olen
:= Length(gTriggers
);
2370 if (forceInternalIndex
>= olen
) then
2372 SetLength(gTriggers
, forceInternalIndex
+1);
2373 for f
:= olen
to High(gTriggers
) do
2375 gTriggers
[f
].TriggerType
:= TRIGGER_NONE
;
2376 gTriggers
[f
].trigDataRec
:= nil;
2377 gTriggers
[f
].exoInit
:= nil;
2378 gTriggers
[f
].exoThink
:= nil;
2379 gTriggers
[f
].exoCheck
:= nil;
2380 gTriggers
[f
].exoAction
:= nil;
2381 gTriggers
[f
].userVars
:= nil;
2384 f
:= forceInternalIndex
;
2385 gTriggers
[f
].trigDataRec
.Free();
2386 gTriggers
[f
].exoInit
.Free();
2387 gTriggers
[f
].exoThink
.Free();
2388 gTriggers
[f
].exoCheck
.Free();
2389 gTriggers
[f
].exoAction
.Free();
2390 gTriggers
[f
].userVars
.Free();
2391 gTriggers
[f
].trigDataRec
:= nil;
2392 gTriggers
[f
].exoInit
:= nil;
2393 gTriggers
[f
].exoThink
:= nil;
2394 gTriggers
[f
].exoCheck
:= nil;
2395 gTriggers
[f
].exoAction
:= nil;
2396 gTriggers
[f
].userVars
:= nil;
2397 find_id
:= DWORD(forceInternalIndex
);
2399 gTriggers
[find_id
] := aTrigger
;
2400 ptg
:= @gTriggers
[find_id
];
2402 ptg
.mapId
:= trec
.id
;
2403 // clone trigger data
2404 if (trec
.trigRec
= nil) then
2406 ptg
.trigDataRec
:= nil;
2408 if (ptg
.TriggerType
<> TRIGGER_SECRET
) then
2410 e_LogWritefln('trigger of type %s has no triggerdata; wtf?!', [ptg
.TriggerType
], TMsgType
.Warning
);
2415 ptg
.trigDataRec
:= trec
.trigRec
.clone(nil);
2421 // if this type of trigger exists both on the client and on the server
2422 // use an uniform numeration
2424 if (ptg
.TriggerType
= TRIGGER_SOUND
) then
2426 Inc(gTriggerClientID
);
2427 ClientID
:= gTriggerClientID
;
2431 PlayerCollide
:= False;
2435 SoundPlayCount
:= 0;
2442 // update cached trigger variables
2443 trigUpdateCacheData(ptg
^, ptg
.trigDataRec
);
2445 ptg
.userVars
:= nil;
2448 ptg
.exoThink
:= TExprBase
.parseStatList(tgclist
, VarToStr(trec
.user
['exoma_think']));
2450 on e
: TExomaParseException
do
2452 conwritefln('*** ERROR parsing exoma_think (%s,%s): %s [%s]', [e
.tokLine
, e
.tokCol
, e
.message, VarToStr(trec
.user
['exoma_think'])]);
2453 ptg
.exoThink
:= nil;
2459 ptg
.exoCheck
:= TExprBase
.parse(tgclist
, VarToStr(trec
.user
['exoma_check']));
2461 on e
: TExomaParseException
do
2463 conwritefln('*** ERROR parsing exoma_check (%s,%s): %s [%s]', [e
.tokLine
, e
.tokCol
, e
.message, VarToStr(trec
.user
['exoma_check'])]);
2464 ptg
.exoCheck
:= nil;
2470 ptg
.exoAction
:= TExprBase
.parseStatList(tgclist
, VarToStr(trec
.user
['exoma_action']));
2472 on e
: TExomaParseException
do
2474 conwritefln('*** ERROR parsing exoma_action (%s,%s): %s [%s]', [e
.tokLine
, e
.tokCol
, e
.message, VarToStr(trec
.user
['exoma_action'])]);
2475 ptg
.exoAction
:= nil;
2481 ptg
.exoInit
:= TExprBase
.parseStatList(tgclist
, VarToStr(trec
.user
['exoma_init']));
2483 on e
: TExomaParseException
do
2485 conwritefln('*** ERROR parsing exoma_init (%s,%s): %s [%s]', [e
.tokLine
, e
.tokCol
, e
.message, VarToStr(trec
.user
['exoma_init'])]);
2492 if (forceInternalIndex
< 0) and (ptg
.exoInit
<> nil) then
2494 //conwritefln('executing trigger init: [%s]', [gTriggers[find_id].exoInit.toString()]);
2497 ptg
.exoInit
.value(tgscope
);
2501 conwritefln('*** trigger exoactivate error: %s', [ptg
.exoInit
.toString()]);
2506 // Çàãðóæàåì çâóê, åñëè ýòî òðèããåð "Çâóê"
2507 if (ptg
.TriggerType
= TRIGGER_SOUND
) and (ptg
.tgcSoundName
<> '') then
2509 // Åùå íåò òàêîãî çâóêà
2510 if not g_Sound_Exists(ptg
.tgcSoundName
) then
2512 fn
:= g_ExtractWadName(ptg
.tgcSoundName
);
2514 begin // Çâóê â ôàéëå ñ êàðòîé
2515 mapw
:= g_ExtractWadName(gMapInfo
.Map
);
2516 fn
:= mapw
+':'+g_ExtractFilePathName(ptg
.tgcSoundName
);
2518 else // Çâóê â îòäåëüíîì ôàéëå
2520 fn
:= GameDir
+ '/wads/' + ptg
.tgcSoundName
;
2523 //e_LogWritefln('loading trigger sound ''%s''', [fn]);
2524 if not g_Sound_CreateWADEx(ptg
.tgcSoundName
, fn
) then
2526 g_FatalError(Format(_lc
[I_GAME_ERROR_TR_SOUND
], [fn
, ptg
.tgcSoundName
]));
2530 // Ñîçäàåì îáúåêò çâóêà
2533 Sound
:= TPlayableSound
.Create();
2534 if not Sound
.SetByName(ptg
.tgcSoundName
) then
2542 // Çàãðóæàåì ìóçûêó, åñëè ýòî òðèããåð "Ìóçûêà"
2543 if (ptg
.TriggerType
= TRIGGER_MUSIC
) and (ptg
.tgcMusicName
<> '') then
2545 // Åùå íåò òàêîé ìóçûêè
2546 if not g_Sound_Exists(ptg
.tgcMusicName
) then
2548 fn
:= g_ExtractWadName(ptg
.tgcMusicName
);
2551 begin // Ìóçûêà â ôàéëå ñ êàðòîé
2552 mapw
:= g_ExtractWadName(gMapInfo
.Map
);
2553 fn
:= mapw
+':'+g_ExtractFilePathName(ptg
.tgcMusicName
);
2555 else // Ìóçûêà â ôàéëå ñ êàðòîé
2557 fn
:= GameDir
+'/wads/'+ptg
.tgcMusicName
;
2560 if not g_Sound_CreateWADEx(ptg
.tgcMusicName
, fn
, True) then
2562 g_FatalError(Format(_lc
[I_GAME_ERROR_TR_SOUND
], [fn
, ptg
.tgcMusicName
]));
2567 // Çàãðóæàåì äàííûå òðèããåðà "Òóðåëü"
2568 if (ptg
.TriggerType
= TRIGGER_SHOT
) then
2574 ShotSightTimeout
:= 0;
2575 ShotSightTarget
:= 0;
2576 ShotSightTargetN
:= 0;
2577 ShotAmmoCount
:= ptg
.tgcAmmo
;
2578 ShotReloadTime
:= 0;
2586 // sorry; grid doesn't support recursive queries, so we have to do this
2588 TSimpleMonsterList
= specialize TSimpleList
<TMonster
>;
2591 tgMonsList
: TSimpleMonsterList
= nil;
2593 procedure g_Triggers_Update();
2596 Affected
: array of Integer;
2598 function monsNear (mon
: TMonster
): Boolean;
2600 result
:= false; // don't stop
2602 gTriggers[a].ActivateUID := mon.UID;
2603 ActivateTrigger(gTriggers[a], ACTIVATE_MONSTERCOLLIDE);
2605 tgMonsList
.append(mon
);
2612 if (tgMonsList
= nil) then tgMonsList
:= TSimpleMonsterList
.Create();
2614 if gTriggers
= nil then
2616 SetLength(Affected
, 0);
2618 for a
:= 0 to High(gTriggers
) do
2619 with gTriggers
[a
] do
2621 if TriggerType
<> TRIGGER_NONE
then
2623 // Óìåíüøàåì âðåìÿ äî çàêðûòèÿ äâåðè (îòêðûòèÿ ëîâóøêè)
2624 if DoorTime
> 0 then DoorTime
:= DoorTime
- 1;
2625 // Óìåíüøàåì âðåìÿ îæèäàíèÿ ïîñëå íàæàòèÿ
2626 if PressTime
> 0 then PressTime
:= PressTime
- 1;
2627 // Ïðîâåðÿåì èãðîêîâ è ìîíñòðîâ, êîòîðûõ ðàíåå çàïîìíèëè:
2628 if (TriggerType
= TRIGGER_DAMAGE
) or (TriggerType
= TRIGGER_HEALTH
) then
2630 for b
:= 0 to High(Activators
) do
2632 // Óìåíüøàåì âðåìÿ äî ïîâòîðíîãî âîçäåéñòâèÿ:
2633 if Activators
[b
].TimeOut
> 0 then
2635 Dec(Activators
[b
].TimeOut
);
2641 // Ñ÷èòàåì, ÷òî îáúåêò ïîêèíóë çîíó äåéñòâèÿ òðèããåðà
2642 if (tgcInterval
= 0) and (Activators
[b
].TimeOut
< 65530) then Activators
[b
].TimeOut
:= 0;
2646 // Îáðàáàòûâàåì ñïàâíåðû
2647 if Enabled
and AutoSpawn
then
2649 if SpawnCooldown
= 0 then
2651 // Åñëè ïðèøëî âðåìÿ, ñïàâíèì ìîíñòðà
2652 if (TriggerType
= TRIGGER_SPAWNMONSTER
) and (tgcDelay
> 0) then
2655 ActivateTrigger(gTriggers
[a
], ACTIVATE_CUSTOM
);
2657 // Åñëè ïðèøëî âðåìÿ, ñïàâíèì ïðåäìåò
2658 if (TriggerType
= TRIGGER_SPAWNITEM
) and (tgcDelay
> 0) then
2661 ActivateTrigger(gTriggers
[a
], ACTIVATE_CUSTOM
);
2666 // Óìåíüøàåì âðåìÿ îæèäàíèÿ
2671 // Îáðàáàòûâàåì ñîáûòèÿ òðèããåðà "Òóðåëü"
2672 if TriggerType
= TRIGGER_SHOT
then
2674 if ShotPanelTime
> 0 then
2677 if ShotPanelTime
= 0 then g_Map_SwitchTextureGUID({ShotPanelType,} trigPanelGUID
);
2679 if ShotSightTime
> 0 then
2682 if ShotSightTime
= 0 then ShotSightTarget
:= ShotSightTargetN
;
2684 if ShotSightTimeout
> 0 then
2686 Dec(ShotSightTimeout
);
2687 if ShotSightTimeout
= 0 then ShotSightTarget
:= 0;
2689 if ShotReloadTime
> 0 then
2691 Dec(ShotReloadTime
);
2692 if ShotReloadTime
= 0 then ShotAmmoCount
:= tgcAmmo
;
2696 // Òðèããåð "Çâóê" óæå îòûãðàë, åñëè íóæíî åùå - ïåðåçàïóñêàåì
2697 if Enabled
and (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) then
2699 if (SoundPlayCount
> 0) and (not Sound
.IsPlaying()) then
2701 if tgcPlayCount
> 0 then SoundPlayCount
-= 1; // Åñëè 0 - èãðàåì çâóê áåñêîíå÷íî
2704 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0);
2708 Sound
.PlayPanVolume((tgcPan
-127.0)/128.0, tgcVolume
/255.0);
2710 if Sound
.IsPlaying() and g_Game_IsNet
and g_Game_IsServer
then MH_SEND_TriggerSound(gTriggers
[a
]);
2714 // Òðèããåð "Ëîâóøêà" - ïîðà îòêðûâàòü
2715 if (TriggerType
= TRIGGER_TRAP
) and (DoorTime
= 0) and (g_Map_PanelByGUID(trigPanelGUID
) <> nil) then
2717 tr_OpenDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
2721 // Òðèããåð "Äâåðü 5 ñåê" - ïîðà çàêðûâàòü
2722 if (TriggerType
= TRIGGER_DOOR5
) and (DoorTime
= 0) and (g_Map_PanelByGUID(trigPanelGUID
) <> nil) then
2724 pan
:= g_Map_PanelByGUID(trigPanelGUID
);
2725 if (pan
<> nil) and pan
.isGWall
then
2728 if {gWalls[trigPanelID].Enabled} pan
.Enabled
then
2734 // Ïîêà îòêðûòà - çàêðûâàåì
2735 if tr_CloseDoor(trigPanelGUID
, tgcSilent
, tgcD2d
) then DoorTime
:= -1;
2740 // Òðèããåð - ðàñøèðèòåëü èëè ïåðåêëþ÷àòåëü, è ïðîøëà çàäåðæêà, è íàæàëè íóæíîå ÷èñëî ðàç:
2741 if (TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
]) and
2742 (PressTime
= 0) and (PressCount
>= tgcPressCount
) then
2744 // Ñáðàñûâàåì çàäåðæêó àêòèâàöèè:
2746 // Ñáðàñûâàåì ñ÷åò÷èê íàæàòèé:
2747 if tgcPressCount
> 0 then PressCount
-= tgcPressCount
else PressCount
:= 0;
2749 // Îïðåäåëÿåì èçìåíÿåìûå èì òðèããåðû:
2750 for b
:= 0 to High(gTriggers
) do
2752 if g_Collide(tgcTX
, tgcTY
, tgcTWidth
, tgcTHeight
, gTriggers
[b
].X
, gTriggers
[b
].Y
,
2753 gTriggers
[b
].Width
, gTriggers
[b
].Height
) and
2754 ((b
<> a
) or (tgcWait
> 0)) then
2755 begin // Can be self-activated, if there is Data.Wait
2756 if (not tgcExtRandom
) or gTriggers
[b
].Enabled
then
2758 SetLength(Affected
, Length(Affected
) + 1);
2759 Affected
[High(Affected
)] := b
;
2765 // if we have panelid, assume that it will switch the moving platform
2766 pan
:= g_Map_PanelByGUID(trigPanelGUID
);
2767 if (pan
<> nil) then
2770 TRIGGER_PRESS
: pan
.movingActive
:= true; // what to do here?
2771 TRIGGER_ON
: pan
.movingActive
:= true;
2772 TRIGGER_OFF
: pan
.movingActive
:= false;
2773 TRIGGER_ONOFF
: pan
.movingActive
:= not pan
.movingActive
;
2775 if not tgcSilent
and (Length(tgcSound
) > 0) then
2777 g_Sound_PlayExAt(tgcSound
, X
, Y
);
2778 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, tgcSound
);
2782 // Âûáèðàåì îäèí èç òðèããåðîâ äëÿ ðàñøèðèòåëÿ, åñëè âêëþ÷åí ðàíäîì:
2783 if (TriggerType
= TRIGGER_PRESS
) and tgcExtRandom
then
2785 if (Length(Affected
) > 0) then
2787 b
:= Affected
[Random(Length(Affected
))];
2788 gTriggers
[b
].ActivateUID
:= gTriggers
[a
].ActivateUID
;
2789 ActivateTrigger(gTriggers
[b
], 0);
2792 else //  ïðîòèâíîì ñëó÷àå ðàáîòàåì êàê îáû÷íî:
2794 for i
:= 0 to High(Affected
) do
2800 gTriggers
[b
].ActivateUID
:= gTriggers
[a
].ActivateUID
;
2801 ActivateTrigger(gTriggers
[b
], 0);
2805 gTriggers
[b
].Enabled
:= True;
2809 gTriggers
[b
].Enabled
:= False;
2810 gTriggers
[b
].TimeOut
:= 0;
2811 if gTriggers
[b
].AutoSpawn
then
2813 gTriggers
[b
].AutoSpawn
:= False;
2814 gTriggers
[b
].SpawnCooldown
:= 0;
2819 gTriggers
[b
].Enabled
:= not gTriggers
[b
].Enabled
;
2820 if not gTriggers
[b
].Enabled
then
2822 gTriggers
[b
].TimeOut
:= 0;
2823 if gTriggers
[b
].AutoSpawn
then
2825 gTriggers
[b
].AutoSpawn
:= False;
2826 gTriggers
[b
].SpawnCooldown
:= 0;
2833 SetLength(Affected
, 0);
2836 // Óìåíüøàåì âðåìÿ äî âîçìîæíîñòè ïîâòîðíîé àêòèâàöèè:
2839 TimeOut
:= TimeOut
- 1;
2840 Continue
; // ×òîáû íå ïîòåðÿòü 1 åäèíèöó çàäåðæêè
2843 // Íèæå èäóò òèïû àêòèâàöèè, åñëè òðèããåð îòêëþ÷¸í - èä¸ì äàëüøå
2848 if ByteBool(ActivateType
and ACTIVATE_PLAYERCOLLIDE
) and
2850 if gPlayers
<> nil then
2851 for b
:= 0 to High(gPlayers
) do
2852 if gPlayers
[b
] <> nil then
2854 // Æèâ, åñòü íóæíûå êëþ÷è è îí ðÿäîì:
2855 if alive
and ((gTriggers
[a
].Keys
and GetKeys
) = gTriggers
[a
].Keys
) and
2856 Collide(X
, Y
, Width
, Height
) then
2858 gTriggers
[a
].ActivateUID
:= UID
;
2860 if (gTriggers
[a
].TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) and
2862 { Don't activate sound/music again if player is here }
2864 ActivateTrigger(gTriggers
[a
], ACTIVATE_PLAYERCOLLIDE
);
2867 { TODO 5 : àêòèâàöèÿ ìîíñòðàìè òðèããåðîâ ñ êëþ÷àìè }
2869 if ByteBool(ActivateType
and ACTIVATE_MONSTERCOLLIDE
) and
2870 ByteBool(ActivateType
and ACTIVATE_NOMONSTER
) and
2871 (TimeOut
= 0) and (Keys
= 0) then
2873 // Åñëè "Ìîíñòð áëèçêî" è "Ìîíñòðîâ íåò",
2874 // çàïóñêàåì òðèããåð íà ñòàðòå êàðòû è ñíèìàåì îáà ôëàãà
2875 ActivateType
:= ActivateType
and not (ACTIVATE_MONSTERCOLLIDE
or ACTIVATE_NOMONSTER
);
2876 gTriggers
[a
].ActivateUID
:= 0;
2877 ActivateTrigger(gTriggers
[a
], 0);
2881 if ByteBool(ActivateType
and ACTIVATE_MONSTERCOLLIDE
) and
2882 (TimeOut
= 0) and (Keys
= 0) then // Åñëè íå íóæíû êëþ÷è
2884 //g_Mons_ForEach(monsNear);
2887 g_Mons_ForEachAt(gTriggers
[a
].X
, gTriggers
[a
].Y
, gTriggers
[a
].Width
, gTriggers
[a
].Height
, monsNear
);
2888 for mon
in tgMonsList
do
2890 gTriggers
[a
].ActivateUID
:= mon
.UID
;
2891 ActivateTrigger(gTriggers
[a
], ACTIVATE_MONSTERCOLLIDE
);
2893 tgMonsList
.reset(); // just in case
2897 if ByteBool(ActivateType
and ACTIVATE_NOMONSTER
) and
2898 (TimeOut
= 0) and (Keys
= 0) then
2899 if not g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then
2901 gTriggers
[a
].ActivateUID
:= 0;
2902 ActivateTrigger(gTriggers
[a
], ACTIVATE_NOMONSTER
);
2906 PlayerCollide
:= g_CollidePlayer(X
, Y
, Width
, Height
);
2910 procedure g_Triggers_Press(ID
: DWORD
; ActivateType
: Byte; ActivateUID
: Word = 0);
2912 if (ID
>= Length(gTriggers
)) then exit
;
2913 gTriggers
[ID
].ActivateUID
:= ActivateUID
;
2914 ActivateTrigger(gTriggers
[ID
], ActivateType
);
2917 function g_Triggers_PressR(X
, Y
: Integer; Width
, Height
: Word; UID
: Word;
2918 ActivateType
: Byte; IgnoreList
: DWArray
= nil): DWArray
;
2926 if gTriggers
= nil then Exit
;
2928 case g_GetUIDType(UID
) of
2932 p
:= g_Player_Get(UID
);
2941 for a
:= 0 to High(gTriggers
) do
2942 if (gTriggers
[a
].TriggerType
<> TRIGGER_NONE
) and
2943 (gTriggers
[a
].TimeOut
= 0) and
2944 (not InDWArray(a
, IgnoreList
)) and
2945 ((gTriggers
[a
].Keys
and k
) = gTriggers
[a
].Keys
) and
2946 ByteBool(gTriggers
[a
].ActivateType
and ActivateType
) then
2947 if g_Collide(X
, Y
, Width
, Height
,
2948 gTriggers
[a
].X
, gTriggers
[a
].Y
,
2949 gTriggers
[a
].Width
, gTriggers
[a
].Height
) then
2951 gTriggers
[a
].ActivateUID
:= UID
;
2952 if ActivateTrigger(gTriggers
[a
], ActivateType
) then
2954 SetLength(Result
, Length(Result
)+1);
2955 Result
[High(Result
)] := a
;
2960 procedure g_Triggers_PressL(X1
, Y1
, X2
, Y2
: Integer; UID
: DWORD
; ActivateType
: Byte);
2966 if gTriggers
= nil then Exit
;
2968 case g_GetUIDType(UID
) of
2972 p
:= g_Player_Get(UID
);
2981 for a
:= 0 to High(gTriggers
) do
2982 if (gTriggers
[a
].TriggerType
<> TRIGGER_NONE
) and
2983 (gTriggers
[a
].TimeOut
= 0) and
2984 ((gTriggers
[a
].Keys
and k
) = gTriggers
[a
].Keys
) and
2985 ByteBool(gTriggers
[a
].ActivateType
and ActivateType
) then
2986 if g_CollideLine(x1
, y1
, x2
, y2
, gTriggers
[a
].X
, gTriggers
[a
].Y
,
2987 gTriggers
[a
].Width
, gTriggers
[a
].Height
) then
2989 gTriggers
[a
].ActivateUID
:= UID
;
2990 ActivateTrigger(gTriggers
[a
], ActivateType
);
2994 procedure g_Triggers_PressC(CX
, CY
: Integer; Radius
: Word; UID
: Word; ActivateType
: Byte; IgnoreTrigger
: Integer = -1);
3001 if gTriggers
= nil then
3004 case g_GetUIDType(UID
) of
3008 p
:= g_Player_Get(UID
);
3017 rsq
:= Radius
* Radius
;
3019 for a
:= 0 to High(gTriggers
) do
3020 if (gTriggers
[a
].ID
<> DWORD(IgnoreTrigger
)) and
3021 (gTriggers
[a
].TriggerType
<> TRIGGER_NONE
) and
3022 (gTriggers
[a
].TimeOut
= 0) and
3023 ((gTriggers
[a
].Keys
and k
) = gTriggers
[a
].Keys
) and
3024 ByteBool(gTriggers
[a
].ActivateType
and ActivateType
) then
3025 with gTriggers
[a
] do
3026 if g_Collide(CX
-Radius
, CY
-Radius
, 2*Radius
, 2*Radius
,
3027 X
, Y
, Width
, Height
) then
3028 if ((Sqr(CX
-X
)+Sqr(CY
-Y
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê âåðõíåìó ëåâîìó óãëó
3029 ((Sqr(CX
-X
-Width
)+Sqr(CY
-Y
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê âåðõíåìó ïðàâîìó óãëó
3030 ((Sqr(CX
-X
-Width
)+Sqr(CY
-Y
-Height
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê íèæíåìó ïðàâîìó óãëó
3031 ((Sqr(CX
-X
)+Sqr(CY
-Y
-Height
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê íèæíåìó ëåâîìó óãëó
3032 ( (CX
> (X
-Radius
)) and (CX
< (X
+Width
+Radius
)) and
3033 (CY
> Y
) and (CY
< (Y
+Height
)) ) or // Öåíòð êðóãà íåäàëåêî îò âåðòèêàëüíûõ ãðàíèö ïðÿìîóãîëüíèêà
3034 ( (CY
> (Y
-Radius
)) and (CY
< (Y
+Height
+Radius
)) and
3035 (CX
> X
) and (CX
< (X
+Width
)) ) then // Öåíòð êðóãà íåäàëåêî îò ãîðèçîíòàëüíûõ ãðàíèö ïðÿìîóãîëüíèêà
3038 ActivateTrigger(gTriggers
[a
], ActivateType
);
3042 procedure g_Triggers_OpenAll();
3047 if gTriggers
= nil then Exit
;
3050 for a
:= 0 to High(gTriggers
) do
3052 with gTriggers
[a
] do
3054 if (TriggerType
= TRIGGER_OPENDOOR
) or
3055 (TriggerType
= TRIGGER_DOOR5
) or
3056 (TriggerType
= TRIGGER_DOOR
) then
3058 tr_OpenDoor(trigPanelGUID
, True, tgcD2d
);
3059 if TriggerType
= TRIGGER_DOOR5
then DoorTime
:= 180;
3065 if b
then g_Sound_PlayEx('SOUND_GAME_DOOROPEN');
3068 procedure g_Triggers_DecreaseSpawner(ID
: DWORD
);
3070 if (gTriggers
<> nil) then
3071 if gTriggers
[ID
].SpawnedCount
> 0 then
3072 Dec(gTriggers
[ID
].SpawnedCount
);
3076 procedure g_Triggers_Free ();
3080 for a
:= 0 to High(gTriggers
) do
3082 if (gTriggers
[a
].TriggerType
= TRIGGER_SOUND
) then
3084 if g_Sound_Exists(gTriggers
[a
].tgcSoundName
) then
3086 g_Sound_Delete(gTriggers
[a
].tgcSoundName
);
3088 gTriggers
[a
].Sound
.Free();
3090 if (gTriggers
[a
].Activators
<> nil) then
3092 SetLength(gTriggers
[a
].Activators
, 0);
3094 gTriggers
[a
].trigDataRec
.Free();
3096 gTriggers
[a
].exoThink
.Free();
3097 gTriggers
[a
].exoCheck
.Free();
3098 gTriggers
[a
].exoAction
.Free();
3099 gTriggers
[a
].userVars
.Free();
3104 SetLength(gMonstersSpawned
, 0);
3108 procedure g_Triggers_SaveState (st
: TStream
);
3110 count
, actCount
, i
, j
: Integer;
3113 kv
: THashStrVariant
.PEntry
;
3116 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðèããåðîâ
3117 count
:= Length(gTriggers
);
3119 // Êîëè÷åñòâî òðèããåðîâ
3120 utils
.writeInt(st
, LongInt(count
));
3121 if (count
= 0) then exit
;
3123 for i
:= 0 to High(gTriggers
) do
3125 // Ñèãíàòóðà òðèããåðà
3126 utils
.writeSign(st
, 'TRGX');
3127 utils
.writeInt(st
, Byte(0));
3129 utils
.writeInt(st
, Byte(gTriggers
[i
].TriggerType
));
3130 if (gTriggers
[i
].TriggerType
= TRIGGER_NONE
) then continue
; // empty one
3131 // Ñïåöèàëüíûå äàííûå òðèããåðà: ïîòîì èç êàðòû îïÿòü âûòàùèì; ñîõðàíèì òîëüêî èíäåêñ
3132 utils
.writeInt(st
, LongInt(gTriggers
[i
].mapIndex
));
3133 // Êîîðäèíàòû ëåâîãî âåðõíåãî óãëà
3134 utils
.writeInt(st
, LongInt(gTriggers
[i
].X
));
3135 utils
.writeInt(st
, LongInt(gTriggers
[i
].Y
));
3137 utils
.writeInt(st
, Word(gTriggers
[i
].Width
));
3138 utils
.writeInt(st
, Word(gTriggers
[i
].Height
));
3139 // Âêëþ÷åí ëè òðèããåð
3140 utils
.writeBool(st
, gTriggers
[i
].Enabled
);
3141 // Òèï àêòèâàöèè òðèããåðà
3142 utils
.writeInt(st
, Byte(gTriggers
[i
].ActivateType
));
3143 // Êëþ÷è, íåîáõîäèìûå äëÿ àêòèâàöèè
3144 utils
.writeInt(st
, Byte(gTriggers
[i
].Keys
));
3145 // ID ïàíåëè, òåêñòóðà êîòîðîé èçìåíèòñÿ
3146 utils
.writeInt(st
, LongInt(gTriggers
[i
].TexturePanelGUID
));
3148 //Mem.WriteWord(gTriggers[i].TexturePanelType);
3149 // Âíóòðåííèé íîìåð äðóãîé ïàíåëè (ïî ñ÷àñòëèâîé ñëó÷àéíîñòè îí áóäåò ñîâïàäàòü ñ òåì, ÷òî ñîçäàíî ïðè çàãðóçêå êàðòû)
3150 utils
.writeInt(st
, LongInt(gTriggers
[i
].trigPanelGUID
));
3151 // Âðåìÿ äî âîçìîæíîñòè àêòèâàöèè
3152 utils
.writeInt(st
, Word(gTriggers
[i
].TimeOut
));
3153 // UID òîãî, êòî àêòèâèðîâàë ýòîò òðèããåð
3154 utils
.writeInt(st
, Word(gTriggers
[i
].ActivateUID
));
3155 // Ñïèñîê UID-îâ îáúåêòîâ, êîòîðûå íàõîäèëèñü ïîä âîçäåéñòâèåì
3156 actCount
:= Length(gTriggers
[i
].Activators
);
3157 utils
.writeInt(st
, LongInt(actCount
));
3158 for j
:= 0 to actCount
-1 do
3161 utils
.writeInt(st
, Word(gTriggers
[i
].Activators
[j
].UID
));
3163 utils
.writeInt(st
, Word(gTriggers
[i
].Activators
[j
].TimeOut
));
3165 // Ñòîèò ëè èãðîê â îáëàñòè òðèããåðà
3166 utils
.writeBool(st
, gTriggers
[i
].PlayerCollide
);
3167 // Âðåìÿ äî çàêðûòèÿ äâåðè
3168 utils
.writeInt(st
, LongInt(gTriggers
[i
].DoorTime
));
3169 // Çàäåðæêà àêòèâàöèè
3170 utils
.writeInt(st
, LongInt(gTriggers
[i
].PressTime
));
3172 utils
.writeInt(st
, LongInt(gTriggers
[i
].PressCount
));
3174 utils
.writeBool(st
, gTriggers
[i
].AutoSpawn
);
3175 // Çàäåðæêà ñïàâíåðà
3176 utils
.writeInt(st
, LongInt(gTriggers
[i
].SpawnCooldown
));
3177 // Ñ÷åò÷èê ñîçäàíèÿ îáúåêòîâ
3178 utils
.writeInt(st
, LongInt(gTriggers
[i
].SpawnedCount
));
3179 // Ñêîëüêî ðàç ïðîèãðàí çâóê
3180 utils
.writeInt(st
, LongInt(gTriggers
[i
].SoundPlayCount
));
3181 // Ïðîèãðûâàåòñÿ ëè çâóê?
3182 if (gTriggers
[i
].Sound
<> nil) then b
:= gTriggers
[i
].Sound
.IsPlaying() else b
:= false;
3183 utils
.writeBool(st
, b
);
3186 // Ïîçèöèÿ ïðîèãðûâàíèÿ çâóêà
3187 utils
.writeInt(st
, LongWord(gTriggers
[i
].Sound
.GetPosition()));
3189 sg
:= gTriggers
[i
].Sound
.GetVolume();
3190 sg
:= sg
/(gSoundLevel
/255.0);
3191 //Mem.WriteSingle(sg);
3192 st
.WriteBuffer(sg
, sizeof(sg
)); // sorry
3193 // Ñòåðåî ñìåùåíèå çâóêà
3194 sg
:= gTriggers
[i
].Sound
.GetPan();
3195 //Mem.WriteSingle(sg);
3196 st
.WriteBuffer(sg
, sizeof(sg
)); // sorry
3199 if (gTriggers
[i
].userVars
= nil) then
3201 utils
.writeInt(st
, LongInt(0));
3205 utils
.writeInt(st
, LongInt(gTriggers
[i
].userVars
.count
)); //FIXME: check for overflow
3206 for kv
in gTriggers
[i
].userVars
.byKeyValue
do
3208 //writeln('<', kv.key, '>:<', VarToStr(kv.value), '>');
3209 utils
.writeStr(st
, kv
.key
);
3210 t
:= LongInt(varType(kv
.value
));
3211 utils
.writeInt(st
, LongInt(t
));
3213 varString
: utils
.writeStr(st
, AnsiString(kv
.value
));
3214 varBoolean
: utils
.writeBool(st
, Boolean(kv
.value
));
3215 varShortInt
: utils
.writeInt(st
, LongInt(kv
.value
));
3216 varSmallint
: utils
.writeInt(st
, LongInt(kv
.value
));
3217 varInteger
: utils
.writeInt(st
, LongInt(kv
.value
));
3218 //varInt64: Mem.WriteInt(Integer(kv.value));
3219 varByte
: utils
.writeInt(st
, LongInt(kv
.value
));
3220 varWord
: utils
.writeInt(st
, LongInt(kv
.value
));
3221 varLongWord
: utils
.writeInt(st
, LongInt(kv
.value
));
3223 else raise Exception
.CreateFmt('cannot save uservar ''%s''', [kv
.key
]);
3231 procedure g_Triggers_LoadState (st
: TStream
);
3233 count
, actCount
, i
, j
, a
: Integer;
3242 uvname
: AnsiString = '';
3243 ustr
: AnsiString = '';
3251 // Êîëè÷åñòâî òðèããåðîâ
3252 count
:= utils
.readLongInt(st
);
3253 if (count
= 0) then exit
;
3254 if (count
< 0) or (count
> 1024*1024) then raise XStreamError
.Create('invalid trigger count');
3256 for a
:= 0 to count
-1 do
3258 // Ñèãíàòóðà òðèããåðà
3259 if not utils
.checkSign(st
, 'TRGX') then raise XStreamError
.Create('invalid trigger signature');
3260 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid trigger version');
3262 Trig
.TriggerType
:= utils
.readByte(st
);
3263 if (Trig
.TriggerType
= TRIGGER_NONE
) then continue
; // empty one
3264 // Ñïåöèàëüíûå äàííûå òðèããåðà: èíäåêñ â gCurrentMap.field['triggers']
3265 mapIndex
:= utils
.readLongInt(st
);
3266 i
:= g_Triggers_CreateWithMapIndex(Trig
, a
, mapIndex
);
3267 // Êîîðäèíàòû ëåâîãî âåðõíåãî óãëà
3268 gTriggers
[i
].X
:= utils
.readLongInt(st
);
3269 gTriggers
[i
].Y
:= utils
.readLongInt(st
);
3271 gTriggers
[i
].Width
:= utils
.readWord(st
);
3272 gTriggers
[i
].Height
:= utils
.readWord(st
);
3273 // Âêëþ÷åí ëè òðèããåð
3274 gTriggers
[i
].Enabled
:= utils
.readBool(st
);
3275 // Òèï àêòèâàöèè òðèããåðà
3276 gTriggers
[i
].ActivateType
:= utils
.readByte(st
);
3277 // Êëþ÷è, íåîáõîäèìûå äëÿ àêòèâàöèè
3278 gTriggers
[i
].Keys
:= utils
.readByte(st
);
3279 // ID ïàíåëè, òåêñòóðà êîòîðîé èçìåíèòñÿ
3280 gTriggers
[i
].TexturePanelGUID
:= utils
.readLongInt(st
);
3282 //Mem.ReadWord(gTriggers[i].TexturePanelType);
3283 // Âíóòðåííèé íîìåð äðóãîé ïàíåëè (ïî ñ÷àñòëèâîé ñëó÷àéíîñòè îí áóäåò ñîâïàäàòü ñ òåì, ÷òî ñîçäàíî ïðè çàãðóçêå êàðòû)
3284 gTriggers
[i
].trigPanelGUID
:= utils
.readLongInt(st
);
3285 // Âðåìÿ äî âîçìîæíîñòè àêòèâàöèè
3286 gTriggers
[i
].TimeOut
:= utils
.readWord(st
);
3287 // UID òîãî, êòî àêòèâèðîâàë ýòîò òðèããåð
3288 gTriggers
[i
].ActivateUID
:= utils
.readWord(st
);
3289 // Ñïèñîê UID-îâ îáúåêòîâ, êîòîðûå íàõîäèëèñü ïîä âîçäåéñòâèåì
3290 actCount
:= utils
.readLongInt(st
);
3291 if (actCount
< 0) or (actCount
> 1024*1024) then raise XStreamError
.Create('invalid activated object count');
3292 if (actCount
> 0) then
3294 SetLength(gTriggers
[i
].Activators
, actCount
);
3295 for j
:= 0 to actCount
-1 do
3298 gTriggers
[i
].Activators
[j
].UID
:= utils
.readWord(st
);
3300 gTriggers
[i
].Activators
[j
].TimeOut
:= utils
.readWord(st
);
3303 // Ñòîèò ëè èãðîê â îáëàñòè òðèããåðà
3304 gTriggers
[i
].PlayerCollide
:= utils
.readBool(st
);
3305 // Âðåìÿ äî çàêðûòèÿ äâåðè
3306 gTriggers
[i
].DoorTime
:= utils
.readLongInt(st
);
3307 // Çàäåðæêà àêòèâàöèè
3308 gTriggers
[i
].PressTime
:= utils
.readLongInt(st
);
3310 gTriggers
[i
].PressCount
:= utils
.readLongInt(st
);
3312 gTriggers
[i
].AutoSpawn
:= utils
.readBool(st
);
3313 // Çàäåðæêà ñïàâíåðà
3314 gTriggers
[i
].SpawnCooldown
:= utils
.readLongInt(st
);
3315 // Ñ÷åò÷èê ñîçäàíèÿ îáúåêòîâ
3316 gTriggers
[i
].SpawnedCount
:= utils
.readLongInt(st
);
3317 // Ñêîëüêî ðàç ïðîèãðàí çâóê
3318 gTriggers
[i
].SoundPlayCount
:= utils
.readLongInt(st
);
3319 // Ïðîèãðûâàåòñÿ ëè çâóê?
3320 b
:= utils
.readBool(st
);
3323 // Ïîçèöèÿ ïðîèãðûâàíèÿ çâóêà
3324 dw
:= utils
.readLongWord(st
);
3326 //Mem.ReadSingle(vol);
3327 st
.ReadBuffer(vol
, sizeof(vol
)); // sorry
3328 // Ñòåðåî ñìåùåíèå çâóêà
3329 //Mem.ReadSingle(pan);
3330 st
.ReadBuffer(pan
, sizeof(pan
)); // sorry
3331 // Çàïóñêàåì çâóê, åñëè åñòü
3332 if (gTriggers
[i
].Sound
<> nil) then
3334 gTriggers
[i
].Sound
.PlayPanVolume(pan
, vol
);
3335 gTriggers
[i
].Sound
.Pause(True);
3336 gTriggers
[i
].Sound
.SetPosition(dw
);
3340 gTriggers
[i
].userVars
.Free();
3341 gTriggers
[i
].userVars
:= nil;
3342 uvcount
:= utils
.readLongInt(st
);
3343 if (uvcount
< 0) or (uvcount
> 1024*1024) then raise XStreamError
.Create('invalid number of user vars in trigger');
3344 if (uvcount
> 0) then
3346 gTriggers
[i
].userVars
:= THashStrVariant
.Create();
3348 while (uvcount
> 0) do
3351 uvname
:= utils
.readStr(st
);
3352 vt
:= utils
.readLongInt(st
);
3354 varString
: begin ustr
:= utils
.readStr(st
); vv
:= ustr
; end;
3355 varBoolean
: begin ubool
:= utils
.readBool(st
); vv
:= ubool
; end;
3356 varShortInt
: begin uint
:= utils
.readLongInt(st
); vv
:= ShortInt(uint
); end;
3357 varSmallint
: begin uint
:= utils
.readLongInt(st
); vv
:= SmallInt(uint
); end;
3358 varInteger
: begin uint
:= utils
.readLongInt(st
); vv
:= LongInt(uint
); end;
3359 varByte
: begin uint
:= utils
.readLongInt(st
); vv
:= Byte(uint
); end;
3360 varWord
: begin uint
:= utils
.readLongInt(st
); vv
:= Word(uint
); end;
3361 varLongWord
: begin uint
:= utils
.readLongInt(st
); vv
:= LongWord(uint
); end;
3362 else raise Exception
.CreateFmt('cannot load uservar ''%s''', [uvname
]);
3364 gTriggers
[i
].userVars
.put(uvname
, vv
);