Skip to content

Commit

Permalink
Merge pull request #632 from McBen/deadCode
Browse files Browse the repository at this point in the history
code cleanup
  • Loading branch information
modos189 authored Jan 18, 2024
2 parents 4c6c000 + e6ab01a commit c565d72
Show file tree
Hide file tree
Showing 9 changed files with 192 additions and 197 deletions.
142 changes: 142 additions & 0 deletions core/code/_deprecated.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/**
* functions that are not use by IITC itself
* and won't most likely not receive any updated
*/
/* global L -- eslint */

/**
* @deprecated
* given counts of resonators, links and fields, calculate the available AP
* doesn't take account AP for resonator upgrades or AP for adding mods
*/
window.portalApGainMaths = function (resCount, linkCount, fieldCount) {
var deployAp = (8 - resCount) * window.DEPLOY_RESONATOR;
if (resCount === 0) deployAp += window.CAPTURE_PORTAL;
if (resCount !== 8) deployAp += window.COMPLETION_BONUS;
// there could also be AP for upgrading existing resonators, and for deploying mods - but we don't have data for that
var friendlyAp = deployAp;

var destroyResoAp = resCount * window.DESTROY_RESONATOR;
var destroyLinkAp = linkCount * window.DESTROY_LINK;
var destroyFieldAp = fieldCount * window.DESTROY_FIELD;
var captureAp = window.CAPTURE_PORTAL + 8 * window.DEPLOY_RESONATOR + window.COMPLETION_BONUS;
var destroyAp = destroyResoAp + destroyLinkAp + destroyFieldAp;
var enemyAp = destroyAp + captureAp;

return {
friendlyAp: friendlyAp,
enemyAp: enemyAp,
destroyAp: destroyAp,
destroyResoAp: destroyResoAp,
captureAp: captureAp,
};
};

/**
* @deprecated
* get the AP gains from a portal, based only on the brief summary data from portals, links and fields
* not entirely accurate - but available for all portals on the screen
*/
window.getPortalApGain = function (guid) {
var p = window.portals[guid];
if (p) {
var data = p.options.data;

var linkCount = window.getPortalLinksCount(guid);
var fieldCount = window.getPortalFieldsCount(guid);

var result = window.portalApGainMaths(data.resCount, linkCount, fieldCount);
return result;
}

return undefined;
};

/**
* @deprecated
* This function will return the potential level a player can upgrade it to
*/
window.potentialPortalLevel = function (d) {
var current_level = window.getPortalLevel(d);
var potential_level = current_level;

if (window.PLAYER.team === d.team) {
var resonators_on_portal = d.resonators;
var resonator_levels = new Array();

// figure out how many of each of these resonators can be placed by the player
var player_resontators = new Array();
for (var i = 1; i <= window.MAX_PORTAL_LEVEL; i++) {
player_resontators[i] = i > window.PLAYER.level ? 0 : window.MAX_RESO_PER_PLAYER[i];
}
$.each(resonators_on_portal, function (ind, reso) {
if (reso !== null && reso.owner === window.PLAYER.nickname) {
player_resontators[reso.level]--;
}
resonator_levels.push(reso === null ? 0 : reso.level);
});

resonator_levels.sort(function (a, b) {
return a - b;
});

// Max out portal
var install_index = 0;
for (var j = window.MAX_PORTAL_LEVEL; j >= 1; j--) {
for (var install = player_resontators[j]; install > 0; install--) {
if (resonator_levels[install_index] < j) {
resonator_levels[install_index] = j;
install_index++;
}
}
}

potential_level =
resonator_levels.reduce(function (a, b) {
return a + b;
}) / 8;
}
return potential_level;
};

/**
* @deprecated
* find the lat/lon for a portal, using any and all available data
* (we have the list of portals, the cached portal details, plus links and fields as sources of portal locations)
*/
window.findPortalLatLng = function (guid) {
if (window.portals[guid]) {
return window.portals[guid].getLatLng();
}

// not found in portals - try the cached (and possibly stale) details - good enough for location
var details = window.portalDetail.get(guid);
if (details) {
return L.latLng(details.latE6 / 1e6, details.lngE6 / 1e6);
}

// now try searching through fields
for (var fguid in window.fields) {
var f = window.fields[fguid].options.data;

for (var i in f.points) {
if (f.points[i].guid === guid) {
return L.latLng(f.points[i].latE6 / 1e6, f.points[i].lngE6 / 1e6);
}
}
}

// and finally search through links
for (var lguid in window.links) {
var l = window.links[lguid].options.data;
if (l.oGuid === guid) {
return L.latLng(l.oLatE6 / 1e6, l.oLngE6 / 1e6);
}
if (l.dGuid === guid) {
return L.latLng(l.dLatE6 / 1e6, l.dLngE6 / 1e6);
}
}

// no luck finding portal lat/lng
return undefined;
};
30 changes: 6 additions & 24 deletions core/code/chat.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
window.chat = function() {};

//WORK IN PROGRESS - NOT YET USED!!
window.chat.commTabs = [
// channel: the COMM channel ('tab' parameter in server requests)
// name: visible name
// inputPrompt: string for the input prompt
// inputColor: (optional) color for input
// sendMessage: (optional) function to send the message (to override the default of sendPlext)
// globalBounds: (optional) if true, always use global latLng bounds
{channel:'all', name:'All', inputPrompt: 'broadcast:', inputColor:'#f66'},
{channel:'faction', name:'Aaction', inputPrompt: 'tell faction:'},
{channel:'alerts', name:'Alerts', inputPrompt: 'tell Jarvis:', inputColor: '#666', globalBounds: true, sendMessage: function() {
alert("Jarvis: A strange game. The only winning move is not to play. How about a nice game of chess?\n(You can't chat to the 'alerts' channel!)");
}},
];
window.chat = function () {};
var chat = window.chat;


window.chat.handleTabCompletion = function() {
Expand Down Expand Up @@ -185,7 +171,7 @@ window.chat.handleFaction = function(data, olderMsgs, ascendingTimestampOrder) {
$('#chatfaction').data('needsClearing', null);

var old = chat._faction.oldestGUID;
chat.writeDataToHash(data, chat._faction, false, olderMsgs, ascendingTimestampOrder);
chat.writeDataToHash(data, chat._faction, olderMsgs, ascendingTimestampOrder);
var oldMsgsWereAdded = old !== chat._faction.oldestGUID;

runHooks('factionChatDataAvailable', {raw: data, result: data.result, processed: chat._faction.data});
Expand Down Expand Up @@ -238,7 +224,7 @@ window.chat.handlePublic = function(data, olderMsgs, ascendingTimestampOrder) {
$('#chatall').data('needsClearing', null);

var old = chat._public.oldestGUID;
chat.writeDataToHash(data, chat._public, undefined, olderMsgs, ascendingTimestampOrder); //NOTE: isPublic passed as undefined - this is the 'all' channel, so not really public or private
chat.writeDataToHash(data, chat._public, olderMsgs, ascendingTimestampOrder);
var oldMsgsWereAdded = old !== chat._public.oldestGUID;

runHooks('publicChatDataAvailable', {raw: data, result: data.result, processed: chat._public.data});
Expand Down Expand Up @@ -288,7 +274,7 @@ window.chat.handleAlerts = function(data, olderMsgs, ascendingTimestampOrder) {
if(data.result.length === 0) return;

var old = chat._alerts.oldestTimestamp;
chat.writeDataToHash(data, chat._alerts, undefined, olderMsgs, ascendingTimestampOrder); //NOTE: isPublic passed as undefined - it's nether public or private!
chat.writeDataToHash(data, chat._alerts, olderMsgs, ascendingTimestampOrder);
var oldMsgsWereAdded = old !== chat._alerts.oldestTimestamp;

// hook for alerts - API change planned here for next refactor
Expand Down Expand Up @@ -407,7 +393,7 @@ window.chat.parseMsgData = function (data) {
};
};

window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, isOlderMsgs, isAscendingOrder) {
window.chat.writeDataToHash = function (newData, storageHash, isOlderMsgs, isAscendingOrder) {
window.chat.updateOldNewHash(newData, storageHash, isOlderMsgs, isAscendingOrder);

newData.result.forEach(function(json) {
Expand Down Expand Up @@ -788,9 +774,6 @@ window.chat.chooseTab = function(tab) {

chat.renderAlerts(false);
break;

default:
throw new Error('chat.chooser was asked to handle unknown button: ' + tt);
}
}

Expand Down Expand Up @@ -923,7 +906,6 @@ window.chat.setupPosting = function() {
}
} catch (e) {
log.error(e);
//if (e.stack) { console.error(e.stack); }
}
});
}
Expand Down
6 changes: 2 additions & 4 deletions core/code/data_cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ window.DataCache = function() {

}

window.DataCache.prototype.store = function (qk, data, freshTime) {
window.DataCache.prototype.store = function (qk, data) {
this.remove(qk);

var time = new Date().getTime();

if (freshTime===undefined) freshTime = this.REQUEST_CACHE_FRESH_AGE*1000;
var expire = time + freshTime;
var expire = time + this.REQUEST_CACHE_FRESH_AGE * 1000;

var dataStr = JSON.stringify(data);

Expand Down
87 changes: 2 additions & 85 deletions core/code/portal_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,54 +48,14 @@ window.getPortalFields = function(guid) {
window.getPortalFieldsCount = function(guid) {
var fields = getPortalFields(guid);
return fields.length;
}


// find the lat/lon for a portal, using any and all available data
// (we have the list of portals, the cached portal details, plus links and fields as sources of portal locations)
window.findPortalLatLng = function(guid) {
if (window.portals[guid]) {
return window.portals[guid].getLatLng();
}

// not found in portals - try the cached (and possibly stale) details - good enough for location
var details = portalDetail.get(guid);
if (details) {
return L.latLng (details.latE6/1E6, details.lngE6/1E6);
}

// now try searching through fields
for (var fguid in window.fields) {
var f = window.fields[fguid].options.data;

for (var i in f.points) {
if (f.points[i].guid == guid) {
return L.latLng (f.points[i].latE6/1E6, f.points[i].lngE6/1E6);
}
}
}

// and finally search through links
for (var lguid in window.links) {
var l = window.links[lguid].options.data;
if (l.oGuid == guid) {
return L.latLng (l.oLatE6/1E6, l.oLngE6/1E6);
}
if (l.dGuid == guid) {
return L.latLng (l.dLatE6/1E6, l.dLngE6/1E6);
}
}

// no luck finding portal lat/lng
return undefined;
};


(function() {
(function () {
var cache = {};
var cache_level = 0;
var GC_LIMIT = 15000; // run garbage collector when cache has more that 5000 items
var GC_KEEP = 10000; // keep the 4000 most recent items
var GC_KEEP = 10000; // keep the 4000 most recent items

window.findPortalGuidByPositionE6 = function(latE6, lngE6) {
var item = cache[latE6+","+lngE6];
Expand Down Expand Up @@ -143,46 +103,3 @@ window.findPortalLatLng = function(guid) {
})();


// get the AP gains from a portal, based only on the brief summary data from portals, links and fields
// not entirely accurate - but available for all portals on the screen
window.getPortalApGain = function(guid) {

var p = window.portals[guid];
if (p) {
var data = p.options.data;

var linkCount = getPortalLinksCount(guid);
var fieldCount = getPortalFieldsCount(guid);

var result = portalApGainMaths(data.resCount, linkCount, fieldCount);
return result;
}

return undefined;
}

// given counts of resonators, links and fields, calculate the available AP
// doesn't take account AP for resonator upgrades or AP for adding mods
window.portalApGainMaths = function(resCount, linkCount, fieldCount) {

var deployAp = (8-resCount)*DEPLOY_RESONATOR;
if (resCount == 0) deployAp += CAPTURE_PORTAL;
if (resCount != 8) deployAp += COMPLETION_BONUS;
// there could also be AP for upgrading existing resonators, and for deploying mods - but we don't have data for that
var friendlyAp = deployAp;

var destroyResoAp = resCount*DESTROY_RESONATOR;
var destroyLinkAp = linkCount*DESTROY_LINK;
var destroyFieldAp = fieldCount*DESTROY_FIELD;
var captureAp = CAPTURE_PORTAL + 8 * DEPLOY_RESONATOR + COMPLETION_BONUS;
var destroyAp = destroyResoAp+destroyLinkAp+destroyFieldAp;
var enemyAp = destroyAp+captureAp;

return {
friendlyAp: friendlyAp,
enemyAp: enemyAp,
destroyAp: destroyAp,
destroyResoAp: destroyResoAp,
captureAp: captureAp
}
}
2 changes: 1 addition & 1 deletion core/code/portal_detail_display.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ window.renderPortalDetails = function(guid) {
historyDetails
);

window.renderPortalUrl(lat, lng, title, guid);
window.renderPortalUrl(lat, lng, title);

// only run the hooks when we have a portalDetails object - most plugins rely on the extended data
// TODO? another hook to call always, for any plugins that can work with less data?
Expand Down
42 changes: 1 addition & 41 deletions core/code/portal_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,48 +130,8 @@ window.getAttackApGain = function(d,fieldCount,linkCount) {
};
}

//This function will return the potential level a player can upgrade it to
window.potentialPortalLevel = function(d) {
var current_level = getPortalLevel(d);
var potential_level = current_level;

if(PLAYER.team === d.team) {
var resonators_on_portal = d.resonators;
var resonator_levels = new Array();
// figure out how many of each of these resonators can be placed by the player
var player_resontators = new Array();
for(var i=1;i<=MAX_PORTAL_LEVEL; i++) {
player_resontators[i] = i > PLAYER.level ? 0 : MAX_RESO_PER_PLAYER[i];
}
$.each(resonators_on_portal, function(ind, reso) {
if(reso !== null && reso.owner === window.PLAYER.nickname) {
player_resontators[reso.level]--;
}
resonator_levels.push(reso === null ? 0 : reso.level);
});

resonator_levels.sort(function(a, b) {
return(a - b);
});

// Max out portal
var install_index = 0;
for(var i=MAX_PORTAL_LEVEL;i>=1; i--) {
for(var install = player_resontators[i]; install>0; install--) {
if(resonator_levels[install_index] < i) {
resonator_levels[install_index] = i;
install_index++;
}
}
}
//log.log(resonator_levels);
potential_level = resonator_levels.reduce(function(a, b) {return a + b;}) / 8;
}
return(potential_level);
}


window.fixPortalImageUrl = function(url) {
window.fixPortalImageUrl = function (url) {
if (url) {
if (window.location.protocol === 'https:') {
url = url.replace(/^http:\/\//, '//');
Expand Down
Loading

0 comments on commit c565d72

Please sign in to comment.