Code Search for Developers
 
 
  

Alliance.java from Magellan-Client at Krugle


Show Alliance.java syntax highlighted

/*
 *  Copyright (C) 2000-2004 Roger Butenuth, Andreas Gampe,
 *                          Stefan Goetz, Sebastian Pappert,
 *                          Klaas Prause, Enno Rehling,
 *                          Sebastian Tusk, Ulrich Kuester,
 *                          Ilja Pavkovic
 *
 * This file is part of the Eressea Java Code Base, see the
 * file LICENSING for the licensing information applying to
 * this file.
 *
 */

package com.eressea;

import java.util.Iterator;

import com.eressea.rules.AllianceCategory;
import com.eressea.util.Translations;

/**
 * A class representing an alliance status between two factions. The faction having this alliance
 * is implicit, the target faction is an explicite field of this class.
 */
public class Alliance {
	private final Faction faction;
	private int state = 0;

	/**
	 * Create a new Alliance object for an alliance with the specified faction and without any
	 * alliance status set.
	 *
	 * @param faction the faction to establish an alliance with.
	 */
	public Alliance(Faction faction) {
		this(faction, 0);
	}

	/**
	 * Create a new Alliance object for an alliance with the specified faction and the specified
	 * status.
	 *
	 * @param faction the faction to establish an alliance with
	 * @param state the alliance status, must be one of constants SILVER, FIGHT, GIVE, GUARD, GUISE
	 * 		  or ALL.
	 *
	 * @throws NullPointerException if the faction parameter is null.
	 */
	public Alliance(Faction faction, int state) {
		if(faction == null) {
			throw new NullPointerException();
		}

		this.faction = faction;
		this.state = state;
	}

	private AllianceCategory getMaxAllianceCategory() {
		Iterator iter = faction.getData().rules.getAllianceCategoryIterator();

		if(iter.hasNext()) {
			AllianceCategory ret = (AllianceCategory) iter.next();

			while(iter.hasNext()) {
				AllianceCategory ac = (AllianceCategory) iter.next();

				if(ac.compareTo(ret) > 0) {
					ret = ac;
				}
			}

			return ret;
		}

		return null;
	}

	/**
	 * Returns the faction this alliance refers to. The return value is never null.
	 *
	 * @return the faction of this alliance
	 */
	public Faction getFaction() {
		return faction;
	}

	/**
	 * Get the state bit-field of this alliance.
	 *
	 * @return the state bitfield.
	 */
	public int getState() {
		return state;
	}

	/**
	 * Set the state bit-field of this alliance.
	 *
	 * @param state state bitfield.
	 */
	public void setState(int state) {
		this.state = state;
	}

	/**
	 * Determine whether a specific state of this alliance is set.
	 *
	 * @param selector specifying one of the constants in this class.
	 *
	 * @return true if specific state is set, false if not which state should be evaluated.
	 */
	public boolean getState(int selector) {
		return ((state & selector) == selector);
	}

	/**
	 * Get a string representation of the alliance state.
	 *
	 * @return the alliance state as string.
	 */
	public String stateToString() {
		AllianceCategory maxAC = getMaxAllianceCategory();

		if(maxAC == null) {
			return "";
		}

		if(getState(maxAC.getBitMask())) {
			return Translations.getOrderTranslation(maxAC.getName());
		}

		StringBuffer ret = new StringBuffer();

		// connect all state strings separated by spaces
		for(Iterator iter = faction.getData().rules.getAllianceCategoryIterator(); iter.hasNext();) {
			AllianceCategory ac = (AllianceCategory) iter.next();

			if(!ac.equals(maxAC) && getState(ac.getBitMask())) {
				ret.append(Translations.getOrderTranslation(ac.getName()));

				if(iter.hasNext()) {
					ret.append(" ");
				}
			}
		}

		return ret.toString();
	}

	/**
	 * Return a string representation of this alliance object.
	 *
	 * @return the alliance object as string.
	 */
	public String toString() {
		return faction.toString() + ": " + stateToString();
	}

	/**
	 * A method to convert an alliance into a trustlevel. This method should be uses when Magellan
	 * calculates trust levels on its own.
	 *
	 * @return the trustlevel of this alliance
	 */
	public int getTrustLevel() {
		int ret = 0;

		// connect all state strings separated by spaces
		for(Iterator iter = faction.getData().rules.getAllianceCategoryIterator(); iter.hasNext();) {
			AllianceCategory ac = (AllianceCategory) iter.next();

			if(getState(ac.getBitMask())) {
				ret += 10;
			}
		}

		return ret;
	}
}




See more files for this project here

Magellan-Client

The Magellan Client is basicly a GUI for the pbem game eressea but can be used for other pbems based on \"atlantis\" too.

Project homepage: http://sourceforge.net/projects/magellan-client
Programming language(s): Java
License: other

  completion/
    AutoCompletion.java
    Completer.java
    CompleterSettingsProvider.java
    Completion.java
    OrderParser.java
  cr/
    Loader.java
  demo/
    actions/
      AbortAction.java
      AddCRAction.java
      AddSelectionAction.java
      ArmyStatsAction.java
      ChangeFactionConfirmationAction.java
      ConfirmAction.java
      ECheckAction.java
      EresseaOptionsAction.java
      ExpandSelectionAction.java
      ExportCRAction.java
      ExternalModuleAction.java
      FactionStatsAction.java
      FileHistoryAction.java
      FileSaveAction.java
      FileSaveAsAction.java
      FillSelectionAction.java
      FindAction.java
      FindPreviousUnconfirmedAction.java
      HelpAction.java
      InfoAction.java
      InvertSelectionAction.java
      IslandAction.java
      MapSaveAction.java
      MenuAction.java
      OpenCRAction.java
      OpenOrdersAction.java
      OpenSelectionAction.java
      OptionAction.java
      QuitAction.java
      RedoAction.java
    desktop/
    Client.java
    ClientPreferences.java
    EMapDetailsPanel.java
    EMapOverviewPanel.java
    FindDialog.java
    MagellanUndoManager.java
    SetOriginDialog.java
  event/
  extern/
  gamebinding/
  io/
  main/
  relation/
  resource/
  rules/
  skillchart/
  swing/
  tasks/
  util/
  Alliance.java
  Battle.java
  Border.java
  Building.java
  CombatSpell.java
  CompleteData.java
  CoordinateID.java
  Described.java
  DescribedObject.java
  EntityID.java
  Faction.java
  GameData.java
  Group.java
  HasRegion.java
  HotSpot.java
  ID.java
  Identifiable.java
  IntegerID.java
  Island.java
  Item.java
  LongID.java
  LuxuryPrice.java
  Message.java
  MissingData.java
  Named.java
  NamedObject.java
  Potion.java
  Region.java
  RegionResource.java
  Related.java
  RelatedObject.java
  Rules.java
  Scheme.java
  Ship.java
  Sign.java
  Skill.java
  Spell.java
  StringID.java
  TempUnit.java
  Unique.java
  Unit.java
  UnitContainer.java
  UnitID.java
  ZeroUnit.java