X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fgame%2Fg_items.pas;h=7331242b7672c3675c54be4b14d630736dfbbd95;hb=3bc42852ee39fff79d1c9b66dd2a55d262a0d9f5;hp=2ddc8586710e50b14d9ed833eb27dd65569f609a;hpb=d7d166dc3cd287276202e862746208892c4cc89f;p=d2df-sdl.git diff --git a/src/game/g_items.pas b/src/game/g_items.pas index 2ddc858..7331242 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 @@ -55,6 +54,7 @@ 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_DrawDrop(); @@ -84,7 +84,6 @@ 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; implementation @@ -212,7 +211,6 @@ begin 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(); @@ -228,6 +226,7 @@ begin 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_JETPACK', GameWAD+':TEXTURES\JETPACK', 32, 32, 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); @@ -266,7 +265,6 @@ begin 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(); @@ -287,6 +285,7 @@ begin g_Frames_DeleteByName('FRAMES_ITEM_WHITESPHERE'); g_Frames_DeleteByName('FRAMES_ITEM_ARMORGREEN'); g_Frames_DeleteByName('FRAMES_ITEM_ARMORBLUE'); + g_Frames_DeleteByName('FRAMES_ITEM_JETPACK'); g_Frames_DeleteByName('FRAMES_ITEM_INVUL'); g_Frames_DeleteByName('FRAMES_ITEM_INVIS'); g_Frames_DeleteByName('FRAMES_ITEM_RESPAWN'); @@ -325,7 +324,6 @@ begin 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; @@ -456,7 +454,6 @@ 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; @@ -486,10 +483,14 @@ 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_JETPACK: if g_Frames_Get(ID, 'FRAMES_ITEM_JETPACK') then it.Animation := TAnimation.Create(ID, True, 15); 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); @@ -503,20 +504,36 @@ 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 @@ -577,7 +594,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; @@ -603,6 +623,8 @@ begin Anim.Free(); end; + Obj.oldX := InitX; + Obj.oldY := InitY; Obj.X := InitX; Obj.Y := InitY; Obj.Vel.X := 0; @@ -626,7 +648,7 @@ end; procedure itemsDrawInternal (dropflag: Boolean); var - i: Integer; + i, fX, fY: Integer; it: PItem; begin if (ggItems = nil) then exit; @@ -634,6 +656,7 @@ begin for i := 0 to High(ggItems) do begin it := @ggItems[i]; + if (not it.slotIsUsed) or (it.ItemType = ITEM_NONE) then continue; // just in case if not it.alive then continue; if (it.dropped <> dropflag) then continue; @@ -641,13 +664,14 @@ begin begin if g_Collide(Obj.X, Obj.Y, Obj.Rect.Width, Obj.Rect.Height, sX, sY, sWidth, sHeight) then begin + Obj.lerp(gLerpFactor, fX, fY); if (Animation = nil) then begin - e_Draw(gItemsTexturesID[ItemType], Obj.X, Obj.Y, 0, true, false); + e_Draw(gItemsTexturesID[ItemType], fX, fY, 0, true, false); end else begin - Animation.Draw(Obj.X, Obj.Y, TMirrorType.None); + Animation.Draw(fX, fY, TMirrorType.None); end; if g_debug_Frames then @@ -688,8 +712,10 @@ procedure g_Items_Pick (ID: DWORD); begin 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 := ITEM_RESPAWNTIME; + ggItems[ID].RespawnTime := IfThen(gLMSRespawn = LMS_RESPAWN_NONE, gGameSettings.ItemRespawnTime, 15) * 36; end; end; @@ -699,11 +725,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); @@ -719,7 +752,7 @@ var begin // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ ïðåäìåòîâ count := 0; - for i := 0 to High(ggItems) do if (ggItems[i].ItemType <> ITEM_NONE) then Inc(count); + for i := 0 to High(ggItems) do if (ggItems[i].ItemType <> ITEM_NONE) and (ggItems[i].slotIsUsed) then Inc(count); // Êîëè÷åñòâî ïðåäìåòîâ utils.writeInt(st, LongInt(count)); @@ -727,7 +760,7 @@ begin 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 // Ñèãíàòóðà ïðåäìåòà utils.writeSign(st, 'ITEM'); @@ -807,7 +840,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; @@ -832,7 +868,7 @@ begin begin for idx := High(ggItems) downto 0 do begin - if ggItems[idx].alive then + if ggItems[idx].alive and ggItems[idx].slotIsUsed then begin result := cb(@ggItems[idx]); if result then exit; @@ -843,7 +879,7 @@ begin begin for idx := 0 to High(ggItems) do begin - if ggItems[idx].alive then + if ggItems[idx].alive and ggItems[idx].slotIsUsed then begin result := cb(@ggItems[idx]); if result then exit; @@ -925,6 +961,7 @@ begin 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);