// Path: core/src/com/galvarez/ttw/model/components/Discoveries.java
// public final class Discoveries extends Component {
// 
//   public final Set<Discovery> done = new HashSet<>();
// 
//   /** Increase to speed progress up. */
//   public int progressPerTurn = 1;
// 
//   /** Contains possibles discoveries when one is expected. */
//   public Map<Faction, Research> nextPossible;
// 
//   public Research last;
// 
//   public Discoveries() {
//   }
// 
// }
// 
// Path: core/src/com/galvarez/ttw/model/components/Policies.java
// public final class Policies extends Component {
// 
//   public final Map<Policy, Discovery> policies = new EnumMap<>(Policy.class);
// 
//   /**
//    * Stability percentage, decrease when changing policies, increase with time
//    * to stability max value.
//    */
//   public int stability = 15;
// 
//   public int stabilityMax = 15;
// 
//   public int stabilityGrowth = 1;
// 
//   public Policies() {
//   }
// 
// }
// 
// Path: core/src/com/galvarez/ttw/model/data/Discovery.java
// public final class Discovery {
// 
//   public final String name;
// 
//   public final Set<Terrain> terrains = EnumSet.noneOf(Terrain.class);
// 
//   public final Set<String> groups;
// 
//   public final Set<Set<String>> previous;
// 
//   public ObjectFloatMap<Faction> factions;
// 
//   /**
//    * Indexed by effect name, contains the delta for the corresponding variable.
//    * Positive numbers are positive modifiers for the discoverer.
//    */
//   public final Map<String, Object> effects;
// 
//   private Discovery(String name, List<List<String>> previous, List<String> groups, List<Terrain> terrains,
//       Map<String, Object> effects) {
//     this.name = name;
//     this.effects = effects != null ? effects : Collections.emptyMap();
//     this.previous = previous.stream().filter(l -> !l.isEmpty()).map(l -> set(l)).collect(toSet());
//     this.groups = set(groups);
//     if (terrains != null)
//       this.terrains.addAll(terrains);
//   }
// 
//   @SuppressWarnings("unchecked")
//   private static <T> Set<T> set(List<T> list) {
//     if (list == null || list.isEmpty())
//       return Collections.emptySet();
//     if (list.size() == 1)
//       return Collections.singleton(list.get(0));
//     else if (list instanceof Set)
//       return (Set<T>) list;
//     else
//       return new HashSet<>(list);
//   }
// 
//   public Discovery(String name) {
//     this(name, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), null);
//   }
// 
//   public String getName() {
//     return name;
//   }
// 
//   @Override
//   public String toString() {
//     return name;
//   }
// 
//   @Override
//   public int hashCode() {
//     return name.hashCode();
//   }
// 
//   @Override
//   public boolean equals(Object obj) {
//     if (obj == this)
//       return true;
//     else if (obj instanceof Discovery)
//       return name.equals(((Discovery) obj).name);
//     else
//       return false;
//   }
// 
//   public static final ReadOnlySerializer<Discovery> SER = new ReadOnlySerializer<Discovery>() {
//     @SuppressWarnings("unchecked")
//     @Override
//     public Discovery read(Json json, JsonValue data, Class type) {
//       return new Discovery(data.getString("name"), //
//           json.readValue(ArrayList.class, ArrayList.class, data.get("previous")), //
//           json.readValue(ArrayList.class, data.get("groups")), //
//           json.readValue(ArrayList.class, Terrain.class, data.get("terrains")), //
//           json.readValue(HashMap.class, data.get("effects")));
//     }
//   };
// 
// }
// 
// Path: core/src/com/galvarez/ttw/model/data/Policy.java
// public enum Policy {
// 
//   FOOD("Our people prefer eating "),
// 
//   WEAPON("When fighting, our people use "),
// 
//   MOVE("We go farther and better by "),
// 
//   TERRAIN("Our preferred terrain is "),
// 
//   RELATION("Our preferred relation is "),
// 
//   VALUE("Our most honored value is "),
// 
//   ART("Our most excellent art is "),
// 
//   GOVERNMENT("We are governed by "),
// 
//   JOBS("Our people are mostly ");
// 
//   public final String msg;
// 
//   private Policy(String msg) {
//     this.msg = msg;
//   }
// 
//   public static final Policy get(String name) {
//     try {
//       return Policy.valueOf(name);
//     } catch (IllegalArgumentException e) {
//       return null;
//     }
//   }
// 
// }


import static java.lang.Math.min;
import static java.util.stream.Collectors.toList;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.artemis.Aspect;
import com.artemis.ComponentMapper;
import com.artemis.Entity;
import com.artemis.EntitySystem;
import com.artemis.annotations.Wire;
import com.artemis.utils.ImmutableBag;
import com.galvarez.ttw.model.components.Discoveries;
import com.galvarez.ttw.model.components.Policies;
import com.galvarez.ttw.model.data.Discovery;
import com.galvarez.ttw.model.data.Policy;
package com.galvarez.ttw.model;





/**
 * For every empire, handle policies changes.
 * <p>
 * When changing a policy, the stability decreases. It increases slowly over
 * time.
 * </p>
 * 
 * @author Guillaume Alvarez
 */
@Wire
public final class PoliciesSystem extends EntitySystem {

  private static final int STABILITY_LOSS_WHEN_SWITCHING = 20;

  @SuppressWarnings("unused")
  private static final Logger log = LoggerFactory.getLogger(PoliciesSystem.class);

  private ComponentMapper<Policies> policies;

// Path: core/src/com/galvarez/ttw/model/components/Discoveries.java
// public final class Discoveries extends Component {
// 
//   public final Set<Discovery> done = new HashSet<>();
// 
//   /** Increase to speed progress up. */
//   public int progressPerTurn = 1;
// 
//   /** Contains possibles discoveries when one is expected. */
//   public Map<Faction, Research> nextPossible;
// 
//   public Research last;
// 
//   public Discoveries() {
//   }
// 
// }
// 
// Path: core/src/com/galvarez/ttw/model/components/Policies.java
// public final class Policies extends Component {
// 
//   public final Map<Policy, Discovery> policies = new EnumMap<>(Policy.class);
// 
//   /**
//    * Stability percentage, decrease when changing policies, increase with time
//    * to stability max value.
//    */
//   public int stability = 15;
// 
//   public int stabilityMax = 15;
// 
//   public int stabilityGrowth = 1;
// 
//   public Policies() {
//   }
// 
// }
// 
// Path: core/src/com/galvarez/ttw/model/data/Discovery.java
// public final class Discovery {
// 
//   public final String name;
// 
//   public final Set<Terrain> terrains = EnumSet.noneOf(Terrain.class);
// 
//   public final Set<String> groups;
// 
//   public final Set<Set<String>> previous;
// 
//   public ObjectFloatMap<Faction> factions;
// 
//   /**
//    * Indexed by effect name, contains the delta for the corresponding variable.
//    * Positive numbers are positive modifiers for the discoverer.
//    */
//   public final Map<String, Object> effects;
// 
//   private Discovery(String name, List<List<String>> previous, List<String> groups, List<Terrain> terrains,
//       Map<String, Object> effects) {
//     this.name = name;
//     this.effects = effects != null ? effects : Collections.emptyMap();
//     this.previous = previous.stream().filter(l -> !l.isEmpty()).map(l -> set(l)).collect(toSet());
//     this.groups = set(groups);
//     if (terrains != null)
//       this.terrains.addAll(terrains);
//   }
// 
//   @SuppressWarnings("unchecked")
//   private static <T> Set<T> set(List<T> list) {
//     if (list == null || list.isEmpty())
//       return Collections.emptySet();
//     if (list.size() == 1)
//       return Collections.singleton(list.get(0));
//     else if (list instanceof Set)
//       return (Set<T>) list;
//     else
//       return new HashSet<>(list);
//   }
// 
//   public Discovery(String name) {
//     this(name, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), null);
//   }
// 
//   public String getName() {
//     return name;
//   }
// 
//   @Override
//   public String toString() {
//     return name;
//   }
// 
//   @Override
//   public int hashCode() {
//     return name.hashCode();
//   }
// 
//   @Override
//   public boolean equals(Object obj) {
//     if (obj == this)
//       return true;
//     else if (obj instanceof Discovery)
//       return name.equals(((Discovery) obj).name);
//     else
//       return false;
//   }
// 
//   public static final ReadOnlySerializer<Discovery> SER = new ReadOnlySerializer<Discovery>() {
//     @SuppressWarnings("unchecked")
//     @Override
//     public Discovery read(Json json, JsonValue data, Class type) {
//       return new Discovery(data.getString("name"), //
//           json.readValue(ArrayList.class, ArrayList.class, data.get("previous")), //
//           json.readValue(ArrayList.class, data.get("groups")), //
//           json.readValue(ArrayList.class, Terrain.class, data.get("terrains")), //
//           json.readValue(HashMap.class, data.get("effects")));
//     }
//   };
// 
// }
// 
// Path: core/src/com/galvarez/ttw/model/data/Policy.java
// public enum Policy {
// 
//   FOOD("Our people prefer eating "),
// 
//   WEAPON("When fighting, our people use "),
// 
//   MOVE("We go farther and better by "),
// 
//   TERRAIN("Our preferred terrain is "),
// 
//   RELATION("Our preferred relation is "),
// 
//   VALUE("Our most honored value is "),
// 
//   ART("Our most excellent art is "),
// 
//   GOVERNMENT("We are governed by "),
// 
//   JOBS("Our people are mostly ");
// 
//   public final String msg;
// 
//   private Policy(String msg) {
//     this.msg = msg;
//   }
// 
//   public static final Policy get(String name) {
//     try {
//       return Policy.valueOf(name);
//     } catch (IllegalArgumentException e) {
//       return null;
//     }
//   }
// 
// }


// Path: core/src/com/galvarez/ttw/model/PoliciesSystem.java
import static java.lang.Math.min;
import static java.util.stream.Collectors.toList;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.artemis.Aspect;
import com.artemis.ComponentMapper;
import com.artemis.Entity;
import com.artemis.EntitySystem;
import com.artemis.annotations.Wire;
import com.artemis.utils.ImmutableBag;
import com.galvarez.ttw.model.components.Discoveries;
import com.galvarez.ttw.model.components.Policies;
import com.galvarez.ttw.model.data.Discovery;
import com.galvarez.ttw.model.data.Policy;

package com.galvarez.ttw.model;





/**
 * For every empire, handle policies changes.
 * <p>
 * When changing a policy, the stability decreases. It increases slowly over
 * time.
 * </p>
 * 
 * @author Guillaume Alvarez
 */
@Wire
public final class PoliciesSystem extends EntitySystem {

  private static final int STABILITY_LOSS_WHEN_SWITCHING = 20;

  @SuppressWarnings("unused")
  private static final Logger log = LoggerFactory.getLogger(PoliciesSystem.class);

  private ComponentMapper<Policies> policies;

  private ComponentMapper<Discoveries> discoveries;