using Newtonsoft.Json.Linq;
using UnityEngine;
using System.Collections.Generic;

public enum MissileTechnique {SeaSkimming = 0};

public class GuidanceModule : Module {
	private MissileTechnique technique;
	private List<ClassType> listCanHit;
	private float failProbability; //per sec

	public GuidanceModule(JObject json) : base(json) {
		this.technique = (MissileTechnique)((int)(json["missileTechnique"]) - 1);

		this.listCanHit = new List<ClassType>();
		foreach (int classType in json["canHit"]) {
			listCanHit.Add((ClassType)(classType - 1));
		}

		this.failProbability = (float)json["failProbability"];
	}

	public MissileTechnique getMissileTechnique() {
		return technique;
	}

	public bool canHit(ClassType classType) {
		return (listCanHit.Contains(classType));
	}

	public float getFailProbability(float delta) {
		return 1 - Mathf.Pow(1 - failProbability, delta);
	}

	public static GuidanceModule[] loadModules(string[] filenames) {
		GuidanceModule[] array = new GuidanceModule[filenames.Length];

		for (int i = 0; i < filenames.Length; i++) {
			array[i] = new GuidanceModule(jsonFromFile(filenames[i]));
		}

		return array;
	}

	override public void updateClasses() {
	}

	override public ModuleData getData(int parent) {
		return new GuidanceModuleData(parent, this);
	}
}

public class GuidanceModuleData : ModuleData {
	public GuidanceModuleData(int parent, Module template) : base(parent, template) {
	}

	override public void deployUnit(int storedUnitID) {
		Debug.LogError("This module cannot deploy units");
	}
}
