Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 3 4 [5]

Author Topic: DFWall - a mass rewall/refloor utility  (Read 5904 times)

LordZabujca

  • Bay Watcher
    • View Profile
Re: DFWall - a mass rewall/refloor utility
« Reply #60 on: June 20, 2008, 11:59:05 pm »

That's because building more than one tile of anything other that walls/floors isn't really supported at the moment in the rectangle contruction - it works only in the pattern rewaller. If you really need it you can change the BuildFloorButton or BuildWallButton in the ini to {F} and it should start constructing fortifications instead of floors/walls.

EDIT:Also, did you manage to fix that "Wrong Material" problem?
« Last Edit: June 21, 2008, 05:39:02 am by LordZabujca »
Logged

Draco18s

  • Bay Watcher
    • View Profile
Re: DFWall - a mass rewall/refloor utility
« Reply #61 on: June 21, 2008, 01:45:30 pm »

Ah.  Or press capslock ;)

And yes.  Had to do with keybindings.  For whatever reason sometimes DF works even though NumLock is off (when I was getting weird behavior was right after it was working peachy) and sometimes is doesn't.
Logged

Draco18s

  • Bay Watcher
    • View Profile
Re: DFWall - a mass rewall/refloor utility
« Reply #62 on: January 02, 2009, 06:00:10 pm »

Hey, I was just wondering if there'd be continued support.  The template way of designating constructions is still quite useful.  I was just messing around today with 40d5 and DFWall attempting to build a (large!) template construction and DF was stealing most of the keystrokes the program was supposed to take (i.e. I can't ctrl-arrows).

The only thing that I could tell DID work was ctrl-q to start a template construction but the keystrokes ended up putting me in the civilization screen and popping back out).

Program still works with 40d, but none of the beta releases.  I suspect that the key-capture code in the new interface is the issue (I've seen reports of it treating AZERTY as QWERTY as well).  At least my save can be loaded in 40d so I can do my megatemplates!
Logged

LordZabujca

  • Bay Watcher
    • View Profile
Re: DFWall - a mass rewall/refloor utility
« Reply #63 on: June 30, 2009, 07:32:56 am »

*raise dead*

Holy crap, how did I miss this? Well, it may be internet ancient, but I believe it deserves a reply anyway.

All the ingame interface stuff is run through a pretty simple-but-sort-of-confusingly-written total-noob-quality AHK script (this utility was actually the first thing I've ever written in AHK), so I imagine it could be easily improved. I don't really think I'll be developing DFWall further, but I see no harm in releasing the source codes:

The mapmaker.
The mapmaker is a pretty horrible from the UI standpoint tool designed to read the tileset and produce a processed list of pixels for every tile. The processed list contains 0s where the pixel was determined to be a part of the background and 1s in all the other cases.

Code: [Select]
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%

CFile = extc.exe
IniFile = DFWall_MapMaker.ini

IniRead, TargetFilename, %IniFile%, Creator_Template, TargetFilename
IniRead, TemporaryFileName, %IniFile%, Creator_Template, TemporaryFileName

TargetFilename .= ".dfm"
TemporaryFileName .= ".tmp"

IniRead, BackgroundColour, %IniFile%, Creator_Tileset, BackgroundColour
IniRead, TileWidth, %IniFile%, Creator_Tileset, TileWidth
IniRead, TileHeight, %IniFile%, Creator_Tileset, TileHeight
IniRead, XTiles, %IniFile%, Creator_Tileset, XTiles
IniRead, YTiles, %IniFile%, Creator_Tileset, YTiles
IniRead, XStart, %IniFile%, Creator_Tileset, XStart
IniRead, YStart, %IniFile%, Creator_Tileset, YStart

^m::
MouseGetPos, xpos, ypos

xposm1 := xpos
xposm1 -= 1
xposp1 := xpos
xposp1 += 1

yposm1 := ypos
yposm1 -= 1
yposp1 := ypos
yposp1 += 1

PixelGetColor, colorxy, %xpos%, %ypos%
PixelGetColor, colorxm1yp1, %xposm1%, %yposp1%
PixelGetColor, colorxm1y, %xposm1%, %ypos%
PixelGetColor, colorxm1ym1, %xposm1%, %yposm1%
PixelGetColor, colorxp1yp1, %xposp1%, %yposp1%
PixelGetColor, colorxp1y, %xposp1%, %ypos%
PixelGetColor, colorxp1ym1, %xposp1%, %yposm1%
PixelGetColor, colorxyp1, %xpos%, %yposp1%
PixelGetColor, colorxym1, %xpos%, %yposm1%

MsgBox,0,Calibration,The cursor is at X%xpos% Y%ypos%. The local colours are:`n%colorxm1ym1% %colorxym1% %colorxp1ym1%`n%colorxm1y% %colorxy% %colorxp1y%`n%colorxm1yp1% %colorxyp1% %colorxp1yp1%
return

^1::
FileDelete %TargetFilename%
TileY = 0
Loop
{
TileX = 0
Loop
{
FocusY = 0
Loop
{
FocusX = 0
Loop
{
posx := XStart+FocusX+TileX*TileWidth
posy := YStart+FocusY+TileY*TileHeight
PixelGetColor, color, posx, posy
;MsgBox, %posx% (%FocusX%) %posy% (%FocusY%) %color% (%BackgroundColour%)
If (color == BackgroundColour)
{
FileAppend, ., %TargetFilename%
}
else
{
FileAppend, #, %TargetFilename%
}
FocusX += 1
If (FocusX == TileWidth)
{
FileAppend, `n, %TargetFilename%
break
}
}
FocusY += 1
If (FocusY == TileHeight)
{
FileAppend, `n, %TargetFilename%
break
}
}
TileX += 1
If (TileX == XTiles)
{
;FileAppend, `n, %TargetFilename%
break
}
}
TileY += 1
If (TileY == YTiles)
{
break
}
}

MsgBox, Done
return

^2::
FileDelete %TargetFilename%
FileDelete %TemporaryFileName%
ArrayHeight = 0
ArrayLenght := TileWidth*TileHeight
TileY = 0

Loop
{
TileX = 0
Loop
{
FocusY = 0
Loop
{
FocusX = 0
Loop
{
posx := XStart+FocusX+TileX*TileWidth
posy := YStart+FocusY+TileY*TileHeight
PixelGetColor, color, posx, posy
;MsgBox, %posx% (%FocusX%) %posy% (%FocusY%) %color% (%BackgroundColour%)
If (color == BackgroundColour)
{
FileAppend, 0, %TemporaryFileName%
}
else
{
FileAppend, 1, %TemporaryFileName%
}
FocusX += 1
If (FocusX == TileWidth)
{
break
}
}
FocusY += 1
If (FocusY == TileHeight)
{
FileAppend, `n, %TemporaryFileName%
;ArrayHeight += 1
break
}
}
TileX += 1
If (TileX == XTiles)
{
break
}
}
TileY += 1
If (TileY == YTiles)
{
break
}
}

FileRead, Contents, %TemporaryFileName%
if not ErrorLevel  ; Successfully loaded.
{
    Sort, Contents
    FileDelete, %TemporaryFileName%
    FileAppend, %Contents%, %TemporaryFileName%
    Contents =  ; Free the memory.
}

Current_Line =
Loop, read, %TemporaryFileName%
{
Next_Line = %A_LoopReadLine%
If (Current_Line <> Next_Line)
{
Current_Line = %A_LoopReadLine%
FileAppend, `n%Current_Line%, %TargetFilename%
ArrayHeight += 1
}
}

ArrayHeight = %ArrayLenght% %ArrayHeight%
FileRead, Contents, %TargetFileName%
if not ErrorLevel  ; Successfully loaded.
{
    FileDelete, %TemporaryFileName%
    FileAppend, %ArrayHeight%, %TemporaryFileName%
    FileAppend, %Contents%, %TemporaryFileName%
    Contents =  ; Free the memory.
}

ToRun = mapmaker.exe < %TemporaryFileName% > %TargetFileName%

;MsgBox, %ToRun%

FileDelete, %TargetFileName%

RunWait %comspec% /c ""%CFile%" <"%TemporaryFileName%" >"%TargetFileName%"", Hide

FileDelete, %TemporaryFileName%
MsgBox, Done

ExitApp

^3::
IniRead, TargetFilename, %IniFile%, Creator_Template, TargetFilename
IniRead, TemporaryFileName, %IniFile%, Creator_Template, TemporaryFileName

TargetFilename .= ".dft"
TemporaryFileName .= ".tmp"

IniRead, BackgroundColour, %IniFile%, Creator_Tileset, BackgroundColour
IniRead, TileWidth, %IniFile%, Creator_Tileset, TileWidth
IniRead, TileHeight, %IniFile%, Creator_Tileset, TileHeight
IniRead, XTiles, %IniFile%, Creator_Tileset, XTiles
IniRead, YTiles, %IniFile%, Creator_Tileset, YTiles
IniRead, XStart, %IniFile%, Creator_Tileset, XStart
IniRead, YStart, %IniFile%, Creator_Tileset, YStart
Return

^4::
ExitApp

The encoder.
The encoding process tries to construct the shortest decision tree necessary to determine the tile type given only the processed list of its pixels. It does so by choosing the list element that divides all remaining possibilities most evenly into two groups, and then doing the same for both groups. It then saves which pixels and in which order are to be examined to determine the type of the currently viewed tile. I honestly have no idea if this greedy approach is the optimal one, but it seems to work allright.
Code: [Select]
#include <stdio.h>
#include <stdlib.h>

int sort(int ArrayLength, int NumberOfArrays, int Array[ArrayLength][NumberOfArrays], int MinArrayIndex, int MaxArrayIndex, int SortByThisElement, int balance)
    {
    int Span = MaxArrayIndex-MinArrayIndex;
    int TempArray[ArrayLength][Span];
    int i,j;
    int x=MinArrayIndex,y=floor((MinArrayIndex+MaxArrayIndex+1-balance)/2);
   
    for (i=0; i<Span; i++) for (j=0; j<ArrayLength; j++) TempArray[j][i]=Array[j][MinArrayIndex+i];
   
    for (i=0; i<Span; i++)
        {
        if (TempArray[SortByThisElement][i]==0)
           {
           for (j=0; j<ArrayLength; j++) Array[j][x]=TempArray[j][i];
           x++;
           }
        else
            {
            for (j=0; j<ArrayLength; j++) Array[j][y]=TempArray[j][i];
            y++;
            }
        }
    return 0;
    }

int mapmake(int ArrayLength, int NumberOfArrays, int Array[ArrayLength][NumberOfArrays], int CurrentMapIndex, int MinArrayIndex, int MaxArrayIndex)
    {
    if (CurrentMapIndex>1) printf("\n");
    int i, j, Span=MaxArrayIndex-MinArrayIndex;
    int FirstOneIndex;
    if(Span<2)
              {
              printf("%d|-1", CurrentMapIndex);
              return 0;
              }
   
    int balance, bestbalance=NumberOfArrays, bestindex=0;
   
   
   
    for (j=0; j<ArrayLength; j++)
        {
        balance=0;
        for (i=MinArrayIndex; i<MaxArrayIndex; i++)
            {
            if (Array[j][i]==1) balance++;
            else balance--;
            }
        if (abs(balance)<abs(bestbalance))
           {
           bestindex=j;
           bestbalance=balance;
           }
        }
   
    //if (CurrentMapIndex<100) printf("0");
    //if (CurrentMapIndex<10) printf("0");
    printf("%d|%d",CurrentMapIndex ,bestindex);
    sort(ArrayLength, NumberOfArrays, Array, MinArrayIndex, MaxArrayIndex, bestindex, bestbalance);
   
    FirstOneIndex=floor((MinArrayIndex+MaxArrayIndex+1-bestbalance)/2);
   
    /*for (i=MinArrayIndex; i<MaxArrayIndex; i++)
        {
        if (i==FirstOneIndex) printf("\n");
        for (j=0; j<ArrayLength; j++) printf("%d", Array[j][i]);
        printf("\n");
        }*/
   
    mapmake(ArrayLength, NumberOfArrays, Array, 2*(CurrentMapIndex), MinArrayIndex, FirstOneIndex);
    mapmake(ArrayLength, NumberOfArrays, Array, 2*(CurrentMapIndex)+1, FirstOneIndex, MaxArrayIndex);
   
    return 0;
    }

int main()
    {
    char c;
    int NumberOfArrays=0, ArrayLength=0;
    while ((c = getchar())!=' ') ArrayLength=10*ArrayLength + (int)(c)-'0';
    while ((c = getchar())!='\n') NumberOfArrays=10*NumberOfArrays + (int)(c)-'0';
   
    int Array[ArrayLength][NumberOfArrays];
    int x=0,y=0;
   
    while ((c = getchar())!=EOF)
          {
          if (c == '\n')
             {
             x=0;
             y++;
             }
          else
              {
              Array[x][y]=(int)(c)-'0';
              x++;
              }
          }
    mapmake(ArrayLength, NumberOfArrays, Array, 1, 0, NumberOfArrays);
    return 0;
    }

DFWall itself.
There's not much to tell, really. The mass rewalling works by using the tree generated by the encoder to save the first x of the selected tiles (it looks for a pixel with the "highlighted" colour in the first letter column in the material selector to determine which ones are those - this is why it fails with many custom tilesets, as there is no guarantee that there will even be a pixel in the exact same colour on two different highlighted tiles) in memory and then repeatedly selecting them when found on the list. The repeated selection process depends on a hardcoded key sequence, which is why you can build only one, say, chest with it at a time. The mass rewaller works by using a pretty simple combination of two loops - each ctrl+arrow changes a global variable that determines the number of iterations. For each tile selected by those loops a construction of your choice is placed. The pattern constructor works pretty much the same way, but without user input and with varying construction types determined by the template file.
Code: [Select]
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%

IniFile = DFWall.ini

IniRead, MapFile, %IniFile%, Tileset, MapFile

MapFile .= ".dfm"

IniRead, StopOnFailure, %IniFile%, Settings, StopOnFailure
IniRead, CompareDepth, %IniFile%, Settings, CompareDepth
IniRead, PageDownCheckDelay, %IniFile%, Settings, PageDownCheckDelay

IniRead, TileWidth, %IniFile%, Tileset, TileWidth
IniRead, TileHeight, %IniFile%, Tileset, TileHeight

IniRead, XStart, %IniFile%, Window, XStart
IniRead, YStart, %IniFile%, Window, YStart
IniRead, DF_Window_Name, %IniFile%, Window, DF_Window_Name

IniRead, SeparatorColour, %IniFile%, Dwarf_Fortress, SeparatorColour
IniRead, BackgroundColour, %IniFile%, Dwarf_Fortress, BackgroundColour
IniRead, SelectedColour, %IniFile%, Dwarf_Fortress, SelectedColour
IniRead, NotSelectedColour, %IniFile%, Dwarf_Fortress, NotSelectedColour

IniRead, PageDownButton, %IniFile%, Dwarf_Fortress, PageDownButton
IniRead, ScrollDownButton, %IniFile%, Dwarf_Fortress, ScrollDownButton
IniRead, SpaceButton, %IniFile%, Dwarf_Fortress, SpaceButton
IniRead, EnterButton, %IniFile%, Dwarf_Fortress, EnterButton
IniRead, TabButton, %IniFile%, Dwarf_Fortress, TabButton

IniRead, UpButton, %IniFile%, Dwarf_Fortress, UpButton
IniRead, DownButton, %IniFile%, Dwarf_Fortress, DownButton
IniRead, LeftButton, %IniFile%, Dwarf_Fortress, LeftButton
IniRead, RightButton, %IniFile%, Dwarf_Fortress, RightButton

IniRead, BuildTableButton, %IniFile%, Dwarf_Fortress, BuildTableButton
IniRead, BuildChairButton, %IniFile%, Dwarf_Fortress, BuildChairButton

IniRead, BuildStatueButton, %IniFile%, Dwarf_Fortress, BuildStatueButton
IniRead, BuildCageButton, %IniFile%, Dwarf_Fortress, BuildCageButton
IniRead, BuildRestraintButton, %IniFile%, Dwarf_Fortress, BuildRestraintButton

IniRead, BuildConstructionButton, %IniFile%, Dwarf_Fortress, BuildConstructionButton

IniRead, BuildFloorButton, %IniFile%, Dwarf_Fortress, BuildFloorButton
IniRead, BuildWallButton, %IniFile%, Dwarf_Fortress, BuildWallButton
IniRead, BuildRampButton, %IniFile%, Dwarf_Fortress, BuildRampButton
IniRead, BuildUpStairsButton, %IniFile%, Dwarf_Fortress, BuildUpStairsButton
IniRead, BuildDownStairsButton, %IniFile%, Dwarf_Fortress, BuildDownStairsButton
IniRead, BuildUpDownStairsButton, %IniFile%, Dwarf_Fortress, BuildUpDownStairsButton
IniRead, BuildFortificationButton, %IniFile%, Dwarf_Fortress, BuildFortificationButton

ConstructFloor = %BuildConstructionButton%%BuildFloorButton%
ConstructWall = %BuildConstructionButton%%BuildWallButton%
ConstructRamp = %BuildConstructionButton%%BuildRampButton%
ConstructUpStair = %BuildConstructionButton%%BuildUpStairButton%
ConstructDownStair = %BuildConstructionButton%%BuildDownStairButton%
ConstructUpDownStair = %BuildConstructionButton%%BuildUpDownStairButton%
ConstructFortification = %BuildConstructionButton%%BuildFortificationButton%

StopMassRewall := 0

EmptySpaceSpaceTile =
NineTile =
NineNineTiles =

ItemPageTop =

BuildMaterial =

BuildMaterial_0 =
BuildMaterial_1 =
BuildMaterial_2 =
BuildMaterial_3 =
BuildMaterial_4 =
BuildMaterial_5 =
BuildMaterial_6 =
BuildMaterial_7 =
BuildMaterial_8 =
BuildMaterial_9 =

MassRewallX = 0
MassRewallY = 0

Loop, read, %MapFile%
{
   StringGetPos, MiddleChar, A_LoopReadLine, |
   StringLeft, LeftPart, A_LoopReadLine, %MiddleChar%
   MiddleChar +=1
   StringTrimLeft, RightPart, A_LoopReadLine, %MiddleChar%
   MapArray%LeftPart% := RightPart
}

;------------------------------------------------------------------------
Parse_Tile(TileX, TileY)
{
global
CurrentMapPosition = 1
Loop
{
CurrentMapValue := MapArray%CurrentMapPosition%
If (CurrentMapValue < 0)
{
break
}
else
{
DeltaY := CurrentMapValue // TileWidth
DeltaX := CurrentMapValue - TileWidth*DeltaY + TileWidth*TileX + XStart
DeltaY += TileHeight*TileY + YStart
PixelGetColor, ParseColour, DeltaX, DeltaY
;MsgBox, %DeltaX% %DeltaY% (%ParseColour%)
If (ParseColour == BackgroundColour)
{
CurrentMapPosition *= 2
}
else
{
CurrentMapPosition *= 2
CurrentMapPosition += 1
}
}
}
CurrentMapPosition .= -0
return %CurrentMapPosition%
}

Parse_Text(TTileX, TTileY, Depth)
{
Returned =
Loop
{
Returned .= Parse_Tile(TTileX, TTileY)
Depth -= 1
TTileX += 1
If (Depth == 0)
{
break
}
}
return Returned
}

IsColourOnTile(TTileX, TTileY, Colour)
{
WellIsIt=0
global TileWidth, TileHeight, XStart, YStart
FocusXStart:=XStart+TileWidth*TTileX
FocusYStart:=YStart+TileHeight*TTileY
FocusXLimit:=XStart+TileWidth*(TTileX+1)
FocusYLimit:=YStart+TileHeight*(TTileY+1)
FocusY := FocusYStart
Loop
{
FocusX := FocusXStart
Loop
{
PixelGetColor, col, %FocusX%, %FocusY%
If (col == Colour)
{
WellIsIt = 1
}
FocusX++
If (FocusX == FocusXLimit)
{
break
}
}
FocusY++
If (FocusY == FocusYLimit)
{
break
}
}
Return %WellIsIt%
}

;------------------------------------------------------------------------

#IfWinActive Dwarf Fortress
^Up::
MassRewallY -= 1
Send {Up}
return

^Down::
MassRewallY += 1
Send {Down}
return

^Left::
MassRewallX -= 1
Send {Left}
return

^Right::
MassRewallX += 1
Send {Right}
return

^1::
Gosub, TabPrepare
Gosub, MaterialSave
BuildMaterial_1 := Parse_Text(26, FocusdY, CompareDepth)
Gosub, TabUndo
return

^2::
Gosub, TabPrepare
Gosub, MaterialSave
BuildMaterial_2 := Parse_Text(26, FocusdY, CompareDepth)
Gosub, TabUndo
return

^3::
Gosub, TabPrepare
Gosub, MaterialSave
BuildMaterial_3 := Parse_Text(26, FocusdY, CompareDepth)
Gosub, TabUndo
return

^4::
Gosub, TabPrepare
Gosub, MaterialSave
BuildMaterial_4 := Parse_Text(26, FocusdY, CompareDepth)
Gosub, TabUndo
return

^5::
Gosub, TabPrepare
Gosub, MaterialSave
BuildMaterial_5 := Parse_Text(26, FocusdY, CompareDepth)
Gosub, TabUndo
return

^6::
Gosub, TabPrepare
Gosub, MaterialSave
BuildMaterial_6 := Parse_Text(26, FocusdY, CompareDepth)
Gosub, TabUndo
return

^7::
Gosub, TabPrepare
Gosub, MaterialSave
BuildMaterial_7 := Parse_Text(26, FocusdY, CompareDepth)
Gosub, TabUndo
return

^8::
Gosub, TabPrepare
Gosub, MaterialSave
BuildMaterial_8 := Parse_Text(26, FocusdY, CompareDepth)
Gosub, TabUndo
return

^9::
Gosub, TabPrepare
Gosub, MaterialSave
BuildMaterial_9 := Parse_Text(26, FocusdY, CompareDepth)
Gosub, TabUndo
return

^0::
Gosub, TabPrepare
Gosub, MaterialSave
BuildMaterial_0 := Parse_Text(26, FocusdY, CompareDepth)
Gosub, TabUndo
return

~w & 1::
MassUsedButton = %BuildWallButton%
BuildMaterial := BuildMaterial_1
Gosub, TabPrepare
Gosub, MassRewall
Gosub, TabUndo
return

~w & 2::
MassUsedButton = %BuildWallButton%
BuildMaterial := BuildMaterial_2
Gosub, TabPrepare
Gosub, MassRewall
Gosub, TabUndo
return

~w & 3::
MassUsedButton = %BuildWallButton%
BuildMaterial := BuildMaterial_3
Gosub, TabPrepare
Gosub, MassRewall
Gosub, TabUndo
return

~w & 4::
MassUsedButton = %BuildWallButton%
BuildMaterial := BuildMaterial_4
Gosub, TabPrepare
Gosub, MassRewall
Gosub, TabUndo
return

~w & 5::
MassUsedButton = %BuildWallButton%
BuildMaterial := BuildMaterial_5
Gosub, TabPrepare
Gosub, MassRewall
Gosub, TabUndo
return

~w & 6::
MassUsedButton = %BuildWallButton%
BuildMaterial := BuildMaterial_6
Gosub, TabPrepare
Gosub, MassRewall
Gosub, TabUndo
return

~w & 7::
MassUsedButton = %BuildWallButton%
BuildMaterial := BuildMaterial_7
Gosub, TabPrepare
Gosub, MassRewall
Gosub, TabUndo
return

~w & 8::
MassUsedButton = %BuildWallButton%
BuildMaterial := BuildMaterial_8
Gosub, TabPrepare
Gosub, MassRewall
Gosub, TabUndo
return

~w & 9::
MassUsedButton = %BuildWallButton%
BuildMaterial := BuildMaterial_9
Gosub, TabPrepare
Gosub, MassRewall
Gosub, TabUndo
return

~w & 0::
MassUsedButton = %BuildWallButton%
BuildMaterial := BuildMaterial_0
Gosub, TabPrepare
Gosub, MassRewall
Gosub, TabUndo
return

~f & 1::
MassUsedButton = %BuildFloorButton%
BuildMaterial := BuildMaterial_1
Gosub, TabPrepare
Gosub, MassRewall
Gosub, TabUndo
return

~f & 2::
MassUsedButton = %BuildFloorButton%
BuildMaterial := BuildMaterial_2
Gosub, TabPrepare
Gosub, MassRewall
Gosub, TabUndo
return

~f & 3::
MassUsedButton = %BuildFloorButton%
BuildMaterial := BuildMaterial_3
Gosub, TabPrepare
Gosub, MassRewall
Gosub, TabUndo
return

~f & 4::
MassUsedButton = %BuildFloorButton%
BuildMaterial := BuildMaterial_4
Gosub, TabPrepare
Gosub, MassRewall
Gosub, TabUndo
return

~f & 5::
MassUsedButton = %BuildFloorButton%
BuildMaterial := BuildMaterial_5
Gosub, TabPrepare
Gosub, MassRewall
Gosub, TabUndo
return

~f & 6::
MassUsedButton = %BuildFloorButton%
BuildMaterial := BuildMaterial_6
Gosub, TabPrepare
Gosub, MassRewall
Gosub, TabUndo
return

~f & 7::
MassUsedButton = %BuildFloorButton%
BuildMaterial := BuildMaterial_7
Gosub, TabPrepare
Gosub, MassRewall
Gosub, TabUndo
return

~f & 8::
MassUsedButton = %BuildFloorButton%
BuildMaterial := BuildMaterial_8
Gosub, TabPrepare
Gosub, MassRewall
Gosub, TabUndo
return

~f & 9::
MassUsedButton = %BuildFloorButton%
BuildMaterial := BuildMaterial_9
Gosub, TabPrepare
Gosub, MassRewall
Gosub, TabUndo
return

~f & 0::
MassUsedButton = %BuildFloorButton%
BuildMaterial := BuildMaterial_0
Gosub, TabPrepare
Gosub, MassRewall
Gosub, TabUndo
return

^.::
Gosub, TabPrepare
Gosub, MaterialSave
EmptySpaceSpaceTile := Parse_Text(76, 4, 1)
NineTile := Parse_Text(75, FocusdY, 1)
NineNineTiles := NineTile
NineNineTiles .= NineTile
Gosub, TabUndo
return

~f & /::
MassUsedButton = %BuildFloorButton%
Gosub, TabPrepare
Gosub, MassRewallAL1
Gosub, TabUndo
return

~w & /::
MassUsedButton = %BuildWallButton%
Gosub, TabPrepare
Gosub, MassRewallAL1
Gosub, TabUndo
return

~f & .::
MassUsedButton = %BuildFloorButton%
Gosub, TabPrepare
Gosub, MassRewallAL10
Gosub, TabUndo
return

~w & .::
MassUsedButton = %BuildWallButton%
Gosub, TabPrepare
Gosub, MassRewallAL10
Gosub, TabUndo
return

~f & ,::
MassUsedButton = %BuildFloorButton%
Gosub, TabPrepare
Gosub, MassRewallAL99
Gosub, TabUndo
return

~w & ,::
MassUsedButton = %BuildWallButton%
Gosub, TabPrepare
Gosub, MassRewallAL99
Gosub, TabUndo
return

^`::
MassRewallX = 0
MassRewallY = 0
return

`::
MsgBox, %MassRewallX% %MassRewallY%
return

^q::
Send %SpaceButton%%SpaceButton%
Gosub, TabPrepare
GoSub, ReadTemplate
GoSub, TemplateArrayize
Direction = 1
X=0
Y=0

Loop %TemplateHeight%
{
BTCounter = 1
Loop %TemplateWidth%
{
TBSelectedMaterial:=MaterialTemplate%X%_%Y%
TBSelectedConstruction:=ConstructionTemplate%X%_%Y%

GoSub, TBConstOneTile

Send %ConstructFloor%
Sleep 150
If (BTCounter < TemplateWidth)
{
If (Direction < 0)
{
Send %LeftButton%
Sleep 150
}
else
{
Send %RightButton%
Sleep 150
}
}
Send %SpaceButton%%SpaceButton%
BTCounter += 1
X += Direction
}
X -= Direction
Direction *= -1
Send %ConstructFloor%
;Sleep 100
Send %DownButton%
Sleep 150
Send %SpaceButton%%SpaceButton%
Y += 1
}
Gosub, TabUndo
return

;------------------------------------------------------------------------
;
;^w::
;MassUsedButton = %BuildWallButton%
;return
;
;------------------------------------------------------------------------

TBConstOneTile:
SpacesAtTheEnd = 0
If (TBSelectedConstruction == ".")
{
return
}
If (TBSelectedConstruction == "w")
{
SpacesAtTheEnd += 1
Send %ConstructWall%
}
else
{
If (TBSelectedConstruction == "f")
{
SpacesAtTheEnd += 1
Send %ConstructFloor%
}
else
{
If (TBSelectedConstruction == "s")
{
Send %BuildStatueButton%
}
else
{
If (TBSelectedConstruction == "t")
{
Send %BuildTableButton%
}
else
{
If (TBSelectedConstruction == "c")
{
Send %BuildChairButton%
}
else
{
If (TBSelectedConstruction == "v")
{
Send %BuildRestraintButton%
}
else
{
If (TBSelectedConstruction == "R")
{
SpacesAtTheEnd += 1
Send %ConstructRamp%
}
else
{
If (TBSelectedConstruction == "U")
{
SpacesAtTheEnd += 1
Send %ConstructUpStairs%
}
else
{
If (TBSelectedConstruction == "D")
{
SpacesAtTheEnd += 1
Send %ConstructDownStairs%
}
else
{
If (TBSelectedConstruction == "X")
{
SpacesAtTheEnd += 1
Send %ConstructUpDownStairs%
}
else
{
If (TBSelectedConstruction == "F")
{
SpacesAtTheEnd += 1
Send %ConstructFortification%
}
else
{
If (TBSelectedConstruction == "j")
{
Send %BuildCageButton%
}
else
{
MsgBox, PatternError
return
}
}
}
}
}
}
}
}
}
}
}
}




Sleep 25
Send %EnterButton%

If (TBSelectedMaterial == ".")
{
Loop 40
{
Sleep 10
CurrentPageTop := Parse_Text(26, 4, 4)
If (ItemPageTop == CurrentPageTop)
{
break
}
}
}
else
{
BuildMaterial := BuildMaterial_%TBSelectedMaterial%
Gosub, FindBuildMaterial
}

Send %EnterButton%

If (SpacesAtTheEnd > 0)
{
;If (TBSelectedConstruction == "s")
; {
; MsgBox, Yo
; }
Loop %SpacesAtTheEnd%
{
Send %SpaceButton%
}
}
return

TemplateArrayize:
Y=0
Loop %TemplateHeight%
{
X=1
Loop %TemplateWidth%
{
Xm1=%X%
Xm1-=1
StringMid, MaterialTemplate%Xm1%_%Y%, MaterialTemplate%Y%, %X%, 1
StringMid, ConstructionTemplate%Xm1%_%Y%, ConstructionTemplate%Y%, %X%, 1
X += 1
}
Y += 1
}
return

ReadTemplate:
Separator = _
LineNumber=0
PartNumber=0
TemplateWidth=0
TemplateHeight=0
Loop, read, template.dft
{
;MsgBox, %PartNumber% %LineNumber% %TemplateWidth% %TemplateHeight%
If (PartNumber == 0)
{
If (TemplateWidth == 0) %A_LoopReadLine%
{
TemplateWidth = %A_LoopReadLine%
}
else
{
If (TemplateHeight==0)
{
TemplateHeight=%A_LoopReadLine%
}
else
{
PartNumber += 1
}
}
}
else
{
If (PartNumber == 1)
{
If (A_LoopReadLine == Separator)
{
PartNumber += 1
LineNumber = 0
}
else
{
MaterialTemplate%LineNumber% = %A_LoopReadLine%
LineNumber += 1
}
}
else
{
ConstructionTemplate%LineNumber% = %A_LoopReadLine%
LineNumber += 1
}
}

}
return

MaterialSave:
ItemPageTop:=Parse_Text(26, 4, 4)
FocusdX=26
FocusdXMax:=26+CompareDepth
Loop
{
FocusdY=5
Loop
{
IsColourOnTileVarS:=IsColourOnTile(FocusdX, FocusdY, SelectedColour)
If (IsColourOnTileVarS==1)
{
break
}
FocusdY +=1
If (FocusdY==18)
{
break
}
}
If (IsColourOnTileVarS==1)
{
break
}
FocusdX += 1
If (FocusdX == FocusdMax)
{
break
}
}
return

MassRewall:
If (MassRewallY>0)
{
MassRewallVerticalButton = {Up}
}
else
{
MassRewallY *= -1
MassRewallVerticalButton = {Down}
}
If (MassRewallX>0)
{
XState=1
MassRewallHorizontalButton = {Left}
}
else
{
XState=-1
MassRewallX *= -1
MassRewallHorizontalButton = {Right}
}
RWFocusY := MassRewallY
Loop
{
If (StopMassRewall == 1)
{
;MsgBox, Yo
break
}
RWFocusX := MassRewallX
Loop
{
If (StopMassRewall == 1)
{
break
}
;Sleep 50
Send %EnterButton%
;Sleep 50
Gosub, FindBuildMaterial
;Sleep 50
Send %EnterButton%
;Sleep 100
Send %MassUsedButton%
;Sleep 50
RWFocusX -= 1
If (RWFocusX < 0)
{
If (XState == 1)
{
XState = -1
MassRewallHorizontalButton = {Right}
}
else
{
XState = 1
MassRewallHorizontalButton = {Left}
}
break
}
else
{
Send %MassRewallHorizontalButton%
Sleep 200
}
}
RWFocusY -= 1
If (RWFocusY < 0)
{
break
}
else
{
Send %MassRewallVerticalButton%
Sleep 200
}
}
;Send %SpaceButton%
;Send %SpaceButton%
Send %SpaceButton%
MassRewallX=0
MassRewallY=0
StopMassRewall:=0
return

MassRewallAL1:
If (MassRewallY>0)
{
MassRewallVerticalButton = {Up}
}
else
{
MassRewallY *= -1
MassRewallVerticalButton = {Down}
}
If (MassRewallX>0)
{
XState=1
MassRewallHorizontalButton = {Left}
}
else
{
XState=-1
MassRewallX *= -1
MassRewallHorizontalButton = {Right}
}
RWFocusY := MassRewallY
Loop
{
If (StopMassRewall == 1)
{
break

}
RWFocusX := MassRewallX
Loop
{
If (StopMassRewall == 1)
{
break

}
;Sleep 50
Send %EnterButton%
;Sleep 50

;Gosub, FindBuildMaterial

Loop 40
{
Sleep 10
CurrentPageTop := Parse_Text(26, 4, 4)
;MsgBox, %ItemPageTop%`n%CurrentPageTop%
If (ItemPageTop == CurrentPageTop)
{
break
}
}

;Sleep 50
Send %EnterButton%
;Sleep 100
Send %MassUsedButton%
;Sleep 50
RWFocusX -= 1
If (RWFocusX < 0)
{
If (XState == 1)
{
XState = -1
MassRewallHorizontalButton = {Right}
}
else
{
XState = 1
MassRewallHorizontalButton = {Left}
}
break
}
else
{
Send %MassRewallHorizontalButton%
Sleep 200
}
}
RWFocusY -= 1
If (RWFocusY < 0)
{
break
}
else
{
Send %MassRewallVerticalButton%
Sleep 200
}
}
;Send %SpaceButton%
;Send %SpaceButton%
Send %SpaceButton%
MassRewallX=0
MassRewallY=0
StopMassRewall:=0
return

MassRewallAL10:
If (MassRewallY>0)
{
MassRewallVerticalButton = {Up}
}
else
{
MassRewallY *= -1
MassRewallVerticalButton = {Down}
}
If (MassRewallX>0)
{
XState=1
MassRewallHorizontalButton = {Left}
}
else
{
XState=-1
MassRewallX *= -1
MassRewallHorizontalButton = {Right}
}
RWFocusY := MassRewallY
Loop
{
If (StopMassRewall == 1)
{
break

}
RWFocusX := MassRewallX
Loop
{
If (StopMassRewall == 1)
{
break
}
;Sleep 50
Send %EnterButton%
;Sleep 50
Gosub, FindBuildMaterialAL10
;Sleep 50
Send %EnterButton%
;Sleep 100
Send %MassUsedButton%
;Sleep 50
RWFocusX -= 1
If (RWFocusX < 0)
{
If (XState == 1)
{
XState = -1
MassRewallHorizontalButton = {Right}
}
else
{
XState = 1
MassRewallHorizontalButton = {Left}
}
break
}
else
{
Send %MassRewallHorizontalButton%
Sleep 200
}
}
RWFocusY -= 1
If (RWFocusY < 0)
{
break
}
else
{
Send %MassRewallVerticalButton%
Sleep 200
}
}
;Send %SpaceButton%
;Send %SpaceButton%
Send %SpaceButton%
MassRewallX=0
MassRewallY=0
StopMassRewall:=0
return

MassRewallAL99:
If (MassRewallY>0)
{
MassRewallVerticalButton = {Up}
}
else
{
MassRewallY *= -1
MassRewallVerticalButton = {Down}
}
If (MassRewallX>0)
{
XState=1
MassRewallHorizontalButton = {Left}
}
else
{
XState=-1
MassRewallX *= -1
MassRewallHorizontalButton = {Right}
}
RWFocusY := MassRewallY
Loop
{
If (StopMassRewall == 1)
{
break

}
RWFocusX := MassRewallX
Loop
{
If (StopMassRewall == 1)
{
break

}
;Sleep 50
Send %EnterButton%
;Sleep 50
Gosub, FindBuildMaterialAL99
;Sleep 50
Send %EnterButton%
;Sleep 100
Send %MassUsedButton%
;Sleep 50
RWFocusX -= 1
If (RWFocusX < 0)
{
If (XState == 1)
{
XState = -1
MassRewallHorizontalButton = {Right}
}
else
{
XState = 1
MassRewallHorizontalButton = {Left}
}
break
}
else
{
Send %MassRewallHorizontalButton%
Sleep 200
}
}
RWFocusY -= 1
If (RWFocusY < 0)
{
break
}
else
{
Send %MassRewallVerticalButton%
Sleep 200
}
}
;Send %SpaceButton%
;Send %SpaceButton%
Send %SpaceButton%
MassRewallX=0
MassRewallY=0
StopMassRewall:=0
return

TabPrepare:
DoTabsOnExit := 5
FullTile := Parse_Tile(0,1)

Loop
{
FocusdTile := Parse_Tile(24,1)
If (FocusdTile == FullTile)
{
IsColourOnTileVar := IsColourOnTile(24,1,SeparatorColour)
If (IsColourOnTileVar == 1)
{
If (IsColourOnTile(55,1,SeparatorColour) == 0)
{
break
}
else
{
Send %TabButton%
DoTabsOnExit -= 1
Sleep 100
}
}
else
{
Send %TabButton%
DoTabsOnExit -= 1
Sleep 100
}
}
else
{
Send %TabButton%
DoTabsOnExit -= 1
Sleep 100
}
If (DoTabsOnExit == 0)
{
break
}
}
If (DoTabsOnExit == 5)
{
DoTabsOnExit := 0
}
return

TabUndo:
Loop
{
If (DoTabsOnExit == 0)
{
break
}
send %TabButton%
DoTabsOnExit := DoTabsOnExit - 1
}
return

FindBuildMaterial:
Loop 40
{
Sleep 10
CurrentPageTop := Parse_Text(26, 4, 4)
;MsgBox, %ItemPageTop%`n%CurrentPageTop%
If (ItemPageTop == CurrentPageTop)
{
break
}
}
FocusX = 26
FocusY = 5
FirstOnPage := Parse_Text(FocusX,FocusY,CompareDepth)
;HowManyDown := 0
Loop
{
;MsgBox, %HowManyDown%
If (HowManyDown == 13)
{
HowManyDown := 0
Send %PageDownButton%
;MsgBox, %PageDownCheckDelay%
Sleep %PageDownCheckDelay%
FocusY := 5
NewFirstOnPage := Parse_Text(FocusX,FocusY,CompareDepth)
;MsgBox, %NewFirstOnPage%
If (NewFirstOnPage == FirstOnPage)
{
If (StopOnFailure = "TRUE") StopMassRewall:=1
Send %SpaceButton%
break
}
else
{
FirstOnPage = %NewFirstOnPage%
}
}
FocusText := Parse_Text(FocusX,FocusY,CompareDepth)
;MsgBox, %BuildMaterial%`n%FocusText%
If (FocusText == BuildMaterial)
{
Loop
{
If (HowManyDown < 1)
{
break
}
Send %ScrollDownButton%
HowManyDown -= 1
Sleep 25
}
Sleep 50
;Send %EnterButton%
break
}
HowManyDown += 1
FocusY += 1
}
return

FindBuildMaterialAL10:
Loop 40
{
Sleep 10
CurrentPageTop := Parse_Text(26, 4, 4)
;MsgBox, %ItemPageTop%`n%CurrentPageTop%
If (ItemPageTop == CurrentPageTop)
{
break
}
}
FocusX = 26
FocusY = 5
FirstOnPage := Parse_Text(FocusX,FocusY,CompareDepth)
Loop
{
;MsgBox, %HowManyDown%
If (HowManyDown == 13)
{
HowManyDown := 0
Send %PageDownButton%
;MsgBox, %PageDownCheckDelay%
Sleep %PageDownCheckDelay%
FocusY := 5
NewFirstOnPage := Parse_Text(FocusX,FocusY,CompareDepth)
;MsgBox, %NewFirstOnPage%
If (NewFirstOnPage == FirstOnPage)
{
If (StopOnFailure = "TRUE")
{
StopMassRewall:=1
}
Send %SpaceButton%
break
}
else
{
FirstOnPage = %NewFirstOnPage%
}
}
FocusText := Parse_Text(76,FocusY,1)
;MsgBox, %FocusText% %EmptySpaceSpaceTile%
If (FocusText != EmptySpaceSpaceTile)
{
Loop
{
If (HowManyDown < 1)
{
break
}
Send %ScrollDownButton%
HowManyDown -= 1
Sleep 25
}
Sleep 50
;Send %EnterButton%
break
}
HowManyDown += 1
FocusY += 1
}
return

FindBuildMaterialAL99:
Loop 40
{
Sleep 10
CurrentPageTop := Parse_Text(26, 4, 4)
;MsgBox, %ItemPageTop%`n%CurrentPageTop%
If (ItemPageTop == CurrentPageTop)
{
break
}
}
FocusX = 26
FocusY = 5
FirstOnPage := Parse_Text(FocusX,FocusY,CompareDepth)
;HowManyDown := 0
Loop
{
;MsgBox, %HowManyDown%
If (HowManyDown == 13)
{
HowManyDown := 0
Send %PageDownButton%
;MsgBox, %PageDownCheckDelay%
Sleep %PageDownCheckDelay%
FocusY := 5
NewFirstOnPage := Parse_Text(FocusX,FocusY,CompareDepth)
;MsgBox, %NewFirstOnPage%
If (NewFirstOnPage == FirstOnPage)
{
If (StopOnFailure = "TRUE") StopMassRewall:=1
Send %SpaceButton%
break
}
else
{
FirstOnPage = %NewFirstOnPage%
}
}
FocusText := Parse_Text(76,FocusY,1)
FocusText .= Parse_Text(75,FocusY,1)
;MsgBox, %BuildMaterial%`n%FocusText%
If (FocusText == NineNineTiles)
{
Loop
{
If (HowManyDown < 1)
{
break
}
Send %ScrollDownButton%
HowManyDown -= 1
Sleep 25
}
Sleep 50
;Send %EnterButton%
break
}
HowManyDown += 1
FocusY += 1
}
return


The code is pretty horrible, sorry about that. I never planned to release it before developing it further and doing a major rewrite along the way, but then Toady just gave us internal mass construction and I kind of lost my motivation :).
Logged
Pages: 1 ... 3 4 [5]