X-Git-Url: http://deadsoftware.ru/gitweb?p=d2df-sdl.git;a=blobdiff_plain;f=src%2Fgame%2Fg_items.pas;h=6bb50708008e2509e4e34b148d4c3c46c272ecb2;hp=dffeb96096c08d34d753150f155a2f86cfb2e057;hb=abda6900c041e39944de6a49aa088a60c170715e;hpb=b7ff38d281991866c467f65974df53b305711281 diff --git a/src/game/g_items.pas b/src/game/g_items.pas index dffeb96..6bb5070 100644 --- a/src/game/g_items.pas +++ b/src/game/g_items.pas @@ -1,9 +1,8 @@ -(* Copyright (C) DooM 2D:Forever Developers +(* Copyright (C) Doom 2D: Forever Developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * the Free Software Foundation, version 3 of the License ONLY. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -19,7 +18,8 @@ unit g_items; interface uses - g_textures, g_phys, g_saveload, BinEditor, MAPDEF; + SysUtils, Classes, + MAPDEF, g_textures, g_phys, g_saveload; Type PItem = ^TItem; @@ -30,19 +30,21 @@ Type arrIdx: Integer; // in ggItems public - ItemType: Byte; - Respawnable: Boolean; - InitX, InitY: Integer; - RespawnTime: Word; - Live: Boolean; - Fall: Boolean; - QuietRespawn: Boolean; - SpawnTrigger: Integer; - Obj: TObj; - Animation: TAnimation; + ItemType: Byte; + Respawnable: Boolean; + InitX, InitY: Integer; + RespawnTime: Word; + alive: Boolean; + Fall: Boolean; + QuietRespawn: Boolean; + SpawnTrigger: Integer; + Obj: TObj; + Animation: TAnimationState; + dropped: Boolean; // dropped from the monster? drops should be rendered after corpses, so zombie corpse will not obscure ammo container, for example procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right! + property used: Boolean read slotIsUsed; property myid: Integer read arrIdx; end; @@ -52,12 +54,13 @@ procedure g_Items_Init(); procedure g_Items_Free(); function g_Items_Create(X, Y: Integer; ItemType: Byte; Fall, Respawnable: Boolean; AdjCoord: Boolean = False; ForcedID: Integer = -1): DWORD; +procedure g_Items_SetDrop (ID: DWORD); +procedure g_Items_PreUpdate(); procedure g_Items_Update(); -procedure g_Items_Draw(); procedure g_Items_Pick(ID: DWORD); procedure g_Items_Remove(ID: DWORD); -procedure g_Items_SaveState(var Mem: TBinMemoryWriter); -procedure g_Items_LoadState(var Mem: TBinMemoryReader); +procedure g_Items_SaveState (st: TStream); +procedure g_Items_LoadState (st: TStream); procedure g_Items_RestartRound (); @@ -78,22 +81,19 @@ function g_Items_ForEachAlive (cb: TItemEachAliveCB; backwards: Boolean=false): var - gItemsTexturesID: Array [1..ITEM_MAX] of DWORD; gMaxDist: Integer = 1; // for sounds - ITEM_RESPAWNTIME: Integer = 60 * 36; + + var (* private state *) + ggItems: Array of TItem = nil; implementation uses - g_basic, e_graphics, g_sound, g_main, g_gfx, g_map, - Math, g_game, g_triggers, g_console, SysUtils, g_player, g_net, g_netmsg, - e_log, - g_grid, binheap, idpool; - - -var - ggItems: Array of TItem = nil; - + Math, + g_basic, g_sound, g_gfx, g_map, r_gfx, + g_game, g_triggers, g_console, g_player, g_net, g_netmsg, + e_log, g_options, + g_grid, binheap, idpool, utils, xstreams; // ////////////////////////////////////////////////////////////////////////// // var @@ -176,152 +176,28 @@ const ((53), (20)), // WEAPON_FLAMETHROWER ((13), (20))); // AMMO_FUELCAN -procedure InitTextures(); -begin - g_Texture_Get('ITEM_MEDKIT_SMALL', gItemsTexturesID[ITEM_MEDKIT_SMALL]); - g_Texture_Get('ITEM_MEDKIT_LARGE', gItemsTexturesID[ITEM_MEDKIT_LARGE]); - g_Texture_Get('ITEM_MEDKIT_BLACK', gItemsTexturesID[ITEM_MEDKIT_BLACK]); - g_Texture_Get('ITEM_SUIT', gItemsTexturesID[ITEM_SUIT]); - g_Texture_Get('ITEM_OXYGEN', gItemsTexturesID[ITEM_OXYGEN]); - g_Texture_Get('ITEM_WEAPON_SAW', gItemsTexturesID[ITEM_WEAPON_SAW]); - g_Texture_Get('ITEM_WEAPON_SHOTGUN1', gItemsTexturesID[ITEM_WEAPON_SHOTGUN1]); - g_Texture_Get('ITEM_WEAPON_SHOTGUN2', gItemsTexturesID[ITEM_WEAPON_SHOTGUN2]); - g_Texture_Get('ITEM_WEAPON_CHAINGUN', gItemsTexturesID[ITEM_WEAPON_CHAINGUN]); - g_Texture_Get('ITEM_WEAPON_ROCKETLAUNCHER', gItemsTexturesID[ITEM_WEAPON_ROCKETLAUNCHER]); - g_Texture_Get('ITEM_WEAPON_PLASMA', gItemsTexturesID[ITEM_WEAPON_PLASMA]); - g_Texture_Get('ITEM_WEAPON_BFG', gItemsTexturesID[ITEM_WEAPON_BFG]); - g_Texture_Get('ITEM_WEAPON_SUPERPULEMET', gItemsTexturesID[ITEM_WEAPON_SUPERPULEMET]); - g_Texture_Get('ITEM_WEAPON_FLAMETHROWER', gItemsTexturesID[ITEM_WEAPON_FLAMETHROWER]); - g_Texture_Get('ITEM_AMMO_BULLETS', gItemsTexturesID[ITEM_AMMO_BULLETS]); - g_Texture_Get('ITEM_AMMO_BULLETS_BOX', gItemsTexturesID[ITEM_AMMO_BULLETS_BOX]); - g_Texture_Get('ITEM_AMMO_SHELLS', gItemsTexturesID[ITEM_AMMO_SHELLS]); - g_Texture_Get('ITEM_AMMO_SHELLS_BOX', gItemsTexturesID[ITEM_AMMO_SHELLS_BOX]); - g_Texture_Get('ITEM_AMMO_ROCKET', gItemsTexturesID[ITEM_AMMO_ROCKET]); - g_Texture_Get('ITEM_AMMO_ROCKET_BOX', gItemsTexturesID[ITEM_AMMO_ROCKET_BOX]); - g_Texture_Get('ITEM_AMMO_CELL', gItemsTexturesID[ITEM_AMMO_CELL]); - g_Texture_Get('ITEM_AMMO_CELL_BIG', gItemsTexturesID[ITEM_AMMO_CELL_BIG]); - g_Texture_Get('ITEM_AMMO_FUELCAN', gItemsTexturesID[ITEM_AMMO_FUELCAN]); - g_Texture_Get('ITEM_AMMO_BACKPACK', gItemsTexturesID[ITEM_AMMO_BACKPACK]); - g_Texture_Get('ITEM_KEY_RED', gItemsTexturesID[ITEM_KEY_RED]); - g_Texture_Get('ITEM_KEY_GREEN', gItemsTexturesID[ITEM_KEY_GREEN]); - g_Texture_Get('ITEM_KEY_BLUE', gItemsTexturesID[ITEM_KEY_BLUE]); - g_Texture_Get('ITEM_WEAPON_KASTET', gItemsTexturesID[ITEM_WEAPON_KASTET]); - g_Texture_Get('ITEM_WEAPON_PISTOL', gItemsTexturesID[ITEM_WEAPON_PISTOL]); - g_Texture_Get('ITEM_JETPACK', gItemsTexturesID[ITEM_JETPACK]); -end; - procedure g_Items_LoadData(); begin - e_WriteLog('Loading items data...', MSG_NOTIFY); + e_WriteLog('Loading items data...', TMsgType.Notify); g_Sound_CreateWADEx('SOUND_ITEM_RESPAWNITEM', GameWAD+':SOUNDS\RESPAWNITEM'); g_Sound_CreateWADEx('SOUND_ITEM_GETRULEZ', GameWAD+':SOUNDS\GETRULEZ'); g_Sound_CreateWADEx('SOUND_ITEM_GETWEAPON', GameWAD+':SOUNDS\GETWEAPON'); g_Sound_CreateWADEx('SOUND_ITEM_GETITEM', GameWAD+':SOUNDS\GETITEM'); - g_Frames_CreateWAD(nil, 'FRAMES_ITEM_BLUESPHERE', GameWAD+':TEXTURES\SBLUE', 32, 32, 4, True); - g_Frames_CreateWAD(nil, 'FRAMES_ITEM_WHITESPHERE', GameWAD+':TEXTURES\SWHITE', 32, 32, 4, True); - g_Frames_CreateWAD(nil, 'FRAMES_ITEM_ARMORGREEN', GameWAD+':TEXTURES\ARMORGREEN', 32, 16, 3, True); - g_Frames_CreateWAD(nil, 'FRAMES_ITEM_ARMORBLUE', GameWAD+':TEXTURES\ARMORBLUE', 32, 16, 3, True); - g_Frames_CreateWAD(nil, 'FRAMES_ITEM_INVUL', GameWAD+':TEXTURES\INVUL', 32, 32, 4, True); - g_Frames_CreateWAD(nil, 'FRAMES_ITEM_INVIS', GameWAD+':TEXTURES\INVIS', 32, 32, 4, True); - g_Frames_CreateWAD(nil, 'FRAMES_ITEM_RESPAWN', GameWAD+':TEXTURES\ITEMRESPAWN', 32, 32, 5, True); - g_Frames_CreateWAD(nil, 'FRAMES_ITEM_BOTTLE', GameWAD+':TEXTURES\BOTTLE', 16, 32, 4, True); - g_Frames_CreateWAD(nil, 'FRAMES_ITEM_HELMET', GameWAD+':TEXTURES\HELMET', 16, 16, 4, True); - g_Frames_CreateWAD(nil, 'FRAMES_FLAG_RED', GameWAD+':TEXTURES\FLAGRED', 64, 64, 5, False); - g_Frames_CreateWAD(nil, 'FRAMES_FLAG_BLUE', GameWAD+':TEXTURES\FLAGBLUE', 64, 64, 5, False); - g_Frames_CreateWAD(nil, 'FRAMES_FLAG_DOM', GameWAD+':TEXTURES\FLAGDOM', 64, 64, 5, False); - g_Texture_CreateWADEx('ITEM_MEDKIT_SMALL', GameWAD+':TEXTURES\MED1'); - g_Texture_CreateWADEx('ITEM_MEDKIT_LARGE', GameWAD+':TEXTURES\MED2'); - g_Texture_CreateWADEx('ITEM_WEAPON_SAW', GameWAD+':TEXTURES\SAW'); - g_Texture_CreateWADEx('ITEM_WEAPON_PISTOL', GameWAD+':TEXTURES\PISTOL'); - g_Texture_CreateWADEx('ITEM_WEAPON_KASTET', GameWAD+':TEXTURES\KASTET'); - g_Texture_CreateWADEx('ITEM_WEAPON_SHOTGUN1', GameWAD+':TEXTURES\SHOTGUN1'); - g_Texture_CreateWADEx('ITEM_WEAPON_SHOTGUN2', GameWAD+':TEXTURES\SHOTGUN2'); - g_Texture_CreateWADEx('ITEM_WEAPON_CHAINGUN', GameWAD+':TEXTURES\MGUN'); - g_Texture_CreateWADEx('ITEM_WEAPON_ROCKETLAUNCHER', GameWAD+':TEXTURES\RLAUNCHER'); - g_Texture_CreateWADEx('ITEM_WEAPON_PLASMA', GameWAD+':TEXTURES\PGUN'); - g_Texture_CreateWADEx('ITEM_WEAPON_BFG', GameWAD+':TEXTURES\BFG'); - g_Texture_CreateWADEx('ITEM_WEAPON_SUPERPULEMET', GameWAD+':TEXTURES\SPULEMET'); - g_Texture_CreateWADEx('ITEM_WEAPON_FLAMETHROWER', GameWAD+':TEXTURES\FLAMETHROWER'); - g_Texture_CreateWADEx('ITEM_AMMO_BULLETS', GameWAD+':TEXTURES\CLIP'); - g_Texture_CreateWADEx('ITEM_AMMO_BULLETS_BOX', GameWAD+':TEXTURES\AMMO'); - g_Texture_CreateWADEx('ITEM_AMMO_SHELLS', GameWAD+':TEXTURES\SHELL1'); - g_Texture_CreateWADEx('ITEM_AMMO_SHELLS_BOX', GameWAD+':TEXTURES\SHELL2'); - g_Texture_CreateWADEx('ITEM_AMMO_ROCKET', GameWAD+':TEXTURES\ROCKET'); - g_Texture_CreateWADEx('ITEM_AMMO_ROCKET_BOX', GameWAD+':TEXTURES\ROCKETS'); - g_Texture_CreateWADEx('ITEM_AMMO_CELL', GameWAD+':TEXTURES\CELL'); - g_Texture_CreateWADEx('ITEM_AMMO_CELL_BIG', GameWAD+':TEXTURES\CELL2'); - g_Texture_CreateWADEx('ITEM_AMMO_FUELCAN', GameWAD+':TEXTURES\FUELCAN'); - g_Texture_CreateWADEx('ITEM_AMMO_BACKPACK', GameWAD+':TEXTURES\BPACK'); - g_Texture_CreateWADEx('ITEM_KEY_RED', GameWAD+':TEXTURES\KEYR'); - g_Texture_CreateWADEx('ITEM_KEY_GREEN', GameWAD+':TEXTURES\KEYG'); - g_Texture_CreateWADEx('ITEM_KEY_BLUE', GameWAD+':TEXTURES\KEYB'); - g_Texture_CreateWADEx('ITEM_OXYGEN', GameWAD+':TEXTURES\OXYGEN'); - g_Texture_CreateWADEx('ITEM_SUIT', GameWAD+':TEXTURES\SUIT'); - g_Texture_CreateWADEx('ITEM_WEAPON_KASTET', GameWAD+':TEXTURES\KASTET'); - g_Texture_CreateWADEx('ITEM_MEDKIT_BLACK', GameWAD+':TEXTURES\BMED'); - g_Texture_CreateWADEx('ITEM_JETPACK', GameWAD+':TEXTURES\JETPACK'); - - InitTextures(); - freeIds := TIdPool.Create(); end; procedure g_Items_FreeData(); begin - e_WriteLog('Releasing items data...', MSG_NOTIFY); + e_WriteLog('Releasing items data...', TMsgType.Notify); g_Sound_Delete('SOUND_ITEM_RESPAWNITEM'); g_Sound_Delete('SOUND_ITEM_GETRULEZ'); g_Sound_Delete('SOUND_ITEM_GETWEAPON'); g_Sound_Delete('SOUND_ITEM_GETITEM'); - g_Frames_DeleteByName('FRAMES_ITEM_BLUESPHERE'); - g_Frames_DeleteByName('FRAMES_ITEM_WHITESPHERE'); - g_Frames_DeleteByName('FRAMES_ITEM_ARMORGREEN'); - g_Frames_DeleteByName('FRAMES_ITEM_ARMORBLUE'); - g_Frames_DeleteByName('FRAMES_ITEM_INVUL'); - g_Frames_DeleteByName('FRAMES_ITEM_INVIS'); - g_Frames_DeleteByName('FRAMES_ITEM_RESPAWN'); - g_Frames_DeleteByName('FRAMES_ITEM_BOTTLE'); - g_Frames_DeleteByName('FRAMES_ITEM_HELMET'); - g_Frames_DeleteByName('FRAMES_FLAG_RED'); - g_Frames_DeleteByName('FRAMES_FLAG_BLUE'); - g_Frames_DeleteByName('FRAMES_FLAG_DOM'); - g_Texture_Delete('ITEM_MEDKIT_SMALL'); - g_Texture_Delete('ITEM_MEDKIT_LARGE'); - g_Texture_Delete('ITEM_WEAPON_SAW'); - g_Texture_Delete('ITEM_WEAPON_PISTOL'); - g_Texture_Delete('ITEM_WEAPON_KASTET'); - g_Texture_Delete('ITEM_WEAPON_SHOTGUN1'); - g_Texture_Delete('ITEM_WEAPON_SHOTGUN2'); - g_Texture_Delete('ITEM_WEAPON_CHAINGUN'); - g_Texture_Delete('ITEM_WEAPON_ROCKETLAUNCHER'); - g_Texture_Delete('ITEM_WEAPON_PLASMA'); - g_Texture_Delete('ITEM_WEAPON_BFG'); - g_Texture_Delete('ITEM_WEAPON_SUPERPULEMET'); - g_Texture_Delete('ITEM_WEAPON_FLAMETHROWER'); - g_Texture_Delete('ITEM_AMMO_BULLETS'); - g_Texture_Delete('ITEM_AMMO_BULLETS_BOX'); - g_Texture_Delete('ITEM_AMMO_SHELLS'); - g_Texture_Delete('ITEM_AMMO_SHELLS_BOX'); - g_Texture_Delete('ITEM_AMMO_ROCKET'); - g_Texture_Delete('ITEM_AMMO_ROCKET_BOX'); - g_Texture_Delete('ITEM_AMMO_CELL'); - g_Texture_Delete('ITEM_AMMO_CELL_BIG'); - g_Texture_Delete('ITEM_AMMO_FUELCAN'); - g_Texture_Delete('ITEM_AMMO_BACKPACK'); - g_Texture_Delete('ITEM_KEY_RED'); - g_Texture_Delete('ITEM_KEY_GREEN'); - g_Texture_Delete('ITEM_KEY_BLUE'); - g_Texture_Delete('ITEM_OXYGEN'); - g_Texture_Delete('ITEM_SUIT'); - g_Texture_Delete('ITEM_WEAPON_KASTET'); - g_Texture_Delete('ITEM_MEDKIT_BLACK'); - g_Texture_Delete('ITEM_JETPACK'); - freeIds.Free(); freeIds := nil; end; @@ -342,7 +218,7 @@ begin it.Animation.Free(); it.Animation := nil; end; - it.Live := False; + it.alive := False; it.SpawnTrigger := -1; it.ItemType := ITEM_NONE; freeIds.release(LongWord(idx)); @@ -365,7 +241,7 @@ begin it.arrIdx := i; it.ItemType := ITEM_NONE; it.Animation := nil; - it.Live := false; + it.alive := false; it.SpawnTrigger := -1; it.Respawnable := false; //if not freeIds.hasFree[LongWord(i)] then raise Exception.Create('internal error in item idx manager'); @@ -436,7 +312,6 @@ function g_Items_Create (X, Y: Integer; ItemType: Byte; Fall, Respawnable: Boolean; AdjCoord: Boolean = False; ForcedID: Integer = -1): DWORD; var find_id: DWORD; - ID: DWORD; it: PItem; begin if ForcedID < 0 then find_id := allocItem() else find_id := wantItemSlot(ForcedID); @@ -451,13 +326,13 @@ begin it.ItemType := ItemType; it.Respawnable := Respawnable; - if g_Game_IsServer and (ITEM_RESPAWNTIME = 0) then it.Respawnable := False; it.InitX := X; it.InitY := Y; it.RespawnTime := 0; it.Fall := Fall; - it.Live := True; + it.alive := True; it.QuietRespawn := False; + it.dropped := false; g_Obj_Init(@it.Obj); it.Obj.X := X; @@ -480,16 +355,20 @@ begin end; end; + it.Obj.oldX := it.Obj.X; + it.Obj.oldY := it.Obj.Y; + // Óñòàíîâêà àíèìàöèè case it.ItemType of - ITEM_ARMOR_GREEN: if g_Frames_Get(ID, 'FRAMES_ITEM_ARMORGREEN') then it.Animation := TAnimation.Create(ID, True, 20); - ITEM_ARMOR_BLUE: if g_Frames_Get(ID, 'FRAMES_ITEM_ARMORBLUE') then it.Animation := TAnimation.Create(ID, True, 20); - ITEM_SPHERE_BLUE: if g_Frames_Get(ID, 'FRAMES_ITEM_BLUESPHERE') then it.Animation := TAnimation.Create(ID, True, 15); - ITEM_SPHERE_WHITE: if g_Frames_Get(ID, 'FRAMES_ITEM_WHITESPHERE') then it.Animation := TAnimation.Create(ID, True, 20); - ITEM_INVUL: if g_Frames_Get(ID, 'FRAMES_ITEM_INVUL') then it.Animation := TAnimation.Create(ID, True, 20); - ITEM_INVIS: if g_Frames_Get(ID, 'FRAMES_ITEM_INVIS') then it.Animation := TAnimation.Create(ID, True, 20); - ITEM_BOTTLE: if g_Frames_Get(ID, 'FRAMES_ITEM_BOTTLE') then it.Animation := TAnimation.Create(ID, True, 20); - ITEM_HELMET: if g_Frames_Get(ID, 'FRAMES_ITEM_HELMET') then it.Animation := TAnimation.Create(ID, True, 20); + ITEM_ARMOR_GREEN: it.Animation := TAnimationState.Create(True, 20, 3); + ITEM_ARMOR_BLUE: it.Animation := TAnimationState.Create(True, 20, 3); + ITEM_JETPACK: it.Animation := TAnimationState.Create(True, 15, 3); + ITEM_SPHERE_BLUE: it.Animation := TAnimationState.Create(True, 15, 4); + ITEM_SPHERE_WHITE: it.Animation := TAnimationState.Create(True, 20, 4); + ITEM_INVUL: it.Animation := TAnimationState.Create(True, 20, 4); + ITEM_INVIS: it.Animation := TAnimationState.Create(True, 20, 4); + ITEM_BOTTLE: it.Animation := TAnimationState.Create(True, 20, 4); + ITEM_HELMET: it.Animation := TAnimationState.Create(True, 20, 4); end; it.positionChanged(); @@ -497,26 +376,40 @@ begin result := find_id; end; +procedure g_Items_PreUpdate (); +var + i: Integer; +begin + if (ggItems = nil) then Exit; + for i := 0 to High(ggItems) do + if (ggItems[i].ItemType <> ITEM_NONE) and ggItems[i].slotIsUsed then + begin + ggItems[i].Obj.oldX := ggItems[i].Obj.X; + ggItems[i].Obj.oldY := ggItems[i].Obj.Y; + end; +end; procedure g_Items_Update (); var i, j, k: Integer; - ID: DWord; - Anim: TAnimation; - m: Word; + m, ItemRespawnTime: Word; r, nxt: Boolean; begin if (ggItems = nil) then exit; + // respawn items in 15 seconds regardless of settings during warmup + ItemRespawnTime := IfThen(gLMSRespawn = LMS_RESPAWN_NONE, gGameSettings.ItemRespawnTime, 15); + for i := 0 to High(ggItems) do begin if (ggItems[i].ItemType = ITEM_NONE) then continue; + if not ggItems[i].slotIsUsed then continue; // just in case with ggItems[i] do begin nxt := False; - if Live then + if alive then begin if Fall then begin @@ -552,7 +445,7 @@ begin Inc(j); if j > High(gPlayers) then j := 0; - if (gPlayers[j] <> nil) and gPlayers[j].Live and g_Obj_Collide(@gPlayers[j].Obj, @Obj) then + if (gPlayers[j] <> nil) and gPlayers[j].alive and g_Obj_Collide(@gPlayers[j].Obj, @Obj) then begin if g_Game_IsClient then continue; @@ -571,7 +464,10 @@ begin // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòüñÿ ñ äðóãèì èãðîêîì if r then begin - if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i); + if not (Respawnable and (ItemRespawnTime > 0)) then + g_Items_Remove(i) + else + g_Items_Pick(i); if g_Game_IsNet then MH_SEND_ItemDestroy(False, i); nxt := True; break; @@ -586,17 +482,12 @@ begin if Respawnable and g_Game_IsServer then begin DecMin(RespawnTime, 0); - if (RespawnTime = 0) and (not Live) then + if (RespawnTime = 0) and (not alive) then begin if not QuietRespawn then g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', InitX, InitY); - - if g_Frames_Get(ID, 'FRAMES_ITEM_RESPAWN') then - begin - Anim := TAnimation.Create(ID, False, 4); - g_GFX_OnceAnim(InitX+(Obj.Rect.Width div 2)-16, InitY+(Obj.Rect.Height div 2)-16, Anim); - Anim.Free(); - end; - + r_GFX_OnceAnim(R_GFX_ITEM_RESPAWN, InitX + (Obj.Rect.Width div 2) - 16, InitY + (Obj.Rect.Height div 2) - 16); + Obj.oldX := InitX; + Obj.oldY := InitY; Obj.X := InitX; Obj.Y := InitY; Obj.Vel.X := 0; @@ -605,7 +496,7 @@ begin Obj.Accel.Y := 0; positionChanged(); // this updates spatial accelerators - Live := true; + alive := true; if g_Game_IsNet then MH_SEND_ItemSpawn(QuietRespawn, i); QuietRespawn := false; @@ -617,48 +508,24 @@ begin end; end; - -procedure g_Items_Draw (); -var - i: Integer; +procedure g_Items_SetDrop (ID: DWORD); begin - if (ggItems = nil) then exit; - - for i := 0 to High(ggItems) do + if (ID < Length(ggItems)) then begin - if not ggItems[i].Live then continue; - - with ggItems[i] do - begin - if g_Collide(Obj.X, Obj.Y, Obj.Rect.Width, Obj.Rect.Height, sX, sY, sWidth, sHeight) then - begin - if (Animation = nil) then - begin - e_Draw(gItemsTexturesID[ItemType], Obj.X, Obj.Y, 0, true, false); - end - else - begin - Animation.Draw(Obj.X, Obj.Y, M_NONE); - end; - - if g_debug_Frames then - begin - e_DrawQuad(Obj.X+Obj.Rect.X, - Obj.Y+Obj.Rect.Y, - Obj.X+Obj.Rect.X+Obj.Rect.Width-1, - Obj.Y+Obj.Rect.Y+Obj.Rect.Height-1, - 0, 255, 0); - end; - end; - end; + ggItems[ID].dropped := true; end; end; procedure g_Items_Pick (ID: DWORD); begin - ggItems[ID].Live := false; - ggItems[ID].RespawnTime := ITEM_RESPAWNTIME; + if (ID < Length(ggItems)) then + begin + ggItems[ID].Obj.oldX := ggItems[ID].Obj.X; + ggItems[ID].Obj.oldY := ggItems[ID].Obj.Y; + ggItems[ID].alive := false; + ggItems[ID].RespawnTime := IfThen(gLMSRespawn = LMS_RESPAWN_NONE, gGameSettings.ItemRespawnTime, 15) * 36; + end; end; @@ -667,11 +534,18 @@ var it: PItem; trig: Integer; begin - if not g_Items_ValidId(ID) then raise Exception.Create('g_Items_Remove: invalid item id'); + if not g_Items_ValidId(ID) then + begin + //writeln('g_Items_Remove: invalid item id: ', ID); + raise Exception.Create('g_Items_Remove: invalid item id'); + //exit; + end; it := @ggItems[ID]; if (it.arrIdx <> Integer(ID)) then raise Exception.Create('g_Items_Remove: arrIdx desync'); + it.Obj.oldX := it.Obj.X; + it.Obj.oldY := it.Obj.Y; trig := it.SpawnTrigger; releaseItem(ID); @@ -680,93 +554,89 @@ begin end; -procedure g_Items_SaveState (var Mem: TBinMemoryWriter); +procedure g_Items_SaveState (st: TStream); var count, i: Integer; - sig: DWORD; + tt: Byte; begin // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ ïðåäìåòîâ count := 0; - if (ggItems <> nil) then - begin - for i := 0 to High(ggItems) do if (ggItems[i].ItemType <> ITEM_NONE) then Inc(count); - end; - - Mem := TBinMemoryWriter.Create((count+1) * 60); + for i := 0 to High(ggItems) do if (ggItems[i].ItemType <> ITEM_NONE) and (ggItems[i].slotIsUsed) then Inc(count); // Êîëè÷åñòâî ïðåäìåòîâ - Mem.WriteInt(count); - + utils.writeInt(st, LongInt(count)); if (count = 0) then exit; for i := 0 to High(ggItems) do begin - if (ggItems[i].ItemType <> ITEM_NONE) then + if (ggItems[i].ItemType <> ITEM_NONE) and (ggItems[i].slotIsUsed) then begin // Ñèãíàòóðà ïðåäìåòà - sig := ITEM_SIGNATURE; // 'ITEM' - Mem.WriteDWORD(sig); + utils.writeSign(st, 'ITEM'); + utils.writeInt(st, Byte(0)); // Òèï ïðåäìåòà - Mem.WriteByte(ggItems[i].ItemType); + tt := ggItems[i].ItemType; + if ggItems[i].dropped then tt := tt or $80; + utils.writeInt(st, Byte(tt)); // Åñòü ëè ðåñïàóí - Mem.WriteBoolean(ggItems[i].Respawnable); + utils.writeBool(st, ggItems[i].Respawnable); // Êîîðäèíàòû ðåñïóíà - Mem.WriteInt(ggItems[i].InitX); - Mem.WriteInt(ggItems[i].InitY); + utils.writeInt(st, LongInt(ggItems[i].InitX)); + utils.writeInt(st, LongInt(ggItems[i].InitY)); // Âðåìÿ äî ðåñïàóíà - Mem.WriteWord(ggItems[i].RespawnTime); + utils.writeInt(st, Word(ggItems[i].RespawnTime)); // Ñóùåñòâóåò ëè ýòîò ïðåäìåò - Mem.WriteBoolean(ggItems[i].Live); + utils.writeBool(st, ggItems[i].alive); // Ìîæåò ëè îí ïàäàòü - Mem.WriteBoolean(ggItems[i].Fall); + utils.writeBool(st, ggItems[i].Fall); // Èíäåêñ òðèããåðà, ñîçäàâøåãî ïðåäìåò - Mem.WriteInt(ggItems[i].SpawnTrigger); + utils.writeInt(st, LongInt(ggItems[i].SpawnTrigger)); // Îáúåêò ïðåäìåòà - Obj_SaveState(@ggItems[i].Obj, Mem); + Obj_SaveState(st, @ggItems[i].Obj); end; end; end; -procedure g_Items_LoadState (var Mem: TBinMemoryReader); +procedure g_Items_LoadState (st: TStream); var count, i, a: Integer; - sig: DWORD; b: Byte; begin - if (Mem = nil) then exit; + assert(st <> nil); g_Items_Free(); // Êîëè÷åñòâî ïðåäìåòîâ - Mem.ReadInt(count); - - if (count = 0) then Exit; + count := utils.readLongInt(st); + if (count = 0) then exit; + if (count < 0) or (count > 1024*1024) then raise XStreamError.Create('invalid number of items'); for a := 0 to count-1 do begin // Ñèãíàòóðà ïðåäìåòà - Mem.ReadDWORD(sig); - if (sig <> ITEM_SIGNATURE) then raise EBinSizeError.Create('g_Items_LoadState: Wrong Item Signature'); // 'ITEM' + if not utils.checkSign(st, 'ITEM') then raise XStreamError.Create('invalid item signature'); + if (utils.readByte(st) <> 0) then raise XStreamError.Create('invalid item version'); // Òèï ïðåäìåòà - Mem.ReadByte(b); + b := utils.readByte(st); // bit7=1: monster drop // Ñîçäàåì ïðåäìåò - i := g_Items_Create(0, 0, b, False, False); + i := g_Items_Create(0, 0, b and $7F, False, False); + if ((b and $80) <> 0) then g_Items_SetDrop(i); // Åñòü ëè ðåñïàóí - Mem.ReadBoolean(ggItems[i].Respawnable); + ggItems[i].Respawnable := utils.readBool(st); // Êîîðäèíàòû ðåñïóíà - Mem.ReadInt(ggItems[i].InitX); - Mem.ReadInt(ggItems[i].InitY); + ggItems[i].InitX := utils.readLongInt(st); + ggItems[i].InitY := utils.readLongInt(st); // Âðåìÿ äî ðåñïàóíà - Mem.ReadWord(ggItems[i].RespawnTime); + ggItems[i].RespawnTime := utils.readWord(st); // Ñóùåñòâóåò ëè ýòîò ïðåäìåò - Mem.ReadBoolean(ggItems[i].Live); + ggItems[i].alive := utils.readBool(st); // Ìîæåò ëè îí ïàäàòü - Mem.ReadBoolean(ggItems[i].Fall); + ggItems[i].Fall := utils.readBool(st); // Èíäåêñ òðèããåðà, ñîçäàâøåãî ïðåäìåò - Mem.ReadInt(ggItems[i].SpawnTrigger); + ggItems[i].SpawnTrigger := utils.readLongInt(st); // Îáúåêò ïðåäìåòà - Obj_LoadState(@ggItems[i].Obj, Mem); + Obj_LoadState(@ggItems[i].Obj, st); end; end; @@ -779,7 +649,10 @@ begin for i := 0 to High(ggItems) do begin it := @ggItems[i]; - if it.Respawnable then + it.Obj.oldX := it.Obj.X; + it.Obj.oldY := it.Obj.Y; + if not it.slotIsUsed then continue; + if it.Respawnable and (it.ItemType <> ITEM_NONE) then begin it.QuietRespawn := True; it.RespawnTime := 0; @@ -804,7 +677,7 @@ begin begin for idx := High(ggItems) downto 0 do begin - if ggItems[idx].Live then + if ggItems[idx].alive and ggItems[idx].slotIsUsed then begin result := cb(@ggItems[idx]); if result then exit; @@ -815,7 +688,7 @@ begin begin for idx := 0 to High(ggItems) do begin - if ggItems[idx].Live then + if ggItems[idx].alive and ggItems[idx].slotIsUsed then begin result := cb(@ggItems[idx]); if result then exit; @@ -890,18 +763,20 @@ begin for f := 0 to High(ggItems) do begin it := @ggItems[f]; - if not it.Live then continue; + if not it.alive then continue; case it.ItemType of - ITEM_KEY_RED: 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); - ITEM_KEY_GREEN: 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); - ITEM_KEY_BLUE: g_AddDynLight(it.Obj.X+(it.Obj.Rect.Width div 2), it.Obj.Y+(it.Obj.Rect.Height div 2), 32, 0.0, 0.0, 1.0, 0.6); + 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); + 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); + 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); 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); 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); + 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); 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); 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); 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); 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); - ITEM_BOTTLE: g_AddDynLight(it.Obj.X+(it.Obj.Rect.Width div 2), it.Obj.Y+(it.Obj.Rect.Height div 2), 32, 0.0, 0.0, 1.0, 0.6); + 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); + 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); end; end; end;