diff --git a/src/game/g_map.pas b/src/game/g_map.pas
index c48d0991929a39fe7f3bd84dafc438f9a7bacf8a..2b8e9ff34d5875ab0042b71f15b9936bfb680e97 100644 (file)
--- a/src/game/g_map.pas
+++ b/src/game/g_map.pas
*
* 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
*
* 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
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
CaptureTime: LongWord;
Animation: TAnimation;
Direction: TDirection;
CaptureTime: LongWord;
Animation: TAnimation;
Direction: TDirection;
+ NeedSend: Boolean;
end;
function g_Map_Load(Res: String): Boolean;
end;
function g_Map_Load(Res: String): Boolean;
function g_Map_GetPoint(PointType: Byte; var RespawnPoint: TRespawnPoint): Boolean;
function g_Map_GetPointCount(PointType: Byte): Word;
function g_Map_GetPoint(PointType: Byte; var RespawnPoint: TRespawnPoint): Boolean;
function g_Map_GetPointCount(PointType: Byte): Word;
+function g_Map_GetRandomPointType(): Byte;
function g_Map_HaveFlagPoints(): Boolean;
function g_Map_HaveFlagPoints(): Boolean;
gLiftMap: array of array of DWORD;
gWADHash: TMD5Digest;
BackID: DWORD = DWORD(-1);
gLiftMap: array of array of DWORD;
gWADHash: TMD5Digest;
BackID: DWORD = DWORD(-1);
- gExternalResources: TStringList;
+ gExternalResources: array of TDiskFileInfo = nil;
gMovingWallIds: array of Integer = nil;
gdbg_map_use_accel_render: Boolean = true;
gMovingWallIds: array of Integer = nil;
gdbg_map_use_accel_render: Boolean = true;
uses
{$INCLUDE ../nogl/noGLuses.inc}
uses
{$INCLUDE ../nogl/noGLuses.inc}
- e_input, g_main, e_log, e_texture, g_items, g_gfx, g_console,
+ e_input, g_main, e_log, e_texture, e_res, g_items, g_gfx, g_console,
g_weapons, g_game, g_sound, e_sound, CONFIG,
g_options, g_triggers, g_player,
Math, g_monsters, g_saveload, g_language, g_netmsg,
sfs, xstreams, hashtable, wadreader,
ImagingTypes, Imaging, ImagingUtility,
g_weapons, g_game, g_sound, e_sound, CONFIG,
g_options, g_triggers, g_player,
Math, g_monsters, g_saveload, g_language, g_netmsg,
sfs, xstreams, hashtable, wadreader,
ImagingTypes, Imaging, ImagingUtility,
- ImagingGif, ImagingNetworkGraphics;
+ ImagingGif, ImagingNetworkGraphics,
+ g_res_downloader;
const
FLAGRECT: TRectWH = (X:15; Y:12; Width:33; Height:52);
const
FLAGRECT: TRectWH = (X:15; Y:12; Width:33; Height:52);
try
e_LogWritefln('parsing "mapdef.txt"...', []);
try
e_LogWritefln('parsing "mapdef.txt"...', []);
- st := openDiskFileRO(DataDir+'mapdef.txt');
- e_LogWritefln('found local "%smapdef.txt"', [DataDir]);
+ st := e_OpenResourceRO(DataDirs, 'mapdef.txt');
+ e_LogWritefln('found local "mapdef.txt"', []);
except
st := nil;
end;
except
st := nil;
end;
end;
end;
-function CreateTexture(RecName: AnsiString; Map: string; log: Boolean): Integer;
+function extractWadName (resourceName: string): string;
+var
+ posN: Integer;
+begin
+ posN := Pos(':', resourceName);
+ if posN > 0 then
+ Result:= Copy(resourceName, 0, posN-1)
+ else
+ Result := '';
+end;
+
+
+procedure addResToExternalResList (res: AnsiString);
+var
+ uname: AnsiString;
+ f: Integer;
+ fi: TDiskFileInfo;
+begin
+ if g_Game_IsClient or not g_Game_IsNet then exit;
+ if (length(res) = 0) then exit; // map wad
+ //res := extractWadName(res);
+ //if (length(res) = 0) then exit; // map wad
+ uname := toLowerCase1251(res);
+ // do not add duplicates
+ for f := 0 to High(gExternalResources) do
+ begin
+ if (gExternalResources[f].userName = uname) then exit;
+ end;
+ //writeln('***(000) addResToExternalResList: res=[', res, ']');
+ // add new resource
+ fi.userName := uname;
+ if not findFileCI(res) then exit;
+ //writeln('***(001) addResToExternalResList: res=[', res, ']');
+ fi.diskName := res;
+ if (not GetDiskFileInfo(res, fi)) then
+ begin
+ fi.tag := -1;
+ end
+ else
+ begin
+ //writeln('***(002) addResToExternalResList: res=[', res, ']');
+ fi.tag := 0; // non-zero means "cannot caclucate hash"
+ try
+ fi.hash := MD5File(fi.diskName);
+ except
+ fi.tag := -1;
+ end;
+ end;
+ //e_LogWritefln('addext: res=[%s]; uname=[%s]; diskName=[%s]', [res, fi.userName, fi.diskName]);
+ SetLength(gExternalResources, length(gExternalResources)+1);
+ gExternalResources[High(gExternalResources)] := fi;
+end;
+
+
+procedure compactExtResList ();
+var
+ src, dest: Integer;
+begin
+ src := 0;
+ dest := 0;
+ for src := 0 to High(gExternalResources) do
+ begin
+ if (gExternalResources[src].tag = 0) then
+ begin
+ // copy it
+ if (dest <> src) then gExternalResources[dest] := gExternalResources[src];
+ Inc(dest);
+ end;
+ end;
+ if (dest <> length(gExternalResources)) then SetLength(gExternalResources, dest);
+end;
+
+
+function GetReplacementWad (WadName: AnsiString): AnsiString;
+begin
+ result := '';
+ if WadName <> '' then
+ begin
+ result := WadName;
+ if g_Game_IsClient then result := g_Res_FindReplacementWad(WadName);
+ if (result = WadName) then result := e_FindWad(WadDirs, result)
+ end;
+end;
+
+
+procedure generateExternalResourcesList (map: TDynRecord);
+begin
+ SetLength(gExternalResources, 0);
+ addResToExternalResList(GetReplacementWad(g_ExtractWadName(map.MusicName)));
+ addResToExternalResList(GetReplacementWad(g_ExtractWadName(map.SkyName)));
+end;
+
+
+function CreateTexture (RecName: AnsiString; Map: string; log: Boolean): Integer;
var
WAD: TWADFile;
TextureData: Pointer;
var
WAD: TWADFile;
TextureData: Pointer;
end;
// Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
end;
// Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
- WADName := g_ExtractWadName(RecName);
+ WADName := GetReplacementWad(g_ExtractWadName(RecName));
+ if (WADName <> '') then addResToExternalResList(WADName);
+ if WADName = '' then WADName := Map; //WADName := GameDir+'/wads/'+WADName else
WAD := TWADFile.Create();
WAD := TWADFile.Create();
-
- if WADName <> '' then WADName := GameDir+'/wads/'+WADName else WADName := Map;
-
WAD.ReadFile(WADName);
//txname := RecName;
WAD.ReadFile(WADName);
//txname := RecName;
end;
// ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
end;
// ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
- WADName := g_ExtractWadName(RecName);
+ WADName := GetReplacementWad(g_ExtractWadName(RecName));
+ if (WADName <> '') then addResToExternalResList(WADName);
+ if WADName = '' then WADName := Map; //WADName := GameDir+'/wads/'+WADName else
WAD := TWADFile.Create();
try
WAD := TWADFile.Create();
try
- if WADName <> '' then WADName := GameDir+'/wads/'+WADName else WADName := Map;
+ //if WADName <> '' then WADName := GameDir+'/wads/'+WADName else WADName := Map;
WAD.ReadFile(WADName);
WAD.ReadFile(WADName);
g_Mons_ForEach(monsDieTrig);
end;
g_Mons_ForEach(monsDieTrig);
end;
-function extractWadName(resourceName: string): string;
-var
- posN: Integer;
-begin
- posN := Pos(':', resourceName);
- if posN > 0 then
- Result:= Copy(resourceName, 0, posN-1)
- else
- Result := '';
-end;
-
-procedure addResToExternalResList(res: string);
-begin
- res := extractWadName(res);
- if (res <> '') and (gExternalResources.IndexOf(res) = -1) then
- gExternalResources.Add(res);
-end;
-
-procedure generateExternalResourcesList({mapReader: TMapReader_1}map: TDynRecord);
-//var
- //textures: TTexturesRec1Array;
- //textures: TDynField;
- //trec: TDynRecord;
- //mapHeader: TMapHeaderRec_1;
- //i: integer;
- //resFile: String = '';
-begin
- if gExternalResources = nil then
- gExternalResources := TStringList.Create;
-
- gExternalResources.Clear;
-
- (*
- {
- textures := GetTextures(map);
- for i := 0 to High(textures) do
- begin
- addResToExternalResList(resFile);
- end;
- }
-
- textures := map['texture'];
- if (textures <> nil) then
- begin
- for trec in textures do
- begin
- addResToExternalResList(resFile);
- end;
- end;
-
- textures := nil;
- *)
-
- //mapHeader := GetMapHeader(map);
-
- addResToExternalResList(map.MusicName);
- addResToExternalResList(map.SkyName);
-end;
-
-
procedure mapCreateGrid ();
var
mapX0: Integer = $3fffffff;
procedure mapCreateGrid ();
var
mapX0: Integer = $3fffffff;
if (gCurrentMap = nil) then
begin
FileName := g_ExtractWadName(Res);
if (gCurrentMap = nil) then
begin
FileName := g_ExtractWadName(Res);
- e_WriteLog('Loading map WAD: '+FileName, TMsgType.Notify);
+ e_LogWritefln('Loading map WAD [%s] (res=[%s])', [FileName, Res], TMsgType.Notify);
g_Game_SetLoadingText(_lc[I_LOAD_WAD_FILE], 0, False);
WAD := TWADFile.Create();
g_Game_SetLoadingText(_lc[I_LOAD_WAD_FILE], 0, False);
WAD := TWADFile.Create();
begin
e_WriteLog(' Loading sky: ' + gMapInfo.SkyName, TMsgType.Notify);
g_Game_SetLoadingText(_lc[I_LOAD_SKY], 0, False);
begin
e_WriteLog(' Loading sky: ' + gMapInfo.SkyName, TMsgType.Notify);
g_Game_SetLoadingText(_lc[I_LOAD_SKY], 0, False);
- FileName := g_ExtractWadName(gMapInfo.SkyName);
-
- if (FileName <> '') then FileName := GameDir+'/wads/'+FileName else FileName := g_ExtractWadName(Res);
-
if gTextureFilter then TEXTUREFILTER := GL_LINEAR else TEXTUREFILTER := GL_NEAREST;
try
if gTextureFilter then TEXTUREFILTER := GL_LINEAR else TEXTUREFILTER := GL_NEAREST;
try
- s := FileName+':'+g_ExtractFilePathName(gMapInfo.SkyName);
+ s := e_GetResourcePath(WadDirs, gMapInfo.SkyName, g_ExtractWadName(Res));
if g_Texture_CreateWAD(BackID, s) then
if g_Texture_CreateWAD(BackID, s) then
- begin
- g_Game_SetupScreenSize();
- end
+ g_Game_SetupScreenSize
else
else
- begin
- g_FatalError(Format(_lc[I_GAME_ERROR_SKY], [s]));
- end;
+ g_FatalError(Format(_lc[I_GAME_ERROR_SKY], [s]))
finally
TEXTUREFILTER := GL_NEAREST;
end;
finally
TEXTUREFILTER := GL_NEAREST;
end;
begin
e_WriteLog(' Loading music: ' + gMapInfo.MusicName, TMsgType.Notify);
g_Game_SetLoadingText(_lc[I_LOAD_MUSIC], 0, False);
begin
e_WriteLog(' Loading music: ' + gMapInfo.MusicName, TMsgType.Notify);
g_Game_SetLoadingText(_lc[I_LOAD_MUSIC], 0, False);
- FileName := g_ExtractWadName(gMapInfo.MusicName);
-
- if FileName <> '' then
- FileName := GameDir+'/wads/'+FileName
- else
- begin
- FileName := g_ExtractWadName(Res);
- end;
- s := FileName+':'+g_ExtractFilePathName(gMapInfo.MusicName);
+ s := e_GetResourcePath(WadDirs, gMapInfo.MusicName, g_ExtractWadName(Res));
if g_Sound_CreateWADEx(gMapInfo.MusicName, s, True) then
ok := True
else
if g_Sound_CreateWADEx(gMapInfo.MusicName, s, True) then
ok := True
else
end;
end;
end;
end;
+ compactExtResList();
e_WriteLog('Done loading map.', TMsgType.Notify);
Result := True;
end;
e_WriteLog('Done loading map.', TMsgType.Notify);
Result := True;
end;
begin
if gFlags[a].Animation <> nil then gFlags[a].Animation.Update();
begin
if gFlags[a].Animation <> nil then gFlags[a].Animation.Update();
+ Obj.oldX := Obj.X;
+ Obj.oldY := Obj.Y;
+
m := g_Obj_Move(@Obj, True, True);
m := g_Obj_Move(@Obj, True, True);
+ NeedSend := NeedSend or (Obj.X <> Obj.oldX) or (Obj.Y <> Obj.oldY);
+
if gTime mod (GAME_TICK*2) <> 0 then Continue;
// Ñîïðîòèâëåíèå âîçäóõà
if gTime mod (GAME_TICK*2) <> 0 then Continue;
// Ñîïðîòèâëåíèå âîçäóõà
Result := Result + 1;
end;
Result := Result + 1;
end;
+function g_Map_GetRandomPointType(): Byte;
+begin
+ if RespawnPoints = nil then
+ Result := 255
+ else
+ Result := RespawnPoints[Random(Length(RespawnPoints))].PointType;
+end;
+
function g_Map_HaveFlagPoints(): Boolean;
begin
Result := (FlagPoints[FLAG_RED] <> nil) and (FlagPoints[FLAG_BLUE] <> nil);
function g_Map_HaveFlagPoints(): Boolean;
begin
Result := (FlagPoints[FLAG_RED] <> nil) and (FlagPoints[FLAG_BLUE] <> nil);
Direction := FlagPoints[Flag]^.Direction;
State := FLAG_STATE_NORMAL;
end;
Direction := FlagPoints[Flag]^.Direction;
State := FLAG_STATE_NORMAL;
end;
+ Obj.oldX := Obj.X;
+ Obj.oldY := Obj.Y;
+ NeedSend := False; // the event will take care of this
Count := -1;
end;
end;
Count := -1;
end;
end;
procedure g_Map_DrawFlags();
var
i, dx: Integer;
procedure g_Map_DrawFlags();
var
i, dx: Integer;
+ tx, ty: Integer;
Mirror: TMirrorType;
begin
if gGameSettings.GameMode <> GM_CTF then
Mirror: TMirrorType;
begin
if gGameSettings.GameMode <> GM_CTF then
if State = FLAG_STATE_NONE then
continue;
if State = FLAG_STATE_NONE then
continue;
+ Obj.lerp(gLerpFactor, tx, ty);
+
if Direction = TDirection.D_LEFT then
begin
Mirror := TMirrorType.Horizontal;
if Direction = TDirection.D_LEFT then
begin
Mirror := TMirrorType.Horizontal;
dx := 1;
end;
dx := 1;
end;
- Animation.Draw(Obj.X+dx, Obj.Y+1, Mirror);
+ Animation.Draw(tx+dx, ty+1, Mirror);
if g_debug_Frames then
begin
if g_debug_Frames then
begin
if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
begin
// Î÷êè Êðàñíîé êîìàíäû
if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
begin
// Î÷êè Êðàñíîé êîìàíäû
- utils.writeInt(st, SmallInt(gTeamStat[TEAM_RED].Goals));
+ utils.writeInt(st, SmallInt(gTeamStat[TEAM_RED].Score));
// Î÷êè Ñèíåé êîìàíäû
// Î÷êè Ñèíåé êîìàíäû
- utils.writeInt(st, SmallInt(gTeamStat[TEAM_BLUE].Goals));
+ utils.writeInt(st, SmallInt(gTeamStat[TEAM_BLUE].Score));
end;
///// /////
end;
end;
///// /////
end;
if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
begin
// Î÷êè Êðàñíîé êîìàíäû
if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
begin
// Î÷êè Êðàñíîé êîìàíäû
- gTeamStat[TEAM_RED].Goals := utils.readSmallInt(st);
+ gTeamStat[TEAM_RED].Score := utils.readSmallInt(st);
// Î÷êè Ñèíåé êîìàíäû
// Î÷êè Ñèíåé êîìàíäû
- gTeamStat[TEAM_BLUE].Goals := utils.readSmallInt(st);
+ gTeamStat[TEAM_BLUE].Score := utils.readSmallInt(st);
end;
///// /////
end;
end;
///// /////
end;