Changeset 7a698dad95e80782edc96d6337ae617f53930aa7
- Timestamp:
- 07/10/07 14:42:36
(1 year ago)
- Author:
- Christopher Jung <bktheg@web.de>
- git-committer:
- Christopher Jung <bktheg@web.de> 1184071356 +0200
- git-parent:
[7b3c789cd06aaa242290464dda877a5e06e5064c]
- git-author:
- Christopher Jung <bktheg@web.de> 1184071356 +0200
- Message:
Primary Key von Nebel geaendert (ist nun system,x,y)
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r425acaa |
r7a698da |
|
| 1 | 1 | CREATE TABLE `nebel` ( |
|---|
| 2 | | `id` int(11) NOT NULL auto_increment, |
|---|
| 3 | 2 | `x` int(11) NOT NULL default '0', |
|---|
| 4 | 3 | `y` int(11) NOT NULL default '0', |
|---|
| 5 | 4 | `system` int(11) NOT NULL default '0', |
|---|
| 6 | 5 | `type` tinyint(3) unsigned NOT NULL default '0', |
|---|
| 7 | | PRIMARY KEY (`id`), |
|---|
| 8 | | KEY `coords` (`x`,`y`,`system`) |
|---|
| | 6 | PRIMARY KEY (`system`,`x`,`y`) |
|---|
| 9 | 7 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; |
|---|
| ree28f5d |
r7a698da |
|
| 326 | 326 | ALTER TABLE `werft_queues` ADD COLUMN energyPerTick int NOT NULL default '0'; |
|---|
| 327 | 327 | ]]></update> |
|---|
| | 328 | <update type="structure" datum="2007-07-10"><![CDATA[ |
|---|
| | 329 | ALTER TABLE `nebel` DROP `id`; |
|---|
| | 330 | ALTER TABLE `nebel` ADD PRIMARY KEY ( `system` , `x` , `y` ); |
|---|
| | 331 | ALTER TABLE `nebel` DROP INDEX `coords`; |
|---|
| | 332 | ]]></update> |
|---|
| 328 | 333 | </updates> |
|---|
| r8721cca |
r7a698da |
|
| 16 | 16 | overflowToDisk="false" |
|---|
| 17 | 17 | /> |
|---|
| | 18 | <cache name="net.driftingsouls.ds2.server.entities.Nebel" |
|---|
| | 19 | maxElementsInMemory="200" |
|---|
| | 20 | eternal="false" |
|---|
| | 21 | timeToIdleSeconds="60" |
|---|
| | 22 | timeToLiveSeconds="600" |
|---|
| | 23 | overflowToDisk="false" |
|---|
| | 24 | /> |
|---|
| 18 | 25 | </ehcache> |
|---|
| rd54fd1c |
r7a698da |
|
| 19 | 19 | package net.driftingsouls.ds2.server; |
|---|
| 20 | 20 | |
|---|
| | 21 | import java.io.Serializable; |
|---|
| | 22 | |
|---|
| 21 | 23 | import net.driftingsouls.ds2.server.framework.db.SQLResultRow; |
|---|
| 22 | 24 | |
|---|
| … | … | |
| 26 | 28 | * |
|---|
| 27 | 29 | */ |
|---|
| 28 | | public class Location { |
|---|
| 29 | | private int x = 0; |
|---|
| 30 | | private int y = 0; |
|---|
| 31 | | private int system = 0; |
|---|
| 32 | | private int hashCode = 0; |
|---|
| | 30 | public final class Location implements Serializable, Locatable { |
|---|
| | 31 | private static final long serialVersionUID = -5144442902462679539L; |
|---|
| | 32 | |
|---|
| | 33 | private final int x; |
|---|
| | 34 | private final int y; |
|---|
| | 35 | private final int system; |
|---|
| | 36 | private transient int hashCode = 0; |
|---|
| 33 | 37 | |
|---|
| 34 | 38 | /** |
|---|
| … | … | |
| 37 | 41 | */ |
|---|
| 38 | 42 | public Location() { |
|---|
| 39 | | // EMPTY |
|---|
| | 43 | this.x = 0; |
|---|
| | 44 | this.y = 0; |
|---|
| | 45 | this.system = 0; |
|---|
| 40 | 46 | } |
|---|
| 41 | 47 | |
|---|
| … | … | |
| 141 | 147 | * @param result Die SQL-Ergebniszeile |
|---|
| 142 | 148 | * @return Das zur Ergebniszeile gehoerende Location-Objekt |
|---|
| 143 | | */ |
|---|
| | 149 | * @deprecated Bitte Hibernate benutzen |
|---|
| | 150 | */ |
|---|
| | 151 | @Deprecated |
|---|
| 144 | 152 | public static Location fromResult(SQLResultRow result) { |
|---|
| 145 | 153 | return new Location(result.getInt("system"), result.getInt("x"), result.getInt("y")); |
|---|
| … | … | |
| 148 | 156 | @Override |
|---|
| 149 | 157 | public boolean equals(Object obj) { |
|---|
| 150 | | if( !(obj instanceof Location) ) { |
|---|
| 151 | | return false; |
|---|
| 152 | | } |
|---|
| 153 | | Location loc = (Location)obj; |
|---|
| 154 | | if( getSystem() != loc.getSystem() ) { |
|---|
| 155 | | return false; |
|---|
| 156 | | } |
|---|
| 157 | | if( getX() != loc.getX() ) { |
|---|
| 158 | | return false; |
|---|
| 159 | | } |
|---|
| 160 | | |
|---|
| 161 | | if( getY() != loc.getY() ) { |
|---|
| | 158 | if( this == obj ) { |
|---|
| | 159 | return true; |
|---|
| | 160 | } |
|---|
| | 161 | if( (obj == null) || (obj.getClass() != getClass()) ) { |
|---|
| | 162 | return false; |
|---|
| | 163 | } |
|---|
| | 164 | |
|---|
| | 165 | final Location loc = (Location)obj; |
|---|
| | 166 | if( this.system != loc.system ) { |
|---|
| | 167 | return false; |
|---|
| | 168 | } |
|---|
| | 169 | if( this.x != loc.x ) { |
|---|
| | 170 | return false; |
|---|
| | 171 | } |
|---|
| | 172 | |
|---|
| | 173 | if( this.y != loc.y ) { |
|---|
| 162 | 174 | return false; |
|---|
| 163 | 175 | } |
|---|
| … | … | |
| 168 | 180 | public int hashCode() { |
|---|
| 169 | 181 | if( hashCode == 0 ) { |
|---|
| 170 | | hashCode = system*10000+x*100+y; |
|---|
| | 182 | hashCode = system*100000+x*1000+y; |
|---|
| 171 | 183 | } |
|---|
| 172 | 184 | |
|---|
| … | … | |
| 183 | 195 | * @return true, falls ein gemeinsamer Sektor existiert |
|---|
| 184 | 196 | */ |
|---|
| 185 | | public boolean sameSector(int ownRadius, Location object, int objectRadius) { |
|---|
| 186 | | if( getSystem() != object.getSystem() ) { |
|---|
| 187 | | return false; |
|---|
| 188 | | } |
|---|
| 189 | | |
|---|
| 190 | | if( Math.floor(Math.sqrt((getX()-object.getX())*(getX()-object.getX())+(getY()-object.getY())*(getY()-object.getY()))) > ownRadius+objectRadius ) { |
|---|
| | 197 | public boolean sameSector(int ownRadius, Locatable object, int objectRadius) { |
|---|
| | 198 | Location loc = object.getLocation(); |
|---|
| | 199 | if( this.system != loc.getSystem() ) { |
|---|
| | 200 | return false; |
|---|
| | 201 | } |
|---|
| | 202 | |
|---|
| | 203 | if( Math.floor(Math.sqrt((this.x-loc.getX())*(this.x-loc.getX())+(this.y-loc.getY())*(this.y-loc.getY()))) > ownRadius+objectRadius ) { |
|---|
| 191 | 204 | return false; |
|---|
| 192 | 205 | } |
|---|
| … | … | |
| 194 | 207 | return true; |
|---|
| 195 | 208 | } |
|---|
| | 209 | |
|---|
| | 210 | public Location getLocation() { |
|---|
| | 211 | return this; |
|---|
| | 212 | } |
|---|
| 196 | 213 | } |
|---|
| rd0533dd |
r7a698da |
|
| 20 | 20 | |
|---|
| 21 | 21 | import javax.persistence.Entity; |
|---|
| 22 | | import javax.persistence.GeneratedValue; |
|---|
| 23 | 22 | import javax.persistence.Id; |
|---|
| 24 | 23 | import javax.persistence.Table; |
|---|
| … | … | |
| 26 | 25 | import net.driftingsouls.ds2.server.Locatable; |
|---|
| 27 | 26 | import net.driftingsouls.ds2.server.Location; |
|---|
| | 27 | import net.driftingsouls.ds2.server.MutableLocation; |
|---|
| 28 | 28 | |
|---|
| | 29 | import org.hibernate.annotations.Cache; |
|---|
| | 30 | import org.hibernate.annotations.CacheConcurrencyStrategy; |
|---|
| 29 | 31 | import org.hibernate.annotations.Immutable; |
|---|
| 30 | 32 | |
|---|
| … | … | |
| 37 | 39 | @Table(name="nebel") |
|---|
| 38 | 40 | @Immutable |
|---|
| | 41 | @Cache(usage=CacheConcurrencyStrategy.READ_ONLY) |
|---|
| 39 | 42 | public class Nebel implements Locatable { |
|---|
| 40 | | @Id @GeneratedValue |
|---|
| 41 | | private int id; |
|---|
| 42 | | private int x; |
|---|
| 43 | | private int y; |
|---|
| 44 | | private int system; |
|---|
| | 43 | @Id |
|---|
| | 44 | private MutableLocation loc; |
|---|
| 45 | 45 | private int type; |
|---|
| 46 | 46 | |
|---|
| … | … | |
| 52 | 52 | // EMPTY |
|---|
| 53 | 53 | } |
|---|
| 54 | | |
|---|
| 55 | | /** |
|---|
| 56 | | * Gibt die ID des Nebels zurueck |
|---|
| 57 | | * @return Die ID |
|---|
| 58 | | */ |
|---|
| 59 | | public int getId() { |
|---|
| 60 | | return id; |
|---|
| 61 | | } |
|---|
| 62 | | |
|---|
| | 54 | |
|---|
| 63 | 55 | /** |
|---|
| 64 | 56 | * Gibt das System des Nebels zurueck |
|---|
| … | … | |
| 66 | 58 | */ |
|---|
| 67 | 59 | public int getSystem() { |
|---|
| 68 | | return system; |
|---|
| | 60 | return loc.getSystem(); |
|---|
| 69 | 61 | } |
|---|
| 70 | 62 | |
|---|
| … | … | |
| 82 | 74 | */ |
|---|
| 83 | 75 | public int getX() { |
|---|
| 84 | | return x; |
|---|
| | 76 | return loc.getX(); |
|---|
| 85 | 77 | } |
|---|
| 86 | 78 | |
|---|
| … | … | |
| 90 | 82 | */ |
|---|
| 91 | 83 | public int getY() { |
|---|
| 92 | | return y; |
|---|
| | 84 | return loc.getY(); |
|---|
| 93 | 85 | } |
|---|
| 94 | 86 | |
|---|
| … | … | |
| 98 | 90 | */ |
|---|
| 99 | 91 | public Location getLocation() { |
|---|
| 100 | | return new Location(this.system, this.x, this.y); |
|---|
| | 92 | return loc.getLocation(); |
|---|
| 101 | 93 | } |
|---|
| 102 | 94 | } |
|---|
| r958e4a8 |
r7a698da |
|
| 23 | 23 | |
|---|
| 24 | 24 | import net.driftingsouls.ds2.server.Location; |
|---|
| | 25 | import net.driftingsouls.ds2.server.MutableLocation; |
|---|
| 25 | 26 | import net.driftingsouls.ds2.server.cargo.Cargo; |
|---|
| 26 | 27 | import net.driftingsouls.ds2.server.cargo.Resources; |
|---|
| … | … | |
| 107 | 108 | } |
|---|
| 108 | 109 | else { |
|---|
| 109 | | Nebel nebel = (Nebel)db.createQuery("from Nebel where x=? and y=? and system=? and type<3") |
|---|
| 110 | | .setInteger(0, ship.getX()) |
|---|
| 111 | | .setInteger(1, ship.getY()) |
|---|
| 112 | | .setInteger(2, ship.getSystem()) |
|---|
| 113 | | .uniqueResult(); |
|---|
| | 110 | Nebel nebel = (Nebel)db.get(Nebel.class, new MutableLocation(ship)); |
|---|
| 114 | 111 | |
|---|
| 115 | | if( nebel != null ) { |
|---|
| | 112 | if( (nebel != null) && (nebel.getType() < 3) ) { |
|---|
| 116 | 113 | Cargo shipCargo = ship.getCargo(); |
|---|
| 117 | 114 | long cargo = shipCargo.getMass(); |
|---|
| r958e4a8 |
r7a698da |
|
| 19 | 19 | package net.driftingsouls.ds2.server.modules; |
|---|
| 20 | 20 | |
|---|
| | 21 | import net.driftingsouls.ds2.server.Location; |
|---|
| | 22 | import net.driftingsouls.ds2.server.MutableLocation; |
|---|
| 21 | 23 | import net.driftingsouls.ds2.server.cargo.Cargo; |
|---|
| 22 | 24 | import net.driftingsouls.ds2.server.cargo.Resources; |
|---|
| … | … | |
| 32 | 34 | |
|---|
| 33 | 35 | /** |
|---|
| 34 | | * Sammelt mit einem Tanker in einem angegebenen Nebel Deuterium. |
|---|
| | 36 | * Sammelt mit einem Tanker in einem Nebel Deuterium. |
|---|
| 35 | 37 | * |
|---|
| 36 | 38 | * @author Christopher Jung |
|---|
| 37 | 39 | * @urlparam Integer ship Die ID des Tankers |
|---|
| 38 | | * @urlparam Integer nebel Die ID des Nebels |
|---|
| 39 | 40 | */ |
|---|
| 40 | 41 | public class DeutSammelnController extends DSGenerator { |
|---|
| … | … | |
| 53 | 54 | |
|---|
| 54 | 55 | parameterNumber("ship"); |
|---|
| 55 | | parameterNumber("nebel"); |
|---|
| 56 | 56 | } |
|---|
| 57 | 57 | |
|---|
| … | … | |
| 62 | 62 | |
|---|
| 63 | 63 | int shipID = getInteger("ship"); |
|---|
| 64 | | int nebelID = getInteger("nebel"); |
|---|
| 65 | 64 | |
|---|
| 66 | 65 | Ship ship = (Ship)db.get(Ship.class, shipID); |
|---|
| … | … | |
| 73 | 72 | ShipTypeData shiptype = ship.getTypeData(); |
|---|
| 74 | 73 | |
|---|
| 75 | | Nebel nebel = (Nebel)db.get(Nebel.class, nebelID); |
|---|
| | 74 | Nebel nebel = (Nebel)db.get(Nebel.class, new MutableLocation(ship)); |
|---|
| 76 | 75 | |
|---|
| 77 | 76 | String errorurl = Common.buildUrl(getContext(), "default", "module", "schiff", "ship", shipID); |
|---|
| 78 | 77 | |
|---|
| 79 | | if( !nebel.getLocation().sameSector(0, ship.getLocation(), 0) ) { |
|---|
| | 78 | if( !nebel.getLocation().sameSector(0, ship, 0) ) { |
|---|
| 80 | 79 | addError("Der Nebel befindet sich nicht im selben Sektor wie das Schiff", errorurl ); |
|---|
| 81 | 80 | |
|---|
| … | … | |
| 174 | 173 | |
|---|
| 175 | 174 | t.set_var( "deuterium.image", Cargo.getResourceImage(Resources.DEUTERIUM), |
|---|
| 176 | | "nebel.id", nebel.getId(), |
|---|
| 177 | 175 | "ship.type.deutfactor", deutfactor, |
|---|
| 178 | 176 | "ship.id", ship.getId(), |
|---|
| r283e6c7 |
r7a698da |
|
| 234 | 234 | } |
|---|
| 235 | 235 | |
|---|
| 236 | | SQLResultRow nebel = db.first("SELECT id,type FROM nebel WHERE system=",this.system," AND x=",x," AND y=",y); |
|---|
| | 236 | SQLResultRow nebel = db.first("SELECT * FROM nebel WHERE system=",this.system," AND x=",x," AND y=",y); |
|---|
| 237 | 237 | |
|---|
| 238 | 238 | // EMP-Nebel? |
|---|
| … | … | |
| 297 | 297 | |
|---|
| 298 | 298 | // Nebel? |
|---|
| 299 | | nebel = db.first("SELECT id FROM nebel WHERE system=",this.system," AND x=",scanner.getInt("x")," AND y=",scanner.getInt("y")); |
|---|
| | 299 | nebel = db.first("SELECT * FROM nebel WHERE system=",this.system," AND x=",scanner.getInt("x")," AND y=",scanner.getInt("y")); |
|---|
| 300 | 300 | if( !nebel.isEmpty() ) { |
|---|
| 301 | 301 | range = (int)Math.round(range/2d); |
|---|
| … | … | |
| 438 | 438 | "FROM nebel " + |
|---|
| 439 | 439 | "WHERE system=",this.system," AND (x BETWEEN 1 AND ",sys.getWidth(),") AND (y BETWEEN 1 AND ",sys.getHeight(),") " + |
|---|
| 440 | | "ORDER BY id"); |
|---|
| | 440 | "ORDER BY system,x,y"); |
|---|
| 441 | 441 | while( nebel.next() ) { |
|---|
| 442 | 442 | int neb = 0; |
|---|
| rd0533dd |
r7a698da |
|
| 574 | 574 | } |
|---|
| 575 | 575 | |
|---|
| 576 | | Nebel nebel = (Nebel)getDB().createQuery("from Nebel where system=? and type<3 order by sqrt((?-x)*(?-x)+(?-y)*(?-y))*((type+1)%3)*3") |
|---|
| | 576 | Nebel nebel = (Nebel)getDB().createQuery("from Nebel where loc.system=? and type<3 order by sqrt((?-loc.x)*(?-loc.x)+(?-loc.y)*(?-loc.y))*((type+1)%3)*3") |
|---|
| 577 | 577 | .setInteger(0, system) |
|---|
| 578 | 578 | .setInteger(1, orderloc.getX()) |
|---|
| r283e6c7 |
r7a698da |
|
| 90 | 90 | |
|---|
| 91 | 91 | // Sollte das Schiff in einem Nebel stehen -> halbe Scannerreichweite |
|---|
| 92 | | SQLResultRow nebel = db.first("SELECT id,type FROM nebel WHERE x=",ship.getInt("x")," AND y=",ship.getInt("y")," AND system=",ship.getInt("system")); |
|---|
| | 92 | SQLResultRow nebel = db.first("SELECT * FROM nebel WHERE x=",ship.getInt("x")," AND y=",ship.getInt("y")," AND system=",ship.getInt("system")); |
|---|
| 93 | 93 | if( !nebel.isEmpty() ) { |
|---|
| 94 | 94 | switch( nebel.getInt("type") ) { |
|---|
| … | … | |
| 186 | 186 | boolean scanableNebel = false; |
|---|
| 187 | 187 | |
|---|
| 188 | | SQLResultRow nebel = db.first("SELECT id,type FROM nebel WHERE x=",scanx," AND y=",scany," AND system="+system); |
|---|
| | 188 | SQLResultRow nebel = db.first("SELECT * FROM nebel WHERE x=",scanx," AND y=",scany," AND system="+system); |
|---|
| 189 | 189 | if( !this.admin && !nebel.isEmpty() && ((nebel.getInt("type") < 3) || (nebel.getInt("type") > 5)) ) { |
|---|
| 190 | 190 | SQLQuery nebelship = db.query("SELECT id,status,type,sensors,crew FROM ships WHERE id>0 AND x=",scanx," AND y=",scany," AND system=",system," AND owner=",user.getID()," AND sensors > 30"); |
|---|
| … | … | |
| 209 | 209 | if( !nebel.isEmpty() && !scanableNebel ) { |
|---|
| 210 | 210 | t.set_var( "sector.nebel", 1, |
|---|
| 211 | | "sector.nebel.id", nebel.getInt("id"), |
|---|
| 212 | 211 | "sector.nebel.type", nebel.getInt("type") ); |
|---|
| 213 | 212 | } |
|---|
| … | … | |
| 215 | 214 | if( !nebel.isEmpty() ) { |
|---|
| 216 | 215 | t.set_var( "sector.nebel", 1, |
|---|
| 217 | | "sector.nebel.id", nebel.getInt("id"), |
|---|
| 218 | 216 | "sector.nebel.type", nebel.getInt("type") ); |
|---|
| 219 | 217 | } |
|---|
| … | … | |
| 407 | 405 | Map<Location,Integer> nebelmap = new HashMap<Location,Integer>(); |
|---|
| 408 | 406 | |
|---|
| 409 | | SQLQuery nebelRow = db.query("SELECT id,x,y,type FROM nebel WHERE ",rangesql); |
|---|
| | 407 | SQLQuery nebelRow = db.query("SELECT x,y,type FROM nebel WHERE ",rangesql); |
|---|
| 410 | 408 | while( nebelRow.next() ) { |
|---|
| 411 | 409 | nebelmap.put(new Location(ship.getInt("system"), nebelRow.getInt("x"), nebelRow.getInt("y")), nebelRow.getInt("type")); |
|---|
| r626f5ca |
r7a698da |
|
| 638 | 638 | SQLResultRow nebel = db.first("SELECT * FROM nebel WHERE x="+x+" AND y="+y+" AND system="+system); |
|---|
| 639 | 639 | if( !nebel.isEmpty() ) { |
|---|
| 640 | | db.update("DELETE FROM nebel WHERE id="+nebel.getInt("id")); |
|---|
| | 640 | db.update("DELETE FROM nebel WHERE system="+nebel.getInt("system")+" AND x="+nebel.getInt("x")+" AND y="+nebel.getInt("y")); |
|---|
| 641 | 641 | } |
|---|
| 642 | 642 | db.update("INSERT INTO nebel (x,y,system,type) " + |
|---|
| r99f4983 |
r7a698da |
|
| 249 | 249 | } |
|---|
| 250 | 250 | |
|---|
| 251 | | List nebellist = db.createQuery("from Nebel where system=? and (x between ? and ?) and (y between ? and ?)") |
|---|
| | 251 | List nebellist = db.createQuery("from Nebel where loc.system=? and (loc.x between ? and ?) and (loc.y between ? and ?)") |
|---|
| 252 | 252 | .setInteger(0, sys) |
|---|
| 253 | 253 | .setInteger(1, x-1) |
|---|
| rfda8be0 |
r7a698da |
|
| 25 | 25 | import java.util.Map; |
|---|
| 26 | 26 | |
|---|
| | 27 | import net.driftingsouls.ds2.server.MutableLocation; |
|---|
| 27 | 28 | import net.driftingsouls.ds2.server.Offizier; |
|---|
| 28 | 29 | import net.driftingsouls.ds2.server.bases.Base; |
|---|
| … | … | |
| 38 | 39 | import net.driftingsouls.ds2.server.framework.db.Database; |
|---|
| 39 | 40 | import net.driftingsouls.ds2.server.framework.db.SQLQuery; |
|---|
| 40 | | import net.driftingsouls.ds2.server.framework.db.SQLResultRow; |
|---|
| 41 | 41 | import net.driftingsouls.ds2.server.framework.templates.TemplateEngine; |
|---|
| 42 | 42 | import net.driftingsouls.ds2.server.modules.SchiffController; |
|---|
| … | … | |
| 227 | 227 | */ |
|---|
| 228 | 228 | |
|---|
| 229 | | Nebel nebel = (Nebel)db.createQuery("from Nebel where x=? and y=? and system=?") |
|---|
| 230 | | .setInteger(0, ship.getX()) |
|---|
| 231 | | .setInteger(1, ship.getY()) |
|---|
| 232 | | .setInteger(2, ship.getSystem()) |
|---|
| 233 | | .uniqueResult(); |
|---|
| 234 | | |
|---|
| | 229 | Nebel nebel = (Nebel)db.get(Nebel.class, new MutableLocation(ship)); |
|---|
| 235 | 230 | if( nebel != null ) { |
|---|
| 236 | | t.set_var( "nebel.id", nebel.getId(), |
|---|
| | 231 | t.set_var( "nebel", true, |
|---|
| 237 | 232 | "nebel.type", nebel.getType(), |
|---|
| 238 | 233 | "global.ship.deutfactor", (shiptype.getDeutFactor() != 0 && (nebel.getType() < 3) )); |
|---|
| radac94a |
r7a698da |
|
| 2139 | 2139 | SQLResultRow nebel = db.first("SELECT id FROM nebel WHERE "+locSQL); |
|---|
| 2140 | 2140 | if( !nebel.isEmpty() ) { |
|---|
| 2141 | | result.add(Integer.toString(nebel.getInt("id"))); |
|---|
| | 2141 | result.add(Location.fromResult(nebel).toString()); |
|---|
| 2142 | 2142 | } |
|---|
| 2143 | 2143 | } |
|---|
| r15c854d |
r7a698da |
|
| 19 | 19 | package net.driftingsouls.ds2.server.ships; |
|---|
| 20 | 20 | |
|---|
| | 21 | import java.util.HashMap; |
|---|
| | 22 | import java.util.Map; |
|---|
| | 23 | |
|---|
| 21 | 24 | import net.driftingsouls.ds2.server.Location; |
|---|
| | 25 | import net.driftingsouls.ds2.server.MutableLocation; |
|---|
| 22 | 26 | import net.driftingsouls.ds2.server.entities.Nebel; |
|---|
| | 27 | import net.driftingsouls.ds2.server.framework.Context; |
|---|
| 23 | 28 | import net.driftingsouls.ds2.server.framework.ContextMap; |
|---|
| 24 | 29 | import net.driftingsouls.ds2.server.framework.Loggable; |
|---|
| … | … | |
| 123 | 128 | * @return Der Nebeltyp oder <code>-1</code> |
|---|
| 124 | 129 | */ |
|---|
| | 130 | @SuppressWarnings("unchecked") |
|---|
| 125 | 131 | public static synchronized int getNebula(Location loc) { |
|---|
| 126 | | org.hibernate.Session db = ContextMap.getContext().getDB(); |
|---|
| 127 | | Nebel nebel = (Nebel)db.createQuery("from Nebel where system=? and x=? and y=?") |
|---|
| 128 | | .setInteger(0, loc.getSystem()) |
|---|
| 129 | | .setInteger(1, loc.getX()) |
|---|
| 130 | | .setInteger(2, loc.getY()) |
|---|
| 131 | | .uniqueResult(); |
|---|
| | 132 | Context context = ContextMap.getContext(); |
|---|
| | 133 | org.hibernate.Session db = context.getDB(); |
|---|
| 132 | 134 | |
|---|
| 133 | | if( nebel == null ) { |
|---|
| 134 | | return 0; |
|---|
| | 135 | // Hibernate cachet nur Ergebnisse, die nicht leer waren. |
|---|
| | 136 | // Da es jedoch viele Positionen ohne Nebel gibt wuerden viele Abfragen |
|---|
| | 137 | // mehrfach durchgefuehrt. Daher wird in der Session vermerkt, welche |
|---|
| | 138 | // Positionen bereits geprueft wurden |
|---|
| | 139 | |
|---|
| | 140 | Map map = (Map)context.getVariable(Ships.class, "getNebula(Location)#Nebel"); |
|---|
| | 141 | if( map == null ) { |
|---|
| | 142 | map = new HashMap(); |
|---|
| | 143 | context.putVariable(Ships.class, "getNebula(Location)#Nebel", map); |
|---|
| | 144 | } |
|---|
| | 145 | if( !map.containsKey(loc) ) { |
|---|
| | 146 | Nebel nebel = (Nebel)db.get(Nebel.class, new MutableLocation(loc)); |
|---|
| | 147 | if( nebel == null ) { |
|---|
| | 148 | map.put(loc, Boolean.FALSE); |
|---|
| | 149 | return 0; |
|---|
| | 150 | } |
|---|
| | 151 | |
|---|
| | 152 | map.put(loc, Boolean.TRUE); |
|---|
| | 153 | return nebel.getType(); |
|---|
| 135 | 154 | } |
|---|
| 136 | 155 | |
|---|
| 137 | | return nebel.getType(); |
|---|
| | 156 | Boolean val = (Boolean)map.get(loc); |
|---|
| | 157 | if( val == Boolean.TRUE ) { |
|---|
| | 158 | Nebel nebel = (Nebel)db.get(Nebel.class, new MutableLocation(loc)); |
|---|
| | 159 | return nebel.getType(); |
|---|
| | 160 | } |
|---|
| | 161 | |
|---|
| | 162 | return 0; |
|---|
| 138 | 163 | } |
|---|
| 139 | 164 | } |
|---|
| r37b7a55 |
r7a698da |
|
| 485 | 485 | this.log("Behandle Schadensnebel"); |
|---|
| 486 | 486 | ships = db.createQuery("select s from Ship as s, Nebel as n " + |
|---|
| 487 | | "where s.system=n.system and s.x=n.x and s.y=n.y and n.type=6 and (s.owner.vaccount=0 or s.owner.wait4vac>0)").list(); |
|---|
| | 487 | "where s.system=n.loc.system and s.x=n.loc.x and s.y=n.loc.y and n.type=6 and (s.owner.vaccount=0 or s.owner.wait4vac>0)").list(); |
|---|
| 488 | 488 | for( Iterator iter=ships.iterator(); iter.hasNext(); ) { |
|---|
| 489 | 489 | Ship ship = (Ship)iter.next(); |
|---|
| r3924571 |
r7a698da |
|
| 12 | 12 | <form action="./ds" method="post"> |
|---|
| 13 | 13 | Aufzuwendende Energie: <input name="e" type="text" size="3" value="{ship.e}" /> |
|---|
| 14 | | {!form_create_hidden sammeln, ship:$ship.id, nebel:$nebel.id} |
|---|
| | 14 | {!form_create_hidden sammeln, ship:$ship.id} |
|---|
| 15 | 15 | <input type="submit" value="Sammeln" /> |
|---|
| 16 | 16 | </form><br /> |
|---|
| r3924571 |
r7a698da |
|
| 13 | 13 | {if sector.nebel} |
|---|
| 14 | 14 | <tr> |
|---|
| 15 | | <td class="show2"><span class="smallfont">{sector.nebel.id}</span></td> |
|---|
| | 15 | <td class="show2"></td> |
|---|
| 16 | 16 | <td class="show2"> </td> |
|---|
| 17 | 17 | <td class="show2"> </td> |
|---|
| r3924571 |
r7a698da |
|
| 88 | 88 | |
|---|
| 89 | 89 | {if global.goodscan} |
|---|
| 90 | | {if nebel.id} |
|---|
| 91 | | <tr> |
|---|
| 92 | | <td class="show2"><span class="smallfont">{nebel.id}</span></td> |
|---|
| | 90 | {if nebel} |
|---|
| | 91 | <tr> |
|---|
| | 92 | <td class="show2"></td> |
|---|
| 93 | 93 | <td class="show2" style="width:150px"> </td> |
|---|
| 94 | 94 | <td class="show2"> </td> |
|---|
| … | … | |
| 98 | 98 | <td class="show2"> |
|---|
| 99 | 99 | {if global.ship.deutfactor} |
|---|
| 100 | | <a class="greenborder" onmouseover="return helpme('Deuterium sammeln');" onmouseout="return nd();" href="./ds?module=deutsammeln&sess={global.sess}&nebel={nebel.id}&ship={global.ship}"><img src="{URL}data/interface/schiffe/schiff_deutsammeln.gif" alt="" /></a> |
|---|
| | 100 | <a class="greenborder" onmouseover="return helpme('Deuterium sammeln');" onmouseout="return nd();" href="./ds?module=deutsammeln&sess={global.sess}&ship={global.ship}"><img src="{URL}data/interface/schiffe/schiff_deutsammeln.gif" alt="" /></a> |
|---|
| 101 | 101 | {/endif} |
|---|
| 102 | 102 | </td> |
|---|