Code Search for Developers
 
 
  

Faction.java from Magellan-Client at Krugle


Show Faction.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 java.util.List;
import java.util.Locale;
import java.util.Map;

import com.eressea.rules.Options;
import com.eressea.rules.Race;
import com.eressea.util.CollectionFactory;
import com.eressea.util.logging.Logger;

/**
 * A class representing a faction in Eressea.
 */
public class Faction extends UnitContainer {
	private static final Logger log = Logger.getInstance(Faction.class);

	/* Implementation note on trust levels:
	 * Trust levels have been introduced to replace the inherently
	 * wrong concept of owner factions. This way there can for
	 * example be more than one faction that can edit its units'
	 * orders.
	 * TL_DEFAULT must keep a value of 0, so this equivalent to a
	 * faction without a specified trust level. Trust levels
	 * expressing an increased amount trust or privileges should get
	 * ascending positive numbers, and the other way round with
	 * negative trust levels.
	 * Therefore comparisons for trust levels should in most cases be
	 * 'greater than' or 'less than' relations rather than absolute
	 * comparisons.
	 */

	/** Any faction has this trust level if not otherwise specified. */
	public static final int TL_DEFAULT = 0;

	/**
	 * This trust level indicates that units of this faction may receive new orders and similar
	 * privileges.
	 */
	public static final int TL_PRIVILEGED = 100;

	/**
	 * The password of this faction required for authentication of orders sent to the Eressea
	 * server.
	 */
	public String password = null;

	/** The email address of the Faction */
	public String email = null;

	/** TODO: DOCUMENT ME! */
	public Options options = null;

	/** TODO: DOCUMENT ME! */
	public int score = -1;

	/** TODO: DOCUMENT ME! */
	public int averageScore = -1;

	/** TODO: DOCUMENT ME! */
	public int persons = -1;

	/** TODO: DOCUMENT ME! */
	public int migrants = -1;

	/** TODO: DOCUMENT ME! */
	public int maxMigrants = -1;

	/** TODO: DOCUMENT ME! */
	public String spellSchool = null; // Magiegebiet

	/**
	 * Indicates to what amount this faction can be trusted. It also influences the privileges of
	 * this faction (e.g. being able to edit its units' orders).
	 */
	public int trustLevel = TL_DEFAULT;
	
	/**
	 * Indicates, if one priviliged faction has set the "GIVE" right
	 * to this faction.
	 * used for showing unit capacity only for items of such factions
	 */
	public boolean hasGiveAlliance = false;
	
	/**
	 * taken from the cr: actual amount of heroes (Fiete)
	 */
	public int heroes = -1;
	
	/**
	 * taken from the cr: actual max amount of heroes (Fiete)
	 */
	public int maxHeroes = -1;
	
	/**
	 * taken from the cr: actual age of faction (Fiete)
	 */
	public int age = -1;

	/**
	 * TODO: DOCUMENT ME!
	 *
	 * @return TODO: DOCUMENT ME!
	 */
	public boolean isPrivileged() {
		return trustLevel >= TL_PRIVILEGED;
	}

	/**
	 * true: indicates that this trustlevel was explicitly set by the user or read from a CR-file
	 * false: indicates that this is either a default level or was calculated by Magellan based on
	 * the alliances of the privileged factions.
	 */
	public boolean trustLevelSetByUser = false;

	/** contains all messages for this faction as <tt>Message</tt> objects */
	public List messages = null;

	/** contains error messages for this faction as <tt>String</tt> objects */
	public List errors = null;

	/** contains the battles, this faction had in the current round, as <tt>Battle</tt> objects */
	public List battles = null;

	/**
	 * The allies of this faction are stored in this map with the faction ID of the ally as key and
	 * an <tt>Alliance</tt> object as value.
	 */
	public Map allies = null;

	/**
	 * The different groups in this faction. The map contains <tt>ID</tt> objects with the group id
	 * as keys and <tt>Group</tt> objects as values.
	 */
	public Map groups = null;

	/** The country code indicating the locale for this faction. */
	private Locale locale = null;

	/**
	 * Creates a new Faction object with the specified id on top of the specified game data object.
	 *
	 * @param id TODO: DOCUMENT ME!
	 * @param data TODO: DOCUMENT ME!
	 */
	public Faction(ID id, GameData data) {
		super(id, data);
	}

	/**
	 * Assigns this faction a locale indicating the language of its report and the orders.
	 *
	 * @param l TODO: DOCUMENT ME!
	 */
	public void setLocale(Locale l) {
		this.locale = l;
	}

	/**
	 * Returns the locale of this faction indicating the language of its report and orders.
	 *
	 * @return TODO: DOCUMENT ME!
	 */
	public Locale getLocale() {
		return this.locale;
	}

	/** A faction dependent prefix to be prepended to this faction's race name. */
	private String raceNamePrefix = null;

	/**
	 * Sets the faction dependent prefix for the race name.
	 *
	 * @param prefix TODO: DOCUMENT ME!
	 */
	public void setRaceNamePrefix(String prefix) {
		this.raceNamePrefix = prefix;
	}

	/**
	 * Returns the faction dependent prefix for the race name.
	 *
	 * @return TODO: DOCUMENT ME!
	 */
	public String getRaceNamePrefix() {
		return this.raceNamePrefix;
	}

	/**
	 * Returns the race of this faction. This method is an alias for the getType() method.
	 *
	 * @return TODO: DOCUMENT ME!
	 */
	public Race getRace() {
		return (Race) this.getType();
	}

	/**
	 * Returns a string representation of this faction.
	 *
	 * @return TODO: DOCUMENT ME!
	 */
	public String toString() {
		return getName() + " (" + this.getID() + ")";
	}

	/**
	 * TODO: DOCUMENT ME!
	 *
	 * @param curGD TODO: DOCUMENT ME!
	 * @param curFaction TODO: DOCUMENT ME!
	 * @param newGD TODO: DOCUMENT ME!
	 * @param newFaction TODO: DOCUMENT ME!
	 */
	public static void merge(GameData curGD, Faction curFaction, GameData newGD, Faction newFaction) {
		UnitContainer.merge(curGD, curFaction, newGD, newFaction);

		if((curFaction.allies != null) && (curFaction.allies.size() > 0)) {
			if(newFaction.allies == null) {
				newFaction.allies = CollectionFactory.createOrderedHashtable();
			} else {
				newFaction.allies.clear();
			}

			for(Iterator iter = curFaction.allies.values().iterator(); iter.hasNext();) {
				Alliance alliance = (Alliance) iter.next();
				Faction ally = newGD.getFaction(alliance.getFaction().getID());
				newFaction.allies.put(ally.getID(), new Alliance(ally, alliance.getState()));
			}
		}

		if(curFaction.email != null) {
			newFaction.email = curFaction.email;
		}

		if((curFaction.groups != null) && (curFaction.groups.size() > 0)) {
			if(newFaction.groups == null) {
				newFaction.groups = CollectionFactory.createHashtable();
			} else {
				newFaction.groups.clear();
			}

			for(Iterator iter = curFaction.groups.values().iterator(); iter.hasNext();) {
				Group curGroup = (Group) iter.next();
				Group newGroup = null;

				try {
					newGroup = new Group((ID) curGroup.getID().clone(), newGD);
				} catch(CloneNotSupportedException e) {
				}

				Group.merge(curGD, curGroup, newGD, newGroup);
				newFaction.groups.put(newGroup.getID(), newGroup);
			}
		}

		if(curFaction.getLocale() != null) {
			newFaction.setLocale(curFaction.getLocale());
		}

		if(curFaction.maxMigrants != -1) {
			newFaction.maxMigrants = curFaction.maxMigrants;
		}

		if(curFaction.options != null) {
			newFaction.options = new Options(curFaction.options);
		}

		if(curFaction.password != null) {
			newFaction.password = curFaction.password;
		}

		if(curFaction.spellSchool != null) {
			newFaction.spellSchool = curFaction.spellSchool;
		}

		// one trustLevel is guaranteed to be TL_DEFAULT
		// ReportMerger.mergeReport() :

		/**
		 * prepare faction trustlevel for merging: - to be added CR is older or of same age -> hold
		 * existing trust levels - to be added CR is newer and contains trust level that were set
		 * by the user explicitly (or read from CR what means the same) -> take the trust levels
		 * out of the new CR otherwise -> hold existing trust levels This means: set those trust
		 * levels, that will not be retained to default values
		 */
		if((curFaction.trustLevel != Faction.TL_DEFAULT) || curFaction.trustLevelSetByUser) {
			newFaction.trustLevel = curFaction.trustLevel;
			newFaction.trustLevelSetByUser = curFaction.trustLevelSetByUser;
		}

		// see Region.merge() for the meaning of the following if
		if(curGD.getDate().equals(newGD.getDate())) {
			if(curFaction.averageScore != -1) {
				newFaction.averageScore = curFaction.averageScore;
			}

			if((curFaction.battles != null) && (curFaction.battles.size() > 0)) {
				newFaction.battles = CollectionFactory.createLinkedList();

				for(Iterator iter = curFaction.battles.iterator(); iter.hasNext();) {
					Battle curBattle = (Battle) iter.next();

					try {
						Battle newBattle = new Battle((ID) curBattle.getID().clone(),
													  curBattle.isBattleSpec());

						for(Iterator msgs = curBattle.messages().iterator(); msgs.hasNext();) {
							Message curMsg = (Message) msgs.next();
							Message newMsg = new Message((ID) curMsg.getID().clone());
							Message.merge(curGD, curMsg, newGD, newMsg);
							newBattle.messages().add(newMsg);
						}

						newFaction.battles.add(curBattle);
					} catch(CloneNotSupportedException e) {
						log.error("Faction.merge()", e);
					}
				}
			}

			if((curFaction.errors != null) && (curFaction.errors.size() > 0)) {
				newFaction.errors = CollectionFactory.createLinkedList(curFaction.errors);
			}

			if((curFaction.messages != null) && (curFaction.messages.size() > 0)) {
				if(newFaction.messages == null) {
					newFaction.messages = CollectionFactory.createLinkedList();
				} else {
					newFaction.messages.clear();
				}

				for(Iterator iter = curFaction.messages.iterator(); iter.hasNext();) {
					Message curMsg = (Message) iter.next();
					Message newMsg = null;

					try {
						newMsg = new Message((ID) curMsg.getID().clone());
					} catch(CloneNotSupportedException e) {
					}

					Message.merge(curGD, curMsg, newGD, newMsg);
					newFaction.messages.add(newMsg);
				}
			}

			if(curFaction.migrants != -1) {
				newFaction.migrants = curFaction.migrants;
			}

			if(curFaction.persons != -1) {
				newFaction.persons = curFaction.persons;
			}

			if(curFaction.raceNamePrefix != null) {
				newFaction.raceNamePrefix = curFaction.raceNamePrefix;
			}

			if(curFaction.score != -1) {
				newFaction.score = curFaction.score;
			}
			
			/**
			 * Fiete: merge also new (20061102) hereos values and age
			 */
			if(curFaction.heroes != -1) {
				newFaction.heroes = curFaction.heroes;
			}
			
			if(curFaction.maxHeroes != -1) {
				newFaction.maxHeroes = curFaction.maxHeroes;
			}
			
			if(curFaction.age != -1) {
				newFaction.age = curFaction.age;
			}
			
			
			if(curFaction.getItems()!=null){
				if(curFaction.getItems().size()>0){
					for (Iterator iter = curFaction.getItems().iterator();iter.hasNext();){
						Item currentItem = (Item)iter.next();
						newFaction.addItem(currentItem);
					}
				}
			}
			
			
		}
	}
}




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