// ==UserScript==
// @name C&C Tiberium Alliances Map (Elda-Mod)
// @description Shows you the region map
// @namespace https://prodgame*.alliances.commandandconquer.com/*/index.aspx*
// @include https://prodgame*.alliances.commandandconquer.com/*/index.aspx*
// @version 2.0
// @author KSX, Elda1990
// @need http://userscripts.org/scripts/source/155357.user.js
// ==/UserScript==
//
// based on CnC: Tiberium Alliances Map (KSX-Mod) v1.5
// https://userscripts.org/scripts/show/149093
//
// based on Tiberium Alliances Map (Nolana Kane) v1.8
// https://userscripts.org/scripts/show/135955
(function() {
var TAMap_mainFunction = function() {
function createMapTweak() {
var TAMap = {};
qx.Class.define("TAMap.main", {
type : "singleton",
extend : qx.core.Object,
members : {
version : "2.0",
buttonMap : null,
mapBox : null,
mapWidget : null,
scroll : null,
mapCanvas : null,
settingsWnd : null,
poiSelect : null,
allianceSelect : null,
obfSectorName : null,
obfAllianceList : null,
obfAllianceId : null,
obfAllianceName : null,
colorFields: {},
visOptions: { colors: {
cityColor : "green" , // type = 1
baseColor : "navy" , // type = 2
campColor : "midnightblue", // type = 3, CampType=2
outpostColor : "royalblue" , // type = 3, CampType=3
poiColor : "orange" , // type = 4, POIType != 0
tunnelColor : "forestgreen" , // type = 4, POIType = 0
enemyBaseColor : "red",
allianceTerrainColor: "teal",
ownBaseColor : "lime",
highlightColor : "white"
}},
// Types: 1 = city
// 2 = Forgotten Base{Id, Level}
// 3 = Camp, Outpost {Id, CampType: 3 = Outpost, 2 = Camp}
// 4 = POI, Tunnel Exit {Id, Level, OwnerAllianceId, OwnerAllianceName, POIType:
// 6 = Aircraft (Off Air)
// 7 = Resonator (Def), 0 = Tunnel!
// ...
//
zoomFactor : 3,
initialize : function() {
if (localStorage) {
var vo = localStorage["TAMap.visOptions"];
if (vo != null) {
this.visOptions = JSON.parse(vo);
}
}
// this.add_ViewModeChange = (new ClientLib.Vis.ViewModeChange).$ctor(this, this.onViewChange);
console.log("Adding button");
var addonmenu = Addons.AddonMainMenu.getInstance();
addonmenu.AddMainMenu("Map",function() { window.TAMap.main.getInstance().showMap(); }, "ALT+M");
/*
this.buttonMap = new qx.ui.form.Button("Map");
this.buttonMap.set({
width : 80,
appearance : "button-bar-center",
toolTipText : ""
});
this.buttonMap.addListener("click", this.showMap, this);
var mainBar = qx.core.Init.getApplication().getUIItem(ClientLib.Data.Missions.PATH.BAR_MENU);
mainBar.getChildren()[1].addAt(this.buttonMap, 8, {
top : 0,
right : 0
});*/
console.log("Button added");
// The Map window
this.mapBox = new qx.ui.window.Window("Map [v"+this.version+" Links-Mod]");
this.mapBox.setPadding(1);
this.mapBox.setLayout(new qx.ui.layout.Grow());
// this.mapBox.setLayout(new qx.ui.layout.VBox());
this.mapBox.setShowMaximize(false);
this.mapBox.setShowMinimize(false);
this.mapBox.moveTo(150, 50);
this.mapBox.setHeight(500);
this.mapBox.setWidth(500);
this.mapBox.setMinWidth(10);
this.mapBox.setMinHeight(10);
this.mapBox.setBackgroundColor("black");
this.mapWidget = new qx.html.Element("canvas", null, {
id : "map",
width : 3000,
height : 3000
});
this.mapWidget.addListener("appear", function() {
console.log("appeared:" + this.mapWidget.getDomElement());
var canvas = this.mapWidget.getDomElement();
if (this.mapCanvas == null) {
this.mapCanvas = canvas;
var _thisMap = this;
canvas.addEventListener("click", function(evt) {
console.log("coords:" + evt.clientX + ":" + evt.clientY);
console.log("offsets:" + canvas.offsetTop + "," + canvas.offsetLeft);
// get canvas position
var obj = canvas;
var top = 0;
var left = 0;
while (obj && obj.tagName != 'BODY') {
top += obj.offsetTop;
left += obj.offsetLeft;
obj = obj.offsetParent;
}
// return relative mouse position
var mouseX = evt.clientX - left + window.pageXOffset + _thisMap.scroll.getScrollX();
var mouseY = evt.clientY - top + window.pageYOffset + _thisMap.scroll.getScrollY();
console.log("M:" + mouseX + "," + mouseY);
var vm = ClientLib.Vis.VisMain.GetInstance();
vm.CenterGridPosition(mouseX / _thisMap.zoomFactor, mouseY / _thisMap.zoomFactor);
_thisMap.updateMap();
setTimeout(function() {
_thisMap.updateMap();
}, 1000);
}, false);
}
this.updateMap();
//for (var x = 0; x < 1000; x++) {
// for (var y = 0; y < 1000; y++) {
// var obj = w.GetObjectFromPosition(x,y);
// if (obj != null) {
// ctx.fillRect(x,y,1,1);
// }
// }
// }
// vm = ClientLib.Vis.VisMain.GetInstance()
// vm.CenterGridPosition(535,142)
// vm.get_Region().get_PosY()/vm.get_Region().get_GridHeight()
// vm.get_Region().get_PosX()/vm.get_Region().get_GridWidth()
}, this);
// new qx.ui.basic.Label().set({
// value: "debugOutput",
// rich : true,
// selectable: true
// });
this.scroll = new qx.ui.container.Scroll().set({
width : 500,
height : 500
});
this.scroll.setMinWidth(10);
this.scroll.setMinHeight(10);
_thisMap = this;
this.mapBox.add(this.scroll);
var p = new qx.ui.core.Widget();
p.setMinHeight(3000);
p.setMinWidth(3000);
p.setHeight(3000);
p.setWidth(3000);
this.scroll.add(p);
p.getContentElement().add(this.mapWidget);
// select box for alliances
var selectBox = new qx.ui.form.SelectBox();
selectBox.addListener("changeSelection", function(e) {
if (e != null && e.getData() && e.getData().length > 0) {
this.visOptions.alliance = e.getData()[0].getModel(); // alliance ID or -1 for all
//console.log("Alliance selected: "+e.getData()[0] + " "+this.visOptions.alliance);
this.saveOptions();
this.updateMap();
}
}, this);
this.allianceSelect = selectBox;
// this.mapBox.add(selectBox);
//
// Select box for POI Type
//
selectBox = new qx.ui.form.SelectBox();
var currentSelection = this.visOptions.poi||-1;
var makePoiItem = function(model, name) {
var item = new qx.ui.form.ListItem(name, null, model);
selectBox.add(item);
if (currentSelection == model) {
selectBox.setSelection([item]);
}
}
makePoiItem( -1 ,"<< None >>" );
makePoiItem(ClientLib.Base.EPOIType.AirBonus ,"Aircraft GNT (Off Air)" );
makePoiItem(ClientLib.Base.EPOIType.CrystalBonus ,"Crystal CNH" );
makePoiItem(ClientLib.Base.EPOIType.DefenseBonus ,"Resonator NT (Def)" );
makePoiItem(ClientLib.Base.EPOIType.InfanteryBonus,"Tungsten C (Off Inf)" );
makePoiItem(ClientLib.Base.EPOIType.PowerBonus ,"Reactor (Power Bonus)" );
makePoiItem(ClientLib.Base.EPOIType.TiberiumBonus ,"Tiberium CN" );
makePoiItem(ClientLib.Base.EPOIType.VehicleBonus ,"Uranium C (Off Vehicles)");
makePoiItem( -2 ,"<< All >>" );
selectBox.addListener("changeSelection", function(e) {
if (e != null && e.getData() && e.getData().length > 0) {
this.visOptions.poi = e.getData()[0].getModel(); // POI ID or -1 for all
console.log("POI selected "+e.getData()[0].getModel());
this.saveOptions();
this.updateMap();
}
}, this);
this.poiSelect = selectBox;
// Checkbox for alliance POIs
checkbox = new qx.ui.form.CheckBox();
checkbox.setValue(this.visOptions.showAlliancePois==true);
checkbox.addListener("changeValue", function(e) {
this.visOptions.showAlliancePois=e.getTarget().getValue();
this.saveOptions();
this.updateMap();
},this);
this.showAlliancePois = checkbox;
// Checkbox for own bases
checkbox = new qx.ui.form.CheckBox();
checkbox.setValue(this.visOptions.showOwnCities==true);
checkbox.addListener("changeValue", function(e) {
this.visOptions.showOwnCities=e.getTarget().getValue();
this.saveOptions();
this.updateMap();
},this);
this.showOwnCities = checkbox;
// Checkbox for showSectionFrame
checkbox = new qx.ui.form.CheckBox();
checkbox.setValue(this.visOptions.showSectionFrame==true);
checkbox.addListener("changeValue", function(e) {
this.visOptions.showSectionFrame=e.getTarget().getValue();
this.saveOptions();
this.updateMap();
},this);
this.showSectionFrame = checkbox;
// Button "Settings"
var bt = new qx.ui.form.Button("Settings");
bt.set({
appearance : "button-text-small",
toolTipText : "Set filters for the map"
});
bt.addListener("click", function() {this.settingsWnd.open()}, this);
this.mapBox.getChildControl("captionbar").add(bt,{row:0,column:5}); // hack hack hack
//
// Settings dialog
//
this.settingsWnd = new qx.ui.window.Window("Map Settings");
this.settingsWnd.setPadding(10);
//this.mapBox.setLayout(new qx.ui.layout.Grow());
var layout = new qx.ui.layout.Grid();
layout.setSpacing(5);
layout.setColumnAlign(1,"left", "center");
layout.setColumnAlign(0,"left", "bottom");
this.settingsWnd.setLayout(layout);
this.settingsWnd.setShowMaximize(false);
this.settingsWnd.setShowMinimize(false);
this.settingsWnd.moveTo(300, 13);
this.settingsWnd.setHeight(580);
this.settingsWnd.setWidth(300);
this.settingsWnd.setMinWidth(10);
this.settingsWnd.setMinHeight(10);
var makeLbl = function(name) {
var lbl = new qx.ui.basic.Label(name);
lbl.setTextColor("white");
return lbl;
}
var _thisMap = this;
var makeTxt = function(option) {
var value = _thisMap.visOptions.colors[option];
var txtField = new qx.ui.form.TextField(value);
txtField.setTextColor("white");
_thisMap.colorFields[option] = txtField;
return txtField;
}
this.settingsWnd.add(makeLbl("- Highlight -"), {row:0, column:0});
this.settingsWnd.add(makeLbl("Alliance:"), {row:1,column:0});
this.settingsWnd.add(this.allianceSelect, {row:1, column:1});
this.settingsWnd.add(makeLbl("POIs:"), {row:2, column:0});
this.settingsWnd.add(this.poiSelect, {row:2, column:1});
this.settingsWnd.add(makeLbl("Alliance POIs:"), {row:3, column:0});
this.settingsWnd.add(this.showAlliancePois, {row:3, column:1});
this.settingsWnd.add(makeLbl("Own Cities:"), {row:4, column:0});
this.settingsWnd.add(this.showOwnCities, {row:4, column:1});
this.settingsWnd.add(makeLbl("Section Frame:"), {row:5, column:0});
this.settingsWnd.add(this.showSectionFrame, {row:5, column:1});
bt = makeLbl("- Colors -");
bt.set({
value: '<a href="http://www.w3schools.com/html/html_colornames.asp" target="_blank">- Colors -</a>',
rich : true,
selectable: true
});
this.settingsWnd.add(bt, {row:10, column:0});
// bt.addListener("click", function() { window.open("http://www.w3schools.com/html/html_colornames.asp") });
this.settingsWnd.add(makeLbl("Alliance Terrain:"), {row:11, column:0});
this.settingsWnd.add(makeTxt("allianceTerrainColor"), {row:11, column:1});
this.settingsWnd.add(makeLbl("Base:"), {row:12, column:0});
this.settingsWnd.add(makeTxt("baseColor"), {row:12, column:1});
this.settingsWnd.add(makeLbl("Camp:"), {row:13, column:0});
this.settingsWnd.add(makeTxt("campColor"), {row:13, column:1});
this.settingsWnd.add(makeLbl("City:"), {row:14, column:0});
this.settingsWnd.add(makeTxt("cityColor"), {row:14, column:1});
this.settingsWnd.add(makeLbl("Enemy:"), {row:15, column:0});
this.settingsWnd.add(makeTxt("enemyBaseColor"), {row:15, column:1});
this.settingsWnd.add(makeLbl("Outpost:"), {row:16, column:0});
this.settingsWnd.add(makeTxt("outpostColor"), {row:16, column:1});
this.settingsWnd.add(makeLbl("Own City:"), {row:17, column:0});
this.settingsWnd.add(makeTxt("ownBaseColor"), {row:17, column:1});
this.settingsWnd.add(makeLbl("POI:"), {row:18, column:0});
this.settingsWnd.add(makeTxt("poiColor"), {row:18, column:1});
this.settingsWnd.add(makeLbl("Tunnel:"), {row:19, column:0});
this.settingsWnd.add(makeTxt("tunnelColor"), {row:19, column:1});
var changeColor = new qx.ui.form.Button("Change");
changeColor.set({
appearance : "button-text-small",
toolTipText : "Save changes to colors"
});
this.settingsWnd.add(changeColor, {row:20, column:0});
changeColor.addListener("click", function() {
for (var option in this.visOptions.colors) {
if (this.colorFields[option]) {
this.visOptions.colors[option] = this.colorFields[option].getValue();
}
}
this.saveOptions();
this.updateMap();
}, this);
this.settingsWnd.addListener("appear", function() {
this.updateFilter();
}, this);
//scroll.add(this.mapWidget);
// scroll.setBackgroundColor("#fff");
//var ele = scroll.getContainerElement();
//console.log("container scroll:" + ele);
//ele.getChild(0).add(this.mapWidget);
//
//this.mapBox.getApplicationRoot().set({
// blockerColor: '#000000',
// blockerOpacity: 0.6
// });
// w.GetBaseOwner(x,y);
//var index=((y * this.m_WorldWidth) + x);
// return this.m_BaseOwner[index];
//
//var ruinPlayerID=this.GetWorldSectorByCoords$0(targetX, targetY).GetPlayerId$0(ruin.PlayerId);
//
// list players for (var i = 0; i < s.m_Players.c; i++) { var p = console.log(s.GetPlayer(i)); }
//
// for(i in s.m_Objects.d) { console.log(s.m_Objects.d[i].$type.m.n);}
// sample object:
// {"Type":1,"SequenceId":3694,"isAttacked":false,"isLocked":false,"isProtected":false,"isAlerted":false,"hasCooldown":false,"Level":10,"Radius":2,"PlayerId":4,"ConditionBuildings":100,"ConditionDefense":100,"Id":76726,"Name":"Sepherian 1"}
// lientLib.Data.Cities.prototype.GetWorldSectorWithMostCities$0=function()
// >> w.GetOwner(534,139);
// >> w.GetObjectFromPosition
//w.GetObjectFromPosition(534,139)
// allianceId = 943 OtherAllianceId = 2049
// md.get_Alliance().GetAllianceRelationshipsByType(webfrontend.gui.alliance.DiplomacyPage.ERelationTypeEnemy,true)
//c=w.GetObjectFromPosition(524,145)
// s.GetPlayer(c.PlayerId)
//s.GetAlliance(p.Alliance) == OtherAllianceId
},
getSectors: function(w) { // work around obfuscated variable names
if (this.obfSectorName == null) {
// auto-detect sector name
Outer:
for (i in w) {
if (w[i].d) {
var maybeSector = w[i].d;
for (j in maybeSector) {
if (maybeSector[j].ConvertToWorldX) {
this.obfSectorName = i;
console.log("Sector field:" + i);
break Outer;
}
break;
}
}
}
}
if (this.obfSectorName == null) console.log("ERROR: getSectors(): obfuscated property not found!");
if (this.obfSectorName != null) return w[this.obfSectorName].d;
if (w.KIH) { // old june version
return w.KIH.d;
} else if (w.RBJXOL) { // july
return w.RBJXOL.d;
} else if(w.IWEESP) {
return w.IWEESP.d; // closed beta 2 world
} else if (w.HYMYNV) { // mid july release
return w.HYMYNV.d;
} else if (w.ONQEIH) { // july 18th
return w.ONQEIH.d;
}
},
getAlliances: function(sector) {// work around obfuscated variable names. sector == current sector
if(typeof(sector)=="undefinied" || sector===null) {console.log("ERROR: getAlliances(sector): sector is not defined!");return null;}
if (this.obfAllianceList == null) {
// find alliance list dynamically
Outer:
for (i in sector) {
if (sector[i].d) {
var maybeAllianceList = sector[i].d;
for (j in maybeAllianceList) {
var maybeAlliance=maybeAllianceList[j];
var propnames=[]; for (p in maybeAlliance) propnames.push(p);
var stringpropcount=0;
var stringpropname=null;
if(propnames.length==13) {
for(k=0;k<propnames.length;k++){
if(typeof(maybeAlliance[propnames[k]])=="string"){
stringpropname=propnames[k];
stringpropcount++;
}
}
if(stringpropcount==1){
this.obfAllianceId = propnames[1];//assuming this is allways the case :-)
this.obfAllianceName = stringpropname;
this.obfAllianceList = i;
console.log("Alliances field:" + i);
break Outer;
}
}
break;// test only the first member
}
}
}
}
if (this.obfAllianceList == null) {
console.log("ERROR: getAlliances(): obfuscated member not found!");
return null;
} else
return sector[this.obfAllianceList].d;
/* if (sector.WGH) {// june
return sector.WGH.d;
} else if (sector.QEKQND) {//july
return sector.QEKQND.d;
} else if (sector.GGUPEV){ // closed beta 2 world
return sector.GGUPEV.d;
} else if(sector.UFVPYE) {
return sector.UFVPYE.d; // July 11, 2012
} else if(sector.UEQLAO) {
return sector.UEQLAO.d; // July 18th
} */
},
isEnemy : function(enemies, alliance, sector) {
if (alliance == null)
return false;
var enemy = enemies.l.filter(function(ele) {
return ele.OtherAllianceId == alliance.Id;
});
return enemy.length > 0;
},
listAllAlliances : function() {
var alliances = [];
var w = ClientLib.Data.MainData.GetInstance().get_World(); if(!w) console.log("ERROR: get_World() failed!");
var sectors = this.getSectors(w); if(!sectors) console.log("ERROR: getSectors() failed!");
for (var i in sectors) { // m_sectors
var s = sectors[i];
var all = this.getAlliances(s); if(!all) console.log("ERROR: getAlliances() failed!");
for(var j in all) { // m_alliances
var a = all[j];
alliances.push({id: a[this.obfAllianceId], name: a[this.obfAllianceName]});
}
}
alliances.sort(function(s1,s2) {
var name1 = s1.name.toLowerCase();
var name2 = s2.name.toLowerCase();
if (name1 < name2) return -1;
if (name1 > name2) return 1;
return 0;
});
var allianceMap = {};
alliances.forEach(function(it) {
allianceMap[it.id] = it;
});
return allianceMap;
},
updateFilter : function() {
var md = ClientLib.Data.MainData.GetInstance();
//var enemies = md.get_Alliance().GetAllianceRelationshipsByType(webfrontend.gui.alliance.DiplomacyPage.ERelationTypeEnemy, true);
this.allianceSelect.removeAll();
var alliances = this.listAllAlliances(); // quite expensive operation
var selected = new qx.ui.form.ListItem("<< None >>", null, -1);
this.allianceSelect.add(selected);
for (i in alliances) {
var a = alliances[i];
//enemies.l.forEach(function(it) {
var tempItem = new qx.ui.form.ListItem(a.name, null, a.id);
if (a.id == this.visOptions.alliance) {
selected = tempItem;
}
this.allianceSelect.add(tempItem);
}
this.allianceSelect.setSelection([selected]);
},
findAllianceById: function(s, id) {
var ra = null;
if (id != 0){
for (var x=1; s.GetAlliance(x) != null; x++){
var a = s.GetAlliance(x);
if (a.FGTNFZ == id) {
ra = a;
}
}
}
return ra;
},
updateMap : function() {
// this.updateFilter(); - we assume that visOptions has all the visualisation options
var canvas = this.mapCanvas;
console.log("Canvas:" + canvas);
var ctx = canvas.getContext('2d');
var sc = this.zoomFactor;
var md = ClientLib.Data.MainData.GetInstance();
var alliance = md.get_Alliance();
//console.log(this.dump(alliance,"alliance",1,true));
var enemies = alliance.GetAllianceRelationshipsByType(webfrontend.gui.alliance.DiplomacyPage.ERelationTypeEnemy, true);
var w = md.get_World();
var vm = ClientLib.Vis.VisMain.GetInstance();
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "rgb(200,0,0)";
var cx = 0;
var cy = 0;
var hilitePois = [];
var sectors = this.getSectors(w);
if(!this.obfAllianceId) this.obfAllianceId=this.getMemberNameByType(alliance,"number",0);
if(!this.obfAllianceName) this.obfAllianceName=this.getMemberNameByType(alliance,"string",0);
var allianceName=alliance[this.obfAllianceName];
//console.log("Alliance: "+allianceName);
//console.log(this.dump(this.showAlliancePois,"chkbox",1,true));
//ctx.fillStyle="#000000";
//ctx.fillRect(0,0,3000,3000);
for (var i in sectors) {// m_Sectors = RBJXOL
var s = sectors[i];
// console.log("Sector "+s.get_Id()+"\n"+ this.dump(s,"sector",2));
// console.log("GetPlayer "+this.dump(s.GetPlayer(s.get_Id()),"*",1));
// console.log("GetPlayerAllianceId "+this.dump(s.GetPlayerAllianceId(3128),"*",1));
// console.log("findAllianceById "+this.dump(this.findAllianceById(s, 289),"*",1));
// console.log("Painting sector:" + s.m_Id);
for (var x = 0; x < 32; x++) {
for (var y = 0; y < 32; y++) {
cx = s.ConvertToWorldX(x);
cy = s.ConvertToWorldY(y);
var obj = w.GetObjectFromPosition(cx, cy);
if (obj != null) {
// ctx.fillStyle = colors[obj.Type];
switch (obj.Type) {
case 1: // player city
// console.log("DEBUG player city at "+cx+","+cy+" "+obj.AUENVZ + "("+obj.LFQYDH+")");
// console.log(this.dump(obj.OSKFZU.m,"obj",2,true));
//var player = s.GetPlayer(obj.PlayerId); //NOT WORKING
var player = s.GetPlayerId(obj); //NOT WORKING
//var player = s.GetPlayer(obj.L);
// console.log(this.dump(player,"player",1));
if(!player) break; //
// console.log("IEHUFP "+this.dump(s.GetPlayer(obj.IEHUFP),"player",1));
//var alliance = s.GetAlliance(player.Alliance);
var paid=s.GetPlayerAllianceId(obj.IEHUFP);
// console.log("DEBUG GetPlayerAllianceId "+paid);
var alliance = this.findAllianceById(s, paid);//TODO
if (alliance != null && this.visOptions.alliance == alliance[obfAllianceId]) {
ctx.fillStyle = this.visOptions.colors.highlightColor;
ctx.fillRect(cx * sc, cy * sc, sc, sc);
} else if (this.isEnemy(enemies, alliance, s)) {
// console.log("Enemy found" + obj);
ctx.fillStyle = this.visOptions.colors.enemyBaseColor;
ctx.fillRect(cx * sc, cy * sc, sc, sc);
} else {
//if (w.GetTerritoryTypeByCoordinates(cx,cy) == ClientLib.Data.ETerritoryType.Own) { ctx.fillStyle = "rgb(255,255,255)"; }
// ClientLib.Data.MainData.GetInstance$9().get_BaseColors$0().GetMapAllianceColorType$0(this.get_AllianceId$1()));
if (obj.PlayerId && s.GetPlayer(obj.PlayerId).Id == md.get_Player().id) {
ctx.fillStyle = this.visOptions.colors.ownBaseColor;
} else {
ctx.fillStyle = this.visOptions.colors.cityColor;
}
ctx.fillRect(cx * sc, cy * sc, sc, sc);
}
break;
case 2: // forgotten camp
ctx.fillStyle = this.visOptions.colors.baseColor;
ctx.fillRect(cx * sc, cy * sc, sc, sc);
break;
case 3: // Camp/Outpost
ctx.fillStyle = (obj.CampType == 2) ? this.visOptions.colors.campColor : this.visOptions.colors.outpostColor;
ctx.fillRect(cx * sc, cy * sc, sc, sc);
break;
case 4: // POI or tunnel
/*
Type:ClientLib.Data.WorldSector.WorldObjectPointOfInterest
System.Int32 Id
ClientLib.Data.WorldSector.WorldObjectPointOfInterest.EPOIType POIType
System.Int32 Level
System.Int64 OwnerAllianceId
System.String OwnerAllianceName
System.Void .ctor (ClientLib.Data.WorldSector.ObjectType type ,ClientLib.Data.World world ,System.String details ,System.Int32 pos)
*/
/*
obj: {} -->
obj.Type: 4
obj.SequenceId: 6805
obj.BNDYIS: 39
obj.MYTWLL: 1
obj.ADKRPM: 8527
obj.YQTUPE: 123
obj.HIFKIQ: "Alliance Name"
obj.LSVKAD: {} -->
*/
//console.log("POI/Tunnel ("+cx+":"+cy+" POIType:"+obj[this.getNameByIdx(obj,3)]+"):\n"+this.dump(obj,"obj",1,true));
if(!this.obfPOIType) {this.obfPOIType=this.getNameByIdx(obj,3);}
if(!this.obfWorldObjectPointOfInterestAllianceName) {this.obfWorldObjectPointOfInterestAllianceName=this.getMemberNameByType(obj,"string",0);}
if(!this.obfWorldObjectPointOfInterestAllianceId) {this.obfWorldObjectPointOfInterestAllianceId=this.getNameByIdx(obj,5);}
if (obj[this.obfPOIType] == 0) {
// Tunnel
ctx.fillStyle = this.visOptions.colors.tunnelColor;
} else {
// POI
ctx.fillStyle = this.visOptions.colors.poiColor;
if(!this.visOptions.showAlliancePois) {
if(this.visOptions.poi==-2){
// Selected POI = << All >>
hilitePois.push([cx,cy]);
}else{
if (this.visOptions.poi && this.visOptions.poi == obj[this.obfPOIType] + 1) {
// for some reasons, the constants in ClientLib are off by 1
hilitePois.push([cx,cy]);
}
}
} else {
if(this.visOptions.poi>=0){
if (
(this.visOptions.poi && this.visOptions.poi == obj[this.obfPOIType] + 1) &&
(obj[this.obfWorldObjectPointOfInterestAllianceId]==this.visOptions.alliance)
) { // for some reasons, the constants in ClientLib are off by 1
hilitePois.push([cx,cy]);
}
}else if(this.visOptions.poi==-2){
// Selected POI = << All >>
if(obj[this.obfWorldObjectPointOfInterestAllianceId]==this.visOptions.alliance){
hilitePois.push([cx,cy]);
}
}
}
}
ctx.fillRect(cx * sc, cy * sc, sc, sc);
break;
}
} else {
var terr = w.GetTerritoryTypeByCoordinates(cx, cy);
switch (terr) {
case ClientLib.Data.ETerritoryType.Alliance: {
ctx.fillStyle = this.visOptions.colors.allianceTerrainColor;
ctx.fillRect(cx * sc, cy * sc, sc, sc);
break;
}
case ClientLib.Data.ETerritoryType.Enemy: {
if (w.GetOwner(cx, cy) != 1610612736) {
ctx.fillStyle = "rgba(80,10,10,0.5)";
ctx.fillRect(cx * sc, cy * sc, sc, sc);
}
break;
}
case ClientLib.Data.ETerritoryType.Neutral: {
//ctx.fillStyle = "rgb(210,210,210)";
//ctx.fillRect(cx,cy,1,1);
break;
}
}
}
}
}
}
// paint home bases
if(this.visOptions.showOwnCities){
var ownCities = md.get_Cities().get_AllCities().d;
for (var i in ownCities) {
var city = ownCities[i];
var x = city.get_PosX() * sc;
var y = city.get_PosY() * sc;
ctx.fillStyle = null;
ctx.strokeStyle = "rgba(255,255,255,0.7)";
ctx.beginPath();
ctx.arc(x+sc/2,y+sc/2,sc,0*Math.PI,2*Math.PI);
ctx.stroke();
ctx.beginPath();
ctx.strokeStyle = "rgba(255,255,255,0.3)";
ctx.arc(x+sc/2,y+sc/2,sc*20,0*Math.PI,2*Math.PI);
ctx.stroke();
}
}
// paint hilited pois
ctx.strokeStyle = "rgb(255,255,255)";
hilitePois.forEach(function(poi) {
ctx.strokeRect(poi[0] * sc - 2, poi[1] * sc - 2, sc+4, sc+4);
});
// m_Region == get_Region()
var topX = Math.floor(vm.get_Region().get_PosX() / vm.get_Region().get_GridWidth());
var topY = Math.floor(vm.get_Region().get_PosY() / vm.get_Region().get_GridHeight());
var width = vm.get_Region().get_ViewWidth() / vm.get_Region().get_ZoomFactor() / vm.get_Region().get_GridWidth();
var height = vm.get_Region().get_ViewHeight() / vm.get_Region().get_ZoomFactor() / vm.get_Region().get_GridHeight();
ctx.strokeStyle = "rgb(200,200,200)";
ctx.lineWidth = 1;
console.log("Selection:" + topX + "," + topY + "w:" + width + "," + height);
if(this.visOptions.showSectionFrame){
ctx.strokeRect(topX * sc, topY * sc, width * sc, height * sc);
}
if (topX * sc < this.scroll.getScrollX() || topX * sc > this.scroll.getScrollX() + this.scroll.getWidth()) {
this.scroll.scrollToX(Math.max(0, topX * sc - 100));
}
if (topY * sc < this.scroll.getScrollY() || topY * sc > this.scroll.getScrollY() + this.scroll.getHeight()) {
this.scroll.scrollToY(Math.max(0, topY * sc - 100));
}
},
getMousePos : function(canvas, evt) {
// get canvas position
var obj = canvas;
var top = 0;
var left = 0;
while (obj && obj.tagName != 'BODY') {
top += obj.offsetTop;
left += obj.offsetLeft;
obj = obj.offsetParent;
}
// return relative mouse position
var mouseX = evt.clientX - left + window.pageXOffset;
var mouseY = evt.clientY - top + window.pageYOffset;
return {
x : mouseX,
y : mouseY
};
},
saveOptions : function() {
if (localStorage) {
localStorage["TAMap.visOptions"] = JSON.stringify(this.visOptions);
}
},
showMap : function() {
console.log("Show map");
this.mapBox.open();
var debugOutput = "";
var mainData = ClientLib.Data.MainData.GetInstance();
var player_cities = mainData.get_Cities();
var current_city = player_cities.get_CurrentOwnCity();
//var sector = mainData.get_World().GetWorldSectorByCoords(current_city.get_PosX(), current_city.get_PosY());
//for (i in sector.m_Objects.d) {
// debugOutput += JSON.stringify(sector.m_Objects.d[i]) + "<br>";
//}
//console.log(debugOutput);
// this.mapWidget.setValue(debugOutput);
//var canvas = this.mapWidget.getDomElement();
//console.log("Canvas:" + canvas);
//var ctx = canvas.getContext('2d');
//console.log(ctx);
//ctx.fillStyle = "rgb(200,0,0)";
//ctx.fillRect (10, 10, 55, 50);
},
getNameByIdx: function (object, idx){
var i=0;
for(var n in object) {
if(i==idx) return n;
i++;
}
return null;
},
getMemberNameByType: function (object, type, idx){
var i=0;
for(var n in object) {
var valueType = typeof(object[n]);
//console.log(n+" "+valueType);
if(type==valueType) {
if(i==idx) return n;
i++;
}
}
return null;
},
dump: function (object,rootName,deep,includeFunction) {
//console.log("dump "+rootName);
var dumpInternal=function(obj, path) {
//console.log("DEBUG: dumpInternal(obj, "+path+") ind:"+ind+", deep:"+deep+", output.length:"+s.length);
if(obj===null) {
s += "" + path +": {null}" + "\n";
return;
} else if(obj===undefined){
s += "" + path +": {undefined}" + "\n";
return;
}
var valueType = typeof(obj);
switch (valueType) {
case "function":
return;
// try{var fr=obj();}catch(ex){var fr=ex;}
// s+= "" + path +": "+ "{function} returns: "+fr + "\n";return;
case "object" : s+= "" + path +": {} -->" /*+ propValue.toString().substr(0,20)*/ + "\n";break;
case "boolean" : s+= "" + path +": "+ obj.toString() + "\n";return;
case "number" : s+= "" + path +": "+ obj.toString() + "\n";return;
case "string" : s+= "" + path +": \""+ obj.toString() + "\"\n";return;
default:s += "" + path +" ("+ valueType +"): "+ obj.toString() + "\n";return;
}
for (var o in objs) {
if(o===obj) {
s+= "{!Recursion stoped!}\n";
return;
} else objs.push(obj);
}
var members=[];for (var p in obj) members.push(p);
if(members.length>1000) {console.log("WARNING: dump() Too much members! "+members.length); return;} //TODO
if(deep>0 && ind>=deep) return;
if(/.GHPRYH$/.test()) return; //TODO
if(path.length>30) {console.log("WARNING: dump() Path too long!"); return;} //TODO
ind++;
for (var propName in obj) {dumpInternal(obj[propName], path+"."+propName);}
ind--;
}
var objs = [];
var ind = 0;
var s = "";
if(typeof(rootName)=='undefined')rootName="*";
if(typeof(deep)=='undefined')deep=1;
if(typeof(includeFunction)=='undefined')includeFunction=false;
try{dumpInternal(object,rootName);}catch(ex){console.log("ERROR: dump() > "+ex);}
return s;
}
}
});
}
function TAMap_checkIfLoaded() {
try {
if ( typeof qx != 'undefined' && typeof Addons != 'undefined') {
var a = qx.core.Init.getApplication();
// application
var mb = qx.core.Init.getApplication().getMenuBar();
var addonmenu = Addons.AddonMainMenu.getInstance();
if (a && mb && addonmenu) {
createMapTweak();
window.TAMap.main.getInstance().initialize();
} else
window.setTimeout(TAMap_checkIfLoaded, 1000);
} else {
window.setTimeout(TAMap_checkIfLoaded, 1000);
}
} catch (e) {
if ( typeof console != 'undefined')
console.log(e);
else if (window.opera)
opera.postError(e);
else
GM_log(e);
}
}
if (/commandandconquer\.com/i.test(document.domain)) {
window.setTimeout(TAMap_checkIfLoaded, 1000);
}
}
// injecting, because there seem to be problems when creating game interface with unsafeWindow
var TAMapScript = document.createElement("script");
var txt = TAMap_mainFunction.toString();
TAMapScript.innerHTML = "(" + txt + ")();";
TAMapScript.type = "text/javascript";
if (/commandandconquer\.com/i.test(document.domain)) {
document.getElementsByTagName("head")[0].appendChild(TAMapScript);
}
})();