From: Kimmo R. <ki...@us...> - 2010-04-20 22:04:23
|
Update of /cvsroot/arianne/stendhal/src/games/stendhal/server/entity/mapstuff/portal In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv23852/src/games/stendhal/server/entity/mapstuff/portal Modified Files: Gate.java Log Message: Don't close the gate if there's something on the way Index: Gate.java =================================================================== RCS file: /cvsroot/arianne/stendhal/src/games/stendhal/server/entity/mapstuff/portal/Gate.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Gate.java 26 Feb 2009 14:57:54 -0000 1.8 --- Gate.java 20 Apr 2010 22:04:15 -0000 1.9 *************** *** 10,15 **** public class Gate extends Entity implements UseListener { - - private static final String HORIZONTAL = "h"; private static final String VERTICAL = "v"; --- 10,13 ---- *************** *** 34,41 **** --- 32,47 ---- } + /** + * Create a new vertical gate. + */ public Gate() { this(VERTICAL); } + /** + * Set the orientation of the gate. + * + * @param orientation "h" for horizontal, "v" for vertical + */ private void setOrientation(final String orientation) { if (HORIZONTAL.equals(orientation)) { *************** *** 46,66 **** } ! public void open() { setOpen(true); } public boolean isOpen() { - return isOpen; } public void close() { setOpen(false); - } public boolean onUsed(final RPEntity user) { - Logger.getLogger(Gate.class).info("use-called"); if (this.nextTo(user)) { setOpen(!isOpen()); --- 52,79 ---- } ! /** ! * Open the gate. ! */ public void open() { setOpen(true); } + /** + * Check if the gate is open. + * + * @return true iff the gate is open + */ public boolean isOpen() { return isOpen; } + /** + * Close the gate. + */ public void close() { setOpen(false); } public boolean onUsed(final RPEntity user) { if (this.nextTo(user)) { setOpen(!isOpen()); *************** *** 70,83 **** } ! private void setOpen(final boolean b) { ! if (b) { setResistance(0); } else { setResistance(100); } ! isOpen = b; notifyWorldAboutChanges(); - } - } --- 83,107 ---- } ! /** ! * Set the door open or closed. ! * ! * @param open true if the door is opened, false otherwise ! */ ! private void setOpen(final boolean open) { ! if (open) { setResistance(0); } else { + // Closing the gate - check there's nobody on the way + if (getZone() != null) { + for (Entity entity : getZone().getEntitiesAt(getX(), getY())) { + if (entity.getResistance() > 0) { + return; + } + } + } setResistance(100); } ! isOpen = open; notifyWorldAboutChanges(); } } |