[WIP]Imba Walls

Discussion in 'Mod Discussions' started by cola_colin, January 20, 2014.

  1. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,074
    Likes Received:
    16,221
    So walls are imba around turrets or not. We should try more to use them like we did in FA to see how imba they are, so Uber can maybe fix them. However placing walls around turrets is a hassle. So inspired by trialq's "Building Writing" I build a mod that kind of works the same way, just it exactly can do one thing: Build a turrets and put walls around it, as tight as possible.
    Look here how it looks:


    Note a few things:
    - Due to how it works (place the turret, wait until it is really placed and then try to place 8 walls in 8 directions around it by trying different build locations starting at the turret and slowly moving away until the wall can be placed) it is a bit slow, but way faster and more precise that any human
    - When using it you need to press the button and then wait until it plays the build sound, do not give commands or move the camera. Mouse movement is okay.
    - It works best when applied at a middle zoom in the middle of the screen, as it suffers from the curvature of the planet.
    - Currently only does a t1 turret, but can be easily modified to do a t2 turret, that's a task that needs to be done when it is implemented as a public mod.

    So I am only wondering if this justifies it's own mod or ...
    @proeleert: Would you like to include this as a part of hotbuild2? The code to do it is this placed in the live_game js. I think you are able to use it, check out how it is bound to m and M at the bottom:

    Code:
        // somehow when putting this directly into live_game js I cannot use an anon func.
        // can be changed to the usual anon func pattern latter
        var fooooobar = function() {
            var stepSize = 3;
            var oldZoomLevel = handlers.zoom_level;
            handlers.zoom_level = function(payload) {
                oldZoomLevel(payload);
                switch(payload.zoom_level) {
                    case "surface":
                        stepSize = 8;
                        break;
                    case "air":
                        stepSize = 3;
                        break;
                    case "orbital":
                        stepSize = 2;
                        break;
                    case "celestial":
                        stepSize = 1;
                        break;
                }
            };
     
            function buildAt(x, y, spec, queue, complete) {
                api.arch.beginFabMode(spec).then(function(ok) {
                    buildSelectedAt(x, y, queue, function(suc) {
                        api.arch.endFabMode();
                        if (complete) {
                            complete(suc);
                        }
                    });
                });
            }
         
            function buildSelectedAt(x, y, queue, complete) {
                holodeck.unitBeginFab(x, y, false);
                holodeck.unitEndFab(x, y, queue, false).then(function(success) {
                    if (complete) {
                        complete(success);
                    }
                });
            }
             
            function tryInLine(x, y, dir, complete) {
                var maxStepSize = 200;
                var stepCounter = 0;
                var doStep = function(suc) {
                    stepCounter += stepSize;
                    if (!suc && stepCounter < maxStepSize) {
                        var xx = x;
                        var yy = y;
                        for (var d = 0; d < dir.length; d++) {
                            switch(dir[d]) {
                                case "up":
                                    xx -= stepCounter;
                                    break;
                                case "down":
                                    xx += stepCounter;
                                    break;
                                case "right":
                                    yy += stepCounter;
                                    break;
                                case "left":
                                    yy -= stepCounter;
                                    break;
                            }
                        }
                        buildSelectedAt(xx, yy, true, doStep);
                    } else {
                        if (complete) {
                            complete();
                        } else {
                            api.arch.endFabMode();
                            api.audio.playSound("/SE/UI/UI_Building_place");
                        }
                    }
                };
                doStep(false);
            }
         
            var holodeck = api.Holodeck.get($('.holodeck'));
            var mouseX = 0;
            var mouseY = 0;
            $(document).mousemove(function(e) {
                mouseX = e.clientX;
                mouseY = e.clientY;
            });
         
            var imbaWall = function(queue) {
                if (model.selectedMobile()) {
                    var wall = "/pa/units/land/land_barrier/land_barrier.json";
                    var turret = "/pa/units/land/laser_defense/laser_defense.json";
                    (function() {
                        var mX = mouseX;
                        var mY = mouseY;
                        buildAt(mX, mY, turret, queue, function(suc) {
                            if (suc) {
                                // if we do not wait for a bit the turret wont be placed already
                                // it would not block the walls, making everything fail by placing the walls inside the turret
                                // does anybody know what to do about this?!
                                window.setTimeout(function() {
                                    api.arch.beginFabMode(wall).then(function(ok) {
                                        // the callback of the callback of the callback of the oh wtf
                                        tryInLine(mX, mY, ["up"], function() {
                                            tryInLine(mX, mY, ["down"], function() {
                                                tryInLine(mX, mY, ["right"], function() {
                                                    tryInLine(mX, mY, ["left"], function() {
                                                        tryInLine(mX, mY, ["up", "left"], function() {
                                                            tryInLine(mX, mY, ["up", "right"], function() {
                                                                tryInLine(mX, mY, ["down", "left"], function() {
                                                                    tryInLine(mX, mY, ["down", "right"]);
                                                                });
                                                            });
                                                        });
                                                    });
                                                });
                                            });
                                        });
                                    });
                                }, 750);
                            }
                        });
                    }());
                }
            };
         
            Mousetrap.bind("m", function() {imbaWall(false);});
            Mousetrap.bind("M", function() {imbaWall(true);});
        };
        fooooobar();
  2. proeleert

    proeleert Post Master General

    Messages:
    1,681
    Likes Received:
    1,656
    I don't mind including this in hotbuild2 at all :)
  3. proeleert

    proeleert Post Master General

    Messages:
    1,681
    Likes Received:
    1,656
    only quick question what's the difference between imbaWall(false) and imbaWall(true) ?
  4. proeleert

    proeleert Post Master General

    Messages:
    1,681
    Likes Received:
    1,656
    Cause I don't see no difference ? I want to bind it to a case insensitive key that's why :)
    Ok it's for queuing :) cool so I leave it true no matter what :)

    Hmmm should I auto Imbawall hotbuild defenses ? Or make an option hmmm :)
    Again an interesting codedrop :)
    Last edited: January 20, 2014
  5. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,074
    Likes Received:
    16,221
    I think the queue or not queue is pretty important. Without a way to do a false there you force the player to first cancel the current build order instead of allowing him to instant make a turret with walls.
    I think an option is better.
  6. proeleert

    proeleert Post Master General

    Messages:
    1,681
    Likes Received:
    1,656
    Yeah I see now :)

    upload_2014-1-20_21-29-59.png
    Imbawall eeeverything :)
    cola_colin likes this.
  7. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,074
    Likes Received:
    16,221
    lol
    I guess 8 walls is not enough for bigger buildings.
    You would need to make it more general for that ;)
  8. igncom1

    igncom1 Post Master General

    Messages:
    7,961
    Likes Received:
    3,132
    I find that walls get absolutely gutted by artillery and reclaiming.
  9. proeleert

    proeleert Post Master General

    Messages:
    1,681
    Likes Received:
    1,656
    Yes this can't be assigned to hotbuild keys but I've got a better idea :)

    When I press the imba wall key I get a popup where I can choose what to ImbaWall.

    upload_2014-1-20_22-20-37.png


    This gonna be neat :)
    Last edited: January 20, 2014
    Antiglow likes this.
  10. trialq

    trialq Post Master General

    Messages:
    1,295
    Likes Received:
    917
    This is awesome. Not only is it a mod I was going to do, I can now use your source as a guide to do the writing mod better.
    stormingkiwi likes this.
  11. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,074
    Likes Received:
    16,221
    Why cant it be assigned?
    I don't want want to use menus to select what I want to build. Isnt the whole point of hotbuild to just press a button and have what you want? I would imagine the best solution would be to have a key to does a turret + walls with either t2 or t1 turret, depending on what is available. Or some sort of extra modifier that you can press while placing any building to add walls to it. That however would need a bit more modifications to the code I posted.
  12. proeleert

    proeleert Post Master General

    Messages:
    1,681
    Likes Received:
    1,656
    https://github.com/pietervanh/Hotbuild2 :p

    Anyways I know what to do this week now :) I'm gonna need screenshots of firebases :) and other buildtemplates. So much to do....

    Attached very very early version.

    Set key for popup in keyboard.

    upload_2014-1-20_22-40-40.png

    press key in game. ...

    Attached Files:

  13. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,074
    Likes Received:
    16,221
    You really want to go down the full template route?
    I feel that in PA the only template I will ever need is a turret + walls.
    So putting in a lot of work for a non perfect template system seems not to be worth it to me.
  14. proeleert

    proeleert Post Master General

    Messages:
    1,681
    Likes Received:
    1,656
    It works if it's a single hotkey fine.
    But say you have a list "single laser" , "double laser" where you have to toggle through.
    You can't toggle through anymore cause from the moment you click the button it start's building.
    Unlike normal mode where you have to click to build.
    Didn't further check it out actually.
    Modifier keys might do the trick ....

    Gonna check If we can have both.
    But now sleepy time.
  15. proeleert

    proeleert Post Master General

    Messages:
    1,681
    Likes Received:
    1,656
    Give me a night of sleep I'll think over it.
  16. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,074
    Likes Received:
    16,221
    hmm, yeah it isnt easy. But I think it is possible with some modifications to my code. What should be possible out of the box is just to skip the toggle. So if an engineer is able to do a t2 turret it will always do a t2 turret. t2 turrets are >>> t1 turrets, so no player would ever want to do a t1 turret when he can a t2 turret anyway I think.
  17. proeleert

    proeleert Post Master General

    Messages:
    1,681
    Likes Received:
    1,656
    That should be easy to do, actually it was like that when I tried :)
    Tomorrow with a clear head I'll look over the code and test some things out.
    Thnx for the code man :)
  18. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,074
    Likes Received:
    16,221
    thanks for doing the work of implementing it into a nice to configure mod. ;)
  19. stormingkiwi

    stormingkiwi Post Master General

    Messages:
    3,266
    Likes Received:
    1,355
    Yes.


    t2 turrets take longer to build than t1 turrets.

    Sometimes time is the most important factor.
  20. proeleert

    proeleert Post Master General

    Messages:
    1,681
    Likes Received:
    1,656

    myeees I got it better :)

    Just one small question provide a modifier to choose imbawall or a list in settings where you provide the structures to be imbawalled ?

    Now it's hardcoded for all defense turrets to be imbawalled :) Works pretty good.

    @cola_colin can you check if this is how you want it ?
    See my cool hack in hotbuild_core.js lines 481 to 490 :)

    Attached Files:

Share This Page