DEADSOFTWARE

migrating from PanelIDs to panel GUIDs; part one
[d2df-sdl.git] / src / game / g_triggers.pas
1 (* Copyright (C) DooM 2D:Forever Developers
2 *
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.
7 *
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.
12 *
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/>.
15 *)
16 {$INCLUDE ../shared/a_modes.inc}
17 unit g_triggers;
19 interface
21 uses
22 MAPDEF, e_graphics, g_basic, g_sound,
23 BinEditor, xdynrec;
25 type
26 TActivator = record
27 UID: Word;
28 TimeOut: Word;
29 end;
30 PTrigger = ^TTrigger;
31 TTrigger = record
32 public
33 ID: DWORD;
34 ClientID: DWORD;
35 TriggerType: Byte;
36 X, Y: Integer;
37 Width, Height: Word;
38 Enabled: Boolean;
39 ActivateType: Byte;
40 Keys: Byte;
41 TexturePanelGUID: Integer;
42 TexturePanelType: Word;
44 TimeOut: Word;
45 ActivateUID: Word;
46 Activators: array of TActivator;
47 PlayerCollide: Boolean;
48 DoorTime: Integer;
49 PressTime: Integer;
50 PressCount: Integer;
51 SoundPlayCount: Integer;
52 Sound: TPlayableSound;
53 AutoSpawn: Boolean;
54 SpawnCooldown: Integer;
55 SpawnedCount: Integer;
56 ShotPanelType: Word;
57 ShotPanelTime: Integer;
58 ShotSightTime: Integer;
59 ShotSightTimeout: Integer;
60 ShotSightTarget: Word;
61 ShotSightTargetN: Word;
62 ShotAmmoCount: Word;
63 ShotReloadTime: Integer;
65 mapId: AnsiString; // trigger id, from map
66 mapIndex: Integer; // index in fields['trigger'], used in save/load
67 trigPanelGUID: Integer;
69 //TrigData: TTriggerData;
70 trigData: TDynRecord; // triggerdata; owned by trigger
72 public
73 function trigCenter (): TDFPoint; inline;
75 public
76 property trigShotPanelGUID: Integer read trigPanelGUID write trigPanelGUID;
77 end;
79 function g_Triggers_Create(Trigger: TTrigger; forceInternalIndex: Integer=-1): DWORD;
80 procedure g_Triggers_Update();
81 procedure g_Triggers_Press(ID: DWORD; ActivateType: Byte; ActivateUID: Word = 0);
82 function g_Triggers_PressR(X, Y: Integer; Width, Height: Word; UID: Word;
83 ActivateType: Byte; IgnoreList: DWArray = nil): DWArray;
84 procedure g_Triggers_PressL(X1, Y1, X2, Y2: Integer; UID: DWORD; ActivateType: Byte);
85 procedure g_Triggers_PressC(CX, CY: Integer; Radius: Word; UID: Word; ActivateType: Byte; IgnoreTrigger: Integer = -1);
86 procedure g_Triggers_OpenAll();
87 procedure g_Triggers_DecreaseSpawner(ID: DWORD);
88 procedure g_Triggers_Free();
89 procedure g_Triggers_SaveState(var Mem: TBinMemoryWriter);
90 procedure g_Triggers_LoadState(var Mem: TBinMemoryReader);
92 function tr_Message(MKind: Integer; MText: string; MSendTo: Integer; MTime: Integer; ActivateUID: Integer): Boolean;
94 {
95 function tr_CloseDoor (PanelGUID: Integer; NoSound: Boolean; d2d: Boolean): Boolean;
96 function tr_OpenDoor (PanelGUID: Integer; NoSound: Boolean; d2d: Boolean): Boolean;
97 procedure tr_CloseTrap (PanelGUID: Integer; NoSound: Boolean; d2d: Boolean);
98 function tr_SetLift (PanelGUID: Integer; d: Integer; NoSound: Boolean; d2d: Boolean): Boolean;
100 function tr_Teleport (ActivateUID: Integer; TX, TY: Integer; TDir: Integer; Silent: Boolean; D2D: Boolean): Boolean;
101 function tr_Push (ActivateUID: Integer; VX, VY: Integer; ResetVel: Boolean): Boolean;
103 procedure tr_MakeEffect (X, Y, VX, VY: Integer; T, ST, CR, CG, CB: Byte; Silent, Send: Boolean);
104 function tr_SpawnShot (ShotType: Integer; wx, wy, dx, dy: Integer; ShotSound: Boolean; ShotTarget: Word): Integer;
107 var
108 gTriggerClientID: Integer = 0;
109 gTriggers: array of TTrigger;
110 gSecretsCount: Integer = 0;
111 gMonstersSpawned: array of LongInt = nil;
113 implementation
115 uses
116 Math,
117 g_player, g_map, g_panel, g_gfx, g_game, g_textures,
118 g_console, g_monsters, g_items, g_phys, g_weapons,
119 wadreader, g_main, SysUtils, e_log, g_language,
120 g_options, g_net, g_netmsg, utils, xparser;
122 const
123 TRIGGER_SIGNATURE = $58475254; // 'TRGX'
124 TRAP_DAMAGE = 1000;
127 function TTrigger.trigCenter (): TDFPoint; inline;
128 begin
129 result := TDFPoint.Create(x+width div 2, y+height div 2);
130 end;
133 function FindTrigger (): DWORD;
134 var
135 i: Integer;
136 begin
137 for i := 0 to High(gTriggers) do
138 begin
139 if gTriggers[i].TriggerType = TRIGGER_NONE then begin result := i; exit; end;
140 end;
142 if (gTriggers = nil) then
143 begin
144 SetLength(gTriggers, 8);
145 result := 0;
146 end
147 else
148 begin
149 result := Length(gTriggers);
150 SetLength(gTriggers, result+8);
151 for i := result to High(gTriggers) do gTriggers[i].TriggerType := TRIGGER_NONE;
152 end;
153 end;
156 function tr_CloseDoor (PanelGUID: Integer; NoSound: Boolean; d2d: Boolean): Boolean;
157 var
158 a, b, c: Integer;
159 pan: TPanel;
160 PanelID: Integer;
161 begin
162 result := false;
163 pan := g_Map_PanelByGUID(PanelGUID);
164 if (pan = nil) or not pan.isGWall then exit; //!FIXME!TRIGANY!
165 PanelID := pan.arrIdx;
167 if not d2d then
168 begin
169 with gWalls[PanelID] do
170 begin
171 if g_CollidePlayer(X, Y, Width, Height) or g_Mons_IsAnyAliveAt(X, Y, Width, Height) then Exit;
172 if not Enabled then
173 begin
174 if not NoSound then
175 begin
176 g_Sound_PlayExAt('SOUND_GAME_DOORCLOSE', X, Y);
177 if g_Game_IsServer and g_Game_IsNet then MH_SEND_Sound(X, Y, 'SOUND_GAME_DOORCLOSE');
178 end;
179 g_Map_EnableWallGUID(PanelGUID);
180 result := true;
181 end;
182 end;
183 end
184 else
185 begin
186 if (gDoorMap = nil) then exit;
188 c := -1;
189 for a := 0 to High(gDoorMap) do
190 begin
191 for b := 0 to High(gDoorMap[a]) do
192 begin
193 if gDoorMap[a, b] = DWORD(PanelID) then
194 begin
195 c := a;
196 break;
197 end;
198 end;
199 if (c <> -1) then break;
200 end;
201 if (c = -1) then exit;
203 for b := 0 to High(gDoorMap[c]) do
204 begin
205 with gWalls[gDoorMap[c, b]] do
206 begin
207 if g_CollidePlayer(X, Y, Width, Height) or g_Mons_IsAnyAliveAt(X, Y, Width, Height) then exit;
208 end;
209 end;
211 if not NoSound then
212 begin
213 for b := 0 to High(gDoorMap[c]) do
214 begin
215 if not gWalls[gDoorMap[c, b]].Enabled then
216 begin
217 with gWalls[PanelID] do
218 begin
219 g_Sound_PlayExAt('SOUND_GAME_DOORCLOSE', X, Y);
220 if g_Game_IsServer and g_Game_IsNet then MH_SEND_Sound(X, Y, 'SOUND_GAME_DOORCLOSE');
221 end;
222 break;
223 end;
224 end;
225 end;
227 for b := 0 to High(gDoorMap[c]) do
228 begin
229 if not gWalls[gDoorMap[c, b]].Enabled then
230 begin
231 g_Map_EnableWall_XXX(gDoorMap[c, b]);
232 result := true;
233 end;
234 end;
235 end;
236 end;
239 procedure tr_CloseTrap (PanelGUID: Integer; NoSound: Boolean; d2d: Boolean);
240 var
241 a, b, c: Integer;
242 wx, wy, wh, ww: Integer;
243 pan: TPanel;
244 PanelID: Integer;
246 function monsDamage (mon: TMonster): Boolean;
247 begin
248 result := false; // don't stop
249 if g_Obj_Collide(wx, wy, ww, wh, @mon.Obj) then mon.Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
250 end;
252 begin
253 pan := g_Map_PanelByGUID(PanelGUID);
254 if (pan = nil) or not pan.isGWall then exit; //!FIXME!TRIGANY!
255 PanelID := pan.arrIdx;
257 if not d2d then
258 begin
259 with gWalls[PanelID] do
260 begin
261 if (not NoSound) and (not Enabled) then
262 begin
263 g_Sound_PlayExAt('SOUND_GAME_SWITCH1', X, Y);
264 if g_Game_IsServer and g_Game_IsNet then MH_SEND_Sound(X, Y, 'SOUND_GAME_SWITCH1');
265 end;
266 end;
268 wx := gWalls[PanelID].X;
269 wy := gWalls[PanelID].Y;
270 ww := gWalls[PanelID].Width;
271 wh := gWalls[PanelID].Height;
273 with gWalls[PanelID] do
274 begin
275 if gPlayers <> nil then
276 begin
277 for a := 0 to High(gPlayers) do
278 begin
279 if (gPlayers[a] <> nil) and gPlayers[a].Live and gPlayers[a].Collide(X, Y, Width, Height) then
280 begin
281 gPlayers[a].Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
282 end;
283 end;
284 end;
286 //g_Mons_ForEach(monsDamage);
287 g_Mons_ForEachAliveAt(wx, wy, ww, wh, monsDamage);
289 if not Enabled then g_Map_EnableWallGUID(PanelGUID);
290 end;
291 end
292 else
293 begin
294 if (gDoorMap = nil) then exit;
296 c := -1;
297 for a := 0 to High(gDoorMap) do
298 begin
299 for b := 0 to High(gDoorMap[a]) do
300 begin
301 if gDoorMap[a, b] = DWORD(PanelID) then
302 begin
303 c := a;
304 break;
305 end;
306 end;
307 if (c <> -1) then break;
308 end;
309 if (c = -1) then exit;
311 if not NoSound then
312 begin
313 for b := 0 to High(gDoorMap[c]) do
314 begin
315 if not gWalls[gDoorMap[c, b]].Enabled then
316 begin
317 with gWalls[PanelID] do
318 begin
319 g_Sound_PlayExAt('SOUND_GAME_SWITCH1', X, Y);
320 if g_Game_IsServer and g_Game_IsNet then MH_SEND_Sound(X, Y, 'SOUND_GAME_SWITCH1');
321 end;
322 Break;
323 end;
324 end;
325 end;
327 for b := 0 to High(gDoorMap[c]) do
328 begin
329 wx := gWalls[gDoorMap[c, b]].X;
330 wy := gWalls[gDoorMap[c, b]].Y;
331 ww := gWalls[gDoorMap[c, b]].Width;
332 wh := gWalls[gDoorMap[c, b]].Height;
334 with gWalls[gDoorMap[c, b]] do
335 begin
336 if gPlayers <> nil then
337 begin
338 for a := 0 to High(gPlayers) do
339 begin
340 if (gPlayers[a] <> nil) and gPlayers[a].Live and gPlayers[a].Collide(X, Y, Width, Height) then
341 begin
342 gPlayers[a].Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
343 end;
344 end;
345 end;
347 //g_Mons_ForEach(monsDamage);
348 g_Mons_ForEachAliveAt(wx, wy, ww, wh, monsDamage);
349 (*
350 if gMonsters <> nil then
351 for a := 0 to High(gMonsters) do
352 if (gMonsters[a] <> nil) and gMonsters[a].Live and
353 g_Obj_Collide(X, Y, Width, Height, @gMonsters[a].Obj) then
354 gMonsters[a].Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
355 *)
357 if not Enabled then g_Map_EnableWall_XXX(gDoorMap[c, b]);
358 end;
359 end;
360 end;
361 end;
364 function tr_OpenDoor (PanelGUID: Integer; NoSound: Boolean; d2d: Boolean): Boolean;
365 var
366 a, b, c: Integer;
367 pan: TPanel;
368 PanelID: Integer;
369 begin
370 result := false;
371 pan := g_Map_PanelByGUID(PanelGUID);
372 if (pan = nil) or not pan.isGWall then exit; //!FIXME!TRIGANY!
373 PanelID := pan.arrIdx;
375 if not d2d then
376 begin
377 with gWalls[PanelID] do
378 begin
379 if Enabled then
380 begin
381 if not NoSound then
382 begin
383 g_Sound_PlayExAt('SOUND_GAME_DOOROPEN', X, Y);
384 if g_Game_IsServer and g_Game_IsNet then MH_SEND_Sound(X, Y, 'SOUND_GAME_DOOROPEN');
385 end;
386 g_Map_DisableWallGUID(PanelGUID);
387 result := true;
388 end;
389 end
390 end
391 else
392 begin
393 if (gDoorMap = nil) then exit;
395 c := -1;
396 for a := 0 to High(gDoorMap) do
397 begin
398 for b := 0 to High(gDoorMap[a]) do
399 begin
400 if gDoorMap[a, b] = DWORD(PanelID) then
401 begin
402 c := a;
403 break;
404 end;
405 end;
406 if (c <> -1) then break;
407 end;
408 if (c = -1) then exit;
410 if not NoSound then
411 begin
412 for b := 0 to High(gDoorMap[c]) do
413 begin
414 if gWalls[gDoorMap[c, b]].Enabled then
415 begin
416 with gWalls[PanelID] do
417 begin
418 g_Sound_PlayExAt('SOUND_GAME_DOOROPEN', X, Y);
419 if g_Game_IsServer and g_Game_IsNet then MH_SEND_Sound(X, Y, 'SOUND_GAME_DOOROPEN');
420 end;
421 break;
422 end;
423 end;
424 end;
426 for b := 0 to High(gDoorMap[c]) do
427 begin
428 if gWalls[gDoorMap[c, b]].Enabled then
429 begin
430 g_Map_DisableWall_XXX(gDoorMap[c, b]);
431 result := true;
432 end;
433 end;
434 end;
435 end;
438 function tr_SetLift (PanelGUID: Integer; d: Integer; NoSound: Boolean; d2d: Boolean): Boolean;
439 var
440 a, b, c: Integer;
441 t: Integer = 0;
442 pan: TPanel;
443 PanelID: Integer;
444 begin
445 result := false;
446 pan := g_Map_PanelByGUID(PanelGUID);
447 if (pan = nil) or not pan.isGLift then exit; //!FIXME!TRIGANY!
448 PanelID := pan.arrIdx;
450 if (gLifts[PanelID].PanelType = PANEL_LIFTUP) or (gLifts[PanelID].PanelType = PANEL_LIFTDOWN) then
451 begin
452 case d of
453 0: t := 0;
454 1: t := 1;
455 else t := IfThen(gLifts[PanelID].LiftType = 1, 0, 1);
456 end
457 end
458 else if (gLifts[PanelID].PanelType = PANEL_LIFTLEFT) or (gLifts[PanelID].PanelType = PANEL_LIFTRIGHT) then
459 begin
460 case d of
461 0: t := 2;
462 1: t := 3;
463 else t := IfThen(gLifts[PanelID].LiftType = 2, 3, 2);
464 end;
465 end;
467 if not d2d then
468 begin
469 with gLifts[PanelID] do
470 begin
471 if (LiftType <> t) then
472 begin
473 g_Map_SetLiftGUID(PanelGUID, t); //???
474 //if not NoSound then g_Sound_PlayExAt('SOUND_GAME_SWITCH0', X, Y);
475 result := true;
476 end;
477 end;
478 end
479 else // Êàê â D2d
480 begin
481 if (gLiftMap = nil) then exit;
483 c := -1;
484 for a := 0 to High(gLiftMap) do
485 begin
486 for b := 0 to High(gLiftMap[a]) do
487 begin
488 if (gLiftMap[a, b] = DWORD(PanelID)) then
489 begin
490 c := a;
491 break;
492 end;
493 end;
494 if (c <> -1) then break;
495 end;
496 if (c = -1) then exit;
498 {if not NoSound then
499 for b := 0 to High(gLiftMap[c]) do
500 if gLifts[gLiftMap[c, b]].LiftType <> t then
501 begin
502 with gLifts[PanelID] do
503 g_Sound_PlayExAt('SOUND_GAME_SWITCH0', X, Y);
504 Break;
505 end;}
507 for b := 0 to High(gLiftMap[c]) do
508 begin
509 with gLifts[gLiftMap[c, b]] do
510 begin
511 if (LiftType <> t) then
512 begin
513 g_Map_SetLift_XXX(gLiftMap[c, b], t);
514 result := true;
515 end;
516 end;
517 end;
518 end;
519 end;
522 function tr_SpawnShot (ShotType: Integer; wx, wy, dx, dy: Integer; ShotSound: Boolean; ShotTarget: Word): Integer;
523 var
524 snd: string;
525 Projectile: Boolean;
526 TextureID: DWORD;
527 Anim: TAnimation;
528 begin
529 result := -1;
530 TextureID := DWORD(-1);
531 snd := 'SOUND_WEAPON_FIREROCKET';
532 Projectile := true;
534 case ShotType of
535 TRIGGER_SHOT_PISTOL:
536 begin
537 g_Weapon_pistol(wx, wy, dx, dy, 0, True);
538 snd := 'SOUND_WEAPON_FIREPISTOL';
539 Projectile := False;
540 if ShotSound then
541 begin
542 g_Player_CreateShell(wx, wy, 0, -2, SHELL_BULLET);
543 if g_Game_IsNet then MH_SEND_Effect(wx, wy, 0, NET_GFX_SHELL1);
544 end;
545 end;
547 TRIGGER_SHOT_BULLET:
548 begin
549 g_Weapon_mgun(wx, wy, dx, dy, 0, True);
550 if gSoundEffectsDF then snd := 'SOUND_WEAPON_FIRECGUN'
551 else snd := 'SOUND_WEAPON_FIREPISTOL';
552 Projectile := False;
553 if ShotSound then
554 begin
555 g_Player_CreateShell(wx, wy, 0, -2, SHELL_BULLET);
556 if g_Game_IsNet then MH_SEND_Effect(wx, wy, 0, NET_GFX_SHELL1);
557 end;
558 end;
560 TRIGGER_SHOT_SHOTGUN:
561 begin
562 g_Weapon_Shotgun(wx, wy, dx, dy, 0, True);
563 snd := 'SOUND_WEAPON_FIRESHOTGUN';
564 Projectile := False;
565 if ShotSound then
566 begin
567 g_Player_CreateShell(wx, wy, 0, -2, SHELL_SHELL);
568 if g_Game_IsNet then MH_SEND_Effect(wx, wy, 0, NET_GFX_SHELL2);
569 end;
570 end;
572 TRIGGER_SHOT_SSG:
573 begin
574 g_Weapon_DShotgun(wx, wy, dx, dy, 0, True);
575 snd := 'SOUND_WEAPON_FIRESHOTGUN2';
576 Projectile := False;
577 if ShotSound then
578 begin
579 g_Player_CreateShell(wx, wy, 0, -2, SHELL_SHELL);
580 g_Player_CreateShell(wx, wy, 0, -2, SHELL_SHELL);
581 if g_Game_IsNet then MH_SEND_Effect(wx, wy, 0, NET_GFX_SHELL3);
582 end;
583 end;
585 TRIGGER_SHOT_IMP:
586 begin
587 g_Weapon_ball1(wx, wy, dx, dy, 0, -1, True);
588 snd := 'SOUND_WEAPON_FIREBALL';
589 end;
591 TRIGGER_SHOT_PLASMA:
592 begin
593 g_Weapon_Plasma(wx, wy, dx, dy, 0, -1, True);
594 snd := 'SOUND_WEAPON_FIREPLASMA';
595 end;
597 TRIGGER_SHOT_SPIDER:
598 begin
599 g_Weapon_aplasma(wx, wy, dx, dy, 0, -1, True);
600 snd := 'SOUND_WEAPON_FIREPLASMA';
601 end;
603 TRIGGER_SHOT_CACO:
604 begin
605 g_Weapon_ball2(wx, wy, dx, dy, 0, -1, True);
606 snd := 'SOUND_WEAPON_FIREBALL';
607 end;
609 TRIGGER_SHOT_BARON:
610 begin
611 g_Weapon_ball7(wx, wy, dx, dy, 0, -1, True);
612 snd := 'SOUND_WEAPON_FIREBALL';
613 end;
615 TRIGGER_SHOT_MANCUB:
616 begin
617 g_Weapon_manfire(wx, wy, dx, dy, 0, -1, True);
618 snd := 'SOUND_WEAPON_FIREBALL';
619 end;
621 TRIGGER_SHOT_REV:
622 begin
623 g_Weapon_revf(wx, wy, dx, dy, 0, ShotTarget, -1, True);
624 snd := 'SOUND_WEAPON_FIREREV';
625 end;
627 TRIGGER_SHOT_ROCKET:
628 begin
629 g_Weapon_Rocket(wx, wy, dx, dy, 0, -1, True);
630 snd := 'SOUND_WEAPON_FIREROCKET';
631 end;
633 TRIGGER_SHOT_BFG:
634 begin
635 g_Weapon_BFGShot(wx, wy, dx, dy, 0, -1, True);
636 snd := 'SOUND_WEAPON_FIREBFG';
637 end;
639 TRIGGER_SHOT_EXPL:
640 begin
641 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
642 begin
643 Anim := TAnimation.Create(TextureID, False, 6);
644 Anim.Blending := False;
645 g_GFX_OnceAnim(wx-64, wy-64, Anim);
646 Anim.Free();
647 end;
648 Projectile := False;
649 g_Weapon_Explode(wx, wy, 60, 0);
650 snd := 'SOUND_WEAPON_EXPLODEROCKET';
651 end;
653 TRIGGER_SHOT_BFGEXPL:
654 begin
655 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_BFG') then
656 begin
657 Anim := TAnimation.Create(TextureID, False, 6);
658 Anim.Blending := False;
659 g_GFX_OnceAnim(wx-64, wy-64, Anim);
660 Anim.Free();
661 end;
662 Projectile := False;
663 g_Weapon_BFG9000(wx, wy, 0);
664 snd := 'SOUND_WEAPON_EXPLODEBFG';
665 end;
667 else exit;
668 end;
670 if g_Game_IsNet and g_Game_IsServer then
671 begin
672 case ShotType of
673 TRIGGER_SHOT_EXPL: MH_SEND_Effect(wx, wy, Byte(ShotSound), NET_GFX_EXPLODE);
674 TRIGGER_SHOT_BFGEXPL: MH_SEND_Effect(wx, wy, Byte(ShotSound), NET_GFX_BFGEXPL);
675 else
676 begin
677 if Projectile then MH_SEND_CreateShot(LastShotID);
678 if ShotSound then MH_SEND_Sound(wx, wy, snd);
679 end;
680 end;
681 end;
683 if ShotSound then g_Sound_PlayExAt(snd, wx, wy);
685 if Projectile then Result := LastShotID;
686 end;
689 procedure MakeShot (var Trigger: TTrigger; wx, wy, dx, dy: Integer; TargetUID: Word);
690 begin
691 with Trigger do
692 begin
693 if (trigData.trigShotAmmo = 0) or ((trigData.trigShotAmmo > 0) and (ShotAmmoCount > 0)) then
694 begin
695 if (trigShotPanelGUID <> -1) and (ShotPanelTime = 0) then
696 begin
697 g_Map_SwitchTextureGUID(ShotPanelType, trigShotPanelGUID);
698 ShotPanelTime := 4; // òèêîâ íà âñïûøêó âûñòðåëà
699 end;
701 if (trigData.trigShotIntSight > 0) then ShotSightTimeout := 180; // ~= 5 ñåêóíä
703 if (ShotAmmoCount > 0) then Dec(ShotAmmoCount);
705 dx += Random(trigData.trigShotAccuracy)-Random(trigData.trigShotAccuracy);
706 dy += Random(trigData.trigShotAccuracy)-Random(trigData.trigShotAccuracy);
708 tr_SpawnShot(trigData.trigShotType, wx, wy, dx, dy, trigData.trigShotSound, TargetUID);
709 end
710 else
711 begin
712 if (trigData.trigShotIntReload > 0) and (ShotReloadTime = 0) then
713 begin
714 ShotReloadTime := trigData.trigShotIntReload; // òèêîâ íà ïåðåçàðÿäêó ïóøêè
715 end;
716 end;
717 end;
718 end;
721 procedure tr_MakeEffect (X, Y, VX, VY: Integer; T, ST, CR, CG, CB: Byte; Silent, Send: Boolean);
722 var
723 FramesID: DWORD;
724 Anim: TAnimation;
725 begin
726 if T = TRIGGER_EFFECT_PARTICLE then
727 begin
728 case ST of
729 TRIGGER_EFFECT_SLIQUID:
730 begin
731 if (CR = 255) and (CG = 0) and (CB = 0) then g_GFX_SimpleWater(X, Y, 1, VX, VY, 1, 0, 0, 0)
732 else if (CR = 0) and (CG = 255) and (CB = 0) then g_GFX_SimpleWater(X, Y, 1, VX, VY, 2, 0, 0, 0)
733 else if (CR = 0) and (CG = 0) and (CB = 255) then g_GFX_SimpleWater(X, Y, 1, VX, VY, 3, 0, 0, 0)
734 else g_GFX_SimpleWater(X, Y, 1, VX, VY, 0, 0, 0, 0);
735 end;
736 TRIGGER_EFFECT_LLIQUID: g_GFX_SimpleWater(X, Y, 1, VX, VY, 4, CR, CG, CB);
737 TRIGGER_EFFECT_DLIQUID: g_GFX_SimpleWater(X, Y, 1, VX, VY, 5, CR, CG, CB);
738 TRIGGER_EFFECT_BLOOD: g_GFX_Blood(X, Y, 1, VX, VY, 0, 0, CR, CG, CB);
739 TRIGGER_EFFECT_SPARK: g_GFX_Spark(X, Y, 1, GetAngle2(VX, VY), 0, 0);
740 TRIGGER_EFFECT_BUBBLE: g_GFX_Bubbles(X, Y, 1, 0, 0);
741 end;
742 end;
744 if T = TRIGGER_EFFECT_ANIMATION then
745 begin
746 case ST of
747 EFFECT_TELEPORT: begin
748 if g_Frames_Get(FramesID, 'FRAMES_TELEPORT') then
749 begin
750 Anim := TAnimation.Create(FramesID, False, 3);
751 if not Silent then g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X, Y);
752 g_GFX_OnceAnim(X-32, Y-32, Anim);
753 Anim.Free();
754 end;
755 if Send and g_Game_IsServer and g_Game_IsNet then MH_SEND_Effect(X, Y, Byte(not Silent), NET_GFX_TELE);
756 end;
757 EFFECT_RESPAWN: begin
758 if g_Frames_Get(FramesID, 'FRAMES_ITEM_RESPAWN') then
759 begin
760 Anim := TAnimation.Create(FramesID, False, 4);
761 if not Silent then g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
762 g_GFX_OnceAnim(X-16, Y-16, Anim);
763 Anim.Free();
764 end;
765 if Send and g_Game_IsServer and g_Game_IsNet then MH_SEND_Effect(X-16, Y-16, Byte(not Silent), NET_GFX_RESPAWN);
766 end;
767 EFFECT_FIRE: begin
768 if g_Frames_Get(FramesID, 'FRAMES_FIRE') then
769 begin
770 Anim := TAnimation.Create(FramesID, False, 4);
771 if not Silent then g_Sound_PlayExAt('SOUND_FIRE', X, Y);
772 g_GFX_OnceAnim(X-32, Y-128, Anim);
773 Anim.Free();
774 end;
775 if Send and g_Game_IsServer and g_Game_IsNet then MH_SEND_Effect(X-32, Y-128, Byte(not Silent), NET_GFX_FIRE);
776 end;
777 end;
778 end;
779 end;
782 function tr_Teleport (ActivateUID: Integer; TX, TY: Integer; TDir: Integer; Silent: Boolean; D2D: Boolean): Boolean;
783 var
784 p: TPlayer;
785 m: TMonster;
786 begin
787 Result := False;
788 if (ActivateUID < 0) or (ActivateUID > $FFFF) then Exit;
789 case g_GetUIDType(ActivateUID) of
790 UID_PLAYER:
791 begin
792 p := g_Player_Get(ActivateUID);
793 if p = nil then Exit;
794 if D2D then
795 begin
796 if p.TeleportTo(TX-(p.Obj.Rect.Width div 2), TY-p.Obj.Rect.Height, Silent, TDir) then result := true;
797 end
798 else
799 begin
800 if p.TeleportTo(TX, TY, Silent, TDir) then result := true;
801 end;
802 end;
803 UID_MONSTER:
804 begin
805 m := g_Monsters_ByUID(ActivateUID);
806 if m = nil then Exit;
807 if D2D then
808 begin
809 if m.TeleportTo(TX-(m.Obj.Rect.Width div 2), TY-m.Obj.Rect.Height, Silent, TDir) then result := true;
810 end
811 else
812 begin
813 if m.TeleportTo(TX, TY, Silent, TDir) then result := true;
814 end;
815 end;
816 end;
817 end;
820 function tr_Push (ActivateUID: Integer; VX, VY: Integer; ResetVel: Boolean): Boolean;
821 var
822 p: TPlayer;
823 m: TMonster;
824 begin
825 result := true;
826 if (ActivateUID < 0) or (ActivateUID > $FFFF) then exit;
827 case g_GetUIDType(ActivateUID) of
828 UID_PLAYER:
829 begin
830 p := g_Player_Get(ActivateUID);
831 if p = nil then Exit;
833 if ResetVel then
834 begin
835 p.GameVelX := 0;
836 p.GameVelY := 0;
837 p.GameAccelX := 0;
838 p.GameAccelY := 0;
839 end;
841 p.Push(VX, VY);
842 end;
844 UID_MONSTER:
845 begin
846 m := g_Monsters_ByUID(ActivateUID);
847 if m = nil then Exit;
849 if ResetVel then
850 begin
851 m.GameVelX := 0;
852 m.GameVelY := 0;
853 m.GameAccelX := 0;
854 m.GameAccelY := 0;
855 end;
857 m.Push(VX, VY);
858 end;
859 end;
860 end;
863 function tr_Message (MKind: Integer; MText: string; MSendTo: Integer; MTime: Integer; ActivateUID: Integer): Boolean;
864 var
865 msg: string;
866 p: TPlayer;
867 i: Integer;
868 begin
869 Result := True;
870 if (ActivateUID < 0) or (ActivateUID > $FFFF) then Exit;
871 msg := b_Text_Format(MText);
872 case MSendTo of
873 0: // activator
874 begin
875 if g_GetUIDType(ActivateUID) = UID_PLAYER then
876 begin
877 if g_Game_IsWatchedPlayer(ActivateUID) then
878 begin
879 if MKind = 0 then g_Console_Add(msg, True)
880 else if MKind = 1 then g_Game_Message(msg, MTime);
881 end
882 else
883 begin
884 p := g_Player_Get(ActivateUID);
885 if g_Game_IsNet and (p.FClientID >= 0) then
886 begin
887 if MKind = 0 then MH_SEND_Chat(msg, NET_CHAT_SYSTEM, p.FClientID)
888 else if MKind = 1 then MH_SEND_GameEvent(NET_EV_BIGTEXT, MTime, msg, p.FClientID);
889 end;
890 end;
891 end;
892 end;
894 1: // activator's team
895 begin
896 if g_GetUIDType(ActivateUID) = UID_PLAYER then
897 begin
898 p := g_Player_Get(ActivateUID);
899 if g_Game_IsWatchedTeam(p.Team) then
900 begin
901 if MKind = 0 then g_Console_Add(msg, True)
902 else if MKind = 1 then g_Game_Message(msg, MTime);
903 end;
905 if g_Game_IsNet then
906 begin
907 for i := Low(gPlayers) to High(gPlayers) do
908 begin
909 if (gPlayers[i].Team = p.Team) and (gPlayers[i].FClientID >= 0) then
910 begin
911 if MKind = 0 then MH_SEND_Chat(msg, NET_CHAT_SYSTEM, gPlayers[i].FClientID)
912 else if MKind = 1 then MH_SEND_GameEvent(NET_EV_BIGTEXT, MTime, msg, gPlayers[i].FClientID);
913 end;
914 end;
915 end;
916 end;
917 end;
919 2: // activator's enemy team
920 begin
921 if g_GetUIDType(ActivateUID) = UID_PLAYER then
922 begin
923 p := g_Player_Get(ActivateUID);
924 if g_Game_IsWatchedTeam(p.Team) then
925 begin
926 if MKind = 0 then g_Console_Add(msg, True)
927 else if MKind = 1 then g_Game_Message(msg, MTime);
928 end;
930 if g_Game_IsNet then
931 begin
932 for i := Low(gPlayers) to High(gPlayers) do
933 begin
934 if (gPlayers[i].Team <> p.Team) and (gPlayers[i].FClientID >= 0) then
935 begin
936 if MKind = 0 then MH_SEND_Chat(msg, NET_CHAT_SYSTEM, gPlayers[i].FClientID)
937 else if MKind = 1 then MH_SEND_GameEvent(NET_EV_BIGTEXT, MTime, msg, gPlayers[i].FClientID);
938 end;
939 end;
940 end;
941 end;
942 end;
944 3: // red team
945 begin
946 if g_Game_IsWatchedTeam(TEAM_RED) then
947 begin
948 if MKind = 0 then g_Console_Add(msg, True)
949 else if MKind = 1 then g_Game_Message(msg, MTime);
950 end;
952 if g_Game_IsNet then
953 begin
954 for i := Low(gPlayers) to High(gPlayers) do
955 begin
956 if (gPlayers[i].Team = TEAM_RED) and (gPlayers[i].FClientID >= 0) then
957 begin
958 if MKind = 0 then MH_SEND_Chat(msg, NET_CHAT_SYSTEM, gPlayers[i].FClientID)
959 else if MKind = 1 then MH_SEND_GameEvent(NET_EV_BIGTEXT, MTime, msg, gPlayers[i].FClientID);
960 end;
961 end;
962 end;
963 end;
965 4: // blue team
966 begin
967 if g_Game_IsWatchedTeam(TEAM_BLUE) then
968 begin
969 if MKind = 0 then g_Console_Add(msg, True)
970 else if MKind = 1 then g_Game_Message(msg, MTime);
971 end;
973 if g_Game_IsNet then
974 begin
975 for i := Low(gPlayers) to High(gPlayers) do
976 begin
977 if (gPlayers[i].Team = TEAM_BLUE) and (gPlayers[i].FClientID >= 0) then
978 begin
979 if MKind = 0 then MH_SEND_Chat(msg, NET_CHAT_SYSTEM, gPlayers[i].FClientID)
980 else if MKind = 1 then MH_SEND_GameEvent(NET_EV_BIGTEXT, MTime, msg, gPlayers[i].FClientID);
981 end;
982 end;
983 end;
984 end;
986 5: // everyone
987 begin
988 if MKind = 0 then g_Console_Add(msg, True)
989 else if MKind = 1 then g_Game_Message(msg, MTime);
991 if g_Game_IsNet then
992 begin
993 if MKind = 0 then MH_SEND_Chat(msg, NET_CHAT_SYSTEM)
994 else if MKind = 1 then MH_SEND_GameEvent(NET_EV_BIGTEXT, MTime, msg);
995 end;
996 end;
997 end;
998 end;
1001 function tr_ShotAimCheck (var Trigger: TTrigger; Obj: PObj): Boolean;
1002 begin
1003 result := false;
1004 with Trigger do
1005 begin
1006 if TriggerType <> TRIGGER_SHOT then Exit;
1007 result := (trigData.trigShotAim and TRIGGER_SHOT_AIM_ALLMAP > 0)
1008 or g_Obj_Collide(X, Y, Width, Height, Obj);
1009 if result and (trigData.trigShotAim and TRIGGER_SHOT_AIM_TRACE > 0) then
1010 begin
1011 result := g_TraceVector(trigData.trigShotPos.X, trigData.trigShotPos.Y,
1012 Obj^.X + Obj^.Rect.X + (Obj^.Rect.Width div 2),
1013 Obj^.Y + Obj^.Rect.Y + (Obj^.Rect.Height div 2));
1014 end;
1015 end;
1016 end;
1019 function ActivateTrigger (var Trigger: TTrigger; actType: Byte): Boolean;
1020 var
1021 animonce: Boolean;
1022 p: TPlayer;
1023 m: TMonster;
1024 pan: TPanel;
1025 idx, k, wx, wy, xd, yd: Integer;
1026 iid: LongWord;
1027 coolDown: Boolean;
1028 pAngle: Real;
1029 FramesID: DWORD;
1030 Anim: TAnimation;
1031 UIDType: Byte;
1032 TargetUID: Word;
1033 it: PItem;
1034 mon: TMonster;
1036 function monsShotTarget (mon: TMonster): Boolean;
1037 begin
1038 result := false; // don't stop
1039 if mon.Live and tr_ShotAimCheck(Trigger, @(mon.Obj)) then
1040 begin
1041 xd := mon.GameX + mon.Obj.Rect.Width div 2;
1042 yd := mon.GameY + mon.Obj.Rect.Height div 2;
1043 TargetUID := mon.UID;
1044 result := true; // stop
1045 end;
1046 end;
1048 function monsShotTargetMonPlr (mon: TMonster): Boolean;
1049 begin
1050 result := false; // don't stop
1051 if mon.Live and tr_ShotAimCheck(Trigger, @(mon.Obj)) then
1052 begin
1053 xd := mon.GameX + mon.Obj.Rect.Width div 2;
1054 yd := mon.GameY + mon.Obj.Rect.Height div 2;
1055 TargetUID := mon.UID;
1056 result := true; // stop
1057 end;
1058 end;
1060 function monShotTargetPlrMon (mon: TMonster): Boolean;
1061 begin
1062 result := false; // don't stop
1063 if mon.Live and tr_ShotAimCheck(Trigger, @(mon.Obj)) then
1064 begin
1065 xd := mon.GameX + mon.Obj.Rect.Width div 2;
1066 yd := mon.GameY + mon.Obj.Rect.Height div 2;
1067 TargetUID := mon.UID;
1068 result := true; // stop
1069 end;
1070 end;
1072 begin
1073 result := false;
1074 if g_Game_IsClient then exit;
1076 if not Trigger.Enabled then exit;
1077 if (Trigger.TimeOut <> 0) and (actType <> ACTIVATE_CUSTOM) then exit;
1078 if gLMSRespawn = LMS_RESPAWN_WARMUP then exit;
1080 animonce := False;
1082 coolDown := (actType <> 0);
1084 with Trigger do
1085 begin
1086 case TriggerType of
1087 TRIGGER_EXIT:
1088 begin
1089 g_Sound_PlayEx('SOUND_GAME_SWITCH0');
1090 if g_Game_IsNet then MH_SEND_Sound(X, Y, 'SOUND_GAME_SWITCH0');
1091 gExitByTrigger := True;
1092 g_Game_ExitLevel(trigData.trigMapName);
1093 TimeOut := 18;
1094 Result := True;
1096 Exit;
1097 end;
1099 TRIGGER_TELEPORT:
1100 begin
1101 Result := tr_Teleport(ActivateUID,
1102 trigData.trigTargetPoint.X, trigData.trigTargetPoint.Y,
1103 trigData.trigTlpDir, trigData.trigsilent_teleport,
1104 trigData.trigd2d_teleport);
1105 TimeOut := 0;
1106 end;
1108 TRIGGER_OPENDOOR:
1109 begin
1110 Result := tr_OpenDoor(trigPanelGUID, trigData.trigNoSound, trigData.trigd2d_doors);
1111 TimeOut := 0;
1112 end;
1114 TRIGGER_CLOSEDOOR:
1115 begin
1116 Result := tr_CloseDoor(trigPanelGUID, trigData.trigNoSound, trigData.trigd2d_doors);
1117 TimeOut := 0;
1118 end;
1120 TRIGGER_DOOR, TRIGGER_DOOR5:
1121 begin
1122 pan := g_Map_PanelByGUID(trigPanelGUID);
1123 if (pan <> nil) and pan.isGWall then
1124 begin
1125 if gWalls[{trigPanelID}pan.arrIdx].Enabled then
1126 begin
1127 result := tr_OpenDoor(trigPanelGUID, trigData.trigNoSound, trigData.trigd2d_doors);
1128 if (TriggerType = TRIGGER_DOOR5) then DoorTime := 180;
1129 end
1130 else
1131 begin
1132 result := tr_CloseDoor(trigPanelGUID, trigData.trigNoSound, trigData.trigd2d_doors);
1133 end;
1135 if result then TimeOut := 18;
1136 end;
1137 end;
1139 TRIGGER_CLOSETRAP, TRIGGER_TRAP:
1140 begin
1141 tr_CloseTrap(trigPanelGUID, trigData.trigNoSound, trigData.trigd2d_doors);
1143 if TriggerType = TRIGGER_TRAP then
1144 begin
1145 DoorTime := 40;
1146 TimeOut := 76;
1147 end
1148 else
1149 begin
1150 DoorTime := -1;
1151 TimeOut := 0;
1152 end;
1154 Result := True;
1155 end;
1157 TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF:
1158 begin
1159 PressCount += 1;
1160 if PressTime = -1 then PressTime := trigData.trigWait;
1161 if coolDown then TimeOut := 18 else TimeOut := 0;
1162 Result := True;
1163 end;
1165 TRIGGER_SECRET:
1166 if g_GetUIDType(ActivateUID) = UID_PLAYER then
1167 begin
1168 Enabled := False;
1169 Result := True;
1170 if gLMSRespawn = LMS_RESPAWN_NONE then
1171 begin
1172 g_Player_Get(ActivateUID).GetSecret();
1173 Inc(gCoopSecretsFound);
1174 if g_Game_IsNet then MH_SEND_GameStats();
1175 end;
1176 end;
1178 TRIGGER_LIFTUP:
1179 begin
1180 Result := tr_SetLift(trigPanelGUID, 0, trigData.trigNoSound, trigData.trigd2d_doors);
1181 TimeOut := 0;
1183 if (not trigData.trigNoSound) and Result then begin
1184 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1185 X + (Width div 2),
1186 Y + (Height div 2));
1187 if g_Game_IsServer and g_Game_IsNet then
1188 MH_SEND_Sound(X + (Width div 2),
1189 Y + (Height div 2),
1190 'SOUND_GAME_SWITCH0');
1191 end;
1192 end;
1194 TRIGGER_LIFTDOWN:
1195 begin
1196 Result := tr_SetLift(trigPanelGUID, 1, trigData.trigNoSound, trigData.trigd2d_doors);
1197 TimeOut := 0;
1199 if (not trigData.trigNoSound) and Result then begin
1200 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1201 X + (Width div 2),
1202 Y + (Height div 2));
1203 if g_Game_IsServer and g_Game_IsNet then
1204 MH_SEND_Sound(X + (Width div 2),
1205 Y + (Height div 2),
1206 'SOUND_GAME_SWITCH0');
1207 end;
1208 end;
1210 TRIGGER_LIFT:
1211 begin
1212 Result := tr_SetLift(trigPanelGUID, 3, trigData.trigNoSound, trigData.trigd2d_doors);
1214 if Result then
1215 begin
1216 TimeOut := 18;
1218 if (not trigData.trigNoSound) and Result then begin
1219 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1220 X + (Width div 2),
1221 Y + (Height div 2));
1222 if g_Game_IsServer and g_Game_IsNet then
1223 MH_SEND_Sound(X + (Width div 2),
1224 Y + (Height div 2),
1225 'SOUND_GAME_SWITCH0');
1226 end;
1227 end;
1228 end;
1230 TRIGGER_TEXTURE:
1231 begin
1232 if trigData.trigActivateOnce then
1233 begin
1234 Enabled := False;
1235 TriggerType := TRIGGER_NONE;
1236 end
1237 else
1238 if coolDown then
1239 TimeOut := 6
1240 else
1241 TimeOut := 0;
1243 animonce := trigData.trigAnimOnce;
1244 Result := True;
1245 end;
1247 TRIGGER_SOUND:
1248 begin
1249 if Sound <> nil then
1250 begin
1251 if trigData.trigSoundSwitch and Sound.IsPlaying() then
1252 begin // Íóæíî âûêëþ÷èòü, åñëè èãðàë
1253 Sound.Stop();
1254 SoundPlayCount := 0;
1255 Result := True;
1256 end
1257 else // (not Data.SoundSwitch) or (not Sound.IsPlaying())
1258 if (trigData.trigPlayCount > 0) or (not Sound.IsPlaying()) then
1259 begin
1260 if trigData.trigPlayCount > 0 then
1261 SoundPlayCount := trigData.trigPlayCount
1262 else // 0 - èãðàåì áåñêîíå÷íî
1263 SoundPlayCount := 1;
1264 Result := True;
1265 end;
1266 if g_Game_IsNet then MH_SEND_TriggerSound(Trigger);
1267 end;
1268 end;
1270 TRIGGER_SPAWNMONSTER:
1271 if (trigData.trigMonType in [MONSTER_DEMON..MONSTER_MAN]) then
1272 begin
1273 Result := False;
1274 if (trigData.trigMonDelay > 0) and (actType <> ACTIVATE_CUSTOM) then
1275 begin
1276 AutoSpawn := not AutoSpawn;
1277 SpawnCooldown := 0;
1278 // Àâòîñïàâíåð ïåðåêëþ÷åí - ìåíÿåì òåêñòóðó
1279 Result := True;
1280 end;
1282 if ((trigData.trigMonDelay = 0) and (actType <> ACTIVATE_CUSTOM))
1283 or ((trigData.trigMonDelay > 0) and (actType = ACTIVATE_CUSTOM)) then
1284 for k := 1 to trigData.trigMonCount do
1285 begin
1286 if (actType = ACTIVATE_CUSTOM) and (trigData.trigMonDelay > 0) then
1287 SpawnCooldown := trigData.trigMonDelay;
1288 if (trigData.trigMonMax > 0) and (SpawnedCount >= trigData.trigMonMax) then
1289 Break;
1291 mon := g_Monsters_Create(trigData.trigMonType,
1292 trigData.trigMonPos.X, trigData.trigMonPos.Y,
1293 TDirection(trigData.trigMonDir), True);
1295 Result := True;
1297 // Çäîðîâüå:
1298 if (trigData.trigMonHealth > 0) then
1299 mon.SetHealth(trigData.trigMonHealth);
1300 // Óñòàíàâëèâàåì ïîâåäåíèå:
1301 mon.MonsterBehaviour := trigData.trigMonBehav;
1302 mon.FNoRespawn := True;
1303 if g_Game_IsNet then
1304 MH_SEND_MonsterSpawn(mon.UID);
1305 // Èäåì èñêàòü öåëü, åñëè íàäî:
1306 if trigData.trigMonActive then
1307 mon.WakeUp();
1309 if trigData.trigMonType <> MONSTER_BARREL then Inc(gTotalMonsters);
1311 if g_Game_IsNet then
1312 begin
1313 SetLength(gMonstersSpawned, Length(gMonstersSpawned)+1);
1314 gMonstersSpawned[High(gMonstersSpawned)] := mon.UID;
1315 end;
1317 if trigData.trigMonMax > 0 then
1318 begin
1319 mon.SpawnTrigger := ID;
1320 Inc(SpawnedCount);
1321 end;
1323 case trigData.trigMonEffect of
1324 EFFECT_TELEPORT: begin
1325 if g_Frames_Get(FramesID, 'FRAMES_TELEPORT') then
1326 begin
1327 Anim := TAnimation.Create(FramesID, False, 3);
1328 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', trigData.trigMonPos.X, trigData.trigMonPos.Y);
1329 g_GFX_OnceAnim(mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2)-32,
1330 mon.Obj.Y+mon.Obj.Rect.Y+(mon.Obj.Rect.Height div 2)-32, Anim);
1331 Anim.Free();
1332 end;
1333 if g_Game_IsServer and g_Game_IsNet then
1334 MH_SEND_Effect(mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2)-32,
1335 mon.Obj.Y+mon.Obj.Rect.Y+(mon.Obj.Rect.Height div 2)-32, 1,
1336 NET_GFX_TELE);
1337 end;
1338 EFFECT_RESPAWN: begin
1339 if g_Frames_Get(FramesID, 'FRAMES_ITEM_RESPAWN') then
1340 begin
1341 Anim := TAnimation.Create(FramesID, False, 4);
1342 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', trigData.trigMonPos.X, trigData.trigMonPos.Y);
1343 g_GFX_OnceAnim(mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2)-16,
1344 mon.Obj.Y+mon.Obj.Rect.Y+(mon.Obj.Rect.Height div 2)-16, Anim);
1345 Anim.Free();
1346 end;
1347 if g_Game_IsServer and g_Game_IsNet then
1348 MH_SEND_Effect(mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2)-16,
1349 mon.Obj.Y+mon.Obj.Rect.Y+(mon.Obj.Rect.Height div 2)-16, 1,
1350 NET_GFX_RESPAWN);
1351 end;
1352 EFFECT_FIRE: begin
1353 if g_Frames_Get(FramesID, 'FRAMES_FIRE') then
1354 begin
1355 Anim := TAnimation.Create(FramesID, False, 4);
1356 g_Sound_PlayExAt('SOUND_FIRE', trigData.trigMonPos.X, trigData.trigMonPos.Y);
1357 g_GFX_OnceAnim(mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2)-32,
1358 mon.Obj.Y+mon.Obj.Rect.Y+mon.Obj.Rect.Height-128, Anim);
1359 Anim.Free();
1360 end;
1361 if g_Game_IsServer and g_Game_IsNet then
1362 MH_SEND_Effect(mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2)-32,
1363 mon.Obj.Y+mon.Obj.Rect.Y+mon.Obj.Rect.Height-128, 1,
1364 NET_GFX_FIRE);
1365 end;
1366 end;
1367 end;
1368 if g_Game_IsNet then
1369 begin
1370 MH_SEND_GameStats();
1371 MH_SEND_CoopStats();
1372 end;
1374 if coolDown then
1375 TimeOut := 18
1376 else
1377 TimeOut := 0;
1378 // Åñëè àêòèâèðîâàí àâòîñïàâíåðîì, íå ìåíÿåì òåêñòóðó
1379 if actType = ACTIVATE_CUSTOM then
1380 Result := False;
1381 end;
1383 TRIGGER_SPAWNITEM:
1384 if (trigData.trigItemType in [ITEM_MEDKIT_SMALL..ITEM_MAX]) then
1385 begin
1386 Result := False;
1387 if (trigData.trigItemDelay > 0) and (actType <> ACTIVATE_CUSTOM) then
1388 begin
1389 AutoSpawn := not AutoSpawn;
1390 SpawnCooldown := 0;
1391 // Àâòîñïàâíåð ïåðåêëþ÷åí - ìåíÿåì òåêñòóðó
1392 Result := True;
1393 end;
1395 if ((trigData.trigItemDelay = 0) and (actType <> ACTIVATE_CUSTOM))
1396 or ((trigData.trigItemDelay > 0) and (actType = ACTIVATE_CUSTOM)) then
1397 if (not trigData.trigItemOnlyDM) or
1398 (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) then
1399 for k := 1 to trigData.trigItemCount do
1400 begin
1401 if (actType = ACTIVATE_CUSTOM) and (trigData.trigItemDelay > 0) then
1402 SpawnCooldown := trigData.trigItemDelay;
1403 if (trigData.trigItemMax > 0) and (SpawnedCount >= trigData.trigItemMax) then
1404 Break;
1406 iid := g_Items_Create(trigData.trigItemPos.X, trigData.trigItemPos.Y,
1407 trigData.trigItemType, trigData.trigItemFalls, False, True);
1409 Result := True;
1411 if trigData.trigItemMax > 0 then
1412 begin
1413 it := g_Items_ByIdx(iid);
1414 it.SpawnTrigger := ID;
1415 Inc(SpawnedCount);
1416 end;
1418 case trigData.trigItemEffect of
1419 EFFECT_TELEPORT: begin
1420 it := g_Items_ByIdx(iid);
1421 if g_Frames_Get(FramesID, 'FRAMES_TELEPORT') then
1422 begin
1423 Anim := TAnimation.Create(FramesID, False, 3);
1424 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', trigData.trigItemPos.X, trigData.trigItemPos.Y);
1425 g_GFX_OnceAnim(it.Obj.X+it.Obj.Rect.X+(it.Obj.Rect.Width div 2)-32,
1426 it.Obj.Y+it.Obj.Rect.Y+(it.Obj.Rect.Height div 2)-32, Anim);
1427 Anim.Free();
1428 end;
1429 if g_Game_IsServer and g_Game_IsNet then
1430 MH_SEND_Effect(it.Obj.X+it.Obj.Rect.X+(it.Obj.Rect.Width div 2)-32,
1431 it.Obj.Y+it.Obj.Rect.Y+(it.Obj.Rect.Height div 2)-32, 1,
1432 NET_GFX_TELE);
1433 end;
1434 EFFECT_RESPAWN: begin
1435 it := g_Items_ByIdx(iid);
1436 if g_Frames_Get(FramesID, 'FRAMES_ITEM_RESPAWN') then
1437 begin
1438 Anim := TAnimation.Create(FramesID, False, 4);
1439 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', trigData.trigItemPos.X, trigData.trigItemPos.Y);
1440 g_GFX_OnceAnim(it.Obj.X+it.Obj.Rect.X+(it.Obj.Rect.Width div 2)-16,
1441 it.Obj.Y+it.Obj.Rect.Y+(it.Obj.Rect.Height div 2)-16, Anim);
1442 Anim.Free();
1443 end;
1444 if g_Game_IsServer and g_Game_IsNet then
1445 MH_SEND_Effect(it.Obj.X+it.Obj.Rect.X+(it.Obj.Rect.Width div 2)-16,
1446 it.Obj.Y+it.Obj.Rect.Y+(it.Obj.Rect.Height div 2)-16, 1,
1447 NET_GFX_RESPAWN);
1448 end;
1449 EFFECT_FIRE: begin
1450 it := g_Items_ByIdx(iid);
1451 if g_Frames_Get(FramesID, 'FRAMES_FIRE') then
1452 begin
1453 Anim := TAnimation.Create(FramesID, False, 4);
1454 g_Sound_PlayExAt('SOUND_FIRE', trigData.trigItemPos.X, trigData.trigItemPos.Y);
1455 g_GFX_OnceAnim(it.Obj.X+it.Obj.Rect.X+(it.Obj.Rect.Width div 2)-32,
1456 it.Obj.Y+it.Obj.Rect.Y+it.Obj.Rect.Height-128, Anim);
1457 Anim.Free();
1458 end;
1459 if g_Game_IsServer and g_Game_IsNet then
1460 MH_SEND_Effect(it.Obj.X+it.Obj.Rect.X+(it.Obj.Rect.Width div 2)-32,
1461 it.Obj.Y+it.Obj.Rect.Y+it.Obj.Rect.Height-128, 1,
1462 NET_GFX_FIRE);
1463 end;
1464 end;
1466 if g_Game_IsNet then
1467 MH_SEND_ItemSpawn(True, iid);
1468 end;
1470 if coolDown then
1471 TimeOut := 18
1472 else
1473 TimeOut := 0;
1474 // Åñëè àêòèâèðîâàí àâòîñïàâíåðîì, íå ìåíÿåì òåêñòóðó
1475 if actType = ACTIVATE_CUSTOM then
1476 Result := False;
1477 end;
1479 TRIGGER_MUSIC:
1480 begin
1481 // Ìåíÿåì ìóçûêó, åñëè åñòü íà ÷òî:
1482 if (Trigger.trigData.trigMusicName <> '') then
1483 begin
1484 gMusic.SetByName(Trigger.trigData.trigMusicName);
1485 gMusic.SpecPause := True;
1486 gMusic.Play();
1487 end;
1489 if Trigger.trigData.trigMusicAction = 1 then
1490 begin // Âêëþ÷èòü
1491 if gMusic.SpecPause then // Áûëà íà ïàóçå => èãðàòü
1492 gMusic.SpecPause := False
1493 else // Èãðàëà => ñíà÷àëà
1494 gMusic.SetPosition(0);
1495 end
1496 else // Âûêëþ÷èòü
1497 begin
1498 // Ïàóçà:
1499 gMusic.SpecPause := True;
1500 end;
1502 if coolDown then
1503 TimeOut := 36
1504 else
1505 TimeOut := 0;
1506 Result := True;
1507 if g_Game_IsNet then MH_SEND_TriggerMusic;
1508 end;
1510 TRIGGER_PUSH:
1511 begin
1512 pAngle := -DegToRad(trigData.trigPushAngle);
1513 Result := tr_Push(ActivateUID,
1514 Floor(Cos(pAngle)*trigData.trigPushForce),
1515 Floor(Sin(pAngle)*trigData.trigPushForce),
1516 trigData.trigResetVel);
1517 TimeOut := 0;
1518 end;
1520 TRIGGER_SCORE:
1521 begin
1522 Result := False;
1523 // Ïðèáàâèòü èëè îòíÿòü î÷êî
1524 if (trigData.trigScoreAction in [0..1]) and (trigData.trigScoreCount > 0) then
1525 begin
1526 // Ñâîåé èëè ÷óæîé êîìàíäå
1527 if (trigData.trigScoreTeam in [0..1]) and (g_GetUIDType(ActivateUID) = UID_PLAYER) then
1528 begin
1529 p := g_Player_Get(ActivateUID);
1530 if ((trigData.trigScoreAction = 0) and (trigData.trigScoreTeam = 0) and (p.Team = TEAM_RED))
1531 or ((trigData.trigScoreAction = 0) and (trigData.trigScoreTeam = 1) and (p.Team = TEAM_BLUE)) then
1532 begin
1533 Inc(gTeamStat[TEAM_RED].Goals, trigData.trigScoreCount); // Red Scores
1535 if trigData.trigScoreCon then
1536 if trigData.trigScoreTeam = 0 then
1537 begin
1538 g_Console_Add(Format(_lc[I_PLAYER_SCORE_ADD_OWN], [p.Name, trigData.trigScoreCount, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1539 if g_Game_IsServer and g_Game_IsNet then
1540 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (trigData.trigScoreCount shl 16), '+r');
1541 end else
1542 begin
1543 g_Console_Add(Format(_lc[I_PLAYER_SCORE_ADD_ENEMY], [p.Name, trigData.trigScoreCount, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1544 if g_Game_IsServer and g_Game_IsNet then
1545 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (trigData.trigScoreCount shl 16), '+re');
1546 end;
1548 if trigData.trigScoreMsg then
1549 begin
1550 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1551 if g_Game_IsServer and g_Game_IsNet then
1552 MH_SEND_GameEvent(NET_EV_SCORE_MSG, TEAM_RED);
1553 end;
1554 end;
1555 if ((trigData.trigScoreAction = 1) and (trigData.trigScoreTeam = 0) and (p.Team = TEAM_RED))
1556 or ((trigData.trigScoreAction = 1) and (trigData.trigScoreTeam = 1) and (p.Team = TEAM_BLUE)) then
1557 begin
1558 Dec(gTeamStat[TEAM_RED].Goals, trigData.trigScoreCount); // Red Fouls
1560 if trigData.trigScoreCon then
1561 if trigData.trigScoreTeam = 0 then
1562 begin
1563 g_Console_Add(Format(_lc[I_PLAYER_SCORE_SUB_OWN], [p.Name, trigData.trigScoreCount, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1564 if g_Game_IsServer and g_Game_IsNet then
1565 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (trigData.trigScoreCount shl 16), '-r');
1566 end else
1567 begin
1568 g_Console_Add(Format(_lc[I_PLAYER_SCORE_SUB_ENEMY], [p.Name, trigData.trigScoreCount, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1569 if g_Game_IsServer and g_Game_IsNet then
1570 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (trigData.trigScoreCount shl 16), '-re');
1571 end;
1573 if trigData.trigScoreMsg then
1574 begin
1575 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1576 if g_Game_IsServer and g_Game_IsNet then
1577 MH_SEND_GameEvent(NET_EV_SCORE_MSG, -TEAM_RED);
1578 end;
1579 end;
1580 if ((trigData.trigScoreAction = 0) and (trigData.trigScoreTeam = 0) and (p.Team = TEAM_BLUE))
1581 or ((trigData.trigScoreAction = 0) and (trigData.trigScoreTeam = 1) and (p.Team = TEAM_RED)) then
1582 begin
1583 Inc(gTeamStat[TEAM_BLUE].Goals, trigData.trigScoreCount); // Blue Scores
1585 if trigData.trigScoreCon then
1586 if trigData.trigScoreTeam = 0 then
1587 begin
1588 g_Console_Add(Format(_lc[I_PLAYER_SCORE_ADD_OWN], [p.Name, trigData.trigScoreCount, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1589 if g_Game_IsServer and g_Game_IsNet then
1590 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (trigData.trigScoreCount shl 16), '+b');
1591 end else
1592 begin
1593 g_Console_Add(Format(_lc[I_PLAYER_SCORE_ADD_ENEMY], [p.Name, trigData.trigScoreCount, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1594 if g_Game_IsServer and g_Game_IsNet then
1595 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (trigData.trigScoreCount shl 16), '+be');
1596 end;
1598 if trigData.trigScoreMsg then
1599 begin
1600 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1601 if g_Game_IsServer and g_Game_IsNet then
1602 MH_SEND_GameEvent(NET_EV_SCORE_MSG, TEAM_BLUE);
1603 end;
1604 end;
1605 if ((trigData.trigScoreAction = 1) and (trigData.trigScoreTeam = 0) and (p.Team = TEAM_BLUE))
1606 or ((trigData.trigScoreAction = 1) and (trigData.trigScoreTeam = 1) and (p.Team = TEAM_RED)) then
1607 begin
1608 Dec(gTeamStat[TEAM_BLUE].Goals, trigData.trigScoreCount); // Blue Fouls
1610 if trigData.trigScoreCon then
1611 if trigData.trigScoreTeam = 0 then
1612 begin
1613 g_Console_Add(Format(_lc[I_PLAYER_SCORE_SUB_OWN], [p.Name, trigData.trigScoreCount, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1614 if g_Game_IsServer and g_Game_IsNet then
1615 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (trigData.trigScoreCount shl 16), '-b');
1616 end else
1617 begin
1618 g_Console_Add(Format(_lc[I_PLAYER_SCORE_SUB_ENEMY], [p.Name, trigData.trigScoreCount, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1619 if g_Game_IsServer and g_Game_IsNet then
1620 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (trigData.trigScoreCount shl 16), '-be');
1621 end;
1623 if trigData.trigScoreMsg then
1624 begin
1625 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1626 if g_Game_IsServer and g_Game_IsNet then
1627 MH_SEND_GameEvent(NET_EV_SCORE_MSG, -TEAM_BLUE);
1628 end;
1629 end;
1630 Result := (p.Team = TEAM_RED) or (p.Team = TEAM_BLUE);
1631 end;
1632 // Êàêîé-òî êîíêðåòíîé êîìàíäå
1633 if trigData.trigScoreTeam in [2..3] then
1634 begin
1635 if (trigData.trigScoreAction = 0) and (trigData.trigScoreTeam = 2) then
1636 begin
1637 Inc(gTeamStat[TEAM_RED].Goals, trigData.trigScoreCount); // Red Scores
1639 if trigData.trigScoreCon then
1640 begin
1641 g_Console_Add(Format(_lc[I_PLAYER_SCORE_ADD_TEAM], [_lc[I_PLAYER_SCORE_RED], trigData.trigScoreCount]), True);
1642 if g_Game_IsServer and g_Game_IsNet then
1643 MH_SEND_GameEvent(NET_EV_SCORE, trigData.trigScoreCount shl 16, '+tr');
1644 end;
1646 if trigData.trigScoreMsg then
1647 begin
1648 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1649 if g_Game_IsServer and g_Game_IsNet then
1650 MH_SEND_GameEvent(NET_EV_SCORE_MSG, TEAM_RED);
1651 end;
1652 end;
1653 if (trigData.trigScoreAction = 1) and (trigData.trigScoreTeam = 2) then
1654 begin
1655 Dec(gTeamStat[TEAM_RED].Goals, trigData.trigScoreCount); // Red Fouls
1657 if trigData.trigScoreCon then
1658 begin
1659 g_Console_Add(Format(_lc[I_PLAYER_SCORE_SUB_TEAM], [_lc[I_PLAYER_SCORE_RED], trigData.trigScoreCount]), True);
1660 if g_Game_IsServer and g_Game_IsNet then
1661 MH_SEND_GameEvent(NET_EV_SCORE, trigData.trigScoreCount shl 16, '-tr');
1662 end;
1664 if trigData.trigScoreMsg then
1665 begin
1666 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1667 if g_Game_IsServer and g_Game_IsNet then
1668 MH_SEND_GameEvent(NET_EV_SCORE_MSG, -TEAM_RED);
1669 end;
1670 end;
1671 if (trigData.trigScoreAction = 0) and (trigData.trigScoreTeam = 3) then
1672 begin
1673 Inc(gTeamStat[TEAM_BLUE].Goals, trigData.trigScoreCount); // Blue Scores
1675 if trigData.trigScoreCon then
1676 begin
1677 g_Console_Add(Format(_lc[I_PLAYER_SCORE_ADD_TEAM], [_lc[I_PLAYER_SCORE_BLUE], trigData.trigScoreCount]), True);
1678 if g_Game_IsServer and g_Game_IsNet then
1679 MH_SEND_GameEvent(NET_EV_SCORE, trigData.trigScoreCount shl 16, '+tb');
1680 end;
1682 if trigData.trigScoreMsg then
1683 begin
1684 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1685 if g_Game_IsServer and g_Game_IsNet then
1686 MH_SEND_GameEvent(NET_EV_SCORE_MSG, TEAM_BLUE);
1687 end;
1688 end;
1689 if (trigData.trigScoreAction = 1) and (trigData.trigScoreTeam = 3) then
1690 begin
1691 Dec(gTeamStat[TEAM_BLUE].Goals, trigData.trigScoreCount); // Blue Fouls
1693 if trigData.trigScoreCon then
1694 begin
1695 g_Console_Add(Format(_lc[I_PLAYER_SCORE_SUB_TEAM], [_lc[I_PLAYER_SCORE_BLUE], trigData.trigScoreCount]), True);
1696 if g_Game_IsServer and g_Game_IsNet then
1697 MH_SEND_GameEvent(NET_EV_SCORE, trigData.trigScoreCount shl 16, '-tb');
1698 end;
1700 if trigData.trigScoreMsg then
1701 begin
1702 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1703 if g_Game_IsServer and g_Game_IsNet then
1704 MH_SEND_GameEvent(NET_EV_SCORE_MSG, -TEAM_BLUE);
1705 end;
1706 end;
1707 Result := True;
1708 end;
1709 end;
1710 // Âûèãðûø
1711 if (trigData.trigScoreAction = 2) and (gGameSettings.GoalLimit > 0) then
1712 begin
1713 // Ñâîåé èëè ÷óæîé êîìàíäû
1714 if (trigData.trigScoreTeam in [0..1]) and (g_GetUIDType(ActivateUID) = UID_PLAYER) then
1715 begin
1716 p := g_Player_Get(ActivateUID);
1717 if ((trigData.trigScoreTeam = 0) and (p.Team = TEAM_RED)) // Red Wins
1718 or ((trigData.trigScoreTeam = 1) and (p.Team = TEAM_BLUE)) then
1719 if gTeamStat[TEAM_RED].Goals < SmallInt(gGameSettings.GoalLimit) then
1720 begin
1721 gTeamStat[TEAM_RED].Goals := gGameSettings.GoalLimit;
1723 if trigData.trigScoreCon then
1724 if trigData.trigScoreTeam = 0 then
1725 begin
1726 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_OWN], [p.Name, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1727 if g_Game_IsServer and g_Game_IsNet then
1728 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wr');
1729 end else
1730 begin
1731 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_ENEMY], [p.Name, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1732 if g_Game_IsServer and g_Game_IsNet then
1733 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wre');
1734 end;
1736 Result := True;
1737 end;
1738 if ((trigData.trigScoreTeam = 0) and (p.Team = TEAM_BLUE)) // Blue Wins
1739 or ((trigData.trigScoreTeam = 1) and (p.Team = TEAM_RED)) then
1740 if gTeamStat[TEAM_BLUE].Goals < SmallInt(gGameSettings.GoalLimit) then
1741 begin
1742 gTeamStat[TEAM_BLUE].Goals := gGameSettings.GoalLimit;
1744 if trigData.trigScoreCon then
1745 if trigData.trigScoreTeam = 0 then
1746 begin
1747 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_OWN], [p.Name, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1748 if g_Game_IsServer and g_Game_IsNet then
1749 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wb');
1750 end else
1751 begin
1752 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_ENEMY], [p.Name, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1753 if g_Game_IsServer and g_Game_IsNet then
1754 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wbe');
1755 end;
1757 Result := True;
1758 end;
1759 end;
1760 // Êàêîé-òî êîíêðåòíîé êîìàíäû
1761 if trigData.trigScoreTeam in [2..3] then
1762 begin
1763 if trigData.trigScoreTeam = 2 then // Red Wins
1764 if gTeamStat[TEAM_RED].Goals < SmallInt(gGameSettings.GoalLimit) then
1765 begin
1766 gTeamStat[TEAM_RED].Goals := gGameSettings.GoalLimit;
1767 Result := True;
1768 end;
1769 if trigData.trigScoreTeam = 3 then // Blue Wins
1770 if gTeamStat[TEAM_BLUE].Goals < SmallInt(gGameSettings.GoalLimit) then
1771 begin
1772 gTeamStat[TEAM_BLUE].Goals := gGameSettings.GoalLimit;
1773 Result := True;
1774 end;
1775 end;
1776 end;
1777 // Ïðîèãðûø
1778 if (trigData.trigScoreAction = 3) and (gGameSettings.GoalLimit > 0) then
1779 begin
1780 // Ñâîåé èëè ÷óæîé êîìàíäû
1781 if (trigData.trigScoreTeam in [0..1]) and (g_GetUIDType(ActivateUID) = UID_PLAYER) then
1782 begin
1783 p := g_Player_Get(ActivateUID);
1784 if ((trigData.trigScoreTeam = 0) and (p.Team = TEAM_BLUE)) // Red Wins
1785 or ((trigData.trigScoreTeam = 1) and (p.Team = TEAM_RED)) then
1786 if gTeamStat[TEAM_RED].Goals < SmallInt(gGameSettings.GoalLimit) then
1787 begin
1788 gTeamStat[TEAM_RED].Goals := gGameSettings.GoalLimit;
1790 if trigData.trigScoreCon then
1791 if trigData.trigScoreTeam = 0 then
1792 begin
1793 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_ENEMY], [p.Name, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1794 if g_Game_IsServer and g_Game_IsNet then
1795 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wre');
1796 end else
1797 begin
1798 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_OWN], [p.Name, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1799 if g_Game_IsServer and g_Game_IsNet then
1800 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wr');
1801 end;
1803 Result := True;
1804 end;
1805 if ((trigData.trigScoreTeam = 0) and (p.Team = TEAM_RED)) // Blue Wins
1806 or ((trigData.trigScoreTeam = 1) and (p.Team = TEAM_BLUE)) then
1807 if gTeamStat[TEAM_BLUE].Goals < SmallInt(gGameSettings.GoalLimit) then
1808 begin
1809 gTeamStat[TEAM_BLUE].Goals := gGameSettings.GoalLimit;
1811 if trigData.trigScoreCon then
1812 if trigData.trigScoreTeam = 0 then
1813 begin
1814 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_ENEMY], [p.Name, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1815 if g_Game_IsServer and g_Game_IsNet then
1816 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wbe');
1817 end else
1818 begin
1819 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_OWN], [p.Name, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1820 if g_Game_IsServer and g_Game_IsNet then
1821 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wb');
1822 end;
1824 Result := True;
1825 end;
1826 end;
1827 // Êàêîé-òî êîíêðåòíîé êîìàíäû
1828 if trigData.trigScoreTeam in [2..3] then
1829 begin
1830 if trigData.trigScoreTeam = 3 then // Red Wins
1831 if gTeamStat[TEAM_RED].Goals < SmallInt(gGameSettings.GoalLimit) then
1832 begin
1833 gTeamStat[TEAM_RED].Goals := gGameSettings.GoalLimit;
1834 Result := True;
1835 end;
1836 if trigData.trigScoreTeam = 2 then // Blue Wins
1837 if gTeamStat[TEAM_BLUE].Goals < SmallInt(gGameSettings.GoalLimit) then
1838 begin
1839 gTeamStat[TEAM_BLUE].Goals := gGameSettings.GoalLimit;
1840 Result := True;
1841 end;
1842 end;
1843 end;
1844 if Result then begin
1845 if coolDown then
1846 TimeOut := 18
1847 else
1848 TimeOut := 0;
1849 if g_Game_IsServer and g_Game_IsNet then
1850 MH_SEND_GameStats;
1851 end;
1852 end;
1854 TRIGGER_MESSAGE:
1855 begin
1856 Result := tr_Message(trigData.trigMessageKind, trigData.trigMessageText,
1857 trigData.trigMessageSendTo, trigData.trigMessageTime,
1858 ActivateUID);
1859 TimeOut := 18;
1860 end;
1862 TRIGGER_DAMAGE, TRIGGER_HEALTH:
1863 begin
1864 Result := False;
1865 UIDType := g_GetUIDType(ActivateUID);
1866 if (UIDType = UID_PLAYER) or (UIDType = UID_MONSTER) then
1867 begin
1868 Result := True;
1869 k := -1;
1870 if coolDown then
1871 begin
1872 // Âñïîìèíàåì, àêòèâèðîâàë ëè îí ìåíÿ ðàíüøå
1873 for idx := 0 to High(Activators) do
1874 if Activators[idx].UID = ActivateUID then
1875 begin
1876 k := idx;
1877 Break;
1878 end;
1879 if k = -1 then
1880 begin // Âèäèì åãî âïåðâûå
1881 // Çàïîìèíàåì åãî
1882 SetLength(Activators, Length(Activators) + 1);
1883 k := High(Activators);
1884 Activators[k].UID := ActivateUID;
1885 end else
1886 begin // Óæå âèäåëè åãî
1887 // Åñëè èíòåðâàë îòêëþ÷¸í, íî îí âñ¸ åù¸ â çîíå ïîðàæåíèÿ, äà¸ì åìó âðåìÿ
1888 if (trigData.trigDamageInterval = 0) and (Activators[k].TimeOut > 0) then
1889 Activators[k].TimeOut := 65535;
1890 // Òàéìàóò ïðîø¸ë - ðàáîòàåì
1891 Result := Activators[k].TimeOut = 0;
1892 end;
1893 end;
1895 if Result then
1896 begin
1897 case UIDType of
1898 UID_PLAYER:
1899 begin
1900 p := g_Player_Get(ActivateUID);
1901 if p = nil then
1902 Exit;
1904 // Íàíîñèì óðîí èãðîêó
1905 if (TriggerType = TRIGGER_DAMAGE) and (trigData.trigDamageValue > 0) then
1906 p.Damage(trigData.trigDamageValue, 0, 0, 0, HIT_SOME);
1908 // Ëå÷èì èãðîêà
1909 if (TriggerType = TRIGGER_HEALTH) and (trigData.trigHealValue > 0) then
1910 if p.Heal(trigData.trigHealValue, not trigData.trigHealMax) and (not trigData.trigHealSilent) then
1911 begin
1912 g_Sound_PlayExAt('SOUND_ITEM_GETITEM', p.Obj.X, p.Obj.Y);
1913 if g_Game_IsServer and g_Game_IsNet then
1914 MH_SEND_Sound(p.Obj.X, p.Obj.Y, 'SOUND_ITEM_GETITEM');
1915 end;
1916 end;
1918 UID_MONSTER:
1919 begin
1920 m := g_Monsters_ByUID(ActivateUID);
1921 if m = nil then
1922 Exit;
1924 // Íàíîñèì óðîí ìîíñòðó
1925 if (TriggerType = TRIGGER_DAMAGE) and (trigData.trigDamageValue > 0) then
1926 m.Damage(trigData.trigDamageValue, 0, 0, 0, HIT_SOME);
1928 // Ëå÷èì ìîíñòðà
1929 if (TriggerType = TRIGGER_HEALTH) and (trigData.trigHealValue > 0) then
1930 if m.Heal(trigData.trigHealValue) and (not trigData.trigHealSilent) then
1931 begin
1932 g_Sound_PlayExAt('SOUND_ITEM_GETITEM', m.Obj.X, m.Obj.Y);
1933 if g_Game_IsServer and g_Game_IsNet then
1934 MH_SEND_Sound(m.Obj.X, m.Obj.Y, 'SOUND_ITEM_GETITEM');
1935 end;
1936 end;
1937 end;
1938 // Íàçíà÷àåì âðåìÿ ñëåäóþùåãî âîçäåéñòâèÿ
1939 if TriggerType = TRIGGER_DAMAGE then
1940 idx := trigData.trigDamageInterval
1941 else
1942 idx := trigData.trigHealInterval;
1943 if coolDown then
1944 if idx > 0 then
1945 Activators[k].TimeOut := idx
1946 else
1947 Activators[k].TimeOut := 65535;
1948 end;
1949 end;
1950 TimeOut := 0;
1951 end;
1953 TRIGGER_SHOT:
1954 begin
1955 if ShotSightTime > 0 then
1956 Exit;
1958 // put this at the beginning so it doesn't trigger itself
1959 TimeOut := trigData.trigShotWait + 1;
1961 wx := trigData.trigShotPos.X;
1962 wy := trigData.trigShotPos.Y;
1963 pAngle := -DegToRad(trigData.trigShotAngle);
1964 xd := wx + Round(Cos(pAngle) * 32.0);
1965 yd := wy + Round(Sin(pAngle) * 32.0);
1966 TargetUID := 0;
1968 case trigData.trigShotTarget of
1969 TRIGGER_SHOT_TARGET_MON: // monsters
1970 //TODO: accelerate this!
1971 g_Mons_ForEachAlive(monsShotTarget);
1973 TRIGGER_SHOT_TARGET_PLR: // players
1974 if gPlayers <> nil then
1975 for idx := Low(gPlayers) to High(gPlayers) do
1976 if (gPlayers[idx] <> nil) and gPlayers[idx].Live and
1977 tr_ShotAimCheck(Trigger, @(gPlayers[idx].Obj)) then
1978 begin
1979 xd := gPlayers[idx].GameX + PLAYER_RECT_CX;
1980 yd := gPlayers[idx].GameY + PLAYER_RECT_CY;
1981 TargetUID := gPlayers[idx].UID;
1982 break;
1983 end;
1985 TRIGGER_SHOT_TARGET_RED: // red team
1986 if gPlayers <> nil then
1987 for idx := Low(gPlayers) to High(gPlayers) do
1988 if (gPlayers[idx] <> nil) and gPlayers[idx].Live and
1989 (gPlayers[idx].Team = TEAM_RED) and
1990 tr_ShotAimCheck(Trigger, @(gPlayers[idx].Obj)) then
1991 begin
1992 xd := gPlayers[idx].GameX + PLAYER_RECT_CX;
1993 yd := gPlayers[idx].GameY + PLAYER_RECT_CY;
1994 TargetUID := gPlayers[idx].UID;
1995 break;
1996 end;
1998 TRIGGER_SHOT_TARGET_BLUE: // blue team
1999 if gPlayers <> nil then
2000 for idx := Low(gPlayers) to High(gPlayers) do
2001 if (gPlayers[idx] <> nil) and gPlayers[idx].Live and
2002 (gPlayers[idx].Team = TEAM_BLUE) and
2003 tr_ShotAimCheck(Trigger, @(gPlayers[idx].Obj)) then
2004 begin
2005 xd := gPlayers[idx].GameX + PLAYER_RECT_CX;
2006 yd := gPlayers[idx].GameY + PLAYER_RECT_CY;
2007 TargetUID := gPlayers[idx].UID;
2008 break;
2009 end;
2011 TRIGGER_SHOT_TARGET_MONPLR: // monsters then players
2012 begin
2013 //TODO: accelerate this!
2014 g_Mons_ForEachAlive(monsShotTargetMonPlr);
2016 if (TargetUID = 0) and (gPlayers <> nil) then
2017 for idx := Low(gPlayers) to High(gPlayers) do
2018 if (gPlayers[idx] <> nil) and gPlayers[idx].Live and
2019 tr_ShotAimCheck(Trigger, @(gPlayers[idx].Obj)) then
2020 begin
2021 xd := gPlayers[idx].GameX + PLAYER_RECT_CX;
2022 yd := gPlayers[idx].GameY + PLAYER_RECT_CY;
2023 TargetUID := gPlayers[idx].UID;
2024 break;
2025 end;
2026 end;
2028 TRIGGER_SHOT_TARGET_PLRMON: // players then monsters
2029 begin
2030 if gPlayers <> nil then
2031 for idx := Low(gPlayers) to High(gPlayers) do
2032 if (gPlayers[idx] <> nil) and gPlayers[idx].Live and
2033 tr_ShotAimCheck(Trigger, @(gPlayers[idx].Obj)) then
2034 begin
2035 xd := gPlayers[idx].GameX + PLAYER_RECT_CX;
2036 yd := gPlayers[idx].GameY + PLAYER_RECT_CY;
2037 TargetUID := gPlayers[idx].UID;
2038 break;
2039 end;
2040 if TargetUID = 0 then
2041 begin
2042 //TODO: accelerate this!
2043 g_Mons_ForEachAlive(monShotTargetPlrMon);
2044 end;
2045 end;
2047 else begin
2048 if (trigData.trigShotTarget <> TRIGGER_SHOT_TARGET_NONE) or
2049 (trigData.trigShotType <> TRIGGER_SHOT_REV) then
2050 TargetUID := ActivateUID;
2051 end;
2052 end;
2054 if (trigData.trigShotTarget = TRIGGER_SHOT_TARGET_NONE) or (TargetUID > 0) or
2055 ((trigData.trigShotTarget > TRIGGER_SHOT_TARGET_NONE) and (TargetUID = 0)) then
2056 begin
2057 Result := True;
2058 if (trigData.trigShotIntSight = 0) or
2059 (trigData.trigShotTarget = TRIGGER_SHOT_TARGET_NONE) or
2060 (TargetUID = ShotSightTarget) then
2061 MakeShot(Trigger, wx, wy, xd, yd, TargetUID)
2062 else
2063 begin
2064 ShotSightTime := trigData.trigShotIntSight;
2065 ShotSightTargetN := TargetUID;
2066 if trigData.trigShotType = TRIGGER_SHOT_BFG then
2067 begin
2068 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', wx, wy);
2069 if g_Game_IsNet and g_Game_IsServer then
2070 MH_SEND_Sound(wx, wy, 'SOUND_WEAPON_STARTFIREBFG');
2071 end;
2072 end;
2073 end;
2074 end;
2076 TRIGGER_EFFECT:
2077 begin
2078 idx := trigData.trigFXCount;
2080 while idx > 0 do
2081 begin
2082 case trigData.trigFXPos of
2083 TRIGGER_EFFECT_POS_CENTER:
2084 begin
2085 wx := X + Width div 2;
2086 wy := Y + Height div 2;
2087 end;
2088 TRIGGER_EFFECT_POS_AREA:
2089 begin
2090 wx := X + Random(Width);
2091 wy := Y + Random(Height);
2092 end;
2093 else begin
2094 wx := X + Width div 2;
2095 wy := Y + Height div 2;
2096 end;
2097 end;
2098 xd := trigData.trigFXVelX;
2099 yd := trigData.trigFXVelY;
2100 if trigData.trigFXSpreadL > 0 then xd := xd - Random(trigData.trigFXSpreadL + 1);
2101 if trigData.trigFXSpreadR > 0 then xd := xd + Random(trigData.trigFXSpreadR + 1);
2102 if trigData.trigFXSpreadU > 0 then yd := yd - Random(trigData.trigFXSpreadU + 1);
2103 if trigData.trigFXSpreadD > 0 then yd := yd + Random(trigData.trigFXSpreadD + 1);
2104 tr_MakeEffect(wx, wy, xd, yd,
2105 trigData.trigFXType, trigData.trigFXSubType,
2106 trigData.trigFXColorR, trigData.trigFXColorG, trigData.trigFXColorB, True, False);
2107 Dec(idx);
2108 end;
2109 TimeOut := trigData.trigFXWait;
2110 end;
2111 end;
2112 end;
2114 if Result {and (Trigger.TexturePanel <> -1)} then
2115 begin
2116 g_Map_SwitchTextureGUID(Trigger.TexturePanelType, Trigger.TexturePanelGUID, IfThen(animonce, 2, 1));
2117 end;
2118 end;
2121 function g_Triggers_CreateWithMapIndex (Trigger: TTrigger; arridx, mapidx: Integer): DWORD;
2122 var
2123 triggers: TDynField;
2124 begin
2125 triggers := gCurrentMap['trigger'];
2126 if (triggers = nil) then raise Exception.Create('LOAD: map has no triggers');
2127 if (mapidx < 0) or (mapidx >= triggers.count) then raise Exception.Create('LOAD: invalid map trigger index');
2128 Trigger.trigData := triggers.item[mapidx];
2129 if (Trigger.trigData = nil) then raise Exception.Create('LOAD: internal error in trigger loader');
2130 Trigger.mapId := Trigger.trigData.id;
2131 Trigger.mapIndex := mapidx;
2132 if (Trigger.trigData.trigRec <> nil) then
2133 begin
2134 Trigger.trigData := Trigger.trigData.trigRec.clone();
2135 end
2136 else
2137 begin
2138 Trigger.trigData := nil;
2139 end;
2140 result := g_Triggers_Create(Trigger, arridx);
2141 end;
2144 function g_Triggers_Create(Trigger: TTrigger; forceInternalIndex: Integer=-1): DWORD;
2145 var
2146 find_id: DWORD;
2147 fn, mapw: AnsiString;
2148 f, olen: Integer;
2149 begin
2150 // Íå ñîçäàâàòü âûõîä, åñëè èãðà áåç âûõîäà:
2151 if (Trigger.TriggerType = TRIGGER_EXIT) and
2152 (not LongBool(gGameSettings.Options and GAME_OPTION_ALLOWEXIT)) then
2153 Trigger.TriggerType := TRIGGER_NONE;
2155 // Åñëè ìîíñòðû çàïðåùåíû, îòìåíÿåì òðèããåð:
2156 if (Trigger.TriggerType = TRIGGER_SPAWNMONSTER) and
2157 (not LongBool(gGameSettings.Options and GAME_OPTION_MONSTERS)) and
2158 (gGameSettings.GameType <> GT_SINGLE) then
2159 Trigger.TriggerType := TRIGGER_NONE;
2161 // Ñ÷èòàåì êîëè÷åñòâî ñåêðåòîâ íà êàðòå:
2162 if Trigger.TriggerType = TRIGGER_SECRET then
2163 gSecretsCount := gSecretsCount + 1;
2165 if (forceInternalIndex < 0) then
2166 begin
2167 find_id := FindTrigger();
2168 end
2169 else
2170 begin
2171 olen := Length(gTriggers);
2172 if (forceInternalIndex >= olen) then
2173 begin
2174 SetLength(gTriggers, forceInternalIndex+1);
2175 for f := olen to High(gTriggers) do gTriggers[f].TriggerType := TRIGGER_NONE;
2176 end;
2177 find_id := DWORD(forceInternalIndex);
2178 end;
2179 gTriggers[find_id] := Trigger;
2181 //e_LogWritefln('created trigger with map index %s, findid=%s (%s)', [Trigger.mapIndex, find_id, Trigger.mapId]);
2184 writeln('trigger #', find_id, ': pos=(', Trigger.x, ',', Trigger.y, ')-(', Trigger.width, 'x', Trigger.height, ')',
2185 '; TexturePanel=', Trigger.TexturePanel,
2186 '; TexturePanelType=', Trigger.TexturePanelType,
2187 '; ShotPanelType=', Trigger.ShotPanelType,
2188 '; TriggerType=', Trigger.TriggerType,
2189 '; ActivateType=', Trigger.ActivateType,
2190 '; Keys=', Trigger.Keys,
2191 '; trigPanelId=', Trigger.trigPanelId,
2192 '; trigShotPanelId=', Trigger.trigShotPanelId
2193 );
2196 with gTriggers[find_id] do
2197 begin
2198 ID := find_id;
2199 // if this type of trigger exists both on the client and on the server
2200 // use an uniform numeration
2201 if Trigger.TriggerType = TRIGGER_SOUND then
2202 begin
2203 Inc(gTriggerClientID);
2204 ClientID := gTriggerClientID;
2205 end
2206 else
2207 ClientID := 0;
2208 TimeOut := 0;
2209 ActivateUID := 0;
2210 PlayerCollide := False;
2211 DoorTime := -1;
2212 PressTime := -1;
2213 PressCount := 0;
2214 SoundPlayCount := 0;
2215 Sound := nil;
2216 AutoSpawn := False;
2217 SpawnCooldown := 0;
2218 SpawnedCount := 0;
2219 end;
2221 // Çàãðóæàåì çâóê, åñëè ýòî òðèããåð "Çâóê":
2222 if (Trigger.TriggerType = TRIGGER_SOUND) and
2223 (Trigger.trigData.trigSoundName <> '') then
2224 begin
2225 // Åùå íåò òàêîãî çâóêà:
2226 if not g_Sound_Exists(Trigger.trigData.trigSoundName) then
2227 begin
2228 fn := g_ExtractWadName(Trigger.trigData.trigSoundName);
2230 if fn = '' then
2231 begin // Çâóê â ôàéëå ñ êàðòîé
2232 mapw := g_ExtractWadName(gMapInfo.Map);
2233 fn := mapw+':'+g_ExtractFilePathName(Trigger.trigData.trigSoundName);
2234 end
2235 else // Çâóê â îòäåëüíîì ôàéëå
2236 fn := GameDir + '/wads/' + Trigger.trigData.trigSoundName;
2238 if not g_Sound_CreateWADEx(Trigger.trigData.trigSoundName, fn) then
2239 g_FatalError(Format(_lc[I_GAME_ERROR_TR_SOUND], [fn, Trigger.trigData.trigSoundName]));
2240 end;
2242 // Ñîçäàåì îáúåêò çâóêà:
2243 with gTriggers[find_id] do
2244 begin
2245 Sound := TPlayableSound.Create();
2246 if not Sound.SetByName(Trigger.trigData.trigSoundName) then
2247 begin
2248 Sound.Free();
2249 Sound := nil;
2250 end;
2251 end;
2252 end;
2254 // Çàãðóæàåì ìóçûêó, åñëè ýòî òðèããåð "Ìóçûêà":
2255 if (Trigger.TriggerType = TRIGGER_MUSIC) and
2256 (Trigger.trigData.trigMusicName <> '') then
2257 begin
2258 // Åùå íåò òàêîé ìóçûêè:
2259 if not g_Sound_Exists(Trigger.trigData.trigMusicName) then
2260 begin
2261 fn := g_ExtractWadName(Trigger.trigData.trigMusicName);
2263 if fn = '' then
2264 begin // Ìóçûêà â ôàéëå ñ êàðòîé
2265 mapw := g_ExtractWadName(gMapInfo.Map);
2266 fn := mapw+':'+g_ExtractFilePathName(Trigger.trigData.trigMusicName);
2267 end
2268 else // Ìóçûêà â ôàéëå ñ êàðòîé
2269 fn := GameDir+'/wads/'+Trigger.trigData.trigMusicName;
2271 if not g_Sound_CreateWADEx(Trigger.trigData.trigMusicName, fn, True) then
2272 g_FatalError(Format(_lc[I_GAME_ERROR_TR_SOUND], [fn, Trigger.trigData.trigMusicName]));
2273 end;
2274 end;
2276 // Çàãðóæàåì äàííûå òðèããåðà "Òóðåëü":
2277 if Trigger.TriggerType = TRIGGER_SHOT then
2278 with gTriggers[find_id] do
2279 begin
2280 ShotPanelTime := 0;
2281 ShotSightTime := 0;
2282 ShotSightTimeout := 0;
2283 ShotSightTarget := 0;
2284 ShotSightTargetN := 0;
2285 ShotAmmoCount := Trigger.trigData.trigShotAmmo;
2286 ShotReloadTime := 0;
2287 end;
2289 Result := find_id;
2290 end;
2293 // sorry; grid doesn't support recursive queries, so we have to do this
2294 type
2295 TSimpleMonsterList = specialize TSimpleList<TMonster>;
2297 var
2298 tgMonsList: TSimpleMonsterList = nil;
2300 procedure g_Triggers_Update();
2301 var
2302 a, b, i: Integer;
2303 Affected: array of Integer;
2305 function monsNear (mon: TMonster): Boolean;
2306 begin
2307 result := false; // don't stop
2309 gTriggers[a].ActivateUID := mon.UID;
2310 ActivateTrigger(gTriggers[a], ACTIVATE_MONSTERCOLLIDE);
2312 tgMonsList.append(mon);
2313 end;
2315 var
2316 mon: TMonster;
2317 pan: TPanel;
2318 begin
2319 if (tgMonsList = nil) then tgMonsList := TSimpleMonsterList.Create();
2321 if gTriggers = nil then
2322 Exit;
2323 SetLength(Affected, 0);
2325 for a := 0 to High(gTriggers) do
2326 with gTriggers[a] do
2327 // Åñòü òðèããåð:
2328 if TriggerType <> TRIGGER_NONE then
2329 begin
2330 // Óìåíüøàåì âðåìÿ äî çàêðûòèÿ äâåðè (îòêðûòèÿ ëîâóøêè)
2331 if DoorTime > 0 then DoorTime := DoorTime - 1;
2332 // Óìåíüøàåì âðåìÿ îæèäàíèÿ ïîñëå íàæàòèÿ
2333 if PressTime > 0 then PressTime := PressTime - 1;
2334 // Ïðîâåðÿåì èãðîêîâ è ìîíñòðîâ, êîòîðûõ ðàíåå çàïîìíèëè:
2335 if (TriggerType = TRIGGER_DAMAGE) or (TriggerType = TRIGGER_HEALTH) then
2336 begin
2337 for b := 0 to High(Activators) do
2338 begin
2339 // Óìåíüøàåì âðåìÿ äî ïîâòîðíîãî âîçäåéñòâèÿ:
2340 if Activators[b].TimeOut > 0 then
2341 begin
2342 Dec(Activators[b].TimeOut);
2343 end
2344 else
2345 begin
2346 continue;
2347 end;
2348 // Ñ÷èòàåì, ÷òî îáúåêò ïîêèíóë çîíó äåéñòâèÿ òðèããåðà
2349 if (trigData.trigDamageInterval = 0) and (Activators[b].TimeOut < 65530) then Activators[b].TimeOut := 0;
2350 end;
2351 end;
2353 // Îáðàáàòûâàåì ñïàâíåðû
2354 if Enabled and AutoSpawn then
2355 begin
2356 if SpawnCooldown = 0 then
2357 begin
2358 // Åñëè ïðèøëî âðåìÿ, ñïàâíèì ìîíñòðà
2359 if (TriggerType = TRIGGER_SPAWNMONSTER) and (trigData.trigMonDelay > 0) then
2360 begin
2361 ActivateUID := 0;
2362 ActivateTrigger(gTriggers[a], ACTIVATE_CUSTOM);
2363 end;
2364 // Åñëè ïðèøëî âðåìÿ, ñïàâíèì ïðåäìåò
2365 if (TriggerType = TRIGGER_SPAWNITEM) and (trigData.trigItemDelay > 0) then
2366 begin
2367 ActivateUID := 0;
2368 ActivateTrigger(gTriggers[a], ACTIVATE_CUSTOM);
2369 end;
2370 end
2371 else
2372 begin
2373 // Óìåíüøàåì âðåìÿ îæèäàíèÿ
2374 Dec(SpawnCooldown);
2375 end;
2376 end;
2378 // Îáðàáàòûâàåì ñîáûòèÿ òðèããåðà "Òóðåëü"
2379 if TriggerType = TRIGGER_SHOT then
2380 begin
2381 if ShotPanelTime > 0 then
2382 begin
2383 Dec(ShotPanelTime);
2384 if ShotPanelTime = 0 then g_Map_SwitchTextureGUID(ShotPanelType, trigShotPanelGUID);
2385 end;
2386 if ShotSightTime > 0 then
2387 begin
2388 Dec(ShotSightTime);
2389 if ShotSightTime = 0 then ShotSightTarget := ShotSightTargetN;
2390 end;
2391 if ShotSightTimeout > 0 then
2392 begin
2393 Dec(ShotSightTimeout);
2394 if ShotSightTimeout = 0 then ShotSightTarget := 0;
2395 end;
2396 if ShotReloadTime > 0 then
2397 begin
2398 Dec(ShotReloadTime);
2399 if ShotReloadTime = 0 then ShotAmmoCount := trigData.trigShotAmmo;
2400 end;
2401 end;
2403 // Òðèããåð "Çâóê" óæå îòûãðàë, åñëè íóæíî åùå - ïåðåçàïóñêàåì
2404 if Enabled and (TriggerType = TRIGGER_SOUND) and (Sound <> nil) then
2405 begin
2406 if (SoundPlayCount > 0) and (not Sound.IsPlaying()) then
2407 begin
2408 if trigData.trigPlayCount > 0 then SoundPlayCount -= 1; // Åñëè 0 - èãðàåì çâóê áåñêîíå÷íî
2409 if trigData.trigLocal then
2410 begin
2411 Sound.PlayVolumeAt(X+(Width div 2), Y+(Height div 2), trigData.trigVolume/255.0);
2412 end
2413 else
2414 begin
2415 Sound.PlayPanVolume((trigData.trigPan-127.0)/128.0, trigData.trigVolume/255.0);
2416 end;
2417 if Sound.IsPlaying() and g_Game_IsNet and g_Game_IsServer then MH_SEND_TriggerSound(gTriggers[a]);
2418 end;
2419 end;
2421 // Òðèããåð "Ëîâóøêà" - ïîðà îòêðûâàòü
2422 if (TriggerType = TRIGGER_TRAP) and (DoorTime = 0) and (g_Map_PanelByGUID(trigPanelGUID) <> nil) then
2423 begin
2424 tr_OpenDoor(trigPanelGUID, trigData.trigNoSound, trigData.trigd2d_doors);
2425 DoorTime := -1;
2426 end;
2428 // Òðèããåð "Äâåðü 5 ñåê" - ïîðà çàêðûâàòü
2429 if (TriggerType = TRIGGER_DOOR5) and (DoorTime = 0) and (g_Map_PanelByGUID(trigPanelGUID) <> nil) then
2430 begin
2431 pan := g_Map_PanelByGUID(trigPanelGUID);
2432 if (pan <> nil) and pan.isGWall then
2433 begin
2434 // Óæå çàêðûòà
2435 if {gWalls[trigPanelID].Enabled} pan.Enabled then
2436 begin
2437 DoorTime := -1;
2438 end
2439 else
2440 begin
2441 // Ïîêà îòêðûòà - çàêðûâàåì
2442 if tr_CloseDoor(trigPanelGUID, trigData.trigNoSound, trigData.trigd2d_doors) then DoorTime := -1;
2443 end;
2444 end;
2445 end;
2447 // Òðèããåð - ðàñøèðèòåëü èëè ïåðåêëþ÷àòåëü, è ïðîøëà çàäåðæêà, è íàæàëè íóæíîå ÷èñëî ðàç:
2448 if (TriggerType in [TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF]) and
2449 (PressTime = 0) and (PressCount >= trigData.trigCount) then
2450 begin
2451 // Ñáðàñûâàåì çàäåðæêó àêòèâàöèè:
2452 PressTime := -1;
2453 // Ñáðàñûâàåì ñ÷åò÷èê íàæàòèé:
2454 if trigData.trigCount > 0 then PressCount -= trigData.trigCount else PressCount := 0;
2456 // Îïðåäåëÿåì èçìåíÿåìûå èì òðèããåðû:
2457 for b := 0 to High(gTriggers) do
2458 begin
2459 if g_Collide(trigData.trigtX, trigData.trigtY, trigData.trigtWidth, trigData.trigtHeight, gTriggers[b].X, gTriggers[b].Y,
2460 gTriggers[b].Width, gTriggers[b].Height) and
2461 ((b <> a) or (trigData.trigWait > 0)) then
2462 begin // Can be self-activated, if there is Data.Wait
2463 if (not trigData.trigExtRandom) or gTriggers[b].Enabled then
2464 begin
2465 SetLength(Affected, Length(Affected) + 1);
2466 Affected[High(Affected)] := b;
2467 end;
2468 end;
2469 end;
2471 // if we have panelid, assume that it will switch the moving platform
2472 if (trigPanelGUID >= 0) then
2473 begin
2474 end;
2476 // Âûáèðàåì îäèí èç òðèããåðîâ äëÿ ðàñøèðèòåëÿ, åñëè âêëþ÷åí ðàíäîì:
2477 if (TriggerType = TRIGGER_PRESS) and trigData.trigExtRandom then
2478 begin
2479 if (Length(Affected) > 0) then
2480 begin
2481 b := Affected[Random(Length(Affected))];
2482 gTriggers[b].ActivateUID := gTriggers[a].ActivateUID;
2483 ActivateTrigger(gTriggers[b], 0);
2484 end;
2485 end
2486 else //  ïðîòèâíîì ñëó÷àå ðàáîòàåì êàê îáû÷íî:
2487 begin
2488 for i := 0 to High(Affected) do
2489 begin
2490 b := Affected[i];
2491 case TriggerType of
2492 TRIGGER_PRESS:
2493 begin
2494 gTriggers[b].ActivateUID := gTriggers[a].ActivateUID;
2495 ActivateTrigger(gTriggers[b], 0);
2496 end;
2497 TRIGGER_ON:
2498 begin
2499 gTriggers[b].Enabled := True;
2500 end;
2501 TRIGGER_OFF:
2502 begin
2503 gTriggers[b].Enabled := False;
2504 gTriggers[b].TimeOut := 0;
2505 if gTriggers[b].AutoSpawn then
2506 begin
2507 gTriggers[b].AutoSpawn := False;
2508 gTriggers[b].SpawnCooldown := 0;
2509 end;
2510 end;
2511 TRIGGER_ONOFF:
2512 begin
2513 gTriggers[b].Enabled := not gTriggers[b].Enabled;
2514 if not gTriggers[b].Enabled then
2515 begin
2516 gTriggers[b].TimeOut := 0;
2517 if gTriggers[b].AutoSpawn then
2518 begin
2519 gTriggers[b].AutoSpawn := False;
2520 gTriggers[b].SpawnCooldown := 0;
2521 end;
2522 end;
2523 end;
2524 end;
2525 end;
2526 end;
2527 SetLength(Affected, 0);
2528 end;
2530 // Óìåíüøàåì âðåìÿ äî âîçìîæíîñòè ïîâòîðíîé àêòèâàöèè:
2531 if TimeOut > 0 then
2532 begin
2533 TimeOut := TimeOut - 1;
2534 Continue; // ×òîáû íå ïîòåðÿòü 1 åäèíèöó çàäåðæêè
2535 end;
2537 // Íèæå èäóò òèïû àêòèâàöèè, åñëè òðèããåð îòêëþ÷¸í - èä¸ì äàëüøå
2538 if not Enabled then
2539 Continue;
2541 // "Èãðîê áëèçêî":
2542 if ByteBool(ActivateType and ACTIVATE_PLAYERCOLLIDE) and
2543 (TimeOut = 0) then
2544 if gPlayers <> nil then
2545 for b := 0 to High(gPlayers) do
2546 if gPlayers[b] <> nil then
2547 with gPlayers[b] do
2548 // Æèâ, åñòü íóæíûå êëþ÷è è îí ðÿäîì:
2549 if Live and ((gTriggers[a].Keys and GetKeys) = gTriggers[a].Keys) and
2550 Collide(X, Y, Width, Height) then
2551 begin
2552 gTriggers[a].ActivateUID := UID;
2554 if (gTriggers[a].TriggerType in [TRIGGER_SOUND, TRIGGER_MUSIC]) and
2555 PlayerCollide then
2556 { Don't activate sound/music again if player is here }
2557 else
2558 ActivateTrigger(gTriggers[a], ACTIVATE_PLAYERCOLLIDE);
2559 end;
2561 { TODO 5 : àêòèâàöèÿ ìîíñòðàìè òðèããåðîâ ñ êëþ÷àìè }
2563 if ByteBool(ActivateType and ACTIVATE_MONSTERCOLLIDE) and
2564 ByteBool(ActivateType and ACTIVATE_NOMONSTER) and
2565 (TimeOut = 0) and (Keys = 0) then
2566 begin
2567 // Åñëè "Ìîíñòð áëèçêî" è "Ìîíñòðîâ íåò",
2568 // çàïóñêàåì òðèããåð íà ñòàðòå êàðòû è ñíèìàåì îáà ôëàãà
2569 ActivateType := ActivateType and not (ACTIVATE_MONSTERCOLLIDE or ACTIVATE_NOMONSTER);
2570 gTriggers[a].ActivateUID := 0;
2571 ActivateTrigger(gTriggers[a], 0);
2572 end else
2573 begin
2574 // "Ìîíñòð áëèçêî"
2575 if ByteBool(ActivateType and ACTIVATE_MONSTERCOLLIDE) and
2576 (TimeOut = 0) and (Keys = 0) then // Åñëè íå íóæíû êëþ÷è
2577 begin
2578 //g_Mons_ForEach(monsNear);
2579 //Alive?!
2580 tgMonsList.reset();
2581 g_Mons_ForEachAt(gTriggers[a].X, gTriggers[a].Y, gTriggers[a].Width, gTriggers[a].Height, monsNear);
2582 for mon in tgMonsList do
2583 begin
2584 gTriggers[a].ActivateUID := mon.UID;
2585 ActivateTrigger(gTriggers[a], ACTIVATE_MONSTERCOLLIDE);
2586 end;
2587 tgMonsList.reset(); // just in case
2588 end;
2590 // "Ìîíñòðîâ íåò"
2591 if ByteBool(ActivateType and ACTIVATE_NOMONSTER) and
2592 (TimeOut = 0) and (Keys = 0) then
2593 if not g_Mons_IsAnyAliveAt(X, Y, Width, Height) then
2594 begin
2595 gTriggers[a].ActivateUID := 0;
2596 ActivateTrigger(gTriggers[a], ACTIVATE_NOMONSTER);
2597 end;
2598 end;
2600 PlayerCollide := g_CollidePlayer(X, Y, Width, Height);
2601 end;
2602 end;
2604 procedure g_Triggers_Press(ID: DWORD; ActivateType: Byte; ActivateUID: Word = 0);
2605 begin
2606 gTriggers[ID].ActivateUID := ActivateUID;
2607 ActivateTrigger(gTriggers[ID], ActivateType);
2608 end;
2610 function g_Triggers_PressR(X, Y: Integer; Width, Height: Word; UID: Word;
2611 ActivateType: Byte; IgnoreList: DWArray = nil): DWArray;
2612 var
2613 a: Integer;
2614 k: Byte;
2615 p: TPlayer;
2616 begin
2617 Result := nil;
2619 if gTriggers = nil then Exit;
2621 case g_GetUIDType(UID) of
2622 UID_GAME: k := 255;
2623 UID_PLAYER:
2624 begin
2625 p := g_Player_Get(UID);
2626 if p <> nil then
2627 k := p.GetKeys
2628 else
2629 k := 0;
2630 end;
2631 else k := 0;
2632 end;
2634 for a := 0 to High(gTriggers) do
2635 if (gTriggers[a].TriggerType <> TRIGGER_NONE) and
2636 (gTriggers[a].TimeOut = 0) and
2637 (not InDWArray(a, IgnoreList)) and
2638 ((gTriggers[a].Keys and k) = gTriggers[a].Keys) and
2639 ByteBool(gTriggers[a].ActivateType and ActivateType) then
2640 if g_Collide(X, Y, Width, Height,
2641 gTriggers[a].X, gTriggers[a].Y,
2642 gTriggers[a].Width, gTriggers[a].Height) then
2643 begin
2644 gTriggers[a].ActivateUID := UID;
2645 if ActivateTrigger(gTriggers[a], ActivateType) then
2646 begin
2647 SetLength(Result, Length(Result)+1);
2648 Result[High(Result)] := a;
2649 end;
2650 end;
2651 end;
2653 procedure g_Triggers_PressL(X1, Y1, X2, Y2: Integer; UID: DWORD; ActivateType: Byte);
2654 var
2655 a: Integer;
2656 k: Byte;
2657 p: TPlayer;
2658 begin
2659 if gTriggers = nil then Exit;
2661 case g_GetUIDType(UID) of
2662 UID_GAME: k := 255;
2663 UID_PLAYER:
2664 begin
2665 p := g_Player_Get(UID);
2666 if p <> nil then
2667 k := p.GetKeys
2668 else
2669 k := 0;
2670 end;
2671 else k := 0;
2672 end;
2674 for a := 0 to High(gTriggers) do
2675 if (gTriggers[a].TriggerType <> TRIGGER_NONE) and
2676 (gTriggers[a].TimeOut = 0) and
2677 ((gTriggers[a].Keys and k) = gTriggers[a].Keys) and
2678 ByteBool(gTriggers[a].ActivateType and ActivateType) then
2679 if g_CollideLine(x1, y1, x2, y2, gTriggers[a].X, gTriggers[a].Y,
2680 gTriggers[a].Width, gTriggers[a].Height) then
2681 begin
2682 gTriggers[a].ActivateUID := UID;
2683 ActivateTrigger(gTriggers[a], ActivateType);
2684 end;
2685 end;
2687 procedure g_Triggers_PressC(CX, CY: Integer; Radius: Word; UID: Word; ActivateType: Byte; IgnoreTrigger: Integer = -1);
2688 var
2689 a: Integer;
2690 k: Byte;
2691 rsq: Word;
2692 p: TPlayer;
2693 begin
2694 if gTriggers = nil then
2695 Exit;
2697 case g_GetUIDType(UID) of
2698 UID_GAME: k := 255;
2699 UID_PLAYER:
2700 begin
2701 p := g_Player_Get(UID);
2702 if p <> nil then
2703 k := p.GetKeys
2704 else
2705 k := 0;
2706 end;
2707 else k := 0;
2708 end;
2710 rsq := Radius * Radius;
2712 for a := 0 to High(gTriggers) do
2713 if (gTriggers[a].ID <> DWORD(IgnoreTrigger)) and
2714 (gTriggers[a].TriggerType <> TRIGGER_NONE) and
2715 (gTriggers[a].TimeOut = 0) and
2716 ((gTriggers[a].Keys and k) = gTriggers[a].Keys) and
2717 ByteBool(gTriggers[a].ActivateType and ActivateType) then
2718 with gTriggers[a] do
2719 if g_Collide(CX-Radius, CY-Radius, 2*Radius, 2*Radius,
2720 X, Y, Width, Height) then
2721 if ((Sqr(CX-X)+Sqr(CY-Y)) < rsq) or // Öåíòð êðóãà áëèçîê ê âåðõíåìó ëåâîìó óãëó
2722 ((Sqr(CX-X-Width)+Sqr(CY-Y)) < rsq) or // Öåíòð êðóãà áëèçîê ê âåðõíåìó ïðàâîìó óãëó
2723 ((Sqr(CX-X-Width)+Sqr(CY-Y-Height)) < rsq) or // Öåíòð êðóãà áëèçîê ê íèæíåìó ïðàâîìó óãëó
2724 ((Sqr(CX-X)+Sqr(CY-Y-Height)) < rsq) or // Öåíòð êðóãà áëèçîê ê íèæíåìó ëåâîìó óãëó
2725 ( (CX > (X-Radius)) and (CX < (X+Width+Radius)) and
2726 (CY > Y) and (CY < (Y+Height)) ) or // Öåíòð êðóãà íåäàëåêî îò âåðòèêàëüíûõ ãðàíèö ïðÿìîóãîëüíèêà
2727 ( (CY > (Y-Radius)) and (CY < (Y+Height+Radius)) and
2728 (CX > X) and (CX < (X+Width)) ) then // Öåíòð êðóãà íåäàëåêî îò ãîðèçîíòàëüíûõ ãðàíèö ïðÿìîóãîëüíèêà
2729 begin
2730 ActivateUID := UID;
2731 ActivateTrigger(gTriggers[a], ActivateType);
2732 end;
2733 end;
2735 procedure g_Triggers_OpenAll();
2736 var
2737 a: Integer;
2738 b: Boolean;
2739 begin
2740 if gTriggers = nil then Exit;
2742 b := False;
2743 for a := 0 to High(gTriggers) do
2744 begin
2745 with gTriggers[a] do
2746 begin
2747 if (TriggerType = TRIGGER_OPENDOOR) or
2748 (TriggerType = TRIGGER_DOOR5) or
2749 (TriggerType = TRIGGER_DOOR) then
2750 begin
2751 tr_OpenDoor(trigPanelGUID, True, trigData.trigd2d_doors);
2752 if TriggerType = TRIGGER_DOOR5 then DoorTime := 180;
2753 b := True;
2754 end;
2755 end;
2756 end;
2758 if b then g_Sound_PlayEx('SOUND_GAME_DOOROPEN');
2759 end;
2761 procedure g_Triggers_DecreaseSpawner(ID: DWORD);
2762 begin
2763 if (gTriggers <> nil) then
2764 if gTriggers[ID].SpawnedCount > 0 then
2765 Dec(gTriggers[ID].SpawnedCount);
2766 end;
2768 procedure g_Triggers_Free();
2769 var
2770 a: Integer;
2771 begin
2772 for a := 0 to High(gTriggers) do
2773 begin
2774 if (gTriggers[a].TriggerType = TRIGGER_SOUND) then
2775 begin
2776 if g_Sound_Exists(gTriggers[a].trigData.trigSoundName) then
2777 begin
2778 g_Sound_Delete(gTriggers[a].trigData.trigSoundName);
2779 end;
2780 gTriggers[a].Sound.Free();
2781 end;
2782 if (gTriggers[a].Activators <> nil) then
2783 begin
2784 SetLength(gTriggers[a].Activators, 0);
2785 end;
2786 gTriggers[a].trigData.Free();
2787 end;
2789 gTriggers := nil;
2790 gSecretsCount := 0;
2791 SetLength(gMonstersSpawned, 0);
2792 end;
2794 procedure g_Triggers_SaveState(var Mem: TBinMemoryWriter);
2795 var
2796 count, act_count, i, j: Integer;
2797 dw: DWORD;
2798 sg: Single;
2799 b: Boolean;
2800 begin
2801 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðèããåðîâ
2802 count := Length(gTriggers);
2804 Mem := TBinMemoryWriter.Create((count+1) * 200);
2806 // Êîëè÷åñòâî òðèããåðîâ:
2807 Mem.WriteInt(count);
2809 //e_LogWritefln('saving %s triggers (count=%s)', [Length(gTriggers), count]);
2811 if count = 0 then exit;
2813 for i := 0 to High(gTriggers) do
2814 begin
2815 // Ñèãíàòóðà òðèããåðà:
2816 dw := TRIGGER_SIGNATURE; // 'TRGX'
2817 Mem.WriteDWORD(dw);
2818 // Òèï òðèããåðà:
2819 Mem.WriteByte(gTriggers[i].TriggerType);
2820 if (gTriggers[i].TriggerType = TRIGGER_NONE) then continue; // empty one
2821 // Ñïåöèàëüíûå äàííûå òðèããåðà: äà â æîïó, ïîòîì èç êàðòû îïÿòü âûòàùèì; ñîõðàíèì òîëüêî èíäåêñ
2822 //e_LogWritefln('=== trigger #%s saved ===', [gTriggers[i].mapIndex]);
2823 Mem.WriteInt(gTriggers[i].mapIndex);
2824 //p := @gTriggers[i].Data;
2825 //Mem.WriteMemory(p, SizeOf(TTriggerData));
2826 // Êîîðäèíàòû ëåâîãî âåðõíåãî óãëà:
2827 Mem.WriteInt(gTriggers[i].X);
2828 Mem.WriteInt(gTriggers[i].Y);
2829 // Ðàçìåðû:
2830 Mem.WriteWord(gTriggers[i].Width);
2831 Mem.WriteWord(gTriggers[i].Height);
2832 // Âêëþ÷åí ëè òðèããåð:
2833 Mem.WriteBoolean(gTriggers[i].Enabled);
2834 // Òèï àêòèâàöèè òðèããåðà:
2835 Mem.WriteByte(gTriggers[i].ActivateType);
2836 // Êëþ÷è, íåîáõîäèìûå äëÿ àêòèâàöèè:
2837 Mem.WriteByte(gTriggers[i].Keys);
2838 // ID ïàíåëè, òåêñòóðà êîòîðîé èçìåíèòñÿ:
2839 Mem.WriteInt(gTriggers[i].TexturePanelGUID);
2840 // Òèï ýòîé ïàíåëè:
2841 Mem.WriteWord(gTriggers[i].TexturePanelType);
2842 // Âíóòðåííèé íîìåð äðóãîé ïàíåëè (ïî ñ÷àñòëèâîé ñëó÷àéíîñòè îí áóäåò ñîâïàäàòü ñ òåì, ÷òî ñîçäàíî ïðè çàãðóçêå êàðòû)
2843 Mem.WriteInt(gTriggers[i].trigPanelGUID);
2844 // Âðåìÿ äî âîçìîæíîñòè àêòèâàöèè:
2845 Mem.WriteWord(gTriggers[i].TimeOut);
2846 // UID òîãî, êòî àêòèâèðîâàë ýòîò òðèããåð:
2847 Mem.WriteWord(gTriggers[i].ActivateUID);
2848 // Ñïèñîê UID-îâ îáúåêòîâ, êîòîðûå íàõîäèëèñü ïîä âîçäåéñòâèåì:
2849 act_count := Length(gTriggers[i].Activators);
2850 Mem.WriteInt(act_count);
2851 for j := 0 to act_count-1 do
2852 begin
2853 // UID îáúåêòà
2854 Mem.WriteWord(gTriggers[i].Activators[j].UID);
2855 // Âðåìÿ îæèäàíèÿ
2856 Mem.WriteWord(gTriggers[i].Activators[j].TimeOut);
2857 end;
2858 // Ñòîèò ëè èãðîê â îáëàñòè òðèããåðà:
2859 Mem.WriteBoolean(gTriggers[i].PlayerCollide);
2860 // Âðåìÿ äî çàêðûòèÿ äâåðè:
2861 Mem.WriteInt(gTriggers[i].DoorTime);
2862 // Çàäåðæêà àêòèâàöèè:
2863 Mem.WriteInt(gTriggers[i].PressTime);
2864 // Ñ÷åò÷èê íàæàòèé:
2865 Mem.WriteInt(gTriggers[i].PressCount);
2866 // Ñïàâíåð àêòèâåí:
2867 Mem.WriteBoolean(gTriggers[i].AutoSpawn);
2868 // Çàäåðæêà ñïàâíåðà:
2869 Mem.WriteInt(gTriggers[i].SpawnCooldown);
2870 // Ñ÷åò÷èê ñîçäàíèÿ îáúåêòîâ:
2871 Mem.WriteInt(gTriggers[i].SpawnedCount);
2872 // Ñêîëüêî ðàç ïðîèãðàí çâóê:
2873 Mem.WriteInt(gTriggers[i].SoundPlayCount);
2874 // Ïðîèãðûâàåòñÿ ëè çâóê?
2875 if gTriggers[i].Sound <> nil then
2876 b := gTriggers[i].Sound.IsPlaying()
2877 else
2878 b := False;
2879 Mem.WriteBoolean(b);
2880 if b then
2881 begin
2882 // Ïîçèöèÿ ïðîèãðûâàíèÿ çâóêà:
2883 dw := gTriggers[i].Sound.GetPosition();
2884 Mem.WriteDWORD(dw);
2885 // Ãðîìêîñòü çâóêà:
2886 sg := gTriggers[i].Sound.GetVolume();
2887 sg := sg / (gSoundLevel/255.0);
2888 Mem.WriteSingle(sg);
2889 // Ñòåðåî ñìåùåíèå çâóêà:
2890 sg := gTriggers[i].Sound.GetPan();
2891 Mem.WriteSingle(sg);
2892 end;
2893 end;
2894 end;
2896 procedure g_Triggers_LoadState(var Mem: TBinMemoryReader);
2897 var
2898 count, act_count, i, j, a: Integer;
2899 dw: DWORD;
2900 vol, pan: Single;
2901 b: Boolean;
2902 //p: Pointer;
2903 Trig: TTrigger;
2904 mapIndex: Integer;
2905 //tw: TStrTextWriter;
2906 begin
2907 if Mem = nil then
2908 Exit;
2910 g_Triggers_Free();
2912 // Êîëè÷åñòâî òðèããåðîâ:
2913 Mem.ReadInt(count);
2915 if (count = 0) then exit;
2917 for a := 0 to count-1 do
2918 begin
2919 // Ñèãíàòóðà òðèããåðà:
2920 Mem.ReadDWORD(dw);
2921 if (dw <> TRIGGER_SIGNATURE) then // 'TRGX'
2922 begin
2923 raise EBinSizeError.Create('g_Triggers_LoadState: Wrong Trigger Signature');
2924 end;
2925 // Òèï òðèããåðà:
2926 Mem.ReadByte(Trig.TriggerType);
2927 // Ñïåöèàëüíûå äàííûå òðèããåðà: èíäåêñ â gCurrentMap.field['triggers']
2928 if (Trig.TriggerType = TRIGGER_NONE) then continue; // empty one
2929 Mem.ReadInt(mapIndex);
2930 //!!!FIXME!!!
2932 Mem.ReadMemory(p, dw);
2933 if dw <> SizeOf(TTriggerData) then
2934 begin
2935 raise EBinSizeError.Create('g_Triggers_LoadState: Wrong TriggerData Size');
2936 end;
2937 Trig.Data := TTriggerData(p^);
2939 // Ñîçäàåì òðèããåð:
2940 i := g_Triggers_CreateWithMapIndex(Trig, a, mapIndex);
2942 if (gTriggers[i].trigData <> nil) then
2943 begin
2944 tw := TStrTextWriter.Create();
2945 try
2946 gTriggers[i].trigData.writeTo(tw);
2947 e_LogWritefln('=== trigger #%s loaded ==='#10'%s'#10'---', [mapIndex, tw.str]);
2948 finally
2949 tw.Free();
2950 end;
2951 end;
2953 // Êîîðäèíàòû ëåâîãî âåðõíåãî óãëà:
2954 Mem.ReadInt(gTriggers[i].X);
2955 Mem.ReadInt(gTriggers[i].Y);
2956 // Ðàçìåðû:
2957 Mem.ReadWord(gTriggers[i].Width);
2958 Mem.ReadWord(gTriggers[i].Height);
2959 // Âêëþ÷åí ëè òðèããåð:
2960 Mem.ReadBoolean(gTriggers[i].Enabled);
2961 // Òèï àêòèâàöèè òðèããåðà:
2962 Mem.ReadByte(gTriggers[i].ActivateType);
2963 // Êëþ÷è, íåîáõîäèìûå äëÿ àêòèâàöèè:
2964 Mem.ReadByte(gTriggers[i].Keys);
2965 // ID ïàíåëè, òåêñòóðà êîòîðîé èçìåíèòñÿ:
2966 Mem.ReadInt(gTriggers[i].TexturePanelGUID);
2967 // Òèï ýòîé ïàíåëè:
2968 Mem.ReadWord(gTriggers[i].TexturePanelType);
2969 // Âíóòðåííèé íîìåð äðóãîé ïàíåëè (ïî ñ÷àñòëèâîé ñëó÷àéíîñòè îí áóäåò ñîâïàäàòü ñ òåì, ÷òî ñîçäàíî ïðè çàãðóçêå êàðòû)
2970 Mem.ReadInt(gTriggers[i].trigPanelGUID);
2971 // Âðåìÿ äî âîçìîæíîñòè àêòèâàöèè:
2972 Mem.ReadWord(gTriggers[i].TimeOut);
2973 // UID òîãî, êòî àêòèâèðîâàë ýòîò òðèããåð:
2974 Mem.ReadWord(gTriggers[i].ActivateUID);
2975 // Ñïèñîê UID-îâ îáúåêòîâ, êîòîðûå íàõîäèëèñü ïîä âîçäåéñòâèåì:
2976 Mem.ReadInt(act_count);
2977 if act_count > 0 then
2978 begin
2979 SetLength(gTriggers[i].Activators, act_count);
2980 for j := 0 to act_count-1 do
2981 begin
2982 // UID îáúåêòà
2983 Mem.ReadWord(gTriggers[i].Activators[j].UID);
2984 // Âðåìÿ îæèäàíèÿ
2985 Mem.ReadWord(gTriggers[i].Activators[j].TimeOut);
2986 end;
2987 end;
2988 // Ñòîèò ëè èãðîê â îáëàñòè òðèããåðà:
2989 Mem.ReadBoolean(gTriggers[i].PlayerCollide);
2990 // Âðåìÿ äî çàêðûòèÿ äâåðè:
2991 Mem.ReadInt(gTriggers[i].DoorTime);
2992 // Çàäåðæêà àêòèâàöèè:
2993 Mem.ReadInt(gTriggers[i].PressTime);
2994 // Ñ÷åò÷èê íàæàòèé:
2995 Mem.ReadInt(gTriggers[i].PressCount);
2996 // Ñïàâíåð àêòèâåí:
2997 Mem.ReadBoolean(gTriggers[i].AutoSpawn);
2998 // Çàäåðæêà ñïàâíåðà:
2999 Mem.ReadInt(gTriggers[i].SpawnCooldown);
3000 // Ñ÷åò÷èê ñîçäàíèÿ îáúåêòîâ:
3001 Mem.ReadInt(gTriggers[i].SpawnedCount);
3002 // Ñêîëüêî ðàç ïðîèãðàí çâóê:
3003 Mem.ReadInt(gTriggers[i].SoundPlayCount);
3004 // Ïðîèãðûâàåòñÿ ëè çâóê?
3005 Mem.ReadBoolean(b);
3006 if b then
3007 begin
3008 // Ïîçèöèÿ ïðîèãðûâàíèÿ çâóêà:
3009 Mem.ReadDWORD(dw);
3010 // Ãðîìêîñòü çâóêà:
3011 Mem.ReadSingle(vol);
3012 // Ñòåðåî ñìåùåíèå çâóêà:
3013 Mem.ReadSingle(pan);
3014 // Çàïóñêàåì çâóê, åñëè åñòü:
3015 if gTriggers[i].Sound <> nil then
3016 begin
3017 gTriggers[i].Sound.PlayPanVolume(pan, vol);
3018 gTriggers[i].Sound.Pause(True);
3019 gTriggers[i].Sound.SetPosition(dw);
3020 end
3021 end;
3022 end;
3023 end;
3025 end.