view api/Objects/GameSystem.cs @ 0:520818033bb6

Initial commit of WarFoundry code
author IBBoard <dev@ibboard.co.uk>
date Fri, 19 Dec 2008 15:57:51 +0000
parents
children 150a5669cd7b
line wrap: on
line source

using System;
using System.Collections.Generic;
using System.Xml;
using System.IO;
using IBBoard.Logging;
using IBBoard.WarFoundry.API.Factories;
using ICSharpCode.SharpZipLib.Zip;

namespace IBBoard.WarFoundry.API.Objects
{
	/// <summary>
	/// Summary description for GameSystem.
	/// </summary>
	public class GameSystem : WarFoundryObject // WarFoundryStagedLoadSourceObject
	{
		private bool warnOnError;
		private Category[] categories;
		private SystemStatsSet stats;
		private string defaultStats;
		private FileInfo sourceFile;

		public GameSystem(string systemID, string systemName) : base(systemID, systemName)
		{
		}
				
		/*public void CompleteLoading(Category[] cats, Dictionary<string, SystemStats> sysStats, string defaultStatsID)
		{
			categories = cats;
			stats = new SystemStatsSet(sysStats); 
			defaultStats = defaultStatsID;
			base.CompleteLoading();
		}*/
		
		public FileInfo SourceFile
		{
			get { return sourceFile; }
			set { sourceFile = value; }
		}
		
		public int GetCategoryCount()
		{
			return categories.Length;
		}

		public Category GetCategory(int index)
		{
			return categories[index];
		}

		public Category GetCategory(string id)
		{
			for (int i = 0; i<categories.Length; i++)
			{
				if (categories[i].ID == id)
				{
					return categories[i];
				}
			}

			return null;
		}

		public Category[] Categories
		{
			get 
			{ 
				return SystemCategories; 
			}
			set 
			{
				SystemCategories = value;
			}
		}
		
		protected virtual Category[] SystemCategories
		{
			get 
			{
				return RawSystemCategories;
			}
			set
			{
				RawSystemCategories = value;
			}
		}
		
		protected Category[] RawSystemCategories
		{
			get 
			{ 
				return categories; 
			}
			set 
			{
				if (value!=null)
				{
					categories = value;
				}
			}
		}

		public bool WarnOnError
		{
			get
			{
				return warnOnError;
			}
			set { warnOnError = value; }
		}
		
		public SystemStats StandardSystemStats
		{
			get
			{
				return SystemStats[defaultStats];
			}
		}
		
		public string StandardSystemStatsID
		{
			get
			{				
				return defaultStats;
			}
			
			set
			{
				if (value != null && value.Trim().Length > 0)
				{
					defaultStats = value;
				}
			}
		}

		public SystemStatsSet SystemStats
		{
			get 
			{ 
				return stats;
			}
			set
			{
				stats = value;
			}
		}
		
		public Race SystemDefaultRace
		{
			get { return WarFoundryLoader.GetDefault().GetRace(this, Race.SYSTEM_DEFAULT_RACE_ID); }
		}

		public bool Matches(GameSystem otherSystem)
		{
			if (otherSystem==null)
			{
				return false;
			}

			return this.ID == otherSystem.ID;
		}

		public override bool Equals(object obj)
		{
			if (obj == null)
			{
				return false;		
			}
			
			if (obj.GetType().Equals(this.GetType()))
			{
				GameSystem otherSystem = (GameSystem)obj;

				return this.ID == otherSystem.ID && this.Name == otherSystem.Name && ((this.RawSystemCategories == null && otherSystem.RawSystemCategories == null) || this.RawSystemCategories.Equals(otherSystem.RawSystemCategories));
			}
			else
			{
				return false;
			}
		}

		public override int GetHashCode()
		{
			return ID.GetHashCode() + Name.GetHashCode() + (RawSystemCategories!=null ? RawSystemCategories.GetHashCode() : 0) + warnOnError.GetHashCode();
		}

		public bool UnitTypeMaxed(UnitType unitType, Army army)
		{
			return unitType.MaxNumber!=-1 && army.GetUnitTypeCount(unitType) >= unitType.MaxNumber;
		}

		public bool UnitTypeMinned(UnitType unitType, Army army)
		{
			return army.GetUnitTypeCount(unitType) <= unitType.MinNumber;
		}
		
		public List<EquipmentItem> GetSystemEquipmentList()
		{
			List<EquipmentItem> items = new List<EquipmentItem>();
			Race defaultRace = SystemDefaultRace;
			
			if (defaultRace!=null)
			{				
				items = defaultRace.GetEquipmentList();
			}
			
			return items;
		}
				
		public EquipmentItem GetSystemEquipmentItem(string id)
		{
			EquipmentItem item = null;
			Race defaultRace = SystemDefaultRace;
			
			if (defaultRace!=null)
			{				
				item = defaultRace.GetEquipmentItem(id);
			}
			
			return item;
		}
		
		public UnitType[] GetSystemUnitTypes(Category cat)
		{
			UnitType[] items = new UnitType[0];
			Race defaultRace = SystemDefaultRace;
			
			if (defaultRace!=null)
			{				
				items = defaultRace.GetUnitTypes(cat);
			}
			
			return items;
		}
				
		public UnitType GetSystemUnitType(string id)
		{
			UnitType unit = null;
			Race defaultRace = SystemDefaultRace;
			
			if (defaultRace!=null)
			{				
				unit = defaultRace.GetUnitType(id);
			}
			
			return unit;
		}
		
		public List<Ability> GetSystemAbilityList()
		{
			List<Ability> items = new List<Ability>();
			Race defaultRace = SystemDefaultRace;
			
			if (defaultRace!=null)
			{				
				items = defaultRace.GetAbilityList();
			}
			
			return items;
		}
				
		public Ability GetSystemAbility(string id)
		{
			Ability ability = null;
			Race defaultRace = SystemDefaultRace;
			
			if (defaultRace!=null)
			{				
				ability = defaultRace.GetAbility(id);
			}
			
			return ability;
		}
	}
}