DEADSOFTWARE

mplat: some code for moving "steps"
[d2df-sdl.git] / src / game / g_map.pas
index 577891f59bbd8ef187dfa536aa3b2406b22a8bdb..bbf39cb5efb7bad44613c76d9352e0cb2655b37b 100644 (file)
@@ -125,6 +125,12 @@ procedure g_Map_ProfilersEnd ();
 
 function g_Map_ParseMap (data: Pointer; dataLen: Integer): TDynRecord;
 
+
+function g_Map_MinX (): Integer; inline;
+function g_Map_MinY (): Integer; inline;
+function g_Map_MaxX (): Integer; inline;
+function g_Map_MaxY (): Integer; inline;
+
 const
   NNF_NO_NAME         = 0;
   NNF_NAME_BEFORE     = 1;
@@ -183,6 +189,9 @@ const
   GridTagLift = 1 shl 8; // gLifts
   GridTagBlockMon = 1 shl 9; // gBlockMon
 
+  GridTagObstacle = (GridTagStep or GridTagWall or GridTagDoor);
+  GridTagLiquid = (GridTagAcid1 or GridTagAcid2 or GridTagWater);
+
   GridDrawableMask = (GridTagBack or GridTagStep or GridTagWall or GridTagDoor or GridTagAcid1 or GridTagAcid2 or GridTagWater or GridTagFore);
 
 
@@ -253,10 +262,18 @@ begin
 end;
 
 
+// ////////////////////////////////////////////////////////////////////////// //
+function g_Map_MinX (): Integer; inline; begin if (mapGrid <> nil) then result := mapGrid.gridX0 else result := 0; end;
+function g_Map_MinY (): Integer; inline; begin if (mapGrid <> nil) then result := mapGrid.gridY0 else result := 0; end;
+function g_Map_MaxX (): Integer; inline; begin if (mapGrid <> nil) then result := mapGrid.gridX0+mapGrid.gridWidth-1 else result := 0; end;
+function g_Map_MaxY (): Integer; inline; begin if (mapGrid <> nil) then result := mapGrid.gridY0+mapGrid.gridHeight-1 else result := 0; end;
+
+
 // ////////////////////////////////////////////////////////////////////////// //
 var
   dfmapdef: TDynMapDef = nil;
 
+
 procedure loadMapDefinition ();
 var
   pr: TTextParser = nil;
@@ -264,13 +281,15 @@ var
   WAD: TWADFile = nil;
 begin
   if (dfmapdef <> nil) then exit;
+
   try
     e_LogWritefln('parsing "mapdef.txt"...', []);
     st := openDiskFileRO(DataDir+'mapdef.txt');
+    e_LogWritefln('found local "%smapdef.txt"', [DataDir]);
   except
     st := nil;
-    e_LogWritefln('local "%smapdef.txt" not found', [DataDir]);
   end;
+
   if (st = nil) then
   begin
     WAD := TWADFile.Create();
@@ -285,15 +304,22 @@ begin
     end;
   end;
 
-  if (st = nil) then
-  begin
-    //raise Exception.Create('cannot open "mapdef.txt"');
-    e_LogWritefln('using default "mapdef.txt"...', [], MSG_WARNING);
-    pr := TStrTextParser.Create(defaultMapDef);
-  end
-  else
-  begin
-    pr := TFileTextParser.Create(st);
+  try
+    if (st = nil) then
+    begin
+      //raise Exception.Create('cannot open "mapdef.txt"');
+      e_LogWriteln('using default "mapdef.txt"...');
+      pr := TStrTextParser.Create(defaultMapDef);
+    end
+    else
+    begin
+      pr := TFileTextParser.Create(st);
+    end;
+  except on e: Exception do
+    begin
+      e_LogWritefln('something is VERY wrong here! -- ', [e.message]);
+      raise;
+    end;
   end;
 
   try
@@ -315,6 +341,8 @@ var
 begin
   result := nil;
   if (dataLen < 4) then exit;
+
+  if (dfmapdef = nil) then writeln('need to load mapdef');
   loadMapDefinition();
   if (dfmapdef = nil) then raise Exception.Create('internal map loader error');
 
@@ -324,6 +352,7 @@ begin
   begin
     // binary map
     try
+      //e_LogWriteln('parsing binary map...');
       result := dfmapdef.parseBinMap(wst);
     except on e: Exception do
       begin
@@ -340,10 +369,11 @@ begin
     // text map
     pr := TFileTextParser.Create(wst);
     try
+      //e_LogWriteln('parsing text map...');
       result := dfmapdef.parseMap(pr);
     except on e: Exception do
       begin
-        if (pr <> nil) then e_LogWritefln('ERROR at (%s,%s): %s', [pr.line, pr.col, e.message])
+        if (pr <> nil) then e_LogWritefln('ERROR at (%s,%s): %s', [pr.tokLine, pr.tokCol, e.message])
         else e_LogWritefln('ERROR: %s', [e.message]);
         pr.Free(); // will free `wst`
         result := nil;
@@ -352,6 +382,7 @@ begin
     end;
     pr.Free(); // will free `wst`
   end;
+  //e_LogWriteln('map parsed.');
 end;
 
 
@@ -1297,7 +1328,7 @@ begin
     end
     else
     begin
-      trigData := Trigger.trigRec.clone();
+      trigData := Trigger.trigRec.clone(nil);
     end;
   end;
 
@@ -1646,6 +1677,12 @@ begin
 
     FreeMem(Data);
 
+    if (mapReader = nil) then
+    begin
+      e_LogWritefln('invalid map file: ''%s''', [mapResName]);
+      exit;
+    end;
+
     generateExternalResourcesList(mapReader);
     mapTextureList := mapReader['texture'];
     // get all other lists here too
@@ -2187,10 +2224,14 @@ begin
     mapReader := g_Map_ParseMap(Data, Len);
   except
     mapReader := nil;
+    FreeMem(Data);
+    exit;
   end;
 
   FreeMem(Data);
 
+  if (mapReader = nil) then exit;
+
   if (mapReader.Width > 0) and (mapReader.Height > 0) then
   begin
     Result.Name := mapReader.MapName;
@@ -2397,6 +2438,8 @@ var
   end;
 
 begin
+  if g_dbgpan_mplat_step then g_dbgpan_mplat_active := true;
+
   UpdatePanelArray(gWalls);
   UpdatePanelArray(gRenderBackgrounds);
   UpdatePanelArray(gRenderForegrounds);
@@ -2405,6 +2448,8 @@ begin
   UpdatePanelArray(gAcid2);
   UpdatePanelArray(gSteps);
 
+  if g_dbgpan_mplat_step then begin g_dbgpan_mplat_step := false; g_dbgpan_mplat_active := false; end;
+
   if gGameSettings.GameMode = GM_CTF then
   begin
     for a := FLAG_RED to FLAG_BLUE do
@@ -2450,7 +2495,7 @@ begin
               if j > High(gPlayers) then j := 0;
               if gPlayers[j] <> nil then
               begin
-                if gPlayers[j].Live and g_Obj_Collide(@Obj, @gPlayers[j].Obj) then
+                if gPlayers[j].alive and g_Obj_Collide(@Obj, @gPlayers[j].Obj) then
                 begin
                   if gPlayers[j].GetFlag(a) then Break;
                 end;