index 5719ca4ff300322779f697deeb1bbb08510a196b..92ee2f66a84b55c4d83e904d4705f584ced54a9d 100644 (file)
--- a/src/game/g_monsters.pas
+++ b/src/game/g_monsters.pas
FNoRespawn: Boolean;
FFireTime: Integer;
trapCheckFrameId: DWord; // for `g_weapons.CheckTrap()`
+ mplatCheckFrameId: LongWord;
constructor Create(MonsterType: Byte; aID: Integer; ForcedUID: Integer = -1);
destructor Destroy(); override;
procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
procedure setPosition (ax, ay: Integer; callPosChanged: Boolean=true); inline;
+ procedure moveBy (dx, dy: Integer); inline;
procedure getMapBox (out x, y, w, h: Integer); inline;
procedure g_Monsters_killedp ();
procedure g_Monsters_SaveState (var Mem: TBinMemoryWriter);
procedure g_Monsters_LoadState (var Mem: TBinMemoryReader);
-function g_Monsters_GetIDByName (name: String): Integer;
-function g_Monsters_GetNameByID (MonsterType: Byte): String;
-function g_Monsters_GetKilledBy (MonsterType: Byte): String;
+
+function g_Mons_SpawnAt (monType: Integer; x, y: Integer; dir: TDirection=D_LEFT): TMonster; overload;
+function g_Mons_SpawnAt (const typeName: AnsiString; x, y: Integer; dir: TDirection=D_LEFT): TMonster; overload;
+
+function g_Mons_TypeLo (): Integer; inline;
+function g_Mons_TypeHi (): Integer; inline;
+
+function g_Mons_TypeIdByName (const name: AnsiString): Integer;
+function g_Mons_NameByTypeId (monType: Integer): AnsiString;
+function g_Mons_GetKilledByTypeId (monType: Integer): AnsiString;
type
function g_Mons_ForEachAt (x, y: Integer; width, height: Integer; cb: TEachMonsterCB): Boolean;
function g_Mons_ForEachAliveAt (x, y: Integer; width, height: Integer; cb: TEachMonsterCB): Boolean;
-function g_Mons_getNewTrapFrameId (): DWord;
+function g_Mons_getNewTrapFrameId (): DWord; inline;
+function g_Mons_getNewMPlatFrameId (): LongWord; inline;
type
// ////////////////////////////////////////////////////////////////////////// //
var
- monCheckTrapLastFrameId: DWord;
+ monCheckTrapLastFrameId: DWord = 0;
+ monCheckMPlatLastFrameId: LongWord = 0;
procedure TMonster.getMapBox (out x, y, w, h: Integer); inline;
MAX_SOUL = 512; // Îãðàíè÷åíèå Lost_Soul'îâ
+// ////////////////////////////////////////////////////////////////////////// //
var
gMonsters: array of TMonster;
uidMap: array [0..65535] of TMonster; // monster knows it's index
end;
-function g_Mons_getNewTrapFrameId (): DWord;
+function g_Mons_getNewTrapFrameId (): DWord; inline;
var
f: Integer;
begin
Inc(monCheckTrapLastFrameId);
- if monCheckTrapLastFrameId = 0 then
+ if (monCheckTrapLastFrameId = 0) then
begin
// wraparound
monCheckTrapLastFrameId := 1;
end;
+function g_Mons_getNewMPlatFrameId (): LongWord; inline;
+var
+ f: Integer;
+begin
+ Inc(monCheckMPlatLastFrameId);
+ if (monCheckMPlatLastFrameId = 0) then
+ begin
+ // wraparound
+ monCheckMPlatLastFrameId := 1;
+ for f := 0 to High(gMonsters) do
+ begin
+ if (gMonsters[f] <> nil) then gMonsters[f].mplatCheckFrameId := 0;
+ end;
+ end;
+ result := monCheckMPlatLastFrameId;
+end;
+
+
var
pt_x: Integer = 0;
pt_xs: Integer = 1;
freeInds := TIdPool.Create();
clearUidMap();
monCheckTrapLastFrameId := 0;
+ monCheckMPlatLastFrameId := 0;
end;
procedure g_Monsters_FreeData();
gMonsters := nil;
clearUidMap();
monCheckTrapLastFrameId := 0;
+ monCheckMPlatLastFrameId := 0;
end;
end;
end;
-function g_Monsters_GetIDByName(name: String): Integer;
+
+// ////////////////////////////////////////////////////////////////////////// //
+function g_Mons_SpawnAt (monType: Integer; x, y: Integer; dir: TDirection=D_LEFT): TMonster; overload;
+begin
+ result := nil;
+ if (monType >= MONSTER_DEMON) and (monType <= MONSTER_MAN) then
+ begin
+ result := g_Monsters_Create(monType, x, y, dir);
+ end;
+end;
+
+
+function g_Mons_SpawnAt (const typeName: AnsiString; x, y: Integer; dir: TDirection=D_LEFT): TMonster; overload;
+begin
+ result := g_Mons_SpawnAt(g_Mons_TypeIdByName(typeName), x, y, dir);
+end;
+
+
+
+// ////////////////////////////////////////////////////////////////////////// //
+function g_Mons_TypeLo (): Integer; inline; begin result := Low(MONSTERTABLE); end;
+function g_Mons_TypeHi (): Integer; inline; begin result := High(MONSTERTABLE); end;
+
+
+function g_Mons_TypeIdByName (const name: String): Integer;
var
i: Integer;
begin
- name := UpperCase(name);
i := MONSTER_DEMON;
while (i <= MONSTER_MAN) do
begin
- if name = MONSTERTABLE[i].Name then
+ if (CompareText(name, MONSTERTABLE[i].Name) = 0) then
begin
- Result := i;
- Exit;
+ result := i;
+ exit;
end;
Inc(i);
end;
-
- Result := -1;
+ result := -1;
+ // HACK!
+ if (CompareText(name, 'zombie') = 0) then result := MONSTER_ZOMBY;
end;
-function g_Monsters_GetNameByID(MonsterType: Byte): String;
+
+function g_Mons_NameByTypeId (monType: Integer): AnsiString;
begin
- if MonsterType in [MONSTER_DEMON..MONSTER_MAN] then
- Result := MONSTERTABLE[MonsterType].Name
+ if (monType >= MONSTER_DEMON) and (monType <= MONSTER_MAN) then
+ result := MONSTERTABLE[monType].Name
else
- Result := '?';
+ result := '?';
end;
-function g_Monsters_GetKilledBy(MonsterType: Byte): String;
+
+function g_Mons_GetKilledByTypeId (monType: Integer): AnsiString;
begin
- if MonsterType in [MONSTER_DEMON..MONSTER_MAN] then
- Result := KilledByMonster[MonsterType]
+ if (monType >= MONSTER_DEMON) and (monType <= MONSTER_MAN) then
+ Result := KilledByMonster[monType]
else
Result := '?';
end;
+
+// ////////////////////////////////////////////////////////////////////////// //
{ T M o n s t e r : }
procedure TMonster.setGameX (v: Integer); inline; begin FObj.X := v; positionChanged(); end;
procedure TMonster.setGameY (v: Integer); inline; begin FObj.Y := v; positionChanged(); end;
+
procedure TMonster.setPosition (ax, ay: Integer; callPosChanged: Boolean=true); inline; begin FObj.X := ax; FObj.Y := ay; if callPosChanged then positionChanged(); end;
+procedure TMonster.moveBy (dx, dy: Integer); inline;
+begin
+ if (dx <> 0) or (dy <> 0) then
+ begin
+ FObj.X += dx;
+ FObj.Y += dy;
+ positionChanged();
+ end;
+end;
+
procedure TMonster.ActionSound();
begin
mProxyId := -1;
mArrIdx := -1;
trapCheckFrameId := 0;
+ mplatCheckFrameId := 0;
if FMonsterType in [MONSTER_ROBO, MONSTER_BARREL] then
FBloodKind := BLOOD_SPARKS