DEADSOFTWARE

simplified trigger loading code
[d2df-sdl.git] / src / shared / MAPDEF.pas
index 4f4a3cdd0859e2d07c7c9bef845684be16b5cd8f..53bedb79b1c329fa632fee6755cd1a82312133e6 100644 (file)
@@ -72,11 +72,8 @@ type
 
     function getPanelByIdx (idx: Integer): TDynRecord; inline;
 
-    function getPanelId (): Integer; inline;
-    //procedure setPanelId (v: Integer); inline;
-
     function getTexturePanel (): Integer; inline;
-    //procedure setTexturePanel (v: Integer); inline;
+    function getTexturePanelRec (): TDynRecord; inline;
 
     function getPanelIndex (pan: TDynRecord): Integer;
 
@@ -143,6 +140,7 @@ type
     {$INCLUDE mapdef_help.inc}
     function trigMonsterId (): Integer; inline;
     function trigPanelId (): Integer; inline; // panel index in list
+    function trigPanelRec (): TDynRecord; inline;
 
   private
     // user fields
@@ -156,9 +154,10 @@ 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 TexturePanel: Integer read getTexturePanel {write setTexturePanel}; // texturepanel, int
+    property tgPanelId: Integer read trigPanelId;
+    property tgPanelRec: TDynRecord read trigPanelRec;
+    property TexturePanelId: Integer read getTexturePanel; // texturepanel, int
+    property TexturePanelRec: TDynRecord read getTexturePanelRec;
     // user fields
     property userPanelId: Integer read getUserPanelId write setUserPanelId;
     property userPanelTrigRef: Boolean read getUserTrigRef write setUserTrigRef;
@@ -187,7 +186,7 @@ var
 begin
   fld := field['userPanelId'];
   //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.varvalue);
+  if (fld = nil) then result := -1 else result := Integer(fld.value);
 end;
 
 
@@ -202,7 +201,7 @@ var
   fld: TDynField;
 begin
   fld := field['userPanelTrigRef'];
-  if (fld = nil) then result := false else result := Boolean(fld.varvalue);
+  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;
 
@@ -245,8 +244,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;
 
 
@@ -255,8 +254,8 @@ 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;
 
@@ -266,8 +265,8 @@ 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 <> TSize) and (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 <> 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;
 
@@ -277,7 +276,7 @@ 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;
 
 
@@ -292,7 +291,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;
@@ -328,22 +327,66 @@ begin
   if (fld <> nil) then result := fld.recref else result := nil;
 end;
 
-
 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;
 
+function TDynRecordHelper.trigPanelRec (): TDynRecord; inline;
+var
+  fld: TDynField;
+begin
+  result := nil;
+  fld := field['panelid'];
+  if (fld = nil) then exit;
+  if (fld.baseType <> TDynField.TType.TInt) then exit;
+  result := fld.recref;
+  if (result <> nil) and (result.typeName <> 'panel') then result := nil;
+end;
 
 // panel index in list
 function TDynRecordHelper.trigPanelId (): Integer; inline;
 var
   fld: TDynField;
 begin
-  fld := getFieldWithType('panelid', TDynField.TType.TInt);
+  result := -1;
+  fld := field['panelid'];
+  if (fld = nil) then exit;
+  if (fld.baseType <> TDynField.TType.TInt) then exit;
+  if (fld.recref = nil) then exit;
+  if (fld.recref.typeName <> 'panel') then exit;
+  result := fld.recrefIndex;
+end;
+
+function TDynRecordHelper.getTexturePanelRec (): TDynRecord;
+var
+  fld: TDynField;
+begin
+  result := nil;
+  fld := field['texture_panel'];
+  if (fld = nil) then exit;
+  if (fld.baseType <> TDynField.TType.TInt) then exit;
+  result := fld.recref;
+  if (result <> nil) and (result.typeName <> 'panel') then result := nil;
+end;
+
+function TDynRecordHelper.getTexturePanel (): Integer;
+var
+  fld: TDynField;
+begin
+  result := -1;
+  fld := field['texture_panel'];
+  if (fld = nil) then exit;
+  if (fld.baseType <> TDynField.TType.TInt) then exit;
+  if (fld.recref = nil) then exit;
+  if (fld.recref.typeName <> 'panel') then exit;
   result := fld.recrefIndex;
 end;
 
@@ -374,9 +417,6 @@ function TDynRecordHelper.TriggerType (): Byte; inline; begin result := Byte(get
 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('texture_panel', TDynField.TType.TInt).recrefIndex; end;
-
 {$INCLUDE mapdef_impl.inc}