1 (* Copyright (C) DooM 2D:Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
22 g_textures
, g_phys
, g_saveload
, BinEditor
, MAPDEF
;
28 InitX
, InitY
: Integer;
32 QuietRespawn
: Boolean;
33 SpawnTrigger
: Integer;
35 Animation
: TAnimation
;
37 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
40 procedure g_Items_LoadData();
41 procedure g_Items_FreeData();
42 procedure g_Items_Init();
43 procedure g_Items_Free();
44 function g_Items_Create(X
, Y
: Integer; ItemType
: Byte;
45 Fall
, Respawnable
: Boolean; AdjCoord
: Boolean = False; ForcedID
: Integer = -1): DWORD
;
46 procedure g_Items_Update();
47 procedure g_Items_Draw();
48 procedure g_Items_Pick(ID
: DWORD
);
49 procedure g_Items_Remove(ID
: DWORD
);
50 procedure g_Items_SaveState(var Mem
: TBinMemoryWriter
);
51 procedure g_Items_LoadState(var Mem
: TBinMemoryReader
);
54 gItems
: Array of TItem
= nil;
55 gItemsTexturesID
: Array [1..ITEM_MAX
] of DWORD
;
56 gMaxDist
: Integer = 1;
57 ITEM_RESPAWNTIME
: Integer = 60 * 36;
62 g_basic
, e_graphics
, g_sound
, g_main
, g_gfx
, g_map
,
63 Math
, g_game
, g_triggers
, g_console
, SysUtils
, g_player
, g_net
, g_netmsg
,
67 ITEM_SIGNATURE
= $4D455449; // 'ITEM'
69 ITEMSIZE
: Array [ITEM_MEDKIT_SMALL
..ITEM_MAX
] of Array [0..1] of Byte =
70 (((14), (15)), // MEDKIT_SMALL
71 ((28), (19)), // MEDKIT_LARGE
72 ((28), (19)), // MEDKIT_BLACK
73 ((31), (16)), // ARMOR_GREEN
74 ((31), (16)), // ARMOR_BLUE
75 ((25), (25)), // SPHERE_BLUE
76 ((25), (25)), // SPHERE_WHITE
78 ((14), (27)), // OXYGEN
79 ((25), (25)), // INVUL
80 ((62), (24)), // WEAPON_SAW
81 ((63), (12)), // WEAPON_SHOTGUN1
82 ((54), (13)), // WEAPON_SHOTGUN2
83 ((54), (16)), // WEAPON_CHAINGUN
84 ((62), (16)), // WEAPON_ROCKETLAUNCHER
85 ((54), (16)), // WEAPON_PLASMA
86 ((61), (36)), // WEAPON_BFG
87 ((54), (16)), // WEAPON_SUPERPULEMET
88 (( 9), (11)), // AMMO_BULLETS
89 ((28), (16)), // AMMO_BULLETS_BOX
90 ((15), ( 7)), // AMMO_SHELLS
91 ((32), (12)), // AMMO_SHELLS_BOX
92 ((12), (27)), // AMMO_ROCKET
93 ((54), (21)), // AMMO_ROCKET_BOX
94 ((15), (12)), // AMMO_CELL
95 ((32), (21)), // AMMO_CELL_BIG
96 ((22), (29)), // AMMO_BACKPACK
97 ((16), (16)), // KEY_RED
98 ((16), (16)), // KEY_GREEN
99 ((16), (16)), // KEY_BLUE
100 (( 1), ( 1)), // WEAPON_KASTET
101 ((43), (16)), // WEAPON_PISTOL
102 ((14), (18)), // BOTTLE
103 ((16), (15)), // HELMET
104 ((32), (24)), // JETPACK
105 ((25), (25)), // INVIS
106 ((53), (20)), // WEAPON_FLAMETHROWER
107 ((13), (20))); // AMMO_FUELCAN
109 procedure InitTextures();
111 g_Texture_Get('ITEM_MEDKIT_SMALL', gItemsTexturesID
[ITEM_MEDKIT_SMALL
]);
112 g_Texture_Get('ITEM_MEDKIT_LARGE', gItemsTexturesID
[ITEM_MEDKIT_LARGE
]);
113 g_Texture_Get('ITEM_MEDKIT_BLACK', gItemsTexturesID
[ITEM_MEDKIT_BLACK
]);
114 g_Texture_Get('ITEM_SUIT', gItemsTexturesID
[ITEM_SUIT
]);
115 g_Texture_Get('ITEM_OXYGEN', gItemsTexturesID
[ITEM_OXYGEN
]);
116 g_Texture_Get('ITEM_WEAPON_SAW', gItemsTexturesID
[ITEM_WEAPON_SAW
]);
117 g_Texture_Get('ITEM_WEAPON_SHOTGUN1', gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
]);
118 g_Texture_Get('ITEM_WEAPON_SHOTGUN2', gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
]);
119 g_Texture_Get('ITEM_WEAPON_CHAINGUN', gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
]);
120 g_Texture_Get('ITEM_WEAPON_ROCKETLAUNCHER', gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
]);
121 g_Texture_Get('ITEM_WEAPON_PLASMA', gItemsTexturesID
[ITEM_WEAPON_PLASMA
]);
122 g_Texture_Get('ITEM_WEAPON_BFG', gItemsTexturesID
[ITEM_WEAPON_BFG
]);
123 g_Texture_Get('ITEM_WEAPON_SUPERPULEMET', gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
]);
124 g_Texture_Get('ITEM_WEAPON_FLAMETHROWER', gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
]);
125 g_Texture_Get('ITEM_AMMO_BULLETS', gItemsTexturesID
[ITEM_AMMO_BULLETS
]);
126 g_Texture_Get('ITEM_AMMO_BULLETS_BOX', gItemsTexturesID
[ITEM_AMMO_BULLETS_BOX
]);
127 g_Texture_Get('ITEM_AMMO_SHELLS', gItemsTexturesID
[ITEM_AMMO_SHELLS
]);
128 g_Texture_Get('ITEM_AMMO_SHELLS_BOX', gItemsTexturesID
[ITEM_AMMO_SHELLS_BOX
]);
129 g_Texture_Get('ITEM_AMMO_ROCKET', gItemsTexturesID
[ITEM_AMMO_ROCKET
]);
130 g_Texture_Get('ITEM_AMMO_ROCKET_BOX', gItemsTexturesID
[ITEM_AMMO_ROCKET_BOX
]);
131 g_Texture_Get('ITEM_AMMO_CELL', gItemsTexturesID
[ITEM_AMMO_CELL
]);
132 g_Texture_Get('ITEM_AMMO_CELL_BIG', gItemsTexturesID
[ITEM_AMMO_CELL_BIG
]);
133 g_Texture_Get('ITEM_AMMO_FUELCAN', gItemsTexturesID
[ITEM_AMMO_FUELCAN
]);
134 g_Texture_Get('ITEM_AMMO_BACKPACK', gItemsTexturesID
[ITEM_AMMO_BACKPACK
]);
135 g_Texture_Get('ITEM_KEY_RED', gItemsTexturesID
[ITEM_KEY_RED
]);
136 g_Texture_Get('ITEM_KEY_GREEN', gItemsTexturesID
[ITEM_KEY_GREEN
]);
137 g_Texture_Get('ITEM_KEY_BLUE', gItemsTexturesID
[ITEM_KEY_BLUE
]);
138 g_Texture_Get('ITEM_WEAPON_KASTET', gItemsTexturesID
[ITEM_WEAPON_KASTET
]);
139 g_Texture_Get('ITEM_WEAPON_PISTOL', gItemsTexturesID
[ITEM_WEAPON_PISTOL
]);
140 g_Texture_Get('ITEM_JETPACK', gItemsTexturesID
[ITEM_JETPACK
]);
143 procedure g_Items_LoadData();
145 e_WriteLog('Loading items data...', MSG_NOTIFY
);
147 g_Sound_CreateWADEx('SOUND_ITEM_RESPAWNITEM', GameWAD
+':SOUNDS\RESPAWNITEM');
148 g_Sound_CreateWADEx('SOUND_ITEM_GETRULEZ', GameWAD
+':SOUNDS\GETRULEZ');
149 g_Sound_CreateWADEx('SOUND_ITEM_GETWEAPON', GameWAD
+':SOUNDS\GETWEAPON');
150 g_Sound_CreateWADEx('SOUND_ITEM_GETITEM', GameWAD
+':SOUNDS\GETITEM');
152 g_Frames_CreateWAD(nil, 'FRAMES_ITEM_BLUESPHERE', GameWAD
+':TEXTURES\SBLUE', 32, 32, 4, True);
153 g_Frames_CreateWAD(nil, 'FRAMES_ITEM_WHITESPHERE', GameWAD
+':TEXTURES\SWHITE', 32, 32, 4, True);
154 g_Frames_CreateWAD(nil, 'FRAMES_ITEM_ARMORGREEN', GameWAD
+':TEXTURES\ARMORGREEN', 32, 16, 3, True);
155 g_Frames_CreateWAD(nil, 'FRAMES_ITEM_ARMORBLUE', GameWAD
+':TEXTURES\ARMORBLUE', 32, 16, 3, True);
156 g_Frames_CreateWAD(nil, 'FRAMES_ITEM_INVUL', GameWAD
+':TEXTURES\INVUL', 32, 32, 4, True);
157 g_Frames_CreateWAD(nil, 'FRAMES_ITEM_INVIS', GameWAD
+':TEXTURES\INVIS', 32, 32, 4, True);
158 g_Frames_CreateWAD(nil, 'FRAMES_ITEM_RESPAWN', GameWAD
+':TEXTURES\ITEMRESPAWN', 32, 32, 5, True);
159 g_Frames_CreateWAD(nil, 'FRAMES_ITEM_BOTTLE', GameWAD
+':TEXTURES\BOTTLE', 16, 32, 4, True);
160 g_Frames_CreateWAD(nil, 'FRAMES_ITEM_HELMET', GameWAD
+':TEXTURES\HELMET', 16, 16, 4, True);
161 g_Frames_CreateWAD(nil, 'FRAMES_FLAG_RED', GameWAD
+':TEXTURES\FLAGRED', 64, 64, 5, False);
162 g_Frames_CreateWAD(nil, 'FRAMES_FLAG_BLUE', GameWAD
+':TEXTURES\FLAGBLUE', 64, 64, 5, False);
163 g_Frames_CreateWAD(nil, 'FRAMES_FLAG_DOM', GameWAD
+':TEXTURES\FLAGDOM', 64, 64, 5, False);
164 g_Texture_CreateWADEx('ITEM_MEDKIT_SMALL', GameWAD
+':TEXTURES\MED1');
165 g_Texture_CreateWADEx('ITEM_MEDKIT_LARGE', GameWAD
+':TEXTURES\MED2');
166 g_Texture_CreateWADEx('ITEM_WEAPON_SAW', GameWAD
+':TEXTURES\SAW');
167 g_Texture_CreateWADEx('ITEM_WEAPON_PISTOL', GameWAD
+':TEXTURES\PISTOL');
168 g_Texture_CreateWADEx('ITEM_WEAPON_KASTET', GameWAD
+':TEXTURES\KASTET');
169 g_Texture_CreateWADEx('ITEM_WEAPON_SHOTGUN1', GameWAD
+':TEXTURES\SHOTGUN1');
170 g_Texture_CreateWADEx('ITEM_WEAPON_SHOTGUN2', GameWAD
+':TEXTURES\SHOTGUN2');
171 g_Texture_CreateWADEx('ITEM_WEAPON_CHAINGUN', GameWAD
+':TEXTURES\MGUN');
172 g_Texture_CreateWADEx('ITEM_WEAPON_ROCKETLAUNCHER', GameWAD
+':TEXTURES\RLAUNCHER');
173 g_Texture_CreateWADEx('ITEM_WEAPON_PLASMA', GameWAD
+':TEXTURES\PGUN');
174 g_Texture_CreateWADEx('ITEM_WEAPON_BFG', GameWAD
+':TEXTURES\BFG');
175 g_Texture_CreateWADEx('ITEM_WEAPON_SUPERPULEMET', GameWAD
+':TEXTURES\SPULEMET');
176 g_Texture_CreateWADEx('ITEM_WEAPON_FLAMETHROWER', GameWAD
+':TEXTURES\FLAMETHROWER');
177 g_Texture_CreateWADEx('ITEM_AMMO_BULLETS', GameWAD
+':TEXTURES\CLIP');
178 g_Texture_CreateWADEx('ITEM_AMMO_BULLETS_BOX', GameWAD
+':TEXTURES\AMMO');
179 g_Texture_CreateWADEx('ITEM_AMMO_SHELLS', GameWAD
+':TEXTURES\SHELL1');
180 g_Texture_CreateWADEx('ITEM_AMMO_SHELLS_BOX', GameWAD
+':TEXTURES\SHELL2');
181 g_Texture_CreateWADEx('ITEM_AMMO_ROCKET', GameWAD
+':TEXTURES\ROCKET');
182 g_Texture_CreateWADEx('ITEM_AMMO_ROCKET_BOX', GameWAD
+':TEXTURES\ROCKETS');
183 g_Texture_CreateWADEx('ITEM_AMMO_CELL', GameWAD
+':TEXTURES\CELL');
184 g_Texture_CreateWADEx('ITEM_AMMO_CELL_BIG', GameWAD
+':TEXTURES\CELL2');
185 g_Texture_CreateWADEx('ITEM_AMMO_FUELCAN', GameWAD
+':TEXTURES\FUELCAN');
186 g_Texture_CreateWADEx('ITEM_AMMO_BACKPACK', GameWAD
+':TEXTURES\BPACK');
187 g_Texture_CreateWADEx('ITEM_KEY_RED', GameWAD
+':TEXTURES\KEYR');
188 g_Texture_CreateWADEx('ITEM_KEY_GREEN', GameWAD
+':TEXTURES\KEYG');
189 g_Texture_CreateWADEx('ITEM_KEY_BLUE', GameWAD
+':TEXTURES\KEYB');
190 g_Texture_CreateWADEx('ITEM_OXYGEN', GameWAD
+':TEXTURES\OXYGEN');
191 g_Texture_CreateWADEx('ITEM_SUIT', GameWAD
+':TEXTURES\SUIT');
192 g_Texture_CreateWADEx('ITEM_WEAPON_KASTET', GameWAD
+':TEXTURES\KASTET');
193 g_Texture_CreateWADEx('ITEM_MEDKIT_BLACK', GameWAD
+':TEXTURES\BMED');
194 g_Texture_CreateWADEx('ITEM_JETPACK', GameWAD
+':TEXTURES\JETPACK');
199 procedure g_Items_FreeData();
201 e_WriteLog('Releasing items data...', MSG_NOTIFY
);
203 g_Sound_Delete('SOUND_ITEM_RESPAWNITEM');
204 g_Sound_Delete('SOUND_ITEM_GETRULEZ');
205 g_Sound_Delete('SOUND_ITEM_GETWEAPON');
206 g_Sound_Delete('SOUND_ITEM_GETITEM');
208 g_Frames_DeleteByName('FRAMES_ITEM_BLUESPHERE');
209 g_Frames_DeleteByName('FRAMES_ITEM_WHITESPHERE');
210 g_Frames_DeleteByName('FRAMES_ITEM_ARMORGREEN');
211 g_Frames_DeleteByName('FRAMES_ITEM_ARMORBLUE');
212 g_Frames_DeleteByName('FRAMES_ITEM_INVUL');
213 g_Frames_DeleteByName('FRAMES_ITEM_INVIS');
214 g_Frames_DeleteByName('FRAMES_ITEM_RESPAWN');
215 g_Frames_DeleteByName('FRAMES_ITEM_BOTTLE');
216 g_Frames_DeleteByName('FRAMES_ITEM_HELMET');
217 g_Frames_DeleteByName('FRAMES_FLAG_RED');
218 g_Frames_DeleteByName('FRAMES_FLAG_BLUE');
219 g_Frames_DeleteByName('FRAMES_FLAG_DOM');
220 g_Texture_Delete('ITEM_MEDKIT_SMALL');
221 g_Texture_Delete('ITEM_MEDKIT_LARGE');
222 g_Texture_Delete('ITEM_WEAPON_SAW');
223 g_Texture_Delete('ITEM_WEAPON_PISTOL');
224 g_Texture_Delete('ITEM_WEAPON_KASTET');
225 g_Texture_Delete('ITEM_WEAPON_SHOTGUN1');
226 g_Texture_Delete('ITEM_WEAPON_SHOTGUN2');
227 g_Texture_Delete('ITEM_WEAPON_CHAINGUN');
228 g_Texture_Delete('ITEM_WEAPON_ROCKETLAUNCHER');
229 g_Texture_Delete('ITEM_WEAPON_PLASMA');
230 g_Texture_Delete('ITEM_WEAPON_BFG');
231 g_Texture_Delete('ITEM_WEAPON_SUPERPULEMET');
232 g_Texture_Delete('ITEM_WEAPON_FLAMETHROWER');
233 g_Texture_Delete('ITEM_AMMO_BULLETS');
234 g_Texture_Delete('ITEM_AMMO_BULLETS_BOX');
235 g_Texture_Delete('ITEM_AMMO_SHELLS');
236 g_Texture_Delete('ITEM_AMMO_SHELLS_BOX');
237 g_Texture_Delete('ITEM_AMMO_ROCKET');
238 g_Texture_Delete('ITEM_AMMO_ROCKET_BOX');
239 g_Texture_Delete('ITEM_AMMO_CELL');
240 g_Texture_Delete('ITEM_AMMO_CELL_BIG');
241 g_Texture_Delete('ITEM_AMMO_FUELCAN');
242 g_Texture_Delete('ITEM_AMMO_BACKPACK');
243 g_Texture_Delete('ITEM_KEY_RED');
244 g_Texture_Delete('ITEM_KEY_GREEN');
245 g_Texture_Delete('ITEM_KEY_BLUE');
246 g_Texture_Delete('ITEM_OXYGEN');
247 g_Texture_Delete('ITEM_SUIT');
248 g_Texture_Delete('ITEM_WEAPON_KASTET');
249 g_Texture_Delete('ITEM_MEDKIT_BLACK');
250 g_Texture_Delete('ITEM_JETPACK');
253 function FindItem(): DWORD
;
257 if gItems
<> nil then
258 for i
:= 0 to High(gItems
) do
259 if gItems
[i
].ItemType
= ITEM_NONE
then
267 SetLength(gItems
, 32);
272 Result
:= High(gItems
) + 1;
273 SetLength(gItems
, Length(gItems
) + 32);
277 procedure g_Items_Init();
281 if gMapInfo
.Height
> gPlayerScreenSize
.Y
then
282 a
:= gMapInfo
.Height
- gPlayerScreenSize
.Y
284 a
:= gMapInfo
.Height
;
286 if gMapInfo
.Width
> gPlayerScreenSize
.X
then
287 b
:= gMapInfo
.Width
- gPlayerScreenSize
.X
291 gMaxDist
:= Trunc(Hypot(a
, b
));
294 procedure g_Items_Free();
298 if gItems
<> nil then
300 for i
:= 0 to High(gItems
) do
301 gItems
[i
].Animation
.Free();
306 function g_Items_Create(X
, Y
: Integer; ItemType
: Byte;
307 Fall
, Respawnable
: Boolean; AdjCoord
: Boolean = False; ForcedID
: Integer = -1): DWORD
;
313 find_id
:= FindItem()
317 if Integer(find_id
) > High(gItems
) then
318 SetLength(gItems
, find_id
+ 32);
321 gItems
[find_id
].ItemType
:= ItemType
;
322 gItems
[find_id
].Respawnable
:= Respawnable
;
323 if g_Game_IsServer
and (ITEM_RESPAWNTIME
= 0) then
324 gItems
[find_id
].Respawnable
:= False;
325 gItems
[find_id
].InitX
:= X
;
326 gItems
[find_id
].InitY
:= Y
;
327 gItems
[find_id
].RespawnTime
:= 0;
328 gItems
[find_id
].Fall
:= Fall
;
329 gItems
[find_id
].Live
:= True;
330 gItems
[find_id
].QuietRespawn
:= False;
332 g_Obj_Init(@gItems
[find_id
].Obj
);
333 gItems
[find_id
].Obj
.X
:= X
;
334 gItems
[find_id
].Obj
.Y
:= Y
;
335 gItems
[find_id
].Obj
.Rect
.Width
:= ITEMSIZE
[ItemType
][0];
336 gItems
[find_id
].Obj
.Rect
.Height
:= ITEMSIZE
[ItemType
][1];
338 gItems
[find_id
].Animation
:= nil;
339 gItems
[find_id
].SpawnTrigger
:= -1;
341 // Êîîðäèíàòû îòíîñèòåëüíî öåíòðà íèæíåãî ðåáðà:
343 with gItems
[find_id
] do
345 Obj
.X
:= X
- (Obj
.Rect
.Width
div 2);
346 Obj
.Y
:= Y
- Obj
.Rect
.Height
;
351 // Óñòàíîâêà àíèìàöèè:
352 with gItems
[find_id
] do
356 if g_Frames_Get(ID
, 'FRAMES_ITEM_ARMORGREEN') then
357 Animation
:= TAnimation
.Create(ID
, True, 20);
359 if g_Frames_Get(ID
, 'FRAMES_ITEM_ARMORBLUE') then
360 Animation
:= TAnimation
.Create(ID
, True, 20);
362 if g_Frames_Get(ID
, 'FRAMES_ITEM_BLUESPHERE') then
363 Animation
:= TAnimation
.Create(ID
, True, 15);
365 if g_Frames_Get(ID
, 'FRAMES_ITEM_WHITESPHERE') then
366 Animation
:= TAnimation
.Create(ID
, True, 20);
368 if g_Frames_Get(ID
, 'FRAMES_ITEM_INVUL') then
369 Animation
:= TAnimation
.Create(ID
, True, 20);
371 if g_Frames_Get(ID
, 'FRAMES_ITEM_INVIS') then
372 Animation
:= TAnimation
.Create(ID
, True, 20);
374 if g_Frames_Get(ID
, 'FRAMES_ITEM_BOTTLE') then
375 Animation
:= TAnimation
.Create(ID
, True, 20);
377 if g_Frames_Get(ID
, 'FRAMES_ITEM_HELMET') then
378 Animation
:= TAnimation
.Create(ID
, True, 20);
385 procedure g_Items_Update();
393 if gItems
<> nil then
394 for i
:= 0 to High(gItems
) do
395 if gItems
[i
].ItemType
<> ITEM_NONE
then
404 m
:= g_Obj_Move(@Obj
, True, True);
405 positionChanged(); // this updates spatial accelerators
407 // Ñîïðîòèâëåíèå âîçäóõà:
408 if gTime
mod (GAME_TICK
*2) = 0 then
409 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
410 // Åñëè âûïàë çà êàðòó:
411 if WordBool(m
and MOVE_FALLOUT
) then
413 if SpawnTrigger
= -1 then
417 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_ItemDestroy(True, i
);
423 // Åñëè èãðîêè ïîáëèçîñòè:
424 if gPlayers
<> nil then
426 j
:= Random(Length(gPlayers
)) - 1;
428 for k
:= 0 to High(gPlayers
) do
431 if j
> High(gPlayers
) then
434 if (gPlayers
[j
] <> nil) and gPlayers
[j
].Live
and
435 g_Obj_Collide(@gPlayers
[j
].Obj
, @Obj
) then
437 if g_Game_IsClient
then Continue
;
439 if not gPlayers
[j
].PickItem(ItemType
, Respawnable
, r
) then
442 if g_Game_IsNet
then MH_SEND_PlayerStats(gPlayers
[j
].UID
);
446 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
447 +2. I_MEGA,I_INVL,I_SUPER
448 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
451 if gSoundEffectsDF
then
453 if ItemType
in [ITEM_SPHERE_BLUE
, ITEM_SPHERE_WHITE
, ITEM_INVUL
,
454 ITEM_INVIS
, ITEM_MEDKIT_BLACK
, ITEM_JETPACK
] then
455 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ',
456 gPlayers
[j
].Obj
.X
, gPlayers
[j
].Obj
.Y
)
458 if ItemType
in [ITEM_WEAPON_SAW
, ITEM_WEAPON_PISTOL
, ITEM_WEAPON_SHOTGUN1
, ITEM_WEAPON_SHOTGUN2
,
459 ITEM_WEAPON_CHAINGUN
, ITEM_WEAPON_ROCKETLAUNCHER
, ITEM_WEAPON_PLASMA
,
460 ITEM_WEAPON_BFG
, ITEM_WEAPON_SUPERPULEMET
, ITEM_WEAPON_FLAMETHROWER
,
461 ITEM_AMMO_BACKPACK
] then
462 g_Sound_PlayExAt('SOUND_ITEM_GETWEAPON',
463 gPlayers
[j
].Obj
.X
, gPlayers
[j
].Obj
.Y
)
465 g_Sound_PlayExAt('SOUND_ITEM_GETITEM',
466 gPlayers
[j
].Obj
.X
, gPlayers
[j
].Obj
.Y
);
470 if ItemType
in [ITEM_SPHERE_BLUE
, ITEM_SPHERE_WHITE
, ITEM_SUIT
,
471 ITEM_MEDKIT_BLACK
, ITEM_INVUL
, ITEM_INVIS
, ITEM_JETPACK
] then
472 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ',
473 gPlayers
[j
].Obj
.X
, gPlayers
[j
].Obj
.Y
)
475 if ItemType
in [ITEM_WEAPON_SAW
, ITEM_WEAPON_PISTOL
, ITEM_WEAPON_SHOTGUN1
, ITEM_WEAPON_SHOTGUN2
,
476 ITEM_WEAPON_CHAINGUN
, ITEM_WEAPON_ROCKETLAUNCHER
, ITEM_WEAPON_PLASMA
,
477 ITEM_WEAPON_BFG
, ITEM_WEAPON_SUPERPULEMET
, ITEM_WEAPON_FLAMETHROWER
] then
478 g_Sound_PlayExAt('SOUND_ITEM_GETWEAPON',
479 gPlayers
[j
].Obj
.X
, gPlayers
[j
].Obj
.Y
)
481 g_Sound_PlayExAt('SOUND_ITEM_GETITEM',
482 gPlayers
[j
].Obj
.X
, gPlayers
[j
].Obj
.Y
);
485 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòüñÿ ñ äðóãèì èãðîêîì:
488 if not Respawnable
then
493 if g_Game_IsNet
then MH_SEND_ItemDestroy(False, i
);
505 if Respawnable
and g_Game_IsServer
then
507 DecMin(RespawnTime
, 0);
508 if (RespawnTime
= 0) and (not Live
) then
510 if not QuietRespawn
then
511 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', InitX
, InitY
);
513 if g_Frames_Get(ID
, 'FRAMES_ITEM_RESPAWN') then
515 Anim
:= TAnimation
.Create(ID
, False, 4);
516 g_GFX_OnceAnim(InitX
+(Obj
.Rect
.Width
div 2)-16, InitY
+(Obj
.Rect
.Height
div 2)-16, Anim
);
526 positionChanged(); // this updates spatial accelerators
530 if g_Game_IsNet
then MH_SEND_ItemSpawn(QuietRespawn
, i
);
531 QuietRespawn
:= False;
535 if Animation
<> nil then
540 procedure g_Items_Draw();
544 if gItems
<> nil then
545 for i
:= 0 to High(gItems
) do
546 if gItems
[i
].Live
then
548 if g_Collide(Obj
.X
, Obj
.Y
, Obj
.Rect
.Width
, Obj
.Rect
.Height
,
549 sX
, sY
, sWidth
, sHeight
) then
551 if Animation
= nil then
552 e_Draw(gItemsTexturesID
[ItemType
], Obj
.X
, Obj
.Y
, 0, True, False)
554 Animation
.Draw(Obj
.X
, Obj
.Y
, M_NONE
);
556 if g_debug_Frames
then
558 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
560 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
561 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
567 procedure g_Items_Pick(ID
: DWORD
);
569 gItems
[ID
].Live
:= False;
570 gItems
[ID
].RespawnTime
:= ITEM_RESPAWNTIME
;
573 procedure g_Items_Remove(ID
: DWORD
);
575 gItems
[ID
].ItemType
:= ITEM_NONE
;
577 if gItems
[ID
].Animation
<> nil then
579 gItems
[ID
].Animation
.Free();
580 gItems
[ID
].Animation
:= nil;
583 gItems
[ID
].Live
:= False;
585 if gItems
[ID
].SpawnTrigger
> -1 then
587 g_Triggers_DecreaseSpawner(gItems
[ID
].SpawnTrigger
);
588 gItems
[ID
].SpawnTrigger
:= -1;
592 procedure g_Items_SaveState(var Mem
: TBinMemoryWriter
);
597 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ ïðåäìåòîâ:
599 if gItems
<> nil then
600 for i
:= 0 to High(gItems
) do
601 if gItems
[i
].ItemType
<> ITEM_NONE
then
604 Mem
:= TBinMemoryWriter
.Create((count
+1) * 60);
606 // Êîëè÷åñòâî ïðåäìåòîâ:
612 for i
:= 0 to High(gItems
) do
613 if gItems
[i
].ItemType
<> ITEM_NONE
then
615 // Ñèãíàòóðà ïðåäìåòà:
616 sig
:= ITEM_SIGNATURE
; // 'ITEM'
619 Mem
.WriteByte(gItems
[i
].ItemType
);
621 Mem
.WriteBoolean(gItems
[i
].Respawnable
);
622 // Êîîðäèíàòû ðåñïóíà:
623 Mem
.WriteInt(gItems
[i
].InitX
);
624 Mem
.WriteInt(gItems
[i
].InitY
);
625 // Âðåìÿ äî ðåñïàóíà:
626 Mem
.WriteWord(gItems
[i
].RespawnTime
);
627 // Ñóùåñòâóåò ëè ýòîò ïðåäìåò:
628 Mem
.WriteBoolean(gItems
[i
].Live
);
629 // Ìîæåò ëè îí ïàäàòü:
630 Mem
.WriteBoolean(gItems
[i
].Fall
);
631 // Èíäåêñ òðèããåðà, ñîçäàâøåãî ïðåäìåò:
632 Mem
.WriteInt(gItems
[i
].SpawnTrigger
);
634 Obj_SaveState(@gItems
[i
].Obj
, Mem
);
638 procedure g_Items_LoadState(var Mem
: TBinMemoryReader
);
640 count
, i
, a
: Integer;
649 // Êîëè÷åñòâî ïðåäìåòîâ:
655 for a
:= 0 to count
-1 do
657 // Ñèãíàòóðà ïðåäìåòà:
659 if sig
<> ITEM_SIGNATURE
then // 'ITEM'
661 raise EBinSizeError
.Create('g_Items_LoadState: Wrong Item Signature');
666 i
:= g_Items_Create(0, 0, b
, False, False);
668 Mem
.ReadBoolean(gItems
[i
].Respawnable
);
669 // Êîîðäèíàòû ðåñïóíà:
670 Mem
.ReadInt(gItems
[i
].InitX
);
671 Mem
.ReadInt(gItems
[i
].InitY
);
672 // Âðåìÿ äî ðåñïàóíà:
673 Mem
.ReadWord(gItems
[i
].RespawnTime
);
674 // Ñóùåñòâóåò ëè ýòîò ïðåäìåò:
675 Mem
.ReadBoolean(gItems
[i
].Live
);
676 // Ìîæåò ëè îí ïàäàòü:
677 Mem
.ReadBoolean(gItems
[i
].Fall
);
678 // Èíäåêñ òðèããåðà, ñîçäàâøåãî ïðåäìåò:
679 Mem
.ReadInt(gItems
[i
].SpawnTrigger
);
681 Obj_LoadState(@gItems
[i
].Obj
, Mem
);
686 procedure TItem
.positionChanged ();