Changeset 89d279c3cd5e9c1635b8bae910ca1a9365cba062

Show
Ignore:
Timestamp:
07/11/07 16:20:16 (1 year ago)
Author:
Christopher Jung <bktheg@web.de>
git-committer:
Christopher Jung <bktheg@web.de> 1184163616 +0200
git-parent:

[bed664f93253d22a033cf37799f8f79ef26bbcec]

git-author:
Christopher Jung <bktheg@web.de> 1184163616 +0200
Message:

Zweiter Teil Werftslots (Unterstuetzung fuer Bauschlangen)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • db/tables/werft_queues.sql

    r07a80e0 r89d279c  
    88  `costsPerTick` varchar(300) NOT NULL default '0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,', 
    99  `energyPerTick` int NOT NULL default '0', 
     10  `slots` INT NOT NULL DEFAULT '1', 
     11  `scheduled` TINYINT( 1 ) NOT NULL DEFAULT '0', 
    1012  PRIMARY KEY  (`werft`,`position`) 
    1113) ENGINE=InnoDB DEFAULT CHARSET=utf8; 
  • db/updates.xml

    rbed664f r89d279c  
    342342                -- Schiffe, welche Module mit Werfteffekt haben, beduerfen fuer eine korrekte Funktion ein Aus- und Wiedereinbau des Moduls 
    343343        ]]></update> 
     344        <update type="structure" datum="2007-07-11"><![CDATA[ 
     345                ALTER TABLE `werft_queues` ADD `slots` INT NOT NULL DEFAULT '1', 
     346                        ADD `scheduled` TINYINT( 1 ) NOT NULL DEFAULT '0'; 
     347        ]]></update> 
    344348</updates> 
  • src/net/driftingsouls/ds2/server/bases/Werft.java

    rd230b2f r89d279c  
    2222import javax.persistence.Entity; 
    2323 
    24 import net.driftingsouls.ds2.server.config.Items; 
    2524import net.driftingsouls.ds2.server.framework.Common; 
    2625import net.driftingsouls.ds2.server.framework.Configuration; 
     
    2827import net.driftingsouls.ds2.server.framework.ContextMap; 
    2928import net.driftingsouls.ds2.server.framework.templates.TemplateEngine; 
    30 import net.driftingsouls.ds2.server.ships.ShipTypeData; 
    3129import net.driftingsouls.ds2.server.werften.BaseWerft; 
    3230import net.driftingsouls.ds2.server.werften.WerftGUI; 
     31import net.driftingsouls.ds2.server.werften.WerftQueueEntry; 
    3332 
    3433import org.apache.commons.lang.StringEscapeUtils; 
     
    102101                        }  
    103102                        else { 
    104                                 ShipTypeData type = werft.getBuildShipType(); 
    105          
    106                                 StringBuilder popup = new StringBuilder(200); 
    107                                 popup.append(Common.tableBegin(420, "left").replace('"', '\'')); 
    108                                 popup.append("<img align='left' border='0' src='"); 
    109                                 popup.append(type.getPicture()); 
    110                                 popup.append("' alt='"); 
    111                                 popup.append(type.getNickname()); 
    112                                 popup.append("' />"); 
    113                                 popup.append("&nbsp;Baut: "); 
    114                                 popup.append(type.getNickname()); 
    115                                 popup.append("<br />"); 
    116                                 popup.append("&nbsp;Dauer: <img style='vertical-align:middle' src='"); 
    117                                 popup.append(Configuration.getSetting("URL")); 
    118                                 popup.append("data/interface/time.gif' alt='noch ' />"); 
    119                                 popup.append(werft.getRemainingTime()); 
    120                                 popup.append("<br />"); 
    121                                 if( werft.getRequiredItem() != -1 ) { 
    122                                          
    123                                         popup.append("&nbsp;Ben&ouml;tigt: "); 
    124                                         popup.append("<img style='vertical-align:middle' src='"); 
    125                                         popup.append("../data/items/"); 
    126                                         popup.append(Items.get().item(werft.getRequiredItem()).getPicture()); 
    127                                         popup.append("' alt='' />"); 
    128                                         if( werft.isBuildContPossible() ) { 
    129                                                 popup.append("<span style='color:green'>"); 
     103                                final WerftQueueEntry[] entries = werft.getBuildQueue(); 
     104                                final int totalSlots = werft.getWerftSlots(); 
     105                                int usedSlots = 0; 
     106                                int buildingCount = 0; 
     107                                for( int i=0; i < entries.length; i++ ) { 
     108                                        usedSlots += entries[i].getSlots(); 
     109                                        if( entries[i].isScheduled() ) { 
     110                                                buildingCount++; 
    130111                                        } 
    131                                         else { 
    132                                                 popup.append("<span style='color:red'>"); 
    133                                         } 
    134                                         popup.append(Items.get().item(werft.getRequiredItem()).getName()); 
    135                                         popup.append("</span>"); 
    136112                                } 
    137                                 popup.append(Common.tableEnd().replace('"', '\'')); 
    138                                 String popupStr = StringEscapeUtils.escapeJavaScript(popup.toString()); 
     113                                 
     114                                StringBuilder popup = new StringBuilder(100); 
     115                                popup.append(Common.tableBegin(420, "left").replace( '"', '\'') ); 
     116                                popup.append("Belegte Werftslots: <img style='vertical-align:middle;border:0px' src='"+Configuration.getSetting("URL")+"data/interface/schiffinfo/werftslots.png' alt='' />"+usedSlots+"/"+totalSlots+"<br />"); 
     117                                popup.append("Im Bau: "+buildingCount+" Schiffe<br />"); 
     118                                popup.append("In der Warteschlange: "+(entries.length - buildingCount)); 
     119                                popup.append(Common.tableEnd().replace( '"', '\'' )); 
     120                                String popupStr = StringEscapeUtils.escapeJavaScript(popup.toString().replace(">", "&gt;").replace("<", "&lt;")); 
    139121                                 
    140122                                result.append("<a name=\"p"); 
     
    159141                                result.append(field); 
    160142                                result.append("\">[W]<span style=\"font-weight:normal\">"); 
    161                                 result.append(werft.getRemainingTime()); 
     143                                result.append(entries.length); 
    162144                                result.append("</span></a>"); 
    163145                        } 
  • src/net/driftingsouls/ds2/server/modules/SchiffeController.java

    rbed664f r89d279c  
    3030import net.driftingsouls.ds2.server.cargo.ResourceList; 
    3131import net.driftingsouls.ds2.server.cargo.Resources; 
    32 import net.driftingsouls.ds2.server.config.Items; 
    3332import net.driftingsouls.ds2.server.entities.User; 
    3433import net.driftingsouls.ds2.server.framework.Common; 
     
    4342import net.driftingsouls.ds2.server.ships.Ships; 
    4443import net.driftingsouls.ds2.server.werften.ShipWerft; 
     44import net.driftingsouls.ds2.server.werften.WerftQueueEntry; 
    4545 
    4646import org.apache.commons.lang.StringEscapeUtils; 
     
    312312                                        } 
    313313                                        else { 
    314                                                 ShipTypeData type = werft.getBuildShipType(); 
    315                                                 if( type != null ) { 
    316                                                         StringBuilder popup = new StringBuilder(100); 
    317                                                         popup.append(Common.tableBegin(420, "left").replace( '"', '\'') ); 
    318                                                         popup.append("<img align='left' border='0' src='"+type.getPicture()+"' alt='"+type.getNickname()+"' />"); 
    319                                                         popup.append("&nbsp;Baut: "+type.getNickname()+"<br />"); 
    320                                                         popup.append("&nbsp;Dauer: <img style='vertical-align:middle' src='"+Configuration.getSetting("URL")+"data/interface/time.gif' alt='noch ' />"+werft.getRemainingTime()+"<br />"); 
    321                                                         if( werft.getRequiredItem() != -1 ) {                                    
    322                                                                 popup.append("&nbsp;Ben&ouml;tigt: "); 
    323                                                                 popup.append("<img style='vertical-align:middle' src='../data/items/"+Items.get().item(werft.getRequiredItem()).getPicture()+"' alt='' />"); 
    324                                                                 if( werft.isBuildContPossible() ) { 
    325                                                                         popup.append("<span style='color:green'>"); 
    326                                                                 } 
    327                                                                 else { 
    328                                                                         popup.append("<span style='color:red'>"); 
    329                                                                 } 
    330                                                                 popup.append(Items.get().item(werft.getRequiredItem()).getName()+"</span>"); 
     314                                                final WerftQueueEntry[] entries = werft.getBuildQueue(); 
     315                                                final int totalSlots = werft.getWerftSlots(); 
     316                                                int usedSlots = 0; 
     317                                                int buildingCount = 0; 
     318                                                for( int i=0; i < entries.length; i++ ) { 
     319                                                        usedSlots += entries[i].getSlots(); 
     320                                                        if( entries[i].isScheduled() ) { 
     321                                                                buildingCount++; 
    331322                                                        } 
    332                                                         popup.append(Common.tableEnd().replace( '"', '\'' )); 
    333                                                         String popupStr = StringEscapeUtils.escapeJavaScript(popup.toString().replace(">", "&gt;").replace("<", "&lt;")); 
    334          
    335                                                         t.set_var(      "ship.werft.popup",             popupStr, 
    336                                                                                 "ship.werft.dauer",             werft.getRemainingTime(), 
    337                                                                                 "ship.werft.building",  1 ); 
    338                                                 } 
     323                                                } 
     324                                                 
     325                                                StringBuilder popup = new StringBuilder(100); 
     326                                                popup.append(Common.tableBegin(420, "left").replace( '"', '\'') ); 
     327                                                popup.append("Belegte Werftslots: <img style='vertical-align:middle;border:0px' src='"+Configuration.getSetting("URL")+"data/interface/schiffinfo/werftslots.png' alt='' />"+usedSlots+"/"+totalSlots+"<br />"); 
     328                                                popup.append("Im Bau: "+buildingCount+" Schiffe<br />"); 
     329                                                popup.append("In der Warteschlange: "+(entries.length - buildingCount)); 
     330                                                popup.append(Common.tableEnd().replace( '"', '\'' )); 
     331                                                String popupStr = StringEscapeUtils.escapeJavaScript(popup.toString().replace(">", "&gt;").replace("<", "&lt;")); 
     332         
     333                                                t.set_var(      "ship.werft.popup",             popupStr, 
     334                                                                        "ship.werft.entries",   entries.length, 
     335                                                                        "ship.werft.building",  1 ); 
    339336                                        } 
    340337                                } 
  • src/net/driftingsouls/ds2/server/modules/schiffplugins/WerftDefault.java

    rc3ab33e r89d279c  
    1919package net.driftingsouls.ds2.server.modules.schiffplugins; 
    2020 
    21 import net.driftingsouls.ds2.server.config.Items; 
    2221import net.driftingsouls.ds2.server.framework.templates.TemplateEngine; 
    2322import net.driftingsouls.ds2.server.modules.SchiffController; 
    2423import net.driftingsouls.ds2.server.ships.Ship; 
    25 import net.driftingsouls.ds2.server.ships.ShipTypeData; 
    2624import net.driftingsouls.ds2.server.werften.ShipWerft; 
     25import net.driftingsouls.ds2.server.werften.WerftQueueEntry; 
    2726 
    2827/** 
     
    5150                t.set_file("_PLUGIN_"+pluginid, "schiff.werft.default.html"); 
    5251 
    53                 if( werft.isBuilding() ) { 
    54                         ShipTypeData type = werft.getBuildShipType(); 
    55                          
    56                         t.set_var(      "global.pluginid",                      pluginid, 
    57                                                 "ship.id",                                      ship.getId(), 
    58                                                 "schiff.werft.prod.dauer",      werft.getRemainingTime(), 
    59                                                 "schiff.werft.prod.type",       type.getTypeId(), 
    60                                                 "schiff.werft.prod.name",       type.getNickname(), 
    61                                                 "schiff.werft.prod.picture",    type.getPicture() ); 
    62                          
    63                         if( werft.getRequiredItem() != -1 ) { 
    64                                 t.set_var(      "schiff.werft.prod.item",                       werft.getRequiredItem(), 
    65                                                         "schiff.werft.prod.item.name",          Items.get().item(werft.getRequiredItem()).getName(), 
    66                                                         "schiff.werft.prod.item.picture",       Items.get().item(werft.getRequiredItem()).getPicture(), 
    67                                                         "schiff.werft.prod.item.available",     werft.isBuildContPossible() ); 
     52                final WerftQueueEntry[] entries = werft.getBuildQueue(); 
     53                final int totalSlots = werft.getWerftSlots(); 
     54                int usedSlots = 0; 
     55                int buildingCount = 0; 
     56                for( int i=0; i < entries.length; i++ ) { 
     57                        usedSlots += entries[i].getSlots(); 
     58                        if( entries[i].isScheduled() ) { 
     59                                buildingCount++; 
    6860                        } 
    6961                } 
     62                t.set_var( 
     63                                "global.pluginid",                      pluginid, 
     64                                "ship.id",                                      ship.getId(), 
     65                                "schiff.werft.usedslots",       usedSlots, 
     66                                "schiff.werft.totalslots",      totalSlots, 
     67                                "schiff.werft.scheduled",       buildingCount, 
     68                                "schiff.werft.waiting",         entries.length-buildingCount 
     69                                ); 
    7070                 
    7171                t.parse(caller.target,"_PLUGIN_"+pluginid); 
  • src/net/driftingsouls/ds2/server/ships/Ship.java

    raf70f40 r89d279c  
    7272import net.driftingsouls.ds2.server.tasks.Task; 
    7373import net.driftingsouls.ds2.server.tasks.Taskmanager; 
     74import net.driftingsouls.ds2.server.werften.ShipWerft; 
    7475 
    7576import org.apache.commons.lang.StringUtils; 
     
    28022803                        .setInteger(0, this.id) 
    28032804                        .executeUpdate(); 
    2804          
    2805                 ContextMap.getContext().getDatabase().update("DELETE FROM werften WHERE shipid=",this.id); 
     2805                 
     2806                ShipWerft werft = (ShipWerft)db.createQuery("from ShipWerft where shipid=?") 
     2807                        .setInteger(0, this.id) 
     2808                        .uniqueResult(); 
     2809                 
     2810                if( werft != null ) { 
     2811                        werft.clearQueue(); 
     2812                        db.delete(werft); 
     2813                } 
    28062814                 
    28072815                db.createQuery("delete from ShipModules where id=?") 
    28082816                        .setInteger(0, this.id) 
    28092817                        .executeUpdate(); 
     2818                 
    28102819                db.delete(this); 
    28112820        } 
  • src/net/driftingsouls/ds2/server/tick/regular/WerftTick.java

    r30f818d r89d279c  
    3030import net.driftingsouls.ds2.server.werften.ShipWerft; 
    3131import net.driftingsouls.ds2.server.werften.WerftObject; 
     32import net.driftingsouls.ds2.server.werften.WerftQueueEntry; 
    3233 
    3334/** 
     
    6364                                 
    6465                                if( werft.isBuilding() ){ 
    65                                         ShipTypeData shipd = werft.getBuildShipType(); 
    66                                          
    67                                         this.log("\tAktueller Auftrag: "+shipd.getTypeId()+"; dauer: "+werft.getRemainingTime()); 
    68                                          
    69                                         if( werft.getRequiredItem() > -1 ) { 
    70                                                 this.log("\tItem benoetigt: "+Items.get().item(werft.getRequiredItem()).getName()+" ("+werft.getRequiredItem()+")"); 
    71                                         } 
    72                                         if( werft.isBuildContPossible() ) { 
    73                                                 werft.continueBuild(); 
    74                                                 this.log("\tVoraussetzungen erfuellt - bau geht weiter"); 
    75                                         } 
    76                                          
    77                                         if( werft.getRemainingTime() <= 0 ) { 
    78                                                 this.log("\tSchiff "+shipd.getTypeId()+" gebaut"); 
    79          
    80                                                 int shipid = werft.finishBuildProcess(); 
    81                                                 this.slog(werft.MESSAGE.getMessage()); 
     66                                        WerftQueueEntry[] entries = werft.getScheduledQueueEntries(); 
     67                                        for( int i=0; i < entries.length; i++ ) { 
     68                                                WerftQueueEntry entry = entries[i]; 
    8269                                                 
    83                                                 if( shipid > 0 ) { 
    84                                                         // MSG 
    85                                                         String msg = "Auf "+werft.getName()+" wurde eine "+shipd.getNickname()+" gebaut. Sie steht bei "+werft.getSystem()+" : "+werft.getX()+"/"+werft.getY()+"."; 
     70                                                ShipTypeData shipd = entry.getBuildShipType(); 
    8671                                                 
    87                                                         PM.send(getContext(), -1, werft.getOwner().getID(), "Schiff gebaut", msg); 
     72                                                this.log("\tAktueller Auftrag: "+shipd.getTypeId()+"; dauer: "+entry.getRemainingTime()); 
     73                                                 
     74                                                if( entry.getRequiredItem() > -1 ) { 
     75                                                        this.log("\tItem benoetigt: "+Items.get().item(entry.getRequiredItem()).getName()+" ("+entry.getRequiredItem()+")"); 
     76                                                } 
     77                                                if( entry.isBuildContPossible() ) { 
     78                                                        entry.continueBuild(); 
     79                                                        this.log("\tVoraussetzungen erfuellt - bau geht weiter"); 
     80                                                } 
     81                                                 
     82                                                if( entry.getRemainingTime() <= 0 ) { 
     83                                                        this.log("\tSchiff "+shipd.getTypeId()+" gebaut"); 
     84                 
     85                                                        int shipid = entry.finishBuildProcess(); 
     86                                                        this.slog(entry.MESSAGE.getMessage()); 
     87                                                         
     88                                                        if( shipid > 0 ) { 
     89                                                                // MSG 
     90                                                                String msg = "Auf "+werft.getName()+" wurde eine "+shipd.getNickname()+" gebaut. Sie steht bei "+werft.getSystem()+" : "+werft.getX()+"/"+werft.getY()+"."; 
     91                                                         
     92                                                                PM.send(getContext(), -1, werft.getOwner().getID(), "Schiff gebaut", msg); 
     93                                                        } 
    8894                                                } 
    8995                                        } 
  • src/net/driftingsouls/ds2/server/werften/ShipWerft.java

    rbed664f r89d279c  
    358358         
    359359        @Override 
    360         public int finishBuildProcess() { 
    361                 int id = super.finishBuildProcess(); 
    362                 if( (id != 0) && (getType() == 2) ) { 
     360        public void onFinishedBuildProcess(int shipid) { 
     361                super.onFinishedBuildProcess(shipid); 
     362                 
     363                // Falls es sich um eine Einwegwerft handelt, dann diese zerstoeren 
     364                if( getType() == 2 ) { 
    363365                        getShip().destroy(); 
    364366                } 
    365                  
    366                 return id; 
    367367        } 
    368368         
  • src/net/driftingsouls/ds2/server/werften/WerftGUI.java

    r30f818d r89d279c  
    141141                                                t.set_var( "werftgui.building.cancel", 1 ); 
    142142                                         
    143                                                 werft.cancelBuild(entry); 
     143                                                entry.cancelBuild(); 
    144144                                        } 
    145145                                } 
     
    256256                        WerftQueueEntry entry = queue[i]; 
    257257 
    258                         remaining += entry.getRemaining(); 
     258                        remaining += entry.getRemainingTime(); 
    259259                         
    260260                        t.set_var( 
    261261                                        "queueship.buildcosts.list",    "", 
    262262                                        "queueship.position",   entry.getPosition(), 
    263                                         "queueship.type.image", entry.getBuilding().getPicture(), 
    264                                         "queueship.type.id",    entry.getBuilding().getTypeId(), 
    265                                         "queueship.type.name",  entry.getBuilding().getNickname(), 
     263                                        "queueship.type.image", entry.getBuildShipType().getPicture(), 
     264                                        "queueship.type.id",    entry.getBuildShipType().getTypeId(), 
     265                                        "queueship.type.name",  entry.getBuildShipType().getNickname(), 
    266266                                        "queueship.remainingtotal",     remaining, 
    267                                         "queueship.building",   i == 0
     267                                        "queueship.building",   entry.isScheduled()
    268268                                        "queueship.uppossible", i > 0, 
    269269                                        "queueship.downpossible",       i < queue.length-1); 
    270270                         
    271                         if( entry.getBuildItem() != -1 ) { 
     271                        if( entry.getRequiredItem() != -1 ) { 
    272272                                t.set_var( 
    273273                                                "queueship.reqitem",    true, 
    274                                                 "queueship.item.picture",       Items.get().item(entry.getBuildItem()).getPicture(), 
    275                                                 "queueship.item.name",  Items.get().item(entry.getBuildItem()).getName()); 
     274                                                "queueship.item.picture",       Items.get().item(entry.getRequiredItem()).getPicture(), 
     275                                                "queueship.item.name",  Items.get().item(entry.getRequiredItem()).getName()); 
    276276                        } 
    277277                         
  • src/net/driftingsouls/ds2/server/werften/WerftObject.java

    </
    rbed664f r89d279c  
    3232import javax.persistence.InheritanceType; 
    3333import javax.persistence.Table; 
    34 import javax.persistence.Transient; 
    3534 
    3635import net.driftingsouls.ds2.server.ContextCommon; 
     
    4039import net.driftingsouls.ds2.server.cargo.Cargo; 
    4140import net.driftingsouls.ds2.server.cargo.ItemCargoEntry; 
    42 import net.driftingsouls.ds2.server.cargo.ItemID; 
    4341import net.driftingsouls.ds2.server.cargo.ResourceEntry; 
    4442import net.driftingsouls.ds2.server.cargo.ResourceID; 
     
    108106         
    109107        /** 
     108         * Gibt die aktuell zum Bau vorgesehenen Bauschlangeneintraege zurueck 
     109         * @return Die Liste der zum Bauvorgesehenen Bauschlangeneintraege 
     110         */ 
     111        public WerftQueueEntry[] getScheduledQueueEntries() { 
     112                org.hibernate.Session db = ContextMap.getContext().getDB(); 
     113                List list = db.createQuery("from WerftQueueEntry where id.werft=? and scheduled=1 order by id.position") 
     114                        .setInteger(0, this.getWerftID()) 
     115                        .list(); 
     116                WerftQueueEntry[] entries = new WerftQueueEntry[list.size()]; 
     117                int index = 0; 
     118                for( Iterator iter=list.iterator(); iter.hasNext(); ) { 
     119                        entries[index++] = (WerftQueueEntry)iter.next(); 
     120                } 
     121                 
     122                return entries; 
     123        } 
     124         
     125        /** 
    110126         * Gibt zurueck, ob in der Werft im Moment gebaut wird 
    111127         * @return <code>true</code>, falls gebaut wird 
    112128         */ 
    113129        public final boolean isBuilding() { 
    114                 return getQueueTopEntry() != null; 
     130                org.hibernate.Session db = ContextMap.getContext().getDB(); 
     131                 
     132                return db.createQuery("from WerftQueueEntry where id.werft=?") 
     133                        .setInteger(0, this.getWerftID()) 
     134                        .iterate().hasNext(); 
    115135        } 
    116136         
     
    123143        } 
    124144         
    125         @Transient 
    126         private WerftQueueEntry topEntry = null; 
    127          
    128         private WerftQueueEntry getQueueTopEntry() { 
    129                 if( topEntry == null ) { 
    130                         org.hibernate.Session db = ContextMap.getContext().getDB(); 
    131                          
    132                         topEntry = (WerftQueueEntry)db 
    133                                 .createQuery("from WerftQueueEntry where id.werft=? and id.position=1") 
    134                                 .setInteger(0, this.getWerftID()) 
    135                                 .uniqueResult(); 
    136                 } 
    137                  
    138                 return topEntry; 
    139         } 
    140          
    141         /** 
    142          * Gibt den im Moment gebauten Schiffstyp zurueck 
    143          * @return Schiffstypdaten oder <code>null</code> 
    144          */ 
    145         public final ShipTypeData getBuildShipType() { 
    146                 WerftQueueEntry entry = getQueueTopEntry(); 
    147                  
    148                 if( entry != null ) { 
    149                         return entry.getBuilding(); 
    150                 } 
    151                  
    152                 return null; 
    153         } 
    154          
    155         /** 
    156          * Dekrementiert die verbliebene Bauzeit um 1 
    157          */ 
    158         public final void decRemainingTime() { 
    159                 WerftQueueEntry entry = getQueueTopEntry(); 
    160                 if( (entry == null) || (entry.getRemaining() <= 0) ) { 
    161                         return; 
    162                 } 
    163                  
    164                 entry.setRemaining(entry.getRemaining()-1); 
    165         } 
    166          
    167         /** 
    168          * Inkrementiert die verbliebene Bauzeit um 1 
    169          */ 
    170         public final void incRemainingTime() { 
    171                 WerftQueueEntry entry = getQueueTopEntry(); 
    172                 if( entry == null ) { 
    173                         return; 
    174                 } 
    175                 entry.setRemaining(entry.getRemaining()+1); 
    176         } 
    177          
    178         /** 
    179          * Liefert die noch verbleibende Bauzeit 
    180          * @return verbleibende Bauzeit 
    181          */ 
    182         public final int getRemainingTime() { 
    183                 WerftQueueEntry entry = getQueueTopEntry(); 
    184                 if( entry != null ) { 
    185                         return entry.getRemaining(); 
    186                 } 
    187                 return 0; 
    188         } 
    189          
    190         /** 
    191          * Gibt das fuer den Bau benoetigte Item zurueck. 
    192          * Falls kein Item benoetigt wird, wird -1 zurueckgegeben. 
    193          * @return Item-ID oder -1 
    194          */ 
    195         public final int getRequiredItem() { 
    196                 WerftQueueEntry entry = getQueueTopEntry(); 
    197                 if( entry != null ) { 
    198                         return entry.getBuildItem(); 
    199                 } 
    200                 return -1; 
     145        /** 
     146         * Gibt die Anzahl der aktuell belegten Slots zurueck 
     147         * @return Die Anzahl der belegten Slots 
     148         */ 
     149        public int getUsedSlots() { 
     150                org.hibernate.Session db = ContextMap.getContext().getDB(); 
     151                 
     152                return ((Number)db.createQuery("select sum(slots) from WerftQueueEntry where id.werft=? and scheduled=1") 
     153                        .setInteger(0, this.getWerftID()) 
     154                        .iterate().next()).intValue(); 
    201155        } 
    202156         
     
    210164         
    211165        /** 
    212          * Beendet den Bauprozess des aktuell gebauten Schiffes erfolgreich. 
    213          * Sollte dies nicht moeglich sein, wird 0 zurueckgegeben. 
    214          *  
    215          * @return die ID des gebauten Schiffes oder 0 
    216          */ 
    217         public int finishBuildProcess() { 
    218                 Context context = ContextMap.getContext(); 
    219                 org.hibernate.Session db = context.getDB(); 
    220                  
    221                 if( !this.isBuilding() ) { 
    222                         return 0; 
    223                 } 
    224                  
    225                 ShipTypeData shipd = this.getBuildShipType(); 
    226  
    227                 int x = this.getX(); 
    228                 int y = this.getY(); 
    229                 int system = this.getSystem(); 
    230                                          
    231                 Cargo cargo = new Cargo(); 
    232                 User auser = this.getOwner(); 
    233                  
    234                 String currentTime = Common.getIngameTime(context.get(ContextCommon.class).getTick()); 
    235                 String history = "Indienststellung am "+currentTime+" durch "+auser.getName()+" ("+auser.getID()+")\n"; 
    236                  
    237                 Ship ship = new Ship(auser); 
    238                 ship.setBaseType((ShipType)db.get(ShipType.class, shipd.getTypeId())); 
    239                 ship.setSystem(system); 
    240                 ship.setX(x); 
    241                 ship.setY(y); 
    242                 ship.setCrew(shipd.getCrew()); 
    243                 ship.setHull(shipd.getHull()); 
    244                 ship.setCargo(cargo); 
    245                 ship.setEnergy(shipd.getEps()); 
    246                 ship.setHistory(history); 
    247  
    248                 int id = (Integer)db.save(ship); 
    249  
    250                 if( shipd.getWerft() != 0 ) { 
    251                         ShipWerft werft = new ShipWerft(ship); 
    252                         db.persist(werft); 
    253                         this.MESSAGE.get().append("\tWerft '"+shipd.getWerft()+"' in Liste der Werften eingetragen\n"); 
    254                 } 
    255                  
    256                 WerftQueueEntry entry = getQueueTopEntry(); 
    257                 if( entry.isBuildFlagschiff() ) { 
    258                         auser.setFlagschiff(id); 
    259                         this.MESSAGE.get().append("\tFlagschiff eingetragen\n"); 
    260                 } 
    261                  
    262                 // Item benutzen 
    263                 if( this.getRequiredItem() > -1 ) { 
    264                         cargo = this.getCargo(true); 
    265                         List<ItemCargoEntry> itemlist = cargo.getItem(this.getRequiredItem()); 
    266                         boolean ok = false; 
    267                         for( int i=0; i < itemlist.size(); i++ ) { 
    268                                 if( itemlist.get(i).getMaxUses() == 0 ) { 
    269                                         ok = true; 
    270                                         break; 
    271                                 } 
    272                         } 
    273                          
    274                         if( !ok ) { 
    275                                 User user = this.getOwner(); 
     166         * Wird von Bauschlangeneintraegen aufgerufen, nachdem sie erfolgreich abgeschlossen wurden. 
     167         * Der Bauschlangeneintrag ist zu diesem Zeitpunkt bereits entfernt. 
     168         * @param shipid Die ID des neugebauten Schiffes 
     169         */ 
     170        protected void onFinishedBuildProcess(int shipid) { 
     171                rescheduleQueue(); 
     172        } 
     173 
     174        /** 
     175         * Berechnet, welche Eintraege der Bauschlange im Moment gebaut werden und welche nicht 
     176         * 
     177         */ 
     178        protected void rescheduleQueue() { 
     179                int freeSlots = this.getWerftSlots(); 
     180                 
     181                final WerftQueueEntry[] entries = getBuildQueue(); 
     182                for( int i=0; i < entries.length; i++ ) { 
     183                        final WerftQueueEntry entry = entries[i]; 
     184                         
     185                        if( (entry.getSlots() <= freeSlots) && entry.isBuildContPossible() ) { 
     186                                entry.setScheduled(true); 
    276187                                 
    277                                 Cargo allyitems = null; 
    278                                 if( user.getAlly() != null ) { 
    279                                         allyitems = new Cargo( Cargo.Type.ITEMSTRING, user.getAlly().getItems() ); 
    280                                         itemlist = allyitems.getItem(this.getRequiredItem()); 
    281                                         for( int i=0; i < itemlist.size(); i++ ) { 
    282                                                 if( itemlist.get(i).getMaxUses() == 0 ) { 
    283                                                         ok = true; 
    284                                                         break; 
    285                                                 } 
    286                                         } 
    287                                 } 
     188                                freeSlots -= entry.getSlots();