[Rel] Hotbuild [57164]

Discussion in 'Mod Discussions' started by cola_colin, August 3, 2013.

Thread Status:
Not open for further replies.
  1. proeleert

    proeleert Post Master General

    Messages:
    1,681
    Likes Received:
    1,656
    My version.
    Altered to use default_keybinds system.
    Also easier to read.
    Removed some stuff.
    Only 1 js.file
    Can now type real keys instead of ascii codes.

    Code:
    //Pause / Unpause energy
    function energyToggle(event)
    {
          var currentOrder = model.selectedEnergyOrderIndex();
          if (currentOrder === 0) {
            eOrder = 'conserve';
          } else {
            eOrder = 'consume';
          }
          model.selectedEnergyOrderIndex(model.energyOrdersMap[eOrder]);
          closeFabMode();
          engine.call('set_order_state', 'energy', eOrder);
          event.preventDefault();
    }
    
    function polelockToggle(event)
    {
                var allSettings = decode(localStorage.settings);
                var currentPoleLock = allSettings.camera_pole_lock.toLowerCase(); // the settings store this upper case, the engine processes it in lowercase... wtf
                var nextSetting = "";
                if (currentPoleLock === 'off') {
                    nextSetting = "on";
                } else {
                    nextSetting = "off";
                }
                engine.call("set_camera_pole_lock", nextSetting);
                allSettings.camera_pole_lock = nextSetting.toUpperCase();
                localStorage.settings = encode(allSettings);
                event.preventDefault();
    }
    
    //begin hotbuild functions
    var currentCycleId = 0;
    var cycleResetTime = 1000;
    var lastCycleTimestamp = new Date();
    var lastkey = 0;
    
    function hotBuild(event,hotbuilds)
    {
      //Nothing selected don't do anything or Game hasn't started
      if(!model.hasSelection() || model.showLanding() || model.chatSelected())
        return;
    
      if (knowsAnyBuildCommand(hotbuilds))
      {
        var failDetect = 0;
        do {
          doCycleId(hotbuilds.length, event.which);
          failDetect++;
          if (failDetect > 1000) {
            gameConsole.log("loop of death\n"); // I dont think this should ever happen...
            return;
          }
        } while(!knowsBuildCommand(hotbuilds[currentCycleId]) && knowsAnyBuildCommand(hotbuilds));
       
        var target = getBuildItemId(hotbuilds[currentCycleId]);
       
        model.executeStartBuild(event, target); //do it do it now
        event.preventDefault();
      }
      else
      {
        gameConsole.log('could not hotbuild item ' + hotbuilds[currentCycleId]);
      }
    }
    
    function knowsAnyBuildCommand(cmds) {
      for (var i = 0; i < cmds.length; i++) {
        if (knowsBuildCommand(cmds[i])) {
          return true;
        }
      }
      return false;
    }
    
    function knowsBuildCommand(cmd) {
      for(var i = 0; i < model.buildItems().length; i++) {
        if (model.buildItems()[i].id() == cmd) {
          return true;
        }
      }
      return false;
    }
    
    function getBuildItemId(cmd) {
      for (var i = 0; i < model.buildItems().length; i++) {
        if (model.buildItems()[i].id() == cmd) {
          return i;
        }
      }
      return -1;
    }
    //move trough hotbuilds array when pushing multiple time the same key in a certain time interval
    function doCycleId(length, key) {
      var thisTime = new Date();
      if (thisTime - lastCycleTimestamp > cycleResetTime
        || key != lastkey) {
        currentCycleId = 0;
      } else {
        currentCycleId++;
        if (currentCycleId == length) {
          currentCycleId = 0;
        }
      }
      lastCycleTimestamp = thisTime;
      lastkey = key;
    }
    //end hotbuilds functions
           
    function closeFabMode() {
      if (model.mode() === 'fab') {
        model.endFabMode();
      }
    }
    
    var hotbuild1 = [
        '/pa/units/land/metal_extractor_adv/metal_extractor_adv.json',
        '/pa/units/land/metal_extractor/metal_extractor.json',
        '/pa/units/land/vehicle_factory_adv/vehicle_factory_adv.json',
        '/pa/units/land/bot_factory_adv/bot_factory_adv.json',
        '/pa/units/air/air_factory_adv/air_factory_adv.json',
        '/pa/units/sea/naval_factory_adv/naval_factory_adv.json'
    ];
    var hotbuild2 = [
        '/pa/units/land/energy_plant_adv/energy_plant_adv.json',
      '/pa/units/land/energy_plant/energy_plant.json',
        '/pa/units/land/radar_adv/radar_adv.json',
        '/pa/units/land/radar/radar.json',
      '/pa/units/land/assault_bot/assault_bot.json',
      '/pa/units/land/assault_bot_adv/assault_bot_adv.json',
      '/pa/units/land/tank_light_laser/tank_light_laser.json',
        '/pa/units/land/tank_laser_adv/tank_laser_adv.json',
        '/pa/units/air/fighter/fighter.json', 
        '/pa/units/air/bomber_adv/bomber_adv.json',
        '/pa/units/sea/destroyer/destroyer.json',       
        '/pa/units/sea/battleship/battleship.json'
    ];
    var hotbuild3 = [
      '/pa/units/land/air_defense/air_defense.json',
      '/pa/units/land/laser_defense_single/laser_defense_single.json',
      '/pa/units/land/artillery_short/artillery_short.json',
        '/pa/units/land/laser_defense_adv/laser_defense_adv.json',
      '/pa/units/land/laser_defense/laser_defense.json',
        '/pa/units/land/land_barrier/land_barrier.json'
    ];
    var hotbuild4 = [
        '/pa/units/land/vehicle_factory/vehicle_factory.json',
        '/pa/units/land/bot_factory/bot_factory.json',
        '/pa/units/air/air_factory/air_factory.json',
        '/pa/units/sea/naval_factory/naval_factory.json',
      '/pa/units/land/fabrication_bot/fabrication_bot.json',
        '/pa/units/land/fabrication_bot_adv/fabrication_bot_adv.json',
        '/pa/units/land/fabrication_vehicle/fabrication_vehicle.json',
        '/pa/units/land/fabrication_vehicle_adv/fabrication_vehicle_adv.json',
        '/pa/units/air/fabrication_aircraft/fabrication_aircraft.json',
        '/pa/units/air/fabrication_aircraft_adv/fabrication_aircraft_adv.json',
        '/pa/units/sea/fabrication_sub/fabrication_sub.json',
        '/pa/units/sea/fabrication_ship_adv/fabrication_ship_adv.json'
    ];
    
    action_sets['gameplay']['hotbuild1'] = function (event) {hotBuild(event, hotbuild1)};
    action_sets['gameplay']['hotbuild2'] = function (event) {hotBuild(event, hotbuild2)};
    action_sets['gameplay']['hotbuild3'] = function (event) {hotBuild(event, hotbuild3)};
    action_sets['gameplay']['hotbuild4'] = function (event) {hotBuild(event, hotbuild4)};
    action_sets['gameplay']['energytoggle'] = function (event) {energyToggle(event)};
    action_sets['gameplay']['pole_lock'] = function (event) {polelockToggle(event)};
    
    default_keybinds['gameplay']['hotbuild1'] = 'e';
    default_keybinds['gameplay']['hotbuild2'] = 'r';
    default_keybinds['gameplay']['hotbuild3'] = 'q';
    default_keybinds['gameplay']['hotbuild4'] = 'f';
    default_keybinds['gameplay']['energytoggle'] = 'tab';
    default_keybinds['gameplay']['pole_lock'] = 'p';
    
  2. MindALot

    MindALot Member

    Messages:
    38
    Likes Received:
    5
    I noticed you overrode reclaim, but do not have a new key for it - what do you use to reclaim ?
  3. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,074
    Likes Received:
    16,221
    I think i, but I dont really reclaim much currently. It costs energy and most wrecks are destroyed before you even can reclaim them.
  4. proeleert

    proeleert Post Master General

    Messages:
    1,681
    Likes Received:
    1,656
    Updated my code with even less code :)
    Code:
    //HOTBUILD works in .57499
    // unit selection cannot cycle!
    /*
    E: MEX / Adv Factories
    R: Power / Radar / Basic Spam / Adv Spam
    A: Air Def / Single Laser / Pelter / Adv Laser / Med Laser / Wall
    F: Veh Fac / Bot Fac / Air Fac / Nav Fac / Fabber
    TAB: Pause / Unpuase
    */
    
    //Pause / Unpause energy
    function energyToggle(event)
    {
          var currentOrder = model.selectedEnergyOrderIndex();
          if (currentOrder === 0) {
            eOrder = 'conserve';
          } else {
            eOrder = 'consume';
          }
          model.selectedEnergyOrderIndex(model.energyOrdersMap[eOrder]);
          closeFabMode();
          engine.call('set_order_state', 'energy', eOrder);
          event.preventDefault();
    }
    
    function polelockToggle(event)
    {
                var allSettings = decode(localStorage.settings);
                var currentPoleLock = allSettings.camera_pole_lock.toLowerCase(); // the settings store this upper case, the engine processes it in lowercase... wtf
                var nextSetting = "";
                if (currentPoleLock === 'off') {
                    nextSetting = "on";
                } else {
                    nextSetting = "off";
                }
                engine.call("set_camera_pole_lock", nextSetting);
                allSettings.camera_pole_lock = nextSetting.toUpperCase();
                localStorage.settings = encode(allSettings);
                event.preventDefault();
    }
    
    //begin hotbuild functions
    var currentCycleId = 0;
    var cycleResetTime = 1000;
    var lastCycleTimestamp = new Date();
    var lastkey = 0;
    
    function hotBuild(event,hotbuilds)
    {
      if (model['maybeSetBuildTarget'])
      {
        if (knowsAnyBuildCommand(hotbuilds))
        {
          var failDetect = 0;
          do {
            doCycleId(hotbuilds.length, event.which);
            failDetect++;
            if (failDetect > 1000) {
              gameConsole.log("loop of death\n"); // I dont think this should ever happen...
              return;
            }
          } while(!knowsBuildCommand(hotbuilds[currentCycleId]) && knowsAnyBuildCommand(hotbuilds));
         
          model['maybeSetBuildTarget'](hotbuilds[currentCycleId]);
          event.preventDefault();
        }
        else
        {
          gameConsole.log('could not hotbuild item ' + hotbuilds[currentCycleId]);
        }
      }
    }
    
    function knowsAnyBuildCommand(cmds) {
      for (var i = 0; i < cmds.length; i++) {
        if (knowsBuildCommand(cmds[i])) {
          return true;
        }
      }
      return false;
    }
    
    function knowsBuildCommand(cmd) {
      for(var i = 0; i < model.buildItems().length; i++) {
        if (model.buildItems()[i].id() == cmd) {
          return true;
        }
      }
      return false;
    }
    
    //move trough hotbuilds array when pushing multiple time the same key in a certain time interval
    function doCycleId(length, key) {
      var thisTime = new Date();
      if (thisTime - lastCycleTimestamp > cycleResetTime
        || key != lastkey) {
        currentCycleId = 0;
      } else {
        currentCycleId++;
        if (currentCycleId == length) {
          currentCycleId = 0;
        }
      }
      lastCycleTimestamp = thisTime;
      lastkey = key;
    }
    //end hotbuilds functions
           
    function closeFabMode() {
      if (model.mode() === 'fab') {
        model.endFabMode();
      }
    }
    
    var hotbuild1 = [
        '/pa/units/land/metal_extractor_adv/metal_extractor_adv.json',
        '/pa/units/land/metal_extractor/metal_extractor.json',
        '/pa/units/land/vehicle_factory_adv/vehicle_factory_adv.json',
        '/pa/units/land/bot_factory_adv/bot_factory_adv.json',
        '/pa/units/air/air_factory_adv/air_factory_adv.json',
        '/pa/units/sea/naval_factory_adv/naval_factory_adv.json'
    ];
    var hotbuild2 = [
        '/pa/units/land/energy_plant_adv/energy_plant_adv.json',
      '/pa/units/land/energy_plant/energy_plant.json',
        '/pa/units/land/radar_adv/radar_adv.json',
        '/pa/units/land/radar/radar.json',
      '/pa/units/land/assault_bot/assault_bot.json',
      '/pa/units/land/assault_bot_adv/assault_bot_adv.json',
      '/pa/units/land/tank_light_laser/tank_light_laser.json',
        '/pa/units/land/tank_laser_adv/tank_laser_adv.json',
        '/pa/units/air/fighter/fighter.json', 
        '/pa/units/air/bomber_adv/bomber_adv.json',
        '/pa/units/sea/destroyer/destroyer.json',       
        '/pa/units/sea/battleship/battleship.json'
    ];
    var hotbuild3 = [
      '/pa/units/land/air_defense/air_defense.json',
      '/pa/units/land/laser_defense_single/laser_defense_single.json',
      '/pa/units/land/artillery_short/artillery_short.json',
        '/pa/units/land/laser_defense_adv/laser_defense_adv.json',
      '/pa/units/land/laser_defense/laser_defense.json',
        '/pa/units/land/land_barrier/land_barrier.json'
    ];
    var hotbuild4 = [
        '/pa/units/land/vehicle_factory/vehicle_factory.json',
        '/pa/units/land/bot_factory/bot_factory.json',
        '/pa/units/air/air_factory/air_factory.json',
        '/pa/units/sea/naval_factory/naval_factory.json',
      '/pa/units/land/fabrication_bot/fabrication_bot.json',
        '/pa/units/land/fabrication_bot_adv/fabrication_bot_adv.json',
        '/pa/units/land/fabrication_vehicle/fabrication_vehicle.json',
        '/pa/units/land/fabrication_vehicle_adv/fabrication_vehicle_adv.json',
        '/pa/units/air/fabrication_aircraft/fabrication_aircraft.json',
        '/pa/units/air/fabrication_aircraft_adv/fabrication_aircraft_adv.json',
        '/pa/units/sea/fabrication_sub/fabrication_sub.json',
        '/pa/units/sea/fabrication_ship_adv/fabrication_ship_adv.json'
    ];
    
    action_sets['gameplay']['hotbuild1'] = function (event) {hotBuild(event, hotbuild1)};
    action_sets['gameplay']['hotbuild2'] = function (event) {hotBuild(event, hotbuild2)};
    action_sets['gameplay']['hotbuild3'] = function (event) {hotBuild(event, hotbuild3)};
    action_sets['gameplay']['hotbuild4'] = function (event) {hotBuild(event, hotbuild4)};
    action_sets['gameplay']['energytoggle'] = function (event) {energyToggle(event)};
    action_sets['gameplay']['pole_lock'] = function (event) {polelockToggle(event)};
    
    default_keybinds['gameplay']['hotbuild1'] = 'e';
    default_keybinds['gameplay']['hotbuild2'] = 'r';
    default_keybinds['gameplay']['hotbuild3'] = 'q';
    default_keybinds['gameplay']['hotbuild4'] = 'f';
    default_keybinds['gameplay']['energytoggle'] = 'tab';
    default_keybinds['gameplay']['pole_lock'] = 'p';
    
    //maybe check keybind conflicts and give popup warning
    stormingkiwi likes this.
  5. numerials

    numerials New Member

    Messages:
    4
    Likes Received:
    1
    So i've been fiddling around with this a bit and can't see the problem mysel I defer to you guys maybe can help me out:

    Problem occurs when using this mod with mexcounter. Either one of them individually works just fine problem doesn't exist.

    When I start a game with this mod & mexcounter enabled through mod-manager I can create a game enter game but there is no zone for selecting at start (A, B, C etc.) And my name in upper left corner for players does NOT say "(Selecting)" nor does the AI.

    Note: Probably completely UNRELATED problem but just incase somebody good detective and its relavant, my modmanager doesn't display bottom half of its screen. I'll upload image once uber-forums allows me to (limit on posts?)

    Running Uber-Launcher with build 57703

    Much appreciate the hard work you guys do!
  6. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,074
    Likes Received:
    16,221
    It sounds like hotbuild and mex counter may be incompatible in some way that breaks the ui.
    I've never used mex counter so far. Maybe I will look into it, but no guarantee on that.
  7. stormingkiwi

    stormingkiwi Post Master General

    Messages:
    3,266
    Likes Received:
    1,355
    I was fiddling around in the game files (to be exact I was adding catapults to a hotkey)

    There are a lot of interesting looking units in the files which 'aren't' in the game... I'm not sure how new they are.. but there's no mention of units like the Crater Maker anywhere that I've seen?

    @proeleert - nice :) I'll stick with Colins because I'm used to it now and I've found some of them a bit of a pain
  8. proeleert

    proeleert Post Master General

    Messages:
    1,681
    Likes Received:
    1,656
    Good idea, there are some bugs in my version, will package the fixed version nicely this weekend.

    Indeed there are , can't wait to use them all :)
  9. stormingkiwi

    stormingkiwi Post Master General

    Messages:
    3,266
    Likes Received:
    1,355
    Im sorry I dont know what I meant when I said I've found bits a pain. Although if you can get catapults working that would be awesome!
  10. proeleert

    proeleert Post Master General

    Messages:
    1,681
    Likes Received:
    1,656
    My version see attached.
    Compatible with mod manager.
    It should have all functions of the original hotbuild mod.
    In the hotbuild2.ini file you can choose which keys you prefer.
    Change following line
    Code:
    live_game='../../mods/hotbuild2/live_game/hotbuild.css','../../mods/hotbuild2/live_game/hotbuild.js','../../mods/hotbuild2/live_game/keys.js'
    to
    Code:
    live_game='../../mods/hotbuild2/live_game/hotbuild.css','../../mods/hotbuild2/live_game/hotbuild.js','../../mods/hotbuild2/live_game/originalkeys.js'
    Or check out keys.js or originalkeys.js if you want to further modify your keys / actions.

    On pressing a key you get a preview what the next building will be when you press the key again. See screenshots :)
    [​IMG]

    [​IMG]

    TODO :
    - Hide images / name after a fixed time ?
    - Add a variable to toggle queuepreview thing on or off
    - Give warning when there are keyconflicts
    - Nicer queuepreview thingie/ placement / layout ?
    - Find out if I can add strategic icon to queuepreview thingie
    - Fix Bugs
    - Any thing else ?
    - Ideas ?

    Offcourse this isn't compatible with hotbuild of cola_colin / so to use this switch hotbuild off.

    cola_colin should I start a new thread for my changed version ?
    Push it to github ?

    Attached Files:

    cola_colin and Quitch like this.
  11. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,074
    Likes Received:
    16,221
    If you give me your github account name I can add you to the pamods group, so you can push it to the repository yourself.
    You can make your own thread, I will close this one and link yours.

    EDIT:
    Also good looking work. I guess I wont have to bother with a rewrite of hotbuild anymore. You can do it :)

    I have enough on my todo list just with PA Stats anyway...

    EDIT 2:
    Something that the mods really needs is more keys, so any building/unit in the game is bound to a reasonable key.
    Last edited: December 8, 2013
  12. Quitch

    Quitch Post Master General

    Messages:
    5,885
    Likes Received:
    6,045
    It seems odd that, by default, the missile launcher and wall share a hotkey. Everything else that's key sharing shares a function.
  13. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,074
    Likes Received:
    16,221
    I've never tried to do this "share a function" pattern, it just randomly happened.
    Also I am surprised hotbuild1 still works. Haven't used it for a while. It's not supported anymore from my side.
  14. Quitch

    Quitch Post Master General

    Messages:
    5,885
    Likes Received:
    6,045
    Oh this is hotbuild1? ****, sorry, wrong topic :)
    reptarking and cola_colin like this.
  15. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,074
    Likes Received:
    16,221
    /lock, so nobody else ends up confused
Thread Status:
Not open for further replies.

Share This Page