summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 31c9216)
raw | patch | inline | side by side (parent: 31c9216)
author | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Fri, 25 Aug 2017 13:15:15 +0000 (16:15 +0300) | ||
committer | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Fri, 25 Aug 2017 13:15:38 +0000 (16:15 +0300) |
src/game/g_monsters.pas | patch | blob | history |
index 04e19241b541fb591877fa8e7f4089cf233ddeb6..2b70da642e49892257507eadf3da63de2a0d32db 100644 (file)
--- a/src/game/g_monsters.pas
+++ b/src/game/g_monsters.pas
e_log, g_main, g_sound, g_gfx, g_player, g_game,
g_weapons, g_triggers, MAPDEF, g_items, g_options,
g_console, g_map, Math, SysUtils, g_menu, wadreader,
- g_language, g_netmsg;
+ g_language, g_netmsg, idpool;
// ////////////////////////////////////////////////////////////////////////// //
var
gMonsters: array of TMonster;
uidMap: array [0..65535] of TMonster; // monster knows it's index
+ freeInds: TIdPool = nil;
procedure clearUidMap ();
idx: Integer;
begin
for idx := 0 to High(uidMap) do uidMap[idx] := nil;
+ freeInds.clear();
end;
soulcount: Integer = 0;
-function allocMonster(): DWORD;
+function allocMonster (): DWORD;
var
- i, olen: Integer;
+ f, olen: Integer;
begin
- for i := 0 to High(gMonsters) do
+ result := freeInds.alloc();
+ if (result > High(gMonsters)) then
begin
- if (gMonsters[i] = nil) then
- begin
- result := i;
- exit;
- end;
- end;
-
- olen := Length(gMonsters);
- if (olen = 0) then
- begin
- SetLength(gMonsters, 64);
- result := 0;
- end
- else
- begin
- result := olen;
- SetLength(gMonsters, Length(gMonsters)+32);
+ olen := Length(gMonsters);
+ SetLength(gMonsters, result+64);
+ for f := olen to High(gMonsters) do gMonsters[f] := nil;
end;
end;
g_Sound_CreateWADEx('SOUND_MONSTER_FISH_ATTACK', GameWAD+':MSOUNDS\FISH_ATTACK');
+ freeInds := TIdPool.Create();
clearUidMap();
monCheckTrapLastFrameId := 0;
end;
g_Sound_Delete('SOUND_MONSTER_SPIDER_WALK');
g_Sound_Delete('SOUND_MONSTER_FISH_ATTACK');
+
+ freeInds.Free();
+ freeInds := nil;
end;
procedure g_Monsters_Init();
if gMonsters = nil then
Exit;
-// Ïðèêîëèñò ñìååòñÿ íàä ñìåðòüþ èãðîêà:
+ // Ïðèêîëèñò ñìååòñÿ íàä ñìåðòüþ èãðîêà:
h := High(gMonsters);
for a := 0 to h do
+ begin
if (gMonsters[a] <> nil) then
+ begin
with gMonsters[a] do
+ begin
if (FMonsterType = MONSTER_MAN) and
(FState <> MONSTATE_DEAD) and
(FState <> MONSTATE_SLEEP) and
g_Sound_PlayExAt('SOUND_MONSTER_TRUP', FObj.X, FObj.Y);
Exit;
end;
+ end;
+ end;
+ end;
end;
procedure g_Monsters_Update();
a: Integer;
begin
if gMonsters <> nil then
+ begin
for a := 0 to High(gMonsters) do
- if gMonsters[a] <> nil then
- gMonsters[a].Draw();
+ begin
+ if (gMonsters[a] <> nil) then gMonsters[a].Draw();
+ end;
+ end;
end;
procedure g_Monsters_DrawHealth();
e_TextureFontGetSize(gStdFont, fW, fH);
for a := 0 to High(gMonsters) do
+ begin
if gMonsters[a] <> nil then
begin
e_TextureFontPrint(gMonsters[a].FObj.X + gMonsters[a].FObj.Rect.X,
gMonsters[a].FObj.Y + gMonsters[a].FObj.Rect.Y + gMonsters[a].FObj.Rect.Height - fH,
IntToStr(gMonsters[a].FHealth), gStdFont);
end;
+ end;
end;
function g_Monsters_ByUID (UID: Word): TMonster;
-//var a: Integer;
begin
result := uidMap[UID];
- {
- Result := nil;
- if gMonsters <> nil then
- for a := 0 to High(gMonsters) do
- if (gMonsters[a] <> nil) and
- (gMonsters[a].FUID = UID) then
- begin
- Result := gMonsters[a];
- Break;
- end;
- }
end;
procedure g_Monsters_SaveState(var Mem: TBinMemoryWriter);
begin
// Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ ìîíñòðîâ:
count := 0;
- if gMonsters <> nil then
+ if (gMonsters <> nil) then
+ begin
for i := 0 to High(gMonsters) do
- if gMonsters[i] <> nil then
- if gMonsters[i].FMonsterType <> MONSTER_NONE then
- count := count + 1;
+ begin
+ if (gMonsters[i] <> nil) then
+ begin
+ if (gMonsters[i].FMonsterType <> MONSTER_NONE) then count += 1;
+ end;
+ end;
+ end;
Mem := TBinMemoryWriter.Create((count+1) * 350);
// Ñîõðàíÿåì ìîíñòðîâ:
for i := 0 to High(gMonsters) do
- if gMonsters[i] <> nil then
- if gMonsters[i].FMonsterType <> MONSTER_NONE then
+ begin
+ if (gMonsters[i] <> nil) then
+ begin
+ if (gMonsters[i].FMonsterType <> MONSTER_NONE) then
begin
- // Òèï ìîíñòðà:
+ // Òèï ìîíñòðà:
b := gMonsters[i].MonsterType;
Mem.WriteByte(b);
- // Ñîõðàíÿåì äàííûå ìîíñòðà:
+ // Ñîõðàíÿåì äàííûå ìîíñòðà:
gMonsters[i].SaveState(Mem);
end;
+ end;
+ end;
end;
procedure g_Monsters_LoadState(var Mem: TBinMemoryReader);
mProxyId := -1;
end;
- if (mArrIdx <> -1) and (mArrIdx < Length(gMonsters)) then gMonsters[mArrIdx] := nil;
+ if (mArrIdx <> -1) and (mArrIdx < Length(gMonsters)) then
+ begin
+ freeInds.release(mArrIdx);
+ gMonsters[mArrIdx] := nil;
+ end;
mArrIdx := -1;
uidMap[FUID] := nil;
end;
end;
-procedure monsPostLoad ();
-begin
-end;
procedure TMonster.LoadState(var Mem: TBinMemoryReader);
var
end;
-begin
- g_SetPostLoadHook(monsPostLoad);
end.