euphemism

Object DTM Generation Tool

Jan 16th, 2012
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Program ObjectDTMGenerationTool;
  2. //{$DEFINE SMART}
  3. {$i SRL\SRL.simba}
  4. {$i ObjectDTM\ObjDTMInclude.simba}
  5.  
  6. var
  7.   CleanMap, CurrentMap, I, X, Y: Integer;
  8.  
  9.   SubPoints: TPointArray;
  10.   Objects: MMObjArray;
  11.   ObjectDTM: ObjDTM;
  12.  
  13.   PageControl: TPageControl;
  14.   TabSheet: Array [0..3] of TTabSheet;
  15.  
  16.   PropertiesControl: TPageControl;
  17.   PropertySheet: Array [0..2] of TTabSheet;
  18.   PropertyPanel: TPanel;
  19.  
  20.   ToolForm: TForm;
  21.   MMap: TImage;
  22.   ObjectsList: TListBox;
  23.   Instructions: TListBox;
  24.   Output: TMemo;
  25.   MainFormButtons: Array [0..1] of TButton;
  26.   SubPointButtons: Array [0..3] of TButton;
  27.  
  28. procedure DeclarePlayers;
  29. begin
  30.  
  31.   HowManyPlayers := 1;
  32.   CurrentPlayer := 0;
  33.   SetLength(Players, HowManyPlayers);
  34.  
  35.   Players[0].Name := '';
  36.   Players[0].Pass := '';
  37.   Players[0].Member := False;
  38.   Players[0].Active := True;
  39. end;
  40.  
  41. procedure DrawDotsEx(pixels: TPointArray; color: Integer);
  42. {:: Author: Sir R. Magician ::}
  43. var
  44.   i : integer;
  45. begin
  46.  
  47.   MMap.Canvas.Pen.Color := color;
  48.  
  49.   for i:= 0 to high(pixels) do
  50.   begin
  51.  
  52.     MMap.canvas.moveto(pixels[i].x,pixels[i].y);
  53.     MMap.canvas.LineTo(pixels[i].x+1,pixels[i].y);
  54.   end;
  55. end;
  56.  
  57. procedure DrawLine(TP1, TP2: TPoint; Color: TColor);
  58. {:: Author: mormonman ::}
  59. begin
  60.  
  61.   MMap.canvas.Pen.Color := Color;
  62.  
  63.   MMap.canvas.moveto(TP1.x,TP1.y);
  64.   MMap.canvas.LineTo(TP2.x,TP2.y);
  65. end;
  66.  
  67. procedure DrawCircle(Center: TPoint; Radius: Integer; Fill: Boolean; Color: TColor);
  68. {:: Author: mormonman ::}
  69. var
  70.   TPA: TPointArray;
  71. begin
  72.   TPA := TPAFromBox(IntToBox(Center.X - Radius, Center.Y - Radius, Center.X + Radius, Center.Y + Radius));
  73.   FilterPointsPie(TPA, 0, 360, -1, Radius, Center.X, Center.Y);
  74.  
  75.   if (not Fill) then
  76.     FilterPointsDist(TPA, Radius-1, Radius, Center.X, Center.Y);
  77.  
  78.   if (Length(TPA) >= 1) then
  79.     DrawDotsEx(TPA, Color);
  80. end;
  81.  
  82. procedure DrawPolygons(Polygons: T2DPointArray; color: TColor);
  83. {:: Author: mormonman ::}
  84. var
  85.   i, h, Hi: Integer;
  86. begin
  87.  
  88.   if (Length(Polygons) < 1) then
  89.     Exit;
  90.  
  91.   for h := 0 to High(Polygons) do
  92.   begin
  93.     Hi := High(Polygons[h]);
  94.     if (Hi < 2) then Exit;
  95.  
  96.     for i := 0 to Hi - 1 do
  97.       DrawLine(Polygons[h][i], Polygons[h][i+1], color);
  98.  
  99.     DrawLine(Polygons[h][Hi], Polygons[h][0], color);
  100.   end;
  101. end;
  102.  
  103. procedure GatherMiniMap;
  104. var
  105.   I: Integer;
  106.   TIA: TIntegerArray;
  107.   TPA: TPointArray;
  108. begin
  109.  
  110.   TPA := TPAFromBox(IntToBox(548, 6, 708, 166));
  111.   FilterPointsPie(TPA, 0, 360, 0, 80, MMCX, MMCY);
  112.  
  113.   TIA := GetColors(TPA);
  114.   OffsetTPA(TPA, IntToPoint(-548, -6));
  115.  
  116.   FastSetPixels(CleanMap, TPA, TIA);
  117.   FastSetPixels(CurrentMap, TPA, TIA);
  118.  
  119.   DrawBitmap(CleanMap, MMap.Canvas, 0, 0);
  120.  
  121.   for I := 0 to High(SubPoints) do
  122.     DrawCircle(SubPoints[i], 7, False, clLime);
  123. end;
  124.  
  125. procedure GatherObject;
  126. var
  127.   I: Integer;
  128.   Name: String;
  129.   Points: String;
  130.   ObjectsTPA: TPointArray;
  131. begin
  132.  
  133.   case ObjectsList.ItemIndex of
  134.  
  135.    -1: Name := 'invalid';
  136.     0: Name := 'ladders';
  137.     1: Name := 'trees';
  138.     2: Name := 'dead trees';
  139.     3: Name := 'plants';
  140.     4: Name := 'flax';
  141.     5: Name := 'boulders';
  142.     6: Name := 'henges';
  143.     7: Name := 'cacti';
  144.     8: Name := 'maple trees';
  145.     9: Name := 'rocks';
  146.   end;
  147.  
  148.   if (Name = 'invalid') then
  149.   begin
  150.  
  151.     WriteLn('You have passed an ' + name + ' index to the finding function, please select an object first.');
  152.     Exit;
  153.   end;
  154.  
  155.   ObjectsTPA := FindMiniMapObj(MMObjRecords[ObjectsList.ItemIndex]);
  156.  
  157.   SetLength(Objects, Length(ObjectsTPA));
  158.   OffsetTPA(ObjectsTPA, IntToPoint(-548, -6));
  159.  
  160.   DrawBitmap(CleanMap, MMap.Canvas, 0, 0);
  161.  
  162.   for I := 0 to (Length(ObjectsTPA) - 1) do
  163.   begin
  164.  
  165.     DrawCircle(ObjectsTPA[i], 7, False, clWhite);
  166.  
  167.     Points := Points + '(' + IntToStr(ObjectsTPA[i].x) + ', ' + IntToStr(ObjectsTPA[i].y) + '), ';
  168.     Objects[i].Center := ObjectsTPA[i];
  169.     Objects[i].ObjType := ObjectsList.ItemIndex;
  170.   end;
  171.  
  172.   for I := 0 to High(SubPoints) do
  173.     DrawCircle(SubPoints[i], 7, False, clLime);
  174.  
  175.   Output.Clear;
  176.   Output.Lines.Add(Points);
  177. end;
  178.  
  179. procedure SubPointManager;
  180. begin
  181.  
  182.   for I := 0 to High(Objects) do
  183.   begin
  184.  
  185.     if InCircle(X, Y, Objects[i].Center.x, Objects[i].Center.y, 7) then
  186.     begin
  187.  
  188.       if (not PointInTPA(Objects[i].Center, SubPoints)) then
  189.       begin
  190.  
  191.         Inc(ObjectDTM.NumOfPoints);
  192.  
  193.         SetLength(ObjectDTM.SubPoints, ObjectDTM.NumOfPoints);
  194.         SetLength(SubPoints, ObjectDTM.NumOfPoints);
  195.  
  196.         ObjectDTM.SubPoints[(ObjectDTM.NumOfPoints) - 1].Base := Objects[i].ObjType;
  197.         ObjectDTM.SubPoints[(ObjectDTM.NumOfPoints) - 1].Point := Objects[i].Center;
  198.         ObjectDTM.SubPoints[(ObjectDTM.NumOfPoints) - 1].Drift := 7;
  199.  
  200.         SubPoints[(ObjectDTM.NumOfPoints) - 1] := Objects[i].Center;
  201.  
  202.         DrawCircle(SubPoints[(ObjectDTM.NumOfPoints) - 1], 7, False, clLime);
  203.         Exit;
  204.       end else
  205.         Continue;
  206.     end;
  207.   end;
  208.  
  209.   for I := 0 to (ObjectDTM.NumOfPoints - 1) do
  210.   begin
  211.  
  212.     if (not InCircle(X, Y, SubPoints[i].x, SubPoints[i].y, 7)) then
  213.       Continue;
  214.  
  215.     DrawCircle(SubPoints[i], 7, False, clRed);
  216.  
  217.     ObjectDTM.SubPoints[i].Base := ObjectDTM.SubPoints[(ObjectDTM.NumOfPoints) - 1].Base;
  218.     ObjectDTM.SubPoints[i].Point := ObjectDTM.SubPoints[(ObjectDTM.NumOfPoints) - 1].Point;
  219.     ObjectDTM.SubPoints[i].Drift := ObjectDTM.SubPoints[(ObjectDTM.NumOfPoints) - 1].Drift;
  220.  
  221.  
  222.     SubPoints[i] := SubPoints[(ObjectDTM.NumOfPoints) - 1];
  223.  
  224.     ObjectDTM.NumOfPoints := (ObjectDTM.NumOfPoints) - 1;
  225.  
  226.     SetLength(SubPoints, ObjectDTM.NumOfPoints);
  227.     SetLength(ObjectDTM.SubPoints, ObjectDTM.NumOfPoints);
  228.   end;
  229. end;
  230.  
  231. procedure AreaManager;
  232. begin
  233.     {
  234.   with Buttons[0] do
  235.   begin
  236.  
  237.     Caption := 'grab minimap';
  238.     OnClick := @MouseClick;
  239.   end;
  240.  
  241.   with Buttons[1] do
  242.   begin
  243.  
  244.     Caption := 'gather object';
  245.     OnClick := @MouseClick;
  246.   end;
  247.  
  248.   with Buttons[2] do
  249.   begin
  250.  
  251.     Caption := 'add area polygon';
  252.     OnClick := @MouseClick;
  253.   end;
  254.  
  255.   with Buttons[3] do
  256.   begin
  257.  
  258.     Caption := 'print object dtm';
  259.     OnClick := @MouseClick;
  260.   end;
  261.   }
  262. end;
  263.  
  264. procedure MainPointManager(Click: Boolean);
  265. begin
  266.  
  267.   DrawBitmap(CleanMap, MMap.Canvas, 0, 0);
  268.  
  269.   if Click then
  270.     ObjectDTM.MainPoint := IntToPoint(X, Y);
  271.  
  272.   for I := 0 to High(SubPoints) do
  273.   begin
  274.  
  275.     DrawCircle(SubPoints[i], 7, False, clLime);
  276.     DrawLine(ObjectDTM.MainPoint, SubPoints[i], clWhite);
  277.   end;
  278.  
  279.   for I := 0 to High(SubPoints) do
  280.     DrawLine(IntToPoint(X, Y), SubPoints[i], clYellow);
  281. end;
  282.  
  283. procedure PrintManager;
  284. var
  285.   ObjectDTMString: String;
  286. begin
  287.  
  288.   ObjectDTMString := ObjDTMToString(ObjectDTM);
  289.  
  290.   OutPut.LINES.Clear;
  291.   OutPut.LINES.Add(ObjectDTMString);
  292.  
  293.   ObjDTM_PrintToRec(ObjectDTMString);
  294.   Writeln('');
  295.   WriteLn(ObjectDTMString);
  296. end;
  297.  
  298. procedure MouseMove(Sender: TObject; S: TShiftState; mX, mY: Integer);
  299. begin
  300.  
  301.   X := mX;
  302.   Y := mY;
  303.  
  304.   case Sender of
  305.  
  306.     MMap:
  307.       begin
  308.  
  309.         if (PropertiesControl.ActivePageIndex = 1) then
  310.           MainPointManager(False);
  311.       end;
  312.   end;
  313. end;
  314.  
  315. procedure MouseClick(Sender: TObject);
  316. begin
  317.  
  318.   case Sender of
  319.  
  320.     MainFormButtons[0]: GatherMiniMap;
  321.     MainFormButtons[1]: PrintManager;
  322.  
  323.     SubPointButtons[0]: GatherObject;
  324.  
  325.     PropertiesControl:
  326.     begin
  327.  
  328.       case PropertiesControl.ActivePageIndex of
  329.  
  330.         0:
  331.         begin
  332.  
  333.           Instructions.Items.Clear;
  334.           Instructions.Items.Add('Instructions: Select an object from the list and click ' + #39 + 'gather object' + #39 + ' to display');
  335.           Instructions.Items.Add('all instances of that object on the minimap.');
  336.           Instructions.Items.Add('click within circles to add or remove sub-points.');
  337.         end;
  338.  
  339.         1:
  340.         begin
  341.  
  342.           Instructions.Items.Clear;
  343.           Instructions.Items.Add('Instructions: Displays current main-point of the Object DTM.');
  344.           Instructions.Items.Add('Mouse over a position and click to change the main-point.');
  345.         end;
  346.       end;
  347.     end;
  348.  
  349.     MMap:
  350.     begin
  351.  
  352.       case PropertiesControl.ActivePageIndex of
  353.  
  354.         0: SubPointManager;
  355.         1: MainPointManager(True);
  356.       end;
  357.     end;
  358.   end;
  359. end;
  360.  
  361. procedure ToolForm_Init;
  362. begin
  363.  
  364.   ToolForm := TForm.Create(nil);
  365.   MMap := TImage.Create(TabSheet[0]);
  366.   ObjectsList := TListBox.Create(TabSheet[0]);
  367.   Instructions := TListBox.Create(TabSheet[0]);
  368.   Output := TMemo.Create(TabSheet[0]);
  369.   PropertyPanel := TPanel.Create(TabSheet[0]);
  370.  
  371.   PageControl := TPageControl.Create(ToolForm);
  372.   PageControl.Parent := ToolForm;
  373.   PageControl.Width := 510;
  374.   PageControl.Height := 330;
  375.   PageControl.Caption := 'TabPageControl';
  376.  
  377.   PropertiesControl := TPageControl.Create(ToolForm);
  378.   PropertiesControl.Parent := PropertyPanel;
  379.   PropertiesControl.Width := 210;
  380.   PropertiesControl.Height := 160;
  381.   PropertiesControl.Caption := 'PropertyPageControl';
  382.   //PropertiesControl.OnChange := @MouseClick;
  383.   PropertiesControl.OnPageChanged := @MouseClick;
  384.  
  385.   for I := 0 to 3 do
  386.   begin
  387.  
  388.     TabSheet[I] := TTabSheet.Create(PageControl);
  389.     TabSheet[I].Parent := PageControl;
  390.     TabSheet[I].PageControl := PageControl;
  391.   end;
  392.  
  393.   TabSheet[0].Caption := 'single';
  394.   TabSheet[1].Caption := 'multi';
  395.   TabSheet[2].Caption := 'path';
  396.   TabSheet[3].Caption := 'multi-path';
  397.  
  398.   for I := 0 to 2 do
  399.   begin
  400.  
  401.     PropertySheet[I] := TTabSheet.Create(ToolForm);
  402.     PropertySheet[I].Parent := PropertyPanel;
  403.     PropertySheet[I].PageControl := PropertiesControl;
  404.   end;
  405.  
  406.   PropertySheet[0].Caption := 'sub-points';
  407.   PropertySheet[1].Caption := 'main-point';
  408.   PropertySheet[2].Caption := 'area';
  409.  
  410.   with PropertyPanel do
  411.   begin
  412.     Parent := TabSheet[0];
  413.     Left := 282;
  414.     Top := 10;
  415.     Caption := 'Object DTM Generation Tool  - by euphemism';
  416.     Width := 210;
  417.     Height := 160;
  418.   end;
  419.  
  420.   for I := 0 to 1 do
  421.   begin
  422.  
  423.     MainFormButtons[i] := TButton.Create(ToolForm);
  424.     MainFormButtons[i].Parent := ToolForm;
  425.     MainFormButtons[i].Width := 100;
  426.     MainFormButtons[i].Height := 30;
  427.     MainFormButtons[i].Top := 55 + (i * 34);
  428.     MainFormButtons[i].Left := 176;
  429.   end;
  430.  
  431.   with MainFormButtons[0] do
  432.   begin
  433.  
  434.     Caption := 'grab minimap';
  435.     OnClick := @MouseClick;
  436.   end;
  437.  
  438.   with MainFormButtons[1] do
  439.   begin
  440.  
  441.     Caption := 'print object dtm';
  442.     OnClick := @MouseClick;
  443.   end;
  444.  
  445.   with SubPointButtons[0] do
  446.   begin
  447.  
  448.     SubPointButtons[0] := TButton.Create(ToolForm);
  449.     Parent := PropertySheet[0];
  450.     Left := 102;
  451.     Top := 4;
  452.     Height := 30;
  453.     Width := 100;
  454.  
  455.     Caption := 'gather object';
  456.     OnClick := @MouseClick;
  457.   end;
  458.  
  459.   with ToolForm do
  460.   begin
  461.     Left := 430;
  462.     Top := 174;
  463.     Caption := 'Object DTM Generation Tool  - by euphemism';
  464.     ClientWidth := 510;
  465.     ClientHeight := 330;
  466.     Color := 15790320;
  467.   end;
  468.  
  469.   with MMap do
  470.   begin
  471.     Parent := TabSheet[0];
  472.     Left := 5;
  473.     Top := 10;
  474.     Width := 160;
  475.     Height := 160;
  476.     OnClick := @MouseClick;
  477.     OnMouseMove := @MouseMove;
  478.   end;
  479.  
  480.   with ObjectsList do
  481.   begin
  482.     Parent := PropertySheet[0];
  483.     Left := 0;
  484.     Top := 4;
  485.     Width := 100;
  486.     Height := 127;
  487.     ItemHeight := 13;
  488.     Items.Add('Ladders');
  489.     Items.Add('Trees');
  490.     Items.Add('Dead Trees');
  491.     Items.Add('Plants');
  492.     Items.Add('Flax');
  493.     Items.Add('Boulders');
  494.     Items.Add('Henges');
  495.     Items.Add('Cacti');
  496.     Items.Add('Maple Trees');
  497.     Items.Add('Rocks');
  498.   end;
  499.  
  500.   with Instructions do
  501.   begin
  502.     Parent := TabSheet[0];
  503.     Left := 10;
  504.     Top := 180;
  505.     Width := 480;
  506.     Height := 50;
  507.     Items.Add('Instructions: Click ' + #39 + 'grab minimap' + #39 + ' to grab the current map view.');
  508.     Items.Add('Select an object from the list and click ' + #39 + 'gather object' + #39 + ' to display');
  509.     Items.Add('all instances of that object on the minimap.');
  510.   end;
  511.  
  512.   with Output do
  513.   begin
  514.     Parent := TabSheet[0];
  515.     Color := 16777215;
  516.     Left := 10;
  517.     Top := 235;
  518.     Width := 480;
  519.     Height := 55;
  520.   end;
  521.  
  522.   CleanMap := BitmapFromString(160, 160, '');
  523.   CurrentMap := BitmapFromString(160, 160, '');
  524.  
  525.   FloodFillBitmap(CleanMap, IntToPoint(0, 0), 0, 16777215);
  526.   FloodFillBitmap(CurrentMap, IntToPoint(0, 0), 0, 16777215);
  527.  
  528.   SetBitmapName(CleanMap, 'Clean');
  529.   SetBitmapName(CurrentMap, 'Current');
  530.  
  531.   DrawBitmap(CleanMap, MMap.Canvas, 0, 0);
  532.  
  533.   SubPoints := LoadTextTPA('Click ' + #39 + 'grab minimap' + #39, 'SmallChars', I);
  534.   OffSetTPA(SubPoints, IntToPoint(28, 62));
  535.   DrawDotsEx(SubPoints, 000000001);
  536.  
  537.   SubPoints := LoadTextTPA('to get client image', 'SmallChars', I);
  538.   OffSetTPA(SubPoints, IntToPoint(31, 79));
  539.   DrawDotsEx(SubPoints, 000000001);
  540.  
  541.   SetLength(SubPoints, 0);
  542. end;
  543.  
  544. procedure ToolForm_SafeInit;
  545. var
  546.   v: TVariantArray;
  547. begin
  548.   SetLength(v, 0);
  549.   ThreadSafeCall('ToolForm_Init', v);
  550. end;
  551.  
  552. function ToolForm_ShowModal: Boolean;
  553. begin
  554.   Result := ToolForm.ShowModal = mrOk;
  555. end;
  556.  
  557. function ToolForm_SafeShowModal: Boolean;
  558. var
  559.   v: TVariantArray;
  560. begin
  561.   SetLength(v, 0);
  562.   Result := ThreadSafeCall('ToolForm_ShowModal', v);
  563. end;
  564.  
  565. begin
  566.  
  567.   {$IFDEF SMART}
  568.     SMART_Server := 10;
  569.     SMART_Members := True;
  570.     SMART_Signed := True;
  571.   {$ENDIF}
  572.  
  573.   SetupSRL;
  574.   ObjDTM_Setup;
  575.  
  576.   ObjectDTM.MainPoint := IntToPoint(80, 80);
  577.   ObjectDTM.NumOfPoints := 0;
  578.   ObjectDTM.NumOfAreaPoints := 0;
  579.  
  580.   SetLength(ObjectDTM.SubPoints, ObjectDTM.NumOfPoints);
  581.   SetLength(ObjectDTM.Area, ObjectDTM.NumOfAreaPoints);
  582.  
  583.   DeclarePlayers;
  584.  
  585.   if (not LoggedIn) then
  586.     LoginPlayer;
  587.  
  588.   while (not RSReady) do
  589.     Wait(500);
  590.  
  591.   ToolForm_SafeInit;
  592.  
  593.   if ToolForm_SafeShowModal then
  594.     WriteLn('Form returned modalresult ok');
  595.  
  596.   FreeBitmap(CleanMap);
  597.   FreeBitmap(CurrentMap);
  598. end.
Advertisement
Add Comment
Please, Sign In to add comment