X-Git-Url: https://deadsoftware.ru/gitweb?p=d2df-sdl.git;a=blobdiff_plain;f=src%2Fgame%2Fg_items.pas;h=b3d8522465bc8b6da4c182b4ef7586e2a1130020;hp=e531acd4fde93d082eeb882295f45db4053d1b52;hb=HEAD;hpb=1bddfaf7b6421f1659a6f211dfdb1dfaef5d5173 diff --git a/src/game/g_items.pas b/src/game/g_items.pas index e531acd..b3d8522 100644 --- a/src/game/g_items.pas +++ b/src/game/g_items.pas @@ -2,8 +2,7 @@ * * 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 @@ -42,8 +41,11 @@ Type Obj: TObj; Animation: TAnimation; dropped: Boolean; // dropped from the monster? drops should be rendered after corpses, so zombie corpse will not obscure ammo container, for example + NeedSend: Boolean; procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right! + procedure getMapBox (out x, y, w, h: Integer); inline; + procedure moveBy (dx, dy: Integer); inline; property myid: Integer read arrIdx; end; @@ -55,6 +57,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(); @@ -79,12 +82,11 @@ type TItemEachAliveCB = function (it: PItem): Boolean is nested; // return `true` to stop function g_Items_ForEachAlive (cb: TItemEachAliveCB; backwards: Boolean=false): Boolean; - +function g_Items_NextAlive (startIdx: Integer): PItem; var gItemsTexturesID: Array [1..ITEM_MAX] of DWORD; gMaxDist: Integer = 1; // for sounds - ITEM_RESPAWNTIME: Integer = 60 * 36; implementation @@ -134,8 +136,26 @@ end; // ////////////////////////////////////////////////////////////////////////// // procedure TItem.positionChanged (); begin + NeedSend := NeedSend or (Obj.X <> Obj.oldX) or (Obj.Y <> Obj.oldY); +end; + +procedure TItem.getMapBox (out x, y, w, h: Integer); inline; +begin + x := Obj.X+Obj.Rect.X; + y := Obj.Y+Obj.Rect.Y; + w := Obj.Rect.Width; + h := Obj.Rect.Height; end; +procedure TItem.moveBy (dx, dy: Integer); inline; +begin + if (dx <> 0) or (dy <> 0) then + begin + Obj.X += dx; + Obj.Y += dy; + positionChanged(); + end; +end; // ////////////////////////////////////////////////////////////////////////// // const @@ -159,7 +179,7 @@ const ((62), (16)), // WEAPON_ROCKETLAUNCHER ((54), (16)), // WEAPON_PLASMA ((61), (36)), // WEAPON_BFG - ((54), (16)), // WEAPON_SUPERPULEMET + ((54), (16)), // WEAPON_SUPERCHAINGUN (( 9), (11)), // AMMO_BULLETS ((28), (16)), // AMMO_BULLETS_BOX ((15), ( 7)), // AMMO_SHELLS @@ -172,7 +192,7 @@ const ((16), (16)), // KEY_RED ((16), (16)), // KEY_GREEN ((16), (16)), // KEY_BLUE - (( 1), ( 1)), // WEAPON_KASTET + (( 1), ( 1)), // WEAPON_IRONFIST ((43), (16)), // WEAPON_PISTOL ((14), (18)), // BOTTLE ((16), (15)), // HELMET @@ -186,16 +206,16 @@ 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_IRONFIST', gItemsTexturesID[ITEM_WEAPON_IRONFIST]); g_Texture_Get('ITEM_WEAPON_SAW', gItemsTexturesID[ITEM_WEAPON_SAW]); + g_Texture_Get('ITEM_WEAPON_PISTOL', gItemsTexturesID[ITEM_WEAPON_PISTOL]); 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_SUPERCHAINGUN', gItemsTexturesID[ITEM_WEAPON_SUPERCHAINGUN]); 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]); @@ -210,9 +230,8 @@ begin 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]); + g_Texture_Get('ITEM_OXYGEN', gItemsTexturesID[ITEM_OXYGEN]); + g_Texture_Get('ITEM_SUIT', gItemsTexturesID[ITEM_SUIT]); end; procedure g_Items_LoadData(); @@ -220,7 +239,7 @@ begin 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_GETPOWERUP', GameWAD+':SOUNDS\GETPOWERUP'); g_Sound_CreateWADEx('SOUND_ITEM_GETWEAPON', GameWAD+':SOUNDS\GETWEAPON'); g_Sound_CreateWADEx('SOUND_ITEM_GETITEM', GameWAD+':SOUNDS\GETITEM'); @@ -228,6 +247,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); @@ -238,16 +258,17 @@ begin 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_MEDKIT_BLACK', GameWAD+':TEXTURES\BMED'); + g_Texture_CreateWADEx('ITEM_WEAPON_IRONFIST', GameWAD+':TEXTURES\IRONFIST'); 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_SUPERCHAINGUN', GameWAD+':TEXTURES\SCHAINGUN'); 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'); @@ -264,9 +285,6 @@ begin 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(); @@ -279,7 +297,7 @@ begin e_WriteLog('Releasing items data...', TMsgType.Notify); g_Sound_Delete('SOUND_ITEM_RESPAWNITEM'); - g_Sound_Delete('SOUND_ITEM_GETRULEZ'); + g_Sound_Delete('SOUND_ITEM_GETPOWERUP'); g_Sound_Delete('SOUND_ITEM_GETWEAPON'); g_Sound_Delete('SOUND_ITEM_GETITEM'); @@ -287,6 +305,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'); @@ -297,16 +316,17 @@ begin g_Frames_DeleteByName('FRAMES_FLAG_DOM'); g_Texture_Delete('ITEM_MEDKIT_SMALL'); g_Texture_Delete('ITEM_MEDKIT_LARGE'); + g_Texture_Delete('ITEM_MEDKIT_BLACK'); + g_Texture_Delete('ITEM_WEAPON_IRONFIST'); 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_SUPERCHAINGUN'); g_Texture_Delete('ITEM_WEAPON_FLAMETHROWER'); g_Texture_Delete('ITEM_AMMO_BULLETS'); g_Texture_Delete('ITEM_AMMO_BULLETS_BOX'); @@ -323,9 +343,6 @@ begin 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; @@ -350,6 +367,7 @@ begin it.alive := False; it.SpawnTrigger := -1; it.ItemType := ITEM_NONE; + it.NeedSend := false; freeIds.release(LongWord(idx)); end; @@ -373,6 +391,7 @@ begin it.alive := false; it.SpawnTrigger := -1; it.Respawnable := false; + it.NeedSend := false; //if not freeIds.hasFree[LongWord(i)] then raise Exception.Create('internal error in item idx manager'); end; end; @@ -456,7 +475,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; @@ -464,6 +482,7 @@ begin it.alive := True; it.QuietRespawn := False; it.dropped := false; + it.NeedSend := false; g_Obj_Init(@it.Obj); it.Obj.X := X; @@ -486,10 +505,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 +526,37 @@ 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{, PowerupRespawnTime}: 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); + //PowerupRespawnTime := IfThen(gLMSRespawn = LMS_RESPAWN_NONE, gGameSettings.PowerupRespawnTime, 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 +617,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 +646,8 @@ begin Anim.Free(); end; + Obj.oldX := InitX; + Obj.oldY := InitY; Obj.X := InitX; Obj.Y := InitY; Obj.Vel.X := 0; @@ -626,7 +671,7 @@ end; procedure itemsDrawInternal (dropflag: Boolean); var - i: Integer; + i, fX, fY: Integer; it: PItem; begin if (ggItems = nil) then exit; @@ -634,6 +679,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 +687,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 @@ -686,24 +733,101 @@ end; procedure g_Items_Pick (ID: DWORD); begin - if (ID < Length(ggItems)) then + if ID >= Length(ggItems) then exit; + + ggItems[ID].Obj.oldX := ggItems[ID].Obj.X; + ggItems[ID].Obj.oldY := ggItems[ID].Obj.Y; + ggItems[ID].alive := false; + + // Items respawn timer + ggItems[ID].RespawnTime := IfThen(gLMSRespawn = LMS_RESPAWN_NONE, gGameSettings.ItemRespawnTime, 15) * 36; + + // Powerup respawn timer + if ggItems[ID].ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL, ITEM_INVIS, + ITEM_MEDKIT_BLACK, ITEM_JETPACK, ITEM_SUIT] then begin - ggItems[ID].alive := false; - ggItems[ID].RespawnTime := ITEM_RESPAWNTIME; + ggItems[ID].RespawnTime := IfThen(gLMSRespawn = LMS_RESPAWN_NONE, gGameSettings.PowerupRespawnTime, 15) * 36; + end; + + // #### Random powerup respawn #### + if (TGameOption.POWERUP_RANDOM in gGameSettings.Options) and (ggItems[ID].ItemType in [ + ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL, ITEM_INVIS, ITEM_MEDKIT_BLACK, ITEM_JETPACK, + ITEM_SUIT + ]) then + begin + ggItems[ID].RespawnTime := Max(1, (gGameSettings.PowerupRespawnTime + + RandomRange(-gGameSettings.PowerupRespawnRandom, gGameSettings.PowerupRespawnRandom + 1)) * 36); + //e_logwritefln ('Randomized powerup %s time: %s', [ggItems[ID].ItemType, ggItems[ID].RespawnTime]); + end; + + // #### Random item respawn #### + // Randomize respawn for all items (excluding powerups) + if (TGameOption.ITEM_ALL_RANDOM in gGameSettings.Options) and (ggItems[ID].ItemType in [ + ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_ARMOR_GREEN, ITEM_ARMOR_BLUE, ITEM_BOTTLE, + ITEM_HELMET, ITEM_OXYGEN, ITEM_AMMO_BULLETS, ITEM_AMMO_BULLETS_BOX, ITEM_AMMO_SHELLS, + ITEM_AMMO_SHELLS_BOX, ITEM_AMMO_ROCKET, ITEM_AMMO_ROCKET_BOX, ITEM_AMMO_CELL, + ITEM_AMMO_CELL_BIG, ITEM_AMMO_FUELCAN, ITEM_AMMO_BACKPACK, ITEM_WEAPON_SAW, + ITEM_WEAPON_SHOTGUN1, ITEM_WEAPON_SHOTGUN2, ITEM_WEAPON_CHAINGUN, ITEM_WEAPON_ROCKETLAUNCHER, + ITEM_WEAPON_PLASMA, ITEM_WEAPON_BFG, ITEM_WEAPON_SUPERCHAINGUN, ITEM_WEAPON_FLAMETHROWER + ]) then + begin + ggItems[ID].RespawnTime := Max(1, (gGameSettings.ItemRespawnTime + + RandomRange(-gGameSettings.ItemRespawnRandom, gGameSettings.ItemRespawnRandom + 1)) * 36); + //e_logwritefln ('Randomized item %s time: %s', [ggItems[ID].ItemType, ggItems[ID].RespawnTime]); + end; + + // Randomize respawn for heal/armor + if (TGameOption.ITEM_LIFE_RANDOM in gGameSettings.Options) and (ggItems[ID].ItemType in [ + ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_ARMOR_GREEN, ITEM_ARMOR_BLUE, ITEM_BOTTLE, + ITEM_HELMET, ITEM_OXYGEN, ITEM_AMMO_BACKPACK + ]) then + begin + ggItems[ID].RespawnTime := Max(1, (gGameSettings.ItemRespawnTime + + RandomRange(-gGameSettings.ItemRespawnRandom, gGameSettings.ItemRespawnRandom + 1)) * 36); + //e_logwritefln ('Randomized help item %s time: %s', [ggItems[ID].ItemType, ggItems[ID].RespawnTime]); end; -end; + // Randomize respawn for ammo + if (TGameOption.ITEM_AMMO_RANDOM in gGameSettings.Options) and (ggItems[ID].ItemType in [ + ITEM_AMMO_BULLETS, ITEM_AMMO_BULLETS_BOX, ITEM_AMMO_SHELLS, ITEM_AMMO_SHELLS_BOX, + ITEM_AMMO_ROCKET, ITEM_AMMO_ROCKET_BOX, ITEM_AMMO_CELL, ITEM_AMMO_CELL_BIG, ITEM_AMMO_FUELCAN + ]) then + begin + ggItems[ID].RespawnTime := Max(1, (gGameSettings.ItemRespawnTime + + RandomRange(-gGameSettings.ItemRespawnRandom, gGameSettings.ItemRespawnRandom + 1)) * 36); + //e_logwritefln ('Randomized ammo %s time: %s', [ggItems[ID].ItemType, ggItems[ID].RespawnTime]); + end; + + // Randomize respawn for weapons + if (TGameOption.ITEM_WEAPON_RANDOM in gGameSettings.Options) and (ggItems[ID].ItemType in [ + ITEM_WEAPON_SAW, ITEM_WEAPON_SHOTGUN1, ITEM_WEAPON_SHOTGUN2, ITEM_WEAPON_CHAINGUN, + ITEM_WEAPON_ROCKETLAUNCHER, ITEM_WEAPON_PLASMA, ITEM_WEAPON_BFG, ITEM_WEAPON_SUPERCHAINGUN, + ITEM_WEAPON_FLAMETHROWER + ]) then + begin + ggItems[ID].RespawnTime := Max(1, (gGameSettings.ItemRespawnTime + + RandomRange(-gGameSettings.ItemRespawnRandom, gGameSettings.ItemRespawnRandom + 1)) * 36); + //e_logwritefln ('Randomized weapon %s time: %s', [ggItems[ID].ItemType, ggItems[ID].RespawnTime]); + end; +end; procedure g_Items_Remove (ID: DWORD); 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 +843,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 +851,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 +931,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 +959,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 +970,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; @@ -852,6 +979,19 @@ begin end; end; +function g_Items_NextAlive (startIdx: Integer): PItem; +var + idx: Integer; +begin + result := nil; + if (ggItems = nil) or (startIdx >= High(ggItems)) then exit; + for idx := startIdx + 1 to High(ggItems) do + if ggItems[idx].alive and ggItems[idx].slotIsUsed then + begin + result := @ggItems[idx]; + exit; + end; +end; // ////////////////////////////////////////////////////////////////////////// // procedure g_Items_EmitPickupSound (idx: Integer); @@ -872,14 +1012,14 @@ begin it := @ggItems[idx]; if gSoundEffectsDF then begin - if it.ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL, - ITEM_INVIS, ITEM_MEDKIT_BLACK, ITEM_JETPACK] then + if it.ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL, ITEM_INVIS, + ITEM_JETPACK, ITEM_MEDKIT_BLACK] then begin - g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', x, y); + g_Sound_PlayExAt('SOUND_ITEM_GETPOWERUP', x, y); end else if it.ItemType in [ITEM_WEAPON_SAW, ITEM_WEAPON_PISTOL, ITEM_WEAPON_SHOTGUN1, ITEM_WEAPON_SHOTGUN2, ITEM_WEAPON_CHAINGUN, ITEM_WEAPON_ROCKETLAUNCHER, ITEM_WEAPON_PLASMA, - ITEM_WEAPON_BFG, ITEM_WEAPON_SUPERPULEMET, ITEM_WEAPON_FLAMETHROWER, + ITEM_WEAPON_BFG, ITEM_WEAPON_SUPERCHAINGUN, ITEM_WEAPON_FLAMETHROWER, ITEM_AMMO_BACKPACK] then begin g_Sound_PlayExAt('SOUND_ITEM_GETWEAPON', x, y); @@ -891,14 +1031,14 @@ begin end else begin - if it.ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_SUIT, - ITEM_MEDKIT_BLACK, ITEM_INVUL, ITEM_INVIS, ITEM_JETPACK] then + if it.ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL, ITEM_INVIS, + ITEM_SUIT, ITEM_JETPACK, ITEM_MEDKIT_BLACK] then begin - g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', x, y); + g_Sound_PlayExAt('SOUND_ITEM_GETPOWERUP', x, y); end else if it.ItemType in [ITEM_WEAPON_SAW, ITEM_WEAPON_PISTOL, ITEM_WEAPON_SHOTGUN1, ITEM_WEAPON_SHOTGUN2, ITEM_WEAPON_CHAINGUN, ITEM_WEAPON_ROCKETLAUNCHER, ITEM_WEAPON_PLASMA, - ITEM_WEAPON_BFG, ITEM_WEAPON_SUPERPULEMET, ITEM_WEAPON_FLAMETHROWER] then + ITEM_WEAPON_BFG, ITEM_WEAPON_SUPERCHAINGUN, ITEM_WEAPON_FLAMETHROWER] then begin g_Sound_PlayExAt('SOUND_ITEM_GETWEAPON', x, y); end @@ -925,6 +1065,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);