DEADSOFTWARE

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