Changeset 7a698dad95e80782edc96d6337ae617f53930aa7

Show
Ignore:
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
  • db/tables/nebel.sql

    r425acaa r7a698da  
    11CREATE TABLE `nebel` ( 
    2   `id` int(11) NOT NULL auto_increment, 
    32  `x` int(11) NOT NULL default '0', 
    43  `y` int(11) NOT NULL default '0', 
    54  `system` int(11) NOT NULL default '0', 
    65  `type` tinyint(3) unsigned NOT NULL default '0', 
    7   PRIMARY KEY  (`id`), 
    8   KEY `coords` (`x`,`y`,`system`) 
     6  PRIMARY KEY  (`system`,`x`,`y`) 
    97) ENGINE=InnoDB DEFAULT CHARSET=utf8;  
  • db/updates.xml

    ree28f5d r7a698da  
    326326                ALTER TABLE `werft_queues` ADD COLUMN energyPerTick int NOT NULL default '0'; 
    327327        ]]></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> 
    328333</updates> 
  • src/ehcache.xml

    r8721cca r7a698da  
    1616                        overflowToDisk="false" 
    1717        /> 
     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        /> 
    1825</ehcache> 
  • src/net/driftingsouls/ds2/server/Location.java

    rd54fd1c r7a698da  
    1919package net.driftingsouls.ds2.server; 
    2020 
     21import java.io.Serializable; 
     22 
    2123import net.driftingsouls.ds2.server.framework.db.SQLResultRow; 
    2224 
     
    2628 * 
    2729 */ 
    28 public class Location { 
    29         private int x = 0; 
    30         private int y = 0; 
    31         private int system = 0; 
    32         private int hashCode = 0; 
     30public 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; 
    3337         
    3438        /** 
     
    3741         */ 
    3842        public Location() { 
    39                 // EMPTY 
     43                this.x = 0; 
     44                this.y = 0; 
     45                this.system = 0; 
    4046        } 
    4147 
     
    141147         * @param result Die SQL-Ergebniszeile 
    142148         * @return Das zur Ergebniszeile gehoerende Location-Objekt 
    143          */ 
     149         * @deprecated Bitte Hibernate benutzen 
     150         */ 
     151        @Deprecated 
    144152        public static Location fromResult(SQLResultRow result) { 
    145153                return new Location(result.getInt("system"), result.getInt("x"), result.getInt("y")); 
     
    148156        @Override 
    149157        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 ) { 
    162174                        return false; 
    163175                } 
     
    168180        public int hashCode() { 
    169181                if( hashCode == 0 ) { 
    170                         hashCode = system*10000+x*100+y; 
     182                        hashCode = system*100000+x*1000+y; 
    171183                } 
    172184                 
     
    183195         * @return true, falls ein gemeinsamer Sektor existiert 
    184196         */ 
    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 ) { 
    191204                        return false; 
    192205                } 
     
    194207                return true; 
    195208        } 
     209 
     210        public Location getLocation() { 
     211                return this; 
     212        } 
    196213} 
  • src/net/driftingsouls/ds2/server/entities/Nebel.java

    rd0533dd r7a698da  
    2020 
    2121import javax.persistence.Entity; 
    22 import javax.persistence.GeneratedValue; 
    2322import javax.persistence.Id; 
    2423import javax.persistence.Table; 
     
    2625import net.driftingsouls.ds2.server.Locatable; 
    2726import net.driftingsouls.ds2.server.Location; 
     27import net.driftingsouls.ds2.server.MutableLocation; 
    2828 
     29import org.hibernate.annotations.Cache; 
     30import org.hibernate.annotations.CacheConcurrencyStrategy; 
    2931import org.hibernate.annotations.Immutable; 
    3032 
     
    3739@Table(name="nebel") 
    3840@Immutable 
     41@Cache(usage=CacheConcurrencyStrategy.READ_ONLY) 
    3942public 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; 
    4545        private int type; 
    4646         
     
    5252                // EMPTY 
    5353        } 
    54          
    55         /** 
    56          * Gibt die ID des Nebels zurueck 
    57          * @return Die ID 
    58          */ 
    59         public int getId() { 
    60                 return id; 
    61         } 
    62          
     54                 
    6355        /** 
    6456         * Gibt das System des Nebels zurueck 
     
    6658         */ 
    6759        public int getSystem() { 
    68                 return system
     60                return loc.getSystem()
    6961        } 
    7062         
     
    8274         */ 
    8375        public int getX() { 
    84                 return x
     76                return loc.getX()
    8577        } 
    8678         
     
    9082         */ 
    9183        public int getY() { 
    92                 return y
     84                return loc.getY()
    9385        } 
    9486         
     
    9890         */ 
    9991        public Location getLocation() { 
    100                 return new Location(this.system, this.x, this.y); 
     92                return loc.getLocation(); 
    10193        } 
    10294} 
  • src/net/driftingsouls/ds2/server/modules/DeutAllController.java

    r958e4a8 r7a698da  
    2323 
    2424import net.driftingsouls.ds2.server.Location; 
     25import net.driftingsouls.ds2.server.MutableLocation; 
    2526import net.driftingsouls.ds2.server.cargo.Cargo; 
    2627import net.driftingsouls.ds2.server.cargo.Resources; 
     
    107108                        } 
    108109                        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)); 
    114111 
    115                                 if( nebel != null ) { 
     112                                if( (nebel != null) && (nebel.getType() < 3) ) { 
    116113                                        Cargo shipCargo = ship.getCargo(); 
    117114                                        long cargo = shipCargo.getMass(); 
  • src/net/driftingsouls/ds2/server/modules/DeutSammelnController.java

    r958e4a8 r7a698da  
    1919package net.driftingsouls.ds2.server.modules; 
    2020 
     21import net.driftingsouls.ds2.server.Location; 
     22import net.driftingsouls.ds2.server.MutableLocation; 
    2123import net.driftingsouls.ds2.server.cargo.Cargo; 
    2224import net.driftingsouls.ds2.server.cargo.Resources; 
     
    3234 
    3335/** 
    34  * Sammelt mit einem Tanker in einem angegebenen Nebel Deuterium. 
     36 * Sammelt mit einem Tanker in einem Nebel Deuterium. 
    3537 *  
    3638 * @author Christopher Jung 
    3739 * @urlparam Integer ship Die ID des Tankers 
    38  * @urlparam Integer nebel Die ID des Nebels 
    3940 */ 
    4041public class DeutSammelnController extends DSGenerator { 
     
    5354                 
    5455                parameterNumber("ship"); 
    55                 parameterNumber("nebel"); 
    5656        } 
    5757         
     
    6262 
    6363                int shipID = getInteger("ship"); 
    64                 int nebelID = getInteger("nebel"); 
    6564                 
    6665                Ship ship = (Ship)db.get(Ship.class, shipID); 
     
    7372                ShipTypeData shiptype = ship.getTypeData(); 
    7473 
    75                 Nebel nebel = (Nebel)db.get(Nebel.class, nebelID); 
     74                Nebel nebel = (Nebel)db.get(Nebel.class, new MutableLocation(ship)); 
    7675 
    7776                String errorurl = Common.buildUrl(getContext(), "default", "module", "schiff", "ship", shipID); 
    7877 
    79                 if( !nebel.getLocation().sameSector(0, ship.getLocation(), 0) ) { 
     78                if( !nebel.getLocation().sameSector(0, ship, 0) ) { 
    8079                        addError("Der Nebel befindet sich nicht im selben Sektor wie das Schiff", errorurl ); 
    8180                         
     
    174173                 
    175174                t.set_var(      "deuterium.image",              Cargo.getResourceImage(Resources.DEUTERIUM), 
    176                                         "nebel.id",                             nebel.getId(), 
    177175                                        "ship.type.deutfactor", deutfactor, 
    178176                                        "ship.id",                              ship.getId(), 
  • src/net/driftingsouls/ds2/server/modules/MapDataController.java

    r283e6c7 r7a698da  
    234234                } 
    235235                 
    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); 
    237237                 
    238238                // EMP-Nebel? 
     
    297297                                         
    298298                                // 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")); 
    300300                                if( !nebel.isEmpty() ) { 
    301301                                        range = (int)Math.round(range/2d);       
     
    438438                                "FROM nebel " + 
    439439                                "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"); 
    441441                while( nebel.next() ) { 
    442442                        int neb = 0; 
  • src/net/driftingsouls/ds2/server/modules/PortalController.java

    rd0533dd r7a698da  
    574574                } 
    575575                 
    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") 
    577577                        .setInteger(0, system) 
    578578                        .setInteger(1, orderloc.getX()) 
  • src/net/driftingsouls/ds2/server/modules/ScanController.java

    r283e6c7 r7a698da  
    9090         
    9191                        // 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")); 
    9393                        if( !nebel.isEmpty() ) { 
    9494                                switch( nebel.getInt("type") ) { 
     
    186186                boolean scanableNebel = false; 
    187187         
    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); 
    189189                if( !this.admin && !nebel.isEmpty() && ((nebel.getInt("type") < 3) || (nebel.getInt("type") > 5)) ) { 
    190190                        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"); 
     
    209209                if( !nebel.isEmpty() && !scanableNebel ) { 
    210210                        t.set_var(      "sector.nebel",                 1, 
    211                                                 "sector.nebel.id",              nebel.getInt("id"), 
    212211                                                "sector.nebel.type",    nebel.getInt("type") ); 
    213212                } 
     
    215214                        if( !nebel.isEmpty() ) { 
    216215                                t.set_var(      "sector.nebel",                 1, 
    217                                                         "sector.nebel.id",              nebel.getInt("id"), 
    218216                                                        "sector.nebel.type",    nebel.getInt("type") ); 
    219217                        } 
     
    407405                Map<Location,Integer> nebelmap = new HashMap<Location,Integer>(); 
    408406 
    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); 
    410408                while( nebelRow.next() ) { 
    411409                        nebelmap.put(new Location(ship.getInt("system"), nebelRow.getInt("x"), nebelRow.getInt("y")), nebelRow.getInt("type")); 
  • src/net/driftingsouls/ds2/server/modules/admin/CreateObjects.java

    r626f5ca r7a698da  
    638638                SQLResultRow nebel = db.first("SELECT * FROM nebel WHERE x="+x+" AND y="+y+" AND system="+system); 
    639639                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")); 
    641641                } 
    642642                db.update("INSERT INTO nebel (x,y,system,type) " + 
  • src/net/driftingsouls/ds2/server/modules/schiffplugins/NavigationDefault.java

    r99f4983 r7a698da  
    249249                        } 
    250250                         
    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 ?)") 
    252252                                .setInteger(0, sys) 
    253253                                .setInteger(1, x-1) 
  • src/net/driftingsouls/ds2/server/modules/schiffplugins/SensorsDefault.java

    rfda8be0 r7a698da  
    2525import java.util.Map; 
    2626 
     27import net.driftingsouls.ds2.server.MutableLocation; 
    2728import net.driftingsouls.ds2.server.Offizier; 
    2829import net.driftingsouls.ds2.server.bases.Base; 
     
    3839import net.driftingsouls.ds2.server.framework.db.Database; 
    3940import net.driftingsouls.ds2.server.framework.db.SQLQuery; 
    40 import net.driftingsouls.ds2.server.framework.db.SQLResultRow; 
    4141import net.driftingsouls.ds2.server.framework.templates.TemplateEngine; 
    4242import net.driftingsouls.ds2.server.modules.SchiffController; 
     
    227227                        */ 
    228228 
    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)); 
    235230                        if( nebel != null ) { 
    236                                 t.set_var(      "nebel.id",            nebel.getId()
     231                                t.set_var(      "nebel",       true
    237232                                                        "nebel.type",   nebel.getType(), 
    238233                                                        "global.ship.deutfactor", (shiptype.getDeutFactor() != 0 && (nebel.getType() < 3) )); 
  • src/net/driftingsouls/ds2/server/scripting/QuestFunctions.java

    radac94a r7a698da  
    21392139                                SQLResultRow nebel = db.first("SELECT id FROM nebel WHERE "+locSQL); 
    21402140                                if( !nebel.isEmpty() ) { 
    2141                                         result.add(Integer.toString(nebel.getInt("id"))); 
     2141                                        result.add(Location.fromResult(nebel).toString()); 
    21422142                                } 
    21432143                        }  
  • src/net/driftingsouls/ds2/server/ships/Ships.java

    r15c854d r7a698da  
    1919package net.driftingsouls.ds2.server.ships; 
    2020 
     21import java.util.HashMap; 
     22import java.util.Map; 
     23 
    2124import net.driftingsouls.ds2.server.Location; 
     25import net.driftingsouls.ds2.server.MutableLocation; 
    2226import net.driftingsouls.ds2.server.entities.Nebel; 
     27import net.driftingsouls.ds2.server.framework.Context; 
    2328import net.driftingsouls.ds2.server.framework.ContextMap; 
    2429import net.driftingsouls.ds2.server.framework.Loggable; 
     
    123128         * @return Der Nebeltyp oder <code>-1</code> 
    124129         */ 
     130        @SuppressWarnings("unchecked") 
    125131        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(); 
    132134                 
    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();          
    135154                } 
    136155                 
    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; 
    138163        } 
    139164} 
  • src/net/driftingsouls/ds2/server/tick/regular/SchiffsTick.java

    r37b7a55 r7a698da  
    485485                this.log("Behandle Schadensnebel"); 
    486486                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(); 
    488488                for( Iterator iter=ships.iterator(); iter.hasNext(); ) { 
    489489                        Ship ship = (Ship)iter.next(); 
  • templates/deutsammeln.html

    r3924571 r7a698da  
    1212        <form action="./ds" method="post"> 
    1313                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
    1515                <input type="submit" value="Sammeln" /> 
    1616        </form><br /> 
  • templates/scan.html

    r3924571 r7a698da  
    1313                {if sector.nebel} 
    1414                        <tr> 
    15                                 <td class="show2"><span class="smallfont">{sector.nebel.id}</span></td> 
     15                                <td class="show2"></td> 
    1616                                <td class="show2">&nbsp;</td> 
    1717                                <td class="show2">&nbsp;</td> 
  • templates/schiff.sensors.default.html

    r3924571 r7a698da  
    8888 
    8989{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> 
    9393                        <td class="show2" style="width:150px">&nbsp;</td> 
    9494                        <td class="show2">&nbsp;</td> 
     
    9898                        <td class="show2"> 
    9999                                {if global.ship.deutfactor} 
    100                                         <a class="greenborder" onmouseover="return helpme('Deuterium sammeln');" onmouseout="return nd();" href="./ds?module=deutsammeln&amp;sess={global.sess}&amp;nebel={nebel.id}&amp;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&amp;sess={global.sess}&amp;ship={global.ship}"><img src="{URL}data/interface/schiffe/schiff_deutsammeln.gif" alt="" /></a> 
    101101                                {/endif} 
    102102                        </td>