Utility Script: vgap Super Filter

« Back to Developers

2655 days, 23 hours, 3 minutes ago
View big beefer's profile
big beefer
Utility Script: vgap Super FilterWrite Reply
Here's an add-on for the coders and those familiar with the objects returned by the API. It adds a filtering mechanism to the ship/planet/base list to find matches based on arbitrary criteria you provide. Very powerful, but a little dangerous too. Be very careful, and know what you are doing, it is quite possible to screw things up (since we're running the code you put in), ie. if you enter:
  return ship.mission = "HYP";
instead of
  return ship.mission == "HYP";
you will likely set all of the FCs for all of your ships to HYP, which may not be what you intended.

Maybe test it out on some finished games or games where possibly having to reset the turn is not a big deal. I'd like to put in a method to save preset filters, but for now you have to type them in.

Anways, here's the notes I included with the script, which hopefully explain how to use it somewhat:
1. Adds a "Filter" checkbox and textarea to lists. When the checkbox is checked
the code in the textbox will be run to evaluate each item for inclusion on
the filitered list, as follows:

The input in the textbox should represent the body of a javascript function
which takes one parameter (ship, planet, or starbase respectively) and
returns a value which can be evaluated as a boolean represnting inclusion.

Example, ship filter, filters all ships with FC equivalent to "HYP":

return ship.friendlycode.toUpperCase() == "HYP";

Example, planet filter, filters all planets able to build a base:

return (planet.duranium >= 120 && planet.tritanium >= 402 &&
planet.molybdenum >= 340 && planet.megacredits >= 900 &&
!planet.buildingstarbase && vgap.getStarbase(planet.id) == null);

Example, starbase filter, filters bases with no ships in orbit:

planet = vgap.getPlanet(starbase.planetid);
return vgap.shipsAt(planet.x, planet.y).length == 0;

2. When a filter is active, the "back" and "next" controls on the map
will only iterate through the filtered set. All/idle will be selected
on the filtered set as well.
http://userscripts.org/scripts/show/132440


2655 days, 11 hours, 27 minutes ago
View lord helmet's profile
lord helmet
RE: Utility Script: vgap Super FilterWrite Reply
Well, nice idea, you can do a lot when diving into the code. I'd like to contribute some more examples:
I'm taxing natives down to happyness 70 and let them recover for a turn or two. So I tried to filter planets where natives can to be taxed higher (down to 70) this turn - not including Fed bonus or Borg malus but 5000mc cap and Insectoids:

return planet.nativeclans>0 && planet.nativehappypoints>70 && planet.clans>Math.min(Math.round(planet.nativetaxrate * planet.nativegovernment * 20 / 100 * planet.nativeclans / 1000 * (planet.nativetype==6 ? 2:1)), 5000)

It still includes planets where there are only few native clans but that could be filtered out too.

And here's the equivalent for the planets to stop taxing:

return (planet.nativehappypoints>=70 && planet.nativehappypoints+planet.nativehappychange<70)

Nice job - again ;)