"Clear speciality"-feature added

This commit is contained in:
Stian Grenborgen 2004-06-15 18:47:22 +00:00
parent ec2c7d907a
commit bbde814211
5 changed files with 68 additions and 1 deletions

View File

@ -326,6 +326,24 @@ public final class InGameController {
}
/**
* Clear the speciality of a <code>Unit</code>. That is, makes it a
* <code>Unit.FREE_COLONIST</code>.
*
* @param unit The <code>Unit</code> to clear the speciality of.
*/
public void clearSpeciality(Unit unit) {
Client client = freeColClient.getClient();
Element clearSpecialityElement = Message.createNewRootElement("clearSpeciality");
clearSpecialityElement.setAttribute("unit", unit.getID());
unit.clearSpeciality();
client.send(clearSpecialityElement);
}
/**
* Leave a ship. This method should only be invoked if the ship is in a harbour.
*

View File

@ -141,6 +141,16 @@ public final class DragListener extends MouseAdapter {
menu.add(menuItem);
}
if (tempUnit.getType() != Unit.INDIAN_CONVERT && tempUnit.getType() != Unit.PETTY_CRIMINAL &&
tempUnit.getType() != Unit.INDENTURED_SERVANT && tempUnit.getType() != Unit.FREE_COLONIST) {
menu.addSeparator();
menuItem = new JMenuItem("Clear speciality");
menuItem.setActionCommand(String.valueOf(UnitLabel.CLEAR_SPECIALITY));
menuItem.addActionListener(unitLabel);
menu.add(menuItem);
}
menu.show(comp, e.getX(), e.getY());
}
} else {

View File

@ -50,7 +50,8 @@ public final class UnitLabel extends JLabel implements ActionListener {
WORKTYPE_FURS = 8,
WORKTYPE_LUMBER = 9,
WORKTYPE_ORE = 10,
WORKTYPE_SILVER = 11;
WORKTYPE_SILVER = 11,
CLEAR_SPECIALITY = 12;
private final Unit unit;
private final Canvas parent;
@ -223,6 +224,8 @@ public final class UnitLabel extends JLabel implements ActionListener {
case WORKTYPE_SILVER:
inGameController.changeWorkType(unit, Goods.SILVER);
break;
case CLEAR_SPECIALITY:
inGameController.clearSpeciality(unit);
default:
logger.warning("Invalid action");
}

View File

@ -2390,6 +2390,18 @@ public class Unit extends FreeColGameObject implements Location, Locatable {
}
}
/**
* Clear the speciality of a <code>Unit</code>. That is, makes it a
* <code>FREE_COLONIST</code>
*/
public void clearSpeciality() {
if (isColonist() && getType() != INDIAN_CONVERT && getType() != INDENTURED_SERVANT && getType() != PETTY_CRIMINAL) {
setType(FREE_COLONIST);
}
}
/**
* Gets the Colony the goods of this unit would go to if it were to de-equip.
* @return The Colony the goods would go to, or null if there is no appropriate Colony

View File

@ -105,6 +105,8 @@ public final class InGameInputHandler implements MessageHandler {
reply = changeState(connection, element);
} else if (type.equals("putOutsideColony")) {
reply = putOutsideColony(connection, element);
} else if (type.equals("clearSpeciality")) {
reply = clearSpeciality(connection, element);
} else if (type.equals("endTurn")) {
reply = endTurn(connection, element);
} else {
@ -899,6 +901,28 @@ public final class InGameInputHandler implements MessageHandler {
}
/**
* Handles a "clearSpeciality"-request from a client.
*
* @param connection The connection the message came from.
* @param clearSpecialityElement The element containing the request.
*/
private Element clearSpeciality(Connection connection, Element clearSpecialityElement) {
Game game = freeColServer.getGame();
ServerPlayer player = freeColServer.getPlayer(connection);
Unit unit = (Unit) game.getFreeColGameObject(clearSpecialityElement.getAttribute("unit"));
if (unit.getOwner() != player) {
throw new IllegalStateException("Not your unit!");
}
unit.clearSpeciality();
return null;
}
/**
* Handles an "endTurn" notification from a client.
*