Changeset fdd9b7da5f3efa70d6ba2e2ede6d0cb28403831c
- Timestamp:
- 07/01/07 09:50:24 (1 year ago)
- git-parent:
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
src/net/driftingsouls/ds2/server/werften/ShipWerft.java
r6b67f71 rfdd9b7d 390 390 391 391 @Override 392 public boolean dismantleShip( int dismantle, boolean testonly) {393 boolean result = super.dismantleShip( dismantle, testonly);392 public boolean dismantleShip(Ship ship, boolean testonly) { 393 boolean result = super.dismantleShip(ship, testonly); 394 394 395 395 this.ship.recalculateShipStatus(); src/net/driftingsouls/ds2/server/werften/WerftGUI.java
rc9078b0 rfdd9b7d 21 21 import java.util.ArrayList; 22 22 import java.util.HashMap; 23 import java.util.Iterator; 23 24 import java.util.List; 24 25 import java.util.Map; … … 26 27 import net.driftingsouls.ds2.server.Location; 27 28 import net.driftingsouls.ds2.server.Offizier; 29 import net.driftingsouls.ds2.server.bases.Base; 28 30 import net.driftingsouls.ds2.server.cargo.Cargo; 29 31 import net.driftingsouls.ds2.server.cargo.ItemCargoEntry; … … 43 45 import net.driftingsouls.ds2.server.framework.Context; 44 46 import net.driftingsouls.ds2.server.framework.ContextMap; 45 import net.driftingsouls.ds2.server.framework.db.Database;46 import net.driftingsouls.ds2.server.framework.db.SQLQuery;47 47 import net.driftingsouls.ds2.server.framework.db.SQLResultRow; 48 48 import net.driftingsouls.ds2.server.framework.templates.TemplateEngine; … … 78 78 */ 79 79 public String execute( WerftObject werft ) { 80 Database db = context.getDatabase();80 org.hibernate.Session db = context.getDB(); 81 81 82 82 int build = context.getRequest().getParameterInt("build"); … … 142 142 t.parse("werftgui.linkedbase.list", "werftgui.linkedbase.listitem", true); 143 143 144 SQLQuery base = db.query("SELECT id,name FROM bases ", 145 "WHERE x=",werft.getX()," AND y=",werft.getY()," AND system=",werft.getSystem()," AND owner=",werft.getOwner()," ORDER BY id"); 146 while( base.next() ) { 147 t.set_var( "linkedbase.selected", (linkedbaseID == base.getInt("id")), 148 "linkedbase.value", base.getInt("id"), 149 "linkedbase.name", base.getString("name")+" ("+base.getInt("id")+")" ); 144 List bases = db.createQuery("from Base " + 145 "where x=? and y=? and system=? and owner=? order by id") 146 .setInteger(0, werft.getX()) 147 .setInteger(1, werft.getY()) 148 .setInteger(2, werft.getSystem()) 149 .setInteger(3, werft.getOwner()) 150 .list(); 151 for( Iterator iter=bases.iterator(); iter.hasNext(); ) { 152 Base base = (Base)iter.next(); 153 154 t.set_var( "linkedbase.selected", (linkedbaseID == base.getID()), 155 "linkedbase.value", base.getID(), 156 "linkedbase.name", base.getName()+" ("+base.getID()+")" ); 150 157 t.parse("werftgui.linkedbase.list", "werftgui.linkedbase.listitem", true); 151 158 } 152 base.free();153 159 } 154 160 } … … 159 165 160 166 private void out_wsShipList(WerftObject werft) { 161 Database db = context.getDatabase();167 org.hibernate.Session db = context.getDB(); 162 168 163 169 t.set_var("werftgui.wsshiplist", 1); 164 170 t.set_block("_WERFT.WERFTGUI", "wsshiplist.listitem", "wsshiplist.list"); 165 171 166 SQLQuery ship = db.query("SELECT t1.id,t1.name,t1.type,t1.status,t1.engine,t1.sensors,t1.comm,t1.weapons,t1.hull,t1.owner,t2.name AS ownername,t2.id AS userid ", 167 "FROM ships t1 JOIN users t2 ON t1.owner=t2.id ", 168 "WHERE t1.id>0 AND t1.x BETWEEN ",(werft.getX()-werft.getSize())," AND ",(werft.getX()+werft.getSize())," AND t1.y BETWEEN ",(werft.getY()-werft.getSize())," AND ",(werft.getY()+werft.getSize())," AND t1.system=",werft.getSystem()," AND !LOCATE('l ',t1.docked) AND t1.battle=0 ORDER BY t2.id,t1.id"); 169 170 while( ship.next() ) { 171 if( (werft.getWerftType() == WerftObject.SHIP) && (((ShipWerft)werft).getShipID() == ship.getInt("id")) ) { 172 List ships = db.createQuery("from Ship s inner join fetch s.owner as u " + 173 "where s.id>0 and (s.x between ? and ?) and (s.y between ? and ?) and s.system=? and " + 174 "locate('l ',s.docked)=0 and s.battle=0 order by u.id,s.id") 175 .setInteger(0, werft.getX()-werft.getSize()) 176 .setInteger(1, werft.getX()+werft.getSize()) 177 .setInteger(2, werft.getY()-werft.getSize()) 178 .setInteger(3, werft.getY()+werft.getSize()) 179 .setInteger(4, werft.getSystem()) 180 .list(); 181 182 for( Iterator iter=ships.iterator(); iter.hasNext(); ) { 183 Ship ship = (Ship)iter.next(); 184 185 if( (werft.getWerftType() == WerftObject.SHIP) && (((ShipWerft)werft).getShip() == ship) ) { 172 186 continue; 173 187 } 174 188 175 ShipTypeData shiptype = Ship.getShipType( ship.getRow());176 177 if( (ship.get Int("hull") < shiptype.getHull()) || (ship.getInt("engine") < 100) ||178 (ship.get Int("sensors") < 100) || (ship.getInt("comm") < 100) || (ship.getInt("weapons") < 100) ) {189 ShipTypeData shiptype = ship.getTypeData(); 190 191 if( (ship.getHull() < shiptype.getHull()) || (ship.getEngine() < 100) || 192 (ship.getSensors() < 100) || (ship.getComm() < 100) || (ship.getWeapons() < 100) ) { 179 193 t.set_var("ship.needsrepair", 1); 180 194 } … … 183 197 } 184 198 185 String ownername = Common._title(ship.getString("ownername")); 186 if( ownername.length() == 0 ) { 187 ownername = "Unbekannter Spieler ("+ship.getInt("owner")+")"; 188 } 199 String ownername = Common._title(ship.getOwner().getName()); 189 200 190 t.set_var( "ship.id", ship.getI nt("id"),191 "ship.name", ship.get String("name"),201 t.set_var( "ship.id", ship.getId(), 202 "ship.name", ship.getName(), 192 203 "ship.owner.name", ownername ); 193 204 194 205 t.parse("wsshiplist.list", "wsshiplist.listitem", true); 195 206 } 196 ship.free();197 207 } 198 208 … … 318 328 private void out_ws(WerftObject werft, int ws) { 319 329 Context context = ContextMap.getContext(); 320 Database db = context.getDatabase();330 org.hibernate.Session db = context.getDB(); 321 331 322 332 User user = (User)context.getActiveUser(); 323 333 String sess = context.getSession(); 324 334 325 S QLResultRow ship = db.first("SELECT * FROM ships WHERE id>0 AND id=",ws);326 if( ship.isEmpty() ) {335 Ship ship = (Ship)db.get(Ship.class, ws); 336 if( (ship == null) || (ship.getId() < 0) ) { 327 337 context.addError("Das angegebene Schiff existiert nicht", werft.getUrlBase()+"&sess="+sess); 328 338 return; … … 332 342 return; 333 343 } 334 if( ! Location.fromResult(ship).sameSector(0, new Location(werft.getSystem(), werft.getX(), werft.getY()), werft.getSize()) ) {344 if( !ship.getLocation().sameSector(0, new Location(werft.getSystem(), werft.getX(), werft.getY()), werft.getSize()) ) { 335 345 context.addError("Das Schiff befindet sich nicht im selben Sektor wie die Werft", werft.getUrlBase()+"&sess="+sess); 336 346 return; 337 347 } 338 348 339 if( ship.get Int("battle") != 0 ) {349 if( ship.getBattle() != 0 ) { 340 350 context.addError("Das Schiff befindet sich in einer Schlacht", werft.getUrlBase()+"&sess="+sess); 341 351 return; 342 352 } 343 353 344 ShipTypeData shipType = Ship.getShipType(ship);354 ShipTypeData shipType = ship.getTypeData(); 345 355 346 356 t.set_var( "werftgui.ws", 1, 347 "ship.id", ship.getI nt("id"),348 "ship.name", ship.get String("name"),349 "ship.own", (ship.get Int("owner") == user.getID()),350 "ship.owner.id", ship.get Int("owner"),357 "ship.id", ship.getId(), 358 "ship.name", ship.getName(), 359 "ship.own", (ship.getOwner() == user), 360 "ship.owner.id", ship.getOwner(), 351 361 "ship.type.modules", shipType.getTypeModules() ); 352 362 353 if( ship.get Int("owner") != user.getID()) {354 User owner = (User)context.getDB().get(User.class, ship.getInt("owner"));363 if( ship.getOwner() != user ) { 364 User owner = ship.getOwner(); 355 365 t.set_var("ship.owner.name", Common._title(owner.getName())); 356 366 } … … 360 370 String conf = context.getRequest().getParameterString("conf"); 361 371 362 this.out_repairShip( ship .getInt("id"), werft, conf );372 this.out_repairShip( ship, werft, conf ); 363 373 } 364 374 else if( action.equals("dismantle") ) { 365 375 String conf = context.getRequest().getParameterString("conf"); 366 376 367 this.out_dismantleShip( ship .getInt("id"), werft, conf );377 this.out_dismantleShip( ship, werft, conf ); 368 378 } 369 379 else if( action.equals("module") ) { 370 this.out_moduleShip( ship .getInt("id"), werft );380 this.out_moduleShip( ship, werft ); 371 381 } 372 382 else { … … 391 401 } 392 402 393 private void out_ws_info(S QLResultRowship) {394 ShipTypeData shipType = Ship.getShipType(ship);403 private void out_ws_info(Ship ship) { 404 ShipTypeData shipType = ship.getTypeData(); 395 405 396 406 t.set_var( "werftgui.ws.showinfo", 1, 397 "ship.name", ship.get String("name"),407 "ship.name", ship.getName(), 398 408 "ship.type.id", shipType.getTypeId(), 399 409 "ship.type.picture", shipType.getPicture(), 400 "ship.id", ship.getI nt("id"),401 "ship.hull", ship.get Int("hull"),410 "ship.id", ship.getId(), 411 "ship.hull", ship.getHull(), 402 412 "ship.type.hull", shipType.getHull(), 403 "ship.hull.color", this.genSubColor(ship.get Int("hull"), shipType.getHull()),404 "ship.panzerung", Math.round(shipType.getPanzerung()*(double)ship.get Int("hull")/shipType.getHull()),405 "ship.shields", ship.get Int("shields"),413 "ship.hull.color", this.genSubColor(ship.getHull(), shipType.getHull()), 414 "ship.panzerung", Math.round(shipType.getPanzerung()*(double)ship.getHull()/shipType.getHull()), 415 "ship.shields", ship.getShields(), 406 416 "ship.type.shields", shipType.getShields(), 407 "ship.shields.color", this.genSubColor(ship.get Int("shields"), shipType.getShields()),408 "ship.engine", ship.get Int("engine"),417 "ship.shields.color", this.genSubColor(ship.getShields(), shipType.getShields()), 418 "ship.engine", ship.getEngine(), 409 419 "ship.type.engine", ( shipType.getCost() > 0 ? 100 : 0 ), 410 "ship.engine.color", this.genSubColor(ship.get Int("engine"), 100),411 "ship.weapons", ship.get Int("engine"),420 "ship.engine.color", this.genSubColor(ship.getEngine(), 100), 421 "ship.weapons", ship.getWeapons(), 412 422 "ship.type.weapons", ( shipType.isMilitary() ? 100 : 0 ), 413 "ship.weapons.color", this.genSubColor(ship.get Int("weapons"), 100),414 "ship.comm", ship.get Int("comm"),423 "ship.weapons.color", this.genSubColor(ship.getWeapons(), 100), 424 "ship.comm", ship.getComm(), 415 425 "ship.type.comm", 100, 416 "ship.comm.color", this.genSubColor(ship.get Int("comm"), 100),417 "ship.sensors", ship.get Int("sensors"),426 "ship.comm.color", this.genSubColor(ship.getComm(), 100), 427 "ship.sensors", ship.getSensors(), 418 428 "ship.type.sensors", 100, 419 "ship.sensors.color", this.genSubColor(ship.get Int("sensors"), 100),420 "ship.crew", ship.get Int("crew"),429 "ship.sensors.color", this.genSubColor(ship.getSensors(), 100), 430 "ship.crew", ship.getCrew(), 421 431 "ship.type.crew", shipType.getCrew(), 422 "ship.crew.color", this.genSubColor(ship.get Int("crew"), shipType.getCrew()),423 "ship.e", ship.get Int("e"),432 "ship.crew.color", this.genSubColor(ship.getCrew(), shipType.getCrew()), 433 "ship.e", ship.getEnergy(), 424 434 "ship.type.e", shipType.getEps(), 425 "ship.e.color", this.genSubColor(ship.get Int("e"), shipType.getEps()),426 "ship.heat", ship.get Int("s") );427 428 Offizier offizier = Offizier.getOffizierByDest('s', ship.getI nt("id"));435 "ship.e.color", this.genSubColor(ship.getEnergy(), shipType.getEps()), 436 "ship.heat", ship.getHeat() ); 437 438 Offizier offizier = Offizier.getOffizierByDest('s', ship.getId()); 429 439 if( offizier != null ) { 430 440 t.set_var( "ship.offizier.id", offizier.getID(), … … 435 445 } 436 446 437 private void out_moduleShip( int shipID, WerftObject werft) {447 private void out_moduleShip(Ship ship, WerftObject werft) { 438 448 Context context = ContextMap.getContext(); 439 org.hibernate.Session db = context.getDB();440 449 String sess = context.getSession(); 441 450 User user = (User)context.getActiveUser(); … … 444 453 int slot = context.getRequest().getParameterInt("slot"); 445 454 String moduleaction = context.getRequest().getParameterString("moduleaction"); 446 447 Ship ship = (Ship)db.get(Ship.class, shipID);448 455 449 456 //Gehoert das Schiff dem User? … … 527 534 } 528 535 529 private void out_dismantleShip( int dismantle, WerftObject werft, String conf) {536 private void out_dismantleShip(Ship ship, WerftObject werft, String conf) { 530 537 Context context = ContextMap.getContext(); 531 org.hibernate.Session db = context.getDB();532 538 String sess = context.getSession(); 533 539 User user = (User)context.getActiveUser(); 534 535 Ship ship = (Ship)db.get(Ship.class, dismantle);536 540 537 541 //Gehoert das Schiff dem User? … … 570 574 } 571 575 572 boolean ok = werft.dismantleShip( dismantle, !conf.equals("ok"));576 boolean ok = werft.dismantleShip(ship, !conf.equals("ok")); 573 577 if( !ok ) { 574 578 t.set_var("ws.dismantle.error", werft.MESSAGE.getMessage() ); … … 582 586 } 583 587 584 private void out_repairShip( int repair, WerftObject werft, String conf) {588 private void out_repairShip(Ship ship, WerftObject werft, String conf) { 585 589 Context context = ContextMap.getContext(); 586 org.hibernate.Session db = context.getDB(); 587 588 Ship ship = (Ship)db.get(Ship.class, repair); 590 589 591 if( (ship == null) || (ship.getId() < 0) ) { 590 592 context.addError("Das angegebene Schiff existiert nicht oder gehört nicht ihnen"); src/net/driftingsouls/ds2/server/werften/WerftObject.java
r6b67f71 rfdd9b7d 830 830 * nur das demontieren selbst.{@link DSObject#MESSAGE} enthaelt die Hinweistexte 831 831 * 832 * @param dismantle Die ID des zu demontierenden Schiffes832 * @param ship Das zu demontierende Schiff 833 833 * @param testonly Soll nur geprueft (true) oder wirklich demontiert werden (false)? 834 834 * @return true, wenn kein Fehler aufgetreten ist 835 835 */ 836 public boolean dismantleShip( int dismantle, boolean testonly) {836 public boolean dismantleShip(Ship ship, boolean testonly) { 837 837 org.hibernate.Session db = ContextMap.getContext().getDB(); 838 838 839 839 StringBuilder output = MESSAGE.get(); 840 840 841 Ship sd = (Ship)db.get(Ship.class, dismantle); 842 if( sd.getId() < 0 ) { 841 if( ship.getId() < 0 ) { 843 842 ContextMap.getContext().addError("Das angegebene Schiff existiert nicht"); 844 843 return false; 845 844 } 846 845 847 Cargo scargo = s d.getCargo();846 Cargo scargo = ship.getCargo(); 848 847 849 848 Cargo cargo = this.getCargo(false); … … 851 850 long maxcargo = this.getMaxCargo(false); 852 851 853 Cargo cost = this.getDismantleCargo( s d);852 Cargo cost = this.getDismantleCargo( ship ); 854 853 855 854 Cargo newcargo = (Cargo)cargo.clone(); … … 866 865 } 867 866 868 if( this.getCrew() + s d.getCrew() > this.getMaxCrew() ) {867 if( this.getCrew() + ship.getCrew() > this.getMaxCrew() ) { 869 868 output.append("Nicht gengend Platz für die Crew\n"); 870 869 ok = false; … … 874 873 875 874 List offiziere = db.createQuery("from Offizier where dest=?") 876 .setString(0, "s "+ dismantle)875 .setString(0, "s "+ship.getId()) 877 876 .list(); 878 877 … … 888 887 this.setCargo(newcargo, false); 889 888 890 this.setCrew(this.getCrew()+s d.getCrew());889 this.setCrew(this.getCrew()+ship.getCrew()); 891 890 for( Iterator iter=offiziere.iterator(); iter.hasNext(); ) { 892 891 Offizier offi = (Offizier)iter.next(); … … 894 893 } 895 894 896 s d.destroy();895 ship.destroy(); 897 896 } 898 897
