X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fgame%2Fg_items.pas;h=a69ceaaf811bd9f84f5b07ec41b0e6e2fcf11537;hb=b00b458845d9f1bcf5d7643c47aaad4455600eb2;hp=88a9cba1c433057f3ede53d4bf118ad43aecbc9c;hpb=dffafd305d0df029f317cc92c1968ba0065c0cd8;p=d2df-sdl.git diff --git a/src/game/g_items.pas b/src/game/g_items.pas index 88a9cba..a69ceaa 100644 --- a/src/game/g_items.pas +++ b/src/game/g_items.pas @@ -41,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; @@ -79,7 +82,7 @@ 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; @@ -133,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 @@ -348,6 +369,7 @@ begin it.alive := False; it.SpawnTrigger := -1; it.ItemType := ITEM_NONE; + it.NeedSend := false; freeIds.release(LongWord(idx)); end; @@ -371,6 +393,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; @@ -461,10 +484,9 @@ begin it.alive := True; it.QuietRespawn := False; it.dropped := false; + it.NeedSend := false; g_Obj_Init(@it.Obj); - it.Obj.oldX := X; - it.Obj.oldY := Y; it.Obj.X := X; it.Obj.Y := Y; it.Obj.Rect.Width := ITEMSIZE[ItemType][0]; @@ -485,6 +507,9 @@ 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); @@ -887,6 +912,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);