Changeset 25dc5ff34167fc62df39f2b19eec0406b2dc7690

Show
Ignore:
Timestamp:
11/03/07 10:57:45 (1 year ago)
Author:
Christopher Jung <bktheg@web.de>
git-committer:
Christopher Jung <bktheg@web.de> 1194083865 +0100
git-parent:

[f082126a9f1dc7b76a2f6e356719d06f76b9a94b]

git-author:
Christopher Jung <bktheg@web.de> 1194083865 +0100
Message:

Kleinere Korrekturen am JN-Router

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/net/driftingsouls/ds2/server/ships/JumpNodeRouter.java

    refe50c3 r25dc5ff  
    4545                 */ 
    4646                public List<SQLResultRow> path = new ArrayList<SQLResultRow>(); 
     47                 
     48                @Override 
     49                public String toString() { 
     50                        StringBuilder builder = new StringBuilder("[distance: "+distance+"\npath: "); 
     51                        for( int i=0; i < path.size(); i++ ) { 
     52                                SQLResultRow pathElem = path.get(i); 
     53                                builder.append(pathElem.getInt("system")+":"+pathElem.getInt("x")+"/"+pathElem.getInt("y")+" -> "+pathElem.getInt("systemout")+":"+pathElem.getInt("xout")+"/"+pathElem.getInt("yout")+"\n"); 
     54                        } 
     55                         
     56                        builder.append("]"); 
     57                        return builder.toString(); 
     58                } 
    4759        } 
    4860         
     
    6173        } 
    6274         
     75        private int getMovementCost(int startX, int startY, int targetX, int targetY) { 
     76                return Math.max(Math.abs(targetX-startX),Math.abs(targetY-startY)); 
     77        } 
     78         
    6379        /** 
    6480         * Findet den kuerzesten Weg zwischen zwei Punkten  
     
    7187         * @return Der Pfad oder <code>null</code> 
    7288         */ 
    73         public Result locateShortestJNPath( int currentsys, int currentx, int currenty, int targetsys, int targetx, int targety) {                               
    74                 if( !jnlist.containsKey(currentsys) ) { 
    75                         return null;     
    76                 } 
    77  
     89        public Result locateShortestJNPath( int currentsys, int currentx, int currenty, int targetsys, int targetx, int targety) { 
    7890                if( currentsys == targetsys ) { 
    7991                        Result res = new Result(); 
    8092                        res.distance = Math.max(Math.abs(targetx-currentx),Math.abs(targety-currenty)); 
    8193                        return res;      
     94                } 
     95                 
     96                if( !jnlist.containsKey(currentsys) ) { 
     97                        return null;     
    8298                } 
    8399                 
     
    91107                                continue; 
    92108                        } 
    93                         int pathcost = Math.max(Math.abs(ajn.getInt("x")-currentx),Math.abs(ajn.getInt("y")-currenty)); 
     109                        int pathcost = getMovementCost(currentx, currenty, ajn.getInt("x"), ajn.getInt("y")); 
    94110                         
     111                        // JN vorlaeufig aus der Liste entfernen um Endlosschleifen zu vermeiden 
    95112                        sysJNList.remove(k); 
    96                         k--; 
    97113                         
    98114                        Result cost = locateShortestJNPath(ajn.getInt("systemout"),ajn.getInt("xout"),ajn.getInt("yout"), targetsys, targetx, targety ); 
     115                         
     116                        sysJNList.add(k, ajn); 
     117                         
     118                        // Keine Route gefunden -> JN-Zielsystem ignorieren 
    99119                        if( cost == null ) { 
    100120                                if( !systemInterestLevel.containsKey(ajn.getInt("systemout")) ) { 
     
    103123                                continue; 
    104124                        } 
     125                        // Erste moegliche Route gefunden 
    105126                        else if( shortestpath == null ) { 
    106127                                shortestpath = cost; 
     
    108129                                shortestpath.path.add(0, ajn); 
    109130                        } 
     131                        // Neue Route mit der alten Route vergleichen 
    110132                        else if( shortestpath.distance > cost.distance+pathcost ) { 
    111133                                shortestpath = cost; 
     
    113135                                shortestpath.path.add(0, ajn); 
    114136                        } 
     137                         
     138                        // JN-Zielsystem bietet gueltige Route -> merken! 
    115139                        if( !systemInterestLevel.containsKey(ajn.getInt("systemout")) ) { 
    116140                                systemInterestLevel.put(ajn.getInt("systemout"), 1); 
    117141                        } 
    118142                } 
    119                         
     143                 
    120144                return shortestpath; 
    121145        }