DEADSOFTWARE

trigger data now cached on map loading (so it should be as fast as the previous trigg...
[d2df-sdl.git] / src / shared / MAPDEF.pas
index d22e73f60a6f77aaf4a501e1a2d0cc2c948a40ba..9875fa1fd26aa35501d8ee4609f9ddeec47113e2 100644 (file)
@@ -40,6 +40,19 @@ type
 
   public
     constructor Create (ax, ay: LongInt);
+
+    function isZero (): Boolean; inline;
+  end;
+
+  TDFSize = packed record
+  public
+    w, h: LongInt;
+
+  public
+    constructor Create (aw, ah: LongInt);
+
+    function isZero (): Boolean; inline;
+    function isValid (): Boolean; inline;
   end;
 
   Char16     = packed array[0..15] of Char;
@@ -59,7 +72,7 @@ type
 
     function getPanelByIdx (idx: Integer): TDynRecord; inline;
 
-    function getPanelId (): Integer; inline;
+    //function getPanelId (): Integer; inline;
     //procedure setPanelId (v: Integer); inline;
 
     function getTexturePanel (): Integer; inline;
@@ -68,6 +81,7 @@ type
     function getPanelIndex (pan: TDynRecord): Integer;
 
     function getPointField (const aname: AnsiString): TDFPoint; inline;
+    function getSizeField (const aname: AnsiString): TDFSize; inline;
 
   public
     function panelCount (): Integer; inline;
@@ -90,6 +104,18 @@ type
     function Alpha (): Byte; inline;
     function Flags (): Byte; inline;
 
+    function moveSpeed (): TDFPoint; inline;
+    function moveStart (): TDFPoint; inline;
+    function moveEnd (): TDFPoint; inline;
+
+    function moveOnce (): Boolean; inline;
+
+    function sizeSpeed (): TDFSize; inline;
+    function sizeEnd (): TDFSize; inline;
+
+    function endPosTrig (): Integer; inline;
+    function endSizeTrig (): Integer; inline;
+
     // texture
     function Resource (): AnsiString; inline;
     function Anim (): Boolean; inline;
@@ -116,6 +142,7 @@ type
 
     {$INCLUDE mapdef_help.inc}
     function trigMonsterId (): Integer; inline;
+    function trigPanelId (): Integer; inline; // panel index in list
 
   private
     // user fields
@@ -129,8 +156,8 @@ type
     property panel[idx: Integer]: TDynRecord read getPanelByIdx;
     property panelIndex[pan: TDynRecord]: Integer read getPanelIndex;
     // triggers
-    property tgPanelID: Integer read getPanelId {write setPanelId};
-    property tgShotPanelID: Integer read getPanelId {write setPanelId};
+    property tgPanelID: Integer read trigPanelId {write setPanelId};
+    property tgShotPanelID: Integer read trigPanelId {write setPanelId};
     property TexturePanel: Integer read getTexturePanel {write setTexturePanel}; // texturepanel, int
     // user fields
     property userPanelId: Integer read getUserPanelId write setUserPanelId;
@@ -145,6 +172,12 @@ uses
 
 // ////////////////////////////////////////////////////////////////////////// //
 constructor TDFPoint.Create (ax, ay: LongInt); begin X := ax; Y := ay; end;
+function TDFPoint.isZero (): Boolean; inline; begin result := (X = 0) and (Y = 0); end;
+
+
+constructor TDFSize.Create (aw, ah: LongInt); begin w := aw; h := ah; end;
+function TDFSize.isZero (): Boolean; inline; begin result := (w = 0) and (h = 0); end;
+function TDFSize.isValid (): Boolean; inline; begin result := (w > 0) and (h > 0); end;
 
 
 // ////////////////////////////////////////////////////////////////////////// //
@@ -153,13 +186,14 @@ var
   fld: TDynField;
 begin
   fld := field['userPanelId'];
-  if (fld = nil) or (fld.baseType <> TDynField.TType.TInt) then result := -1 else result := fld.ival;
+  //if (fld = nil) or (fld.baseType <> TDynField.TType.TInt) then result := -1 else result := fld.ival;
+  if (fld = nil) then result := -1 else result := Integer(fld.value);
 end;
 
 
 procedure TDynRecordHelper.setUserPanelId (v: Integer); inline;
 begin
-  setUserField('userPanelId', Integer(v));
+  user['userPanelId'] := v;
 end;
 
 
@@ -168,13 +202,42 @@ var
   fld: TDynField;
 begin
   fld := field['userPanelTrigRef'];
-  if (fld = nil) or (fld.baseType <> TDynField.TType.TBool) then result := false else result := (fld.ival <> 0);
+  if (fld = nil) then result := false else result := Boolean(fld.value);
+  //if (fld = nil) or (fld.baseType <> TDynField.TType.TBool) then result := false else result := (fld.ival <> 0);
 end;
 
 
 procedure TDynRecordHelper.setUserTrigRef (v: Boolean); inline;
 begin
-  setUserField('userPanelTrigRef', v);
+  user['userPanelTrigRef'] := v;
+end;
+
+
+// ////////////////////////////////////////////////////////////////////////// //
+function TDynRecordHelper.moveSpeed (): TDFPoint; inline; begin result := getPointField('move_speed'); end;
+function TDynRecordHelper.moveStart (): TDFPoint; inline; begin result := getPointField('move_start'); end;
+function TDynRecordHelper.moveEnd (): TDFPoint; inline; begin result := getPointField('move_end'); end;
+
+function TDynRecordHelper.sizeSpeed (): TDFSize; inline; begin result := getSizeField('size_speed'); end;
+function TDynRecordHelper.sizeEnd (): TDFSize; inline; begin result := getSizeField('size_end'); end;
+
+function TDynRecordHelper.moveOnce (): Boolean; inline; begin result := (getFieldWithType('move_once', TDynField.TType.TBool).ival <> 0); end;
+
+
+function TDynRecordHelper.endPosTrig (): Integer; inline;
+var
+  fld: TDynField;
+begin
+  fld := getFieldWithType('end_pos_trigger', TDynField.TType.TInt);
+  result := fld.recrefIndex;
+end;
+
+function TDynRecordHelper.endSizeTrig (): Integer; inline;
+var
+  fld: TDynField;
+begin
+  fld := getFieldWithType('end_size_trigger', TDynField.TType.TInt);
+  result := fld.recrefIndex;
 end;
 
 
@@ -182,8 +245,8 @@ end;
 function TDynRecordHelper.getFieldWithType (const aname: AnsiString; atype: TDynField.TType): TDynField; inline;
 begin
   result := field[aname];
-  if (result = nil) then raise Exception.Create(Format('field ''%s'' not found in record ''%s'' of type ''%s''', [aname, name, id]));
-  if (result.baseType <> atype) then raise Exception.Create(Format('field ''%s'' in record ''%s'' of type ''%s'' has invalid data type', [aname, name, id]));
+  if (result = nil) then raise Exception.Create(Format('field ''%s'' not found in record ''%s'' of type ''%s''', [aname, typeName, id]));
+  if (result.baseType <> atype) then raise Exception.Create(Format('field ''%s'' in record ''%s'' of type ''%s'' has invalid data type', [aname, typeName, id]));
 end;
 
 
@@ -192,18 +255,29 @@ var
   fld: TDynField;
 begin
   fld := field[aname];
-  if (fld = nil) then raise Exception.Create(Format('field ''%s'' not found in record ''%s'' of type ''%s''', [aname, name, id]));
-  if (fld.baseType <> TPoint) then raise Exception.Create(Format('field ''%s'' in record ''%s'' of type ''%s'' has invalid data type', [aname, name, id]));
+  if (fld = nil) then raise Exception.Create(Format('field ''%s'' not found in record ''%s'' of type ''%s''', [aname, typeName, id]));
+  if (fld.baseType <> TPoint) then raise Exception.Create(Format('field ''%s'' in record ''%s'' of type ''%s'' has invalid data type', [aname, typeName, id]));
   result := TDFPoint.Create(fld.ival, fld.ival2);
 end;
 
 
+function TDynRecordHelper.getSizeField (const aname: AnsiString): TDFSize; inline;
+var
+  fld: TDynField;
+begin
+  fld := field[aname];
+  if (fld = nil) then raise Exception.Create(Format('field ''%s'' not found in record ''%s'' of type ''%s''', [aname, typeName, id]));
+  if (fld.baseType <> TSize) and (fld.baseType <> TPoint) then raise Exception.Create(Format('field ''%s'' in record ''%s'' of type ''%s'' has invalid data type', [aname, typeName, id]));
+  result := TDFSize.Create(fld.ival, fld.ival2);
+end;
+
+
 function TDynRecordHelper.getPanelByIdx (idx: Integer): TDynRecord; inline;
 var
   fld: TDynField;
 begin
   fld := headerRec['panel'];
-  if (fld <> nil) then result := fld.item[idx] else result := nil;
+  if (fld <> nil) then result := fld.itemAt[idx] else result := nil;
 end;
 
 
@@ -218,7 +292,7 @@ begin
     fld := headerRec['panel'];
     if (fld <> nil) then
     begin
-      for f := 0 to fld.count-1 do if (fld.item[f] = pan) then begin result := f; exit; end;
+      for f := 0 to fld.count-1 do if (fld.itemAt[f] = pan) then begin result := f; exit; end;
     end;
   end;
 end;
@@ -259,7 +333,25 @@ function TDynRecordHelper.trigMonsterId (): Integer; inline;
 var
   fld: TDynField;
 begin
-  fld := getFieldWithType('monsterid', TDynField.TType.TInt);
+  result := -1;
+  fld := field['monsterid'];
+  if (fld = nil) then exit;
+  if (fld.baseType <> TDynField.TType.TInt) then exit;
+  if (fld.recref = nil) then exit;
+  result := fld.recrefIndex;
+end;
+
+
+// panel index in list
+function TDynRecordHelper.trigPanelId (): Integer; inline;
+var
+  fld: TDynField;
+begin
+  result := -1;
+  fld := field['panelid'];
+  if (fld = nil) then exit;
+  if (fld.baseType <> TDynField.TType.TInt) then exit;
+  if (fld.recref = nil) then exit;
   result := fld.recrefIndex;
 end;
 
@@ -287,11 +379,11 @@ function TDynRecordHelper.Direction (): Byte; inline; begin result := Byte(getFi
 function TDynRecordHelper.AreaType (): Byte; inline; begin result := Byte(getFieldWithType('type', TDynField.TType.TUByte).ival); end;
 function TDynRecordHelper.Enabled (): Boolean; inline; begin result := (getFieldWithType('enabled', TDynField.TType.TBool).ival <> 0); end;
 function TDynRecordHelper.TriggerType (): Byte; inline; begin result := Byte(getFieldWithType('type', TDynField.TType.TUByte).ival); end;
-function TDynRecordHelper.ActivateType (): Byte; inline; begin result := Byte(getFieldWithType('activatetype', TDynField.TType.TUByte).ival); end;
+function TDynRecordHelper.ActivateType (): Byte; inline; begin result := Byte(getFieldWithType('activate_type', TDynField.TType.TUByte).ival); end;
 function TDynRecordHelper.Keys (): Byte; inline; begin result := Byte(getFieldWithType('keys', TDynField.TType.TUByte).ival); end;
 
-function TDynRecordHelper.getPanelId (): Integer; inline; begin result := getFieldWithType('panelid', TDynField.TType.TInt).recrefIndex; end;
-function TDynRecordHelper.getTexturePanel (): Integer; begin result := getFieldWithType('texturepanel', TDynField.TType.TInt).recrefIndex; end;
+//function TDynRecordHelper.getPanelId (): Integer; inline; begin result := getFieldWithType('panelid', TDynField.TType.TInt).recrefIndex; end;
+function TDynRecordHelper.getTexturePanel (): Integer; begin result := getFieldWithType('texture_panel', TDynField.TType.TInt).recrefIndex; end;
 
 {$INCLUDE mapdef_impl.inc}