import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.*;

public class Ground extends Unit {

	Structure	structure;	//この土地の上に立てられた建築物。(川の上なら橋や渡。平地なら道路・田畑・森・草原・焼跡・都市)
	Creature	creature;	//この土地の上に駐留している生物。(市民とか軍隊とか歩兵とか騎馬兵とか)

	int	groundKind;

	static final int DEEP_WATER = -4;	//深水
	static final int SHALLOW_WATER = -3;	//浅水
	static final int SWAMP = -2;		//沼沢地
	static final int LOW_LAND = -1;		//低地
	static final int PLAIN_LAND = 0;	//平地
	static final int HIGH_LAND = 1;		//高地
	static final int HILL_LAND = 2;		//丘陵地
	static final int LOW_MOUNTAIN = 3;	//山地
	static final int HIGH_MOUNTAIN = 4;	//高山


	public Ground(int x, int y, Board board, int groundKind) {
		this.x = x;
		this.y = y;
		this.board = board;

		this.groundKind = groundKind;

	}

	public Structure getStructure() { return structure; }
	public void setStructure(Structure structure) { this.structure = structure; }
	public void removeStructure() { structure = null; }

	public Creature getCreature() { return creature; }
	public void setCreature(Creature creature) { this.creature = creature; }
	public void removeCreature() { creature = null; }

	public int getGroundKind() { return groundKind; }

	/** この土地を通過するには、どのくらいの移動力を消費するか。 */
	public int getRestraint() {
		if ( structure != null ) {
			return ( structure.getRestraint() * 4 );
		}
		else {
			return ( getGroundRestraint() * 4 );
		}
	}

	/** この地形を通過するには、どのくらいの移動力を消費するか。 */
	public int getGroundRestraint() {

		int retRestraint;

		switch ( groundKind ) {
			case PLAIN_LAND:
				retRestraint = 2;
				break;
			case HILL_LAND:
			case LOW_LAND:
				retRestraint = 3;
				break;
			case HIGH_LAND:
			case SWAMP:
				retRestraint = 4;
				break;
			case LOW_MOUNTAIN:
			case SHALLOW_WATER:
				retRestraint = 5;
				break;
			case DEEP_WATER:
				retRestraint = 6;
				break;
			default:
				retRestraint = 4;
				break;
		}

		return retRestraint;
	}

	public int getOffensivePower(Direction attackedDirection) {
		return ( groundKind + structure.getOffensivePower(attackedDirection) );
	}
	public int getDefensivePower(Direction attackedDirection) {
		return ( groundKind + structure.getDefensivePower(attackedDirection) );
	}


	public void show(Graphics g, int x, int y, Component view) {
		uge.show(g, x,y, this, view);

		if ( structure != null ) {
			structure.show(g, x,y, view);
		}

		if ( creature != null ) {
			creature.show(g, x,y, view);
		}
	}
}
