Author Topic: "Tool" to simplify map-making  (Read 1408 times)

Code: [Select]

function getMap() {
$Map[0] = 0;
for(%i = 0; %i < BrickGroup_27690.getCount(); %i = %i + 1) {
%brick = BrickGroup_27690.getObject(%i);
if(%brick.getDatablock().uiName $= "1x1f") {
$Map[0] = $Map[0] + 1;
$Map[$Map[0],0] = %brick.colorID;
%x = getWord(%brick.getPosition(),0);
%y = getWord(%brick.getPosition(),1);
%x = (%x + 173.25)*16;
%y = (%y - 110.25)*16;
$Map[$Map[0],1] = %x SPC %y SPC "0.1";
}
}
}

function makeMap() {
for(%i = 0; %i < $Map[0]; %i = %i + 1) {
%newbrick = new fxDTSBrick() {
dataBlock = brick16x16fData;
scale = "1 1 1";
client = 0;
stackBL_ID = 0;
angleID = 0;
colorID = $Map[%i,0];
colorFXID = 0;
printID = 0;
shapeFXID = "0";
rotation = "1 0 0 0";
};

%newbrick.setTransform($Map[%i,1] SPC %height);
%newbrick.setTrusted(1);
%newbrick.plant();
BrickGroup_27690.add(%newbrick);
}
}


Ok now here's how it works. First, you need to set it up. To set it up, change Brickgroup_27690 to Brickgroup_YOURID in both occurances. Change Brickgroup_33576 to a friend's ID or don't. It won't affect you at all.

Next, build a map made purely out of 1x1f. This code will pass the map to largescale with 16x16 baseplates.

Now, to pass the map to largescale, you must do the following:
$Map[0]=0;
getMap();
makeMap();

It is super important to set $Map[0] to 0 to avoid having bricks overlap eachother. If you want to use a different baseplate, use the following:

For 8x8 Plates:

Code: [Select]
function getMap() {
$Map[0] = 0;
for(%i = 0; %i < BrickGroup_27690.getCount(); %i = %i + 1) {
%brick = BrickGroup_27690.getObject(%i);
if(%brick.getDatablock().uiName $= "1x1f") {
$Map[0] = $Map[0] + 1;
$Map[$Map[0],0] = %brick.colorID;
%x = getWord(%brick.getPosition(),0);
%y = getWord(%brick.getPosition(),1);
%x = (%x + 173.25)*8;
%y = (%y - 110.25)*8;
$Map[$Map[0],1] = %x SPC %y SPC "0.1";
}
}
}

function makeMap() {
for(%i = 0; %i < $Map[0]; %i = %i + 1) {
%newbrick = new fxDTSBrick() {
dataBlock = brick8x8fData;
scale = "1 1 1";
client = 0;
stackBL_ID = 0;
angleID = 0;
colorID = $Map[%i,0];
colorFXID = 0;
printID = 0;
shapeFXID = "0";
rotation = "1 0 0 0";
};

%newbrick.setTransform($Map[%i,1] SPC %height);
%newbrick.setTrusted(1);
%newbrick.plant();
BrickGroup_27690.add(%newbrick);
}
}




For 32x32 plates:

Code: [Select]
function getMap() {
$Map[0] = 0;
for(%i = 0; %i < BrickGroup_27690.getCount(); %i = %i + 1) {
%brick = BrickGroup_27690.getObject(%i);
if(%brick.getDatablock().uiName $= "1x1f") {
$Map[0] = $Map[0] + 1;
$Map[$Map[0],0] = %brick.colorID;
%x = getWord(%brick.getPosition(),0);
%y = getWord(%brick.getPosition(),1);
%x = (%x + 173.25)*32;
%y = (%y - 110.25)*32;
$Map[$Map[0],1] = %x SPC %y SPC "0.1";
}
}
}

function makeMap() {
for(%i = 0; %i < $Map[0]; %i = %i + 1) {
%newbrick = new fxDTSBrick() {
dataBlock = brick32x32fData;
scale = "1 1 1";
client = 0;
stackBL_ID = 0;
angleID = 0;
colorID = $Map[%i,0];
colorFXID = 0;
printID = 0;
shapeFXID = "0";
rotation = "1 0 0 0";
};

%newbrick.setTransform($Map[%i,1] SPC %height);
%newbrick.setTrusted(1);
%newbrick.plant();
BrickGroup_27690.add(%newbrick);
}
}



For 64x baseplates (damn this is huge)
Code: [Select]
function getMap() {
$Map[0] = 0;
for(%i = 0; %i < BrickGroup_27690.getCount(); %i = %i + 1) {
%brick = BrickGroup_27690.getObject(%i);
if(%brick.getDatablock().uiName $= "1x1f") {
$Map[0] = $Map[0] + 1;
$Map[$Map[0],0] = %brick.colorID;
%x = getWord(%brick.getPosition(),0);
%y = getWord(%brick.getPosition(),1);
%x = (%x + 173.25)*64;
%y = (%y - 110.25)*64;
$Map[$Map[0],1] = %x SPC %y SPC "0.1";
}
}
}

function makeMap() {
for(%i = 0; %i < $Map[0]; %i = %i + 1) {
%newbrick = new fxDTSBrick() {
dataBlock = brick64x64fData;
scale = "1 1 1";
client = 0;
stackBL_ID = 0;
angleID = 0;
colorID = $Map[%i,0];
colorFXID = 0;
printID = 0;
shapeFXID = "0";
rotation = "1 0 0 0";
};

%newbrick.setTransform($Map[%i,1] SPC %height);
%newbrick.setTrusted(1);
%newbrick.plant();
BrickGroup_27690.add(%newbrick);
}
}
« Last Edit: February 23, 2017, 01:38:38 PM by Pastrey Crust »

Lol, you should make this a bit more dynamic IMO. First, users shouldn't have to initialize/set variables every time they want to call the function, this should be handled internally. Secondly, why not just have the function take an argument which changes the size instead of providing 10 different functions for each size?

This is a cool tool but people are lazy and want to do the least amount of work possible, so when developing a tool, you should try to make it as nice/easy as possible for other modders to implement. Would like to see more revisions on this with more features.

Edit: Plz no generic var/function names to avoid possible confliction.
« Last Edit: February 23, 2017, 02:47:24 PM by elm »

To be honest, I never intended on releasing this since it's such a simple piece of code. Bloo Kirby the 2nd asked me to post it.

Well thank you for posting this.

In makeMap you're dropping the last brick in that loop.  Counting starts at 1 on your stored info.
Also I wouldn't suggest making bricks that quickly.  I've run into issues with similar coding and some of bricks not appearing.  Dunno if you ran into that.

Here's how I would do it:
Code: [Select]
function scaleMap(%dbname,%blid)
{
    if(!isObject(%dbname)){echo("targetdb doesn't exist");return;}
    %scalex = %dbname.sizeX;
    %scaley = %dbname.sizeY;
   
    if(isObject(MapScaler)){MapScaler.delete();}
    %scaler = new SimObject(MapScaler);

    %bg = nametoid("BrickGroup_"@%blid);
    %scaler.bg = %bg;
    %scaler.dbname = %dbname;
    %count = %bg.getCount();
for(%i = 0; %i < %count; %i++)
    {
        %brickcount = 0;
%brick = %bg.getObject(%i);
if(%brick.getDatablock().uiName $= "1x1f")
        {
%scaler.brick[%brickcount,0] = %brick.colorID;
%x = (getWord(%brick.getPosition(),0)+ 173.25)*%scalex;
%y = (getWord(%brick.getPosition(),1) - 110.25)*%scaley;
%scaler.brick[%brickcount,1] = %x SPC %y SPC "0.1";
    %brickcount += 1;
}
}
}

function makeMap()
{
    if(!isObject(MapScaler)){echo("run scaleMap() first");return;}
    %scaler = MapScaler;
    %scaler.loopTick = schedule(100,%scaler,"makeMapLoop",%scaler,0);
}

function makeMapLoop(%scaler,%line)
{
    cancel(%scaler.loopTick);
   
    if(%scaler.brick[%line,1]$=""){echo("Finished.");return;}
   
    %newbrick = new fxDTSBrick()
    {
        dataBlock = %scaler.dbname;
        scale = "1 1 1";
        client = 0;
        stackBL_ID = mAbs(%scaler.bg.bl_id);//I'm pretty sure this exists, if not it will turn into a 0. like the original code. ...  I dunno if this even needs to be anything...
        angleID = 0;
        colorID = %scaler.brick[%line,0];
        colorFXID = 0;
        printID = 0;
        shapeFXID = "0";
        rotation = "1 0 0 0";
    };

    %newbrick.setTransform(%scaler.brick[%line,1]);
    %newbrick.setTrusted(1);
    %newbrick.plant();
    %scaler.bg.add(%newbrick);
   
    %line +=1;
    %scaler.loopTick = schedule(100,%scaler,"makeMapLoop",%scaler,%line);
}

Dunno if it's any better.  It was just a nice thing to do over breakfast.

Uh- is there any reason you have those specific 173.25 and 110.25 offsets?

Yes. I built some stuff there and then realized that if I built the map at 0,0, those buildings would've messed with the brick planting also no, didn't run into unplanted bricks.