Skip to content

Instantly share code, notes, and snippets.

@wfjsw
Created August 9, 2022 14:01
Show Gist options
  • Save wfjsw/7649e8501bf68e5af9e05bb2ed1ec9d5 to your computer and use it in GitHub Desktop.
Save wfjsw/7649e8501bf68e5af9e05bb2ed1ec9d5 to your computer and use it in GitHub Desktop.
paladin80/map - Paladin Vent Influence Map Source Code
import java.awt.image.BufferedImage;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.geom.Rectangle2D;
import java.util.*;
import java.sql.*;
public class Map extends Frame implements Runnable {
private final int quarternizer = 1;
private final int sWidth=900*2, sHeight=1024*2, sX=180, sY=0;
BufferedImage img=new BufferedImage(sWidth, sHeight, BufferedImage.TYPE_INT_ARGB);
Graphics2D g=img.createGraphics();
private final double scale=4.8445284569785E17/((sHeight-20)/2.0);
private Hashtable alliances=new Hashtable();
private Vector alliancesV=new Vector();
private Hashtable systems=new Hashtable();
private Vector systemsSov=new Vector();
private Hashtable jumpsTable =new Hashtable();
private Vector jumpsV=new Vector();
private Vector colorTable=new Vector();
private Connection db;
private final String soveregntyDate;
public static void main(String[]args){
Connection db;
try{
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
db=DriverManager.getConnection("jdbc:mysql://localhost/eve", "root", "");
new Map(db, "");
}catch(Exception ex){
ex.printStackTrace();
}
}
public Map(Connection db, String date){
soveregntyDate=date;
this.db = db;
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
try{
//load alliances
Statement st=db.createStatement();
ResultSet rs=st.executeQuery("SELECT id, name, color FROM evealliances ORDER BY onMap DESC, name DESC");
while(rs.next()){
Alliance al=new Alliance();
al.id=rs.getInt(1);
al.name=rs.getString(2);
String color=rs.getString(3);
if(color.length()==6){
int r=Integer.parseInt(color.substring(0,2),16);
int g=Integer.parseInt(color.substring(2,4),16);
int b=Integer.parseInt(color.substring(4,6),16);
if(r+g+b>=128){
al.setColor(new Color(r,g,b));
}
//al.color=nextColor();
}
alliances.put(Integer.valueOf(al.id), al);
alliancesV.addElement(al);
}
rs.close();
st.close();
//load systems
g.setColor(new Color(0, 0, 0x0));
g.fillRect(0,0,sWidth,sHeight);
st=db.createStatement();
rs=st.executeQuery("SELECT x, z, solarSystemID, allianceID, stantion, constellationID, regionID FROM mapsolarsystems");
while(rs.next()){
SolarSystem ss=new SolarSystem();
ss.x=(int)(rs.getDouble(1)/scale)+sWidth/2+sX;
ss.y=(int)(rs.getDouble(2)/scale)+sHeight/2+sY;
ss.id=rs.getInt(3);
ss.constelationID=rs.getInt(6);
ss.RegionID=rs.getInt(7);
ss.sovereignty=(Alliance)alliances.get(Integer.valueOf(rs.getInt(4)));
ss.stantion=rs.getInt(5)==1;
systems.put(Integer.valueOf(ss.id), ss);
if(ss.sovereignty!=null)systemsSov.addElement(ss);
}
rs.close();
st.close();
//load jumps
st=db.createStatement();
rs=st.executeQuery("SELECT fromSolarSystemID, toSolarSystemID FROM mapsolarsystemjumps");
while(rs.next()){
SolarSystem from=(SolarSystem)systems.get(Integer.valueOf(rs.getInt(1)));
SolarSystem to=(SolarSystem)systems.get(Integer.valueOf(rs.getInt(2)));
jumpsV.addElement(new Jump(from, to));
if(from!=null && to!=null){
Vector v=(Vector) jumpsTable.get(from);
if(v==null){
v=new Vector();
jumpsTable.put(from, v);
}
v.addElement(to);
v=(Vector) jumpsTable.get(to);
if(v==null){
v=new Vector();
jumpsTable.put(to, v);
}
v.addElement(from);
}
}
rs.close();
st.close();
//region names
g.setColor(new Color(0xff,0xff,0xff, 0x30));
Font font=g.getFont();
st=db.createStatement();
rs=st.executeQuery("SELECT r.x, r.z, r.regionName FROM mapsolarsystems s LEFT JOIN mapregions r ON r.regionID=s.regionID /*WHERE s.allianceID<>0*/ GROUP BY r.regionID");
while(rs.next()){
int x=(int)(rs.getDouble(1)/scale)+sWidth/2+sX;
int y=(int)(rs.getDouble(2)/scale)+sHeight/2+sY;
String s=rs.getString(3);
Rectangle2D r=font.getStringBounds(s, g.getFontRenderContext());
g.drawString(s, x-(int)r.getWidth()/2, y+10);
}
///*
//alliance influence
Vector sovOrig=new Vector();
for(int i=0;i<systemsSov.size();i++){
sovOrig.addElement(systemsSov.elementAt(i));
}
for(int i=0;i<sovOrig.size();i++){
SolarSystem ss=(SolarSystem)sovOrig.elementAt(i);
double influence=10.0;
int level=2;
if(ss.stantion){
influence*=6;
level=1;
}
Vector v=new Vector();
addInfluence(ss, influence, ss.sovereignty, level, v);
}
//NPC
Hashtable npc=new Hashtable();
Color npcColor=new Color(0,0,0,0);
st=db.createStatement();
rs=st.executeQuery("SELECT id, name, systemID, influence FROM npcalliances");
while(rs.next()){
int id=rs.getInt(1);
Alliance al=(Alliance)npc.get(Integer.valueOf(id));
if(al==null){
al=new Alliance();
al.id = id;
al.name = rs.getString(2);
al.nameColor=al.color=npcColor;
al.npc=true;
npc.put(Integer.valueOf(id), al);
}
SolarSystem ss=(SolarSystem)systems.get(Integer.valueOf(rs.getInt(3)));
if(ss==null)continue;
double influence=rs.getDouble(4);
addInfluence(ss, influence, al, 4, new Vector());
}
jumpsTable=null;
//drawLegend(false);
new Thread(this).start();
//*/
setSize(1280, 1024);
setVisible(true);
}catch(Exception ex){
ex.printStackTrace();
}
}
public void addInfluence(SolarSystem ss, double value, Alliance al, int level, Vector set){
ss.addInfluence(al, value);
if(!systemsSov.contains(ss))systemsSov.addElement(ss);
if(level>=4)return;
//spread over the jump gates
Vector arr=(Vector) jumpsTable.get(ss);
if(arr==null)return;
for(int i=0;i<arr.size();i++){
SolarSystem s=(SolarSystem)arr.elementAt(i);
if(set.contains(s))continue;
set.addElement(s);
addInfluence(s, value*0.3, al, level+1, set);
}
}
public void paint(Graphics g) {
if(g==null)return;
g.drawImage(img, 5, 20, sWidth/2, 1000, null);
//g.drawImage(img, 50, 55, null);
super.paint(g);
}
private Color nextColor(){
int max=0;
int cr=0,cg=0,cb=0;
for(int r=0;r<256;r+=4)for(int g=0;g<256;g+=4)for(int b=0;b<256;b+=4){
if(r+g+b<256 || r+g+b>512)continue;
int min=1000000000;
for(int i=0;i<colorTable.size();i++){
Color c=(Color)colorTable.elementAt(i);
int dr=r-c.getRed();
int dg=g-c.getGreen();
int db=b-c.getBlue();
int dif=dr*dr+dg*dg+db*db;
if(min>dif)min=dif;
}
if(max<min){
max=min;
cr=r;
cg=g;
cb=b;
}
}
return new Color(cr, cg, cb, 0x90);
}
/*
int colorCounter=1;
private Color nextColor(){
int r=colorCounter%4;
int g=colorCounter/4%4;
int b=colorCounter/16%4;
if(r==0 && g==0 && b==0){
r=1;
colorCounter++;
}
r=r*70+(r>0?45:0);
g=g*70+(g>0?45:0);
b=b*70+(b>0?45:0);
colorCounter++;
return new Color(r, g, b, 0x50);
}
*/
public void run() {
if(1==1){
final double validInf=0.023;
final double insensitivity=500;
final int qMax=sWidth/ quarternizer;
Hashtable totalInf=new Hashtable();
Alliance[]prevRow=null;
double[]prevInf=new double[qMax];
boolean[]curBorder=new boolean[qMax];
for(int y=0;y<sHeight;y+= quarternizer){
Alliance[]curRow=new Alliance[qMax];
for(int x=0;x<sWidth;x+= quarternizer){
//Thread.yield();
totalInf.clear();
for(int i=0;i<systemsSov.size();i++){
SolarSystem ss=(SolarSystem)systemsSov.elementAt(i);
int dx=x-ss.x, dy=y-ss.y;
int len2=dx*dx+dy*dy;
if(Math.abs(dx)>400 || Math.abs(dy)>400 || len2>160000) continue;
Enumeration en=ss.influence.keys();
while(en.hasMoreElements()){
Alliance al=(Alliance)en.nextElement();
Double d=(Double)totalInf.get(al);
double add=((Double)ss.influence.get(al)).doubleValue()/(insensitivity+len2);
if(d==null){
totalInf.put(al, Double.valueOf(add));
}else{
totalInf.put(al, Double.valueOf(d.doubleValue()+add));
}
}
}
double max=0.0;
Alliance best=null;
Enumeration en=totalInf.keys();
while(en.hasMoreElements()){
Alliance al=(Alliance)en.nextElement();
Double d=(Double)totalInf.get(al);
if(d.doubleValue()>max){
max=d.doubleValue();
best=al;
}
}
int q=x/ quarternizer;
if(max<validInf)best=null;
if(best!=null){
if(best.color==null){
best.setColor(nextColor());
saveColor(best);
}
best.used=true;
best.x+=x;
best.y+=y;
best.count++;
}
curRow[q]=best;
//draw the prew row point
if(y>0){
Alliance prew=prevRow[q];
if(prew!=null && !prew.npc){
boolean border=q==0||q==qMax-1||curBorder[q]||prew!=best||prew!=prevRow[q-1]||prew!=prevRow[q+1];
int alpha=Math.min(190, (int)(Math.log(Math.log(prevInf[q]+1.0)+1.0)*700));
if(!border){
g.setColor(new Color(prew.color.getRed(),prew.color.getGreen(),prew.color.getBlue(),alpha));
}else{
Color c=new Color(prew.color.getRed(), prew.color.getGreen(), prew.color.getBlue(), Math.max(0x28, alpha));
g.setColor(c);
}
g.fillRect(x, y - quarternizer, quarternizer, quarternizer);
}
}
prevInf[q]=max;
curBorder[q] = (y==0||prevRow[q]!=best);
}
prevRow=curRow;
paint(getGraphics());
try{Thread.sleep(10);}catch(Exception ex){}
}
for(int x=0;x<sWidth;x+= quarternizer){
Alliance prew=prevRow[x/ quarternizer];
if(prew!=null){
int alpha=Math.min(190, (int)(Math.log(Math.log(prevInf[x/ quarternizer]+1.0)+1.0)*700));
g.setColor(new Color(prew.color.getRed(),prew.color.getGreen(),prew.color.getBlue(),alpha));
g.fillRect(x, sHeight - quarternizer, quarternizer, quarternizer);
}
}
}
drawLegend(true);
try{
javax.imageio.ImageIO.write(img, "png", new java.io.File("influence.png"));
System.out.println("Image saved");
System.exit(0);
}catch(Exception ex){
ex.printStackTrace();
}
repaint();
}
private void saveColor(Alliance al){
String r=Integer.toHexString(al.color.getRed());
while(r.length()<2)r="0"+r;
String g=Integer.toHexString(al.color.getGreen());
while(g.length()<2)g="0"+g;
String b=Integer.toHexString(al.color.getBlue());
while(b.length()<2)b="0"+b;
try{
Statement st=db.createStatement();
st.executeUpdate("UPDATE evealliances SET color='"+r+g+b+"' WHERE id="+al.id);
st.close();
}catch(Exception ex){
ex.printStackTrace();
}
}
private void drawLegend(boolean checkUsed){
//draw jumps
for(int i=0;i<jumpsV.size();i++)((Jump)jumpsV.elementAt(i)).draw();
//draw systems
Enumeration en=systems.elements();
while(en.hasMoreElements())((SolarSystem)en.nextElement()).draw();
paint(getGraphics());
try{
Statement st=db.createStatement();
st.executeUpdate("UPDATE evealliances SET onMap=0");
st.close();
//legend
//int y=17;
//int x=sWidth-210;
g.setColor(Color.GREEN);
//g.drawString("LEGEND", x+17, y-5);
g.setColor(Color.DARK_GRAY);
g.drawString("Created by [AEGL, UNL] Paladin Vent", 0, 17);
g.drawString("using sovereignty data on "+soveregntyDate, 0, 35);
Font defaultFont=g.getFont();
for(int i=alliancesV.size()-1;i>=0;i--){
Alliance al=(Alliance)alliancesV.elementAt(i);
if(checkUsed && !al.used)continue;
int ax=(int)(al.x/al.count);
int ay=(int)(al.y/al.count);
//g.setColor(al.color);
//g.fillRect(x,y,15,15);
//g.drawLine(x,y,ax,ay);
//g.setColor(Color.WHITE);
//g.drawString(al.name, x+17, y+12);
//y+=17;
Font aliFont=new Font("Verdana", Font.BOLD, (int)(Math.sqrt(al.count)* quarternizer /30)+8);
g.setFont(aliFont);
Rectangle2D r=aliFont.getStringBounds(al.name, g.getFontRenderContext());
g.setColor(Color.BLACK);
g.drawString(al.name, ax-(int)r.getWidth()/2-1, ay+10);
g.drawString(al.name, ax-(int)r.getWidth()/2+1, ay+10);
g.drawString(al.name, ax-(int)r.getWidth()/2, ay+10-1);
g.drawString(al.name, ax-(int)r.getWidth()/2, ay+10+1);
g.setColor(al.nameColor);
g.drawString(al.name, ax-(int)r.getWidth()/2, ay+10);
g.setFont(defaultFont);
st=db.createStatement();
st.executeUpdate("UPDATE evealliances SET onMap=1 WHERE id="+al.id);
st.close();
}
/*
Color c=new Color(0xB0, 0xB0, 0xFF);
y+=30;
g.setColor(c);
g.drawRect(x,y,15,15);
g.drawLine(x,y+7,x+7,y+7);
g.setColor(Color.WHITE);
g.drawString("Outpost", x+17, y+12);
y+=17;
g.setColor(c);
g.drawOval(x+2, y+2, 10, 10);
g.setColor(Color.WHITE);
g.drawString("Claimed system", x+17, y+12);
*/
Font small=new Font("MS Sans Serif",0,9);
g.setFont(small);
g.setColor(Color.WHITE);
int y=70;
g.drawString("Sov. Lost",35,y);
g.drawString("Sov. Gain",135,y);
g.drawString("System",208,y);
g.drawString("Region",250,y);
y+=15;
st=db.createStatement();
Shape defClip=g.getClip();
String sql=
"SELECT l.fromAllianceID, l.toAllianceID, s.solarSystemName, r.regionName, s.stantion " +
"FROM sovchangelog l " +
//"LEFT JOIN evealliances a1 ON l.fromAllianceID=a1.id " +
//"LEFT JOIN evealliances a2 ON l.toAllianceID=a2.id " +
"LEFT JOIN mapsolarsystems s ON s.solarSystemID=l.systemID " +
"LEFT JOIN mapregions r ON s.regionID=r.regionID " +
"WHERE l.date='"+soveregntyDate+"' " +
//"WHERE l.date='2007-03-06' " +
"ORDER BY r.z, r.x";
System.out.println(sql);
ResultSet rs=st.executeQuery(sql);
Color cStantion=new Color(0, 0, 0x40);
while(rs.next()){
//String fromS=rs.getString(1), toS=rs.getString(2);
String system=rs.getString(3), region=rs.getString(4);
if(rs.getInt(5)==1){
g.setClip(5,y-50,298,100);
g.setColor(cStantion);
g.fillRect(5, y-10, 290, 13);
}
//if(stantion)system="OP:"+system;
Alliance from=(Alliance)alliances.get(Integer.valueOf(rs.getInt(1)));
if(from!=null){
g.setClip(5,y-50,98,100);
g.setColor(from.nameColor);
g.drawString(from.name, 5, y);
}
Alliance to=(Alliance)alliances.get(Integer.valueOf(rs.getInt(2)));
if(to!=null){
g.setClip(105,y-50,98,100);
g.setColor(to.nameColor);
g.drawString(to.name, 105, y);
}
g.setColor(starColor);
g.setClip(205,y-50,40,100);
g.drawString(system, 205, y);
g.setColor(Color.WHITE);
g.setClip(246,y-50,50,100);
g.drawString(region, 246, y);
y+=15;
}
g.setClip(defClip);
g.setFont(defaultFont);
g.setColor(Color.DARK_GRAY);
int y2=74;
g.drawLine(5,y2,295,y2);
g.drawLine(104,y2-15,104,y-10);
g.drawLine(204,y2-15,204,y-10);
g.drawLine(245,y2-15,245,y-10);
rs.close();
st.close();
}catch(Exception ex){
ex.printStackTrace();
}
}
private static final Color starColor=new Color(0xB0, 0xB0, 0xFF);
private class SolarSystem{
int x, y;
int id, constelationID, RegionID;
Alliance sovereignty;
Hashtable influence=new Hashtable();
boolean stantion;
void addInfluence(Alliance al, double value){
Double inf=(Double)influence.get(al);
if(inf==null){
influence.put(al, Double.valueOf(value));
}else{
influence.put(al, Double.valueOf(value+inf.doubleValue()));
}
}
void draw(){
if(sovereignty!=null && sovereignty.color==null){
sovereignty.setColor(nextColor());
saveColor(sovereignty);
}
g.setColor(sovereignty!=null?sovereignty.starColor:starColor);
if(stantion){
g.fillOval(x-1, y-1, 2, 2);
g.drawRect(x-2,y-2, 4, 4);
}else if (sovereignty!=null){
g.fillOval(x-2, y-2, 4, 4);
}else{
g.fillOval(x-1, y-1, 2, 2);
}
}
}
private class Alliance{
int id;
String name;
Color color=null, nameColor=null, starColor=null;
boolean used=false, npc=false;
long x=0, y=0;
long count=0;
void setColor(Color c){
color=new Color(c.getRGB());
float[] hsb=Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null);
hsb[2]=1;
nameColor=new Color(Color.HSBtoRGB(hsb[0], hsb[1], hsb[2]));
hsb[1]=Math.max(0.2f, hsb[1]*.7f);
starColor=new Color(Color.HSBtoRGB(hsb[0], hsb[1], hsb[2]));
colorTable.addElement(color);
}
}
private class MapPoint{
Alliance claim;
double inluence;
}
private class Jump{
SolarSystem from, to;
private final Color sJump=new Color(0, 0, 0xFF, 0x30);
private final Color cJump=new Color(0xFF, 0, 0, 0x30);
private final Color rJump=new Color(0xFF, 0, 0xFF, 0x30);
Jump(SolarSystem from, SolarSystem to){
this.from=from;
this.to=to;
}
void draw(){
if(from.constelationID==to.constelationID){
g.setColor(sJump);
}else if(from.RegionID==to.RegionID){
g.setColor(cJump);
}else{
g.setColor(rJump);
}
g.drawLine(from.x, from.y, to.x, to.y);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment