Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
// Warzone 3.1 Beta 1 had a bug in pickStructLocation()
// see http://forums.wz2100.net/viewtopic.php?f=35&t=8694 for details
// Let's fix that bug...
 
(function() {
 
  // We can work out if this bug is present by checking whether removeReticuleButton() is present
  // removeReticuleButton() was added to the JS API in the same version that the pickStructLocation() bug was fixed


  if (!backport.global.removeReticuleButton) { // the pickStructLocation() bug is present
 
    // define a new function that calls the original function then fixes it's return value
    backport("pickStructLocation",function(droid,structureType,x,y) {
      // apply the original (native) function
      var pos = pickStructLocation.native.apply(null,arguments);
      // the bug effected everything except cyborg factories
      if (structureType != "A0CyborgFactory") {
        pos.x += 1;
        pos.y += 1;
      }
      // return correct position back to calling script
      return pos;
    });
 
  }
 
})();
 
// thereafter, scripts can safely use pickStructLocation() without having to worry about offset bugs :)

You can get the pickStructLocation bugfix in a ready-made backport script: pickStructLocation.js (smile)

See also