[SOLVED ]Intelligent Building placement



  • I need help figuring out the problem with this Script i wrote...

    Basically it's calculating the rooms possible Extensions and builds them in a pattern or is atleast supposed to... the pattern is stored int the template variable... the algorithm is written to find a place where it can built the template and if the template wouldnt fit inside anyways it will skip a few x values ahead to save CPU... (it breaks the Limitation of 30 CPU anyways but thats why theres a bucket...) 

     

    EDIT: SOLVED code is working now:



  • I'm working on similar code myself.

    I've found that using the RoomVisuals system is amazing for debugging code like this.

    Without reading through your code looking for errors, and since you didn't say what kind of help you want except that apparently the code isn't doing what you think it should - my advice is to add some debug code to draw circles/squares/polygons/etc on the screen when your code detects collisions or when it thinks it has found a nice spot to put structures down.

    I imagine once you can visualize its calculations you'll find your issues fairly easily.

    Good luck!  🙂



  • I actually did that with console input and dont know why its skipping a few values or not detects some wall elements even if it logs them as wall... 

     

    -EDIT: I activated a few Visual logs and you can check them out if you want... the algorithm works to some extend but I still have a problem with the coordinates thats completely breaking my mind... somehow the coordinates its checking are offset by ... something... not even rotated I checked on that...



  • Dont ask me why it has this path... probs messed up an x -y xD

     



  • Looks like you're on the right track.  That entire structure has an X value too small and a Y value too big.  Maybe adding an offset to the Y instead of the X in one of the calcs?



  • i just completely redesigned the code couse it was a bit confusing here and there ... (the code im using is now up there...) im currently testing it but forgot the visual log again xD but in theory it should work

     



  • How can that be possible.......... 

    //if valid count up else reset the counter
    if(invalidTile){
    new RoomVisual(room).drawCross(gridX + tx + area[0],gridY + ty + area[1],{color: '#ff0000'})
    counter = 0;
    //skip to the position after the invalid tile (couse scanning through the area between invalid tile and start point is pointless couse it would always return invalid)
    console.log(gridXkey+" -> "+Object.keys(scan[gridYkey])[txScanKey]);
    gridXkey = Object.keys(scan[gridYkey])[txScanKey];
    } else {
    counter++
    new RoomVisual(room).drawCross(gridX + tx + area[0],gridY + ty + area[1],{color: '#00ff00'})
    }