1ee3fec1b60dd6f7490401081245f37770940e60
1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
22 MAPDEF
, g_textures
, g_phys
, g_saveload
;
30 arrIdx
: Integer; // in ggItems
35 InitX
, InitY
: Integer;
39 QuietRespawn
: Boolean;
40 SpawnTrigger
: Integer;
42 Animation
: TAnimationState
;
43 dropped
: Boolean; // dropped from the monster? drops should be rendered after corpses, so zombie corpse will not obscure ammo container, for example
46 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
47 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
48 procedure moveBy (dx
, dy
: Integer); inline;
50 property used
: Boolean read slotIsUsed
;
51 property myid
: Integer read arrIdx
;
54 procedure g_Items_LoadData();
55 procedure g_Items_FreeData();
56 procedure g_Items_Init();
57 procedure g_Items_Free();
58 function g_Items_Create(X
, Y
: Integer; ItemType
: Byte;
59 Fall
, Respawnable
: Boolean; AdjCoord
: Boolean = False; ForcedID
: Integer = -1): DWORD
;
60 procedure g_Items_SetDrop (ID
: DWORD
);
61 procedure g_Items_PreUpdate();
62 procedure g_Items_Update();
63 procedure g_Items_Pick(ID
: DWORD
);
64 procedure g_Items_Remove(ID
: DWORD
);
65 procedure g_Items_SaveState (st
: TStream
);
66 procedure g_Items_LoadState (st
: TStream
);
68 procedure g_Items_RestartRound ();
70 function g_Items_ValidId (idx
: Integer): Boolean; inline;
71 function g_Items_ByIdx (idx
: Integer): PItem
;
72 function g_Items_ObjByIdx (idx
: Integer): PObj
;
74 procedure g_Items_EmitPickupSound (idx
: Integer); // at item position
75 procedure g_Items_EmitPickupSoundAt (idx
, x
, y
: Integer);
77 procedure g_Items_AddDynLights();
81 TItemEachAliveCB
= function (it
: PItem
): Boolean is nested
; // return `true` to stop
83 function g_Items_ForEachAlive (cb
: TItemEachAliveCB
; backwards
: Boolean=false): Boolean;
84 function g_Items_NextAlive (startIdx
: Integer): PItem
;
87 gMaxDist
: Integer = 1; // for sounds
89 var (* private state *)
90 ggItems
: Array of TItem
= nil;
96 g_basic
, g_sound
, g_gfx
, g_map
, r_textures
, r_animations
,
97 g_game
, g_triggers
, g_console
, g_player
, g_net
, g_netmsg
,
99 g_grid
, binheap
, idpool
, utils
, xstreams
;
101 // ////////////////////////////////////////////////////////////////////////// //
103 freeIds
: TIdPool
= nil;
106 // ////////////////////////////////////////////////////////////////////////// //
107 function g_Items_ValidId (idx
: Integer): Boolean; inline;
110 if (idx
< 0) or (idx
> High(ggItems
)) then exit
;
111 if not ggItems
[idx
].slotIsUsed
then exit
;
116 function g_Items_ByIdx (idx
: Integer): PItem
;
118 if (idx
< 0) or (idx
> High(ggItems
)) then raise Exception
.Create('g_ItemObjByIdx: invalid index');
119 result
:= @ggItems
[idx
];
120 if not result
.slotIsUsed
then raise Exception
.Create('g_ItemObjByIdx: requested inexistent item');
124 function g_Items_ObjByIdx (idx
: Integer): PObj
;
126 if (idx
< 0) or (idx
> High(ggItems
)) then raise Exception
.Create('g_ItemObjByIdx: invalid index');
127 if not ggItems
[idx
].slotIsUsed
then raise Exception
.Create('g_ItemObjByIdx: requested inexistent item');
128 result
:= @ggItems
[idx
].Obj
;
132 // ////////////////////////////////////////////////////////////////////////// //
133 procedure TItem
.positionChanged ();
135 NeedSend
:= NeedSend
or (Obj
.X
<> Obj
.oldX
) or (Obj
.Y
<> Obj
.oldY
);
138 procedure TItem
.getMapBox (out x
, y
, w
, h
: Integer); inline;
140 x
:= Obj
.X
+Obj
.Rect
.X
;
141 y
:= Obj
.Y
+Obj
.Rect
.Y
;
143 h
:= Obj
.Rect
.Height
;
146 procedure TItem
.moveBy (dx
, dy
: Integer); inline;
148 if (dx
<> 0) or (dy
<> 0) then
156 // ////////////////////////////////////////////////////////////////////////// //
158 ITEM_SIGNATURE
= $4D455449; // 'ITEM'
160 ITEMSIZE
: Array [ITEM_MEDKIT_SMALL
..ITEM_MAX
] of Array [0..1] of Byte =
161 (((14), (15)), // MEDKIT_SMALL
162 ((28), (19)), // MEDKIT_LARGE
163 ((28), (19)), // MEDKIT_BLACK
164 ((31), (16)), // ARMOR_GREEN
165 ((31), (16)), // ARMOR_BLUE
166 ((25), (25)), // SPHERE_BLUE
167 ((25), (25)), // SPHERE_WHITE
168 ((24), (47)), // SUIT
169 ((14), (27)), // OXYGEN
170 ((25), (25)), // INVUL
171 ((62), (24)), // WEAPON_SAW
172 ((63), (12)), // WEAPON_SHOTGUN1
173 ((54), (13)), // WEAPON_SHOTGUN2
174 ((54), (16)), // WEAPON_CHAINGUN
175 ((62), (16)), // WEAPON_ROCKETLAUNCHER
176 ((54), (16)), // WEAPON_PLASMA
177 ((61), (36)), // WEAPON_BFG
178 ((54), (16)), // WEAPON_SUPERPULEMET
179 (( 9), (11)), // AMMO_BULLETS
180 ((28), (16)), // AMMO_BULLETS_BOX
181 ((15), ( 7)), // AMMO_SHELLS
182 ((32), (12)), // AMMO_SHELLS_BOX
183 ((12), (27)), // AMMO_ROCKET
184 ((54), (21)), // AMMO_ROCKET_BOX
185 ((15), (12)), // AMMO_CELL
186 ((32), (21)), // AMMO_CELL_BIG
187 ((22), (29)), // AMMO_BACKPACK
188 ((16), (16)), // KEY_RED
189 ((16), (16)), // KEY_GREEN
190 ((16), (16)), // KEY_BLUE
191 (( 1), ( 1)), // WEAPON_KASTET
192 ((43), (16)), // WEAPON_PISTOL
193 ((14), (18)), // BOTTLE
194 ((16), (15)), // HELMET
195 ((32), (24)), // JETPACK
196 ((25), (25)), // INVIS
197 ((53), (20)), // WEAPON_FLAMETHROWER
198 ((13), (20))); // AMMO_FUELCAN
200 procedure g_Items_LoadData();
202 e_WriteLog('Loading items data...', TMsgType
.Notify
);
204 g_Sound_CreateWADEx('SOUND_ITEM_RESPAWNITEM', GameWAD
+':SOUNDS\RESPAWNITEM');
205 g_Sound_CreateWADEx('SOUND_ITEM_GETRULEZ', GameWAD
+':SOUNDS\GETRULEZ');
206 g_Sound_CreateWADEx('SOUND_ITEM_GETWEAPON', GameWAD
+':SOUNDS\GETWEAPON');
207 g_Sound_CreateWADEx('SOUND_ITEM_GETITEM', GameWAD
+':SOUNDS\GETITEM');
209 freeIds
:= TIdPool
.Create();
213 procedure g_Items_FreeData();
215 e_WriteLog('Releasing items data...', TMsgType
.Notify
);
217 g_Sound_Delete('SOUND_ITEM_RESPAWNITEM');
218 g_Sound_Delete('SOUND_ITEM_GETRULEZ');
219 g_Sound_Delete('SOUND_ITEM_GETWEAPON');
220 g_Sound_Delete('SOUND_ITEM_GETITEM');
227 procedure releaseItem (idx
: Integer);
231 if (idx
< 0) or (idx
> High(ggItems
)) then raise Exception
.Create('releaseItem: invalid item id');
232 if not freeIds
.hasAlloced
[LongWord(idx
)] then raise Exception
.Create('releaseItem: trying to release unallocated item (0)');
234 if not it
.slotIsUsed
then raise Exception
.Create('releaseItem: trying to release unallocated item (1)');
235 if (it
.arrIdx
<> idx
) then raise Exception
.Create('releaseItem: arrIdx inconsistency');
236 it
.slotIsUsed
:= false;
237 if (it
.Animation
<> nil) then
243 it
.SpawnTrigger
:= -1;
244 it
.ItemType
:= ITEM_NONE
;
245 it
.NeedSend
:= false;
246 freeIds
.release(LongWord(idx
));
250 procedure growItemArrayTo (newsz
: Integer);
255 if (newsz
< Length(ggItems
)) then exit
;
257 olen
:= Length(ggItems
);
258 SetLength(ggItems
, newsz
);
259 for i
:= olen
to High(ggItems
) do
262 it
.slotIsUsed
:= false;
264 it
.ItemType
:= ITEM_NONE
;
267 it
.SpawnTrigger
:= -1;
268 it
.Respawnable
:= false;
269 it
.NeedSend
:= false;
270 //if not freeIds.hasFree[LongWord(i)] then raise Exception.Create('internal error in item idx manager');
275 function allocItem (): DWORD
;
277 result
:= freeIds
.alloc();
278 if (result
>= Length(ggItems
)) then growItemArrayTo(Integer(result
)+64);
279 if (Integer(result
) > High(ggItems
)) then raise Exception
.Create('allocItem: freeid list corrupted');
280 if (ggItems
[result
].arrIdx
<> Integer(result
)) then raise Exception
.Create('allocItem: arrIdx inconsistency');
284 // it will be slow if the slot is free (we have to rebuild the heap)
285 function wantItemSlot (slot
: Integer): Integer;
290 if (slot
< 0) or (slot
> $0fffffff) then raise Exception
.Create('wantItemSlot: bad item slot request');
291 // do we need to grow item storate?
292 olen
:= Length(ggItems
);
293 if (slot
>= olen
) then growItemArrayTo(slot
+64);
295 it
:= @ggItems
[slot
];
296 if not it
.slotIsUsed
then
298 freeIds
.alloc(LongWord(slot
));
302 if not freeIds
.hasAlloced
[slot
] then raise Exception
.Create('wantItemSlot: internal error in item idx manager');
304 it
.slotIsUsed
:= false;
310 // ////////////////////////////////////////////////////////////////////////// //
311 procedure g_Items_Init ();
315 if gMapInfo
.Height
> gPlayerScreenSize
.Y
then a
:= gMapInfo
.Height
-gPlayerScreenSize
.Y
else a
:= gMapInfo
.Height
;
316 if gMapInfo
.Width
> gPlayerScreenSize
.X
then b
:= gMapInfo
.Width
-gPlayerScreenSize
.X
else b
:= gMapInfo
.Width
;
317 gMaxDist
:= Trunc(Hypot(a
, b
));
321 procedure g_Items_Free ();
325 if (ggItems
<> nil) then
327 for i
:= 0 to High(ggItems
) do ggItems
[i
].Animation
.Free();
334 function g_Items_Create (X
, Y
: Integer; ItemType
: Byte;
335 Fall
, Respawnable
: Boolean; AdjCoord
: Boolean = False; ForcedID
: Integer = -1): DWORD
;
340 if ForcedID
< 0 then find_id
:= allocItem() else find_id
:= wantItemSlot(ForcedID
);
342 //{$IF DEFINED(D2F_DEBUG)}e_WriteLog(Format('allocated item #%d', [Integer(find_id)]), MSG_NOTIFY);{$ENDIF}
344 it
:= @ggItems
[find_id
];
346 if (it
.arrIdx
<> Integer(find_id
)) then raise Exception
.Create('g_Items_Create: arrIdx inconsistency');
347 //it.arrIdx := find_id;
348 it
.slotIsUsed
:= true;
350 it
.ItemType
:= ItemType
;
351 it
.Respawnable
:= Respawnable
;
357 it
.QuietRespawn
:= False;
359 it
.NeedSend
:= false;
364 it
.Obj
.Rect
.Width
:= ITEMSIZE
[ItemType
][0];
365 it
.Obj
.Rect
.Height
:= ITEMSIZE
[ItemType
][1];
368 it
.SpawnTrigger
:= -1;
370 // Êîîðäèíàòû îòíîñèòåëüíî öåíòðà íèæíåãî ðåáðà
375 Obj
.X
:= X
- (Obj
.Rect
.Width
div 2);
376 Obj
.Y
:= Y
- Obj
.Rect
.Height
;
382 it
.Obj
.oldX
:= it
.Obj
.X
;
383 it
.Obj
.oldY
:= it
.Obj
.Y
;
385 // Óñòàíîâêà àíèìàöèè
387 ITEM_ARMOR_GREEN
: it
.Animation
:= TAnimationState
.Create(True, 20, 3);
388 ITEM_ARMOR_BLUE
: it
.Animation
:= TAnimationState
.Create(True, 20, 3);
389 ITEM_JETPACK
: it
.Animation
:= TAnimationState
.Create(True, 15, 3);
390 ITEM_SPHERE_BLUE
: it
.Animation
:= TAnimationState
.Create(True, 15, 4);
391 ITEM_SPHERE_WHITE
: it
.Animation
:= TAnimationState
.Create(True, 20, 4);
392 ITEM_INVUL
: it
.Animation
:= TAnimationState
.Create(True, 20, 4);
393 ITEM_INVIS
: it
.Animation
:= TAnimationState
.Create(True, 20, 4);
394 ITEM_BOTTLE
: it
.Animation
:= TAnimationState
.Create(True, 20, 4);
395 ITEM_HELMET
: it
.Animation
:= TAnimationState
.Create(True, 20, 4);
398 it
.positionChanged();
403 procedure g_Items_PreUpdate ();
407 if (ggItems
= nil) then Exit
;
408 for i
:= 0 to High(ggItems
) do
409 if (ggItems
[i
].ItemType
<> ITEM_NONE
) and ggItems
[i
].slotIsUsed
then
411 ggItems
[i
].Obj
.oldX
:= ggItems
[i
].Obj
.X
;
412 ggItems
[i
].Obj
.oldY
:= ggItems
[i
].Obj
.Y
;
416 procedure g_Items_Update ();
421 m
, ItemRespawnTime
: Word;
424 if (ggItems
= nil) then exit
;
426 // respawn items in 15 seconds regardless of settings during warmup
427 ItemRespawnTime
:= IfThen(gLMSRespawn
= LMS_RESPAWN_NONE
, gGameSettings
.ItemRespawnTime
, 15);
429 for i
:= 0 to High(ggItems
) do
431 if (ggItems
[i
].ItemType
= ITEM_NONE
) then continue
;
432 if not ggItems
[i
].slotIsUsed
then continue
; // just in case
442 m
:= g_Obj_Move(@Obj
, True, True);
443 positionChanged(); // this updates spatial accelerators
445 // Ñîïðîòèâëåíèå âîçäóõà
446 if gTime
mod (GAME_TICK
*2) = 0 then Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
448 // Åñëè âûïàë çà êàðòó
449 if WordBool(m
and MOVE_FALLOUT
) then
451 if SpawnTrigger
= -1 then
458 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_ItemDestroy(True, i
);
464 // Åñëè èãðîêè ïîáëèçîñòè
465 if (gPlayers
<> nil) then
467 j
:= Random(Length(gPlayers
))-1;
469 for k
:= 0 to High(gPlayers
) do
472 if j
> High(gPlayers
) then j
:= 0;
474 if (gPlayers
[j
] <> nil) and gPlayers
[j
].alive
and g_Obj_Collide(@gPlayers
[j
].Obj
, @Obj
) then
476 if g_Game_IsClient
then continue
;
478 if not gPlayers
[j
].PickItem(ItemType
, Respawnable
, r
) then continue
;
480 if g_Game_IsNet
then MH_SEND_PlayerStats(gPlayers
[j
].UID
);
484 1. I_NONE,I_CLIP,I_SHEL,I_ROCKET,I_CELL,I_AMMO,I_SBOX,I_RBOX,I_CELP,I_BPACK,I_CSAW,I_SGUN,I_SGUN2,I_MGUN,I_LAUN,I_PLAS,I_BFG,I_GUN2
485 +2. I_MEGA,I_INVL,I_SUPER
486 3. I_STIM,I_MEDI,I_ARM1,I_ARM2,I_AQUA,I_KEYR,I_KEYG,I_KEYB,I_SUIT,I_RTORCH,I_GTORCH,I_BTORCH,I_GOR1,I_FCAN
488 g_Items_EmitPickupSoundAt(i
, gPlayers
[j
].Obj
.X
, gPlayers
[j
].Obj
.Y
);
490 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòüñÿ ñ äðóãèì èãðîêîì
493 if not (Respawnable
and (ItemRespawnTime
> 0)) then
497 if g_Game_IsNet
then MH_SEND_ItemDestroy(False, i
);
505 if nxt
then continue
;
508 if Respawnable
and g_Game_IsServer
then
510 DecMin(RespawnTime
, 0);
511 if (RespawnTime
= 0) and (not alive
) then
513 if not QuietRespawn
then g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', InitX
, InitY
);
515 if g_Frames_Get(ID
, 'FRAMES_ITEM_RESPAWN') then
517 Anim
:= TAnimation
.Create(ID
, False, 4);
518 g_GFX_OnceAnim(InitX
+(Obj
.Rect
.Width
div 2)-16, InitY
+(Obj
.Rect
.Height
div 2)-16, Anim
);
530 positionChanged(); // this updates spatial accelerators
534 if g_Game_IsNet
then MH_SEND_ItemSpawn(QuietRespawn
, i
);
535 QuietRespawn
:= false;
539 if (Animation
<> nil) then Animation
.Update();
544 procedure g_Items_SetDrop (ID
: DWORD
);
546 if (ID
< Length(ggItems
)) then
548 ggItems
[ID
].dropped
:= true;
553 procedure g_Items_Pick (ID
: DWORD
);
555 if (ID
< Length(ggItems
)) then
557 ggItems
[ID
].Obj
.oldX
:= ggItems
[ID
].Obj
.X
;
558 ggItems
[ID
].Obj
.oldY
:= ggItems
[ID
].Obj
.Y
;
559 ggItems
[ID
].alive
:= false;
560 ggItems
[ID
].RespawnTime
:= IfThen(gLMSRespawn
= LMS_RESPAWN_NONE
, gGameSettings
.ItemRespawnTime
, 15) * 36;
565 procedure g_Items_Remove (ID
: DWORD
);
570 if not g_Items_ValidId(ID
) then
572 //writeln('g_Items_Remove: invalid item id: ', ID);
573 raise Exception
.Create('g_Items_Remove: invalid item id');
578 if (it
.arrIdx
<> Integer(ID
)) then raise Exception
.Create('g_Items_Remove: arrIdx desync');
580 it
.Obj
.oldX
:= it
.Obj
.X
;
581 it
.Obj
.oldY
:= it
.Obj
.Y
;
582 trig
:= it
.SpawnTrigger
;
586 if (trig
> -1) then g_Triggers_DecreaseSpawner(trig
);
590 procedure g_Items_SaveState (st
: TStream
);
595 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ ïðåäìåòîâ
597 for i
:= 0 to High(ggItems
) do if (ggItems
[i
].ItemType
<> ITEM_NONE
) and (ggItems
[i
].slotIsUsed
) then Inc(count
);
599 // Êîëè÷åñòâî ïðåäìåòîâ
600 utils
.writeInt(st
, LongInt(count
));
601 if (count
= 0) then exit
;
603 for i
:= 0 to High(ggItems
) do
605 if (ggItems
[i
].ItemType
<> ITEM_NONE
) and (ggItems
[i
].slotIsUsed
) then
607 // Ñèãíàòóðà ïðåäìåòà
608 utils
.writeSign(st
, 'ITEM');
609 utils
.writeInt(st
, Byte(0));
611 tt
:= ggItems
[i
].ItemType
;
612 if ggItems
[i
].dropped
then tt
:= tt
or $80;
613 utils
.writeInt(st
, Byte(tt
));
615 utils
.writeBool(st
, ggItems
[i
].Respawnable
);
616 // Êîîðäèíàòû ðåñïóíà
617 utils
.writeInt(st
, LongInt(ggItems
[i
].InitX
));
618 utils
.writeInt(st
, LongInt(ggItems
[i
].InitY
));
620 utils
.writeInt(st
, Word(ggItems
[i
].RespawnTime
));
621 // Ñóùåñòâóåò ëè ýòîò ïðåäìåò
622 utils
.writeBool(st
, ggItems
[i
].alive
);
623 // Ìîæåò ëè îí ïàäàòü
624 utils
.writeBool(st
, ggItems
[i
].Fall
);
625 // Èíäåêñ òðèããåðà, ñîçäàâøåãî ïðåäìåò
626 utils
.writeInt(st
, LongInt(ggItems
[i
].SpawnTrigger
));
628 Obj_SaveState(st
, @ggItems
[i
].Obj
);
634 procedure g_Items_LoadState (st
: TStream
);
636 count
, i
, a
: Integer;
643 // Êîëè÷åñòâî ïðåäìåòîâ
644 count
:= utils
.readLongInt(st
);
645 if (count
= 0) then exit
;
646 if (count
< 0) or (count
> 1024*1024) then raise XStreamError
.Create('invalid number of items');
648 for a
:= 0 to count
-1 do
650 // Ñèãíàòóðà ïðåäìåòà
651 if not utils
.checkSign(st
, 'ITEM') then raise XStreamError
.Create('invalid item signature');
652 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid item version');
654 b
:= utils
.readByte(st
); // bit7=1: monster drop
656 i
:= g_Items_Create(0, 0, b
and $7F, False, False);
657 if ((b
and $80) <> 0) then g_Items_SetDrop(i
);
659 ggItems
[i
].Respawnable
:= utils
.readBool(st
);
660 // Êîîðäèíàòû ðåñïóíà
661 ggItems
[i
].InitX
:= utils
.readLongInt(st
);
662 ggItems
[i
].InitY
:= utils
.readLongInt(st
);
664 ggItems
[i
].RespawnTime
:= utils
.readWord(st
);
665 // Ñóùåñòâóåò ëè ýòîò ïðåäìåò
666 ggItems
[i
].alive
:= utils
.readBool(st
);
667 // Ìîæåò ëè îí ïàäàòü
668 ggItems
[i
].Fall
:= utils
.readBool(st
);
669 // Èíäåêñ òðèããåðà, ñîçäàâøåãî ïðåäìåò
670 ggItems
[i
].SpawnTrigger
:= utils
.readLongInt(st
);
672 Obj_LoadState(@ggItems
[i
].Obj
, st
);
677 procedure g_Items_RestartRound ();
682 for i
:= 0 to High(ggItems
) do
685 it
.Obj
.oldX
:= it
.Obj
.X
;
686 it
.Obj
.oldY
:= it
.Obj
.Y
;
687 if not it
.slotIsUsed
then continue
;
688 if it
.Respawnable
and (it
.ItemType
<> ITEM_NONE
) then
690 it
.QuietRespawn
:= True;
696 if g_Game_IsNet
then MH_SEND_ItemDestroy(True, i
);
702 function g_Items_ForEachAlive (cb
: TItemEachAliveCB
; backwards
: Boolean=false): Boolean;
707 if (ggItems
= nil) or not assigned(cb
) then exit
;
711 for idx
:= High(ggItems
) downto 0 do
713 if ggItems
[idx
].alive
and ggItems
[idx
].slotIsUsed
then
715 result
:= cb(@ggItems
[idx
]);
722 for idx
:= 0 to High(ggItems
) do
724 if ggItems
[idx
].alive
and ggItems
[idx
].slotIsUsed
then
726 result
:= cb(@ggItems
[idx
]);
733 function g_Items_NextAlive (startIdx
: Integer): PItem
;
738 if (ggItems
= nil) or (startIdx
>= High(ggItems
)) then exit
;
739 for idx
:= startIdx
+ 1 to High(ggItems
) do
740 if ggItems
[idx
].alive
and ggItems
[idx
].slotIsUsed
then
742 result
:= @ggItems
[idx
];
747 // ////////////////////////////////////////////////////////////////////////// //
748 procedure g_Items_EmitPickupSound (idx
: Integer);
752 if not g_Items_ValidId(idx
) then exit
;
754 g_Items_EmitPickupSoundAt(idx
, it
.Obj
.X
, it
.Obj
.Y
);
757 procedure g_Items_EmitPickupSoundAt (idx
, x
, y
: Integer);
761 if not g_Items_ValidId(idx
) then exit
;
764 if gSoundEffectsDF
then
766 if it
.ItemType
in [ITEM_SPHERE_BLUE
, ITEM_SPHERE_WHITE
, ITEM_INVUL
,
767 ITEM_INVIS
, ITEM_MEDKIT_BLACK
, ITEM_JETPACK
] then
769 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', x
, y
);
771 else if it
.ItemType
in [ITEM_WEAPON_SAW
, ITEM_WEAPON_PISTOL
, ITEM_WEAPON_SHOTGUN1
, ITEM_WEAPON_SHOTGUN2
,
772 ITEM_WEAPON_CHAINGUN
, ITEM_WEAPON_ROCKETLAUNCHER
, ITEM_WEAPON_PLASMA
,
773 ITEM_WEAPON_BFG
, ITEM_WEAPON_SUPERPULEMET
, ITEM_WEAPON_FLAMETHROWER
,
774 ITEM_AMMO_BACKPACK
] then
776 g_Sound_PlayExAt('SOUND_ITEM_GETWEAPON', x
, y
);
780 g_Sound_PlayExAt('SOUND_ITEM_GETITEM', x
, y
);
785 if it
.ItemType
in [ITEM_SPHERE_BLUE
, ITEM_SPHERE_WHITE
, ITEM_SUIT
,
786 ITEM_MEDKIT_BLACK
, ITEM_INVUL
, ITEM_INVIS
, ITEM_JETPACK
] then
788 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', x
, y
);
790 else if it
.ItemType
in [ITEM_WEAPON_SAW
, ITEM_WEAPON_PISTOL
, ITEM_WEAPON_SHOTGUN1
, ITEM_WEAPON_SHOTGUN2
,
791 ITEM_WEAPON_CHAINGUN
, ITEM_WEAPON_ROCKETLAUNCHER
, ITEM_WEAPON_PLASMA
,
792 ITEM_WEAPON_BFG
, ITEM_WEAPON_SUPERPULEMET
, ITEM_WEAPON_FLAMETHROWER
] then
794 g_Sound_PlayExAt('SOUND_ITEM_GETWEAPON', x
, y
);
798 g_Sound_PlayExAt('SOUND_ITEM_GETITEM', x
, y
);
804 procedure g_Items_AddDynLights();
809 for f
:= 0 to High(ggItems
) do
812 if not it
.alive
then continue
;
814 ITEM_KEY_RED
: g_AddDynLight(it
.Obj
.X
+(it
.Obj
.Rect
.Width
div 2), it
.Obj
.Y
+(it
.Obj
.Rect
.Height
div 2), 24, 1.0, 0.0, 0.0, 0.6);
815 ITEM_KEY_GREEN
: g_AddDynLight(it
.Obj
.X
+(it
.Obj
.Rect
.Width
div 2), it
.Obj
.Y
+(it
.Obj
.Rect
.Height
div 2), 24, 0.0, 1.0, 0.0, 0.6);
816 ITEM_KEY_BLUE
: g_AddDynLight(it
.Obj
.X
+(it
.Obj
.Rect
.Width
div 2), it
.Obj
.Y
+(it
.Obj
.Rect
.Height
div 2), 24, 0.0, 0.0, 1.0, 0.6);
817 ITEM_ARMOR_GREEN
: g_AddDynLight(it
.Obj
.X
+(it
.Obj
.Rect
.Width
div 2), it
.Obj
.Y
+(it
.Obj
.Rect
.Height
div 2), 42, 0.0, 1.0, 0.0, 0.6);
818 ITEM_ARMOR_BLUE
: g_AddDynLight(it
.Obj
.X
+(it
.Obj
.Rect
.Width
div 2), it
.Obj
.Y
+(it
.Obj
.Rect
.Height
div 2), 42, 0.0, 0.0, 1.0, 0.6);
819 ITEM_JETPACK
: g_AddDynLight(it
.Obj
.X
+(it
.Obj
.Rect
.Width
div 2), it
.Obj
.Y
+(it
.Obj
.Rect
.Height
div 2), 32, 1.0, 1.0, 1.0, 0.6);
820 ITEM_SPHERE_BLUE
: g_AddDynLight(it
.Obj
.X
+(it
.Obj
.Rect
.Width
div 2), it
.Obj
.Y
+(it
.Obj
.Rect
.Height
div 2), 32, 0.0, 1.0, 0.0, 0.6);
821 ITEM_SPHERE_WHITE
: g_AddDynLight(it
.Obj
.X
+(it
.Obj
.Rect
.Width
div 2), it
.Obj
.Y
+(it
.Obj
.Rect
.Height
div 2), 32, 1.0, 1.0, 1.0, 0.6);
822 ITEM_INVUL
: g_AddDynLight(it
.Obj
.X
+(it
.Obj
.Rect
.Width
div 2), it
.Obj
.Y
+(it
.Obj
.Rect
.Height
div 2), 32, 1.0, 0.0, 0.0, 0.6);
823 ITEM_INVIS
: g_AddDynLight(it
.Obj
.X
+(it
.Obj
.Rect
.Width
div 2), it
.Obj
.Y
+(it
.Obj
.Rect
.Height
div 2), 32, 1.0, 1.0, 0.0, 0.6);
824 ITEM_BOTTLE
: g_AddDynLight(it
.Obj
.X
+(it
.Obj
.Rect
.Width
div 2), it
.Obj
.Y
+(it
.Obj
.Rect
.Height
div 2), 16, 0.0, 0.0, 0.8, 0.6);
825 ITEM_HELMET
: g_AddDynLight(it
.Obj
.X
+(it
.Obj
.Rect
.Width
div 2), it
.Obj
.Y
+(it
.Obj
.Rect
.Height
div 2), 16, 0.0, 0.8, 0.0, 0.6);