updated to comply with code review comments from breunigs
This commit is contained in:
parent
14a5803a64
commit
84390e7b66
44
main.js
44
main.js
@ -181,27 +181,35 @@ window.NOMINATIM = 'http://nominatim.openstreetmap.org/search?format=json&limit=
|
||||
|
||||
// INGRESS CONSTANTS /////////////////////////////////////////////////
|
||||
// http://decodeingress.me/2012/11/18/ingress-portal-levels-and-link-range/
|
||||
var RESO_NRG = [0, 1000, 1500, 2000, 2500, 3000, 4000, 5000, 6000];
|
||||
var MAX_XM_PER_LEVEL = [0, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000];
|
||||
var MIN_AP_FOR_LEVEL = [0, 10000, 30000, 70000, 150000, 300000, 600000, 1200000];
|
||||
var HACK_RANGE = 40; // in meters, max. distance from portal to be able to access it
|
||||
var OCTANTS = ['E', 'NE', 'N', 'NW', 'W', 'SW', 'S', 'SE'];
|
||||
var DESTROY_RESONATOR = 75; //AP for destroying portal
|
||||
var DESTROY_LINK = 187; //AP for destroying link
|
||||
var DESTROY_FIELD = 750; //AP for destroying field
|
||||
var CAPTURE_PORTAL = 500; //AP for capturing a portal
|
||||
var DEPLOY_RESONATOR = 125; //AP for deploying a resonator
|
||||
var COMPLETION_BONUS = 250; //AP for deploying all resonators on portal
|
||||
window.RESO_NRG = [0, 1000, 1500, 2000, 2500, 3000, 4000, 5000, 6000];
|
||||
window.MAX_XM_PER_LEVEL = [0, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000];
|
||||
window.MIN_AP_FOR_LEVEL = [0, 10000, 30000, 70000, 150000, 300000, 600000, 1200000];
|
||||
window.HACK_RANGE = 40; // in meters, max. distance from portal to be able to access it
|
||||
window.OCTANTS = ['E', 'NE', 'N', 'NW', 'W', 'SW', 'S', 'SE'];
|
||||
window.DESTROY_RESONATOR = 75; //AP for destroying portal
|
||||
window.DESTROY_LINK = 187; //AP for destroying link
|
||||
window.DESTROY_FIELD = 750; //AP for destroying field
|
||||
window.CAPTURE_PORTAL = 500; //AP for capturing a portal
|
||||
window.DEPLOY_RESONATOR = 125; //AP for deploying a resonator
|
||||
window.COMPLETION_BONUS = 250; //AP for deploying all resonators on portal
|
||||
|
||||
// OTHER MORE-OR-LESS CONSTANTS //////////////////////////////////////
|
||||
var TEAM_NONE = 0, TEAM_RES = 1, TEAM_ENL = 2;
|
||||
var TEAM_TO_CSS = ['none', 'res', 'enl'];
|
||||
var TYPE_UNKNOWN = 0, TYPE_PORTAL = 1, TYPE_LINK = 2, TYPE_FIELD = 3, TYPE_PLAYER = 4, TYPE_CHAT = 5, TYPE_RESONATOR = 6;
|
||||
window.TEAM_NONE = 0;
|
||||
window.TEAM_RES = 1;
|
||||
window.TEAM_ENL = 2;
|
||||
window.TEAM_TO_CSS = ['none', 'res', 'enl'];
|
||||
window.TYPE_UNKNOWN = 0;
|
||||
window.TYPE_PORTAL = 1;
|
||||
window.TYPE_LINK = 2;
|
||||
window.TYPE_FIELD = 3;
|
||||
window.TYPE_PLAYER = 4;
|
||||
window.TYPE_CHAT = 5;
|
||||
window.TYPE_RESONATOR = 6;
|
||||
|
||||
var SLOT_TO_LAT = [0, Math.sqrt(2)/2, 1, Math.sqrt(2)/2, 0, -Math.sqrt(2)/2, -1, -Math.sqrt(2)/2];
|
||||
var SLOT_TO_LNG = [1, Math.sqrt(2)/2, 0, -Math.sqrt(2)/2, -1, -Math.sqrt(2)/2, 0, Math.sqrt(2)/2];
|
||||
var EARTH_RADIUS=6378137;
|
||||
var DEG2RAD = Math.PI / 180;
|
||||
window.SLOT_TO_LAT = [0, Math.sqrt(2)/2, 1, Math.sqrt(2)/2, 0, -Math.sqrt(2)/2, -1, -Math.sqrt(2)/2];
|
||||
window.SLOT_TO_LNG = [1, Math.sqrt(2)/2, 0, -Math.sqrt(2)/2, -1, -Math.sqrt(2)/2, 0, Math.sqrt(2)/2];
|
||||
window.EARTH_RADIUS=6378137;
|
||||
window.DEG2RAD = Math.PI / 180;
|
||||
|
||||
// STORAGE ///////////////////////////////////////////////////////////
|
||||
// global variables used for storage. Most likely READ ONLY. Proper
|
||||
|
132
plugins/compute-ap-stats.user.js
Normal file
132
plugins/compute-ap-stats.user.js
Normal file
@ -0,0 +1,132 @@
|
||||
// ==UserScript==
|
||||
// @id iitc-plugin-compute-ap-stats@breunigs
|
||||
// @name iitc: Compute AP statistics
|
||||
// @version 0.1
|
||||
// @namespace https://github.com/breunigs/ingress-intel-total-conversion
|
||||
// @updateURL https://raw.github.com/breunigs/ingress-intel-total-conversion/gh-pages/plugins/compute_AP_stats.user.js
|
||||
// @downloadURL https://raw.github.com/breunigs/ingress-intel-total-conversion/gh-pages/plugins/compute_AP_stats.user.js
|
||||
// @description Tries to determine overal AP stats for the current zoom
|
||||
// @include http://www.ingress.com/intel*
|
||||
// @match http://www.ingress.com/intel*
|
||||
// ==/UserScript==
|
||||
|
||||
function wrapper() {
|
||||
// ensure plugin framework is there, even if iitc is not yet loaded
|
||||
if(typeof window.plugin !== 'function') window.plugin = function() {};
|
||||
|
||||
|
||||
// PLUGIN START ////////////////////////////////////////////////////////
|
||||
|
||||
// use own namespace for plugin
|
||||
window.plugin.compAPStats = function() {};
|
||||
|
||||
window.plugin.compAPStats.setupCallback = function() {
|
||||
$('#toolbox').append('<a onclick="window.plugin.compAPStats.guess()">Compute AP Stats</a> ');
|
||||
}
|
||||
|
||||
window.plugin.compAPStats.compAPStats = function() {
|
||||
|
||||
var totalAP_RES = 0;
|
||||
var totalAP_ENL = 0;
|
||||
|
||||
var allResEdges = new Array();
|
||||
var allResFields = new Array();
|
||||
var allEnlEdges = new Array();
|
||||
var allEnlFields = new Array();
|
||||
|
||||
|
||||
// Grab every portal in the viewable area and compute individual AP stats (ignoring links and fields for now)
|
||||
$.each(window.portals, function(ind, portal) {
|
||||
var d = portal.options.details
|
||||
var resoCount = 0;
|
||||
|
||||
// see how many resonators the portal has
|
||||
$.each(d.resonatorArray.resonators, function(ind, reso) {
|
||||
if(!reso) return true;
|
||||
resoCount += 1;
|
||||
});
|
||||
|
||||
// sum up the AP for the resonators, and any bonus
|
||||
var resoAp = resoCount * DESTROY_RESONATOR;
|
||||
var portalSum = resoAp + CAPTURE_PORTAL + 8*DEPLOY_RESONATOR + COMPLETION_BONUS;
|
||||
|
||||
// Team1 is a Res portal, Team2 is a Enl portal
|
||||
if ( getTeam(d) === TEAM_ENL ) {
|
||||
totalAP_RES += portalSum;
|
||||
|
||||
$.each(d.portalV2.linkedEdges, function(ind,edge) {
|
||||
if(!edge) return true;
|
||||
allEnlEdges.push(edge.edgeGuid);
|
||||
});
|
||||
|
||||
$.each(d.portalV2.linkedFields, function(ind,field) {
|
||||
if(!field) return true;
|
||||
allEnlFields.push(field);
|
||||
});
|
||||
}
|
||||
else if ( getTeam(d) === TEAM_RES ) {
|
||||
totalAP_ENL += portalSum;
|
||||
|
||||
$.each(d.portalV2.linkedEdges, function(ind,edge) {
|
||||
if(!edge) return true;
|
||||
allResEdges.push(edge.edgeGuid);
|
||||
});
|
||||
|
||||
$.each(d.portalV2.linkedFields, function(ind,field) {
|
||||
if(!field) return true;
|
||||
allResFields.push(field);
|
||||
});
|
||||
}
|
||||
else {
|
||||
// it's a neutral portal, potential for both teams. by definition no fields or edges
|
||||
totalAP_ENL += portalSum;
|
||||
totalAP_RES += portalSum;
|
||||
}
|
||||
});
|
||||
|
||||
// Compute team field AP
|
||||
allResFields = $.unique(allResFields);
|
||||
totalAP_ENL += (allResFields.length * DESTROY_FIELD);
|
||||
allEnlFields = $.unique(allEnlFields);
|
||||
totalAP_RES += (allEnlFields.length * DESTROY_FIELD);
|
||||
|
||||
// Compute team Link AP
|
||||
allResEdges = $.unique(allResEdges);
|
||||
totalAP_ENL += (allResEdges.length * DESTROY_LINK);
|
||||
allEnlEdges = $.unique(allEnlEdges);
|
||||
totalAP_RES += (allEnlEdges.length * DESTROY_LINK);
|
||||
|
||||
return [totalAP_RES, totalAP_ENL];
|
||||
}
|
||||
|
||||
window.plugin.compAPStats.guess = function() {
|
||||
var res = window.plugin.compAPStats.compAPStats();
|
||||
var totalAP_RES = res[0];
|
||||
var totalAP_ENL = res[1];
|
||||
|
||||
var s = 'Calculated AP gain potential:\n\n';
|
||||
s += 'Available Resistance AP: \t' + digits(totalAP_RES) + '\n';
|
||||
s += 'Available Enlightened AP: \t' + digits(totalAP_ENL) + '\n';
|
||||
|
||||
alert(s);
|
||||
}
|
||||
|
||||
var setup = function() {
|
||||
window.plugin.compAPStats.setupCallback();
|
||||
}
|
||||
|
||||
// PLUGIN END //////////////////////////////////////////////////////////
|
||||
|
||||
if(window.iitcLoaded && typeof setup === 'function') {
|
||||
setup();
|
||||
} else {
|
||||
if(window.bootPlugins)
|
||||
window.bootPlugins.push(setup);
|
||||
else
|
||||
window.bootPlugins = [setup];
|
||||
}
|
||||
} // wrapper end
|
||||
// inject code into site context
|
||||
var script = document.createElement('script');
|
||||
script.appendChild(document.createTextNode('('+ wrapper +')();'));
|
||||
(document.body || document.head || document.documentElement).appendChild(script);
|
@ -1,132 +0,0 @@
|
||||
// ==UserScript==
|
||||
// @id iitc-plugin-compute-ap-stats@breunigs
|
||||
// @name iitc: Compute AP statistics
|
||||
// @version 0.1
|
||||
// @namespace https://github.com/breunigs/ingress-intel-total-conversion
|
||||
// @updateURL https://raw.github.com/breunigs/ingress-intel-total-conversion/gh-pages/plugins/compute_AP_stats.user.js
|
||||
// @downloadURL https://raw.github.com/breunigs/ingress-intel-total-conversion/gh-pages/plugins/compute_AP_stats.user.js
|
||||
// @description Tries to determine overal AP stats for the current zoom
|
||||
// @include http://www.ingress.com/intel*
|
||||
// @match http://www.ingress.com/intel*
|
||||
// ==/UserScript==
|
||||
|
||||
function wrapper() {
|
||||
// ensure plugin framework is there, even if iitc is not yet loaded
|
||||
if(typeof window.plugin !== 'function') window.plugin = function() {};
|
||||
|
||||
|
||||
// PLUGIN START ////////////////////////////////////////////////////////
|
||||
|
||||
// use own namespace for plugin
|
||||
window.plugin.compAPStats = function() {};
|
||||
|
||||
window.plugin.compAPStats.setupCallback = function() {
|
||||
$('#toolbox').append('<a onclick="window.plugin.compAPStats.guess()">Compute AP Stats</a> ');
|
||||
}
|
||||
|
||||
window.plugin.compAPStats.compAPStats = function() {
|
||||
var DESTROY_RESONATOR = 75; //AP for destroying portal
|
||||
var DESTROY_LINK = 187; //AP for destroying link
|
||||
var DESTROY_FIELD = 750; //AP for destroying field
|
||||
var CAPTURE_PORTAL = 500; //AP for capturing a portal
|
||||
var DEPLOY_RESONATOR = 125; //AP for deploying a resonator
|
||||
var COMPLETION_BONUS = 250; //AP for deploying all resonators on portal
|
||||
|
||||
var totalAP_RES = 0;
|
||||
var totalAP_ENL = 0;
|
||||
|
||||
//Grab every portal in the viewable area and compute individual AP stats
|
||||
$.each(window.portals, function(ind, portal) {
|
||||
var d = portal.options.details
|
||||
var resoCount = 0;
|
||||
|
||||
//This code lovingly copied and chopped from parent plugin func getDestroyAP();
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
$.each(d.resonatorArray.resonators, function(ind, reso) {
|
||||
if(!reso) return true;
|
||||
resoCount += 1;
|
||||
});
|
||||
|
||||
//We'll count fields/links below so we don't duplicate AP
|
||||
//var linkCount = d.portalV2.linkedEdges ? d.portalV2.linkedEdges.length : 0;
|
||||
//var fieldCount = d.portalV2.linkedFields ? d.portalV2.linkedFields.length : 0;
|
||||
|
||||
var resoAp = resoCount * DESTROY_RESONATOR;
|
||||
//var linkAp = linkCount * DESTROY_LINK;
|
||||
//var fieldAp = fieldCount * DESTROY_FIELD;
|
||||
var sum = resoAp + CAPTURE_PORTAL + 8*DEPLOY_RESONATOR + COMPLETION_BONUS;
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//Team1 is a Res portal, Team2 is a Enl portal
|
||||
if ( getTeam(d) == 1 )
|
||||
totalAP_ENL += sum;
|
||||
else if ( getTeam(d) == 2 )
|
||||
totalAP_RES += sum;
|
||||
else { //it's a neutral portal, potential for both teams
|
||||
totalAP_ENL += sum;
|
||||
totalAP_RES += sum;
|
||||
}
|
||||
});
|
||||
|
||||
//Compute team field AP
|
||||
$.each(window.fields, function(ind, field) {
|
||||
//This is a hack that extrapolates the team based on the fill color of a field
|
||||
//Yes, I know it's painful. We'd have an easier time if they would embed the
|
||||
//filed details in the leaflet object like they do for portals.
|
||||
var color = field.options.fillColor; //pukes out a string *sigh*
|
||||
var team = 0;
|
||||
|
||||
if( color == '#0088FF' ) //color is RES
|
||||
totalAP_ENL += DESTROY_FIELD;
|
||||
else if( color == '#03FE03' ) //color is Enl
|
||||
totalAP_RES += DESTROY_FIELD;
|
||||
});
|
||||
|
||||
//Compute team Link AP
|
||||
$.each(window.links, function(ind, link) {
|
||||
//This is a hack that extrapolates the team based on the fill color of a link
|
||||
//Yes, I know it's painful. We'd have an easier time if they would embed the
|
||||
//filed details in the leaflet object like they do for portals.
|
||||
var color = link.options.color; //pukes out a string *sigh*
|
||||
|
||||
var team = 0;
|
||||
|
||||
if( color == '#0088FF' ) //color is RES
|
||||
totalAP_ENL += DESTROY_LINK;
|
||||
else if( color == '#03FE03' ) //color is Enl
|
||||
totalAP_RES += DESTROY_LINK;
|
||||
});
|
||||
|
||||
return [totalAP_RES, totalAP_ENL];
|
||||
}
|
||||
|
||||
window.plugin.compAPStats.guess = function() {
|
||||
var totalAP_RES = window.plugin.compAPStats.compAPStats()[0];
|
||||
var totalAP_ENL = window.plugin.compAPStats.compAPStats()[1];
|
||||
|
||||
var s = 'Total AP for viewable area:\n\n';
|
||||
s += 'Possible Resistance AP: ' + totalAP_RES + '\n';
|
||||
s += 'Possible Enlightened AP: ' + totalAP_ENL + '\n';
|
||||
|
||||
alert(s);
|
||||
}
|
||||
|
||||
var setup = function() {
|
||||
window.plugin.compAPStats.setupCallback();
|
||||
}
|
||||
|
||||
// PLUGIN END //////////////////////////////////////////////////////////
|
||||
|
||||
if(window.iitcLoaded && typeof setup === 'function') {
|
||||
setup();
|
||||
} else {
|
||||
if(window.bootPlugins)
|
||||
window.bootPlugins.push(setup);
|
||||
else
|
||||
window.bootPlugins = [setup];
|
||||
}
|
||||
} // wrapper end
|
||||
// inject code into site context
|
||||
var script = document.createElement('script');
|
||||
script.appendChild(document.createTextNode('('+ wrapper +')();'));
|
||||
(document.body || document.head || document.documentElement).appendChild(script);
|
Loading…
x
Reference in New Issue
Block a user