diff --git a/code/portal_detail_display.js b/code/portal_detail_display.js
index 53a54b99..4fc9cd9b 100644
--- a/code/portal_detail_display.js
+++ b/code/portal_detail_display.js
@@ -26,6 +26,11 @@ window.renderPortalDetails = function(guid) {
var data = portal.options.data;
var details = portalDetail.get(guid);
+ // details and data can get out of sync. if we have details, construct a matching 'data'
+ if (details) {
+ data = getPortalSummaryData(details);
+ }
+
var modDetails = details ? '
'+getModDetails(details)+'
' : '';
var miscDetails = details ? getPortalMiscDetails(guid,details) : '';
@@ -78,8 +83,8 @@ window.renderPortalDetails = function(guid) {
}
// portal level. start with basic data - then extend with fractional info in tooltip if available
- var levelInt = data ? data.level : getPortalLevel(details);
- var levelDetails = data.level;
+ var levelInt = portal.options.level;
+ var levelDetails = portal.options.level;
if (details) {
levelDetails = getPortalLevel(details);
if(levelDetails != 8) {
@@ -178,7 +183,9 @@ window.getPortalMiscDetails = function(guid,d) {
: null;
var sinceText = time ? ['since', time] : null;
- var linkedFields = ['fields', getPortalFields(guid).length];
+ var fieldCount = getPortalFieldsCount(guid);
+
+ var linkedFields = ['fields', fieldCount];
// collect and html-ify random data
var randDetailsData = [];
@@ -189,7 +196,7 @@ window.getPortalMiscDetails = function(guid,d) {
randDetailsData.push (
getRangeText(d), getEnergyText(d),
linksText, getAvgResoDistText(d),
- linkedFields, getAttackApGainText(d),
+ linkedFields, getAttackApGainText(d,fieldCount),
getHackDetailsText(d), getMitigationText(d)
);
diff --git a/code/portal_info.js b/code/portal_info.js
index cd2af05e..69958823 100644
--- a/code/portal_info.js
+++ b/code/portal_info.js
@@ -100,11 +100,13 @@ window.getAvgResoDist = function(d) {
return resos ? sum/resos : 0;
}
-window.getAttackApGain = function(d) {
+window.getAttackApGain = function(d,fieldCount) {
+ if (!fieldCount) fieldCount = 0;
+
var resoCount = 0;
var maxResonators = MAX_RESO_PER_PLAYER.slice(0);
var curResonators = [ 0, 0, 0, 0, 0, 0, 0, 0, 0];
-
+
for(var n = PLAYER.level + 1; n < 9; n++) {
maxResonators[n] = 0;
}
@@ -125,9 +127,6 @@ window.getAttackApGain = function(d) {
var linkCount = d.portalV2.linkedEdges ? d.portalV2.linkedEdges.length : 0;
-//FIXME: portalV2.linkedFields was never a piece of data from the server - it was something faked in IITC
-//with the portal guid, window.getPortalFields will return the count of linked fields - but no guid passed into here
- var fieldCount = d.portalV2.linkedFields ? d.portalV2.linkedFields.length : 0;
var resoAp = resoCount * DESTROY_RESONATOR;
var linkAp = linkCount * DESTROY_LINK;
@@ -311,4 +310,30 @@ window.getPortalHackDetails = function(d) {
return {cooldown: cooldownTime, hacks: numHacks, burnout: cooldownTime*(numHacks-1)};
}
+// given a detailed portal structure, return summary portal data, as seen in the map tile data
+window.getPortalSummaryData = function(d) {
+ // NOTE: the summary data reports unclaimed portals as level 1 - not zero as elsewhere in IITC
+ var level = d.controllingTeam.team == "NEUTRAL" ? 1 : parseInt(getPortalLevel(d));
+ var resCount = 0;
+ if (d.resonatorArray && d.resonatorArray.resonators) {
+ for (var x in d.resonatorArray.resonators) {
+ if (d.resonatorArray.resonators[x]) resCount++;
+ }
+ }
+ var maxEnergy = getTotalPortalEnergy(d);
+ var curEnergy = getCurrentPortalEnergy(d);
+ var health = maxEnergy>0 ? parseInt(curEnergy/maxEnergy*100) : 0;
+
+ return {
+ level: level,
+ title: d.portalV2.descriptiveText.TITLE,
+ image: d.imageByUrl && d.imageByUrl.imageUrl,
+ resCount: resCount,
+ latE6: d.locationE6.latE6,
+ health: health,
+ team: d.controllingTeam.team,
+ lngE6: d.locationE6.lngE6,
+ type: 'portal'
+ };
+}