Changeset 548df42f8807e2be470936e582eb1072ebeed33a

Show
Ignore:
Timestamp:
08/05/07 22:13:18 (1 year ago)
Author:
Christopher Jung <bktheg@web.de>
git-committer:
Christopher Jung <bktheg@web.de> 1186344798 +0200
git-parent:

[c86520efe0863d81050672baad06de32e5eea40c]

git-author:
Sebastian Gift <Madison@gt-knm.de> 1186344798 +0200
Message:

Nahrungsversorgung der Schiffe geaendert

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/net/driftingsouls/ds2/server/modules/BaseController.java

    r799695d r548df42  
    4545 * @urlparam Integer col Die ID der Basis 
    4646 */ 
    47 public class BaseController extends DSGenerator {        
     47public class BaseController extends DSGenerator { 
     48        private static final int NAHRUNG_CHECKOUT_FACTOR = 1; 
     49         
    4850        private Base base; 
    4951         
     
    9698                Cargo usercargo = new Cargo( Cargo.Type.STRING, user.getCargo()); 
    9799 
    98                 if( (count < 0) && (-count*100 > usercargo.getResourceCount(Resources.NAHRUNG)) ) { 
    99                         count = -usercargo.getResourceCount(Resources.NAHRUNG)/100
     100                if( (count < 0) && (-count*NAHRUNG_CHECKOUT_FACTOR > usercargo.getResourceCount(Resources.NAHRUNG)) ) { 
     101                        count = -usercargo.getResourceCount(Resources.NAHRUNG)/NAHRUNG_CHECKOUT_FACTOR
    100102                } 
    101103                 
     
    111113                 
    112114                cargo.substractResource( Resources.NAHRUNG, count ); 
    113                 usercargo.addResource( Resources.NAHRUNG, count*100 ); 
     115                usercargo.addResource( Resources.NAHRUNG, count*NAHRUNG_CHECKOUT_FACTOR ); 
    114116         
    115117                user.setCargo(usercargo.save()); 
    116118                base.setCargo(cargo); 
    117119         
    118                 t.set_var("base.message", "<img src=\""+Cargo.getResourceImage(Resources.NAHRUNG)+"\" alt=\"\" />"+Math.abs(count)+" 100er Pakete transferiert" ); 
     120                t.set_var("base.message", "<img src=\""+Cargo.getResourceImage(Resources.NAHRUNG)+"\" alt=\"\" />"+Math.abs(count)+" transferiert" ); 
    119121         
    120122                redirect(); 
     
    375377                                tooltiptext.append("<form action='./ds' method='post'>"); 
    376378                                tooltiptext.append("<div>"); 
    377                                 tooltiptext.append("Nahrung in 100er Paketen transferieren: <input name='nahrung' type='text' size='6' value='"+res.getCount1()+"' /><br />"); 
     379                                tooltiptext.append("Nahrung transferieren: <input name='nahrung' type='text' size='6' value='"+res.getCount1()+"' /><br />"); 
    378380                                tooltiptext.append("<input name='col' type='hidden' value='"+base.getID()+"' />"); 
    379381                                tooltiptext.append("<input name='sess' type='hidden' value='"+getString("sess")+"' />"); 
  • src/net/driftingsouls/ds2/server/ships/Ship.java

    rc3e8956 r548df42  
    833833                                String astatus = oldstatus[i]; 
    834834                                if( !astatus.equals("disable_iff") && !astatus.equals("mangel_nahrung") &&  
    835                                         !astatus.equals("mangel_reaktor") && !astatus.equals("offizier") &&  
    836                                         !astatus.equals("nocrew") && !astatus.equals("nebel") && !astatus.equals("tblmodules") ) { 
     835                                               !astatus.equals("mangel_reaktor") && !astatus.equals("offizier") &&  
     836                                               !astatus.equals("nocrew") && !astatus.equals("nebel") && !astatus.equals("tblmodules") ) { 
    837837                                        status.add(astatus); 
    838838                                } 
     
    843843                if( type.getRm() > 0 ) { 
    844844                        long ep = cargo.getResourceCount( Resources.URAN ) * type.getRu() +  
    845                                cargo.getResourceCount( Resources.DEUTERIUM ) * type.getRd() +  
    846                                cargo.getResourceCount( Resources.ANTIMATERIE ) * type.getRa(); 
     845                        cargo.getResourceCount( Resources.DEUTERIUM ) * type.getRd() +  
     846                        cargo.getResourceCount( Resources.ANTIMATERIE ) * type.getRa(); 
    847847                        long er = ep/type.getRm(); 
    848848                         
     
    861861                        status.add("nocrew");    
    862862                } 
    863          
     863 
    864864                // Die Items nach IFF und Hydros durchsuchen 
    865865                boolean disableIFF = false; 
    866          
     866 
    867867                if( cargo.getItemWithEffect(ItemEffect.Type.DISABLE_IFF) != null ) { 
    868868                        disableIFF = true; 
     
    872872                        status.add("disable_iff"); 
    873873                } 
    874                  
    875                 Cargo usercargo = new Cargo(Cargo.Type.STRING, this.owner.getCargo()); 
    876                  
    877                 // Den Nahrungsverbrauch berechnen 
    878                 if( this.crew > 0 ) { 
    879                         double scale = 1; 
    880                         if( (this.alarm == 1) && (type.getShipClass() != ShipClasses.GESCHUETZ.ordinal()) ) { 
    881                                 scale = 0.9;     
    882                         } 
    883                          
    884                         int nn = (int)Math.ceil(this.crew/scale) - type.getHydro(); 
    885                         if( (nn > 0) || ((nn == 0) && (type.getHydro() == 0)) ) { 
    886                                 if( nn == 0 ) nn = 1; 
    887                                 long nr = usercargo.getResourceCount( Resources.NAHRUNG )/nn; 
    888                                  
    889                                 if( nr <= MANGEL_TICKS ) { 
    890                                         status.add("mangel_nahrung"); 
    891                                 } 
    892                         } 
    893                 } 
    894                  
     874 
    895875                // Ist ein Offizier an Bord? 
    896876                Offizier offi = Offizier.getOffizierByDest('s', this.id); 
     
    898878                        status.add("offizier"); 
    899879                } 
    900                  
     880 
    901881                ShipModules modules = (ShipModules)db.get(ShipModules.class, this.id); 
    902882                if( modules != null ) { 
    903883                        status.add("tblmodules"); 
    904884                } 
     885 
     886                if( lackOfFood() ) { 
     887                        status.add("mangel_nahrung"); 
     888                } 
     889 
     890                this.status = Common.implode(" ", status); 
     891 
     892                return this.status; 
     893        } 
     894 
     895        private boolean lackOfFood() { 
     896                if( timeUntilLackOfFood() <= MANGEL_TICKS ) { 
     897                        return true; 
     898                } 
     899 
     900                return false; 
     901        } 
     902 
     903        private long timeUntilLackOfFood() { 
     904                Cargo usercargo = new Cargo(Cargo.Type.STRING, this.owner.getCargo()); 
     905                long timeUntilLackOfFood = 0; 
     906                int foodConsumption = getNettoFoodConsumption(); 
     907 
     908                if( foodConsumption <= 0 ) { 
     909                        return Long.MAX_VALUE; 
     910                } 
     911 
     912                //Den Nahrungsverbrauch berechnen 
     913                if( isUserCargoUsable() ) { 
     914                        timeUntilLackOfFood = usercargo.getResourceCount(Resources.NAHRUNG) / foodConsumption; 
     915                } 
     916                else { 
     917                        //Basisschiff beruecksichtigen 
     918                        Ship baseShip = getBaseShip(); 
     919                        if( baseShip != null ) { 
     920                                timeUntilLackOfFood = baseShip.timeUntilLackOfFood(); 
     921                        } 
     922 
     923                        timeUntilLackOfFood += this.cargo.getResourceCount(Resources.NAHRUNG) / foodConsumption; 
     924                } 
     925                return timeUntilLackOfFood; 
     926        } 
     927 
     928        /** 
     929         * Calculates the amount of food a ship consumes. 
     930         * The calculation is done with respect to hydros. 
     931         *  
     932         * @return Amount of food this ship consumes 
     933         */ 
     934        private int getFoodConsumption() { 
     935                ShipTypeData shiptype = this.getTypeData(); 
     936                int scaledCrew = getScaledCrew(); 
     937                int production = shiptype.getHydro(); 
     938                return scaledCrew-production; 
     939        } 
     940 
     941        /** 
     942         * Calculates the amound of food the ship consumes with respect to docked ships. 
     943         *  
     944         * @return The amount this ship consumes with respect to docked ships. 
     945         */ 
     946        private int getNettoFoodConsumption() { 
     947                org.hibernate.Session db = ContextMap.getContext().getDB(); 
     948                int foodConsumption = getFoodConsumption(); 
    905949                 
    906                 this.status = Common.implode(" ", status); 
    907                          
    908                 return this.status; 
    909         } 
    910          
     950                //Angehaengte Schiffe beruecksichtigen 
     951                List dockedShips = db.createQuery("from Ship as ship where ship.docked=?") 
     952                        .setEntity(0, this) 
     953                        .list(); 
     954                for( Iterator iter=dockedShips.iterator(); iter.hasNext(); ) { 
     955                        Ship dockedShip = (Ship)iter.next(); 
     956                                 
     957                        foodConsumption += dockedShip.getNettoFoodConsumption(); 
     958                } 
     959                return foodConsumption; 
     960        } 
     961 
     962        /** 
     963         * Returns the crew scaled by a factor according to alert red. 
     964         * Ships with actived alert red consume more food. 
     965         *  
     966         * @return Crew scaled by a factor according to shiptype. 
     967         */ 
     968        private int getScaledCrew() { 
     969                ShipTypeData type = this.getTypeData(); 
     970                double scale = 1; 
     971                if( (this.alarm == 1) && (type.getShipClass() != ShipClasses.GESCHUETZ.ordinal()) ) { 
     972                        scale = 0.9;     
     973                } 
     974 
     975                int scaledCrew = (int)Math.ceil(this.crew/scale) - type.getHydro(); 
     976                return scaledCrew; 
     977        } 
     978 
    911979        /** 
    912980         * Repraesentiert ein in ein Schiff eingebautes Modul (oder vielmehr die Daten,  
     
    927995                 */ 
    928996                public final String data; 
    929                  
     997 
    930998                protected ModuleEntry(int slot, int moduleType, String data) { 
    931999                        this.slot = slot; 
     
    9331001                        this.data = data; 
    9341002                } 
    935                  
     1003 
    9361004                @Override 
    9371005                public String toString() { 
     
    9391007                } 
    9401008        } 
    941          
     1009 
    9421010        /** 
    9431011         * Gibt die Moduleintraege des Schiffes zurueck 
     
    9461014        public ModuleEntry[] getModules() { 
    9471015                org.hibernate.Session db = ContextMap.getContext().getDB(); 
    948                  
     1016 
    9491017                List<Ship.ModuleEntry> result = new ArrayList<ModuleEntry>(); 
    950                  
     1018 
    9511019                if( this.status.indexOf("tblmodules") == -1 ) { 
    9521020                        return new ModuleEntry[0]; 
    9531021                } 
    954                  
     1022 
    9551023                ShipModules moduletbl = (ShipModules)db.get(ShipModules.class, this.id);         
    9561024                if( moduletbl == null ) { 
     
    9581026                        return new ModuleEntry[0]; 
    9591027                } 
    960                  
     1028 
    9611029                if( moduletbl.getModules().length() != 0 ) { 
    9621030                        String[] modulelist = StringUtils.split(moduletbl.getModules(), ';'); 
     
    9681036                        } 
    9691037                } 
    970                  
     1038 
    9711039                return result.toArray(new ModuleEntry[result.size()]); 
    9721040        } 
    973          
     1041 
    9741042        /** 
    9751043         * Fuegt ein Modul in das Schiff ein 
     
    9821050                        throw new UnsupportedOperationException("addModules kann nur bei Schiffen mit positiver ID ausgefuhert werden!"); 
    9831051                } 
    984                  
     1052 
    9851053                org.hibernate.Session db = ContextMap.getContext().getDB(); 
    9861054 
     
    9891057                        shipModules = new ShipModules(this.id); 
    9901058                        db.persist(shipModules); 
    991                          
     1059 
    9921060                        if( this.status.length() != 0 ) { 
    9931061                                this.status += " tblmodules";    
     
    10001068                        shipModules = (ShipModules)db.get(ShipModules.class, this.id); 
    10011069                } 
    1002                  
     1070 
    10031071                List<ModuleEntry> moduletbl = new ArrayList<ModuleEntry>(); 
    10041072                moduletbl.addAll(Arrays.asList(getModules())); 
    1005                                  
     1073 
    10061074                //check modules 
    1007                  
     1075 
    10081076                //rebuild 
    10091077                moduletbl.add(new ModuleEntry(slot, moduleid, data )); 
    1010                  
     1078 
    10111079                ShipTypeData type = Ship.getShipType( this.shiptype.getId(), false, true ); 
    1012                  
     1080 
    10131081                Map<Integer,String[]>slotlist = new HashMap<Integer,String[]>(); 
    10141082                String[] tmpslotlist = StringUtils.splitPreserveAllTokens(type.getTypeModules(), ';'); 
     
    10171085                        slotlist.put(Integer.parseInt(aslot[0]), aslot); 
    10181086                } 
    1019                  
     1087 
    10201088                List<Module> moduleobjlist = new ArrayList<Module>(); 
    10211089                List<String> moduleSlotData = new ArrayList<String>();  
    1022                  
     1090 
    10231091                for( int i=0; i < moduletbl.size(); i++ ) { 
    10241092                        ModuleEntry module = moduletbl.get(i); 
     
    10291097                                } 
    10301098                                moduleobjlist.add(moduleobj); 
    1031                          
     1099 
    10321100                                moduleSlotData.add(module.slot+":"+module.moduleType+":"+module.data); 
    10331101                        } 
    10341102                } 
    1035                  
     1103 
    10361104                for( int i=0; i < moduleobjlist.size(); i++ ) { 
    10371105                        type = moduleobjlist.get(i).modifyStats( type, moduleobjlist );          
    10381106                } 
    1039                  
     1107 
    10401108                shipModules.setModules(Common.implode(";",moduleSlotData)); 
    10411109                shipModules.setNickname(type.getNickname()); 
     
    10671135                shipModules.setOneWayWerft(type.getOneWayWerft()); 
    10681136        } 
    1069          
     1137 
    10701138        /** 
    10711139         * Entfernt ein Modul aus dem Schiff 
     
    10781146                        throw new UnsupportedOperationException("addModules kann nur bei Schiffen mit positiver ID ausgefuhert werden!"); 
    10791147                } 
    1080                  
     1148 
    10811149                org.hibernate.Session db = ContextMap.getContext().getDB(); 
    1082                  
     1150 
    10831151                if( this.status.indexOf("tblmodules") == -1 ) { 
    10841152                        return; 
    10851153                } 
    1086                  
     1154 
    10871155                ShipModules shipModules = (ShipModules)db.get(ShipModules.class, this.id); 
    1088                  
     1156 
    10891157                List<ModuleEntry> moduletbl = new ArrayList<ModuleEntry>(); 
    10901158                moduletbl.addAll(Arrays.asList(getModules())); 
    1091                  
     1159 
    10921160                //check modules 
    1093                  
     1161 
    10941162                //rebuild        
    10951163                ShipTypeData type = Ship.getShipType( this.shiptype.getId(), false, true ); 
    1096                  
     1164 
    10971165                Map<Integer,String[]>slotlist = new HashMap<Integer,String[]>(); 
    10981166                String[] tmpslotlist = StringUtils.split(type.getTypeModules(), ';'); 
     
    11011169                        slotlist.put(Integer.parseInt(aslot[0]), aslot); 
    11021170                } 
    1103                  
     1171 
    11041172                List<Module> moduleobjlist = new ArrayList<Module>(); 
    11051173                List<String> moduleSlotData = new ArrayList<String>();  
    1106                  
     1174 
    11071175                for( int i=0; i < moduletbl.size(); i++ ) { 
    11081176                        ModuleEntry module = moduletbl.get(i); 
    11091177                        if( module.moduleType != 0 ) { 
    11101178                                Module moduleobj = Modules.getShipModule( module ); 
    1111                                  
     1179 
    11121180                                if( moduleobj.isSame(slot, moduleid, data) ) { 
    11131181                                        continue; 
    11141182                                } 
    1115                                  
     1183 
    11161184                                if( (module.slot > 0) && (slotlist.get(module.slot).length > 2) ) { 
    11171185                                        moduleobj.setSlotData(slotlist.get(module.slot)[2]); 
    11181186                                } 
    11191187                                moduleobjlist.add(moduleobj); 
    1120                          
     1188 
    11211189                                moduleSlotData.add(module.slot+":"+module.moduleType+":"+module.data); 
    11221190                        } 
     
    11261194                        type = moduleobjlist.get(i).modifyStats( type, moduleobjlist );          
    11271195                } 
    1128                  
     1196 
    11291197                if( moduleSlotData.size() > 0 ) { 
    11301198                        shipModules.setModules(Common.implode(";",moduleSlotData)); 
     
    11621230                        String[] status = StringUtils.split(this.status, ' '); 
    11631231                        String[] newstatus = new String[status.length-1]; 
    1164                          
     1232 
    11651233                        for( int i=0,j=0; i < status.length; i++ ) { 
    11661234                                if( !status[i].equals("tblmodules") ) { 
     
    11681236                                }        
    11691237                        } 
    1170          
     1238 
    11711239                        this.status = Common.implode(" ",newstatus); 
    11721240                } 
    11731241        } 
    1174          
     1242 
    11751243        /** 
    11761244         * Berechnet die durch Module verursachten Effekte des Schiffes neu 
     
    11781246        public void recalculateModules() { 
    11791247                org.hibernate.Session db = ContextMap.getContext().getDB(); 
    1180                  
     1248 
    11811249                if( this.status.indexOf("tblmodules") == -1 ) { 
    11821250                        return; 
    11831251                } 
    1184                  
     1252 
    11851253                ShipModules shipModules = (ShipModules)db.get(ShipModules.class, this.id); 
    1186                  
     1254 
    11871255                List<ModuleEntry> moduletbl = new ArrayList<ModuleEntry>(); 
    11881256                moduletbl.addAll(Arrays.asList(getModules())); 
    1189                  
     1257 
    11901258                //check modules 
    1191                  
     1259 
    11921260                //rebuild        
    11931261                ShipTypeData type = Ship.getShipType( this.shiptype.getId(), false, true ); 
    1194                  
     1262 
    11951263                Map<Integer,String[]>slotlist = new HashMap<Integer,String[]>(); 
    11961264                String[] tmpslotlist = StringUtils.split(type.getTypeModules(), ';'); 
     
    11991267                        slotlist.put(Integer.parseInt(aslot[0]), aslot); 
    12001268                } 
    1201                  
     1269 
    12021270                List<Module> moduleobjlist = new ArrayList<Module>(); 
    12031271                List<String> moduleSlotData = new ArrayList<String>();  
    1204                  
     1272 
    12051273                for( int i=0; i < moduletbl.size(); i++ ) { 
    12061274                        ModuleEntry module = moduletbl.get(i); 
    12071275                        if( module.moduleType != 0 ) { 
    12081276                                Module moduleobj = Modules.getShipModule( module ); 
    1209                                  
     1277 
    12101278                                if( (module.slot > 0) && (slotlist.get(module.slot).length > 2) ) { 
    12111279                                        moduleobj.setSlotData(slotlist.get(module.slot)[2]); 
    12121280                                } 
    12131281                                moduleobjlist.add(moduleobj); 
    1214                          
     1282 
    12151283                                moduleSlotData.add(module.slot+":"+module.moduleType+":"+module.data); 
    12161284                        } 
     
    12201288                        type = moduleobjlist.get(i).modifyStats( type, moduleobjlist );          
    12211289                } 
    1222                  
     1290 
    12231291                shipModules.setModules(Common.implode(";",moduleSlotData)); 
    12241292                shipModules.setNickname(type.getNickname()); 
     
    12501318                shipModules.setOneWayWerft(type.getOneWayWerft()); 
    12511319        } 
    1252          
     1320 
    12531321        private void handleRedAlert() { 
    12541322                User owner = this.owner; 
    12551323                Integer[] attackers = redAlertCheck( owner, this.getLocation(), false ); 
    1256                  
     1324 
    12571325                org.hibernate.Session db = ContextMap.getContext().getDB(); 
    1258          
     1326 
    12591327                if( attackers.length > 0 ) { 
    12601328                        // Schauen wir mal ob wir noch ein Schiff mit rotem Alarm ohne Schlacht finden (sortiert nach Besitzer-ID) 
     
    12621330                                        "system=? and lock is null and docked='' and e>0 and " + 
    12631331                                        "owner in ("+Common.implode(",",attackers)+") and alarm=1 and " + 
    1264                                        "locate('nocrew',status)=0 and battle=0 order by owner") 
    1265                                                .setInteger(0, this.x) 
    1266                                                .setInteger(1, this.y) 
    1267                                                .setInteger(2, this.system) 
    1268                                                .setMaxResults(1) 
    1269                                                .uniqueResult(); 
    1270                                  
     1332                        "locate('nocrew',status)=0 and battle=0 order by owner") 
     1333                        .setInteger(0, this.x) 
     1334                        .setInteger(1, this.y) 
     1335                        .setInteger(2, this.system) 
     1336                        .setMaxResults(1) 
     1337                        .uniqueResult(); 
     1338 
    12711339                        if( eship != null ) { 
    12721340                                Battle battle = new Battle(); 
    12731341                                battle.setStartOwn(true); 
    12741342                                battle.create(eship.getOwner().getID(), eship.getId(), this.id); 
    1275                                  
     1343 
    12761344                                MESSAGE.get().append("<span style=\"color:red\">Feindliche Schiffe feuern beim Einflug</span><br />\n"); 
    12771345                        } 
     
    12811349                                                "system=? and lock is null and docked='' and e>0 and " + 
    12821350                                                "owner in ("+Common.implode(",",attackers)+") and alarm=1 and " + 
    1283                                                "locate('nocrew',status)=0 and battle!=0 order by owner") 
    1284                                                        .setInteger(0, this.x) 
    1285                                                        .setInteger(1, this.y) 
    1286                                                        .setInteger(2, this.system) 
    1287                                                        .setMaxResults(1) 
    1288                                                        .uniqueResult(); 
    1289                                                  
     1351                                "locate('nocrew',status)=0 and battle!=0 order by owner") 
     1352                                .setInteger(0, this.x) 
     1353                                .setInteger(1, this.y) 
     1354                                .setInteger(2, this.system) 
     1355                                .setMaxResults(1) 
     1356                                .uniqueResult(); 
     1357 
    12901358                                if( eship != null ) { 
    12911359                                        Battle battle = new Battle(); 
     
    12931361                                        int oside = (bship.getSide() + 1) % 2 + 1; 
    12941362                                        battle.load(eship.getBattle(), this.owner.getID(), 0, 0, oside); 
    1295                                          
     1363 
    12961364                                        int docked = ((Number)db.createQuery("select count(*) from Ship where docked=?") 
    1297                                                 .setString(0, Integer.toString(this.id)) 
    1298                                                 .iterate().next()).intValue(); 
    1299                                          
     1365                                                       .setString(0, Integer.toString(this.id)) 
     1366                                                       .iterate().next()).intValue(); 
     1367 
    13001368                                        if( docked != 0 ) { 
    13011369                                                List dlist = db.createQuery("from Ship where docked=?") 
    1302                                                        .setString(0, Integer.toString(this.id)) 
    1303                                                        .list(); 
     1370                                                .setString(0, Integer.toString(this.id)) 
     1371                                                .list(); 
    13041372                                                for( Iterator iter=dlist.iterator(); iter.hasNext(); ) { 
    13051373                                                        Ship aship = (Ship)iter.next(); 
    1306                                                          
     1374 
    13071375                                                        battle.addShip( this.owner.getID(), aship.getId() ); 
    13081376                                                } 
    13091377                                        } 
    13101378                                        battle.addShip( this.owner.getID(), this.id ); 
    1311                                          
     1379 
    13121380                                        if( battle.getEnemyLog(true).length() != 0 ) { 
    13131381                                                battle.writeLog(); 
    13141382                                        } 
    1315                                          
     1383 
    13161384                                        MESSAGE.get().append("<br /><span style=\"color:red\">Feindliche Schiffe feuern beim Einflug</span><br />\n"); 
    13171385                                } 
     
    13191387                } 
    13201388        } 
    1321          
     1389 
    13221390        /** 
    13231391         * Gibt <code>true</code> zurueck, wenn der angegebene Sektor fuer den angegebenen Spieler 
     
    13311399        public static boolean getRedAlertStatus( int userid, int system, int x, int y ) { 
    13321400                org.hibernate.Session db = ContextMap.getContext().getDB(); 
    1333                  
     1401 
    13341402                User user = (User)db.get(User.class, userid); 
    1335                  
     1403 
    13361404                Integer[] attackers = redAlertCheck(user,  
    13371405                                new Location(system, x, y), true); 
    1338                  
     1406 
    13391407                if( attackers.length > 0 ) { 
    13401408                        return true; 
     
    13421410                return false; 
    13431411        } 
    1344          
     1412 
    13451413        private static Integer[] redAlertCheck( User user, Location loc, boolean checkonly ) { 
    13461414                Context context = ContextMap.getContext(); 
    13471415                org.hibernate.Session db = context.getDB(); 
    1348                  
     1416 
    13491417                User.Relations relationlist = user.getRelations(); 
    1350                  
     1418 
    13511419                List<Integer> attackers = new ArrayList<Integer>(); 
    1352                  
     1420 
    13531421                List ownerList = db.createQuery("select distinct s.owner from Ship as s where s.id>0 and s.x=? and s.y=? and " + 
    1354                                "s.system=? and s.e>0 and s.owner!=? and s.alarm=1 and s.lock is null and s.docked='' and locate('nocrew',s.status)=0") 
    1355                        .setInteger(0, loc.getX()) 
    1356                        .setInteger(1, loc.getY()) 
    1357                        .setInteger(2, loc.getSystem()) 
    1358                        .setEntity(3, user) 
    1359                        .list(); 
     1422                "s.system=? and s.e>0 and s.owner!=? and s.alarm=1 and s.lock is null and s.docked='' and locate('nocrew',s.status)=0") 
     1423                .setInteger(0, loc.getX()) 
     1424                .setInteger(1, loc.getY()) 
     1425                .setInteger(2, loc.getSystem()) 
     1426                .setEntity(3, user) 
     1427                .list(); 
    13601428                for( Iterator iter=ownerList.iterator(); iter.hasNext(); ) { 
    13611429                        User auser = (User)iter.next(); 
    1362                          
     1430 
    13631431                        if( (auser.getVacationCount() != 0) && (auser.getWait4VacationCount() == 0) ) { 
    13641432                                continue;        
    13651433                        } 
    1366                          
     1434 
    13671435                        if( relationlist.fromOther.get(auser.getID()) == User.Relation.ENEMY ) { 
    13681436                                attackers.add(auser.getID()); 
     
    13721440                        }  
    13731441                } 
    1374          
     1442 
    13751443                return attackers.toArray(new Integer[attackers.size()]); 
    13761444        } 
    1377          
     1445 
    13781446        private static class MovementResult { 
    13791447                int distance; 
    13801448                boolean moved; 
    13811449                boolean error; 
    1382                  
     1450 
    13831451                MovementResult(int distance, boolean moved, boolean error) { 
    13841452                        this.distance = distance; 
     
    13871455                } 
    13881456        } 
    1389          
     1457 
    13901458        private static MovementResult moveSingle(Ship ship, ShipTypeData shiptype, Offizier offizier, int direction, int distance, int adocked, boolean forceLowHeat, boolean verbose) { 
    13911459                boolean moved = false; 
    13921460                boolean error = false; 
    13931461                boolean firstOutput = true; 
    1394                  
     1462 
    13951463                StringBuilder out = MESSAGE.get(); 
    1396                  
     1464 
    13971465                if( ship.getEngine() <= 0 ) { 
    13981466                        if(verbose) { 
     
    14001468                        } 
    14011469                        distance = 0; 
    1402                          
     1470 
    14031471                        return new MovementResult(distance, moved, true); 
    14041472                } 
    1405                  
     1473 
    14061474                int newe = ship.getEnergy() - shiptype.getCost(); 
    14071475                int news = ship.getHeat() + shiptype.getHeat(); 
    1408                                  
     1476 
    14091477                newe -= adocked; 
    14101478                if( shiptype.getCrew()/2 > ship.getCrew() ) { 
     
    14141482                        } 
    14151483                } 
    1416                  
     1484 
    14171485                // Antrieb teilweise beschaedigt? 
    14181486                if( ship.getEngine() < 20 ) { 
     
    14251493                        newe -= 1; 
    14261494                } 
    1427                  
     1495 
    14281496                if( newe < 0 ) { 
    14291497                        if(!verbose && firstOutput) 
     
    14341502                        out.append("<span style=\"color:#ff0000\">Keine Energie. Stoppe bei "+Ships.getLocationText(ship.getLocation(), true)+"</span><br />\n"); 
    14351503                        distance = 0; 
    1436                          
     1504 
    14371505                        return new MovementResult(distance, moved, true); 
    14381506                } 
     
    14651533                        } 
    14661534                } 
    1467                  
     1535 
    14681536                // Grillen wir uns bei dem Flug eventuell den Antrieb? 
    14691537                if( news > 100 )  { 
     
    14841552                int x = ship.getX(); 
    14851553                int y = ship.getY(); 
    1486          
     1554 
    14871555                if( direction == 1 ) { x--; y--; } 
    14881556                else if( direction == 2 ) { y--; } 
     
    14931561                else if( direction == 8 ) { y++; } 
    14941562                else if( direction == 9 ) { x++; y++; } 
    1495          
     1563 
    14961564                StarSystem sys = Systems.get().system(ship.getSystem()); 
    1497                  
     1565 
    14981566                if( x > sys.getWidth()) {  
    14991567                        x = sys.getWidth(); 
     
    15121580                        distance = 0; 
    15131581                } 
    1514                  
     1582 
    15151583                if( (ship.getX() != x) || (ship.getY() != y) ) { 
    15161584                        moved = true; 
    1517                          
     1585 
    15181586                        if( ship.getHeat() >= 100 ) { 
    15191587                                if( !verbose && firstOutput) { 
     
    15221590                                } 
    15231591                                out.append("<span style=\"color:#ff0000\">Triebwerke &uuml;berhitzt</span><br />\n"); 
    1524                                  
     1592 
    15251593                                if( (RandomUtils.nextInt(101)) < 3*(news-100) ) { 
    15261594                                        int dmg = (int)( (2*(RandomUtils.nextInt(101)/100d)) + 1 ) * (news-100); 
     
    15371605                                } 
    15381606                        } 
    1539                                                  
     1607 
    15401608                        ship.setX(x); 
    15411609                        s